Fixed some PHP warnings and display issues. Brought up to date with 1.1.x plugin management/install/upgrade system.
authorDan Fuhry <dan@enanocms.org>
Sun, 01 Aug 2010 12:42:21 -0400
changeset 39 e9a7e37bdadd
parent 38 512951548faa
child 40 2607b83e986d
Fixed some PHP warnings and display issues. Brought up to date with 1.1.x plugin management/install/upgrade system.
plugins/Gallery.php
plugins/gallery/browser.php
--- a/plugins/Gallery.php	Wed Aug 26 23:37:37 2009 -0400
+++ b/plugins/Gallery.php	Sun Aug 01 12:42:21 2010 -0400
@@ -1,12 +1,15 @@
 <?php
-/*
-Plugin Name: Snapr
-Plugin URI: http://enanocms.org/plugin/snapr
-Description: Provides an intuitive image gallery system with a browser, viewer for individual images, upload interface, and comment system integration.
-Author: Dan Fuhry
-Version: 0.1 beta 3
-Author URI: http://enanocms.org/
-*/
+/**!info**
+{
+  "Plugin Name"  : "Snapr",
+  "Plugin URI"   : "http://enanocms.org/plugin/snapr",
+  "Description"  : "Provides an intuitive image gallery system with a browser, viewer for individual images, upload interface, and comment system integration.",
+  "Author"       : "Dan Fuhry",
+  "Version"      : "0.1b3",
+  "Author URI"   : "http://enanocms.org/",
+  "Version list" : ['0.1b1', '0.1b2', '0.1 beta 3', '0.1b3']
+}
+**!*/
 
 global $db, $session, $paths, $template, $plugins; // Common objects
 
@@ -19,8 +22,9 @@
   die_semicritical('Snapr can\'t load on this site', '<p>This version of Snapr requires Enano 1.1.6 or later.</p>');
 }
 
-$magick_path = getConfig('imagemagick_path');
-if ( !file_exists($magick_path) || !is_executable($magick_path) )
+$magick_path = getConfig('imagemagick_path', '/usr/bin/convert');
+$have_gd_scale_support = function_exists('imagecreatetruecolor') && function_exists('imagejpeg') && function_exists('imagecopyresampled');
+if ( (!file_exists($magick_path) || !is_executable($magick_path)) && !$have_gd_scale_support )
 {
   $fn = basename(__FILE__);
   // set disabled flag with new plugin system
@@ -40,47 +44,52 @@
     setConfig("plugin_$fn", '0');
   }
   
-  die_semicritical('Snapr can\'t load on this site', '<p>You must have ImageMagick installed and working to use this plugin. The plugin has been disabled, please setup ImageMagick and then re-enable it.</p>');
+  die_semicritical('Snapr can\'t load on this site', '<p>You must have ImageMagick or GD installed and working to use this plugin. The plugin has been disabled, please setup ImageMagick and then re-enable it.</p>');
 }
 
