Polylang not working with NGGallery
-
Hello,
unfortunately, this subject has never been fixed and commented by the author within the last 6 months or more.
Polylang itself works well on the whole site except when it comes to NGGallery. The problem is that sub-galleries are shown in the main language but as soon as you try to navigate them in another language, the site redirects to the main gallery page.
Check yourself: https://www.riverside-kustomz.de/en/gallery/ (default is german)
Both plugins are always up to date.
Never worked for me since I installed version 1.5
-
Hi!
A bit of history… Once upon a time – before Photocrati bought NextGen Gallery – I decided to support NextGen Gallery.
Since Nextgen Gallery was supporting WPML, I thought that it would be quite easy. But in fact, it was a long path of several months… I had first to dive into the the NextGen Gallery code, undrstand how it worked and how it supports WPML. Then I had to rewrite the WPML API, including functions not documented by WPML but used by Nextgen Gallery. I had to “guess” what these functions did…
Finally, after several tests, I believe that I reached my goal. At the end, I was not very happy with the way it worked because using strings translations to translate albums and pictures is really not user friendly. But I believe that Nextgen gallery worked the same way with Polylang and WPML. And I couldn’t do more.
Then Photocrati released Nextgen gallery 2.0 and broke the support of WPML (and Polylang in the same time). A lot of users complained. I tried to dive again into the code of Nextgen Gallery to help fixing this but trying to understand the code was even worse than the first time…
I thus decided not to go further.
Hi!
Okay, thats understandable but should be an important info in your documents. That it doesnt and won’t support one of the most used WordPress plugins.
Which is a pity but that’s sometimes the case for free products. Too bad. Thanks for the reply.
Dang, thats sux. Okay, lets say I don’t want ngg_translation. But I at least want polylang not to break links to galleries in ngg gallery album. You can checkout the problem over here: https://www.kklietkabelis.tk/pramogos/nuotrauku-galerija/. Try to go to any gallery and it will fail… :-(, no errors or etc. I think its somekind of redirect taking action, maybe header or so on. Don’t even know where to start looking at…
Please this was 7 month ago, maybe during this months something has changed?
P.S. Always using borth latest. Always up to date so check with latest versions. qTranslate is doesn’t work with 4.2.2 WordPress, so its out of the question. ??
P.P.S. Can’t escape ngg, because of album option and possibility to display whole album. Wish there was alternative I could migrate with few clicks to from ngg which would be compatible with latest wordpress and polylang.
UPDATE:
I’ve changed permalinks to default the ugly ones, with get params. And now I can see, that it uses in all links smae page_id as I’m in now. For some reason it is not generating gallery page id. Ah but figured out that ngg is using separate url parser. Because it has no effect on WordPress permalink changes.Okay with phpstorm debuging and xdebug, I figured out, that as response to url request Initiator: which is the target link, on response I get
301 Moved Permanently and as result same page request was made from is reloaded. Still looking for where request url is parsed and gallery id is parsed from url or gallery is requested from mysql with a gallery slug.breakpointing:
\wp-content\plugins\nextgen-gallery\products\photocrati_nextgen\modules\router\package.module.router.php:978
public function get_formatted_querystring() { <breakpoint here> $retval = '/' . $this->object->get_router()->get_querystring(); $settings = $this->object->_settings; $retval = str_replace(array('&', '='), array('/', $settings->router_param_separator), $retval); return $retval; }
UPDATE:
Okay in my case I have this url https://www.kklietkabelis.tk//pramogos/nuotrauku-galerija/ this is directory to page with album shortcode. Then: galerija/lietkabelis-zalgiris is the other part of the link to specific gallery. While galerija is a slug for ngg_gallery and “lietkabelis-zalgiris”, is slug for specific gallery. And in var_dump of $retval, I can’t find “lietkabelis-zalgiris”.Seems that params are removed with javascript or some preprocessor, because I put echo $_SERVER[‘REQUEST_URI’]; to album shortcode page and doesn’t matter if I request /pramogos/nuotrauku-galerija/galerija/lietkabelis-zalgiris ir returns only /pramogos/nuotrauku-galerija/.
Found the function which causes this:
wp-content\plugins\nextgen-gallery\products\photocrati_nextgen\modules\router\package.module.router.php:206
public function get_request_uri($with_params = TRUE) { if (!empty($_SERVER['ORIG_REQUEST_URI'])) { $retval = $_SERVER['ORIG_REQUEST_URI']; } elseif (!empty($_SERVER['PATH_INFO'])) { $retval = $_SERVER['PATH_INFO']; } else { $retval = $_SERVER['REQUEST_URI']; } exit(var_dump($retval)); // Remove the querystring if (($index = strpos($retval, '?')) !== FALSE) { $retval = substr($retval, 0, $index); } // Remove the router's context $retval = preg_replace('#^' . preg_quote($this->object->context, '#') . '#', '', $retval); // Remove the params if (!$with_params) { $retval = $this->object->strip_param_segments($retval); } // Ensure that request uri starts with a slash if (strpos($retval, '/') !== 0) { $retval = "/{$retval}"; } return $retval; }
UPDATE: Sorry that wasn’t the function, was var_dumping wrong var.
Here is the function:wp-content\plugins\nextgen-gallery\products\photocrati_nextgen\modules\router\package.module.router.php:526
public function serve_request() { $served = FALSE; // ensure that the routing patterns array exists if (!is_array($this->object->_routing_patterns)) { $this->object->_routing_patterns = array(); } // if the application root matches, then we'll try to route the request if ($request_uri = $this->object->get_app_request_uri()) { // Perform URL rewrites $redirect = $this->object->do_rewrites($request_uri); // Are we to perform a redirect? if ($redirect) { $this->object->execute_route_handler($this->object->parse_route_handler($redirect)); } else { foreach ($this->object->_routing_patterns as $pattern => $handler) { if (preg_match($pattern, $this->object->get_app_request_uri(), $matches)) { $served = TRUE; // Add placeholder parameters foreach ($matches as $key => $value) { if (is_numeric($key)) { continue; } $this->object->set_parameter_value($key, $value, NULL); } // If a handler is attached to the route, execute it. A // handler can be // - FALSE, meaning don't do any post-processing to the route // - A string, such as controller#action // - An array: array( // 'controller' => 'I_Test_Controller', // 'action' => 'index', // 'context' => 'all', (optional) // 'method' => array('GET') (optional) // ) if ($handler && ($handler = $this->object->parse_route_handler($handler))) { // Is this handler for the current HTTP request method? if (isset($handler['method'])) { if (!is_array($handler['method'])) { $handler['$method'] = array($handler['method']); } if (in_array($this->object->get_router()->get_request_method(), $handler['method'])) { $this->object->execute_route_handler($handler); } } else { $this->object->execute_route_handler($handler); } } else { if (!$handler) { $this->object->passthru(); } } } } } } exit(var_dump($this->object)); return $served; }
After that _request_uri att becomes false, while before it was full requested url. Here is the var_dump:
object(C_Routing_App)[421] public '_request_uri' => boolean false public '_settings' => object(stdClass)[422] public 'router_param_separator' => string '--' (length=2) public 'router_param_slug' => string 'galerija' (length=8) public 'router_param_prefix' => string '' (length=0) public 'context' => string '/photocrati_ajax' (length=16) public 'adapted' => boolean true public '_mixins' => array (size=8) 'Mixin_Url_Manipulation' => null 'Mixin_Routing_App' => object(Mixin_Routing_App)[416] public 'object' => &object(C_Routing_App)[421] public 'method_called' => null 'A_I18N_Routing_App' => null 'A_WordPress_Routing_App' => null 'A_NextGen_Basic_Gallery_Urls' => null 'A_NextGen_Basic_ImageBrowser_Urls' => null 'A_NextGen_Basic_TagCloud_Urls' => null 'A_NextGen_Basic_Album_Urls' => null public '_mixin_priorities' => array (size=8) 0 => string 'A_NextGen_Basic_Album_Urls' (length=26) 1 => string 'A_NextGen_Basic_TagCloud_Urls' (length=29) 2 => string 'A_NextGen_Basic_ImageBrowser_Urls' (length=33) 3 => string 'A_NextGen_Basic_Gallery_Urls' (length=28) 4 => string 'A_WordPress_Routing_App' (length=23) 5 => string 'A_I18N_Routing_App' (length=18) 6 => string 'Mixin_Routing_App' (length=17) 7 => string 'Mixin_Url_Manipulation' (length=22) public '_method_map_cache' => array (size=6) 'route' => string 'Mixin_Routing_App' (length=17) '_route_to_regex' => string 'Mixin_Routing_App' (length=17) 'serve_request' => string 'Mixin_Routing_App' (length=17) 'get_app_request_uri' => string 'Mixin_Routing_App' (length=17) 'does_app_serve_request' => string 'Mixin_Routing_App' (length=17) 'get_router' => string 'Mixin_Routing_App' (length=17) public '_disabled_map' => array (size=0) empty public '_interfaces' => array (size=2) 0 => string 'I_Component' (length=11) 1 => string 'I_Routing_App' (length=13) public '_throw_error' => boolean true public '_wrapped_instance' => boolean false public 'object' => &object(C_Routing_App)[421] public '_routing_patterns' => array (size=1) '#^(/)(galerija/)?(/?([^/]+\-\-)?[^/]+\-\-[^/]+/?){0,}/?$#i' => string 'I_Ajax_Controller#index' (length=23)
Well guess parsed params are sent to polylang, which then replies if post in current language is found then it loads it if not it doesn’t. Guess its caused by this problem, as there is no language link between polylang and ngg_gallery. So how to make polylang ignore ngg_gallery, well not to precess requests to ngg_gallery.
OKay, so problem all the time was redirect to 301, because redirecte_url and requested_url do not match in
F:\xampp\htdocs\lietkabelis.tk\wp-content\plugins\polylang\frontend\frontend-links.php:after:538
If I set: $redirect_url = $requested_url; Then everything works. But I wonder why do they become not equal in the first place. :wondering:
But I wonder why do they become not equal in the first place. :wondering:
Because of a bug in Nextgen Gallery putting two slashes in the url. See:
https://www.ads-software.com/support/topic/why-hacking-_serverrequest_uriYeah in the target link I’ve posted temporary solution that skips 301 check. Because in ngg it would take another night to analyse the code and see where that double slash is generated as well maybe the fix would be wrong, unless I’d test in multiple different scenarios, which would take another nights ?? lol
- The topic ‘Polylang not working with NGGallery’ is closed to new replies.