public function save() { access::verify_csrf(); $form = theme::get_edit_form_admin(); if ($form->validate()) { module::set_var("gallery", "page_size", $form->edit_theme->page_size->value); $thumb_size = $form->edit_theme->thumb_size->value; $thumb_dirty = false; if (module::get_var("gallery", "thumb_size") != $thumb_size) { graphics::remove_rule("gallery", "thumb", "gallery_graphics::resize"); graphics::add_rule("gallery", "thumb", "gallery_graphics::resize", array("width" => $thumb_size, "height" => $thumb_size, "master" => Image::AUTO), 100); module::set_var("gallery", "thumb_size", $thumb_size); } $resize_size = $form->edit_theme->resize_size->value; $resize_dirty = false; if (module::get_var("gallery", "resize_size") != $resize_size) { graphics::remove_rule("gallery", "resize", "gallery_graphics::resize"); graphics::add_rule("gallery", "resize", "gallery_graphics::resize", array("width" => $resize_size, "height" => $resize_size, "master" => Image::AUTO), 100); module::set_var("gallery", "resize_size", $resize_size); } module::set_var("gallery", "header_text", $form->edit_theme->header_text->value); module::set_var("gallery", "footer_text", $form->edit_theme->footer_text->value); module::set_var("gallery", "show_credits", $form->edit_theme->show_credits->value); message::success(t("Updated theme details")); url::redirect("admin/theme_options"); } else { $view = new Admin_View("admin.html"); $view->content = $form; print $view; } }
static function uninstall() { graphics::remove_rules("watermark"); module::delete("watermark"); Database::instance()->query("DROP TABLE `watermarks`"); dir::unlink(VARPATH . "modules/watermark"); }
public function save() { access::verify_csrf(); $form = $this->_get_edit_form_admin(); if ($form->validate()) { module::set_var("gallery", "page_size", $form->edit_theme->page_size->value); $thumb_size = $form->edit_theme->thumb_size->value; if (module::get_var("gallery", "thumb_size") != $thumb_size) { graphics::remove_rule("gallery", "thumb", "gallery_graphics::resize"); graphics::add_rule("gallery", "thumb", "gallery_graphics::resize", array("width" => $thumb_size, "height" => $thumb_size, "master" => Image::AUTO), 100); module::set_var("gallery", "thumb_size", $thumb_size); } $resize_size = $form->edit_theme->resize_size->value; if (module::get_var("gallery", "resize_size") != $resize_size) { graphics::remove_rule("gallery", "resize", "gallery_graphics::resize"); graphics::add_rule("gallery", "resize", "gallery_graphics::resize", array("width" => $resize_size, "height" => $resize_size, "master" => Image::AUTO), 100); module::set_var("gallery", "resize_size", $resize_size); } module::set_var("gallery", "show_credits", $form->edit_theme->show_credits->value); // Sanitize values that get placed directly in HTML output by theme. module::set_var("gallery", "header_text", html::purify($form->edit_theme->header_text->value)); module::set_var("gallery", "footer_text", html::purify($form->edit_theme->footer_text->value)); module::set_var("gallery", "favicon_url", html::purify($form->edit_theme->favicon_url->value)); module::set_var("gallery", "apple_touch_icon_url", html::purify($form->edit_theme->apple_touch_icon_url->value)); module::event("theme_edit_form_completed", $form); message::success(t("Updated theme details")); url::redirect("admin/theme_options"); } else { $view = new Admin_View("admin.html"); $view->content = new View("admin_theme_options.html"); $view->content->form = $form; print $view; } }
/** * Task that rebuilds all dirty images. * @param Task_Model the task */ static function rebuild_dirty_images($task) { $errors = array(); try { $result = graphics::find_dirty_images_query()->select("id")->execute(); $total_count = $task->get("total_count", $result->count()); $mode = $task->get("mode", "init"); if ($mode == "init") { $task->set("total_count", $total_count); $task->set("mode", "process"); batch::start(); } $completed = $task->get("completed", 0); $ignored = $task->get("ignored", array()); $i = 0; foreach ($result as $row) { if (array_key_exists($row->id, $ignored)) { continue; } $item = ORM::factory("item", $row->id); if ($item->loaded()) { try { graphics::generate($item); $completed++; $errors[] = t("Successfully rebuilt images for '%title'", array("title" => html::purify($item->title))); } catch (Exception $e) { $errors[] = t("Unable to rebuild images for '%title'", array("title" => html::purify($item->title))); $errors[] = (string) $e; $ignored[$item->id] = 1; } } if (++$i == 2) { break; } } $task->status = t2("Updated: 1 image. Total: %total_count.", "Updated: %count images. Total: %total_count.", $completed, array("total_count" => $total_count)); if ($completed < $total_count) { $task->percent_complete = (int) (100 * ($completed + count($ignored)) / $total_count); } else { $task->percent_complete = 100; } $task->set("completed", $completed); $task->set("ignored", $ignored); if ($task->percent_complete == 100) { $task->done = true; $task->state = "success"; batch::stop(); site_status::clear("graphics_dirty"); } } catch (Exception $e) { Kohana_Log::add("error", (string) $e); $task->done = true; $task->state = "error"; $task->status = $e->getMessage(); $errors[] = (string) $e; } if ($errors) { $task->log($errors); } }
/** * Crop the input image so that it matches the aspect ratio specified in the * rectangle_thumbs.aspect_ratio module setting. Focus on the center of the image and crop out * the biggest piece that we can. * * @param string $input_file * @param string $output_file * @param array $options */ static function crop_to_aspect_ratio($input_file, $output_file, $options) { graphics::init_toolkit(); if (@filesize($input_file) == 0) { throw new Exception("@todo EMPTY_INPUT_FILE"); } list($desired_width, $desired_height) = explode(":", module::get_var("rectangle_thumbs", "aspect_ratio")); $desired_ratio = $desired_width / $desired_height; // Crop the largest rectangular section we can out of the original image. Start with a // rectangular section that's guaranteed to be too large, then shrink it horizontally to just // barely fit. If it's still too tall vertically, shrink both dimensions proportionally until // the horizontal edge fits as well. $dims = getimagesize($input_file); if ($desired_ratio == 1) { $new_width = $new_height = min($dims[0], $dims[1]); } else { if ($desired_ratio < 1) { list($new_width, $new_height) = array($dims[0], $dims[0] / $desired_ratio); } else { list($new_width, $new_height) = array($dims[1] * $desired_ratio, $dims[1]); } } if ($new_width > $dims[0]) { // Too wide, scale it down list($new_width, $new_height) = array($dims[0], $dims[0] / $desired_ratio); } if ($new_height > $dims[1]) { // Too tall, scale it down some more $new_width = min($dims[0], $dims[1] * $desired_ratio); $new_height = $new_width / $desired_ratio; } $new_width = round($new_width); $new_height = round($new_height); Image::factory($input_file)->crop($new_width, $new_height)->quality(module::get_var("gallery", "image_quality"))->save($output_file); }
/** * Task that rebuilds all dirty images. * @param Task_Model the task */ static function rebuild_dirty_images($task) { $result = graphics::find_dirty_images_query(); $remaining = $result->count(); $completed = $task->get("completed", 0); $i = 0; foreach ($result as $row) { $item = ORM::factory("item", $row->id); if ($item->loaded) { graphics::generate($item); } $completed++; $remaining--; if (++$i == 2) { break; } } $task->status = t2("Updated: 1 image. Total: %total_count.", "Updated: %count images. Total: %total_count.", $completed, array("total_count" => $remaining + $completed)); if ($completed + $remaining > 0) { $task->percent_complete = (int) (100 * $completed / ($completed + $remaining)); } else { $task->percent_complete = 100; } $task->set("completed", $completed); if ($remaining == 0) { $task->done = true; $task->state = "success"; site_status::clear("graphics_dirty"); } }
/** * Rotate an image. Valid options are degrees * * @param string $input_file * @param string $output_file * @param array $options */ static function rotate($input_file, $output_file, $options) { graphics::init_toolkit(); module::event("graphics_rotate", $input_file, $output_file, $options); // BEGIN mod to original function $image_info = getimagesize($input_file); // [0]=w, [1]=h, [2]=type (1=GIF, 2=JPG, 3=PNG) if (module::get_var("image_optimizer", "rotate_jpg") || $image_info[2] == 2) { // rotate_jpg enabled, the file is a jpg. get args $path = module::get_var("image_optimizer", "path_jpg"); $exec_args = " -rotate "; $exec_args .= $options["degrees"] > 0 ? $options["degrees"] : $options["degrees"] + 360; $exec_args .= " -copy all -optimize -outfile "; // run it - from input_file to tmp_file $tmp_file = image_optimizer::make_temp_name($output_file); exec(escapeshellcmd($path) . $exec_args . escapeshellarg($tmp_file) . " " . escapeshellarg($input_file), $exec_output, $exec_status); if ($exec_status || !filesize($tmp_file)) { // either a blank/nonexistant file or an error - log an error and pass to normal function Kohana_Log::add("error", "image_optimizer rotation failed on " . $output_file); unlink($tmp_file); } else { // worked - move temp to output rename($tmp_file, $output_file); $status = true; } } if (!$status) { // we got here if we weren't supposed to use jpegtran or if jpegtran failed // END mod to original function Image::factory($input_file)->quality(module::get_var("gallery", "image_quality"))->rotate($options["degrees"])->save($output_file); // BEGIN mod to original function } // END mod to original function module::event("graphics_rotate_completed", $input_file, $output_file, $options); }
static function item_created($item) { // Only works on photos if (!$item->is_photo()) { return; } // Locate jhead if (!is_file($path = exec('which jhead'))) { // @todo throw an exception ? Kohana::log('error', 'jhead is not installed'); } $binary = str_replace('\\', '/', realpath(dirname($path))); $binary .= '/jhead'; $binary .= PHP_SHLIB_SUFFIX === 'dll' ? '.exe' : ''; if (!is_file($binary)) { // @todo throw an exception ? Kohana::log('error', 'Unable to locate jhead binary'); } // Invoke jhead if ($error = exec(escapeshellcmd($binary) . ' -q -autorot ' . $item->file_path())) { // @todo throw an exception ? Kohana::log('error', 'Error during execution of jhead'); } // Update item $image_info = getimagesize($item->file_path()); $item->width = $image_info[0]; $item->height = $image_info[1]; $item->resize_dirty = 1; $item->thumb_dirty = 1; $item->save(); graphics::generate($item); }
static function install() { // Insert a rule into the thumbnail generation pipeline that converts the source image to the // right aspect ratio such that when we resize it down, it comes out to the right dimensions. graphics::add_rule("rectangle_thumbs", "thumb", "rectangle_thumbs_graphics::crop_to_aspect_ratio", array(), 50); module::set_var("rectangle_thumbs", "aspect_ratio", "3:1"); module::set_version("rectangle_thumbs", 1); }
/** * Overlay an image on top of the input file. * * Valid options are: file, mime_type, position, transparency_percent, padding * * Valid positions: northwest, north, northeast, * west, center, east, * southwest, south, southeast * * padding is in pixels * * @param string $input_file * @param string $output_file * @param array $options */ static function composite($input_file, $output_file, $options) { try { graphics::init_toolkit(); module::event("graphics_composite", $input_file, $output_file, $options); list($width, $height) = getimagesize($input_file); list($w_width, $w_height) = getimagesize($options["file"]); $pad = isset($options["padding"]) ? $options["padding"] : 10; $top = $pad; $left = $pad; $y_center = max($height / 2 - $w_height / 2, $pad); $x_center = max($width / 2 - $w_width / 2, $pad); $bottom = max($height - $w_height - $pad, $pad); $right = max($width - $w_width - $pad, $pad); switch ($options["position"]) { case "northwest": $x = $left; $y = $top; break; case "north": $x = $x_center; $y = $top; break; case "northeast": $x = $right; $y = $top; break; case "west": $x = $left; $y = $y_center; break; case "center": $x = $x_center; $y = $y_center; break; case "east": $x = $right; $y = $y_center; break; case "southwest": $x = $left; $y = $bottom; break; case "south": $x = $x_center; $y = $bottom; break; case "southeast": $x = $right; $y = $bottom; break; } Image::factory($input_file)->composite($options["file"], $x, $y, $options["transparency"])->quality(module::get_var("gallery", "image_quality"))->save($output_file); module::event("graphics_composite_completed", $input_file, $output_file, $options); } catch (ErrorException $e) { Kohana::log("error", $e->get_message()); } }
static function user_login($user) { // If this user is an admin, check to see if there are any post-install tasks that we need // to run and take care of those now. if ($user->admin && module::get_var("gallery", "choose_default_tookit", null)) { graphics::choose_default_toolkit(); module::clear_var("gallery", "choose_default_tookit"); } }
/** * Crop the input image so that it's square. Focus on the center of the image. * * @param string $input_file * @param string $output_file * @param array $options */ static function crop_to_square($input_file, $output_file, $options) { graphics::init_toolkit(); if (@filesize($input_file) == 0) { throw new Exception("@todo EMPTY_INPUT_FILE"); } $size = module::get_var("gallery", "thumb_size"); $dims = getimagesize($input_file); Image::factory($input_file)->crop(min($dims[0], $dims[1]), min($dims[0], $dims[1]))->quality(module::get_var("gallery", "image_quality"))->save($output_file); }
public function save() { access::verify_csrf(); $form = self::get_edit_form_admin(); if ($form->validate()) { $edit_theme = $form->edit_theme; module::set_var("gallery", "page_size", $edit_theme->row_count->value * 3); $resize_size = $edit_theme->resize_size->value; $thumb_size = 200; $build_resize = $edit_theme->build_resize->value; $build_thumbs = $edit_theme->build_thumbs->value; if (module::get_var("gallery", "resize_size") != $resize_size) { module::set_var("gallery", "resize_size", $resize_size); $build_resize = true; } if (module::get_var("gallery", "thumb_size") != $thumb_size) { module::set_var("gallery", "thumb_size", $thumb_size); } if ($build_resize) { graphics::remove_rule("gallery", "resize", "gallery_graphics::resize"); graphics::add_rule("gallery", "resize", "gallery_graphics::resize", array("width" => $resize_size, "height" => $resize_size, "master" => Image::AUTO), 100); } if ($build_thumbs) { graphics::remove_rule("gallery", "thumb", "gallery_graphics::resize"); graphics::add_rule("gallery", "thumb", "gallery_graphics::resize", array("width" => 200, "height" => 200, "master" => Image::AUTO), 100); } module::set_var("th_greydragon", "photonav_top", $edit_theme->photonav_top->value); module::set_var("th_greydragon", "photonav_bottom", $edit_theme->photonav_bottom->value); $sidebar_allowed = $edit_theme->sidebar_allowed->value; $sidebar_visible = $edit_theme->sidebar_visible->value; if ($sidebar_allowed == "none") { $sidebar_visible = "none"; } if ($sidebar_allowed == "right") { $sidebar_visible = "right"; } if ($sidebar_allowed == "left") { $sidebar_visible = "left"; } module::set_var("th_greydragon", "sidebar_allowed", $sidebar_allowed); module::set_var("th_greydragon", "sidebar_visible", $sidebar_visible); module::set_var("gallery", "header_text", $edit_theme->header_text->value); module::set_var("gallery", "footer_text", $edit_theme->footer_text->value); module::set_var("gallery", "show_credits", $edit_theme->show_credits->value); module::set_var("th_greydragon", "copyright", $edit_theme->copyright->value); module::set_var("th_greydragon", "logo_path", $edit_theme->logo_path->value); module::event("theme_edit_form_completed", $form); message::success(t("Updated theme details")); url::redirect("admin/theme_options"); } else { $view = new Admin_View("admin.html"); $view->content = $form; print $view; } }
static function remove_album_cover($album) { access::required("edit", $album); @unlink($album->thumb_path()); model_cache::clear("item", $album->album_cover_item_id); $album->album_cover_item_id = null; $album->thumb_width = 0; $album->thumb_height = 0; $album->thumb_dirty = 1; $album->save(); graphics::generate($album); }
/** * Task that rebuilds all dirty images. * @param Task_Model the task */ static function rebuild_dirty_images($task) { $errors = array(); try { $result = graphics::find_dirty_images_query(); $completed = $task->get("completed", 0); $ignored = $task->get("ignored", array()); $remaining = $result->count() - count($ignored); $i = 0; foreach ($result as $row) { if (array_key_exists($row->id, $ignored)) { continue; } $item = ORM::factory("item", $row->id); if ($item->loaded) { try { graphics::generate($item); $ignored[$item->id] = 1; $errors[] = t("Successfully rebuilt images for '%title'", array("title" => html::purify($item->title))); } catch (Exception $e) { $errors[] = t("Unable to rebuild images for '%title'", array("title" => html::purify($item->title))); $errors[] = $e->__toString(); } } $completed++; $remaining--; if (++$i == 2) { break; } } $task->status = t2("Updated: 1 image. Total: %total_count.", "Updated: %count images. Total: %total_count.", $completed, array("total_count" => $remaining + $completed)); if ($completed + $remaining > 0) { $task->percent_complete = (int) (100 * $completed / ($completed + $remaining)); } else { $task->percent_complete = 100; } $task->set("completed", $completed); $task->set("ignored", $ignored); if ($remaining == 0) { $task->done = true; $task->state = "success"; site_status::clear("graphics_dirty"); } } catch (Exception $e) { $task->done = true; $task->state = "error"; $task->status = $e->getMessage(); $errors[] = $e->__toString(); } if ($errors) { $task->log($errors); } }
static function buttons($item, $page_type) { $elements = array("left" => array(), "center" => array(), "right" => array(), "additional" => array()); switch ($item->type) { case "movie": $edit_title = t("Edit this movie"); $move_title = t("Move this movie to another album"); $cover_title = t("Choose this movie as the album cover"); $delete_title = t("Delete this movie"); break; case "album": $edit_title = t("Edit this album"); $move_title = t("Move this album to another album"); $cover_title = t("Choose this album as the album cover"); $delete_title = t("Delete this album"); break; default: $edit_title = t("Edit this photo"); $move_title = t("Move this photo to another album"); $cover_title = t("Choose this photo as the album cover"); $delete_title = t("Delete this photo"); break; } $csrf = access::csrf_token(); $elements["left"][] = (object) array("title" => $edit_title, "class" => "gDialogLink gButtonLink", "icon" => "ui-icon-pencil", "href" => url::site("quick/form_edit/{$item->id}?page_type={$page_type}")); if ($item->is_photo() && graphics::can("rotate")) { $elements["left"][] = (object) array("title" => t("Rotate 90 degrees counter clockwise"), "class" => "gButtonLink", "icon" => "ui-icon-rotate-ccw", "href" => url::site("quick/rotate/{$item->id}/ccw?csrf={$csrf}&page_type={$page_type}")); $elements["left"][] = (object) array("title" => t("Rotate 90 degrees clockwise"), "class" => "gButtonLink", "icon" => "ui-icon-rotate-cw", "href" => url::site("quick/rotate/{$item->id}/cw?csrf={$csrf}&page_type={$page_type}")); } // Don't move photos from the photo page; we don't yet have a good way of redirecting after move if ($page_type == "album") { $elements["left"][] = (object) array("title" => $move_title, "class" => "gDialogLink gButtonLink", "icon" => "ui-icon-folder-open", "href" => url::site("move/browse/{$item->id}")); } $parent = $item->parent(); if (access::can("edit", $parent)) { // We can't make this item the highlight if it's an album with no album cover, or if it's // already the album cover. if ($item->type == "album" && empty($item->album_cover_item_id) || $item->type == "album" && $parent->album_cover_item_id == $item->album_cover_item_id || $parent->album_cover_item_id == $item->id) { $disabledState = " ui-state-disabled"; } else { $disabledState = " "; } $elements["right"][] = (object) array("title" => $cover_title, "class" => "gButtonLink{$disabledState}", "icon" => "ui-icon-star", "href" => url::site("quick/make_album_cover/{$item->id}?csrf={$csrf}&page_type={$page_type}")); $elements["right"][] = (object) array("title" => $delete_title, "class" => "gDialogLink gButtonLink", "icon" => "ui-icon-trash", "id" => "gQuickDelete", "href" => url::site("quick/form_delete/{$item->id}?csrf={$csrf}&page_type={$page_type}")); } if ($item->is_album()) { $elements["additional"][] = (object) array("title" => t("Add a photo"), "class" => "add_item gDialogLink", "href" => url::site("simple_uploader/app/{$item->id}")); $elements["additional"][] = (object) array("title" => t("Add an album"), "class" => "add_album gDialogLink", "href" => url::site("form/add/albums/{$item->id}?type=album")); $elements["additional"][] = (object) array("title" => t("Edit permissions"), "class" => "permissions gDialogLink", "href" => url::site("permissions/browse/{$item->id}")); } return $elements; }
public function choose($toolkit_id) { access::verify_csrf(); if ($toolkit_id != module::get_var("gallery", "graphics_toolkit")) { $tk = graphics::detect_toolkits(); module::set_var("gallery", "graphics_toolkit", $toolkit_id); module::set_var("gallery", "graphics_toolkit_path", $tk->{$toolkit_id}->dir); site_status::clear("missing_graphics_toolkit"); $msg = t("Changed graphics toolkit to: %toolkit", array("toolkit" => $tk->{$toolkit_id}->name)); message::success($msg); log::success("graphics", $msg); } url::redirect("admin/graphics"); }
public function choose($toolkit) { access::verify_csrf(); if ($toolkit != module::get_var("gallery", "graphics_toolkit")) { module::set_var("gallery", "graphics_toolkit", $toolkit); $toolkit_info = graphics::detect_toolkits(); if ($toolkit == "graphicsmagick" || $toolkit == "imagemagick") { module::set_var("gallery", "graphics_toolkit_path", $toolkit_info[$toolkit]); } site_status::clear("missing_graphics_toolkit"); message::success(t("Updated Graphics Toolkit")); log::success("graphics", t("Changed graphics toolkit to: %toolkit", array("toolkit" => $toolkit))); } url::redirect("admin/graphics"); }
/** * Create a new photo. * @param integer $parent_id id of parent album * @param string $filename path to the photo file on disk * @param string $name the filename to use for this photo in the album * @param integer $title the title of the new photo * @param string $description (optional) the longer description of this photo * @return Item_Model */ static function create($parent, $filename, $name, $title, $description = null, $owner_id = null) { if (!$parent->loaded || $parent->type != "album") { throw new Exception("@todo INVALID_PARENT"); } if (!is_file($filename)) { throw new Exception("@todo MISSING_IMAGE_FILE"); } if (!($image_info = getimagesize($filename))) { throw new Exception("@todo INVALID_IMAGE_FILE"); } // Force an extension onto the name $pi = pathinfo($name); if (empty($pi["extension"])) { $pi["extension"] = image_type_to_extension($image_info[2], false); $name .= "." . $pi["extension"]; } $photo = ORM::factory("item"); $photo->type = "photo"; $photo->title = $title; $photo->description = $description; $photo->name = $name; $photo->owner_id = $owner_id; $photo->width = $image_info[0]; $photo->height = $image_info[1]; $photo->mime_type = empty($image_info['mime']) ? "application/unknown" : $image_info['mime']; $photo->thumb_dirty = 1; $photo->resize_dirty = 1; // Randomize the name if there's a conflict while (ORM::Factory("item")->where("parent_id", $parent->id)->where("name", $photo->name)->find()->id) { // @todo Improve this. Random numbers are not user friendly $photo->name = rand() . "." . $pi["extension"]; } // This saves the photo $photo->add_to_parent($parent); copy($filename, $photo->file_path()); module::event("item_created", $photo); // Build our thumbnail/resizes graphics::generate($photo); // If the parent has no cover item, make this it. $parent = $photo->parent(); if ($parent->album_cover_item_id == null) { $parent->album_cover_item_id = $photo->id; $parent->save(); graphics::generate($parent); } return $photo; }
public function save() { access::verify_csrf(); $form = $this->_get_admin_form(); if ($form->validate()) { module::set_var("gallery", "movie_allow_uploads", $form->settings->allow_uploads->value); if ($form->settings->rebuild_thumbs->value) { graphics::mark_dirty(true, false, "movie"); } // All done - redirect with message. message::success(t("Movies settings updated successfully")); url::redirect("admin/movies"); } // Something went wrong - print view from existing form. $this->_print_view($form); }
public function save($source_id) { access::verify_csrf(); $source = ORM::factory("item", $source_id); access::required("edit", $source); $target = ORM::factory("item", $this->input->post("target_id")); access::required("edit", $target); $source->move_to($target); // If the target has no cover item, make this it. if ($target->album_cover_item_id == null) { $target->album_cover_item_id = $source->type == "album" ? $source->album_cover_item_id : $source->id; $target->save(); graphics::generate($target); } print json_encode(array("result" => "success", "location" => url::site("albums/{$target->id}"))); }
public function restore($id) { // Allow the user to restore the original photo. // Make sure the current user has suficient access to view and edit the item. $item = ORM::factory("item", $id); access::required("view", $item); access::required("edit", $item); // Figure out where the original was stashed at. $original_image = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item->file_path()); // Make sure the current item is a photo and that an original exists. if ($item->is_photo() && file_exists($original_image)) { // Delete the modified version of the photo. @unlink($item->file_path()); // Copy the original image back over, display an error message if the copy fails. if (@rename($original_image, $item->file_path())) { // Re-generate the items resize and thumbnail. $item_data = model_cache::get("item", $id); $item_data->resize_dirty = 1; $item_data->thumb_dirty = 1; $item_data->save(); graphics::generate($item_data); // If the item is the thumbnail for the parent album, // fix the parent's thumbnail as well. $parent = $item_data->parent(); if ($parent->album_cover_item_id == $item_data->id) { copy($item_data->thumb_path(), $parent->thumb_path()); $parent->thumb_width = $item_data->thumb_width; $parent->thumb_height = $item_data->thumb_height; $parent->save(); } // Display a success message and redirect to the items page. message::success(t("Your original image has been restored.")); url::redirect($item->url()); } else { // Display an error message if the copy failed. message::error(t("Image restore failed!")); url::redirect($item->url()); } } else { // Display an error message if there is not an original photo. message::error(t("Image restore failed!")); url::redirect($item->url()); } }
public function make_album_cover($id) { access::verify_csrf(); $item = ORM::factory("item", $id); access::required("edit", $item); $parent = $item->parent(); access::required("edit", $parent); if ($item->type == "photo") { $parent->album_cover_item_id = $item->id; } else { if ($item->type == "album") { $parent->album_cover_item_id = $item->album_cover_item_id; } } $parent->thumb_dirty = 1; $parent->save(); graphics::generate($parent); print json_encode(array("result" => "success")); }
public function save($source_id) { access::verify_csrf(); $source = ORM::factory("item", $source_id); $target = ORM::factory("item", Input::instance()->post("target_id")); access::required("view", $source); access::required("view", $target); access::required("edit", $target); model_cache::clear(); $target->album_cover_item_id = $source->is_album() ? $source->album_cover_item_id : $source->id; $target->thumb_dirty = 1; $target->save(); graphics::generate($target); $grand_parent = $target->parent(); if ($grand_parent && access::can("edit", $grand_parent) && $grand_parent->album_cover_item_id == null) { item::make_album_cover($target); } $msg = t("Made <b>%title</b> album's cover for <b>%album</b>", array("title" => html::purify($source->title), "album" => html::purify($target->title))); message::success($msg); json::reply(array("result" => "success")); }
public function render() { $v = new View("form_uploadify.html"); $v->album = $this->data["album"]; $v->script_data = $this->data["script_data"]; $v->simultaneous_upload_limit = module::get_var("gallery", "simultaneous_upload_limit"); $v->movies_allowed = movie::allow_uploads(); $v->extensions = legal_file::get_filters(); $v->suhosin_session_encrypt = (bool) ini_get("suhosin.session.encrypt"); list($toolkit_max_filesize_bytes, $toolkit_max_filesize) = graphics::max_filesize(); $upload_max_filesize = trim(ini_get("upload_max_filesize")); $upload_max_filesize_bytes = num::convert_to_bytes($upload_max_filesize); if ($upload_max_filesize_bytes < $toolkit_max_filesize_bytes) { $v->size_limit_bytes = $upload_max_filesize_bytes; $v->size_limit = $upload_max_filesize; } else { $v->size_limit_bytes = $toolkit_max_filesize_bytes; $v->size_limit = $toolkit_max_filesize; } return $v; }
static function update_rules() { // Make sure our thumb size matches the gallery one $thumb_size = module::get_var("gallery", "thumb_size"); if ($thumb_size != module::get_var("custom_albums", "thumb_size")) { // Remove and readd our rule with the latest thumb size graphics::remove_rule("custom_albums", "thumb", "custom_albums_graphics::build_thumb"); graphics::add_rule("custom_albums", "thumb", "custom_albums_graphics::build_thumb", array("width" => $thumb_size, "height" => $thumb_size, "master" => Image::AUTO), 101); // Deactivate the gallery thumbnail generation, we'll handle it now graphics::deactivate_rules("gallery"); module::set_var("custom_albums", "thumb_size", $thumb_size); } // Make sure our resize size matches the gallery one $resize_size = module::get_var("gallery", "resize_size"); if ($resize_size != module::get_var("custom_albums", "resize_size")) { // Remove and readd our rule with the latest resize size graphics::remove_rule("custom_albums", "resize", "custom_albums_graphics::build_resize"); graphics::add_rule("custom_albums", "resize", "custom_albums_graphics::build_resize", array("width" => $resize_size, "height" => $resize_size, "master" => Image::AUTO), 101); // Deactivate the gallery resize, we'll handle it now graphics::deactivate_rules("gallery"); module::set_var("custom_albums", "resize_size", $resize_size); } }
public function rotate($id, $dir) { access::verify_csrf(); $item = ORM::factory("item", $id); if (!$item->loaded) { return ""; } $degrees = 0; switch ($dir) { case "ccw": $degrees = -90; break; case "cw": $degrees = 90; break; } if ($degrees) { graphics::rotate($item->file_path(), $item->file_path(), array("degrees" => $degrees)); list($item->width, $item->height) = getimagesize($item->file_path()); $item->resize_dirty = 1; $item->thumb_dirty = 1; $item->save(); graphics::generate($item); $parent = $item->parent(); if ($parent->album_cover_item_id == $item->id) { copy($item->thumb_path(), $parent->thumb_path()); $parent->thumb_width = $item->thumb_width; $parent->thumb_height = $item->thumb_height; $parent->save(); } } if (Input::instance()->get("page_type") == "album") { print json_encode(array("src" => $item->thumb_url() . "?rnd=" . rand(), "width" => $item->thumb_width, "height" => $item->thumb_height)); } else { print json_encode(array("src" => $item->resize_url() . "?rnd=" . rand(), "width" => $item->resize_width, "height" => $item->resize_height)); } }
public function rotate($id, $dir) { access::verify_csrf(); $item = model_cache::get("item", $id); access::required("view", $item); access::required("edit", $item); $degrees = 0; switch ($dir) { case "ccw": $degrees = -90; break; case "cw": $degrees = 90; break; } if ($degrees) { gallery_graphics::rotate($item->file_path(), $item->file_path(), array("degrees" => $degrees)); list($item->width, $item->height) = getimagesize($item->file_path()); $item->resize_dirty = 1; $item->thumb_dirty = 1; $item->save(); graphics::generate($item); $parent = $item->parent(); // @todo: this is an inadequate way to regenerate the parent's thumbnail after rotation. if ($parent->album_cover_item_id == $item->id) { copy($item->thumb_path(), $parent->thumb_path()); $parent->thumb_width = $item->thumb_width; $parent->thumb_height = $item->thumb_height; $parent->save(); } } if (Input::instance()->get("page_type") == "collection") { print json_encode(array("src" => $item->thumb_url() . "?rnd=" . rand(), "width" => $item->thumb_width, "height" => $item->thumb_height)); } else { print json_encode(array("src" => $item->resize_url() . "?rnd=" . rand(), "width" => $item->resize_width, "height" => $item->resize_height)); } }
/** * This needs to be run once, after the initial install, to choose a graphics toolkit. */ static function choose_default_toolkit() { // Detect a graphics toolkit $toolkits = graphics::detect_toolkits(); foreach (array("imagemagick", "graphicsmagick", "gd") as $tk) { if ($toolkits[$tk]) { module::set_var("gallery", "graphics_toolkit", $tk); module::set_var("gallery", "graphics_toolkit_path", $tk == "gd" ? "" : $toolkits[$tk]); break; } } if (!module::get_var("gallery", "graphics_toolkit")) { site_status::warning(t("Graphics toolkit missing! Please <a href=\"%url\">choose a toolkit</a>", array("url" => url::site("admin/graphics"))), "missing_graphics_toolkit"); } }
echo url::site("quick/form_edit/{$item->id}?page_type={$page_type}"); ?> " title="<?php echo $title; ?> "> <span class="ui-icon ui-icon-pencil"> <?php echo $title; ?> </span> </a> <?php if ($item->is_photo() && graphics::can("rotate")) { ?> <a class="gButtonLink ui-corner-all ui-state-default" href="<?php echo url::site("quick/rotate/{$item->id}/ccw?csrf={$csrf}&page_type={$page_type}"); ?> " title="<?php echo t("Rotate 90 degrees counter clockwise"); ?> "> <span class="ui-icon ui-icon-rotate-ccw"> <?php echo t("Rotate 90 degrees counter clockwise"); ?> </span> </a>