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


PHP item::find_by_path方法代码示例

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


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

示例1: __call

 public function __call($function, $args)
 {
     // Force zlib compression off.  Image and movie files are already compressed and
     // recompressing them is CPU intensive.
     if (ini_get("zlib.output_compression")) {
         ini_set("zlib.output_compression", "Off");
     }
     // request_uri: gallery3/var/albums/foo/bar.jpg?m=1234
     $request_uri = rawurldecode(Input::instance()->server("REQUEST_URI"));
     // get rid of query parameters
     // request_uri: gallery3/var/albums/foo/bar.jpg
     $request_uri = preg_replace("/\\?.*/", "", $request_uri);
     // var_uri: gallery3/var/
     $var_uri = url::file("var/");
     // Make sure that the request is for a file inside var
     $offset = strpos(rawurldecode($request_uri), $var_uri);
     if ($offset !== 0) {
         throw new Kohana_404_Exception();
     }
     // file_uri: albums/foo/bar.jpg
     $file_uri = substr($request_uri, strlen($var_uri));
     // type: albums
     // path: foo/bar.jpg
     list($type, $path) = explode("/", $file_uri, 2);
     if ($type != "resizes" && $type != "albums" && $type != "thumbs") {
         throw new Kohana_404_Exception();
     }
     // If the last element is .album.jpg, pop that off since it's not a real item
     $path = preg_replace("|/.album.jpg\$|", "", $path);
     $item = item::find_by_path($path);
     if (!$item->loaded()) {
         // We didn't turn it up. If we're looking for a .jpg then it's it's possible that we're
         // requesting the thumbnail for a movie.  In that case, the .flv, .mp4 or .m4v file would
         // have been converted to a .jpg. So try some alternate types:
         if (preg_match('/.jpg$/', $path)) {
             foreach (array("flv", "mp4", "m4v") as $ext) {
                 $movie_path = preg_replace('/.jpg$/', ".{$ext}", $path);
                 $item = item::find_by_path($movie_path);
                 if ($item->loaded()) {
                     break;
                 }
             }
         }
     }
     if (!$item->loaded()) {
         throw new Kohana_404_Exception();
     }
     // Make sure we have access to the item
     if (!access::can("view", $item)) {
         throw new Kohana_404_Exception();
     }
     // Make sure we have view_full access to the original
     if ($type == "albums" && !access::can("view_full", $item)) {
         throw new Kohana_404_Exception();
     }
     // Don't try to load a directory
     if ($type == "albums" && $item->is_album()) {
         throw new Kohana_404_Exception();
     }
     if ($type == "albums") {
         $file = $item->file_path();
     } else {
         if ($type == "resizes") {
             $file = $item->resize_path();
         } else {
             $file = $item->thumb_path();
         }
     }
     if (!file_exists($file)) {
         throw new Kohana_404_Exception();
     }
     header("Content-Length: " . filesize($file));
     header("Pragma:");
     // Check that the content hasn't expired or it wasn't changed since cached
     expires::check(2592000, $item->updated);
     // We don't need to save the session for this request
     Session::instance()->abort_save();
     expires::set(2592000, $item->updated);
     // 30 days
     // Dump out the image.  If the item is a movie, then its thumbnail will be a JPG.
     if ($item->is_movie() && $type != "albums") {
         header("Content-Type: image/jpeg");
     } else {
         header("Content-Type: {$item->mime_type}");
     }
     // Don't use Kohana::close_buffers(false) here because that only closes all the buffers
     // that Kohana started.  We want to close *all* buffers at this point because otherwise we're
     // going to buffer up whatever file we're proxying (and it may be very large).  This may
     // affect embedding or systems with PHP's output_buffering enabled.
     while (ob_get_level()) {
         Kohana_Log::add("error", "" . print_r(ob_get_level(), 1));
         if (!@ob_end_clean()) {
             // ob_end_clean() can return false if the buffer can't be removed for some reason
             // (zlib output compression buffers sometimes cause problems).
             break;
         }
     }
     readfile($file);
 }
开发者ID:JasonWiki,项目名称:docs,代码行数:99,代码来源:file_proxy.php

示例2: find_by_path_test

 public function find_by_path_test()
 {
     $level1 = test::random_album();
     $level2 = test::random_album_unsaved($level1);
     $level2->name = "plus + space";
     $level2->save()->reload();
     $level3 = test::random_photo_unsaved($level2);
     $level3->name = "same.jpg";
     $level3->save()->reload();
     $level2b = test::random_album($level1);
     $level3b = test::random_photo_unsaved($level2b);
     $level3b->name = "same.jpg";
     $level3b->save()->reload();
     // Item in album
     $this->assert_same($level3->id, item::find_by_path("/{$level1->name}/{$level2->name}/{$level3->name}")->id);
     // Album, ends with a slash
     $this->assert_same($level2->id, item::find_by_path("{$level1->name}/{$level2->name}/")->id);
     // Album, ends without a slash
     $this->assert_same($level2->id, item::find_by_path("/{$level1->name}/{$level2->name}")->id);
     // Return root if "" is passed
     $this->assert_same(item::root()->id, item::find_by_path("")->id);
     // Verify that we don't get confused by the part names, using the fallback code.
     db::build()->update("items")->set(array("relative_path_cache" => null))->where("id", "IN", array($level3->id, $level3b->id))->execute();
     $this->assert_same($level3->id, item::find_by_path("{$level1->name}/{$level2->name}/{$level3->name}")->id);
     $this->assert_same($level3b->id, item::find_by_path("{$level1->name}/{$level2b->name}/{$level3b->name}")->id);
     // Verify that we don't get false positives
     $this->assert_false(item::find_by_path("foo/bar/baz")->loaded());
     // Verify that the fallback code works
     $this->assert_same($level3b->id, item::find_by_path("{$level1->name}/{$level2b->name}/{$level3b->name}")->id);
 }
开发者ID:assad2012,项目名称:gallery3-appfog,代码行数:30,代码来源:Item_Helper_Test.php

示例3: find_by_path_with_album_test

 public function find_by_path_with_album_test()
 {
     $parent = test::random_album();
     $album = test::random_movie($parent);
     $album_path = "{$parent->name}/{$album->name}";
     $thumb_path = "{$album_path}/.album.jpg";
     // Check normal operation.
     $this->assert_equal($album->id, item::find_by_path($album_path, "albums")->id);
     $this->assert_equal($album->id, item::find_by_path($thumb_path, "thumbs")->id);
     $this->assert_equal($album->id, item::find_by_path($album_path)->id);
     // Check that we don't get false positives.
     $this->assert_equal(null, item::find_by_path($thumb_path, "albums")->id);
     $this->assert_equal(null, item::find_by_path($album_path, "thumbs")->id);
     $this->assert_equal(null, item::find_by_path($thumb_path)->id);
     // Check normal operation without relative path cache.
     self::_remove_relative_path_caches();
     $this->assert_equal($album->id, item::find_by_path($album_path, "albums")->id);
     self::_remove_relative_path_caches();
     $this->assert_equal($album->id, item::find_by_path($thumb_path, "thumbs")->id);
     self::_remove_relative_path_caches();
     $this->assert_equal($album->id, item::find_by_path($album_path)->id);
     // Check that we don't get false positives without relative path cache.
     self::_remove_relative_path_caches();
     $this->assert_equal(null, item::find_by_path($thumb_path, "albums")->id);
     $this->assert_equal(null, item::find_by_path($album_path, "thumbs")->id);
     $this->assert_equal(null, item::find_by_path($thumb_path)->id);
 }
开发者ID:HarriLu,项目名称:gallery3,代码行数:27,代码来源:Item_Helper_Test.php

