/products/photocrati_nextgen/modules/wordpress_routing/package.module.wordpress_routing.php

  1. <?php 
  2. /** 
  3. * Class A_WordPress_Base_Url 
  4. * @mixin C_Router 
  5. * @adapts I_Router 
  6. */ 
  7. class A_WordPress_Base_Url extends Mixin 
  8. function _add_index_dot_php_to_url($url) 
  9. if (strpos($url, '/index.php') === FALSE) { 
  10. $pattern = get_option('permalink_structure'); 
  11. if (!$pattern or strpos($pattern, '/index.php') !== FALSE) { 
  12. $url = $this->object->join_paths($url, '/index.php'); 
  13. return $url; 
  14. function get_base_url($site_url = FALSE) 
  15. $retval = NULL; 
  16. $add_index_dot_php = TRUE; 
  17. if (in_array($site_url, array(TRUE, 'site'), TRUE)) { 
  18. $retval = site_url(); 
  19. } elseif (in_array($site_url, array(FALSE, 'home'), TRUE)) { 
  20. $retval = home_url(); 
  21. } elseif (in_array($site_url, array('plugins', 'plugin'), TRUE)) { 
  22. $retval = plugins_url(); 
  23. $add_index_dot_php = FALSE; 
  24. } elseif (in_array($site_url, array('plugins_mu', 'plugin_mu'), TRUE)) { 
  25. $retval = WPMU_PLUGIN_URL; 
  26. $retval = set_url_scheme($retval); 
  27. $retval = apply_filters('plugins_url', $retval, '', ''); 
  28. $add_index_dot_php = FALSE; 
  29. } elseif (in_array($site_url, array('templates', 'template', 'themes', 'theme'), TRUE)) { 
  30. $retval = get_template_directory_uri(); 
  31. $add_index_dot_php = FALSE; 
  32. } elseif (in_array($site_url, array('styles', 'style', 'stylesheets', 'stylesheet'), TRUE)) { 
  33. $retval = get_stylesheet_directory_uri(); 
  34. $add_index_dot_php = FALSE; 
  35. } elseif (in_array($site_url, array('content'), TRUE)) { 
  36. $retval = content_url(); 
  37. $add_index_dot_php = FALSE; 
  38. } elseif (in_array($site_url, array('root'), TRUE)) { 
  39. $retval = get_option('home'); 
  40. if (is_ssl()) { 
  41. $scheme = 'https'; 
  42. } else { 
  43. $scheme = parse_url($retval, PHP_URL_SCHEME); 
  44. $retval = set_url_scheme($retval, $scheme); 
  45. } elseif (in_array($site_url, array('gallery', 'galleries'), TRUE)) { 
  46. $root_type = defined('NGG_GALLERY_ROOT_TYPE') ? NGG_GALLERY_ROOT_TYPE : 'site'; 
  47. $add_index_dot_php = FALSE; 
  48. if ($root_type === 'content') { 
  49. $retval = content_url(); 
  50. } else { 
  51. $retval = site_url(); 
  52. } else { 
  53. $retval = site_url(); 
  54. if ($add_index_dot_php) { 
  55. $retval = $this->_add_index_dot_php_to_url($retval); 
  56. if ($this->object->is_https()) { 
  57. $retval = preg_replace('/^http:\\/\\//i', 'https://', $retval, 1); 
  58. return $retval; 
  59. /** 
  60. * Class A_WordPress_Router 
  61. * @mixin C_Router 
  62. * @adapts I_Router 
  63. */ 
  64. class A_WordPress_Router extends Mixin 
  65. function get_url($uri = '/', $with_qs = TRUE, $site_url = FALSE) 
  66. static $cache = array(); 
  67. $key = implode('|', array($uri, $with_qs, $site_url)); 
  68. if (isset($cache[$key])) { 
  69. return $cache[$key]; 
  70. } else { 
  71. $retval = $this->call_parent('get_url', $uri, $with_qs, $site_url); 
  72. // Determine whether the url is a directory or file on the filesystem 
  73. // If so, then we do NOT need /index.php as part of the url 
  74. $base_url = $this->object->get_base_url(); 
  75. $filename = str_replace($base_url, C_Fs::get_instance()->get_document_root(), $retval); 
  76. if ($retval && @file_exists($filename) && $retval != $base_url) { 
  77. // Remove index.php from the url 
  78. $retval = $this->object->remove_url_segment('/index.php', $retval); 
  79. // Static urls don't end with a slash 
  80. $retval = untrailingslashit($retval); 
  81. $cache[$key] = $retval; 
  82. return $retval; 
  83. /** 
  84. * Class A_WordPress_Routing_App 
  85. * @mixin C_Routing_App 
  86. * @adapts I_Routing_App 
  87. */ 
  88. class A_WordPress_Routing_App extends Mixin 
  89. function remove_parameter($key, $id = NULL, $url = FALSE) 
  90. $generated_url = $this->call_parent('remove_parameter', $key, $id, $url); 
  91. $generated_url = $this->object->add_post_permalink_to_url($generated_url); 
  92. return $generated_url; 
  93. function parse_url($url) 
  94. $parts = parse_url($url); 
  95. if (!isset($parts['path'])) { 
  96. $parts['path'] = '/'; 
  97. if (!isset($parts['query'])) { 
  98. $parts['query'] = ''; 
  99. return $parts; 
  100. /** 
  101. * Adds the post permalink to the url, if it isn't already present. 
  102. * 
  103. * The generated_url could look like: 
  104. * http://localhost/dir/nggallery/show/slideshow 
  105. * @param $generated_url 
  106. * @return mixed 
  107. */ 
  108. function add_post_permalink_to_url($generated_url) 
  109. if (!apply_filters('ngg_wprouting_add_post_permalink', TRUE)) { 
  110. return $generated_url; 
  111. $base_url = $this->object->get_router()->get_base_url('home'); 
  112. $settings = C_NextGen_Settings::get_instance(); 
  113. if (strlen($generated_url) < 2) { 
  114. $generated_url = $base_url; 
  115. $original_url = $generated_url; 
  116. $generated_parts = explode($settings->router_param_slug, $generated_url); 
  117. $generated_url = $generated_parts[0]; 
  118. $ngg_parameters = '/'; 
  119. if (isset($generated_parts[1])) { 
  120. $parts = explode('?', $generated_parts[1]); 
  121. $ngg_parameters = array_shift($parts); 
  122. $post_permalink = get_permalink(isset($_REQUEST['p']) ? $_REQUEST['p'] : 0); 
  123. if ($post_permalink == '/') { 
  124. $post_permalink = $base_url; 
  125. // Trailing slash all of the urls 
  126. $original_url = trailingslashit($original_url); 
  127. $post_permalink = trailingslashit($post_permalink); 
  128. $generated_url = trailingslashit($generated_url); 
  129. // We need to determine if the generated url and the post permalink TRULY differ. If they 
  130. // differ, then we'll return post_permalink + nggallery parameters appended. Otherwise, we'll 
  131. // just return the generated url 
  132. $generated_url = str_replace($base_url, home_url(), $generated_url); 
  133. $generated_parts = $this->parse_url($generated_url); 
  134. $post_parts = $this->parse_url($post_permalink); 
  135. $generated_parts['path'] = trailingslashit($generated_parts['path']); 
  136. if (isset($generated_parts['query'])) { 
  137. $generated_parts['query'] = untrailingslashit($generated_parts['query']); 
  138. $post_parts['path'] = trailingslashit($post_parts['path']); 
  139. if (isset($post_parts['query'])) { 
  140. $post_parts['query'] = untrailingslashit($post_parts['query']); 
  141. $generated_url = $this->object->construct_url_from_parts($generated_parts); 
  142. $post_permalink = $this->object->construct_url_from_parts($post_parts); 
  143. // No change required... 
  144. if ($generated_url == $post_permalink) { 
  145. $generated_url = $original_url; 
  146. // Ensure that the generated url has the real base url for default permalinks 
  147. if (strpos($generated_url, home_url()) !== FALSE && strpos($generated_url, $base_url) === FALSE) { 
  148. $generated_url = str_replace(home_url(), $base_url, $generated_url); 
  149. } else { 
  150. // The post permalink differs from the generated url 
  151. $post_permalink = str_replace(home_url(), $base_url, $post_permalink); 
  152. $post_parts = $this->parse_url($post_permalink); 
  153. $post_parts['path'] = $this->object->join_paths($post_parts['path'], $settings->router_param_slug, $ngg_parameters); 
  154. $post_parts['path'] = str_replace('index.php/index.php', 'index.php', $post_parts['path']); 
  155. // incase permalink_structure contains index.php 
  156. if (!empty($generated_parts['query']) && empty($post_parts['query'])) { 
  157. $post_parts['query'] = $generated_parts['query']; 
  158. $generated_url = $this->object->construct_url_from_parts($post_parts); 
  159. return $generated_url; 
  160. function join_paths() 
  161. $args = func_get_args(); 
  162. return $this->get_router()->join_paths($args); 
  163. function passthru() 
  164. $router = C_Router::get_instance(); 
  165. $_SERVER['ORIG_REQUEST_URI'] = $_SERVER['REQUEST_URI']; 
  166. $base_parts = parse_url($router->get_base_url('root')); 
  167. $new_request_uri = $router->join_paths(!empty($base_parts['path']) ? $base_parts['path'] : '', $this->object->strip_param_segments($router->get_request_uri())); 
  168. $new_request_uri = str_replace('index.php/index.php', 'index.php', $new_request_uri); 
  169. $_SERVER['UNENCODED_URL'] = $_SERVER['HTTP_X_ORIGINAL_URL'] = $_SERVER['REQUEST_URI'] = '/' . trailingslashit($new_request_uri); 
  170. if (isset($_SERVER['PATH_INFO'])) { 
  171. $_SERVER['ORIG_PATH_INFO'] = $_SERVER['PATH_INFO']; 
  172. unset($_SERVER['PATH_INFO']); 
.