52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?php
|
|
|
|
class Helper
|
|
{
|
|
public static function boolval($var)
|
|
{
|
|
return (bool) $var;
|
|
}
|
|
|
|
public static function replaceLinks($string, $linkTemplate = '/page/point/id/')
|
|
{
|
|
preg_match_all("(\[#(\d+)>?(.*?)\])", $string, $links);
|
|
$links = isset($links[0]) ? $links[0] : FALSE;
|
|
if ($links)
|
|
{
|
|
foreach ($links as $link)
|
|
{
|
|
$idAndLink = mb_substr($link, 2, -1);
|
|
$idAndLink = explode('>', $idAndLink);
|
|
|
|
$linkId = $idAndLink[0];
|
|
$linkName = isset($idAndLink[1])?$idAndLink[1]:'<span class="glyphicon glyphicon-link"></span>';
|
|
|
|
if ($linkId)
|
|
{
|
|
$linkPoint = Point::model()->getByPK($linkId);
|
|
if ($linkPoint->id)
|
|
{
|
|
$linkPoint->name = str_replace('"', 'ʺ', $linkPoint->name);
|
|
$string = str_replace($link, '<a href="'.$linkTemplate.$linkId.'" title="'.$linkPoint->name.'">'.$linkName.'</a>', $string);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $string;
|
|
}
|
|
|
|
public static function buildOG($point)
|
|
{
|
|
$og = array();
|
|
$og['title'] = $point->name . ' [wikipoints.ru]';
|
|
$og['description'] = mb_substr($point->description, 0, 200).'...';
|
|
$og['site_name'] = 'WikiPoints: Лучшие выходные - это выходные в путешествии!';
|
|
$og['type'] = 'article';
|
|
$og['url'] = 'http://wikipoints.ru/?point=' . $point->id;
|
|
$og['image'] = $point->getImg();
|
|
|
|
return $og;
|
|
}
|
|
}
|