示例4: __call

 public function __call($function, $args)
 {
     // request_uri: gallery3/var/albums/foo/bar.jpg?m=1234
     $request_uri = rawurldecode(Input::instance()->server("REQUEST_URI"));
     // get rid of query parameters
     // request_uri: gallery3/var/albums/foo/bar.jpg
     $request_uri = preg_replace("/\\?.*/", "", $request_uri);
     // var_uri: gallery3/var/
     $var_uri = url::file("var/");
     // Make sure that the request is for a file inside var
     $offset = strpos(rawurldecode($request_uri), $var_uri);
     if ($offset !== 0) {
         throw new Kohana_404_Exception();
     }
     // file_uri: albums/foo/bar.jpg
     $file_uri = substr($request_uri, strlen($var_uri));
     // type: albums
     // path: foo/bar.jpg
     list($type, $path) = explode("/", $file_uri, 2);
     if ($type != "resizes" && $type != "albums" && $type != "thumbs") {
         throw new Kohana_404_Exception();
     }
     // If the last element is .album.jpg, pop that off since it's not a real item
     $path = preg_replace("|/.album.jpg\$|", "", $path);
     $item = item::find_by_path($path);
     if (!$item->loaded()) {
         // We didn't turn it up. If we're looking for a .jpg then it's it's possible that we're
         // requesting the thumbnail for a movie.  In that case, the .flv, .mp4 or .m4v file would
         // have been converted to a .jpg. So try some alternate types:
         if (preg_match('/.jpg$/', $path)) {
             // rWatcher Mod:   look for videos with file extensions supported by the videos module in addition to flv mp4 and m4v
             // Original Line:  foreach (array("flv", "mp4", "m4v") as $ext) {
             foreach (array_merge(array("flv", "mp4", "m4v"), unserialize(module::get_var("videos", "allowed_extensions"))) as $ext) {
                 $movie_path = preg_replace('/.jpg$/', ".{$ext}", $path);
                 $item = item::find_by_path($movie_path);
                 if ($item->loaded()) {
                     break;
                 }
             }
         }
         // rWatcher Mod:
         // If we're looking for a .flv then it's it's possible that we're requesting a flash resize
         // for a movie.
         if (strtolower(substr($path, strlen($path) - 4)) == ".flv") {
             $movie_path = str_ireplace(".flv", "", $path);
             $item = ORM::factory("item")->where("relative_path_cache", "=", $movie_path)->find();
         }
         // END rWatcher Mod
     }
     if (!$item->loaded()) {
         throw new Kohana_404_Exception();
     }
     // Make sure we have access to the item
     if (!access::can("view", $item)) {
         throw new Kohana_404_Exception();
     }
     // Make sure we have view_full access to the original
     if ($type == "albums" && !access::can("view_full", $item)) {
         throw new Kohana_404_Exception();
     }
     // Don't try to load a directory
     if ($type == "albums" && $item->is_album()) {
         throw new Kohana_404_Exception();
     }
     if ($type == "albums") {
         $file = $item->file_path();
     } else {
         if ($type == "resizes") {
             $file = $item->resize_path();
             // rWatcher MOD
             //  If the resize is for a movie, assume it needs a .flv extension.
             if ($item->is_movie()) {
                 $file = $file . ".flv";
             }
             // End rWatcher MOD
         } else {
             $file = $item->thumb_path();
         }
     }
     if (!file_exists($file)) {
         throw new Kohana_404_Exception();
     }
     header("Content-Length: " . filesize($file));
     header("Pragma:");
     // Check that the content hasn't expired or it wasn't changed since cached
     expires::check(2592000, $item->updated);
     // We don't need to save the session for this request
     Session::instance()->abort_save();
     expires::set(2592000, $item->updated);
     // 30 days
     // Dump out the image.  If the item is a movie, then its thumbnail will be a JPG.
     if ($item->is_movie() && $type != "albums") {
         header("Content-Type: image/jpeg");
     } else {
         header("Content-Type: {$item->mime_type}");
     }
     Kohana::close_buffers(false);
     readfile($file);
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:99,代码来源:file_proxy.php

示例5: __call

 public function __call($function, $args)
 {
     // Force zlib compression off.  Image and movie files are already compressed and
     // recompressing them is CPU intensive.
     if (ini_get("zlib.output_compression")) {
         ini_set("zlib.output_compression", "Off");
     }
     // request_uri: gallery3/var/albums/foo/bar.jpg?m=1234
     $request_uri = rawurldecode(Input::instance()->server("REQUEST_URI"));
     // get rid of query parameters
     // request_uri: gallery3/var/albums/foo/bar.jpg
     $request_uri = preg_replace("/\\?.*/", "", $request_uri);
     // var_uri: gallery3/var/
     $var_uri = url::file("var/");
     // Make sure that the request is for a file inside var
     $offset = strpos(rawurldecode($request_uri), $var_uri);
     if ($offset !== 0) {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 1;
         throw $e;
     }
     // file_uri: albums/foo/bar.jpg
     $file_uri = substr($request_uri, strlen($var_uri));
     // type: albums
     // path: foo/bar.jpg
     list($type, $path) = explode("/", $file_uri, 2);
     if ($type != "resizes" && $type != "albums" && $type != "thumbs") {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 2;
         throw $e;
     }
     // Get the item model using the path and type (which corresponds to a var subdir)
     $item = item::find_by_path($path, $type);
     if (!$item->loaded()) {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 3;
         throw $e;
     }
     // Make sure we have access to the item
     if (!access::can("view", $item)) {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 4;
         throw $e;
     }
     // Make sure we have view_full access to the original
     if ($type == "albums" && !access::can("view_full", $item)) {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 5;
         throw $e;
     }
     // Don't try to load a directory
     if ($type == "albums" && $item->is_album()) {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 6;
         throw $e;
     }
     // Note: this code is roughly duplicated in data_rest, so if you modify this, please look to
     // see if you should make the same change there as well.
     if ($type == "albums") {
         $file = $item->file_path();
     } else {
         if ($type == "resizes") {
             $file = $item->resize_path();
         } else {
             $file = $item->thumb_path();
         }
     }
     if (!file_exists($file)) {
         $e = new Kohana_404_Exception();
         $e->test_fail_code = 7;
         throw $e;
     }
     if (gallery::show_profiler()) {
         Profiler::enable();
         $profiler = new Profiler();
         $profiler->render();
         exit;
     }
     header("Content-Length: " . filesize($file));
     header("Pragma:");
     // Check that the content hasn't expired or it wasn't changed since cached
     expires::check(2592000, $item->updated);
     // We don't need to save the session for this request
     Session::instance()->abort_save();
     expires::set(2592000, $item->updated);
     // 30 days
     // Dump out the image.  If the item is a movie or album, then its thumbnail will be a JPG.
     if (($item->is_movie() || $item->is_album()) && $type == "thumbs") {
         header("Content-Type: image/jpeg");
     } else {
         header("Content-Type: {$item->mime_type}");
     }
     if (TEST_MODE) {
         return $file;
     } else {
         // Don't use Kohana::close_buffers(false) here because that only closes all the buffers
         // that Kohana started.  We want to close *all* buffers at this point because otherwise we're
         // going to buffer up whatever file we're proxying (and it may be very large).  This may
         // affect embedding or systems with PHP's output_buffering enabled.
         while (ob_get_level()) {
//.........这里部分代码省略.........
开发者ID:HarriLu,项目名称:gallery3,代码行数:101,代码来源:file_proxy.php

示例6: graphics_rotate

 static function graphics_rotate($input_file, $output_file, $options)
 {
     // Remove the current item's file size from the quotas table.
     $item = item::find_by_path(substr(str_replace(VARPATH, "", $input_file), strpos(str_replace(VARPATH, "", $input_file), "/") + 1));
     if ($item->loaded()) {
         $record = ORM::factory("users_space_usage")->where("owner_id", "=", $item->owner_id)->find();
         $record->remove_item($item);
     }
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:9,代码来源:quotas_event.php


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