コード例 #1
0
ファイル: tag_event.php プロジェクト: xafr/gallery3
 /**
  * Handle the creation of a new photo.
  * @todo Get tags from the XMP and/or IPTC data in the image
  *
  * @param Item_Model $photo
  */
 static function item_created($photo)
 {
     $tags = array();
     if ($photo->is_photo()) {
         $path = $photo->file_path();
         $size = getimagesize($photo->file_path(), $info);
         if (is_array($info) && !empty($info["APP13"])) {
             $iptc = iptcparse($info["APP13"]);
             if (!empty($iptc["2#025"])) {
                 foreach ($iptc["2#025"] as $tag) {
                     $tag = str_replace("", "", $tag);
                     if (function_exists("mb_detect_encoding") && mb_detect_encoding($tag) != "UTF-8") {
                         $tag = utf8_encode($tag);
                     }
                     $tags[$tag] = 1;
                 }
             }
         }
     }
     // @todo figure out how to read the keywords from xmp
     foreach (array_keys($tags) as $tag) {
         tag::add($photo, $tag);
     }
     return;
 }
コード例 #2
0
ファイル: tag_event.php プロジェクト: andyst/gallery3
 /**
  * Handle the creation of a new photo.
  * @todo Get tags from the XMP and/or IPTC data in the image
  *
  * @param Item_Model $photo
  */
 static function item_created($photo)
 {
     $tags = array();
     if ($photo->is_photo()) {
         $path = $photo->file_path();
         $size = getimagesize($photo->file_path(), $info);
         if (is_array($info) && !empty($info["APP13"])) {
             $iptc = iptcparse($info["APP13"]);
             if (!empty($iptc["2#025"])) {
                 foreach ($iptc["2#025"] as $tag) {
                     $tag = str_replace("", "", $tag);
                     foreach (explode(",", $tag) as $word) {
                         $word = trim($word);
                         if (function_exists("mb_detect_encoding") && mb_detect_encoding($word) != "UTF-8") {
                             $word = utf8_encode($word);
                         }
                         $tags[$word] = 1;
                     }
                 }
             }
         }
     }
     // @todo figure out how to read the keywords from xmp
     foreach (array_keys($tags) as $tag) {
         try {
             tag::add($photo, $tag);
         } catch (Exception $e) {
             Kohana_Log::add("error", "Error adding tag: {$tag}\n" . $e->getMessage() . "\n" . $e->getTraceAsString());
         }
     }
     return;
 }
コード例 #3
0
ファイル: graphics.php プロジェクト: Juuro/Dreamapp-Website
 /**
  * Rebuild the thumb and resize for the given item.
  * @param Item_Model $item
  */
 static function generate($item)
 {
     if ($item->type == "album") {
         $cover = $item->album_cover();
         if (!$cover) {
             return;
         }
         $input_file = $cover->file_path();
     } else {
         $input_file = $item->file_path();
     }
     $ops = array();
     if ($item->thumb_dirty) {
         $ops["thumb"] = $item->thumb_path();
     }
     if ($item->resize_dirty && $item->type != "album") {
         $ops["resize"] = $item->resize_path();
     }
     if (!$ops) {
         return;
     }
     foreach (array("thumb" => $item->thumb_path(), "resize" => $item->resize_path()) as $target => $output_file) {
         $working_file = $input_file;
         foreach (ORM::factory("graphics_rule")->where("target", $target)->orderby("priority", "asc")->find_all() as $rule) {
             $args = array($working_file, $output_file, unserialize($rule->args));
             call_user_func_array(array("graphics", $rule->operation), $args);
             $working_file = $output_file;
         }
     }
     if (!empty($ops["thumb"])) {
         $dims = getimagesize($item->thumb_path());
         $item->thumb_width = $dims[0];
         $item->thumb_height = $dims[1];
         $item->thumb_dirty = 0;
     }
     if (!empty($ops["resize"])) {
         $dims = getimagesize($item->resize_path());
         $item->resize_width = $dims[0];
         $item->resize_height = $dims[1];
         $item->resize_dirty = 0;
     }
     $item->save();
 }
コード例 #4
0
ファイル: tag_event.php プロジェクト: Juuro/Dreamapp-Website
 /**
  * Handle the creation of a new photo.
  * @todo Get tags from the XMP and/or IPTC data in the image
  *
  * @param Item_Model $photo
  */
 static function item_created($photo)
 {
     if ($photo->is_photo()) {
         $path = $photo->file_path();
         $tags = array();
         $size = getimagesize($photo->file_path(), $info);
         if (is_array($info) && !empty($info["APP13"])) {
             $iptc = iptcparse($info["APP13"]);
             if (!empty($iptc["2#025"])) {
                 foreach ($iptc["2#025"] as $tag) {
                     $tags[$tag] = 1;
                 }
             }
         }
     }
     // @todo figure out how to read the keywords from xmp
     foreach (array_keys($tags) as $tag) {
         tag::add($photo, $tag);
     }
     return;
 }
