summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/helpers/MY_url.php30
-rw-r--r--core/hooks/init_gallery.php1
-rw-r--r--core/models/item.php20
-rw-r--r--core/tests/Albums_Controller_Test.php3
-rw-r--r--core/tests/Photos_Controller_Test.php2
5 files changed, 43 insertions, 13 deletions
diff --git a/core/helpers/MY_url.php b/core/helpers/MY_url.php
index fa358543..dd3682df 100644
--- a/core/helpers/MY_url.php
+++ b/core/helpers/MY_url.php
@@ -18,6 +18,36 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class url extends url_Core {
+ static function site($uri, $protocol=false) {
+ list($controller, $arg1, $args) = explode("/", $uri, 3);
+ if ($controller == "albums" || $controller == "photos") {
+ $uri = ORM::factory("item", $arg1)->relative_path();
+ }
+ return parent::site($uri, $protocol);
+ }
+
+ static function parse_url() {
+ if (Router::$controller) {
+ return;
+ }
+
+ $count = count(Router::$segments);
+ foreach (ORM::factory("item")
+ ->where("name", Router::$segments[$count - 1])
+ ->where("level", $count + 1)
+ ->find_all() as $match) {
+ if ($match->relative_path() == Router::$current_uri) {
+ $item = $match;
+ }
+ }
+
+ if (!empty($item)) {
+ Router::$controller = "{$item->type}s";
+ Router::$controller_path = APPPATH . "controllers/{$item->type}s.php";
+ Router::$method = $item->id;
+ }
+ }
+
/**
* Just like url::file() except that it returns an absolute URI
*/
diff --git a/core/hooks/init_gallery.php b/core/hooks/init_gallery.php
index c6a22319..27a4d8a4 100644
--- a/core/hooks/init_gallery.php
+++ b/core/hooks/init_gallery.php
@@ -20,3 +20,4 @@
Event::add("system.ready", array("I18n", "instance"));
Event::add("system.post_routing", array("theme", "load_themes"));
Event::add("system.ready", array("module", "load_modules"));
+Event::add("system.post_routing", array("url", "parse_url"));
diff --git a/core/models/item.php b/core/models/item.php
index ed82da52..e5e8c556 100644
--- a/core/models/item.php
+++ b/core/models/item.php
@@ -147,7 +147,7 @@ class Item_Model extends ORM_MPTT {
* photo: /var/albums/album1/album2/photo.jpg
*/
public function file_path() {
- return VARPATH . "albums/" . $this->_relative_path();
+ return VARPATH . "albums/" . $this->relative_path();
}
/**
@@ -156,8 +156,8 @@ class Item_Model extends ORM_MPTT {
*/
public function file_url($full_uri=false) {
return $full_uri ?
- url::abs_file("var/albums/" . $this->_relative_path()) :
- url::file("var/albums/" . $this->_relative_path());
+ url::abs_file("var/albums/" . $this->relative_path()) :
+ url::file("var/albums/" . $this->relative_path());
}
/**
@@ -165,7 +165,7 @@ class Item_Model extends ORM_MPTT {
* photo: /var/albums/album1/photo.thumb.jpg
*/
public function thumb_path() {
- return VARPATH . "thumbs/" . $this->_relative_path() .
+ return VARPATH . "thumbs/" . $this->relative_path() .
($this->type == "album" ? "/.album.jpg" : "");
}
@@ -175,8 +175,8 @@ class Item_Model extends ORM_MPTT {
*/
public function thumb_url($full_uri=true) {
return ($full_uri ?
- url::abs_file("var/thumbs/" . $this->_relative_path()) :
- url::file("var/thumbs/" . $this->_relative_path())) .
+ url::abs_file("var/thumbs/" . $this->relative_path()) :
+ url::file("var/thumbs/" . $this->relative_path())) .
($this->type == "album" ? "/.album.jpg" : "");
}
@@ -185,7 +185,7 @@ class Item_Model extends ORM_MPTT {
* photo: /var/albums/album1/photo.resize.jpg
*/
public function resize_path() {
- return VARPATH . "resizes/" . $this->_relative_path() .
+ return VARPATH . "resizes/" . $this->relative_path() .
($this->type == "album" ? "/.album.jpg" : "");
}
@@ -195,8 +195,8 @@ class Item_Model extends ORM_MPTT {
*/
public function resize_url($full_uri=true) {
return ($full_uri ?
- url::abs_file("var/resizes/" . $this->_relative_path()) :
- url::file("var/resizes/" . $this->_relative_path())) .
+ url::abs_file("var/resizes/" . $this->relative_path()) :
+ url::file("var/resizes/" . $this->relative_path())) .
($this->type == "album" ? "/.album.jpg" : "");
}
@@ -204,7 +204,7 @@ class Item_Model extends ORM_MPTT {
* Return the relative path to this item's file.
* @return string
*/
- private function _relative_path() {
+ public function relative_path() {
if (empty($this->relative_path)) {
foreach ($this->parents() as $parent) {
if ($parent->id > 1) {
diff --git a/core/tests/Albums_Controller_Test.php b/core/tests/Albums_Controller_Test.php
index 06360b79..57a5bf64 100644
--- a/core/tests/Albums_Controller_Test.php
+++ b/core/tests/Albums_Controller_Test.php
@@ -40,8 +40,7 @@ class Albums_Controller_Test extends Unit_Test_Case {
ob_end_clean();
$this->assert_equal(
- json_encode(array("result" => "success",
- "location" => "http://./index.php/albums/$album->id")),
+ json_encode(array("result" => "success", "location" => "http://./index.php/test")),
$results);
$this->assert_equal("new title", $album->title);
$this->assert_equal("new description", $album->description);
diff --git a/core/tests/Photos_Controller_Test.php b/core/tests/Photos_Controller_Test.php
index d48ae35e..2b28f774 100644
--- a/core/tests/Photos_Controller_Test.php
+++ b/core/tests/Photos_Controller_Test.php
@@ -41,7 +41,7 @@ class Photos_Controller_Test extends Unit_Test_Case {
$this->assert_equal(
json_encode(array("result" => "success",
- "location" => "http://./index.php/photos/$photo->id")),
+ "location" => "http://./index.php/test.jpeg")),
$results);
$this->assert_equal("new title", $photo->title);
$this->assert_equal("new description", $photo->description);