PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/nextgen-gallery/admin/install.php

https://gitlab.com/blueprintmrk/bladencountyrecords
PHP | 293 lines | 194 code | 47 blank | 52 comment | 13 complexity | 510c808863052b90bc7758fb23ca8c04 MD5 | raw file
  1. <?php
  2. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
  3. /**
  4. * creates all tables for the gallery
  5. * called during register_activation hook
  6. *
  7. * @access internal
  8. * @return void
  9. */
  10. function nggallery_install () {
  11. global $wpdb , $wp_roles, $wp_version;
  12. // Check for capability
  13. if ( !current_user_can('activate_plugins') )
  14. return;
  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", __('Sorry, NextGEN Gallery works only with a role called administrator',"nggallery") );
  20. return;
  21. }
  22. $role->add_cap('NextGEN Gallery overview');
  23. $role->add_cap('NextGEN Use TinyMCE');
  24. $role->add_cap('NextGEN Upload images');
  25. $role->add_cap('NextGEN Manage gallery');
  26. $role->add_cap('NextGEN Manage tags');
  27. $role->add_cap('NextGEN Manage others gallery');
  28. $role->add_cap('NextGEN Edit album');
  29. $role->add_cap('NextGEN Change style');
  30. $role->add_cap('NextGEN Change options');
  31. // upgrade function changed in WordPress 2.3
  32. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  33. // add charset & collate like wp core
  34. $charset_collate = '';
  35. if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
  36. if ( ! empty($wpdb->charset) )
  37. $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
  38. if ( ! empty($wpdb->collate) )
  39. $charset_collate .= " COLLATE $wpdb->collate";
  40. }
  41. $nggpictures = $wpdb->prefix . 'ngg_pictures';
  42. $nggallery = $wpdb->prefix . 'ngg_gallery';
  43. $nggalbum = $wpdb->prefix . 'ngg_album';
  44. // could be case senstive : http://dev.mysql.com/doc/refman/5.1/en/identifier-case-sensitivity.html
  45. if( !$wpdb->get_var( "SHOW TABLES LIKE '$nggpictures'" ) ) {
  46. $sql = "CREATE TABLE " . $nggpictures . " (
  47. pid BIGINT(20) NOT NULL AUTO_INCREMENT ,
  48. image_slug VARCHAR(255) NOT NULL ,
  49. post_id BIGINT(20) DEFAULT '0' NOT NULL ,
  50. galleryid BIGINT(20) DEFAULT '0' NOT NULL ,
  51. filename VARCHAR(255) NOT NULL ,
  52. description MEDIUMTEXT NULL ,
  53. alttext MEDIUMTEXT NULL ,
  54. imagedate DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  55. exclude TINYINT NULL DEFAULT '0' ,
  56. sortorder BIGINT(20) DEFAULT '0' NOT NULL ,
  57. meta_data LONGTEXT,
  58. PRIMARY KEY pid (pid),
  59. KEY post_id (post_id)
  60. ) $charset_collate;";
  61. dbDelta($sql);
  62. }
  63. if( !$wpdb->get_var( "SHOW TABLES LIKE '$nggallery'" )) {
  64. $sql = "CREATE TABLE " . $nggallery . " (
  65. gid BIGINT(20) NOT NULL AUTO_INCREMENT ,
  66. name VARCHAR(255) NOT NULL ,
  67. slug VARCHAR(255) NOT NULL ,
  68. path MEDIUMTEXT NULL ,
  69. title MEDIUMTEXT NULL ,
  70. galdesc MEDIUMTEXT NULL ,
  71. pageid BIGINT(20) DEFAULT '0' NOT NULL ,
  72. previewpic BIGINT(20) DEFAULT '0' NOT NULL ,
  73. author BIGINT(20) DEFAULT '0' NOT NULL ,
  74. PRIMARY KEY gid (gid)
  75. ) $charset_collate;";
  76. dbDelta($sql);
  77. }
  78. if( !$wpdb->get_var( "SHOW TABLES LIKE '$nggalbum'" )) {
  79. $sql = "CREATE TABLE " . $nggalbum . " (
  80. id BIGINT(20) NOT NULL AUTO_INCREMENT ,
  81. name VARCHAR(255) NOT NULL ,
  82. slug VARCHAR(255) NOT NULL ,
  83. previewpic BIGINT(20) DEFAULT '0' NOT NULL ,
  84. albumdesc MEDIUMTEXT NULL ,
  85. sortorder LONGTEXT NOT NULL,
  86. pageid BIGINT(20) DEFAULT '0' NOT NULL,
  87. PRIMARY KEY id (id)
  88. ) $charset_collate;";
  89. dbDelta($sql);
  90. }
  91. // check one table again, to be sure
  92. if( !$wpdb->get_var( "SHOW TABLES LIKE '$nggpictures'" ) ) {
  93. update_option( "ngg_init_check", __('NextGEN Gallery : Tables could not created, please check your database settings',"nggallery") );
  94. return;
  95. }
  96. $options = get_option('ngg_options');
  97. // set the default settings, if we didn't upgrade
  98. if ( empty( $options ) )
  99. ngg_default_options();
  100. // if all is passed , save the DBVERSION
  101. add_option("ngg_db_version", NGG_DBVERSION);
  102. }
  103. /**
  104. * Setup the default option array for the gallery
  105. *
  106. * @access internal
  107. * @since version 0.33
  108. * @return void
  109. */
  110. function ngg_default_options() {
  111. global $blog_id, $ngg;
  112. $ngg_options['gallerypath'] = 'wp-content/gallery/'; // set default path to the gallery
  113. $ngg_options['deleteImg'] = true; // delete Images
  114. $ngg_options['swfUpload'] = true; // activate the batch upload
  115. $ngg_options['usePermalinks'] = false; // use permalinks for parameters
  116. $ngg_options['graphicLibrary'] = 'gd'; // default graphic library
  117. $ngg_options['imageMagickDir'] = '/usr/local/bin/'; // default path to ImageMagick
  118. $ngg_options['useMediaRSS'] = false; // activate the global Media RSS file
  119. $ngg_options['usePicLens'] = false; // activate the PicLens Link for galleries
  120. // Tags / categories
  121. $ngg_options['activateTags'] = false; // append related images
  122. $ngg_options['appendType'] = 'tags'; // look for category or tags
  123. $ngg_options['maxImages'] = 7; // number of images toshow
  124. // Thumbnail Settings
  125. $ngg_options['thumbwidth'] = 100; // Thumb Width
  126. $ngg_options['thumbheight'] = 75; // Thumb height
  127. $ngg_options['thumbfix'] = true; // Fix the dimension
  128. $ngg_options['thumbquality'] = 100; // Thumb Quality
  129. // Image Settings
  130. $ngg_options['imgWidth'] = 800; // Image Width
  131. $ngg_options['imgHeight'] = 600; // Image height
  132. $ngg_options['imgQuality'] = 85; // Image Quality
  133. $ngg_options['imgCacheSinglePic'] = true; // Cached the singlepic
  134. $ngg_options['imgBackup'] = true; // Create a backup
  135. $ngg_options['imgAutoResize'] = false; // Resize after upload
  136. // Gallery Settings
  137. $ngg_options['galImages'] = '20'; // Number of images per page
  138. $ngg_options['galPagedGalleries'] = 0; // Number of galleries per page (in a album)
  139. $ngg_options['galColumns'] = 0; // Number of columns for the gallery
  140. $ngg_options['galShowSlide'] = true; // Show slideshow
  141. $ngg_options['galTextSlide'] = __('[Show as slideshow]','nggallery'); // Text for slideshow
  142. $ngg_options['galTextGallery'] = __('[Show picture list]','nggallery'); // Text for gallery
  143. $ngg_options['galShowOrder'] = 'gallery'; // Show order
  144. $ngg_options['galSort'] = 'sortorder'; // Sort order
  145. $ngg_options['galSortDir'] = 'ASC'; // Sort direction
  146. $ngg_options['galNoPages'] = true; // use no subpages for gallery
  147. $ngg_options['galImgBrowser'] = false; // Show ImageBrowser, instead effect
  148. $ngg_options['galHiddenImg'] = false; // For paged galleries we can hide image
  149. $ngg_options['galAjaxNav'] = false; // AJAX Navigation for Shutter effect
  150. // Thumbnail Effect
  151. $ngg_options['thumbEffect'] = 'shutter'; // select effect
  152. $ngg_options['thumbCode'] = 'class="shutterset_%GALLERY_NAME%"';
  153. // Watermark settings
  154. $ngg_options['wmPos'] = 'botRight'; // Postion
  155. $ngg_options['wmXpos'] = 5; // X Pos
  156. $ngg_options['wmYpos'] = 5; // Y Pos
  157. $ngg_options['wmType'] = 'text'; // Type : 'image' / 'text'
  158. $ngg_options['wmPath'] = ''; // Path to image
  159. $ngg_options['wmFont'] = 'arial.ttf'; // Font type
  160. $ngg_options['wmSize'] = 10; // Font Size
  161. $ngg_options['wmText'] = get_option('blogname'); // Text
  162. $ngg_options['wmColor'] = '000000'; // Font Color
  163. $ngg_options['wmOpaque'] = '100'; // Font Opaque
  164. // Image Rotator settings
  165. $ngg_options['enableIR'] = false;
  166. $ngg_options['slideFx'] = 'fade';
  167. $ngg_options['irURL'] = '';
  168. $ngg_options['irXHTMLvalid'] = false;
  169. $ngg_options['irAudio'] = '';
  170. $ngg_options['irWidth'] = 320;
  171. $ngg_options['irHeight'] = 240;
  172. $ngg_options['irShuffle'] = true;
  173. $ngg_options['irLinkfromdisplay'] = true;
  174. $ngg_options['irShownavigation'] = false;
  175. $ngg_options['irShowicons'] = false;
  176. $ngg_options['irWatermark'] = false;
  177. $ngg_options['irOverstretch'] = 'true';
  178. $ngg_options['irRotatetime'] = 10;
  179. $ngg_options['irTransition'] = 'random';
  180. $ngg_options['irKenburns'] = false;
  181. $ngg_options['irBackcolor'] = '000000';
  182. $ngg_options['irFrontcolor'] = 'FFFFFF';
  183. $ngg_options['irLightcolor'] = 'CC0000';
  184. $ngg_options['irScreencolor'] = '000000';
  185. // CSS Style
  186. $ngg_options['activateCSS'] = true; // activate the CSS file
  187. $ngg_options['CSSfile'] = 'nggallery.css'; // set default css filename
  188. // special overrides for WPMU
  189. if (is_multisite()) {
  190. // get the site options
  191. $ngg_wpmu_options = get_site_option('ngg_options');
  192. // get the default value during first installation
  193. if (!is_array($ngg_wpmu_options)) {
  194. $ngg_wpmu_options['gallerypath'] = 'wp-content/blogs.dir/%BLOG_ID%/files/';
  195. $ngg_wpmu_options['wpmuCSSfile'] = 'nggallery.css';
  196. update_site_option('ngg_options', $ngg_wpmu_options);
  197. }
  198. $ngg_options['gallerypath'] = str_replace("%BLOG_ID%", $blog_id , $ngg_wpmu_options['gallerypath']);
  199. $ngg_options['CSSfile'] = $ngg_wpmu_options['wpmuCSSfile'];
  200. $ngg_options['imgCacheSinglePic'] = true; // under WPMU this should be enabled
  201. }
  202. update_option('ngg_options', $ngg_options);
  203. }
  204. /**
  205. * Deregister a capability from all classic roles
  206. *
  207. * @access internal
  208. * @param string $capability name of the capability which should be deregister
  209. * @return void
  210. */
  211. function ngg_remove_capability($capability){
  212. // this function remove the $capability only from the classic roles
  213. $check_order = array("subscriber", "contributor", "author", "editor", "administrator");
  214. foreach ($check_order as $role) {
  215. $role = get_role($role);
  216. $role->remove_cap($capability) ;
  217. }
  218. }
  219. /**
  220. * Uninstall all settings and tables
  221. * Called via Setup and register_unstall hook
  222. *
  223. * @access internal
  224. * @return void
  225. */
  226. function nggallery_uninstall() {
  227. global $wpdb;
  228. // first remove all tables
  229. $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}ngg_pictures");
  230. $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}ngg_gallery");
  231. $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}ngg_album");
  232. // then remove all options
  233. delete_option( 'ngg_options' );
  234. delete_option( 'ngg_db_version' );
  235. delete_option( 'ngg_update_exists' );
  236. delete_option( 'ngg_next_update' );
  237. // now remove the capability
  238. ngg_remove_capability("NextGEN Gallery overview");
  239. ngg_remove_capability("NextGEN Use TinyMCE");
  240. ngg_remove_capability("NextGEN Upload images");
  241. ngg_remove_capability("NextGEN Manage gallery");
  242. ngg_remove_capability("NextGEN Edit album");
  243. ngg_remove_capability("NextGEN Change style");
  244. ngg_remove_capability("NextGEN Change options");
  245. }
  246. ?>