Another try at serving css for API rendered views
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 22 Jan 2011 06:20:52 +0000 (01:20 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 22 Jan 2011 06:20:52 +0000 (01:20 -0500)
ansel/lib/View/GalleryRenderer/GalleryLightbox.php
ansel/migration/9_ansel_upgrade_sqlng.php.foo [new file with mode: 0644]

index a298e1d..dc09d03 100644 (file)
@@ -13,7 +13,6 @@
  */
 class Ansel_View_GalleryRenderer_GalleryLightbox extends Ansel_View_GalleryRenderer_Base
 {
-
     public function __construct($view)
     {
         parent::__construct($view);
@@ -23,6 +22,7 @@ class Ansel_View_GalleryRenderer_GalleryLightbox extends Ansel_View_GalleryRende
     /**
      * Perform any tasks that should be performed before the view is rendered.
      *
+     * @TODO: move to const'r
      */
     protected function _init()
     {
@@ -58,34 +58,40 @@ class Ansel_View_GalleryRenderer_GalleryLightbox extends Ansel_View_GalleryRende
         /* Get JSON data for view */
         // 0 == normal, 1 == by date
         if ($this->mode == 0) {
-            $json = $this->view->json(array('full' => !empty($this->view->api), 'perpage' => $this->perpage));
+            $json = $this->view->json(array(
+                'full' => !empty($this->view->api),
+                'perpage' => $this->perpage));
         } else {
             if (!empty($this->date['day']) && $this->numTiles) {
-                $json = $this->view->json(array('full' => !empty($this->view->api), 'perpage' => $this->perpage));
+                $json = $this->view->json(array(
+                    'full' => !empty($this->view->api),
+                    'perpage' => $this->perpage));
             } else {
                 $json = '[]';
             }
         }
 
-        /* Don't bother if we are being called from the api */
+        // Don't bother if we are being called from the api
         if (!$this->view->api) {
-            $option_edit = $this->view->gallery->hasPermission($GLOBALS['registry']->getAuth(),
-                                                         Horde_Perms::EDIT);
+            $option_edit = $this->view->gallery->hasPermission(
+                $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT);
             $option_select = $option_delete = $this->view->gallery->hasPermission(
                 $GLOBALS['registry']->getAuth(), Horde_Perms::DELETE);
-            $option_move = ($option_delete && $GLOBALS['injector']->getInstance('Ansel_Storage')->countGalleries(Horde_Perms::EDIT));
-            $option_copy = ($option_edit && $GLOBALS['injector']->getInstance('Ansel_Storage')->countGalleries(Horde_Perms::EDIT));
+            $option_move = $option_delete &&
+                $GLOBALS['injector']->getInstance('Ansel_Storage')->countGalleries(Horde_Perms::EDIT);
+            $option_copy = $option_edit &&
+                $GLOBALS['injector']->getInstance('Ansel_Storage')->countGalleries(Horde_Perms::EDIT);
             /* See if we requested a show_actions change (fallback for non-js) */
             if (Horde_Util::getFormData('actionID', '') == 'show_actions') {
                 $prefs->setValue('show_actions', (int)!$prefs->getValue('show_actions'));
             }
         }
 
-        /* Set up the pager */
-        $date_params = Ansel::getDateParameter(
-            array('year' => !empty($this->view->year) ? $this->view->year : 0,
-                  'month' => !empty($this->view->month) ? $this->view->month : 0,
-                  'day' => !empty($this->view->day) ? $this->view->day : 0));
+        // Set up the pager
+        $date_params = Ansel::getDateParameter(array(
+            'year' => !empty($this->view->year) ? $this->view->year : 0,
+            'month' => !empty($this->view->month) ? $this->view->month : 0,
+            'day' => !empty($this->view->day) ? $this->view->day : 0));
 
         $vars = Horde_Variables::getDefaultVariables();
         if (!empty($this->view->page)) {
@@ -118,25 +124,26 @@ class Ansel_View_GalleryRenderer_GalleryLightbox extends Ansel_View_GalleryRende
                         'url' => $pagerurl,
                         'perpage' => $this->perpage,
                         'url_callback' => $callback);
-
         $pager = new Horde_Core_Ui_Pager('page', $vars, $params);
+
         Horde::startBuffer();
-        /* Create the js variables to pass to the lightbox script */
+
+        // Lightbox js variables
         $jsvars = array('graphics_dir' => Horde::url(Horde_Themes::img(), true, -1),
                         'image_text' => _("Photo"),
                         'of_text' => _("of"),
                         'start_page' => $page);
-
         $flipped = array_flip($date_params);
         if (count($flipped) == 1 && !empty($flipped[0])) {
             $jsvars['gallery_url'] = $pagerurl . '?';
         } else {
             $jsvars['gallery_url'] = $pagerurl . '&';
         }
-        /* Output js/css here if we are calling via the api */
+        
+        // Output js/css here if we are calling via the api
         if ($this->view->api) {
             $GLOBALS['injector']->getInstance('Horde_Themes_Css')->addThemeStylesheet('lightbox.css');
-            Horde::includeStylesheetFiles(array('nobase' => true));
+            Horde::includeStylesheetFiles(array('nobase' => true), true);
             $includes = $GLOBALS['injector']->createInstance('Horde_Script_Files');
             $includes->add('accesskeys.js', 'horde', true);
             $includes->add('effects.js', 'horde', true);
@@ -144,7 +151,8 @@ class Ansel_View_GalleryRenderer_GalleryLightbox extends Ansel_View_GalleryRende
             $includes->includeFiles();
         }
 
-        /* Needed in the template files */
+        // Needed in the template files
+        // @TODO: Horde_View
         $tilesperrow = $this->view->tilesperrow ? $this->view->tilesperrow : $prefs->getValue('tilesperrow');
         $cellwidth = round(100 / $tilesperrow);
         $count = 0;
diff --git a/ansel/migration/9_ansel_upgrade_sqlng.php.foo b/ansel/migration/9_ansel_upgrade_sqlng.php.foo
new file mode 100644 (file)
index 0000000..be7b787
--- /dev/null
@@ -0,0 +1,176 @@
+<?php
+/**
+ * @author   Jan Schneider <jan@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/gpl.html GPL
+ * @package  Kronolith
+ */
+
+require_once dirname(__FILE__) . '/../lib/Kronolith.php';
+
+/**
+ * Adds tables for the Sqlng share driver.
+ *
+ * Copyright 2011 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author   Jan Schneider <jan@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/gpl.html GPL
+ * @package  Kronolith
+ */
+class KronolithUpgradeSqlng extends Horde_Db_Migration_Base
+{
+    /**
+     * Upgrade.
+     */
+    public function up()
+    {
+        $t = $this->createTable('kronolith_sharesng', array('primaryKey' => 'share_id'));
+        $t->column('share_name', 'string', array('limit' => 255, 'null' => false));
+        $t->column('share_owner', 'string', array('limit' => 255));
+        $t->column('share_flags', 'integer', array('default' => 0, 'null' => false));
+        $t->column('perm_creator_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_creator_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_creator_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_creator_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_creator_' . Kronolith::PERMS_DELEGATE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_default_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_default_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_default_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_default_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_default_' . Kronolith::PERMS_DELEGATE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_guest_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_guest_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_guest_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_guest_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_guest_' . Kronolith::PERMS_DELEGATE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('attribute_name', 'string', array('limit' => 255, 'null' => false));
+        $t->column('attribute_desc', 'string', array('limit' => 255));
+        $t->column('attribute_color', 'string', array('limit' => 7));
+        $t->end();
+
+        $this->addIndex('kronolith_sharesng', array('share_name'));
+        $this->addIndex('kronolith_sharesng', array('share_owner'));
+        $this->addIndex('kronolith_sharesng', array('perm_creator_' . Horde_Perms::SHOW));
+        $this->addIndex('kronolith_sharesng', array('perm_creator_' . Horde_Perms::READ));
+        $this->addIndex('kronolith_sharesng', array('perm_creator_' . Horde_Perms::EDIT));
+        $this->addIndex('kronolith_sharesng', array('perm_creator_' . Horde_Perms::DELETE));
+        $this->addIndex('kronolith_sharesng', array('perm_creator_' . Kronolith::PERMS_DELEGATE));
+        $this->addIndex('kronolith_sharesng', array('perm_default_' . Horde_Perms::SHOW));
+        $this->addIndex('kronolith_sharesng', array('perm_default_' . Horde_Perms::READ));
+        $this->addIndex('kronolith_sharesng', array('perm_default_' . Horde_Perms::EDIT));
+        $this->addIndex('kronolith_sharesng', array('perm_default_' . Horde_Perms::DELETE));
+        $this->addIndex('kronolith_sharesng', array('perm_default_' . Kronolith::PERMS_DELEGATE));
+        $this->addIndex('kronolith_sharesng', array('perm_guest_' . Horde_Perms::SHOW));
+        $this->addIndex('kronolith_sharesng', array('perm_guest_' . Horde_Perms::READ));
+        $this->addIndex('kronolith_sharesng', array('perm_guest_' . Horde_Perms::EDIT));
+        $this->addIndex('kronolith_sharesng', array('perm_guest_' . Horde_Perms::DELETE));
+        $this->addIndex('kronolith_sharesng', array('perm_guest_' . Kronolith::PERMS_DELEGATE));
+
+        $t = $this->createTable('kronolith_sharesng_groups', array('primaryKey' => false));
+        $t->column('share_id', 'integer', array('null' => false));
+        $t->column('group_uid', 'string', array('limit' => 255, 'null' => false));
+        $t->column('perm_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Kronolith::PERMS_DELEGATE, 'boolean', array('default' => false, 'null' => false));
+        $t->end();
+
+        $this->addIndex('kronolith_sharesng_groups', array('share_id'));
+        $this->addIndex('kronolith_sharesng_groups', array('group_uid'));
+        $this->addIndex('kronolith_sharesng_groups', array('perm_' . Horde_Perms::SHOW));
+        $this->addIndex('kronolith_sharesng_groups', array('perm_' . Horde_Perms::READ));
+        $this->addIndex('kronolith_sharesng_groups', array('perm_' . Horde_Perms::EDIT));
+        $this->addIndex('kronolith_sharesng_groups', array('perm_' . Horde_Perms::DELETE));
+        $this->addIndex('kronolith_sharesng_groups', array('perm_' . Kronolith::PERMS_DELEGATE));
+
+        $t = $this->createTable('kronolith_sharesng_users', array('primaryKey' => false));
+        $t->column('share_id', 'integer', array('null' => false));
+        $t->column('user_uid', 'string', array('limit' => 255));
+        $t->column('perm_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Kronolith::PERMS_DELEGATE, 'boolean', array('default' => false, 'null' => false));
+        $t->end();
+
+        $this->addIndex('kronolith_sharesng_users', array('share_id'));
+        $this->addIndex('kronolith_sharesng_users', array('user_uid'));
+        $this->addIndex('kronolith_sharesng_users', array('perm_' . Horde_Perms::SHOW));
+        $this->addIndex('kronolith_sharesng_users', array('perm_' . Horde_Perms::READ));
+        $this->addIndex('kronolith_sharesng_users', array('perm_' . Horde_Perms::EDIT));
+        $this->addIndex('kronolith_sharesng_users', array('perm_' . Horde_Perms::DELETE));
+        $this->addIndex('kronolith_sharesng_users', array('perm_' . Kronolith::PERMS_DELEGATE));
+
+        $this->dataUp();
+    }
+
+    /**
+     * Downgrade
+     */
+    public function down()
+    {
+        $this->dropTable('kronolith_sharesng');
+        $this->dropTable('kronolith_sharesng_groups');
+        $this->dropTable('kronolith_sharesng_users');
+    }
+
+    public function dataUp()
+    {
+        $whos = array('creator', 'default', 'guest');
+        $perms = array(Horde_Perms::SHOW,
+                       Horde_Perms::READ,
+                       Horde_Perms::EDIT,
+                       Horde_Perms::DELETE,
+                       Kronolith::PERMS_DELEGATE);
+
+        $sql = 'INSERT INTO kronolith_sharesng (share_id, share_name, share_owner, share_flags, attribute_name, attribute_desc, attribute_color';
+        $count = 0;
+        foreach ($whos as $who) {
+            foreach ($perms as $perm) {
+                $sql .= ', perm_' . $who . '_' . $perm;
+                $count++;
+            }
+        }
+        $sql .= ') VALUES (?, ?, ?, ?, ?, ?, ?' . str_repeat(', ?', $count) . ')';
+
+        foreach ($this->select('SELECT * FROM kronolith_shares') as $share) {
+            $values = array($share['share_id'],
+                            $share['share_name'],
+                            $share['share_owner'],
+                            $share['share_flags'],
+                            $share['attribute_name'],
+                            $share['attribute_desc'],
+                            $share['attribute_color']);
+            foreach ($whos as $who) {
+                foreach ($perms as $perm) {
+                    $values[] = (bool)($share['perm_' . $who] & $perm);
+                }
+            }
+            $this->insert($sql, $values);
+        }
+
+        foreach (array('user', 'group') as $what) {
+            $sql = 'INSERT INTO kronolith_sharesng_' . $what . 's (share_id, ' . $what . '_uid';
+            $count = 0;
+            foreach ($perms as $perm) {
+                $sql .= ', perm_' . $perm;
+                $count++;
+            }
+            $sql .= ') VALUES (?, ?' . str_repeat(', ?', $count) . ')';
+
+            foreach ($this->select('SELECT * FROM kronolith_shares_' . $what . 's') as $share) {
+                $values = array($share['share_id'],
+                                $share[$what . '_uid']);
+                foreach ($perms as $perm) {
+                    $values[] = (bool)($share['perm'] & $perm);
+                }
+                $this->insert($sql, $values);
+            }
+        }
+    }
+}