summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Kinkade <nkinkade@nkinka.de>2009-12-05 03:44:14 +0000
committerNathan Kinkade <nkinkade@nkinka.de>2009-12-05 03:44:14 +0000
commit65684fa3a9f9ff5cea918b75ba31684a0049a9f9 (patch)
tree4ed939cd1f274f1416dbf6aacd0f26a420c1cb9e
Initial checkin.
-rw-r--r--controllers/randimg.php29
-rw-r--r--helpers/randimg.php41
-rw-r--r--module.info3
-rw-r--r--views/randimg.html.php2
4 files changed, 75 insertions, 0 deletions
diff --git a/controllers/randimg.php b/controllers/randimg.php
new file mode 100644
index 0000000..3045f22
--- /dev/null
+++ b/controllers/randimg.php
@@ -0,0 +1,29 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+class randimg_Controller extends REST_Controller {
+
+ protected $resource_type = "randimg";
+
+ public function _index() {
+ // Far from perfection, but at least require view permission for the root album
+ $album = ORM::factory("item", 1);
+ access::required("view", $album);
+ print randimg::randimg_link();
+ }
+
+}
diff --git a/helpers/randimg.php b/helpers/randimg.php
new file mode 100644
index 0000000..8917858
--- /dev/null
+++ b/helpers/randimg.php
@@ -0,0 +1,41 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+class randimg_Core {
+
+ static function randimg_link() {
+
+ $db = Database::instance();
+ $query = "
+ SELECT i1.name, i1.title, i1.description, i2.slug
+ FROM items i1 JOIN items i2
+ ON i1.parent_id = i2.id
+ ORDER BY RAND()
+ LIMIT 1;
+ ";
+ $result = $db->query($query)->current();
+
+ $randimg = new View("randimg.html");
+ $relpath = "$result->slug/$result->name";
+ $randimg->imgpath = $relpath;
+ $randimg->img_title = $result->title;
+
+ return $randimg;
+
+ }
+
+}
diff --git a/module.info b/module.info
new file mode 100644
index 0000000..386907d
--- /dev/null
+++ b/module.info
@@ -0,0 +1,3 @@
+name = "RandImg"
+description = "Returns an <img> link of a random image."
+version = 1
diff --git a/views/randimg.html.php b/views/randimg.html.php
new file mode 100644
index 0000000..f3ae4bf
--- /dev/null
+++ b/views/randimg.html.php
@@ -0,0 +1,2 @@
+<?php defined("SYSPATH") or die("No direct script access.") ?>
+<?php echo "<a href='http://natha.nkinka.de/photos/index.php/$imgpath' title='$img_title'><img src='http://natha.nkinka.de/photos/var/resizes/$imgpath' style='border: thin solid black;' alt='$img_title' /></a>"; ?>