/products/photocrati_nextgen/modules/ngglegacy/nggallery.php

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