5 Module: photocrati-wordpress_routing,
6 Depends: { photocrati-router }
9 class M_WordPress_Routing extends C_Base_Module
11 static $_use_canonical_redirect = NULL;
12 static $_use_old_slugs = NULL;
17 'photocrati-wordpress_routing',
19 "Integrates the MVC module's routing implementation with WordPress",
21 'http://www.nextgen-gallery.com',
23 'http://www.photocrati.com'
27 function _register_adapters()
29 $this->get_registry()->add_adapter('I_Router', 'A_WordPress_Router');
30 $this->get_registry()->add_adapter('I_Routing_App', 'A_WordPress_Routing_App');
33 function _register_hooks()
35 add_action('template_redirect', array(&$this, 'restore_request_uri'), 1);
37 // These two things cause conflicts in NGG. So we temporarily
38 // disable them and then reactivate them, if they were used,
39 // in the restore_request_uri() method
40 if (has_action('template_redirect', 'wp_old_slug_redirect')) {
41 remove_action( 'template_redirect', 'wp_old_slug_redirect');
42 if (!is_null(self::$_use_canonical_redirect)) self::$_use_old_slugs = TRUE;
44 if (has_action('template_redirect', 'redirect_canonical')) {
45 remove_action( 'template_redirect', 'redirect_canonical');
46 if (!is_null(self::$_use_canonical_redirect)) self::$_use_canonical_redirect = TRUE;
52 * When WordPress sees a url like http://foobar.com/nggallery/page/2/, it thinks that it is an
53 * invalid url. Therefore, we modify the request uri before WordPress parses the request, and then
54 * restore the request uri afterwards
56 function restore_request_uri()
58 if (isset($_SERVER['ORIG_REQUEST_URI'])) {
59 $request_uri = $_SERVER['ORIG_REQUEST_URI'];
60 $_SERVER['UNENCODED_URL'] = $_SERVER['HTTP_X_ORIGINAL_URL'] = $_SERVER['REQUEST_URI'] = $request_uri;
62 // this is the proper behavior but it causes problems with WPML
64 if (self::$_use_old_slugs) wp_old_slug_redirect();
65 if (self::$_use_canonical_redirect) redirect_canonical();
69 function get_type_list()
72 'A_Wordpress_Router' => 'adapter.wordpress_router.php',
73 'A_Wordpress_Routing_App' => 'adapter.wordpress_routing_app.php'
78 new M_WordPress_Routing();