Пример #1
0
function merge_params($url, $hash)
{
    if (isset($hash['controller'])) {
        $url = replace_controller($url, $hash['controller']);
        unset($hash['controller']);
    }
    if (isset($hash['action'])) {
        $url = replace_action($url, $hash['action']);
        unset($hash['action']);
    }
    $params = params2hash($url);
    $params = array_merge($params, $hash);
    $params = hash2params($params);
    $parts = url_split($url);
    $parts['params'] = $params;
    $result = url_join($parts);
    return $result;
}
Пример #2
0
function get_real_url($url, $echo = 0, $level = 0)
{
    if ($level > 5) {
        return $url;
    }
    list($host, $path, $filename, $ext, $proto, $port) = url_split($url);
    // опознаётся два протокола: http и https
    if (!$port) {
        $port = $proto == 'https' ? 443 : 80;
    }
    $fp = fsockopen($host, $port, $errno, $errstr, 10);
    if (!$fp) {
        echo "{$errstr} ({$errno})\n";
        $answer = $url;
    } else {
        // GET, HEAD, OPTIONS, TRACE
        $req = $ext ? "/{$path}/{$filename}.{$ext}" : "/{$path}/{$filename}";
        fputs($fp, "HEAD {$req} HTTP/1.0\r\nHost: {$host}\r\n\r\n");
        $head = '';
        while (!feof($fp)) {
            $head .= fgets($fp, 128);
        }
        fclose($fp);
        if ($echo) {
            echo "{$level}:\n{$head}";
        }
        if (preg_match('/^Location: *http:\\/\\/([^\\r\\n]*)/m', $head, $matches)) {
            $level++;
            $answer = get_real_url('http://' . $matches[1], $echo, $level);
        } elseif (preg_match('/^Location: *([^\\r\\n]*)/m', $head, $matches)) {
            $level++;
            $answer = get_real_url("http://{$host}/{$path}/{$matches[1]}", $echo, $level);
        } else {
            $answer = $url;
        }
    }
    // if
    return $answer;
}
Пример #3
0
 //print_r( $all_pict );
 if ($all_pict) {
     while (list($key, $val) = each($all_pict)) {
         // могут встречаться \" и \' (картинки в скриптах), попробовал исправить так
         if (substr($val, 0, 2) == '\\"' or substr($val, 0, 2) == '\\\'') {
             $val = substr(stripslashes($val), 1, -1);
         }
         // убираем символы \n и \r
         $val = str_replace("\n", '', $val);
         $val = str_replace("\r", '', $val);
         if ($val and !isset($pictures[$val]) and !strstr($val, '"') and !strstr($val, '\'')) {
             $pictures[$val] = basename($val);
             // присваеваем имя
             if (preg_match('/^ *(https?:\\/\\/.*)$/m', $val)) {
                 $link = $val;
                 list(, , $pname, $pext) = url_split($val);
                 $pictures[$val] = $pext ? "{$pname}.{$pext}" : $pname;
             } elseif (preg_match('/^\\//', $val, $link)) {
                 $link = "{$proto}://{$host}{$val}";
             } else {
                 $link = "{$proto}://{$host}/{$path}/{$val}";
             }
             if ($link and $picture = file_get_contents($link)) {
                 // сохраняем картинку
                 $len = strlen($picture);
                 if (file_exists("{$dir}/{$pictures[$val]}")) {
                     // если в папке есть файл с таким именем
                     $pictures[$val] = $len . $pictures[$val];
                 }
                 // то называем по другому
                 if ($fp = fopen("{$dir}/{$pictures[$val]}", 'w')) {