コード例 #5
0
ファイル: plugin_move.php プロジェクト: ezioms/RpgEditor
 /**
  * Gestion du changement de carte.
  * 
  * @return  void
  */
 public function index()
 {
     if (isset($this->data->action_map->item) && $this->data->action_map->item && !($obj = Item_Model::instance()->select($this->user->id, $this->data->action_map->item, 1))) {
         echo 'no';
         return;
     }
     if ($this->data->action_map->prix && is_numeric($this->data->action_map->prix) && $this->user->argent >= $this->data->action_map->prix) {
         $this->user->argent -= $this->data->action_map->prix;
     }
     if (!$this->data->action_map->prix || $this->user->argent >= $this->data->action_map->prix) {
         $this->user->positionX = $this->data->action_map->x_move * 50 + 25;
         $this->user->positionY = $this->data->action_map->y_move * 50 + 25;
         $this->user->positionZ = $this->data->action_map->z_move * 50 + 25;
         $this->user->region_id = $this->data->action_map->id_region_move;
         $this->user->update();
         History_Model::instance()->user_insert($this->user->id, $this->data->id, $this->data->action_map->id_region_move, 'change_map');
         echo '<script>window.location.reload();</script>';
     }
 }
コード例 #6
0
ファイル: item.php プロジェクト: qboy1987/mooiyou
 /**
  * Find the position of the given item in its parent album.  The resulting
  * value is 1-indexed, so the first child in the album is at position 1.
  *
  * @param Item_Model $item
  * @param array      $where an array of arrays, each compatible with ORM::where()
  */
 static function get_position($item, $where = array())
 {
     $album = $item->parent();
     if (!strcasecmp($album->sort_order, "DESC")) {
         $comp = ">";
     } else {
         $comp = "<";
     }
     $query_model = ORM::factory("item");
     // If the comparison column has NULLs in it, we can't use comparators on it
     // and will have to deal with it the hard way.
     $count = $query_model->viewable()->where("parent_id", "=", $album->id)->where($album->sort_column, "IS", null)->merge_where($where)->count_all();
     if (empty($count)) {
         // There are no NULLs in the sort column, so we can just use it directly.
         $sort_column = $album->sort_column;
         $position = $query_model->viewable()->where("parent_id", "=", $album->id)->where($sort_column, $comp, $item->{$sort_column})->merge_where($where)->count_all();
         // We stopped short of our target value in the sort (notice that we're
         // using a inequality comparator above) because it's possible that we have
         // duplicate values in the sort column.  An equality check would just
         // arbitrarily pick one of those multiple possible equivalent columns,
         // which would mean that if you choose a sort order that has duplicates,
         // it'd pick any one of them as the child's "position".
         //
         // Fix this by doing a 2nd query where we iterate over the equivalent
         // columns and add them to our position count.
         foreach ($query_model->viewable()->select("id")->where("parent_id", "=", $album->id)->where($sort_column, "=", $item->{$sort_column})->merge_where($where)->order_by(array("id" => "ASC"))->find_all() as $row) {
             $position++;
             if ($row->id == $item->id) {
                 break;
             }
         }
     } else {
         // There are NULLs in the sort column, so we can't use MySQL comparators.
         // Fall back to iterating over every child row to get to the current one.
         // This can be wildly inefficient for really large albums, but it should
         // be a rare case that the user is sorting an album with null values in
         // the sort column.
         //
         // Reproduce the children() functionality here using Database directly to
         // avoid loading the whole ORM for each row.
         $order_by = array($album->sort_column => $album->sort_order);
         // Use id as a tie breaker
         if ($album->sort_column != "id") {
             $order_by["id"] = "ASC";
         }
         $position = 0;
         foreach ($query_model->viewable()->select("id")->where("parent_id", "=", $album->id)->merge_where($where)->order_by($order_by)->find_all() as $row) {
             $position++;
             if ($row->id == $item->id) {
                 break;
             }
         }
     }
     return $position;
 }
