adding Photo Gallery
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 8 Feb 2010 19:54:30 +0000 (19:54 +0000)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 8 Feb 2010 19:54:30 +0000 (19:54 +0000)
Toolkit/Photos/Display.php [new file with mode: 0755]
Toolkit/Photos/assets/.keepme [new file with mode: 0644]
Toolkit/Photos/templates/compiled/.cvsignore [new file with mode: 0755]
Toolkit/Photos/templates/compiled/.keepme [new file with mode: 0644]
Toolkit/Photos/templates/compiled/photoCats.html.en.php [new file with mode: 0755]
Toolkit/Photos/templates/compiled/photoCats.html.gettext.serial [new file with mode: 0644]
Toolkit/Photos/templates/compiled/photos.html.en.php [new file with mode: 0755]
Toolkit/Photos/templates/photoCats.html [new file with mode: 0755]
Toolkit/Photos/templates/photos.html [new file with mode: 0755]

diff --git a/Toolkit/Photos/Display.php b/Toolkit/Photos/Display.php
new file mode 100755 (executable)
index 0000000..0159542
--- /dev/null
@@ -0,0 +1,255 @@
+<?php
+
+/**
+ * Display.php
+ *
+ * PHP version 5
+ *
+ * @category  Photos
+ * @package   Toolkit_Photos
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2009 Gaslight Media
+ * @license   Gaslight Media
+ * @version   CVS: $Id: Display.php,v 1.8 2010/01/15 01:13:01 jamie Exp $
+ * @link      <>
+ */
+
+/**
+ * Toolkit_Photos_Display
+ *
+ * Display the Photo Gallery assoc to a toolbox page
+ *
+ * @category  Photos
+ * @package   Toolkit_Photos
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2009 Gaslight Media
+ * @license   Gaslight Media
+ * @link      <>
+ */
+class Toolkit_Photos_Display
+{
+    // {{{ Properties
+
+    /**
+     * Options for Flexy Templates
+     * @var    array
+     * @access protected
+     */
+    protected $flexyOptions = array(
+        'templateDir'    => '/templates',
+        'compileDir'    => '/templates/compiled',
+        'forceCompile'    => false,
+        'allowPHP'        => true,
+    );
+
+    /**
+     * page name for form action and links
+     * @var    unknown
+     * @access protected
+     */
+    protected $pageName;
+
+    /**
+     * Photo Table Name
+     * @var    string
+     * @access protected
+     */
+    protected $photoTable = 'photo';
+
+    /**
+     * Photo Category Table Name
+     * @var    string
+     * @access protected
+     */
+    protected $categoryTable = 'photo_category';
+
+    /**
+     * rowCount
+     *
+     * @var float
+     * @access protected
+     */
+    protected $rowCount = 3;
+    // }}}
+    // {{{ __construct()
+
+    /**
+     * __construct()
+     *
+     * @return void
+     * @access public
+     */
+    function __construct()
+    {
+        // assign the global dbh to $this->dbh;
+        $this->dbh = Toolkit_Database::getInstance();
+        // set paths for templates
+        $this->flexyOptions['templateDir'] = dirname(__FILE__)
+            .$this->flexyOptions['templateDir'];
+        $this->flexyOptions['compileDir']  = dirname(__FILE__)
+            .$this->flexyOptions['compileDir'];
+        // the main display page for events to link to
+        $this->pageName = BASE_URL.'index.php?catid='.$_REQUEST['catid'];
+    }
+
+    // }}}
+    // {{{ listPhotoCategories()
+
+    /**
+     * listPhotoCategories()
+     *
+     * Display Photo Categories
+     *
+     * @return mixed  Return description (if any) ...
+     * @access public
+     */
+    function listPhotoCategories()
+    {
+        $sql = "
+          SELECT pc.*
+            FROM photo_category pc, photo_category_bus pcb
+           WHERE pcb.photocat_id = pc.id
+             AND pcb.buscat_id = {$_REQUEST['catid']}
+             AND pc.id IN (
+                 SELECT distinct(catid)
+                   FROM photo)
+        ORDER BY pcb.pos;";
+        try {
+            $data = $this->dbh->query($sql)->fetchAll();
+            if (is_array($data)) {
+                $i = 0;
+                foreach ($data as &$row) {
+                    unset($row['image']);
+                    // use the first one from its photos
+                    $sql = "
+                    SELECT image
+                      FROM photo
+                     WHERE catid = {$row['id']}
+                       AND image != ''";
+                    try {
+                        $row2 = $this->dbh->query($sql)->fetch();
+                        $data[$i]['image'] = $row2['image'];
+                    } catch(PDOException $e) {
+                        Toolkit_Common::handleError($e);
+                    }
+                    ++$i;
+                }
+                $template      = new HTML_Template_Flexy($this->flexyOptions);
+                $page          = new stdClass;
+                $page->appbase = GLM_APP_BASE_URL;
+                $page->page    = BASE_URL.'index.php?catid='.$_REQUEST['catid'].'&photo_catid=';
+                $page->cats    = $data;
+                $page->imgPath = PHOTO_SMALL_URL;
+                $template->compile('photoCats.html');
+                return $template->bufferedOutputObject($page);
+            } else {
+                return '';
+            }
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+    }
+
+    // }}}
+    // {{{ listPhotos()
+
+    /**
+     * listPhotos()
+     *
+     * Display Photos
+     *
+     * @return mixed  Return description (if any) ...
+     * @access public
+     */
+    function listPhotos()
+    {
+        // where clauses
+        if ($_REQUEST['photo_catid']) {
+            // grab photo album name for display
+            try {
+                $sql = "
+                SELECT category
+                  FROM photo_category
+                 WHERE id = :id";
+                $stmt1 = $this->dbh->prepare($sql);
+                $stmt1->bindParam(":id", $_REQUEST['photo_catid'], PDO::PARAM_INT);
+                $stmt1->execute();
+                $albumName = $stmt1->fetchColumn();
+            } catch(PDOException $e) {
+                Toolkit_Common::handleError($e);
+            }
+            $where[] = "catid = {$_REQUEST['photo_catid']}";
+        }
+        // query
+        $sql = "
+        SELECT *
+        FROM   {$this->photoTable}";
+        if (is_array($where)) {
+            $sql .= " WHERE ".implode(" AND ", $where);
+        }
+        $sql .= " ORDER BY pos";
+        try {
+            $data = $this->dbh->query($sql)->fetchAll();
+            $count = 1;
+            $trueCount = 1;
+            $num = count($data);
+            foreach ($data as &$row) {
+                if ($count == 1) {
+                    $row['firstInRow'] = true;
+                } else {
+                    $row['firstInRow'] = false;
+                }
+                if ($count == $this->rowCount || $trueCount == $num) {
+                    $row['lastInRow'] = true;
+                    $count = 0;
+                } else {
+                    $row['lastInRow'] = false;
+                }
+                ++$count;
+                ++$trueCount;
+            }
+            if (is_array($data)) {
+                $template      = new HTML_Template_Flexy($this->flexyOptions);
+                $page          = new stdClass;
+                $page->album   = ($albumName) ? $albumName: 'Photo Gallery';
+                $page->appbase = GLM_APP_BASE_URL;
+                $page->photos  = $data;
+                $page->imgPath = PHOTO_SMALL_URL;
+                $page->orgPath = PHOTO_LARGE_URL;
+                $template->compile('photos.html');
+                return $template->bufferedOutputObject($page);
+            } else {
+                return '';
+            }
+        } catch(PDOException $e) {
+            Toolkit_Common::handleError($e);
+        }
+    }
+
+    // }}}
+    // {{{ toHTML()
+
+    /**
+     * toHTML()
+     *
+     * call to listPhotos function for display of Photos
+     *
+     * @return void
+     * @access public
+     */
+    function toHTML()
+    {
+               $GLOBALS['scripts'][] = GLM_APP_BASE_URL . 'gallery/thickbox-3.1.1.js';
+               $GLOBALS['styleSheets'][] = GLM_APP_BASE_URL . 'gallery/gallery.css';
+               $GLOBALS['styleSheets'][] = GLM_APP_BASE_URL . 'gallery/thickbox.css';
+
+        if (is_array($_REQUEST['photo_catid'])) {
+            return $this->listPhotoCategories();
+        } elseif ($_REQUEST['photo_catid']) {
+            return $this->listPhotos();
+        }
+    }
+
+    // }}}
+}
+?>
diff --git a/Toolkit/Photos/assets/.keepme b/Toolkit/Photos/assets/.keepme
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/Toolkit/Photos/templates/compiled/.cvsignore b/Toolkit/Photos/templates/compiled/.cvsignore
new file mode 100755 (executable)
index 0000000..65fb5e5
--- /dev/null
@@ -0,0 +1 @@
+* *.*
diff --git a/Toolkit/Photos/templates/compiled/.keepme b/Toolkit/Photos/templates/compiled/.keepme
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/Toolkit/Photos/templates/compiled/photoCats.html.en.php b/Toolkit/Photos/templates/compiled/photoCats.html.en.php
new file mode 100755 (executable)
index 0000000..db6cfd2
--- /dev/null
@@ -0,0 +1,8 @@
+<script type="text/javascript" src="<?php echo htmlspecialchars($t->appbase);?>gallery/thickbox.js"></script>
+<div id="photo-gallery">
+  <p>Click an image to enter a Photo Album</p>
+  <?php if ($this->options['strict'] || (is_array($t->cats)  || is_object($t->cats))) foreach($t->cats as $photo) {?><div class="thumb">
+    <div class="photocattitle"><?php echo htmlspecialchars($photo['category']);?></div>
+    <a href="<?php echo htmlspecialchars($t->page);?><?php echo htmlspecialchars($photo['id']);?>"><img src="<?php echo htmlspecialchars($t->imgPath);?><?php echo htmlspecialchars($photo['image']);?>" alt="<?php echo htmlspecialchars($photo['image']);?>"></a>
+  </div><?php }?>
+</div>
diff --git a/Toolkit/Photos/templates/compiled/photoCats.html.gettext.serial b/Toolkit/Photos/templates/compiled/photoCats.html.gettext.serial
new file mode 100644 (file)
index 0000000..febccfc
--- /dev/null
@@ -0,0 +1 @@
+a:1:{i:0;s:37:"Click an image to enter a Photo Album";}
\ No newline at end of file
diff --git a/Toolkit/Photos/templates/compiled/photos.html.en.php b/Toolkit/Photos/templates/compiled/photos.html.en.php
new file mode 100755 (executable)
index 0000000..75b0fd7
--- /dev/null
@@ -0,0 +1,15 @@
+<div id="photo-gallery">
+  <h2><?php echo htmlspecialchars($t->album);?></h2>
+  <?php if ($this->options['strict'] || (is_array($t->photos)  || is_object($t->photos))) foreach($t->photos as $photo) {?>
+  <?php if ($photo['firstInRow'])  {?>
+  <div class="galleryRow">
+  <?php }?>
+  <div class="thumb">
+      <a href="<?php echo htmlspecialchars($t->orgPath);?><?php echo htmlspecialchars($photo['image']);?>" class="thickbox" rel="gallery-photos" title="<?php echo htmlspecialchars($photo['title']);?> <?php echo htmlspecialchars($photo['description']);?>"><img src="<?php echo htmlspecialchars($t->imgPath);?><?php echo htmlspecialchars($photo['image']);?>" title="<?php echo htmlspecialchars($photo['title']);?>" alt="<?php echo htmlspecialchars($photo['image']);?>"></a>
+      <div class="phototitle"><?php echo htmlspecialchars($photo['title']);?></div>
+  </div><!-- /.thumb -->
+  <?php if ($photo['lastInRow'])  {?>
+  </div><!-- /.galleryRow -->
+  <?php }?>
+  <?php }?>
+</div><!-- /.photo-gallery -->
diff --git a/Toolkit/Photos/templates/photoCats.html b/Toolkit/Photos/templates/photoCats.html
new file mode 100755 (executable)
index 0000000..e877442
--- /dev/null
@@ -0,0 +1,8 @@
+<script type="text/javascript" src="{appbase}gallery/thickbox.js"></script>
+<div id="photo-gallery">
+  <p>Click an image to enter a Photo Album</p>
+  <div class="thumb" flexy:foreach="cats,photo">
+    <div class="photocattitle">{photo[category]}</div>
+    <a href="{page}{photo[id]}"><img src="{imgPath}{photo[image]}" alt="{photo[image]}"></a>
+  </div>
+</div>
diff --git a/Toolkit/Photos/templates/photos.html b/Toolkit/Photos/templates/photos.html
new file mode 100755 (executable)
index 0000000..fdd861d
--- /dev/null
@@ -0,0 +1,15 @@
+<div id="photo-gallery">
+  <h2>{album}</h2>
+  {foreach:photos,photo}
+  {if:photo[firstInRow]}
+  <div class="galleryRow">
+  {end:}
+  <div class="thumb">
+      <a href="{orgPath}{photo[image]}" class="thickbox" rel="gallery-photos" title="{photo[title]} {photo[description]}"><img src="{imgPath}{photo[image]}" title="{photo[title]}" alt="{photo[image]}"></a>
+      <div class="phototitle">{photo[title]}</div>
+  </div><!-- /.thumb -->
+  {if:photo[lastInRow]}
+  </div><!-- /.galleryRow -->
+  {end:}
+  {end:}
+</div><!-- /.photo-gallery -->