Esempio n. 1
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);
     }
 }
Esempio n. 2
0
	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);
		}
	}
Esempio n. 3
0
	/**
	 * 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;
	}
Esempio n. 4
0
 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);
 }
Esempio n. 5
0
	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');
	}
Esempio n. 6
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');
 }
Esempio n. 7
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);
         }
     }
 }