Вход Регистрация
Файл: apwa/includes/hooks/hook_urlname.php
Строк: 235
<?php

//
// phpBB hook_urlname
//
define('HOOK_URLNAME_VERSION','0.1.8-20140316');
//
// copyright (c) 2014 c61 http://c61.no-ip.org <c61@yandex.ru>
// license http://opensource.org/licenses/gpl-license.php GNU Public License
//

if (!defined('IN_PHPBB'))
{
    exit;
}

class 
URLNAME
{
    
// Выдавать отладочную информацию в 'DEBUG'
    
private $debug false;

    
// Настройки мода
    
private $use_iurl_title = array();
    private 
$use_iurl_strong = array();
    private 
$use_user_colour NULL;
    private 
$use_user_strong = array();
    private 
$use_wiki_strong = array();

    
// Разрешить корректировать фичи phpBB при обработке magic url
    
private $correct_phpbb_bugs true;
    
// Количество скорректированных фич
    
private $phpbb_bugs_corrected 0;

    
// Кэш для уменьшения количества sql-запросов
    
private $posts = array();
    private 
$topics = array();
    private 
$forums = array();
    private 
$users = array();

    
// Время кэширования sql в секундах (0 - отключено)
    
private $sql_cache_ttl 0;

    public function 
URLNAME()
    {
        global 
$phpEx$phpbb_seo$auth;

        
// Debug
        
if ($this->debug && $auth->acl_get('a_'))
        {
            global 
$db;

            
$this->t0 microtime();
            
$this->d0 $db->sql_num_queries();
            
$this->dc0 $db->sql_num_queries(true);
        }

        
// Настройки мода

        // Форумы, темы, сообщения
        // Использовать всплывающую подсказку (время размещения и номер сообщения) названий тем, сообщений
        
$this->use_iurl_title['use'] = true;
        
// Использовать выделение (тэги strong, i) названий форумов, тем, сообщений
        
$this->use_iurl_strong['use'] = true;
        
// Открывающй и закрывающий тэги выделения названий форумов, тем, сообщений
        
$this->use_iurl_strong['open'] = $this->use_iurl_strong['use'] ? '<strong><i>' '';
        
$this->use_iurl_strong['close'] = $this->use_iurl_strong['use'] ? '</i></strong>''';

        
// Пользователи
        // Использовать цвет ника пользователя
        
$this->use_user_colour true;
        
// Использовать выделение (тэг strong) ника пользователя
        
$this->use_user_strong['use'] = true;
        
// Открывающй и закрывающий тэги выделения ника пользователя
        
$this->use_user_strong['open'] = $this->use_user_strong['use'] ? '<strong>' '';
        
$this->use_user_strong['close'] = $this->use_user_strong['use'] ? '</strong>''';

        
// Ресурсы Wiki
        // Использовать выделение (тэг i) разделов wiki
        
$this->use_wiki_strong['use'] = true;
        
// Открывающй и закрывающий тэги выделения разделов wiki
        
$this->use_wiki_strong['open'] = $this->use_wiki_strong['use'] ? '<i>' '';
        
$this->use_wiki_strong['close'] = $this->use_wiki_strong['use'] ? '</i>''';
        
// Поиск URL
        
{
            
$this->wiki_search = array(
                
'/>http(.*?)://(S+).community.wikia.com/wiki/(.*?)</isu',
                
'/>http(.*?)://(S+).wikipedia.org/wiki/(.*?)</isu',
                
'/>http(.*?)://(S+).wikiquote.org/wiki/(.*?)</isu',
                
'/>http(.*?)://(S+).wikibooks.org/wiki/(.*?)</isu',
                
'/>http(.*?)://(wiki).phpbb.com/(.*?)</isu',
                
'/>http(.*?)://(wiki).wargaming.net/ru/(.*?)</isu',
                
'/>http(.*?)://(wiki).iteach.ru/index.php/(.*?)</isu',
                
'/>http(.*?)://(wiki).debian.org/(.*?)</isu',
                
'/>http(.*?)://(wiki).web.ru/wiki/(.*?)</isu',
                
'/>http(.*?)://(www.)*lurkmore.to/(.*?)</isu',
                
'/>http(.*?)://(www.)*sportswiki.ru/(.*?)</isu',
                
'/>http(.*?)://(www.)*altlinux.org/(.*?)</isu',
                
'/>http(.*?)://(S+).ageofstars.wikia.com/wiki/(.*?)</isu',
                
'/>http(.*?)://(S+).althistory.wikia.com/wiki/(.*?)</isu',
                
'/>http(.*?)://(S+).coincollecting.wikia.com/wiki/(.*?)</isu',
                
'/>http(.*?)://(S+).cybernetics.wikia.com/wiki/(.*?)</isu',
                
'/>http(.*?)://(S+).math.wikia.com/wiki/(.*?)</isu',
                
'/>http(.*?)://(S+).morfey13.wikia.com/wiki/(.*?)</isu',
                
'/>http(.*?)://(S+).prikolchik.wikia.com/wiki/(.*?)</isu',
                
'/>http(.*?)://(S+).russianhistory.wikia.com/wiki/(.*?)</isu',
                
'/>http(.*?)://(S+).science.wikia.com/wiki/(.*?)</isu',
                
'/>http(.*?)://(S+).pages.wikia.com/wiki/(.*?)</isu',
                
'/>http(.*?)://(S+).tarna-ilu.wikia.com/wiki/(.*?)</isu',
                
'/>http(.*?)://(www.)*mind-control.wikia.com/wiki/(.*?)</isu',
                
'/>http(.*?)://(www.)*absurdopedia.wikia.com/wiki/(.*?)</isu',
            );
        }

        
//-------------------------------------------------------------------------

        // Поиск для стандартных URL
        
{
            
$this->std_search = array(
    
//            вариант без учёта hilit=viewtopic/viewforum/memberlist
    //            'p'    =>    '/>viewtopic.'.$phpEx.'(.*?)[?|&|;]p=(d+)/isu',
    //            't'    =>    '/>viewtopic.'.$phpEx.'(.*?)[?|&|;]t=(d+)/isu',
    //            'f'    =>    '/>viewforum.'.$phpEx.'(.*?)[?|&|;]f=(d+)/isu',
    //            'u'    =>    '/>memberlist.'.$phpEx.'(.*?)[?|&|;]u=(d+)/isu',
    //            вариант с учётом hilit=viewtopic/viewforum/memberlist
                
'p'    =>    '/>(<spans*class="posthilit">|)viewtopic(</span>|).'.$phpEx.'(.*?)[?|&|;]p=(d+)/isu',
                
't'    =>    '/>(<spans*class="posthilit">|)viewtopic(</span>|).'.$phpEx.'(.*?)[?|&|;]t=(d+)/isu',
                
'f'    =>    '/>(<spans*class="posthilit">|)viewforum(</span>|).'.$phpEx.'(.*?)[?|&|;]f=(d+)/isu',
                
'u'    =>    '/>(<spans*class="posthilit">|)memberlist(</span>|).'.$phpEx.'(.*?)[?|&|;]u=(d+)/isu',
            );
        }

        
// Поиск для Simple SEO mod URL или SEO Ultimate SEO URL в режиме Simple
        
{
            
$this->sseo_search = array(
                
'p'    =>    '/>post(d+)(.*?).html(.*?)#p(d+)/isu',
                
'pt'    =>    '/>topic(d+)(.*?).html(.*?)#p(d+)/isu',
                
't'    =>    '/>topic(d+)(.*?).html/isu',
                
'f'    =>    '/>forum(d+).html/isu',
                
'u'    =>    '/>member(d+).html/isu',
            );
        }

        
// Поиск для Ultimate SEO mod URL
        
if (isset($phpbb_seo))
        {
            
$this->useo_search = array(
                
'p'    =>    '/>(.*?)-t(d+)(.*?).html(.*?)#p(d+)/isu',
                
't'    =>    '/>(.*?)-t(d+)(.*?).html/isu',
                
'f'    =>    '/>(.*?).html/isu',
                
'f-f'    =>    '/>(.*?)-f(d+).html/isu',
                
'u'    =>    '/>(.*?)-u(d+).html/isu',
            );
        }
    }

    private function 
do_urlname_debug($str)
    {
        if (
$this->debug)
        {
            global 
$template;

            if (isset(
$template->_rootref['DEBUG_OUTPUT']))
            {
                
$template->_rootref['DEBUG_OUTPUT'] = $str $template->_rootref['DEBUG_OUTPUT'];
            }
        }
    }

    public function 
do_urlname_end()
    {
        global 
$auth;

        if (
$this->debug && $auth->acl_get('a_'))
        {
            global 
$db;

            
$endtime explode(' 'microtime());
            
$starttime explode(' '$this->t0);
            
$starttime $starttime[1] + $starttime[0];
            
$totaltime $endtime[0] + $endtime[1] - $starttime;
            
$this->do_urlname_debug('<span style="cursor:help;" title="hook_urlname v.' HOOK_URLNAME_VERSION ' &bull; http://c61.no-ip.org">' sprintf('hUN Time : %.3fs | ' . ($db->sql_num_queries() - $this->d0) . '/' . ($db->sql_num_queries(true) - $this->dc0) . ' Queries'$totaltime) . (((isset($this->correct_phpbb_bugs) && $this->correct_phpbb_bugs) ? (' | ' $this->phpbb_bugs_corrected ' Magic urls corr`d') : '')) . '</span><br />');
        }
    }

    private function 
do_urlname_auth($forum_id$global POST_GLOBAL)
    {
        global 
$auth;

        if (!isset(
$this->forums[$forum_id]['auth']))
        {
            
$this->forums[$forum_id]['auth'] = $auth->acl_gets('f_list''f_read'$forum_id);
        }
        return ((
$global == POST_GLOBAL) || $this->forums[$forum_id]['auth']) ? true false;
    }

    private function 
do_urlname_not_url($str)
    {
        return (
strpos($str,'://') === false) ? true false;
    }

    public function 
do_urlname(&$item)
    {
        global 
$db$user$phpbb_seo;

        if(!isset(
$item)) return;

        
// Если нет тэгов a, то незачем что-либо пытаться делать
        
if (strpos($item,'<a ') === false) return;

        
// Разыскиваемые тэги
        // Будут исключены:
        // pre, code - это код и незачем...
        // script - скрипты тем более не трогаем
        
$tags = array();
        if (
strpos($item,'<pre') !== false)
        {
            
$tags[] = 'pre';
        }
        else if (
strpos($item,'<code') !== false)
        {
            
$tags[] = 'code';
        }
        if (
strpos($item,'<script') !== false)
        {
            
$tags[] = 'script';
        }
        
$ent = array();
        foreach(
$tags as $tag)
        {
            
// Поиск тэга
            
if(preg_match_all("/(?=(<$tag.*?>(?>(?1)|.)*?</$tag>))/isu",$item,$matches,PREG_OFFSET_CAPTURE))
            {
                foreach(
$matches[1] as $match)
                {
                    
// Собираем вхождения тэгов в массив 'индекс' => 'длина'
                    
$ent[(int) $match[1]] = (int) strlen($match[0]);
                }
            }
        }
        
// Добавляем пустышку - чтобы алгоритм обработал остатки текста за последним тэгом
        
$ent[(int) strlen($item)] = (int) 0;

        
// Сортируем по ключу, по возрастанию
        
if(ksort($ent))
        {
            
// Начальный индекс, новый текст
            
$start 0;
            
$newtext '';
            
// Проход по всем вхождениям
            
foreach($ent as $key => $val)
            {
                if(
$key $start)    // Индекс больше стартового ?
                
{
                    
// Да. Выделяем подстроку
                    
$substr substr($item,$start,$key-$start);

                    if (isset(
$this->correct_phpbb_bugs) && $this->correct_phpbb_bugs)
                    {
                        
// Исправление фичи phpbb:
                        // когда последний символ ссылки из ряда .,:! то этот символ теряется
                        //
                        // признаком является наличие </a><!-- m --> и
                        // проблемный символ
                        //
                        // проблемный символ следует добавить в конец ссылки и
                        // перенести на место перед </a>
                        //
                        // ВНИМАНИЕ !!! Перед установкой хука должен быть применён
                        // патч для корректной обработки url с кириллицей, входящий
                        // в комплект мода

                        
if (preg_match_all('/<!-- (m|w) --><a (.*?)href="http(.*?)://(.*?)"(.*?)>(.*?)</a><!-- (m|w) -->(.|,|:|!|?|)/isu',$substr.'<',$bugmatches,PREG_OFFSET_CAPTURE))
                        {
                            
$i = -1;
                            
$add 0;
                            foreach(
$bugmatches[8] as $bugmatch)
                            {
                                ++
$i;
                                switch (
$bugmatch[0])
                                {
                                    case 
'.':
                                    case 
',':
                                    case 
':':
                                    case 
'!':
                                    case 
'?':
                                        
$substr substr_replace($substr$bugmatch[0] . '</a><!-- ' $bugmatches[7][$i][0] . ' -->'$bugmatches[6][$i][1] + strlen($bugmatches[6][$i][0]) + $add15);
                                        
$substr substr_replace($substr$bugmatch[0], $bugmatches[4][$i][1] + strlen($bugmatches[4][$i][0]) + $add0);
                                        ++
$add;
                                        ++
$this->phpbb_bugs_corrected;
                                        break;
                                }
                            }
                        }
                    }

                    
// Поиск тэга <a...href="..."...>?</a>
                    
if (preg_match_all('/<a(.*?)href="(.*?)"(.*?)>(.*?)</a>/isu',$substr,$amatches))
                    {
                        
// Поиски и замены
                        
if (isset($searches)) unset($searches);
                        if (isset(
$replaces)) unset($replaces);
                        
$searches = array();
                        
$replaces = array();

                        
$i = -1;
                        foreach(
$amatches[4] as $amatch)
                        {
                            ++
$i;

                            
// Подготовка поиска
                            
$lamatch '>'.$amatch;
                            if (isset(
$search)) unset($search);
                            if (isset(
$replace)) unset($replace);
                            if (isset(
$strong)) unset($strong);
                            if (isset(
$title)) unset($title);

                            
// Проверяем на наличие ссылки в href с учётом hilit
                            
if (strpos(htmlspecialchars_decode($amatches[2][$i]),str_replace(array('<span class="posthilit">','</span>','./'),'',htmlspecialchars_decode($amatch))) !== false)
                            {
                                
// Поиск вариантов...
                                //if (!isset($search))
                                
{
                                    
// Поиск viewtopic.php?....p=? или аналога SEO
                                    
$post_id 0;
                                    if (isset(
$this->std_search)
                                     && 
preg_match($this->std_search['p'],$lamatch,$pmatch)
                                    
// вариант без учёта hilit=viewtopic
                                    // &&    !empty($pmatch[2])
                                    // вариант с учётом hilit=viewtopic
                                     
&&    !empty($pmatch[4])
                                        )
                                    {
                                        
// вариант без учёта hilit=viewtopic
                                        //$post_id = $pmatch[2];
                                        // вариант с учётом hilit=viewtopic
                                        
$post_id $pmatch[4];
                                    }
                                    else if (isset(
$this->sseo_search)
                                     &&      
preg_match($this->sseo_search['p'],$lamatch,$pmatch)
                                     &&      !empty(
$pmatch[4])
                                        )
                                    {
                                        
$post_id $pmatch[4];
                                    }
                                    else if (isset(
$this->sseo_search)
                                     &&      
preg_match($this->sseo_search['pt'],$lamatch,$pmatch)
                                     &&      !empty(
$pmatch[4])
                                        )
                                    {
                                        
$post_id $pmatch[4];
                                    }
                                    else if (isset(
$this->useo_search)
                                     &&      
preg_match($this->useo_search['p'],$lamatch,$pmatch)
                                     &&      !empty(
$pmatch[1])
                                     &&      
$this->do_urlname_not_url($pmatch[1])
                                     &&      !empty(
$pmatch[2])
                                     &&      !empty(
$pmatch[5])
                                        )
                                    {
                                        
$post_id $pmatch[5];
                                    }
                                    if (
$post_id)
                                    {
                                        if (empty(
$this->posts[$post_id]))
                                        {
                                            
$sql 'SELECT topic_id,forum_id,post_time,post_subject
                                                FROM ' 
POSTS_TABLE '
                                                WHERE post_id = ' 
$post_id;
                                            
$result $db->sql_query($sql,$this->sql_cache_ttl);
                                            
$row $db->sql_fetchrow($result);
                                            
$db->sql_freeresult($result);
                                            if (empty(
$row)) continue;

                                            if (
strpos($row['post_subject'],'Re: ') === 0)
                                            {
                                                
$row['post_subject'] = substr_replace($row['post_subject'],'',0,4);
                                            }

                                            
$this->posts[$post_id] = $row;
                                        }
                                        
$topic_id $this->posts[$post_id]['topic_id'];

                                        if (empty(
$this->topics[$topic_id]))
                                        {
                                            
$sql 'SELECT forum_id,topic_title,topic_time,topic_type,topic_first_post_id,topic_first_poster_name
                                                FROM ' 
TOPICS_TABLE '
                                                WHERE topic_id = ' 
$topic_id;
                                            
$result $db->sql_query($sql,$this->sql_cache_ttl);
                                            
$row $db->sql_fetchrow($result);
                                            
$db->sql_freeresult($result);

                                            
$this->topics[$topic_id] = $row;
                                        }

                                        if (empty(
$this->posts[$post_id]['post_subject']))
                                        {
                                            
$this->posts[$post_id]['post_subject'] = $this->topics[$topic_id]['topic_title'];
                                        }

                                        if (
$this->do_urlname_auth($this->posts[$post_id]['forum_id'], $this->topics[$topic_id]['topic_type']))
                                        {
                                            
$strong $this->use_iurl_strong;
                                            
$title $this->use_iurl_title;
                                            if (
$post_id == $this->topics[$topic_id]['topic_first_post_id'])
                                            {
                                                
$title['type'] = 'topic';
                                                
$title['username'] = $this->topics[$topic_id]['topic_first_poster_name'];
                                            }
                                            else
                                            {
                                                
$title['type'] = 'post';
                                                
$title['id'] = $post_id;
                                            }
                                            
$title['title'] = $this->topics[$topic_id]['topic_title'];
                                            
$title['time'] = $this->posts[$post_id]['post_time'];
                                            
$search '>'.$amatch.'<';
                                            
$replace '>'.censor_text($this->posts[$post_id]['post_subject']).'<';
                                        }
                                    }
                                }
                                if (!isset(
$search))
                                {
                                    
// Поиск viewtopic.php?....t=? или аналога SEO
                                    
$topic_id 0;
                                    if (isset(
$this->std_search)
                                     && 
preg_match($this->std_search['t'],$lamatch,$tmatch)
                                    
// вариант без учёта hilit=viewtopic
                                    // &&    !empty($tmatch[2])
                                    // вариант с учётом hilit=viewtopic
                                     
&&    !empty($tmatch[4])
                                        )
                                    {
                                    
// вариант без учёта hilit=viewtopic
                                    //    $topic_id = $tmatch[2];
                                    // вариант с учётом hilit=viewtopic
                                        
$topic_id $tmatch[4];
                                    }
                                    else if (isset(
$this->sseo_search)
                                     &&      
preg_match($this->sseo_search['t'],$lamatch,$tmatch)
                                     &&      !empty(
$tmatch[1])
                                        )
                                    {
                                        
$topic_id $tmatch[1];
                                    }
                                    else if (isset(
$this->useo_search)
                                     &&      
preg_match($this->useo_search['t'],$lamatch,$tmatch)
                                     &&      !empty(
$tmatch[1])
                                     &&      
$this->do_urlname_not_url($tmatch[1])
                                     &&      !empty(
$tmatch[2])
                                        )
                                    {
                                        
$topic_id $tmatch[2];
                                    }
                                    if (
$topic_id)
                                    {
                                        if (empty(
$this->topics[$topic_id]))
                                        {
                                            
$sql 'SELECT forum_id,topic_type,topic_title,topic_time,topic_first_post_id,topic_first_poster_name
                                                FROM ' 
TOPICS_TABLE '
                                                WHERE topic_id = ' 
$topic_id;
                                            
$result $db->sql_query($sql,$this->sql_cache_ttl);
                                            
$row $db->sql_fetchrow($result);
                                            
$db->sql_freeresult($result);
                                            if (empty(
$row)) continue;

                                            
$this->topics[$topic_id] = $row;
                                        }

                                        if (
$this->do_urlname_auth($this->topics[$topic_id]['forum_id'], $this->topics[$topic_id]['topic_type']))
                                        {
                                            
$strong $this->use_iurl_strong;
                                            
$title $this->use_iurl_title;
                                            
$title['type'] = 'topic';
                                            
$title['username'] = $this->topics[$topic_id]['topic_first_poster_name'];
                                            
$title['title'] = $this->topics[$topic_id]['topic_title'];
                                            
$title['time'] = $this->topics[$topic_id]['topic_time'];
                                            
$search '>'.$amatch.'<';
                                            
$replace '>'.censor_text($this->topics[$topic_id]['topic_title']).'<';
                                        }
                                    }
                                }
                                if (!isset(
$search))
                                {
                                    
// Поиск viewforum.php?....f=? или аналога SEO
                                    
$forum_id 0;
                                    if (isset(
$this->std_search)
                                     && 
preg_match($this->std_search['f'],$lamatch,$fmatch)
                                    
// вариант без учёта hilit=viewforum
                                    // &&    !empty($fmatch[2])
                                    // вариант с учётом hilit=viewforum
                                     
&&    !empty($fmatch[4])
                                        )
                                    {
                                        
// вариант без учёта hilit=viewforum
                                        //$forum_id = $fmatch[2];
                                        // вариант с учётом hilit=viewforum
                                        
$forum_id $fmatch[4];
                                    }
                                    else if (isset(
$this->sseo_search)
                                     &&      
preg_match($this->sseo_search['f'],$lamatch,$fmatch)
                                     &&      !empty(
$fmatch[1])
                                        )
                                    {
                                        
$forum_id $fmatch[1];
                                    }
                                    else if (isset(
$this->useo_search)
                                     &&      
preg_match($this->useo_search['f'],$lamatch,$fmatch)
                                     &&      !empty(
$fmatch[1])
                                     &&      
$this->do_urlname_not_url($fmatch[1])
                                     &&      (
$forum_id $phpbb_seo->get_forum_id($forum_id,$fmatch[1]))
                                        )
                                    {
                                        ;
                                    }
                                    else if (isset(
$this->useo_search)
                                     &&      
preg_match($this->useo_search['f-f'],$lamatch,$fmatch)
                                     &&      !empty(
$fmatch[1])
                                     &&      
$this->do_urlname_not_url($fmatch[1])
                                     &&      !empty(
$fmatch[2])
                                        )
                                    {
                                        
$forum_id $fmatch[2];
                                    }
                                    if (
$forum_id)
                                    {
                                        if (empty(
$this->forums[$forum_id]['forum_name']))
                                        {
                                            
$sql 'SELECT forum_name,forum_desc,forum_type
                                                FROM ' 
FORUMS_TABLE '
                                                WHERE forum_id = ' 
$forum_id;
                                            
$result $db->sql_query($sql,$this->sql_cache_ttl);
                                            
$row $db->sql_fetchrow($result);
                                            
$db->sql_freeresult($result);
                                            if (empty(
$row)) continue;

                                            
$this->forums[$forum_id]['forum_name'] = $row['forum_name'];
                                            
$this->forums[$forum_id]['forum_desc'] = $row['forum_desc'];
                                            
$this->forums[$forum_id]['forum_type'] = $row['forum_type'];
                                        }

                                        if (
$this->do_urlname_auth($forum_id))
                                        {
                                            
$strong $this->use_iurl_strong;
                                            
$title $this->use_iurl_title;
                                            
$title['type'] = ($this->forums[$forum_id]['forum_type'] == FORUM_CAT) ? 'category' 'forum';
                                            
$title['title'] = $this->forums[$forum_id]['forum_name'] . (!empty($this->forums[$forum_id]['forum_desc']) ? (': '.$this->forums[$forum_id]['forum_desc']) : '');
                                            
$search '>'.$amatch.'<';
                                            
$replace '>'.$this->forums[$forum_id]['forum_name'].'<';
                                        }
                                    }
                                }
                                if (!isset(
$search))
                                {
                                    
// Поиск memberlist.php?....u=? или аналога SEO
                                    
$user_id 0;
                                    if (isset(
$this->std_search)
                                     && 
preg_match($this->std_search['u'],$lamatch,$umatch)
                                    
// вариант без учёта hilit=memberlist
                                    // &&    !empty($umatch[2])
                                    // вариант с учётом hilit=memberlist
                                     
&&    !empty($umatch[4])
                                        )
                                    {
                                        
// вариант без учёта hilit=memberlist
                                        //$user_id = $umatch[2];
                                        // вариант с учётом hilit=memberlist
                                        
$user_id $umatch[4];
                                    }
                                    else if (isset(
$this->sseo_search)
                                     &&      
preg_match($this->sseo_search['u'],$lamatch,$umatch)
                                     &&      !empty(
$umatch[1])
                                        )
                                    {
                                        
$user_id $umatch[1];
                                    }
                                    else if (isset(
$this->useo_search)
                                     &&      
preg_match($this->useo_search['u'],$lamatch,$umatch)
                                     &&      !empty(
$umatch[1])
                                     &&      
$this->do_urlname_not_url($umatch[1])
                                     &&      !empty(
$umatch[2])
                                        )
                                    {
                                        
$user_id $umatch[2];
                                    }
                                    if (
$user_id)
                                    {
                                        if (empty(
$this->users[$user_id]))
                                        {
                                            
$sql 'SELECT username,user_colour
                                                FROM ' 
USERS_TABLE '
                                                WHERE user_id = ' 
$user_id;
                                            
$result $db->sql_query($sql,$this->sql_cache_ttl);
                                            
$row $db->sql_fetchrow($result);
                                            
$db->sql_freeresult($result);
                                            if (empty(
$row)) continue;

                                            if (
$user_id == ANONYMOUS)
                                            {
                                                
$row['username'] = $user->lang['GUEST'];
                                            }

                                            
$this->users[$user_id] = $row;
                                        }

                                        if (!empty(
$this->users[$user_id]['username']))
                                        {
                                            if (
$this->use_user_colour)
                                            {
                                                
$search $amatches[0][$i];
                                                
$replace = ($this->use_user_strong['use'] ? $this->use_user_strong['open'] : '').get_username_string('full'$user_id$this->users[$user_id]['username'], $this->users[$user_id]['user_colour']).($this->use_user_strong['use'] ? $this->use_user_strong['close'] : '');
                                            }
                                            else
                                            {
                                                
$strong $this->use_user_strong;
                                                
$search '>'.$amatch.'<';
                                                
$replace '>'.$this->users[$user_id]['username'].'<';
                                            }
                                        }
                                    }
                                }
                            }

                            
// Wiki
                            
if (!isset($search) && isset($this->wiki_search) && ((strpos($amatch,'http://') === 0) || (strpos($amatch,'https://') === 0)))
                            {
                                
$wiki_long = (strpos($amatch,' ... ') !== false) ? true false;
                                
$lruamatch '>'.urldecode($amatch).'<';
                                
$lru2amatch '>'.urldecode($amatches[2][$i]).'<';
                                foreach (
$this->wiki_search as $wiki)
                                {
                                    if (
$wiki_long)
                                    {
                                        if (!
preg_match($wiki,$lruamatch,$wmatch)) continue;
                                        if (empty(
$wmatch[3])) continue;
                                    }
                                    if(
preg_match($wiki,$lru2amatch,$hmatch))
                                    {
                                        
$wiki_topic str_replace('_',' ',$hmatch[3]);
                                        if ((
$p strpos($wiki_topic,'#')) !== false)
                                        {
                                            
$wiki_subtopic substr($wiki_topic,$p 1);
                                            if (
preg_match('/.([0-9A-Z]{2})/i'$wiki_subtopic))
                                            {
                                                
$wiki_subtopic str_replace('%','.',urldecode(str_replace('.''%'$wiki_subtopic)));
                                            }
                                            
$wiki_topic substr($wiki_topic,0,$p) . ': ' $wiki_subtopic;
                                        }
                                        
$wiki_topic htmlspecialchars(str_replace(':',': ',$wiki_topic));
                                        if (!empty(
$wiki_topic))
                                        {
                                            
$strong $this->use_wiki_strong;
                                            
$search '>'.$amatch.'<';
                                            
$replace '>'.$wiki_topic.'<';
                                        }
                                        break;
                                    }
                                }
                            }

                            
// Обработка поисков и замен в подстроке
                            
if (isset($search) && isset($replace))
                            {
                                if (!
in_array($amatches[0][$i],$searches))
                                {
                                    
$a_replace $amatches[0][$i];
                                    
$do_a_replace false;
                                    if (isset(
$title) && $title['use'] && !empty($title['type']) && !preg_match('/title="(.*?)"/isu'$a_replace))
                                    {
                                        
$ar '<a title="';
                                        switch (
$title['type'])
                                        {
                                            case 
'post':
                                                
$ar .= $user->lang('MESSAGE').' #'.$title['id'].' &bull; ';
                                            case 
'topic':
                                                
$ar .= $user->lang('TOPIC').' &laquo;'.$title['title'].'&raquo;';
                                                break;
                                            case 
'forum':
                                                
$ar .= $user->lang('FORUM').' &laquo;'.$title['title'].'&raquo;';
                                                break;
                                            case 
'category':
                                                
$ar .= $user->lang('FORUM_CAT').' &laquo;'.$title['title'].'&raquo;';
                                                break;
                                        }
                                        if (!empty(
$title['username']))
                                        {
                                            
$ar .= ' &bull; '.$user->lang('AUTHOR').' '.$title['username'];
                                        }
                                        if (!empty(
$title['time']))
                                        {
                                            
$ar .= ' &bull; '.$user->lang('POST_TIME').' '.$user->format_date($title['time'], falsefalse);
                                        }
                                        
$ar .= '" ';
                                        
$a_replace str_replace('<a ',$ar,$a_replace);
                                        
$do_a_replace true;
                                    }
                                    if (isset(
$strong) && $strong['use'] && !in_array($amatches[0][$i],$searches) && !empty($strong['open']) && !empty($strong['close']))
                                    {
                                        
$a_replace $strong['open'].$a_replace.$strong['close'];
                                        
$do_a_replace true;
                                    }
                                    if (
$do_a_replace)
                                    {
                                        
$searches[] = $amatches[0][$i];
                                        
$replaces[] = $a_replace;
                                    }
                                }
                                if (!
in_array($search,$searches))
                                {
                                    
$searches[] = $search;
                                    
$replaces[] = $replace;
                                }
                            }
                        }
                        
$substr = @str_replace($searches$replaces$substr);
                    }

                    
// Отправляем подстроку с заменами и тэги в результирующий текст
                    
$newtext .= $substr . ($val substr($item,$key,$val) : '');
                    
// Переопределяем начальный индекс
                    
$start $key $val;
                }
            }

            
// Если всё нормально - переопределяем текст сообщения
            
if($newtext != '')
            {
                
$item $newtext;
            }
        }
    }

}