コード例 #7
0
 /**
  * Rebuild the thumb and resize for the given item.
  * @param Item_Model $item
  */
 static function generate($item)
 {
     if ($item->is_album()) {
         if (!($cover = $item->album_cover())) {
             // This album has no cover; there's nothing to generate.  Because of an old bug, it's
             // possible that there's an album cover item id that points to an invalid item.  In that
             // case, just null out the album cover item id.  It's not optimal to do that at this low
             // level, but it's not trivial to find these cases quickly in an upgrade script and if we
             // don't do this, the album may be permanently marked as "needs rebuilding"
             //
             // ref: http://sourceforge.net/apps/trac/gallery/ticket/1172
             //      http://gallery.menalto.com/node/96926
             if ($item->album_cover_item_id) {
                 $item->album_cover_item_id = null;
                 $item->save();
             }
             return;
         }
         $input_file = $cover->file_path();
         $input_item = $cover;
     } else {
         $input_file = $item->file_path();
         $input_item = $item;
     }
     if ($item->thumb_dirty) {
         $ops["thumb"] = $item->thumb_path();
     }
     if ($item->resize_dirty && !$item->is_album() && !$item->is_movie()) {
         $ops["resize"] = $item->resize_path();
     }
     if (empty($ops)) {
         $item->thumb_dirty = 0;
         $item->resize_dirty = 0;
         $item->save();
         return;
     }
     try {
         foreach ($ops as $target => $output_file) {
             if ($input_item->is_movie()) {
                 // Convert the movie filename to a JPG first, delete anything that might already be there
                 $output_file = legal_file::change_extension($output_file, "jpg");
                 unlink($output_file);
                 // Run movie_extract_frame events, which can either:
                 //  - generate an output file, bypassing the ffmpeg-based movie::extract_frame
                 //  - add to the options sent to movie::extract_frame (e.g. change frame extract time,
                 //    add de-interlacing arguments to ffmpeg... see movie helper for more info)
                 // Note that the args are similar to those of the events in gallery_graphics
                 $movie_options_wrapper = new stdClass();
                 $movie_options_wrapper->movie_options = array();
                 module::event("movie_extract_frame", $input_file, $output_file, $movie_options_wrapper, $input_item);
                 // If no output_file generated by events, run movie::extract_frame with movie_options
                 clearstatcache();
                 if (@filesize($output_file) == 0) {
                     try {
                         movie::extract_frame($input_file, $output_file, $movie_options_wrapper->movie_options);
                     } catch (Exception $e) {
                         // Didn't work, likely because of MISSING_FFMPEG - copy missing_movie instead
                         copy(MODPATH . "gallery/images/missing_movie.jpg", $output_file);
                     }
                 }
                 $working_file = $output_file;
             } else {
                 $working_file = $input_file;
             }
             foreach (self::_get_rules($target) as $rule) {
                 $args = array($working_file, $output_file, unserialize($rule->args), $item);
                 call_user_func_array($rule->operation, $args);
                 $working_file = $output_file;
             }
         }
         if (!empty($ops["thumb"])) {
             if (file_exists($item->thumb_path())) {
                 $item->thumb_dirty = 0;
             } else {
                 copy(MODPATH . "gallery/images/missing_photo.png", $item->thumb_path());
             }
             $dims = getimagesize($item->thumb_path());
             $item->thumb_width = $dims[0];
             $item->thumb_height = $dims[1];
         }
         if (!empty($ops["resize"])) {
             if (file_exists($item->resize_path())) {
                 $item->resize_dirty = 0;
             } else {
                 copy(MODPATH . "gallery/images/missing_photo.png", $item->resize_path());
             }
             $dims = getimagesize($item->resize_path());
             $item->resize_width = $dims[0];
             $item->resize_height = $dims[1];
         }
         $item->save();
     } catch (Exception $e) {
         // Something went wrong rebuilding the image.  Leave it dirty and move on.
         // @todo we should handle this better.
         Kohana_Log::add("error", "Caught exception rebuilding image: {$item->title}\n" . $e->getMessage() . "\n" . $e->getTraceAsString());
         throw $e;
     }
 }
