当前位置: 首页>>代码示例>>PHP>>正文


PHP item::convert_filename_to_slug方法代码示例

本文整理汇总了PHP中item::convert_filename_to_slug方法的典型用法代码示例。如果您正苦于以下问题:PHP item::convert_filename_to_slug方法的具体用法?PHP item::convert_filename_to_slug怎么用?PHP item::convert_filename_to_slug使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在item的用法示例。


在下文中一共展示了item::convert_filename_to_slug方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fix_internet_addresses

 static function fix_internet_addresses($task)
 {
     $start = microtime(true);
     $total = $task->get("total");
     if (empty($total)) {
         $task->set("total", $total = db::build()->count_records("items"));
         $task->set("last_id", 0);
         $task->set("completed", 0);
     }
     $last_id = $task->get("last_id");
     $completed = $task->get("completed");
     foreach (ORM::factory("item")->where("id", ">", $last_id)->find_all(100) as $item) {
         $item->slug = item::convert_filename_to_slug($item->slug);
         $item->save();
         $last_id = $item->id;
         $completed++;
         if ($completed == $total || microtime(true) - $start > 1.5) {
             break;
         }
     }
     $task->set("completed", $completed);
     $task->set("last_id", $last_id);
     if ($total == $completed) {
         $task->done = true;
         $task->state = "success";
         $task->percent_complete = 100;
         db::build()->update("items")->set("relative_path_cache", null)->set("relative_url_cache", null)->execute();
     } else {
         $task->percent_complete = round(100 * $completed / $total);
     }
     $task->status = t2("One row updated", "%count / %total rows updated", $completed, array("total" => $total));
 }
开发者ID:Weerwolf,项目名称:gallery3-contrib,代码行数:32,代码来源:rescue_task.php

示例2: convert_filename_to_slug_test

 public function convert_filename_to_slug_test()
 {
     $this->assert_equal("foo", item::convert_filename_to_slug("{[foo]}"));
     $this->assert_equal("foo-bar", item::convert_filename_to_slug("{[foo!@#!\$@#^\$@(\$!(@bar]}"));
     $this->assert_equal("english-text", item::convert_filename_to_slug("english text"));
     $this->assert_equal("new-line", item::convert_filename_to_slug("new \n line"));
     $this->assert_equal("foo-and-bar", item::convert_filename_to_slug("foo&bar"));
     $this->assert_equal("special", item::convert_filename_to_slug("šṗëçîąļ"));
 }
开发者ID:assad2012,项目名称:gallery3-appfog,代码行数:9,代码来源:Item_Helper_Test.php

示例3: create

 /**
  * Create a new album.
  * @param integer $parent_id id of parent album
  * @param string  $name the name of this new album (it will become the directory name on disk)
  * @param integer $title the title of the new album
  * @param string  $description (optional) the longer description of this album
  * @param string  $slug (optional) the url component for this photo
  * @return Item_Model
  */
 static function create($parent, $name, $title, $description = null, $owner_id = null, $slug = null)
 {
     if (!$parent->loaded || !$parent->is_album()) {
         throw new Exception("@todo INVALID_PARENT");
     }
     if (strpos($name, "/")) {
         throw new Exception("@todo NAME_CANNOT_CONTAIN_SLASH");
     }
     // We don't allow trailing periods as a security measure
     // ref: http://dev.kohanaphp.com/issues/684
     if (rtrim($name, ".") != $name) {
         throw new Exception("@todo NAME_CANNOT_END_IN_PERIOD");
     }
     if (empty($slug)) {
         $slug = item::convert_filename_to_slug($name);
     }
     $album = ORM::factory("item");
     $album->type = "album";
     $album->title = $title;
     $album->description = $description;
     $album->name = $name;
     $album->owner_id = $owner_id;
     $album->thumb_dirty = 1;
     $album->resize_dirty = 1;
     $album->slug = $slug;
     $album->rand_key = (double) mt_rand() / (double) mt_getrandmax();
     $album->sort_column = "created";
     $album->sort_order = "ASC";
     // Randomize the name or slug if there's a conflict
     // @todo Improve this.  Random numbers are not user friendly
     while (ORM::factory("item")->where("parent_id", $parent->id)->open_paren()->where("name", $album->name)->orwhere("slug", $album->slug)->close_paren()->find()->id) {
         $rand = rand();
         $album->name = "{$name}-{$rand}";
         $album->slug = "{$slug}-{$rand}";
     }
     $album = $album->add_to_parent($parent);
     mkdir($album->file_path());
     mkdir(dirname($album->thumb_path()));
     mkdir(dirname($album->resize_path()));
     // @todo: publish this from inside Item_Model::save() when we refactor to the point where
     // there's only one save() happening here.
     module::event("item_created", $album);
     return $album;
 }
开发者ID:brocki,项目名称:gallery3,代码行数:53,代码来源:album.php

示例4: upgrade


