$mobiContent->appendChapterTitle($story["title"]); $mobiContent->appendParagraph("by: " . $story["author"]); $mobiContent->appendPageBreak(); for ($i = 0; $i < $numChapter; $i++) { $title = isset($story["chapters"]["title"][$i]) ? $story["chapters"]["title"][$i] : ""; $content = isset($story["chapters"]["content"][$i]) ? $story["chapters"]["content"][$i] : ""; if (!empty($content) && !empty($title)) { $title = formatTitle($title, $i); $mobiContent->appendChapterTitle($title); $mobiContent->appendParagraph($content); $mobiContent->appendPageBreak(); } } $mobi->setContentProvider($mobiContent); $filename = $uniqid . "_" . $story["title"] . " - " . $story["author"] . ".mobi"; $mobi->save("./tmp/" . $filename); if (!empty($email)) { mailAttachment($filename, "./tmp/", $email, $uniqid); } } else { if ($format == "txt") { include_once "include/html2text.php"; $output = $story["title"] . "\r\n\r\nby " . $story["author"] . "\r\n\r\n\r\n"; for ($i = 0; $i < $numChapter; $i++) { $title = isset($story["chapters"]["title"][$i]) ? $story["chapters"]["title"][$i] : ""; $content = isset($story["chapters"]["content"][$i]) ? $story["chapters"]["content"][$i] : ""; if (!empty($content) && !empty($title)) { $title = formatTitle($title, $i); $content = convert_html_to_text($content); $output .= $title . "\r\n\r\n" . $content . "\r\n\r\n"; }
/** * Create a MOBI and export to defined path * @param $dir str directory of the source file to convert * @param $src str filename of the source file to convert * @param $path str path to export the resultant MOBI to * @param $chapters array chapters to convert into a single MOBI * @param $journalId int Id of the journal(imprint) * @param $args array arguments for the conversion (e.g. Description, cover image, etc) */ function createMobi($dir = null, $src, $path, $chapters = array(), $journalId, $args = array()) { $mobi = new MOBI(); $CBPPlatformDao =& DAORegistry::getDAO('CBPPlatformDAO'); $imprintType = $CBPPlatformDao->getImprintType($journalId); $mobiContent = $this->contentStart; if (isset($args['cover'])) { $mobiContent .= "<img src='" . $args['cover'] . "' style=\"margin: 0px auto;\" />"; } else { if (isset($args['title'])) { $mobiContent .= "<h1>" . $args['title'] . "</h1><br />"; } if (isset($args['author'])) { $mobiContent .= "<p><strong>" . $args['author'] . "</strong></p>"; } } $copyrightStatement = $CBPPlatformDao->getJournalCopyrightStatement($journalId); if (!empty($copyrightStatement)) { $copyrightStatement = reset($copyrightStatement); $mobiContent .= "<mbp:pagebreak /><div style='width: 75%; text-align: center; margin: 0 auto;'><p>" . $copyrightStatement . "</p></div>"; } if (!empty($chapters)) { for ($i = 0; $i < count($chapters); $i++) { $document = new TransformDoc(); $document->setStrFile($chapters[$i]['src'], $chapters[$i]['dir']); $document->generateXHTML(); //problem, here $document->validatorXHTML(); $contentPreg = $this->stripTags($document->getStrXHTML()); $introduction = ""; if ($imprintType == "collection") { if ($chapters[$i]['description'] != "") { $introduction = "<mbp:pagebreak /><div class='submissionIntroEpub'><h1>" . $chapters[$i]['author'] . "</h1><div style='font-style: italic;'>" . $this->stripTags($chapters[$i]['description'], true) . "</div></div></body></html>"; } } $mobiContent .= $introduction . $contentPreg; } } else { $content = new TransformDoc(); $content->setStrFile($src, $dir); $content->generateXHTML(); $content->validatorXHTML(); $contentPreg = $this->stripTags($content->getStrXHTML()); $mobiContent .= $contentPreg; } $mobiContent .= "</body></html>"; isset($args['title']) ? $options['title'] = $args['title'] : ($options['title'] = "No Title"); isset($args['description']) ? $options['subject'] = $args['description'] : ($options['subject'] = "No description"); isset($args['author']) ? $options['author'] = $args['author'] : ($options['author'] = "No author"); isset($args['isbn']) ? $options['uniqueID'] = $args['isbn'] : ($options['uniqueID'] = "No isbn"); $mobi->setData($mobiContent); $mobi->setOptions($options); $mobi->save($path); }