/**
* @param array $book_contents
* @param array $metadata
*/
protected function echoPartsAndChapters($book_contents, $metadata)
{
$part_printf = '<div class="part %s" id="%s">';
$part_printf .= '<div class="part-title-wrap"><h3 class="part-number">%s</h3><h1 class="part-title">%s</h1></div>%s';
$part_printf .= '</div>';
$chapter_printf = '<div class="chapter %s" id="%s">';
$chapter_printf .= '<div class="chapter-title-wrap"><h3 class="chapter-number">%s</h3><h2 class="chapter-title">%s</h2></div>';
$chapter_printf .= '<div class="ugc chapter-ugc">%s</div>%s%s';
$chapter_printf .= '</div>';
$s = $i = $j = 1;
foreach ($book_contents['part'] as $part) {
$invisibility = get_post_meta($part['ID'], 'pb_part_invisible', true) == 'on' ? 'invisible' : '';
$part_printf_changed = '';
$slug = $part['post_name'];
$title = $part['post_title'];
$part_content = trim(get_post_meta($part['ID'], 'pb_part_content', true));
// Inject introduction class?
if ('invisible' !== $invisibility) {
// visible
if (count($book_contents['part']) == 1) {
// only part
if ($part_content) {
// has content
if (!$this->hasIntroduction) {
$part_printf_changed = str_replace('<div class="part %s" id=', '<div class="part introduction %s" id=', $part_printf);
$this->hasIntroduction = true;
}
}
} elseif (count($book_contents['part']) > 1) {
// multiple parts
if (!$this->hasIntroduction) {
$part_printf_changed = str_replace('<div class="part %s" id=', '<div class="part introduction %s" id=', $part_printf);
$this->hasIntroduction = true;
}
}
}
// Inject part content?
if ($part_content) {
$part_content = $this->preProcessPostContent($part_content);
if ($part_printf_changed) {
$part_printf_changed = str_replace('</h1></div>%s</div>', '</h1></div><div class="ugc part-ugc">%s</div></div>', $part_printf_changed);
} else {
$part_printf_changed = str_replace('</h1></div>%s</div>', '</h1></div><div class="ugc part-ugc">%s</div></div>', $part_printf);
}
}
$m = 'invisible' == $invisibility ? '' : $i;
$my_part = sprintf($part_printf_changed ? $part_printf_changed : $part_printf, $invisibility, $slug, $m, Sanitize\decode($title), $part_content) . "\n";
$my_chapters = '';
foreach ($part['chapters'] as $chapter) {
if (!$chapter['export']) {
continue;
// Skip
}
$chapter_printf_changed = '';
$chapter_id = $chapter['ID'];
$subclass = \Pressbooks\Taxonomy::getChapterType($chapter_id);
$slug = $chapter['post_name'];
$title = get_post_meta($chapter_id, 'pb_show_title', true) ? $chapter['post_title'] : '<span class="display-none">' . $chapter['post_title'] . '</span>';
// Preserve auto-indexing in Prince using hidden span
$content = $chapter['post_content'];
$append_chapter_content = apply_filters('pb_append_chapter_content', '', $chapter_id);
$short_title = trim(get_post_meta($chapter_id, 'pb_short_title', true));
$subtitle = trim(get_post_meta($chapter_id, 'pb_subtitle', true));
$author = trim(get_post_meta($chapter_id, 'pb_section_author', true));
if (\Pressbooks\Modules\Export\Export::isParsingSubsections() == true) {
$sections = \Pressbooks\Book::getSubsections($chapter_id);
if ($sections) {
$content = \Pressbooks\Book::tagSubsections($content, $chapter_id);
}
}
if ($author) {
$content = '<h2 class="chapter-author">' . Sanitize\decode($author) . '</h2>' . $content;
}
if ($subtitle) {
$content = '<h2 class="chapter-subtitle">' . Sanitize\decode($subtitle) . '</h2>' . $content;
}
if ($short_title) {
$content = '<h6 class="short-title">' . Sanitize\decode($short_title) . '</h6>' . $content;
}
// Inject introduction class?
if (!$this->hasIntroduction) {
$chapter_printf_changed = str_replace('<div class="chapter %s" id=', '<div class="chapter introduction %s" id=', $chapter_printf);
$this->hasIntroduction = true;
}
$n = 'numberless' == $subclass ? '' : $j;
$my_chapters .= sprintf($chapter_printf_changed ? $chapter_printf_changed : $chapter_printf, $subclass, $slug, $n, Sanitize\decode($title), $content, $append_chapter_content, $this->doEndnotes($chapter_id)) . "\n";
if ('numberless' !== $subclass) {
++$j;
}
}
// Echo with parts?
if ('invisible' !== $invisibility) {
// visible
if (count($book_contents['part']) == 1) {
// only part
if ($part_content) {
// has content
echo $my_part;
// show
if ($my_chapters) {
echo $my_chapters;
}
} else {
// no content
if ($my_chapters) {
echo $my_chapters;
}
}
} elseif (count($book_contents['part']) > 1) {
// multiple parts
if ($my_chapters) {
// has chapter
echo $my_part . $my_chapters;
// show
} else {
// no chapter
if ($part_content) {
// has content
echo $my_part;
// show
}
}
}
++$i;
} elseif ('invisible' == $invisibility) {
// invisible
if ($my_chapters) {
echo $my_chapters;
}
}
}
}