コード例 #8
0
ファイル: graphics.php プロジェクト: HarriLu/gallery3
 /**
  * Rebuild the thumb and resize for the given item.
  * @param Item_Model $item
  */
 static function generate($item)
 {
     if ($item->thumb_dirty) {
         $ops["thumb"] = $item->thumb_path();
     }
     if ($item->resize_dirty && $item->is_photo()) {
         $ops["resize"] = $item->resize_path();
     }
     try {
         foreach ($ops as $target => $output_file) {
             $working_file = $item->file_path();
             // Delete anything that might already be there
             @unlink($output_file);
             switch ($item->type) {
                 case "movie":
                     // Run movie_extract_frame events, which can either:
                     //  - generate an output file, bypassing the ffmpeg-based movie::extract_frame
                     //  - add to the options sent to movie::extract_frame (e.g. change frame extract time,
                     //    add de-interlacing arguments to ffmpeg... see movie helper for more info)
                     // Note that the args are similar to those of the events in gallery_graphics
                     $movie_options_wrapper = new stdClass();
                     $movie_options_wrapper->movie_options = array();
                     module::event("movie_extract_frame", $working_file, $output_file, $movie_options_wrapper, $item);
                     // If no output_file generated by events, run movie::extract_frame with movie_options
                     clearstatcache();
                     if (@filesize($output_file) == 0) {
                         try {
                             movie::extract_frame($working_file, $output_file, $movie_options_wrapper->movie_options);
                             // If we're here, we know ffmpeg is installed and the movie is valid.  Because the
                             // user may not always have had ffmpeg installed, the movie's width, height, and
                             // mime type may need updating.  Let's use this opportunity to make sure they're
                             // correct.  It's not optimal to do it at this low level, but it's not trivial to find
                             // these cases quickly in an upgrade script.
                             list($width, $height, $mime_type) = movie::get_file_metadata($working_file);
                             // Only set them if they need updating to avoid marking them as "changed"
                             if ($item->width != $width || $item->height != $height || $item->mime_type != $mime_type) {
                                 $item->width = $width;
                                 $item->height = $height;
                                 $item->mime_type = $mime_type;
                             }
                         } catch (Exception $e) {
                             // Didn't work, likely because of MISSING_FFMPEG - use placeholder
                             graphics::_replace_image_with_placeholder($item, $target);
                             break;
                         }
                     }
                     $working_file = $output_file;
                 case "photo":
                     // Run the graphics rules (for both movies and photos)
                     foreach (self::_get_rules($target) as $rule) {
                         $args = array($working_file, $output_file, unserialize($rule->args), $item);
                         call_user_func_array($rule->operation, $args);
                         $working_file = $output_file;
                     }
                     break;
                 case "album":
                     if (!($cover = $item->album_cover())) {
                         // This album has no cover; copy its placeholder image.  Because of an old bug, it's
                         // possible that there's an album cover item id that points to an invalid item.  In that
                         // case, just null out the album cover item id.  It's not optimal to do that at this low
                         // level, but it's not trivial to find these cases quickly in an upgrade script and if we
                         // don't do this, the album may be permanently marked as "needs rebuilding"
                         //
                         // ref: http://sourceforge.net/apps/trac/gallery/ticket/1172
                         //      http://galleryproject.org/node/96926
                         if ($item->album_cover_item_id) {
                             $item->album_cover_item_id = null;
                             $item->save();
                         }
                         graphics::_replace_image_with_placeholder($item, $target);
                         break;
                     }
                     if ($cover->thumb_dirty) {
                         graphics::generate($cover);
                     }
                     if (!$cover->thumb_dirty) {
                         // Make the album cover from the cover item's thumb.  Run gallery_graphics::resize with
                         // null options and it will figure out if this is a direct copy or conversion to jpg.
                         $working_file = $cover->thumb_path();
                         gallery_graphics::resize($working_file, $output_file, null, $item);
                     }
                     break;
             }
         }
         if (!empty($ops["thumb"])) {
             if (file_exists($item->thumb_path())) {
                 $item->thumb_dirty = 0;
             } else {
                 Kohana_Log::add("error", "Failed to rebuild thumb image: {$item->title}");
                 graphics::_replace_image_with_placeholder($item, "thumb");
             }
         }
         if (!empty($ops["resize"])) {
             if (file_exists($item->resize_path())) {
                 $item->resize_dirty = 0;
             } else {
                 Kohana_Log::add("error", "Failed to rebuild resize image: {$item->title}");
                 graphics::_replace_image_with_placeholder($item, "resize");
             }
         }
         graphics::_update_item_dimensions($item);
         $item->save();
     } catch (Exception $e) {
         // Something went wrong rebuilding the image.  Replace with the placeholder images,
         // leave it dirty and move on.
         Kohana_Log::add("error", "Caught exception rebuilding images: {$item->title}\n" . $e->getMessage() . "\n" . $e->getTraceAsString());
         if ($item->is_photo()) {
             graphics::_replace_image_with_placeholder($item, "resize");
         }
         graphics::_replace_image_with_placeholder($item, "thumb");
         try {
             graphics::_update_item_dimensions($item);
         } catch (Exception $e) {
             // Looks like get_file_metadata couldn't identify our placeholders.  We should never get
             // here, but in the odd case we do, we need to do something.  Let's put in hardcoded values.
             if ($item->is_photo()) {
                 list($item->resize_width, $item->resize_height) = array(200, 200);
             }
             list($item->thumb_width, $item->thumb_height) = array(200, 200);
         }
         $item->save();
         throw $e;
     }
 }
コード例 #9
0
ファイル: users.php プロジェクト: ezioms/RpgEditor
 /**
  * Methode : sauver les données d'un user et de ses objets
  */
 public function save_items($idUser)
 {
     $this->auto_render = FALSE;
     if (!request::is_ajax()) {
         return false;
     }
     if (($value = $this->input->post('item')) !== FALSE) {
         $item = Item_Model::instance();
         $item->user_delete_all($idUser);
         foreach ($value as $key => $row) {
             if ($row > 0) {
                 for ($n = 0; $n < $row; $n++) {
                     $item->user_insert($idUser, $key);
                 }
             }
         }
     }
 }
コード例 #10
0
ファイル: admin_item.php プロジェクト: ezioms/RpgEditor
 /**
  * Méthode :
  */
 public function index(&$view)
 {
     $view->items = Item_Model::instance()->select();
 }
