Skip to content

Commit 28789f4

Browse files
committed
switch to component
1 parent 44c9211 commit 28789f4

File tree

4 files changed

+99
-84
lines changed

4 files changed

+99
-84
lines changed

admin/apple-actions/index/class-export.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Apple_Exporter\Exporter_Content_Settings;
1919
use Apple_Exporter\Theme;
2020
use Apple_Exporter\Third_Party\Jetpack_Tiled_Gallery;
21-
use Apple_Exporter\Footnotes;
2221
use Apple_News;
2322
use BC_Setup;
2423

@@ -59,7 +58,6 @@ public function __construct( $settings, $id = null, $sections = null ) {
5958
$this->id = $id;
6059
$this->set_theme();
6160
Jetpack_Tiled_Gallery::instance();
62-
Footnotes::instance();
6361
}
6462

6563
/**

includes/apple-exporter/class-component-factory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public static function initialize(
102102
self::register_component( 'audio', '\\Apple_Exporter\\Components\\Audio' );
103103
self::register_component( 'heading', '\\Apple_Exporter\\Components\\Heading' );
104104
self::register_component( 'blockquote', '\\Apple_Exporter\\Components\\Quote' );
105+
self::register_component( 'footnotes', '\\Apple_Exporter\\Components\\Footnotes' );
105106
self::register_component( 'p', '\\Apple_Exporter\\Components\\Body' );
106107
self::register_component( 'ol', '\\Apple_Exporter\\Components\\Body' );
107108
self::register_component( 'ul', '\\Apple_Exporter\\Components\\Body' );

includes/apple-exporter/class-footnotes.php

Lines changed: 0 additions & 82 deletions
This file was deleted.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Publish to Apple News: \Apple_Exporter\Components\Footnotes class
4+
*
5+
* @package Apple_News
6+
* @subpackage Apple_Exporter\Components
7+
*/
8+
9+
namespace Apple_Exporter\Components;
10+
11+
/**
12+
* A translation of the WordPress Footnotes block.
13+
*
14+
* @since 0.2.5
15+
*/
16+
class Footnotes extends Component {
17+
18+
/**
19+
* Look for node matches for this component.
20+
*
21+
* @param \DOMElement $node The node to examine for matches.
22+
* @access public
23+
* @return \DOMElement|null The node on success, or null on no match.
24+
*/
25+
public static function node_matches( $node ) {
26+
if (
27+
'ol' === $node->nodeName &&
28+
self::node_has_class( $node, 'wp-block-footnotes' )
29+
) {
30+
return $node;
31+
}
32+
33+
return null;
34+
}
35+
36+
/**
37+
* Register all specs for the component.
38+
*
39+
* @access public
40+
*/
41+
public function register_specs() {
42+
$this->register_spec(
43+
'footnotes-json',
44+
__( 'Footnotes JSON', 'apple-news' ),
45+
[
46+
'role' => 'container',
47+
'layout' => 'body-layout',
48+
'components' => '#components#',
49+
]
50+
);
51+
52+
$this->register_spec(
53+
'footnote-json',
54+
__( 'Footnote JSON', 'apple-news' ),
55+
[
56+
'role' => 'text',
57+
'text' => '#text#',
58+
'identifier' => '#identifier#',
59+
]
60+
);
61+
62+
}
63+
64+
/**
65+
* Build the component.
66+
*
67+
* @param string $html The HTML to parse into text for processing.
68+
* @access protected
69+
*/
70+
protected function build( $html ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
71+
preg_match_all( '/<li.*?>.*?<\/li>/', $html, $matches );
72+
$items = $matches[0];
73+
74+
// convert each list item to a paragraph with a number added.
75+
foreach ( $items as $key => $item ) {
76+
$count = $key + 1;
77+
$text = preg_replace(
78+
'/<li(.*?)>(.*?)<\/li>/',
79+
"<p$1>${count}. $2</p>",
80+
$item
81+
);
82+
preg_match( '/id="(.*?)"/', $text, $matches );
83+
$id = $matches[1] ?? null;
84+
$components[] = [
85+
'role' => 'body',
86+
'text' => $text,
87+
'format' => 'html',
88+
'identifier' => $id,
89+
];
90+
}
91+
$this->register_json(
92+
'footnotes-json',
93+
[
94+
'#components#' => $components,
95+
]
96+
);
97+
}
98+
}

0 commit comments

Comments
 (0)