2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4 // +----------------------------------------------------------------------+
5 // | Akelos Framework - http://www.akelos.org |
6 // +----------------------------------------------------------------------+
7 // | Copyright (c) 2002-2006, Akelos Media, S.L. & Bermi Ferrer Martinez |
8 // | Released under the GNU Lesser General Public License, see LICENSE.txt|
9 // +----------------------------------------------------------------------+
11 if(!class_exists('AkRouter')){
13 ak_compat('http_build_query');
16 * Native PHP URL rewriting for the Akelos Framework.
18 * @package ActionController
20 * @author Bermi Ferrer <bermi a.t akelos c.om>
21 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
22 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
26 if(!defined('OPTIONAL')){
27 define('OPTIONAL', false);
30 if(!defined('COMPULSORY')){
31 define('COMPULSORY', true);
34 if(!defined('COMPULSORY_REGEX')){
35 define('COMPULSORY_REGEX', '([^\/]+){1}');
42 * Native PHP URL rewriting for the Akelos Framework
44 * This class implements PHP based URL rewriting for the Akelos Framework, thus shifting the responsibility of URL parsing from the webserver to the Akelos Framework itself. This has been a requested feature for two primary reasons.
46 * - Not all webservers support rewriting. By moving this code to the core, the framework is able to function out of the box on almost all webservers.
48 * - A rewriting implementation in the Akelos Framework can also be used to generate custom URLs by linking it to the standard URL helpers such as url_for, link_to, and redirect_to.
50 * @author Bermi Ferrer <bermi a.t akelos d.t c.om>
51 * @copyright Copyright (c) 2002-2005, Akelos Media, S.L. http://www.akelos.org
52 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
54 class AkRouter
extends AkObject
59 // --- Private properties --- //
63 * Routes setting container
67 * @var array $_loaded_routes
69 var $_loaded_routes = array();
74 // ------ CLASS METHODS ------ //
77 // ---- Constructor ---- //
79 function __construct()
82 * We will try to guess if mod_rewrite is enabled.
83 * Set AK_ENABLE_URL_REWRITE in your config
84 * to avoid the overhead this function causes
86 if(!defined('AK_ENABLE_URL_REWRITE') ||
(defined('AK_ENABLE_URL_REWRITE') && AK_ENABLE_URL_REWRITE
!== false)){
87 $this->_loadUrlRewriteSettings();
92 // ---- Getters ---- //
98 * $this->_loaded_routes getter
100 * Use this method to get $this->_loaded_routes value
103 * @return array Returns Loaded Routes array.
107 return $this->_loaded_routes
;
113 // ---- Public methods ---- //
119 * Generates a custom URL, depending on current rewrite rules.
121 * Generates a custom URL, depending on current rewrite rules.
124 * @param array $params An array with parameters to include in the url.
125 * - <code>array('controller'=>'post','action'=>'view','id'=>'10')</code>
126 * - <code>array('controller'=>'page','action'=>'view_page','webpage'=>'contact_us')</code>
127 * @return string Having the following rewrite rules:
129 * $Router =& new AkRouter();
131 * $Router->map('/setup/*config_settings',array('controller'=>'setup'));
132 * $Router->map('/customize/*options/:action',array('controller'=>'themes','options'=>3));
133 * $Router->map('/blog/:action/:id',array('controller'=>'post','action'=>'list','id'=>OPTIONAL),array('id'=>'/\d{1,}/'));
134 * $Router->map('/:year/:month/:day', array('controller' => 'articles','action' => 'view_headlines','year' => COMPULSORY,'month' => 'all','day' => OPTIONAL) , array('year'=>'/(20){1}\d{2}/','month'=>'/((1)?\d{1,2}){2}/','day'=>'/(([1-3])?\d{1,2}){2}/'));
135 * $Router->map('/:webpage', array('controller' => 'page', 'action' => 'view_page', 'webpage' => 'index'),array('webpage'=>'/(\w|_)+/'));
136 * $Router->map('/', array('controller' => 'page', 'action' => 'view_page', 'webpage'=>'index'));
137 * $Router->map('/:controller/:action/:id');
140 * We get the following results:
142 * <code>$Router->toUrl(array('controller'=>'page','action'=>'view_page','webpage'=>'contact_us'));</code>
143 * Produces: /contact_us/
145 * <code>$Router->toUrl(array('controller'=>'page','action'=>'view_page','webpage'=>'index'));</code>
148 * <code>$Router->toUrl(array('controller'=>'post','action'=>'list','id'=>null));</code>
151 * <code>$Router->toUrl(array('controller'=>'post','action'=>'view','id'=>null));</code>
152 * Produces: /blog/view/
154 * <code>$Router->toUrl(array('controller'=>'post','action'=>'view','id'=>'10'));</code>
155 * Produces: /blog/view/10/
157 * <code>$Router->toUrl(array('controller'=>'blog','action'=>'view','id'=>'newest'));</code>
158 * Produces: /blog/view/newest/
160 * <code>$Router->toUrl(array('controller' => 'articles','action' => 'view_headlines','year' => '2005','month' => '10', 'day' => null));</code>
161 * Produces: /2005/10/
163 * <code>$Router->toUrl(array('controller'</code> => 'articles','action' => 'view_headlines','year' => '2006','month' => 'all', 'day' => null));</code>
166 * <code>$Router->toUrl(array('controller' => 'user','action' => 'list','id' => '12'));</code>
167 * Produces: /user/list/12/
169 * <code>$Router->toUrl(array('controller' => 'setup','config_settings' => array('themes','clone','12')));</code>
170 * Produces: /setup/themes/clone/12/
172 * <code>$Router->toUrl(array('controller' => 'themes','options' => array('blue','css','sans_serif'), 'action'=>'clone'));</code>
173 * Produces: /customize/blue/css/sans_serif/clone/
175 function toUrl($params=array())
178 $_cache_key = md5(serialize($params));
179 if(!isset($_cache[$_cache_key])){
182 if(isset($params[AK_SESSION_NAME
]) && isset($_COOKIE)){
183 unset($params[AK_SESSION_NAME
]);
187 foreach ($this->_loaded_routes
as $route){
188 $params_copy = $params;
191 foreach ($params_copy as $k=>$v){
198 if(isset($route['options'])){
199 foreach ($route['options'] as $option=>$value){
201 !empty($route['url_pieces']) &&
202 isset($route['options'][$option]) &&
203 array_search(':'.$option, $route['url_pieces']) === false &&
204 array_search('*'.$option, $route['url_pieces']) === false &&
207 is_integer($value)) &&
209 !isset($params_copy[$option]
211 $params_copy[$option] != $value
217 if(isset($params_copy[$option]) &&
218 $value == $params_copy[$option] &&
219 $value !== OPTIONAL
&&
220 $value !== COMPULSORY
)
222 if($option == 'controller'){
223 $_controller = $value;
225 unset($params_copy[$option]);
232 foreach ($route['arr_params'] as $arr_route){
233 if(isset($
$arr_route) && is_array($
$arr_route)){
234 $
$arr_route = join('/',$
$arr_route);
238 $_url_pieces = array();
239 foreach (array_reverse($route['url_pieces']) as $v){
240 if(strstr($v,':') ||
strstr($v,'*')){
242 if(isset($params[$v])){
243 if (count($_url_pieces) ||
isset($route['options'][$v]) && $params[$v] != $route['options'][$v] ||
!isset($route['options'][$v]) ||
isset($route['options'][$v]) && $route['options'][$v] === COMPULSORY
){
244 $_url_pieces[] = is_array($params[$v]) ?
join('/',$params[$v]) : $params[$v];
248 $_url_pieces[] = is_array($v) ?
join('/',$v) : $v;
253 $parsed = str_replace('//','/','/'.join('/',array_reverse($_url_pieces)).'/');
255 // This might be faster but using eval here might cause security issues
256 //@eval('$parsed = "/".trim(str_replace("//","/","'.str_replace(array('/:','/*'),'/$','/'.join('/',$route['url_pieces']).'/').'"),"/")."/";');
262 if(is_string($parsed)){
263 if($parsed_arr = $this->toParams($parsed)){
264 if($parsed == '/' && count(array_diff($params,$parsed_arr)) == 0){
265 $_cache[$_cache_key] = '/';
266 return $_cache[$_cache_key];
269 if( isset($parsed_arr['controller']) &&
270 ((isset($controller) && $parsed_arr['controller'] == $controller) ||
271 (isset($_controller) && $parsed_arr['controller'] == $_controller))){
274 if( isset($route['options']['controller']) &&
275 $route['options']['controller'] !== OPTIONAL
&&
276 $route['options']['controller'] !== COMPULSORY
&&
277 $parsed_arr['controller'] != $route['options']['controller'] &&
278 count(array_diff(array_keys($route['options']),array_keys($parsed_arr))) > 0){
282 $url_params = array_merge($parsed_arr,$params_copy);
285 foreach ($parsed_arr as $k=>$v){
286 if(isset($url_params[$k]) && $url_params[$k] == $v){
287 unset($url_params[$k]);
292 foreach (array_reverse($route['url_pieces'], true) as $position => $piece){
293 $piece = str_replace(array(':','*'),'', $piece);
295 if(strstr($parsed,'/'.$
$piece.'/')){
296 unset($url_params[$piece]);
301 foreach ($url_params as $k=>$v){
303 unset($url_params[$k]);
307 if($parsed == '/' && !empty($url_params['controller'])){
308 $parsed = '/'.join('/',array_diff(array($url_params['controller'],@$url_params['action'],@$url_params['id']),array('')));
309 unset($url_params['controller'],$url_params['action'],$url_params['id']);
312 if(defined('AK_URL_REWRITE_ENABLED') && AK_URL_REWRITE_ENABLED
=== true){
313 if(isset($url_params['ak'])){
314 unset($url_params['ak']);
316 if(isset($url_params['lang'])){
317 $parsed = '/'.$url_params['lang'].$parsed;
318 unset($url_params['lang']);
320 $parsed .= count($url_params) ?
'?'.http_build_query($url_params) : '';
322 $parsed = count($url_params) ?
'/?ak='.$parsed.'&'.http_build_query($url_params) : '/?ak='.$parsed;
324 $_cache[$_cache_key] = $parsed;
331 (array)$extra_parameters = @array_diff
($params_copy,$parsed_arr);
334 if($parsed == '' && is_array($params)){
335 $parsed = '?'.http_build_query(array_merge($params,(array)$extra_parameters));
341 if(defined('AK_URL_REWRITE_ENABLED') && AK_URL_REWRITE_ENABLED
=== false && $parsed{0} != '?'){
342 $parsed = '?ak='.trim($parsed,'/');
345 $parsed .= empty($extra_parameters) ?
'' : (strstr($parsed,'?') ?
'&' : '?').http_build_query($extra_parameters);
346 $_cache[$_cache_key] = $parsed;
348 return $_cache[$_cache_key];
355 * Gets the parameters from a Akelos Framework friendly URL.
357 * This method returns the parameters found in an Akelos Framework friendly URL.
359 * This function will inspect the rewrite rules and will return the params that match the first one.
362 * @param string $url URL to get params from.
363 * @return mixed Having the following rewrite rules:
365 * $Router =& new AkRouter();
367 * $Router->map('/setup/*config_settings',array('controller'=>'setup'));
368 * $Router->map('/customize/*options/:action',array('controller'=>'themes','options'=>3));
369 * $Router->map('/blog/:action/:id',array('controller'=>'post','action'=>'list','id'=>OPTIONAL),array('id'=>'/\d{1,}/'));
370 * $Router->map('/:year/:month/:day', array('controller' => 'articles','action' => 'view_headlines','year' => COMPULSORY,'month' => 'all','day' => OPTIONAL) , array('year'=>'/(20){1}\d{2}/','month'=>'/((1)?\d{1,2}){2}/','day'=>'/(([1-3])?\d{1,2}){2}/'));
371 * $Router->map('/:webpage', array('controller' => 'page', 'action' => 'view_page', 'webpage' => 'index'),array('webpage'=>'/(\w|_)+/'));
372 * $Router->map('/', array('controller' => 'page', 'action' => 'view_page', 'webpage'=>'index'));
373 * $Router->map('/:controller/:action/:id');
376 * We get the following results:
378 * <code>$Router->toParams('/contact_us');</code>
379 * Produces: array('controller'=>'page','action'=>'view_page','webpage'=>'contact_us');
381 * <code>$Router->toParams('/');</code>
382 * Produces: array('controller'=>'page','action'=>'view_page','webpage'=>'index');
384 * <code>$Router->toParams('');</code>
385 * Produces: array('controller'=>'page','action'=>'view_page','webpage'=>'index');
387 * <code>$Router->toParams('/blog/');</code>
388 * Produces: array('controller'=>'post','action'=>'list','id'=>null);
390 * <code>$Router->toParams('/blog/view');</code>
391 * Produces: array('controller'=>'post','action'=>'view','id'=>null);
393 * <code>$Router->toParams('/blog/view/10/');</code>
394 * Produces: array('controller'=>'post','action'=>'view','id'=>'10');
396 * <code>$Router->toParams('/blog/view/newest/');</code>
397 * Produces: array('controller'=>'blog','action'=>'view','id'=>'newest');
399 * <code>$Router->toParams('/2005/10/');</code>
400 * Produces: array('controller' => 'articles','action' => 'view_headlines','year' => '2005','month' => '10', 'day' => null);
402 * <code>$Router->toParams('/2006/');</code>
403 * Produces: array('controller' => 'articles','action' => 'view_headlines','year' => '2006','month' => 'all', 'day' => null);
405 * <code>$Router->toParams('/user/list/12');</code>
406 * Produces: array('controller' => 'user','action' => 'list','id' => '12');
408 * <code>$Router->toParams('/setup/themes/clone/12/');</code>
409 * Produces: array('controller' => 'setup','config_settings' => array('themes','clone','12'));
411 * <code>$Router->toParams('/customize/blue/css/sans_serif/clone/');</code>
412 * Produces: array('controller' => 'themes','options' => array('blue','css','sans_serif'), 'action'=>'clone');
414 * This function returns false in case no rule is found for selected URL
416 function toParams($url)
418 $url = $url == '/' ||
$url == '' ?
'/' : '/'.trim($url,'/').'/';
421 foreach ($this->_loaded_routes
as $route){
424 if(preg_match($route['regex'], $url)){
425 foreach ($route['regex_array'] as $single_regex_arr){
427 $k = key($single_regex_arr);
429 $single_regex = $single_regex_arr[$k];
430 $single_regex = '/^(\/'.$single_regex.'){1}/';
431 preg_match($single_regex, $url, $got);
433 if(in_array($k,$route['arr_params'])){
434 $url_parts = strstr(trim($url,'/'),'/') ?
explode('/',trim($url,'/')) : array(trim($url,'/'));
436 $pieces = (isset($route['options'][$k]) && $route['options'][$k] > 0) ?
$route['options'][$k] : count($url_parts);
439 $url_part = array_shift($url_parts);
440 $url = substr_replace($url,'',1,strlen($url_part)+
1);
442 if(preg_match($single_regex, '/'.$url_part)){
443 $params[$k][] = $url_part;
446 }elseif(!empty($got[0])){
447 $url = substr_replace($url,'',1,strlen($got[0]));
448 if(in_array($k,$route['var_params'] )){
449 $param = trim($got[0],'/');
450 $params[$k] = $param;
453 if(isset($route['options'][$k])){
455 if($route['options'][$k] !== COMPULSORY
&&
456 $route['options'][$k] !== OPTIONAL
&&
457 $route['options'][$k] != '' &&
458 ((!isset($params[$k]))||
(isset($params[$k]) && $params[$k] == ''))){
459 $params[$k] = $route['options'][$k];
464 if(isset($route['options'])){
465 foreach ($route['options'] as $option=>$value){
466 if($value !== COMPULSORY
&& $value !== OPTIONAL
&& $value != '' && !isset($params[$option])){
467 $params[$option] = $value;
473 $params = array_map(array(&$this,'_urlDecode'),$params);
485 * Rewrite rules are defined on the file <code>config/routes.php</code>
487 * Rules that are defined first take precedence over the rest.
490 * @param string $url_pattern URL patterns have the following format:
492 * - <b>/static_text</b>
493 * - <b>/:variable</b> (will load $variable)
494 * - <b>/*array</b> (will load $array as an array)
495 * @param array $options Options is an array with and array pair of field=>value
496 * The following example <code>array('controller' => 'page')</code> sets var 'controler' to 'page' if no 'controller' is specified in the $url_pattern param this value will be used.
498 * The following constants can be used as values:
500 * OPTIONAL // 'var_name'=> OPTIONAL, will set 'var_name' as an option
501 * COMPULSORY // 'var_name'=> COMPULSORY, will require 'var_name' to be set
503 * @param array $requirements $requirements holds an array with and array pair of field=>value where value is a perl compatible regular expression that will be used to validate rewrite rules
504 * The following example <code>array('id'=>'/\d+/')</code> will require that var 'id' must be a numeric field.
506 * NOTE:If option <b>'id'=>OPTIONAL</b> this requirement will be used in case 'id' is set to something
509 function connect($url_pattern, $options = array(), $requirements = null)
512 if(!empty($options['requirements'])){
513 $requirements = empty($requirements) ?
$options['requirements'] : array_merge($options['requirements'],$requirements);
514 unset($options['requirements']);
517 preg_match_all('/(([^\/]){1}(\/\/)?){1,}/',$url_pattern,$found);
518 $url_pieces = $found[0];
520 $regex_arr = array();
521 $optional_pieces = array();
522 $var_params = array();
523 $arr_params = array();
524 foreach ($url_pieces as $piece){
525 $is_var = $piece[0] == ':';
526 $is_arr = $piece[0] == '*';
527 $is_constant = !$is_var && !$is_arr;
529 $piece = $is_constant ?
$piece : substr($piece,1);
531 if($is_var && !isset($options[$piece])){
532 $options[$piece] = OPTIONAL
;
535 if($is_arr && !isset($options[$piece])){
536 $options[$piece] = OPTIONAL
;
542 $regex_arr[] = array('_constant_'.$piece => '('.$piece.'(?=(\/|$))){1}');
543 }elseif(isset($requirements[$piece])){
544 if (isset($options[$piece]) && $options[$piece] !== COMPULSORY
){
545 $regex_arr[] = array($piece=> '(('.trim($requirements[$piece],'/').'){1})?');
546 }elseif(isset($options[$piece]) && $options[$piece] !== OPTIONAL
){
547 $regex_arr[] = array($piece=> '(('.trim($requirements[$piece],'/').'){1}|('.$options[$piece].'){1}){1}');
549 $regex_arr[] = array($piece=> '('.trim($requirements[$piece],'/').'){1}');
551 }elseif(isset($options[$piece])){
552 if($options[$piece] === OPTIONAL
){
553 $regex_arr[] = array($piece=>'[^\/]*');
554 }elseif ($options[$piece] === COMPULSORY
){
555 $regex_arr[] = array($piece=> COMPULSORY_REGEX
);
556 }elseif(is_string($options[$piece]) && $options[$piece][0] == '/' &&
557 ($_tmp_close_char = strlen($options[$piece])-1 ||
$options[$piece][$_tmp_close_char] == '/')){
558 $regex_arr[] = array($piece=> substr($options[$piece],1,$_tmp_close_char*-1));
559 }elseif ($options[$piece] != ''){
560 $regex_arr[] = array($piece=>'[^\/]*');
561 $optional_pieces[$piece] = $piece;
564 $regex_arr[] = array($piece => $piece);
569 $var_params[] = $piece;
572 $arr_params[] = $piece;
575 if(isset($options[$piece]) && $options[$piece] === OPTIONAL
){
576 $optional_pieces[$piece] = $piece;
580 foreach (array_reverse($regex_arr) as $pos=>$single_regex_arr){
581 $var_name = key($single_regex_arr);
582 if((isset($options[$var_name]) && $options[$var_name] === COMPULSORY
) ||
(isset($requirements[$var_name]) && $requirements[$var_name] === COMPULSORY
)){
583 $last_optional_var = $pos;
589 $pieces_count = count($regex_arr);
591 foreach ($regex_arr as $pos=>$single_regex_arr){
592 $k = key($single_regex_arr);
593 $single_regex = $single_regex_arr[$k];
595 $slash_delimiter = isset($last_optional_var) && ($last_optional_var <= $pos) ?
'{1}' : '?';
597 if(isset($optional_pieces[$k])){
598 $terminal = (is_numeric($options[$k]) && $options[$k] > 0 && in_array($k,$arr_params)) ?
'{'.$options[$k].'}' : ($pieces_count == $pos+
1 ?
'?' : '{1}');
599 $regex .= $is_arr ?
'('.$single_regex.'\/'.$slash_delimiter.')+' : '('.$single_regex.'\/'.$slash_delimiter.')'.$terminal;
601 $regex .= $is_arr ?
$single_regex.'\/+' : $single_regex.'\/'.($pieces_count == $pos+
1 ?
'?' : $slash_delimiter);
604 $regex = rtrim($regex ,'/').'){1}$/';
605 $regex = str_replace('/^\$/','/^\\/?$/',$regex);
608 $this->_loaded_routes
[] = array(
609 'url_path' => $url_pattern,
610 'options' => $options,
611 'requirements' => $requirements,
612 'url_pieces' => $url_pieces,
614 'regex_array' => $regex_arr,
615 'optional_params' => $optional_pieces,
616 'var_params' => $var_params,
617 'arr_params' => $arr_params
631 function map($url_pattern, $options = array(), $requirements = null)
633 return $this->connect($url_pattern, $options, $requirements);
640 * Url decode a strin or an array of strings
642 function _urlDecode($input)
645 if (is_string($input)){
646 return urldecode($input);
647 }elseif (is_array($input)){
648 return array_map(array(&$this,'_urlDecode'),$input);
656 // {{{ _loadUrlRewriteSettings()
658 * This method tries to determine if url rewrite is enabled on this server.
659 * It has only been tested on apache.
660 * It is strongly recomended that you manually define the constant
661 * AK_URL_REWRITE_ENABLED on your config file to the avoid overload
662 * this function causes and to prevent from missfunctioning
664 function _loadUrlRewriteSettings()
671 if(defined('AK_URL_REWRITE_ENABLED')){
672 $result = AK_URL_REWRITE_ENABLED
;
673 return AK_URL_REWRITE_ENABLED
;
676 if(!defined('AK_URL_REWRITE_ENABLED')){
677 define('AK_URL_REWRITE_ENABLED',false);
678 $result = AK_URL_REWRITE_ENABLED
;
682 if(defined('AK_ENABLE_URL_REWRITE') && AK_ENABLE_URL_REWRITE
== false){
683 if(!defined('AK_URL_REWRITE_ENABLED')){
684 define('AK_URL_REWRITE_ENABLED',false);
686 $result = AK_URL_REWRITE_ENABLED
;
690 $url_rewrite_status = false;
692 //echo '<pre>'.print_r(get_defined_functions(), true).'</pre>';
694 if( isset($_SERVER['REDIRECT_STATUS'])
695 && $_SERVER['REDIRECT_STATUS'] == 200
696 && isset($_SERVER['REDIRECT_QUERY_STRING'])
697 && strstr($_SERVER['REDIRECT_QUERY_STRING'],'ak=')){
699 if(strstr($_SERVER['REDIRECT_QUERY_STRING'],'&')){
700 $tmp_arr = explode('&',$_SERVER['REDIRECT_QUERY_STRING']);
701 $ak_request = $tmp_arr[0];
703 $ak_request = $_SERVER['REDIRECT_QUERY_STRING'];
705 $ak_request = trim(str_replace('ak=','',$ak_request),'/');
707 if(strstr($_SERVER['REDIRECT_URL'],$ak_request)){
708 $url_rewrite_status = true;
710 $url_rewrite_status = false;
714 // We check if available by investigating the .htaccess file if no query has been set yet
715 elseif(function_exists('apache_get_modules')){
717 $available_modules = apache_get_modules();
719 if(in_array('mod_rewrite',(array)$available_modules)){
721 // Local session name is changed intentionally from .htaccess
722 // So we can see if the file has been loaded.
723 // if so, we restore the session.name to its original
725 if(ini_get('session.name') == 'AK_SESSID'){
726 $session_name = defined('AK_SESSION_NAME') ? AK_SESSION_NAME
: get_cfg_var('session.name');
727 ini_set('session.name',$session_name);
728 $url_rewrite_status = true;
730 // In some cases where session.name cant be set up by htaccess file,
731 // we can check for modrewrite status on this file
732 }elseif (file_exists(AK_BASE_DIR
.DS
.'.htaccess')){
733 $htaccess_file = Ak
::file_get_contents(AK_BASE_DIR
.DS
.'.htaccess');
734 if(stristr($htaccess_file,'RewriteEngine on')){
735 $url_rewrite_status = true;
740 // If none of the above works we try to fetch a file that should be remaped
741 }elseif (isset($_SERVER['REDIRECT_URL']) && $_SERVER['REDIRECT_URL'] == '/' && isset($_SERVER['REDIRECT_STATUS']) && $_SERVER['REDIRECT_STATUS'] == 200){
742 $url_rewrite_test_url = AK_URL
.'mod_rewrite_test';
743 if(!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])){
744 $url_rewrite_test_url = AK_PROTOCOL
.$_SERVER['PHP_AUTH_USER'].':'.$_SERVER['PHP_AUTH_PW'].'@'.AK_HOST
.'/mod_rewrite_test';
747 $url_rewrite_status = strstr(@file_get_contents
($url_rewrite_test_url), 'AK_URL_REWRITE_ENABLED');
748 $AK_URL_REWRITE_ENABLED = "define(\\'AK_URL_REWRITE_ENABLED\\', ".($url_rewrite_status ?
'true' : 'false').");\n";
750 register_shutdown_function(create_function('',"Ak::file_put_contents(AK_CONFIG_DIR.DS.'config.php',
751 str_replace('<?php\n','<?php\n\n$AK_URL_REWRITE_ENABLED',Ak::file_get_contents(AK_CONFIG_DIR.DS.'config.php')));"));
756 if(!defined('AK_URL_REWRITE_ENABLED')){
757 define('AK_URL_REWRITE_ENABLED', $url_rewrite_status);
759 $result = AK_URL_REWRITE_ENABLED
;
760 return AK_URL_REWRITE_ENABLED
;
770 $AkRouter =& Ak
::singleton('AkRouter', $null);