コード例 #11
0
ファイル: item.php プロジェクト: jhilden/gallery3
 /**
  * Move this item to the specified target.
  * @chainable
  * @param   Item_Model $target  Target item (must be an album)
  * @return  ORM_MPTT
  */
 function move_to($target)
 {
     if (!$target->is_album()) {
         throw new Exception("@todo INVALID_MOVE_TYPE {$target->type}");
     }
     if ($this->id == 1) {
         throw new Exception("@todo INVALID_SOURCE root album");
     }
     $original_path = $this->file_path();
     $original_resize_path = $this->resize_path();
     $original_thumb_path = $this->thumb_path();
     $original_parent = $this->parent();
     parent::move_to($target, true);
     model_cache::clear();
     $this->relative_path_cache = null;
     rename($original_path, $this->file_path());
     if ($this->is_album()) {
         @rename(dirname($original_resize_path), dirname($this->resize_path()));
         @rename(dirname($original_thumb_path), dirname($this->thumb_path()));
         Database::instance()->update("items", array("relative_path_cache" => null), array("left_ptr >" => $this->left_ptr, "right_ptr <" => $this->right_ptr));
     } else {
         @rename($original_resize_path, $this->resize_path());
         @rename($original_thumb_path, $this->thumb_path());
     }
     module::event("item_moved", $this, $original_parent);
     return $this;
 }
コード例 #12
0
ファイル: map.php プロジェクト: ezioms/RpgEditor
 /**
  * Générer un JSON
  *
  * @return void
  */
 public function index($render = TRUE)
 {
     $json = new View('map/json');
     $json->my = $this->user;
     if (!($this->region = Region_Model::instance()->select(array('id' => $this->user->region_id), 1))) {
         return FALSE;
     }
     $json->items = Item_Model::instance()->select();
     $elements = $modules = $items = FALSE;
     if (($rows = Map_Model::instance()->select(array('region_id' => $this->region->id), FALSE)) !== FALSE) {
         $prenoms = Name_Model::instance()->select();
         $listName = array();
         foreach ($prenoms as $prenom) {
             $listName[] = ucfirst(mb_strtolower($prenom->prenom));
         }
         $images = file::listing_dir(DOCROOT . 'images/character');
         foreach ($rows as $row) {
             if (!$row->module_map && !$row->bot) {
                 $elements[] = '{"x" : ' . $row->x . ', "z" : ' . $row->z . ', "y" : ' . $row->y . ', "subX" : ' . $row->subX . ', "subZ" : ' . $row->subZ . ', "subY" : ' . $row->subY . ', "materials" : [ "' . $row->background_px . '", "' . $row->background_nx . '", "' . $row->background_py . '", "' . $row->background_ny . '", "' . $row->background_pz . '", "' . $row->background_nz . '"	] }';
             } else {
                 $data = @unserialize($row->action_map);
                 $action = json_encode($data);
                 if ($row->module_map == 'article') {
                     $article = Article_Model::instance()->select(array('id_article' => $data->id_article, 'article_category_id' => 2, 'status' => 1), 1);
                     $modules[] = '{"x" : ' . $row->x . ', "z" : ' . $row->z . ', "y" : ' . $row->y . ', "subX" : ' . $row->subX . ', "subZ" : ' . $row->subZ . ', "subY" : ' . $row->subY . ', "data" : ' . $action . ', "article" : ' . json_encode($article->article) . ' }';
                 } elseif ($row->bot) {
                     $v = new stdClass();
                     $v->id = 0;
                     $v->name = $row->bot ? $row->title : $listName[array_rand($listName)];
                     $v->x = $row->x;
                     $v->y = $row->y;
                     $v->z = $row->z;
                     $v->region_id = $row->region_id;
                     $v->user_id = $this->user->id;
                     if ($row->bot == 2) {
                         $v->image = 'animals/bears.png';
                     } elseif ($row->bot == 3) {
                         $v->image = 'animals/dog.png';
                     } else {
                         $v->image = 'character/' . $images[array_rand($images)];
                     }
                     $v->hp_max = 100;
                     $v->hp = 100;
                     $v->leak = 0;
                     $v->type = $row->bot;
                     $v->fixe = $row->bot && !$row->module_map ? 0 : 1;
                     $v->argent = 1000;
                     $v->xp = 10;
                     $v->niveau = 0;
                     $this->botFixe[] = $v;
                     if ($row->module_map == 'quete') {
                         $modules[] = '{"x" : ' . $row->x . ', "z" : ' . $row->z . ', "y" : ' . ($row->y - 1) . ', "subX" : ' . $row->subX . ', "subZ" : ' . $row->subZ . ', "subY" : ' . $row->subY . ', "data" : ' . $action . ', "article" : "" }';
                     }
                 } else {
                     $modules[] = '{"x" : ' . $row->x . ', "z" : ' . $row->z . ', "y" : ' . ($row->y - 1) . ', "subX" : ' . $row->subX . ', "subZ" : ' . $row->subZ . ', "subY" : ' . $row->subY . ', "data" : ' . $action . ', "article" : "" }';
                 }
             }
         }
     }
     $articles = Article_Model::instance()->select(array('region_id' => $this->region->id, 'article_category_id' => 2, 'status' => 1));
     $articlesList = null;
     if ($articles) {
         foreach ($articles as $row) {
             $articlesList[] = json_encode($row->reponse ? $row->article . '<div class="reponse">' . $row->reponse . '</div>' : $row->article);
         }
     }
     $this->region->map = new stdClass();
     $this->region->map->region = $this->region;
     $this->region->map->elements = $elements ? implode(',', $elements) : FALSE;
     $this->region->map->modules = $modules ? implode(',', $modules) : FALSE;
     $this->region->map->articles = $articlesList ? implode(',', $articlesList) : FALSE;
     $this->region->map->region->bots = $this->botFixe;
     $json->region = $this->region;
     $sounds = file::listing_dir(DOCROOT . 'audios', array('home.mp3'));
     $json->sounds = $sounds ? json_encode($sounds) : FALSE;
     return $json->render($render);
 }
