Mixin_Router

The NextGEN Gallery Mixin Router class.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/router/package.module.router.php  
  1. class Mixin_Router extends Mixin 
  2. function set_routed_app($app) 
  3. $this->object->_routed_app = $app; 
  4. function &get_routed_app() 
  5. $retval = $this->object->_routed_app ? $this->object->_routed_app : $this->object->get_default_app(); 
  6. return $retval; 
  7. function &get_default_app() 
  8. if (is_null($this->object->_default_app)) { 
  9. $this->object->_default_app = $this->object->create_app(); 
  10. $retval = $this->object->_default_app; 
  11. return $retval; 
  12. function route($patterns, $handler = FALSE) 
  13. $this->object->get_default_app()->route($patterns, $handler); 
  14. function rewrite($src, $dst, $redirect = FALSE) 
  15. $this->object->get_default_app()->rewrite($src, $dst, $redirect); 
  16. function get_parameter($key, $prefix = NULL, $default = NULL) 
  17. return $this->object->get_routed_app()->get_parameter($key, $prefix, $default); 
  18. function param($key, $prefix = NULL, $default = NULL) 
  19. return $this->object->get_parameter($key, $prefix, $default); 
  20. function has_parameter_segments() 
  21. return $this->object->get_routed_app()->has_parameter_segments(); 
  22. function passthru() 
  23. return $this->object->get_default_app()->passthru(); 
  24. /** 
  25. * Gets url for the router 
  26. * @param string $uri 
  27. * @return string 
  28. */ 
  29. function get_url($uri = '/', $with_qs = TRUE, $site_url = FALSE) 
  30. $retval = $this->object->join_paths($this->object->get_base_url($site_url), $uri); 
  31. if ($with_qs) { 
  32. $parts = parse_url($retval); 
  33. if (!isset($parts['query'])) { 
  34. $parts['query'] = $this->object->get_querystring(); 
  35. } else { 
  36. $parts['query'] = $this->object->join_querystrings($parts['query'], $this->object->get_querystring()); 
  37. $retval = $this->object->construct_url_from_parts($parts); 
  38. return str_replace("\\", "/", $retval); 
  39. /** 
  40. * Currents the relative url 
  41. * @param string $uri 
  42. * @param boolean $with_qs 
  43. * @return string 
  44. */ 
  45. function get_relative_url($uri = '/', $with_qs = TRUE) 
  46. $url = $this->object->get_url($uri, $with_qs = TRUE); 
  47. if ($url !== '/') { 
  48. $retval = str_replace($this->object->get_base_url(), '', $url); 
  49. return '/' . lrtim($retval, '/'); 
  50. /** 
  51. * Returns a static url 
  52. * @param string $path 
  53. * @param string $module 
  54. * @return string 
  55. */ 
  56. function get_static_url($path, $module = FALSE) 
  57. $fs = C_Fs::get_instance(); 
  58. $path = $fs->find_abspath($path, $module); 
  59. $base_url = $this->object->get_base_url(TRUE); 
  60. $base_url = $this->object->remove_url_segment('/index.php', $base_url); 
  61. $path = str_replace($fs->get_document_root('plugins'), $base_url, $path); 
  62. // adjust for possible windows hosts 
  63. return str_replace("\\", '/', $path); 
  64. /** 
  65. * Gets the routed url 
  66. * @returns string 
  67. */ 
  68. function get_routed_url() 
  69. $retval = $this->object->get_url($this->object->get_request_uri()); 
  70. if ($app = $this->object->get_routed_app()) { 
  71. $retval = $this->object->get_url($app->get_app_uri()); 
  72. return $retval; 
  73. /** 
  74. * Gets the base url for the router 
  75. * @param bool $site_url Unused 
  76. * @return string 
  77. */ 
  78. function get_base_url($site_url = FALSE) 
  79. $protocol = $this->object->is_https() ? 'https://' : 'http://'; 
  80. $retval = "{$protocol}{$_SERVER['SERVER_NAME']}{$this->object->context}"; 
  81. return str_replace("\\", "/", rtrim($retval, "/\\")); 
  82. /** 
  83. * Determines if the current request is over HTTPs or not 
  84. */ 
  85. function is_https() 
  86. return !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' || !empty($_SERVER['HTTP_USESSL']) && strtolower($_SERVER['HTTP_USESSL']) !== 'off' || !empty($_SERVER['REDIRECT_HTTPS']) && strtolower($_SERVER['REDIRECT_HTTPS']) !== 'off' || !empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443; 
  87. /** 
  88. * Serve request using defined Routing Apps 
  89. * @param string|FALSE $request_uri 
  90. */ 
  91. function serve_request() 
  92. $served = FALSE; 
  93. // iterate over all apps, and serve the route 
  94. foreach ($this->object->get_apps() as $app) { 
  95. if ($served = $app->serve_request($this->object->context)) { 
  96. break; 
  97. return $served; 
  98. /** 
  99. * Gets the querystring of the current request 
  100. * @return string 
  101. */ 
  102. function get_querystring() 
  103. return isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null; 
  104. function set_querystring($value) 
  105. $_SERVER['QUERY_STRING'] = $value; 
  106. /** 
  107. * Gets the request for the router 
  108. * @return string 
  109. */ 
  110. function get_request_uri($with_params = TRUE) 
  111. if (!empty($_SERVER['ORIG_REQUEST_URI'])) { 
  112. $retval = $_SERVER['ORIG_REQUEST_URI']; 
  113. } elseif (!empty($_SERVER['PATH_INFO'])) { 
  114. $retval = $_SERVER['PATH_INFO']; 
  115. } else { 
  116. $retval = $_SERVER['REQUEST_URI']; 
  117. // Remove the querystring 
  118. if (($index = strpos($retval, '?')) !== FALSE) { 
  119. $retval = substr($retval, 0, $index); 
  120. // Remove the router's context 
  121. $retval = preg_replace('#^' . preg_quote($this->object->context, '#') . '#', '', $retval); 
  122. // Remove the params 
  123. if (!$with_params) { 
  124. $retval = $this->object->strip_param_segments($retval); 
  125. // Ensure that request uri starts with a slash 
  126. if (strpos($retval, '/') !== 0) { 
  127. $retval = "/{$retval}"; 
  128. return $retval; 
  129. /** 
  130. * Gets the method of the HTTP request 
  131. * @return string 
  132. */ 
  133. function get_request_method() 
  134. return $this->object->_request_method; 
  135. function &create_app($name = '/') 
  136. $factory = C_Component_Factory::get_instance(); 
  137. $app = $factory->create('routing_app', $name); 
  138. $this->object->_apps[] = $app; 
  139. return $app; 
  140. /** 
  141. * Gets a list of apps registered for the router 
  142. * @return array 
  143. */ 
  144. function get_apps() 
  145. usort($this->object->_apps, array(&$this, '_sort_apps')); 
  146. return array_reverse($this->object->_apps); 
  147. /** 
  148. * Sorts apps.This is needed because we want the most specific app to be 
  149. * executed first 
  150. * @param C_Routed_App $a 
  151. * @param C_Routed_App $b 
  152. * @return int 
  153. */ 
  154. function _sort_apps($a, $b) 
  155. return strnatcmp($a->context, $b->context);