При сохранении статьи проводится маркдаун-процессинг, сохраняется ID первой фотки
This commit is contained in:
parent
e034a2819b
commit
cc16b420d2
|
|
@ -62,11 +62,11 @@ class Helper
|
||||||
$imgAndId = mb_substr($img, 2, -1);
|
$imgAndId = mb_substr($img, 2, -1);
|
||||||
$imgAndId = explode('#', $imgAndId);
|
$imgAndId = explode('#', $imgAndId);
|
||||||
|
|
||||||
$imgId = $imgAndId[1];
|
$imgId = (int)$imgAndId[1];
|
||||||
|
|
||||||
$imgObj = ArticlePhotos::model()->getByPK($imgId);
|
$imgObj = ArticlePhotos::model()->getByPK($imgId);
|
||||||
|
|
||||||
if ($imgObj) {
|
if ($imgObj->name) {
|
||||||
switch ($replaceType) {
|
switch ($replaceType) {
|
||||||
case 'html':
|
case 'html':
|
||||||
$imgObj->caption = $linkTitle = str_replace('"', 'ʺ', $imgObj->caption);
|
$imgObj->caption = $linkTitle = str_replace('"', 'ʺ', $imgObj->caption);
|
||||||
|
|
@ -78,6 +78,17 @@ class Helper
|
||||||
$string = str_replace($img, $imgTag, $string);
|
$string = str_replace($img, $imgTag, $string);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
switch ($replaceType) {
|
||||||
|
case 'html':
|
||||||
|
$imgTag = '<div style="text-align: center;"><img src="/img/noPhoto.png" title="Фотография потерялась" class="imageInArticle" /></div>';
|
||||||
|
$string = str_replace($img, $imgTag, $string);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$imgTag = '';
|
||||||
|
$string = str_replace($img, $imgTag, $string);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -85,6 +96,19 @@ class Helper
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getFirstImg($string)
|
||||||
|
{
|
||||||
|
preg_match_all("(\[img[\|]#(\d+)\])", $string, $images);
|
||||||
|
$images = isset($images[0]) ? $images[0] : FALSE;
|
||||||
|
$img = isset($images[0]) ? $images[0] : FALSE;
|
||||||
|
if ($img) {
|
||||||
|
$imgId = (int) mb_substr($img, 6, -1);
|
||||||
|
$imgObj = ArticlePhotos::model()->getByPK($imgId);
|
||||||
|
return $imgObj->name ? (int)$imgObj->id : 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static function buildOG($point)
|
public static function buildOG($point)
|
||||||
{
|
{
|
||||||
$og = array();
|
$og = array();
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@ class Markdown
|
||||||
static function processing($string)
|
static function processing($string)
|
||||||
{
|
{
|
||||||
$string = self::replaceHeaders($string);
|
$string = self::replaceHeaders($string);
|
||||||
$string = self::replaceBoldItalic($string);
|
|
||||||
$string = self::replaceBold($string);
|
$string = self::replaceBold($string);
|
||||||
$string = self::replaceItalic($string);
|
$string = self::replaceItalic($string);
|
||||||
$string = self::replaceUnderline($string);
|
$string = self::replaceUnderline($string);
|
||||||
$string = self::replaceUrls($string);
|
$string = self::replaceUrls($string);
|
||||||
|
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,14 +33,7 @@ class Markdown
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
static private function replaceBoldItalic($string)
|
static private function replaceBold($string)
|
||||||
{
|
|
||||||
$pr = '(\*{3}(.+?)\*{3})';
|
|
||||||
$rep = '<b><i>$1</i></b>';
|
|
||||||
return preg_replace($pr, $rep, $string);
|
|
||||||
}
|
|
||||||
|
|
||||||
static private function replaceBold($string)
|
|
||||||
{
|
{
|
||||||
$pr = '(\*{2}(.+?)\*{2})';
|
$pr = '(\*{2}(.+?)\*{2})';
|
||||||
$rep = '<b>$1</b>';
|
$rep = '<b>$1</b>';
|
||||||
|
|
@ -64,7 +57,7 @@ class Markdown
|
||||||
static private function replaceUrls($string)
|
static private function replaceUrls($string)
|
||||||
{
|
{
|
||||||
$pr = '((https{0,1}:\/\/[\da-z\.-]+\.[a-z]{2,6})[\/\w\?=&#%+\.,-]*\/?)';
|
$pr = '((https{0,1}:\/\/[\da-z\.-]+\.[a-z]{2,6})[\/\w\?=&#%+\.,-]*\/?)';
|
||||||
$rep = '<a href="$0" target="_blank">$1</a>';
|
$rep = '<a href="$0" title="$0" target="_blank">$1</a>';
|
||||||
return preg_replace($pr, $rep, $string);
|
return preg_replace($pr, $rep, $string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,12 @@ class ArticlesController extends Controller
|
||||||
$id = (int) $_POST['id'];
|
$id = (int) $_POST['id'];
|
||||||
$title = $_POST['title'];
|
$title = $_POST['title'];
|
||||||
$text = $_POST['text'];
|
$text = $_POST['text'];
|
||||||
$text = strip_tags($text);
|
|
||||||
$text = str_replace(array('<','>','"',"'",'--'), array('<','>','″','′','–'), $text);
|
$html = strip_tags($text);
|
||||||
|
$html = str_replace(array('<','>','"',"'",'--'), array('<','>','″','′','–'), $html);
|
||||||
|
$html = Markdown::processing($html);
|
||||||
|
$html = nl2br($html);
|
||||||
|
|
||||||
$allowComments = (int) isset($_POST['allowComments']);
|
$allowComments = (int) isset($_POST['allowComments']);
|
||||||
|
|
||||||
$article = $id ? Article::model()->getByPK($id) : new Article();
|
$article = $id ? Article::model()->getByPK($id) : new Article();
|
||||||
|
|
@ -92,6 +96,8 @@ class ArticlesController extends Controller
|
||||||
|
|
||||||
$article->title = $title;
|
$article->title = $title;
|
||||||
$article->text = $text;
|
$article->text = $text;
|
||||||
|
$article->html = $html;
|
||||||
|
$article->photoId = Helper::getFirstImg($text);
|
||||||
$article->allowComments = $allowComments;
|
$article->allowComments = $allowComments;
|
||||||
$article->save();
|
$article->save();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue