예제 #1
0
파일: reader.php 프로젝트: Nakei/FoOlSlide
	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);
		}
	}
예제 #2
0
 /**
  * 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);
     }
 }
예제 #3
0
파일: comic.php 프로젝트: Nakei/FoOlSlide
	/**
	 * 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;
	}
예제 #4
0
 function serie($stub = NULL, $chapter_id = "")
 {
     $comic = new Comic();
     $comic->where("stub", $stub)->get();
     if ($comic->result_count() == 0) {
         set_notice('warn', _('Sorry, the series you are looking for does not exist.'));
         $this->manage();
         return false;
     }
     $this->viewdata["function_title"] = '<a href="' . site_url('/admin/series/manage/') . '">' . _('Manage') . '</a>';
     if ($chapter_id == "") {
         $this->viewdata["extra_title"][] = $comic->name;
     }
     $data["comic"] = $comic;
     if ($chapter_id != "") {
         if ($this->input->post()) {
             $chapter = new Chapter();
             $chapter->update_chapter_db($this->input->post());
             $subchapter = is_int($chapter->subchapter) ? $chapter->subchapter : 0;
             set_notice('notice', sprintf(_('Information for Chapter %s has been updated.'), $chapter->chapter . '.' . $subchapter));
         }
         $chapter = new Chapter($chapter_id);
         $data["chapter"] = $chapter;
         $team = new Team();
         $teams = $team->get_teams($chapter->team_id, $chapter->joint_id);
         $table = ormer($chapter);
         $table[] = array(_('Teams'), array('name' => 'team', 'type' => 'input', 'value' => $teams, 'help' => _('Insert the names of the teams who worked on this chapter.')));
         $table = tabler($table);
         $data["table"] = $table;
         $this->viewdata["extra_title"][] = '<a href="' . site_url('admin/series/series/' . $comic->stub) . '">' . $comic->name . '</a>';
         $this->viewdata["extra_title"][] = $chapter->name != "" ? $chapter->name : $chapter->chapter . "." . $chapter->subchapter;
         $data["pages"] = $chapter->get_pages();
         $this->viewdata["main_content_view"] = $this->load->view("admin/series/chapter.php", $data, TRUE);
         $this->load->view("admin/default.php", $this->viewdata);
         return true;
     }
     if ($this->input->post()) {
         // Prepare for stub change in case we have to redirect instead of just printing the view
         $old_comic_stub = $comic->stub;
         $comic->update_comic_db($this->input->post());
         $config['upload_path'] = 'content/cache/';
         $config['allowed_types'] = 'jpg|png|gif';
         $this->load->library('upload', $config);
         $field_name = "thumbnail";
         if (count($_FILES) > 0 && $this->upload->do_upload($field_name)) {
             $up_data = $this->upload->data();
             if (!$this->files_model->comic_thumb($comic, $up_data)) {
                 log_message("error", "Controller: series.php/serie: image failed being added to folder");
             }
             if (!unlink($up_data["full_path"])) {
                 log_message('error', 'series.php/serie: couldn\'t remove cache file ' . $data["full_path"]);
                 return false;
             }
         }
         flash_notice('notice', sprintf(_('Updated series information for %s.'), $comic->name));
         // Did we change the stub of the comic? We need to redirect to the new page then.
         if (isset($old_comic_stub) && $old_comic_stub != $comic->stub) {
             redirect('/admin/series/series/' . $comic->stub);
         }
     }
     $chapters = new Chapter();
     $chapters->where('comic_id', $comic->id)->include_related('team')->order_by('volume', 'DESC')->order_by('chapter', 'DESC')->order_by('subchapter', 'DESC')->get();
     foreach ($chapters->all as $key => $item) {
         if ($item->joint_id > 0) {
             $teams = new Team();
             $jointers = $teams->get_teams(0, $item->joint_id);
             $item->jointers = $jointers;
             unset($jointers);
             unset($teams);
         }
     }
     $data["chapters"] = $chapters;
     if ($comic->get_thumb()) {
         $comic->thumbnail = $comic->get_thumb();
     }
     $table = ormer($comic);
     $licenses = new License();
     $table[] = array(_('Licensed in'), array('name' => 'licensed', 'type' => 'nation', 'value' => $licenses->get_by_comic($comic->id), 'help' => _('Insert the nations where the series is licensed in order to limit the availability.')));
     $table = tabler($table);
     $data['table'] = $table;
     $this->viewdata["main_content_view"] = $this->load->view("admin/series/series.php", $data, TRUE);
     $this->load->view("admin/default.php", $this->viewdata);
 }
예제 #5
0
파일: reader.php 프로젝트: Nakei/FoOlSlide
	public function comic($stub = NULL) {
		if (is_null($stub))
			show_404();
		$comic = new Comic();
		$comic->where('stub', $stub)->get();
		if ($comic->result_count() < 1)
			show_404();

		$chapters = new Chapter();
		$chapters->where('comic_id', $comic->id)->order_by('volume', 'desc')->order_by('chapter', 'desc')->order_by('subchapter', 'desc')->get_bulk();

		$this->template->set('comic', $comic);
		$this->template->set('chapters', $chapters);
		$this->template->title($comic->name);
		$this->template->build('comic');
	}
예제 #6
0
파일: chapter.php 프로젝트: Nakei/FoOlSlide
	/**
	 * 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;
		}
	}
예제 #7
0
 public function series($stub = NULL)
 {
     if (is_null($stub)) {
         show_404();
     }
     $comic = new Comic();
     $comic->where('stub', $stub)->get();
     if ($comic->result_count() < 1) {
         show_404();
     }
     if (!$this->_check_adult($comic)) {
         // or this function won't stop
         return FALSE;
     }
     $chapters = new Chapter();
     $chapters->where('comic_id', $comic->id)->order_by('volume', 'desc')->order_by('chapter', 'desc')->order_by('subchapter', 'desc')->get_bulk();
     $this->template->set('comic', $comic);
     $this->template->set('chapters', $chapters);
     $this->template->title($comic->name, get_setting('fs_gen_site_title'));
     $this->template->build('comic');
 }
예제 #8
0
 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);
         }
     }
 }
예제 #9
0
 /**
  * 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();
 }