//.........这里部分代码省略.........
         }
         module::set_version("gallery", $version = 18);
     }
     // Rename blocks_site.sidebar to blocks_site_sidebar
     if ($version == 18) {
         $blocks = block_manager::get_active("site.sidebar");
         block_manager::set_active("site_sidebar", $blocks);
         module::clear_var("gallery", "blocks_site.sidebar");
         module::set_version("gallery", $version = 19);
     }
     // Set a default for the number of simultaneous uploads
     // Version 20 was reverted in 57adefc5baa7a2b0dfcd3e736e80c2fa86d3bfa2, so skip it.
     if ($version == 19 || $version == 20) {
         module::set_var("gallery", "simultaneous_upload_limit", 5);
         module::set_version("gallery", $version = 21);
     }
     // Update the graphics rules table so that the maximum height for resizes is 640 not 480.
     // Fixes ticket #671
     if ($version == 21) {
         $resize_rule = ORM::factory("graphics_rule")->where("id", "=", "2")->find();
         // make sure it hasn't been changed already
         $args = unserialize($resize_rule->args);
         if ($args["height"] == 480 && $args["width"] == 640) {
             $args["height"] = 640;
             $resize_rule->args = serialize($args);
             $resize_rule->save();
         }
         module::set_version("gallery", $version = 22);
     }
     // Update slug values to be legal.  We should have done this in the 11->12 upgrader, but I was
     // lazy.  Mea culpa!
     if ($version == 22) {
         foreach (db::build()->from("items")->select("id", "slug")->where(db::expr("`slug` REGEXP '[^_A-Za-z0-9-]'"), "=", 1)->execute() as $row) {
             $new_slug = item::convert_filename_to_slug($row->slug);
             if (empty($new_slug)) {
                 $new_slug = random::int();
             }
             db::build()->update("items")->set("slug", $new_slug)->set("relative_url_cache", null)->where("id", "=", $row->id)->execute();
         }
         module::set_version("gallery", $version = 23);
     }
     if ($version == 23) {
         $db->query("CREATE TABLE {failed_logins} (\n                  `id` int(9) NOT NULL auto_increment,\n                  `count` int(9) NOT NULL,\n                  `name` varchar(255) NOT NULL,\n                  `time` int(9) NOT NULL,\n                  PRIMARY KEY (`id`))\n                  DEFAULT CHARSET=utf8;");
         module::set_version("gallery", $version = 24);
     }
     if ($version == 24) {
         foreach (array("logs", "tmp", "uploads") as $dir) {
             self::_protect_directory(VARPATH . $dir);
         }
         module::set_version("gallery", $version = 25);
     }
     if ($version == 25) {
         db::build()->update("items")->set("title", db::expr("`name`"))->and_open()->where("title", "IS", null)->or_where("title", "=", "")->close()->execute();
         module::set_version("gallery", $version = 26);
     }
     if ($version == 26) {
         if (in_array("failed_logins", Database::instance()->list_tables())) {
             $db->query("RENAME TABLE {failed_logins} TO {failed_auths}");
         }
         module::set_version("gallery", $version = 27);
     }
     if ($version == 27) {
         // Set the admin area timeout to 90 minutes
         module::set_var("gallery", "admin_area_timeout", 90 * 60);
         module::set_version("gallery", $version = 28);
     }
开发者ID:HarriLu,项目名称:gallery3,代码行数:67,代码来源:gallery_installer.php

示例5: upgrade


//.........这里部分代码省略.........
         }
         module::set_version("gallery", $version = 18);
     }
     // Rename blocks_site.sidebar to blocks_site_sidebar
     if ($version == 18) {
         $blocks = block_manager::get_active("site.sidebar");
         block_manager::set_active("site_sidebar", $blocks);
         module::clear_var("gallery", "blocks_site.sidebar");
         module::set_version("gallery", $version = 19);
     }
     // Set a default for the number of simultaneous uploads
     // Version 20 was reverted in 57adefc5baa7a2b0dfcd3e736e80c2fa86d3bfa2, so skip it.
     if ($version == 19 || $version == 20) {
         module::set_var("gallery", "simultaneous_upload_limit", 5);
         module::set_version("gallery", $version = 21);
     }
     // Update the graphics rules table so that the maximum height for resizes is 640 not 480.
     // Fixes ticket #671
     if ($version == 21) {
         $resize_rule = ORM::factory("graphics_rule")->where("id", "=", "2")->find();
         // make sure it hasn't been changed already
         $args = unserialize($resize_rule->args);
         if ($args["height"] == 480 && $args["width"] == 640) {
             $args["height"] = 640;
             $resize_rule->args = serialize($args);
             $resize_rule->save();
         }
         module::set_version("gallery", $version = 22);
     }
     // Update slug values to be legal.  We should have done this in the 11->12 upgrader, but I was
     // lazy.  Mea culpa!
     if ($version == 22) {
         foreach (db::build()->from("items")->select("id", "slug")->where(db::expr("`slug` REGEXP '[^_A-Za-z0-9-]'"), "=", 1)->execute() as $row) {
             $new_slug = item::convert_filename_to_slug($row->slug);
             if (empty($new_slug)) {
                 $new_slug = random::int();
             }
             db::build()->update("items")->set("slug", $new_slug)->set("relative_url_cache", null)->where("id", "=", $row->id)->execute();
         }
         module::set_version("gallery", $version = 23);
     }
     if ($version == 23) {
         $db->query("CREATE TABLE {failed_logins} (\n                  `id` int(9) NOT NULL auto_increment,\n                  `count` int(9) NOT NULL,\n                  `name` varchar(255) NOT NULL,\n                  `time` int(9) NOT NULL,\n                  PRIMARY KEY (`id`))\n                  DEFAULT CHARSET=utf8;");
         module::set_version("gallery", $version = 24);
     }
     if ($version == 24) {
         foreach (array("logs", "tmp", "uploads") as $dir) {
             self::_protect_directory(VARPATH . $dir);
         }
         module::set_version("gallery", $version = 25);
     }
     if ($version == 25) {
         db::build()->update("items")->set("title", db::expr("`name`"))->and_open()->where("title", "IS", null)->or_where("title", "=", "")->close()->execute();
         module::set_version("gallery", $version = 26);
     }
     if ($version == 26) {
         if (in_array("failed_logins", Database::instance()->list_tables())) {
             $db->query("RENAME TABLE {failed_logins} TO {failed_auths}");
         }
         module::set_version("gallery", $version = 27);
     }
     if ($version == 27) {
         // Set the admin area timeout to 90 minutes
         module::set_var("gallery", "admin_area_timeout", 90 * 60);
         module::set_version("gallery", $version = 28);
     }
