Поправил регулярку, разбивающую текст на предложения; Обработка внутренних ссылок;

This commit is contained in:
Krivchikov Dmitry 2014-11-16 13:06:30 +03:00
parent c0986a556d
commit 4203efc2c0
2 changed files with 27 additions and 2 deletions

View File

@ -6,4 +6,29 @@ class Helper
{ {
return (bool) $var; return (bool) $var;
} }
public static function replaceLinks($string)
{
preg_match_all("(\[#\d*\])", $string, $links);
$links = isset($links[0]) ? $links[0] : FALSE;
if ($links)
{
foreach ($links as $link)
{
$linkId = (int)mb_substr($link, 2, -1);
if ($linkId)
{
$linkPoint = Point::model()->getByPK($linkId);
if ($linkPoint->id)
{
$linkPoint->name = str_replace('"', 'ʺ', $linkPoint->name);
$string = str_replace($link, '[<a href="/page/point/id/'.$linkId.'" title="'.$linkPoint->name.'"><span class="glyphicon glyphicon-link"></span></a>]', $string);
}
}
}
}
return $string;
}
} }

View File

@ -74,8 +74,8 @@ class PageController extends Controller
$point->categoryIcon = $categories[$point->categoryId]['icon']; $point->categoryIcon = $categories[$point->categoryId]['icon'];
$point->categoryName = $categories[$point->categoryId]['name']; $point->categoryName = $categories[$point->categoryId]['name'];
preg_match_all("/.*?[.?!](?:\s|$)/s", $point->descriptionHtml, $items); $point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml);
preg_match_all("/.*?(([.?!](?:\s|$))|$)/s", $point->descriptionHtml, $items);
$randomPoint = Point::model()->getRandom(); $randomPoint = Point::model()->getRandom();
$similarPoints = Point::model()->getAll(array('where' => 'categoryId = '.$point->categoryId.' AND `id` <> '.$point->id.' ORDER BY RAND() LIMIT 6;')); $similarPoints = Point::model()->getAll(array('where' => 'categoryId = '.$point->categoryId.' AND `id` <> '.$point->id.' ORDER BY RAND() LIMIT 6;'));
$closestPoints = Point::model()->getClosestPoints($pointId); $closestPoints = Point::model()->getClosestPoints($pointId);