Редирект ссылок

Lange

Пользователь
Всем доброго времени суток. Возникла необходимость мода редирект ссылок. Нашёл мод который мне нужен, но он под старую версию TP. Прощу помощи адаптации под новую версию.

Файлы:
go.php
PHP:
<?php
header('Location: '.urldecode($_GET['url']));
?>
robots.txt
Код:
User-agent: *
Disallow: /go.php

bbcode.php найти:
PHP:
function make_clickable ($text)
{
  global $bb_cfg;
 
  $url_regexp = "#
    (?<![\"'=])
    \b
    (
      (https?://|ftp://|www\.|ftp\.)
      [\w\#!$%&~/.\-;:=?@\[\]+]+
    )
    (?![\"']|\[/url|\[/img|</a)
    (?=[,!]?\s|[\)<!])
  #xi";
 
  $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
 
      // pad it with a space so we can match things at the start of the 1st line.
      $ret = " $text ";
 
  if ($bb_cfg['parse_ed2k_links'])
  {
    // ed2k file links (Meithar):
    // ed2k://|file|fileName|fileSize|fileHash|(optional params)|(optional params)|etc|
    $ret = preg_replace_callback("#\b(ed2k://\|file\|([^\\/\|:<>\*\?\"]+?)\|(\d+?)\|([a-f0-9]{32})\|(.*?)/?)(?![\"'])(?=([,\.]*?[\s<\[])|[,\.]*?$)#i", "ed2k_link_callback", $ret);
    // ed2k server links:
    // ed2k://|server|serverIP|serverPort
    $ret = preg_replace("#\b(ed2k://\|server\|([\d\.]+?)\|(\d+?)\|/?)\B#i", "<a href=\"\\1\" class=\"postLink\">\\2:\\3</a>", $ret);
  }
 
  // hide passkey
  $ret = preg_replace('#\?'. $bb_cfg['passkey_key'] .'=[a-zA-Z0-9]{'. BT_AUTH_KEY_LENGTH .'}&#', '?passkey&', $ret);
  // hide sid
  $ret = preg_replace('#([\?&;])sid=[a-zA-Z0-9]{'. SID_LENGTH .'}#', '$1sid', $ret);
 
  // matches an "xxxx://yyyy" URL at the start of a line, or after a space.
  // xxxx can only be alpha characters.
  // yyyy is anything up to the first space, newline, comma, double quote or <
#  $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" class=\"postLink\">\\2</a>", $ret);
  $ret = preg_replace_callback($url_regexp, 'make_url_clickable_callback', $ret);
 
  // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
  // Must contain at least 2 dots. xxxx contains either alphanum, or "-"
  // zzzz is optional.. will contain everything up to the first space, newline,
  // comma, double quote or <.
#  $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" class=\"postLink\">\\2</a>", $ret);
 
  // matches an email@domain type address at the start of a line, or after a space.
  // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
  $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\" class=\"postLink\">\\2@\\3</a>", $ret);
 
  // Remove our padding..
  $ret = substr(substr($ret, 0, -1), 1);
 
  return($ret);
}
 
/**
* Nathan Codding - Feb 6, 2001
* Reverses the effects of make_clickable(), for use in editpost.
* - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs.
*
*/
function undo_make_clickable($text)
{
  $text = preg_replace("#<!-- BBCode auto-link start --><a href=\"(.*?)\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text);
  $text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text);
 
  return $text;
 
}

Заменить на это:
PHP:
function make_clickable ($text)
{
  global $bb_cfg;
 
  $url_regexp = "#
    (?<![\"'=])
    \b
    (
      (https?://|ftp://|www\.|ftp\.)
      [\w\#!$%&~/.\-;:=?@\[\]+]+
    )
    (?![\"']|\[/url|\[/img|</a)
    (?=[,!]?\s|[\)<!])
  #xi";
 
  $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
 
  // pad it with a space so we can match things at the start of the 1st line.
  $ret = ' ' . $text;
 
  if ($bb_cfg['parse_ed2k_links'])
  {
    // ed2k file links (Meithar):
    // ed2k://|file|fileName|fileSize|fileHash|(optional params)|(optional params)|etc|
    $ret = preg_replace_callback("#\b(ed2k://\|file\|([^\\/\|:<>\*\?\"]+?)\|(\d+?)\|([a-f0-9]{32})\|(.*?)/?)(?![\"'])(?=([,\.]*?[\s<\[])|[,\.]*?$)#i", "ed2k_link_callback", $ret);
    // ed2k server links:
    // ed2k://|server|serverIP|serverPort
    $ret = preg_replace("#\b(ed2k://\|server\|([\d\.]+?)\|(\d+?)\|/?)\B#i", "<a href=\"\\1\" class=\"postLink\">\\2:\\3</a>", $ret);
  }
 
  // hide passkey
  $ret = preg_replace('#\?'. $bb_cfg['passkey_key'] .'=[a-zA-Z0-9]{'. BT_AUTH_KEY_LENGTH .'}&#', '?passkey&', $ret);
  // hide sid
  $ret = preg_replace('#([\?&;])sid=[a-zA-Z0-9]{'. SID_LENGTH .'}#', '$1sid', $ret);
 
  // matches an "xxxx://yyyy" URL at the start of a line, or after a space.
  // xxxx can only be alpha characters.
  // yyyy is anything up to the first space, newline, comma, double quote or <
  $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://site.ru/go.php?url=\\2\" target=\"_blank\"  rel=\"nofollow\" class=\"postLink\">\\2</a>", $ret);
 
  // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
  // Must contain at least 2 dots. xxxx contains either alphanum, or "-"
  // zzzz is optional.. will contain everything up to the first space, newline,
  // comma, double quote or <.
  $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://site.ru/go.php?url=http://\\2\" target=\"_blank\" rel=\"nofollow\" class=\"postLink\">\\2</a>", $ret);
 
  // matches an email@domain type address at the start of a line, or after a space.
  // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
  $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
 
  // Remove our padding..
  $ret = substr($ret, 1);
 
  return($ret);
 
}
 
/**
 
* Nathan Codding - Feb 6, 2001
* Reverses the effects of make_clickable(), for use in editpost.
* - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs.
*
*/
function undo_make_clickable($text)
{
  $text = preg_replace("#<!-- BBCode auto-link start --><a href=\"http://site.ru/go.php?url=(.*?)\" target=\"_blank\">.*?</a><!-- BBCode auto-link end -->#i", "\\1", $text);
  $text = preg_replace("#<!-- BBcode auto-mailto start --><a href=\"mailto:(.*?)\">.*?</a><!-- BBCode auto-mailto end -->#i", "\\1", $text);
 
  return $text;
 
}

bbcode.tpl найти:
HTML:
<!-- BEGIN url --><a href="{URL}" class="postLink">{DESCRIPTION}</a><!-- END url -->

Заменить на это:
HTML:
<!-- BEGIN url --><a href="http://site.ru/go.php?url={URL}" {NOFOLLOW} target="_blank" class="postlink">{DESCRIPTION}</a><!-- END url -->
 

dimka3210

Пользователь
Lange, ты устанавливал? Пиши ошибки, а мы уже по факту ответим. Нет желания тупо ставить мод.
 

Lange

Пользователь
dimka3210, в

Please Login or Register to view hidden text.

не понятно куда вставлять, строчки нет такой, какую заменять нужно.
Кстати тут есть различия в функции make_clickable
Вот нынешняя:
PHP:
    function make_clickable ($text)
    {
        global $bb_cfg;
 
        $url_regexp = "#
            (?<![\"'=])
            \b
            (
                https?://[\w\#!$%&~/.\-;:=?@а-яА-Я\[\]+]+
            )
            (?![\"']|\[/url|\[/img|</a)
            (?=[,!]?\s|[\)<!])
        #xiu";
 
        // pad it with a space so we can match things at the start of the 1st line.
        $ret = " $text ";
 
        // hide passkey
        $ret = hide_passkey($ret);
 
        // matches an "xxxx://yyyy" URL at the start of a line, or after a space.
        $ret = preg_replace_callback($url_regexp, array(&$this, 'make_url_clickable_callback'), $ret);
 
        // Remove our padding..
        $ret = substr(substr($ret, 0, -1), 1);
 
        return($ret);
    }
 

Lange

Пользователь
drew, сделал, теперь ссылки цеплять не хочет. Пишу

Please Login or Register to view hidden text.

адрес идёт без site.ru/redirect.php?url=

Please Login or Register to view hidden text.


А когда в адресную строку вставляю site.ru/redirect.php?url=

Please Login or Register to view hidden text.

это, то всё нормально, но перенаправляет на битый адрес вида site.ru/тут квадратики.



Сделал!
 

Lange

Пользователь
Странно, не обрабатывается ссылка вида

Please Login or Register to view hidden text.

, что делать?

Please Login or Register to view hidden text.

обрабатывает это только значение, с www ни в какую не хочет:( и с тегом url не работает.
PHP:
    function make_url_clickable_callback ($m)
    {
        $max_len = 70;
        $href    = $m[1];
     
        $name    = (mb_strlen($href, 'UTF-8') > $max_len) ? mb_substr($href, 0, $max_len - 19) .'...'. mb_substr($href, -16) : $href;
     
        if(!preg_match("#{site.ru}#", $href))
        {
     
            return '<a href="'. make_url('/redirect.php?url=') . urlencode($href) .'" class="postLink" target="_blank">'. $name .'</a>';     
     
        }
     
        return "<a href=\"$href\" class=\"postLink\">$name</a>";
    }
 
Сверху