nggLoader

The NextGEN Gallery nggLoader class.

Defined (1)

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

/products/photocrati_nextgen/modules/ngglegacy/nggallery.php  
  1. class nggLoader 
  2. var $version = NGG_PLUGIN_VERSION; 
  3. var $dbversion = '1.8.1'; 
  4. var $minimum_WP = '3.6.1'; 
  5. var $options = ''; 
  6. var $manage_page; 
  7. var $add_PHP5_notice = false; 
  8. var $plugin_name = ''; 
  9.  
  10. function __construct() 
  11. // Stop the plugin if we missed the requirements 
  12. if ( ( !$this->required_version() ) || ( !$this->check_memory_limit() ) ) 
  13. return; 
  14.  
  15. // Determine plugin basename based on whether NGG is being used in 
  16. // it's legacy form, or as a Photocrati-theme Gallery 
  17. if (defined('NGG_PLUGIN_BASENAME')) $this->plugin_name = NGG_PLUGIN_BASENAME; 
  18. else $this->plugin_name = basename(dirname(__FILE__)).'/'.basename(__FILE__); 
  19.  
  20. // Get some constants first 
  21. $this->load_options(); 
  22. $this->define_constant(); 
  23. $this->define_tables(); 
  24. $this->load_dependencies(); 
  25.  
  26. // Start this plugin once all other plugins are fully loaded 
  27. add_action( 'plugins_loaded', array(&$this, 'start_plugin') ); 
  28.  
  29. // Register_taxonomy must be used during the init 
  30. add_action( 'init', array(&$this, 'register_taxonomy'), 9); 
  31. add_action( 'wpmu_new_blog', array(&$this, 'multisite_new_blog'), 10, 6); 
  32.  
  33. // Add a message for PHP4 Users, can disable the update message later on 
  34. if (version_compare(PHP_VERSION, '5.0.0', '<')) 
  35. add_filter('transient_update_plugins', array(&$this, 'disable_upgrade')); 
  36.  
  37. //Add some links on the plugin page 
  38. add_filter('plugin_row_meta', array(&$this, 'add_plugin_links'), 10, 2); 
  39.  
  40. // Check for the header / footer 
  41. add_action( 'init', array(&$this, 'test_head_footer_init' ) ); 
  42.  
  43. // Show NextGEN version in header 
  44. add_action('wp_head', array('nggGallery', 'nextgen_version') ); 
  45.  
  46. function start_plugin() { 
  47.  
  48. global $nggRewrite; 
  49.  
  50. // All credits to the tranlator 
  51. $this->translator = '<p class="hint">'. __('<strong>Translation by : </strong><a target="_blank" href="https://www.imagely.com/wordpress-gallery-plugin/nextgen-pro/">See here</a>', 'nggallery') . '</p>'; 
  52.  
  53. // Content Filters 
  54. add_filter('ngg_gallery_name', 'sanitize_title'); 
  55.  
  56. // Check if we are in the admin area 
  57. if ( is_admin() ) { 
  58.  
  59. // Pass the init check or show a message 
  60. if (get_option( 'ngg_init_check' ) != false ) 
  61. add_action( 'admin_notices', create_function('', 'echo \'<div id="message" class="error"><p><strong>' . get_option( "ngg_init_check" ) . '</strong></p></div>\';') ); 
  62.  
  63. } else { 
  64.  
  65. // Add MRSS to wp_head 
  66. if ( isset( $this->options['useMediaRSS'] ) && $this->options['useMediaRSS'] ) 
  67. add_action('wp_head', array('nggMediaRss', 'add_mrss_alternate_link')); 
  68.  
  69.  
  70. function required_version() { 
  71.  
  72. global $wp_version; 
  73.  
  74. // Check for WP version installation 
  75. $wp_ok = version_compare($wp_version, $this->minimum_WP, '>='); 
  76.  
  77. if ( ($wp_ok == FALSE) ) { 
  78. add_action( 
  79. 'admin_notices',  
  80. create_function( 
  81. '',  
  82. '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 );' 
  83. ); 
  84. return false; 
  85.  
  86. return true; 
  87.  
  88.  
  89. function check_memory_limit() { 
  90.  
  91. // get the real memory limit before some increase it 
  92. $this->memory_limit = ini_get('memory_limit'); 
  93.  
  94. // PHP docs : Note that to have no memory limit, set this directive to -1. 
  95. if ($this->memory_limit == -1 ) return true; 
  96.  
  97. // Yes, we reached Gigabyte limits, so check if it's a megabyte limit 
  98. if (strtolower( substr($this->memory_limit, -1) ) == 'm') { 
  99.  
  100. $this->memory_limit = (int) substr( $this->memory_limit, 0, -1); 
  101.  
  102. //This works only with enough memory, 16MB is silly, wordpress requires already 16MB :-) 
  103. if ( ($this->memory_limit != 0) && ($this->memory_limit < 16 ) ) { 
  104. add_action( 
  105. 'admin_notices',  
  106. create_function( 
  107. '',  
  108. 'echo \'<div id="message" class="error"><p><strong>' . __('Sorry, NextGEN Gallery works only with a Memory Limit of 16 MB or higher', 'nggallery') . '</strong></p></div>\';' 
  109. ); 
  110. return false; 
  111.  
  112. return true; 
  113.  
  114.  
  115. function define_tables() { 
  116. global $wpdb; 
  117.  
  118. // add database pointer 
  119. $wpdb->nggpictures = $wpdb->prefix . 'ngg_pictures'; 
  120. $wpdb->nggallery = $wpdb->prefix . 'ngg_gallery'; 
  121. $wpdb->nggalbum = $wpdb->prefix . 'ngg_album'; 
  122.  
  123.  
  124. function register_taxonomy() { 
  125. global $wp_rewrite; 
  126.  
  127. // Register the NextGEN taxonomy 
  128. $args = array( 
  129. 'label' => __('Picture tag', 'nggallery'),  
  130. 'template' => __('Picture tag: %2$l.', 'nggallery'),  
  131. 'helps' => __('Separate picture tags with commas.', 'nggallery'),  
  132. 'sort' => true,  
  133. 'args' => array('orderby' => 'term_order') 
  134. ); 
  135.  
  136. register_taxonomy( 'ngg_tag', 'nggallery', $args ); 
  137.  
  138. function define_constant() { 
  139.  
  140. global $wp_version; 
  141.  
  142. //TODO:SHOULD BE REMOVED LATER 
  143. define('NGGVERSION', $this->version); 
  144. // Minimum required database version 
  145.  
  146. define('NGG_DBVERSION', $this->dbversion); 
  147.  
  148. // define URL 
  149. define('NGGFOLDER', dirname( $this->plugin_name ) ); 
  150.  
  151. // Legacy expects this to have a trailing slash 
  152. define( 
  153. 'NGGALLERY_ABSPATH',  
  154. defined('NGG_LEGACY_MOD_DIR') ? 
  155. rtrim(NGG_LEGACY_MOD_DIR, "/\\").DIRECTORY_SEPARATOR : 
  156. rtrim(dirname(__FILE__), "/\\").DIRECTORY_SEPARATOR 
  157. ); 
  158.  
  159. // Legacy expects this to have a trailing slash 
  160. define('NGGALLERY_URLPATH', plugin_dir_url(__FILE__)); 
  161.  
  162. // look for imagerotator 
  163. define('NGGALLERY_IREXIST', !empty( $this->options['irURL'] )); 
  164.  
  165. // get value for safe mode 
  166. if ( (gettype( ini_get('safe_mode') ) == 'string') ) { 
  167. // if sever did in in a other way 
  168. if ( ini_get('safe_mode') == 'off' ) define('SAFE_MODE', FALSE); 
  169. else define( 'SAFE_MODE', ini_get('safe_mode') ); 
  170. } else 
  171. define( 'SAFE_MODE', ini_get('safe_mode') ); 
  172.  
  173. if ( version_compare($wp_version, '3.2.999', '>') ) 
  174. define('IS_WP_3_3', TRUE); 
  175.  
  176.  
  177. function load_dependencies() { 
  178.  
  179. // Load global libraries // average memory usage (in bytes) 
  180. require_once (dirname (__FILE__) . '/lib/core.php'); // 94.840 
  181. require_once (dirname (__FILE__) . '/lib/class.ngg_serializable.php'); // 94.840 
  182. require_once (dirname (__FILE__) . '/lib/ngg-db.php'); // 132.400 
  183. require_once (dirname (__FILE__) . '/lib/image.php'); // 59.424 
  184. require_once (dirname (__FILE__) . '/lib/tags.php'); // 117.136 
  185. require_once (dirname (__FILE__) . '/lib/post-thumbnail.php'); // n.a. 
  186. require_once (dirname (__FILE__) . '/lib/multisite.php'); 
  187. require_once (dirname (__FILE__) . '/lib/sitemap.php'); 
  188.  
  189. // Load frontend libraries 
  190. require_once (dirname (__FILE__) . '/lib/shortcodes.php'); // 92.664 
  191.  
  192. // We didn't need all stuff during a AJAX operation 
  193. if ( defined('DOING_AJAX') ) 
  194. require_once (dirname (__FILE__) . '/admin/ajax.php'); 
  195. else { 
  196. require_once (dirname (__FILE__) . '/lib/meta.php'); // 131.856 
  197. require_once (dirname (__FILE__) . '/lib/media-rss.php'); // 82.768 
  198. require_once (dirname (__FILE__) . '/lib/rewrite.php'); // 71.936 
  199.  
  200. // Load backend libraries 
  201. if ( is_admin() ) { 
  202. require_once (dirname (__FILE__) . '/admin/admin.php'); 
  203. require_once (dirname (__FILE__) . '/admin/media-upload.php'); 
  204. $this->nggAdminPanel = new nggAdminPanel(); 
  205.  
  206. function load_thickbox_images() { 
  207. // WP core reference relative to the images. Bad idea 
  208. 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"; 
  209.  
  210. function load_options() { 
  211. // Load the options 
  212. $this->options = get_option('ngg_options'); 
  213.  
  214. // THX to Shiba for the code 
  215. // See: http://shibashake.com/wordpress-theme/write-a-plugin-for-wordpress-multi-site 
  216. function multisite_new_blog($blog_id, $user_id, $domain, $path, $site_id, $meta ) { 
  217. global $wpdb; 
  218.  
  219. include_once (dirname (__FILE__) . '/admin/install.php'); 
  220.  
  221. if (is_plugin_active_for_network( $this->plugin_name )) { 
  222. $current_blog = $wpdb->blogid; 
  223. switch_to_blog($blog_id); 
  224. $installer = new C_NggLegacy_Installer; 
  225. nggallery_install($installer); 
  226. switch_to_blog($current_blog); 
  227.  
  228. function disable_upgrade($option) { 
  229.  
  230. // PHP5.2 is required for NGG V1.4.0 
  231. if ( version_compare($option->response[ $this->plugin_name ]->new_version, '1.4.0', '>=') ) 
  232. return $option; 
  233.  
  234. if( isset($option->response[ $this->plugin_name ]) ) { 
  235. //Clear it''s download link 
  236. $option->response[ $this->plugin_name ]->package = ''; 
  237.  
  238. //Add a notice message 
  239. if ($this->add_PHP5_notice == false) { 
  240. 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>\';') ); 
  241. $this->add_PHP5_notice = true; 
  242. return $option; 
  243.  
  244. // Add links to Plugins page 
  245. function add_plugin_links($links, $file) { 
  246.  
  247. if ( $file == $this->plugin_name ) { 
  248. $links[] = '<a href="http://wordpress.org/support/plugin/nextgen-gallery">' . __('Get help', 'nggallery') . '</a>'; 
  249. $links[] = '<a href="https://bitbucket.org/photocrati/nextgen-gallery">' . __('Contribute', 'nggallery') . '</a>'; 
  250. return $links; 
  251.  
  252. // Check for the header / footer, parts taken from Matt Martz (http://sivel.net/) 
  253. function test_head_footer_init() { 
  254.  
  255. // If test-head query var exists hook into wp_head 
  256. if ( isset( $_GET['test-head'] ) ) 
  257. add_action( 'wp_head', create_function('', 'echo \'<!--wp_head-->\';'), 99999 ); 
  258.  
  259. // If test-footer query var exists hook into wp_footer 
  260. if ( isset( $_GET['test-footer'] ) ) 
  261. add_action( 'wp_footer', create_function('', 'echo \'<!--wp_footer-->\';'), 99999 );