コード例 #13
0
ファイル: graphics.php プロジェクト: JasonWiki/docs
 /**
  * Rebuild the thumb and resize for the given item.
  * @param Item_Model $item
  */
 static function generate($item)
 {
     if ($item->is_album()) {
         if (!($cover = $item->album_cover())) {
             // This album has no cover; there's nothing to generate.  Because of an old bug, it's
             // possible that there's an album cover item id that points to an invalid item.  In that
             // case, just null out the album cover item id.  It's not optimal to do that at this low
             // level, but it's not trivial to find these cases quickly in an upgrade script and if we
             // don't do this, the album may be permanently marked as "needs rebuilding"
             //
             // ref: http://sourceforge.net/apps/trac/gallery/ticket/1172
             //      http://gallery.menalto.com/node/96926
             if ($item->album_cover_item_id) {
                 $item->album_cover_item_id = null;
                 $item->save();
             }
             return;
         }
         $input_file = $cover->file_path();
         $input_item = $cover;
     } else {
         $input_file = $item->file_path();
         $input_item = $item;
     }
     if ($item->thumb_dirty) {
         $ops["thumb"] = $item->thumb_path();
     }
     if ($item->resize_dirty && !$item->is_album() && !$item->is_movie()) {
         $ops["resize"] = $item->resize_path();
     }
     if (empty($ops)) {
         $item->thumb_dirty = 0;
         $item->resize_dirty = 0;
         $item->save();
         return;
     }
     try {
         foreach ($ops as $target => $output_file) {
             if ($input_item->is_movie()) {
                 // Convert the movie to a JPG first
                 $output_file = legal_file::change_extension($output_file, "jpg");
                 try {
                     movie::extract_frame($input_file, $output_file);
                 } catch (Exception $e) {
                     // Assuming this is MISSING_FFMPEG for now
                     copy(MODPATH . "gallery/images/missing_movie.jpg", $output_file);
                 }
                 $working_file = $output_file;
             } else {
                 $working_file = $input_file;
             }
             foreach (self::_get_rules($target) as $rule) {
                 $args = array($working_file, $output_file, unserialize($rule->args), $item);
                 call_user_func_array($rule->operation, $args);
                 $working_file = $output_file;
             }
         }
         if (!empty($ops["thumb"])) {
             if (file_exists($item->thumb_path())) {
                 $item->thumb_dirty = 0;
             } else {
                 copy(MODPATH . "gallery/images/missing_photo.png", $item->thumb_path());
             }
             $dims = getimagesize($item->thumb_path());
             $item->thumb_width = $dims[0];
             $item->thumb_height = $dims[1];
         }
         if (!empty($ops["resize"])) {
             if (file_exists($item->resize_path())) {
                 $item->resize_dirty = 0;
             } else {
                 copy(MODPATH . "gallery/images/missing_photo.png", $item->resize_path());
             }
             $dims = getimagesize($item->resize_path());
             $item->resize_width = $dims[0];
             $item->resize_height = $dims[1];
         }
         $item->save();
     } catch (Exception $e) {
         // Something went wrong rebuilding the image.  Leave it dirty and move on.
         // @todo we should handle this better.
         Kohana_Log::add("error", "Caught exception rebuilding image: {$item->title}\n" . $e->getMessage() . "\n" . $e->getTraceAsString());
         throw $e;
     }
 }
コード例 #14
0
ファイル: items.php プロジェクト: ezioms/RpgEditor
 public function __construct()
 {
     parent::__construct();
     parent::access('item');
     $this->item = Item_Model::instance();
 }
コード例 #15
0
ファイル: item.php プロジェクト: viosca/gallery3
 /**
  * Move this item to the specified target.
  * @chainable
  * @param   Item_Model $target  Target item (must be an album)
  * @return  ORM_MPTT
  */
 function move_to($target)
 {
     if (!$target->is_album()) {
         throw new Exception("@todo INVALID_MOVE_TYPE {$target->type}");
     }
     if (file_exists($target_file = "{$target->file_path()}/{$this->name}")) {
         throw new Exception("@todo INVALID_MOVE_TARGET_EXISTS: {$target_file}");
     }
     if ($this->id == 1) {
         throw new Exception("@todo INVALID_SOURCE root album");
     }
     $original_path = $this->file_path();
     $original_resize_path = $this->resize_path();
     $original_thumb_path = $this->thumb_path();
     $original_parent = $this->parent();
     parent::move_to($target, true);
     model_cache::clear();
     $this->relative_path_cache = null;
     rename($original_path, $this->file_path());
     if ($this->is_album()) {
         @rename(dirname($original_resize_path), dirname($this->resize_path()));
         @rename(dirname($original_thumb_path), dirname($this->thumb_path()));
         db::build()->update("items")->set("relative_path_cache", null)->set("relative_url_cache", null)->where("left_ptr", ">", $this->left_ptr)->where("right_ptr", "<", $this->right_ptr)->execute();
     } else {
         @rename($original_resize_path, $this->resize_path());
         @rename($original_thumb_path, $this->thumb_path());
     }
     module::event("item_moved", $this, $original_parent);
     return $this;
 }
