eef10b74c2ce1165a1bcfa4783a84caa1f8f9c75
[web/PetoskeyRobotics.git] /
1 <?php
2
3 /***
4  {
5         Module: photocrati-wordpress_routing,
6         Depends: { photocrati-router }
7  }
8  ***/
9 class M_WordPress_Routing extends C_Base_Module
10 {
11     static $_use_canonical_redirect = NULL;
12     static $_use_old_slugs          = NULL;
13
14     function define()
15         {
16                 parent::define(
17                         'photocrati-wordpress_routing',
18                         'WordPress Routing',
19                         "Integrates the MVC module's routing implementation with WordPress",
20                         '0.5',
21                         'http://www.nextgen-gallery.com',
22                         'Photocrati Media',
23                         'http://www.photocrati.com'
24                 );
25         }
26
27         function _register_adapters()
28         {
29                 $this->get_registry()->add_adapter('I_Router', 'A_WordPress_Router');
30         $this->get_registry()->add_adapter('I_Routing_App', 'A_WordPress_Routing_App');
31         }
32
33     function _register_hooks()
34     {
35         add_action('template_redirect', array(&$this, 'restore_request_uri'), 1);
36
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;
43         }
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;
47         }
48     }
49
50
51     /**
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
55      */
56     function restore_request_uri()
57         {
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;
61                 }
62         // this is the proper behavior but it causes problems with WPML
63         else {
64             if (self::$_use_old_slugs) wp_old_slug_redirect();
65             if (self::$_use_canonical_redirect) redirect_canonical();
66         }
67         }
68
69     function get_type_list()
70     {
71         return array(
72             'A_Wordpress_Router' => 'adapter.wordpress_router.php',
73             'A_Wordpress_Routing_App' => 'adapter.wordpress_routing_app.php'
74         );
75     }
76 }
77
78 new M_WordPress_Routing();