public function install($db_type) { $f3 = \Base::instance(); $db_type = strtoupper($db_type); if ($db = storage::instance()->get($db_type)) { $f3->set('DB', $db); } else { $f3->error(256, 'no valid DB specified'); } // setup the models \Model\Post::setup(); \Model\Tag::setup(); \Model\Comment::setup(); \Model\User::setup(); // create demo admin user $user = new \Model\User(); $user->load(array('username = ?', 'admin')); if ($user->dry()) { $user->username = '******'; $user->name = 'Administrator'; $user->password = '******'; $user->save(); \Flash::instance()->addMessage('Admin User created,' . ' username: admin, password: fabulog', 'success'); } \Flash::instance()->addMessage('Setup complete', 'success'); }
} if (!is_writable('app/data/')) { $preErr[] = sprintf('please make sure that the \'%s\' directory is writable.', 'app/data/'); } if (!is_writable('app/data/config.json')) { $preErr[] = sprintf('please make sure that the \'%s\' file is writable.', 'app/data/config.json'); } if (isset($preErr)) { header('Content-Type: text;'); die(implode("\n", $preErr)); } $f3->config('app/config.ini'); ## DB Setup $cfg = Config::instance(); if ($cfg->ACTIVE_DB) { $f3->set('DB', storage::instance()->get($cfg->ACTIVE_DB)); } else { $f3->error(500, 'Sorry, but there is no active DB setup.'); } $f3->set('CONFIG', $cfg); $f3->set('FLASH', Flash::instance()); \Template::instance()->extend('image', '\\Template\\Tags\\Image::render'); \Template::instance()->extend('pagebrowser', '\\Pagination::renderTag'); // Handles all <form> data \Template\FooForms::init(); ## POSTS // view list $f3->route(array('GET /', 'GET /page/@page'), 'Controller\\Post->getList'); // view single $f3->route(array('GET /@slug', 'GET /post/@id'), 'Controller\\Post->getSingle'); // post comment
public function addChapter($storyID, $post) { $location = \Config::instance()->chapter_data_location; // Get current chapter count and raise if (FALSE == ($chapterCount = @$this->exec("SELECT COUNT(chapid) as chapters FROM `tbl_chapters` WHERE `sid` = :sid ", [":sid" => $storyID])[0]['chapters'])) { return FALSE; } $chapterCount++; $kv = ['title' => $post['chapter_title'], 'inorder' => $chapterCount, 'notes' => $post['chapter_notes'], 'validated' => "1", 'wordcount' => $this->str_word_count_utf8($post['chapter_text']), 'rating' => "0", 'sid' => $storyID]; if ($location != "local") { $kv['chaptertext'] = $post['chapter_text']; } $chapterID = $this->insertArray($this->prefix . 'chapters', $kv); if ($location == "local") { $db = \storage::instance()->localChapterDB(); $chapterAdd = @$db->exec('INSERT INTO "chapters" ("chapid","sid","inorder","chaptertext") VALUES ( :chapid, :sid, :inorder, :chaptertext )', [':chapid' => $chapterID, ':sid' => $storyID, ':inorder' => $chapterCount, ':chaptertext' => $post['chapter_text']]); } $this->rebuildStoryCache($storyID); return $chapterID; }
public function saveChapter($chapterID, $chapterText) { $location = \Config::instance()->chapter_data_location; if ($location == "local") { $db = \storage::instance()->localChapterDB(); $chapterSave = @$db->exec('UPDATE "chapters" SET "chaptertext" = :chaptertext WHERE "chapid" = :chapid', array(':chapid' => $chapterID, ':chaptertext' => $chapterText)); } else { $chapterSave = $this->exec('UPDATE `tbl_chapters` SET `chaptertext` = :chaptertext WHERE `chapid` = :chapid', array(':chapid' => $chapterID, ':chaptertext' => $chapterText)); } return $chapterSave; }