function permlink_to_param()
 {
     if (!empty($_SERVER['PATH_INFO'])) {
         // Fetch the rewrite rules.
         $rewrite = rewrite_rules('matches');
         $pathinfo = $_SERVER['PATH_INFO'];
         // Trim leading '/'.
         $pathinfo = preg_replace('!^/!', '', $pathinfo);
         if (!empty($rewrite)) {
             // Get the name of the file requesting path info.
             $req_uri = $_SERVER['REQUEST_URI'];
             $req_uri = str_replace($pathinfo, '', $req_uri);
             $req_uri = preg_replace("!/+\$!", '', $req_uri);
             $req_uri = explode('/', $req_uri);
             $req_uri = $req_uri[count($req_uri) - 1];
             // Look for matches.
             $pathinfomatch = $pathinfo;
             foreach ($rewrite as $match => $query) {
                 // If the request URI is the anchor of the match, prepend it
                 // to the path info.
                 if (!empty($req_uri) && strpos($match, $req_uri) === 0) {
                     $pathinfomatch = $req_uri . '/' . $pathinfo;
                 }
                 if (preg_match("!^{$match}!", $pathinfomatch, $matches)) {
                     // Got a match.
                     // Trim the query of everything up to the '?'.
                     $query = preg_replace("!^.+\\?!", '', $query);
                     // Substitute the substring matches into the query.
                     @eval("\$query = \"{$query}\";");
                     // Parse the query.
                     parse_str($query, $_GET);
                     break;
                 }
             }
         }
     }
 }
  <p><?php 
    printf(_LANG_WPL_USE_HTACCESS, $permalink_structure);
    ?>
</p>
  <?php 
    $site_root = str_replace('http://', '', trim($siteurl));
    $site_root = preg_replace('|([^/]*)(.*)|i', '$2', $site_root);
    if ('/' != substr($site_root, -1)) {
        $site_root = $site_root . '/';
    }
    $home_root = str_replace('http://', '', trim($siteurl));
    $home_root = preg_replace('|([^/]*)(.*)|i', '$2', $home_root);
    if ('/' != substr($home_root, -1)) {
        $home_root = $home_root . '/';
    }
    $rewrite = rewrite_rules('', $permalink_structure);
    $rule_text = '';
    foreach ($rewrite as $match => $query) {
        if (strstr($query, 'index.php')) {
            $rule_text .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA]\n";
        } else {
            $rule_text .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA]\n";
        }
    }
    ?>
 
<form action="">
    <p>
    	<textarea rows="5" style="width: 98%;"><?php 
    echo "RewriteEngine On\nRewriteBase {$home_root}\n{$rule_text}";
    ?>
