Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function consume() {
break;
}
$this->append_rich_text( htmlspecialchars( $this->markup_processor->get_modifiable_text() ) );
if ( in_array( $this->markup_processor->get_tag(), array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ) ) ) {
if ( in_array( $this->get_tag_name(), array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ) ) ) {
$this->on_title_candidate( $this->markup_processor->get_modifiable_text() );
}
break;
Expand Down Expand Up @@ -90,7 +90,11 @@ public function consume() {

private function handle_tag() {
$html = $this->markup_processor;
$tag = strtoupper( $html->get_tag() );
if($html instanceof WP_HTML_Processor) {
$tag = strtoupper( $html->get_tag() );
} else {
$tag = strtoupper( $html->get_tag_local_name() );
}
$tag_lowercase = strtolower( $tag );

$is_void_tag = ! $html->expects_closer() && ! $html->is_tag_closer();
Expand All @@ -100,14 +104,14 @@ private function handle_tag() {
$this->on_title_candidate( $html->get_modifiable_text() );
break;
case 'META':
$key = $html->get_attribute( 'name' );
$value = $html->get_attribute( 'content' );
$key = $this->get_attribute( 'name' );
$value = $this->get_attribute( 'content' );
if ( ! array_key_exists( $key, $this->metadata ) ) {
if ( $key ) {
$this->metadata[ $key ] = array();
}
}
switch ( $html->get_attribute( 'type' ) ) {
switch ( $this->get_attribute( 'type' ) ) {
case 'integer':
$value = (int) $value;
break;
Expand All @@ -124,8 +128,8 @@ private function handle_tag() {
$template = new WP_HTML_Tag_Processor( '<img>' );
$template->next_tag();
foreach ( array( 'alt', 'title', 'src' ) as $attr ) {
if ( $html->get_attribute( $attr ) ) {
$template->set_attribute( $attr, $html->get_attribute( $attr ) );
if ( $this->get_attribute( $attr ) ) {
$template->set_attribute( $attr, $this->get_attribute( $attr ) );
}
}
/**
Expand Down Expand Up @@ -211,8 +215,8 @@ private function handle_tag() {
case 'A':
$template = new WP_HTML_Tag_Processor( '<a>' );
$template->next_tag();
if ( $html->get_attribute( 'href' ) ) {
$template->set_attribute( 'href', $html->get_attribute( 'href' ) );
if ( $this->get_attribute( 'href' ) ) {
$template->set_attribute( 'href', $this->get_attribute( 'href' ) );
}
/**
*
Expand Down Expand Up @@ -297,6 +301,22 @@ private function handle_tag() {
}
}

private function get_tag_name() {
if($this->markup_processor instanceof WP_HTML_Processor) {
return $this->markup_processor->get_tag();
} else {
return $this->markup_processor->get_tag_local_name();
}
}

private function get_attribute($key) {
if($this->markup_processor instanceof WP_HTML_Processor) {
return $this->markup_processor->get_attribute($key);
} else {
return $this->markup_processor->get_attribute('', $key);
}
}

private function on_title_candidate( $text ) {
if ( ! array_key_exists( 'post_title', $this->metadata ) ) {
$this->metadata['post_title'] = array(
Expand Down
18 changes: 10 additions & 8 deletions components/DataLiberation/EntityReader/EPubEntityReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function next_entity() {
return false;
}

$this->remaining_html_files = [];
foreach ( $this->manifest['items'] as $item ) {
if ( $item['media-type'] !== 'application/xhtml+xml' ) {
continue;
Expand Down Expand Up @@ -137,11 +138,12 @@ private function parse_manifest() {
$xml = XMLProcessor::create_from_string(
$this->zip->get_contents( 'META-INF/container.xml' )
);
if ( false === $xml->next_tag( 'rootfile' ) ) {

if ( false === $xml->next_tag( ['urn:oasis:names:tc:opendocument:xmlns:container', 'rootfile'] ) ) {
return false;
}

$full_path = $xml->get_attribute( 'full-path' );
$full_path = $xml->get_attribute( '', 'full-path' );
if ( ! $full_path ) {
return false;
}
Expand All @@ -161,16 +163,16 @@ private function parse_manifest() {
);
while ( $xml->next_tag() ) {
$parsed_entry = array();
$keys = $xml->get_attribute_names_with_prefix( '' );
foreach ( $keys as $key ) {
$parsed_entry[ $key ] = $xml->get_attribute( $key );
$keys = $xml->get_attribute_names_with_prefix( '', '' );
foreach ( $keys as list($ns, $key) ) {
$parsed_entry[ $key ] = $xml->get_attribute( $ns, $key );
}
if ( $xml->matches_breadcrumbs( array( 'metadata', '*' ) ) ) {
if ( $xml->matches_breadcrumbs( array( 'package', 'metadata', '*' ) ) ) {
$parsed['metadata'][] = array(
'tag' => $xml->get_tag(),
'tag' => $xml->get_tag_local_name(),
'attributes' => $parsed_entry,
);
} elseif ( $xml->matches_breadcrumbs( array( 'manifest', 'item' ) ) ) {
} elseif ( $xml->matches_breadcrumbs( array( 'package', 'manifest', 'item' ) ) ) {
$parsed_entry['type'] = 'item';
$parsed['items'][] = $parsed_entry;
}
Expand Down
Loading
Loading