DLE — Редирект внешних ссылок
Распечатать

DLE — Редирект внешних ссылок

DLE — Редирект внешних ссылок i-notes, vitnet" />
Версия DLE: 9.x - 13.x

Этот маленький хак позволит Вам изменять все внешние ссылки в новостях на *site/go/?, с добавлением тегов от индексации поисковиков nofollow.

Установка:

1. Открываем файл engine/classes/parse.class.php
Найти:
if( $this->safe_mode AND !$config['allow_search_link'] AND $target )
return "<a href=\"" . $url['html'] . "\" " . $target . " rel=\"nofollow\">" . $url['show'] . "</a>" . $url['end'];
else
return "<a href=\"" . $url['html'] . "\" " . $target . ">" . $url['show'] . "</a>" . $url['end'];

Заменить на:
if( $this->safe_mode AND !$config['allow_search_link'] AND $target ) {
return "<a href=\"" . $url['html'] . "\" " . $target . " rel=\"nofollow\">" . $url['show'] . "</a>" . $url['end'];
} elseif( $this->check_home($url['html']) ) {
return "<a href=\"" . $url['html'] . "\" " . $target . ">" . $url['show'] . "</a>" . $url['end'];
} else {
$url['html'] = $config['http_home_url'] . "go/?" . $url['html'];
return "<a href=\"" . $url['html'] . "\" " . $target . " rel=\"nofollow\">" . $url['show'] . "</a>" . $url['end'];
}

Далее найти:
dle 10.1, 10.2
function decode_url( $matches = array() ) {

$show = $matches[3];
$url  = $matches[1].$matches[2];
$url = str_replace("&","&", $url );

return "" . $show . "";
}

dle 10.3
function decode_url( $matches=array() ) {

$url    = $matches[1];
$show   = $matches[3];
$params = trim($matches[2]);
if( !$params OR $params == 'target="_blank"' OR $params == 'target="_blank" rel="nofollow"' OR $params == 'rel="nofollow"' ) {
$url = str_replace("&", "&", $url );
return "" . $show . "";
} else {
return $matches[0];
}
}

dle 12.x
function decode_url( $matches = array() ) {
$url  = $matches[1];
$show = $matches[3];
$params = trim($matches[2]);
if( preg_match( "#title=['\"](.+?)['\"]#i", $params, $match ) ) {
$match[1] = str_replace(""", '"', $match[1]);
$match[1] = str_replace("'", "'", $match[1]);
$match[1] = str_replace("&", "&", $match[1]);

$url = $url . "|" . $match[1];
$params = trim(str_replace($match[0], "", $params));
}

if( preg_match( "#rel=['\"](.+?)['\"]#i", $params, $match ) ) {
$params = trim(str_replace($match[0], "", $params));
}

if( !$params OR $params == 'target="_blank"' ) {
$url = str_replace("&", "&", $url );
return "" . $show . "";
} else {
return $matches[0];
}
}

Заменить на (привести в такой вид)
dle 10.1, 10.2
function decode_url( $matches = array() ) {
global $config;
$show = $matches[3];
$url  = $matches[1] . $matches[2];
$url = str_replace("&","&", $url );
$url = str_replace($config['http_home_url'] . "go/?", "", $url);

return "" . $show . "";
}

dle 10.3
function decode_url( $matches = array() ) {
global $config;

$url    = $matches[1];
$show   = $matches[3];
$params = trim($matches[2]);
if( !$params OR $params == 'target="_blank"' OR $params == 'target="_blank" rel="nofollow"' OR $params == 'rel="nofollow"' ) {
$url = str_replace("&", "&", $url );
$url = str_replace($config['http_home_url'] . "go/?", "", $url);
return "" . $show . "";
} else {
return $matches[0];
}
}

dle 12.x
function decode_url( $matches = array() ) {
$url  = $matches[1];
$show = $matches[3];
$params = trim($matches[2]);
if( preg_match( "#title=['\"](.+?)['\"]#i", $params, $match ) ) {
$match[1] = str_replace(""", '"', $match[1]);
$match[1] = str_replace("'", "'", $match[1]);
$match[1] = str_replace("&", "&", $match[1]);

$url = $url . "|" . $match[1];
$params = trim(str_replace($match[0], "", $params));
}

if( preg_match( "#rel=['\"](.+?)['\"]#i", $params, $match ) ) {
$params = trim(str_replace($match[0], "", $params));
}

if( !$params OR $params == 'target="_blank"' ) {
$url = str_replace("&", "&", $url );
$url = str_replace($config['http_home_url'] . "go/?", "", $url);
return "" . $show . "";
} else {
return $matches[0];
}
}

2. В корне сайта создаем папку go и в этой папке создаем файл index.php со следующим содержимым:
v.1
<?php
if( !empty($_SERVER['QUERY_STRING']) ) {
header('Location: ' . $_SERVER['QUERY_STRING']);
} else header('Location: /');
?>

v.2
<?php
if( !empty($_SERVER['QUERY_STRING']) ) {
echo <<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Переход по внешней ссылке</title>
<!--meta http-equiv="Content-Type" content="text/html; charset=utf-8" /-->
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<meta name="robots" content="noindex">
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
</head>
<body id="body">
<noindex><br /><br /><center>Перенаправление на внешний ресурс: <br /><br />
<div id="waiting"></div>
<noscript>Нажмите <a href="{$_SERVER['QUERY_STRING']}" rel="nofollow">сюда</a> если ваш браузер не перешел по ссылке автоматически.</noscript></center></noindex>
<script type='text/jаvascript'>
function countdown(sec) {
sec--;
if( sec > 0 ) {
document.getElementById("waiting").innerHTML = 'Осталось '+sec+'c.';
window.setTimeout("countdown("+sec+")", 1000);
} else {
document.getElementById("waiting").innerHTML = 'Нажмите <a href="{$_SERVER['QUERY_STRING']}" rel="nofollow">сюда</a> если ваш браузер не перешел по ссылке автоматически.';
window.location.href = "{$_SERVER['QUERY_STRING']}";
}
}
countdown(3); // Сколько секунд ждать: 3 = 3 сек.
</script>
</body>
</html>
HTML;
} else header('Location: /');
?>

3. Так же в папке /go/ рекомендуется создать файл .htaccess со следующим содержимым:
DirectoryIndex index.php
RewriteEngine Off

Готово!

Теперь создаем какую-нибудь новость и смотрим на результат. Все внешние ссылки будут с атрибутом nofollow, а также сама ссылка вида http://site/go/?http://внешняя ссылка

* В админ центре, в разделе Перестроение публикаций выполните перестроение (для старых новостей).

CMS: DLE

Категория: Хаки, плагины, баг-фиксы

Автор: i-notes, vitnet

Источник: Перейти

Опубликовал: Дмитрий


Подождите, сейчас файл будет подготовлен, через
секунд Вы получите ссылку на скачивание,
а сейчас может Зарегистрируемся? wink это быстро!

Имя:*
E-Mail:
Кликните на изображение чтобы обновить код, если он неразборчив

Copyright © 2023 | Проект GiG-LiFe.ru
Материалы на этом сайте взяты из общедоступных источников и могут быть удалены по просьбе авторов, при наличии доказательства авторства.
Materials on this site are taken from public sources and may be deleted at the request of their authors when there is evidence of authorship.