Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add observer example to readmes #97

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,83 @@ The information displayed in the list of Print Issues is filterable. Custom colu

The export of posts in a Print Issue is highly customizeable, from the file name of the zip, to the file name of the individual files, to the contents of the files themselves. The best reference would be to read through `includes/functions/plugins/article-export.php`. [Here's](https://github.com/10up/eight-day-week/wiki/Sample-Eight-Day-Week-filters-for-the-Observer) a few examples used on the *Observer*.

### Sample Eight Day Week filters for the Observer

Examples from Observer's eight-day-week-filters.php:

```php
<?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;

} );
```

## Known Caveats/Issues

### Gutenberg exports
Expand Down
77 changes: 77 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,83 @@ The information displayed in the list of Print Issues is filterable. Custom colu

The export of posts in a Print Issue is highly customizable, from the file name of the zip, to the file name of the individual files, to the contents of the files themselves. The best reference would be to read through `includes/functions/plugins/article-export.php`. [Here's](https://github.com/10up/eight-day-week/wiki/Sample-Eight-Day-Week-filters-for-the-Observer) a few examples used on the *Observer*.

**Sample Eight Day Week filters for the Observer**

Examples from Observer's eight-day-week-filters.php:

`
<?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;

} );
`

== Known Caveats/Issues ==

**Gutenberg exports**
Expand Down