-if ( !getConfig('gallery_version') )
-{
-  $q = $db->sql_query('CREATE TABLE '.table_prefix.'gallery(
-                        img_id int(12) NOT NULL auto_increment,
-                        is_folder tinyint(1) NOT NULL DEFAULT 0,
-                        folder_parent int(12) DEFAULT NULL,
-                        img_title varchar(255) NOT NULL DEFAULT \'\',
-                        img_desc longtext NOT NULL DEFAULT \'\',
-                        print_sizes longtext NOT NULL DEFAULT \'\',
-                        img_filename varchar(255) NOT NULL,
-                        img_time_upload int(12) NOT NULL DEFAULT 0,
-                        img_time_mod int(12) NOT NULL DEFAULT 0,
-                        img_tags longtext,
-                        PRIMARY KEY ( img_id )
-                      );');
-  
-  if ( !$q )
-    $db->_die();
-  
-  $q = $db->sql_query('CREATE FULLTEXT INDEX '.table_prefix.'gal_idx ON '.table_prefix.'gallery(img_title, img_desc);');
-  
-  if ( !$q )
-    $db->_die();
-  
-  $q = $db->sql_query('INSERT INTO '.table_prefix.'gallery(img_title,img_desc,img_filename,img_time_upload,img_time_mod,img_tags) VALUES(\'Welcome to Snapr!\', \'You\'\'re past the hard part - Snapr is set up and working on your server. What you\'\'re looking at now is what most users will see when they look at an image in your gallery. The next step is to [[Special:GalleryUpload|upload some images]]. After that, make your gallery publicly accessible by adding a link to the [[Special:Gallery|browser]], if you haven\'\'t already done so. See the README file included with Snapr for more information.\', \'snapr-logo.png\', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), \'[]\');');
-  
-  if ( !$q )
-    $db->_die();
-  
-  setConfig('gallery_version', GALLERY_VERSION);
-}
-if ( getConfig('gallery_version') == '0.1b1' )
-{
-  $q = $db->sql_query('ALTER TABLE ' . table_prefix . 'gallery ADD COLUMN img_tags longtext;');
-  if ( !$q )
-    $db->_die();
-  setConfig('gallery_version', '0.1b2');
-}
+/**!install dbms="mysql"; **
+
+CREATE TABLE {{TABLE_PREFIX}}gallery(
+	img_id int(12) NOT NULL auto_increment,
+	is_folder tinyint(1) NOT NULL DEFAULT 0,
+	folder_parent int(12) DEFAULT NULL,
+	img_title varchar(255) NOT NULL DEFAULT '',
+	img_desc longtext NOT NULL DEFAULT '',
+	print_sizes longtext NOT NULL DEFAULT '',
+	img_filename varchar(255) NOT NULL,
+	img_time_upload int(12) NOT NULL DEFAULT 0,
+	img_time_mod int(12) NOT NULL DEFAULT 0,
+	img_tags longtext,
+	PRIMARY KEY ( img_id )
+);
+
+CREATE FULLTEXT INDEX {{TABLE_PREFIX}}gal_idx ON {{TABLE_PREFIX}}gallery(img_title, img_desc);
+
+INSERT INTO {{TABLE_PREFIX}}gallery(img_title,img_desc,img_filename,img_time_upload,img_time_mod,img_tags) VALUES
+	('Welcome to Snapr!',
+	 'You''re past the hard part - Snapr is set up and working on your server. What you''re looking at now is what most users will see when they look at an image in your gallery. The next step is to [[Special:GalleryUpload|upload some images]]. After that, make your gallery publicly accessible by adding a link to the [[Special:Gallery|browser]], if you haven''t already done so. See the README file included with Snapr for more information.',
+	 'snapr-logo.png',
+	 UNIX_TIMESTAMP(),
+	 UNIX_TIMESTAMP(),
+	 '[]');
+
+**!*/
+
+/**!uninstall dbms="mysql"; **
+ALTER TABLE {{TABLE_PREFIX}}gallery DROP INDEX {{TABLE_PREFIX}}gal_idx;
+DROP TABLE {{TABLE_PREFIX}}gallery;
+
+**!*/
+
+/**!upgrade dbms="mysql"; from="0.1b1"; to="0.1b2"; **
+ALTER TABLE {{TABLE_PREFIX}}gallery ADD COLUMN img_tags longtext;
+**!*/
+
+/**!upgrade dbms="mysql"; from="0.1b2"; to="0.1b3"; **
+**!*/
+
+/**!upgrade dbms="mysql"; from="0.1 beta 3"; to="0.1b3"; **
+**!*/
 
 require( ENANO_ROOT . '/plugins/gallery/functions.php' );
 require( ENANO_ROOT . '/plugins/gallery/nssetup.php' );
--- a/plugins/gallery/browser.php	Wed Aug 26 23:37:37 2009 -0400
+++ b/plugins/gallery/browser.php	Sun Aug 01 12:42:21 2010 -0400
@@ -16,15 +16,7 @@
 ## BROWSER INTERFACE
 ##
 
-$plugins->attachHook('base_classes_initted', '
-  global $paths;
-    $paths->add_page(Array(
-      \'name\'=>\'Image gallery\',
-      \'urlname\'=>\'Gallery\',
-      \'namespace\'=>\'Special\',
-      \'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
-      ));
-  ');
+$plugins->attachHook('session_started', 'register_special_page("Gallery", "Image gallery");');
 
 /**
  * Class to handle building the HTML for gallery pages. Called by the pagination function.
@@ -281,7 +273,8 @@
     
     $first_row = $row;
     
-    $db->sql_data_seek(0, $img_query);
+    if ( $db->numrows($img_query) > 0 )
+      $db->sql_data_seek(0, $img_query);
     
     /* $folders = $folders_old; */
   }
@@ -430,7 +423,8 @@
         </div>
         <div class="select-pad">&nbsp;</div>';
   
-  $db->sql_data_seek(0, $img_query);
+  if ( $db->numrows($img_query) > 0 )
+	$db->sql_data_seek(0, $img_query);
   
   //
   // Main fetcher
@@ -452,7 +446,14 @@
   $per_page = 25;
   
   $html = paginate($img_query, '{img_id}', $db->numrows($img_query), makeUrl($paths->fullpage, 'sort=' . $sort_column . '&order=' . $sort_order . '&start=%s', false), $start, $per_page, $callers, '<ul class="snapr-gallery">', '</ul><span class="menuclear"></span>');
-  echo $html;
+  if ( empty($html) )
+  {
+  	  echo '<h2 class="emptymessage">No images</h2>';
+  }
+  else
+  {
+	  echo $html;
+  }
   
   if ( $session->user_level >= USER_LEVEL_ADMIN )
   {