/** * Creates a compressed cache file for the chapter * * @author Woxxy * @return url to compressed file */ function compress($comic, $language = 'en', $volume = null, $chapter = null, $subchapter = 0) { require_once FCPATH . 'assets/pclzip/pclzip.lib.php'; $files = array(); if (get_setting('fs_dl_volume_enabled') && $volume !== null && $chapter === null) { if ($volume == 0) { show_404(); } $chapters = new Chapter(); $chapters->where('comic_id', $comic->id)->where('volume', $volume)->order_by('volume', 'asc')->order_by('chapter', 'asc')->order_by('subchapter', 'asc')->get(); if ($chapters->result_count() == 0) { show_404(); } $volume_id = $volume; $chapter_id = $chapters->id; $filepath = $comic->directory(); $filename = $this->filename_chapters_compressed($chapters); foreach ($chapters as $chaptere) { $pages = new Page(); $pages->where('chapter_id', $chaptere->id)->get(); foreach ($pages as $page) { $files[] = array(PCLZIP_ATT_FILE_NAME => 'content/comics/' . $comic->directory() . '/' . $chaptere->directory() . '/' . $page->filename, PCLZIP_ATT_FILE_NEW_FULL_NAME => $this->filename_chapter_compressed($chaptere) . '/' . $page->filename); } } } else { $chaptere = new Chapter(); $chaptere->where('comic_id', $comic->id)->where('language', $language)->where('volume', $volume)->where('chapter', $chapter)->where('subchapter', $subchapter); $chaptere->get(); if ($chaptere->result_count() == 0) { show_404(); } $volume_id = 0; $chapter_id = $chaptere->id; $filepath = $comic->directory() . '/' . $chaptere->directory(); $filename = $this->filename_chapter_compressed($chaptere); $pages = new Page(); $pages->where('chapter_id', $chaptere->id)->get(); foreach ($pages as $page) { $files[] = 'content/comics/' . $comic->directory() . '/' . $chaptere->directory() . '/' . $page->filename; } } $this->where('comic_id', $comic->id)->where('volume_id', $volume_id)->where('chapter_id', $chapter_id)->get(); if ($this->result_count() == 0 || !file_exists('content/comics/' . $filepath . '/' . $this->filename)) { $this->remove_old(); $archive = new PclZip('content/comics/' . $filepath . '/' . $filename . '.zip'); $archive->create($files, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_NO_COMPRESSION); $this->comic_id = $comic->id; $this->volume_id = $volume_id; $this->chapter_id = $chapter_id; $this->filename = $filename . '.zip'; $this->size = filesize('content/comics/' . $filepath . '/' . $filename . '.zip'); $this->lastdownload = date('Y-m-d H:i:s', time()); $this->save(); } else { $this->lastdownload = date('Y-m-d H:i:s', time()); $this->save(); } return array("url" => site_url() . 'content/comics/' . $filepath . '/' . urlencode($this->filename), "server_path" => FCPATH . 'content/comics/' . $filepath . '/' . $this->filename); }
public function download($comic, $language = 'en', $volume = 0, $chapter = "", $subchapter = 0, $team = 0, $joint = 0, $pagetext = 'page', $page = 1) { if(!get_setting('fs_dl_enabled')) show_404(); $comice = new Comic(); $comice->where('stub', $comic)->get(); if ($comice->result_count() == 0) { set_notice('warn', 'This comic doesn\'t exist.'); } if ($chapter == "") { redirect('/reader/comic/' . $comic); } $chaptere = new Chapter(); $chaptere->where('comic_id', $comice->id)->where('language', $language)->where('volume', $volume)->where('chapter', $chapter)->order_by('subchapter', 'ASC'); if (!is_int($subchapter) && $subchapter == 'page') { $current_page = $team; } else { $chaptere->where('subchapter', $subchapter); if ($team == 'page') $current_page = $joint; else { if ($team != 0) { $teame = new Team(); $teame->where('stub', $team)->get(); $chaptere->where('team_id', $teame->id); } if ($joint == 'page') $current_page = $pagetext; if ($joint != 0) { $chaptere->where('joint_id', $joint); } } } if (!isset($current_page)) { if ($page != 1) $current_page = $page; else $current_page = 1; } $chaptere->get(); if ($chaptere->result_count() == 0) { show_404(); } $archive = new Archive(); $url = $archive->compress($chaptere); redirect($url); }
/** * @return string * Get all chapters */ public function getChapters() { $chapters = Chapter::get()->sort('Number'); return $chapters; }
public function read($comic, $language = 'en', $volume = 0, $chapter = "", $subchapter = 0, $team = 0, $joint = 0, $pagetext = 'page', $page = 1) { $comice = new Comic(); $comice->where('stub', $comic)->get(); if ($comice->result_count() == 0) { set_notice('warn', 'This comic doesn\'t exist.'); } if ($chapter == "") { redirect('series/' . $comic); } if (!$this->_check_adult($comice)) { // or this function won't stop return FALSE; } $chaptere = new Chapter(); $chaptere->where('comic_id', $comice->id)->where('language', $language)->where('volume', $volume)->where('chapter', $chapter)->order_by('subchapter', 'ASC'); if (!is_int($subchapter) && $subchapter == 'page') { $current_page = $team; } else { $chaptere->where('subchapter', $subchapter); if ($team == 'page') { $current_page = $joint; } else { if ($team != 0) { $teame = new Team(); $teame->where('stub', $team)->get(); $chaptere->where('team_id', $teame->id); } if ($joint == 'page') { $current_page = $pagetext; } if ($joint != 0) { $chaptere->where('joint_id', $joint); } } } if (!isset($current_page)) { if ($page != 1) { $current_page = $page; } else { $current_page = 1; } } $chaptere->get(); if ($chaptere->result_count() == 0) { show_404(); } $pages = $chaptere->get_pages(); foreach ($pages as $page) { unset($page["object"]); } $next_chapter = $chaptere->next(); if ($current_page > count($pages)) { redirect($next_chapter); } if ($current_page < 1) { $current_page = 1; } $chapters = new Chapter(); $chapters->where('comic_id', $comice->id)->order_by('volume', 'desc')->order_by('chapter', 'desc')->order_by('subchapter', 'desc')->get_bulk(); $comics = new Comic(); $comics->order_by('name', 'ASC')->limit(100)->get(); $this->template->set('is_reader', TRUE); $this->template->set('comic', $comice); $this->template->set('chapter', $chaptere); $this->template->set('chapters', $chapters); $this->template->set('comics', $comics); $this->template->set('current_page', $current_page); $this->template->set('pages', $pages); $this->template->set('next_chapter', $next_chapter); $this->template->title($comice->name, _('Chapter') . ' ' . $chaptere->chapter, get_setting('fs_gen_site_title')); switch ($comice->format) { case 1: $format = 'readtoon'; break; default: $format = 'read'; } $this->template->build($format); }