开发者ID:Joe7,项目名称:gallery3,代码行数:67,代码来源:gallery_installer.php

示例6: save

 /**
  * Handle any business logic necessary to create or modify an item.
  * @see ORM::save()
  *
  * @return ORM Item_Model
  */
 public function save()
 {
     $significant_changes = $this->changed;
     unset($significant_changes["view_count"]);
     unset($significant_changes["relative_url_cache"]);
     unset($significant_changes["relative_path_cache"]);
     if (!empty($this->changed) && $significant_changes || isset($this->data_file)) {
         $this->updated = time();
         if (!$this->loaded()) {
             // Create a new item.
             module::event("item_before_create", $this);
             // Set a weight if it's missing.  We don't do this in the constructor because it's not a
             // simple assignment.
             if (empty($this->weight)) {
                 $this->weight = item::get_max_weight();
             }
             // Make an url friendly slug from the name, if necessary
             if (empty($this->slug)) {
                 $this->slug = item::convert_filename_to_slug(pathinfo($this->name, PATHINFO_FILENAME));
                 // If the filename is all invalid characters, then the slug may be empty here.  Pick a
                 // random value.
                 if (empty($this->slug)) {
                     $this->slug = (string) rand(1000, 9999);
                 }
             }
             // Get the width, height and mime type from our data file for photos and movies.
             if ($this->is_photo() || $this->is_movie()) {
                 if ($this->is_photo()) {
                     list($this->width, $this->height, $this->mime_type, $extension) = photo::get_file_metadata($this->data_file);
                 } else {
                     if ($this->is_movie()) {
                         list($this->width, $this->height, $this->mime_type, $extension) = movie::get_file_metadata($this->data_file);
                     }
                 }
                 // Force an extension onto the name if necessary
                 $pi = pathinfo($this->data_file);
                 if (empty($pi["extension"])) {
                     $this->name = "{$this->name}.{$extension}";
                 }
             }
             $this->_randomize_name_or_slug_on_conflict();
             parent::save();
             // Build our url caches, then save again.  We have to do this after it's already been
             // saved once because we use only information from the database to build the paths.  If we
             // could depend on a save happening later we could defer this 2nd save.
             $this->_build_relative_caches();
             parent::save();
             // Take any actions that we can only do once all our paths are set correctly after saving.
             switch ($this->type) {
                 case "album":
                     mkdir($this->file_path());
                     mkdir(dirname($this->thumb_path()));
                     mkdir(dirname($this->resize_path()));
                     break;
                 case "photo":
                 case "movie":
                     // The thumb or resize may already exist in the case where a movie and a photo generate
                     // a thumbnail of the same name (eg, foo.flv movie and foo.jpg photo will generate
                     // foo.jpg thumbnail).  If that happens, randomize and save again.
                     if (file_exists($this->resize_path()) || file_exists($this->thumb_path())) {
                         $pi = pathinfo($this->name);
                         $this->name = $pi["filename"] . "-" . random::int() . "." . $pi["extension"];
                         parent::save();
                     }
                     copy($this->data_file, $this->file_path());
                     break;
             }
             // This will almost definitely trigger another save, so put it at the end so that we're
             // tail recursive.  Null out the data file variable first, otherwise the next save will
             // trigger an item_updated_data_file event.
             $this->data_file = null;
             module::event("item_created", $this);
         } else {
             // Update an existing item
             module::event("item_before_update", $item);
             // If any significant fields have changed, load up a copy of the original item and
             // keep it around.
             $original = ORM::factory("item", $this->id);
             // Preserve the extension of the data file. Many helpers, (e.g. ImageMagick), assume
             // the MIME type from the extension. So when we adopt the new data file, it's important
             // to adopt the new extension. That ensures that the item's extension is always
             // appropriate for its data. We don't try to preserve the name of the data file, though,
             // because the name is typically a temporary randomly-generated name.
             if (isset($this->data_file)) {
                 $extension = pathinfo($this->data_file, PATHINFO_EXTENSION);
                 $new_name = pathinfo($this->name, PATHINFO_FILENAME) . ".{$extension}";
                 if (!empty($extension) && strcmp($this->name, $new_name)) {
                     $this->name = $new_name;
                 }
                 if ($this->is_photo()) {
                     list($this->width, $this->height, $this->mime_type, $extension) = photo::get_file_metadata($this->data_file);
                 } else {
                     if ($this->is_movie()) {
                         list($this->width, $this->height, $this->mime_type, $extension) = movie::get_file_metadata($this->data_file);
//.........这里部分代码省略.........
开发者ID:assad2012,项目名称:gallery3-appfog,代码行数:101,代码来源:item.php

示例7: create

 /**
  * 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
  * @param string  $slug (optional) the url component for this photo
  * @return Item_Model
  */
 static function create($parent, $filename, $name, $title, $description = null, $owner_id = null, $slug = null)
 {
     if (!$parent->loaded || !$parent->is_album()) {
         throw new Exception("@todo INVALID_PARENT");
     }
     if (!is_file($filename)) {
         throw new Exception("@todo MISSING_IMAGE_FILE");
     }
     if (strpos($name, "/")) {
         throw new Exception("@todo NAME_CANNOT_CONTAIN_SLASH");
     }
     // We don't allow trailing periods as a security measure
     // ref: http://dev.kohanaphp.com/issues/684
     if (rtrim($name, ".") != $name) {
         throw new Exception("@todo NAME_CANNOT_END_IN_PERIOD");
     }
     if (filesize($filename) == 0) {
         throw new Exception("@todo EMPTY_INPUT_FILE");
     }
     $image_info = getimagesize($filename);
     // Force an extension onto the name
     $pi = pathinfo($filename);
     if (empty($pi["extension"])) {
         $pi["extension"] = image_type_to_extension($image_info[2], false);
         $name .= "." . $pi["extension"];
     }
     if (empty($slug)) {
         $slug = item::convert_filename_to_slug($name);
     }
     $photo = ORM::factory("item");
     $photo->type = "photo";
     $photo->title = $title;
     $photo->description = $description;
     $photo->name = $name;
     $photo->owner_id = $owner_id ? $owner_id : user::active();
     $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;
     $photo->sort_column = "weight";
     $photo->slug = $slug;
     $photo->rand_key = (double) mt_rand() / (double) mt_getrandmax();
     // Randomize the name or slug if there's a conflict
     // @todo Improve this.  Random numbers are not user friendly
     while (ORM::factory("item")->where("parent_id", $parent->id)->open_paren()->where("name", $photo->name)->orwhere("slug", $photo->slug)->close_paren()->find()->id) {
         $rand = rand();
         $photo->name = "{$name}.{$rand}.{$pi['extension']}";
         $photo->slug = "{$slug}-{$rand}";
     }
     // This saves the photo
     $photo->add_to_parent($parent);
     /*
      * If the thumb or resize already exists then rename it. We need to do this after the save
      * because the resize_path and thumb_path both call relative_path which caches the
      * path. Before add_to_parent the relative path will be incorrect.
      */
     if (file_exists($photo->resize_path()) || file_exists($photo->thumb_path())) {
         $photo->name = $pi["filename"] . "-" . rand() . "." . $pi["extension"];
         $photo->save();
     }
     copy($filename, $photo->file_path());
     // @todo: publish this from inside Item_Model::save() when we refactor to the point where
     // there's only one save() happening here.
     module::event("item_created", $photo);
     // Build our thumbnail/resizes.  If we fail to build thumbnail/resize we assume that the image
     // is bad in some way and discard it.
     try {
         graphics::generate($photo);
     } catch (Exception $e) {
         $photo->delete();
         throw $e;
     }
     // If the parent has no cover item, make this it.
     if (access::can("edit", $parent) && $parent->album_cover_item_id == null) {
         item::make_album_cover($photo);
     }
     return $photo;
 }
开发者ID:estebandito,项目名称:gallery3,代码行数:89,代码来源:photo.php

示例8: create

 /**
  * Create a new movie.
  * @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
  * @param string  $slug (optional) the url component for this photo
  * @return Item_Model
  */
 static function create($parent, $filename, $name, $title, $description = null, $owner_id = null, $slug = null)
 {
     if (!$parent->loaded || !$parent->is_album()) {
         throw new Exception("@todo INVALID_PARENT");
     }
     if (!is_file($filename)) {
         throw new Exception("@todo MISSING_MOVIE_FILE");
     }
     if (strpos($name, "/")) {
         throw new Exception("@todo NAME_CANNOT_CONTAIN_SLASH");
     }
     // We don't allow trailing periods as a security measure
     // ref: http://dev.kohanaphp.com/issues/684
     if (rtrim($name, ".") != $name) {
         throw new Exception("@todo NAME_CANNOT_END_IN_PERIOD");
     }
     try {
         $movie_info = movie::getmoviesize($filename);
     } catch (Exception $e) {
         // Assuming this is MISSING_FFMPEG for now
         $movie_info = getimagesize(MODPATH . "gallery/images/missing_movie.png");
     }
     // Force an extension onto the name
     $pi = pathinfo($filename);
     if (empty($pi["extension"])) {
         $pi["extension"] = image_type_to_extension($movie_info[2], false);
         $name .= "." . $pi["extension"];
     }
     if (empty($slug)) {
         $slug = item::convert_filename_to_slug($name);
     }
     $movie = ORM::factory("item");
     $movie->type = "movie";
     $movie->title = $title;
     $movie->description = $description;
     $movie->name = $name;
     $movie->owner_id = $owner_id ? $owner_id : user::active();
     $movie->width = $movie_info[0];
     $movie->height = $movie_info[1];
     $movie->mime_type = strtolower($pi["extension"]) == "mp4" ? "video/mp4" : "video/x-flv";
     $movie->thumb_dirty = 1;
     $movie->resize_dirty = 1;
     $movie->sort_column = "weight";
     $movie->slug = $slug;
     $movie->rand_key = (double) mt_rand() / (double) mt_getrandmax();
     // Randomize the name if there's a conflict
     // @todo Improve this.  Random numbers are not user friendly
     while (ORM::factory("item")->where("parent_id", $parent->id)->open_paren()->where("name", $movie->name)->orwhere("slug", $movie->slug)->close_paren()->find()->id) {
         $rand = rand();
         $movie->name = "{$name}.{$rand}.{$pi['extension']}";
         $movie->slug = "{$slug}-{$rand}";
     }
     // This saves the photo
     $movie->add_to_parent($parent);
     // If the thumb or resize already exists then rename it
     if (file_exists($movie->resize_path()) || file_exists($movie->thumb_path())) {
         $movie->name = $pi["filename"] . "-" . rand() . "." . $pi["extension"];
         $movie->save();
     }
     copy($filename, $movie->file_path());
     // @todo: publish this from inside Item_Model::save() when we refactor to the point where
     // there's only one save() happening here.
     module::event("item_created", $movie);
     // Build our thumbnail
     graphics::generate($movie);
     // If the parent has no cover item, make this it.
     if (access::can("edit", $parent) && $parent->album_cover_item_id == null) {
         item::make_album_cover($movie);
     }
     return $movie;
 }
开发者ID:CardinS2U,项目名称:gallery3,代码行数:81,代码来源:movie.php

示例9: save

 /**
  * Handle any business logic necessary to create or modify an item.
  * @see ORM::save()
  *
  * @return ORM Item_Model
  */
 public function save()
 {
     $significant_changes = $this->changed;
     foreach (array("view_count", "relative_url_cache", "relative_path_cache", "resize_width", "resize_height", "resize_dirty", "thumb_width", "thumb_height", "thumb_dirty") as $key) {
         unset($significant_changes[$key]);
     }
     if (!empty($this->changed) && $significant_changes || isset($this->data_file)) {
         $this->updated = time();
         if (!$this->loaded()) {
             // Create a new item.
             module::event("item_before_create", $this);
             // Set a weight if it's missing.  We don't do this in the constructor because it's not a
             // simple assignment.
             if (empty($this->weight)) {
                 $this->weight = item::get_max_weight();
             }
             if ($this->is_album()) {
                 // Sanitize the album name.
                 $this->name = legal_file::sanitize_dirname($this->name);
             } else {
                 // Process the data file info.  This also sanitizes the item name.
                 if (isset($this->data_file)) {
                     $this->_process_data_file_info();
                 } else {
                     // New photos and movies must have a data file.
                     $this->data_file_error = true;
                 }
             }
             // Make an url friendly slug from the name, if necessary
             if (empty($this->slug)) {
                 $this->slug = item::convert_filename_to_slug(pathinfo($this->name, PATHINFO_FILENAME));
                 // If the filename is all invalid characters, then the slug may be empty here.  We set a
                 // generic name ("photo", "movie", or "album") based on its type, then rely on
                 // check_and_fix_conflicts to ensure it doesn't conflict with another name.
                 if (empty($this->slug)) {
                     $this->slug = $this->type;
                 }
             }
             $this->_check_and_fix_conflicts();
             parent::save();
             // Build our url caches, then save again.  We have to do this after it's already been
             // saved once because we use only information from the database to build the paths.  If we
             // could depend on a save happening later we could defer this 2nd save.
             $this->_build_relative_caches();
             parent::save();
             // Take any actions that we can only do once all our paths are set correctly after saving.
             switch ($this->type) {
                 case "album":
                     mkdir($this->file_path());
                     mkdir(dirname($this->thumb_path()));
                     mkdir(dirname($this->resize_path()));
                     break;
                 case "photo":
                 case "movie":
                     copy($this->data_file, $this->file_path());
                     break;
             }
             // This will almost definitely trigger another save, so put it at the end so that we're
             // tail recursive.  Null out the data file variable first, otherwise the next save will
             // trigger an item_updated_data_file event.
             $this->data_file = null;
             module::event("item_created", $this);
         } else {
             // Update an existing item
             module::event("item_before_update", $this);
             // If any significant fields have changed, load up a copy of the original item and
             // keep it around.
             $original = ORM::factory("item", $this->id);
             // If we have a new data file, process its info.  This will get its metadata and
             // preserve the extension of the data file. Many helpers, (e.g. ImageMagick), assume
             // the MIME type from the extension. So when we adopt the new data file, it's important
             // to adopt the new extension. That ensures that the item's extension is always
             // appropriate for its data. We don't try to preserve the name of the data file, though,
             // because the name is typically a temporary randomly-generated name.
             if (isset($this->data_file)) {
                 $this->_process_data_file_info();
             } else {
                 if (!$this->is_album() && array_key_exists("name", $this->changed)) {
                     // There's no new data file, but the name changed.  If it's a photo or movie,
                     // make sure the new name still agrees with the file type.
                     $this->name = legal_file::sanitize_filename($this->name, pathinfo($original->name, PATHINFO_EXTENSION), $this->type);
                 }
             }
             // If an album's name changed, sanitize it.
             if ($this->is_album() && array_key_exists("name", $this->changed)) {
                 $this->name = legal_file::sanitize_dirname($this->name);
             }
             // If an album's cover has changed (or been removed), delete any existing album cover,
             // reset the thumb metadata, and mark the thumb as dirty.
             if (array_key_exists("album_cover_item_id", $this->changed) && $this->is_album()) {
                 @unlink($original->thumb_path());
                 $this->thumb_dirty = 1;
                 $this->thumb_height = 0;
                 $this->thumb_width = 0;
//.........这里部分代码省略.........
开发者ID:sandadze,项目名称:gallery3,代码行数:101,代码来源:item.php

示例10: upgrade


//.........这里部分代码省略.........
         module::set_version("gallery", $version = 15);
     }
     if ($version == 15) {
         module::set_var("gallery", "identity_provider", "user");
         module::set_version("gallery", $version = 16);
     }
     // Convert block keys to an md5 hash of the module and block name
     if ($version == 16) {
         foreach (array("dashboard_sidebar", "dashboard_center", "site_sidebar") as $location) {
             $blocks = block_manager::get_active($location);
             $new_blocks = array();
             foreach ($blocks as $block) {
                 $new_blocks[md5("{$block[0]}:{$block[1]}")] = $block;
             }
             block_manager::set_active($location, $new_blocks);
         }
         module::set_version("gallery", $version = 17);
     }
     // We didn't like md5 hashes so convert block keys back to random keys to allow duplicates.
     if ($version == 17) {
         foreach (array("dashboard_sidebar", "dashboard_center", "site_sidebar") as $location) {
             $blocks = block_manager::get_active($location);
             $new_blocks = array();
             foreach ($blocks as $block) {
                 $new_blocks[rand()] = $block;
             }
             block_manager::set_active($location, $new_blocks);
         }
         module::set_version("gallery", $version = 18);
     }
     // Rename blocks_site.sidebar to blocks_site_sidebar
     if ($version == 18) {
         $blocks = block_manager::get_active("site.sidebar");
         block_manager::set_active("site_sidebar", $blocks);
         module::clear_var("gallery", "blocks_site.sidebar");
         module::set_version("gallery", $version = 19);
     }
     // Set a default for the number of simultaneous uploads
     // Version 20 was reverted in 57adefc5baa7a2b0dfcd3e736e80c2fa86d3bfa2, so skip it.
     if ($version == 19 || $version == 20) {
         module::set_var("gallery", "simultaneous_upload_limit", 5);
         module::set_version("gallery", $version = 21);
     }
     // Update the graphics rules table so that the maximum height for resizes is 640 not 480.
     // Fixes ticket #671
     if ($version == 21) {
         $resize_rule = ORM::factory("graphics_rule")->where("id", "=", "2")->find();
         // make sure it hasn't been changed already
         $args = unserialize($resize_rule->args);
         if ($args["height"] == 480 && $args["width"] == 640) {
             $args["height"] = 640;
             $resize_rule->args = serialize($args);
             $resize_rule->save();
         }
         module::set_version("gallery", $version = 22);
     }
     // Update slug values to be legal.  We should have done this in the 11->12 upgrader, but I was
     // lazy.  Mea culpa!
     if ($version == 22) {
         foreach (db::build()->from("items")->select("id", "slug")->where(new Database_Expression("`slug` REGEXP '[^_A-Za-z0-9-]'"), "=", 1)->execute() as $row) {
             $new_slug = item::convert_filename_to_slug($row->slug);
             if (empty($new_slug)) {
                 $new_slug = rand();
             }
             db::build()->update("items")->set("slug", $new_slug)->set("relative_url_cache", null)->where("id", "=", $row->id)->execute();
         }
         module::set_version("gallery", $version = 23);
     }
     if ($version == 23) {
         $db->query("CREATE TABLE {failed_logins} (\n                  `id` int(9) NOT NULL auto_increment,\n                  `count` int(9) NOT NULL,\n                  `name` varchar(255) NOT NULL,\n                  `time` int(9) NOT NULL,\n                  PRIMARY KEY (`id`))\n                  DEFAULT CHARSET=utf8;");
         module::set_version("gallery", $version = 24);
     }
     if ($version == 24) {
         foreach (array("logs", "tmp", "uploads") as $dir) {
             self::_protect_directory(VARPATH . $dir);
         }
         module::set_version("gallery", $version = 25);
     }
     if ($version == 25) {
         db::build()->update("items")->set("title", new Database_Expression("`name`"))->and_open()->where("title", "IS", null)->or_where("title", "=", "")->close()->execute();
         module::set_version("gallery", $version = 26);
     }
     if ($version == 26) {
         $db->query("RENAME TABLE {failed_logins} TO {failed_auths}");
         module::set_version("gallery", $version = 27);
     }
     if ($version == 27) {
         // Set the admin area timeout to 90 minutes
         module::set_var("gallery", "admin_area_timeout", 90 * 60);
         module::set_version("gallery", $version = 28);
     }
     if ($version == 28) {
         module::set_var("gallery", "credits", "Powered by <a href=\"%url\">%gallery_version</a>");
         module::set_version("gallery", $version = 29);
     }
     if ($version == 29) {
         $db->query("ALTER TABLE {caches} ADD KEY (`key`);");
         module::set_version("gallery", $version = 30);
     }
 }
开发者ID:andyst,项目名称:gallery3,代码行数:101,代码来源:gallery_installer.php

示例11: convert_filename_to_slug_test

 public function convert_filename_to_slug_test()
 {
     $this->assert_equal("foo", item::convert_filename_to_slug("{[foo]}"));
     $this->assert_equal("foo-bar", item::convert_filename_to_slug("{[foo!@#!\$@#^\$@(\$!(@bar]}"));
 }
开发者ID:viosca,项目名称:gallery3,代码行数:5,代码来源:Item_Helper_Test.php

示例12: _add_item

 private function _add_item(&$input, &$reply)
 {
     $album = trim($input->post('set_albumName'));
     $userfilename = $this->decode($input->post('userfile_name'));
     $title = $this->decode($input->post('caption'));
     $forcefilename = $this->decode($input->post('force_filename'));
     $autorotate = trim($input->post('auto_rotate'));
     if ($album == '0') {
         $parent = item::root();
     } else {
         $parent = ORM::factory("item")->where("id", "=", $album)->find();
     }
     if (isset($parent) && $parent->loaded() && $parent->id != '') {
         if (function_exists('mime_content_type')) {
             $type = mime_content_type($_FILES['userfile']['tmp_name']);
         } else {
             $type = self::get_mime_type($_FILES['userfile']['name']);
         }
         /* <any ugly idea is welcome here> */
         if ($type == '') {
             if (function_exists('getimagesize')) {
                 $size = getimagesize($_FILES['userfile']['tmp_name']);
                 $type = $size['mime'];
             } else {
                 if (function_exists('exif_imagetype') && function_exists('image_type_to_mime_type')) {
                     $type = image_type_to_mime_type(exif_imagetype($_FILES['userfile']['tmp_name']));
                 }
             }
         }
         /* </any ugly idea is welcome here> */
         if ($type != '' && !in_array($type, array('image/jpeg', 'image/gif', 'image/png'))) {
             $reply->set('status_text', t("'%path' is an unsupported image type '%type'", array('path' => $_FILES['userfile']['tmp_name'], 'type' => $type)));
             $reply->send(gallery_remote::UPLOAD_PHOTO_FAIL);
             return;
         }
         if ($forcefilename != '') {
             $filename = $forcefilename;
         } else {
             if ($userfilename != '') {
                 $filename = $userfilename;
             } else {
                 $filename = $_FILES['userfile']['name'];
             }
         }
         $slug = $filename;
         $pos = strpos($slug, '.');
         if ($pos !== false) {
             $slug = substr($slug, 0, $pos);
         }
         //*/ fix for a gallery remote bug...
         $filename = str_replace('.JPG.jpeg', '.jpeg', $filename);
         //*/
         //*/ suddenly gallery fails because the uploaded(!) file (of cause!) doesn't contain a file extension
         if (strpos($_FILES['userfile']['tmp_name'], '.') === false) {
             $moveto = $_FILES['userfile']['tmp_name'] . '.' . substr($type, strpos($type, '/') + 1);
             rename($_FILES['userfile']['tmp_name'], $moveto);
             $_FILES['userfile']['tmp_name'] = $moveto;
         }
         //*/
         try {
             $item = ORM::factory('item');
             $item->type = 'photo';
             $item->parent_id = $parent->id;
             $item->set_data_file($_FILES['userfile']['tmp_name']);
             $item->name = $filename;
             $item->slug = item::convert_filename_to_slug($slug);
             $item->mime_type = $type;
             $item->title = $title;
             $item->title or $item->title = ' ';
             //don't use $item->name as this clutters up the UI
             //$item->description =
             $item->view_count = 0;
             try {
                 $item->validate();
                 try {
                     $item->save();
                     $reply->set('item_name', $item->id);
                     $reply->set('status_text', 'New item created successfuly.');
                     $reply->send();
                 } catch (ORM_Validation_Exception $e) {
                     $validation = $e->validation;
                     //print_r($validation->errors()); exit;
                     $reply->set('status_text', t('Failed to validate item %item: %errors', array('item' => $filename, 'errors' => str_replace("\n", ' ', print_r($validation->errors(), true)))));
                     $reply->send(gallery_remote::UPLOAD_PHOTO_FAIL);
                     //FIXME gallery remote ignores this return value and continues to wait
                 } catch (Exception $e) {
                     $reply->set('status_text', t('Failed to add item %item.', array('item' => $filename)));
                     $reply->send(gallery_remote::UPLOAD_PHOTO_FAIL);
                     //FIXME gallery remote ignores this return value and continues to wait
                 }
             } catch (ORM_Validation_Exception $e) {
                 $validation = $e->validation;
                 //print_r($validation->errors()); exit;
                 $reply->set('status_text', t('Failed to validate item %item: %errors', array('item' => $filename, 'errors' => str_replace("\n", ' ', print_r($validation->errors(), true)))));
                 $reply->send(gallery_remote::UPLOAD_PHOTO_FAIL);
                 //FIXME gallery remote ignores this return value and continues to wait
             }
         } catch (Exception $e) {
             $reply->set('status_text', t("Corrupt image '%path'", array('path' => $_FILES['userfile']['tmp_name'])));
             $reply->send(gallery_remote::UPLOAD_PHOTO_FAIL);
//.........这里部分代码省略.........
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:101,代码来源:gallery_remote.php

示例13: import_item


//.........这里部分代码省略.........
     if (!file_exists($g1_path)) {
         // If the Gallery 1 source image isn't available, this operation is going to fail.  That can
         // happen in cases where there's corruption in the source Gallery 1.  In that case, fall
         // back on using a broken image.  It's important that we import *something* otherwise
         // anything that refers to this item in Gallery 1 will have a dangling pointer in Gallery 3
         //
         // Note that this will change movies to be photos, if there's a broken movie.  Hopefully
         // this case is rare enough that we don't need to take any heroic action here.
         g1_import::log(t('%path missing in import; replacing it with a placeholder', array('path' => $g1_path)));
         $g1_path = MODPATH . 'g1_import/data/broken-image.gif';
         $g1_type = 'GalleryPhotoItem';
         $corrupt = 1;
     }
     $item = null;
     switch ($g1_type) {
         case 'GalleryPhotoItem':
             if (function_exists('mime_content_type')) {
                 $type = mime_content_type($g1_path);
             } else {
                 $type = self::get_mime_type($g1_path);
             }
             if ($type != '' && !in_array($type, array('image/jpeg', 'image/gif', 'image/png'))) {
                 Kohana_Log::add('alert', "{$g1_path} is an unsupported image type {$type}; using a placeholder gif");
                 $messages[] = t("'%path' is an unsupported image type '%type', using a placeholder", array('path' => $g1_path, 'type' => $type));
                 $g1_path = MODPATH . 'g1_import/data/broken-image.gif';
                 $corrupt = 1;
             }
             try {
                 $item = ORM::factory('item');
                 $item->type = 'photo';
                 $item->parent_id = $album_id;
                 $item->set_data_file($g1_path);
                 $item->name = $g1_item . '.' . $album_item->image->type;
                 $item->slug = item::convert_filename_to_slug($g1_item);
                 $item->mime_type = $type;
                 $item->title = utf8_encode(self::_decode_html_special_chars(trim($album_item->caption)));
                 $item->title or $item->title = ' ';
                 //don't use $item->name as this clutters up the UI
                 if (isset($album_item->description) && $album_item->description != '') {
                     $item->description = utf8_encode(self::_decode_html_special_chars(trim($album_item->description)));
                 }
                 //$item->owner_id = self::map($g1_item->getOwnerId());
                 try {
                     $item->view_count = (int) $album_item->clicks;
                 } catch (Exception $e) {
                     $item->view_count = 1;
                 }
                 if (strlen($item->title) > 255) {
                     if (strlen($item->description) == 0) {
                         $item->description = $item->title;
                     }
                     $item->title = substr($item->title, 0, 252) . '...';
                 }
             } catch (Exception $e) {
                 $exception_info = (string) new G1_Import_Exception(t("Corrupt image '%path'", array('path' => $g1_path)), $e, $messages);
                 Kohana_Log::add('alert', "Corrupt image {$g1_path}\n" . $exception_info);
                 $messages[] = $exception_info;
                 $corrupt = 1;
                 $item = null;
                 return $messages;
             }
             try {
                 $item->validate();
             } catch (ORM_Validation_Exception $e) {
                 $exception_info = (string) new G1_Import_Exception(t('Failed to validate Gallery 1 item %item.', array('item' => $item_id)), $e, $messages);
                 Kohana_Log::add('alert', "Failed to validate Gallery 1 item {$item_id}.\n" . $exception_info);
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:67,代码来源:g1_import.php


注:本文中的item::convert_filename_to_slug方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。