コード例 #16
0
ファイル: access.php プロジェクト: hiwilson/gallery3
 /**
  * Add new access rows when a new item is added.
  *
  * @param Item_Model $item
  * @return void
  */
 static function add_item($item)
 {
     $access_intent = ORM::factory("access_intent", $item->id);
     if ($access_intent->loaded) {
         throw new Exception("@todo ITEM_ALREADY_ADDED {$item->id}");
     }
     $access_intent = ORM::factory("access_intent");
     $access_intent->item_id = $item->id;
     $access_intent->save();
     // Create a new access cache entry and copy the parents values.
     $access_cache = ORM::factory("access_cache");
     $access_cache->item_id = $item->id;
     if ($item->id != 1) {
         $parent_access_cache = ORM::factory("access_cache")->where("item_id", $item->parent()->id)->find();
         foreach (self::_get_all_groups() as $group) {
             foreach (ORM::factory("permission")->find_all() as $perm) {
                 $field = "{$perm->name}_{$group->id}";
                 if ($perm->name == "view") {
                     $item->{$field} = $item->parent()->{$field};
                 } else {
                     $access_cache->{$field} = $parent_access_cache->{$field};
                 }
             }
         }
     }
     $item->save();
     $access_cache->save();
 }
コード例 #17
0
ファイル: ORM_MPTT.php プロジェクト: eo04837/gallery3
 /**
  * Move this item to the specified target.
  *
  * @chainable
  * @param   Item_Model $target Target node
  * @return  ORM_MTPP
  */
 function move_to($target)
 {
     if ($this->left_ptr <= $target->left_ptr && $this->right_ptr >= $target->right_ptr) {
         throw new Exception("@todo INVALID_TARGET can't move item inside itself");
     }
     $number_to_move = (int) (($this->right_ptr - $this->left_ptr) / 2 + 1);
     $size_of_hole = $number_to_move * 2;
     $original_left_ptr = $this->left_ptr;
     $original_right_ptr = $this->right_ptr;
     $target_right_ptr = $target->right_ptr;
     $level_delta = $target->level + 1 - $this->level;
     $this->lock();
     try {
         if ($level_delta) {
             // Update the levels for the to-be-moved items
             $this->db->query("UPDATE {{$this->table_name}} SET `level` = `level` + {$level_delta}" . " WHERE `left_ptr` >= {$original_left_ptr} AND `right_ptr` <= {$original_right_ptr}");
         }
         // Make a hole in the target for the move
         $target->db->query("UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` + {$size_of_hole}" . " WHERE `left_ptr` >= {$target_right_ptr}");
         $target->db->query("UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` + {$size_of_hole}" . " WHERE `right_ptr` >= {$target_right_ptr}");
         // Change the parent.
         $this->db->query("UPDATE {{$this->table_name}} SET `parent_id` = {$target->id}" . " WHERE `id` = {$this->id}");
         // If the source is to the right of the target then we just adjusted its left_ptr and right_ptr above.
         $left_ptr = $original_left_ptr;
         $right_ptr = $original_right_ptr;
         if ($original_left_ptr > $target_right_ptr) {
             $left_ptr += $size_of_hole;
             $right_ptr += $size_of_hole;
         }
         $new_offset = $target->right_ptr - $left_ptr;
         $this->db->query("UPDATE {{$this->table_name}}" . "   SET `left_ptr` = `left_ptr` + {$new_offset}," . "       `right_ptr` = `right_ptr` + {$new_offset}" . " WHERE `left_ptr` >= {$left_ptr}" . "   AND `right_ptr` <= {$right_ptr}");
         // Close the hole in the source's parent after the move
         $this->db->query("UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` - {$size_of_hole}" . " WHERE `left_ptr` > {$right_ptr}");
         $this->db->query("UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` - {$size_of_hole}" . " WHERE `right_ptr` > {$right_ptr}");
     } catch (Exception $e) {
         $this->unlock();
         throw $e;
     }
     $this->unlock();
     // Lets reload to get the changes.
     $this->reload();
     $target->reload();
     return $this;
 }
