Прятатель ссылок FREE
settings_varname);
$html = '';
if (!empty($links))
{
foreach ($links as $key => $link)
{
$html .= '
' . get_option('home') . '/ =>
|
|
';
}
}
return $html;
}
function addLinks($data)
{
$links = array();
for ($i = 0; $i < sizeof($data['request']); ++$i)
{
$request = trim($data['request'][$i]);
$destination = trim($data['destination'][$i]);
if ($request == '' && ($destination == 'http://' || $destination == ''))
{
continue;
}
else
{
$links[] = array(
'destination' => $destination,
'request' => $request,
'redirect' => 301,
'anonymous' => 0,
'clicks' => 0,
'clicks_unique' => 0,
);
}
}
update_option($this->settings_varname, $links);
}
function redirect()
{
$home_url = get_option('home');
if ('http://' == substr($home_url, 0, 7)) {
$home_url = substr($home_url, 7);
}
if ('https://' == substr($home_url, 0, 8)) {
$home_url = substr($home_url, 8);
}
$url_path = $this->getPath($home_url, '', $this->url());
$url_path = rtrim($url_path, '/');
// 1.0.2 (отрезает лишнии параметры у адреса, например ?utm_compaign=123 и т.д.)
if (FALSE !== strpos($url_path, '?')) {
$url_path = substr($url_path, 0, strpos($url_path, '?'));
}
$links = get_option($this->settings_varname);
if (!empty($links))
{
foreach ($links as $key => $link)
{
if (urldecode(trim($url_path, '/')) == trim($link['request'], '/'))
{
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: ' . $link['destination']);
exit();
}
else
{
unset($links);
}
}
}
}
function url()
{
return $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
}
function getPath($site_url, $replace, $now_url)
{
$chr = chr(1);
$now_url_lower= strtolower($now_url);
$site_url_lower = strtolower($site_url);
while (FALSE !== ($pos = strpos($now_url_lower, $site_url_lower)))
{
$now_url = substr_replace($now_url, $chr, $pos, strlen($site_url));
$now_url_lower = substr_replace($now_url_lower, $chr, $pos, strlen($site_url));
}
$now_url = str_replace($chr,$replace,$now_url);
return $now_url;
}
}