Переделал замену ссылок в wiki-разметке
This commit is contained in:
parent
1348709a62
commit
f50413b1d4
|
|
@ -8,9 +8,15 @@ class Helper
|
||||||
return (bool) $var;
|
return (bool) $var;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function replaceLinks($string, $linkTemplate = '/page/point/id/')
|
/**
|
||||||
|
* TYPES: 'clear','html','js'
|
||||||
|
* @param type $string
|
||||||
|
* @param type $replaceType
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
public static function replaceLinks($string, $replaceType = 'clear')
|
||||||
{
|
{
|
||||||
preg_match_all("(\[#(\d+)[>\|](.*?)\])", $string, $links);
|
preg_match_all("((\[#(\d+)[>\|](.*?)\])|(\[#(\d+)\]))", $string, $links);
|
||||||
$links = isset($links[0]) ? $links[0] : FALSE;
|
$links = isset($links[0]) ? $links[0] : FALSE;
|
||||||
if ($links) {
|
if ($links) {
|
||||||
foreach ($links as $link) {
|
foreach ($links as $link) {
|
||||||
|
|
@ -19,13 +25,26 @@ class Helper
|
||||||
$idAndLink = explode($delimiter, $idAndLink);
|
$idAndLink = explode($delimiter, $idAndLink);
|
||||||
|
|
||||||
$linkId = $idAndLink[0];
|
$linkId = $idAndLink[0];
|
||||||
$linkName = isset($idAndLink[1]) ? $idAndLink[1] : '<span class="glyphicon glyphicon-link"></span>';
|
$linkName = isset($idAndLink[1]) ? $idAndLink[1] : '';
|
||||||
|
|
||||||
if ($linkId) {
|
if ($linkId) {
|
||||||
$linkPoint = Point::model()->getByPK($linkId);
|
$linkPoint = Point::model()->getByPK($linkId);
|
||||||
if ($linkPoint->id) {
|
if ($linkPoint && $linkPoint->id) {
|
||||||
$linkPoint->name = str_replace('"', 'ʺ', $linkPoint->name);
|
$linkTitle = str_replace('"', 'ʺ', $linkPoint->name);
|
||||||
$string = str_replace($link, '<a href="' . $linkTemplate . $linkId . '" title="' . $linkPoint->name . '">' . $linkName . '</a>', $string);
|
|
||||||
|
switch ($replaceType) {
|
||||||
|
case 'html':
|
||||||
|
$linkName = $linkName ? $linkName : '<span class="glyphicon glyphicon-link"></span>';
|
||||||
|
$string = str_replace($link, '<a href="/page/point/id/' . $linkId . '" title="' . $linkTitle . '">' . $linkName . '</a>', $string);
|
||||||
|
break;
|
||||||
|
case 'js':
|
||||||
|
$linkName = $linkName ? $linkName : '<span class="glyphicon glyphicon-link"></span>';
|
||||||
|
$string = str_replace($link, '<a href="/?point=' . $linkId . '" title="' . $linkTitle . '">' . $linkName . '</a>', $string);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$string = str_replace($link, $linkName, $string);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ class JsonController extends Controller
|
||||||
$point = Point::model()->getByPK($id);
|
$point = Point::model()->getByPK($id);
|
||||||
|
|
||||||
$point->descriptionHtml = nl2br($point->description);
|
$point->descriptionHtml = nl2br($point->description);
|
||||||
$point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml, '/?point=');
|
$point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml, 'js');
|
||||||
$point->name = htmlspecialchars($point->name);
|
$point->name = htmlspecialchars($point->name);
|
||||||
$point->moderate = $point->moderate ? 'show' : 'hide';
|
$point->moderate = $point->moderate ? 'show' : 'hide';
|
||||||
$imgs = $point->photos;
|
$imgs = $point->photos;
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ 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'];
|
||||||
$point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml);
|
$point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml, 'html');
|
||||||
// preg_match_all("/.*?(([.?!](?:\s|$))|$)/s", $point->descriptionHtml, $items);
|
// preg_match_all("/.*?(([.?!](?:\s|$))|$)/s", $point->descriptionHtml, $items);
|
||||||
preg_match_all("/.*?((([^.?!\s]{3,}?)[.?!](?:\s|$))|$)/s", $point->descriptionHtml, $items);
|
preg_match_all("/.*?((([^.?!\s]{3,}?)[.?!](?:\s|$))|$)/s", $point->descriptionHtml, $items);
|
||||||
$point->inFavorites = Favorite::model()->checkIsMy($pointId);
|
$point->inFavorites = Favorite::model()->checkIsMy($pointId);
|
||||||
|
|
@ -220,7 +220,7 @@ class PageController extends Controller
|
||||||
|
|
||||||
$categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true));
|
$categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true));
|
||||||
|
|
||||||
$point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml);
|
$point->description = Helper::replaceLinks($point->description);
|
||||||
|
|
||||||
self::renderPartial('vkPoint.php', array(
|
self::renderPartial('vkPoint.php', array(
|
||||||
'point' => $point,
|
'point' => $point,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue