bd8315e69c97657bfbe9a00b8806383b67550de0
[web/PetoskeyRobotics.git] /
1 <?php
2
3 /***
4 {
5     Module: photocrati-third_party_compat,
6     Depends: {}
7 }
8  ***/
9 class M_Third_Party_Compat extends C_Base_Module
10 {
11     function define()
12     {
13         parent::define(
14             'photocrati-third_party_compat',
15             'Third Party Compatibility',
16             "Adds Third party compatibility hacks, adjustments, and modifications",
17             '0.3',
18             'http://www.nextgen-gallery.com',
19             'Photocrati Media',
20             'http://www.photocrati.com'
21         );
22
23         // the following constants were renamed for 2.0.41; keep them declared for compatibility sake until
24         // other parties can update themselves.
25         $changed_constants = array(
26             'NEXTGEN_ADD_GALLERY_SLUG'                     => 'NGG_ADD_GALLERY_SLUG',
27             'NEXTGEN_BASIC_SINGLEPIC_MODULE_NAME'          => 'NGG_BASIC_SINGLEPIC',
28             'NEXTGEN_BASIC_TAG_CLOUD_MODULE_NAME'          => 'NGG_BASIC_TAGCLOUD',
29             'NEXTGEN_DISPLAY_PRIORITY_BASE'                => 'NGG_DISPLAY_PRIORITY_BASE',
30             'NEXTGEN_DISPLAY_PRIORITY_STEP'                => 'NGG_DISPLAY_PRIORITY_STEP',
31             'NEXTGEN_DISPLAY_SETTINGS_SLUG'                => 'NGG_DISPLAY_SETTINGS_SLUG',
32             'NEXTGEN_FS_ACCESS_SLUG'                       => 'NGG_FS_ACCESS_SLUG',
33             'NEXTGEN_GALLERY_ATTACH_TO_POST_SLUG'          => 'NGG_ATTACH_TO_POST_SLUG',
34             'NEXTGEN_GALLERY_BASIC_SLIDESHOW'              => 'NGG_BASIC_SLIDESHOW',
35             'NEXTGEN_GALLERY_BASIC_THUMBNAILS'             => 'NGG_BASIC_THUMBNAILS',
36             'NEXTGEN_GALLERY_CHANGE_OPTIONS_CAP'           => 'NGG_CHANGE_OPTIONS_CAP',
37             'NEXTGEN_GALLERY_I18N_DOMAIN'                  => 'NGG_I18N_DOMAIN',
38             'NEXTGEN_GALLERY_IMPORT_ROOT'                  => 'NGG_IMPORT_ROOT',
39             'NEXTGEN_GALLERY_MODULE_DIR'                   => 'NGG_MODULE_DIR',
40             'NEXTGEN_GALLERY_MODULE_URL'                   => 'NGG_MODULE_URL',
41             'NEXTGEN_GALLERY_NEXTGEN_BASIC_COMPACT_ALBUM'  => 'NGG_BASIC_COMPACT_ALBUM',
42             'NEXTGEN_GALLERY_NEXTGEN_BASIC_EXTENDED_ALBUM' => 'NGG_BASIC_EXTENDED_ALBUM',
43             'NEXTGEN_GALLERY_NEXTGEN_BASIC_IMAGEBROWSER'   => 'NGG_BASIC_IMAGEBROWSER',
44             'NEXTGEN_GALLERY_NGGLEGACY_MOD_DIR'            => 'NGG_LEGACY_MOD_DIR',
45             'NEXTGEN_GALLERY_NGGLEGACY_MOD_URL'            => 'NGG_LEGACY_MOD_URL',
46             'NEXTGEN_GALLERY_PLUGIN'                       => 'NGG_PLUGIN',
47             'NEXTGEN_GALLERY_PLUGIN_BASENAME'              => 'NGG_PLUGIN_BASENAME',
48             'NEXTGEN_GALLERY_PLUGIN_DIR'                   => 'NGG_PLUGIN_DIR',
49             'NEXTGEN_GALLERY_PLUGIN_STARTED_AT'            => 'NGG_PLUGIN_STARTED_AT',
50             'NEXTGEN_GALLERY_PLUGIN_URL'                   => 'NGG_PLUGIN_URL',
51             'NEXTGEN_GALLERY_PLUGIN_VERSION'               => 'NGG_PLUGIN_VERSION',
52             'NEXTGEN_GALLERY_PRODUCT_DIR'                  => 'NGG_PRODUCT_DIR',
53             'NEXTGEN_GALLERY_PRODUCT_URL'                  => 'NGG_PRODUCT_URL',
54             'NEXTGEN_GALLERY_PROTECT_IMAGE_MOD_STATIC_URL' => 'NGG_PROTUCT_IMAGE_MOD_STATIC_URL',
55             'NEXTGEN_GALLERY_PROTECT_IMAGE_MOD_URL'        => 'NGG_PROTECT_IMAGE_MOD_URL',
56             'NEXTGEN_GALLERY_TESTS_DIR'                    => 'NGG_TESTS_DIR',
57             'NEXTGEN_LIGHTBOX_ADVANCED_OPTIONS_SLUG'       => 'NGG_LIGHTBOX_ADVANCED_OPTIONS_SLUG',
58             'NEXTGEN_LIGHTBOX_OPTIONS_SLUG'                => 'NGG_LIGHTBOX_OPTIONS_SLUG',
59             'NEXTGEN_OTHER_OPTIONS_SLUG'                   => 'NGG_OTHER_OPTIONS_SLUG'
60         );
61         foreach ($changed_constants as $old => $new) {
62             if (defined($new) && !defined($old)) {
63                 define($old, constant($new));
64             }
65         }
66
67         // Resolve problems with zlib compression: https://core.trac.wordpress.org/ticket/18525
68         if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 4) {
69             @ini_set('zlib.output_compression', 'Off');
70         }
71     }
72
73     function _register_adapters()
74     {
75     }
76
77     function _register_hooks()
78     {
79         add_action('init', array(&$this, 'colorbox'),   PHP_INT_MAX);
80         add_action('init', array(&$this, 'flattr'),     PHP_INT_MAX);
81         add_action('wp',   array(&$this, 'bjlazyload'), PHP_INT_MAX);
82
83         add_action('plugins_loaded', array(&$this, 'wpml'), PHP_INT_MAX);
84         add_action('plugins_loaded', array(&$this, 'wpml_translation_management'), PHP_INT_MAX);
85
86         add_filter('home_url', array(&$this, 'wpml_home_url'), -1, 4);
87         add_filter('headway_gzip', array(&$this, 'headway_gzip'), (PHP_INT_MAX - 1));
88         add_filter('ckeditor_external_plugins', array(&$this, 'ckeditor_plugins'), 11);
89         add_filter('bp_do_redirect_canonical', array(&$this, 'fix_buddypress_routing'));
90         add_filter('the_content', array(&$this, 'check_weaverii'), -(PHP_INT_MAX-2));
91         add_action('wp', array(&$this, 'check_for_jquery_lightbox'));
92
93         // WPML fix
94         if (class_exists('SitePress')) {
95             M_WordPress_Routing::$_use_canonical_redirect = FALSE;
96             M_WordPress_Routing::$_use_old_slugs = FALSE;
97             add_action('template_redirect', array(&$this, 'fix_wpml_canonical_redirect'), 1);
98         }
99
100         // TODO: Only needed for NGG Pro 1.0.10 and lower
101         add_action('the_post', array(&$this, 'add_ngg_pro_page_parameter'));
102     }
103
104     function fix_buddypress_routing()
105     {
106         M_WordPress_Routing::$_use_canonical_redirect = FALSE;
107
108         return FALSE;
109     }
110
111     function fix_wpml_canonical_redirect()
112     {
113         M_WordPress_Routing::$_use_canonical_redirect = FALSE;
114         M_WordPress_Routing::$_use_old_slugs = FALSE;
115     }
116
117     /**
118      * WPML's home_url filter causes a conflict with NextGEN's url generation, but doesn't appear to be necessary for
119      * WPML to function. This is necessary until we properly support WP_CONTENT_URL & WP_PLUGINS_URL.
120      *
121      * @param $url
122      * @param $path
123      * @param $orig_scheme
124      * @param $blog_id
125      * @return mixed
126      */
127     function wpml_home_url($url, $path, $orig_scheme, $blog_id)
128     {
129         if (!class_exists('SitePress'))
130             return $url;
131
132         global $wp_filter;
133
134         if (empty($wp_filter['home_url'][1]))
135             return $url;
136
137         foreach ($wp_filter['home_url'][1] as $id => $filter) {
138             if (!strpos($id, 'home_url'))
139                 continue;
140             $object = $filter['function'][0];
141             if (is_object($object) && get_class($object) != 'SitePress')
142                 continue;
143             remove_filter('home_url', array($object, 'home_url'), 1);
144         }
145
146         return $url;
147     }
148
149     /**
150      * CKEditor features a custom NextGEN shortcode generator that unfortunately relies on parts of the NextGEN
151      * 1.9x API that has been deprecated in NextGEN 2.0
152      *
153      * @param $plugins
154      * @return mixed
155      */
156     function ckeditor_plugins($plugins)
157     {
158         if (!class_exists('add_ckeditor_button'))
159             return $plugins;
160
161         if (!empty($plugins['nextgen']))
162             unset($plugins['nextgen']);
163
164         return $plugins;
165     }
166
167     function check_for_jquery_lightbox()
168     {
169         // Fix for jQuery Lightbox: http://wordpress.org/plugins/wp-jquery-lightbox/
170         // jQuery Lightbox tries to modify the content of a post, but it does so before we modify
171         // the content, and therefore it's modifications have no effect on our galleries
172         if (function_exists('jqlb_autoexpand_rel_wlightbox')) {
173             $settings = C_NextGen_Settings::get_instance();
174
175             // First, we make it appear that NGG has no lightbox effect enabled. That way
176             // we don't any lightbox resources
177             unset($settings->thumbEffect);
178
179             // We would normally just let the third-party plugin do it's thing, but it's regex doesn't
180             // seem to work on our <a> tags (perhaps because they span multiple of lines or have data attributes)
181             // So instead, we just do what the third-party plugin wants - add the rel attribute
182             $settings->thumbCode="rel='lightbox[%POST_ID%]'";
183         }
184     }
185
186     /**
187      * Weaver II's 'weaver_show_posts' shortcode creates a new wp-query, causing a second round of 'the_content'
188      * filters to apply. This checks for WeaverII and enables all NextGEN shortcodes that would otherwise be left
189      * disabled by our shortcode manager. See https://core.trac.wordpress.org/ticket/17817 for more.
190      *
191      * @param $content
192      * @return $content
193      */
194     function check_weaverii($content)
195     {
196         if (function_exists('weaverii_show_posts_shortcode'))
197             C_NextGen_Shortcode_Manager::get_instance()->activate_all();
198
199         return $content;
200     }
201
202     /**
203      * WPML assigns an action to 'init' that *may* enqueue some admin-side JS. This JS relies on some inline JS
204      * to be injected that isn't present in ATP so for ATP requests ONLY we disable their action that enqueues
205      * their JS files.
206      */
207     function wpml()
208     {
209         if (!class_exists('SitePress'))
210             return;
211
212         if (FALSE === strpos(strtolower($_SERVER['REQUEST_URI']), '/nextgen-attach_to_post'))
213             return;
214
215         global $wp_filter;
216
217         if (empty($wp_filter['init'][2]))
218             return;
219
220         foreach ($wp_filter['init'][2] as $id => $filter) {
221             if (!strpos($id, 'js_load'))
222                 continue;
223
224             $object = $filter['function'][0];
225
226             if (is_object($object) && get_class($object) != 'SitePress')
227                 continue;
228
229             remove_action('init', array($object, 'js_load'), 2);
230         }
231     }
232
233     /**
234      * WPML Translation Management has a similar problem to plain ol' WPML
235      */
236     function wpml_translation_management()
237     {
238         if (!class_exists('WPML_Translation_Management'))
239             return;
240
241         if (FALSE === strpos(strtolower($_SERVER['REQUEST_URI']), '/nextgen-attach_to_post'))
242             return;
243
244         global $wp_filter;
245
246         if (empty($wp_filter['init'][10]))
247             return;
248
249         foreach ($wp_filter['init'][10] as $id => $filter) {
250             if (!strpos($id, 'init'))
251                 continue;
252
253             $object = $filter['function'][0];
254
255             if (is_object($object) && get_class($object) != 'WPML_Translation_Management')
256                 continue;
257
258             remove_action('init', array($object, 'init'), 10);
259         }
260     }
261
262     /**
263      * NGG Pro 1.0.10 relies on the 'page' parameter for pagination, but that conflicts with
264      * WordPress Post Pagination (<!-- nextpage -->). This was fixed in 1.0.11, so this code is
265      * for backwards compatibility
266      * TODO: This can be removed in a later release
267      */
268     function add_ngg_pro_page_parameter()
269     {
270         global $post;
271
272         if ($post AND (strpos($post->content, "<!--nextpage-->") === FALSE) AND (strpos($_SERVER['REQUEST_URI'], '/page/') !== FALSE)) {
273             if (preg_match("#/page/(\\d+)#", $_SERVER['REQUEST_URI'], $match)) {
274                 $_REQUEST['page'] = $match[1];
275             }
276         }
277     }
278
279     /**
280      * Headway themes offer gzip compression, but it causes problems with NextGEN output. Disable that feature while
281      * NextGEN is active.
282      *
283      * @param $option
284      * @return bool
285      */
286     function headway_gzip($option)
287     {
288         if (!class_exists('HeadwayOption'))
289             return $option;
290
291         return FALSE;
292     }
293
294     /**
295      * Colorbox fires a filter (pri=100) to add class attributes to images via a the_content filter. We fire our
296      * shortcodes at PHP_INT_MAX-1 to avoid encoding issues with some themes. Here we move the Colorbox filters
297      * priority to PHP_INT_MAX so that they run after our shortcode text has been replaced with rendered galleries.
298      */
299     function colorbox()
300     {
301         if (!class_exists('JQueryColorboxFrontend'))
302             return;
303
304         global $wp_filter;
305
306         if (empty($wp_filter['the_content'][100]))
307             return;
308
309         foreach ($wp_filter['the_content'][100] as $id => $filter) {
310             if (!strpos($id, 'addColorboxGroupIdToImages'))
311                 continue;
312
313             $object = $filter['function'][0];
314
315             if (is_object($object) && get_class($object) != 'JQueryColorboxFrontend')
316                 continue;
317
318             remove_filter('the_content', array($object, 'addColorboxGroupIdToImages'), 100);
319             remove_filter('the_excerpt', array($object, 'addColorboxGroupIdToImages'), 100);
320             add_filter('the_content', array($object, 'addColorboxGroupIdToImages'), PHP_INT_MAX);
321             add_filter('the_excerpt', array($object, 'addColorboxGroupIdToImages'), PHP_INT_MAX);
322             break;
323         }
324     }
325
326     /**
327      * Flattr fires a filter (pri=32767) on "the_content" that recurses. This causes problems,
328      * see https://core.trac.wordpress.org/ticket/17817 for more information. Moving their filter to PHP_INT_MAX
329      * is enough for us though
330      */
331     function flattr()
332     {
333         if (!class_exists('Flattr'))
334             return;
335
336         global $wp_filter;
337
338         $level = 32767;
339
340         if (empty($wp_filter['the_content'][$level]))
341             return;
342
343         foreach ($wp_filter['the_content'][$level] as $id => $filter) {
344             if (!strpos($id, 'injectIntoTheContent'))
345                 continue;
346
347             $object = $filter['function'][0];
348
349             if (is_object($object) && get_class($object) != 'Flattr')
350                 continue;
351
352             remove_filter('the_content', array($object, 'injectIntoTheContent'), $level);
353             add_filter('the_content', array($object, 'injectIntoTheContent'), PHP_INT_MAX);
354             break;
355         }
356     }
357
358     /**
359      * For the same reasons as Colorbox we move BJ-Lazy-load's filter() method to a later priority so it can access
360      * our rendered galleries.
361      */
362     function bjlazyload()
363     {
364         if (!class_exists('BJLL'))
365             return;
366
367         global $wp_filter;
368
369         if (empty($wp_filter['the_content'][200]))
370             return;
371
372         foreach ($wp_filter['the_content'][200] as $id => $filter) {
373             if (!strpos($id, 'filter'))
374                 continue;
375
376             $object = $filter['function'][0];
377
378             if (is_object($object) && get_class($object) != 'BJLL')
379                 continue;
380
381             remove_filter('the_content', array($object, 'filter'), 200);
382             add_filter('the_content', array($object, 'filter'), PHP_INT_MAX);
383             break;
384         }
385
386         add_filter('the_content', array($this, 'bjlazyload_filter'), PHP_INT_MAX-1);
387     }
388
389     /**
390      * BJ-Lazy-load's regex is lazy and doesn't handle multiline search or instances where <img is immediately followed
391      * by a newline. The following regex replaces newlines and strips unnecessary space. We fire this filter
392      * before BJ-Lazy-Load's to make our galleries compatible with its expectations.
393      *
394      * @param string $content
395      * @return string
396      */
397     function bjlazyload_filter($content)
398     {
399         return trim(preg_replace("/\s\s+/", " ", $content));
400     }
401
402     function get_type_list()
403     {
404         return array(
405         );
406     }
407 }
408
409 new M_Third_Party_Compat();