summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/libraries/ORM_MPTT.php26
-rw-r--r--core/models/item.php11
-rw-r--r--modules/media_rss/controllers/media_rss.php15
-rw-r--r--modules/media_rss/views/feed.mrss.php28
4 files changed, 67 insertions, 13 deletions
diff --git a/core/libraries/ORM_MPTT.php b/core/libraries/ORM_MPTT.php
index f79ea910..023960e3 100644
--- a/core/libraries/ORM_MPTT.php
+++ b/core/libraries/ORM_MPTT.php
@@ -137,6 +137,32 @@ class ORM_MPTT_Core extends ORM {
}
/**
+ * Return all of the children of the specified type, ordered by id.
+ *
+ * @chainable
+ * @param string type to return
+ * @param integer SQL limit
+ * @param integer SQL offset
+ * @param boolean flag to return all grandchildren as well
+ * @return array ORM
+ */
+ function decendents_by_type($type="photo", $limit=NULL, $offset=0, $grand_children=false) {
+ if (!isset($this->children)) {
+ if (!empty($grandchildren)) {
+ $this->where("left >=", $this->left)
+ ->where("right <=", $this->right);
+ } else {
+ $this->where("parent_id", $this->id);
+ }
+ $this->children =
+ $this->where("type", $type)
+ ->orderby("id", "ASC")
+ ->find_all($limit, $offset);
+ }
+ return $this->children;
+ }
+
+ /**
* @see ORM::reload
*/
function reload() {
diff --git a/core/models/item.php b/core/models/item.php
index 5fcd16d0..f03d1a91 100644
--- a/core/models/item.php
+++ b/core/models/item.php
@@ -50,6 +50,14 @@ class Item_Model extends ORM_MPTT {
}
/**
+ * album: http://example.com/gallery3/var/resizes/album1/
+ * photo: http://example.com/gallery3/var/albums/album1/photo.jpg
+ */
+ public function url($index = FALSE, $protocol = FALSE) {
+ return $this->_relative_path(url::base($index, $protocol) . "albums", "", "");
+ }
+
+ /**
* album: /var/resizes/album1/.thumb.jpg
* photo: /var/albums/album1/photo.thumb.jpg
*/
@@ -183,6 +191,9 @@ class Item_Model extends ORM_MPTT {
} catch (Exception $e) {
return null;
}
+ } else if ($column == "height" || $column == "width") {
+ $dims = getimagesize($this->file_path());
+ return $column == "width" ? $dims[0] : $dims[1];
} else {
return parent::__get($column);
}
diff --git a/modules/media_rss/controllers/media_rss.php b/modules/media_rss/controllers/media_rss.php
index e6b499ea..f88e7004 100644
--- a/modules/media_rss/controllers/media_rss.php
+++ b/modules/media_rss/controllers/media_rss.php
@@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Media_RSS_Controller extends Controller {
+ public static $LIMIT = 10;
public function feed($id) {
$item = ORM::factory("item", $id)->find();
if (!$item->loaded) {
@@ -27,11 +28,15 @@ class Media_RSS_Controller extends Controller {
$view = new View("feed.mrss");
$view->item = $item;
- // This should probably be a method in ORM_MPTT
- $view->children = ORM::factory("item")
- ->where("parent_id", $item->id)
- ->where("type", "photo")
- ->find_all();
+ $offset = $this->input->get("offset", 0);
+ $view->children = $item->decendents_by_type("photo", Media_RSS_Controller::$LIMIT, $offset);
+
+ if (!empty($offset)) {
+ $view->prevOffset = $offset - Media_RSS_Controller::$LIMIT;
+ }
+ if ($view->children->count() >= Media_RSS_Controller::$LIMIT) {
+ $view->nextOffset = $offset + Media_RSS_Controller::$LIMIT;
+ }
header("Content-type: application/rss+xml");
print $view;
diff --git a/modules/media_rss/views/feed.mrss.php b/modules/media_rss/views/feed.mrss.php
index 4ccde722..f4efe27d 100644
--- a/modules/media_rss/views/feed.mrss.php
+++ b/modules/media_rss/views/feed.mrss.php
@@ -11,7 +11,7 @@
<atom:link rel="previous" href="<?= url::site("media_rss/feed/{$item->id}?offset={$prevOffset}") ?>" />
<? endif; ?>
<? if (isset($nextOffset)): ?>
- <atom:link rel="next" href="href="<?= url::site("media_rss/feed/{$item->id}?offset={$nextOffset}") ?>"/>
+ <atom:link rel="next" href="<?= url::site("media_rss/feed/{$item->id}?offset={$nextOffset}") ?>"/>
<? endif; ?>
<?
// @todo do we want to add an upload date to the items table?
@@ -20,16 +20,28 @@
<pubDate><?= $date ?></pubDate>
<lastBuildDate><?= $date ?></lastBuildDate>
<? foreach ($children as $child): ?>
- <item>
+ <item> $child->resize_url(false, "http")
<title><?= $child->title ?></title>
- <link><?= $child->resize_url(false, "http") ?></link>
+ <link><?= url::site("photos/$child->id", "http") ?></link>
<guid isPermaLink="false"><?= $child->id ?></guid>
<description><?= $child->description ?></description>
- <media:content url="<?= $child->thumbnail_url(false, "http") ?>"
- type="<?= $child->mime_type ?>"
- height="<?= $child->resize_height ?>"
- width="<?= $child->resize_width ?>"
- />
+ <media:group>
+ <media:thumbnail url="<?= $child->thumbnail_url(false, "http") ?>"
+ height="<?= $child->thumbnail_height ?>"
+ width="<?= $child->thumbnail_width ?>"
+ />
+ <media:content url="<?= $child->resize_url(false, "http") ?>"
+ type="<?= $child->mime_type ?>"
+ height="<?= $child->resize_height ?>"
+ width="<?= $child->resize_width ?>"
+ isDefault="true"
+ />
+ <media:content url="<?= $child->url(false, "http") ?>"
+ type="<?= $child->mime_type ?>"
+ height="<?= $child->height ?>"
+ width="<?= $child->width ?>"
+ />
+ </media:group>
</item>
<? endforeach; ?>
</channel>