Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #177 from gemedet/image
Browse files Browse the repository at this point in the history
Use H1 for header title and cover image caption
  • Loading branch information
everton-rosario committed May 19, 2016
2 parents f1dfe09 + e665110 commit ed25fc8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
61 changes: 34 additions & 27 deletions class-instant-articles-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,15 +578,45 @@ public function to_instant_article() {
// Get time zone configured in WordPress. Default to UTC if no time zone configured.
$date_time_zone = get_option( 'timezone_string' ) ? new DateTimeZone( get_option( 'timezone_string' ) ) : new DateTimeZone( 'UTC' );

// Initialize transformer
$file_path = plugin_dir_path( __FILE__ ) . 'rules-configuration.json';
$configuration = file_get_contents( $file_path );

$transformer = new Transformer();
$this->transformer = $transformer;
$transformer->loadRules( $configuration );

$transformer = apply_filters( 'instant_articles_transformer_rules_loaded', $transformer );

$settings_publishing = Instant_Articles_Option_Publishing::get_option_decoded();

if (
isset ( $settings_publishing['custom_rules_enabled'] ) &&
! empty( $settings_publishing['custom_rules_enabled'] ) &&
isset ( $settings_publishing['custom_rules'] ) &&
! empty( $settings_publishing['custom_rules'] )
) {
$transformer->loadRules( $settings_publishing['custom_rules'] );
}

$transformer = apply_filters( 'instant_articles_transformer_custom_rules_loaded', $transformer );

$blog_charset = get_option( 'blog_charset' );

$header =
Header::create()
->withPublishTime(
Time::create( Time::PUBLISHED )->withDatetime( new DateTime( $this->_post->post_date, $date_time_zone ) )
)
->withModifyTime(
Time::create( Time::MODIFIED )->withDatetime( new DateTime( $this->_post->post_modified, $date_time_zone ) )
)
->withTitle( $this->get_the_title() );
);

$title = $this->get_the_title();
if ( $title ) {
$document = DOMDocument::loadHTML( '<?xml encoding="' . $blog_charset . '" ?><h1>' . $title . '</h1>' );
$transformer->transform( $header, $document );
}

$authors = $this->get_the_authors();
foreach ( $authors as $author ) {
Expand All @@ -610,9 +640,8 @@ public function to_instant_article() {
if ( $cover['src'] ) {
$image = Image::create()->withURL( $cover['src'] );
if ( isset( $cover['caption'] ) && strlen( $cover['caption'] ) > 0 ) {
$image->withCaption(
Caption::create()->withTitle( $cover['caption'] )
);
$document = DOMDocument::loadHTML( '<?xml encoding="' . $blog_charset . '" ?><h1>' . $cover['caption'] . '</h1>' );
$image->withCaption( $transformer->transform( Caption::create(), $document ) );
}

$header->withCover( $image );
Expand All @@ -632,28 +661,6 @@ public function to_instant_article() {
$this->instant_article->withStyle( 'default' );
}

$file_path = plugin_dir_path( __FILE__ ) . 'rules-configuration.json';
$configuration = file_get_contents( $file_path );

$transformer = new Transformer();
$this->transformer = $transformer;
$transformer->loadRules( $configuration );

$transformer = apply_filters( 'instant_articles_transformer_rules_loaded', $transformer );

$settings_publishing = Instant_Articles_Option_Publishing::get_option_decoded();

if (
isset ( $settings_publishing['custom_rules_enabled'] ) &&
! empty( $settings_publishing['custom_rules_enabled'] ) &&
isset ( $settings_publishing['custom_rules'] ) &&
! empty( $settings_publishing['custom_rules'] )
) {
$transformer->loadRules( $settings_publishing['custom_rules'] );
}

$transformer = apply_filters( 'instant_articles_transformer_custom_rules_loaded', $transformer );

$libxml_previous_state = libxml_use_internal_errors( true );
$document = new DOMDocument( '1.0', get_option( 'blog_charset' ) );
$content = $this->get_the_content();
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"php": ">=5.4",
"facebook/php-sdk-v4": "~5.0",
"apache/log4php": "2.3.0",
"facebook/facebook-instant-articles-sdk-php": "^1.0.0"
"facebook/facebook-instant-articles-sdk-php": "^1.1.0"
}
}

0 comments on commit ed25fc8

Please sign in to comment.