5 Module: photocrati-third_party_compat,
9 class M_Third_Party_Compat extends C_Base_Module
14 'photocrati-third_party_compat',
15 'Third Party Compatibility',
16 "Adds Third party compatibility hacks, adjustments, and modifications",
18 'http://www.nextgen-gallery.com',
20 'http://www.photocrati.com'
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'
61 foreach ($changed_constants as $old => $new) {
62 if (defined($new) && !defined($old)) {
63 define($old, constant($new));
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');
73 function _register_adapters()
77 function _register_hooks()
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);
83 add_action('plugins_loaded', array(&$this, 'wpml'), PHP_INT_MAX);
84 add_action('plugins_loaded', array(&$this, 'wpml_translation_management'), PHP_INT_MAX);
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'));
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);
100 // TODO: Only needed for NGG Pro 1.0.10 and lower
101 add_action('the_post', array(&$this, 'add_ngg_pro_page_parameter'));
104 function fix_buddypress_routing()
106 M_WordPress_Routing::$_use_canonical_redirect = FALSE;
111 function fix_wpml_canonical_redirect()
113 M_WordPress_Routing::$_use_canonical_redirect = FALSE;
114 M_WordPress_Routing::$_use_old_slugs = FALSE;
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.
123 * @param $orig_scheme
127 function wpml_home_url($url, $path, $orig_scheme, $blog_id)
129 if (!class_exists('SitePress'))
134 if (empty($wp_filter['home_url'][1]))
137 foreach ($wp_filter['home_url'][1] as $id => $filter) {
138 if (!strpos($id, 'home_url'))
140 $object = $filter['function'][0];
141 if (is_object($object) && get_class($object) != 'SitePress')
143 remove_filter('home_url', array($object, 'home_url'), 1);
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
156 function ckeditor_plugins($plugins)
158 if (!class_exists('add_ckeditor_button'))
161 if (!empty($plugins['nextgen']))
162 unset($plugins['nextgen']);
167 function check_for_jquery_lightbox()
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();
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);
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%]'";
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.
194 function check_weaverii($content)
196 if (function_exists('weaverii_show_posts_shortcode'))
197 C_NextGen_Shortcode_Manager::get_instance()->activate_all();
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
209 if (!class_exists('SitePress'))
212 if (FALSE === strpos(strtolower($_SERVER['REQUEST_URI']), '/nextgen-attach_to_post'))
217 if (empty($wp_filter['init'][2]))
220 foreach ($wp_filter['init'][2] as $id => $filter) {
221 if (!strpos($id, 'js_load'))
224 $object = $filter['function'][0];
226 if (is_object($object) && get_class($object) != 'SitePress')
229 remove_action('init', array($object, 'js_load'), 2);
234 * WPML Translation Management has a similar problem to plain ol' WPML
236 function wpml_translation_management()
238 if (!class_exists('WPML_Translation_Management'))
241 if (FALSE === strpos(strtolower($_SERVER['REQUEST_URI']), '/nextgen-attach_to_post'))
246 if (empty($wp_filter['init'][10]))
249 foreach ($wp_filter['init'][10] as $id => $filter) {
250 if (!strpos($id, 'init'))
253 $object = $filter['function'][0];
255 if (is_object($object) && get_class($object) != 'WPML_Translation_Management')
258 remove_action('init', array($object, 'init'), 10);
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
268 function add_ngg_pro_page_parameter()
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];
280 * Headway themes offer gzip compression, but it causes problems with NextGEN output. Disable that feature while
286 function headway_gzip($option)
288 if (!class_exists('HeadwayOption'))
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.
301 if (!class_exists('JQueryColorboxFrontend'))
306 if (empty($wp_filter['the_content'][100]))
309 foreach ($wp_filter['the_content'][100] as $id => $filter) {
310 if (!strpos($id, 'addColorboxGroupIdToImages'))
313 $object = $filter['function'][0];
315 if (is_object($object) && get_class($object) != 'JQueryColorboxFrontend')
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);
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
333 if (!class_exists('Flattr'))
340 if (empty($wp_filter['the_content'][$level]))
343 foreach ($wp_filter['the_content'][$level] as $id => $filter) {
344 if (!strpos($id, 'injectIntoTheContent'))
347 $object = $filter['function'][0];
349 if (is_object($object) && get_class($object) != 'Flattr')
352 remove_filter('the_content', array($object, 'injectIntoTheContent'), $level);
353 add_filter('the_content', array($object, 'injectIntoTheContent'), PHP_INT_MAX);
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.
362 function bjlazyload()
364 if (!class_exists('BJLL'))
369 if (empty($wp_filter['the_content'][200]))
372 foreach ($wp_filter['the_content'][200] as $id => $filter) {
373 if (!strpos($id, 'filter'))
376 $object = $filter['function'][0];
378 if (is_object($object) && get_class($object) != 'BJLL')
381 remove_filter('the_content', array($object, 'filter'), 200);
382 add_filter('the_content', array($object, 'filter'), PHP_INT_MAX);
386 add_filter('the_content', array($this, 'bjlazyload_filter'), PHP_INT_MAX-1);
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.
394 * @param string $content
397 function bjlazyload_filter($content)
399 return trim(preg_replace("/\s\s+/", " ", $content));
402 function get_type_list()
409 new M_Third_Party_Compat();