topics)>0){ $topic = Transliterator::toUrl($this->topics[0]->title)."/"; } else{ $topic = ""; } switch ($this->type){ case 6: return "https://old.amic.ru/long/{$this->id}/"; break; default: return "/news/".$topic.Transliterator::toUrl($this->title)."-".$this->id; } } public function getMainPic(){ } /** * @return Image */ public function getPreview($type="webp"):Image{ return Image::findOne($this->id,$type); } /** * @return Image */ public function getImage($type="webp"):Image { return Image::findOne($this->id,$type); } public function getOld():ActiveQuery { return $this->hasOne(OldNews::class,['alias'=>'alias']); } /** * @return ActiveQuery */ public function getCommentsAll(): ActiveQuery { return $this->hasMany(Comments::class,['comment_pull_id'=>"uid"]); } public static function getMainView(){ return self::find()->joinWith("topics t")->andWhere(["t.id"=>[33,]]); } public static function getPartnersNews(){ return self::find()->joinWith("topics t")->andWhere(["t.id"=>[34,]]); } public static function getMainOfWeek(){ return self::find()->joinWith("topics t")->andWhere(["t.id"=>[35,]]); } public function getPublishedAt(){ if($this->dt_pubdt_pub))." ".mb_strtolower(Transliterator::month(date("n",strtotime($this->dt_pub)))); } else { $diff = ceil((time() - strtotime($this->dt_pub))/60); //В минутах if($diff<=60){ return Transliterator::plural($diff,['минуту','минуты', 'минут'],true,'только что','минуту')." назад"; } else { $diff = (int)floor($diff/60); return Transliterator::plural($diff,['час','часа', 'часов'],true,'только что','час')." назад"; } } } public function renderBody() { $post = $this; return \Yii::$app->cache->getOrSet("post-body-".$this->id,function () use ($post){ $body = $post->text; $body = self::processInjects($body); $body = self::processSingleImg($body); return $body; },600); } public static function processInjects($text) { $re = '/##news_(.*)##/mU'; $res = preg_replace_callback($re,function (array $matches): string { $post = News::findOne(['uid'=>ArrayHelper::getValue($matches,1)]); if($post instanceof News) { return \Yii::$app->view->render("/news/view/inject",["post"=>$post]); } else { return ""; } },$text); return $res; } public static function processSingleImg($text) { $re = '/()()(<\/p>)/mU'; $res = preg_replace_callback($re,function (array $matches): string { $img = ArrayHelper::getValue($matches,2); $pic= "
{$img}
"; return ArrayHelper::getValue($matches,1).$pic.ArrayHelper::getValue($matches,3); },$text); return $res; } public static function find() { return parent::find()->orderBy(["dt_pub"=>SORT_DESC]); } }