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();
 }
Exemple #2
0
 /**
  * Cache the result row
  */
 public function current()
 {
     $row = parent::current();
     if (is_object($row)) {
         model_cache::set($row);
     }
     return $row;
 }
Exemple #3
0
 /**
  * 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));
 }
Exemple #6
0
 /**
  * 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;
 }
Exemple #7
0
 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);
 }
Exemple #8
0
 /**
  * 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;
 }
Exemple #9
0
 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 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"));
 }
Exemple #12
0
 /**
  * Load the corresponding Module_Model
  * @param string $module_name
  */
 static function get($module_name)
 {
     return model_cache::get("module", $module_name, "name");
 }
Exemple #13
0
 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);
     }
 }
Exemple #14
0
 /**
  * Internal method to add Permission/Group columns
  *
  * @param  Group_Model $group
  * @param  string  $perm_name
  * @return void
  */
 private static function _add_columns($perm_name, $group)
 {
     $db = Database::instance();
     $field = "{$perm_name}_{$group->id}";
     $cache_table = $perm_name == "view" ? "items" : "access_caches";
     $db->query("ALTER TABLE {{$cache_table}} ADD `{$field}` SMALLINT NOT NULL DEFAULT 0");
     $db->query("ALTER TABLE {access_intents} ADD `{$field}` BOOLEAN DEFAULT NULL");
     $db->update("access_intents", array($field => 0), array("item_id" => 1));
     model_cache::clear();
     ORM::factory("access_intent")->clear_cache();
 }
Exemple #15
0
 /**
  * Internal method to add Permission/Group columns
  *
  * @param  Group_Model $group
  * @param  string  $perm_name
  * @return void
  */
 private static function _add_columns($perm_name, $group)
 {
     $db = Database::instance();
     $field = "{$perm_name}_{$group->id}";
     $cache_table = $perm_name == "view" ? "items" : "access_caches";
     $not_null = $cache_table == "items" ? "" : "NOT NULL";
     $db->query("ALTER TABLE {{$cache_table}} ADD `{$field}` BINARY {$not_null} DEFAULT FALSE");
     $db->query("ALTER TABLE {access_intents} ADD `{$field}` BINARY DEFAULT NULL");
     $db->update("access_intents", array($field => self::DENY), array("item_id" => 1));
     model_cache::clear();
     ORM::factory("access_intent")->clear_cache();
 }
Exemple #16
0
 /**
  * Return the root Item_Model
  * @return Item_Model
  */
 static function root()
 {
     return model_cache::get("item", 1);
 }
Exemple #17
0
 /**
  * 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);
 }
Exemple #18
0
 /**
  * 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 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));
 }
Exemple #20
0
 /**
  * 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);
 }
Exemple #21
0
 /**
  * Internal method to add Permission/Group columns
  *
  * @param  Group_Model $group
  * @param  string  $perm_name
  * @return void
  */
 private static function _add_columns($perm_name, $group)
 {
     $field = "{$perm_name}_{$group->id}";
     $cache_table = $perm_name == "view" ? "items" : "access_caches";
     $not_null = $cache_table == "items" ? "" : "NOT NULL";
     Database::instance()->query("ALTER TABLE {{$cache_table}} ADD `{$field}` BINARY {$not_null} DEFAULT FALSE");
     Database::instance()->query("ALTER TABLE {access_intents} ADD `{$field}` BINARY DEFAULT NULL");
     db::build()->update("access_intents")->set($field, access::DENY)->where("item_id", "=", 1)->execute();
     model_cache::clear();
     ORM::factory("access_intent")->clear_cache();
 }
Exemple #22
0
 /**
  * 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);
 }
Exemple #23
0
 function item()
 {
     return model_cache::get("item", $this->item_id);
 }
Exemple #24
0
 /**
  * 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;
 }
Exemple #25
0
 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;
 }
Exemple #26
0
 /**
  * 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);
 }
 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));
 }
Exemple #28
0
 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;
 }
Exemple #29
0
 /**
  * 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;
     }
 }
Exemple #30
0
 /**
  * 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;
 }