nggLoader

Class nggLoader.

Defined (1)

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

/nggallery.php  
  1. class nggLoader { 
  2.  
  3. var $version = '1.9.31'; 
  4. var $dbversion = '1.8.3'; 
  5. var $minimum_WP = '4.0'; 
  6. var $options = ''; 
  7. var $manage_page; 
  8. var $add_PHP5_notice = false; 
  9.  
  10. /** 
  11. * class constructor 
  12. */ 
  13. function nggLoader() { 
  14.  
  15. // Stop the plugin if we missed the requirements 
  16. if ( ( !$this->required_version() ) || ( !$this->check_memory_limit() ) ) 
  17. return; 
  18.  
  19. // Set error handler 
  20. set_exception_handler(array(&$this, 'exception_handler')); 
  21.  
  22. // Get some constants first 
  23. $this->load_options(); 
  24. $this->define_constant(); 
  25. $this->define_tables(); 
  26. $this->load_dependencies(); 
  27.  
  28. $this->plugin_name = basename(dirname(__FILE__)).'/'.basename(__FILE__); 
  29.  
  30. // Init options & tables during activation & deregister init option 
  31. register_activation_hook( $this->plugin_name, array(&$this, 'activate') ); 
  32. register_deactivation_hook( $this->plugin_name, array(&$this, 'deactivate') ); 
  33.  
  34. // Register a uninstall hook to remove all tables & option automatic 
  35. register_uninstall_hook( $this->plugin_name, array(__CLASS__, 'uninstall') ); 
  36.  
  37. // Start this plugin once all other plugins are fully loaded 
  38. add_action( 'plugins_loaded', array(&$this, 'start_plugin') ); 
  39.  
  40. // Register_taxonomy must be used during the init 
  41. add_action( 'init', array(&$this, 'register_taxonomy') ); 
  42. add_action( 'wpmu_new_blog', array(&$this, 'multisite_new_blog'), 10, 6); 
  43.  
  44. // Add a message for PHP4 Users, can disable the update message later on 
  45. if (version_compare(PHP_VERSION, '5.0.0', '<')) 
  46. add_filter('transient_update_plugins', array(&$this, 'disable_upgrade')); 
  47.  
  48. //Add some links on the plugin page 
  49. add_filter('plugin_row_meta', array(&$this, 'add_plugin_links'), 10, 2); 
  50.  
  51. // Check for the header / footer 
  52. add_action( 'init', array(&$this, 'test_head_footer_init' ) ); 
  53.  
  54. // Show NextGEN version in header 
  55. add_action('wp_head', array('nggGallery', 'nextgen_version') ); 
  56.  
  57. // Handle upload requests 
  58. add_action('init', array(&$this, 'handle_upload_request')); 
  59.  
  60. function show_upgrade_message() { 
  61. if( is_network_admin() ) { 
  62. $url = network_admin_url('admin.php?page=' . NGGFOLDER); 
  63. } else { 
  64. $url = admin_url('admin.php?page=' . NGGFOLDER); 
  65. ?> 
  66. <div id="message" class="update-nag"> 
  67. <p><strong><?php _e('NextCellent Gallery requires a database upgrade.', "nggallery") ?> <a href="<?php echo $url ?>"><?php _e('Upgrade now.', 'nggallery'); ?></a></strong></p> 
  68. </div> 
  69. <?php 
  70.  
  71. /** 
  72. * Main start invoked after all plugins are loaded. 
  73. */ 
  74. function start_plugin() { 
  75.  
  76. // Load the language file 
  77. load_plugin_textdomain('nggallery', false, NGGFOLDER . '/lang'); 
  78.  
  79. // All credits to the translator 
  80. $this->translator = '<p class="hint">'. __('<strong>Translation by : </strong><a target="_blank" href="http://alexrabe.de/wordpress-plugins/nextgen-gallery/languages/">See here</a>', 'nggallery') . '</p>'; 
  81. $this->translator .= '<p class="hint">'. __('<strong>This translation is not yet updated for Version 1.9.0</strong>. If you would like to help with translation, download the current po from the plugin folder and read <a href="http://alexrabe.de/wordpress-plugins/wordtube/translation-of-plugins/">here</a> how you can translate the plugin.', 'nggallery') . '</p>'; 
  82.  
  83. // Content Filters 
  84. add_filter('ngg_gallery_name', 'sanitize_title'); 
  85.  
  86. // Check if we are in the admin area 
  87. if ( is_admin() ) { 
  88.  
  89. // Pass the init check or show a message 
  90. if (get_option( 'ngg_init_check' ) != false ) 
  91. add_action( 'admin_notices', create_function('', 'echo \'<div id="message" class="error"><p><strong>' . get_option( "ngg_init_check" ) . '</strong></p></div>\';') ); 
  92.  
  93. } else { 
  94.  
  95. // Add MRSS to wp_head 
  96. if ( $this->options['useMediaRSS'] ) 
  97. add_action('wp_head', array('nggMediaRss', 'add_mrss_alternate_link')); 
  98.  
  99. // Look for XML request, before page is render 
  100. add_action('parse_request', array(&$this, 'check_request') ); 
  101.  
  102. // Add the script and style files 
  103. add_action('wp_enqueue_scripts', array(&$this, 'load_scripts') ); 
  104. add_action('wp_enqueue_scripts', array(&$this, 'load_styles') ); 
  105.  
  106.  
  107. if( get_option( 'ngg_db_version' ) != NGG_DBVERSION && isset($_GET['page']) != "nextcellent" ) { 
  108.  
  109. $ngg_options = get_option('ngg_options'); 
  110.  
  111. /** 
  112. * If the silentUpgrade option is not empty, we try and do the upgrade now. 
  113. */ 
  114. if ( !empty( $ngg_options['silentUpgrade'] ) ) { 
  115. include_once( dirname( __FILE__ ) . '/admin/functions.php' ); 
  116. include_once( dirname( __FILE__ ) . '/admin/upgrade.php' ); 
  117. try { 
  118. ngg_upgrade(); 
  119. } catch (Exception $e) { 
  120. add_action( 'admin_notices', create_function( '', 'echo \'<div id="message" class="error"><p><strong>' . __( 'Something went wrong while upgrading NextCellent Gallery.', "nggallery" ) . '</strong></p></div>\';' ) ); 
  121. } else { 
  122. add_action( 'all_admin_notices', array($this, 'show_upgrade_message') ); 
  123.  
  124. /** 
  125. * Look for XML request 
  126. * @param $wp 
  127. */ 
  128. function check_request( $wp ) { 
  129.  
  130. if ( !array_key_exists('callback', $wp->query_vars) ) 
  131. return; 
  132.  
  133. if ( $wp->query_vars['callback'] == 'imagerotator') { 
  134. require_once (dirname (__FILE__) . '/xml/imagerotator.php'); 
  135. exit(); 
  136.  
  137. if ( $wp->query_vars['callback'] == 'json') { 
  138. require_once (dirname (__FILE__) . '/xml/json.php'); 
  139. exit(); 
  140.  
  141. if ( $wp->query_vars['callback'] == 'image') { 
  142. require_once (dirname (__FILE__) . '/nggshow.php'); 
  143. exit(); 
  144.  
  145. //TODO:see trac #12400 could be an option for WP3.0 
  146. if ( $wp->query_vars['callback'] == 'ngg-ajax') { 
  147. require_once (dirname (__FILE__) . '/xml/ajax.php'); 
  148. exit(); 
  149.  
  150. /** 
  151. * Check WP version . Return false if not supported, otherwise true 
  152. * Display msg in case not supported 
  153. * @return bool 
  154. */ 
  155. function required_version() { 
  156. global $wp_version; 
  157.  
  158. // Check for WP version installation 
  159. $wp_ok = version_compare($wp_version, $this->minimum_WP, '>='); 
  160.  
  161. if ( ($wp_ok == FALSE) ) { 
  162. add_action( 
  163. 'admin_notices',  
  164. create_function( 
  165. '',  
  166. 'global $ngg; printf (\'<div id="message" class="error"><p><strong>\' . __(\'Sorry, NextGEN Gallery works only under WordPress %s or higher\', "nggallery" ) . \'</strong></p></div>\', $ngg->minimum_WP );' 
  167. ); 
  168. return false; 
  169. return true; 
  170.  
  171. /** 
  172. * Checks if there is enough memory to perform the plugin 
  173. * Inner working: get memory value from memory_limit. If -1 there is no memory limit 
  174. * If there is 16MB or less, send msg 
  175. * Returns false if there is enough memory, otherwise false. 
  176. * @return bool 
  177. */ 
  178. function check_memory_limit() { 
  179.  
  180. // get the real memory limit before some increase it 
  181. $this->memory_limit = ini_get('memory_limit'); 
  182.  
  183. // PHP docs : Note that to have no memory limit, set this directive to -1. 
  184. if ($this->memory_limit == -1 ) return true; 
  185.  
  186. // Yes, we reached Gigabyte limits, so check if it's a megabyte limit 
  187. if (strtolower( substr($this->memory_limit, -1) ) == 'm') { 
  188.  
  189. $this->memory_limit = (int) substr( $this->memory_limit, 0, -1); 
  190.  
  191. //This works only with enough memory, 16MB is silly, wordpress requires already 16MB :-) 
  192. if ( ($this->memory_limit != 0) && ($this->memory_limit < 16 ) ) { 
  193. add_action( 
  194. 'admin_notices',  
  195. create_function( 
  196. '',  
  197. 'echo \'<div id="message" class="error"><p><strong>' . __('Sorry, NextCellent Gallery works only with a Memory Limit of 16 MB or higher', 'nggallery') . '</strong></p></div>\';' 
  198. ); 
  199. return false; 
  200. return true; 
  201.  
  202. /** 
  203. * add dynamic properties to global wpdb object. 
  204. */ 
  205.  
  206. function define_tables() { 
  207. global $wpdb; 
  208.  
  209. // add database pointer 
  210. $wpdb->nggpictures = $wpdb->prefix . 'ngg_pictures'; 
  211. $wpdb->nggallery = $wpdb->prefix . 'ngg_gallery'; 
  212. $wpdb->nggalbum = $wpdb->prefix . 'ngg_album'; 
  213.  
  214.  
  215.  
  216. function register_taxonomy() { 
  217. global $wp_rewrite; 
  218.  
  219. // Register the NextGEN taxonomy 
  220. $args = array( 
  221. 'label' => __('Picture tag', 'nggallery'),  
  222. 'template' => __('Picture tag: %2$l.', 'nggallery'),  
  223. 'helps' => __('Separate picture tags with commas.', 'nggallery'),  
  224. 'sort' => true,  
  225. 'args' => array('orderby' => 'term_order') 
  226. ); 
  227.  
  228. register_taxonomy( 'ngg_tag', 'nggallery', $args ); 
  229.  
  230. /** 
  231. * Define several constants 
  232. * 20140517 - Suppressed unused constant 
  233. */ 
  234. function define_constant() { 
  235.  
  236. global $wp_version; 
  237.  
  238. // Minimum required database version 
  239. define('NGG_DBVERSION', $this->dbversion); 
  240.  
  241. // required for Windows & XAMPP 
  242. define('WINABSPATH', str_replace("\\", "/", ABSPATH) ); 
  243. define('NGG_CONTENT_DIR', str_replace("\\", "/", WP_CONTENT_DIR) ); 
  244.  
  245. // define URL 
  246. define('NGGFOLDER', basename( dirname(__FILE__) ) ); 
  247.  
  248. define('NGGALLERY_ABSPATH', trailingslashit( str_replace("\\", "/", WP_PLUGIN_DIR . '/' . NGGFOLDER ) ) ); 
  249. define('NGGALLERY_URLPATH', trailingslashit( plugins_url( NGGFOLDER ) ) ); 
  250.  
  251. // look for imagerotator 
  252. define('NGGALLERY_IREXIST', !empty( $this->options['irURL'] )); 
  253.  
  254. // get value for safe mode 
  255. if ( (gettype( ini_get('safe_mode') ) == 'string') ) { 
  256. // if sever did in in a other way 
  257. if ( ini_get('safe_mode') == 'off' ) define('SAFE_MODE', FALSE); 
  258. else define( 'SAFE_MODE', ini_get('safe_mode') ); 
  259. } else 
  260. define( 'SAFE_MODE', ini_get('safe_mode') ); 
  261.  
  262. if ( version_compare($wp_version, '3.2.999', '>') ) 
  263. define('IS_WP_3_3', TRUE); 
  264.  
  265. /** 
  266. * Load libraries 
  267. */ 
  268. function load_dependencies() { 
  269.  
  270. // Load global libraries // average memory usage (in bytes) 
  271. require_once (dirname (__FILE__) . '/lib/core.php'); // 94.840 
  272. require_once (dirname (__FILE__) . '/lib/ngg-db.php'); // 132.400 
  273. require_once (dirname (__FILE__) . '/lib/image.php'); // 59.424 
  274. require_once (dirname (__FILE__) . '/lib/tags.php'); // 117.136 
  275. require_once (dirname (__FILE__) . '/lib/post-thumbnail.php'); // n.a. 
  276. require_once( dirname( __FILE__ ) . '/widgets/class-ngg-slideshow-widget.php' ); 
  277. require_once( dirname( __FILE__ ) . '/widgets/class-ngg-media-rss-widget.php' ); 
  278. require_once( dirname( __FILE__ ) . '/widgets/class-ngg-gallery-widget.php' ); 
  279. require_once (dirname (__FILE__) . '/lib/multisite.php'); 
  280. require_once (dirname (__FILE__) . '/lib/sitemap.php'); 
  281.  
  282. // Load frontend libraries 
  283. require_once (dirname (__FILE__) . '/lib/navigation.php'); // 242.016 
  284. require_once (dirname (__FILE__) . '/nggfunctions.php'); // n.a. 
  285. require_once (dirname (__FILE__) . '/lib/shortcodes.php'); // 92.664 
  286.  
  287. // Add to the toolbar 
  288. add_action( 'admin_bar_menu', array( &$this, 'admin_bar_menu' ), 999 ); 
  289.  
  290. //Just needed if you access remote to WordPress 
  291. if ( defined('XMLRPC_REQUEST') ) 
  292. require_once (dirname (__FILE__) . '/lib/xmlrpc.php'); 
  293.  
  294. // We didn't need all stuff during a AJAX operation 
  295. if ( defined('DOING_AJAX') ) 
  296. require_once (dirname (__FILE__) . '/admin/ajax.php'); 
  297. else { 
  298. require_once (dirname (__FILE__) . '/lib/meta.php'); // 131.856 
  299. require_once (dirname (__FILE__) . '/lib/media-rss.php'); // 82.768 
  300. require_once (dirname (__FILE__) . '/lib/rewrite.php'); // 71.936 
  301. include_once (dirname (__FILE__) . '/admin/tinymce/tinymce.php'); // 22.408 
  302.  
  303. // Load backend libraries 
  304. if ( is_admin() ) { 
  305. require_once (dirname (__FILE__) . '/admin/class-ngg-admin-launcher.php'); 
  306. require_once (dirname (__FILE__) . '/admin/media-upload.php'); 
  307. $this->nggAdminPanel = new NGG_Admin_Launcher(); 
  308.  
  309. /** 
  310. * Add NextCellent to the WordPress toolbar. 
  311. * @since 1.9.24 Moved from admin.php 
  312. */ 
  313. function admin_bar_menu() { 
  314. // If the current user can't write posts, this is all of no use, so let's not output an admin menu 
  315. if ( ! current_user_can( 'NextGEN Gallery overview' ) ) { 
  316. return; 
  317.  
  318. global $wp_admin_bar; 
  319.  
  320. if ( current_user_can( 'NextGEN Upload images' ) ) { 
  321. $wp_admin_bar->add_node( array( 
  322. 'parent' => 'new-content',  
  323. 'id' => 'ngg-menu-add-gallery',  
  324. 'title' => __( 'NextCellent Gallery / Images', 'nggallery' ),  
  325. 'href' => admin_url( 'admin.php?page=nggallery-add-gallery' ) 
  326. ) ); 
  327.  
  328. //If the user is in the admin screen, there is no need to display this. 
  329. if ( !is_admin() ) { 
  330. $wp_admin_bar->add_node( array( 
  331. 'parent' => 'site-name',  
  332. 'id' => 'ngg-menu-overview',  
  333. 'title' => __( 'NextCellent', 'nggallery' ),  
  334. 'href' => admin_url( 'admin.php?page=' . NGGFOLDER ) 
  335. ) ); 
  336. if ( current_user_can( 'NextGEN Manage gallery' ) ) { 
  337. $wp_admin_bar->add_node( array( 
  338. 'parent' => 'ngg-menu-overview',  
  339. 'id' => 'ngg-menu-manage-gallery',  
  340. 'title' => __( 'Gallery', 'nggallery' ),  
  341. 'href' => admin_url( 'admin.php?page=nggallery-manage' ) 
  342. ) ); 
  343. if ( current_user_can( 'NextGEN Edit album' ) ) { 
  344. $wp_admin_bar->add_node( array( 
  345. 'parent' => 'ngg-menu-overview',  
  346. 'id' => 'ngg-menu-manage-album',  
  347. 'title' => __( 'Albums', 'nggallery' ),  
  348. 'href' => admin_url( 'admin.php?page=nggallery-manage-album' ) 
  349. ) ); 
  350. if ( current_user_can( 'NextGEN Manage tags' ) ) { 
  351. $wp_admin_bar->add_node( array( 
  352. 'parent' => 'ngg-menu-overview',  
  353. 'id' => 'ngg-menu-tags',  
  354. 'title' => __( 'Tags', 'nggallery' ),  
  355. 'href' => admin_url( 'admin.php?page=nggallery-tags' ) 
  356. ) ); 
  357. if ( current_user_can( 'NextGEN Change options' ) ) { 
  358. $wp_admin_bar->add_node( array( 
  359. 'parent' => 'ngg-menu-overview',  
  360. 'id' => 'ngg-menu-options',  
  361. 'title' => __( 'Settings', 'nggallery' ),  
  362. 'href' => admin_url( 'admin.php?page=nggallery-options' ) 
  363. ) ); 
  364. if ( current_user_can( 'NextGEN Change style' ) ) { 
  365. $wp_admin_bar->add_node( array( 
  366. 'parent' => 'ngg-menu-overview',  
  367. 'id' => 'ngg-menu-style',  
  368. 'title' => __( 'Style', 'nggallery' ),  
  369. 'href' => admin_url( 'admin.php?page=nggallery-style' ) 
  370. ) ); 
  371.  
  372. /** 
  373. * Load scripts depending options defined 
  374. * 20150106: Added js for Qunit 
  375. * 20150107: jquery is almost mandatory... Should it be enqueued only when lightbox is activated? 
  376. */ 
  377. function load_scripts() { 
  378.  
  379. // if you want to prevent Nextcellent load the scripts (for testing or development purposes), add this constant 
  380. if ( defined('NGG_SKIP_LOAD_SCRIPTS') ) 
  381. return; 
  382.  
  383. // activate Thickbox 
  384. if ($this->options['thumbEffect'] == 'thickbox') { 
  385. wp_enqueue_script( 'thickbox' ); 
  386. // Load the thickbox images after all other scripts 
  387. add_action( 'wp_footer', array(&$this, 'load_thickbox_images'), 11 ); 
  388.  
  389.  
  390. // activate jquery.lightbox 
  391. if ($this->options['thumbEffect'] == 'lightbox') { 
  392. wp_enqueue_script('jquery'); 
  393.  
  394. // activate modified Shutter reloaded if not use the Shutter plugin 
  395. if ( ($this->options['thumbEffect'] == "shutter") && !function_exists('srel_makeshutter') ) { 
  396. wp_register_script('shutter', NGGALLERY_URLPATH .'shutter/shutter-reloaded.js', false , '1.3.3'); 
  397. wp_localize_script('shutter', 'shutterSettings', array( 
  398. 'msgLoading' => __('L O A D I N G', 'nggallery'),  
  399. 'msgClose' => __('Click to Close', 'nggallery'),  
  400. 'imageCount' => '1' 
  401. ) ); 
  402. wp_enqueue_script( 'shutter' ); 
  403.  
  404. // required for the slideshow 
  405. if ( NGGALLERY_IREXIST == true && $this->options['enableIR'] == '1' && nggGallery::detect_mobile_phone() === false ) 
  406. wp_enqueue_script('swfobject'); 
  407. else { 
  408. wp_enqueue_script('owl', NGGALLERY_URLPATH .'js/owl.carousel.min.js', array('jquery'), '2'); 
  409.  
  410. // Load AJAX navigation script, works only with shutter script as we need to add the listener 
  411. if ( $this->options['galAjaxNav'] ) { 
  412. if ( ($this->options['thumbEffect'] == "shutter") || function_exists('srel_makeshutter') ) { 
  413. wp_enqueue_script ( 'ngg_script', NGGALLERY_URLPATH . 'js/ngg.js', array('jquery', 'jquery-ui-tooltip'), '2.1'); 
  414. wp_localize_script( 'ngg_script', 'ngg_ajax', array('path' => NGGALLERY_URLPATH,  
  415. 'callback' => trailingslashit( home_url() ) . 'index.php?callback=ngg-ajax',  
  416. 'loading' => __('loading', 'nggallery'),  
  417. ) ); 
  418.  
  419. // If activated, add PicLens/Cooliris javascript to footer 
  420. if ( $this->options['usePicLens'] ) 
  421. nggMediaRss::add_piclens_javascript(); 
  422.  
  423. // Added Qunit for javascript unit testing 
  424. $nxc=isset($_GET['nextcellent'])?$_GET['nextcellent']:""; 
  425. if ($nxc) { 
  426. wp_enqueue_script( "qunit-init" , NGGALLERY_URLPATH . "js/nxc.main.js" , array ('jquery')); //main q-unit call 
  427. wp_enqueue_script( "qunit" , NGGALLERY_URLPATH . "js/qunit-1.16.0.js" , array ('jquery')); //qunit core 
  428. wp_enqueue_script( "nextcellent-test" , NGGALLERY_URLPATH . "js/nxc.test.js", array ('jquery')); //unit testing specific for nextcellent 
  429.  
  430.  
  431. function load_thickbox_images() { 
  432. // WP core reference relative to the images. Bad idea 
  433. echo "\n" . '<script type="text/javascript">tb_pathToImage = "' . site_url() . '/wp-includes/js/thickbox/loadingAnimation.gif";tb_closeImage = "' . site_url() . '/wp-includes/js/thickbox/tb-close.png";</script>'. "\n"; 
  434.  
  435. /** 
  436. * Load styles based on options defined 
  437. * 20150106: added style for Qunit 
  438. */ 
  439. function load_styles() { 
  440.  
  441. //Notice stylesheet selection has this priority: 
  442. //1-sytlesheet loaded from filter ngg_load_stylesheet 
  443. //2-nggalery.css on folder's current theme 
  444. //3-active stylesheet defined on styles. 
  445.  
  446. if ( $css_file = nggGallery::get_theme_css_file() ) { 
  447. wp_enqueue_style('NextGEN', $css_file , false, '1.0.0', 'screen'); 
  448. //load the framework 
  449. wp_enqueue_style('NextCellent-Framework', NGGALLERY_URLPATH . 'css/framework-min.css', false, '1.0.1', 'screen'); 
  450. } elseif ($this->options['activateCSS']) { 
  451. //convert the path to an URL 
  452. $replace = content_url(); 
  453. $path = str_replace( NGG_CONTENT_DIR , $replace, $this->options['CSSfile']);  
  454. wp_enqueue_style('NextGEN', $path, false, '1.0.0', 'screen'); 
  455. //load the framework 
  456. wp_enqueue_style('NextCellent-Framework', NGGALLERY_URLPATH . 'css/framework-min.css', false, '1.0.1', 'screen'); 
  457.  
  458.  
  459. // activate Thickbox 
  460. if ($this->options['thumbEffect'] == 'thickbox') 
  461. wp_enqueue_style( 'thickbox'); 
  462.  
  463. // activate modified Shutter reloaded if not use the Shutter plugin 
  464. if ( ($this->options['thumbEffect'] == 'shutter') && !function_exists('srel_makeshutter') ) 
  465. wp_enqueue_style('shutter', NGGALLERY_URLPATH .'shutter/shutter-reloaded.css', false, '1.3.4', 'screen'); 
  466.  
  467. // add qunit style if activated. I put 1.0.0 as formula, but it would mean nothing. 
  468.  
  469. $nxc=isset($_GET['nextcellent'])?$_GET['nextcellent']:""; 
  470. if ($nxc) { 
  471. wp_enqueue_style ( "qunit", NGGALLERY_URLPATH . "css/qunit-1.16.0.css" , false, '1.0.0' , 'screen' ); 
  472.  
  473.  
  474. function load_options() { 
  475. // Load the options 
  476. $this->options = get_option('ngg_options'); 
  477.  
  478. // THX to Shiba for the code 
  479. // See: http://shibashake.com/wordpress-theme/write-a-plugin-for-wordpress-multi-site 
  480. function multisite_new_blog($blog_id, $user_id, $domain, $path, $site_id, $meta ) { 
  481. global $wpdb; 
  482.  
  483. include_once (dirname (__FILE__) . '/admin/class-ngg-installer.php'); 
  484.  
  485. if (is_plugin_active_for_network( $this->plugin_name )) { 
  486. $current_blog = $wpdb->blogid; 
  487. switch_to_blog($blog_id); 
  488. NGG_Installer::install(); 
  489. switch_to_blog($current_blog); 
  490.  
  491. /** 
  492. * Removes all transients created by NextGEN. Called during activation 
  493. * and deactivation routines 
  494. */ 
  495. static function remove_transients() 
  496. global $wpdb, $_wp_using_ext_object_cache; 
  497.  
  498. // Fetch all transients 
  499. $query = " 
  500. SELECT option_name FROM {$wpdb->options} 
  501. WHERE option_name LIKE '%ngg_request%' 
  502. "; 
  503. $transient_names = $wpdb->get_col($query);; 
  504.  
  505. // Delete all transients in the database 
  506. $query = " 
  507. DELETE FROM {$wpdb->options} 
  508. WHERE option_name LIKE '%ngg_request%' 
  509. "; 
  510. $wpdb->query($query); 
  511.  
  512. // If using an external caching mechanism, delete the cached items 
  513. if ($_wp_using_ext_object_cache) { 
  514. foreach ($transient_names as $transient) { 
  515. wp_cache_delete($transient, 'transient'); 
  516. wp_cache_delete(substr($transient, 11), 'transient'); 
  517.  
  518. /** 
  519. * Activation hook 
  520. * register_activation_hook( $this->plugin_name, array(&$this, 'activate') ); 
  521. * Disable Plugin if PHP version is lower than 5.2 
  522. * However, why the plugin spread initial validation over so different places? Not need to do that... 
  523. */ 
  524. function activate() { 
  525. global $wpdb; 
  526. //Starting from version 1.8.0 it's works only with PHP5.2 
  527. if (version_compare(PHP_VERSION, '5.2.0', '<')) { 
  528. deactivate_plugins($this->plugin_name); // Deactivate ourself 
  529. wp_die("Sorry, but you can't run this plugin, it requires PHP 5.2 or higher."); 
  530. return; 
  531.  
  532. // Clean up transients 
  533. self::remove_transients(); 
  534.  
  535. include_once (dirname (__FILE__) . '/admin/class-ngg-installer.php'); 
  536.  
  537. if (is_multisite()) { 
  538. $network=isset($_SERVER['SCRIPT_NAME'])?$_SERVER['SCRIPT_NAME']:""; 
  539. $activate=isset($_GET['action'])?$_GET['action']:""; 
  540. $isNetwork=($network=='/wp-admin/network/plugins.php')?true:false; 
  541. $isActivation=($activate=='deactivate')?false:true; 
  542.  
  543. if ($isNetwork and $isActivation) { 
  544. $old_blog = $wpdb->blogid; 
  545. $blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs", NULL)); 
  546. foreach ($blogids as $blog_id) { 
  547. switch_to_blog($blog_id); 
  548. NGG_Installer::install(); 
  549. switch_to_blog($old_blog); 
  550. return; 
  551.  
  552. // check for tables 
  553. NGG_Installer::install(); 
  554. // remove the update message 
  555. delete_option( 'ngg_update_exists' ); 
  556.  
  557.  
  558. /** 
  559. * delete init options and transients 
  560. */ 
  561. function deactivate() { 
  562.  
  563. // remove & reset the init check option 
  564. delete_option( 'ngg_init_check' ); 
  565. delete_option( 'ngg_update_exists' ); 
  566.  
  567. // Clean up transients 
  568. self::remove_transients(); 
  569.  
  570. /** 
  571. * Uninstall procedure. Pay attention this method is static on the class 
  572. * See register_uninstall_hook( $this->plugin_name, array(__CLASS__, 'uninstall') ); 
  573. */ 
  574. static function uninstall() { 
  575. // Clean up transients 
  576. self::remove_transients(); 
  577.  
  578. include_once (dirname (__FILE__) . '/admin/class-ngg-installer.php'); 
  579. NGG_Installer::uninstall(); 
  580.  
  581. /** 
  582. * @param $option 
  583. * @return mixed 
  584. */ 
  585. function disable_upgrade($option) { 
  586.  
  587. // PHP5.2 is required for NGG V1.4.0 
  588. if ( version_compare($option->response[ $this->plugin_name ]->new_version, '1.4.0', '>=') ) 
  589. return $option; 
  590.  
  591. if( isset($option->response[ $this->plugin_name ]) ) { 
  592. //Clear it''s download link 
  593. $option->response[ $this->plugin_name ]->package = ''; 
  594.  
  595. //Add a notice message 
  596. if ($this->add_PHP5_notice == false) { 
  597. add_action( "in_plugin_update_message-$this->plugin_name", create_function('', 'echo \'<br /><span style="color:red">Please update to PHP5.2 as soon as possible, the plugin is not tested under PHP4 anymore</span>\';') ); 
  598. $this->add_PHP5_notice = true; 
  599. return $option; 
  600.  
  601. // Add links to Plugins page 
  602. function add_plugin_links($links, $file) { 
  603.  
  604. if ( $file == $this->plugin_name ) { 
  605. $plugin_name = plugin_basename(NGGALLERY_ABSPATH); 
  606. $links[] = "<a href='admin.php?page={$plugin_name}'>" . __('Overview', 'nggallery') . '</a>'; 
  607. $links[] = '<a href="http://wordpress.org/support/plugin/nextcellent-gallery-nextgen-legacy">' . __('Get help', 'nggallery') . '</a>'; 
  608. //$links[] = '<a href="">' . __('Contribute', 'nggallery') . '</a>'; 
  609. return $links; 
  610.  
  611. // Check for the header / footer, parts taken from Matt Martz (http://sivel.net/) 
  612. function test_head_footer_init() { 
  613.  
  614. // If test-head query var exists hook into wp_head 
  615. if ( isset( $_GET['test-head'] ) ) 
  616. add_action( 'wp_head', create_function('', 'echo \'<!--wp_head-->\';'), 99999 ); 
  617.  
  618. // If test-footer query var exists hook into wp_footer 
  619. if ( isset( $_GET['test-footer'] ) ) 
  620. add_action( 'wp_footer', create_function('', 'echo \'<!--wp_footer-->\';'), 99999 ); 
  621.  
  622. /** 
  623. * Handles upload requests 
  624. */ 
  625. function handle_upload_request() 
  626. if (isset($_GET['nggupload'])) { 
  627. require_once(implode(DIRECTORY_SEPARATOR, array( 
  628. NGGALLERY_ABSPATH,  
  629. 'admin',  
  630. 'upload.php' 
  631. ))); 
  632. throw new E_Clean_Exit(); 
  633.  
  634. /** 
  635. * Handles clean exits gracefully. Re-raises anything else 
  636. * @param Exception $ex 
  637. */ 
  638. function exception_handler($ex) 
  639. if (get_class($ex) != 'E_Clean_Exit') throw $ex;