Created
November 6, 2015 15:10
-
-
Save joshlevinson/4a2c3ed78b21b3c54eba to your computer and use it in GitHub Desktop.
Sample Eight Day Week filters for the Observer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'Eight_Day_Week\Plugins\Article_Export\xml_outer_elements', function( $elements, $article ) { | |
$elements['subHeadline'] = get_post_meta( $article->ID, 'nyo_dek', true ); | |
return $elements; | |
}, 10, 2 ); | |
add_filter( 'Eight_Day_Week\Plugins\Article_Export\xml_outer_elements', function( $elements, $article ) { | |
if( function_exists( '\Eight_Day_Week\Plugins\Article_Byline\get_article_byline' ) ) { | |
$elements['byline'] = \Eight_Day_Week\Plugins\Article_Byline\get_article_byline( $article ); | |
} | |
return $elements; | |
}, 10, 2 ); | |
add_filter( 'Eight_Day_Week\Plugins\Article_Export\xpath_extract', function( $extract ) { | |
$extract[] = [ | |
'tag_name' => 'pullQuote', | |
'container' => 'pullQuotes', | |
'query' => '//p[contains(@class, "pullquote")]' | |
]; | |
return $extract; | |
} ); | |
add_filter( 'Eight_Day_Week\Plugins\Article_Export\dom', function ( $dom ) { | |
$swap_tag_name = 'emphasized'; | |
$extract_map = [ | |
'strong' => [ | |
'solo' => 'bold', | |
'inner' => 'em' | |
], | |
'em' => [ | |
'solo' => 'italics', | |
'inner' => 'strong' | |
], | |
]; | |
foreach ( $extract_map as $tag_name => $map ) { | |
$nodes = $dom->getElementsByTagName( $tag_name ); | |
$length = $nodes->length; | |
for ( $i = $length; -- $i >= 0; ) { | |
$el = $nodes->item( $i ); | |
$emphasized = $el->getElementsByTagName( $map['inner'] ); | |
if ( $emphasized->length ) { | |
$em = $dom->createElement( $swap_tag_name ); | |
$em->nodeValue = $el->nodeValue; | |
try { | |
$el->parentNode->replaceChild( $em, $el ); | |
} catch ( \Exception $e ) { | |
} | |
continue; | |
} | |
$new = $dom->createElement( $map['solo'] ); | |
$new->nodeValue = $el->nodeValue; | |
try { | |
$el->parentNode->replaceChild( $new, $el ); | |
} catch ( \Exception $e ) { | |
} | |
} | |
} | |
return $dom; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment