/** * 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(); }
public function compressed_chapter($path, $filename, $chapter_id) { $chapter = new Chapter(); $chapter->where("id", $chapter_id)->get(); $uniqid = uniqid(); if (is_dir($path)) { $this->folder_chapter($path, $chapter); return TRUE; } $cachedir = 'content/cache/' . time() . "_" . $uniqid; if (!mkdir($cachedir)) { log_message('error', 'compressed_chapter: failed creating dir'); return FALSE; } if (function_exists('rar_open') && strtolower(substr($filename, -4)) == '.rar') { $this->uncompress_rar($path, $cachedir); } if (strtolower(substr($filename, -4)) == '.zip') { $this->uncompress_zip($path, $cachedir); } $pages_added = $this->folder_chapter($cachedir, $chapter); // Let's delete all the cache if (!delete_files($cachedir, TRUE)) { log_message('error', 'compressed_chapter: files inside cache dir could not be removed'); return FALSE; } else { if (!rmdir($cachedir)) { log_message('error', 'compressed_chapter: cache dir could not be removed'); return FALSE; } } return $pages_added; }
/** * 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 getRaw($bid) { $_action = 'show'; $_viewtype = 'chapter/show'; $_viewdata = array('env' => $this->_env, 'action' => $_action, 'book_id' => $bid); $chapters = Chapter::where('book_id', '=', $bid)->get(); $formattedChapters = []; foreach ($chapters as $key => $chapter) { $tmpChapter = ['id' => $chapter['id'], 'book_id' => $chapter['book_id'], 'title' => $chapter['title'], 'markerdata' => json_decode($chapter['markerdata'], true), 'order' => $chapter['order']]; $formattedChapters[] = $tmpChapter; } echo json_encode($formattedChapters, JSON_NUMERIC_CHECK); }
public function compressed_chapter($data) { $chapter = new Chapter(); $chapter->where("id", $data["chapter_id"])->get(); $uniqid = uniqid(); $overwrite = ($data["overwrite"] == 1); if(is_dir($data["full_path"])) { $this->folder_chapter($data["full_path"], $chapter, $overwrite); return TRUE; } $cachedir = 'content/cache/' . $data["raw_name"] . "_" . $uniqid; if (!mkdir($cachedir)) { log_message('error', 'compressed_chapter: failed creating dir'); return FALSE; } if(function_exists('rar_open') && strtolower($data["file_ext"]) == '.rar') $this->uncompress_rar($data["full_path"], $cachedir); if (strtolower($data["file_ext"]) == '.zip') $this->uncompress_zip($data["full_path"], $cachedir); $this->folder_chapter($cachedir, $chapter, $overwrite); // Let's delete all the cache if (!delete_files($cachedir, TRUE)) { log_message('error', 'compressed_chapter: files inside cache dir could not be removed'); return FALSE; } else { if (!rmdir($cachedir)) { log_message('error', 'compressed_chapter: cache dir could not be removed'); return FALSE; } } return TRUE; }
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); }
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; }
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'); }
/** * Returns the URL of the reader for the next chapter * * @author Woxxy * @return string the href to the next chapter */ public function next() { // If we've already used this function, it's ready for use, no need to calc it again if (isset($this->next)) return $this->next; // Needs the comic $this->get_comic(); $chapter = new Chapter(); // Check if there are subchapters for this chapter. $chapter->where('comic_id', $this->comic->id)->where('volume', $this->volume)->where('chapter', $this->chapter)->where('language', $this->language)->having('subchapter >', $this->subchapter)->order_by('subchapter', 'asc')->limit(1)->get(); if ($chapter->result_count() == 0) { // There aren't subchapters for this chapter. Then let's look for the next chapter $chapter = new Chapter(); $chapter->where('comic_id', $this->comic->id)->where('volume', $this->volume)->having('chapter > ', $this->chapter)->where('language', $this->language)->order_by('chapter', 'asc')->order_by('subchapter', 'asc')->limit(1)->get(); if ($chapter->result_count() == 0) { // Check if there's a chapter in the next volume. // This works even if chapter goes vol2 33 -> vol3 34 or vol2 33 -> vol3 1 $chapter = new Chapter(); $chapter->where('comic_id', $this->comic->id)->having('volume > ', $this->volume)->where('language', $this->language)->order_by('chapter', 'asc')->order_by('subchapter', 'asc')->limit(1)->get(); if ($chapter->result_count() == 0) { // There's no next chapter. Redirect to the comic page. return site_url('/reader/read/' . $this->comic->stub); } } } // We do have a chapter or more. Get them. $chaptere = new Chapter(); $chaptere->where('comic_id', $this->comic->id)->where('volume', $chapter->volume)->where('chapter', $chapter->chapter)->where('language', $this->language)->where('subchapter', $chapter->subchapter)->get(); $done = false; // Do we have more than a next chapter? Make so it has the same teams on it. if ($chaptere->result_count() > 1) { foreach ($chaptere->all as $chap) { if ($chap->team_id == $this->team_id && $chap->joint_id == $this->joint_id) { $chapter = $chap; $done = true; break; } } // What if the teams changed, and the old teams stopped working on it? Get a different team. // There must be multiple teams on the next chapter for this to happen. Rare but happens. if (!$done) { /** * @todo This is a pretty random way to select the next chapter version, needs refinement. */ $chapter = $chaptere->all['0']; } } // There's only one chapter, simply use it. else { $chapter = $chaptere; } // This is a heavy function. Let's play it smart and cache the value. // Send to the href function that returns a nice URL. $this->next = $chapter->href(); // finally, return the URL. return $this->next; }
/** * When missing chapters are found, this cleans up and adds new chapters * * @param int $comic_id * @param array $new_chapters_array */ public function _clean_comic($comic_id, $new_chapters_array) { // found, let's get all chapters for this comic $chapters = new Chapter(); $chapters->where('comic_id', $comic_id)->get(); $chapters = $chapters->all_to_array(); foreach ($new_chapters_array as $key => $item) { foreach ($chapters as $k => $i) { if ($item["id"] == $i["id"]) { if ($item["stub"] != $i["stub"] || $item["uniqid"] != $i["uniqid"]) { $chapter = new Chapter($item["id"]); $chapter->remove(); unset($chapters[$k]); break; } unset($chapters[$k]); unset($new_chapters_array[$key]); break; } } } foreach ($new_chapters_array as $key => $item) { $chapter = new Chapter(); $chapter->from_array($item); $chapter->save_as_new(); } foreach ($chapters as $key => $item) { $chapter = new Chapter($item["id"]); $chapter->remove(); } }
function joint_get() { if (!$this->get('id') || !is_numeric($this->get('id'))) { $this->response(NULL, 400); } if (!$this->get('page') || !is_numeric($this->get('page')) || $this->get('page') < 1) $page = 1; else $page = (int) $this->get('page'); $page = ($page * 100) - 100; $joint = new Joint(); $joint->where('joint_id', $this->get('id'))->limit(1)->get(); if ($joint->result_count() == 1) { $team = new Team(); $teams = $team->get_teams(0, $this->get('id')); $result = array(); foreach ($teams as $item) { $result['teams'][] = $item->to_array(); } $chapters = new Chapter(); $chapters->where('joint_id', $joint->joint_id); $chapters->limit(100, $page)->get(); $chapters->get_comic(); $result['chapters'] = array(); foreach ($chapters->all as $key => $chapter) { $result['chapters'][$key]['comic'] = $chapter->comic->to_array(); $result['chapters'][$key]['chapter'] = $chapter->to_array(); $result['chapters'][$key]['teams'] = $result['teams']; } $this->response($result, 200); // 200 being the HTTP response code } else { $this->response(array('error' => _('Team could not be found')), 404); } }
/** * Returns chapters per page by joint ID * Also returns the teams * * This is not a method light enough to lookup teams. use api/members/joint for that * * Available filters: id (required), page, per_page (default:30, max:100), orderby * * @author Woxxy */ function joint_get() { // check that the id is at least a valid number $this->_check_id(); // grab by joint_id, id for joints means nothing much $joint = new Joint(); $joint->where('joint_id', $this->get('id'))->limit(1)->get(); if ($joint->result_count() == 1) { // good old get_teams() will give us all Team objects in an array $team = new Team(); $teams = $team->get_teams(0, $this->get('id')); // $teams is a normal array, so we have to do a loop $result = array(); foreach ($teams as $item) { $result['teams'][] = $item->to_array(); } // grab all the chapters from the same joint $chapters = new Chapter(); $chapters->where('joint_id', $joint->joint_id); // apply the limit and orderby filters $this->_orderby($chapters); $this->_page_to_offset($chapters); $chapters->get(); $chapters->get_comic(); // let's put the chapters in a nice [comic][chapter][teams] list $result['chapters'] = array(); foreach ($chapters->all as $key => $chapter) { $result['chapters'][$key]['comic'] = $chapter->comic->to_array(); $result['chapters'][$key]['chapter'] = $chapter->to_array(); $result['chapters'][$key]['teams'] = $result['teams']; } // all good $this->response($result, 200); // 200 being the HTTP response code } else { // nothing for this joint or page $this->response(array('error' => _('Team could not be found')), 404); } }
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'); }
public function check($repair = FALSE, $recursive = FALSE) { $dir = "content/comics/" . $this->directory() . "/"; $errors = array(); if (!is_dir($dir)) { $errors[] = 'comic_directory_not_found'; set_notice('warning', _('No directory found for:') . ' ' . $this->name . ' (' . $this->directory() . ')'); log_message('debug', 'check: comic directory missing at ' . $dir); if ($repair) { // the best we can do is removing the database entry $this->remove_comic_db(); } } else { // check that there are no unidentified files in the comic folder $map = directory_map($dir, 1); foreach ($map as $key => $item) { $item_path = $dir . $item; if (is_dir($item_path)) { // gotta split the directory to get stub and uniqid $item_arr = explode('_', $item); $uniqid = end($item_arr); $stub = str_replace('_' . $uniqid, '', $item); $chapter = new Chapter(); $chapter->where('stub', $stub)->where('uniqid', $uniqid)->get(); if ($chapter->result_count() == 0) { $errors[] = 'comic_unidentified_directory_found'; set_notice('warning', _('Unidentified directory found at:') . ' ' . $item_path); log_message('debug', 'check: unidentified directory found at ' . $item_path); if ($repair) { // you have to remove all the files in the folder first delete_files($item_path, TRUE); rmdir($item_path); } } } else { if ($item != $this->thumbnail && $item != 'thumb_' . $this->thumbnail) { $ext = strtolower(substr($item, -4)); if (in_array($ext, array('.zip'))) { $archive = new Archive(); $archive->where('comic_id', $this->id)->where('filename', $item)->get(); if ($archive->result_count()) { continue; } } // if it's not the thumbnail image, it's an unidentified file $errors[] = 'comic_unidentified_file_found'; set_notice('warning', _('Unidentified file found at:') . ' ' . $item_path); log_message('debug', 'check: unidentified file found at ' . $item_path); if ($repair) { unlink($item_path); } } } } } return $errors; }
public function getNew() { $books = DB::table('books')->orderBy('created', 'desc')->take(8)->get(); $formattedBooks = []; foreach ($books as $key => $book) { $tmpBook = ['id' => $book->id, 'name' => $book->name, 'traveler_id' => $book->traveler_id, 'likes' => $book->likes, 'created' => $book->created]; // search first image of the book $tmpImg = null; $chapters = Chapter::where('book_id', '=', $book->id)->get(); foreach ($chapters as $chapter) { $element = Element::where('chapter_id', '=', $chapter->id)->where('type', '=', '2')->first(); if ($element) { $tmpImg = $element; break; } } if ($tmpImg) { $tmpBook['img'] = $tmpImg; } $formattedBooks[] = $tmpBook; } echo json_encode($formattedBooks, JSON_NUMERIC_CHECK); }
public function showPrivate($sl) { $chapter = Chapter::where('secret_link', '=', $sl)->first(); if ($chapter->public_state == true && Book::where('id', '=', $chapter->book_id)->first()->public_state == true) { return Redirect::to('/chapter/' . $chapter->slug); } $markdownParser = new MarkdownParser(); $markdownText = $markdownParser->transformMarkdown($chapter->text); return View::make('chapter.single', array('chapter' => $chapter, 'chapter_text' => $markdownText, 'pageTitle' => 'Chapter: ' . $chapter->title)); }
/** * 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; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroyBook($id) { $book_destroy = Book::find($id); if (Sentry::getUser()->id == $book_destroy->author_id) { foreach (Chapter::where('book_id', '=', $book_destroy->id)->get() as $chapter) { $chapter->book_id = ''; $chapter->save(); } $book_destroy->delete(); return Redirect::to('/dashboard')->with('global_success', 'Your book was deleted and chapters are now unassigned. 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 book? See "Edit corner" below to browse your own resources.'); } }