function 
urlname()
{
    global 
$template;

    if (isset(
$template->_tpldata['postrow']))
    {
        
$urlname = new URLNAME();
        foreach(
$template->_tpldata['postrow'] as $key => $val)
        {
            
$urlname->do_urlname($template->_tpldata['postrow'][$key]['MESSAGE']);
        }
        
$urlname->do_urlname_end();
    }
    else if (isset(
$template->_rootref['PREVIEW_MESSAGE']))
    {
        
$urlname = new URLNAME();
        
$urlname->do_urlname($template->_rootref['PREVIEW_MESSAGE']);
        if(isset(
$template->_tpldata['topic_review_row']))
        {
            foreach(
$template->_tpldata['topic_review_row'] as $key => $val)
            {
                
$urlname->do_urlname($template->_tpldata['topic_review_row'][$key]['MESSAGE']);
            }
        }
        
$urlname->do_urlname_end();
    }
    else if (isset(
$template->_rootref['MESSAGE']))
    {
        
$urlname = new URLNAME();
        
$urlname->do_urlname($template->_rootref['MESSAGE']);
        if(isset(
$template->_tpldata['history_row']))
        {
            foreach(
$template->_tpldata['history_row'] as $key => $val)
            {
                
$urlname->do_urlname($template->_tpldata['history_row'][$key]['MESSAGE']);
            }
        }
        
$urlname->do_urlname_end();
    }
}

// Регистрируем хук
$phpbb_hook->register(array('template''display'), 'urlname');

?>
Онлайн: 0
Реклама