ADD возможность вставлять фотки в статьи в исходном размере

This commit is contained in:
Krivchikov Dmitry 2016-05-09 20:28:40 +03:00
parent 34b5d8300e
commit 1773cc8a2b
1 changed files with 9 additions and 4 deletions

View File

@ -63,14 +63,19 @@ class Helper
public static function replaceImgs($string, $replaceType = 'clear', $size = 'middle') public static function replaceImgs($string, $replaceType = 'clear', $size = 'middle')
{ {
preg_match_all("(\[img[\|]#(\d+)\])", $string, $images); preg_match_all("(\[img[\|]#(\d+)([\|](\w+))?\])", $string, $images);
$images = isset($images[0]) ? $images[0] : FALSE; $images = isset($images[0]) ? $images[0] : FALSE;
if ($images) { if ($images) {
foreach ($images as $img) { foreach ($images as $img) {
$imgAndId = mb_substr($img, 2, -1); $imgAndId = mb_substr($img, 2, -1);
$imgAndId = explode('#', $imgAndId); $imgAndId = explode('|', $imgAndId);
$imgId = (int)$imgAndId[1]; $imgId = intval(substr($imgAndId[1], 1));
$currentSize = '/'.$size;
if (isset($imgAndId[2]) && $imgAndId[2] == 'src') {
$currentSize = '';
}
$imgObj = ArticlePhotos::model()->getByPK($imgId); $imgObj = ArticlePhotos::model()->getByPK($imgId);
@ -78,7 +83,7 @@ class Helper
switch ($replaceType) { switch ($replaceType) {
case 'html': case 'html':
$imgObj->caption = $linkTitle = str_replace('"', 'ʺ', $imgObj->caption); $imgObj->caption = $linkTitle = str_replace('"', 'ʺ', $imgObj->caption);
$imgTag = '<div style="text-align: center;"><img src="/photos/articles/'.$size.'/' . $imgObj->name . '" title="' . $imgObj->caption . '" class="imageInArticle" /></div>'; $imgTag = '<div style="text-align: center;"><img src="/photos/articles'.$currentSize.'/' . $imgObj->name . '" title="' . $imgObj->caption . '" class="imageInArticle" /></div>';
$string = str_replace($img, $imgTag, $string); $string = str_replace($img, $imgTag, $string);
break; break;
default: default: