NGG_Installer

Class NGG_Installer.

Defined (1)

The class is defined in the following location(s).

/admin/class-ngg-installer.php  
  1. class NGG_Installer { 
  2.  
  3. /** 
  4. * Create all tables and options. 
  5. * This function is called during the activation hook. 
  6. */ 
  7. public static function install() { 
  8.  
  9. global $wpdb; 
  10.  
  11. // Check for capability 
  12. if ( ! current_user_can( 'activate_plugins' ) ) { 
  13. return; 
  14.  
  15. // Set the capabilities for the administrator 
  16. $role = get_role( 'administrator' ); 
  17. // We need this role, no other chance 
  18. if ( empty( $role ) ) { 
  19. update_option( "ngg_init_check",  
  20. __( 'Sorry, NextCellent Gallery works only with a role called administrator', "nggallery" ) ); 
  21.  
  22. return; 
  23.  
  24. $role->add_cap( 'NextGEN Gallery overview' ); 
  25. $role->add_cap( 'NextGEN Use TinyMCE' ); 
  26. $role->add_cap( 'NextGEN Upload images' ); 
  27. $role->add_cap( 'NextGEN Manage gallery' ); 
  28. $role->add_cap( 'NextGEN Manage tags' ); 
  29. $role->add_cap( 'NextGEN Manage others gallery' ); 
  30. $role->add_cap( 'NextGEN Edit album' ); 
  31. $role->add_cap( 'NextGEN Change style' ); 
  32. $role->add_cap( 'NextGEN Change options' ); 
  33.  
  34. // upgrade function changed in WordPress 2.3 
  35. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 
  36.  
  37. // add charset & collate like wp core 
  38. $charset_collate = ''; 
  39.  
  40. if ( version_compare( $wpdb->get_var( "SELECT VERSION() AS `mysql_version`" ), '4.1.0', '>=' ) ) { 
  41. if ( ! empty( $wpdb->charset ) ) { 
  42. $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; 
  43. if ( ! empty( $wpdb->collate ) ) { 
  44. $charset_collate .= " COLLATE $wpdb->collate"; 
  45.  
  46. $nggpictures = $wpdb->prefix . 'ngg_pictures'; 
  47. $nggallery = $wpdb->prefix . 'ngg_gallery'; 
  48. $nggalbum = $wpdb->prefix . 'ngg_album'; 
  49.  
  50. // Create pictures table 
  51. $sql = "CREATE TABLE " . $nggpictures . " ( 
  52. pid BIGINT(20) NOT NULL AUTO_INCREMENT ,  
  53. image_slug VARCHAR(255) NOT NULL ,  
  54. post_id BIGINT(20) DEFAULT '0' NOT NULL ,  
  55. galleryid BIGINT(20) DEFAULT '0' NOT NULL ,  
  56. filename VARCHAR(255) NOT NULL ,  
  57. description MEDIUMTEXT NULL ,  
  58. alttext MEDIUMTEXT NULL ,  
  59. imagedate DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',  
  60. exclude TINYINT NULL DEFAULT '0' ,  
  61. sortorder BIGINT(20) DEFAULT '0' NOT NULL ,  
  62. meta_data LONGTEXT,  
  63. PRIMARY KEY (pid),  
  64. KEY post_id (post_id) 
  65. ) $charset_collate;"; 
  66. dbDelta( $sql ); 
  67.  
  68. // Create gallery table 
  69. $sql = "CREATE TABLE " . $nggallery . " ( 
  70. gid BIGINT(20) NOT NULL AUTO_INCREMENT ,  
  71. name VARCHAR(255) NOT NULL ,  
  72. slug VARCHAR(255) NOT NULL ,  
  73. path MEDIUMTEXT NULL ,  
  74. title MEDIUMTEXT NULL ,  
  75. galdesc MEDIUMTEXT NULL ,  
  76. pageid BIGINT(20) DEFAULT '0' NOT NULL ,  
  77. previewpic BIGINT(20) DEFAULT '0' NOT NULL ,  
  78. author BIGINT(20) DEFAULT '0' NOT NULL ,  
  79. PRIMARY KEY (gid) 
  80. ) $charset_collate;"; 
  81. dbDelta( $sql ); 
  82.  
  83. // Create albums table 
  84. $sql = "CREATE TABLE " . $nggalbum . " ( 
  85. id BIGINT(20) NOT NULL AUTO_INCREMENT ,  
  86. name VARCHAR(255) NOT NULL ,  
  87. slug VARCHAR(255) NOT NULL ,  
  88. previewpic BIGINT(20) DEFAULT '0' NOT NULL ,  
  89. albumdesc MEDIUMTEXT NULL ,  
  90. sortorder LONGTEXT NOT NULL,  
  91. pageid BIGINT(20) DEFAULT '0' NOT NULL,  
  92. PRIMARY KEY (id) 
  93. ) $charset_collate;"; 
  94. dbDelta( $sql ); 
  95.  
  96. // check one table again, to be sure 
  97. if ( ! $wpdb->get_var( "SHOW TABLES LIKE '$nggpictures'" ) ) { 
  98. update_option( "ngg_init_check",  
  99. __( 'NextCellent Gallery : Tables could not created, please check your database settings',  
  100. "nggallery" ) ); 
  101.  
  102. return; 
  103.  
  104. $options = get_option( 'ngg_options' ); 
  105. // set the default settings, if we didn't upgrade 
  106. if ( empty( $options ) ) { 
  107. NGG_Installer::set_default_options(); 
  108.  
  109. // if all is passed , save the DBVERSION 
  110. add_option( "ngg_db_version", NGG_DBVERSION ); 
  111.  
  112.  
  113. /** 
  114. * Setup the default option array for NextCellent. 
  115. * When adding new options, an upgrade should be made for existing users as well. 
  116. * @see NGG_Upgrader 
  117. */ 
  118. public static function set_default_options() { 
  119.  
  120. global $blog_id; 
  121.  
  122. $ngg_options['gallerypath'] = 'wp-content/gallery/'; // set default path to the gallery 
  123. $ngg_options['deleteImg'] = true; // delete Images 
  124. $ngg_options['swfUpload'] = true; // activate the batch upload 
  125. $ngg_options['usePermalinks'] = false; // use permalinks for parameters 
  126. $ngg_options['permalinkSlug'] = 'nggallery'; // the default slug for permalinks 
  127. $ngg_options['graphicLibrary'] = 'gd'; // default graphic library 
  128. $ngg_options['imageMagickDir'] = '/usr/local/bin/'; // default path to ImageMagick 
  129. $ngg_options['useMediaRSS'] = false; // activate the global Media RSS file 
  130. $ngg_options['usePicLens'] = false; // activate the PicLens Link for galleries 
  131. $ngg_options['silentUpdate'] = false; //If the database should be updated silently. 
  132.  
  133. // Tags / categories 
  134. $ngg_options['activateTags'] = false; // append related images 
  135. $ngg_options['appendType'] = 'tags'; // look for category or tags 
  136. $ngg_options['maxImages'] = 7; // number of images toshow 
  137.  
  138. // Thumbnail Settings 
  139. $ngg_options['thumbwidth'] = 100; // Thumb Width 
  140. $ngg_options['thumbheight'] = 75; // Thumb height 
  141. $ngg_options['thumbfix'] = true; // Fix the dimension 
  142. $ngg_options['thumbquality'] = 100; // Thumb Quality 
  143.  
  144. // Image Settings 
  145. $ngg_options['imgWidth'] = 800; // Image Width 
  146. $ngg_options['imgHeight'] = 600; // Image height 
  147. $ngg_options['imgQuality'] = 85; // Image Quality 
  148. $ngg_options['imgBackup'] = true; // Create a backup 
  149. $ngg_options['imgAutoResize'] = false; // Resize after upload 
  150.  
  151. // Gallery Settings 
  152. $ngg_options['galImages'] = 20; // Number of images per page 
  153. $ngg_options['galPagedGalleries'] = 0; // Number of galleries per page (in a album) 
  154. $ngg_options['galColumns'] = 0; // Number of columns for the gallery 
  155. $ngg_options['galShowSlide'] = true; // Show slideshow 
  156. $ngg_options['galTextSlide'] = __( '[Show as slideshow]', 'nggallery' ); // Text for slideshow 
  157. $ngg_options['galTextGallery'] = __( '[Show picture list]', 'nggallery' ); // Text for gallery 
  158. $ngg_options['galShowOrder'] = 'gallery'; // Show order 
  159. $ngg_options['galSort'] = 'sortorder'; // Sort order 
  160. $ngg_options['galSortDir'] = 'ASC'; // Sort direction 
  161. $ngg_options['galNoPages'] = true; // use no subpages for gallery 
  162. $ngg_options['galImgBrowser'] = false; // Show ImageBrowser, instead effect 
  163. $ngg_options['galHiddenImg'] = false; // For paged galleries we can hide image 
  164. $ngg_options['galAjaxNav'] = false; // AJAX Navigation for Shutter effect 
  165.  
  166. // Thumbnail Effect 
  167. $ngg_options['thumbEffect'] = 'shutter'; // select effect 
  168. $ngg_options['thumbCode'] = 'class="shutterset_%GALLERY_NAME%"'; 
  169.  
  170. // Watermark settings 
  171. $ngg_options['wmPos'] = 'botRight'; // Postion 
  172. $ngg_options['wmXpos'] = 5; // X Pos 
  173. $ngg_options['wmYpos'] = 5; // Y Pos 
  174. $ngg_options['wmType'] = 'text'; // Type : 'image' / 'text' 
  175. $ngg_options['wmPath'] = ''; // Path to image 
  176. $ngg_options['wmFont'] = 'arial.ttf'; // Font type 
  177. $ngg_options['wmSize'] = 10; // Font Size 
  178. $ngg_options['wmText'] = get_option( 'blogname' ); // Text 
  179. $ngg_options['wmColor'] = '000000'; // Font Color 
  180. $ngg_options['wmOpaque'] = '100'; // Font Opaque 
  181.  
  182. // Slideshow settings 
  183. $ngg_options['slideFx'] = 'fadeIn'; //The effect 
  184. $ngg_options['irWidth'] = 320; //Width (in px) 
  185. $ngg_options['irHeight'] = 240; //Height (in px) 
  186. $ngg_options['irAutoDim'] = true; //Automatically set the dimensions. 
  187. $ngg_options['irRotatetime'] = 3; //Duration (in seconds) 
  188. $ngg_options['irLoop'] = true; //Loop or not 
  189. $ngg_options['irDrag'] = true; //Enable drag or not 
  190. $ngg_options['irNavigation'] = false; //Show navigation 
  191. $ngg_options['irNavigationDots'] = false; //Show navigation dots 
  192. $ngg_options['irAutoplay'] = true; //Autoplay 
  193. $ngg_options['irAutoplayHover'] = true; //Pause on hover 
  194. $ngg_options['irNumber'] = 20; //Number of images when random or latest 
  195. $ngg_options['irClick'] = true; //Go to next on click. 
  196.  
  197. // CSS Style 
  198. $ngg_options['activateCSS'] = true; // activate the CSS file 
  199. $ngg_options['CSSfile'] = NGGALLERY_ABSPATH . 'css/nggallery.css'; // set default css filename 
  200.  
  201. // special overrides for WPMU 
  202. if ( is_multisite() ) { 
  203. // get the site options 
  204. $ngg_wpmu_options = get_site_option( 'ngg_options' ); 
  205.  
  206. // get the default value during first installation 
  207. if ( ! is_array( $ngg_wpmu_options ) ) { 
  208. $ngg_wpmu_options['gallerypath'] = 'wp-content/blogs.dir/%BLOG_ID%/files/'; 
  209. $ngg_wpmu_options['wpmuCSSfile'] = 'nggallery.css'; 
  210. $ngg_wpmu_options['silentUpdate'] = false; 
  211. update_site_option( 'ngg_options', $ngg_wpmu_options ); 
  212.  
  213. $ngg_options['gallerypath'] = str_replace( "%BLOG_ID%", $blog_id, $ngg_wpmu_options['gallerypath'] ); 
  214. $ngg_options['CSSfile'] = $ngg_wpmu_options['wpmuCSSfile']; 
  215.  
  216. update_option( 'ngg_options', $ngg_options ); 
  217.  
  218.  
  219. /** 
  220. * Deregister a capability from all classic roles 
  221. * @access internal 
  222. * @param string $capability name of the capability which should be deregister 
  223. * @return void 
  224. */ 
  225. private static function ngg_remove_capability( $capability ) { 
  226. // this function remove the $capability only from the classic roles 
  227. $check_order = array( "subscriber", "contributor", "author", "editor", "administrator" ); 
  228.  
  229. foreach ( $check_order as $role ) { 
  230.  
  231. $role = get_role( $role ); 
  232. $role->remove_cap( $capability ); 
  233.  
  234.  
  235. /** 
  236. * Uninstall all tables, settings and capabilities. 
  237. * This function is called during the uninstall hook and from the setup page. 
  238. */ 
  239. public static function uninstall() { 
  240. global $wpdb; 
  241.  
  242. //First remove all tables. 
  243. $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}ngg_pictures" ); 
  244. $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}ngg_gallery" ); 
  245. $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}ngg_album" ); 
  246.  
  247. //Then remove all options. 
  248. delete_option( 'ngg_options' ); 
  249. delete_option( 'ngg_db_version' ); 
  250. delete_option( 'ngg_update_exists' ); 
  251. delete_option( 'ngg_next_update' ); 
  252.  
  253. //As last item, we remove all capabilities. 
  254. NGG_Installer::ngg_remove_capability( "NextGEN Gallery overview" ); 
  255. NGG_Installer::ngg_remove_capability( "NextGEN Use TinyMCE" ); 
  256. NGG_Installer::ngg_remove_capability( "NextGEN Upload images" ); 
  257. NGG_Installer::ngg_remove_capability( "NextGEN Manage gallery" ); 
  258. NGG_Installer::ngg_remove_capability( "NextGEN Edit album" ); 
  259. NGG_Installer::ngg_remove_capability( "NextGEN Change style" ); 
  260. NGG_Installer::ngg_remove_capability( "NextGEN Change options" ); 
  261.