Mixin_Routing_App

The NextGEN Gallery Mixin Routing App class.

Defined (1)

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

/products/photocrati_nextgen/modules/router/package.module.router.php  
  1. class Mixin_Routing_App extends Mixin 
  2. /** 
  3. * Creates a new route endpoint with the assigned handler 
  4. * @param array $routes URL to route, eg /page/{page}/ 
  5. * @param array $handler Formatted array 
  6. */ 
  7. function route($routes, $handler) 
  8. // ensure that the routing patterns array exists 
  9. if (!is_array($this->object->_routing_patterns)) { 
  10. $this->object->_routing_patterns = array(); 
  11. if (!is_array($routes)) { 
  12. $routes = array($routes); 
  13. // fetch all routing patterns 
  14. $patterns = $this->object->_routing_patterns; 
  15. foreach ($routes as $route) { 
  16. // add the routing pattern 
  17. $patterns[$this->object->_route_to_regex($route)] = $handler; 
  18. // update routing patterns 
  19. $this->object->_routing_patterns = $patterns; 
  20. /** 
  21. * Handles internal url rewriting with optional HTTP redirection,  
  22. * @param string $src Original URL 
  23. * @param string $dst Destination URL 
  24. * @param bool $redirect FALSE for internal handling, otherwise the HTTP code to send 
  25. */ 
  26. function rewrite($src, $dst, $redirect = FALSE, $stop = FALSE) 
  27. // ensure that rewrite patterns array exists 
  28. if (!is_array($this->object->_rewrite_patterns)) { 
  29. $this->object->_rewrite_patterns = array(); 
  30. // fetch all rewrite patterns 
  31. $patterns = $this->object->_rewrite_patterns; 
  32. // Assign rewrite definition 
  33. $definition = array('dst' => $dst, 'redirect' => $redirect, 'stop' => $stop); 
  34. // We treat wildcards much differently than normal rewrites 
  35. if (preg_match("/\\{[\\.\\\\*]/", $src)) { 
  36. $pattern = str_replace('{*}', '(.*?)', $src); 
  37. $pattern = str_replace('{.*}', '(.*?)', $pattern); 
  38. $pattern = str_replace('{\\w}', '([^/]*)', $pattern); 
  39. $pattern = str_replace('{\\d}', '(\\d*)', $pattern); 
  40. $src = '#' . (strpos($src, '/') === 0 ? '^' : '') . $pattern . '/?$#'; 
  41. $definition['wildcards'] = TRUE; 
  42. } else { 
  43. $src = $this->object->_route_to_regex($src); 
  44. // add the rewrite pattern 
  45. $patterns[$src] = $definition; 
  46. // update rewrite patterns; 
  47. $this->object->_rewrite_patterns = $patterns; 
  48. /** 
  49. * Gets an instance of the router 
  50. * @return type 
  51. */ 
  52. function get_router() 
  53. return C_Router::get_instance(); 
  54. function get_app_url($request_uri = FALSE, $with_qs = FALSE) 
  55. return $this->object->get_router()->get_url($this->object->get_app_uri($request_uri), $with_qs); 
  56. function get_routed_url($with_qs = TRUE) 
  57. return $this->object->get_app_url(FALSE, $with_qs); 
  58. function get_app_uri($request_uri = FALSE) 
  59. if (!$request_uri) { 
  60. $request_uri = $this->object->get_app_request_uri(); 
  61. return $this->object->join_paths($this->object->context, $request_uri); 
  62. function get_app_request_uri() 
  63. $retval = FALSE; 
  64. if ($this->object->_request_uri) { 
  65. $retval = $this->object->_request_uri; 
  66. } else { 
  67. if ($retval = $this->object->does_app_serve_request()) { 
  68. if (strpos($retval, '/') !== 0) { 
  69. $retval = '/' . $retval; 
  70. $this->object->set_app_request_uri($retval); 
  71. return $retval; 
  72. /** 
  73. * Sets the application request uri 
  74. * @param type $uri 
  75. */ 
  76. function set_app_request_uri($uri) 
  77. $this->object->_request_uri = $uri; 
  78. /** 
  79. * Gets the application's routing regex pattern 
  80. * @return string 
  81. */ 
  82. function get_app_routing_pattern() 
  83. return $this->object->_route_to_regex($this->object->context); 
  84. /** 
  85. * Determines whether this app serves the request 
  86. * @return boolean|string 
  87. */ 
  88. function does_app_serve_request() 
  89. $retval = FALSE; 
  90. $request_uri = $this->object->get_router()->get_request_uri(TRUE); 
  91. // Is the context present in the uri? 
  92. if (($index = strpos($request_uri, $this->object->context)) !== FALSE) { 
  93. $starts_with_slash = strpos($this->object->context, '/') === 0; 
  94. if ($starts_with_slash && $index === 0 or !$starts_with_slash) { 
  95. $regex = implode('', array('#', $starts_with_slash ? '^' : '', preg_quote($this->object->context, '#'), '#')); 
  96. $retval = preg_replace($regex, '', $request_uri); 
  97. if (!$retval) { 
  98. $retval = '/'; 
  99. if (strpos($retval, '/') !== 0) { 
  100. $retval = '/' . $retval; 
  101. if (substr($retval, -1) != '/') { 
  102. $retval = $retval . '/'; 
  103. return $retval; 
  104. /** 
  105. * Performs the url rewriting routines. Returns the HTTP status code used to 
  106. * redirect, if we're to do so. Otherwise FALSE 
  107. * @return int|bool 
  108. */ 
  109. function do_rewrites($request_uri = FALSE) 
  110. $redirect = FALSE; 
  111. static $stop_processing = FALSE; 
  112. // Get the request uri if not provided, if provided decode it 
  113. if (!$request_uri) { 
  114. $request_uri = $this->object->get_app_request_uri(); 
  115. } else { 
  116. $request_uri = urldecode($request_uri); 
  117. // ensure that rewrite patterns array exists 
  118. if (!is_array($this->object->_rewrite_patterns)) { 
  119. $this->object->_rewrite_patterns = array(); 
  120. // Process each rewrite rule 
  121. // start rewriting urls 
  122. if (!$stop_processing) { 
  123. foreach ($this->object->_rewrite_patterns as $pattern => $details) { 
  124. // Remove this pattern from future processing for this request 
  125. unset($this->object->_rewrite_patterns[$pattern]); 
  126. // Wildcards are processed much differently 
  127. if (isset($details['wildcards']) && $details['wildcards']) { 
  128. if (preg_match($pattern, $request_uri, $matches)) { 
  129. foreach ($matches as $index => $match) { 
  130. if ($index == 0) { 
  131. $request_uri = str_replace($match, $details['dst'], $request_uri); 
  132. if ($index > 0) { 
  133. $request_uri = str_replace("{{$index}}", $match, $request_uri); 
  134. // Set the redirect flag if we're to do so 
  135. if (isset($details['redirect']) && $details['redirect']) { 
  136. $redirect = $details['redirect'] === TRUE ? 302 : intval($details['redirect']); 
  137. break; 
  138. // Stop processing rewrite patterns? 
  139. if ($details['stop']) { 
  140. $stop_processing = TRUE; 
  141. } elseif (preg_match_all($pattern, $request_uri, $matches, PREG_SET_ORDER)) { 
  142. // Assign new request URI 
  143. $request_uri = $details['dst']; 
  144. // Substitute placeholders 
  145. foreach ($matches as $match) { 
  146. if ($redirect) { 
  147. break; 
  148. foreach ($match as $key => $val) { 
  149. // If we have a placeholder that needs swapped, swap 
  150. // it now 
  151. if (is_numeric($key)) { 
  152. continue; 
  153. $request_uri = str_replace("{{$key}}", $val, $request_uri); 
  154. // Set the redirect flag if we're to do so 
  155. if (isset($details['redirect']) && $details['redirect']) { 
  156. $redirect = $details['redirect'] === TRUE ? 302 : intval($details['redirect']); 
  157. break; 
  158. if ($stop_processing) { 
  159. break; 
  160. // Cache all known data about the application request 
  161. $this->object->set_app_request_uri($request_uri); 
  162. $this->object->get_router()->set_routed_app($this->object); 
  163. return $redirect; 
  164. /** 
  165. * Determines if the current routing app meets our requirements and serves them 
  166. * @return bool 
  167. */ 
  168. function serve_request() 
  169. $served = FALSE; 
  170. // ensure that the routing patterns array exists 
  171. if (!is_array($this->object->_routing_patterns)) { 
  172. $this->object->_routing_patterns = array(); 
  173. // if the application root matches, then we'll try to route the request 
  174. if ($request_uri = $this->object->get_app_request_uri()) { 
  175. // Perform URL rewrites 
  176. $redirect = $this->object->do_rewrites($request_uri); 
  177. // Are we to perform a redirect? 
  178. if ($redirect) { 
  179. $this->object->execute_route_handler($this->object->parse_route_handler($redirect)); 
  180. } else { 
  181. foreach ($this->object->_routing_patterns as $pattern => $handler) { 
  182. if (preg_match($pattern, $this->object->get_app_request_uri(), $matches)) { 
  183. $served = TRUE; 
  184. // Add placeholder parameters 
  185. foreach ($matches as $key => $value) { 
  186. if (is_numeric($key)) { 
  187. continue; 
  188. $this->object->set_parameter_value($key, $value, NULL); 
  189. // If a handler is attached to the route, execute it. A 
  190. // handler can be 
  191. // - FALSE, meaning don't do any post-processing to the route 
  192. // - A string, such as controller#action 
  193. // - An array: array( 
  194. // 'controller' => 'I_Test_Controller',  
  195. // 'action' => 'index',  
  196. // 'context' => 'all', (optional) 
  197. // 'method' => array('GET') (optional) 
  198. // ) 
  199. if ($handler && ($handler = $this->object->parse_route_handler($handler))) { 
  200. // Is this handler for the current HTTP request method? 
  201. if (isset($handler['method'])) { 
  202. if (!is_array($handler['method'])) { 
  203. $handler['$method'] = array($handler['method']); 
  204. if (in_array($this->object->get_router()->get_request_method(), $handler['method'])) { 
  205. $this->object->execute_route_handler($handler); 
  206. } else { 
  207. $this->object->execute_route_handler($handler); 
  208. } else { 
  209. if (!$handler) { 
  210. $this->object->passthru(); 
  211. return $served; 
  212. /** 
  213. * Executes an action of a particular controller 
  214. * @param array $handler 
  215. */ 
  216. function execute_route_handler($handler) 
  217. // Get action 
  218. $action = $handler['action']; 
  219. // Get controller 
  220. $controller = $this->object->get_registry()->get_utility($handler['controller'], $handler['context']); 
  221. // Call action 
  222. $controller->{$action}(); 
  223. // Clean Exit (fastcgi safe) 
  224. C_NextGEN_Bootstrap::shutdown(); 
  225. /** 
  226. * Parses the route handler 
  227. * @param mixed $handler 
  228. * @return array 
  229. */ 
  230. function parse_route_handler($handler) 
  231. if (is_string($handler)) { 
  232. $handler = array_combine(array('controller', 'action'), explode('#', $handler)); 
  233. } elseif (is_numeric($handler)) { 
  234. $handler = array('controller' => 'I_Http_Response', 'action' => 'http_' . $handler); 
  235. if (!isset($handler['context'])) { 
  236. $handler['context'] = FALSE; 
  237. if (strpos($handler['action'], '_action') === FALSE) { 
  238. $handler['action'] .= '_action'; 
  239. return $handler; 
  240. function add_placeholder_params_from_matches($matches) 
  241. // Add the placeholder parameter values to the _params array 
  242. foreach ($matches as $key => $value) { 
  243. if (is_numeric($key)) { 
  244. continue; 
  245. $this->object->add_placeholder_param($key, $value, $matches[0]); 
  246. /** 
  247. * Used to pass execution to PHP and perhaps an above framework 
  248. */ 
  249. function passthru() 
  250. /** 
  251. * Adds a placeholder parameter 
  252. * @param string $name 
  253. * @param stirng $value 
  254. * @param string $source 
  255. */ 
  256. function add_placeholder_param($name, $value, $source = NULL) 
  257. if (!is_array($this->object->_parameters)) { 
  258. $this->object->_parameters = array('global'); 
  259. if (!isset($this->object->_parameters['global'])) { 
  260. $this->object->_parameters['global'] = array(); 
  261. $this->object->_parameters['global'][] = array('id' => '', 'name' => $name, 'value' => $value, 'source' => $source); 
  262. /** 
  263. * Converts the route to the regex 
  264. * @param string $route 
  265. * @return string 
  266. */ 
  267. function _route_to_regex($route) 
  268. // Get the settings manager 
  269. $settings = $this->object->_settings; 
  270. $param_slug = $settings->router_param_slug; 
  271. // convert route to RegEx pattern 
  272. $route_regex = preg_quote(str_replace(array('{', '}'), array('~', '~'), $route), '#'); 
  273. // Wrap the route 
  274. $route_regex = '(' . $route_regex . ')'; 
  275. // If the route starts with a slash, then it must appear at the beginning 
  276. // of a request uri 
  277. if (strpos($route, '/') === 0) { 
  278. $route_regex = '^' . $route_regex; 
  279. // If the route is not /, and perhaps /foo, then we need to optionally 
  280. // look for a trailing slash as well 
  281. if ($route != '/') { 
  282. $route_regex .= '/?'; 
  283. // If parameters come after a slug, it might appear as well 
  284. if ($param_slug) { 
  285. $route_regex .= "(" . preg_quote($param_slug, '#') . '/)?'; 
  286. // Parameter might follow the request uri 
  287. $route_regex .= "(/?([^/]+\\-\\-)?[^/]+\\-\\-[^/]+/?) {0, }"; 
  288. // Create the regex 
  289. $route_regex = '#' . $route_regex . '/?$#i'; 
  290. // convert placeholders to regex as well 
  291. return preg_replace('/~([^~]+)~/i', ($param_slug ? '(' . preg_quote($param_slug, '#') . '\\K)?' : '') . '(?P<\\1>[^/]+)/?', $route_regex); 
  292. /** 
  293. * Gets a request parameter from either the request uri or querystring 
  294. * This method takes into consideration the values of the router_param_prefix 
  295. * and router_param_separator settings when searching for the parameter 
  296. * Parameter can take on the following forms: 
  297. * /key--value 
  298. * /[MVC_PARAM_PREFIX]key--value 
  299. * /[MVC_PARAM_PREFIX]-key--value 
  300. * /[MVC_PARAM_PREFIX]_key--value 
  301. * /id--key--value 
  302. * /id--[MVC_PARAM_PREFIX]key--value 
  303. * /id--[MVC_PARAM_PREFIX]-key--value 
  304. * /id--[MVC_PARAM_PREFIX]_key--value 
  305. * @param string $key 
  306. * @param mixed $id 
  307. * @param mixed $default 
  308. * @return mixed 
  309. */ 
  310. function get_parameter($key, $id = NULL, $default = NULL, $segment = FALSE, $url = FALSE) 
  311. $retval = $default; 
  312. $settings = $this->object->_settings; 
  313. $quoted_key = preg_quote($key, '#'); 
  314. $id = $id ? preg_quote($id, '#') : "[^/]+"; 
  315. $param_prefix = preg_quote($settings->router_param_prefix, '#'); 
  316. $param_sep = preg_quote($settings->router_param_separator, '#'); 
  317. $param_regex = "#/((?P<id>{$id}) {$param_sep})?({$param_prefix}[-_]?)?{$quoted_key}{$param_sep}(?P<value>[^/\\?]+)/?#i"; 
  318. $found = FALSE; 
  319. $sources = $url ? array('custom' => $url) : $this->object->get_parameter_sources(); 
  320. foreach ($sources as $source_name => $source) { 
  321. if (preg_match($param_regex, $source, $matches)) { 
  322. if ($segment) { 
  323. $retval = array('segment' => $matches[0], 'source' => $source_name); 
  324. } else { 
  325. $retval = $this->object->recursive_stripslashes($matches['value']); 
  326. $found = TRUE; 
  327. break; 
  328. // Lastly, check the $_REQUEST 
  329. if (!$found && !$url && isset($_REQUEST[$key])) { 
  330. $found = TRUE; 
  331. $retval = $this->object->recursive_stripslashes($_REQUEST[$key]); 
  332. if (!$found && isset($_SERVER['REQUEST_URI'])) { 
  333. $params = array(); 
  334. parse_str(@parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY), $params); 
  335. if (isset($params[$key])) { 
  336. $found = TRUE; 
  337. $retval = $this->object->recursive_stripslashes($params[$key]); 
  338. return $retval; 
  339. /** 
  340. * Checks and cleans a URL. This function is from WordPress. 
  341. * A number of characters are removed from the URL. If the URL is for displaying 
  342. * (the default behaviour) ampersands are also replaced. The 'clean_url' filter 
  343. * is applied to the returned cleaned URL. 
  344. * @since 2.8.0 
  345. * @uses wp_kses_bad_protocol() To only permit protocols in the URL set 
  346. * via $protocols or the common ones set in the function. 
  347. * @param string $url The URL to be cleaned. 
  348. * @param array $protocols Optional. An array of acceptable protocols. 
  349. * Defaults to 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'svn' if not set. 
  350. * @param string $_context Private. Use esc_url_raw() for database usage. 
  351. * @return string The cleaned $url after the 'clean_url' filter is applied. 
  352. */ 
  353. function esc_url($url, $protocols = null, $_context = 'display') 
  354. $original_url = $url; 
  355. $url = preg_replace('|[^a-z0-9-~+_.?#=!&;, /:%@$\\|*\'()\\x80-\\xff]|i', '', $url); 
  356. $strip = array('%0d', '%0a', '%0D', '%0A'); 
  357. $url = _deep_replace($strip, $url); 
  358. $url = str_replace(';//', '://', $url); 
  359. // Replace ampersands and single quotes only when displaying. 
  360. if ('display' == $_context) { 
  361. $url = wp_kses_normalize_entities($url); 
  362. $url = str_replace('&', '&', $url); 
  363. $url = str_replace("'", ''', $url); 
  364. if (!empty($url[0]) && '/' === $url[0]) { 
  365. $good_protocol_url = $url; 
  366. } else { 
  367. if (!is_array($protocols)) { 
  368. $protocols = wp_allowed_protocols(); 
  369. $good_protocol_url = wp_kses_bad_protocol($url, $protocols); 
  370. if (strtolower($good_protocol_url) != strtolower($url)) { 
  371. return ''; 
  372. /** 
  373. * Filter a string cleaned and escaped for output as a URL. 
  374. * @since 2.3.0 
  375. * @param string $good_protocol_url The cleaned URL to be returned. 
  376. * @param string $original_url The URL prior to cleaning. 
  377. * @param string $_context If 'display', replace ampersands and single quotes only. 
  378. */ 
  379. return apply_filters('clean_url', $good_protocol_url, $original_url, $_context); 
  380. /** 
  381. * Sets the value of a particular parameter 
  382. * @param string $key 
  383. * @param mixed $value 
  384. * @param mixed $id 
  385. */ 
  386. function set_parameter_value($key, $value, $id = NULL, $use_prefix = FALSE, $url = FALSE) 
  387. // Remove the parameter from both the querystring and request uri 
  388. $retval = $this->object->remove_parameter($key, $id, $url); 
  389. // Get the settings manager 
  390. $settings = $this->object->_settings; 
  391. $param_slug = $settings->router_param_slug; 
  392. // We're modifying a url passed in 
  393. if ($url) { 
  394. $parts = parse_url($retval); 
  395. if (!isset($parts['path'])) { 
  396. $parts['path'] = ''; 
  397. $parts['path'] = $this->object->join_paths($parts['path'], $param_slug && strpos($parts['path'], $param_slug) === FALSE ? $param_slug : '', $this->object->create_parameter_segment($key, $value, $id, $use_prefix)); 
  398. $parts['path'] = str_replace('//', '/', $parts['path']); 
  399. $retval = $this->object->construct_url_from_parts($parts); 
  400. } else { 
  401. // This parameter is being appended to the current request uri 
  402. $this->object->add_parameter_to_app_request_uri($key, $value, $id, $use_prefix); 
  403. // Return the new full url 
  404. $retval = $this->object->get_routed_url(); 
  405. return (is_null($retval) or is_numeric($retval) or is_array($retval)) ? $retval : $this->esc_url($retval); 
  406. /** 
  407. * Alias for remove_parameter() 
  408. * @param string $key 
  409. * @param mixed $id 
  410. * @return string 
  411. */ 
  412. function remove_param($key, $id = NULL, $url = FALSE) 
  413. return $this->object->remove_parameter($key, $id, $url); 
  414. /** 
  415. * Removes a parameter from the querystring and application request URI 
  416. * and returns the full application URL 
  417. * @param string $key 
  418. * @param mixed $id 
  419. * @return string 
  420. */ 
  421. function remove_parameter($key, $id = NULL, $url = FALSE) 
  422. $retval = $url; 
  423. $settings = $this->object->_settings; 
  424. $param_sep = $settings->router_param_separator; 
  425. $param_prefix = $settings->router_param_prefix ? preg_quote($settings->router_param_prefix, '#') : ''; 
  426. $param_slug = $settings->router_param_slug ? preg_quote($settings->router_param_slug, '#') : FALSE; 
  427. // Is the parameter already part of the request? If so, modify that 
  428. // parameter 
  429. if (($segment = $this->object->get_parameter_segment($key, $id, $url)) && is_array($segment)) { 
  430. extract($segment); 
  431. if ($source == 'querystring') { 
  432. $preg_id = $id ? '\\d+' : preg_quote($id, '#'); 
  433. $preg_key = preg_quote($key, '#'); 
  434. $regex = implode('', array('#', $id ? "{$preg_id}{$param_sep}" : '', "(({$param_prefix}{$param_sep})?)?{$preg_key}({$param_sep}|=)[^\\/&]+&?#i")); 
  435. $qs = preg_replace($regex, '', $this->get_router()->get_querystring()); 
  436. $this->object->get_router()->set_querystring($qs); 
  437. $retval = $this->object->get_routed_url(); 
  438. } elseif ($source == 'request_uri') { 
  439. $uri = $this->object->get_app_request_uri(); 
  440. $uri = $this->object->join_paths(explode($segment, $uri)); 
  441. if ($settings->router_param_slug && preg_match("#{$param_slug}/?\$#i", $uri, $match)) { 
  442. $retval = $this->object->remove_url_segment($match[0], $retval); 
  443. $this->object->set_app_request_uri($uri); 
  444. $retval = $this->object->get_routed_url(); 
  445. } else { 
  446. $retval = $this->object->join_paths(explode($segment, $url)); 
  447. if ($settings->router_param_slug && preg_match("#/{$param_slug}\$#i", $retval, $match)) { 
  448. $retval = $this->object->remove_url_segment($match[0], $retval); 
  449. if (is_string($retval)) { 
  450. $retval = rtrim($retval, ' ?&'); 
  451. return (is_null($retval) or is_numeric($retval) or is_array($retval)) ? $retval : $this->esc_url($retval); 
  452. /** 
  453. * Adds a parameter to the application's request URI 
  454. * @param string $key 
  455. * @param mixed $value 
  456. * @param mixed $id 
  457. */ 
  458. function add_parameter_to_app_request_uri($key, $value, $id = NULL, $use_prefix = FALSE) 
  459. $settings = $this->object->_settings; 
  460. $param_slug = $settings->router_param_slug; 
  461. $uri = $this->object->get_app_request_uri(); 
  462. $parts = array($uri); 
  463. if ($param_slug && strpos($uri, $param_slug) === FALSE) { 
  464. $parts[] = $param_slug; 
  465. $parts[] = $this->object->create_parameter_segment($key, $value, $id, $use_prefix); 
  466. $this->object->set_app_request_uri($this->object->join_paths($parts)); 
  467. return $this->object->get_app_request_uri(); 
  468. /** 
  469. * Creates a parameter segment 
  470. * @param string $key 
  471. * @param mixed $value 
  472. * @param mixed $id 
  473. * @return string 
  474. */ 
  475. function create_parameter_segment($key, $value, $id = NULL, $use_prefix = FALSE) 
  476. $settings = $this->object->_settings; 
  477. if ($use_prefix) { 
  478. $key = $settings->router_param_prefix . $key; 
  479. if ($value === TRUE) { 
  480. $value = 1; 
  481. } elseif ($value == FALSE) { 
  482. $value = 0; 
  483. // null and false values 
  484. $retval = $key . $settings->router_param_separator . $value; 
  485. if ($id) { 
  486. $retval = $id . $settings->router_param_separator . $retval; 
  487. return $retval; 
  488. /** 
  489. * Alias for set_parameter_value 
  490. * @param string $key 
  491. * @param mixed $value 
  492. * @param mixed $id 
  493. */ 
  494. function set_parameter($key, $value, $id = NULL, $use_prefix = FALSE, $url = FALSE) 
  495. return $this->object->set_parameter_value($key, $value, $id, $use_prefix, $url); 
  496. /** 
  497. * Alias for set_parameter_value 
  498. * @param string $key 
  499. * @param mixed $value 
  500. * @param mixed $id 
  501. */ 
  502. function set_param($key, $value, $id = NULL, $use_prefix = FALSE, $url = FALSE) 
  503. return $this->object->set_parameter_value($key, $value, $id, $use_prefix = FALSE, $url); 
  504. /** 
  505. * Gets a parameter's value 
  506. * @param string $key 
  507. * @param mixed $id 
  508. * @param mixed $default 
  509. * @return mixed 
  510. */ 
  511. function get_parameter_value($key, $id = NULL, $default = NULL, $url = FALSE) 
  512. return $this->object->get_parameter($key, $id, $default, FALSE, $url); 
  513. /** 
  514. * Gets a parameter's matching URI segment 
  515. * @param string $key 
  516. * @param mixed $id 
  517. * @param mixed $default 
  518. * @return mixed 
  519. */ 
  520. function get_parameter_segment($key, $id = NULL, $url = FALSE) 
  521. return $this->object->get_parameter($key, $id, NULL, TRUE, $url); 
  522. /** 
  523. * Gets sources used for parsing and extracting parameters 
  524. * @return array 
  525. */ 
  526. function get_parameter_sources() 
  527. return array('querystring' => $this->object->get_formatted_querystring(), 'request_uri' => $this->object->get_app_request_uri()); 
  528. function get_postdata() 
  529. $retval = '/' . urldecode(file_get_contents("php://input")); 
  530. $settings = $this->object->_settings; 
  531. $retval = str_replace(array('&', '='), array('/', $settings->router_param_separator), $retval); 
  532. return $retval; 
  533. function get_formatted_querystring() 
  534. $retval = '/' . $this->object->get_router()->get_querystring(); 
  535. $settings = $this->object->_settings; 
  536. $retval = str_replace(array('&', '='), array('/', $settings->router_param_separator), $retval); 
  537. return $retval; 
  538. function has_parameter_segments() 
  539. $retval = FALSE; 
  540. $settings = $this->object->_settings; 
  541. $request_uri = $this->object->get_app_request_uri(); 
  542. $sep = preg_quote($settings->router_param_separator, '#'); 
  543. // If we detect the MVC_PARAM_SLUG, then we assume that we have parameters 
  544. if ($settings->router_param_slug && strpos($request_uri, '/' . $settings->router_param_slug . '/') !== FALSE) { 
  545. $retval = TRUE; 
  546. // If the above didn't pass, then we try finding parameters in our 
  547. // desired format 
  548. if (!$retval) { 
  549. $regex = implode('', array('#', $settings->router_param_slug ? '/' . preg_quote($settings->router_param_slug, '#') . '/?' : '', "(/?([^/]+{$sep})?[^/]+{$sep}[^/]+/?) {0, }", '$#')); 
  550. $retval = preg_match($regex, $request_uri); 
  551. return $retval; 
  552. /** 
  553. * Recursively calls stripslashes() on strings, arrays, and objects 
  554. * @param mixed $value Value to be processed 
  555. * @return mixed Resulting value 
  556. */ 
  557. function recursive_stripslashes($value) 
  558. if (is_string($value)) { 
  559. $value = stripslashes($value); 
  560. } elseif (is_array($value)) { 
  561. foreach ($value as &$tmp) { 
  562. $tmp = $this->object->recursive_stripslashes($tmp); 
  563. } elseif (is_object($value)) { 
  564. foreach (get_object_vars($value) as $key => $data) { 
  565. $value->{$key} = recursive_stripslashes($data); 
  566. return $value;