Отрисовка баннеров и обработка кликов

@param string $text HTML страницы
@return string  HTML страницы
352566
public function clientOnPageRender($text)
    {
        $Eresus = Eresus_CMS::getLegacyKernel();
        /** @var TClientUI $page */
        $page = Eresus_Kernel::app()->getPage();
        if (arg('banners-click'))
        {
            /*
             * Если передан аргумент banners-click, надо перенаправить польщователя на URL баннера
             */
            if (count($Eresus->request['arg']) != 1)
            {
                $page->httpError(404);
            }

            $id = arg('banners-click', 'int');
            if ($id == '' | $id != arg('banners-click'))
            {
                $page->httpError(404);
            }

            $this->processClick($id);

        }
        else
        {
            $repo = Banners_Repository::getInstance();
            // Ищем все места вставки баннеров
            preg_match_all('/\$\(Banners:([^)]+)\)/', $text, $blocks,
                PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
            $delta = 0;
            foreach ($blocks as $block)
            {
                // Получаем баннеры для этого блока в порядке уменьшения приоритета
                $query = $repo->getQuery();
                $query
                    ->activeOnly()
                    ->forSection($page->id)
                    ->forBlock($block[1][0])
                    ->orderBy('priority', ezcQuerySelect::DESC); // TODO!
                $banners = $query->fetchAll();
                if (count($banners))
                {
                    /* Отсекаем баннеры с низким приоритетом */
                    $priority = $banners[0]->getPriority();
                    for ($i = 0; $i < count($banners); $i++)
                    {
                        if ($banners[$i]->getPriority() != $priority)
                        {
                            $banners = array_slice($banners, 0, $i);
                            break;
                        }
                    }

                    // Выбираем случайный баннер
                    $banner = $banners[mt_rand(0, count($banners) - 1)];
                    $banner->incShows();
                    $repo->save($banner);

                    $code = $banner->render();
                    $text = substr_replace($text, $code, $block[0][1] + $delta, strlen($block[0][0]));
                    $delta += strlen($code) - strlen($block[0][0]);
                }
            }
            $items = $Eresus->db->select($this->table['name'],
                "`active` = 1 AND (`showCount` != 0 AND `shows` > `showCount`) AND ((`showTill` < '" .
                gettime() . "') AND (`showTill` != '0000-00-00'))");
            if (count($items))
            {
                foreach ($items as $item)
                {
                    /* sendMail($item['mail'], 'Ваш баннер деактивирован', 'Ваш баннер "'.$item['caption'].
                     ' был отключен, т.к. так как превышены количество показов либо дата показа."'); */
                    sendMail(option('sendNotifyTo'), 'Баннер деактивирован', 'Баннер "' .
                        $item['caption'] . ' был отключен системой управления сайтом."');
                }
                $Eresus->db->update($this->table['name'],
                    "`active`='0'", "(`showCount` != 0 AND `shows` > `showCount`) AND ((`showTill` < '" .
                    gettime() . "') AND (`showTill` != '0000-00-00'))");
            }
        }
        return $text;
    }
393865
protected function renderText($text)
	{
		if ($this->enableNewlines) {
			return preg_replace("/(  \n|\n)/", "\\\\\\\\\n", $this->escapeLatex($text[1]));
		} else {
			return parent::renderText($text);
		}
	}
1368675
private function prettify($text)
    {
        if (strpos($this->template, '{ext}') !== false || strpos($text, '.') !== false) {
            // Check to see if the file is index.html already
            if (strpos($text, 'index.') === false) {
                $parts = explode('.', $text);
                $text = array_shift($parts);
                $ext = array_shift($parts);

                return $text.'/index.'.$ext;
            }
        }

        return $text;
    }
770423
protected function getActivePageWrapper($text)
    {
        $color = '';

        if ($this->color) {
            $color = $this->color;
        }

        return '<li class="active ' . $color . '"><a>' . $text . '</a></li>';
    }
300659
public function html2text($html)
    {
        if (!$this->html2textLoaded) {
            require dirname(__FILE__).'/../Utility/Html2Text.php';
            $this->html2textLoaded = true;
        }
        $html2text = new Html2Text($html);

        return $html2text->get_text();
    }
689199
public function convertToUrl($text)
    {
        $text =$this->convertToCode($text);
        $text = str_replace("_", "-", $text);
        return $text;
    }
709183
public function convertCharacters($text)
    {
        $text = html_entity_decode($text, ENT_QUOTES, $this->decode_charset);
        $text = strtr($text, $this->translation_table);

        return $text;
    }
1198116
public function showMoreFilter($text)
    {
        // <!--more--></div>
        $text = str_replace('<!--more--></div>', '</div><!--more-->', $text);

        $text_array = explode('<!--more-->', $text, 2);

        if (2 === \count($text_array) && $text_array[0] && $text_array[1]) {
            $result = '<div class="show-more-block">';

            $result .= '<div class="show-more-teaser">' . $text_array[0] . '</div>';
            $result .= '<div class="show-more-complete">' . $text_array[1] . '</div>';
            $result .= '<div class="show-more-button"><span class="link">Подробнее...</span></div>';

            $result .= '</div>';

            return $result;
        }

        return $text;
    }
855888
public function label($text)
    {
        $label = self::createElement('label');

        if (isset($this->attributeList['id'])) {
            $label->refer($this->attributeList['id']);
        }

        return $label->text($this)
            ->text($text);
    }
1209446
protected function parse_markdown( $text ) {
		static $markdown = null;

		if ( null === $markdown ) {
			$markdown = new Parsedown();
		}

		return $markdown->text( $text );
	}
896853
public static function markdownProcessor($text)
    {
        $MarkdownParser = static::getMarkdownParser();
        $text = $MarkdownParser->parse($text);
        $text = static::emailToLink($text);
        $text = str_replace('<p>h', '<p> h', $text);
        $text = static::urlToLink($text);

        return $text;
    }
643309
function borkify( $text )
    {
        $textBlocks = preg_split( "/(%[^ ]+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
        $newTextBlocks = array();
        foreach ( $textBlocks as $text )
        {
            if ( $text[0] == '%' )
            {
                $newTextBlocks[] = $text;
                continue;
            }
            $orgtext = $text;
            $text = preg_replace( "/a\B/", "e", $text );
            $text = preg_replace( "/an/", "un", $text );
            $text = preg_replace( "/au/", "oo", $text );
            $text = preg_replace( "/en\b/", "ee", $text );
            $text = preg_replace( "/\Bew/", "oo", $text );
            $text = preg_replace( "/\Bf/", "ff", $text );
            $text = preg_replace( "/\Bi/", "ee", $text );
            $text = preg_replace( "/\Bir/", "ur", $text );
            $text = preg_replace( "/\bo/", "oo", $text );
            $text = preg_replace( "/ow/", "oo", $text );
            $text = preg_replace( "/ph/", "f", $text );
            $text = preg_replace( "/th\b/", "t", $text );
            $text = preg_replace( "/\Btion/", "shun", $text );
            $text = preg_replace( "/\Bu/", "oo", $text );
            $text = preg_replace( "/\bU/", "Oo", $text );
            $text = preg_replace( "/y\b/", "ai", $text );
            $text = preg_replace( "/v/", "f", $text );
            $text = preg_replace( "/w/", "v", $text );
            $text = preg_replace( "/ooo/", "oo", $text );
            if ( $orgtext == $text )
                $text = $text . "-a";
            $newTextBlocks[] = $text;
        }
        $text = implode( '', $newTextBlocks );
        $text = preg_replace( "/([:.?!])(.*)/", "\\2\\1", $text );
        $text = "[" . $text . "]";
        return $text;
    }
1313010
protected function sanitize_text( $text ) {
		// not fancy
		$text = strip_tags( $text );
		$text = esc_html( $text );
		$text = trim( $text );

		return $text;
	}
449875
public function parse(string $text) : string
    {
        $tokens = $this->tokenizer->tokenize($text);
        $segments = $this->createSegments($tokens);
        $nodes = $this->createTree($segments);
        return $this->generator->generateMarkup($nodes);
    }
81941
public static function cleanText($text): string
    {
        return html_entity_decode(self::oneSpace(str_replace(' ?', '', mb_convert_encoding(strip_tags($text), 'UTF-8', 'UTF-8'))));
    }
1202886
public function clientBeforeSend($text)
    {
        $local_part = '[\d\wа-я][\d\wа-я\.\-]*';
        $server_part = '[\d\wа-я][\d\wа-я\-\.]+\.(\w{2,}|рф)';
        if ($this->settings['href_method'] != 'none')
        {
            preg_match_all('/<a\s+.*href="mailto:([^"]+)"(.*)>/ui', $text, $matches,
                PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
            $delta = 0;
            for ($i = 0; $i < count($matches); $i++)
            {
                $replace = $this->encodeHref($matches[$i][1][0]);
                $text = substr_replace($text, $replace, $matches[$i][1][1] + $delta,
                    strlen($matches[$i][1][0]));
                $delta += strlen($replace) - strlen($matches[$i][1][0]);
            }
        }
        if ($this->settings['text_method'] != 'none')
        {
            preg_match_all('/(mailto:)?' . $local_part . '@' . $server_part . '/ui', $text, $matches,
                PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
            $delta = 0;
            for ($i = 0; $i < count($matches); $i++)
            {
                if (strpos($matches[$i][0][0], 'mailto:') === false)
                {
                    $replace = $this->encodeText($matches[$i][0][0]);
                    $text = substr_replace($text, $replace, $matches[$i][0][1] + $delta,
                        strlen($matches[$i][0][0]));
                    $delta += strlen($replace) - strlen($matches[$i][0][0]);
                }
            }
        }
        return $text;
    }
1294797
public function apply($text)
    {
        $foreground = null;
        $background = null;

        if($this->foreground)
            $foreground = 'color: ' . $this->foreground . ';';

        if($this->background)
            $background = 'background: ' . $this->background . ';';

        $dom = '<span style="'.$foreground.$background.'">' . $text . '</span>';

        return $dom;
    }