=================================================================== RCS file: /home/cvsd/home/cvs/Metafox/rewrite.php,v retrieving revision 1.1 retrieving revision 1.10 diff -u -p -r1.1 -r1.10 --- Metafox/rewrite.php 2012/05/15 17:47:56 1.1 +++ Metafox/rewrite.php 2014/01/02 11:02:26 1.10 @@ -1,7 +1,7 @@ 0 @@ -60,7 +65,6 @@ if ($link == 'index.php' || in_array('ezin_print', $setvars)) ) { // redirect - ezin_cgi_parse(); // section if (in_array('ezin_section_key', $setvars)) { @@ -104,16 +108,36 @@ if ($link == 'index.php' if (strlen($link) == 0) { $link = 'index.php'; } + if ($ezin_cfg['redirect_equal_url'] == 1) { + // redirect for old access-key + $keys = array( + array('ezin_article_key', 'article_id'), + array('ezin_section_key', 'section_id'), + array('ezin_author_key', 'author_id') + ); + foreach ($keys as $key) { + $id_param = Platon::parse_id_param($key[0]); + $ar = ezin_validate_IDs(array($key[1] => $id_param)); + if (isset($ar['redirect']) + && $ar['redirect']) + { + ezin_redirect_auto($ar); + } + } + // end redirect for old access-key + } + require_once $link; } } // type 1 -if (in_array($link, array('section.php', 'article.php', 'author.php', 'print.php'))) { +if (in_array($link, array('section.php', 'article.php', 'author.php', 'print.php', 'message.php'))) { + $link_file_type = 1; if ( $ezin_cfg['link_file_type'] != 1 && $ezin_cfg['link_redirect'] > 0) { // redirect - ezin_cgi_parse(); + switch ($link) { case 'section.php': $section_id = Platon::parse_id_param(); @@ -131,10 +155,37 @@ if (in_array($link, array('section.php', $article_id = Platon::parse_id_param(); ezin_redirect_print($article_id); break; - + case 'message.php': + $message_id = Platon::parse_id_param(); + ezin_redirect_message($message_id); + break; } } else { // normal + if ($ezin_cfg['redirect_equal_url'] == 1) { + // redirect for old access-key + $id_param = Platon::parse_id_param(); + switch($link) { + case 'article.php': + $ar = ezin_validate_IDs(array('article_id' => $id_param)); + break; + case 'section.php': + $ar = ezin_validate_IDs(array('section_id' => $id_param)); + break; + case 'author.php': + $ar = ezin_validate_IDs(array('author_id' => $id_param)); + break; + case 'message.php': + $ar = ezin_validate_IDs(array('message_id' => $id_param)); + break; + } + if (isset($ar['redirect']) + && $ar['redirect']) + { + ezin_redirect_auto($ar); + } + // end redirect for old access-key + } require_once $link; } } @@ -143,6 +194,7 @@ if (in_array($link, array('section.php', if (strlen($link) > 0 && strtolower(substr($link, -4)) != '.php') { + $link_file_type = 2; $args = explode('/', $link); //print_r($args); @@ -154,7 +206,15 @@ if (strlen($link) > 0 if (count($args) == 1 && strlen($args[0]) > 0) { - ezin_redirect_section($args[0]); + $ar = ezin_validate_IDs(array('section_id' => $args[0])); + if (intval($ar['section_id']) > 0) { + ezin_redirect_section($args[0]); + } else { + $ar = ezin_validate_IDs(array('article_id' => $args[0])); + if (intval($ar['article_id']) > 0) { + ezin_redirect_article($args[0]); + } + } } // others, default: article @@ -171,6 +231,10 @@ if (strlen($link) > 0 ezin_redirect_print($args[1]); $showed = true; } + if (ezin_get_rewrite_key($args[0]) == 'message') { + ezin_redirect_message($args[1]); + $showed = true; + } if (!$showed) { ezin_redirect_article($args[1]); } @@ -191,8 +255,31 @@ if (strlen($link) > 0 && strlen($args[0]) > 0) { require_once 'cfgldr.inc.php'; - $ezin_cgi['query_string'][] = $args[0]; - $ezin_cgi['input'] = 'section'; + // check article + if (ezin_exists_article($args[0]) + && ezin_exists_section($args[0])) + { + $ar = ezin_validate_IDs(array('article_id' => $args[0])); + } else { + $ar = ezin_validate_IDs(array('section_id' => $args[0])); + } + if ($ezin_cfg['redirect_equal_url'] == 1) { + // redirect for old access-key + if (isset($ar['redirect']) + && $ar['redirect']) + { + ezin_redirect_auto($ar); + } + // end redirect for old access-key + } + + if (intval($ar['article_id']) > 0) { + $ezin_cgi['query_string'] = $args; + $ezin_cgi['input'] = 'article'; + } else { + $ezin_cgi['query_string'] = $args; + $ezin_cgi['input'] = 'section'; + } require_once 'index.php'; } @@ -204,17 +291,51 @@ if (strlen($link) > 0 $showed = false; if (ezin_get_rewrite_key($args[0]) == 'author') { - $ezin_cgi['query_string'][] = $args[1]; + array_shift($args); + if ($ezin_cfg['redirect_equal_url'] == 1) { + // redirect for old access-key + $ar = ezin_validate_IDs(array('author_id' => $args[0])); + if (isset($ar['redirect']) + && $ar['redirect']) + { + ezin_redirect_auto($ar); + } + // end redirect for old access-key + } + $ezin_cgi['query_string'] = $args; $ezin_cgi['input'] = 'author'; $showed = true; } if (ezin_get_rewrite_key($args[0]) == 'print') { - $ezin_cgi['query_string'][] = $args[1]; + array_shift($args); + $ezin_cgi['query_string'] = $args; $ezin_cgi['input'] = 'print'; $showed = true; } + if (ezin_get_rewrite_key($args[0]) == 'message') { + array_shift($args); + $ezin_cgi['query_string'] = $args; + $ezin_cgi['input'] = 'message'; + $showed = true; + } if (!$showed) { - $ezin_cgi['query_string'][] = $args[1]; + $section_id = array_shift($args); + if ($ezin_cfg['redirect_equal_url'] == 1) { + // redirect for old access-key + if ($section_id == $args[0]) { + $ar = ezin_validate_IDs(array('section_id' => $args[0])); + $ar['redirect'] = true; + } else { + $ar = ezin_validate_IDs(array('article_id' => $args[0])); + } + if (isset($ar['redirect']) + && $ar['redirect']) + { + ezin_redirect_auto($ar); + } + // end redirect for old access-key + } + $ezin_cgi['query_string'] = $args; $ezin_cgi['input'] = 'article'; } @@ -224,4 +345,11 @@ if (strlen($link) > 0 } +// notfound +if ($link_file_type == -1) { + require_once 'cfgldr.inc.php'; + $ezin_cgi['input'] = 'notfound'; + require_once 'index.php'; +} + ?>