From 4203efc2c0d2be758cbd41b2e45088e00d3f841b Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Sun, 16 Nov 2014 13:06:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=80=D0=B5=D0=B3=D1=83=D0=BB=D1=8F=D1=80=D0=BA=D1=83?= =?UTF-8?q?,=20=D1=80=D0=B0=D0=B7=D0=B1=D0=B8=D0=B2=D0=B0=D1=8E=D1=89?= =?UTF-8?q?=D1=83=D1=8E=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=B4=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F;=20=D0=9E=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B2=D0=BD=D1=83=D1=82=D1=80=D0=B5=D0=BD=D0=BD=D0=B8?= =?UTF-8?q?=D1=85=20=D1=81=D1=81=D1=8B=D0=BB=D0=BE=D0=BA;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ground/classes/Helper.php | 25 +++++++++++++++++++++++++ ground/controllers/PageController.php | 4 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ground/classes/Helper.php b/ground/classes/Helper.php index d4e2f70..aa108ab 100644 --- a/ground/classes/Helper.php +++ b/ground/classes/Helper.php @@ -6,4 +6,29 @@ class Helper { 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, '[]', $string); + } + } + } + } + + return $string; + } } diff --git a/ground/controllers/PageController.php b/ground/controllers/PageController.php index 89c7d40..44bd993 100644 --- a/ground/controllers/PageController.php +++ b/ground/controllers/PageController.php @@ -74,8 +74,8 @@ class PageController extends Controller $point->categoryIcon = $categories[$point->categoryId]['icon']; $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(); $similarPoints = Point::model()->getAll(array('where' => 'categoryId = '.$point->categoryId.' AND `id` <> '.$point->id.' ORDER BY RAND() LIMIT 6;')); $closestPoints = Point::model()->getClosestPoints($pointId);