C_NextGEN_Bootstrap

NextGEN Gallery is built on top of the Pope Framework: https://bitbucket.org/photocrati/pope-framework.

Defined (1)

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

/nggallery.php  
  1. class C_NextGEN_Bootstrap 
  2. var $_registry = NULL; 
  3. var $_settings_option_name = 'ngg_options'; 
  4. var $_pope_loaded = FALSE; 
  5. static $debug = FALSE; 
  6. var $minimum_ngg_pro_version = '2.0.5'; 
  7. var $minimum_ngg_plus_version = '1.0.1'; 
  8.  
  9. static function shutdown($exception=NULL) 
  10. if (is_null($exception)) { 
  11. throw new E_Clean_Exit; 
  12. elseif (!($exception instanceof E_Clean_Exit)) { 
  13. ob_end_clean(); 
  14. self::print_exception($exception); 
  15.  
  16.  
  17. static function print_exception($exception) 
  18. $klass = get_class($exception); 
  19. echo "<h1>{$klass} thrown</h1>"; 
  20. echo "<p>{$exception->getMessage()}</p>"; 
  21. if (self::$debug OR (defined('NGG_DEBUG') AND NGG_DEBUG == TRUE)) { 
  22. echo "<h3>Where:</h3>"; 
  23. echo "<p>On line <strong>{$exception->getLine()}</strong> of <strong>{$exception->getFile()}</strong></p>"; 
  24. echo "<h3>Trace:</h3>"; 
  25. echo "<pre>{$exception->getTraceAsString()}</pre>"; 
  26. if (method_exists($exception, 'getPrevious')) { 
  27. if (($previous = $exception->getPrevious())) { 
  28. self::print_exception($previous); 
  29.  
  30. static function get_backtrace($objects=FALSE, $remove_dynamic_calls=TRUE) 
  31. $trace = debug_backtrace($objects); 
  32. if ($remove_dynamic_calls) { 
  33. $skip_methods = array( 
  34. '_exec_cached_method',  
  35. '__call',  
  36. 'get_method_property',  
  37. 'set_method_property',  
  38. 'call_method' 
  39. ); 
  40. foreach ($trace as $key => &$value) { 
  41. if (isset($value['class']) && isset($value['function'])) { 
  42. if ($value['class'] == 'ReflectionMethod' && $value['function'] == 'invokeArgs') 
  43. unset($trace[$key]); 
  44.  
  45. else if ($value['class'] == 'ExtensibleObject' && in_array($value['function'], $skip_methods)) 
  46. unset($trace[$key]); 
  47.  
  48. return $trace; 
  49.  
  50. function __construct() 
  51. set_exception_handler(__CLASS__.'::shutdown'); 
  52.  
  53. // We only load the plugin if we're outside of the activation request, loaded in an iframe 
  54. // by WordPress. Reason being, if WP_DEBUG is enabled, and another Pope-based plugin (such as 
  55. // the photocrati theme or NextGEN Pro/Plus), then PHP will output strict warnings 
  56. if ($this->is_not_activating()) { 
  57. $this->_define_constants(); 
  58. $this->_load_non_pope(); 
  59. $this->_register_hooks(); 
  60. $this->_load_pope(); 
  61.  
  62. function is_not_activating() 
  63. return !$this->is_activating(); 
  64.  
  65. function is_activating() 
  66. $retval = strpos($_SERVER['REQUEST_URI'], 'plugins.php') !== FALSE && isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('activate-selected')); 
  67.  
  68. if (!$retval && strpos($_SERVER['REQUEST_URI'], 'update.php') !== FALSE && isset($_REQUEST['action']) && $_REQUEST['action'] == 'install-plugin' && isset($_REQUEST['plugin']) && strpos($_REQUEST['plugin'], 'nextgen-gallery') === 0) { 
  69. $retval = TRUE; 
  70.  
  71. if (!$retval && strpos($_SERVER['REQUEST_URI'], 'update.php') !== FALSE && isset($_REQUEST['action']) && $_REQUEST['action'] == 'activate-plugin' && isset($_REQUEST['plugin']) && strpos($_REQUEST['plugin'], 'nextgen-gallery') === 0) { 
  72. $retval = TRUE; 
  73.  
  74. return $retval; 
  75.  
  76. function _load_non_pope() 
  77. // Load caching component 
  78. include_once('non_pope/class.photocrati_transient_manager.php'); 
  79.  
  80. if (isset($_REQUEST['ngg_flush']) OR isset($_REQUEST['ngg_flush_expired'])) { 
  81. C_Photocrati_Transient_Manager::flush(); 
  82. die("Flushed all caches"); 
  83.  
  84. // Load Settings Manager 
  85. include_once('non_pope/class.photocrati_settings_manager.php'); 
  86. include_once('non_pope/class.nextgen_settings.php'); 
  87. C_Photocrati_Global_Settings_Manager::$option_name = $this->_settings_option_name; 
  88. C_Photocrati_Settings_Manager::$option_name = $this->_settings_option_name; 
  89.  
  90. // Load the installer 
  91. include_once('non_pope/class.photocrati_installer.php'); 
  92.  
  93. // Load the resource manager 
  94. include_once('non_pope/class.photocrati_resource_manager.php'); 
  95. C_Photocrati_Resource_Manager::init(); 
  96.  
  97. // Load the style manager 
  98. include_once('non_pope/class.nextgen_style_manager.php'); 
  99.  
  100. // Load the shortcode manager 
  101. include_once('non_pope/class.nextgen_shortcode_manager.php'); 
  102. C_NextGen_Shortcode_Manager::get_instance(); 
  103.  
  104. function fix_loading_order() 
  105. // If a plugin wasn't activated/deactivated siliently, we can listen for these things 
  106. if (did_action('activate_plugin') || did_action('deactivate_plugin')) return; 
  107. else if (strpos($_SERVER['REQUEST_URI'], 'plugins') !== FALSE) return; 
  108. else if (!$this->is_page_request()) return; 
  109.  
  110. $plugins = get_option('active_plugins'); 
  111.  
  112. // Remove NGG from the list 
  113. $ngg = basename(dirname(__FILE__)).'/'.basename(__FILE__); 
  114. $order = array(); 
  115. foreach ($plugins as $plugin) { 
  116. if ($plugin != $ngg) $order[] = $plugin; 
  117.  
  118.  
  119. // Get the position of either NGG Pro or NGG Plus 
  120. $insert_at = FALSE; 
  121. for($i=0; $i<count($order); $i++) { 
  122. $plugin = $order[$i]; 
  123. if (strpos($plugin, 'nggallery-pro') !== FALSE) $insert_at = $i+1; 
  124. else if (strpos($plugin, 'ngg-plus') !== FALSE) $insert_at = $i+1; 
  125.  
  126. // Re-insert NGG after Pro or Plus 
  127. if ($insert_at === FALSE || $insert_at === count($order)) $order[] = $ngg; 
  128. elseif ($insert_at === 0) array_unshift($order, $ngg); 
  129. else array_splice($order, $insert_at, 0, array($ngg)); 
  130.  
  131. if ($order != $plugins) { 
  132. $order = array_filter($order); 
  133. update_option('active_plugins', $order); 
  134.  
  135. /** 
  136. * Loads the Pope Framework 
  137. */ 
  138. function _load_pope() 
  139. // No need to initialize pope again 
  140. if ($this->_pope_loaded) return; 
  141.  
  142. // Pope requires a a higher limit 
  143. $tmp = ini_get('xdebug.max_nesting_level'); 
  144. if ($tmp && (int)$tmp <= 300) @ini_set('xdebug.max_nesting_level', 300); 
  145.  
  146. // Include pope framework 
  147. require_once(implode( 
  148. DIRECTORY_SEPARATOR, array(NGG_PLUGIN_DIR, 'pope', 'lib', 'autoload.php') 
  149. )); 
  150.  
  151. // Enable/disable pope caching. For now, the pope cache will not be used in multisite environments 
  152. if (class_exists('C_Pope_Cache')) { 
  153. if ((C_Pope_Cache::$enabled = NGG_POPE_CACHE)) { 
  154. $blogid = (is_multisite() ? get_current_blog_id() : NULL); 
  155. if (isset($_SERVER['SERVER_ADDR'])) 
  156. $cache_key_prefix = abs(crc32((implode('|', array($blogid, site_url(), AUTH_KEY, $_SERVER['SERVER_ADDR']))))); 
  157. else 
  158. $cache_key_prefix = abs(crc32(implode('|', array($blogid, site_url(), AUTH_KEY)))); 
  159.  
  160. C_Pope_Cache::set_driver('C_Pope_Cache_SingleFile'); 
  161. C_Pope_Cache::add_key_prefix($cache_key_prefix); 
  162.  
  163. // Enforce interfaces 
  164. if (property_exists('ExtensibleObject', 'enforce_interfaces')) ExtensibleObject::$enforce_interfaces = EXTENSIBLE_OBJECT_ENFORCE_INTERFACES; 
  165.  
  166. // Get the component registry 
  167. $this->_registry = C_Component_Registry::get_instance(); 
  168.  
  169. // Add the default Pope factory utility, C_Component_Factory 
  170. $this->_registry->add_utility('I_Component_Factory', 'C_Component_Factory'); 
  171.  
  172. // Blacklist any modules which are known NOT to work with this version of NextGEN Gallery 
  173. // We need to check if we have this ability as it's only available with Pope 0.9 
  174. if (method_exists($this->_registry, 'blacklist_module_file')) { 
  175. $this->_registry->blacklist_module_file('module.nextgen_pro_lightbox_legacy.php'); 
  176. $this->_registry->blacklist_module_file('module.protect_image.php'); 
  177. // TODO: Add module id for protect image 
  178.  
  179. // If Pro is incompatible, then we need to blacklist all of Pro's modules 
  180. // TODO: Pope needs a better way of introspecting into a product's list of provided modules 
  181. if ($this->is_pro_incompatible()) { 
  182. $pro_modules = array( 
  183. 'photocrati-comments',  
  184. 'photocrati-galleria',  
  185. 'photocrati-nextgen_pro_slideshow',  
  186. 'photocrati-nextgen_pro_horizontal_filmstrip',  
  187. 'photocrati-nextgen_pro_thumbnail_grid',  
  188. 'photocrati-nextgen_pro_blog_gallery',  
  189. 'photocrati-nextgen_pro_film',  
  190. 'photocrati-nextgen_pro_masonry',  
  191. 'photocrati-nextgen_pro_albums',  
  192. 'photocrati-nextgen_pro_lightbox',  
  193. 'photocrati-nextgen_pro_lightbox_legacy',  
  194. 'photocrati-nextgen_pro_ecommerce',  
  195. 'photocrati-paypal_express_checkout',  
  196. 'photocrati-paypal_standard',  
  197. 'photocrati-stripe' 
  198. ); 
  199. foreach ($pro_modules as $mod) $this->_registry->blacklist_module_file($mod); 
  200.  
  201. // Load embedded products. Each product is expected to load any 
  202. // modules required 
  203. $this->_registry->add_module_path(NGG_PRODUCT_DIR, 2, false); 
  204. $this->_registry->load_all_products(); 
  205.  
  206. // Give third-party plugins that opportunity to include their own products 
  207. // and modules 
  208. do_action('load_nextgen_gallery_modules', $this->_registry); 
  209.  
  210. // Initializes all loaded modules 
  211. $this->_registry->initialize_all_modules(); 
  212.  
  213. $this->_pope_loaded = TRUE; 
  214.  
  215. function is_pro_compatible() 
  216. $retval = TRUE; 
  217.  
  218. if (defined('NEXTGEN_GALLERY_PRO_VERSION')) $retval = FALSE; 
  219. if (defined('NEXTGEN_GALLERY_PRO_PLUGIN_BASENAME') && !defined('NGG_PRO_PLUGIN_VERSION')) $retval = FALSE; // 1.0 - 1.0.6 
  220. if (defined('NGG_PRO_PLUGIN_VERSION') && version_compare(NGG_PRO_PLUGIN_VERSION, $this->minimum_ngg_pro_version) < 0) $retval = FALSE; 
  221. if (defined('NGG_PLUS_PLUGIN_VERSION') && version_compare(NGG_PLUS_PLUGIN_VERSION, $this->minimum_ngg_plus_version) < 0) $retval = FALSE; 
  222.  
  223. return $retval; 
  224.  
  225. function is_pro_incompatible() 
  226. return !$this->is_pro_compatible(); 
  227.  
  228. function render_incompatibility_warning() 
  229. echo '<div class="updated error"><p>'; 
  230. echo esc_html( 
  231. sprintf( 
  232. __("NextGEN Gallery %s is incompatible with this version of NextGEN Pro. Please update NextGEN Pro to version %s or higher to restore NextGEN Pro functionality.",  
  233. 'nggallery' 
  234. ),  
  235. NGG_PLUGIN_VERSION, $this->minimum_ngg_pro_version 
  236. )); 
  237. echo '</p></div>'; 
  238.  
  239.  
  240. /** 
  241. * Registers hooks for the WordPress framework necessary for instantiating 
  242. * the plugin 
  243. */ 
  244. function _register_hooks() 
  245. // Register the deactivation routines 
  246. add_action('deactivate_'.NGG_PLUGIN_BASENAME, array(get_class(), 'deactivate')); 
  247.  
  248. // Register our test suite 
  249. add_filter('simpletest_suites', array(&$this, 'add_testsuite')); 
  250.  
  251. // Ensure that settings manager is saved as an array 
  252. add_filter('pre_update_option_'.$this->_settings_option_name, array(&$this, 'persist_settings')); 
  253. add_filter('pre_update_site_option_'.$this->_settings_option_name, array(&$this, 'persist_settings')); 
  254.  
  255. // This plugin uses jQuery extensively 
  256. if (NGG_FIX_JQUERY) { 
  257. add_action('wp_enqueue_scripts', array(&$this, 'fix_jquery')); 
  258. add_action('wp_print_scripts', array(&$this, 'fix_jquery')); 
  259.  
  260. // If the selected stylesheet is using an unsafe path, then notify the user 
  261. add_action('all_admin_notices', array(&$this, 'display_stylesheet_notice')); 
  262.  
  263. // Delete displayed gallery transients periodically 
  264. if (NGG_CRON_ENABLED) { 
  265. add_filter('cron_schedules', array(&$this, 'add_ngg_schedule')); 
  266. add_action('ngg_delete_expired_transients', array(&$this, 'delete_expired_transients')); 
  267. add_action('wp', array(&$this, 'schedule_cron_jobs')); 
  268.  
  269. // Update modules 
  270. add_action('init', array(&$this, 'update'), PHP_INT_MAX-2); 
  271.  
  272. // Start the plugin! 
  273. add_action('init', array(&$this, 'route'), 11); 
  274.  
  275. // Flush pope cache 
  276. add_action('init', array(&$this, 'flush_pope_cache')); 
  277.  
  278. // NGG extension plugins should be loaded in a specific order 
  279. add_action('shutdown', array(&$this, 'fix_loading_order')); 
  280.  
  281. // Display a warning if an compatible version of NextGEN Pro is installed alongside this 
  282. // version of NextGEN Gallery 
  283. if ($this->is_pro_incompatible()) { 
  284. add_filter('http_request_args', array(&$this, 'fix_autoupdate_api_requests'), 10, 2); 
  285. add_action('all_admin_notices', array(&$this, 'render_incompatibility_warning')); 
  286.  
  287. add_filter('ngg_load_frontend_logic', array($this, 'disable_frontend_logic'), -10, 2); 
  288.  
  289. function disable_frontend_logic($enabled, $module_id) 
  290. if (is_admin()) 
  291. $settings = C_NextGen_Settings::get_instance(); 
  292. if (!$settings->get('always_enable_frontend_logic')) 
  293. $enabled = FALSE; 
  294. return $enabled; 
  295.  
  296. function fix_autoupdate_api_requests($args, $url) 
  297. // Is this an HTTP request to the licensing server? 
  298. if (preg_match("/api_act=/", $url)) { 
  299. $args['autoupdate'] = TRUE; 
  300.  
  301. // If we're supposed to pass all Pro modules, then include them here 
  302. if (preg_match("/api_act=(ckups|cklic)/", $url) && isset($args['body']) && is_array($args['body']) && isset($args['body']['module-list'])) { 
  303. $pro_modules = array( 
  304. 'photocrati-comments',  
  305. 'photocrati-galleria',  
  306. 'photocrati-nextgen_pro_slideshow',  
  307. 'photocrati-nextgen_pro_horizontal_filmstrip',  
  308. 'photocrati-nextgen_pro_thumbnail_grid',  
  309. 'photocrati-nextgen_pro_blog_gallery',  
  310. 'photocrati-nextgen_pro_film',  
  311. 'photocrati-nextgen_pro_masonry',  
  312. 'photocrati-nextgen_pro_albums',  
  313. 'photocrati-auto_update',  
  314. 'photocrati-auto_update-admin',  
  315. 'photocrati-nextgen_pro_lightbox',  
  316. 'photocrati-nextgen_pro_lightbox_legacy',  
  317. 'photocrati-nextgen_pro_ecommerce',  
  318. 'photocrati-paypal_express_checkout',  
  319. 'photocrati-paypal_standard',  
  320. 'photocrati-stripe' 
  321. ); 
  322. foreach ($pro_modules as $mod) { 
  323. if (!isset($args['body']['module-list'][$mod])) $args['body']['module-list'][$mod] = '0.1'; 
  324. return $args; 
  325.  
  326. function flush_pope_cache() 
  327. if (is_user_logged_in() && current_user_can('manage_options') && isset($_REQUEST['ngg_flush_pope_cache'])) { 
  328. C_Pope_Cache::get_instance()->flush(); 
  329. print "Flushed pope cache"; 
  330. exit; 
  331.  
  332. function schedule_cron_jobs() 
  333. if (!wp_next_scheduled('ngg_delete_expired_transients')) { 
  334. wp_schedule_event(time(), 'ngg_custom', 'ngg_delete_expired_transients'); 
  335.  
  336. /** 
  337. * Defines a new cron schedule 
  338. * @param $schedules 
  339. * @return mixed 
  340. */ 
  341. function add_ngg_schedule($schedules) 
  342. $schedules['ngg_custom'] = array( 
  343. 'interval' => NGG_CRON_SCHEDULE,  
  344. 'display' => sprintf(__('Every %d seconds', 'nggallery'), NGG_CRON_SCHEDULE) 
  345. ); 
  346.  
  347. return $schedules; 
  348.  
  349.  
  350. /** 
  351. * Flush all expires transients created by the plugin 
  352. */ 
  353. function delete_expired_transients() 
  354. C_Photocrati_Transient_Manager::flush(); 
  355.  
  356. /** 
  357. * Ensure that C_Photocrati_Settings_Manager gets persisted as an array 
  358. * @param $settings 
  359. * @return array 
  360. */ 
  361. function persist_settings($settings) 
  362. if (is_object($settings) && $settings instanceof C_Photocrati_Settings_Manager_Base) { 
  363. $settings = $settings->to_array(); 
  364. return $settings; 
  365.  
  366. /** 
  367. * Ensures that the version of JQuery used is expected for NextGEN Gallery 
  368. */ 
  369. function fix_jquery() 
  370. global $wp_scripts; 
  371.  
  372. // Determine which version of jQuery to include 
  373. $src = '/wp-includes/js/jquery/jquery.js'; 
  374.  
  375. // Ensure that jQuery is always set to the default 
  376. if (isset($wp_scripts->registered['jquery'])) { 
  377. $jquery = $wp_scripts->registered['jquery']; 
  378.  
  379. // There's an exception to the rule. We'll allow the same 
  380. // version of jQuery as included with WP to be fetched from 
  381. // Google AJAX libraries, as we have a systematic means of verifying 
  382. // that won't cause any troubles 
  383. $version = preg_quote($jquery->ver, '#'); 
  384. if (!preg_match("#ajax\\.googleapis\\.com/ajax/libs/jquery/{$version}/jquery\\.min\\.js#", $jquery->src)) { 
  385. $jquery->src = FALSE; 
  386. if (array_search('jquery-core', $jquery->deps) === FALSE) { 
  387. $jquery->deps[] = 'jquery-core'; 
  388. if (array_search('jquery-migrate', $jquery->deps) === FALSE) { 
  389. $jquery->deps[] = 'jquery-migrate'; 
  390.  
  391. // Ensure that jquery-core is used, as WP intended 
  392. if (isset($wp_scripts->registered['jquery-core'])) { 
  393. $wp_scripts->registered['jquery-core']->src = $src; 
  394.  
  395. wp_enqueue_script('jquery'); 
  396.  
  397. /** 
  398. * Displays a notice to the user that the current stylesheet location is unsafe 
  399. */ 
  400. function display_stylesheet_notice() 
  401. if (C_NextGen_Style_Manager::get_instance()->is_directory_unsafe()) { 
  402. $styles = C_NextGen_Style_Manager::get_instance(); 
  403. $filename = $styles->get_selected_stylesheet(); 
  404. $abspath = $styles->find_selected_stylesheet_abspath(); 
  405. $newpath = $styles->new_dir; 
  406.  
  407. echo "<div class='updated error'> 
  408. <h3>WARNING: NextGEN Gallery Stylesheet NOT Upgrade-safe</h3> 
  409. <p> 
  410. <strong>{$filename}</strong> is currently stored in <strong>{$abspath}</strong>, which isn't upgrade-safe. Please move the stylesheet to 
  411. <strong>{$newpath}</strong> to ensure that your customizations persist after updates. 
  412. </p></div>"; 
  413.  
  414. /** 
  415. * Updates all modules 
  416. */ 
  417. function update() 
  418. if ((!(defined('DOING_AJAX') && DOING_AJAX)) && !isset($_REQUEST['doing_wp_cron'])) { 
  419.  
  420. $this->_load_pope(); 
  421.  
  422. // Try updating all modules 
  423. C_Photocrati_Installer::update(); 
  424.  
  425. /** 
  426. * Routes access points using the Pope Router 
  427. * @return boolean 
  428. */ 
  429. function route() 
  430. $this->_load_pope(); 
  431. $router = C_Router::get_instance(); 
  432.  
  433. // Set context to path if subdirectory install 
  434. $parts = parse_url($router->get_base_url(FALSE)); 
  435. if (isset($parts['path'])) { 
  436. $parts = explode('/index.php', $parts['path']); 
  437. $router->context = array_shift($parts); 
  438.  
  439. // Provide a means for modules/third-parties to configure routes 
  440. do_action_ref_array('ngg_routes', array(&$router)); 
  441.  
  442. // Serve the routes 
  443. if (!$router->serve_request() && $router->has_parameter_segments()) { 
  444. return $router->passthru(); 
  445.  
  446. function is_page_request() 
  447. return !(defined('DOING_AJAX') && DOING_AJAX) && !(defined('DOING_CRON') && DOING_CRON) && !(defined('NGG_AJAX_SLUG') && strpos($_SERVER['REQUEST_URI'], NGG_AJAX_SLUG) !== FALSE); 
  448.  
  449. /** 
  450. * Run the uninstaller 
  451. */ 
  452. static function deactivate() 
  453. include_once('products/photocrati_nextgen/class.nextgen_product_installer.php'); 
  454. C_Photocrati_Installer::add_handler(NGG_PLUGIN_BASENAME, 'C_NextGen_Product_Installer'); 
  455. C_Photocrati_Installer::uninstall(NGG_PLUGIN_BASENAME); 
  456.  
  457. /** 
  458. * Defines necessary plugins for the plugin to load correctly 
  459. */ 
  460. function _define_constants() 
  461. define('NGG_PLUGIN', basename($this->directory_path())); 
  462. define('NGG_PLUGIN_BASENAME', plugin_basename(__FILE__)); 
  463. define('NGG_PLUGIN_DIR', $this->directory_path()); 
  464. define('NGG_PLUGIN_URL', $this->path_uri()); 
  465. define('NGG_TESTS_DIR', implode(DIRECTORY_SEPARATOR, array(rtrim(NGG_PLUGIN_DIR, "/\\"), 'tests'))); 
  466. define('NGG_PRODUCT_DIR', implode(DIRECTORY_SEPARATOR, array(rtrim(NGG_PLUGIN_DIR, "/\\"), 'products'))); 
  467. define('NGG_MODULE_DIR', implode(DIRECTORY_SEPARATOR, array(rtrim(NGG_PRODUCT_DIR, "/\\"), 'photocrati_nextgen', 'modules'))); 
  468. define('NGG_PRODUCT_URL', path_join(str_replace("\\", '/', NGG_PLUGIN_URL), 'products')); 
  469. define('NGG_MODULE_URL', path_join(str_replace("\\", '/', NGG_PRODUCT_URL), 'photocrati_nextgen/modules')); 
  470. define('NGG_PLUGIN_STARTED_AT', microtime()); 
  471. define('NGG_PLUGIN_VERSION', '2.2.3'); 
  472.  
  473. if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) 
  474. define('NGG_SCRIPT_VERSION', (string)mt_rand(0, mt_getrandmax())); 
  475. else 
  476. define('NGG_SCRIPT_VERSION', NGG_PLUGIN_VERSION); 
  477.  
  478. if (!defined('NGG_HIDE_STRICT_ERRORS')) { 
  479. define('NGG_HIDE_STRICT_ERRORS', TRUE); 
  480.  
  481. // Should we display E_STRICT errors? 
  482. if (NGG_HIDE_STRICT_ERRORS) { 
  483. $level = error_reporting(); 
  484. if ($level != 0) error_reporting($level & ~E_STRICT); 
  485.  
  486. // Should we display NGG debugging information? 
  487. if (!defined('NGG_DEBUG')) { 
  488. define('NGG_DEBUG', FALSE); 
  489. self::$debug = NGG_DEBUG; 
  490.  
  491. // User definable constants 
  492. if (!defined('NGG_IMPORT_ROOT')) { 
  493. $path = WP_CONTENT_DIR; 
  494. if (defined('NEXTGEN_GALLERY_IMPORT_ROOT')) { 
  495. $path = NEXTGEN_GALLERY_IMPORT_ROOT; 
  496. define('NGG_IMPORT_ROOT', $path); 
  497.  
  498. // Should the Photocrati cache be enabled 
  499. if (!defined('PHOTOCRATI_CACHE')) { 
  500. define('PHOTOCRATI_CACHE', TRUE); 
  501. if (!defined('PHOTOCRATI_CACHE_TTL')) { 
  502. define('PHOTOCRATI_CACHE_TTL', 1800); 
  503.  
  504. // Cron job 
  505. if (!defined('NGG_CRON_SCHEDULE')) { 
  506. define('NGG_CRON_SCHEDULE', 900); 
  507.  
  508. if (!defined('NGG_CRON_ENABLED')) { 
  509. define('NGG_CRON_ENABLED', TRUE); 
  510.  
  511. // Don't enforce interfaces 
  512. if (!defined('EXTENSIBLE_OBJECT_ENFORCE_INTERFACES')) { 
  513. define('EXTENSIBLE_OBJECT_ENFORCE_INTERFACES', FALSE); 
  514.  
  515. // Fix jquery 
  516. if (!defined('NGG_FIX_JQUERY')) { 
  517. define('NGG_FIX_JQUERY', TRUE); 
  518.  
  519. // Use Pope's new caching mechanism? 
  520. if (!defined('NGG_POPE_CACHE')) { 
  521. define('NGG_POPE_CACHE', FALSE); 
  522.  
  523. /** 
  524. * Defines the NextGEN Test Suite 
  525. * @param array $suites 
  526. * @return array 
  527. */ 
  528. function add_testsuite($suites=array()) 
  529. $tests_dir = NGG_TESTS_DIR; 
  530.  
  531. if (file_exists($tests_dir)) { 
  532.  
  533. // Include mock objects 
  534. // TODO: These mock objects should be moved to the appropriate 
  535. // test folder 
  536. require_once(path_join($tests_dir, 'mocks.php')); 
  537.  
  538. // Define the NextGEN Test Suite 
  539. $suites['nextgen'] = array( 
  540. // path_join($tests_dir, 'mvc'),  
  541. path_join($tests_dir, 'datamapper'),  
  542. path_join($tests_dir, 'nextgen_data'),  
  543. path_join($tests_dir, 'gallery_display') 
  544. ); 
  545.  
  546. return $suites; 
  547.  
  548.  
  549. /** 
  550. * Returns the path to a file within the plugin root folder 
  551. * @param type $file_name 
  552. * @return type 
  553. */ 
  554. function file_path($file_name=NULL) 
  555. $path = dirname(__FILE__); 
  556.  
  557. if ($file_name != null) 
  558. $path .= '/' . $file_name; 
  559.  
  560. return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path); 
  561.  
  562.  
  563. /** 
  564. * Gets the directory path used by the plugin 
  565. * @return string 
  566. */ 
  567. function directory_path($dir=NULL) 
  568. return $this->file_path($dir); 
  569.  
  570.  
  571. /** 
  572. * Determines the location of the plugin - within a theme or plugin 
  573. * @return string 
  574. */ 
  575. function get_plugin_location() 
  576. $path = dirname(__FILE__); 
  577. $gallery_dir = strtolower($path); 
  578. $gallery_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $gallery_dir); 
  579.  
  580. $theme_dir = strtolower(get_stylesheet_directory()); 
  581. $theme_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $theme_dir); 
  582.  
  583. $plugin_dir = strtolower(WP_PLUGIN_DIR); 
  584. $plugin_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $plugin_dir); 
  585.  
  586. $common_dir_theme = substr($gallery_dir, 0, strlen($theme_dir)); 
  587. $common_dir_plugin = substr($gallery_dir, 0, strlen($plugin_dir)); 
  588.  
  589. if ($common_dir_theme == $theme_dir) 
  590. return 'theme'; 
  591.  
  592. if ($common_dir_plugin == $plugin_dir) 
  593. return 'plugin'; 
  594.  
  595. $parent_dir = dirname($path); 
  596.  
  597. if (file_exists($parent_dir . DIRECTORY_SEPARATOR . 'style.css')) 
  598. return 'theme'; 
  599.  
  600. return 'plugin'; 
  601.  
  602.  
  603. /** 
  604. * Gets the URI for a particular path 
  605. * @param string $path 
  606. * @param boolean $url_encode 
  607. * @return string 
  608. */ 
  609. function path_uri($path = null, $url_encode = false) 
  610. $location = $this->get_plugin_location(); 
  611. $uri = null; 
  612.  
  613. $path = str_replace(array('/', '\\'), '/', $path); 
  614.  
  615. if ($url_encode) 
  616. $path_list = explode('/', $path); 
  617.  
  618. foreach ($path_list as $index => $path_item) 
  619. $path_list[$index] = urlencode($path_item); 
  620.  
  621. $path = implode('/', $path_list); 
  622.  
  623. if ($location == 'theme') 
  624. $theme_uri = get_stylesheet_directory_uri(); 
  625.  
  626. $uri = $theme_uri . 'nextgen-gallery'; 
  627.  
  628. if ($path != null) 
  629. $uri .= '/' . $path; 
  630. else 
  631. // XXX Note, paths could not match but STILL being contained in the theme (i.e. WordPress returns the wrong path for the theme directory, either with wrong formatting or wrong encoding) 
  632. $base = basename(dirname(__FILE__)); 
  633.  
  634. if ($base != 'nextgen-gallery') 
  635. // XXX this is needed when using symlinks, if the user renames the plugin folder everything will break though 
  636. $base = 'nextgen-gallery'; 
  637.  
  638. if ($path != null) 
  639. $base .= '/' . $path; 
  640.  
  641. $uri = plugins_url($base); 
  642.  
  643. return $uri; 
  644.  
  645. /** 
  646. * Returns the URI for a particular file 
  647. * @param string $file_name 
  648. * @return string 
  649. */ 
  650. function file_uri($file_name = NULL) 
  651. return $this->path($file_name);