static function activate() { // Update the root item. This is a quick hack because the search module is activated as part // of the official install, so this way we don't start off with a "your index is out of date" // banner. search::update(model_cache::get("item", 1)); search::check_index(); }
/** * Look up a group by name. * @param integer $id the group name * @return Group_Model the group object, or null if the name was invalid. */ static function lookup_by_name($name) { $group = model_cache::get("group", $name, "name"); if ($group->loaded) { return $group; } return null; }
/** * Allows the given item to be displayed again. * * @param int $id the item id */ public function unstar($id) { $item = model_cache::get("item", $id); $msg = t("Un-starred <b>%title</b> item", array("title" => html::purify($item->title))); $this->_check_star_permissions($item); star::unstar($item); message::success($msg); json::reply(array("result" => "success", "reload" => 1)); }
/** * Allows the given item to be displayed again. * * @param int $id the item id */ public function show($id) { $item = model_cache::get("item", $id); $msg = t("Displayed <b>%title</b> item", array("title" => html::purify($item->title))); $this->_check_hide_permissions($item); hide::show($item); message::success($msg); json::reply(array("result" => "success", "reload" => 1)); }
/** * Returns the hidden_item model related to the given item. * * There is an attempt to fetch the model from the database through the model * cache. If it fails, a new unsaved model is created. * * @param Item_Model $item the item * @return Hidden_Item_Model the related hidden_item model */ static function get_hidden_item_model(Item_Model $item) { try { $model = model_cache::get("item", $id); } catch (Exception $e) { $model = ORM::factory("hidden_item"); $model->item_id = $item->id; $model->validate(); } return $model; }
/** * Search the groups by the field and value. * @param string $field_name column to look up the user by * @param string $value value to match * @return Group_Definition the group object, or null if the name was invalid. */ private static function _lookup_by_field($field_name, $value) { try { $user = model_cache::get("group", $value, $field_name); if ($user->loaded()) { return $user; } } catch (Exception $e) { if (strpos($e->getMessage(), "MISSING_MODEL") === false) { throw $e; } } return null; }
static function site($uri, $protocol = false) { if (($pos = strpos($uri, "?")) !== false) { list($uri, $query) = explode("?", $uri, 2); $query = "?{$query}"; } else { $query = ""; } $parts = explode("/", $uri, 3); if ($parts[0] == "albums" || $parts[0] == "photos") { $uri = model_cache::get("item", $parts[1])->relative_path(); } return parent::site($uri . $query, $protocol); }
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 rotate($id, $dir) { access::verify_csrf(); $item = model_cache::get("item", $id); access::required("view", $item); access::required("edit", $item); $item = $this->p_rotate($item, $dir); json::reply(self::child_json_encode($item)); }
/** * Load the corresponding Module_Model * @param string $module_name */ static function get($module_name) { return model_cache::get("module", $module_name, "name"); }
public function form_edit($id) { $item = model_cache::get("item", $id); access::required("view", $item); access::required("edit", $item); if ($item->is_album()) { $form = album::get_edit_form($item); } else { $form = photo::get_edit_form($item); } print $form; }
/** * Internal method to set a permission * * @param Group_Model $group * @param string $perm_name * @param Item_Model $item * @param boolean $value */ private static function _set(Group_Model $group, $perm_name, $album, $value) { if (get_class($group) != "Group_Model") { throw new Exception("@todo PERMISSIONS_ONLY_WORK_ON_GROUPS"); } if (!$album->loaded) { throw new Exception("@todo INVALID_ALBUM {$album->id}"); } if (!$album->is_album()) { throw new Exception("@todo INVALID_ALBUM_TYPE not an album"); } $access = model_cache::get("access_intent", $album->id, "item_id"); $access->__set("{$perm_name}_{$group->id}", $value); $access->save(); if ($perm_name == "view") { self::_update_access_view_cache($group, $album); } else { self::_update_access_non_view_cache($group, $perm_name, $album); } self::_update_htaccess_files($album, $group, $perm_name, $value); model_cache::clear(); }
public function form_edit($id) { $item = model_cache::get("item", $id); access::required("view", $item); access::required("edit", $item); switch ($item->type) { case "album": return print album::get_edit_form($item); case "photo": return print photo::get_edit_form($item); case "movie": return print movie::get_edit_form($item); } }
/** * Return the parent of this node * * @return ORM */ function parent() { if (!$this->parent_id) { return null; } return model_cache::get($this->model_name, $this->parent_id); }
/** * Return the root Item_Model * @return Item_Model */ static function root() { return model_cache::get("item", 1); }
/** * Return the Item_Model representing the cover for this album. * @return Item_Model or null if there's no cover */ public function album_cover() { if ($this->type != "album") { return null; } if (empty($this->album_cover_item_id)) { return null; } return model_cache::get("item", $this->album_cover_item_id); }
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(); 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(); } } print json_encode(self::child_json_encode($item)); }
/** * The group of all logged-in visitors. This does not include guest users. * * @return Group_Model */ static function registered_users() { return model_cache::get("group", 2); }
function item() { return model_cache::get("item", $this->item_id); }
/** * Look up a user by name. * @param integer $id the user name * @return User_Model the user object, or null if the name was invalid. */ static function lookup_by_name($name) { $user = model_cache::get("user", $name, "name"); if ($user->loaded) { return $user; } return null; }
/** * Internal method to set a permission * * @param Group_Model $group * @param string $perm_name * @param Item_Model $item * @param boolean $value */ private static function _set($group, $perm_name, $album, $value) { if (!$album->loaded) { throw new Exception("@todo INVALID_ALBUM {$album->id}"); } if ($album->type != "album") { throw new Exception("@todo INVALID_ALBUM_TYPE not an album"); } $access = model_cache::get("access_intent", $album->id, "item_id"); $access->__set("{$perm_name}_{$group->id}", $value); $access->save(); if ($perm_name == "view") { self::_update_access_view_cache($group, $album); } else { self::_update_access_non_view_cache($group, $perm_name, $album); } self::_update_htaccess_files($album, $group, $perm_name, $value); }
public function form_edit($id) { $item = model_cache::get("item", $id); access::required("view", $item); access::required("edit", $item); switch ($item->type) { case "album": $form = album::get_edit_form($item); break; case "photo": $form = photo::get_edit_form($item); break; case "movie": $form = movie::get_edit_form($item); break; } // Pass on the source item where this form was generated, so we have an idea where to return to. $form->hidden("from_id")->value((int) Input::instance()->get("from_id", 0)); print $form; }
/** * Return the Item_Model representing the cover for this album. * @return Item_Model or null if there's no cover */ public function album_cover() { if (!$this->is_album()) { return null; } if (empty($this->album_cover_item_id)) { return null; } try { return model_cache::get("item", $this->album_cover_item_id); } catch (Exception $e) { // It's possible (unlikely) that the item was deleted, if so keep going. return null; } }
/** * Look up a user by id. * @param integer $id the user id * @return User_Model the user object, or null if the id was invalid. */ static function lookup($id) { $user = model_cache::get("user", $id); if ($user->loaded) { return $user; } return null; }