public function storyBlocks($select) { $select = explode(".", $select); if ($select[1] == "stats") { $statsCache = $this->model->blockStats(); foreach ($statsCache as $sC) { $data[$sC['field']] = $sC['value']; } if ($data['newmember'] != "") { $data['newmember'] = explode(",", $data['newmember']); } return \View\Story::archiveStats($data); } elseif ($select[1] == "new") { $items = (isset($select[2]) and is_numeric($select[2])) ? $select[2] : 5; $data = $this->model->blockNewStories($items); $size = isset($select[3]) ? $select[3] : 'large'; return \View\Story::blockStory("new", $data, $size); } elseif ($select[1] == "random") { $items = (isset($select[2]) and is_numeric($select[2])) ? $select[2] : 1; $data = $this->model->blockRandomStory($items); return \View\Story::blockStory("random", $data); } elseif ($select[1] == "featured") { /* $items: 0 = all featured stories $order: "random" or NULL */ $items = (isset($select[2]) and is_numeric($select[2])) ? $select[2] : 1; $order = isset($select[3]) ? $select[3] : FALSE; $data = $this->model->blockFeaturedStory($items, $order); return \View\Story::blockStory("featured", $data); } elseif ($select[1] == "recommend") { // break if module not enabled if (empty(\Config::instance()->modules_enabled['recommendations'])) { return NULL; } /* $items: 0 = all featured stories $order: "random" or NULL */ $items = (isset($select[2]) and is_numeric($select[2])) ? $select[2] : 1; $order = isset($select[3]) ? $select[3] : FALSE; $data = $this->model->blockRecommendedStory($items, $order); return \View\Story::blockStory("recommended", $data); } elseif ($select[1] == "tagcloud") { $items = (isset($select[2]) and is_numeric($select[2])) ? $select[2] : 15; $data = $this->model->blockTagcloud($items); return \View\Story::blockTagcloud($data); } return ""; }
public static function buildStory($storyData, $content, $dropdown) { \Registry::get('VIEW')->javascript('body', TRUE, 'chapter.js'); \Registry::get('VIEW')->javascript('body', FALSE, "var url='" . \Base::instance()->get('BASE') . "/story/read/{$storyData['sid']},'"); $storyData['cache_authors'] = json_decode($storyData['cache_authors'], TRUE); $storyData['published'] = date(\Config::instance()->date_format_short, $storyData['published']); $storyData['modified'] = date(\Config::instance()->date_format_short, $storyData['modified']); $can_edit = $storyData['can_edit'] ? "userCP" : NULL; if (!$can_edit and $_SESSION['groups'] & 64) { $can_edit = "adminCP"; } \Base::instance()->set('data', ["story" => $storyData, "content" => $content, "dropdown" => $dropdown, "can_edit" => $can_edit, "infoblock" => $storyData['chapters'] > 1 ? "" : \View\Story::buildInfoblock($storyData), "feedback_form_label" => "__Review"]); return parent::render('story/single.html'); }
protected function createEPub($id) { $epubSQL = "SELECT \r\n\t\t\tS.sid, S.title, S.storynotes, S.summary, UNIX_TIMESTAMP(S.date) as written, UNIX_TIMESTAMP(S.date) as updated, \r\n\t\t\tGROUP_CONCAT(DISTINCT U.nickname ORDER BY U.nickname ASC SEPARATOR ', ') as authors,\r\n\t\t\tGROUP_CONCAT(DISTINCT T.label ORDER BY T.tgid,T.label ASC SEPARATOR ', ') as tags\r\n\t\t\tFROM `tbl_stories`S\r\n\t\t\t\tINNER JOIN `tbl_stories_authors`rSA ON ( S.sid=rSA.sid ) \r\n\t\t\t\t\tINNER JOIN `tbl_users`U ON (rSA.aid=U.uid)\r\n\t\t\t\tINNER JOIN `tbl_stories_tags`rST ON (S.sid=rST.sid) \r\n\t\t\t\t\tINNER JOIN `tbl_tags`T ON (rST.tid=T.tid)\r\n\t\t\tWHERE S.sid=:sid \r\n\t\t\tGROUP BY S.sid"; $epubData = $this->exec($epubSQL, array(':sid' => $id))[0]; \Base::instance()->set('UI', "template/epub/"); $filename = realpath("tmp/epub") . "/s{$epubData['sid']}.zip"; // Load or create the namespace if ("" == @\Config::instance()->epub_namespace) { $cfg = \Config::instance(); $cfg['epub_namespace'] = uuid_v5("6ba7b810-9dad-11d1-80b4-00c04fd430c8", \Base::instance()->get('HOST') . \Base::instance()->get('BASE')); $cfg->save(); } /* This must be coming from admin panel at some point, right now we will fake it */ $epubData['version'] = 2; // supported by most readers, v3 is still quite new $epubData['language'] = "de"; $epubData['uuid'] = uuid_v5(\Config::instance()->epub_namespace, $epubData['title']); \Base::instance()->set('EPUB', $epubData); $body = ""; $re_element = array("old" => array("<center>", "</center>"), "new" => array("<span style=\"text-align: center;\">", "</span>")); $elements_allowed = "<a><abbr><acronym><applet><b><bdo><big><br><cite><code><del><dfn><em><i><img><ins><kbd><map><ns:svg><q><samp><small><span><strong><sub><sup><tt><var>"; // The folder *should* exist, but creating it and ignoring the outcome is the quickest way of making sure it really is there @mkdir("tmp/epub", 0777, TRUE); /* Create the Archive Since the mimetype file has to be at the beginning of the archive and uncompressed, we have to create the zip file from binary */ file_put_contents($filename, base64_decode("UEsDBAoAAAAAAOmRAT1vYassFAAAABQAAAAIAAAAbWltZXR5cGVhcHBsaWNhdGlvbi9lcHViK3ppcFBLAQIUAAoAAAAAAOmRAT1vYassFAAAABQAAAAIAAAAAAAAAAAAIAAAAAAAAABtaW1ldHlwZVBLBQYAAAAAAQABADYAAAA6AAAAAAA=")); $zip = new \ZipArchive(); $res = $zip->open($filename); if ($res === TRUE) { // memorize the XML opening tag $xml = \View\Story::epubXMLtag(); // add folder for container file & META-INF/container.xml $zip->addEmptyDir('META-INF'); $zip->addFromString('META-INF/container.xml', $xml . \View\Story::epubContainer()); // styles.css $zip->addEmptyDir('Styles'); $zip->addFromString('Styles/styles.css', \View\Story::epubCSS()); // add folder for content $zip->addEmptyDir('content'); // title.xhtml $zip->addFromString('content/title.xhtml', $xml . \View\Story::epubPage(\View\Story::epubTitle(), $epubData['title'], $epubData['language'])); // page[n].xhtml | epub_page $chapters = $this->exec("SELECT C.title, C.inorder\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `tbl_chapters`C\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE C.validated > '0' AND C.sid = :sid\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY C.inorder ASC ", [":sid" => $epubData['sid']]); if (sizeof($chapters) > 0) { $n = 1; foreach ($chapters as $chapter) { $chapterText = $this->getChapter($epubData['sid'], $chapter['inorder'], FALSE); $chapterTOC[] = array("number" => $n, "title" => "{$chapter['title']}"); $body = \View\Story::epubChapter($chapter['title'], strip_tags(str_replace($re_element['old'], $re_element['new'], $chapterText), $elements_allowed)); $zip->addFromString('content/chapter' . $n++ . '.xhtml', $xml . \View\Story::epubPage($body, $chapter['title'], $epubData['language'])); } } else { return "__StoryError"; } // root.opf $zip->addFromString('root.opf', $xml . \View\Story::epubRoot($chapterTOC)); // TOC $zip->addFromString('toc.ncx', $xml . \View\Story::epubTOC($chapterTOC)); if ($epubData['version'] == 3) { $zip->addFromString('toc.xhtml', $xml . \View\Story::epubTOC($chapterTOC, 3)); } $zip->close(); } return [@fopen($filename, "rb"), filesize($filename)]; }