-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnggallery.php
More file actions
1032 lines (868 loc) · 30.3 KB
/
nggallery.php
File metadata and controls
1032 lines (868 loc) · 30.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
/**
* Plugin Name: NextGEN Gallery
* Description: The most popular gallery plugin for WordPress and one of the most popular plugins of all time with over 18 million downloads.
* Version: 2.2.12
* Author: Imagely
* Plugin URI: https://www.imagely.com/wordpress-gallery-plugin/nextgen-gallery/
* Author URI: https://www.imagely.com
* License: GPLv2
* Text Domain: nggallery
* Domain Path: /products/photocrati_nextgen/modules/i18n/lang
*/
if (!class_exists('E_Clean_Exit')) { class E_Clean_Exit extends RuntimeException {} }
if (!class_exists('E_NggErrorException')) { class E_NggErrorException extends RuntimeException {} }
// This is a temporary function to replace the use of WP's esc_url which strips spaces away from URLs
// TODO: Move this to a better place
if (!function_exists('nextgen_esc_url')) {
function nextgen_esc_url( $url, $protocols = null, $_context = 'display' ) {
$original_url = $url;
if ( '' == $url )
return $url;
$url = preg_replace('|[^a-z0-9 \\-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i', '', $url);
$strip = array('%0d', '%0a', '%0D', '%0A');
$url = _deep_replace($strip, $url);
$url = str_replace(';//', '://', $url);
/* If the URL doesn't appear to contain a scheme, we
* presume it needs http:// appended (unless a relative
* link starting with /, # or ? or a php file).
*/
if ( strpos($url, ':') === false && ! in_array( $url[0], array( '/', '#', '?' ) ) &&
! preg_match('/^[a-z0-9-]+?\.php/i', $url) )
$url = 'http://' . $url;
// Replace ampersands and single quotes only when displaying.
if ( 'display' == $_context ) {
$url = wp_kses_normalize_entities( $url );
$url = str_replace( '&', '&', $url );
$url = str_replace( "'", ''', $url );
$url = str_replace( ' ', '%20', $url );
}
if ( '/' === $url[0] ) {
$good_protocol_url = $url;
} else {
if ( ! is_array( $protocols ) )
$protocols = wp_allowed_protocols();
$good_protocol_url = wp_kses_bad_protocol( $url, $protocols );
if ( strtolower( $good_protocol_url ) != strtolower( $url ) )
return '';
}
return apply_filters('clean_url', $good_protocol_url, $original_url, $_context);
}
}
/**
* NextGEN Gallery is built on top of the Pope Framework:
* https://bitbucket.org/photocrati/pope-framework
*
* Pope constructs applications by assembling modules.
*
* The Bootstrapper. This class performs the following:
* 1) Loads the Pope Framework
* 2) Adds a path to the C_Component_Registry instance to search for products
* 3) Loads all found Products. A Product is a collection of modules with some
* additional meta data. A Product is responsible for loading any modules it
* requires.
* 4) Once all Products (and their associated modules) have been loaded (or in
* otherwords, "included"), the modules are initialized.
*/
class C_NextGEN_Bootstrap
{
var $_registry = NULL;
var $_settings_option_name = 'ngg_options';
var $_pope_loaded = FALSE;
static $debug = FALSE;
var $minimum_ngg_pro_version = '2.0.5';
var $minimum_ngg_plus_version = '1.0.1';
static function shutdown($exception=NULL)
{
if (is_null($exception)) {
throw new E_Clean_Exit;
}
elseif (!($exception instanceof E_Clean_Exit)) {
ob_end_clean();
self::print_exception($exception);
}
}
static function print_exception($exception)
{
$klass = get_class($exception);
echo "<h1>{$klass} thrown</h1>";
echo "<p>{$exception->getMessage()}</p>";
if (self::$debug OR (defined('NGG_DEBUG') AND NGG_DEBUG == TRUE)) {
echo "<h3>Where:</h3>";
echo "<p>On line <strong>{$exception->getLine()}</strong> of <strong>{$exception->getFile()}</strong></p>";
echo "<h3>Trace:</h3>";
echo "<pre>{$exception->getTraceAsString()}</pre>";
if (method_exists($exception, 'getPrevious')) {
if (($previous = $exception->getPrevious())) {
self::print_exception($previous);
}
}
}
}
static function get_backtrace($objects=FALSE, $remove_dynamic_calls=TRUE)
{
$trace = debug_backtrace($objects);
if ($remove_dynamic_calls) {
$skip_methods = array(
'_exec_cached_method',
'__call',
'get_method_property',
'set_method_property',
'call_method'
);
foreach ($trace as $key => &$value) {
if (isset($value['class']) && isset($value['function'])) {
if ($value['class'] == 'ReflectionMethod' && $value['function'] == 'invokeArgs')
unset($trace[$key]);
else if ($value['class'] == 'ExtensibleObject' && in_array($value['function'], $skip_methods))
unset($trace[$key]);
}
}
}
return $trace;
}
function __construct()
{
set_exception_handler(__CLASS__.'::shutdown');
// We only load the plugin if we're outside of the activation request, loaded in an iframe
// by WordPress. Reason being, if WP_DEBUG is enabled, and another Pope-based plugin (such as
// the photocrati theme or NextGEN Pro/Plus), then PHP will output strict warnings
if ($this->is_not_activating()) {
$this->_define_constants();
$this->_load_non_pope();
$this->_register_hooks();
$this->_load_pope();
}
}
function is_not_activating()
{
return !$this->is_activating();
}
function is_activating()
{
$retval = strpos($_SERVER['REQUEST_URI'], 'plugins.php') !== FALSE && isset($_REQUEST['action']) && in_array($_REQUEST['action'], array('activate-selected'));
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) {
$retval = TRUE;
}
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) {
$retval = TRUE;
}
return $retval;
}
function _load_non_pope()
{
// Load caching component
include_once('non_pope/class.photocrati_transient_manager.php');
if (isset($_REQUEST['ngg_flush']))
{
C_Photocrati_Transient_Manager::flush();
die("Flushed all caches");
}
if (isset($_REQUEST['ngg_flush_expired']))
{
C_Photocrati_Transient_Manager::get_instance()->flush_expired();
die("Flushed all expired caches");
}
// Load Settings Manager
include_once('non_pope/class.photocrati_settings_manager.php');
include_once('non_pope/class.nextgen_settings.php');
C_Photocrati_Global_Settings_Manager::$option_name = $this->_settings_option_name;
C_Photocrati_Settings_Manager::$option_name = $this->_settings_option_name;
// Load the installer
include_once('non_pope/class.photocrati_installer.php');
// Load the resource manager
include_once('non_pope/class.photocrati_resource_manager.php');
C_Photocrati_Resource_Manager::init();
// Load the style manager
include_once('non_pope/class.nextgen_style_manager.php');
// Load the shortcode manager
include_once('non_pope/class.nextgen_shortcode_manager.php');
C_NextGen_Shortcode_Manager::get_instance();
}
function fix_loading_order()
{
// If a plugin wasn't activated/deactivated siliently, we can listen for these things
if (did_action('activate_plugin') || did_action('deactivate_plugin')) return;
else if (strpos($_SERVER['REQUEST_URI'], 'plugins') !== FALSE) return;
else if (!$this->is_page_request()) return;
$plugins = get_option('active_plugins');
// Remove NGG from the list
$ngg = basename(dirname(__FILE__)).'/'.basename(__FILE__);
$order = array();
foreach ($plugins as $plugin) {
if ($plugin != $ngg) $order[] = $plugin;
}
// Get the position of either NGG Pro or NGG Plus
$insert_at = FALSE;
for($i=0; $i<count($order); $i++) {
$plugin = $order[$i];
if (strpos($plugin, 'nggallery-pro') !== FALSE) $insert_at = $i+1;
else if (strpos($plugin, 'ngg-plus') !== FALSE) $insert_at = $i+1;
}
// Re-insert NGG after Pro or Plus
if ($insert_at === FALSE || $insert_at === count($order)) $order[] = $ngg;
elseif ($insert_at === 0) array_unshift($order, $ngg);
else array_splice($order, $insert_at, 0, array($ngg));
if ($order != $plugins) {
$order = array_filter($order);
update_option('active_plugins', $order);
}
}
/**
* Loads the Pope Framework
*/
function _load_pope()
{
// No need to initialize pope again
if ($this->_pope_loaded) return;
// Pope requires a a higher limit
$tmp = ini_get('xdebug.max_nesting_level');
if ($tmp && (int)$tmp <= 300) @ini_set('xdebug.max_nesting_level', 300);
// Include pope framework
require_once(implode(
DIRECTORY_SEPARATOR, array(NGG_PLUGIN_DIR, 'pope','lib','autoload.php')
));
// Enable/disable pope caching. For now, the pope cache will not be used in multisite environments
if (class_exists('C_Pope_Cache')) {
if ((C_Pope_Cache::$enabled = NGG_POPE_CACHE)) {
$blogid = (is_multisite() ? get_current_blog_id() : NULL);
if (isset($_SERVER['SERVER_ADDR']))
$cache_key_prefix = abs(crc32((implode('|', array($blogid, site_url(), AUTH_KEY, $_SERVER['SERVER_ADDR'])))));
else
$cache_key_prefix = abs(crc32(implode('|', array($blogid, site_url(), AUTH_KEY))));
C_Pope_Cache::set_driver('C_Pope_Cache_SingleFile');
C_Pope_Cache::add_key_prefix($cache_key_prefix);
}
}
// Enforce interfaces
if (property_exists('ExtensibleObject', 'enforce_interfaces')) ExtensibleObject::$enforce_interfaces = EXTENSIBLE_OBJECT_ENFORCE_INTERFACES;
// Get the component registry
$this->_registry = C_Component_Registry::get_instance();
// Add the default Pope factory utility, C_Component_Factory
$this->_registry->add_utility('I_Component_Factory', 'C_Component_Factory');
// Blacklist any modules which are known NOT to work with this version of NextGEN Gallery
// We need to check if we have this ability as it's only available with Pope 0.9
if (method_exists($this->_registry, 'blacklist_module_file')) {
$this->_registry->blacklist_module_file('module.nextgen_pro_lightbox_legacy.php');
$this->_registry->blacklist_module_file('module.protect_image.php');
// TODO: Add module id for protect image
}
// If Pro is incompatible, then we need to blacklist all of Pro's modules
// TODO: Pope needs a better way of introspecting into a product's list of provided modules
if ($this->is_pro_incompatible()) {
$pro_modules = array(
'photocrati-comments',
'photocrati-galleria',
'photocrati-nextgen_pro_slideshow',
'photocrati-nextgen_pro_horizontal_filmstrip',
'photocrati-nextgen_pro_thumbnail_grid',
'photocrati-nextgen_pro_blog_gallery',
'photocrati-nextgen_pro_film',
'photocrati-nextgen_pro_masonry',
'photocrati-nextgen_pro_albums',
'photocrati-nextgen_pro_lightbox',
'photocrati-nextgen_pro_lightbox_legacy',
'photocrati-nextgen_pro_ecommerce',
'photocrati-paypal_express_checkout',
'photocrati-paypal_standard',
'photocrati-stripe'
);
foreach ($pro_modules as $mod) $this->_registry->blacklist_module_file($mod);
}
// Load embedded products. Each product is expected to load any
// modules required
$this->_registry->add_module_path(NGG_PRODUCT_DIR, 2, false);
$this->_registry->load_all_products();
// Give third-party plugins that opportunity to include their own products
// and modules
do_action('load_nextgen_gallery_modules', $this->_registry);
// Initializes all loaded modules
$this->_registry->initialize_all_modules();
$this->_pope_loaded = TRUE;
}
function is_pro_compatible()
{
$retval = TRUE;
if (defined('NEXTGEN_GALLERY_PRO_VERSION')) $retval = FALSE;
if (defined('NEXTGEN_GALLERY_PRO_PLUGIN_BASENAME') && !defined('NGG_PRO_PLUGIN_VERSION')) $retval = FALSE; // 1.0 - 1.0.6
if (defined('NGG_PRO_PLUGIN_VERSION') && version_compare(NGG_PRO_PLUGIN_VERSION, $this->minimum_ngg_pro_version) < 0) $retval = FALSE;
if (defined('NGG_PLUS_PLUGIN_VERSION') && version_compare(NGG_PLUS_PLUGIN_VERSION, $this->minimum_ngg_plus_version) < 0) $retval = FALSE;
return $retval;
}
function is_pro_incompatible()
{
return !$this->is_pro_compatible();
}
function render_incompatibility_warning()
{
echo '<div class="updated error"><p>';
echo esc_html(
sprintf(
__("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.",
'nggallery'
),
NGG_PLUGIN_VERSION, $this->minimum_ngg_pro_version
));
echo '</p></div>';
}
/**
* Registers hooks for the WordPress framework necessary for instantiating
* the plugin
*/
function _register_hooks()
{
// Register the deactivation routines
add_action('deactivate_'.NGG_PLUGIN_BASENAME, array(get_class(), 'deactivate'));
// Register our test suite
add_filter('simpletest_suites', array(&$this, 'add_testsuite'));
// Ensure that settings manager is saved as an array
add_filter('pre_update_option_'.$this->_settings_option_name, array(&$this, 'persist_settings'));
add_filter('pre_update_site_option_'.$this->_settings_option_name, array(&$this, 'persist_settings'));
// This plugin uses jQuery extensively
if (NGG_FIX_JQUERY) {
add_action('wp_enqueue_scripts', array(&$this, 'fix_jquery'));
add_action('wp_print_scripts', array(&$this, 'fix_jquery'));
}
// If the selected stylesheet is using an unsafe path, then notify the user
add_action('all_admin_notices', array(&$this, 'display_stylesheet_notice'));
// Delete displayed gallery transients periodically
if (NGG_CRON_ENABLED) {
add_filter('cron_schedules', array(&$this, 'add_ngg_schedule'));
add_action('ngg_delete_expired_transients', array($this, 'delete_expired_transients'));
add_action('wp', array(&$this, 'schedule_cron_jobs'));
}
// Update modules
add_action('init', array(&$this, 'update'), PHP_INT_MAX-2);
// Start the plugin!
add_action('init', array(&$this, 'route'), 11);
// Flush pope cache
add_action('init', array(&$this, 'flush_pope_cache'));
// NGG extension plugins should be loaded in a specific order
add_action('shutdown', array(&$this, 'fix_loading_order'));
// Display a warning if an compatible version of NextGEN Pro is installed alongside this
// version of NextGEN Gallery
if ($this->is_pro_incompatible()) {
add_filter('http_request_args', array(&$this, 'fix_autoupdate_api_requests'), 10, 2);
add_action('all_admin_notices', array(&$this, 'render_incompatibility_warning'));
}
add_filter('ngg_load_frontend_logic', array($this, 'disable_frontend_logic'), -10, 2);
}
function disable_frontend_logic($enabled, $module_id)
{
if (is_admin())
{
$settings = C_NextGen_Settings::get_instance();
if (!$settings->get('always_enable_frontend_logic'))
$enabled = FALSE;
}
return $enabled;
}
function fix_autoupdate_api_requests($args, $url)
{
// Is this an HTTP request to the licensing server?
if (preg_match("/api_act=/", $url)) {
$args['autoupdate'] = TRUE;
// If we're supposed to pass all Pro modules, then include them here
if (preg_match("/api_act=(ckups|cklic)/", $url) && isset($args['body']) && is_array($args['body']) && isset($args['body']['module-list'])) {
$pro_modules = array(
'photocrati-comments',
'photocrati-galleria',
'photocrati-nextgen_pro_slideshow',
'photocrati-nextgen_pro_horizontal_filmstrip',
'photocrati-nextgen_pro_thumbnail_grid',
'photocrati-nextgen_pro_blog_gallery',
'photocrati-nextgen_pro_film',
'photocrati-nextgen_pro_masonry',
'photocrati-nextgen_pro_albums',
'photocrati-auto_update',
'photocrati-auto_update-admin',
'photocrati-nextgen_pro_lightbox',
'photocrati-nextgen_pro_lightbox_legacy',
'photocrati-nextgen_pro_ecommerce',
'photocrati-paypal_express_checkout',
'photocrati-paypal_standard',
'photocrati-stripe'
);
foreach ($pro_modules as $mod) {
if (!isset($args['body']['module-list'][$mod])) $args['body']['module-list'][$mod] = '0.1';
}
}
}
return $args;
}
function flush_pope_cache()
{
if (is_user_logged_in() && current_user_can('manage_options') && isset($_REQUEST['ngg_flush_pope_cache'])) {
C_Pope_Cache::get_instance()->flush();
print "Flushed pope cache";
exit;
}
}
function schedule_cron_jobs()
{
if (!wp_next_scheduled('ngg_delete_expired_transients')) {
wp_schedule_event(time(), 'ngg_custom', 'ngg_delete_expired_transients');
}
}
/**
* Defines a new cron schedule
* @param $schedules
* @return mixed
*/
function add_ngg_schedule($schedules)
{
$schedules['ngg_custom'] = array(
'interval' => NGG_CRON_SCHEDULE,
'display' => sprintf(__('Every %d seconds', 'nggallery'), NGG_CRON_SCHEDULE)
);
return $schedules;
}
/**
* Flush all expires transients created by the plugin
*/
function delete_expired_transients()
{
C_Photocrati_Transient_Manager::get_instance()->flush_expired();
}
/**
* Ensure that C_Photocrati_Settings_Manager gets persisted as an array
* @param $settings
* @return array
*/
function persist_settings($settings)
{
if (is_object($settings) && $settings instanceof C_Photocrati_Settings_Manager_Base) {
$settings = $settings->to_array();
}
return $settings;
}
/**
* Ensures that the version of JQuery used is expected for NextGEN Gallery
*/
function fix_jquery()
{
global $wp_scripts;
// Determine which version of jQuery to include
$src = '/wp-includes/js/jquery/jquery.js';
// Ensure that jQuery is always set to the default
if (isset($wp_scripts->registered['jquery'])) {
$jquery = $wp_scripts->registered['jquery'];
// There's an exception to the rule. We'll allow the same
// version of jQuery as included with WP to be fetched from
// Google AJAX libraries, as we have a systematic means of verifying
// that won't cause any troubles
$version = preg_quote($jquery->ver, '#');
if (!preg_match("#ajax\\.googleapis\\.com/ajax/libs/jquery/{$version}/jquery\\.min\\.js#", $jquery->src)) {
$jquery->src = FALSE;
if (array_search('jquery-core', $jquery->deps) === FALSE) {
$jquery->deps[] = 'jquery-core';
}
if (array_search('jquery-migrate', $jquery->deps) === FALSE) {
$jquery->deps[] = 'jquery-migrate';
}
}
}
// Ensure that jquery-core is used, as WP intended
if (isset($wp_scripts->registered['jquery-core'])) {
$wp_scripts->registered['jquery-core']->src = $src;
}
wp_enqueue_script('jquery');
}
/**
* Displays a notice to the user that the current stylesheet location is unsafe
*/
function display_stylesheet_notice()
{
if (C_NextGen_Style_Manager::get_instance()->is_directory_unsafe()) {
$styles = C_NextGen_Style_Manager::get_instance();
$filename = $styles->get_selected_stylesheet();
$abspath = $styles->find_selected_stylesheet_abspath();
$newpath = $styles->new_dir;
echo "<div class='updated error'>
<h3>WARNING: NextGEN Gallery Stylesheet NOT Upgrade-safe</h3>
<p>
<strong>{$filename}</strong> is currently stored in <strong>{$abspath}</strong>, which isn't upgrade-safe. Please move the stylesheet to
<strong>{$newpath}</strong> to ensure that your customizations persist after updates.
</p></div>";
}
}
/**
* Updates all modules
*/
function update()
{
if ((!(defined('DOING_AJAX') && DOING_AJAX)) && !isset($_REQUEST['doing_wp_cron'])) {
$this->_load_pope();
// Try updating all modules
C_Photocrati_Installer::update();
}
}
/**
* Routes access points using the Pope Router
* @return boolean
*/
function route()
{
$this->_load_pope();
$router = C_Router::get_instance();
// Set context to path if subdirectory install
$parts = parse_url($router->get_base_url(FALSE));
if (isset($parts['path'])) {
$parts = explode('/index.php', $parts['path']);
$router->context = array_shift($parts);
}
// Provide a means for modules/third-parties to configure routes
do_action_ref_array('ngg_routes', array(&$router));
// Serve the routes
if (!$router->serve_request() && $router->has_parameter_segments()) {
return $router->passthru();
}
}
function is_page_request()
{
return !(defined('DOING_AJAX') && DOING_AJAX) && !(defined('DOING_CRON') && DOING_CRON) && !(defined('NGG_AJAX_SLUG') && strpos($_SERVER['REQUEST_URI'], NGG_AJAX_SLUG) !== FALSE);
}
/**
* Run the uninstaller
*/
static function deactivate()
{
include_once('products/photocrati_nextgen/class.nextgen_product_installer.php');
C_Photocrati_Installer::add_handler(NGG_PLUGIN_BASENAME, 'C_NextGen_Product_Installer');
C_Photocrati_Installer::uninstall(NGG_PLUGIN_BASENAME);
}
/**
* Defines necessary plugins for the plugin to load correctly
*/
function _define_constants()
{
define('NGG_PLUGIN', basename($this->directory_path()));
define('NGG_PLUGIN_BASENAME', plugin_basename(__FILE__));
define('NGG_PLUGIN_DIR', $this->directory_path());
define('NGG_PLUGIN_URL', $this->path_uri());
define('NGG_TESTS_DIR', implode(DIRECTORY_SEPARATOR, array(rtrim(NGG_PLUGIN_DIR, "/\\"), 'tests')));
define('NGG_PRODUCT_DIR', implode(DIRECTORY_SEPARATOR, array(rtrim(NGG_PLUGIN_DIR, "/\\"), 'products')));
define('NGG_MODULE_DIR', implode(DIRECTORY_SEPARATOR, array(rtrim(NGG_PRODUCT_DIR, "/\\"), 'photocrati_nextgen', 'modules')));
define('NGG_PRODUCT_URL', path_join(str_replace("\\", '/', NGG_PLUGIN_URL), 'products'));
define('NGG_MODULE_URL', path_join(str_replace("\\", '/', NGG_PRODUCT_URL), 'photocrati_nextgen/modules'));
define('NGG_PLUGIN_STARTED_AT', microtime());
define('NGG_PLUGIN_VERSION', '2.2.12');
if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG)
define('NGG_SCRIPT_VERSION', (string)mt_rand(0, mt_getrandmax()));
else
define('NGG_SCRIPT_VERSION', NGG_PLUGIN_VERSION);
if (!defined('NGG_HIDE_STRICT_ERRORS')) {
define('NGG_HIDE_STRICT_ERRORS', TRUE);
}
// Should we display E_STRICT errors?
if (NGG_HIDE_STRICT_ERRORS) {
$level = error_reporting();
if ($level != 0) error_reporting($level & ~E_STRICT);
}
// Should we display NGG debugging information?
if (!defined('NGG_DEBUG')) {
define('NGG_DEBUG', FALSE);
}
self::$debug = NGG_DEBUG;
// User definable constants
if (!defined('NGG_IMPORT_ROOT')) {
$path = WP_CONTENT_DIR;
if (defined('NEXTGEN_GALLERY_IMPORT_ROOT')) {
$path = NEXTGEN_GALLERY_IMPORT_ROOT;
}
define('NGG_IMPORT_ROOT', $path);
}
// Should the Photocrati cache be enabled
if (!defined('PHOTOCRATI_CACHE')) {
define('PHOTOCRATI_CACHE', TRUE);
}
if (!defined('PHOTOCRATI_CACHE_TTL')) {
define('PHOTOCRATI_CACHE_TTL', 1800);
}
// Cron job
if (!defined('NGG_CRON_SCHEDULE')) {
define('NGG_CRON_SCHEDULE', 900);
}
if (!defined('NGG_CRON_ENABLED')) {
define('NGG_CRON_ENABLED', TRUE);
}
// Don't enforce interfaces
if (!defined('EXTENSIBLE_OBJECT_ENFORCE_INTERFACES')) {
define('EXTENSIBLE_OBJECT_ENFORCE_INTERFACES', FALSE);
}
// Fix jquery
if (!defined('NGG_FIX_JQUERY')) {
define('NGG_FIX_JQUERY', TRUE);
}
// Use Pope's new caching mechanism?
if (!defined('NGG_POPE_CACHE')) {
define('NGG_POPE_CACHE', FALSE);
}
}
/**
* Defines the NextGEN Test Suite
* @param array $suites
* @return array
*/
function add_testsuite($suites=array())
{
$tests_dir = NGG_TESTS_DIR;
if (file_exists($tests_dir)) {
// Include mock objects
// TODO: These mock objects should be moved to the appropriate
// test folder
require_once(path_join($tests_dir, 'mocks.php'));
// Define the NextGEN Test Suite
$suites['nextgen'] = array(
// path_join($tests_dir, 'mvc'),
path_join($tests_dir, 'datamapper'),
path_join($tests_dir, 'nextgen_data'),
path_join($tests_dir, 'gallery_display')
);
}
return $suites;
}
/**
* Returns the path to a file within the plugin root folder
* @param type $file_name
* @return type
*/
function file_path($file_name=NULL)
{
$path = dirname(__FILE__);
if ($file_name != null)
{
$path .= '/' . $file_name;
}
return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
}
/**
* Gets the directory path used by the plugin
* @return string
*/
function directory_path($dir=NULL)
{
return $this->file_path($dir);
}
/**
* Determines the location of the plugin - within a theme or plugin
* @return string
*/
function get_plugin_location()
{
$path = dirname(__FILE__);
$gallery_dir = strtolower($path);
$gallery_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $gallery_dir);
$theme_dir = strtolower(get_stylesheet_directory());
$theme_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $theme_dir);
$plugin_dir = strtolower(WP_PLUGIN_DIR);
$plugin_dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $plugin_dir);
$common_dir_theme = substr($gallery_dir, 0, strlen($theme_dir));
$common_dir_plugin = substr($gallery_dir, 0, strlen($plugin_dir));
if ($common_dir_theme == $theme_dir)
{
return 'theme';
}
if ($common_dir_plugin == $plugin_dir)
{
return 'plugin';
}
$parent_dir = dirname($path);
if (file_exists($parent_dir . DIRECTORY_SEPARATOR . 'style.css'))
{
return 'theme';
}
return 'plugin';
}
/**
* Gets the URI for a particular path
* @param string $path
* @param boolean $url_encode
* @return string
*/
function path_uri($path = null, $url_encode = false)
{
$location = $this->get_plugin_location();
$uri = null;
$path = str_replace(array('/', '\\'), '/', $path);
if ($url_encode)
{
$path_list = explode('/', $path);
foreach ($path_list as $index => $path_item)
{
$path_list[$index] = urlencode($path_item);
}
$path = implode('/', $path_list);
}
if ($location == 'theme')
{
$theme_uri = get_stylesheet_directory_uri();
$uri = $theme_uri . 'nextgen-gallery';
if ($path != null)
{
$uri .= '/' . $path;
}
}
else
{
// 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)
$base = basename(dirname(__FILE__));
if ($base != 'nextgen-gallery')
{
// XXX this is needed when using symlinks, if the user renames the plugin folder everything will break though
$base = 'nextgen-gallery';
}
if ($path != null)
{
$base .= '/' . $path;
}
$uri = plugins_url($base);
}
return $uri;
}
/**
* Returns the URI for a particular file
* @param string $file_name
* @return string
*/
function file_uri($file_name = NULL)
{
return $this->path($file_name);
}
}
#region Freemius
/**
* Customize the opt-in message.
*
* @author Vova Feldman (@svovaf)
* @since 2.1.32
*
* @param string $message
* @param string $user_first_name
* @param string $plugin_title
* @param string $user_login
* @param string $site_link
* @param string $freemius_link
*
* @return string
*/
function ngg_fs_custom_connect_message(
$message,
$user_first_name,
$plugin_title,
$user_login,
$site_link,
$freemius_link
) {
return sprintf(
__fs( 'hey-x' ) . '<br>' .
__( 'Allow %6$s to collect some usage data with %5$s to make the plugin even more awesome. If you skip this, that\'s okay! %2$s will still work just fine.', 'nggallery' ),
$user_first_name,
'<b>' . __('NextGEN Gallery', 'nggallery') . '</b>',
'<b>' . $user_login . '</b>',
$site_link,
$freemius_link,
'<b>' . __('Imagely', 'nggallery') . '</b>'
);
}
/**
* Uninstall cleanup script.
*/
function ngg_fs_uninstall() {
// Your cleanup script.
}
/**
* Send custom event about 1st gallery creation.
*
* @author Vova Feldman (@svovaf)
*/
function fs_track_new_gallery() {
global $ngg_fs;
$galleries = C_Gallery_Mapper::get_instance()->count();
if (1 == $galleries) {
// Only track event on 1st gallery creation.
$ngg_fs->track_event_once( 'new_gallery' );
}
}
/**
* Create a helper function for easy SDK access.
*
* @author Vova Feldman (@svovaf)
* @since 2.1.32
*
* @param bool $activate_for_all If true, activate Freemius for all users. Was added for testing.
*
* @return \Freemius
*/
function ngg_fs( $activate_for_all = false ) {
global $ngg_fs;
if ( ! $activate_for_all ) {
$ngg_options = get_option( 'ngg_options' );
$ngg_run_freemius = get_option( 'ngg_run_freemius', null );
if ( false === $ngg_options ) {
// New plugin installation.
if ( defined( 'WP_FS__DEV_MODE' ) && WP_FS__DEV_MODE ) {
// Always run Freemius in development mode for new plugin installs.
$run_freemius = true;
} else {
// Run Freemius code on 20% of the new installations.
// $random = rand( 1, 10 );
// $run_freemius = ( 1 <= $random && $random <= 2 );
// Update 2016-08: run on all new instances
$run_freemius = TRUE;
}
update_option( 'ngg_run_freemius', $run_freemius );
// Compare both bool or string 0/1 because get_option() may give us either
} else if ( ( is_bool( $ngg_run_freemius ) && $ngg_run_freemius ) || '1' === $ngg_run_freemius ) {
// If runFreemius was set, use the value.
$run_freemius = $ngg_run_freemius;
} else {
// Don't run Freemius for plugin updates.
$run_freemius = false;
if (is_null($ngg_run_freemius))
update_option('ngg_run_freemius', FALSE);
}
if ( ! $run_freemius ) {
return false;
}
}
if ( ! isset( $ngg_fs ) ) {
// Include Freemius SDK.
require_once dirname( __FILE__ ) . '/freemius/start.php';
$ngg_fs = fs_dynamic_init( array(
'id' => '266',
'slug' => 'nextgen-gallery',
'public_key' => 'pk_009356711cd548837f074e1ef60a4',
'is_premium' => false,
'has_addons' => false,
'has_paid_plans' => false,
'menu' => array(
'slug' => 'nextgen-gallery',
'account' => false,
'contact' => false,