function comic_get() { if (!$this->get('id') || !is_numeric($this->get('id'))) { $this->response(NULL, 400); } $comic = new Comic(); $comic->where('id', $this->get('id'))->limit(1)->get(); if ($comic->result_count() == 1) { $chapters = new Chapter(); $chapters->where('comic_id', $comic->id)->get(); $chapters->get_teams(); $result = array(); $result["comic"] = $comic->to_array(); $result["chapters"] = array(); foreach ($chapters->all as $key => $chapter) { $result['chapters'][$key] = $chapter->to_array(); foreach ($chapter->teams as $team) { $result['chapters'][$key]['teams'][] = $team->to_array(); } } $this->response($result, 200); // 200 being the HTTP response code } else { $this->response(array('error' => _('Comic could not be found')), 404); } }
function jkcomics_display_comic($atts) { $a = shortcode_atts(array('id' => false, 'bar' => 'something else'), $atts); $output = array(); // $comic = new Comic(); if (!$a['id']) { $comic->getMostRecent(); } else { $comic->getByPostId($a['id']); } // $categories = get_terms('comic_types'); // $template = new Template(); $templateResponse = $template->get(__DIR__ . '/templates/comic.php', array('comic' => $comic, 'categories' => $categories)); $output[] = $templateResponse; $output = implode("\n", $output); return $output; }
/** * Returns the comic * * Available filters: id (required) * * @author Woxxy */ function comic_get() { if ($this->get('id')) { //// check that the id is at least a valid number $this->_check_id(); // get the comic $comic = new Comic(); $comic->where('id', $this->get('id'))->limit(1)->get(); } else { if ($this->get('stub')) { // mostly used for load balancer $comic = new Comic(); $comic->where('stub', $this->get('stub')); // back compatibility with version 0.7.6, though stub is already an unique key if ($this->get('uniqid')) { $comic->where('uniqid', $this->get('uniqid')); } $comic->limit(1)->get(); } else { $this->response(array('error' => _('You didn\'t use the necessary parameters')), 404); } } if ($comic->result_count() == 1) { $chapters = new Chapter(); $chapters->where('comic_id', $comic->id)->get(); $chapters->get_teams(); $result = array(); $result["comic"] = $comic->to_array(); // order in the beautiful [comic][chapter][teams][page] $result["chapters"] = array(); foreach ($chapters->all as $key => $chapter) { $result['chapters'][$key]['comic'] = $result["comic"]; $result['chapters'][$key]['chapter'] = $chapter->to_array(); // if it's requested, throw in also the pages (for load balancer) if ($this->get('chapter_stub') == $chapter->stub && $this->get('chapter_uniqid') == $chapter->uniqid) { $pages = new Page(); $pages->where('chapter_id', $chapter->id)->get(); $result["chapters"][$key]["chapter"]["pages"] = $pages->all_to_array(); } // teams is a normal array, can't use $team->all_to_array() foreach ($chapter->teams as $team) { $result['chapters'][$key]['teams'][] = $team->to_array(); } } // all good $this->response($result, 200); // 200 being the HTTP response code } else { // there's no comic with that id $this->response(array('error' => _('Comic could not be found')), 404); } }
/** * 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); }
/** * Handles both creating of new comics 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. * * @author Woxxy * @param array $data contains the minimal data * @return boolean true on success, false on failure */ public function update_comic_db($data = array()) { // Check if we're updating or creating a new comic by looking at $data["id"]. // False is returned if the chapter ID was not found. if (isset($data["id"]) && $data['id'] != '') { $this->where("id", $data["id"])->get(); if ($this->result_count() == 0) { set_notice('error', _('The comic you wanted to edit doesn\'t exist.')); log_message('error', 'update_comic_db: failed to find requested id'); return false; } // Save the stub in a variable in case it gets changed, so we can change folder name $old_stub = $this->stub; $old_name = $this->name; } else { // let's set the creator name if it's a new entry $this->creator = $this->logged_id(); } // always set the editor name $this->editor = $this->logged_id(); // Unset sensible variables unset($data["creator"]); unset($data["editor"]); unset($data["uniqid"]); unset($data["stub"]); // Allow only admins and mods to arbitrarily change the release date $CI = & get_instance(); if (!$CI->tank_auth->is_allowed()) unset($data["created"]); if (!$CI->tank_auth->is_allowed()) unset($data["edited"]); // Loop over the array and assign values to the variables. foreach ($data as $key => $value) { $this->$key = $value; } // Double check that we have all the necessary automated variables if (!isset($this->uniqid)) $this->uniqid = uniqid(); if (!isset($this->stub)) $this->stub = $this->stub(); // Create a new stub if the name has changed if(isset($old_name) && isset($old_stub) && ($old_name != $this->name)) { // Prepare a new stub. $this->stub = $this->name; // stub() is also able to restub the $this->stub. Already stubbed values won't change. $this->stub = $this->stub(); } // Make so there's no intersecting stubs, and make a stub with a number in case of duplicates // In case this chapter already has a stub and it wasn't changed, don't change it! if ((!isset($this->id) || $this->id == '') || (isset($old_stub) && $old_stub != $this->stub)) { $i = 1; $found = FALSE; $comic = new Comic(); $comic->where('stub', $this->stub)->get(); if ($comic->result_count() == 0) { $found = TRUE; } while (!$found) { $i++; $pre_stub = $this->stub . '_' . $i; $comic = new Comic(); $comic->where('stub', $pre_stub)->get(); if ($comic->result_count() == 0) { $this->stub = $pre_stub; $found = TRUE; } } } // This is necessary to make the checkbox work. /** * @todo make the checkbox work consistently across the whole framework */ if (!isset($data['hidden']) || $data['hidden'] != 1) $this->hidden = 0; // rename the folder if the stub changed if (isset($old_stub) && $old_stub != $this->stub && is_dir("content/comics/" . $old_stub . "_" . $this->uniqid)) { $dir_old = "content/comics/" . $old_stub . "_" . $this->uniqid; $dir_new = "content/comics/" . $this->stub . "_" . $this->uniqid; rename($dir_old, $dir_new); } // 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_comic_db: failed validation'); } else { set_notice('error', _('Failed saving the Comic to database for unknown reasons.')); log_message('error', 'update_comic_db: failed to save'); } return false; } if (!isset($data['licensed'])) { $data['licensed'] = array(); } $license = new License(); $license->update($this->id, $data['licensed']); // Good job! return true; }
<?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';
<?php define('CURRENT_CHAPTER', 2); include_once 'core/classes.php'; $site_info = new SiteInfo(); $comic = new Comic(); $nav = new Navigation(); $chapter = new Chapter(); $hasPageInfo = false; $lastPage = $nav->getLastPage(); $current_chapter = $chapter->getChapterByNumber(CURRENT_CHAPTER); $chapters = $chapter->getChapters(); $current_page = $comic->getPageByNumber($lastPage['number']); include 'parts/head.php'; ?> <body> <div id="content"> <?php include 'parts/header.php'; ?> <main> <h2>Contact</h2> <p>If you have any questions or comments about Relativity or my work in general, please email bk at relativitycomic.com</p> <h3>Follow Relativity on:</h3> <ul class="social"> <li><a href="https://twitter.com/RelativityComic" target="_blank">twitter</a></li> <li><a href="http://relativitycomic.tumblr.com/" target="_blank">tumblr</a></li> <li><a href="https://www.facebook.com/relativitywebcomic" target="_blank">facebook</a></li> <li><a href="http://relativitycomic.com/rss.xml" target="_blank">rss</a></li>
function import($stub) { if (!$this->tank_auth->is_admin()) { show_404(); } if (!$stub) { show_404(); } $comic = new Comic(); $comic->where('stub', $stub)->get(); $data['comic'] = $comic; $this->viewdata["extra_title"][] = $comic->name; $archive[] = array(_("Absolute directory path to ZIP archive for the series") . ' ' . $comic->name, array('type' => 'input', 'name' => 'directory', 'help' => sprintf(_('Insert the absolute directory path. This means from the lowest accessible directory. Example: %s'), '/var/www/backup/' . $comic->stub))); $data['archive'] = tabler($archive, FALSE, TRUE, TRUE); $this->viewdata["function_title"] = _("Import"); if ($this->input->post('directory')) { $data['directory'] = $this->input->post('directory'); if (!is_dir($data['directory'])) { set_notice('error', _('The directory you set does not exist.')); $this->viewdata["main_content_view"] = $this->load->view("admin/series/import", $data, TRUE); $this->load->view("admin/default.php", $this->viewdata); return FALSE; } $data['archives'] = $this->files_model->import_list($data); $this->viewdata["main_content_view"] = $this->load->view("admin/series/import_compressed_list", $data, TRUE); $this->load->view("admin/default.php", $this->viewdata); return TRUE; } if ($this->input->post('action') == 'execute') { $result = $this->files_model->import_compressed(); if (isset($result['error']) && !$result['error']) { $this->output->set_output(json_encode($result)); return FALSE; } else { $this->output->set_output(json_encode($result)); return true; } } $this->viewdata["main_content_view"] = $this->load->view("admin/series/import", $data, TRUE); $this->load->view("admin/default.php", $this->viewdata); }
public function search() { if (!$this->input->post('search')) { $this->template->title(_('Search')); $this->template->build('search_pre'); return TRUE; } $search = HTMLpurify($this->input->post('search'), 'unallowed'); $this->template->title(_('Search')); $comics = new Comic(); $comics->ilike('name', $search)->limit(20)->get(); foreach ($comics->all as $comic) { $comic->latest_chapter = new Chapter(); $comic->latest_chapter->where('comic_id', $comic->id)->order_by('created', 'DESC')->limit(1)->get()->get_teams(); } $this->template->set('search', $search); $this->template->set('comics', $comics); $this->template->build('search'); }
/** * Handles both creating of new chapters 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. * * @author Woxxy * @param array $data contains the minimal data * @return object the comic the chapter derives from. */ public function update_chapter_db($data = array()) { // Check if we're updating or creating a new chapter by looking at $data["id"]. // False is returned if the chapter ID was not found. if (isset($data["id"]) && $data['id'] != "") { $this->where("id", $data["id"])->get(); if ($this->result_count() == 0) { set_notice('error', _('The chapter you tried to edit doesn\'t exist.')); log_message('error', 'update_chapter_db: failed to find requested id'); return false; } // Save the stub in case it gets changed (different chapter number/name etc.) // Stub is always automatized. $old_stub = $this->stub; } else { // if we're here, it means that we're creating a new chapter // Set the creator name if it's a new chapter. if (!isset($this->comic_id)) { set_notice('error', 'You didn\'t select a comic to refer to.'); log_message('error', 'update_chapter_db: comic_id was not set'); return false; } // Check that the related comic is defined, and exists. $comic = new Comic($this->comic_id); if ($comic->result_count() == 0) { set_notice('error', _('The comic you were referring to doesn\'t exist.')); log_message('error', 'update_chapter_db: comic_id does not exist in comic database'); return false; } // Set the creator. This happens only on new chapter creation. $this->creator = $this->logged_id(); } // Always set the editor $this->editor = $this->logged_id(); // Unset the sensible variables. // Not even admins should touch these, for database stability. unset($data["creator"]); unset($data["editor"]); unset($data["uniqid"]); unset($data["stub"]); unset($data["team_id"]); unset($data["joint_id"]); // Loop over the array and assign values to the variables. foreach ($data as $key => $value) { $this->$key = $value; } // Double check that we have all the necessary automated variables if (!isset($this->uniqid)) $this->uniqid = uniqid(); if (!isset($this->stub)) $this->stub = $this->stub(); // This is necessary to make the checkbox work. /** * @todo make the checkbox work consistently across the whole framework */ if (!isset($data['hidden']) || $data['hidden'] != 1) $this->hidden = 0; // Prepare a new stub. $this->stub = $this->chapter . '_' . $this->subchapter . '_' . $this->name; // stub() is also able to restub the $this->stub. Already stubbed values won't change. $this->stub = $this->stub(); // If the new stub is different from the old one (if the chapter was // already existing), rename the folder. if (isset($old_stub) && $old_stub != $this->stub) { $this->get_comic(); $dir_old = "content/comics/" . $this->comic->directory() . "/" . $old_stub . "_" . $this->uniqid; $dir_new = "content/comics/" . $this->comic->directory() . "/" . $this->stub . "_" . $this->uniqid; rename($dir_old, $dir_new); } // $data['team'] must be an array of team NAMES if (isset($data['team'])) { // Remove the empty values in the array of team names. // It happens that the POST contains extra empty values. if (is_array($data['team'])) { foreach ($data['team'] as $key => $value) { if ($value == "") { unset($data['team'][$key]); } } sort($data["team"]); } // In case there's more than a team name in array, get the joint_id. // The joint model is able to create new joints on the fly, do not worry. // Worry rather that the team names must exist. if (count($data['team']) > 1) { // Set team_id to 0 since it's a joint. $this->team_id = 0; $joint = new Joint(); // If the search returns false, something went wrong. // GUI errors are inside the function. if (!$this->joint_id = $joint->add_joint_via_name($data['team'])) { log_message('error', 'update_chapter_db: error with joint_id'); return false; } } // In case there's only one team in the array, find the team. // return false in case one of the names doesn't exist. else if (count($data['team']) == 1) { // Set joint_id to 0 since it's a single team $this->joint_id = 0; $team = new Team(); $team->where("name", $data['team'][0])->get(); if ($team->result_count() == 0) { set_notice('error', _('The team you were referring this chapter to doesn\'t exist.')); log_message('error', 'update_chapter_db: team_id does not exist in team database'); return false; } $this->team_id = $team->id; } else { set_notice('error', _('You must select at least one team for this chapter')); log_message('error', 'update_chapter_db: team_id not defined'); return false; } } else if (!isset($this->team)) { // If we're here it means that this is a new chapter with no teams assigned. // The system doesn't allow chapters without related teams. It must be at // least "anonymous" or a default anonymous team. set_notice('error', _('You haven\'t selected any team in relation to this chapter.')); log_message('error', 'update_chapter_db: team_id does not defined'); return false; } // Save with validation. Push false if fail, true if good. $success = $this->save(); if (!$success) { if (!$this->valid) { log_message('error', $this->error->string); set_notice('error', _('Check that you have inputted all the required fields.')); log_message('error', 'update_chapter_db: failed validation'); } else { set_notice('error', _('Failed to save to database for unknown reasons.')); log_message('error', 'update_chapter_db: failed to save'); } return false; } else { // Here we go! return true; } }
/** * @dataProvider goodIsValidIDs */ public function testIsValid($id) { $a = new Comic(); $a->id = $id; $this->assertTrue($a->is_valid()); }
public function check_external($repair = FALSE, $recursive = FALSE) { $this->load->helper('directory'); // check if all that is inside is writeable if (!$this->check_writable('content/comics/')) { return FALSE; } // check that every folder has a correpsonding comic $map = directory_map('content/comics/', 1); foreach ($map as $key => $item) { // gotta split the directory to get stub and uniqid $item_arr = explode('_', $item); $uniqid = end($item_arr); $stub = str_replace('_' . $uniqid, '', $item); $comic = new Comic(); $comic->where('stub', $stub)->where('uniqid', $uniqid)->get(); if ($comic->result_count() == 0) { $errors[] = 'comic_entry_not_found'; set_notice('warning', _('No database entry found for:') . ' ' . $stub); log_message('debug', 'check: database entry missing for ' . $stub); if ($repair) { if (is_dir('content/comics/' . $item)) { // you have to remove all the files in the folder first delete_files('content/comics/' . $item, TRUE); rmdir('content/comics/' . $item); } else { unlink('content/comics/' . $item); } } } } // check the database entries $comics = new Comic(); $comics->get(); foreach ($comics->all as $key => $comic) { $comic->check($repair); } // if recursive, this will go through a through (and long) check of all chapters if ($recursive) { $chapters = new Chapter(); $chapters->get_iterated(); foreach ($chapters as $chapter) { $chapter->check($repair); } // viceversa, check that all the database entries have a matching file $pages = new Page(); $pages->get_iterated(); foreach ($pages as $page) { $page->check($repair); } } }
<?php /** * Template Name: Upload Page * Description: Uploads an image to a chapter */ ?> <?php get_header(); ?> <?php include_once 'lib/Comic.php'; $comic = Comic::factory(); ?> <script type="text/javascript" src="/wp-content/themes/cb-comics/js/jquery-2.1.4.min.js"></script> <script type="text/javascript" src="/wp-content/themes/cb-comics/js/bootstrap.min.js"></script> <script type="text/javascript" src="/wp-content/themes/cb-comics/js/upload.js"></script> <link rel="stylesheet" href="/wp-content/themes/cb-comics/css/bootstrap.min.css"> <div class="container"> <div class="row"> <h1 class="col-md-8">Chapters</h1> <div class="col-md-4"> <button class="btn btn-link" data-toggle="modal" data-target="#addChapterModal">+ Add chapter</button> </div> </div> <div class="row"> <?php
function tools_check_comics($repair = FALSE) { // basically CSRF protection from repairing if (!$this->input->is_cli_request()) { $repair = FALSE; } if ($this->input->post('repair') == 'repair') { $repair = TRUE; } $recursive = FALSE; if ($this->input->is_cli_request()) { $recursive = TRUE; } $comics = new Comic(); $comics->check_external($repair, $recursive); $warnings = array(); foreach ($this->notices as $notice) { if ($notice['type'] == 'error') { if (!$this->input->is_cli_request()) { $this->output->set_output(json_encode(array('status' => 'error', 'message' => $notice['message']))); } if ($this->input->is_cli_request()) { echo PHP_EOL . _('You have to correct the errors above to continue.') . PHP_EOL; } return FALSE; } if ($notice['type'] == 'warning') { $warnings[] = $notice['message']; } } if (!$recursive) { // if we are here we at most have warning notices // add count to request so we can process chapters one by one $chapters = new Chapter(); $count = $chapters->count(); } if (!$this->input->is_cli_request()) { $this->output->set_output(json_encode(array('status' => count($warnings) > 0 ? 'warning' : 'success', 'messages' => $warnings, 'count' => $count))); } else { echo '#----------DONE----------#' . PHP_EOL; if (!$repair) { echo sprintf(_('To repair automatically by removing the unidentified data and rebuilding the missing thumbnails, enter: %s'), 'php ' . FCPATH . 'index.php admin system tools_check_comics repair') . PHP_EOL; } else { echo _('Successfully repaired your library.') . PHP_EOL; } } }
/** * Grabs the failed tries to get to the comics, and if this Slide is active * as a load balancer, it will fetch data from the master Slide, copy and * serve it. * * @author Woxxy */ public function comics() { // grab the urls $this->comic_dir = $this->uri->segment(3); $this->chapter_dir = $this->uri->segment(4); $this->filename = $this->uri->segment(5); // check that $comic is actually the interesting kind of foldername // get the divider index if (($comic_split = $this->_lastIndexOf($this->comic_dir, '_')) == -1) { show_404(); } // check that $chapter is actually the interesting kind of foldername // get the divider index if (($chapter_split = $this->_lastIndexOf($this->chapter_dir, '_')) == -1) { show_404(); } if (!$this->filename) { show_404(); } // separate stub and uniqid from both folders $this->comic_stub = substr($this->comic_dir, 0, $comic_split); $this->comic_uniqid = substr($this->comic_dir, $comic_split + 1); $this->chapter_stub = substr($this->chapter_dir, 0, $chapter_split); $this->chapter_uniqid = substr($this->chapter_dir, $chapter_split + 1); // flag that forces updating the data for this chapter $this->update = FALSE; // flat that allows us not to send an image, used if we're at least cleaning up $this->give_404 = FALSE; // check that the comic exists in the database $this->comic = new Comic(); $this->comic->where('stub', $this->comic_stub)->where('uniqid', $this->comic_uniqid)->limit(1)->get(); // if there's a result, let's check if there's the chapter available if ($this->comic->result_count() == 1) { // we got the comic! let's see if we got the chapter $this->chapter = new Chapter(); $this->chapter->where('stub', $this->chapter_stub)->where('uniqid', $this->chapter_uniqid)->limit(1)->get(); if ($this->chapter->result_count() == 1) { // we got the chapter! let's see if we're lucky and we already have its page data $this->page = new Page(); $this->page->where('chapter_id', $this->chapter->id)->where('filename', $this->filename)->get(); if ($this->page->result_count() == 1) { // we got its pagedata! let's grab the image if ($this->_grab_page()) { $this->output->set_content_type($this->page->mime)->set_output($this->file); // good end return TRUE; } } } } // we will need the url to the master Slide anyway $this->url = get_setting('fs_balancer_master_url'); // we want it always with a trailing slash if (substr($this->url, -1, 0) != '/') { $this->url = $this->url . '/'; } $this->load->library('curl'); // first of all, does the image even exist? Since we're going to grab // the image anyway if it exists, lets get ahead and grab it first // uri_string starts with a slash, so we have to remove it $this->file = $this->curl->simple_get($this->url . 'content/comics/' . $this->comic_stub . '_' . $this->comic_uniqid . '/' . $this->chapter_stub . '_' . $this->chapter_uniqid . '/' . $this->filename); $this->load->helper('file'); /** * @todo this still doesn't work in chrome at first load, even with echo */ $this->output->set_content_type(get_mime_by_extension($this->filename))->_display($this->file); // if the file doesn't exist, let's not go through the rest of the mess if (!$this->file) { show_404(); } // oh no, this chapter might not be up to date! let's grab the comic data // /api/reader/comic gives us the comic data and all its chapters! // form the get request and decode the result // if the master server works it should be trustable $request_url = $this->url . 'api/reader/comic/stub/' . $this->comic_stub . '/uniqid/' . $this->comic_uniqid . '/chapter_stub/' . $this->chapter_stub . '/chapter_uniqid/' . $this->chapter_uniqid . '/format/json'; $result = $this->curl->simple_get($request_url); $result = json_decode($result, TRUE); // if there's PHP errors in the $result, the json_decode might fail // and return NULL, show a 404. if (is_null($result)) { log_message('error', 'content:comics() json_decode failed'); show_404(); } // just show 404 if the API gives a formal error if (isset($result["error"])) { log_message('error', 'content:comics() json had an error: ' . $result["error"]); show_404(); } // search for the value of the chapter, so we don't bother anymore // if it doesn't exist in database - though it should $found = FALSE; foreach ($result["chapters"] as $key => $item) { if ($item["chapter"]["stub"] == $this->chapter_stub && $item["chapter"]["uniqid"] == $this->chapter_uniqid) { // update the comic in the database $comic = new Comic($result["comic"]["id"]); // the comic array fits just right, an update costs nearly nothing $comic->from_array($result["comic"]); if ($comic->result_count() == 0) { $comic->save_as_new(); } else { $comic->save(); } // remove remainants of deleted or updated chapters // we need an array of chapters $chapter_objects = array(); foreach ($result["chapters"] as $k => $i) { $chapter_objects[] = $i["chapter"]; } $this->_clean_comic($result["comic"]["id"], $chapter_objects); $this->_clean_chapter($item["chapter"]["id"], $item["chapter"]["pages"]); $found = TRUE; break; } } if (!$found) { log_message('error', 'content:comics() chapter was not in the json array'); show_404(); } $this->_grab_page(); }
<div class="comic-container"> <div class="comic-categories-container"> <?php if (!empty($categories)) { ?> <ul class="comic-categories"> <?php foreach ($categories as $category) { ?> <?php $args = array(); $args['orderby'] = 'date'; $args['order'] = 'ASC'; $args['tax_query'] = array(array('taxonomy' => 'comic_types', 'field' => 'slug', 'terms' => $category->slug)); $posts = Comic::getAll($args); $postFirst = $posts[0]; ?> <li><a href="<?php echo $postFirst->url; ?> "><?php echo $category->name; ?> </a></li> <?php } ?> </ul> <?php } ?>