Exemplo n.º 3
0
Arquivo: cms.php Projeto: vityapro/cms
 /**
  * Возвращает текущий URI
  * Нужна для того, чтобы иметь возможность переопределить URI.
  * По сути является эмулятором внутреннего mod_rewrite
  * @return string
  */
 private function detectURI()
 {
     if (strpos($_SERVER['REQUEST_URI'], '/', 1) === 1) {
         self::error404();
     }
     $request_uri = ltrim(urldecode(trim($_SERVER['REQUEST_URI'])), '/');
     if (!$request_uri) {
         return;
     }
     // игнорируемые для детекта url
     if (preg_match('/^(admin|install|migrate|index)(.*)/ui', $request_uri)) {
         return;
     }
     // Есть ли в url GET параметры
     $pos_que = mb_strpos($request_uri, '?');
     // если есть и это не go/url= и load/url=
     if ($pos_que !== false && mb_strpos($request_uri, '/url=') === false) {
         // получаем строку запроса
         $query_data = array();
         $query_str = mb_substr($request_uri, $pos_que + 1);
         // удаляем строку запроса из URL
         $uri = rtrim(mb_substr($request_uri, 0, $pos_que), '/');
         // парсим строку запроса
         parse_str($query_str, $query_data);
         // добавляем к полученным данным $_REQUEST
         // именно в таком порядке, чтобы POST имел преимущество над GET
         // это необходимо если в $_REQUEST GET запроса нет, но в url он есть
         $_REQUEST = array_merge($query_data, $_REQUEST);
         // если в $uri пусто (например главная страница)
         if (!$uri) {
             return;
         }
     } else {
         $uri = $request_uri;
     }
     $rules = array();
     if (self::includeFile('url_rewrite.php')) {
         //подключаем список rewrite-правил
         if (function_exists('rewrite_rules')) {
             //получаем правила
             $rules = rewrite_rules();
         }
     }
     if (self::includeFile('custom_rewrite.php')) {
         //подключаем список пользовательских rewrite-правил
         if (function_exists('custom_rewrite_rules')) {
             //добавляем к полученным ранее правилам пользовательские
             $rules = array_merge($rules, custom_rewrite_rules());
         }
     }
     $found = false;
     // Запоминаем реальный uri
     $this->real_uri = $uri;
     if ($rules) {
         //перебираем правила
         foreach ($rules as $rule) {
             //небольшая валидация правила
             if (!$rule['source'] || !$rule['target'] || !$rule['action']) {
                 continue;
             }
             //проверяем совпадение выражения source с текущим uri
             if (preg_match($rule['source'], $uri, $matches)) {
                 //перебираем совпавшие сегменты и добавляем их в target
                 //чтобы сохранить параметры из $uri в новом адресе
                 foreach ($matches as $key => $value) {
                     if (!$key) {
                         continue;
                     }
                     if (mb_strstr($rule['target'], '{' . $key . '}')) {
                         $rule['target'] = str_replace('{' . $key . '}', $value, $rule['target']);
                     }
                 }
                 //выполняем действие
                 switch ($rule['action']) {
                     case 'rewrite':
                         $uri = $rule['target'];
                         $found = true;
                         break;
                     case 'redirect':
                         self::redirect($rule['target']);
                         break;
                     case 'redirect-301':
                         self::redirect($rule['target'], '301');
                         break;
                     case 'alias':
                         // Разбираем $rule['target'] на путь к файлу и его параметры
                         $t = parse_url($rule['target']);
                         // Для удобства формируем массив $include_query
                         // переменные будут сохранены в элементах массива
                         if (!empty($t['query'])) {
                             mb_parse_str($t['query'], $include_query);
                         }
                         if (file_exists(PATH . '/' . $t['path'])) {
                             include_once PATH . '/' . $t['path'];
                         }
                         self::halt();
                 }
             }
             if ($found) {
                 break;
             }
         }
     }
     return $uri;
 }
$wpj_foot = <<<EOD
</body></html>
EOD;
$use_cache = 1;
// No reason not to
/* Including config and functions files */
$curpath = dirname(__FILE__) . '/';
if (!file_exists($curpath . '/wp-config.php')) {
    die($wpj_head . _LANG_WA_HEADER_GUIDE1 . $wpj_foot);
}
$wp_inblock = 0;
require $curpath . '/wp-config.php';
$path_info = array();
if (!empty($_SERVER['PATH_INFO'])) {
    // Fetch the rewrite rules.
    $rewrite = rewrite_rules('matches');
    $pathinfo = $_SERVER['PATH_INFO'];
    // Trim leading '/'.
    $pathinfo = preg_replace('!^/!', '', $pathinfo);
    if (!empty($rewrite)) {
        // Get the name of the file requesting path info.
        $req_uri = $_SERVER['REQUEST_URI'];
        $req_uri = str_replace($pathinfo, '', $req_uri);
        $req_uri = preg_replace("!/+\$!", '', $req_uri);
        $req_uri = explode('/', $req_uri);
        $req_uri = $req_uri[count($req_uri) - 1];
        // Look for matches.
        $pathinfomatch = $pathinfo;
        foreach ($rewrite as $match => $query) {
            // If the request URI is the anchor of the match, prepend it
            // to the path info.
Exemplo n.º 5
0
$usersmenus = new usersMenus();
if (!$usersmenus->AsDansGuardianAdministrator) {
    $tpl = new templates();
    $alert = $tpl->_ENGINE_parse_body('{ERROR_NO_PRIVS}');
    echo "alert('{$alert}');";
    die;
}
if (isset($_GET["rewrite_rules_list"])) {
    rewrite_rules_list();
    exit;
}
if (isset($_POST["rewrite_rule_enable"])) {
    rewrite_rule_enable();
    exit;
}
rewrite_rules();
function rewrite_rules_list()
{
    $ID = $_GET["ID"];
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_squid_builder();
    if ($ID == 0) {
        $sock = new sockets();
        $ligne = unserialize(base64_decode($sock->GET_INFO("DansGuardianDefaultMainRule")));
    } else {
        $sql = "SELECT RewriteRules FROM webfilter_rules WHERE ID={$ID}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
    }
    $RewriteRules = unserialize(base64_decode($ligne["RewriteRules"]));
    $search = '%';