/** * Removes the compressed file from the disk and database * * @author Woxxy * @returns bool */ function remove() { $chapter = new Chapter(); $chapter->where('id', $this->chapter_id)->get(); $chapter->get_comic(); unlink("content/comics/" . $chapter->comic->directory() . "/" . $chapter->directory() . "/" . $this->filename); $this->delete(); }
/** * Removes the compressed file from the disk and database * * @author Woxxy * @returns bool */ function remove() { $chapter = new Chapter($this->chapter_id); $chapter->get_comic(); if (file_exists("content/comics/" . $chapter->comic->directory() . "/" . $chapter->directory() . "/" . $this->filename)) { if (!@unlink("content/comics/" . $chapter->comic->directory() . "/" . $chapter->directory() . "/" . $this->filename)) { log_message('error', 'remove: error when trying to unlink() the compressed ZIP'); return FALSE; } } $this->delete(); }
public function saveBook() { $book = Input::get('book'); $chapters = Input::get('chapters'); $bookMdl = Book::find($book['id']); $bookMdl->name = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name']); $bookMdl->urlname = str_replace(' ', '-', iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name'])); $bookMdl->save(); foreach ($chapters as $key => $chapter) { if ($chapter['id']) { $chapMdl = Chapter::find($chapter['id']); } else { $chapMdl = new Chapter(); } if ($chapter['id'] && $chapter['isDeleted']) { $chapMdl->delete(); } else { $chapMdl->book_id = $chapter['book_id']; $chapMdl->title = $chapter['title']; $chapMdl->markerdata = count($chapter['markerdata']) ? json_encode($chapter['markerdata']) : null; $chapMdl->order = $chapter['order']; $chapMdl->save(); if (count($chapter['elements'])) { foreach ($chapter['elements'] as $key => $element) { if ($element['id']) { $elementMdl = Element::find($element['id']); } else { $elementMdl = new Element(); } if ($element['id'] && $element['isDeleted']) { $elementMdl->delete(); } else { $elementMdl->chapter_id = $chapMdl->id ?: $element['chapter_id']; $elementMdl->order = $element['order']; $elementMdl->type = $element['type']; if ($element['type'] == 4 || $element['type'] == 5) { $elementMdl->content = json_encode($element['content']); } else { $elementMdl->content = $element['content']; } $elementMdl->note = $element['note']; $elementMdl->save(); } } } } } echo json_encode(['ok']); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $users = User::all(); $book_count = Book::all()->count(); $chapter_count = Chapter::all()->count(); return View::make('admin.admin_panel', array('pageTitle' => 'Admin Panel', 'users' => $users, 'book_count' => $book_count, 'chapter_count' => $chapter_count)); }
public function get() { $messages = $this->messageController->getMessages($this::MESSAGE_KEY); //contestant take test only one time, so //if !admin && has-result >>> redirect to 'result' //(admin not blocked, need to review test-page) $contestant = Auth::user(); if ($contestant->id != 1 && $contestant->result != "") { return Redirect::to('result'); } //load random-question from database $chapters = Chapter::all(); $random_questions = array(); foreach ($chapters as $chapter) { //each chapter, load random-questions by chapter-rate //then store in $random_questions // if($chapter->rate != 0){//make sure chapter has question // $random_questions[] = $chapter->getQuestions->random($chapter->rate); // } if (count($chapter->getQuestions) > $chapter->rate) { $random_questions[] = $chapter->getQuestions->random($chapter->rate); } } //get timer from test option $test_options = TestOption::all(); $timer = $test_options[0]; return View::make('test-bootstrap', array('random_questions' => $random_questions, 'timer' => $timer, 'messages' => $messages)); }
public function getTopicList() { $currentchapterid = Session::get('chapterid'); $currentchapter = Chapter::find($currentchapterid); $subjectid = $currentchapter->getSubjectID(); $subject = Subject::find($subjectid); return Response::json($subject->getTopics()); }
/** * Generate a link to the post in the category * * @param string base url to use * @param string glue between url params */ function get_chapter_url($blogurl = '', $glue = '&') { if (empty($blogurl)) { $this->get_Blog(); $blogurl = $this->Blog->gen_blogurl(); } $permalink = url_add_tail($blogurl, '/' . $this->main_Chapter->get_url_path()); return $permalink . '#item_' . $this->ID; }
/** * Get blog's category ordering value in case of root categories, parent Chapter subcat ordering otherwise * * @return string parent subcat ordering */ function get_parent_subcat_ordering() { if (empty($this->parent_ID)) { // Return the default blog setting $this->load_Blog(); return $this->Blog->get_setting('category_ordering'); } $this->get_parent_Chapter(); return $this->parent_Chapter->get_subcat_ordering(); }
public function executeAddchapter() { $c = new Criteria(); $c->add(ChapterPeer::NAME, $this->getRequestParameter('chapter')); $exchapter = ChapterPeer::doSelectOne($c); if ($exchapter) { $this->setFlash('notice', 'Chapter could not be added. A chapter with this name already exists.'); } else { $chapter = new Chapter(); $chapter->setName($this->getRequestParameter('chapter')); $chapter->save(); $cr = new Chapterregion(); $cr->setChapterId($chapter->getId()); $cr->setRegionId($this->getRequestParameter('region')); $cr->save(); $this->setFlash('notice', 'Chapter <b>' . $chapter->getName() . '</b> has been created successfully.'); } $this->redirect('admin/chapters'); }
public function refreshAllNumbers($courseId) { $chapters = Chapter::model()->findAllByAttributes(array('courseId' => intval($courseId)), array('order' => 'weight asc')); $count = count($chapters); for ($i = 0; $i < $count; $i++) { //$chapters[$i]->update(array('number'=>$i+1)); $chapters[$i]->number = $i + 1; $chapters[$i]->save(); } }
/** * Create a new category * * This funtion has to handle all needed DB dependencies! * * @param string Category name * @param string Category ID ('NULL' as string(!) for root) * @param integer|NULL Blog ID (will be taken from parent cat, if empty) * @param string Category description * @param boolean Set to true if the new object needs to be added into the ChapterCache after it was created * @param integer Category order */ function cat_create($cat_name, $cat_parent_ID, $cat_blog_ID = NULL, $cat_description = NULL, $add_to_cache = false, $cat_order = NULL) { global $DB; load_class('chapters/model/_chapter.class.php', 'Chapter'); if (!$cat_blog_ID) { if (empty($cat_parent_ID)) { debug_die('cat_create(-) missing parameters (cat_parent_ID)!'); } $ChapterCache =& get_ChapterCache(); $Chapter = $ChapterCache->get_by_ID($cat_parent_ID); $cat_blog_ID = $Chapter->blog_ID; } if ($cat_parent_ID === 'NULL') { // fix old use case $cat_parent_ID = NULL; } $new_Chapter = new Chapter(NULL, $cat_blog_ID); $new_Chapter->set('name', $cat_name); $new_Chapter->set('parent_ID', $cat_parent_ID); if (!empty($cat_description)) { // Set decription $new_Chapter->set('description', $cat_description); } $new_Chapter->set('order', $cat_order); if (!$new_Chapter->dbinsert()) { return 0; } if ($add_to_cache) { // add new Category into the Cache $ChapterCache =& get_ChapterCache(); $ChapterCache->add($new_Chapter); } return $new_Chapter->ID; }
public function getPrev($chid) { $_action = 'show'; $chapter = Chapter::find($chid); $book = Book::find($chapter->book_id); $firstTextElement = Element::where('chapter_id', '=', $chid)->where('type', '!=', '2')->first(); $firstImage = Element::where('chapter_id', '=', $chid)->where('type', '=', '2')->first(); $tmpELement = ['id' => $firstTextElement['id'], 'chapter_id' => $firstTextElement['chapter_id'], 'order' => $firstTextElement['order'], 'type' => $firstTextElement['type'], 'content' => $firstTextElement['content'], 'note' => $firstTextElement['note']]; if ($firstTextElement['type'] == 4 || $firstTextElement['type'] == 5) { $tmpELement['content'] = json_decode($firstTextElement['content'], true); //dd($element['content']); } $prevInfo = ['chapter' => $chapter, 'book' => $book, 'info' => $tmpELement ?: null, 'img' => $firstImage ?: null]; echo json_encode($prevInfo, JSON_NUMERIC_CHECK); }
/** * Generate the permalink for the item. * * Note: Each item has an unique permalink at any given time. * Some admin settings may however change the permalinks for previous items. * Note: This actually only returns the URL, to get a real link, use {@link Item::get_permanent_link()} * * @todo archives modes in clean URL mode * * @param string single, archive, subchap * @param string base url to use * @param string glue between url params */ function get_permanent_url($permalink_type = '', $blogurl = '', $glue = '&') { global $DB, $cacheweekly, $Settings, $posttypes_specialtypes, $posttypes_nopermanentURL, $posttypes_catpermanentURL; $this->get_Blog(); if ($this->Blog->get_setting('front_disp') == 'page' && $this->Blog->get_setting('front_post_ID') == $this->ID) { // This item is used as front specific page on the blog's home $permalink_type = 'none'; } elseif (in_array($this->ityp_ID, $posttypes_specialtypes)) { // This is not an "in stream" post: if (in_array($this->ityp_ID, $posttypes_nopermanentURL)) { // This type of post is not allowed to have a permalink: $permalink_type = 'none'; } elseif (in_array($this->ityp_ID, $posttypes_catpermanentURL)) { // This post has a permanent URL as url to main chapter: $permalink_type = 'cat'; } else { // allowed to have a permalink: // force use of single url: $permalink_type = 'single'; } } elseif (empty($permalink_type)) { // Normal "in stream" post: // Use default from collection settings (may be an "in stream" URL): $permalink_type = $this->Blog->get_setting('permalinks'); } switch ($permalink_type) { case 'archive': return $this->get_archive_url($blogurl, $glue); case 'subchap': return $this->get_chapter_url($blogurl, $glue); case 'none': // This is a silent fallback when we try to permalink to an Item that cannot be addressed directly: // Link to blog home: return $this->Blog->gen_blogurl(); case 'cat': // Link to permanent url of main chapter: $this->get_main_Chapter(); return $this->main_Chapter->get_permanent_url(NULL, $blogurl, 1, NULL, $glue); case 'single': default: return $this->get_single_url(true, $blogurl, $glue); } }
public function post() { //page-navigation $admin_navigation = new AdminNavigation(); if ($admin_navigation->isNavigate()) { return $admin_navigation->goToN(); } //message-notification $messages = array(); if (Input::has('chapter_rate')) { $chapters = Chapter::all(); //get chapter-data, create chapter-rules for validation $chapter_rate_data = array(); $chapter_rate_rules = array(); foreach ($chapters as $chapter) { $max_rate = $chapter->getQuestions->count(); $chapter_rate_data[$chapter->id] = Input::get($chapter->id); $chapter_rate_rules[$chapter->id] = 'integer|max:' . $max_rate; } //validate if chapter-rate <= max_rate $validator = Validator::make($chapter_rate_data, $chapter_rate_rules); if ($validator->fails()) { $validate_messages = $validator->messages()->toArray(); $this->messageController->send($validate_messages, $this::MESSAGE_KEY); return Redirect::back(); } //save chapter-rate to database $i = -1; foreach ($chapters as $chapter) { $chapter->rate = Input::get($chapter->id); $chapter->save(); $messages['chapter_rate[' . ++$i . ']'] = 'chapter-' . $chapter->id . '-chapter_rate:saved'; } //return back, show confirm from database $this->messageController->send($messages, $this::MESSAGE_KEY); return Redirect::back(); } //as a fallback $this->messageController->send($messages, $this::MESSAGE_KEY); return Redirect::to('admin/chapter-rate'); }
/** * @param integer $book_id * @param integer $chap_id * @return Chapter * @throws CHttpException */ protected function loadChapter($book_id, $chap_id) { $book_id = (int) $book_id; $chap_id = (int) $chap_id; /** @var Chapter $chap */ $chap = Chapter::model()->with("book.membership")->findByPk($chap_id); if (!$chap) { throw new CHttpException(404, "Главы не существует. Возможно, она была удалена. <a href='/book/{$book_id}/'>Вернуться к оглавлению перевода</a>."); } if ($chap->book->id != $book_id) { $this->redirect($chap->book->getUrl($chap_id)); } // ac_read для всего перевода. Если нельзя в весь перевод, редиректим в оглавление перевода, пусть контроллер Book объясняет, почему да как. if (!$chap->book->can("read")) { $this->redirect($chap->book->url); } // ac_read для этой главы if (!$chap->can("read")) { $msg = $chap->deniedWhy; $msg .= "<br /><br /><a href='{$chap->book->url}'>Вернуться к оглавлению</a>."; throw new CHttpException(403, $msg); } return $chap; }
<?php define('CURRENT_CHAPTER', 1); include_once '../core/classes.php'; $site_info = new SiteInfo(); $comic = new Comic(); $nav = new Navigation(); $chapter = new Chapter(); $chapters = $chapter->getChapters(); $current_chapter = $chapter->getChapterByNumber(CURRENT_CHAPTER); $hasPageInfo = false; if ($_GET && isset($_GET["page"])) { $pageNum = $_GET["page"]; //$meta_info = $comic->getMetaInfo($pageNum); $current_page = $comic->getPageByNumber($pageNum); date_default_timezone_set("America/Chicago"); $rightnow = date('Y-m-d G:i:s', time()); if ($rightnow > $current_page->post_date) { $hasPageInfo = true; } } else { $current_page = $comic->getPageByNumber(1); } include '../parts/head.php'; ?> <body> <div id="content"> <?php include '../parts/header.php'; include '../parts/page-content.php';
public function postQuestionChange() { //message-notification $messages = array(); //handle navigation $admin_navigation = new AdminNavigation(); if ($admin_navigation->isNavigate()) { return $admin_navigation->goToN(); } //handle chapter-text change //redirect after changed if (Input::has('chapter_change')) { $chapter = Chapter::find(Input::get('chapter_change')); $chapter->text = Input::get('chapter_text'); $chapter->save(); $messages['chapter_change_text'] = 'chapter-' . $chapter->id . ':saved'; $this->messageController->send($messages, $this::MESSAGE_KEY); return Redirect::back(); } //handle delete-question //redirect after deleted, no need to modify other inputs if (Input::has('delete_question')) { $question = Question::find(Input::get('delete_question')); $store_question_id = $question->id; $question->delete(); $messages['delete_question'] = 'question-' . $store_question_id . ':deleted'; $this->messageController->send($messages, $this::MESSAGE_KEY); return Redirect::back(); } //handle change on a question (both this one, and it's options) //redirect after all-changes saved if (Input::has('question_change')) { $question = Question::find(Input::get('question_change')); //question-change, change question-text if (Input::has('question_text')) { $question->text = Input::get('question_text'); $question->save(); $messages['question_change_text'] = 'question-' . $question->id . ':saved'; } //question-change, change question-chapter_id if (Input::has('chapter_id')) { $question->chapter_id = Input::get('chapter_id'); $question->save(); $new_chapter = $question->getChapter; $messages['question_change_chapter_id'] = 'question-' . $question->id . ':now belongs to chapter-' . $new_chapter->id; } //options-change if (Input::has('options')) { $options = Input::get('options'); //save options-change $i = -1; foreach ($options as $option_id => $option_text) { $option = Option::find($option_id); $option->text = $option_text; //reset all option-is_right = 0 //is_right set again with input-is_right checked $option->is_right = 0; $option->save(); $messages['options_change[' . ++$i . ']'] = 'option-' . $option->id . ':saved'; } //modify option-is_right if (Input::has('is_right')) { $option = Option::find(Input::get('is_right')); //this option set is_right = 1 $option->is_right = 1; $option->save(); $messages['options_change_is_right'] = 'option-' . $option->id . '-is_right:saved'; } } //send message-notification $this->messageController->send($messages, $this::MESSAGE_KEY); return Redirect::back(); } //new-question //redirect after create new-one if (Input::has('new_question')) { //save new question $question = new Question(); //delete + auto_increment >>> modify question-id not continuous //manually change question-id $last_question = Question::all()->last(); $question->id = $last_question->id + 1; $question->text = Input::get('question_text'); $question->chapter_id = Input::get('chapter_id'); $question->save(); $question_id = $question->id; $messages['new_question'] = 'question-' . $question->id . ':saved'; //save new options $options_text = Input::get('options'); $created_options = array(); for ($i = 0; $i < 4; $i++) { $option = new Option(); $option->text = $options_text[$i]; $option->question_id = $question_id; $option->is_right = 0; $option->save(); //store in array new-option in $created_options, to add is_right on which $created_options[$i] = $option; $messages['option[' . $i . ']'] = 'option-' . $option->id . ':saved'; } if (Input::has('is_right')) { $right_option = Input::get('is_right'); //get option from store-$created_options, which selected is_right $option = $created_options[$right_option]; $option->is_right = 1; $option->save(); $messages['option_is_right'] = 'option-' . $option->id . '-is_right:saved'; } //send message-notification $this->messageController->send($messages, $this::MESSAGE_KEY); return Redirect::back(); } //as a fallback //send message-notification $this->messageController->send($messages, $this::MESSAGE_KEY); return Redirect::back(); }
<?php class Chapter { public function __construct() { require 'idiorm.php'; ORM::configure('mysql:host=localhost;dbname=etutor'); ORM::configure('username', 'root'); ORM::configure('password', 'pass'); } public function data() { $id = $_GET['id']; $name = ORM::for_table('name')->raw_query("SELECT * FROM lessons x JOIN units y on x.id = y.l_id WHERE y.l_id = " . $id)->find_many(); foreach ($name as $names) { $nam['units'][] = array('cname' => $names->u_name, 'id' => $names->id, 'vpath' => $names->v_url, 'ipath' => $names->v_image, "dur" => $names->v_dur); } echo json_encode($nam); } } $serv = new Chapter(); $serv->data();
/** * Note: This test assumes default Yii::t() fallback behavior * @test */ public function furtherFallbackBehaviorTests() { $books = Book::model()->findAll(); $book = $books[0]; $this->assertEquals(2, count($books)); $fooText = "Lean on me"; Yii::app()->language = Yii::app()->sourceLanguage; $this->assertEquals($fooText, Yii::t('app', $fooText)); Yii::app()->language = 'ch'; $this->assertEquals($fooText, Yii::t('app', $fooText)); $chapter = new Chapter(); $chapter->_book_id = $book->id; $chapter->_title = $fooText; Yii::app()->language = 'en_us'; $this->assertEquals($fooText, $chapter->title); Yii::app()->language = 'de'; $this->assertEquals($fooText, $chapter->title); $saveResult = $chapter->save(); $this->assertTrue($saveResult); $chapters = Chapter::model()->findAll(); $chapter = $chapters[0]; $this->assertEquals(1, count($chapters)); $this->assertEquals($fooText, $chapter->title); $this->assertEquals($fooText, $chapter->title_de); $this->assertEquals($fooText, $chapter->title_ch); Yii::app()->language = 'ch'; $this->assertEquals($book->title_en_us, $book->title_ch); $this->assertEquals($book->title_pt, 'O Diabo Veste Prada'); $this->assertEquals($book->title_sv, 'Djävulen bär Prada'); $this->assertEquals($book->title_en_us, 'The Devil Wears Prada'); $this->assertEquals($book->title_en, 'The Devil Wears Prada'); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroyChapter($id) { $chapter_destroy = Chapter::find($id); if (Sentry::getUser()->id === $chapter_destroy->author_id) { $chapter_destroy->delete(); return Redirect::to('/dashboard')->with('global_success', 'Your chapter was deleted, but you can start new one with forms on your right.'); } else { return Redirect::to('/dashboard')->with('global_error', 'Come on! Why would you delete not your chapter? See "Edit corner" below to browse your own resources.'); } }
public function showTable($opts = false) { global $zdb_action; if (is_array($opts)) { extract($opts); } if (!$view) { $view = $_REQUEST['view']; } if ($this->_gridEdit == true) { $ajax = true; } if (isset($_REQUEST['row'])) { $row = $_REQUEST['row']; $date_range = $this->rowToDateRange($row, $view); $filters['dates'] = " from " . $date_range['date_starting'] . " to " . $date_range['date_ending']; } $limit_chapter = $this->limitChapterSql(); $sql = " SELECT {$this->_table}.* "; $sql .= $limit_chapter['select']; $sql .= " FROM {$this->_table} "; $sql .= $limit_chapter['join']; $sql .= $join; $sql .= " WHERE 1"; $sql .= $limit_chapter['where']; $sql .= $date_range['where']; $sql .= $this->_where; if ($where) { $sql .= $where; } if ($this->_dateField) { $sql .= " ORDER BY {$this->_dateField} DESC "; } $this->_tableSql = $sql; if ($sql_only) { return $sql; } $browse = new browse($sql, array("db" => $this->_db, "rows" => 100)); foreach ($_GET as $f => $v) { $browse->add_var("&{$f}={$v}"); } if (is_object($this->_dbo)) { $rows = $this->_dbo->fetchAll($browse->sql); } else { $rows = $zdb_action->fetchAll($browse->sql); } // Backwards compatibility for GreenpeaceUSA. JB 10/7/08 4:30 PM if (is_array($this->hidefields)) { $hidefields = $this->hidefields; } elseif (is_array($this->_hiddenFields)) { $hidefields = $this->_hiddenFields; } else { $hidefields = array(); } // Activate some graphing variables. $graphf = array(); $data = array(); $i = 0; if (!$this->_tableTitle) { $this->_tableTitle = camelcap($this->_table); } if (is_array($limit_chapter)) { $chapter_id = $limit_chapter[chapter_id]; $chapter_name = Chapter::get_name($chapter_id); $filters[chapter] = " in chapter {$chapter_name} "; } if ($num = count($rows)) { ?> <div>Showing <b><?php echo $num; ?> </b> <?php echo $this->_tableTitle; ?> s <?php if (is_array($limit_chapter)) { ?> for chapter <b><?php echo $chapter_name; ?> </b> <?php } ?> .</div> <?php echo $browse->show_nav_lite(); ?> <table class="list"><?php foreach ($rows as $row) { $i++; $i % 2 ? $row_class = "odd" : ($row_class = "even"); extract($row); if ($i == 1) { // do header row ?> <tr class="reverse"> <td>Action</td> <?php foreach ($row as $f => $v) { if (!in_array($f, $hidefields)) { ?> <td><?php echo camelcap($f); ?> </td> <?php } } ?> </tr> <?php } if ($ajax) { if (is_array($this->_idField)) { $ajax = false; } else { $this->loadRecord($row[$this->_idField]); } } ?> <tr class="<?php echo $row_class; ?> "> <td nowrap> <?php $this->adminActionCell($row); ?> </td> <?php foreach ($row as $f => $v) { if (!in_array($f, $hidefields)) { // Deal with fields that have relationships defined to other tables via phpmyadmin. if ($related = $this->tbl[$f][rel]) { $obj = DBOS::factory($this->tbl[$f][rel][foreign_table], $v); if (is_object($obj)) { $v = $obj->summary_link(); } } if ($f == $graphf[0]) { $data[$i - 1][label] = $v; } if ($f == $graphf[1]) { $data[$i - 1][point] = $v; } ?> <td> <?php if (!$ajax || $related || $this->tbl[$f][type] == "timestamp") { ?> <?php echo $v; ?> <?php } else { $ajaxable = $this->ajaxField($f, array("raw" => true, "gridedit" => true)); if ($ajaxable === false) { echo $v; } } ?> </td> <?php } ?> <?php } ?> </tr> <?php } ?> </table> <center><?php $browse->show_nav(); ?> </center> <?php if (count($data)) { $g = new ACGraph($data); $g->render(); } } else { ?> <p id="noRecordsFound"><?php if ($this->_noRecordsMessage) { echo $this->_noRecordsMessage; } else { ?> No records found in <?php echo $this->_tableTitle; ?> table <?php } ?> </p><?php } if (is_array($filters)) { ?> <br /> for filters:<br /><?php echo implode(",<br />", $filters); } ?> <div class="table_debug_info" style="display:none;"><?php da($sql); ?> </div><?php }
public function loadModel($id) { $model = Chapter::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function refreshAllChapterIds($courseId) { $lessons = Lesson::model()->findAllByAttributes(array('courseId' => intval($courseId)), array('order' => 'weight asc')); foreach ($lessons as $lesson) { $criteria = new CDbCriteria(); $criteria->select = "id"; $criteria->condition = "courseId=:courseId and weight<:weight"; $criteria->params = array(':courseId' => $courseId, ':weight' => $lesson->weight); $criteria->order = "weight desc"; $criteria->limit = 1; $chapter = Chapter::model()->find($criteria); if ($chapter) { $lesson->chapterId = $chapter->id; } else { $lesson->chapterId = 0; } $lesson->save(); } }
/** * wp.newCategory * * @see http://codex.wordpress.org/XML-RPC_wp#wp.newCategory * * @param xmlrpcmsg XML-RPC Message * 0 blogid (int): Unique identifier of the blog. * 1 username (string): User login. * 2 password (string): Password for said username. * 3 params (struct): * - name (string) * - slug (string) * - parent_id (int) * - description (string) */ function wp_newcategory($m) { global $DB; // CHECK LOGIN: /** * @var User */ if (!($current_User =& xmlrpcs_login($m, 1, 2))) { // Login failed, return (last) error: return xmlrpcs_resperror(); } // GET BLOG: /** * @var Blog */ if (!($Blog =& xmlrpcs_get_Blog($m, 0))) { // Login failed, return (last) error: return xmlrpcs_resperror(); } if (!$current_User->check_perm('blog_cats', '', false, $Blog->ID)) { return xmlrpcs_resperror(5, 'You are not allowed to add or edit categories in this blog.'); } $xcontent = $m->getParam(3); $contentstruct = xmlrpc_decode_recurse($xcontent); $slug = strtolower($contentstruct['name']); if (!empty($contentstruct['slug'])) { $slug = $contentstruct['slug']; } load_class('chapters/model/_chapter.class.php', 'Chapter'); $new_Chapter = new Chapter(NULL, $Blog->ID); $new_Chapter->set('name', $contentstruct['name']); $new_Chapter->set('urlname', $slug); $new_Chapter->set('parent_ID', intval($contentstruct['parent_id'])); if (!empty($contentstruct['description'])) { // Set decription $new_Chapter->set('description', $contentstruct['description']); } $cat_ID = $new_Chapter->dbinsert(); logIO('OK.'); return new xmlrpcresp(new xmlrpcval($cat_ID, 'int')); }
/** * Removes the comic from the database, but before it removes all the * related chapters and their pages from the database (not the files). * * @author Woxxy * @return object a copy of the comic that has been deleted */ public function remove_comic_db() { // Get all its chapters $chapters = new Chapter(); $chapters->where("comic_id", $this->id)->get_iterated(); // Remove all the chapters from the database. This will also remove all the pages foreach ($chapters as $chapter) { $chapter->remove_chapter_db(); } // We need a clone if we want to keep the variables after deletion $temp = $this->get_clone(); $success = $this->delete(); if (!$success) { set_notice('error', _('The comic couldn\'t be removed from the database for unknown reasons.')); log_message('error', 'remove_comic_db: id found but entry not removed'); return false; } // Return the comic clone return $temp; }
/** * Import WordPress data from XML file into b2evolution database */ function wpxml_import() { global $DB, $tableprefix; // Load classes: load_class('regional/model/_country.class.php', 'Country'); load_class('regional/model/_region.class.php', 'Region'); load_class('regional/model/_subregion.class.php', 'Subregion'); load_class('regional/model/_city.class.php', 'City'); // Set Blog from request blog ID $wp_blog_ID = param('wp_blog_ID', 'integer', 0); $BlogCache =& get_BlogCache(); $wp_Blog =& $BlogCache->get_by_ID($wp_blog_ID); // The import type ( replace | append ) $import_type = param('import_type', 'string', 'replace'); // Get XML file from request $xml_file = $_FILES['wp_file']; // Parse WordPress XML file into array $xml_data = wpxml_parser($xml_file['tmp_name']); $DB->begin(); if ($import_type == 'replace') { // Remove data from selected blog // Get existing categories $SQL = new SQL(); $SQL->SELECT('cat_ID'); $SQL->FROM('T_categories'); $SQL->WHERE('cat_blog_ID = ' . $DB->quote($wp_blog_ID)); $old_categories = $DB->get_col($SQL->get()); if (!empty($old_categories)) { // Get existing posts $SQL = new SQL(); $SQL->SELECT('post_ID'); $SQL->FROM('T_items__item'); $SQL->WHERE('post_main_cat_ID IN ( ' . implode(', ', $old_categories) . ' )'); $old_posts = $DB->get_col($SQL->get()); } echo T_('Removing the comments... '); evo_flush(); if (!empty($old_posts)) { $SQL = new SQL(); $SQL->SELECT('comment_ID'); $SQL->FROM('T_comments'); $SQL->WHERE('comment_post_ID IN ( ' . implode(', ', $old_posts) . ' )'); $old_comments = $DB->get_col($SQL->get()); $DB->query('DELETE FROM T_comments WHERE comment_post_ID IN ( ' . implode(', ', $old_posts) . ' )'); if (!empty($old_comments)) { $DB->query('DELETE FROM T_comments__votes WHERE cmvt_cmt_ID IN ( ' . implode(', ', $old_comments) . ' )'); } } echo T_('OK') . '<br />'; echo T_('Removing the posts... '); evo_flush(); if (!empty($old_categories)) { $DB->query('DELETE FROM T_items__item WHERE post_main_cat_ID IN ( ' . implode(', ', $old_categories) . ' )'); if (!empty($old_posts)) { // Remove the post's data from related tables $DB->query('DELETE FROM T_items__item_settings WHERE iset_item_ID IN ( ' . implode(', ', $old_posts) . ' )'); $DB->query('DELETE FROM T_items__prerendering WHERE itpr_itm_ID IN ( ' . implode(', ', $old_posts) . ' )'); $DB->query('DELETE FROM T_items__subscriptions WHERE isub_item_ID IN ( ' . implode(', ', $old_posts) . ' )'); $DB->query('DELETE FROM T_items__version WHERE iver_itm_ID IN ( ' . implode(', ', $old_posts) . ' )'); $DB->query('DELETE FROM T_postcats WHERE postcat_post_ID IN ( ' . implode(', ', $old_posts) . ' )'); $DB->query('DELETE FROM T_slug WHERE slug_itm_ID IN ( ' . implode(', ', $old_posts) . ' )'); } } echo T_('OK') . '<br />'; echo T_('Removing the categories... '); evo_flush(); $DB->query('DELETE FROM T_categories WHERE cat_blog_ID = ' . $DB->quote($wp_blog_ID)); echo T_('OK') . '<br />'; echo T_('Removing the tags that are no longer used... '); evo_flush(); if (!empty($old_posts)) { // Remove the tags // Get tags from selected blog $SQL = new SQL(); $SQL->SELECT('itag_tag_ID'); $SQL->FROM('T_items__itemtag'); $SQL->WHERE('itag_itm_ID IN ( ' . implode(', ', $old_posts) . ' )'); $old_tags_this_blog = array_unique($DB->get_col($SQL->get())); if (!empty($old_tags_this_blog)) { // Get tags from other blogs $SQL = new SQL(); $SQL->SELECT('itag_tag_ID'); $SQL->FROM('T_items__itemtag'); $SQL->WHERE('itag_itm_ID NOT IN ( ' . implode(', ', $old_posts) . ' )'); $old_tags_other_blogs = array_unique($DB->get_col($SQL->get())); $old_tags_other_blogs_sql = !empty($old_tags_other_blogs) ? ' AND tag_ID NOT IN ( ' . implode(', ', $old_tags_other_blogs) . ' )' : ''; // Remove the tags that are no longer used $DB->query('DELETE FROM T_items__tag WHERE tag_ID IN ( ' . implode(', ', $old_tags_this_blog) . ' )' . $old_tags_other_blogs_sql); } // Remove the links of tags with posts $DB->query('DELETE FROM T_items__itemtag WHERE itag_itm_ID IN ( ' . implode(', ', $old_posts) . ' )'); } echo T_('OK') . '<br /><br />'; } /* Import authors */ $authors = array(); $authors_IDs = array(); if (isset($xml_data['authors']) && count($xml_data['authors']) > 0) { global $Settings, $UserSettings; echo T_('Importing the users... '); evo_flush(); // Get existing users $SQL = new SQL(); $SQL->SELECT('user_login, user_ID'); $SQL->FROM('T_users'); $existing_users = $DB->get_assoc($SQL->get()); $authors_count = 0; foreach ($xml_data['authors'] as $author) { if (empty($existing_users[(string) $author['author_login']])) { // Insert new user into DB if User doesn't exist with current login name $GroupCache =& get_GroupCache(); if (!empty($author['author_group'])) { // Set user group from xml data if (($UserGroup =& $GroupCache->get_by_name($author['author_group'], false)) === false) { // If user's group doesn't exist yet, we should create new $UserGroup = new Group(); $UserGroup->set('name', $author['author_group']); $UserGroup->dbinsert(); } } else { // Set default user group is it is not defined in xml if (($UserGroup =& $GroupCache->get_by_name('Normal Users', false)) === false) { // Exit from import of users, because we cannot set default user group break; } } unset($author_created_from_country); if (!empty($author['author_created_from_country'])) { // Get country ID from DB by code $CountryCache =& get_CountryCache(); if (($Country =& $CountryCache->get_by_name($author['author_created_from_country'], false)) !== false) { $author_created_from_country = $Country->ID; } } // Get regional IDs by their names $author_regions = wp_get_regional_data($author['author_country'], $author['author_region'], $author['author_subregion'], $author['author_city']); $User = new User(); $User->set('login', $author['author_login']); $User->set('email', $author['author_email']); $User->set('firstname', $author['author_first_name']); $User->set('lastname', $author['author_last_name']); $User->set('pass', $author['author_pass']); $User->set_Group($UserGroup); $User->set('status', !empty($author['author_status']) ? $author['author_status'] : 'autoactivated'); $User->set('nickname', $author['author_nickname']); $User->set('url', $author['author_url']); $User->set('level', $author['author_level']); $User->set('locale', $author['author_locale']); $User->set('gender', $author['author_gender'] == 'female' ? 'F' : ($author['author_gender'] == 'male' ? 'M' : '')); if ($author['author_age_min'] > 0) { $User->set('age_min', $author['author_age_min']); } if ($author['author_age_max'] > 0) { $User->set('age_max', $author['author_age_max']); } if (isset($author_created_from_country)) { // User was created from this country $User->set('reg_ctry_ID', $author_created_from_country); } if (!empty($author_regions['country'])) { // Country $User->set('ctry_ID', $author_regions['country']); if (!empty($author_regions['region'])) { // Region $User->set('rgn_ID', $author_regions['region']); if (!empty($author_regions['subregion'])) { // Subregion $User->set('subrg_ID', $author_regions['subregion']); } if (!empty($author_regions['city'])) { // City $User->set('city_ID', $author_regions['city']); } } } $User->set('source', $author['author_source']); $User->set_datecreated($author['author_created_ts'], true); $User->set('lastseen_ts', $author['author_lastseen_ts']); $User->set('profileupdate_date', $author['author_profileupdate_date']); $User->dbinsert(); $user_ID = $User->ID; if (!empty($user_ID) && !empty($author['author_created_fromIPv4'])) { $UserSettings->set('created_fromIPv4', ip2int($author['author_created_fromIPv4']), $user_ID); } $authors_count++; } else { // Get ID of existing user $user_ID = $existing_users[(string) $author['author_login']]; } // Save user ID of current author $authors[$author['author_login']] = (string) $user_ID; $authors_IDs[$author['author_id']] = (string) $user_ID; } $UserSettings->dbupdate(); echo sprintf(T_('%d records'), $authors_count) . '<br />'; } /* Import categories */ $category_default = 0; // Get existing categories $SQL = new SQL(); $SQL->SELECT('cat_urlname, cat_ID'); $SQL->FROM('T_categories'); $SQL->WHERE('cat_blog_ID = ' . $DB->quote($wp_blog_ID)); $categories = $DB->get_assoc($SQL->get()); if (isset($xml_data['categories']) && count($xml_data['categories']) > 0) { echo T_('Importing the categories... '); evo_flush(); load_class('chapters/model/_chapter.class.php', 'Chapter'); load_funcs('locales/_charset.funcs.php'); $categories_count = 0; foreach ($xml_data['categories'] as $cat) { if (empty($categories[(string) $cat['category_nicename']])) { $Chapter = new Chapter(NULL, $wp_blog_ID); $Chapter->set('name', $cat['cat_name']); $Chapter->set('urlname', $cat['category_nicename']); $Chapter->set('description', $cat['category_description']); if (!empty($cat['category_parent']) && isset($categories[(string) $cat['category_parent']])) { // Set category parent ID $Chapter->set('parent_ID', $categories[(string) $cat['category_parent']]); } $Chapter->dbinsert(); // Save new category $categories[$cat['category_nicename']] = $Chapter->ID; if (empty($category_default)) { // Set first category as default $category_default = $Chapter->ID; } $categories_count++; } } if (empty($category_default)) { // Set first category as default foreach ($categories as $category_name => $category_ID) { $category_default = $category_ID; break; } } echo sprintf(T_('%d records'), $categories_count) . '<br />'; } /* Import tags */ $tags = array(); if (isset($xml_data['tags']) && count($xml_data['tags']) > 0) { echo T_('Importing the tags... '); evo_flush(); // Get existing tags $SQL = new SQL(); $SQL->SELECT('tag_name, tag_ID'); $SQL->FROM('T_items__tag'); $tags = $DB->get_assoc($SQL->get()); $tags_count = 0; foreach ($xml_data['tags'] as $tag) { if (empty($tags[(string) $tag['tag_name']])) { // Insert new tag into DB if tag doesn't exist with current name mysql_query('INSERT INTO ' . $tableprefix . 'items__tag ( tag_name ) VALUES ( ' . $DB->quote($tag['tag_name']) . ' )', $DB->dbhandle); $tag_ID = mysql_insert_id($DB->dbhandle); // Save new tag $tags[$tag['tag_name']] = (string) $tag_ID; $tags_count++; } } echo sprintf(T_('%d records'), $tags_count) . '<br />'; } /* Import posts */ $posts = array(); $comments = array(); if (isset($xml_data['posts']) && count($xml_data['posts']) > 0) { load_class('items/model/_item.class.php', 'Item'); // Set status's links between WP and b2evo names $post_statuses = array('publish' => 'published', 'pending' => 'deprecated', 'deprecated' => 'deprecated', 'protected' => 'protected', 'private' => 'private', 'redirected' => 'redirected', 'draft' => 'draft'); // Get post types $SQL = new SQL(); $SQL->SELECT('LOWER( ptyp_name ), ptyp_ID'); $SQL->FROM('T_items__type'); $post_types = $DB->get_assoc($SQL->get()); echo T_('Importing the posts... '); evo_flush(); foreach ($xml_data['posts'] as $post) { $author_ID = isset($authors[(string) $post['post_author']]) ? $authors[(string) $post['post_author']] : 1; $last_edit_user_ID = isset($authors[(string) $post['post_lastedit_user']]) ? $authors[(string) $post['post_lastedit_user']] : $author_ID; $post_main_cat_ID = $category_default; $post_extra_cat_IDs = array($post_main_cat_ID); $post_tags = array(); if (!empty($post['terms'])) { // Set categories and tags foreach ($post['terms'] as $term) { switch ($term['domain']) { case 'category': if (isset($categories[(string) $term['slug']])) { if ($post_main_cat_ID == $category_default) { // Set main category $post_main_cat_ID = $categories[(string) $term['slug']]; } else { // Set extra categories $post_extra_cat_IDs[] = $categories[(string) $term['slug']]; } } break; case 'post_tag': if (isset($tags[(string) $term['slug']])) { // Set tag $post_tags[] = $term['slug']; } break; } } } // Set post type ID $post_type_ID = isset($post_types[strtolower($post['post_type'])]) ? $post_types[strtolower($post['post_type'])] : '1'; // Get regional IDs by their names $item_regions = wp_get_regional_data($post['post_country'], $post['post_region'], $post['post_subregion'], $post['post_city']); $Item = new Item(); $Item->set('main_cat_ID', $post_main_cat_ID); $Item->set('creator_user_ID', $author_ID); $Item->set('lastedit_user_ID', $last_edit_user_ID); $Item->set('title', $post['post_title']); $Item->set('content', $post['post_content']); $Item->set('excerpt', $post['post_excerpt']); $Item->set('datestart', $post['post_date']); $Item->set('datecreated', !empty($post['post_datecreated']) ? $post['post_datecreated'] : $post['post_date']); $Item->set('datemodified', !empty($post['post_datemodified']) ? $post['post_datemodified'] : $post['post_date']); $Item->set('urltitle', !empty($post['post_urltitle']) ? $post['post_urltitle'] : $post['post_title']); $Item->set('status', isset($post_statuses[(string) $post['status']]) ? $post_statuses[(string) $post['status']] : 'draft'); $Item->set('comment_status', $post['comment_status'] == 'open' ? 'open' : 'closed'); $Item->set('ptyp_ID', $post_type_ID); if (empty($post['post_excerpt']) && !empty($post['post_content'])) { // Generate excerpt $Item->set('excerpt', wp_generate_excerpt($post['post_content'])); $Item->set('excerpt_autogenerated', '1'); } $Item->set('extra_cat_IDs', $post_extra_cat_IDs); $Item->set('dateset', $post['post_date_mode'] == 'set' ? 1 : 0); if (isset($authors[(string) $post['post_assigned_user']])) { $Item->set('assigned_user', $authors[(string) $post['post_assigned_user']]); } $Item->set('datedeadline', $post['post_datedeadline']); $Item->set('locale', $post['post_locale']); $Item->set('excerpt_autogenerated', $post['post_excerpt_autogenerated']); $Item->set('titletag', $post['post_titletag']); $Item->set('notifications_status', $post['post_notifications_status']); $Item->set('views', $post['post_views']); $Item->set('renderers', array($post['post_renderers'])); $Item->set('priority', $post['post_priority']); $Item->set('featured', $post['post_featured']); $Item->set('order', $post['post_order']); if (!empty($item_regions['country'])) { // Country $Item->set('ctry_ID', $item_regions['country']); if (!empty($item_regions['region'])) { // Region $Item->set('rgn_ID', $item_regions['region']); if (!empty($item_regions['subregion'])) { // Subregion $Item->set('subrg_ID', $item_regions['subregion']); } if (!empty($item_regions['city'])) { // City $Item->set('city_ID', $item_regions['city']); } } } if (count($post_tags) > 0) { $Item->tags = $post_tags; } $Item->dbinsert(); $posts[$post['post_id']] = $Item->ID; if (!empty($post['comments'])) { // Set comments $comments[$Item->ID] = $post['comments']; } } foreach ($xml_data['posts'] as $post) { // Set post parents if (!empty($post['post_parent']) && isset($posts[(string) $post['post_parent']])) { mysql_query('UPDATE ' . $tableprefix . 'items__item SET post_parent_ID = ' . $DB->quote($posts[(string) $post['post_parent']]) . ' WHERE post_ID = ' . $DB->quote($posts[(string) $post['post_id']]), $DB->dbhandle); } } echo sprintf(T_('%d records'), count($xml_data['posts'])) . '<br />'; } /* Import comments */ if (!empty($comments)) { echo T_('Importing the comments... '); evo_flush(); $comments_count = 0; $comments_IDs = array(); foreach ($comments as $post_ID => $comments) { if (empty($comments)) { // Skip if no comments continue; } foreach ($comments as $comment) { $comment_author_ID = 0; if (!empty($comment['comment_user_id']) && isset($authors_IDs[(string) $comment['comment_user_id']])) { // Author ID $comment_author_ID = $authors_IDs[(string) $comment['comment_user_id']]; } $comment_parent_ID = 0; if (!empty($comment['comment_parent']) && isset($comments_IDs[(string) $comment['comment_parent']])) { // Parent comment ID $comment_parent_ID = $comments_IDs[(string) $comment['comment_parent']]; } unset($comment_IP_country); if (!empty($comment['comment_IP_country'])) { // Get country ID by code $CountryCache =& get_CountryCache(); if ($Country =& $CountryCache->get_by_name($comment['comment_IP_country'], false)) { $comment_IP_country = $Country->ID; } } $Comment = new Comment(); $Comment->item_ID = $post_ID; $Comment->set('post_ID', $post_ID); if (!empty($comment_parent_ID)) { $Comment->set('in_reply_to_cmt_ID', $comment_parent_ID); } $Comment->set('date', $comment['comment_date']); if (!empty($comment_author_ID)) { $Comment->set('author_ID', $comment_author_ID); } $Comment->set('author', evo_substr($comment['comment_author'], 0, 100)); $Comment->set('author_IP', $comment['comment_author_IP']); $Comment->set('author_email', $comment['comment_author_email']); $Comment->set('content', $comment['comment_content']); if (empty($comment['comment_status'])) { // If comment status is empty (the export of wordpress doesn't provide this field) $Comment->set('status', $comment['comment_approved'] == '1' ? 'published' : 'draft'); } else { // Set status when we have predefined value $Comment->set('status', $comment['comment_status']); } if (!empty($comment_IP_country)) { // Country $Comment->set('IP_ctry_ID', $comment_IP_country); } $Comment->set('rating', $comment['comment_rating']); $Comment->set('featured', $comment['comment_featured']); $Comment->set('nofollow', $comment['comment_nofollow']); $Comment->set('helpful_addvotes', $comment['comment_helpful_addvotes']); $Comment->set('helpful_countvotes', $comment['comment_helpful_countvotes']); $Comment->set('spam_addvotes', $comment['comment_spam_addvotes']); $Comment->set('spam_countvotes', $comment['comment_spam_countvotes']); $Comment->set('karma', $comment['comment_karma']); $Comment->set('spam_karma', $comment['comment_spam_karma']); $Comment->set('allow_msgform', $comment['comment_allow_msgform']); $Comment->set('notif_status', $comment['comment_notif_status']); $Comment->dbinsert(); $comments_IDs[$comment['comment_id']] = $Comment->ID; $comments_count++; } } echo sprintf(T_('%d records'), $comments_count) . '<br />'; } $DB->commit(); }
/** * Handles both creating of new pages in the database and editing old ones. * It determines if it should update or not by checking if $this->id has * been set. It can get the values from both the $data array and direct * variable assignation. Be aware that array > variables. The latter ones * will be overwritten. Particularly, the variables that the user isn't * allowed to set personally are unset and reset with the automated values. * It's quite safe to throw stuff at it. * * If you're overwriting an image, at this point the ID would be alreasy set. * * @author Woxxy * @param array $data contains the minimal data * @return boolean true on success, false on failure */ public function update_page_db($data = array()) { // Check if we're updating or creating a new entry by looking at $data["id"]. // False is returned if the ID was not found. if (isset($data["id"])) { $this->where("id", $data["id"])->get(); if ($chapter->result_count() == 0) { set_notice('error', _('There isn\'t a page in the database related to this ID.')); log_message('error', 'update_page_db: failed to find requested id'); return false; } } else { // let's set the creator name if it's a new entry if (!isset($this->chapter_id)) { set_notice('error', _('There was no selected chapter.')); log_message('error', 'update_page_db: chapter_id was not set'); return false; } // let's also check that the related comic is defined, and exists $chapter = new Chapter($this->chapter_id); if ($chapter->result_count() == 0) { set_notice('error', _('The selected chapter doesn\'t exist.')); log_message('error', 'update_page_db: chapter_id does not exist in comic database'); return false; } $this->creator = $this->logged_id(); } // always set the editor name $this->editor = $this->logged_id(); // Unset sensible variables // Not even admins should touch these, for database stability. // Yeah, basically everything, as this function is fully automated unset($data["creator"]); unset($data["editor"]); unset($data["filename"]); unset($data["mime"]); unset($data["size"]); unset($data["height"]); unset($data["width"]); // Loop over the array and assign values to the variables. foreach ($data as $key => $value) { $this->{$key} = $value; } // let's save and give some error check. Push false if fail, true if good. $success = $this->save(); if (!$success) { if (!$this->valid) { set_notice('error', _('Check that you have inputted all the required fields.')); log_message('error', 'update_page_db: failed validation'); } else { set_notice('error', _('Failed to write to database for unknown reasons.')); log_message('error', 'update_page_db: failed to save'); } return false; } else { // Good job! return true; } }
public function remove_team($also_chapters = FALSE) { if ($this->result_count() != 1) { set_notice('error', _('Failed to remove the chapter directory. Please, check file permissions.')); log_message('error', 'remove_team: id not found'); return false; } if ($also_chapters) { $chapters = new Chapter(); $chapters->where("team_id", $this->id)->get(); foreach ($chapters->all as $chapter) { if (!$chapter->remove()) { set_notice('error', _('Failed removing the chapters while removing the team.')); log_message('error', 'remove_team: failed removing chapter'); return false; } } } $joint = new Joint(); if (!$joint->remove_team_from_all($this->id)) { log_message('error', 'remove_team: failed removing traces of team in joints'); return false; } if (!$this->delete()) { set_notice('error', _('Failed to delete the team for unknown reasons.')); log_message('error', 'remove_team: failed removing team'); return false; } return true; }
/** * Optimizes the selected image with optipng, if optipng is even available. * This function overwrites the existing images. Notice that this will be * a quite long-running function, but it will save you so much bandwidth * that it might be worth it. * * @todo complete this function and put it in the loop with some checkbox * @author Woxxy * @return boolean true if success, false if failure. */ public function optipng() { if ($this->mime != 'image/png') return false; $chapter = new Chapter($this->chapter_id); $comic = new Comic($chapter->comic_id); $rel = 'content/comics/"' . $comic->directory() . '/' . $chapter->directory() . '/' . $this->filename; $abs = realpath($rel); $output = array(); exec('optipng -o7 ' . $abs, $output); }
function delete($type, $id = 0) { if (!isAjax()) { $this->output->set_output(_('You can\'t delete chapters from outside the admin panel through this link.')); log_message("error", "Controller: series.php/remove: failed serie removal"); return false; } $id = intval($id); switch ($type) { case "serie": $comic = new Comic(); $comic->where('id', $id)->get(); $title = $comic->name; if (!$comic->remove()) { flash_notice('error', sprintf(_('Failed to delete the series %s.'), $title)); log_message("error", "Controller: series.php/remove: failed serie removal"); $this->output->set_output(json_encode(array('href' => site_url("admin/series/manage")))); return false; } flash_notice('notice', 'The serie ' . $comic->name . ' has been removed'); $this->output->set_output(json_encode(array('href' => site_url("admin/series/manage")))); break; case "chapter": $chapter = new Chapter($id); $title = $chapter->chapter; if (!($comic = $chapter->remove())) { flash_notice('error', sprintf(_('Failed to delete chapter %s.'), $chapter->comic->chapter)); log_message("error", "Controller: series.php/remove: failed chapter removal"); $this->output->set_output(json_encode(array('href' => site_url("admin/series/series/" . $comic->stub)))); return false; } set_notice('notice', 'Chapter deleted.'); $this->output->set_output(json_encode(array('href' => site_url("admin/series/serie/" . $comic->stub)))); break; case "page": $page = new Page($this->input->post('id')); $page->get_chapter(); $page->chapter->get_comic(); if (!($data = $page->remove_page())) { log_message("error", "Controller: series.php/remove: failed page removal"); return false; } $this->output->set_output(json_encode(array('href' => site_url("admin/series/serie/" . $page->chapter->comic->stub . "/" . $page->chapter->id)))); break; case "allpages": $chapter = new Chapter($id); $chapter->get_comic(); if (!$chapter->remove_all_pages()) { log_message("error", "Controller: series.php/remove: failed all pages removal"); return false; } $this->output->set_output(json_encode(array('href' => site_url("admin/series/serie/" . $chapter->comic->stub . "/" . $chapter->id)))); break; } }