36], [['alias', 'old_url', 'author', 'link'], 'string', 'max' => 255], [['meta_title'], 'string'], [['id'], 'unique'], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'uid' => 'Uid', 'alias' => 'Alias', 'old_url' => 'Old Url', 'dt_pub' => 'Dt Pub', 'dt_cr' => 'Dt Cr', 'dt_upd' => 'Dt Upd', 'rev' => 'Rev', 'title' => 'Title', 'lid' => 'Lid', 'text' => 'Text', 'meta_title' => 'Meta Title', 'author' => 'Author', 'show_author' => 'Show Author', 'editors' => 'Editors', 'link' => 'Link', 'embed_url' => 'Embed Url', 'photo_name' => 'Photo Name', 'photo_title' => 'Photo Title', 'photo_include' => 'Photo Include', 'photo_rcol' => 'Photo Rcol', 'active' => 'Active', 'verifed' => 'Verifed', 'top' => 'Top', 'NH' => 'Nh', 'comments' => 'Comments', 'flags' => 'Flags', 'photo' => 'Photo', 'video' => 'Video', 'audio' => 'Audio', 'export_rss' => 'Export Rss', 'noindex' => 'Noindex', 'type' => 'Type', 'inscription' => 'Inscription', 'old_gallery_title' => 'Old Gallery Title', ]; } /** * {@inheritdoc} * @return status. */ public function saveImg($id, $file, $type) { $post = Yii::$app->request->post(); $pcut = isset($post['cropping'])?$post['cropping']:false; $t = ['image/jpeg'=>'jpg','image/png'=>'png', 'image/webp'=>'webp']; //расширить допустимый список и вынести в общий класс if( isset( $t[$type] ) ){ $ext = $t[$type]; //загрузка временной фото на обработку $name = basename($id."_origin.".$ext); $file_tmp = Yii::getAlias('@webroot').'/'.static::$story_dir."/news/$name"; if( move_uploaded_file($file, $file_tmp) ){ // фото исходник для дальнейшей обработки $name = basename($id."_sizehd.jpg"); $hdfile = Yii::getAlias('@webroot').'/'.static::$story_dir."/news/$name"; if( $pcut ){ $cut = ['x'=>round($pcut['x']), 'y'=>round($pcut['y']), 'w'=>round($pcut['width']), 'h'=>round($pcut['height'])]; $this->generateImageCrop($file_tmp, $hdfile, 1920, 1080, $cut); }else{ // без обрезки $this->generatePreview( $file_tmp, $hdfile, 1920, 1080); } //unlink($file_tmp); удалить оригинал или оставить? // фото на главную сюжета 1300х731 $name = basename($id."_size1.webp"); $ofile = Yii::getAlias('@webroot').'/'.static::$story_dir."/webp/$name"; $this->generatePreview( $hdfile, $ofile, 1300, 731); $name = basename($id."_size1.jpg"); $ofile = Yii::getAlias('@webroot').'/'.static::$story_dir."/news/$name"; $this->generatePreview( $hdfile, $ofile, 1300, 731); // фото на НЧ 841x473 $name = basename($id."_size5.webp"); $ofile = Yii::getAlias('@webroot').'/'.static::$story_dir."/webp/$name"; $this->generatePreview( $hdfile, $ofile, 841, 473); $name = basename($id."_size5.jpg"); $ofile = Yii::getAlias('@webroot').'/'.static::$story_dir."/news/$name"; $this->generatePreview( $hdfile, $ofile, 841, 473); // фото на в ленту(можно отдавать поисковикам) сюжета 680x383 $name = basename($id."_size2.webp"); $ofile = Yii::getAlias('@webroot').'/'.static::$story_dir."/webp/$name"; $this->generatePreview( $hdfile, $ofile, 680, 383); $name = basename($id."_size2.jpg"); $ofile = Yii::getAlias('@webroot').'/'.static::$story_dir."/news/$name"; $this->generatePreview( $hdfile, $ofile, 680, 383); $name = basename($id."_size3.webp"); $ofile = Yii::getAlias('@webroot').'/'.static::$story_dir."/webp/$name"; $this->generatePreview( $hdfile, $ofile, 500, 282); $name = basename($id."_size3.jpg"); $ofile = Yii::getAlias('@webroot').'/'.static::$story_dir."/news/$name"; $this->generatePreview( $hdfile, $ofile, 500, 282); // size3 пропустим в текущем дизайне не применим // фото на в малая(можно отдавать в админку, инжекты и пр. лабудень) сюжета 320х180 $name = basename($id."_size4.webp"); $ofile = Yii::getAlias('@webroot').'/'.static::$story_dir."/webp/$name"; $this->generatePreview( $hdfile, $ofile, 320, 180 ); $name = basename($id."_size4.jpg"); $ofile = Yii::getAlias('@webroot').'/'.static::$story_dir."/news/$name"; $this->generatePreview( $hdfile, $ofile, 320, 180 ); $name = basename($id.".jpg"); $ofile = Yii::getAlias('@webroot').'/'.static::$story_dir."/news/$name"; $this->generatePreview( $hdfile, $ofile, 94, 94, ['sharpen' => '10 -enhance -gravity center -crop 94x94+0+0 +repage'] ); return $file_tmp; } } return false; } /** * {@inheritdoc} * @return status. */ public function deleteImg($id) { $img = ["_origin.png", "_origin.jpeg", "_origin.jpg", "_sizehd.jpg", "_size1.webp", "_size1.jpg", "_size2.webp", "_size2.jpg", "_size3.webp", "_size3.jpg", "_size4.webp", "_size4.jpg", ".jpg"]; foreach( $img as $prefix ){ $name = basename($id.$prefix); if( strpos( $prefix, 'webp' ) === false ){ $file = Yii::getAlias('@webroot').'/'.static::$story_dir."/news/$name"; }else{ $file = Yii::getAlias('@webroot').'/'.static::$story_dir."/webp/$name"; } @unlink( $file ); } } public function Active($id, $state = -1) { if( $state < 0 ){ $this->active = ($this->active == 'Y')?'N':'Y'; }else{ $this->active = $state; } return $this->save(false); } public function NH($id, $state = -1) { if( $state < 0 ){ $this->NH = ($this->NH == 'Y')?'N':'Y'; }else{ $this->NH = $state; } return $this->save(false); } public function KD($id, $state = -1) { if( $state < 0 ){ $this->top = ($this->top == 'Y')?'N':'Y'; }else{ $this->top = $state; } return $this->save(false); } /** * {@inheritdoc} * @return NewsQuery the active query used by this AR class. */ public static function find() { return new NewsQuery(get_called_class()); } /** * @return \yii\db\ActiveQuery */ public function getTopicRelations() { return $this->hasMany(NewsTopicRelation::class,['news_id'=>'id']); } /** * @return \yii\db\ActiveQuery */ public function getTopics() { return $this->hasMany(NewsTopic::class,['id'=>'topic_id'])->via('topicRelations'); } /** * @return \yii\db\ActiveQuery */ public function getTagsRelations() { return $this->hasMany(TagsRelation::class,['news_id'=>'id']); } /** * @return \yii\db\ActiveQuery */ public function getTags() { return $this->hasMany(Tags::class,['id'=>'topic_id'])->via('tagsRelations'); } /** * @return \yii\db\ActiveQuery */ public function getStoryRelations() { return $this->hasMany(StoryRelation::class,['news_id'=>'id']); } public function isAmicPhoto() { return (bool) ($this->flags & 2); } /** * @return \yii\db\ActiveQuery */ public function getStories() { return $this->hasMany(Story::class,['id'=>'topic_id'])->via('storyRelations'); } /** * @return \yii\db\ActiveQuery */ public function getStory() { return $this->hasMany(Story::class,['id'=>'topic_id'])->via('storyRelations'); } /** * @return Image */ public function getImage($type="webp"):Image { return Image::findOne($this->id,$type,$this->photo_name); } }