コード例 #18
0
ファイル: graphics.php プロジェクト: viosca/gallery3
 /**
  * Rebuild the thumb and resize for the given item.
  * @param Item_Model $item
  */
 static function generate($item)
 {
     if ($item->is_album()) {
         if (!($cover = $item->album_cover())) {
             // This album has no cover; there's nothing to generate.
             return;
         }
         $input_file = $cover->file_path();
         $input_item = $cover;
     } else {
         $input_file = $item->file_path();
         $input_item = $item;
     }
     if ($item->thumb_dirty) {
         $ops["thumb"] = $item->thumb_path();
     }
     if ($item->resize_dirty && !$item->is_album() && !$item->is_movie()) {
         $ops["resize"] = $item->resize_path();
     }
     if (empty($ops)) {
         $item->thumb_dirty = 0;
         $item->resize_dirty = 0;
         $item->save();
         return;
     }
     try {
         foreach ($ops as $target => $output_file) {
             if ($input_item->is_movie()) {
                 // Convert the movie to a JPG first
                 $output_file = preg_replace("/...\$/", "jpg", $output_file);
                 try {
                     movie::extract_frame($input_file, $output_file);
                 } catch (Exception $e) {
                     // Assuming this is MISSING_FFMPEG for now
                     copy(MODPATH . "gallery/images/missing_movie.png", $output_file);
                 }
                 $working_file = $output_file;
             } else {
                 $working_file = $input_file;
             }
             foreach (self::_get_rules($target) as $rule) {
                 $args = array($working_file, $output_file, unserialize($rule->args));
                 call_user_func_array($rule->operation, $args);
                 $working_file = $output_file;
             }
         }
         if (!empty($ops["thumb"])) {
             $dims = getimagesize($item->thumb_path());
             $item->thumb_width = $dims[0];
             $item->thumb_height = $dims[1];
             $item->thumb_dirty = 0;
         }
         if (!empty($ops["resize"])) {
             $dims = getimagesize($item->resize_path());
             $item->resize_width = $dims[0];
             $item->resize_height = $dims[1];
             $item->resize_dirty = 0;
         }
         $item->save();
     } catch (Exception $e) {
         // Something went wrong rebuilding the image.  Leave it dirty and move on.
         // @todo we should handle this better.
         Kohana_Log::add("error", "Caught exception rebuilding image: {$item->title}\n" . $e->getMessage() . "\n" . $e->getTraceAsString());
         throw $e;
     }
 }
コード例 #19
0
ファイル: graphics.php プロジェクト: hiwilson/gallery3
 /**
  * Rebuild the thumb and resize for the given item.
  * @param Item_Model $item
  * @return true on successful generation
  */
 static function generate($item)
 {
     if ($item->is_album()) {
         if (!($cover = $item->album_cover())) {
             return false;
         }
         $input_file = $cover->file_path();
         $input_item = $cover;
     } else {
         $input_file = $item->file_path();
         $input_item = $item;
     }
     if ($item->thumb_dirty) {
         $ops["thumb"] = $item->thumb_path();
     }
     if ($item->resize_dirty && !$item->is_album() && !$item->is_movie()) {
         $ops["resize"] = $item->resize_path();
     }
     if (empty($ops)) {
         $item->thumb_dirty = 0;
         $item->resize_dirty = 0;
         $item->save();
         return true;
     }
     try {
         foreach ($ops as $target => $output_file) {
             if ($input_item->is_movie()) {
                 // Convert the movie to a JPG first
                 $output_file = preg_replace("/...\$/", "jpg", $output_file);
                 try {
                     movie::extract_frame($input_file, $output_file);
                 } catch (Exception $e) {
                     // Assuming this is MISSING_FFMPEG for now
                     copy(MODPATH . "gallery/images/missing_movie.png", $output_file);
                 }
                 $working_file = $output_file;
             } else {
                 $working_file = $input_file;
             }
             foreach (ORM::factory("graphics_rule")->where("target", $target)->where("active", true)->orderby("priority", "asc")->find_all() as $rule) {
                 $args = array($working_file, $output_file, unserialize($rule->args));
                 call_user_func_array(array("graphics", $rule->operation), $args);
                 $working_file = $output_file;
             }
         }
         if (!empty($ops["thumb"])) {
             $dims = getimagesize($item->thumb_path());
             $item->thumb_width = $dims[0];
             $item->thumb_height = $dims[1];
             $item->thumb_dirty = 0;
         }
         if (!empty($ops["resize"])) {
             $dims = getimagesize($item->resize_path());
             $item->resize_width = $dims[0];
             $item->resize_height = $dims[1];
             $item->resize_dirty = 0;
         }
         $item->save();
     } catch (Exception $e) {
         // Something went wrong rebuilding the image.  Leave it dirty and move on.
         // @todo we should handle this better.
         Kohana::log("error", "Caught exception rebuilding image: {$item->title}\n" . $e->getMessage() . "\n" . $e->getTraceAsString());
         return false;
     }
     return true;
 }
コード例 #20
0
ファイル: aws_s3.php プロジェクト: webmatter/gallery3-contrib
 static function base64_filename(Item_Model $item)
 {
     $file_path = explode("/", $item->relative_path());
     return base64_encode(end($file_path));
 }