getBookContents() static public method

Returns an array representing the entire structure of a book, in correct order, with a maximum amount of fields. Data is raw and must be post-processed.
See also: bottom of this file for more info
static public getBookContents ( ) : array
return array
 /**
  * Create $this->outputPath
  *
  * @return bool
  */
 function convert()
 {
     // Create ICML
     $vars = array('meta' => \PressBooks\Book::getBookInformation(), 'book_contents' => $this->preProcessBookContents(\PressBooks\Book::getBookContents()));
     $cc_copyright = strip_tags($this->doCopyrightLicense($vars['meta']));
     $vars['do_copyright_license'] = $cc_copyright;
     $book_html = $this->loadTemplate(__DIR__ . '/templates/xhtml.php', $vars);
     $content = $this->transformXML($book_html, PB_PLUGIN_DIR . 'symbionts/icml/tkbr2icml-v044.xsl');
     // Save ICML as file in exports folder
     $filename = $this->timestampedFileName('.icml');
     file_put_contents($filename, $content);
     $this->outputPath = $filename;
     if (!filesize($this->outputPath)) {
         $this->logError($this->bookHtmlError($book_html));
         unlink($this->outputPath);
         return false;
     }
     return true;
 }
 /**
  * Create $this->outputPath
  *
  * @return bool
  */
 function convert()
 {
     // Sanity check
     if (empty($this->tmpDir) || !is_dir($this->tmpDir)) {
         $this->logError('$this->tmpDir must be set before calling convert().');
         return false;
     }
     if (empty($this->exportStylePath) || !is_file($this->exportStylePath)) {
         $this->logError('$this->exportStylePath must be set before calling convert().');
         return false;
     }
     // Convert
     $metadata = \PressBooks\Book::getBookInformation();
     $book_contents = $this->preProcessBookContents(\PressBooks\Book::getBookContents());
     try {
         $this->createContainer();
         $this->createOEPBS($book_contents, $metadata);
         $this->createOPF($book_contents, $metadata);
         $this->createNCX($book_contents, $metadata);
     } catch (\Exception $e) {
         $this->logError($e->getMessage());
         return false;
     }
     $filename = $this->timestampedFileName($this->suffix);
     if (!$this->zipEpub($filename)) {
         return false;
     }
     $this->outputPath = $filename;
     return true;
 }
 /**
  * Restructures \PressBooks\Book::getBookContents() into a format more useful
  * for direct iteration, and tracks a nesting level for Bookmark and ToC
  * entries.
  *
  * @return array
  */
 function getOrderedBookContents()
 {
     $book_contents = \PressBooks\Book::getBookContents();
     $ordered = array();
     foreach ($book_contents as $type => $struct) {
         if (strpos($type, '__') === 0) {
             continue;
             // Skip __magic keys
         }
         switch ($type) {
             case 'part':
                 foreach ($struct as $part) {
                     $part_content = trim(get_post_meta($part['ID'], 'pb_part_content', true));
                     if ($part_content || $this->atLeastOneExport($part['chapters'])) {
                         if (!empty($part['post_content'])) {
                             $part['mpdf_level'] = 1;
                             $part['post_content'] .= $part_content;
                         } else {
                             $part['post_content'] = $part_content;
                             $part['mpdf_level'] = 0;
                         }
                         $ordered[] = $part;
                         foreach ($part['chapters'] as $chapter) {
                             if (!$chapter['export']) {
                                 continue;
                             }
                             $chapter['mpdf_level'] = $part['mpdf_level'] + 1;
                             $ordered[] = $chapter;
                             if (\PressBooks\Export\Export::shouldParseSections() == true) {
                                 $sections = \PressBooks\Book::getSubsections($chapter['ID']);
                                 if ($sections) {
                                     foreach ($sections as $section) {
                                         $section['mpdf_level'] = $part['mpdf_level'] + 2;
                                         $ordered[] = $section;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 break;
             default:
                 foreach ($struct as $item) {
                     if (!$item['export']) {
                         continue;
                     }
                     $item['mpdf_level'] = 1;
                     $ordered[] = $item;
                     if (\PressBooks\Export\Export::shouldParseSections() == true) {
                         $sections = \PressBooks\Book::getSubsections($item['ID']);
                         if ($sections) {
                             foreach ($sections as $section) {
                                 $section['mpdf_level'] = 2;
                                 $ordered[] = $section;
                             }
                         }
                     }
                 }
                 break;
         }
     }
     return $ordered;
 }
 /**
  * Procedure for "format/xhtml" rewrite rule.
  */
 function transform()
 {
     // Check permissions
     if (!current_user_can('manage_options')) {
         $timestamp = absint(@$_REQUEST['timestamp']);
         $hashkey = @$_REQUEST['hashkey'];
         if (!$this->verifyNonce($timestamp, $hashkey)) {
             wp_die(__('Invalid permission error', 'pressbooks'));
         }
     }
     // Override footnote shortcode
     if (!empty($_GET['endnotes'])) {
         add_shortcode('footnote', array($this, 'endnoteShortcode'));
     } else {
         add_shortcode('footnote', array($this, 'footnoteShortcode'));
     }
     // ------------------------------------------------------------------------------------------------------------
     // XHTML, Start!
     $metadata = \PressBooks\Book::getBookInformation();
     $book_contents = $this->preProcessBookContents(\PressBooks\Book::getBookContents());
     $this->echoDocType($book_contents, $metadata);
     echo "<head>\n";
     echo '<meta content="text/html; charset=UTF-8" http-equiv="content-type" />' . "\n";
     echo '<base href="' . trailingslashit(site_url('', 'http')) . '" />' . "\n";
     $this->echoMetaData($book_contents, $metadata);
     echo '<title>' . get_bloginfo('name') . "</title>\n";
     echo "</head>\n<body>\n";
     // Before Title Page
     $this->echoBeforeTitle($book_contents, $metadata);
     // Half-title
     $this->echoHalfTitle($book_contents, $metadata);
     // Cover
     $this->echoCover($book_contents, $metadata);
     // Title
     $this->echoTitle($book_contents, $metadata);
     // Copyright
     $this->echoCopyright($book_contents, $metadata);
     // Dedication and Epigraph (In that order!)
     $this->echoDedicationAndEpigraph($book_contents, $metadata);
     // Table of contents
     $this->echoToc($book_contents, $metadata);
     // Front-matter
     $this->echoFrontMatter($book_contents, $metadata);
     // Promo
     $this->createPromo($book_contents, $metadata);
     // Parts, Chapters
     $this->echoPartsAndChapters($book_contents, $metadata);
     // Back-matter
     $this->echoBackMatter($book_contents, $metadata);
     // XHTML, Stop!
     echo "</body>\n</html>";
 }