PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/nextgen-gallery/nggallery.php

https://gitlab.com/blueprintmrk/bladencountyrecords
PHP | 526 lines | 306 code | 118 blank | 102 comment | 74 complexity | 4f415854577b9cbc2c9f3d0d716e50e0 MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: NextGEN Gallery
  4. Plugin URI: http://alexrabe.de/?page_id=80
  5. Description: A NextGENeration Photo gallery for the Web 2.0.
  6. Author: Alex Rabe
  7. Version: 1.7.4
  8. Author URI: http://alexrabe.de/
  9. Copyright 2007-2011 by Alex Rabe & NextGEN DEV-Team
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2 of the License, or
  13. (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. // Stop direct call
  23. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
  24. // ini_set('display_errors', '1');
  25. // ini_set('error_reporting', E_ALL);
  26. if (!class_exists('nggLoader')) {
  27. class nggLoader {
  28. var $version = '1.7.4';
  29. var $dbversion = '1.7.0';
  30. var $minium_WP = '3.0';
  31. var $donators = 'http://nextgen.boelinger.com/donators.php';
  32. var $options = '';
  33. var $manage_page;
  34. var $add_PHP5_notice = false;
  35. function nggLoader() {
  36. // Stop the plugin if we missed the requirements
  37. if ( ( !$this->required_version() ) || ( !$this->check_memory_limit() ) )
  38. return;
  39. // Get some constants first
  40. $this->load_options();
  41. $this->define_constant();
  42. $this->define_tables();
  43. $this->load_dependencies();
  44. $this->start_rewrite_module();
  45. $this->plugin_name = plugin_basename(__FILE__);
  46. // Init options & tables during activation & deregister init option
  47. register_activation_hook( $this->plugin_name, array(&$this, 'activate') );
  48. register_deactivation_hook( $this->plugin_name, array(&$this, 'deactivate') );
  49. // Register a uninstall hook to remove all tables & option automatic
  50. register_uninstall_hook( $this->plugin_name, array('nggLoader', 'uninstall') );
  51. // Start this plugin once all other plugins are fully loaded
  52. add_action( 'plugins_loaded', array(&$this, 'start_plugin') );
  53. // Register_taxonomy must be used during the init
  54. add_action( 'init', array(&$this, 'register_taxonomy') );
  55. // Hook to upgrade all blogs with one click and adding a new one later
  56. add_action( 'wpmu_upgrade_site', array(&$this, 'multisite_upgrade') );
  57. add_action( 'wpmu_new_blog', array(&$this, 'multisite_new_blog'), 10, 6);
  58. // Add a message for PHP4 Users, can disable the update message later on
  59. if (version_compare(PHP_VERSION, '5.0.0', '<'))
  60. add_filter('transient_update_plugins', array(&$this, 'disable_upgrade'));
  61. //Add some links on the plugin page
  62. add_filter('plugin_row_meta', array(&$this, 'add_plugin_links'), 10, 2);
  63. // Check for the header / footer
  64. add_action( 'init', array(&$this, 'test_head_footer_init' ) );
  65. }
  66. function start_plugin() {
  67. global $nggRewrite;
  68. // Load the language file
  69. $this->load_textdomain();
  70. // All credits to the tranlator
  71. $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>';
  72. $this->translator .= '<p class="hint">'. __('<strong>This translation is not yet updated for Version 1.7.3</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>';
  73. // Check for upgrade
  74. $this->check_for_upgrade();
  75. // Content Filters
  76. add_filter('ngg_gallery_name', 'sanitize_title');
  77. // Check if we are in the admin area
  78. if ( is_admin() ) {
  79. // Pass the init check or show a message
  80. if (get_option( 'ngg_init_check' ) != false )
  81. add_action( 'admin_notices', create_function('', 'echo \'<div id="message" class="error"><p><strong>' . get_option( "ngg_init_check" ) . '</strong></p></div>\';') );
  82. } else {
  83. // Add MRSS to wp_head
  84. if ( $this->options['useMediaRSS'] )
  85. add_action('wp_head', array('nggMediaRss', 'add_mrss_alternate_link'));
  86. // If activated, add PicLens/Cooliris javascript to footer
  87. if ( $this->options['usePicLens'] )
  88. add_action('wp_head', array('nggMediaRss', 'add_piclens_javascript'));
  89. // Look for XML request, before page is render
  90. add_action('parse_request', array(&$this, 'check_request') );
  91. // Add the script and style files
  92. add_action('template_redirect', array(&$this, 'load_scripts') );
  93. add_action('template_redirect', array(&$this, 'load_styles') );
  94. // Add a version number to the header
  95. add_action('wp_head', create_function('', 'echo "\n<meta name=\'NextGEN\' content=\'' . $this->version . '\' />\n";') );
  96. }
  97. }
  98. function check_request( $wp ) {
  99. if ( !array_key_exists('callback', $wp->query_vars) )
  100. return;
  101. if ( $wp->query_vars['callback'] == 'imagerotator') {
  102. require_once (dirname (__FILE__) . '/xml/imagerotator.php');
  103. exit();
  104. }
  105. if ( $wp->query_vars['callback'] == 'json') {
  106. require_once (dirname (__FILE__) . '/xml/json.php');
  107. exit();
  108. }
  109. if ( $wp->query_vars['callback'] == 'image') {
  110. require_once (dirname (__FILE__) . '/nggshow.php');
  111. exit();
  112. }
  113. //TODO:see trac #12400 could be an option for WP3.0
  114. if ( $wp->query_vars['callback'] == 'ngg-ajax') {
  115. require_once (dirname (__FILE__) . '/xml/ajax.php');
  116. exit();
  117. }
  118. }
  119. function required_version() {
  120. global $wp_version;
  121. // Check for WP version installation
  122. $wp_ok = version_compare($wp_version, $this->minium_WP, '>=');
  123. if ( ($wp_ok == FALSE) ) {
  124. add_action(
  125. 'admin_notices',
  126. create_function(
  127. '',
  128. '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->minium_WP );'
  129. )
  130. );
  131. return false;
  132. }
  133. return true;
  134. }
  135. function check_memory_limit() {
  136. // get the real memory limit before some increase it
  137. $this->memory_limit = (int) substr( ini_get('memory_limit'), 0, -1);
  138. //This works only with enough memory, 16MB is silly, wordpress requires already 16MB :-)
  139. if ( ($this->memory_limit != 0) && ($this->memory_limit < 16 ) ) {
  140. add_action(
  141. 'admin_notices',
  142. create_function(
  143. '',
  144. '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>\';'
  145. )
  146. );
  147. return false;
  148. }
  149. return true;
  150. }
  151. function check_for_upgrade() {
  152. // Inform about a database upgrade
  153. if( get_option( 'ngg_db_version' ) != NGG_DBVERSION ) {
  154. add_action(
  155. 'admin_notices',
  156. create_function(
  157. '',
  158. 'echo \'<div id="message" class="error"><p><strong>' . __('Please update the database of NextGEN Gallery.', 'nggallery') . ' <a href="admin.php?page=nextgen-gallery">' . __('Click here to proceed.', 'nggallery') . '</a>' . '</strong></p></div>\';'
  159. )
  160. );
  161. }
  162. return;
  163. }
  164. function define_tables() {
  165. global $wpdb;
  166. // add database pointer
  167. $wpdb->nggpictures = $wpdb->prefix . 'ngg_pictures';
  168. $wpdb->nggallery = $wpdb->prefix . 'ngg_gallery';
  169. $wpdb->nggalbum = $wpdb->prefix . 'ngg_album';
  170. }
  171. function register_taxonomy() {
  172. global $wp_rewrite;
  173. // Register the NextGEN taxonomy
  174. $args = array(
  175. 'label' => __('Picture tag', 'nggallery'),
  176. 'template' => __('Picture tag: %2$l.', 'nggallery'),
  177. 'helps' => __('Separate picture tags with commas.', 'nggallery'),
  178. 'sort' => true,
  179. 'args' => array('orderby' => 'term_order')
  180. );
  181. register_taxonomy( 'ngg_tag', 'nggallery', $args );
  182. }
  183. function define_constant() {
  184. //TODO:SHOULD BE REMOVED LATER
  185. define('NGGVERSION', $this->version);
  186. // Minimum required database version
  187. define('NGG_DBVERSION', $this->dbversion);
  188. // required for Windows & XAMPP
  189. define('WINABSPATH', str_replace("\\", "/", ABSPATH) );
  190. // define URL
  191. define('NGGFOLDER', plugin_basename( dirname(__FILE__)) );
  192. define('NGGALLERY_ABSPATH', trailingslashit( str_replace("\\","/", WP_PLUGIN_DIR . '/' . plugin_basename( dirname(__FILE__) ) ) ) );
  193. define('NGGALLERY_URLPATH', trailingslashit( plugins_url( '', __FILE__ ) ) );
  194. // look for imagerotator
  195. define('NGGALLERY_IREXIST', !empty( $this->options['irURL'] ));
  196. // get value for safe mode
  197. if ( (gettype( ini_get('safe_mode') ) == 'string') ) {
  198. // if sever did in in a other way
  199. if ( ini_get('safe_mode') == 'off' ) define('SAFE_MODE', FALSE);
  200. else define( 'SAFE_MODE', ini_get('safe_mode') );
  201. } else
  202. define( 'SAFE_MODE', ini_get('safe_mode') );
  203. }
  204. function load_dependencies() {
  205. // Load global libraries // average memory usage (in bytes)
  206. require_once (dirname (__FILE__) . '/lib/core.php'); // 94.840
  207. require_once (dirname (__FILE__) . '/lib/ngg-db.php'); // 132.400
  208. require_once (dirname (__FILE__) . '/lib/image.php'); // 59.424
  209. require_once (dirname (__FILE__) . '/lib/tags.php'); // 117.136
  210. require_once (dirname (__FILE__) . '/lib/post-thumbnail.php'); // n.a.
  211. require_once (dirname (__FILE__) . '/widgets/widgets.php'); // 298.792
  212. require_once (dirname (__FILE__) . '/lib/multisite.php');
  213. // Load frontend libraries
  214. require_once (dirname (__FILE__) . '/lib/navigation.php'); // 242.016
  215. require_once (dirname (__FILE__) . '/nggfunctions.php'); // n.a.
  216. require_once (dirname (__FILE__) . '/lib/shortcodes.php'); // 92.664
  217. //Just needed if you access remote to WordPress
  218. if ( defined('XMLRPC_REQUEST') )
  219. require_once (dirname (__FILE__) . '/lib/xmlrpc.php');
  220. // We didn't need all stuff during a AJAX operation
  221. if ( defined('DOING_AJAX') )
  222. require_once (dirname (__FILE__) . '/admin/ajax.php');
  223. else {
  224. require_once (dirname (__FILE__) . '/lib/meta.php'); // 131.856
  225. require_once (dirname (__FILE__) . '/lib/media-rss.php'); // 82.768
  226. require_once (dirname (__FILE__) . '/lib/rewrite.php'); // 71.936
  227. include_once (dirname (__FILE__) . '/admin/tinymce/tinymce.php'); // 22.408
  228. // Load backend libraries
  229. if ( is_admin() ) {
  230. require_once (dirname (__FILE__) . '/admin/admin.php');
  231. require_once (dirname (__FILE__) . '/admin/media-upload.php');
  232. $this->nggAdminPanel = new nggAdminPanel();
  233. }
  234. }
  235. }
  236. function load_textdomain() {
  237. load_plugin_textdomain('nggallery', false, dirname( plugin_basename(__FILE__) ) . '/lang');
  238. }
  239. function load_scripts() {
  240. // if you don't want that NGG load the scripts, add this constant
  241. if ( defined('NGG_SKIP_LOAD_SCRIPTS') )
  242. return;
  243. // activate Thickbox
  244. if ($this->options['thumbEffect'] == 'thickbox') {
  245. wp_enqueue_script( 'thickbox' );
  246. // Load the thickbox images after all other scripts
  247. add_action( 'wp_footer', array(&$this, 'load_thickbox_images'), 11 );
  248. }
  249. // activate modified Shutter reloaded if not use the Shutter plugin
  250. if ( ($this->options['thumbEffect'] == "shutter") && !function_exists('srel_makeshutter') ) {
  251. wp_register_script('shutter', NGGALLERY_URLPATH .'shutter/shutter-reloaded.js', false ,'1.3.0');
  252. wp_localize_script('shutter', 'shutterSettings', array(
  253. 'msgLoading' => __('L O A D I N G', 'nggallery'),
  254. 'msgClose' => __('Click to Close', 'nggallery'),
  255. 'imageCount' => '1'
  256. ) );
  257. wp_enqueue_script( 'shutter' );
  258. }
  259. // required for the slideshow
  260. if ( NGGALLERY_IREXIST == true && $this->options['enableIR'] == '1' && nggGallery::detect_mobile_phone() === false )
  261. wp_enqueue_script('swfobject', NGGALLERY_URLPATH .'admin/js/swfobject.js', FALSE, '2.2');
  262. else {
  263. wp_register_script('jquery-cycle', NGGALLERY_URLPATH .'js/jquery.cycle.all.min.js', array('jquery'), '2.88');
  264. wp_enqueue_script('ngg-slideshow', NGGALLERY_URLPATH .'js/ngg.slideshow.min.js', array('jquery-cycle'), '1.05');
  265. }
  266. // Load AJAX navigation script, works only with shutter script as we need to add the listener
  267. if ( $this->options['galAjaxNav'] ) {
  268. if ( ($this->options['thumbEffect'] == "shutter") || function_exists('srel_makeshutter') ) {
  269. wp_enqueue_script ( 'ngg_script', NGGALLERY_URLPATH . 'js/ngg.js', array('jquery'), '2.0');
  270. wp_localize_script( 'ngg_script', 'ngg_ajax', array('path' => NGGALLERY_URLPATH,
  271. 'callback' => site_url() . '/' . 'index.php?callback=ngg-ajax',
  272. 'loading' => __('loading', 'nggallery'),
  273. ) );
  274. }
  275. }
  276. }
  277. function load_thickbox_images() {
  278. // WP core reference relative to the images. Bad idea
  279. 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";
  280. }
  281. function load_styles() {
  282. // check first the theme folder for a nggallery.css
  283. if ( nggGallery::get_theme_css_file() )
  284. wp_enqueue_style('NextGEN', nggGallery::get_theme_css_file() , false, '1.0.0', 'screen');
  285. else if ($this->options['activateCSS'])
  286. wp_enqueue_style('NextGEN', NGGALLERY_URLPATH . 'css/' . $this->options['CSSfile'], false, '1.0.0', 'screen');
  287. // activate Thickbox
  288. if ($this->options['thumbEffect'] == 'thickbox')
  289. wp_enqueue_style( 'thickbox');
  290. // activate modified Shutter reloaded if not use the Shutter plugin
  291. if ( ($this->options['thumbEffect'] == 'shutter') && !function_exists('srel_makeshutter') )
  292. wp_enqueue_style('shutter', NGGALLERY_URLPATH .'shutter/shutter-reloaded.css', false, '1.3.0', 'screen');
  293. }
  294. function load_options() {
  295. // Load the options
  296. $this->options = get_option('ngg_options');
  297. }
  298. // Add rewrite rules
  299. function start_rewrite_module() {
  300. global $nggRewrite;
  301. if ( class_exists('nggRewrite') )
  302. $nggRewrite = new nggRewrite();
  303. }
  304. // THX to Shiba for the code
  305. // See: http://shibashake.com/wordpress-theme/write-a-plugin-for-wordpress-multi-site
  306. function multisite_new_blog($blog_id, $user_id, $domain, $path, $site_id, $meta ) {
  307. global $wpdb;
  308. include_once (dirname (__FILE__) . '/admin/install.php');
  309. if (is_plugin_active_for_network( $this->plugin_name )) {
  310. $current_blog = $wpdb->blogid;
  311. switch_to_blog($blog_id);
  312. nggallery_install();
  313. switch_to_blog($current_blog);
  314. }
  315. }
  316. function activate() {
  317. global $wpdb;
  318. //Starting from version 1.8.0 it's works only with PHP5.2
  319. //if (version_compare(PHP_VERSION, '5.2.0', '<')) {
  320. // deactivate_plugins(plugin_basename(__FILE__)); // Deactivate ourself
  321. // wp_die("Sorry, but you can't run this plugin, it requires PHP 5.2 or higher.");
  322. // return;
  323. //}
  324. include_once (dirname (__FILE__) . '/admin/install.php');
  325. if ( is_multisite() ) {
  326. // check if it is a network activation - if so, run the activation function for each blog id
  327. if (isset($_GET['networkwide']) && ($_GET['networkwide'] == 1)) {
  328. $current_blog = $wpdb->blogid;
  329. // Get all blog ids
  330. $blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs"));
  331. foreach ($blogids as $blog_id) {
  332. switch_to_blog($blog_id);
  333. nggallery_install();
  334. }
  335. switch_to_blog($current_blog);
  336. return;
  337. }
  338. }
  339. // check for tables
  340. nggallery_install();
  341. // remove the update message
  342. delete_option( 'ngg_update_exists' );
  343. }
  344. function deactivate() {
  345. // remove & reset the init check option
  346. delete_option( 'ngg_init_check' );
  347. delete_option( 'ngg_update_exists' );
  348. }
  349. function uninstall() {
  350. include_once (dirname (__FILE__) . '/admin/install.php');
  351. nggallery_uninstall();
  352. }
  353. function multisite_upgrade ( $blog_id ) {
  354. global $wpdb;
  355. include_once (dirname (__FILE__) . '/admin/upgrade.php');
  356. $current_blog = $wpdb->blogid;
  357. switch_to_blog( $blog_id );
  358. ngg_upgrade();
  359. switch_to_blog($current_blog);
  360. return;
  361. }
  362. function disable_upgrade($option){
  363. $this_plugin = plugin_basename(__FILE__);
  364. // PHP5.2 is required for NGG V1.4.0
  365. if ( version_compare($option->response[ $this_plugin ]->new_version, '1.4.0', '>=') )
  366. return $option;
  367. if( isset($option->response[ $this_plugin ]) ){
  368. //Clear it''s download link
  369. $option->response[ $this_plugin ]->package = '';
  370. //Add a notice message
  371. if ($this->add_PHP5_notice == false){
  372. 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>\';') );
  373. $this->add_PHP5_notice = true;
  374. }
  375. }
  376. return $option;
  377. }
  378. // Taken from Google XML Sitemaps from Arne Brachhold
  379. function add_plugin_links($links, $file) {
  380. if ( $file == plugin_basename(__FILE__) ) {
  381. $links[] = '<a href="admin.php?page=nextgen-gallery">' . __('Overview', 'nggallery') . '</a>';
  382. $links[] = '<a href="http://wordpress.org/tags/nextgen-gallery?forum_id=10">' . __('Get help', 'nggallery') . '</a>';
  383. $links[] = '<a href="http://code.google.com/p/nextgen-gallery/">' . __('Contribute', 'nggallery') . '</a>';
  384. $links[] = '<a href="http://alexrabe.de/donation/">' . __('Donate', 'nggallery') . '</a>';
  385. }
  386. return $links;
  387. }
  388. // Check for the header / footer, parts taken from Matt Martz (http://sivel.net/)
  389. function test_head_footer_init() {
  390. // If test-head query var exists hook into wp_head
  391. if ( isset( $_GET['test-head'] ) )
  392. add_action( 'wp_head', create_function('', 'echo \'<!--wp_head-->\';'), 99999 );
  393. // If test-footer query var exists hook into wp_footer
  394. if ( isset( $_GET['test-footer'] ) )
  395. add_action( 'wp_footer', create_function('', 'echo \'<!--wp_footer-->\';'), 99999 );
  396. }
  397. }
  398. // Let's start the holy plugin
  399. global $ngg;
  400. $ngg = new nggLoader();
  401. }
  402. ?>