90 changed files with 0 additions and 6199 deletions
			
			
		| @ -1,116 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\widgets\MenuItemCreatorWidget; |  | ||||||
| use core\components\modules\ModuleInterface; |  | ||||||
| use yii\helpers\ArrayHelper; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * blog module definition class |  | ||||||
|  */ |  | ||||||
| class BlogModule extends \yii\base\Module implements ModuleInterface |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * @inheritdoc |  | ||||||
|      */ |  | ||||||
|     public $controllerNamespace = 'common\modules\blog\controllers'; |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @inheritdoc |  | ||||||
|      */ |  | ||||||
|     public function init() |  | ||||||
|     { |  | ||||||
|         parent::init(); |  | ||||||
|         // custom initialization code goes here |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public function bootstrap($app) |  | ||||||
| 	{ |  | ||||||
| 		// add migration path |  | ||||||
| 		$app->controllerMap['migrate']['migrationPath'][] = '@common/modules/blog/migrations'; |  | ||||||
| 
 |  | ||||||
| 		// add search rules |  | ||||||
| 		$app->params['search_rules'][] = "SELECT title, content, CONCAT('/blog/manage/post/view/', blog_post_id) AS url FROM {{blog_posts_lng}}"; |  | ||||||
| 		 |  | ||||||
| 		// add rules |  | ||||||
| 		$app->getUrlManager()->addRules([ |  | ||||||
| 			'blog' => 'blog/post/index', |  | ||||||
| 		]); |  | ||||||
| 
 |  | ||||||
| 		$app->getUrlManager()->addRules([ |  | ||||||
| 			['class' => 'common\modules\blog\urls\BlogMainUrlRule'], |  | ||||||
| 			['class' => 'common\modules\blog\urls\BlogCategoryUrlRule'], |  | ||||||
| 			['class' => 'common\modules\blog\urls\BlogTagUrlRule'], |  | ||||||
| 		]); |  | ||||||
| 
 |  | ||||||
| 		$app->getUrlManager()->addRules([ |  | ||||||
| 			'blog/manage/post/view/<id:\d+>' => 'blog/manage/post/view', |  | ||||||
| 		]); |  | ||||||
| 
 |  | ||||||
| 		// add languages |  | ||||||
| 		$app->getI18n()->translations = ArrayHelper::merge($app->getI18n()->translations, [ |  | ||||||
| 			'blog' => [ |  | ||||||
| 				'class' => 'yii\i18n\PhpMessageSource', |  | ||||||
| 				'basePath' => '@common/modules/blog/messages', |  | ||||||
| 			], |  | ||||||
| 			'blog_public' => [ |  | ||||||
| 				'class' => 'yii\i18n\PhpMessageSource', |  | ||||||
| 				'basePath' => '@common/modules/blog/messages', |  | ||||||
| 			], |  | ||||||
| 		]); |  | ||||||
| 
 |  | ||||||
| 		// add menu items |  | ||||||
| 		/*$app->params['adminMenu'][] = [ |  | ||||||
| 			'label' => \Yii::t('blog', 'Blog'), 'icon' => 'book', 'items' => [ |  | ||||||
| 				['label' => \Yii::t('blog', 'Categories'), 'icon' => 'caret-right', 'url' => ['/blog/manage/category/index'], 'active' => \Yii::$app->controller->getUniqueId() == 'blog/manage/category'], |  | ||||||
| 				['label' => \Yii::t('blog', 'Posts'), 'icon' => 'caret-right', 'url' => ['/blog/manage/post/index'], 'active' => \Yii::$app->controller->getUniqueId() == 'blog/manage/post'], |  | ||||||
| 			], 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('BlogManagement') |  | ||||||
| 		];*/ |  | ||||||
| 		//print_r(basename($app->getBasePath())); die; |  | ||||||
| 		//print_r($app->basePath); die; |  | ||||||
| 
 |  | ||||||
| 		if (basename($app->getBasePath()) === 'backend') { |  | ||||||
| 			$app->params['adminMenu'][] = [ |  | ||||||
| 				'label'   => \Yii::t( 'blog', 'Blog' ), |  | ||||||
| 				'icon'    => 'book', |  | ||||||
| 				'items'   => [ |  | ||||||
| 					[ |  | ||||||
| 						'label' => \Yii::t( 'blog', 'Categories' ), |  | ||||||
| 						'icon'  => 'caret-right', |  | ||||||
| 						'url'   => [ '/blog/manage/category/index' ] |  | ||||||
| 					], |  | ||||||
| 					[ |  | ||||||
| 						'label' => \Yii::t( 'blog', 'Posts' ), |  | ||||||
| 						'icon'  => 'caret-right', |  | ||||||
| 						'url'   => [ '/blog/manage/post/index' ] |  | ||||||
| 					], |  | ||||||
| 					[ |  | ||||||
| 						'label' => \Yii::t( 'blog', 'Comments' ), |  | ||||||
| 						'icon'  => 'caret-right', |  | ||||||
| 						'url'   => [ '/blog/manage/comment/index' ] |  | ||||||
| 					], |  | ||||||
| 					[ |  | ||||||
| 						'label' => \Yii::t( 'blog', 'Tags' ), |  | ||||||
| 						'icon'  => 'caret-right', |  | ||||||
| 						'url'   => [ '/blog/manage/tag/index' ] |  | ||||||
| 					], |  | ||||||
| 				], |  | ||||||
| 				'visible' => \Yii::$app->user->can( 'admin' ) || \Yii::$app->user->can( 'BlogManagement' ) |  | ||||||
| 			]; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public static function getMenuItemCreator($menu_id): array |  | ||||||
| 	{ |  | ||||||
| 		$widgets = []; |  | ||||||
| 		$widgets[] = [ |  | ||||||
| 			'id' => 'blog', |  | ||||||
| 			'title' => \Yii::t('blog', 'Blog'), |  | ||||||
| 			'content' => MenuItemCreatorWidget::widget([ |  | ||||||
| 				'menu_id' => $menu_id, |  | ||||||
| 			]), |  | ||||||
| 		]; |  | ||||||
| 		return $widgets; |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,249 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\controllers; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\forms\BlogCommentForm; |  | ||||||
| use common\modules\blog\repositories\read\BlogCategoryReadRepository; |  | ||||||
| use common\modules\blog\repositories\read\BlogPostReadRepository; |  | ||||||
| use common\modules\blog\repositories\read\BlogTagReadRepository; |  | ||||||
| use common\modules\blog\services\BlogCommentService; |  | ||||||
| use frontend\components\FrontendController; |  | ||||||
| use Yii; |  | ||||||
| use yii\data\ActiveDataProvider; |  | ||||||
| use yii\web\NotFoundHttpException; |  | ||||||
| use yii\filters\AccessControl; |  | ||||||
| 
 |  | ||||||
| class PostController extends FrontendController |  | ||||||
| { |  | ||||||
|     public $layout = 'blog'; |  | ||||||
| 
 |  | ||||||
|     private $service; |  | ||||||
|     private $posts; |  | ||||||
|     private $categories; |  | ||||||
|     private $tags; |  | ||||||
| 
 |  | ||||||
|     public function __construct( |  | ||||||
|         $id, |  | ||||||
|         $module, |  | ||||||
|         BlogCommentService $service, |  | ||||||
|         BlogPostReadRepository $posts, |  | ||||||
|         BlogCategoryReadRepository $categories, |  | ||||||
|         BlogTagReadRepository $tags, |  | ||||||
|         $config = [] |  | ||||||
|     ) |  | ||||||
|     { |  | ||||||
|         parent::__construct($id, $module, $config); |  | ||||||
|         $this->service = $service; |  | ||||||
|         $this->posts = $posts; |  | ||||||
|         $this->categories = $categories; |  | ||||||
|         $this->tags = $tags; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public function behaviors(): array |  | ||||||
| 	{ |  | ||||||
| 		return [ |  | ||||||
| 			'access' => [ |  | ||||||
| 				'class' => AccessControl::class, |  | ||||||
| 				'rules' => [ |  | ||||||
| 					[ |  | ||||||
| 						'actions' => ['index', 'category', 'tag', 'post'], |  | ||||||
| 						'allow' => true, |  | ||||||
| 						//'roles' => ['Blog'], |  | ||||||
| 					], |  | ||||||
| 					[ |  | ||||||
| 						'actions' => ['preview'], |  | ||||||
| 						'allow' => true, |  | ||||||
| 						'roles' => ['BlogManagement'], |  | ||||||
| 					], |  | ||||||
| 					[ |  | ||||||
| 						'actions' => ['comment'], |  | ||||||
| 						'allow' => true, |  | ||||||
| 						'roles' => ['Comments'], |  | ||||||
| 					], |  | ||||||
| 					[    // all the action are accessible to admin |  | ||||||
| 						'allow' => true, |  | ||||||
| 						'roles' => ['admin'], |  | ||||||
| 					], |  | ||||||
| 				], |  | ||||||
| 			], |  | ||||||
| 		]; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @return string |  | ||||||
| 	 */ |  | ||||||
|     public function actionIndex() |  | ||||||
|     { |  | ||||||
| 	    /* @var $dataProvider ActiveDataProvider */ |  | ||||||
|         $dataProvider = $this->posts->getAll(); |  | ||||||
| 	    $dataProvider->pagination->pageSize = 10; |  | ||||||
| 
 |  | ||||||
|         return $this->render('index', [ |  | ||||||
|             'dataProvider' => $dataProvider, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return string |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     public function actionCategory($id) |  | ||||||
|     { |  | ||||||
| 	    if (!$category = $this->categories->find($id)) { |  | ||||||
| 		    throw new NotFoundHttpException('The requested page does not exist.'); |  | ||||||
| 	    } |  | ||||||
|         $dataProvider = $this->posts->getAllByCategory($category); |  | ||||||
| 
 |  | ||||||
|         return $this->render('category', [ |  | ||||||
|             'category' => $category, |  | ||||||
|             'dataProvider' => $dataProvider, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @param $id |  | ||||||
|      * @return mixed |  | ||||||
|      * @throws NotFoundHttpException |  | ||||||
|      */ |  | ||||||
|     public function actionTag($id) |  | ||||||
|     { |  | ||||||
|         if (!$tag = $this->tags->find($id)) { |  | ||||||
|             throw new NotFoundHttpException('The requested page does not exist.'); |  | ||||||
|         } |  | ||||||
|         $dataProvider = $this->posts->getAllByTag($tag); |  | ||||||
| 
 |  | ||||||
|         return $this->render('tag', [ |  | ||||||
|             'tag' => $tag, |  | ||||||
|             'dataProvider' => $dataProvider, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @param $id |  | ||||||
|      * @return mixed |  | ||||||
|      * @throws NotFoundHttpException |  | ||||||
|      */ |  | ||||||
|     public function actionPost($id) |  | ||||||
|     { |  | ||||||
|         if (!$post = $this->posts->find($id)) { |  | ||||||
|             throw new NotFoundHttpException('The requested page does not exist.'); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return $this->render('post', [ |  | ||||||
|             'post' => $post, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @param $id |  | ||||||
|      * @return mixed |  | ||||||
|      * @throws NotFoundHttpException |  | ||||||
|      */ |  | ||||||
|     public function actionComment($id) |  | ||||||
|     { |  | ||||||
|         if (!$post = $this->posts->find($id)) { |  | ||||||
|             throw new NotFoundHttpException('The requested page does not exist.'); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         $form = new BlogCommentForm(); |  | ||||||
| 
 |  | ||||||
|         if ($form->load(Yii::$app->request->post()) && $form->validate()) { |  | ||||||
|             try { |  | ||||||
|                 $comment = $this->service->create($post->id, Yii::$app->user->id, $form); |  | ||||||
|                 return $this->redirect(['post', 'id' => $post->id, '#' => 'comment_' . $comment->id]); |  | ||||||
|             } catch (\DomainException $e) { |  | ||||||
|                 Yii::$app->errorHandler->logException($e); |  | ||||||
|                 Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return $this->render('comment', [ |  | ||||||
|             'post' => $post, |  | ||||||
|             'model' => $form, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public function beforeAction($action) |  | ||||||
| 	{ |  | ||||||
| 		// ...set `$this->enableCsrfValidation` here based on some conditions... |  | ||||||
| 		// call parent method that will check CSRF if such property is true. |  | ||||||
| 		if ($action->id === 'preview') { |  | ||||||
| 			# code... |  | ||||||
| 			$this->enableCsrfValidation = false; |  | ||||||
| 		} |  | ||||||
| 		return parent::beforeAction($action); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	/*public function actionPreview($id = null) |  | ||||||
|     { |  | ||||||
| 	    Yii::$app->controller->enableCsrfValidation = false; |  | ||||||
| 	    $form = new BlogPostForm(); |  | ||||||
| 	    $parent = $id ? BlogPost::findOne($id) : null; |  | ||||||
| 
 |  | ||||||
| 	    if ($form->load(Yii::$app->request->post())) { |  | ||||||
| 		    $form->slug = md5(time()); |  | ||||||
| 	    	if ($form->validate()) { |  | ||||||
| 			    $post               = new BlogPost(); |  | ||||||
| 			    $post->id           = - 1; |  | ||||||
| 			    $post->title        = $form->title; |  | ||||||
| 			    $post->description  = $form->description; |  | ||||||
| 			    $post->content      = $form->content; |  | ||||||
| 			    $post->category_id  = $form->category_id; |  | ||||||
| 			    $post->created_at   = time(); |  | ||||||
| 			    $post->updated_at   = time(); |  | ||||||
| 			    $post->published_at = time(); |  | ||||||
| 
 |  | ||||||
| 			    $meta            = new Meta( $form->meta->title, $form->meta->description, $form->meta->keywords ); |  | ||||||
| 			    $post->meta      = $meta; |  | ||||||
| 			    $post->meta_json = Json::encode( [ |  | ||||||
| 				    'title'       => $form->meta->title, |  | ||||||
| 				    'description' => $form->meta->description, |  | ||||||
| 				    'keywords'    => $form->meta->keywords, |  | ||||||
| 			    ] ); |  | ||||||
| 			    $post->video     = $form->video; |  | ||||||
| 			    $post->slug      = $form->slug; |  | ||||||
| 
 |  | ||||||
| 			    if ( $form->image ) { |  | ||||||
| 				    $post->setImage( $form->image ); |  | ||||||
| 			    } else if ( $form->video ) { |  | ||||||
| 				    $src      = 'https://i.ytimg.com/vi/' . BlogPostHelper::parseYoutubeUrl( $post->video ) . '/maxresdefault.jpg'; |  | ||||||
| 				    $filename = ( new Security() )->generateRandomString( 15 ) . '.jpg'; |  | ||||||
| 				    copy( $src, \Yii::getAlias( BlogPost::FILE_ORIGINAL_PATH . '/' . $post->id . '.jpg' ) ); |  | ||||||
| 				    //copy($src, \Yii::getAlias(BlogPost::FILE_ORIGINAL_PATH . '/' . $filename)); |  | ||||||
| 				    $post->image = $filename; |  | ||||||
| 			    } |  | ||||||
| 
 |  | ||||||
| 			    if ( $post->image ) { |  | ||||||
| 				    $path = $post->getUploadedFilePath( 'image' ); |  | ||||||
| 				    FileHelper::createDirectory( pathinfo( $path, PATHINFO_DIRNAME ), 0775, true ); |  | ||||||
| 				    $post->image->saveAs( $path ); |  | ||||||
| 				    $post->image = $post->getImageFileUrl( 'image' ); |  | ||||||
| 			    } else { |  | ||||||
| 				    $post->image = $parent->image; |  | ||||||
| 				    //$post->image = $post->getImageFileUrl( 'image' ); |  | ||||||
| 			    } |  | ||||||
| 
 |  | ||||||
| 			    return $this->render( 'post', [ |  | ||||||
| 				    'post' => $post, |  | ||||||
| 			    ] ); |  | ||||||
| 		    } |  | ||||||
| 	    } else {print_r($form->errors);} |  | ||||||
| 	    return ''; |  | ||||||
|     }*/ |  | ||||||
| 
 |  | ||||||
| 	public function actionPreview($id, $language = '') |  | ||||||
| 	{ |  | ||||||
| 		if (!$post = $this->posts->findPreview($id, $language)) { |  | ||||||
| 			throw new NotFoundHttpException('The requested page does not exist.'); |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		/*if ($language) { |  | ||||||
| 			Yii::$app->language = $language; |  | ||||||
| 		}*/ |  | ||||||
| 		return $this->render('post', [ |  | ||||||
| 			'post' => $post, |  | ||||||
| 		]); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,156 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\controllers\manage; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogCategory; |  | ||||||
| use common\modules\blog\forms\BlogCategoryForm; |  | ||||||
| use common\modules\blog\forms\search\BlogCategorySearch; |  | ||||||
| use common\modules\blog\services\BlogCategoryManageService; |  | ||||||
| use Yii; |  | ||||||
| use yii\data\ActiveDataProvider; |  | ||||||
| use yii\web\Controller; |  | ||||||
| use yii\web\NotFoundHttpException; |  | ||||||
| use yii\filters\VerbFilter; |  | ||||||
| use yii\filters\AccessControl; |  | ||||||
| 
 |  | ||||||
| class CategoryController extends Controller |  | ||||||
| { |  | ||||||
|     private $service; |  | ||||||
| 
 |  | ||||||
|     public function __construct($id, $module, BlogCategoryManageService $service, $config = []) |  | ||||||
|     { |  | ||||||
|         parent::__construct($id, $module, $config); |  | ||||||
|         $this->service = $service; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function behaviors(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             'access' => [ |  | ||||||
|                 'class' => AccessControl::class, |  | ||||||
|                 'rules' => [ |  | ||||||
|                     [ |  | ||||||
|                         'allow' => true, |  | ||||||
|                         'roles' => ['BlogManagement'], |  | ||||||
|                     ], |  | ||||||
|                     [    // all the action are accessible to admin |  | ||||||
|                         'allow' => true, |  | ||||||
|                         'roles' => ['admin'], |  | ||||||
|                     ], |  | ||||||
|                 ], |  | ||||||
|             ], |  | ||||||
|             'verbs' => [ |  | ||||||
|                 'class' => VerbFilter::class, |  | ||||||
|                 'actions' => [ |  | ||||||
|                     'delete' => ['POST'], |  | ||||||
|                 ], |  | ||||||
|             ], |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @return string |  | ||||||
| 	 */ |  | ||||||
|     public function actionIndex() |  | ||||||
|     { |  | ||||||
|         $searchModel = new BlogCategorySearch(); |  | ||||||
|         $dataProvider = $searchModel->search(Yii::$app->request->queryParams); |  | ||||||
| 
 |  | ||||||
|         return $this->render('index', [ |  | ||||||
|             'searchModel' => $searchModel, |  | ||||||
|             'dataProvider' => $dataProvider, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return string |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     public function actionView($id) |  | ||||||
|     { |  | ||||||
|     	$category = $this->findModel($id); |  | ||||||
|         return $this->render('view', [ |  | ||||||
|             'category' => $category, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @return string|\yii\web\Response |  | ||||||
| 	 */ |  | ||||||
|     public function actionCreate() |  | ||||||
|     { |  | ||||||
|         $form = new BlogCategoryForm(); |  | ||||||
|         $form->updateSort(); |  | ||||||
|         if ($form->load(Yii::$app->request->post()) && $form->validate()) { |  | ||||||
|             try { |  | ||||||
|                 $category = $this->service->create($form); |  | ||||||
|                 return $this->redirect(['view', 'id' => $category->id]); |  | ||||||
|             } catch (\DomainException $e) { |  | ||||||
|                 Yii::$app->errorHandler->logException($e); |  | ||||||
|                 Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return $this->render('create', [ |  | ||||||
|             'model' => $form, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return string|\yii\web\Response |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     public function actionUpdate($id) |  | ||||||
|     { |  | ||||||
|         $category = $this->findModel($id); |  | ||||||
|         $form = new BlogCategoryForm($category); |  | ||||||
|         if ($form->load(Yii::$app->request->post()) && $form->validate()) { |  | ||||||
|             try { |  | ||||||
|                 $this->service->edit($category->id, $form); |  | ||||||
|                 return $this->redirect(['view', 'id' => $category->id]); |  | ||||||
|             } catch (\DomainException $e) { |  | ||||||
|                 Yii::$app->errorHandler->logException($e); |  | ||||||
|                 Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return $this->render('update', [ |  | ||||||
|             'model' => $form, |  | ||||||
|             'category' => $category, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return \yii\web\Response |  | ||||||
| 	 */ |  | ||||||
|     public function actionDelete($id) |  | ||||||
|     { |  | ||||||
| 	    //$category = $this->findModel($id); |  | ||||||
|         try { |  | ||||||
|             $this->service->remove($id); |  | ||||||
|         } catch (\DomainException $e) { |  | ||||||
|             Yii::$app->errorHandler->logException($e); |  | ||||||
|             Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|         } |  | ||||||
|         return $this->redirect(['index']); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return BlogCategory |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     protected function findModel($id): BlogCategory |  | ||||||
|     { |  | ||||||
|         if (($model = BlogCategory::findOne($id)) !== null) { |  | ||||||
|             return $model; |  | ||||||
|         } |  | ||||||
|         throw new NotFoundHttpException('The requested page does not exist.'); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,159 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\controllers\manage; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| use common\modules\blog\forms\BlogCommentEditForm; |  | ||||||
| use common\modules\blog\forms\search\BlogCommentSearch; |  | ||||||
| use common\modules\blog\services\BlogCommentManageService; |  | ||||||
| use Yii; |  | ||||||
| use yii\web\Controller; |  | ||||||
| use yii\web\NotFoundHttpException; |  | ||||||
| use yii\filters\VerbFilter; |  | ||||||
| use yii\filters\AccessControl; |  | ||||||
| 
 |  | ||||||
| class CommentController extends Controller |  | ||||||
| { |  | ||||||
|     private $service; |  | ||||||
| 
 |  | ||||||
|     public function __construct($id, $module, BlogCommentManageService $service, $config = []) |  | ||||||
|     { |  | ||||||
|         parent::__construct($id, $module, $config); |  | ||||||
|         $this->service = $service; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function behaviors(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             'access' => [ |  | ||||||
|                 'class' => AccessControl::class, |  | ||||||
|                 'rules' => [ |  | ||||||
|                     [ |  | ||||||
|                         'allow' => true, |  | ||||||
|                         'roles' => ['BlogManagement'], |  | ||||||
|                     ], |  | ||||||
|                     [    // all the action are accessible to admin |  | ||||||
|                         'allow' => true, |  | ||||||
|                         'roles' => ['admin'], |  | ||||||
|                     ], |  | ||||||
|                 ], |  | ||||||
|             ], |  | ||||||
|             'verbs' => [ |  | ||||||
|                 'class' => VerbFilter::class, |  | ||||||
|                 'actions' => [ |  | ||||||
|                     'delete' => ['POST'], |  | ||||||
|                 ], |  | ||||||
|             ], |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @return mixed |  | ||||||
|      */ |  | ||||||
|     public function actionIndex() |  | ||||||
|     { |  | ||||||
|         $searchModel = new BlogCommentSearch(); |  | ||||||
|         $dataProvider = $searchModel->search(Yii::$app->request->queryParams); |  | ||||||
| 
 |  | ||||||
|         return $this->render('index', [ |  | ||||||
|             'searchModel' => $searchModel, |  | ||||||
|             'dataProvider' => $dataProvider, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $post_id |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return string|\yii\web\Response |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     public function actionUpdate($post_id, $id) |  | ||||||
|     { |  | ||||||
|         $post = $this->findModel($post_id); |  | ||||||
|         $comment = $post->getComment($id); |  | ||||||
| 
 |  | ||||||
|         $form = new BlogCommentEditForm($comment); |  | ||||||
|         if ($form->load(Yii::$app->request->post()) && $form->validate()) { |  | ||||||
|             try { |  | ||||||
|                 $this->service->edit($post->id, $comment->id, $form); |  | ||||||
|                 return $this->redirect(['view', 'post_id' => $post->id, 'id' => $comment->id]); |  | ||||||
|             } catch (\DomainException $e) { |  | ||||||
|                 Yii::$app->errorHandler->logException($e); |  | ||||||
|                 Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return $this->render('update', [ |  | ||||||
|             'post' => $post, |  | ||||||
|             'model' => $form, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $post_id |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return string |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     public function actionView($post_id, $id) |  | ||||||
|     { |  | ||||||
|         $post = $this->findModel($post_id); |  | ||||||
|         $comment = $post->getComment($id); |  | ||||||
| 
 |  | ||||||
|         return $this->render('view', [ |  | ||||||
|             'post' => $post, |  | ||||||
|             'comment' => $comment, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $post_id |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return \yii\web\Response |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     public function actionActivate($post_id, $id) |  | ||||||
|     { |  | ||||||
|         $post = $this->findModel($post_id); |  | ||||||
|         try { |  | ||||||
|             $this->service->activate($post->id, $id); |  | ||||||
|         } catch (\DomainException $e) { |  | ||||||
|             Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|         } |  | ||||||
|         return $this->redirect(['view', 'post_id' => $post_id, 'id' => $id]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $post_id |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return \yii\web\Response |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     public function actionDelete($post_id, $id) |  | ||||||
|     { |  | ||||||
|         $post = $this->findModel($post_id); |  | ||||||
|         try { |  | ||||||
|             $this->service->remove($post->id, $id); |  | ||||||
|         } catch (\DomainException $e) { |  | ||||||
|             Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|         } |  | ||||||
|         return $this->redirect(['index']); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return BlogPost |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     protected function findModel($id): BlogPost |  | ||||||
|     { |  | ||||||
|         if (($model = BlogPost::findOne($id)) !== null) { |  | ||||||
|             return $model; |  | ||||||
|         } |  | ||||||
|         throw new NotFoundHttpException('The requested page does not exist.'); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,311 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\controllers\manage; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| use common\modules\blog\entities\BlogTag; |  | ||||||
| use common\modules\blog\forms\BlogPostForm; |  | ||||||
| use common\modules\blog\forms\search\BlogPostSearch; |  | ||||||
| use common\modules\blog\services\BlogPostManageService; |  | ||||||
| use Yii; |  | ||||||
| use yii\helpers\Url; |  | ||||||
| use yii\web\Controller; |  | ||||||
| use yii\web\NotFoundHttpException; |  | ||||||
| use yii\filters\VerbFilter; |  | ||||||
| use yii\filters\AccessControl; |  | ||||||
| use yii\web\Response; |  | ||||||
| 
 |  | ||||||
| class PostController extends Controller |  | ||||||
| { |  | ||||||
|     private $service; |  | ||||||
| 
 |  | ||||||
|     public function __construct($id, $module, BlogPostManageService $service, $config = []) |  | ||||||
|     { |  | ||||||
|         parent::__construct($id, $module, $config); |  | ||||||
|         $this->service = $service; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function behaviors(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             'access' => [ |  | ||||||
|                 'class' => AccessControl::class, |  | ||||||
|                 'rules' => [ |  | ||||||
|                     [ |  | ||||||
|                         'allow' => true, |  | ||||||
|                         'roles' => ['BlogManagement'], |  | ||||||
|                     ], |  | ||||||
|                     [    // all the action are accessible to admin |  | ||||||
|                         'allow' => true, |  | ||||||
|                         'roles' => ['admin'], |  | ||||||
|                     ], |  | ||||||
|                 ], |  | ||||||
|             ], |  | ||||||
|             'verbs' => [ |  | ||||||
|                 'class' => VerbFilter::class, |  | ||||||
|                 'actions' => [ |  | ||||||
|                     'delete' => ['POST'], |  | ||||||
|                     'activate' => ['POST'], |  | ||||||
|                     'draft' => ['POST'], |  | ||||||
|                     'delete-photo' => ['POST'], |  | ||||||
|                     'move-photo-up' => ['POST'], |  | ||||||
|                     'move-photo-down' => ['POST'], |  | ||||||
| 	                'restore-history' => ['POST'], |  | ||||||
|                     'clear-history' => ['POST'], |  | ||||||
|                 ], |  | ||||||
|             ], |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @return string |  | ||||||
| 	 */ |  | ||||||
|     public function actionIndex() |  | ||||||
|     { |  | ||||||
|         $searchModel = new BlogPostSearch(); |  | ||||||
|         $dataProvider = $searchModel->search(Yii::$app->request->queryParams); |  | ||||||
|         return $this->render( 'index', [ |  | ||||||
|             'searchModel' => $searchModel, |  | ||||||
|             'dataProvider' => $dataProvider, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return string |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     public function actionView($id) |  | ||||||
|     { |  | ||||||
|     	$post = $this->findModel($id); |  | ||||||
| 
 |  | ||||||
|     	$history = BlogPost::find() |  | ||||||
| 		    ->andWhere(['OR', ['revision_id' => $id], ['id' => $id]]) |  | ||||||
| 		    ->orderBy(['revision_at' => SORT_DESC]) |  | ||||||
| 		    ->limit(20) |  | ||||||
| 		    ->all(); |  | ||||||
| 
 |  | ||||||
|         return $this->render('view', [ |  | ||||||
|             'post' => $post, |  | ||||||
| 	        'history' => $history, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function actionCreatePreview($id = null, $language = '') |  | ||||||
|     { |  | ||||||
|     	$this->service->removePreviews(); |  | ||||||
| 
 |  | ||||||
| 	    $form = new BlogPostForm(); |  | ||||||
| 	    $form->type = BlogPost::TYPE_PREVIEW; |  | ||||||
| 	    if ($form->load(Yii::$app->request->post()) && $form->validate()) { |  | ||||||
| 		    try { |  | ||||||
| 			    $post = $this->service->create( $form, BlogPost::TYPE_PREVIEW ); |  | ||||||
| 			    if ($id && !$post->image) { |  | ||||||
| 			    	$real_post = BlogPost::findOne($id); |  | ||||||
| 			    	if ($real_post->image) { |  | ||||||
| 					    $post->image = $real_post->image; |  | ||||||
| 					    $post->save(); |  | ||||||
| 					    $path = Yii::getAlias('@staticRoot/origin/posts'); |  | ||||||
| 					    $parts = pathinfo($real_post->image); |  | ||||||
| 					    copy($path . '/' . $real_post->id . '.' . $parts['extension'], $path . '/' . $post->id . '.' .  $parts['extension']); |  | ||||||
| 				    } |  | ||||||
| 			    } |  | ||||||
| 			    return $this->redirect(Url::to(Yii::$app->get('frontendUrlManager')->createAbsoluteUrl(['/blog/post/preview', 'id' => $post->id, 'language' => $language]))); |  | ||||||
| 		    } catch (\DomainException $e) { |  | ||||||
| 			    Yii::$app->errorHandler->logException($e); |  | ||||||
| 			    Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
| 		    } |  | ||||||
| 	    } |  | ||||||
| 	    $form->published_at = date('d.m.Y H:i:s'); |  | ||||||
| 	    return $this->render('create', [ |  | ||||||
| 		    'model' => $form, |  | ||||||
| 	    ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public function actionCreate() |  | ||||||
|     { |  | ||||||
|         $form = new BlogPostForm(); |  | ||||||
|         if ($form->load(Yii::$app->request->post()) && $form->validate()) { |  | ||||||
|             try { |  | ||||||
| 	            $post = $this->service->create( $form ); |  | ||||||
| 	            return $this->redirect( [ 'view', 'id' => $post->id ] ); |  | ||||||
|             } catch (\DomainException $e) { |  | ||||||
|                 Yii::$app->errorHandler->logException($e); |  | ||||||
|                 Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 	    $form->published_at = date('d.m.Y H:i:s'); |  | ||||||
|         return $this->render('create', [ |  | ||||||
|             'model' => $form, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return string|\yii\web\Response |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     public function actionUpdate($id) |  | ||||||
|     { |  | ||||||
|         $post = $this->findModel($id); |  | ||||||
|         $form = new BlogPostForm($post); |  | ||||||
| 
 |  | ||||||
|         $form->published_at = date('d.m.Y H:i:s', $form->published_at); |  | ||||||
|         if ($form->load(Yii::$app->request->post()) && $form->validate()) { |  | ||||||
|             try { |  | ||||||
|                 $this->service->edit($post->id, $form); |  | ||||||
|                 return $this->redirect(['view', 'id' => $post->id]); |  | ||||||
|             } catch (\DomainException $e) { |  | ||||||
|                 Yii::$app->errorHandler->logException($e); |  | ||||||
|                 Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return $this->render('update', [ |  | ||||||
|             'model' => $form, |  | ||||||
|             'post' => $post, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return Response |  | ||||||
| 	 */ |  | ||||||
|     public function actionDelete($id) |  | ||||||
|     { |  | ||||||
|         try { |  | ||||||
|             $this->service->remove($id); |  | ||||||
|         } catch (\DomainException $e) { |  | ||||||
|             Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|         } |  | ||||||
|         return $this->redirect(['index']); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @param integer $id |  | ||||||
|      * @return mixed |  | ||||||
|      */ |  | ||||||
|     public function actionActivate($id) |  | ||||||
|     { |  | ||||||
|         try { |  | ||||||
|             $this->service->activate($id); |  | ||||||
|         } catch (\DomainException $e) { |  | ||||||
|             Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|         } |  | ||||||
|         return $this->redirect(['view', 'id' => $id]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @param integer $id |  | ||||||
|      * @return mixed |  | ||||||
|      */ |  | ||||||
|     public function actionDraft($id) |  | ||||||
|     { |  | ||||||
|         try { |  | ||||||
|             $this->service->draft($id); |  | ||||||
|         } catch (\DomainException $e) { |  | ||||||
|             Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|         } |  | ||||||
|         return $this->redirect(['view', 'id' => $id]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function actionTagSearch($q = null, $id = null) |  | ||||||
|     { |  | ||||||
| 	    \Yii::$app->response->format = Response::FORMAT_JSON; |  | ||||||
| 	    $out = ['results' => ['id' => '', 'text' => '']]; |  | ||||||
| 	    if (!is_null($q)) { |  | ||||||
| 		    $data = BlogTag::find()->select('name as id, name as text')->andWhere(['like', 'name', $q])->orderBy('name')->limit(20)->asArray()->all(); |  | ||||||
| 		    $out['results'] = array_values($data); |  | ||||||
| 	    } |  | ||||||
| 	    elseif ($id > 0) { |  | ||||||
| 	    	$tag_name = BlogTag::findOne($id)->name; |  | ||||||
| 		    $out['results'] = ['id' => $tag_name, 'text' => $tag_name]; |  | ||||||
| 	    } |  | ||||||
| 	    return $out; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public function actionPostSearch($q = null, $id = null) |  | ||||||
| 	{ |  | ||||||
| 		\Yii::$app->response->format = Response::FORMAT_JSON; |  | ||||||
| 		$out = ['results' => ['id' => '', 'text' => '']]; |  | ||||||
| 		if (!is_null($q)) { |  | ||||||
| 			//$data = BlogPost::find()->select('id, title as text')->andWhere(['like', 'title', $q])->limit(20)->asArray()->all(); |  | ||||||
| 			//$out['results'] = array_values($data); |  | ||||||
| 			$data = []; |  | ||||||
| 			$posts = BlogPost::find() |  | ||||||
| 			             ->with('translation') |  | ||||||
| 			             ->leftJoin('{{%blog_posts_lng}}', '`blog_posts_lng`.`blog_post_id` = `blog_posts`.`id`') |  | ||||||
| 			             ->andWhere(['like', 'blog_posts_lng.title', $q]) |  | ||||||
| 			             ->limit(20) |  | ||||||
| 			             ->all(); |  | ||||||
| 
 |  | ||||||
| 			foreach ($posts as $post) { |  | ||||||
| 				$data[] = [ |  | ||||||
| 					'id' => $post->id, |  | ||||||
| 					'text' => isset($post->translation) ? $post->translation->title : null, |  | ||||||
| 				]; |  | ||||||
| 			} |  | ||||||
| 			$out['results'] = array_values($data); |  | ||||||
| 		} |  | ||||||
| 		elseif ($id > 0) { |  | ||||||
| 			$tag_name = BlogPost::findOne($id)->translation->title; |  | ||||||
| 			$out['results'] = ['id' => $tag_name, 'text' => $tag_name]; |  | ||||||
| 		} |  | ||||||
| 		else { |  | ||||||
| 			//$data = BlogPost::find()->select('id, title as text')->orderBy(['created_at' => SORT_DESC])->limit(20)->asArray()->all(); |  | ||||||
| 			//$out['results'] = array_values($data); |  | ||||||
| 			$data = []; |  | ||||||
| 			$posts = BlogPost::find()->orderBy(['id' => SORT_DESC])->limit(20)->all(); |  | ||||||
| 
 |  | ||||||
| 			foreach ($posts as $post) { |  | ||||||
| 				$data[] = [ |  | ||||||
| 					'id' => $post->id, |  | ||||||
| 					'text' => isset($post->translation) ? $post->translation->title : null, |  | ||||||
| 				]; |  | ||||||
| 			} |  | ||||||
| 			$out['results'] = array_values($data); |  | ||||||
| 		} |  | ||||||
| 		return $out; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function actionRestoreHistory($id) |  | ||||||
| 	{ |  | ||||||
| 		$post = $this->findModel($id); |  | ||||||
| 		if ($post_id = $post->revision_id) { |  | ||||||
| 			$new_id = $this->service->restoreHistory($id, $post->revision_id); |  | ||||||
| 			return $this->redirect(['/blog/manage/post/view', 'id' => $new_id]); |  | ||||||
| 		} |  | ||||||
| 		return $this->redirect(['/blog/manage/post/index']); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function actionClearHistory($id) |  | ||||||
| 	{ |  | ||||||
| 		$post = $this->findModel($id); |  | ||||||
| 		$this->service->clearHistory($post); |  | ||||||
| 		return $this->redirect(['/blog/manage/post/view', 'id' => $post->id]); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return BlogPost |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     protected function findModel($id): BlogPost |  | ||||||
|     { |  | ||||||
|         if (($model = BlogPost::findOne($id)) !== null) { |  | ||||||
|             return $model; |  | ||||||
|         } |  | ||||||
|         throw new NotFoundHttpException('The requested page does not exist.'); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	protected function findLanguageModel($id) |  | ||||||
| 	{ |  | ||||||
| 		if (($model = BlogPost::find()->multilingual()->andWhere(['id' => $id])->one()) !== null) { |  | ||||||
| 			return $model; |  | ||||||
| 		} |  | ||||||
| 		throw new NotFoundHttpException('The requested page does not exist.'); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,151 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\controllers\manage; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogTag; |  | ||||||
| use common\modules\blog\forms\BlogTagSingleForm; |  | ||||||
| use common\modules\blog\forms\search\BlogTagSearch; |  | ||||||
| use common\modules\blog\services\BlogTagManageService; |  | ||||||
| use Yii; |  | ||||||
| use yii\web\Controller; |  | ||||||
| use yii\web\NotFoundHttpException; |  | ||||||
| use yii\filters\VerbFilter; |  | ||||||
| use yii\filters\AccessControl; |  | ||||||
| 
 |  | ||||||
| class TagController extends Controller |  | ||||||
| { |  | ||||||
|     private $service; |  | ||||||
| 
 |  | ||||||
|     public function __construct($id, $module, BlogTagManageService $service, $config = []) |  | ||||||
|     { |  | ||||||
|         parent::__construct($id, $module, $config); |  | ||||||
|         $this->service = $service; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function behaviors(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             'access' => [ |  | ||||||
|                 'class' => AccessControl::class, |  | ||||||
|                 'rules' => [ |  | ||||||
|                     [ |  | ||||||
|                         'allow' => true, |  | ||||||
|                         'roles' => ['BlogManagement'], |  | ||||||
|                     ], |  | ||||||
|                     [    // all the action are accessible to admin |  | ||||||
|                         'allow' => true, |  | ||||||
|                         'roles' => ['admin'], |  | ||||||
|                     ], |  | ||||||
|                 ], |  | ||||||
|             ], |  | ||||||
|             'verbs' => [ |  | ||||||
|                 'class' => VerbFilter::class, |  | ||||||
|                 'actions' => [ |  | ||||||
|                     'delete' => ['POST'], |  | ||||||
|                 ], |  | ||||||
|             ], |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @return string |  | ||||||
| 	 */ |  | ||||||
|     public function actionIndex() |  | ||||||
|     { |  | ||||||
|         $searchModel = new BlogTagSearch(); |  | ||||||
|         $dataProvider = $searchModel->search(Yii::$app->request->queryParams); |  | ||||||
|         return $this->render('index', [ |  | ||||||
|             'searchModel' => $searchModel, |  | ||||||
|             'dataProvider' => $dataProvider, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return string |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     public function actionView($id) |  | ||||||
|     { |  | ||||||
|     	$tag = $this->findModel($id); |  | ||||||
|         return $this->render('view', [ |  | ||||||
|             'tag' => $tag, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @return string|\yii\web\Response |  | ||||||
| 	 */ |  | ||||||
|     public function actionCreate() |  | ||||||
|     { |  | ||||||
|         $form = new BlogTagSingleForm(); |  | ||||||
|         if ($form->load(Yii::$app->request->post()) && $form->validate()) { |  | ||||||
|             try { |  | ||||||
|             	$tag = $this->service->create($form); |  | ||||||
|                 return $this->redirect(['view', 'id' => $tag->id]); |  | ||||||
|             } catch (\DomainException $e) { |  | ||||||
|                 Yii::$app->errorHandler->logException($e); |  | ||||||
|                 Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return $this->render('create', [ |  | ||||||
|             'model' => $form, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return string|\yii\web\Response |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     public function actionUpdate($id) |  | ||||||
|     { |  | ||||||
|         $tag = $this->findModel($id); |  | ||||||
|         $form = new BlogTagSingleForm($tag); |  | ||||||
|         if ($form->load(Yii::$app->request->post()) && $form->validate()) { |  | ||||||
|             try { |  | ||||||
|                 $this->service->edit($tag->id, $form); |  | ||||||
|                 return $this->redirect(['view', 'id' => $tag->id]); |  | ||||||
|             } catch (\DomainException $e) { |  | ||||||
|                 Yii::$app->errorHandler->logException($e); |  | ||||||
|                 Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return $this->render('update', [ |  | ||||||
|             'model' => $form, |  | ||||||
|             'tag' => $tag, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return \yii\web\Response |  | ||||||
| 	 */ |  | ||||||
|     public function actionDelete($id) |  | ||||||
|     { |  | ||||||
|         try { |  | ||||||
|             $this->service->remove($id); |  | ||||||
|         } catch (\DomainException $e) { |  | ||||||
|             Yii::$app->errorHandler->logException($e); |  | ||||||
|             Yii::$app->session->setFlash('error', $e->getMessage()); |  | ||||||
|         } |  | ||||||
|         return $this->redirect(['index']); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	/** |  | ||||||
| 	 * @param $id |  | ||||||
| 	 * |  | ||||||
| 	 * @return BlogTag |  | ||||||
| 	 * @throws NotFoundHttpException |  | ||||||
| 	 */ |  | ||||||
|     protected function findModel($id): BlogTag |  | ||||||
|     { |  | ||||||
|         if (($model = BlogTag::findOne($id)) !== null) { |  | ||||||
|             return $model; |  | ||||||
|         } |  | ||||||
|         throw new NotFoundHttpException('The requested page does not exist.'); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,117 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\entities; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\queries\BlogCategoryQuery; |  | ||||||
| use core\behaviors\LanguageBehavior; |  | ||||||
| use core\behaviors\SluggableRelationBehavior; |  | ||||||
| use yii\db\ActiveRecord; |  | ||||||
| use Yii; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @property integer $id |  | ||||||
|  * @property string $slug |  | ||||||
|  * @property integer $sort |  | ||||||
|  * |  | ||||||
|  * |  | ||||||
|  * @method ActiveRecord findTranslation(string $language) |  | ||||||
|  * @method void saveTranslations($translations) |  | ||||||
|  * |  | ||||||
|  * @property ActiveRecord[] $translations |  | ||||||
|  * @property ActiveRecord $translation |  | ||||||
|  */ |  | ||||||
| class BlogCategory extends ActiveRecord |  | ||||||
| { |  | ||||||
|     public $_form; |  | ||||||
| 
 |  | ||||||
|     public static function create($form, $slug, $sort): self |  | ||||||
|     { |  | ||||||
|         $category        = new static(); |  | ||||||
|         $category->slug  = $slug; |  | ||||||
|         $category->sort  = $sort; |  | ||||||
|         $category->_form = $form; |  | ||||||
| 
 |  | ||||||
|         return $category; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function edit($form, $slug, $sort): void |  | ||||||
|     { |  | ||||||
|         $this->slug  = $slug; |  | ||||||
|         $this->sort  = $sort; |  | ||||||
|         $this->_form = $form; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function attributeLabels() |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             'id'               => Yii::t('blog', 'ID'), |  | ||||||
|             'name'             => Yii::t('blog', 'Name'), |  | ||||||
|             'slug'             => Yii::t('blog', 'SEO link'), |  | ||||||
|             'sort'             => Yii::t('blog', 'Sort'), |  | ||||||
|             'title'            => Yii::t('blog', 'Title'), |  | ||||||
|             'description'      => Yii::t('blog', 'Description'), |  | ||||||
|             'meta_title'       => Yii::t('blog', 'META Title'), |  | ||||||
|             'meta_description' => Yii::t('blog', 'META Description'), |  | ||||||
|             'meta_keywords'    => Yii::t('blog', 'META Keywords'), |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function getSeoTitle(): string |  | ||||||
|     { |  | ||||||
|         return $this->translation->meta_title ?: $this->getHeadingTile(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function getHeadingTile(): string |  | ||||||
|     { |  | ||||||
|         return $this->translation->title ?: $this->translation->name; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function getPostsCount(): int |  | ||||||
|     { |  | ||||||
|         return BlogPost::find()->where(['category_id' => $this->id])->count('*'); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static function tableName(): string |  | ||||||
|     { |  | ||||||
|         return '{{%blog_categories}}'; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function behaviors(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             /*[ |  | ||||||
|                 'class' => SluggableBehavior::class, |  | ||||||
|                 'attribute' => 'title', |  | ||||||
|                 'ensureUnique' => true, |  | ||||||
|                 'preserveNonEmptyValues' => true, |  | ||||||
|             ],*/ |  | ||||||
|             [ |  | ||||||
|                 'class'               => LanguageBehavior::class, |  | ||||||
|                 'virtualClassName'    => 'BlogCategoryVirtualTranslate', |  | ||||||
|                 'translatedLanguages' => \Yii::$app->params['translatedLanguages'], |  | ||||||
|                 'relativeField'       => 'blog_category_id', |  | ||||||
|                 'tableName'           => '{{%blog_categories_lng}}', |  | ||||||
|                 'attributes'          => [ |  | ||||||
|                     'title', |  | ||||||
|                     'description', |  | ||||||
|                     'name', |  | ||||||
|                     'meta_title', |  | ||||||
|                     'meta_description', |  | ||||||
|                     'meta_keywords' |  | ||||||
|                 ], |  | ||||||
|                 //'defaultLanguage' => basename(Yii::$app->getBasePath()) === 'backend' ? Yii::$app->language : Yii::$app->params['defaultLanguage'], |  | ||||||
|                 'defaultLanguage'     => \Yii::$app->params['defaultLanguage'], |  | ||||||
|             ], |  | ||||||
|             [ |  | ||||||
|                 'class'     => SluggableRelationBehavior::class, |  | ||||||
|                 'attribute' => 'name', |  | ||||||
|                 'relation'  => 'translation', |  | ||||||
|             ], |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static function find(): BlogCategoryQuery |  | ||||||
|     { |  | ||||||
|         return new BlogCategoryQuery(static::class); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,93 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\entities; |  | ||||||
| 
 |  | ||||||
| use core\entities\user\User; |  | ||||||
| use yii\db\ActiveQuery; |  | ||||||
| use yii\db\ActiveRecord; |  | ||||||
| use Yii; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @property int $id |  | ||||||
|  * @property int $created_at |  | ||||||
|  * @property int $post_id |  | ||||||
|  * @property int $user_id |  | ||||||
|  * @property int $parent_id |  | ||||||
|  * @property string $text |  | ||||||
|  * @property bool $active |  | ||||||
|  * |  | ||||||
|  * @property BlogPost $post |  | ||||||
|  */ |  | ||||||
| class BlogComment extends ActiveRecord |  | ||||||
| { |  | ||||||
|     public static function create($userId, $parentId, $text): self |  | ||||||
|     { |  | ||||||
|         $review = new static(); |  | ||||||
|         $review->user_id = $userId; |  | ||||||
|         $review->parent_id = $parentId; |  | ||||||
|         $review->text = $text; |  | ||||||
|         $review->created_at = time(); |  | ||||||
|         $review->active = true; |  | ||||||
|         return $review; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function edit($parentId, $text): void |  | ||||||
|     { |  | ||||||
|         $this->parent_id = $parentId; |  | ||||||
|         $this->text = $text; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function attributeLabels() |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             'id' => Yii::t('blog', 'ID'), |  | ||||||
|             'user_id' => Yii::t('blog', 'User'), |  | ||||||
|             'parent_id' => Yii::t('blog', 'Parent Comment ID'), |  | ||||||
|             'created_at' => Yii::t('blog', 'Created At'), |  | ||||||
|             'active' => Yii::t('blog', 'Published'), |  | ||||||
|             'post_id' => Yii::t('blog', 'Post'), |  | ||||||
|             'text' => Yii::t('blog', 'Comment'), |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function activate(): void |  | ||||||
|     { |  | ||||||
|         $this->active = true; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function draft(): void |  | ||||||
|     { |  | ||||||
|         $this->active = false; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function isActive(): bool |  | ||||||
|     { |  | ||||||
|         return $this->active == true; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function isIdEqualTo($id): bool |  | ||||||
|     { |  | ||||||
|         return $this->id == $id; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function isChildOf($id): bool |  | ||||||
|     { |  | ||||||
|         return $this->parent_id == $id; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function getPost(): ActiveQuery |  | ||||||
|     { |  | ||||||
|         return $this->hasOne(BlogPost::class, ['id' => 'post_id']); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function getUser(): ActiveQuery |  | ||||||
|     { |  | ||||||
|         return $this->hasOne(User::class, ['id' => 'user_id']); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static function tableName(): string |  | ||||||
|     { |  | ||||||
|         return '{{%blog_comments}}'; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,376 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\entities; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\queries\BlogPostQuery; |  | ||||||
| use core\behaviors\LanguageBehavior; |  | ||||||
| use core\behaviors\SluggableRelationBehavior; |  | ||||||
| use lhs\Yii2SaveRelationsBehavior\SaveRelationsBehavior; |  | ||||||
| use yii\behaviors\TimestampBehavior; |  | ||||||
| use yii\db\ActiveQuery; |  | ||||||
| use yii\db\ActiveRecord; |  | ||||||
| use yii\web\UploadedFile; |  | ||||||
| use yiidreamteam\upload\ImageUploadBehavior; |  | ||||||
| use Yii; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * This is the model class for table "posts". |  | ||||||
|  * |  | ||||||
|  * @property int $id |  | ||||||
|  * @property int $category_id |  | ||||||
|  * @property int $published_at |  | ||||||
|  * @property int $created_at |  | ||||||
|  * @property int $updated_at |  | ||||||
|  * @property string $image |  | ||||||
|  * @property string $video |  | ||||||
|  * @property int $status |  | ||||||
|  * @property int $comments_count |  | ||||||
|  * @property int $views |  | ||||||
|  * @property string $slug |  | ||||||
|  * @property int $type |  | ||||||
|  * @property int $revision_at |  | ||||||
|  * @property int $revision_id |  | ||||||
|  * |  | ||||||
|  * @method ActiveRecord findTranslation(string $language) |  | ||||||
|  * @method void saveTranslations($translations) |  | ||||||
|  * |  | ||||||
|  * @property ActiveRecord[] translations |  | ||||||
|  * @property ActiveRecord[] translation |  | ||||||
|  * |  | ||||||
|  * @property BlogComment[] $blogComments |  | ||||||
|  * @property BlogTagAssignment[] $blogTagAssignments |  | ||||||
|  * @property BlogTag[] $tags |  | ||||||
|  * @property BlogCategory $category |  | ||||||
|  * |  | ||||||
|  * @mixin ImageUploadBehavior |  | ||||||
|  */ |  | ||||||
| class BlogPost extends ActiveRecord |  | ||||||
| { |  | ||||||
| 	const STATUS_DRAFT = 0; |  | ||||||
| 	const STATUS_ACTIVE = 1; |  | ||||||
| 
 |  | ||||||
| 	const TYPE_PUBLIC = 0; |  | ||||||
| 	const TYPE_REVISION = 1; |  | ||||||
| 	const TYPE_PREVIEW = 2; |  | ||||||
| 
 |  | ||||||
| 	const FILE_ORIGINAL_PATH = '@staticRoot/origin/posts'; |  | ||||||
| 
 |  | ||||||
| 	public $_form; |  | ||||||
| 
 |  | ||||||
| 	public static function create($form, $categoryId, $slug, $published_at, $video, $type = BlogPost::TYPE_PUBLIC): self |  | ||||||
| 	{ |  | ||||||
| 		$post = new static(); |  | ||||||
| 		$post->category_id = $categoryId; |  | ||||||
| 		$post->slug = $slug; |  | ||||||
| 		$post->status = self::STATUS_DRAFT; |  | ||||||
| 		$post->created_at = time(); |  | ||||||
| 		$post->comments_count = 0; |  | ||||||
| 		$post->published_at = $published_at; |  | ||||||
| 		$post->video = $video; |  | ||||||
| 		$post->type = $type; |  | ||||||
| 		$post->revision_at = time(); |  | ||||||
| 		$post->_form = $form; |  | ||||||
| 		return $post; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function setImage(UploadedFile $image): void |  | ||||||
| 	{ |  | ||||||
| 		$this->image = $image; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	public function edit($form, $categoryId, $slug, $published_at, $video, $type = BlogPost::TYPE_PUBLIC): void |  | ||||||
| 	{ |  | ||||||
| 		$this->category_id = $categoryId; |  | ||||||
| 		$this->slug = $slug; |  | ||||||
| 		$this->published_at = $published_at; |  | ||||||
| 		$this->video = $video; |  | ||||||
| 		$this->type = $type; |  | ||||||
| 		$this->revision_at = time(); |  | ||||||
| 		$this->_form = $form; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @inheritdoc |  | ||||||
|      */ |  | ||||||
|     public static function tableName() |  | ||||||
|     { |  | ||||||
|         return 'blog_posts'; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @inheritdoc |  | ||||||
|      */ |  | ||||||
|     public function attributeLabels() |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             'id' => Yii::t('blog', 'ID'), |  | ||||||
|             'category_id' => Yii::t('blog', 'Category'), |  | ||||||
|             'published_at' => Yii::t('blog', 'Published At'), |  | ||||||
|             'created_at' => Yii::t('blog', 'Created At'), |  | ||||||
|             'updated_at' => Yii::t('blog', 'Updated At'), |  | ||||||
|             'title' => Yii::t('blog', 'Title'), |  | ||||||
|             'description' => Yii::t('blog', 'Description'), |  | ||||||
|             'content' => Yii::t('blog', 'Content'), |  | ||||||
|             'image' => Yii::t('blog', 'Image'), |  | ||||||
|             'video' => Yii::t('blog', 'Video'), |  | ||||||
|             'type' => Yii::t('blog', 'Type'), |  | ||||||
|             'revision_at' => Yii::t('blog', 'Revision At'), |  | ||||||
|             'status' => Yii::t('blog', 'Status'), |  | ||||||
|             'meta_json' => Yii::t('blog', 'Meta Json'), |  | ||||||
|             'comments_count' => Yii::t('blog', 'Comments Count'), |  | ||||||
|             'views' => Yii::t('blog', 'Views'), |  | ||||||
|             'slug' => Yii::t('blog', 'Slug'), |  | ||||||
|             'meta_title' => Yii::t('blog', 'META Title'), |  | ||||||
|             'meta_description' => Yii::t('blog', 'META Description'), |  | ||||||
|             'meta_keywords' => Yii::t('blog', 'META Keywords'), |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public function activate(): void |  | ||||||
| 	{ |  | ||||||
| 		if ($this->isActive()) { |  | ||||||
| 			throw new \DomainException('Post is already active.'); |  | ||||||
| 		} |  | ||||||
| 		$this->status = self::STATUS_ACTIVE; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function draft(): void |  | ||||||
| 	{ |  | ||||||
| 		if ($this->isDraft()) { |  | ||||||
| 			throw new \DomainException('Post is already draft.'); |  | ||||||
| 		} |  | ||||||
| 		$this->status = self::STATUS_DRAFT; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function isActive(): bool |  | ||||||
| 	{ |  | ||||||
| 		return $this->status == self::STATUS_ACTIVE; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	public function isDraft(): bool |  | ||||||
| 	{ |  | ||||||
| 		return $this->status == self::STATUS_DRAFT; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function getSeoTitle(): string |  | ||||||
| 	{ |  | ||||||
| 		return $this->translation->meta_title ?: $this->translation->title; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// Tags |  | ||||||
| 
 |  | ||||||
| 	public function assignTag($id): void |  | ||||||
| 	{ |  | ||||||
| 		$assignments = $this->blogTagAssignments; |  | ||||||
| 		foreach ($assignments as $assignment) { |  | ||||||
| 			if ($assignment->isForTag($id)) { |  | ||||||
| 				return; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		$assignments[] = BlogTagAssignment::create($id); |  | ||||||
| 		$this->blogTagAssignments = $assignments; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function revokeTag($id): void |  | ||||||
| 	{ |  | ||||||
| 		$assignments = $this->blogTagAssignments; |  | ||||||
| 		foreach ($assignments as $i => $assignment) { |  | ||||||
| 			if ($assignment->isForTag($id)) { |  | ||||||
| 				unset($assignments[$i]); |  | ||||||
| 				$this->blogTagAssignments = $assignments; |  | ||||||
| 				return; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		throw new \DomainException('Assignment is not found.'); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function revokeTags(): void |  | ||||||
| 	{ |  | ||||||
| 		$this->blogTagAssignments = []; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// Comments |  | ||||||
| 
 |  | ||||||
| 	public function addComment($userId, $parentId, $text): BlogComment |  | ||||||
| 	{ |  | ||||||
| 		$parent = $parentId ? $this->getComment($parentId) : null; |  | ||||||
| 		if ($parent && !$parent->isActive()) { |  | ||||||
| 			throw new \DomainException('Cannot add comment to inactive parent.'); |  | ||||||
| 		} |  | ||||||
| 		$comments = $this->blogComments; |  | ||||||
| 		$comments[] = $comment = BlogComment::create($userId, $parent ? $parent->id : null, $text); |  | ||||||
| 		$this->updateComments($comments); |  | ||||||
| 		return $comment; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function editComment($id, $parentId, $text): void |  | ||||||
| 	{ |  | ||||||
| 		$parent = $parentId ? $this->getComment($parentId) : null; |  | ||||||
| 		$comments = $this->blogComments; |  | ||||||
| 		foreach ($comments as $comment) { |  | ||||||
| 			if ($comment->isIdEqualTo($id)) { |  | ||||||
| 				$comment->edit($parent ? $parent->id : null, $text); |  | ||||||
| 				$this->updateComments($comments); |  | ||||||
| 				return; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		throw new \DomainException('Comment is not found.'); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function activateComment($id): void |  | ||||||
| 	{ |  | ||||||
| 		$comments = $this->blogComments; |  | ||||||
| 		foreach ($comments as $comment) { |  | ||||||
| 			if ($comment->isIdEqualTo($id)) { |  | ||||||
| 				$comment->activate(); |  | ||||||
| 				$this->updateComments($comments); |  | ||||||
| 				return; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		throw new \DomainException('Comment is not found.'); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function removeComment($id): void |  | ||||||
| 	{ |  | ||||||
| 		$comments = $this->blogComments; |  | ||||||
| 		foreach ($comments as $i => $comment) { |  | ||||||
| 			if ($comment->isIdEqualTo($id)) { |  | ||||||
| 				if ($this->hasChildren($comment->id)) { |  | ||||||
| 					$comment->draft(); |  | ||||||
| 				} else { |  | ||||||
| 					unset($comments[$i]); |  | ||||||
| 				} |  | ||||||
| 				$this->updateComments($comments); |  | ||||||
| 				return; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		throw new \DomainException('Comment is not found.'); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function getComment($id): BlogComment |  | ||||||
| 	{ |  | ||||||
| 		foreach ($this->blogComments as $comment) { |  | ||||||
| 			if ($comment->isIdEqualTo($id)) { |  | ||||||
| 				return $comment; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		throw new \DomainException('Comment is not found.'); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	private function hasChildren($id): bool |  | ||||||
| 	{ |  | ||||||
| 		foreach ($this->blogComments as $comment) { |  | ||||||
| 			if ($comment->isChildOf($id)) { |  | ||||||
| 				return true; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		return false; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	private function updateComments(array $comments): void |  | ||||||
| 	{ |  | ||||||
| 		$this->blogComments = $comments; |  | ||||||
| 		$this->comments_count = count(array_filter($comments, function (BlogComment $comment) { |  | ||||||
| 			return $comment->isActive(); |  | ||||||
| 		})); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	###################################### |  | ||||||
| 
 |  | ||||||
|     public function getBlogComments(): ActiveQuery |  | ||||||
|     { |  | ||||||
|         return $this->hasMany(BlogComment::class, ['post_id' => 'id']); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function getBlogTagAssignments(): ActiveQuery |  | ||||||
|     { |  | ||||||
|         return $this->hasMany(BlogTagAssignment::class, ['post_id' => 'id']); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function getTags(): ActiveQuery |  | ||||||
|     { |  | ||||||
|         return $this->hasMany(BlogTag::class, ['id' => 'tag_id'])->viaTable('blog_tag_assignments', ['post_id' => 'id']); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function getCategory(): ActiveQuery |  | ||||||
|     { |  | ||||||
|         return $this->hasOne(BlogCategory::class, ['id' => 'category_id']); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     ###################################### |  | ||||||
| 
 |  | ||||||
| 	public function behaviors(): array |  | ||||||
| 	{ |  | ||||||
| 		return [ |  | ||||||
| 			TimestampBehavior::class, |  | ||||||
| 			[ |  | ||||||
| 				'class' => SaveRelationsBehavior::class, |  | ||||||
| 				'relations' => ['blogTagAssignments', 'blogComments'], |  | ||||||
| 			], |  | ||||||
| 			/*[ |  | ||||||
| 				'class' => SluggableBehavior::class, |  | ||||||
| 				'attribute' => 'title', |  | ||||||
| 				'ensureUnique' => true, |  | ||||||
| 				'preserveNonEmptyValues' => true, |  | ||||||
| 			],*/ |  | ||||||
| 			[ |  | ||||||
| 				'class' => LanguageBehavior::class, |  | ||||||
| 				'virtualClassName' => 'BlogVirtualTranslate', |  | ||||||
| 				'translatedLanguages' => \Yii::$app->params['translatedLanguages'], |  | ||||||
| 				'relativeField' => 'blog_post_id', |  | ||||||
| 				'tableName' => "{{%blog_posts_lng}}", |  | ||||||
| 				'attributes' => ['title', 'description', 'content', 'meta_title', 'meta_description', 'meta_keywords'], |  | ||||||
| 				//'defaultLanguage' => basename(Yii::$app->getBasePath()) === 'backend' ? Yii::$app->language : Yii::$app->params['defaultLanguage'], |  | ||||||
| 				'defaultLanguage' => \Yii::$app->params['defaultLanguage'], |  | ||||||
| 			], |  | ||||||
| 			[ |  | ||||||
| 				'class' => SluggableRelationBehavior::class, |  | ||||||
| 				'attribute' => 'title', |  | ||||||
| 				'relation' => 'translation', |  | ||||||
| 			], |  | ||||||
| 			[ |  | ||||||
| 				// todo Image Sizes to settings or theme settings |  | ||||||
| 				'class' => ImageUploadBehavior::class, |  | ||||||
| 				'attribute' => 'image', |  | ||||||
| 				'createThumbsOnRequest' => true, |  | ||||||
| 				//'filePath' => $this::FILE_ORIGINAL_PATH . '/[[id]].[[extension]]', |  | ||||||
| 				'filePath' => '@staticRoot/origin/posts/[[id]].[[extension]]', |  | ||||||
| 				'fileUrl' => '@static/origin/posts/[[id]].[[extension]]', |  | ||||||
| 				'thumbPath' => '@staticRoot/cache/posts/[[profile]]_[[id]].[[extension]]', |  | ||||||
| 				'thumbUrl' => '@static/cache/posts/[[profile]]_[[id]].[[extension]]', |  | ||||||
| 				'thumbs' => [ |  | ||||||
| 					'blog_list' => ['width' => 750, 'height' => 300, 'resizeUp' => true], |  | ||||||
| 					'blog_post' => ['width' => 900, 'height' => 300], |  | ||||||
| 
 |  | ||||||
| 					'admin' => ['width' => 60, 'height' => 60], |  | ||||||
| 					'thumb' => ['width' => 150, 'height' => 150], |  | ||||||
| 					'list' => ['width' => 200, 'height' => 200], |  | ||||||
| 					'home_slider' => ['width' => 369, 'height' => 343], |  | ||||||
| 					'94_94' => ['width' => 94, 'height' => 94], |  | ||||||
| 					'368_287' => ['width' => 368, 'height' => 287], |  | ||||||
| 					'370_325' => ['width' => 370, 'height' => 325], |  | ||||||
| 					'683_407' => ['width' => 683, 'height' => 407], |  | ||||||
| 					'thumb_gallery_view' => ['width' => 300, 'height' => 170], |  | ||||||
| 					//'widget_list' => ['width' => 228, 'height' => 228], |  | ||||||
| 					//'origin' => ['processor' => [new WaterMarker(1024, 768, '@frontend/web/image/logo.png'), 'process']], |  | ||||||
| 					'origin' => ['width' => 1024, 'height' => 768], |  | ||||||
| 				], |  | ||||||
| 			], |  | ||||||
| 		]; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function transactions(): array |  | ||||||
| 	{ |  | ||||||
| 		return [ |  | ||||||
| 			self::SCENARIO_DEFAULT => self::OP_ALL, |  | ||||||
| 		]; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public static function find(): BlogPostQuery |  | ||||||
| 	{ |  | ||||||
| 		return new BlogPostQuery(static::class); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,58 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\entities; |  | ||||||
| 
 |  | ||||||
| use yii\db\ActiveRecord; |  | ||||||
| use yii\caching\TagDependency; |  | ||||||
| use yii\behaviors\SluggableBehavior; |  | ||||||
| use Yii; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @property integer $id |  | ||||||
|  * @property string $name |  | ||||||
|  * @property string $slug |  | ||||||
|  */ |  | ||||||
| class BlogTag extends ActiveRecord |  | ||||||
| { |  | ||||||
|     public static function create($name, $slug): self |  | ||||||
|     { |  | ||||||
|         $tag = new static(); |  | ||||||
|         $tag->name = $name; |  | ||||||
|         $tag->slug = $slug; |  | ||||||
|         return $tag; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function edit($name, $slug): void |  | ||||||
|     { |  | ||||||
|         $this->name = $name; |  | ||||||
|         if ($slug != $this->slug) |  | ||||||
|         { |  | ||||||
|             TagDependency::invalidate(\Yii::$app->cache, 'blog_tags'); |  | ||||||
|         } |  | ||||||
|         $this->slug = $slug; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function attributeLabels() |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             'name' => Yii::t('blog', 'Tag Name'), |  | ||||||
|             'slug' => Yii::t('blog', 'SEO link'), |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static function tableName(): string |  | ||||||
|     { |  | ||||||
|         return '{{%blog_tags}}'; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function behaviors() { |  | ||||||
| 	    return [ |  | ||||||
| 		    [ |  | ||||||
| 			    'class' => SluggableBehavior::class, |  | ||||||
| 			    'attribute' => 'name', |  | ||||||
| 			    'ensureUnique' => true, |  | ||||||
| 			    'preserveNonEmptyValues' => true, |  | ||||||
| 		    ], |  | ||||||
| 	    ]; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,37 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\entities; |  | ||||||
| 
 |  | ||||||
| use yii\db\ActiveRecord; |  | ||||||
| use yii\db\ActiveQuery; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @property integer $post_id; |  | ||||||
|  * @property integer $tag_id; |  | ||||||
|  * |  | ||||||
|  * @property BlogTag $tag |  | ||||||
|  */ |  | ||||||
| class BlogTagAssignment extends ActiveRecord |  | ||||||
| { |  | ||||||
|     public static function create($tagId): self |  | ||||||
|     { |  | ||||||
|         $assignment = new static(); |  | ||||||
|         $assignment->tag_id = $tagId; |  | ||||||
|         return $assignment; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function isForTag($id): bool |  | ||||||
|     { |  | ||||||
|         return $this->tag_id == $id; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static function tableName(): string |  | ||||||
|     { |  | ||||||
|         return '{{%blog_tag_assignments}}'; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public function getTag(): ActiveQuery |  | ||||||
| 	{ |  | ||||||
| 		return $this->hasOne(BlogTag::class, ['id' => 'tag_id']); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,15 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Created by Error202 |  | ||||||
|  * Date: 27.07.2018 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\entities\queries; |  | ||||||
| 
 |  | ||||||
| use yii\db\ActiveQuery; |  | ||||||
| use core\components\LanguageTranslateTrait; |  | ||||||
| 
 |  | ||||||
| class BlogCategoryQuery extends ActiveQuery |  | ||||||
| { |  | ||||||
| 	use LanguageTranslateTrait; |  | ||||||
| } |  | ||||||
| @ -1,50 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\entities\queries; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| use core\components\LanguageTranslateTrait; |  | ||||||
| use yii\db\ActiveQuery; |  | ||||||
| 
 |  | ||||||
| class BlogPostQuery extends ActiveQuery |  | ||||||
| { |  | ||||||
| 	use LanguageTranslateTrait; |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @param null $alias |  | ||||||
|      * @return $this |  | ||||||
|      */ |  | ||||||
|     public function active($alias = null) |  | ||||||
|     { |  | ||||||
|         return $this->andWhere([ |  | ||||||
|             ($alias ? $alias . '.' : '') . 'status' => BlogPost::STATUS_ACTIVE, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function pubDate() |  | ||||||
|     { |  | ||||||
|     	return $this->andWhere(['<', 'published_at', time()]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function typePublic($alias = null) |  | ||||||
|     { |  | ||||||
| 	    return $this->andWhere([ |  | ||||||
| 		    ($alias ? $alias . '.' : '') . 'type' => BlogPost::TYPE_PUBLIC, |  | ||||||
| 	    ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /*public function byType($type) |  | ||||||
|     { |  | ||||||
|     	return $this->andWhere(['type_id' => $type]); |  | ||||||
|     }*/ |  | ||||||
| 
 |  | ||||||
|     public function last() |  | ||||||
|     { |  | ||||||
|     	return $this->orderBy(['published_at' => SORT_DESC]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public function popular() |  | ||||||
| 	{ |  | ||||||
| 		return $this->orderBy(['views' => SORT_DESC]); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,83 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\forms; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogCategory; |  | ||||||
| use core\components\LanguageDynamicModel; |  | ||||||
| use core\forms\CompositeForm; |  | ||||||
| use core\forms\MetaForm; |  | ||||||
| use core\validators\SlugValidator; |  | ||||||
| use Yii; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @property MetaForm $meta; |  | ||||||
|  */ |  | ||||||
| class BlogCategoryForm extends LanguageDynamicModel |  | ||||||
| { |  | ||||||
|     public $name; |  | ||||||
|     public $slug; |  | ||||||
|     public $title; |  | ||||||
|     public $description; |  | ||||||
|     public $sort; |  | ||||||
| 	public $meta_title; |  | ||||||
| 	public $meta_description; |  | ||||||
| 	public $meta_keywords; |  | ||||||
| 
 |  | ||||||
|     public $_category; |  | ||||||
| 
 |  | ||||||
|     public function __construct(BlogCategory $category = null, array $attributes = [], $config = []) |  | ||||||
|     { |  | ||||||
|         if ($category) { |  | ||||||
|             $this->slug = $category->slug; |  | ||||||
|             $this->sort = $category->sort; |  | ||||||
|             $this->_category = $category; |  | ||||||
|         } else { |  | ||||||
|             $this->sort = BlogCategory::find()->max('sort') + 1; |  | ||||||
|         } |  | ||||||
|         parent::__construct($category, $attributes, $config); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function rules(): array |  | ||||||
|     { |  | ||||||
| 	    return array_merge( |  | ||||||
| 		    parent::rules(), |  | ||||||
| 		    [ |  | ||||||
| 	            [['name'], 'required'], |  | ||||||
| 	            [['name', 'slug', 'title', 'meta_title', 'meta_keywords'], 'string', 'max' => 255], |  | ||||||
| 	            [['description', 'meta_description'], 'string'], |  | ||||||
| 	            ['slug', SlugValidator::class], |  | ||||||
| 	            [['slug'], 'unique', 'targetClass' => BlogCategory::class, 'filter' => $this->_category ? ['<>', 'id', $this->_category->id] : null] |  | ||||||
| 	        ] |  | ||||||
| 	    ); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function attributeLabels() |  | ||||||
|     { |  | ||||||
| 	    return array_merge( |  | ||||||
| 		    parent::attributeLabels(), |  | ||||||
| 		    [ |  | ||||||
| 	            'name' => Yii::t('blog', 'Name'), |  | ||||||
| 	            'slug' => Yii::t('blog', 'SEO link'), |  | ||||||
| 	            'sort' => Yii::t('blog', 'Sort'), |  | ||||||
| 	            'title' => Yii::t('blog', 'Title'), |  | ||||||
| 	            'description' => Yii::t('blog', 'Description'), |  | ||||||
| 	            'meta_title' => Yii::t('blog', 'META Title'), |  | ||||||
| 	            'meta_description' => Yii::t('blog', 'META Description'), |  | ||||||
| 	            'meta_keywords' => Yii::t('blog', 'META Keywords'), |  | ||||||
| 	        ] |  | ||||||
| 	    ); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public function attributeHints() { |  | ||||||
| 		return array_merge( |  | ||||||
| 			parent::attributeHints(), |  | ||||||
| 			[ |  | ||||||
| 				'slug' => Yii::t('blog', 'SEO link will be generated automatically if not specified'), |  | ||||||
| 			] |  | ||||||
| 		); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
|     public function updateSort() { |  | ||||||
| 	    $this->sort = BlogCategory::find()->max('sort') + 1; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,37 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\forms; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogComment; |  | ||||||
| use yii\base\Model; |  | ||||||
| use Yii; |  | ||||||
| 
 |  | ||||||
| class BlogCommentEditForm extends Model |  | ||||||
| { |  | ||||||
|     public $parentId; |  | ||||||
|     public $text; |  | ||||||
| 
 |  | ||||||
|     public function __construct(BlogComment $comment, $config = []) |  | ||||||
|     { |  | ||||||
|         $this->parentId = $comment->parent_id; |  | ||||||
|         $this->text = $comment->text; |  | ||||||
|         parent::__construct($config); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function rules(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             [['text'], 'required'], |  | ||||||
|             ['text', 'string'], |  | ||||||
|             ['parentId', 'integer'], |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function attributeLabels() |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             'parentId' => Yii::t('blog', 'Parent Comment ID'), |  | ||||||
|             'text' => Yii::t('blog', 'Comment'), |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,20 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\forms; |  | ||||||
| 
 |  | ||||||
| use yii\base\Model; |  | ||||||
| 
 |  | ||||||
| class BlogCommentForm extends Model |  | ||||||
| { |  | ||||||
|     public $parentId; |  | ||||||
|     public $text; |  | ||||||
| 
 |  | ||||||
|     public function rules(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             [['text'], 'required'], |  | ||||||
|             ['text', 'string'], |  | ||||||
|             ['parentId', 'integer'], |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,144 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\forms; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogCategory; |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| use core\forms\CompositeForm; |  | ||||||
| use core\forms\CompositeLanguageForm; |  | ||||||
| use core\forms\MetaForm; |  | ||||||
| use core\validators\SlugValidator; |  | ||||||
| use yii\db\ActiveQuery; |  | ||||||
| use yii\db\ActiveRecord; |  | ||||||
| use yii\helpers\ArrayHelper; |  | ||||||
| use yii\web\UploadedFile; |  | ||||||
| use Yii; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @property MetaForm $meta |  | ||||||
|  * @property BlogTagForm $tags |  | ||||||
|  */ |  | ||||||
| class BlogPostForm extends CompositeLanguageForm |  | ||||||
| { |  | ||||||
| 	public $type; |  | ||||||
| 
 |  | ||||||
|     public $category_id; |  | ||||||
|     public $title; |  | ||||||
|     public $description; |  | ||||||
|     public $content; |  | ||||||
|     public $image; |  | ||||||
|     public $video; |  | ||||||
|     public $published_at; |  | ||||||
|     public $slug; |  | ||||||
|     public $reset_image; |  | ||||||
|     public $status; |  | ||||||
| 	public $meta_title; |  | ||||||
| 	public $meta_description; |  | ||||||
| 	public $meta_keywords; |  | ||||||
| 
 |  | ||||||
| 	public $_post; |  | ||||||
| 
 |  | ||||||
| 	public function __construct(BlogPost $post = null, array $attributes = [], $config = []) |  | ||||||
|     { |  | ||||||
|         if ($post) { |  | ||||||
|             $this->category_id = $post->category_id; |  | ||||||
|             $this->video = $post->video; |  | ||||||
|             $this->published_at = $post->published_at; |  | ||||||
|             $this->slug = $post->slug; |  | ||||||
|             $this->tags = new BlogTagForm($post); |  | ||||||
|             $this->status = $post->status; |  | ||||||
|             $this->_post = $post; |  | ||||||
|         } else { |  | ||||||
|             $this->tags = new BlogTagForm(); |  | ||||||
|             $this->status = 0; |  | ||||||
|         } |  | ||||||
|         parent::__construct($post, $attributes, $config); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function rules(): array |  | ||||||
|     { |  | ||||||
| 	    return array_merge( |  | ||||||
| 		    parent::rules(), |  | ||||||
| 		    [ |  | ||||||
| 	            [['category_id', 'title'], 'required'], |  | ||||||
| 	            [['title', 'video', 'meta_title', 'meta_keywords'], 'string', 'max' => 255], |  | ||||||
| 	            [['category_id', 'status'], 'integer'], |  | ||||||
| 	            [['description', 'content', 'meta_description'], 'string'], |  | ||||||
| 	            [['image'], 'image'], |  | ||||||
| 		        ['reset_image', 'boolean'], |  | ||||||
| 		        ['published_at', 'safe'], |  | ||||||
| 		        ['slug', SlugValidator::class], |  | ||||||
| 		        [['slug'], 'unique', 'targetClass' => BlogPost::class, 'filter' => function (ActiveQuery $query) { |  | ||||||
| 	                if ($this->type != BlogPost::TYPE_PUBLIC) { |  | ||||||
| 			            $query->andWhere($this->type . '=' . BlogPost::TYPE_PUBLIC); |  | ||||||
| 		            } |  | ||||||
| 
 |  | ||||||
| 	                $query->andWhere(['type' => BlogPost::TYPE_PUBLIC]); |  | ||||||
| 	                if ($this->_post) { |  | ||||||
| 	                    $query->andWhere(['<>', 'id', $this->_post->id]); |  | ||||||
| 		            } |  | ||||||
| 		            return $query; |  | ||||||
| 		        }], |  | ||||||
| 	        ] |  | ||||||
| 	    ); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function attributeLabels() |  | ||||||
|     { |  | ||||||
| 	    return array_merge( |  | ||||||
| 		    parent::attributeLabels(), |  | ||||||
| 		    [ |  | ||||||
| 			    'id' => Yii::t('blog', 'ID'), |  | ||||||
| 			    'category_id' => Yii::t('blog', 'Category'), |  | ||||||
| 			    'published_at' => Yii::t('blog', 'Published At'), |  | ||||||
| 			    'created_at' => Yii::t('blog', 'Created At'), |  | ||||||
| 			    'updated_at' => Yii::t('blog', 'Updated At'), |  | ||||||
| 			    'title' => Yii::t('blog', 'Title'), |  | ||||||
| 			    'description' => Yii::t('blog', 'Description'), |  | ||||||
| 			    'content' => Yii::t('blog', 'Content'), |  | ||||||
| 			    'image' => Yii::t('blog', 'Image'), |  | ||||||
| 			    'video' => Yii::t('blog', 'Video'), |  | ||||||
| 			    'status' => Yii::t('blog', 'Status'), |  | ||||||
| 			    'comments_count' => Yii::t('blog', 'Comments Count'), |  | ||||||
| 			    'views' => Yii::t('blog', 'Views'), |  | ||||||
| 			    'slug' => Yii::t('blog', 'Slug'), |  | ||||||
| 			    'reset_image' => Yii::t('blog', 'Reset Image'), |  | ||||||
| 			    'meta_title' => Yii::t('blog', 'META Title'), |  | ||||||
| 			    'meta_description' => Yii::t('blog', 'META Description'), |  | ||||||
| 			    'meta_keywords' => Yii::t('blog', 'META Keywords'), |  | ||||||
| 		    ] |  | ||||||
| 	    ); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function attributeHints() { |  | ||||||
| 	    return array_merge( |  | ||||||
| 		    parent::attributeHints(), |  | ||||||
| 		    [ |  | ||||||
| 			    'published_at' => Yii::t('blog', 'The article will be published after the specified date if its status is not a draft'), |  | ||||||
| 			    'slug' => Yii::t('pages', 'SEO link will be generated automatically if not specified'), |  | ||||||
| 		    ] |  | ||||||
| 	    ); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public function categoriesList(): array |  | ||||||
|     { |  | ||||||
| 	    return ArrayHelper::map(BlogCategory::find()->orderBy('sort')->all(), 'id', function (BlogCategory $category) { |  | ||||||
| 		    return $category->translation->name; |  | ||||||
| 	    }); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     protected function internalForms(): array |  | ||||||
|     { |  | ||||||
|         return ['tags']; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function beforeValidate(): bool |  | ||||||
|     { |  | ||||||
|         if (parent::beforeValidate()) { |  | ||||||
| 	        $this->image = UploadedFile::getInstance($this, 'image'); |  | ||||||
|             $this->published_at = strtotime($this->published_at); |  | ||||||
|             return true; |  | ||||||
|         } |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,46 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\forms; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| use common\modules\blog\entities\BlogTag; |  | ||||||
| use yii\base\Model; |  | ||||||
| use yii\helpers\ArrayHelper; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @property array $newNames |  | ||||||
|  */ |  | ||||||
| class BlogTagForm extends Model |  | ||||||
| { |  | ||||||
|     public $existing = []; |  | ||||||
|     public $textNew; |  | ||||||
|     public $new_tags; |  | ||||||
| 
 |  | ||||||
|     public function __construct(BlogPost $post = null, $config = []) |  | ||||||
|     { |  | ||||||
|         if ($post) { |  | ||||||
| 	        $this->new_tags = ArrayHelper::map($post->blogTagAssignments, 'tag_id', 'tag.name'); |  | ||||||
|         } |  | ||||||
|         parent::__construct($config); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function rules(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             ['existing', 'each', 'rule' => ['integer']], |  | ||||||
|             [['textNew'], 'string'], |  | ||||||
|             ['existing', 'default', 'value' => []], |  | ||||||
| 	        ['new_tags', 'each', 'rule' => ['string']], |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function tagsList(): array |  | ||||||
|     { |  | ||||||
|         return ArrayHelper::map(BlogTag::find()->orderBy('name')->asArray()->all(), 'id', 'name'); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function getNewNames(): array |  | ||||||
|     { |  | ||||||
|         return array_filter(array_map('trim', preg_split('#\s*,\s*#i', $this->textNew))); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,51 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\forms; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogTag; |  | ||||||
| use core\validators\SlugValidator; |  | ||||||
| use yii\base\Model; |  | ||||||
| use Yii; |  | ||||||
| 
 |  | ||||||
| class BlogTagSingleForm extends Model |  | ||||||
| { |  | ||||||
|     public $name; |  | ||||||
|     public $slug; |  | ||||||
|     public $type_id; |  | ||||||
| 
 |  | ||||||
|     private $_tag; |  | ||||||
| 
 |  | ||||||
|     public function __construct(BlogTag $tag = null, $config = []) |  | ||||||
|     { |  | ||||||
|         if ($tag) { |  | ||||||
|             $this->name = $tag->name; |  | ||||||
|             $this->slug = $tag->slug; |  | ||||||
|             $this->_tag = $tag; |  | ||||||
|         } |  | ||||||
|         parent::__construct($config); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function rules(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             [['name'], 'required'], |  | ||||||
|             [['name', 'slug'], 'string', 'max' => 255], |  | ||||||
|             ['slug', SlugValidator::class], |  | ||||||
|             [['name', 'slug'], 'unique', 'targetClass' => BlogTag::class, 'filter' => $this->_tag ? ['<>', 'id', $this->_tag->id] : null] |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function attributeLabels() |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             'name' => Yii::t('blog', 'Tag Name'), |  | ||||||
|             'slug' => Yii::t('blog', 'SEO link'), |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function attributeHints() { |  | ||||||
| 	    return [ |  | ||||||
| 		    'slug' => Yii::t('pages', 'SEO link will be generated automatically if not specified'), |  | ||||||
| 	    ]; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,56 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\forms\search; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogCategory; |  | ||||||
| use yii\base\Model; |  | ||||||
| use yii\data\ActiveDataProvider; |  | ||||||
| 
 |  | ||||||
| class BlogCategorySearch extends Model |  | ||||||
| { |  | ||||||
|     public $id; |  | ||||||
|     public $name; |  | ||||||
|     public $slug; |  | ||||||
|     public $title; |  | ||||||
| 
 |  | ||||||
|     public function rules(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             [['id'], 'integer'], |  | ||||||
| 	        [['slug'], 'safe'], |  | ||||||
|             [['name', 'title'], 'safe'], |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @param array $params |  | ||||||
|      * @return ActiveDataProvider |  | ||||||
|      */ |  | ||||||
|     public function search(array $params): ActiveDataProvider |  | ||||||
|     { |  | ||||||
|         $query = BlogCategory::find(); |  | ||||||
| 
 |  | ||||||
|         $dataProvider = new ActiveDataProvider([ |  | ||||||
|             'query' => $query, |  | ||||||
|             'sort' => [ |  | ||||||
|                 'defaultOrder' => ['sort' => SORT_ASC] |  | ||||||
|             ] |  | ||||||
|         ]); |  | ||||||
|         $this->load($params); |  | ||||||
| 
 |  | ||||||
|         if (!$this->validate()) { |  | ||||||
|             $query->where('0=1'); |  | ||||||
|             return $dataProvider; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         $query->andFilterWhere([ |  | ||||||
|             'id' => $this->id, |  | ||||||
|         ]); |  | ||||||
| 
 |  | ||||||
|         $query |  | ||||||
|             ->andFilterWhere(['like', 'name', $this->name]) |  | ||||||
|             ->andFilterWhere(['like', 'slug', $this->slug]) |  | ||||||
|             ->andFilterWhere(['like', 'title', $this->title]); |  | ||||||
|         return $dataProvider; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,72 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\forms\search; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogComment; |  | ||||||
| use Yii; |  | ||||||
| use yii\base\Model; |  | ||||||
| use yii\data\ActiveDataProvider; |  | ||||||
| 
 |  | ||||||
| class BlogCommentSearch extends Model |  | ||||||
| { |  | ||||||
|     public $id; |  | ||||||
|     public $text; |  | ||||||
|     public $active; |  | ||||||
|     public $post_id; |  | ||||||
| 
 |  | ||||||
|     public function rules(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             [['id', 'post_id'], 'integer'], |  | ||||||
|             [['text'], 'safe'], |  | ||||||
|             [['active'], 'boolean'], |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @param array $params |  | ||||||
|      * @return ActiveDataProvider |  | ||||||
|      */ |  | ||||||
|     public function search(array $params): ActiveDataProvider |  | ||||||
|     { |  | ||||||
|         $query = BlogComment::find()->with(['post']); |  | ||||||
| 
 |  | ||||||
|         $dataProvider = new ActiveDataProvider([ |  | ||||||
|             'query' => $query, |  | ||||||
|             'key' => function (BlogComment $comment) { |  | ||||||
|                 return [ |  | ||||||
|                     'post_id' => $comment->post_id, |  | ||||||
|                     'id' => $comment->id, |  | ||||||
|                 ]; |  | ||||||
|             }, |  | ||||||
|             'sort' => [ |  | ||||||
|                 'defaultOrder' => ['id' => SORT_DESC] |  | ||||||
|             ] |  | ||||||
|         ]); |  | ||||||
| 
 |  | ||||||
|         $this->load($params); |  | ||||||
| 
 |  | ||||||
|         if (!$this->validate()) { |  | ||||||
|             $query->where('0=1'); |  | ||||||
|             return $dataProvider; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         $query->andFilterWhere([ |  | ||||||
|             'id' => $this->id, |  | ||||||
|             'post_id' => $this->post_id, |  | ||||||
|         ]); |  | ||||||
| 
 |  | ||||||
|         $query |  | ||||||
|             ->andFilterWhere(['like', 'text', $this->text]); |  | ||||||
| 
 |  | ||||||
|         return $dataProvider; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function activeList(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             1 => Yii::$app->formatter->asBoolean(true), |  | ||||||
|             0 => Yii::$app->formatter->asBoolean(false), |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,71 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\forms\search; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogCategory; |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| use common\modules\blog\helpers\BlogPostHelper; |  | ||||||
| use yii\base\Model; |  | ||||||
| use yii\data\ActiveDataProvider; |  | ||||||
| use yii\helpers\ArrayHelper; |  | ||||||
| 
 |  | ||||||
| class BlogPostSearch extends Model |  | ||||||
| { |  | ||||||
|     public $id; |  | ||||||
|     public $title; |  | ||||||
|     public $status; |  | ||||||
|     public $category_id; |  | ||||||
| 
 |  | ||||||
|     public function rules(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             [['id', 'status', 'category_id'], 'integer'], |  | ||||||
|             [['title'], 'safe'], |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @param array $params |  | ||||||
|      * @return ActiveDataProvider |  | ||||||
|      */ |  | ||||||
|     public function search(array $params): ActiveDataProvider |  | ||||||
|     { |  | ||||||
|         $query = BlogPost::find()->typePublic()->joinWith('translation'); |  | ||||||
| 
 |  | ||||||
|         $dataProvider = new ActiveDataProvider([ |  | ||||||
|             'query' => $query, |  | ||||||
|             'sort' => [ |  | ||||||
|                 'defaultOrder' => ['id' => SORT_DESC] |  | ||||||
|             ] |  | ||||||
|         ]); |  | ||||||
| 
 |  | ||||||
|         $this->load($params); |  | ||||||
| 
 |  | ||||||
|         if (!$this->validate()) { |  | ||||||
|             $query->where('0=1'); |  | ||||||
|             return $dataProvider; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         $query->andFilterWhere([ |  | ||||||
|             'id' => $this->id, |  | ||||||
|             'category_id' => $this->category_id, |  | ||||||
|         ]); |  | ||||||
| 
 |  | ||||||
|         $query |  | ||||||
|             ->andFilterWhere(['like', 'title', $this->title]); |  | ||||||
| 
 |  | ||||||
|         return $dataProvider; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function categoriesList(): array |  | ||||||
|     { |  | ||||||
|         return ArrayHelper::map(BlogCategory::find()->orderBy('sort')->all(), 'id', function (BlogCategory $category) { |  | ||||||
|         	return $category->translation->name; |  | ||||||
|         }); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function statusList(): array |  | ||||||
|     { |  | ||||||
|         return BlogPostHelper::statusList(); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,55 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\forms\search; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogTag; |  | ||||||
| use yii\base\Model; |  | ||||||
| use yii\data\ActiveDataProvider; |  | ||||||
| 
 |  | ||||||
| class BlogTagSearch extends Model |  | ||||||
| { |  | ||||||
|     public $id; |  | ||||||
|     public $name; |  | ||||||
|     public $slug; |  | ||||||
| 
 |  | ||||||
|     public function rules(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             [['id'], 'integer'], |  | ||||||
|             [['name', 'slug'], 'safe'], |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @param array $params |  | ||||||
|      * @return ActiveDataProvider |  | ||||||
|      */ |  | ||||||
|     public function search(array $params): ActiveDataProvider |  | ||||||
|     { |  | ||||||
|         $query = BlogTag::find(); |  | ||||||
| 
 |  | ||||||
|         $dataProvider = new ActiveDataProvider([ |  | ||||||
|             'query' => $query, |  | ||||||
|             'sort' => [ |  | ||||||
|                 'defaultOrder' => ['name' => SORT_ASC] |  | ||||||
|             ] |  | ||||||
|         ]); |  | ||||||
| 
 |  | ||||||
|         $this->load($params); |  | ||||||
| 
 |  | ||||||
|         if (!$this->validate()) { |  | ||||||
|             $query->where('0=1'); |  | ||||||
|             return $dataProvider; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         $query->andFilterWhere([ |  | ||||||
|             'id' => $this->id, |  | ||||||
|         ]); |  | ||||||
| 
 |  | ||||||
|         $query |  | ||||||
|             ->andFilterWhere(['like', 'name', $this->name]) |  | ||||||
|             ->andFilterWhere(['like', 'slug', $this->slug]); |  | ||||||
| 
 |  | ||||||
|         return $dataProvider; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,132 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\helpers; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| use common\modules\blog\forms\BlogPostForm; |  | ||||||
| use common\modules\blog\repositories\BlogRepository; |  | ||||||
| use common\modules\blog\repositories\read\BlogPostReadRepository; |  | ||||||
| use common\modules\blog\services\BlogPostManageService; |  | ||||||
| use core\dispatchers\DeferredEventDispatcher; |  | ||||||
| use core\entities\post\Post; |  | ||||||
| use core\services\TransactionManager; |  | ||||||
| use yii\helpers\ArrayHelper; |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use Yii; |  | ||||||
| 
 |  | ||||||
| class BlogPostHelper |  | ||||||
| { |  | ||||||
| 	public static function statusList(): array |  | ||||||
|     { |  | ||||||
|         return [ |  | ||||||
|             Post::STATUS_DRAFT => Yii::t('blog', 'Draft'), |  | ||||||
|             Post::STATUS_ACTIVE => Yii::t('blog', 'Active'), |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static function statusName($status): string |  | ||||||
|     { |  | ||||||
|         return ArrayHelper::getValue(self::statusList(), $status); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static function statusLabel($status): string |  | ||||||
|     { |  | ||||||
|         switch ($status) { |  | ||||||
|             case Post::STATUS_DRAFT: |  | ||||||
|                 $class = 'label label-default'; |  | ||||||
|                 break; |  | ||||||
|             case Post::STATUS_ACTIVE: |  | ||||||
|                 $class = 'label label-success'; |  | ||||||
|                 break; |  | ||||||
|             default: |  | ||||||
|                 $class = 'label label-default'; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         return Html::tag('span', ArrayHelper::getValue(self::statusList(), $status), [ |  | ||||||
|             'class' => $class, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public static function parseYoutubeUrl($url) |  | ||||||
| 	{ |  | ||||||
| 		$urls = parse_url($url); |  | ||||||
| 		//url is http://youtu.be/xxxx |  | ||||||
| 		if($urls['host'] == 'youtu.be'){ |  | ||||||
| 			$id = ltrim($urls['path'],'/'); |  | ||||||
| 		} |  | ||||||
| 		//url is http://www.youtube.com/embed/xxxx |  | ||||||
| 		else if(strpos($urls['path'],'embed') == 1){ |  | ||||||
| 			$id = end(explode('/',$urls['path'])); |  | ||||||
| 		} |  | ||||||
| 		//url is xxxx only |  | ||||||
| 		else if(strpos($url,'/')===false){ |  | ||||||
| 			$id = $url; |  | ||||||
| 		} |  | ||||||
| 		//http://www.youtube.com/watch?feature=player_embedded&v=m-t4pcO99gI |  | ||||||
| 		//url is http://www.youtube.com/watch?v=xxxx |  | ||||||
| 		else{ |  | ||||||
| 			parse_str($urls['query']); |  | ||||||
| 			/* @var $v */ |  | ||||||
| 			$id = $v; |  | ||||||
| 			if(!empty($feature)){ |  | ||||||
| 				$id = end(explode('v=',$urls['query'])); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		return $id; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public static function saveRevision1(BlogPost $model) { |  | ||||||
| 		if (!$model->revision_id) { |  | ||||||
| 
 |  | ||||||
| 			$blogForm = new BlogPostForm($model); |  | ||||||
| 			$blog = BlogPost::create( |  | ||||||
| 				$blogForm, |  | ||||||
| 				$model->category_id, |  | ||||||
| 				$model->slug, |  | ||||||
| 				$model->published_at, |  | ||||||
| 				$model->video, |  | ||||||
| 				$model->type |  | ||||||
| 			); |  | ||||||
| 			$blog->type = BlogPost::TYPE_REVISION; |  | ||||||
| 			$blog->revision_at = $model->updated_at; |  | ||||||
| 			$blog->revision_id = $model->id; |  | ||||||
| 
 |  | ||||||
| 			foreach ($model->tags as $tag) { |  | ||||||
| 				$blog->assignTag($tag->id); |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			$blog->save(); |  | ||||||
| 
 |  | ||||||
| 			if ($model->image) { |  | ||||||
| 				$path  = Yii::getAlias( '@staticRoot/origin/posts' ); |  | ||||||
| 				$parts = pathinfo( $model->image ); |  | ||||||
| 				copy( $path . '/' . $model->id . '.' . $parts['extension'], $path . '/' . $blog->id . '.' . $parts['extension'] ); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public static function saveRevision(BlogPost $model) { |  | ||||||
| 		if (!$model->revision_id) { |  | ||||||
| 			$revision                      = clone $model; |  | ||||||
| 			$revision->id                  = null; |  | ||||||
| 			$revision->isNewRecord         = true; |  | ||||||
| 			$revision->revision_at         = $revision->updated_at; |  | ||||||
| 			$revision->revision_id         = $model->id; |  | ||||||
| 			$revision->type                = BlogPost::TYPE_REVISION; |  | ||||||
| 			$revision->_form               = new BlogPostForm($model); |  | ||||||
| 			$revision->save(); |  | ||||||
| 
 |  | ||||||
| 			// tags |  | ||||||
| 			foreach ($model->tags as $tag) { |  | ||||||
| 				$revision->assignTag($tag->id); |  | ||||||
| 			} |  | ||||||
| 			$revision->save(); |  | ||||||
| 
 |  | ||||||
| 			if ($model->image) { |  | ||||||
| 				$path  = Yii::getAlias( '@staticRoot/origin/posts' ); |  | ||||||
| 				$parts = pathinfo( $model->image ); |  | ||||||
| 				copy( $path . '/' . $model->id . '.' . $parts['extension'], $path . '/' . $revision->id . '.' . $parts['extension'] ); |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,11 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| return [ |  | ||||||
|     'version'     => '1.0.1', |  | ||||||
|     'name'        => 'blog', |  | ||||||
|     'description' => 'Blog system for site with comments and slug', |  | ||||||
|     'module'      => 'BlogModule', |  | ||||||
|     'permissions' => [ |  | ||||||
|         'BlogManagement' => 'Blog management system' |  | ||||||
|     ], |  | ||||||
| ]; |  | ||||||
| @ -1,83 +0,0 @@ | |||||||
| <?php |  | ||||||
| return [ |  | ||||||
| 	'blog' => 'Блог', |  | ||||||
| 	'Blog system for site with comments and slug' => 'Публикация статей на сайте в виде ленты. Статьи разделены по категориям', |  | ||||||
| 	'All Posts' => 'Все статьи', |  | ||||||
| 	'Posts' => 'Статьи', |  | ||||||
| 	'Categories' => 'Категории', |  | ||||||
| 	'Tags' => 'Теги', |  | ||||||
| 	'News' => 'Новости', |  | ||||||
| 	'Comments' => 'Комментарии', |  | ||||||
| 	'Articles' => 'Статьи', |  | ||||||
| 	'Blog' => 'Блог', |  | ||||||
| 	'Blogs' => 'Блоги', |  | ||||||
| 	'Events' => 'События', |  | ||||||
| 	'Gallery' => 'Фотогалерея', |  | ||||||
| 	'Create Post' => 'Новая статья', |  | ||||||
| 	'Create Category' => 'Новая категория', |  | ||||||
| 	'Create Tag' => 'Новый тег', |  | ||||||
| 	'Common' => 'Основное', |  | ||||||
| 	'Title' => 'Заголовок', |  | ||||||
| 	'Description' => 'Описание', |  | ||||||
| 	'Content' => 'Содержание', |  | ||||||
| 	'Image' => 'Изображение', |  | ||||||
| 	'Existing' => 'Существующие', |  | ||||||
| 	'New tag' => 'Новый тег', |  | ||||||
| 	'Category' => 'Категория', |  | ||||||
| 	'Post is already active.' => 'Статья уже опубликована.', |  | ||||||
| 	'Published At' => 'Опубликовано', |  | ||||||
| 	'Created At' => 'Создано', |  | ||||||
| 	'Updated At' => 'Обновлено', |  | ||||||
| 	'Status' => 'Статус', |  | ||||||
| 	'ID' => '№', |  | ||||||
| 	'SEO' => 'МЕТА теги', |  | ||||||
| 	'Tag Name' => 'Тег', |  | ||||||
| 	'SEO link' => 'ЧПУ ссылка', |  | ||||||
| 	'Draft' => 'Черновик', |  | ||||||
| 	'Active' => 'Опубликовано', |  | ||||||
| 	'Activate' => 'Опубликовать', |  | ||||||
| 	'META Title' => 'Заголовок', |  | ||||||
| 	'META Description' => 'Описание', |  | ||||||
| 	'META Keywords' => 'Ключевые слова', |  | ||||||
| 	'Name' => 'Название', |  | ||||||
| 	'Sort' => 'Позиция', |  | ||||||
| 	'Update: {name}' => 'Редактирование: {name}', |  | ||||||
| 	'Types' => 'Типы', |  | ||||||
| 	'Create Type' => 'Новый тип', |  | ||||||
| 	'Singular' => 'Единственное число', |  | ||||||
| 	'Plural' => 'Множественное число', |  | ||||||
| 	'Slug' => 'ЧПУ ссылка', |  | ||||||
| 	'Update Post: {name}' => 'Редактирование: {name}', |  | ||||||
| 	'Update Post Comment: {name}' => 'Редактирование комментария: {name}', |  | ||||||
| 	'Update Tag: {name}' => 'Редактирование тега: {name}', |  | ||||||
| 	'Parent Comment ID' => 'Родительский комментарий', |  | ||||||
| 	'Comment' => 'Комментарий', |  | ||||||
| 	'Published' => 'Опубликовано', |  | ||||||
| 	'User' => 'Пользователь', |  | ||||||
| 	'Post' => 'Статья', |  | ||||||
| 	'YouTube URL' => 'Ссылка YouTube', |  | ||||||
| 	'Video URL' => 'Ссылка на видео (YouTube, Vimeo)', |  | ||||||
| 	'Add Image' => 'Новое изображение', |  | ||||||
| 	'Video' => 'Видео', |  | ||||||
| 	'If a video link is specified, the image will be used as a preview image' => 'Если указана ссылка на видео, то изображение будет рассматриваться как картинка для предварительного просмотра', |  | ||||||
| 	'Reset Image' => 'Сбросить изображение', |  | ||||||
| 	'Set tags...' => 'Укажите теги...', |  | ||||||
| 	'Publish' => 'Публикация', |  | ||||||
| 	'Preview on site' => 'Просмотр на сайте', |  | ||||||
| 	'Publish Date' => 'Дата публикации', |  | ||||||
| 	'The article will be published after the specified date if its status is not a draft' => 'Статья будет опубликована после наступления указанной даты, если ее статус не черновик.', |  | ||||||
| 	'Blog Post' => 'Статья', |  | ||||||
| 	'Blog Home' => 'Блог', |  | ||||||
| 	'Select post...' => 'Укажите статью...', |  | ||||||
| 	'Type' => 'Тип', |  | ||||||
| 	'Revision At' => 'Версия', |  | ||||||
| 	'History' => 'История изменений', |  | ||||||
| 	'Clear History' => 'Очистить историю', |  | ||||||
| 	'History is empty' => 'Нет изменений', |  | ||||||
| 	'Current Edition' => 'Текущая редакция', |  | ||||||
| 	'Restore' => 'Восстановить', |  | ||||||
| 	'Are you sure you want to restore this history item?' => 'Вы уверены, что хотите восстановить эту запись?', |  | ||||||
| 	'Are you sure you want to remove this history?' => 'Вы уверены, что хотите удалить всю историю?', |  | ||||||
| 	'View' => 'Просмотр', |  | ||||||
| 	'SEO link will be generated automatically if not specified' => 'ЧПУ ссылка будет сгенерирована автоматически, если не указано', |  | ||||||
| ]; |  | ||||||
| @ -1,8 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| return [ |  | ||||||
| 	'Blog' => 'Блог', |  | ||||||
| 	'Read More' => 'Подробнее', |  | ||||||
| 	'Leave a Comment' => 'Комментировать', |  | ||||||
| 	'Categories' => 'Категории', |  | ||||||
| ]; |  | ||||||
| @ -1,31 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\db\Migration; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Handles the creation of table `blog_categories`. |  | ||||||
|  */ |  | ||||||
| class m180605_184534_create_blog_categories_table extends Migration |  | ||||||
| { |  | ||||||
|     public function up() |  | ||||||
|     { |  | ||||||
|         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |  | ||||||
| 
 |  | ||||||
|         $this->createTable('{{%blog_categories}}', [ |  | ||||||
|             'id'          => $this->primaryKey(), |  | ||||||
|             'name'        => $this->string()->notNull(), |  | ||||||
|             'slug'        => $this->string()->notNull(), |  | ||||||
|             'title'       => $this->string(), |  | ||||||
|             'description' => $this->text(), |  | ||||||
|             'sort'        => $this->integer()->notNull(), |  | ||||||
|             'meta_json'   => 'LONGTEXT NOT NULL', |  | ||||||
|         ], $tableOptions); |  | ||||||
| 
 |  | ||||||
|         $this->createIndex('{{%idx-blog_categories-slug}}', '{{%blog_categories}}', 'slug', true); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function down() |  | ||||||
|     { |  | ||||||
|         $this->dropTable('{{%blog_categories}}'); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,42 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\db\Migration; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Handles the creation of table `blog_posts`. |  | ||||||
|  */ |  | ||||||
| class m180605_190347_create_blog_posts_table extends Migration |  | ||||||
| { |  | ||||||
|     public function up() |  | ||||||
|     { |  | ||||||
|         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |  | ||||||
| 
 |  | ||||||
|         $this->createTable('{{%blog_posts}}', [ |  | ||||||
|             'id'             => $this->primaryKey(), |  | ||||||
|             'category_id'    => $this->integer()->notNull(), |  | ||||||
|             'published_at'   => $this->integer()->unsigned()->notNull(), |  | ||||||
|             'created_at'     => $this->integer()->unsigned(), |  | ||||||
|             'updated_at'     => $this->integer()->unsigned(), |  | ||||||
|             'title'          => $this->string()->notNull(), |  | ||||||
|             'description'    => $this->text(), |  | ||||||
|             'content'        => 'MEDIUMTEXT', |  | ||||||
|             'image'          => $this->string(), |  | ||||||
|             'video'          => $this->string(), |  | ||||||
|             'status'         => $this->integer()->notNull(), |  | ||||||
|             'meta_json'      => 'TEXT NOT NULL', |  | ||||||
|             'comments_count' => $this->integer()->notNull()->defaultValue(0), |  | ||||||
|             'views'          => $this->integer()->notNull()->defaultValue(0), |  | ||||||
|             'slug'           => $this->string()->notNull(), |  | ||||||
|         ], $tableOptions); |  | ||||||
| 
 |  | ||||||
|         $this->createIndex('{{%idx-blog_posts-category_id}}', '{{%blog_posts}}', 'category_id'); |  | ||||||
|         $this->createIndex('{{%idx-blog_posts-slug}}', '{{%blog_posts}}', 'slug', true); |  | ||||||
|         $this->addForeignKey('{{%fk-blog_posts-category_id}}', '{{%blog_posts}}', 'category_id', '{{%blog_categories}}', 'id'); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function down() |  | ||||||
|     { |  | ||||||
|         $this->dropForeignKey('{{%fk-blog_posts-category_id}}', '{{%blog_posts}}'); |  | ||||||
|         $this->dropTable('{{%blog_posts}}'); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,28 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\db\Migration; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Handles the creation of table `blog_tags`. |  | ||||||
|  */ |  | ||||||
| class m180605_193423_create_blog_tags_table extends Migration |  | ||||||
| { |  | ||||||
|     public function up() |  | ||||||
|     { |  | ||||||
|         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |  | ||||||
| 
 |  | ||||||
|         $this->createTable('{{%blog_tags}}', [ |  | ||||||
|             'id'   => $this->primaryKey(), |  | ||||||
|             'name' => $this->string()->notNull(), |  | ||||||
|             'slug' => $this->string()->notNull(), |  | ||||||
|         ], $tableOptions); |  | ||||||
| 
 |  | ||||||
|         $this->createIndex('{{%idx-blog_tags-slug}}', '{{%blog_tags}}', 'slug', true); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function down() |  | ||||||
|     { |  | ||||||
|         $this->dropIndex('{{%idx-blog_tags-slug}}', '{{%blog_tags}}'); |  | ||||||
|         $this->dropTable('{{%blog_tags}}'); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,36 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\db\Migration; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Handles the creation of table `blog_tag_assignments`. |  | ||||||
|  */ |  | ||||||
| class m180605_193748_create_blog_tag_assignments_table extends Migration |  | ||||||
| { |  | ||||||
|     public function up() |  | ||||||
|     { |  | ||||||
|         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; |  | ||||||
| 
 |  | ||||||
|         $this->createTable('{{%blog_tag_assignments}}', [ |  | ||||||
|             'post_id' => $this->integer()->notNull(), |  | ||||||
|             'tag_id'  => $this->integer()->notNull(), |  | ||||||
|         ], $tableOptions); |  | ||||||
| 
 |  | ||||||
|         $this->addPrimaryKey('{{%pk-blog_tag_assignments}}', '{{%blog_tag_assignments}}', ['post_id', 'tag_id']); |  | ||||||
| 
 |  | ||||||
|         $this->createIndex('{{%idx-blog_tag_assignments-post_id}}', '{{%blog_tag_assignments}}', 'post_id'); |  | ||||||
|         $this->createIndex('{{%idx-blog_tag_assignments-tag_id}}', '{{%blog_tag_assignments}}', 'tag_id'); |  | ||||||
| 
 |  | ||||||
|         $this->addForeignKey('{{%fk-blog_tag_assignments-post_id}}', '{{%blog_tag_assignments}}', 'post_id', '{{%blog_posts}}', 'id', 'CASCADE', 'RESTRICT'); |  | ||||||
|         $this->addForeignKey('{{%fk-blog_tag_assignments-tag_id}}', '{{%blog_tag_assignments}}', 'tag_id', '{{%blog_tags}}', 'id', 'CASCADE', 'RESTRICT'); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function down() |  | ||||||
|     { |  | ||||||
|         $this->dropIndex('{{%idx-blog_tag_assignments-tag_id}}', '{{%blog_tag_assignments}}'); |  | ||||||
|         $this->dropIndex('{{%idx-blog_tag_assignments-post_id}}', '{{%blog_tag_assignments}}'); |  | ||||||
|         $this->dropForeignKey('{{%fk-blog_tag_assignments-tag_id}}', '{{%blog_tag_assignments}}'); |  | ||||||
|         $this->dropForeignKey('{{%fk-blog_tag_assignments-post_id}}', '{{%blog_tag_assignments}}'); |  | ||||||
|         $this->dropTable('{{%blog_tag_assignments}}'); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,43 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\db\Migration; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Handles the creation of table `blog_comments`. |  | ||||||
|  */ |  | ||||||
| class m180605_194207_create_blog_comments_table extends Migration |  | ||||||
| { |  | ||||||
|     public function up() |  | ||||||
|     { |  | ||||||
|         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |  | ||||||
| 
 |  | ||||||
|         $this->createTable('{{%blog_comments}}', [ |  | ||||||
|             'id'         => $this->primaryKey(), |  | ||||||
|             'post_id'    => $this->integer()->notNull(), |  | ||||||
|             'user_id'    => $this->integer()->notNull(), |  | ||||||
|             'parent_id'  => $this->integer(), |  | ||||||
|             'created_at' => $this->integer()->unsigned()->notNull(), |  | ||||||
|             'text'       => $this->text()->notNull(), |  | ||||||
|             'active'     => $this->boolean()->notNull(), |  | ||||||
|         ], $tableOptions); |  | ||||||
| 
 |  | ||||||
|         $this->createIndex('{{%idx-blog_comments-post_id}}', '{{%blog_comments}}', 'post_id'); |  | ||||||
|         $this->createIndex('{{%idx-blog_comments-user_id}}', '{{%blog_comments}}', 'user_id'); |  | ||||||
|         $this->createIndex('{{%idx-blog_comments-parent_id}}', '{{%blog_comments}}', 'parent_id'); |  | ||||||
| 
 |  | ||||||
|         $this->addForeignKey('{{%fk-blog_comments-post_id}}', '{{%blog_comments}}', 'post_id', '{{%blog_posts}}', 'id', 'CASCADE'); |  | ||||||
|         $this->addForeignKey('{{%fk-blog_comments-user_id}}', '{{%blog_comments}}', 'user_id', '{{%users}}', 'id', 'CASCADE'); |  | ||||||
|         $this->addForeignKey('{{%fk-blog_comments-parent_id}}', '{{%blog_comments}}', 'parent_id', '{{%blog_comments}}', 'id', 'CASCADE'); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function down() |  | ||||||
|     { |  | ||||||
|         $this->dropForeignKey('{{%fk-blog_comments-parent_id}}', '{{%blog_comments}}'); |  | ||||||
|         $this->dropForeignKey('{{%fk-blog_comments-user_id}}', '{{%blog_comments}}'); |  | ||||||
|         $this->dropForeignKey('{{%fk-blog_comments-post_id}}', '{{%blog_comments}}'); |  | ||||||
|         $this->dropIndex('{{%idx-blog_comments-parent_id}}', '{{%blog_comments}}'); |  | ||||||
|         $this->dropIndex('{{%idx-blog_comments-user_id}}', '{{%blog_comments}}'); |  | ||||||
|         $this->dropIndex('{{%idx-blog_comments-post_id}}', '{{%blog_comments}}'); |  | ||||||
|         $this->dropTable('{{%blog_comments}}'); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,33 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\db\Migration; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Class m180725_091725_add_blog_posts_type_field |  | ||||||
|  */ |  | ||||||
| class m180725_091725_add_blog_posts_type_field extends Migration |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * {@inheritdoc} |  | ||||||
|      */ |  | ||||||
|     public function safeUp() |  | ||||||
|     { |  | ||||||
|         $this->addColumn('{{%blog_posts}}', 'type', $this->integer(2)->defaultValue(0)); // 0 - public, 1 - revision, 2 - preview |  | ||||||
|         $this->addColumn('{{%blog_posts}}', 'revision_at', $this->integer()->unsigned()); |  | ||||||
|         $this->addColumn('{{%blog_posts}}', 'revision_id', $this->integer()); |  | ||||||
| 
 |  | ||||||
|         $this->createIndex('idx_blog_posts_revision_id', '{{%blog_posts}}', 'revision_id'); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * {@inheritdoc} |  | ||||||
|      */ |  | ||||||
|     public function safeDown() |  | ||||||
|     { |  | ||||||
|         $this->dropIndex('idx_blog_posts_revision_id', '{{%blog_posts}}'); |  | ||||||
| 
 |  | ||||||
|         $this->dropColumn('{{%blog_posts}}', 'type'); |  | ||||||
|         $this->dropColumn('{{%blog_posts}}', 'revision_at'); |  | ||||||
|         $this->dropColumn('{{%blog_posts}}', 'revision_id'); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,27 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\db\Migration; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Class m180725_113503_remove_blog_posts_slug_unique_index |  | ||||||
|  */ |  | ||||||
| class m180725_113503_remove_blog_posts_slug_unique_index extends Migration |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * {@inheritdoc} |  | ||||||
|      */ |  | ||||||
|     public function safeUp() |  | ||||||
|     { |  | ||||||
|         $this->dropIndex('{{%idx-blog_posts-slug}}', '{{%blog_posts}}'); |  | ||||||
|         $this->createIndex('{{%idx-blog_posts-slug}}', '{{%blog_posts}}', 'slug'); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * {@inheritdoc} |  | ||||||
|      */ |  | ||||||
|     public function safeDown() |  | ||||||
|     { |  | ||||||
|         $this->dropIndex('{{%idx-blog_posts-slug}}', '{{%blog_posts}}'); |  | ||||||
|         $this->createIndex('{{%idx-blog_posts-slug}}', '{{%blog_posts}}', 'slug'); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,33 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\db\Migration; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Class m180827_195932_set_blog_unicode_collate |  | ||||||
|  */ |  | ||||||
| class m180827_195932_set_blog_unicode_collate extends Migration |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * {@inheritdoc} |  | ||||||
|      */ |  | ||||||
|     public function safeUp() |  | ||||||
|     { |  | ||||||
|         $tables = ['blog_tag_assignments']; |  | ||||||
|         $db     = Yii::$app->getDb(); |  | ||||||
|         $db->createCommand('SET FOREIGN_KEY_CHECKS=0;')->execute(); |  | ||||||
| 
 |  | ||||||
|         foreach ($tables as $table) { |  | ||||||
|             $db->createCommand("ALTER TABLE `$table` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci")->execute(); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         $db->createCommand('SET FOREIGN_KEY_CHECKS=1;')->execute(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * {@inheritdoc} |  | ||||||
|      */ |  | ||||||
|     public function safeDown() |  | ||||||
|     { |  | ||||||
|         true; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,54 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\db\Migration; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Handles the creation of table `blog_post_lng`. |  | ||||||
|  */ |  | ||||||
| class m180828_190314_create_blog_post_lng_table extends Migration |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * {@inheritdoc} |  | ||||||
|      */ |  | ||||||
|     public function safeUp() |  | ||||||
|     { |  | ||||||
|         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |  | ||||||
| 
 |  | ||||||
|         $this->createTable('{{%blog_posts_lng}}', [ |  | ||||||
|             'id'               => $this->primaryKey(), |  | ||||||
|             'blog_post_id'     => $this->integer()->notNull(), |  | ||||||
|             'language'         => $this->string(6)->notNull(), |  | ||||||
|             'title'            => $this->string()->notNull(), |  | ||||||
|             'description'      => $this->text(), |  | ||||||
|             'content'          => 'MEDIUMTEXT', |  | ||||||
|             'meta_title'       => $this->string(255), |  | ||||||
|             'meta_description' => $this->text(), |  | ||||||
|             'meta_keywords'    => $this->string(255), |  | ||||||
|         ], $tableOptions); |  | ||||||
| 
 |  | ||||||
|         $this->createIndex('idx_blog_posts_lng_language', '{{%blog_posts_lng}}', 'language'); |  | ||||||
|         $this->createIndex('idx_blog_posts_lng_blog_post_id', '{{%blog_posts_lng}}', 'blog_post_id'); |  | ||||||
|         $this->addForeignKey('frg_blog_posts_lng_blog_posts_blog_post_id_id', '{{%blog_posts_lng}}', 'blog_post_id', '{{%blog_posts}}', 'id', 'CASCADE', 'CASCADE'); |  | ||||||
| 
 |  | ||||||
|         $this->dropColumn('{{%blog_posts}}', 'title'); |  | ||||||
|         $this->dropColumn('{{%blog_posts}}', 'description'); |  | ||||||
|         $this->dropColumn('{{%blog_posts}}', 'content'); |  | ||||||
|         $this->dropColumn('{{%blog_posts}}', 'meta_json'); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * {@inheritdoc} |  | ||||||
|      */ |  | ||||||
|     public function safeDown() |  | ||||||
|     { |  | ||||||
|         $this->addColumn('{{%blog_posts}}', 'title', $this->string(255)->notNull()); |  | ||||||
|         $this->addColumn('{{%blog_posts}}', 'description', $this->text()); |  | ||||||
|         $this->addColumn('{{%blog_posts}}', 'description', 'MEDIUMTEXT'); |  | ||||||
|         $this->addColumn('{{%blog_posts}}', 'meta_json', $this->text()); |  | ||||||
| 
 |  | ||||||
|         $this->dropForeignKey('frg_blog_posts_lng_blog_posts_blog_post_id_id', '{{%blog_posts_lng}}'); |  | ||||||
|         $this->dropIndex('idx_blog_posts_lng_blog_post_id', '{{%blog_posts_lng}}'); |  | ||||||
|         $this->dropIndex('idx_blog_posts_lng_language', '{{%blog_posts_lng}}'); |  | ||||||
|         $this->dropTable('{{%blog_posts_lng}}'); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,55 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\db\Migration; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Handles the creation of table `blog_categories_lng`. |  | ||||||
|  */ |  | ||||||
| class m180830_163050_create_blog_categories_lng_table extends Migration |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * {@inheritdoc} |  | ||||||
|      */ |  | ||||||
|     public function safeUp() |  | ||||||
|     { |  | ||||||
|         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |  | ||||||
| 
 |  | ||||||
|         $this->createTable('{{%blog_categories_lng}}', [ |  | ||||||
|             'id'               => $this->primaryKey(), |  | ||||||
|             'blog_category_id' => $this->integer()->notNull(), |  | ||||||
|             'language'         => $this->string(6)->notNull(), |  | ||||||
|             'name'             => $this->string()->notNull(), |  | ||||||
|             'title'            => $this->string(), |  | ||||||
|             'description'      => $this->text(), |  | ||||||
|             'meta_title'       => $this->string(255), |  | ||||||
|             'meta_description' => $this->text(), |  | ||||||
|             'meta_keywords'    => $this->string(255), |  | ||||||
|         ], $tableOptions); |  | ||||||
| 
 |  | ||||||
|         $this->createIndex('idx_blog_categories_lng_language', '{{%blog_categories_lng}}', 'language'); |  | ||||||
|         $this->createIndex('idx_blog_categories_lng_blog_category_id', '{{%blog_categories_lng}}', 'blog_category_id'); |  | ||||||
|         $this->addForeignKey('frg_blog_categories_lng_blog_categories_blog_category_id_id', '{{%blog_categories_lng}}', 'blog_category_id', '{{%blog_categories}}', 'id', 'CASCADE', 'CASCADE'); |  | ||||||
| 
 |  | ||||||
|         $this->dropColumn('{{%blog_categories}}', 'title'); |  | ||||||
|         $this->dropColumn('{{%blog_categories}}', 'description'); |  | ||||||
|         $this->dropColumn('{{%blog_categories}}', 'name'); |  | ||||||
|         $this->dropColumn('{{%blog_categories}}', 'meta_json'); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * {@inheritdoc} |  | ||||||
|      */ |  | ||||||
|     public function safeDown() |  | ||||||
|     { |  | ||||||
|         $this->dropForeignKey('frg_blog_categories_lng_blog_categories_blog_category_id_id', '{{%blog_categories_lng}}'); |  | ||||||
|         $this->dropIndex('idx_blog_categories_lng_blog_category_id', '{{%blog_categories_lng}}'); |  | ||||||
|         $this->dropIndex('idx_blog_categories_lng_language', '{{%blog_categories_lng}}'); |  | ||||||
| 
 |  | ||||||
|         $this->dropTable('{{%blog_categories_lng}}'); |  | ||||||
| 
 |  | ||||||
|         $this->addColumn('{{%blog_categories}}', 'title', $this->string(255)); |  | ||||||
|         $this->addColumn('{{%blog_categories}}', 'name', $this->string(255)->notNull()); |  | ||||||
|         $this->addColumn('{{%blog_categories}}', 'description', $this->text()); |  | ||||||
|         $this->addColumn('{{%blog_categories}}', 'meta_json', 'LONGTEXT NOT NULL'); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,31 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\repositories; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogCategory; |  | ||||||
| use core\repositories\NotFoundException; |  | ||||||
| 
 |  | ||||||
| class BlogCategoryRepository |  | ||||||
| { |  | ||||||
|     public function get($id): BlogCategory |  | ||||||
|     { |  | ||||||
|         if (!$category = BlogCategory::findOne($id)) { |  | ||||||
|             throw new NotFoundException('Category is not found.'); |  | ||||||
|         } |  | ||||||
|         return $category; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function save(BlogCategory $category): void |  | ||||||
|     { |  | ||||||
|         if (!$category->save()) { |  | ||||||
|             throw new \RuntimeException('Saving error.'); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function remove(BlogCategory $category): void |  | ||||||
|     { |  | ||||||
|         if (!$category->delete()) { |  | ||||||
|             throw new \RuntimeException('Removing error.'); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,36 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\repositories; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| use core\repositories\NotFoundException; |  | ||||||
| 
 |  | ||||||
| class BlogRepository |  | ||||||
| { |  | ||||||
|     public function get($id): BlogPost |  | ||||||
|     { |  | ||||||
|         if (!$post = BlogPost::findOne($id)) { |  | ||||||
|             throw new NotFoundException('Post is not found.'); |  | ||||||
|         } |  | ||||||
|         return $post; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function existsByCategory($id): bool |  | ||||||
|     { |  | ||||||
|         return BlogPost::find()->andWhere(['category_id' => $id])->exists(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function save(BlogPost $post): void |  | ||||||
|     { |  | ||||||
|         if (!$post->save()) { |  | ||||||
|             throw new \RuntimeException('Saving error.'); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function remove(BlogPost $post): void |  | ||||||
|     { |  | ||||||
|         if (!$post->delete()) { |  | ||||||
|             throw new \RuntimeException('Removing error.'); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,36 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\repositories; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogTag; |  | ||||||
| use core\repositories\NotFoundException; |  | ||||||
| 
 |  | ||||||
| class BlogTagRepository |  | ||||||
| { |  | ||||||
|     public function get($id): BlogTag |  | ||||||
|     { |  | ||||||
|         if (!$tag = BlogTag::findOne($id)) { |  | ||||||
|             throw new NotFoundException('Tag is not found.'); |  | ||||||
|         } |  | ||||||
|         return $tag; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function findByName($name): ?BlogTag |  | ||||||
|     { |  | ||||||
|         return BlogTag::findOne(['name' => $name]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function save(BlogTag $tag): void |  | ||||||
|     { |  | ||||||
|         if (!$tag->save()) { |  | ||||||
|             throw new \RuntimeException('Saving error.'); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function remove(BlogTag $tag): void |  | ||||||
|     { |  | ||||||
|         if (!$tag->delete()) { |  | ||||||
|             throw new \RuntimeException('Removing error.'); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,23 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\repositories\read; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogCategory; |  | ||||||
| 
 |  | ||||||
| class BlogCategoryReadRepository |  | ||||||
| { |  | ||||||
|     public function getAll(): array |  | ||||||
|     { |  | ||||||
|         return BlogCategory::find()->orderBy('sort')->all(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function find($id): ?BlogCategory |  | ||||||
|     { |  | ||||||
|         return BlogCategory::findOne($id); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function findBySlug($slug): ?BlogCategory |  | ||||||
|     { |  | ||||||
|         return BlogCategory::find()->andWhere(['slug' => $slug])->one(); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,99 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\repositories\read; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogCategory; |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| use common\modules\blog\entities\BlogTag; |  | ||||||
| use yii\data\ActiveDataProvider; |  | ||||||
| use yii\data\DataProviderInterface; |  | ||||||
| use yii\db\ActiveQuery; |  | ||||||
| 
 |  | ||||||
| class BlogPostReadRepository |  | ||||||
| { |  | ||||||
|     public function count(): int |  | ||||||
|     { |  | ||||||
|         return BlogPost::find()->active()->pubDate()->typePublic()->count(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function getAllByRange($offset, $limit): array |  | ||||||
|     { |  | ||||||
|         return BlogPost::find()->active()->pubDate()->typePublic()->orderBy(['id' => SORT_ASC])->limit($limit)->offset($offset)->all(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function getAll(): DataProviderInterface |  | ||||||
|     { |  | ||||||
|         $query = BlogPost::find()->active()->pubDate()->typePublic()->with('category'); |  | ||||||
|         return $this->getProvider($query); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function getAllByCategory(BlogCategory $category): DataProviderInterface |  | ||||||
|     { |  | ||||||
|         $query = BlogPost::find()->active()->pubDate()->typePublic()->andWhere(['category_id' => $category->id])->with('category'); |  | ||||||
|         return $this->getProvider($query); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function findNext(int $id): ?BlogPost |  | ||||||
|     { |  | ||||||
|         return BlogPost::find()->active()->pubDate()->typePublic()->andWhere(['>', 'id', $id])->one(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function findPrev(int $id): ?BlogPost |  | ||||||
|     { |  | ||||||
|         return BlogPost::find()->active()->pubDate()->typePublic()->andWhere(['<', 'id', $id])->orderBy(['id' => SORT_DESC])->one(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     public function getAllByTag(BlogTag $tag): DataProviderInterface |  | ||||||
|     { |  | ||||||
|         $query = BlogPost::find()->alias('p')->active('p')->typePublic('p')->with('category'); |  | ||||||
|         $query->joinWith(['blogTagAssignments ta'], false); |  | ||||||
|         $query->andWhere(['ta.tag_id' => $tag->id]); |  | ||||||
|         $query->groupBy('p.id'); |  | ||||||
|         return $this->getProvider($query); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public function getByTagsId(BlogPost $post, array $tag_ids, int $limit = 15): DataProviderInterface |  | ||||||
| 	{ |  | ||||||
| 		$query = BlogPost::find()->alias('p')->active('p')->typePublic('p')->with('category'); |  | ||||||
| 		$query->joinWith(['blogTagAssignments ta'], false); |  | ||||||
| 		$query->andWhere(['ta.tag_id' => $tag_ids]); |  | ||||||
| 		$query->andWhere(['!=', 'p.id', $post->id]); |  | ||||||
| 		$query->groupBy('p.id'); |  | ||||||
| 		$query->limit($limit); |  | ||||||
| 		return $this->getProvider($query); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
|     public function getLast($limit): array |  | ||||||
|     { |  | ||||||
|         return BlogPost::find()->with('category')->orderBy(['id' => SORT_DESC])->limit($limit)->all(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function getPopular($limit): array |  | ||||||
|     { |  | ||||||
|         return BlogPost::find()->with('category')->orderBy(['comments_count' => SORT_DESC])->limit($limit)->all(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function find($id): ?BlogPost |  | ||||||
|     { |  | ||||||
|         return BlogPost::find()->active()->andWhere(['id' => $id])->one(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     private function getProvider(ActiveQuery $query): ActiveDataProvider |  | ||||||
|     { |  | ||||||
|         return new ActiveDataProvider([ |  | ||||||
|             'query' => $query, |  | ||||||
|             'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]], |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public function findBySlug($slug): ?BlogPost |  | ||||||
| 	{ |  | ||||||
| 		return BlogPost::find()->andWhere(['slug' => $slug])->one(); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function findPreview($id, $language): ?BlogPost |  | ||||||
| 	{ |  | ||||||
| 		return BlogPost::find()->localized($language)->andWhere(['id' => $id])->one(); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,18 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\repositories\read; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogTag; |  | ||||||
| 
 |  | ||||||
| class BlogTagReadRepository |  | ||||||
| { |  | ||||||
|     public function find($id): ?BlogTag |  | ||||||
|     { |  | ||||||
|         return BlogTag::findOne($id); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function findBySlug($slug): ?BlogTag |  | ||||||
|     { |  | ||||||
|         return BlogTag::find()->andWhere(['slug' => $slug])->one(); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,52 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\services; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogCategory; |  | ||||||
| use common\modules\blog\forms\BlogCategoryForm; |  | ||||||
| use common\modules\blog\repositories\BlogCategoryRepository; |  | ||||||
| use common\modules\blog\repositories\BlogRepository; |  | ||||||
| use core\entities\Meta; |  | ||||||
| 
 |  | ||||||
| class BlogCategoryManageService |  | ||||||
| { |  | ||||||
|     private $categories; |  | ||||||
|     private $posts; |  | ||||||
| 
 |  | ||||||
|     public function __construct(BlogCategoryRepository $categories, BlogRepository $posts) |  | ||||||
|     { |  | ||||||
|         $this->categories = $categories; |  | ||||||
|         $this->posts = $posts; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function create(BlogCategoryForm $form): BlogCategory |  | ||||||
|     { |  | ||||||
|         $category = BlogCategory::create( |  | ||||||
|         	$form, |  | ||||||
|             $form->slug, |  | ||||||
|             $form->sort |  | ||||||
|         ); |  | ||||||
|         $this->categories->save($category); |  | ||||||
|         return $category; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function edit($id, BlogCategoryForm $form): void |  | ||||||
|     { |  | ||||||
|         $category = $this->categories->get($id); |  | ||||||
|         $category->edit( |  | ||||||
|         	$form, |  | ||||||
|             $form->slug, |  | ||||||
|             $form->sort |  | ||||||
|         ); |  | ||||||
|         $this->categories->save($category); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function remove($id): void |  | ||||||
|     { |  | ||||||
|         $category = $this->categories->get($id); |  | ||||||
|         if ($this->posts->existsByCategory($category->id)) { |  | ||||||
|             throw new \DomainException('Unable to remove category with posts.'); |  | ||||||
|         } |  | ||||||
|         $this->categories->remove($category); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,37 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\services; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\forms\BlogCommentEditForm; |  | ||||||
| use common\modules\blog\repositories\BlogRepository; |  | ||||||
| 
 |  | ||||||
| class BlogCommentManageService |  | ||||||
| { |  | ||||||
|     private $posts; |  | ||||||
| 
 |  | ||||||
|     public function __construct(BlogRepository $posts) |  | ||||||
|     { |  | ||||||
|         $this->posts = $posts; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function edit($postId, $id, BlogCommentEditForm $form): void |  | ||||||
|     { |  | ||||||
|         $post = $this->posts->get($postId); |  | ||||||
|         $post->editComment($id, $form->parentId, $form->text); |  | ||||||
|         $this->posts->save($post); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function activate($postId, $id): void |  | ||||||
|     { |  | ||||||
|         $post = $this->posts->get($postId); |  | ||||||
|         $post->activateComment($id); |  | ||||||
|         $this->posts->save($post); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function remove($postId, $id): void |  | ||||||
|     { |  | ||||||
|         $post = $this->posts->get($postId); |  | ||||||
|         $post->removeComment($id); |  | ||||||
|         $this->posts->save($post); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,32 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\services; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogComment; |  | ||||||
| use common\modules\blog\forms\BlogCommentForm; |  | ||||||
| use common\modules\blog\repositories\BlogRepository; |  | ||||||
| use core\repositories\user\UserRepository; |  | ||||||
| 
 |  | ||||||
| class BlogCommentService |  | ||||||
| { |  | ||||||
|     private $posts; |  | ||||||
|     private $users; |  | ||||||
| 
 |  | ||||||
|     public function __construct(BlogRepository $posts, UserRepository $users) |  | ||||||
|     { |  | ||||||
|         $this->posts = $posts; |  | ||||||
|         $this->users = $users; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function create($postId, $userId, BlogCommentForm $form): BlogComment |  | ||||||
|     { |  | ||||||
|         $post = $this->posts->get($postId); |  | ||||||
|         $user = $this->users->get($userId); |  | ||||||
| 
 |  | ||||||
|         $comment = $post->addComment($user->id, $form->parentId, $form->text); |  | ||||||
| 
 |  | ||||||
|         $this->posts->save($post); |  | ||||||
| 
 |  | ||||||
|         return $comment; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,193 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\services; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| use common\modules\blog\entities\BlogTag; |  | ||||||
| use common\modules\blog\forms\BlogPostForm; |  | ||||||
| use common\modules\blog\helpers\BlogPostHelper; |  | ||||||
| use common\modules\blog\repositories\BlogCategoryRepository; |  | ||||||
| use common\modules\blog\repositories\BlogRepository; |  | ||||||
| use common\modules\blog\repositories\BlogTagRepository; |  | ||||||
| use core\helpers\VideoHelper; |  | ||||||
| use core\services\TransactionManager; |  | ||||||
| use yii\base\Security; |  | ||||||
| use yii\helpers\Inflector; |  | ||||||
| 
 |  | ||||||
| class BlogPostManageService |  | ||||||
| { |  | ||||||
|     private $posts; |  | ||||||
|     private $categories; |  | ||||||
|     private $tags; |  | ||||||
|     private $transaction; |  | ||||||
| 
 |  | ||||||
|     public function __construct( |  | ||||||
|         BlogRepository $posts, |  | ||||||
|         BlogCategoryRepository $categories, |  | ||||||
|         BlogTagRepository $tags, |  | ||||||
|         TransactionManager $transaction |  | ||||||
|     ) |  | ||||||
|     { |  | ||||||
|         $this->posts = $posts; |  | ||||||
|         $this->categories = $categories; |  | ||||||
|         $this->tags = $tags; |  | ||||||
|         $this->transaction = $transaction; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function create(BlogPostForm $form, $type = BlogPost::TYPE_PUBLIC): BlogPost |  | ||||||
|     { |  | ||||||
|         $category = $this->categories->get($form->category_id); |  | ||||||
| 
 |  | ||||||
|         $post = BlogPost::create( |  | ||||||
|         	$form, |  | ||||||
|             $category->id, |  | ||||||
|             $form->slug, |  | ||||||
|             $form->published_at, |  | ||||||
|             $form->video, |  | ||||||
|             $type |  | ||||||
|         ); |  | ||||||
| 
 |  | ||||||
|         $this->transaction->wrap(function () use ($post, $form) { |  | ||||||
| 
 |  | ||||||
| 	        if (is_array($form->tags->new_tags) && !empty($form->tags->new_tags)) { |  | ||||||
| 		        foreach ( $form->tags->new_tags as $tag_id => $tag_name ) { |  | ||||||
| 			        if ( !$tag = $this->tags->findByName( $tag_name ) ) { |  | ||||||
| 				        $tag = BlogTag::create( $tag_name, Inflector::slug( $tag_name, '_' ) ); |  | ||||||
| 				        $this->tags->save( $tag ); |  | ||||||
| 			        } |  | ||||||
| 			        $post->assignTag( $tag->id ); |  | ||||||
| 		        } |  | ||||||
| 	        } |  | ||||||
|             $this->posts->save($post); |  | ||||||
| 
 |  | ||||||
| 	        if ($form->image) { |  | ||||||
| 		        $post->setImage($form->image); |  | ||||||
| 	        } |  | ||||||
| 	        else if ($form->video) { |  | ||||||
| 		        $src = VideoHelper::getThumb($form->video); |  | ||||||
| 		        //$src = 'https://i.ytimg.com/vi/' . BlogPostHelper::parseYoutubeUrl($post->video) . '/maxresdefault.jpg'; |  | ||||||
| 		        $filename = (new Security())->generateRandomString(15) . '.jpg'; |  | ||||||
| 		        copy($src, \Yii::getAlias(BlogPost::FILE_ORIGINAL_PATH . '/' . $post->id . '.jpg')); |  | ||||||
| 		        $post->image = $filename; |  | ||||||
| 	        } |  | ||||||
| 
 |  | ||||||
| 	        if ($form->status == BlogPost::STATUS_ACTIVE) { |  | ||||||
| 	        	$post->activate(); |  | ||||||
| 	        } |  | ||||||
| 
 |  | ||||||
| 	        $this->posts->save($post); |  | ||||||
|         }); |  | ||||||
| 
 |  | ||||||
|         return $post; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function edit($id, BlogPostForm $form): void |  | ||||||
|     { |  | ||||||
|         $post = $this->posts->get($id); |  | ||||||
|         BlogPostHelper::saveRevision(clone $post); |  | ||||||
| 	    //$this->saveRevision(clone $post); |  | ||||||
| 
 |  | ||||||
| 	    //print_r($post->translations); die; |  | ||||||
| 
 |  | ||||||
|         $category = $this->categories->get($form->category_id); |  | ||||||
| 
 |  | ||||||
|         $post->edit( |  | ||||||
|         	$form, |  | ||||||
|             $category->id, |  | ||||||
|             $form->slug, |  | ||||||
|             $form->published_at, |  | ||||||
|             $form->video, |  | ||||||
|             $post->type |  | ||||||
|         ); |  | ||||||
| 
 |  | ||||||
|         if ($form->image) { |  | ||||||
| 	        $post->cleanFiles(); |  | ||||||
|             $post->setImage($form->image); |  | ||||||
|         } |  | ||||||
| 	    elseif ($form->video && (!$post->image || $form->reset_image)) { |  | ||||||
| 		    $post->cleanFiles(); |  | ||||||
| 		    $src = VideoHelper::getThumb($form->video); |  | ||||||
| 			$filename = (new Security())->generateRandomString(15) . '.jpg'; |  | ||||||
| 			copy($src, \Yii::getAlias(BlogPost::FILE_ORIGINAL_PATH . '/' . $post->id . '.jpg')); |  | ||||||
| 			$post->image = $filename; |  | ||||||
| 		} |  | ||||||
| 		elseif ($post->image && $form->reset_image) { |  | ||||||
|         	$post->cleanFiles(); |  | ||||||
| 			$post->image = null; |  | ||||||
| 			$post->updateAttributes(['image']); |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
|         $this->transaction->wrap(function () use ($post, $form) { |  | ||||||
|             $post->revokeTags(); |  | ||||||
|             $this->posts->save($post); |  | ||||||
| 
 |  | ||||||
|             if (is_array($form->tags->new_tags) && !empty($form->tags->new_tags)) { |  | ||||||
| 	            foreach ( $form->tags->new_tags as $tag_id => $tag_name ) { |  | ||||||
| 		            if ( ! $tag = $this->tags->findByName( $tag_name ) ) { |  | ||||||
| 			            $tag = BlogTag::create( $tag_name, Inflector::slug( $tag_name, '_' ) ); |  | ||||||
| 			            $this->tags->save( $tag ); |  | ||||||
| 		            } |  | ||||||
| 		            $post->assignTag( $tag->id ); |  | ||||||
| 	            } |  | ||||||
|             } |  | ||||||
| 	        $this->posts->save( $post ); |  | ||||||
|         }); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function activate($id): void |  | ||||||
|     { |  | ||||||
|         $post = $this->posts->get($id); |  | ||||||
|         $post->activate(); |  | ||||||
|         $this->posts->save($post); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function draft($id): void |  | ||||||
|     { |  | ||||||
|         $post = $this->posts->get($id); |  | ||||||
|         $post->draft(); |  | ||||||
|         $this->posts->save($post); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function remove($id): void |  | ||||||
|     { |  | ||||||
|         $post = $this->posts->get($id); |  | ||||||
| 	    // Remove revisions |  | ||||||
| 	    $this->clearHistory($post); |  | ||||||
| 	    // Remove preview |  | ||||||
| 	    $this->removePreviews(); |  | ||||||
| 
 |  | ||||||
|         $this->posts->remove($post); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function removePreviews(): void |  | ||||||
|     { |  | ||||||
|     	$posts = BlogPost::find()->andWhere(['type' => BlogPost::TYPE_PREVIEW])->all(); |  | ||||||
|     	foreach ($posts as $post) { |  | ||||||
|     		$post->delete(); |  | ||||||
| 	    } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function clearHistory(BlogPost $post): void |  | ||||||
|     { |  | ||||||
|     	BlogPost::deleteAll(['revision_id' => $post->id]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	public function restoreHistory($from_id, $id): int |  | ||||||
| 	{ |  | ||||||
| 		$post = $this->posts->get($id); |  | ||||||
| 		$from = $this->posts->get($from_id); |  | ||||||
| 
 |  | ||||||
| 		// update revision id |  | ||||||
| 		BlogPost::updateAll(['revision_id' => $from->id], ['revision_id' => $post->id]); |  | ||||||
| 
 |  | ||||||
| 		$this->posts->remove($post); |  | ||||||
| 		$from->revision_id = null; |  | ||||||
| 		$from->type = BlogPost::TYPE_PUBLIC; |  | ||||||
| 		$this->posts->save($from); |  | ||||||
| 
 |  | ||||||
| 		// delete never revisions |  | ||||||
| 		BlogPost::deleteAll(['AND', ['revision_id' => $from->id], ['>', 'revision_at', $from->revision_at]]); |  | ||||||
| 
 |  | ||||||
| 		return $from->id; |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,43 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\services; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogTag; |  | ||||||
| use common\modules\blog\forms\BlogTagSingleForm; |  | ||||||
| use common\modules\blog\repositories\BlogTagRepository; |  | ||||||
| 
 |  | ||||||
| class BlogTagManageService |  | ||||||
| { |  | ||||||
|     private $tags; |  | ||||||
| 
 |  | ||||||
|     public function __construct(BlogTagRepository $tags) |  | ||||||
|     { |  | ||||||
|         $this->tags = $tags; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function create(BlogTagSingleForm $form): BlogTag |  | ||||||
|     { |  | ||||||
|         $tag = BlogTag::create( |  | ||||||
|             $form->name, |  | ||||||
|             $form->slug |  | ||||||
|         ); |  | ||||||
|         $this->tags->save($tag); |  | ||||||
|         return $tag; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function edit($id, BlogTagSingleForm $form): void |  | ||||||
|     { |  | ||||||
|         $tag = $this->tags->get($id); |  | ||||||
|         $tag->edit( |  | ||||||
|             $form->name, |  | ||||||
|             $form->slug |  | ||||||
|         ); |  | ||||||
|         $this->tags->save($tag); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function remove($id): void |  | ||||||
|     { |  | ||||||
|         $tag = $this->tags->get($id); |  | ||||||
|         $this->tags->remove($tag); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,92 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\urls; |  | ||||||
| 
 |  | ||||||
| use yii\caching\TagDependency; |  | ||||||
| use common\modules\blog\repositories\read\BlogCategoryReadRepository; |  | ||||||
| use yii\base\BaseObject; |  | ||||||
| use core\helpers\LanguageHelper; |  | ||||||
| use yii\caching\Cache; |  | ||||||
| use yii\web\UrlNormalizerRedirectException; |  | ||||||
| use yii\web\UrlRuleInterface; |  | ||||||
| 
 |  | ||||||
| class BlogCategoryUrlRule extends BaseObject implements UrlRuleInterface |  | ||||||
| { |  | ||||||
| 	public $prefix = 'blog/category'; |  | ||||||
| 
 |  | ||||||
|     private $repository; |  | ||||||
|     private $cache; |  | ||||||
| 
 |  | ||||||
|     public function __construct(BlogCategoryReadRepository $repository, Cache $cache, $config = []) |  | ||||||
|     { |  | ||||||
|         parent::__construct($config); |  | ||||||
|         $this->repository = $repository; |  | ||||||
|         $this->cache = $cache; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function parseRequest($manager, $request) |  | ||||||
|     { |  | ||||||
| 	    $uri = ltrim(LanguageHelper::processLangInUrl($request->pathInfo), '/'); |  | ||||||
| 	    if (preg_match('#^' . $this->prefix . '/(.*[a-z])$#is', $uri, $matches)) { |  | ||||||
| 		    $path = $matches['1']; |  | ||||||
| 
 |  | ||||||
| 		    $result = $this->cache->getOrSet( [ 'blog_category_route', 'path' => $path ], function () use ( $path ) { |  | ||||||
| 			    if ( ! $post = $this->repository->findBySlug( $this->getPathSlug( $path ) ) ) { |  | ||||||
| 				    return [ 'id' => null, 'path' => null ]; |  | ||||||
| 			    } |  | ||||||
| 			    return [ 'id' => $post->id, 'path' => $post->slug ]; |  | ||||||
| 		    }, null, new TagDependency(['tags' => ['blog']]) ); |  | ||||||
| 
 |  | ||||||
| 		    if ( empty( $result['id'] ) ) { |  | ||||||
| 			    return false; |  | ||||||
| 		    } |  | ||||||
| 
 |  | ||||||
| 		    if ( $path != $result['path'] ) { |  | ||||||
| 			    throw new UrlNormalizerRedirectException( [ |  | ||||||
| 				    'blog/post/category', |  | ||||||
| 				    'id' => $result['id'], |  | ||||||
| 			    ], 301 ); |  | ||||||
| 		    } |  | ||||||
| 
 |  | ||||||
| 		    return [ 'blog/post/category', [ 'id' => $result['id'] ] ]; |  | ||||||
| 	    } |  | ||||||
| 	    return false; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function createUrl($manager, $route, $params) |  | ||||||
|     { |  | ||||||
|         if ($route == 'blog/post/category') { |  | ||||||
|             if (empty($params['id'])) { |  | ||||||
|                 throw new \InvalidArgumentException('Empty id.'); |  | ||||||
|             } |  | ||||||
|             $id = $params['id']; |  | ||||||
| 
 |  | ||||||
|             $url = $this->cache->getOrSet(['blog_category_route', 'id' => $id], function () use ($id) { |  | ||||||
|                 if (!$post = $this->repository->find($id)) { |  | ||||||
|                     return null; |  | ||||||
|                 } |  | ||||||
|                 return $post->slug; |  | ||||||
|                 //return $this->getPagePath($post); |  | ||||||
|             }, null, new TagDependency(['tags' => ['blog']])); |  | ||||||
| 
 |  | ||||||
|             if (!$url) { |  | ||||||
|                 throw new \InvalidArgumentException('Undefined id.'); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
| 	        $url = $this->prefix . '/' . $url; |  | ||||||
| 	        unset($params['id']); |  | ||||||
|             if (!empty($params) && ($query = http_build_query($params)) !== '') { |  | ||||||
|                 $url .= '?' . $query; |  | ||||||
|             } |  | ||||||
|             //return $url; |  | ||||||
| 	        return LanguageHelper::addLangToUrl($url, isset($params['language']) ? $params['language'] : null); |  | ||||||
|         } |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     private function getPathSlug($path): string |  | ||||||
|     { |  | ||||||
|         $chunks = explode('/', $path); |  | ||||||
|         return end($chunks); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,90 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\urls; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\repositories\read\BlogPostReadRepository; |  | ||||||
| use yii\base\BaseObject; |  | ||||||
| use yii\caching\Cache; |  | ||||||
| use yii\caching\TagDependency; |  | ||||||
| use yii\web\UrlNormalizerRedirectException; |  | ||||||
| use yii\web\UrlRuleInterface; |  | ||||||
| use InvalidArgumentException; |  | ||||||
| use core\helpers\LanguageHelper; |  | ||||||
| 
 |  | ||||||
| class BlogMainUrlRule extends BaseObject implements UrlRuleInterface |  | ||||||
| { |  | ||||||
| 	public $prefix = 'blog/post'; |  | ||||||
| 
 |  | ||||||
|     private $repository; |  | ||||||
|     private $cache; |  | ||||||
| 
 |  | ||||||
|     public function __construct(BlogPostReadRepository $repository, Cache $cache, $config = []) |  | ||||||
|     { |  | ||||||
|         parent::__construct($config); |  | ||||||
|         $this->repository = $repository; |  | ||||||
|         $this->cache = $cache; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function parseRequest($manager, $request) |  | ||||||
|     { |  | ||||||
| 	    $uri = ltrim(LanguageHelper::processLangInUrl($request->pathInfo), '/'); |  | ||||||
| 	    if (preg_match('#^' . $this->prefix . '/(.*[a-z])$#is', $uri, $matches)) { |  | ||||||
| 		    $path = $matches['1']; |  | ||||||
| 
 |  | ||||||
| 		    $result = $this->cache->getOrSet( [ 'blog_main_route', 'path' => $path ], function () use ( $path ) { |  | ||||||
| 			    if ( ! $post = $this->repository->findBySlug($this->getPathSlug( $path ) ) ) { |  | ||||||
| 				    return [ 'id' => null, 'path' => null ]; |  | ||||||
| 			    } |  | ||||||
| 			    return [ 'id' => $post->id, 'path' => $post->slug ]; |  | ||||||
| 		    }, null, new TagDependency(['tags' => ['blog']]) ); |  | ||||||
| 
 |  | ||||||
| 		    if ( empty( $result['id'] ) ) { |  | ||||||
| 			    return false; |  | ||||||
| 		    } |  | ||||||
| 
 |  | ||||||
| 		    if ( $path != $result['path'] ) { |  | ||||||
| 			    throw new UrlNormalizerRedirectException( [ 'blog/post/post', 'id' => $result['id'] ], 301 ); |  | ||||||
| 		    } |  | ||||||
| 
 |  | ||||||
| 		    return ['blog/post/post', ['id' => $result['id']]]; |  | ||||||
| 	    } |  | ||||||
| 	    return false; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function createUrl($manager, $route, $params) |  | ||||||
|     { |  | ||||||
|         if ($route == 'blog/post/post') { |  | ||||||
| 	        if (empty($params['id'])) { |  | ||||||
| 		        throw new InvalidArgumentException('Empty id.'); |  | ||||||
| 	        } |  | ||||||
| 	        $id = $params['id']; |  | ||||||
| 
 |  | ||||||
|             $url = $this->cache->getOrSet(['post_main_route', 'id' => $id], function () use ($id) { |  | ||||||
|                 if (!$post = $this->repository->find($id)) { |  | ||||||
|                     return null; |  | ||||||
|                 } |  | ||||||
|                 return $post->slug; |  | ||||||
|             }, null, new TagDependency(['tags' => ['blog']])); |  | ||||||
| 
 |  | ||||||
|             if (!$url) { |  | ||||||
|             	return '#'; |  | ||||||
|                 //throw new InvalidArgumentException('Undefined id.'); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
| 	        $url = $this->prefix . '/' . $url; |  | ||||||
| 	        unset($params['id']); |  | ||||||
| 	        if (!empty($params) && ($query = http_build_query($params)) !== '') { |  | ||||||
| 		        $url .= '?' . $query; |  | ||||||
| 	        } |  | ||||||
| 	        //return $url; |  | ||||||
| 	        return LanguageHelper::addLangToUrl($url, isset($params['language']) ? $params['language'] : null); |  | ||||||
|         } |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 	private function getPathSlug($path): string |  | ||||||
| 	{ |  | ||||||
| 		$chunks = explode('/', $path); |  | ||||||
| 		return end($chunks); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,91 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\urls; |  | ||||||
| 
 |  | ||||||
| use yii\caching\TagDependency; |  | ||||||
| use common\modules\blog\repositories\read\BlogTagReadRepository; |  | ||||||
| use yii\base\BaseObject; |  | ||||||
| use yii\base\InvalidParamException; |  | ||||||
| use yii\caching\Cache; |  | ||||||
| use yii\web\UrlNormalizerRedirectException; |  | ||||||
| use yii\web\UrlRuleInterface; |  | ||||||
| 
 |  | ||||||
| class BlogTagUrlRule extends BaseObject implements UrlRuleInterface |  | ||||||
| { |  | ||||||
| 	public $prefix = 'blog/tag'; |  | ||||||
| 
 |  | ||||||
|     private $repository; |  | ||||||
|     private $cache; |  | ||||||
| 
 |  | ||||||
|     public function __construct(BlogTagReadRepository $repository, Cache $cache, $config = []) |  | ||||||
|     { |  | ||||||
|         parent::__construct($config); |  | ||||||
|         $this->repository = $repository; |  | ||||||
|         $this->cache = $cache; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function parseRequest($manager, $request) |  | ||||||
|     { |  | ||||||
| 	    if (preg_match('#^' . $this->prefix . '/(.*[a-z])$#is', $request->pathInfo, $matches)) { |  | ||||||
| 		    $path = $matches['1']; |  | ||||||
| 
 |  | ||||||
| 		    $result = $this->cache->getOrSet( [ 'blog_tag_route', 'path' => $path ], function () use ( $path ) { |  | ||||||
| 			    if ( ! $post = $this->repository->findBySlug( $this->getPathSlug( $path ) ) ) { |  | ||||||
| 				    return [ 'id' => null, 'path' => null ]; |  | ||||||
| 			    } |  | ||||||
| 			    return [ 'id' => $post->id, 'path' => $post->slug ]; |  | ||||||
| 		    }, null, new TagDependency(['tags' => ['blog']]) ); |  | ||||||
| 
 |  | ||||||
| 		    if ( empty( $result['id'] ) ) { |  | ||||||
| 			    return false; |  | ||||||
| 		    } |  | ||||||
| 
 |  | ||||||
| 		    if ( $path != $result['path'] ) { |  | ||||||
| 			    throw new UrlNormalizerRedirectException( [ |  | ||||||
| 				    'blog/post/tag', |  | ||||||
| 				    'id' => $result['id'], |  | ||||||
| 			    ], 301 ); |  | ||||||
| 		    } |  | ||||||
| 
 |  | ||||||
| 		    return [ 'blog/post/tag', [ 'id' => $result['id'] ] ]; |  | ||||||
| 	    } |  | ||||||
| 	    return false; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function createUrl($manager, $route, $params) |  | ||||||
|     { |  | ||||||
|         if ($route == 'blog/post/tag') { |  | ||||||
|             if (empty($params['id'])) { |  | ||||||
|                 throw new \InvalidArgumentException('Empty id.'); |  | ||||||
|             } |  | ||||||
|             $id = $params['id']; |  | ||||||
| 
 |  | ||||||
|             $url = $this->cache->getOrSet(['blog_tag_route', 'id' => $id], function () use ($id) { |  | ||||||
|                 if (!$post = $this->repository->find($id)) { |  | ||||||
|                     return null; |  | ||||||
|                 } |  | ||||||
|                 return $post->slug; |  | ||||||
|                 //return $this->getPagePath($post); |  | ||||||
|             }, null, new TagDependency(['tags' => ['blog']])); |  | ||||||
| 
 |  | ||||||
|             if (!$url) { |  | ||||||
|                 throw new \InvalidArgumentException('Undefined id.'); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
| 	        $url = $this->prefix . '/' . $url; |  | ||||||
| 	        unset($params['id']); |  | ||||||
|             if (!empty($params) && ($query = http_build_query($params)) !== '') { |  | ||||||
|                 $url .= '?' . $query; |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             return $url; |  | ||||||
|         } |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     private function getPathSlug($path): string |  | ||||||
|     { |  | ||||||
|         $chunks = explode('/', $path); |  | ||||||
|         return end($chunks); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,73 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use yii\widgets\ActiveForm; |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $model \common\modules\blog\forms\BlogCategoryForm */ |  | ||||||
| /* @var $form yii\widgets\ActiveForm */ |  | ||||||
| 
 |  | ||||||
| $js2 = ' |  | ||||||
| $(".hint-block").each(function () { |  | ||||||
|     var $hint = $(this); |  | ||||||
|     var label = $hint.parent().find("label"); |  | ||||||
|     label.html(label.html() + \' <i style="color:#3c8dbc" class="fa fa-question-circle" aria-hidden="true"></i>\'); |  | ||||||
|     label.addClass("help").popover({ |  | ||||||
|         html: true, |  | ||||||
|         trigger: "hover", |  | ||||||
|         placement: "bottom", |  | ||||||
|         content: $hint.html() |  | ||||||
|     }); |  | ||||||
|     $(this).hide(); |  | ||||||
| }); |  | ||||||
| '; |  | ||||||
| $this->registerJs($js2); |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <div class="category-form"> |  | ||||||
| 
 |  | ||||||
|     <?php $form = ActiveForm::begin(); ?> |  | ||||||
| 
 |  | ||||||
|     <div class="box box-default"> |  | ||||||
|         <div class="box-header with-border"><?= Yii::t('blog', 'Common') ?></div>
 |  | ||||||
|         <div class="box-body"> |  | ||||||
| 
 |  | ||||||
|             <div class="row"> |  | ||||||
|                 <div class="col-md-2"> |  | ||||||
| 	                <?= $form->field($model, 'sort')->textInput(['maxlength' => true]) ?> |  | ||||||
|                 </div> |  | ||||||
|                 <div class="col-md-10"> |  | ||||||
| 	                <?= $form->field($model, 'slug')->textInput(['maxlength' => true]) ?> |  | ||||||
|                 </div> |  | ||||||
|             </div> |  | ||||||
| 
 |  | ||||||
| 	        <?php |  | ||||||
| 	        $items = []; |  | ||||||
| 	        foreach (Yii::$app->params['translatedLanguages'] as $language => $language_name) { |  | ||||||
| 		        $items[] = [ |  | ||||||
| 			        'label' => $language_name, |  | ||||||
| 			        'content' => $this->render('_form_tab', [ |  | ||||||
| 				        'form' => $form, |  | ||||||
| 				        'model' => $model, |  | ||||||
| 				        'language' => $language, |  | ||||||
| 			        ]), |  | ||||||
| 		        ]; |  | ||||||
| 	        } |  | ||||||
| 	        ?> |  | ||||||
| 
 |  | ||||||
| 	        <div class="nav-tabs-custom"> |  | ||||||
| 		        <?= \yii\bootstrap\Tabs::widget([ |  | ||||||
| 			        'items' => $items |  | ||||||
| 		        ]) ?> |  | ||||||
| 	        </div> |  | ||||||
| 
 |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
|     <div class="form-group"> |  | ||||||
|         <?= Html::submitButton(Yii::t('buttons','Save'), ['class' => 'btn btn-success']) ?> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
|     <?php ActiveForm::end(); ?> |  | ||||||
| 
 |  | ||||||
| </div> |  | ||||||
| @ -1,35 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Created by Error202 |  | ||||||
|  * Date: 28.08.2018 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| use zertex\ckeditor\CKEditor; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @var $this \yii\web\View |  | ||||||
|  * @var $form \yii\widgets\ActiveForm |  | ||||||
|  * @var $model \common\modules\blog\forms\BlogPostForm |  | ||||||
|  * @var $language string |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| $postfix = $language == Yii::$app->params['defaultLanguage'] ? '' : '_' . $language; |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <div class="box box-default"> |  | ||||||
| 	<div class="box-body"> |  | ||||||
| 		<?= $form->field($model, 'name' . $postfix)->textInput(['maxlength' => true]) ?> |  | ||||||
| 		<?= $form->field($model, 'title' . $postfix)->textInput(['maxlength' => true]) ?> |  | ||||||
| 		<?= $form->field($model, 'description' . $postfix)->widget(CKEditor::class) ?> |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| <div class="box box-default"> |  | ||||||
| 	<div class="box-header with-border"><?= Yii::t('blog', 'SEO') ?></div>
 |  | ||||||
| 	<div class="box-body"> |  | ||||||
| 		<?= $form->field($model, 'meta_title' . $postfix)->textInput() ?> |  | ||||||
| 		<?= $form->field($model, 'meta_description' . $postfix)->textarea(['rows' => 2]) ?> |  | ||||||
| 		<?= $form->field($model, 'meta_keywords' . $postfix)->textInput() ?> |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
| @ -1,77 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Created by Error202 |  | ||||||
|  * Date: 25.08.2018 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| use yii\widgets\DetailView; |  | ||||||
| use common\modules\blog\entities\BlogCategory; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @var $this \yii\web\View |  | ||||||
|  * @var $category BlogCategory |  | ||||||
|  * @var $language string |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <?= DetailView::widget([ |  | ||||||
| 	'model' => $category, |  | ||||||
| 	'attributes' => [ |  | ||||||
| 		[ |  | ||||||
| 			'label' => Yii::t('blog', 'Name'), |  | ||||||
| 			'value' => function(BlogCategory $entity) use ($language) { |  | ||||||
| 				return $entity->findTranslation($language)->name; |  | ||||||
| 			} |  | ||||||
| 		], |  | ||||||
| 		[ |  | ||||||
| 			'label' => Yii::t('blog', 'Title'), |  | ||||||
| 			'value' => function(BlogCategory $entity) use ($language) { |  | ||||||
| 				return $entity->findTranslation($language)->title; |  | ||||||
| 			} |  | ||||||
| 		], |  | ||||||
| 	], |  | ||||||
| ]) ?> |  | ||||||
| 
 |  | ||||||
| <div class="box"> |  | ||||||
| 	<div class="box-header with-border"><?= Yii::t('blog', 'SEO') ?></div>
 |  | ||||||
| 	<div class="box-body"> |  | ||||||
| 
 |  | ||||||
| <?= DetailView::widget([ |  | ||||||
| 	'model' => $category, |  | ||||||
| 	'attributes' => [ |  | ||||||
| 		[ |  | ||||||
| 			'label' => Yii::t('blog', 'META Title'), |  | ||||||
| 			'value' => function(BlogCategory $entity) use ($language) { |  | ||||||
| 				return $entity->findTranslation($language)->meta_title; |  | ||||||
| 			} |  | ||||||
| 		], |  | ||||||
| 		[ |  | ||||||
| 			'label' => Yii::t('blog', 'META Description'), |  | ||||||
| 			'value' => function(BlogCategory $entity) use ($language) { |  | ||||||
| 				return $entity->findTranslation($language)->meta_description; |  | ||||||
| 			} |  | ||||||
| 		], |  | ||||||
| 		[ |  | ||||||
| 			'label' => Yii::t('blog', 'META Keywords'), |  | ||||||
| 			'value' => function(BlogCategory $entity) use ($language) { |  | ||||||
| 				return $entity->findTranslation($language)->meta_keywords; |  | ||||||
| 			} |  | ||||||
| 		], |  | ||||||
| 	], |  | ||||||
| ]) ?> |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
| 
 |  | ||||||
| <div class="box"> |  | ||||||
| 	<div class="box-header with-border"><?= Yii::t('blog', 'Description') ?></div>
 |  | ||||||
| 	<div class="box-body"> |  | ||||||
| 		<?= Yii::$app->formatter->asHtml($category->findTranslation($language)->description, [ |  | ||||||
| 			'Attr.AllowedRel' => array('nofollow'), |  | ||||||
| 			'HTML.SafeObject' => true, |  | ||||||
| 			'Output.FlashCompat' => true, |  | ||||||
| 			'HTML.SafeIframe' => true, |  | ||||||
| 			'URI.SafeIframeRegexp'=>'%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%', |  | ||||||
| 		]) ?> |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
| @ -1,17 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $model \common\modules\blog\forms\BlogCategoryForm */ |  | ||||||
| 
 |  | ||||||
| $title = Yii::t('blog', 'Create Category'); |  | ||||||
| $this->title = $title; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => Yii::t('blog', 'Categories'), 'url' => ['index']]; |  | ||||||
| $this->params['breadcrumbs'][] = $title; |  | ||||||
| ?> |  | ||||||
| <div class="category-create"> |  | ||||||
| 
 |  | ||||||
|     <?= $this->render('_form', [ |  | ||||||
|         'model' => $model, |  | ||||||
|     ]) ?> |  | ||||||
| 
 |  | ||||||
| </div> |  | ||||||
| @ -1,59 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogCategory; |  | ||||||
| use yii\grid\ActionColumn; |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use yii\grid\GridView; |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $searchModel \common\modules\blog\forms\search\BlogCategorySearch */ |  | ||||||
| /* @var $dataProvider yii\data\ActiveDataProvider */ |  | ||||||
| 
 |  | ||||||
| $title = Yii::t('blog', 'Categories'); |  | ||||||
| $this->title = $title; |  | ||||||
| $this->params['breadcrumbs'][] = $title; |  | ||||||
| ?> |  | ||||||
| <div class="blog-category-index"> |  | ||||||
| 
 |  | ||||||
|     <p> |  | ||||||
|         <?= Html::a(Yii::t('blog', 'Create Category'), ['create'], ['class' => 'btn btn-success']) ?> |  | ||||||
|     </p> |  | ||||||
| 
 |  | ||||||
|     <div class="box"> |  | ||||||
|         <div class="box-body"> |  | ||||||
|             <?= GridView::widget([ |  | ||||||
|                 'dataProvider' => $dataProvider, |  | ||||||
|                 'filterModel' => $searchModel, |  | ||||||
|                 'columns' => [ |  | ||||||
|                     [ |  | ||||||
|                         'attribute' => 'sort', |  | ||||||
|                         'options' => ['style' => 'width: 100px;'], |  | ||||||
|                     ], |  | ||||||
|                     [ |  | ||||||
|                         'attribute' => 'name', |  | ||||||
|                         'value' => function (BlogCategory $model) { |  | ||||||
|                             return Html::a(Html::encode($model->translation->name), ['view', 'id' => $model->id]); |  | ||||||
|                         }, |  | ||||||
|                         'format' => 'raw', |  | ||||||
|                     ], |  | ||||||
|                     [ |  | ||||||
|                         'attribute' => 'slug', |  | ||||||
|                     ], |  | ||||||
| 	                [ |  | ||||||
| 		                'attribute' => 'title', |  | ||||||
| 		                'value' => function (BlogCategory $model) { |  | ||||||
| 			                $title = isset($model->findTranslation(Yii::$app->language)->title) ? $model->findTranslation(Yii::$app->language)->title : $model->findTranslation(Yii::$app->params['defaultLanguage'])->title; |  | ||||||
| 			                return Html::a(Html::encode($title), ['view', 'id' => $model->id]); |  | ||||||
| 		                }, |  | ||||||
| 		                'format' => 'raw', |  | ||||||
| 	                ], |  | ||||||
|                     [ |  | ||||||
|                         'class' => ActionColumn::class, |  | ||||||
|                         'options' => ['style' => 'width: 100px;'], |  | ||||||
|                         'contentOptions' => ['class' => 'text-center'], |  | ||||||
|                     ], |  | ||||||
|                 ], |  | ||||||
|             ]); ?> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| </div> |  | ||||||
| @ -1,19 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $category \common\modules\blog\entities\BlogCategory */ |  | ||||||
| /* @var $model \common\modules\blog\forms\BlogCategoryForm */ |  | ||||||
| 
 |  | ||||||
| $title = Yii::t('blog', 'Update: {name}', ['name' => $category->translation->name]); |  | ||||||
| $this->title = $title; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => Yii::t('blog', 'Categories'), 'url' => ['index']]; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => $category->translation->name, 'url' => ['view', 'id' => $category->id]]; |  | ||||||
| $this->params['breadcrumbs'][] = Yii::t('buttons', 'Editing'); |  | ||||||
| ?> |  | ||||||
| <div class="category-update"> |  | ||||||
| 
 |  | ||||||
|     <?= $this->render('_form', [ |  | ||||||
|         'model' => $model, |  | ||||||
|     ]) ?> |  | ||||||
| 
 |  | ||||||
| </div> |  | ||||||
| @ -1,69 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use yii\widgets\DetailView; |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $category \common\modules\blog\entities\BlogCategory */ |  | ||||||
| 
 |  | ||||||
| $title = $category->translation->name; |  | ||||||
| $this->title = $title; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => Yii::t('blog', 'Categories'), 'url' => ['index']]; |  | ||||||
| $this->params['breadcrumbs'][] = $title; |  | ||||||
| 
 |  | ||||||
| $css = <<<CSS |  | ||||||
| 	.detail-view th { |  | ||||||
| 		width: 25%; |  | ||||||
| 	} |  | ||||||
| CSS; |  | ||||||
| $this->registerCss($css); |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <div class="blog-category-view"> |  | ||||||
| 
 |  | ||||||
|     <p> |  | ||||||
|         <?= Html::a(Yii::t('blog', 'Categories'), ['index'], ['class' => 'btn btn-default']) ?> |  | ||||||
|         <?= Html::a(Yii::t('buttons', 'Edit'), ['update', 'id' => $category->id], ['class' => 'btn btn-primary']) ?> |  | ||||||
|         <?= Html::a(Yii::t('buttons', 'Delete'), ['delete', 'id' => $category->id], [ |  | ||||||
|             'class' => 'btn btn-danger', |  | ||||||
|             'data' => [ |  | ||||||
|                 'confirm' => Yii::t('buttons', 'Are you sure you want to delete this item?'), |  | ||||||
|                 'method' => 'post', |  | ||||||
|             ], |  | ||||||
|         ]) ?> |  | ||||||
|     </p> |  | ||||||
| 
 |  | ||||||
|     <div class="box"> |  | ||||||
|         <div class="box-header with-border"><?= Yii::t('blog', 'Common') ?></div>
 |  | ||||||
|         <div class="box-body"> |  | ||||||
|             <?= DetailView::widget([ |  | ||||||
|                 'model' => $category, |  | ||||||
|                 'attributes' => [ |  | ||||||
|                     'id', |  | ||||||
|                     'slug', |  | ||||||
|                     'sort', |  | ||||||
|                 ], |  | ||||||
|             ]) ?> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
| 	<?php |  | ||||||
| 	$items = []; |  | ||||||
| 	foreach (Yii::$app->params['translatedLanguages'] as $language => $language_name) { |  | ||||||
| 		$items[] = [ |  | ||||||
| 			'label' => $language_name, |  | ||||||
| 			'content' => $this->render('_view_tab', [ |  | ||||||
| 				'category' => $category, |  | ||||||
| 				'language' => $language, |  | ||||||
| 			]), |  | ||||||
| 		]; |  | ||||||
| 	} |  | ||||||
| 	?> |  | ||||||
| 
 |  | ||||||
| 	<div class="nav-tabs-custom"> |  | ||||||
| 		<?= \yii\bootstrap\Tabs::widget([ |  | ||||||
| 			'items' => $items, |  | ||||||
| 		]) ?> |  | ||||||
| 	</div> |  | ||||||
| 
 |  | ||||||
| </div> |  | ||||||
| @ -1,54 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogComment; |  | ||||||
| use yii\grid\ActionColumn; |  | ||||||
| use yii\grid\GridView; |  | ||||||
| use yii\helpers\StringHelper; |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $searchModel \common\modules\blog\forms\search\BlogCommentSearch */ |  | ||||||
| /* @var $dataProvider yii\data\ActiveDataProvider */ |  | ||||||
| 
 |  | ||||||
| $this->title = Yii::t('blog', 'Comments'); |  | ||||||
| $this->params['breadcrumbs'][] = $this->title; |  | ||||||
| ?> |  | ||||||
| <div class="blog-comments-index"> |  | ||||||
|     <div class="box"> |  | ||||||
|         <div class="box-body"> |  | ||||||
|             <?= GridView::widget([ |  | ||||||
|                 'dataProvider' => $dataProvider, |  | ||||||
|                 'filterModel' => $searchModel, |  | ||||||
|                 'columns' => [ |  | ||||||
|                     [ |  | ||||||
|                         'attribute' => 'id', |  | ||||||
|                         'options' => ['style' => 'width: 40px;'], |  | ||||||
|                         'contentOptions' => ['class' => 'text-center'], |  | ||||||
|                     ], |  | ||||||
|                     [ |  | ||||||
|                         'attribute' => 'text', |  | ||||||
|                         'value' => function (BlogComment $model) { |  | ||||||
|                             return StringHelper::truncate(strip_tags($model->text), 100); |  | ||||||
|                         }, |  | ||||||
|                     ], |  | ||||||
| 	                [ |  | ||||||
| 		                'attribute' => 'created_at', |  | ||||||
| 		                'format' => ['datetime', 'php:d.m.Y H:i'], |  | ||||||
| 		                'options' => ['style' => 'width: 60px;'], |  | ||||||
| 		                'contentOptions' => ['class' => 'text-center'], |  | ||||||
| 	                ], |  | ||||||
|                     [ |  | ||||||
|                         'attribute' => 'active', |  | ||||||
|                         'filter' => $searchModel->activeList(), |  | ||||||
|                         'format' => 'boolean', |  | ||||||
|                         'contentOptions' => ['style' => 'width: 150px'], |  | ||||||
|                     ], |  | ||||||
|                     [ |  | ||||||
|                         'class' => ActionColumn::class, |  | ||||||
|                         'options' => ['style' => 'width: 100px;'], |  | ||||||
|                         'contentOptions' => ['class' => 'text-center'], |  | ||||||
|                     ], |  | ||||||
|                 ], |  | ||||||
|             ]); ?> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| </div> |  | ||||||
| @ -1,34 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use yii\bootstrap\ActiveForm; |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $post \common\modules\blog\entities\BlogPost */ |  | ||||||
| /* @var $model \common\modules\blog\forms\BlogCommentEditForm */ |  | ||||||
| 
 |  | ||||||
| $this->title = Yii::t('blog', 'Update Post Comment: {name}', ['name' => $post->title]); |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => Yii::t('blog', 'Comment'), 'url' => ['index']]; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => $post->title, 'url' => ['view', 'id' => $post->id]]; |  | ||||||
| $this->params['breadcrumbs'][] = Yii::t('buttons', 'Editing'); |  | ||||||
| ?> |  | ||||||
| <div class="post-update"> |  | ||||||
| 
 |  | ||||||
|     <?php $form = ActiveForm::begin([ |  | ||||||
|         'options' => ['enctype'=>'multipart/form-data'] |  | ||||||
|     ]); ?> |  | ||||||
| 
 |  | ||||||
|     <div class="box box-default"> |  | ||||||
|         <div class="box-header with-border"><?= Yii::t('blog', 'Common') ?></div>
 |  | ||||||
|         <div class="box-body"> |  | ||||||
|             <?= $form->field($model, 'parentId')->textInput() ?> |  | ||||||
|             <?= $form->field($model, 'text')->textarea(['rows' => 20]) ?> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
|     <div class="form-group"> |  | ||||||
|         <?= Html::submitButton(Yii::t('buttons', 'Save'), ['class' => 'btn btn-success']) ?> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
|     <?php ActiveForm::end(); ?> |  | ||||||
| </div> |  | ||||||
| @ -1,71 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use yii\widgets\DetailView; |  | ||||||
| use core\entities\user\User; |  | ||||||
| use common\modules\blog\entities\BlogComment; |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $post \common\modules\blog\entities\BlogPost */ |  | ||||||
| /* @var $comment BlogComment */ |  | ||||||
| /* @var $modificationsProvider yii\data\ActiveDataProvider */ |  | ||||||
| 
 |  | ||||||
| $this->title = $post->title; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => Yii::t('blog', 'Comments'), 'url' => ['index']]; |  | ||||||
| $this->params['breadcrumbs'][] = $this->title; |  | ||||||
| ?> |  | ||||||
| <div class="user-view"> |  | ||||||
| 
 |  | ||||||
|     <p> |  | ||||||
|         <?= Html::a(Yii::t('blog', 'Comments'), ['index'], ['class' => 'btn btn-default']) ?> |  | ||||||
|         <?= Html::a(Yii::t('buttons', 'Edit'), ['update', 'post_id' => $post->id, 'id' => $comment->id], ['class' => 'btn btn-primary']) ?> |  | ||||||
|         <?php if ($comment->isActive()): ?> |  | ||||||
|             <?= Html::a(Yii::t('buttons', 'Delete'), ['delete', 'post_id' => $post->id, 'id' => $comment->id], [ |  | ||||||
|                 'class' => 'btn btn-danger', |  | ||||||
|                 'data' => [ |  | ||||||
|                     'confirm' => Yii::t('buttons', 'Are you sure you want to delete this item?'), |  | ||||||
|                     'method' => 'post', |  | ||||||
|                 ], |  | ||||||
|             ]) ?> |  | ||||||
|         <?php else: ?> |  | ||||||
|             <?= Html::a(Yii::t('buttons', 'Restore'), ['activate', 'post_id' => $post->id, 'id' => $comment->id], [ |  | ||||||
|                 'class' => 'btn btn-success', |  | ||||||
|                 'data' => [ |  | ||||||
|                     'confirm' => Yii::t('buttons', 'Are you sure you want to activate this item?'), |  | ||||||
|                     'method' => 'post', |  | ||||||
|                 ], |  | ||||||
|             ]) ?> |  | ||||||
|         <?php endif; ?> |  | ||||||
|     </p> |  | ||||||
| 
 |  | ||||||
|     <div class="box"> |  | ||||||
|         <div class="box-body"> |  | ||||||
|             <?= DetailView::widget([ |  | ||||||
|                 'model' => $comment, |  | ||||||
|                 'attributes' => [ |  | ||||||
|                     'id', |  | ||||||
|                     'created_at:boolean', |  | ||||||
|                     'active:boolean', |  | ||||||
|                     [ |  | ||||||
|                         'attribute' => 'user_id', |  | ||||||
|                         'value' => function(BlogComment $comment) { |  | ||||||
|                             return User::findOne($comment->user_id)->username; |  | ||||||
|                         }, |  | ||||||
|                     ], |  | ||||||
|                     'parent_id', |  | ||||||
|                     [ |  | ||||||
|                         'attribute' => 'post_id', |  | ||||||
|                         'value' => $post->title, |  | ||||||
|                     ], |  | ||||||
|                 ], |  | ||||||
|             ]) ?> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
|     <div class="box"> |  | ||||||
|         <div class="box-body"> |  | ||||||
|             <?= Yii::$app->formatter->asNtext($comment->text) ?> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
| </div> |  | ||||||
| @ -1,222 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use kartik\file\FileInput; |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use kartik\form\ActiveForm; |  | ||||||
| use yii\web\JsExpression; |  | ||||||
| use yii\helpers\Url; |  | ||||||
| use yii\helpers\Json; |  | ||||||
| use yii\helpers\ArrayHelper; |  | ||||||
| use kartik\widgets\DateTimePicker; |  | ||||||
| use kartik\widgets\Select2; |  | ||||||
| use common\modules\blog\helpers\BlogPostHelper; |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $model \common\modules\blog\forms\BlogPostForm */ |  | ||||||
| /* @var $form yii\widgets\ActiveForm */ |  | ||||||
| 
 |  | ||||||
| $fetchUrl = Url::to( [ 'tag-search' ] ); |  | ||||||
| 
 |  | ||||||
| if (isset($model->_post)) { |  | ||||||
| 	$tagsJson = Json::encode( Json::encode( ArrayHelper::map( $model->_post->tags, 'id', 'name' ) ) ); |  | ||||||
| 
 |  | ||||||
| 	$js = <<<JS |  | ||||||
| 	var arr = {$tagsJson}; |  | ||||||
| 	$.each(JSON.parse(arr), function( key, value ) { |  | ||||||
|   		$("#posttagform-new_tags").append("<option value='"+value+"' selected>"+value+"</option>"); |  | ||||||
| 	}); |  | ||||||
| 	$('#posttagform-new_tags').trigger('change'); |  | ||||||
| JS; |  | ||||||
| 	$this->registerJs( $js, $this::POS_READY ); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| $js2 = ' |  | ||||||
| $(".hint-block").each(function () { |  | ||||||
|     var $hint = $(this); |  | ||||||
|     var label = $hint.parent().find("label"); |  | ||||||
|     label.html(label.html() + \' <i style="color:#3c8dbc" class="fa fa-question-circle" aria-hidden="true"></i>\'); |  | ||||||
|     label.addClass("help").popover({ |  | ||||||
|         html: true, |  | ||||||
|         trigger: "hover", |  | ||||||
|         placement: "bottom", |  | ||||||
|         content: $hint.html() |  | ||||||
|     }); |  | ||||||
|     $(this).hide(); |  | ||||||
| }); |  | ||||||
| '; |  | ||||||
| $this->registerJs($js2); |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <div class="post-form"> |  | ||||||
| 
 |  | ||||||
|     <?php $form = ActiveForm::begin([ |  | ||||||
|         'options' => ['enctype'=>'multipart/form-data'] |  | ||||||
|     ]); ?> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	<div class="row"> |  | ||||||
| 		<div class="col-md-10"> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 		    <div class="row"> |  | ||||||
| 		        <div class="col-md-6"> |  | ||||||
| 		            <div class="box box-default"> |  | ||||||
| 		                <div class="box-body"> |  | ||||||
| 		                    <?= $form->field($model, 'category_id')->dropDownList($model->categoriesList()) ?> |  | ||||||
| 		                </div> |  | ||||||
| 		            </div> |  | ||||||
| 		        </div> |  | ||||||
| 		        <div class="col-md-6"> |  | ||||||
| 		            <div class="box box-default"> |  | ||||||
| 		                <div class="box-body"> |  | ||||||
| 			                <?= $form->field($model->tags, 'new_tags')->widget(Select2::class, [ |  | ||||||
| 				                'options' => [ |  | ||||||
| 					                'placeholder' => Yii::t('blog','Set tags...'), |  | ||||||
| 					                'multiple' => true, |  | ||||||
| 				                ], |  | ||||||
| 				                'pluginOptions' => [ |  | ||||||
| 					                'tags' => true, |  | ||||||
| 					                'tokenSeparators' => [',', ' '], |  | ||||||
| 					                'maximumInputLength' => 12, |  | ||||||
| 					                'ajax' => [ |  | ||||||
| 						                'url' => $fetchUrl, |  | ||||||
| 						                'dataType' => 'json', |  | ||||||
| 						                'data' => new JsExpression('function(params) { return {q:params.term}; }') |  | ||||||
| 					                ], |  | ||||||
| 					                'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), |  | ||||||
| 					                'templateResult' => new JsExpression('function(tag) { return tag.text; }'), |  | ||||||
| 					                'templateSelection' => new JsExpression('function (tag) { return tag.text; }'), |  | ||||||
| 				                ], |  | ||||||
| 			                ])->label(Yii::t('blog', 'Tags')); ?> |  | ||||||
| 		                </div> |  | ||||||
| 		            </div> |  | ||||||
| 		        </div> |  | ||||||
| 		    </div> |  | ||||||
| 
 |  | ||||||
| 			<div class="box box-default"> |  | ||||||
| 				<div class="box-body"> |  | ||||||
| 					<!-- < ?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?> --> |  | ||||||
| 					<?= $form->field($model, 'slug')->textInput(['maxlength' => true]) ?> |  | ||||||
| 					<!-- < ?= $form->field($model, 'description')->textarea(['rows' => 5]) ?> |  | ||||||
| 					< ?= $form->field($model, 'content')->widget(CKEditor::class) ?> --> |  | ||||||
| 				</div> |  | ||||||
| 			</div> |  | ||||||
| 
 |  | ||||||
| 			<?php |  | ||||||
| 			$items = []; |  | ||||||
| 			foreach (Yii::$app->params['translatedLanguages'] as $language => $language_name) { |  | ||||||
| 				$items[] = [ |  | ||||||
| 					'label' => $language_name, |  | ||||||
| 					'content' => $this->render('_form_tab', [ |  | ||||||
| 						'form' => $form, |  | ||||||
| 						'model' => $model, |  | ||||||
| 						'language' => $language, |  | ||||||
| 					]), |  | ||||||
| 				]; |  | ||||||
| 			} |  | ||||||
| 			?> |  | ||||||
| 
 |  | ||||||
| 			<div class="nav-tabs-custom"> |  | ||||||
| 				<?= \yii\bootstrap\Tabs::widget([ |  | ||||||
| 					'items' => $items |  | ||||||
| 				]) ?> |  | ||||||
| 			</div> |  | ||||||
| 
 |  | ||||||
| 			<div class="box box-default"> |  | ||||||
| 				<div class="box-body"> |  | ||||||
| 
 |  | ||||||
| 					<ul class="nav nav-tabs"> |  | ||||||
| 						<li class="active"><a data-toggle="tab" href="#field_image"><?= Yii::t('blog', 'Image') ?></a></li>
 |  | ||||||
| 						<li><a data-toggle="tab" href="#field_video"><?= Yii::t('blog', 'Video') ?></a></li>
 |  | ||||||
| 					</ul> |  | ||||||
| 
 |  | ||||||
| 					<div class="tab-content"> |  | ||||||
| 						<div id="field_image" class="tab-pane fade in active" style="padding-top: 20px;"> |  | ||||||
| 							<?= $form->field($model, 'image')->label(false)->widget(FileInput::class, [ |  | ||||||
| 								'options' => [ |  | ||||||
| 									'accept' => 'image/*', |  | ||||||
| 								], |  | ||||||
| 								'pluginOptions' => [ |  | ||||||
| 									'showUpload' => false, |  | ||||||
| 								], |  | ||||||
| 							]) ?> |  | ||||||
| 
 |  | ||||||
| 							<?php if (isset($model->_post) && $model->_post->image): ?> |  | ||||||
| 								<?= Html::img($model->_post->getThumbFileUrl('image', 'thumb_gallery_view'), [ |  | ||||||
| 									'class' => 'thumbnail', |  | ||||||
| 									'width' => 300, |  | ||||||
| 								]) ?> |  | ||||||
| 
 |  | ||||||
| 								<?= $form->field($model, 'reset_image')->checkbox() ?> |  | ||||||
| 							<?php endif; ?> |  | ||||||
| 						</div> |  | ||||||
| 						<div id="field_video" class="tab-pane fade" style="padding-top: 20px;"> |  | ||||||
| 							<?= $form->field($model, 'video')->textInput()->label(Yii::t('blog', 'Video URL'))->hint(Yii::t('blog', 'If a video link is specified, the image will be used as a preview image')) ?> |  | ||||||
| 						</div> |  | ||||||
| 					</div> |  | ||||||
| 
 |  | ||||||
| 				</div> |  | ||||||
| 			</div> |  | ||||||
| 
 |  | ||||||
| 		    <div class="form-group"> |  | ||||||
| 		        <?= Html::submitButton(Yii::t('buttons', 'Save'), [ |  | ||||||
| 		        	'class' => 'btn btn-success', |  | ||||||
| 			        'value'=>'save', |  | ||||||
| 			        'name'=>'submit_save', |  | ||||||
| 			        'formaction' => Yii::$app->request->getUrl(), |  | ||||||
| 			        'formtarget' => '_self', |  | ||||||
| 		        ]) ?> |  | ||||||
| 		    </div> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 		</div> |  | ||||||
| 		<div class="col-md-2"> |  | ||||||
| 			<div class="box box-default"> |  | ||||||
| 				<div class="box-header with-border"><?= Yii::t('blog', 'Publish') ?></div>
 |  | ||||||
| 				<div class="box-body"> |  | ||||||
| 
 |  | ||||||
| 					<div class="btn-group"> |  | ||||||
| 						<button type="button" class="btn btn-info"><?= Yii::t('blog', 'Preview on site') ?></button>
 |  | ||||||
| 						<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown"> |  | ||||||
| 							<span class="caret"></span> |  | ||||||
| 							<span class="sr-only">Toggle Dropdown</span> |  | ||||||
| 						</button> |  | ||||||
| 						<ul class="dropdown-menu" role="menu"> |  | ||||||
| 							<?php foreach (Yii::$app->params['translatedLanguages'] as $language => $language_name): ?> |  | ||||||
| 								<li> |  | ||||||
| 									<?= Html::submitButton($language_name, [ |  | ||||||
| 										'class' => 'btn btn-block btn-flat bg-white', |  | ||||||
| 										'value'=>'preview', |  | ||||||
| 										'name'=>'submit_preview', |  | ||||||
| 										'formaction' => \yii\helpers\Url::to(['/blog/manage/post/create-preview', 'language' => $language == Yii::$app->params['defaultLanguage'] ? '' : $language]), |  | ||||||
| 										'formtarget' => '_blank', |  | ||||||
| 										'style' => 'border:0; background-color:#ffffff;', |  | ||||||
| 									]) ?> |  | ||||||
| 								</li> |  | ||||||
| 							<?php endforeach; ?> |  | ||||||
| 						</ul> |  | ||||||
| 					</div> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 					<hr> |  | ||||||
| 					<?= $form->field($model, 'status')->radioList(BlogPostHelper::statusList()) ?> |  | ||||||
| 					<hr> |  | ||||||
| 					<?= $form->field($model, 'published_at')->widget(DateTimePicker::class, [ |  | ||||||
| 						'options' => [], |  | ||||||
| 						'removeButton' => false, |  | ||||||
| 						'pluginOptions' => [ |  | ||||||
| 							'autoclose' => true, |  | ||||||
| 							'format' => 'dd.mm.yyyy hh:ii:ss', |  | ||||||
| 						] |  | ||||||
| 					])->label(Yii::t('blog', 'Publish Date')); ?> |  | ||||||
| 				</div> |  | ||||||
| 			</div> |  | ||||||
| 		</div> |  | ||||||
| 	</div> |  | ||||||
| 
 |  | ||||||
|     <?php ActiveForm::end(); ?> |  | ||||||
| 
 |  | ||||||
| </div> |  | ||||||
| @ -1,35 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Created by Error202 |  | ||||||
|  * Date: 28.08.2018 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| use zertex\ckeditor\CKEditor; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @var $this \yii\web\View |  | ||||||
|  * @var $form \yii\widgets\ActiveForm |  | ||||||
|  * @var $model \common\modules\blog\forms\BlogPostForm |  | ||||||
|  * @var $language string |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| $postfix = $language == Yii::$app->params['defaultLanguage'] ? '' : '_' . $language; |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <div class="box box-default"> |  | ||||||
| 	<div class="box-body"> |  | ||||||
| 		<?= $form->field($model, 'title' . $postfix)->textInput(['maxlength' => true]) ?> |  | ||||||
| 		<?= $form->field($model, 'description' . $postfix)->textarea(['rows' => 5]) ?> |  | ||||||
| 		<?= $form->field($model, 'content' . $postfix)->widget(CKEditor::class) ?> |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| <div class="box box-default"> |  | ||||||
| 	<div class="box-header with-border"><?= Yii::t('blog', 'SEO') ?></div>
 |  | ||||||
| 	<div class="box-body"> |  | ||||||
| 		<?= $form->field($model, 'meta_title' . $postfix)->textInput() ?> |  | ||||||
| 		<?= $form->field($model, 'meta_description' . $postfix)->textarea(['rows' => 2]) ?> |  | ||||||
| 		<?= $form->field($model, 'meta_keywords' . $postfix)->textInput() ?> |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
| @ -1,78 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Created by Error202 |  | ||||||
|  * Date: 25.08.2018 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| use yii\widgets\DetailView; |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @var $this \yii\web\View |  | ||||||
|  * @var $post \common\modules\blog\entities\BlogPost |  | ||||||
|  * @var $language string |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <?= DetailView::widget([ |  | ||||||
| 	'model' => $post, |  | ||||||
| 	'attributes' => [ |  | ||||||
| 		[ |  | ||||||
| 			'label' => Yii::t('blog', 'Title'), |  | ||||||
| 			'value' => function(BlogPost $entity) use ($language) { |  | ||||||
| 				return $entity->findTranslation($language)->title; |  | ||||||
| 			} |  | ||||||
| 		], |  | ||||||
| 	], |  | ||||||
| ]) ?> |  | ||||||
| 
 |  | ||||||
| <div class="box"> |  | ||||||
| 	<div class="box-header with-border"><?= Yii::t('blog', 'SEO') ?></div>
 |  | ||||||
| 	<div class="box-body"> |  | ||||||
| 
 |  | ||||||
| <?= DetailView::widget([ |  | ||||||
| 	'model' => $post, |  | ||||||
| 	'attributes' => [ |  | ||||||
| 		[ |  | ||||||
| 			'label' => Yii::t('blog', 'META Title'), |  | ||||||
| 			'value' => function(BlogPost $entity) use ($language) { |  | ||||||
| 				return $entity->findTranslation($language)->meta_title; |  | ||||||
| 			} |  | ||||||
| 		], |  | ||||||
| 		[ |  | ||||||
| 			'label' => Yii::t('blog', 'META Description'), |  | ||||||
| 			'value' => function(BlogPost $entity) use ($language) { |  | ||||||
| 				return $entity->findTranslation($language)->meta_description; |  | ||||||
| 			} |  | ||||||
| 		], |  | ||||||
| 		[ |  | ||||||
| 			'label' => Yii::t('blog', 'META Keywords'), |  | ||||||
| 			'value' => function(BlogPost $entity) use ($language) { |  | ||||||
| 				return $entity->findTranslation($language)->meta_keywords; |  | ||||||
| 			} |  | ||||||
| 		], |  | ||||||
| 	], |  | ||||||
| ]) ?> |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
| 
 |  | ||||||
| <div class="box"> |  | ||||||
| 	<div class="box-header with-border"><?= Yii::t('blog', 'Description') ?></div>
 |  | ||||||
| 	<div class="box-body"> |  | ||||||
| 		<?= Yii::$app->formatter->asNtext($post->findTranslation($language)->description) ?> |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
| 
 |  | ||||||
| <div class="box"> |  | ||||||
| 	<div class="box-header with-border"><?= Yii::t('blog', 'Content') ?></div>
 |  | ||||||
| 	<div class="box-body"> |  | ||||||
| 		<?= Yii::$app->formatter->asHtml($post->findTranslation($language)->content, [ |  | ||||||
| 			'Attr.AllowedRel' => array('nofollow'), |  | ||||||
| 			'HTML.SafeObject' => true, |  | ||||||
| 			'Output.FlashCompat' => true, |  | ||||||
| 			'HTML.SafeIframe' => true, |  | ||||||
| 			'URI.SafeIframeRegexp'=>'%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%', |  | ||||||
| 		]) ?> |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
| @ -1,17 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $model \common\modules\blog\forms\BlogPostForm */ |  | ||||||
| 
 |  | ||||||
| $title = Yii::t('blog', 'Create Post'); |  | ||||||
| $this->title = $title; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => Yii::t('blog', 'Posts'), 'url' => ['index']]; |  | ||||||
| $this->params['breadcrumbs'][] = $title; |  | ||||||
| ?> |  | ||||||
| <div class="post-create"> |  | ||||||
| 
 |  | ||||||
|     <?= $this->render('_form', [ |  | ||||||
|         'model' => $model, |  | ||||||
|     ]) ?> |  | ||||||
| 
 |  | ||||||
| </div> |  | ||||||
| @ -1,80 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| use common\modules\blog\helpers\BlogPostHelper; |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use yii\grid\ActionColumn; |  | ||||||
| use yii\grid\GridView; |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $searchModel \common\modules\blog\forms\search\BlogPostSearch */ |  | ||||||
| /* @var $dataProvider yii\data\ActiveDataProvider */ |  | ||||||
| 
 |  | ||||||
| $title                         = Yii::t('blog', 'All Posts'); |  | ||||||
| $this->title                   = $title; |  | ||||||
| $this->params['breadcrumbs'][] = $title; |  | ||||||
| ?> |  | ||||||
| <div class="blog-post-index"> |  | ||||||
| 
 |  | ||||||
|     <p> |  | ||||||
|         <?= Html::a(Yii::t('blog', 'Create Post'), ['create'], ['class' => 'btn btn-success']) ?> |  | ||||||
|     </p> |  | ||||||
| 
 |  | ||||||
|     <div class="box"> |  | ||||||
|         <div class="box-body"> |  | ||||||
|             <?= GridView::widget([ |  | ||||||
|                 'dataProvider' => $dataProvider, |  | ||||||
|                 'filterModel'  => $searchModel, |  | ||||||
|                 'columns'      => [ |  | ||||||
|                     [ |  | ||||||
|                         'attribute'      => 'id', |  | ||||||
|                         'options'        => ['style' => 'width: 40px;'], |  | ||||||
|                         'contentOptions' => ['class' => 'text-center'], |  | ||||||
|                     ], |  | ||||||
|                     [ |  | ||||||
|                         'attribute' => 'title', |  | ||||||
|                         'value'     => function (BlogPost $model) { |  | ||||||
|                             $title = isset($model->translation->title) ? $model->findTranslation(Yii::$app->language)->title : $model->findTranslation(Yii::$app->params['defaultLanguage'])->title; |  | ||||||
| 
 |  | ||||||
|                             return Html::a(Html::encode($title), ['view', 'id' => $model->id]); |  | ||||||
|                         }, |  | ||||||
|                         'format'    => 'raw', |  | ||||||
|                     ], |  | ||||||
|                     [ |  | ||||||
|                         'attribute' => 'category_id', |  | ||||||
|                         'filter'    => $searchModel->categoriesList(), |  | ||||||
|                         'value'     => function (BlogPost $model) { |  | ||||||
|                             return $model->category->translation->name; |  | ||||||
|                         }, |  | ||||||
|                     ], |  | ||||||
|                     [ |  | ||||||
|                         'attribute'      => 'published_at', |  | ||||||
|                         'format'         => ['datetime', 'php:d.m.Y H:i'], |  | ||||||
|                         'options'        => ['style' => 'width: 60px;'], |  | ||||||
|                         'contentOptions' => ['class' => 'text-center'], |  | ||||||
|                     ], |  | ||||||
|                     [ |  | ||||||
|                         'attribute'      => 'status', |  | ||||||
|                         'filter'         => $searchModel->statusList(), |  | ||||||
|                         'value'          => function (BlogPost $model) { |  | ||||||
|                             return BlogPostHelper::statusLabel($model->status); |  | ||||||
|                         }, |  | ||||||
|                         'format'         => 'raw', |  | ||||||
|                         'options'        => ['style' => 'width: 120px;'], |  | ||||||
|                         'contentOptions' => ['class' => 'text-center'], |  | ||||||
|                     ], |  | ||||||
|                     [ |  | ||||||
|                         'class'          => ActionColumn::class, |  | ||||||
|                         /*'urlCreator' => function($action, BlogPost $model, $key, $index, $column) { |  | ||||||
|                             $params = is_array($key) ? $key : ['id' => (string) $key]; |  | ||||||
|                             $params[0] = $column->controller ? $column->controller . '/' . $action : $action; |  | ||||||
|                             return Url::toRoute($params); |  | ||||||
|                         },*/ |  | ||||||
|                         'options'        => ['style' => 'width: 100px;'], |  | ||||||
|                         'contentOptions' => ['class' => 'text-center'], |  | ||||||
|                     ], |  | ||||||
|                 ], |  | ||||||
|             ]); ?> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| </div> |  | ||||||
| @ -1,21 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $post \common\modules\blog\entities\BlogPost */ |  | ||||||
| /* @var $model \common\modules\blog\forms\BlogPostForm */ |  | ||||||
| 
 |  | ||||||
| use yii\helpers\StringHelper; |  | ||||||
| 
 |  | ||||||
| $title = Yii::t('blog', 'Update Post: {name}', ['name' => StringHelper::truncateWords($post->translation->title, 6, '...')]); |  | ||||||
| $this->title = $title; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => Yii::t('blog', 'Posts'), 'url' => ['index']]; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => StringHelper::truncateWords($post->translation->title, 4, '...'), 'url' => ['view', 'id' => $post->id]]; |  | ||||||
| $this->params['breadcrumbs'][] = Yii::t('buttons', 'Editing'); |  | ||||||
| ?> |  | ||||||
| <div class="post-update"> |  | ||||||
| 
 |  | ||||||
|     <?= $this->render('_form', [ |  | ||||||
|         'model' => $model, |  | ||||||
|     ]) ?> |  | ||||||
| 
 |  | ||||||
| </div> |  | ||||||
| @ -1,183 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\helpers\BlogPostHelper; |  | ||||||
| use yii\helpers\ArrayHelper; |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use yii\widgets\DetailView; |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $post \common\modules\blog\entities\BlogPost */ |  | ||||||
| /* @var $modificationsProvider yii\data\ActiveDataProvider */ |  | ||||||
| /* @var $history \common\modules\blog\entities\BlogPost[] */ |  | ||||||
| 
 |  | ||||||
| $title = $post->translation->title; |  | ||||||
| $this->title = $title; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => Yii::t('blog', 'Posts'), 'url' => ['index']]; |  | ||||||
| $this->params['breadcrumbs'][] = $title; |  | ||||||
| 
 |  | ||||||
| $css = <<<CSS |  | ||||||
| .detail-view th { |  | ||||||
| 	width: 25%; |  | ||||||
| } |  | ||||||
| CSS; |  | ||||||
| $this->registerCss($css); |  | ||||||
| ?> |  | ||||||
| <div class="post-view"> |  | ||||||
| 
 |  | ||||||
|     <p> |  | ||||||
|         <?= Html::a(Yii::t('blog', 'All Posts'), ['index'], ['class' => 'btn btn-default']) ?> |  | ||||||
|         <?php if ($post->isActive()): ?> |  | ||||||
|             <?= Html::a(Yii::t('blog', 'Draft'), ['draft', 'id' => $post->id], ['class' => 'btn btn-primary', 'data-method' => 'post']) ?> |  | ||||||
|         <?php else: ?> |  | ||||||
|             <?= Html::a(Yii::t('blog', 'Activate'), ['activate', 'id' => $post->id], ['class' => 'btn btn-success', 'data-method' => 'post']) ?> |  | ||||||
|         <?php endif; ?> |  | ||||||
|         <?= Html::a(Yii::t('buttons', 'Edit'), ['update', 'id' => $post->id], ['class' => 'btn btn-primary']) ?> |  | ||||||
|         <?= Html::a(Yii::t('buttons', 'Delete'), ['delete', 'id' => $post->id], [ |  | ||||||
|             'class' => 'btn btn-danger', |  | ||||||
|             'data' => [ |  | ||||||
|                 'confirm' => Yii::t('buttons', 'Are you sure you want to delete this item?'), |  | ||||||
|                 'method' => 'post', |  | ||||||
|             ], |  | ||||||
|         ]) ?> |  | ||||||
|     </p> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	<div class="row"> |  | ||||||
| 		<div class="col-md-9"> |  | ||||||
| 
 |  | ||||||
| 		    <div class="box"> |  | ||||||
| 		        <div class="box-header with-border"><?= Yii::t('blog', 'Common') ?></div>
 |  | ||||||
| 		        <div class="box-body"> |  | ||||||
| 		            <?= DetailView::widget([ |  | ||||||
| 		                'model' => $post, |  | ||||||
| 		                'attributes' => [ |  | ||||||
| 		                    'id', |  | ||||||
| 		                    [ |  | ||||||
| 		                        'attribute' => 'status', |  | ||||||
| 		                        'value' => BlogPostHelper::statusLabel($post->status), |  | ||||||
| 		                        'format' => 'raw', |  | ||||||
| 		                    ], |  | ||||||
| 		                    [ |  | ||||||
| 		                        'attribute' => 'category_id', |  | ||||||
| 		                        'value' => $post->category->translation->name, //ArrayHelper::getValue($post, 'category.name'), |  | ||||||
| 		                    ], |  | ||||||
| 		                    [ |  | ||||||
| 		                        'label' => Yii::t('post', 'Tags'), |  | ||||||
| 		                        'format' => 'raw', |  | ||||||
| 		                        'value' => '<i class="fa fa-tag" aria-hidden="true"></i> ' . implode(' <i class="fa fa-tag" aria-hidden="true"></i> ', ArrayHelper::getColumn($post->tags, 'name')), |  | ||||||
| 		                    ], |  | ||||||
| 			                'slug' |  | ||||||
| 		                ], |  | ||||||
| 		            ]) ?> |  | ||||||
| 		        </div> |  | ||||||
| 		    </div> |  | ||||||
| 
 |  | ||||||
| 			<?php |  | ||||||
| 			$items = []; |  | ||||||
| 			foreach (Yii::$app->params['translatedLanguages'] as $language => $language_name) { |  | ||||||
| 				$items[] = [ |  | ||||||
| 					'label' => $language_name, |  | ||||||
| 					'content' => $this->render('_view_tab', [ |  | ||||||
| 						'post' => $post, |  | ||||||
| 						'language' => $language, |  | ||||||
| 					]), |  | ||||||
| 				]; |  | ||||||
| 			} |  | ||||||
| 			?> |  | ||||||
| 
 |  | ||||||
| 			<div class="nav-tabs-custom"> |  | ||||||
| 				<?= \yii\bootstrap\Tabs::widget([ |  | ||||||
| 					'items' => $items, |  | ||||||
| 				]) ?> |  | ||||||
| 			</div> |  | ||||||
| 
 |  | ||||||
| 			<?php if ($post->image): ?> |  | ||||||
| 				<div class="box"> |  | ||||||
| 					<div class="box-header with-border"><?= Yii::t('blog', 'Image') ?></div>
 |  | ||||||
| 					<div class="box-body"> |  | ||||||
| 						<?= Html::img($post->getThumbFileUrl('image', 'thumb_gallery_view'), [ |  | ||||||
| 							'class' => 'thumbnail', |  | ||||||
| 							'width' => 300, |  | ||||||
| 						]) ?> |  | ||||||
| 					</div> |  | ||||||
| 				</div> |  | ||||||
| 			<?php endif; ?> |  | ||||||
| 
 |  | ||||||
| 			<?php if (!$post->image && $post->video): ?> |  | ||||||
| 				<div class="box"> |  | ||||||
| 					<div class="box-header with-border"><?= Yii::t('blog', 'Image') ?></div>
 |  | ||||||
| 					<div class="box-body"> |  | ||||||
| 						<!-- < ?= Html::img('https://i.ytimg.com/vi/' . BlogPostHelper::parseYoutubeUrl($post->video) . '/maxresdefault.jpg', [ |  | ||||||
| 							'width' => 300, |  | ||||||
| 							'class' => 'thumbnail', |  | ||||||
| 						]) ?> --> |  | ||||||
| 						<?= Html::img(\core\helpers\VideoHelper::getThumb($post->video), [ |  | ||||||
| 							'width' => 300, |  | ||||||
| 							'class' => 'thumbnail', |  | ||||||
| 						]) ?> |  | ||||||
| 					</div> |  | ||||||
| 				</div> |  | ||||||
| 			<?php endif; ?> |  | ||||||
| 
 |  | ||||||
| 			<?php if ($post->video): ?> |  | ||||||
| 				<div class="box"> |  | ||||||
| 					<div class="box-header with-border"><?= Yii::t('blog', 'Video') ?></div>
 |  | ||||||
| 					<div class="box-body"> |  | ||||||
| 						<?= \core\widgets\VideoWidget::widget([ |  | ||||||
| 							'src' => $post->video, |  | ||||||
| 							'style' => '', |  | ||||||
| 						]) ?> |  | ||||||
| 					</div> |  | ||||||
| 				</div> |  | ||||||
| 			<?php endif; ?> |  | ||||||
| 		</div> |  | ||||||
| 		<div class="col-md-3"> |  | ||||||
| 			<div class="box"> |  | ||||||
| 				<div class="box-header with-border"><?= Yii::t('blog', 'History') ?></div>
 |  | ||||||
| 				<div class="box-body"> |  | ||||||
| 					<?php if ($history): ?> |  | ||||||
| 					<ul> |  | ||||||
| 					<?php foreach ($history as $item): ?> |  | ||||||
| 						<li> |  | ||||||
| 							<?php if ($item->revision_id): ?> |  | ||||||
| 								<?= date('d.m.Y H:i', $item->revision_at) ?> |  | ||||||
| 								→ |  | ||||||
| 								<?= Html::a(Yii::t('blog', 'View'), \yii\helpers\Url::to(Yii::$app->get('frontendUrlManager')->createAbsoluteUrl(['/blog/post/preview', 'id' => $item->id])), [ |  | ||||||
| 									'style' => 'font-size:11px;', |  | ||||||
| 									'target' => '_blank', |  | ||||||
| 								]) ?> |  | ||||||
| 								| |  | ||||||
| 
 |  | ||||||
| 								<?= Html::a(Yii::t('blog', 'Restore'), ['/blog/manage/post/restore-history', 'id' => $item->id], [ |  | ||||||
| 									'style' => 'font-size:11px; color: red', |  | ||||||
| 									'data' => [ |  | ||||||
| 										'confirm' => Yii::t('blog', 'Are you sure you want to restore this history item?'), |  | ||||||
| 										'method' => 'post', |  | ||||||
| 									], |  | ||||||
| 								]) ?> |  | ||||||
| 
 |  | ||||||
| 							<?php else: ?> |  | ||||||
| 								<strong><?= Yii::t('blog', 'Current Edition') ?></strong>
 |  | ||||||
| 							<?php endif; ?> |  | ||||||
| 						</li> |  | ||||||
| 					<?php endforeach; ?> |  | ||||||
| 					</ul> |  | ||||||
| 					<?= Html::a(Yii::t('blog', 'Clear History'), ['/blog/manage/post/clear-history', 'id' => $post->id], [ |  | ||||||
| 						'class' => 'btn btn-danger btn-sm pull-right', |  | ||||||
| 						'data' => [ |  | ||||||
| 							'confirm' => Yii::t('blog', 'Are you sure you want to remove this history?'), |  | ||||||
| 							'method' => 'post', |  | ||||||
| 						], |  | ||||||
| 					]) ?> |  | ||||||
| 					<?php else: ?> |  | ||||||
| 						<div style="padding: 20px 0; text-align: center"><?= Yii::t('blog', 'History is empty') ?></div>
 |  | ||||||
| 					<?php endif; ?> |  | ||||||
| 
 |  | ||||||
| 				</div> |  | ||||||
| 			</div> |  | ||||||
| 		</div> |  | ||||||
| 	</div> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| </div> |  | ||||||
| @ -1,45 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use yii\widgets\ActiveForm; |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $model \common\modules\blog\forms\BlogTagSingleForm */ |  | ||||||
| /* @var $form yii\widgets\ActiveForm */ |  | ||||||
| 
 |  | ||||||
| $js2 = ' |  | ||||||
| $(".hint-block").each(function () { |  | ||||||
|     var $hint = $(this); |  | ||||||
|     var label = $hint.parent().find("label"); |  | ||||||
|     label.html(label.html() + \' <i style="color:#3c8dbc" class="fa fa-question-circle" aria-hidden="true"></i>\'); |  | ||||||
|     label.addClass("help").popover({ |  | ||||||
|         html: true, |  | ||||||
|         trigger: "hover", |  | ||||||
|         placement: "bottom", |  | ||||||
|         content: $hint.html() |  | ||||||
|     }); |  | ||||||
|     $(this).hide(); |  | ||||||
| }); |  | ||||||
| '; |  | ||||||
| $this->registerJs($js2); |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <div class="tag-form"> |  | ||||||
| 
 |  | ||||||
|     <?php $form = ActiveForm::begin(); ?> |  | ||||||
| 
 |  | ||||||
|     <div class="box box-default"> |  | ||||||
|         <div class="box-body"> |  | ||||||
|             <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> |  | ||||||
|             <?= $form->field($model, 'slug')->textInput(['maxlength' => true]) ?> |  | ||||||
| 
 |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
|     <div class="form-group"> |  | ||||||
|         <?= Html::submitButton(Yii::t('buttons', 'Save'), ['class' => 'btn btn-success']) ?> |  | ||||||
|     </div> |  | ||||||
| 
 |  | ||||||
|     <?php ActiveForm::end(); ?> |  | ||||||
| 
 |  | ||||||
| </div> |  | ||||||
| @ -1,17 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $model \common\modules\blog\forms\BlogTagSingleForm */ |  | ||||||
| 
 |  | ||||||
| $title = Yii::t('blog', 'Create Tag'); |  | ||||||
| $this->title = $title; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => Yii::t('blog', 'Tags'), 'url' => ['index']]; |  | ||||||
| $this->params['breadcrumbs'][] = $this->title; |  | ||||||
| ?> |  | ||||||
| <div class="tag-create"> |  | ||||||
| 
 |  | ||||||
|     <?= $this->render('_form', [ |  | ||||||
|         'model' => $model, |  | ||||||
|     ]) ?> |  | ||||||
| 
 |  | ||||||
| </div> |  | ||||||
| @ -1,47 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogTag; |  | ||||||
| use yii\grid\ActionColumn; |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use yii\grid\GridView; |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $searchModel \common\modules\blog\forms\search\BlogTagSearch */ |  | ||||||
| /* @var $dataProvider yii\data\ActiveDataProvider */ |  | ||||||
| 
 |  | ||||||
| $title = Yii::t('blog', 'Tags'); |  | ||||||
| $this->title = $title; |  | ||||||
| $this->params['breadcrumbs'][] = $title; |  | ||||||
| ?> |  | ||||||
| <div class="blog-tags-index"> |  | ||||||
| 
 |  | ||||||
|     <p> |  | ||||||
|         <?= Html::a(Yii::t('blog', 'Create Tag'), ['create'], ['class' => 'btn btn-success']) ?> |  | ||||||
|     </p> |  | ||||||
| 
 |  | ||||||
|     <div class="box"> |  | ||||||
|         <div class="box-body"> |  | ||||||
|             <?= GridView::widget([ |  | ||||||
|                 'dataProvider' => $dataProvider, |  | ||||||
|                 'filterModel' => $searchModel, |  | ||||||
|                 'columns' => [ |  | ||||||
|                     [ |  | ||||||
|                         'attribute' => 'name', |  | ||||||
|                         'value' => function (BlogTag $model) { |  | ||||||
|                             return Html::a(Html::encode($model->name), ['view', 'id' => $model->id]); |  | ||||||
|                         }, |  | ||||||
|                         'format' => 'raw', |  | ||||||
|                     ], |  | ||||||
|                     [ |  | ||||||
|                         'attribute' => 'slug', |  | ||||||
|                     ], |  | ||||||
|                     [ |  | ||||||
|                         'class' => ActionColumn::class, |  | ||||||
|                         'options' => ['style' => 'width: 100px;'], |  | ||||||
|                         'contentOptions' => ['class' => 'text-center'], |  | ||||||
|                     ], |  | ||||||
|                 ], |  | ||||||
|             ]); ?> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| </div> |  | ||||||
| @ -1,19 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $tag \common\modules\blog\entities\BlogTag */ |  | ||||||
| /* @var $model \common\modules\blog\forms\BlogTagSingleForm */ |  | ||||||
| 
 |  | ||||||
| $title = Yii::t('blog', 'Update Tag: {name}', ['name' => $tag->name]); |  | ||||||
| $this->title = $title; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => Yii::t('blog', 'Tags'), 'url' => ['index']]; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => $tag->name, 'url' => ['view', 'id' => $tag->id]]; |  | ||||||
| $this->params['breadcrumbs'][] = Yii::t('buttons', 'Editing'); |  | ||||||
| ?> |  | ||||||
| <div class="tag-update"> |  | ||||||
| 
 |  | ||||||
|     <?= $this->render('_form', [ |  | ||||||
|         'model' => $model, |  | ||||||
|     ]) ?> |  | ||||||
| 
 |  | ||||||
| </div> |  | ||||||
| @ -1,39 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use yii\widgets\DetailView; |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $tag \common\modules\blog\entities\BlogTag */ |  | ||||||
| 
 |  | ||||||
| $title = $tag->name; |  | ||||||
| $this->title = $title; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => Yii::t('blog', 'Tags'), 'url' => ['index']]; |  | ||||||
| $this->params['breadcrumbs'][] = $title; |  | ||||||
| ?> |  | ||||||
| <div class="user-view"> |  | ||||||
| 
 |  | ||||||
|     <p> |  | ||||||
|         <?= Html::a(Yii::t('blog', 'Tags'), ['index'], ['class' => 'btn btn-default']) ?> |  | ||||||
|         <?= Html::a(Yii::t('buttons', 'Edit'), ['update', 'id' => $tag->id], ['class' => 'btn btn-primary']) ?> |  | ||||||
|         <?= Html::a(Yii::t('buttons', 'Delete'), ['delete', 'id' => $tag->id], [ |  | ||||||
|             'class' => 'btn btn-danger', |  | ||||||
|             'data' => [ |  | ||||||
|                 'confirm' => Yii::t('buttons', 'Are you sure you want to delete this item?'), |  | ||||||
|                 'method' => 'post', |  | ||||||
|             ], |  | ||||||
|         ]) ?> |  | ||||||
|     </p> |  | ||||||
| 
 |  | ||||||
|     <div class="box"> |  | ||||||
|         <div class="box-body"> |  | ||||||
|             <?= DetailView::widget([ |  | ||||||
|                 'model' => $tag, |  | ||||||
|                 'attributes' => [ |  | ||||||
|                     'name', |  | ||||||
|                     'slug', |  | ||||||
|                 ], |  | ||||||
|             ]) ?> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| </div> |  | ||||||
| @ -1,42 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $dataProvider yii\data\DataProviderInterface */ |  | ||||||
| 
 |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <article class="heading-component"> |  | ||||||
| 	<div class="heading-component-inner"> |  | ||||||
| 		<h5 class="heading-component-title"><?= Yii::t('blog', 'All Posts') ?></h5>
 |  | ||||||
| 	</div> |  | ||||||
| </article> |  | ||||||
| 
 |  | ||||||
| <?= \yii\widgets\ListView::widget([ |  | ||||||
|     'dataProvider' => $dataProvider, |  | ||||||
|     'layout' => "<div class='row row-30'>{items}</div>\n<nav class='pagination-wrap' aria-label='Page navigation'>{pager}</nav>", |  | ||||||
|     'itemView' => '_post', |  | ||||||
|     'pager' => [ |  | ||||||
|         //'pagination' => null, |  | ||||||
| 	    'maxButtonCount' => 7, |  | ||||||
| 	    'pageCssClass' => 'page-item', |  | ||||||
| 	    'options' => [ |  | ||||||
| 	        'class' => 'pagination', |  | ||||||
| 	    ], |  | ||||||
| 	    'disabledListItemSubTagOptions' => ['tag' => 'div', 'class' => 'disabled'], |  | ||||||
| 	    'activePageCssClass' => 'active', |  | ||||||
| 	    'linkOptions' => [ |  | ||||||
| 	    	'class' => 'page-link', |  | ||||||
| 	    ], |  | ||||||
| 	    'prevPageLabel' => '<span class="fa fa-angle-left"></span>', |  | ||||||
| 	    'nextPageLabel' => '<span class="fa fa-angle-right"></span>', |  | ||||||
|     ], |  | ||||||
|     'itemOptions' => [ |  | ||||||
| 	    'tag' => false |  | ||||||
|     ], |  | ||||||
| 	'options' => [ |  | ||||||
| 		'tag' => false, |  | ||||||
| 		'class' => 'row row-30', |  | ||||||
| 		'id' => false, |  | ||||||
| 	], |  | ||||||
| ]) ?> |  | ||||||
| 
 |  | ||||||
| @ -1,51 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $model \common\modules\blog\entities\BlogPost */ |  | ||||||
| 
 |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use yii\helpers\Url; |  | ||||||
| use yii\helpers\StringHelper; |  | ||||||
| 
 |  | ||||||
| $url = Url::to(['blog/post/post', 'id' =>$model->id]); |  | ||||||
| $url_full = Yii::$app->params['frontendHostInfo'] . Url::to(['blog/post/post', 'id' =>$model->id]); |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| <div class="col-md-6"> |  | ||||||
| 	<article class="post-future"> |  | ||||||
| 		<a class="post-future-figure" href="<?= $url ?>">
 |  | ||||||
| 			<img src="<?= Html::encode($model->getThumbFileUrl('image', '368_287')) ?>" alt="<?= Html::encode($model->title) ?>" />
 |  | ||||||
| 		</a> |  | ||||||
| 		<div class="post-future-main"> |  | ||||||
| 			<h4 class="post-future-title"><a href="<?= $url ?>"><?= Html::encode($model->title) ?></a></h4>
 |  | ||||||
| 			<div class="post-future-meta"> |  | ||||||
| 				<!-- Badge--> |  | ||||||
| 				<div class="badge badge-secondary"><?= $model->category->name ?></div>
 |  | ||||||
| 				<div class="post-future-time"><span class="icon fa fa-calendar"></span> |  | ||||||
| 					<time datetime="<?= date('Y') ?>"><?= Yii::$app->formatter->asDate($model->published_at, 'php:d F, Y') ?></time>
 |  | ||||||
| 				</div> |  | ||||||
| 			</div> |  | ||||||
| 			<hr/> |  | ||||||
| 			<div class="post-future-text"> |  | ||||||
| 				<p><?= StringHelper::truncateWords(Html::encode($model->description), 12, '...') ?></p>
 |  | ||||||
| 			</div> |  | ||||||
| 			<div class="post-future-footer group-flex group-flex-xs"><a class="button button-gray-outline" href="#"><?= Yii::t('blog', 'Read more') ?></a>
 |  | ||||||
| 				<div class="post-future-share"> |  | ||||||
| 					<div class="inline-toggle-parent"> |  | ||||||
| 						<div class="inline-toggle icon fa fa-share-alt" title="<?= Yii::t('blog', 'Share') ?>"></div>
 |  | ||||||
| 						<div class="inline-toggle-element"> |  | ||||||
| 							<ul class="list-inline"> |  | ||||||
| 								<li><span class="fa fa-share-alt"></span></li> |  | ||||||
| 								<li><a target="_blank" class="icon fa fa-facebook" href="https://www.facebook.com/sharer.php?src=sp&u=<?= urlencode($url_full) ?>"></a></li>
 |  | ||||||
| 								<li><a target="_blank" class="icon fa fa-odnoklassniki" href="https://connect.ok.ru/offer?url=<?= urlencode($url_full) ?>"></a></li>
 |  | ||||||
| 								<li><a target="_blank" class="icon fa fa-google-plus" href="https://plus.google.com/share?url=<?= urlencode($url_full) ?>"></a></li>
 |  | ||||||
| 								<li><a target="_blank" class="icon fa fa-vk" href="https://vk.com/share.php?url=<?= urlencode($url_full) ?>"></a></li>
 |  | ||||||
| 							</ul> |  | ||||||
| 						</div> |  | ||||||
| 					</div> |  | ||||||
| 				</div> |  | ||||||
| 			</div> |  | ||||||
| 		</div> |  | ||||||
| 	</article> |  | ||||||
| </div> |  | ||||||
| @ -1,40 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $dataProvider yii\data\DataProviderInterface */ |  | ||||||
| /* @var $category \common\modules\blog\entities\BlogCategory */ |  | ||||||
| 
 |  | ||||||
| use yii\helpers\Html; |  | ||||||
| 
 |  | ||||||
| $this->title = $category->getSeoTitle(); |  | ||||||
| 
 |  | ||||||
| $this->registerMetaTag(['name' =>'description', 'content' => $category->meta->description]); |  | ||||||
| $this->registerMetaTag(['name' =>'keywords', 'content' => $category->meta->keywords]); |  | ||||||
| 
 |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => Yii::t('blog', 'Blog'), 'url' => ['blog/post/index']]; |  | ||||||
| $this->params['breadcrumbs'][] = $category->name; |  | ||||||
| 
 |  | ||||||
| $this->params['active_category'] = $category; |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <h1><?= Html::encode($category->getHeadingTile()) ?></h1>
 |  | ||||||
| 
 |  | ||||||
| <?php if (trim($category->description)): ?> |  | ||||||
|     <div class="panel panel-default"> |  | ||||||
|         <div class="panel-body"> |  | ||||||
|             <?= Yii::$app->formatter->asHtml($category->description, [ |  | ||||||
|                 'Attr.AllowedRel' => array('nofollow'), |  | ||||||
|                 'HTML.SafeObject' => true, |  | ||||||
|                 'Output.FlashCompat' => true, |  | ||||||
|                 'HTML.SafeIframe' => true, |  | ||||||
|                 'URI.SafeIframeRegexp'=>'%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%', |  | ||||||
|             ]) ?> |  | ||||||
|         </div> |  | ||||||
|     </div> |  | ||||||
| <?php endif; ?> |  | ||||||
| 
 |  | ||||||
| <?= $this->render('_list', [ |  | ||||||
|     'dataProvider' => $dataProvider |  | ||||||
| ]) ?> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| @ -1,13 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $dataProvider yii\data\DataProviderInterface */ |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| $this->title = Yii::t('blog', 'Blog'); |  | ||||||
| $this->params['breadcrumbs'][] = $this->title; |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <?= $this->render('_list', [ |  | ||||||
|     'dataProvider' => $dataProvider |  | ||||||
| ]) ?> |  | ||||||
| @ -1,113 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $post \common\modules\blog\entities\BlogPost */ |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\widgets\CommentsWidget; |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use yii\helpers\Url; |  | ||||||
| 
 |  | ||||||
| $this->title = $post->getSeoTitle(); |  | ||||||
| 
 |  | ||||||
| $this->registerMetaTag(['name' =>'description', 'content' => $post->meta->description]); |  | ||||||
| $this->registerMetaTag(['name' =>'keywords', 'content' => $post->meta->keywords]); |  | ||||||
| 
 |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => Yii::t('blog', 'Blog'), 'url' => ['blog/post/index']]; |  | ||||||
| $this->params['breadcrumbs'][] = ['label' => $post->category->name, 'url' => ['blog/post/category', 'id' => $post->category->id]]; |  | ||||||
| $this->params['breadcrumbs'][] = $post->title; |  | ||||||
| 
 |  | ||||||
| $this->params['active_category'] = $post->category; |  | ||||||
| 
 |  | ||||||
| $tagLinks = []; |  | ||||||
| foreach ($post->tags as $tag) { |  | ||||||
|     $tagLinks[] = '<li>' . Html::a(Html::encode($tag->name), ['tag', 'slug' => $tag->slug]) . '</li>'; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| $url = Url::to(['blog/post/post', 'id' =>$post->id]); |  | ||||||
| $url_full = Yii::$app->params['frontendHostInfo'] . Url::to(['blog/post/post', 'id' =>$post->id]); |  | ||||||
| 
 |  | ||||||
| $js = <<<JS |  | ||||||
| 	jQuery(document).ready(function($) { |  | ||||||
| 		if (device.desktop() || device.tablet()) { |  | ||||||
| 			var relative_slider = $('#relative_carousel').bxSlider({ |  | ||||||
| 				infiniteLoop: true, |  | ||||||
| 				hideControlOnEnd: true, |  | ||||||
| 				minSlides: 2, |  | ||||||
| 				maxSlides: 2, |  | ||||||
| 				moveSlides: 1, |  | ||||||
| 				slideMargin: 0, |  | ||||||
| 				pager: false, |  | ||||||
| 				prevText: '', |  | ||||||
| 				nextText: '', |  | ||||||
| 				controls: false |  | ||||||
| 			}); |  | ||||||
| 			 |  | ||||||
| 			$('#relative-button-prev').on('click', function(){ |  | ||||||
|       			relative_slider.goToPrevSlide(); |  | ||||||
|       			return false; |  | ||||||
|     		}); |  | ||||||
|     		 |  | ||||||
|     		$('#relative-button-next').on('click', function(){ |  | ||||||
|       			relative_slider.goToNextSlide(); |  | ||||||
|       			return false; |  | ||||||
|     		}) |  | ||||||
| 		} |  | ||||||
| 	}); |  | ||||||
| 
 |  | ||||||
| JS; |  | ||||||
| $this->registerJs($js, $this::POS_READY); |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| <div class="blog-post"> |  | ||||||
| 	<!-- Badge--> |  | ||||||
| 	<div class="badge badge-secondary"><?= $post->category->name ?> |  | ||||||
| 	</div> |  | ||||||
| 	<h3 class="blog-post-title"><?= Html::encode($post->title) ?></h3>
 |  | ||||||
| 	<div class="blog-post-header"> |  | ||||||
| 		<div class="blog-post-meta"> |  | ||||||
| 			<time class="blog-post-time" datetime="<?= date('Y') ?>"><span class="icon fa fa-calendar"></span><?= Yii::$app->formatter->asDate($post->published_at, 'php:d F, Y') ?></time>
 |  | ||||||
| 			<div class="blog-post-comment"><span class="icon fa fa-comment"></span><?= $post->comments_count ?></div>
 |  | ||||||
| 			<div class="blog-post-view"><span class="icon fa fa-eye"></span><?= $post->views ?></div>
 |  | ||||||
| 		</div> |  | ||||||
| 	</div> |  | ||||||
| 	<div class="blog-post-author-quote"> |  | ||||||
| 		<p><?= $post->description ?></p>
 |  | ||||||
| 	</div> |  | ||||||
| 	<div class="blog-post-share"> |  | ||||||
| 		<p><?= Yii::t('blog', 'Share') ?></p>
 |  | ||||||
| 		<ul class="group"> |  | ||||||
| 			<li><a target="_blank" class="icon fa fa-facebook" href="https://www.facebook.com/sharer.php?src=sp&u=<?= urlencode($url_full) ?>"></a></li>
 |  | ||||||
| 			<li><a target="_blank" class="icon fa fa-odnoklassniki" href="https://connect.ok.ru/offer?url=<?= urlencode($url_full) ?>"></a></li>
 |  | ||||||
| 			<li><a target="_blank" class="icon fa fa-google-plus" href="https://plus.google.com/share?url=<?= urlencode($url_full) ?>"></a></li>
 |  | ||||||
| 			<li><a target="_blank" class="icon fa fa-vk" href="https://vk.com/share.php?url=<?= urlencode($url_full) ?>"></a></li>
 |  | ||||||
| 		</ul> |  | ||||||
| 	</div> |  | ||||||
| 	<div class="blog-post-content"> |  | ||||||
| 
 |  | ||||||
| 		<img src="<?= Html::encode($post->getThumbFileUrl('image', '683_407')) ?>" alt="<?= Html::encode($post->title) ?>" width="683" height="407" />
 |  | ||||||
| 
 |  | ||||||
| 		<?= Yii::$app->formatter->asHtml($post->content, [ |  | ||||||
| 			'Attr.AllowedRel' => array('nofollow'), |  | ||||||
| 			'HTML.SafeObject' => true, |  | ||||||
| 			'Output.FlashCompat' => true, |  | ||||||
| 			'HTML.SafeIframe' => true, |  | ||||||
| 			'URI.SafeIframeRegexp'=>'%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%', |  | ||||||
| 		]) ?> |  | ||||||
| 
 |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
| 
 |  | ||||||
| <?= \common\modules\blog\widgets\PostByTagsWidget::widget([ |  | ||||||
| 	'count' => 10, |  | ||||||
| 	'view' => 'slider-relative', |  | ||||||
| 	'post' => $post, |  | ||||||
| ]) ?> |  | ||||||
| 
 |  | ||||||
| <ul class="list-tags" style="margin-top:20px"><?= implode(', ', $tagLinks) ?></ul>
 |  | ||||||
| 
 |  | ||||||
| <?= CommentsWidget::widget([ |  | ||||||
|     'post' => $post, |  | ||||||
| ]) ?> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| @ -1,29 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\widgets; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogCategory; |  | ||||||
| use common\modules\blog\repositories\read\BlogCategoryReadRepository; |  | ||||||
| use yii\base\Widget; |  | ||||||
| use yii\helpers\Html; |  | ||||||
| 
 |  | ||||||
| class CategoriesWidget extends Widget |  | ||||||
| { |  | ||||||
|     /** @var BlogCategory|null */ |  | ||||||
|     public $active; |  | ||||||
| 
 |  | ||||||
|     private $categories; |  | ||||||
| 
 |  | ||||||
|     public function __construct(BlogCategoryReadRepository $categories, $config = []) |  | ||||||
|     { |  | ||||||
|         parent::__construct($config); |  | ||||||
|         $this->categories = $categories; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function run(): string |  | ||||||
|     { |  | ||||||
|     	return $this->render('categories/categories', [ |  | ||||||
|     		'categories' => $this->categories->getAll(), |  | ||||||
| 	    ]); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,20 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\widgets; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogComment; |  | ||||||
| 
 |  | ||||||
| class CommentView |  | ||||||
| { |  | ||||||
|     public $comment; |  | ||||||
|     /** |  | ||||||
|      * @var self[] |  | ||||||
|      */ |  | ||||||
|     public $children; |  | ||||||
| 
 |  | ||||||
|     public function __construct(BlogComment $comment, array $children) |  | ||||||
|     { |  | ||||||
|         $this->comment = $comment; |  | ||||||
|         $this->children = $children; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,57 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\widgets; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogComment; |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| use common\modules\blog\forms\BlogCommentForm; |  | ||||||
| use yii\base\InvalidConfigException; |  | ||||||
| use yii\base\Widget; |  | ||||||
| 
 |  | ||||||
| class CommentsWidget extends Widget |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * @var BlogPost |  | ||||||
|      */ |  | ||||||
|     public $post; |  | ||||||
| 
 |  | ||||||
|     public function init(): void |  | ||||||
|     { |  | ||||||
|         if (!$this->post) { |  | ||||||
|             throw new InvalidConfigException('Specify the post.'); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function run(): string |  | ||||||
|     { |  | ||||||
|         $form = new BlogCommentForm(); |  | ||||||
| 
 |  | ||||||
|         $comments = $this->post->getBlogComments() |  | ||||||
|             ->orderBy(['parent_id' => SORT_ASC, 'id' => SORT_ASC]) |  | ||||||
|             ->all(); |  | ||||||
| 
 |  | ||||||
|         $items = $this->treeRecursive($comments, null); |  | ||||||
| 
 |  | ||||||
|         return $this->render('comments/comments', [ |  | ||||||
|             'post' => $this->post, |  | ||||||
|             'items' => $items, |  | ||||||
|             'commentForm' => $form, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @param BlogComment[] $comments |  | ||||||
|      * @param integer $parentId |  | ||||||
|      * @return CommentView[] |  | ||||||
|      */ |  | ||||||
|     public function treeRecursive(&$comments, $parentId): array |  | ||||||
|     { |  | ||||||
|         $items = []; |  | ||||||
|         foreach ($comments as $comment) { |  | ||||||
|             if ($comment->parent_id == $parentId) { |  | ||||||
|                 $items[] = new CommentView($comment, $this->treeRecursive($comments, $comment->id)); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return $items; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,30 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Created by Error202 |  | ||||||
|  * Date: 10.07.2018 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\widgets; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| use core\forms\menu\MenuItemForm; |  | ||||||
| use yii\base\Widget; |  | ||||||
| 
 |  | ||||||
| class MenuItemCreatorWidget extends Widget |  | ||||||
| { |  | ||||||
| 	public $menu_id; |  | ||||||
| 
 |  | ||||||
| 	public function run() |  | ||||||
| 	{ |  | ||||||
| 		$form = new MenuItemForm(); |  | ||||||
| 		$form->module = 'blog'; |  | ||||||
| 		$form->name = \Yii::t('blog', 'Blog'); |  | ||||||
| 		$form->title_attr = \Yii::t('blog', 'Blog'); |  | ||||||
| 		$form->menu_id = $this->menu_id; |  | ||||||
| 		$form->url = '/blog/post/index'; |  | ||||||
| 
 |  | ||||||
| 		return $this->render('menu-item/creator', [ |  | ||||||
| 			'model' => $form, |  | ||||||
| 		]); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,42 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Created by Error202 |  | ||||||
|  * Date: 24.01.2018 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\widgets; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogTagAssignment; |  | ||||||
| use common\modules\blog\repositories\read\BlogPostReadRepository; |  | ||||||
| use yii\base\Widget; |  | ||||||
| use yii\helpers\ArrayHelper; |  | ||||||
| use yii\helpers\Url; |  | ||||||
| 
 |  | ||||||
| class PostByTagsWidget extends Widget |  | ||||||
| { |  | ||||||
| 	public $count; |  | ||||||
| 	public $view; |  | ||||||
| 	public $post; |  | ||||||
| 
 |  | ||||||
| 	public $posts; |  | ||||||
| 
 |  | ||||||
| 	public function __construct(BlogPostReadRepository $posts, $config = []) |  | ||||||
| 	{ |  | ||||||
| 		parent::__construct($config); |  | ||||||
| 		$this->count = $this->count ? $this->count : 5; |  | ||||||
| 		$this->posts = $posts; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	public function run(): string |  | ||||||
| 	{ |  | ||||||
| 		$tag_ids = ArrayHelper::getColumn(BlogTagAssignment::find()->andWhere(['post_id' => $this->post->id])->all(), 'tag_id'); |  | ||||||
| 		$posts = $this->posts->getByTagsId($this->post, $tag_ids, $this->count)->getModels(); |  | ||||||
| 
 |  | ||||||
| 		return $this->render($this->view, [ |  | ||||||
| 			'posts' => $posts, |  | ||||||
| 			'view' => $this->view, |  | ||||||
| 			'url' => Url::canonical(), |  | ||||||
| 		]); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,39 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Created by Error202 |  | ||||||
|  * Date: 30.01.2018 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| namespace common\modules\blog\widgets; |  | ||||||
| 
 |  | ||||||
| use common\modules\blog\entities\BlogPost; |  | ||||||
| use yii\base\Widget; |  | ||||||
| 
 |  | ||||||
| class TagWidget extends Widget |  | ||||||
| { |  | ||||||
| 	public $post_id; |  | ||||||
| 
 |  | ||||||
| 	public function run() { |  | ||||||
| 
 |  | ||||||
| 		// tags from categories with assignments, ordered by count |  | ||||||
| 		$tags = BlogPost::find()->select('t.name as name, count(t.id) as cnt, t.id as id') |  | ||||||
| 			->from('blog_posts as p, blog_tag_assignments as a, blog_tags as t') |  | ||||||
| 			->andWhere('p.id = a.post_id') |  | ||||||
| 			->andWhere('t.id = a.tag_id') |  | ||||||
| 			->andWhere(isset($this->post_id) ? 'p.id = ' . $this->post_id : '') |  | ||||||
| 			->groupBy('t.id') |  | ||||||
| 			->orderBy('cnt DESC') |  | ||||||
| 			->limit(20) |  | ||||||
| 			->asArray() |  | ||||||
| 			->all(); |  | ||||||
| 
 |  | ||||||
| 		if ($tags) { |  | ||||||
| 			return $this->render( 'tags/tags', [ |  | ||||||
| 				'tags' => $tags, |  | ||||||
| 			] ); |  | ||||||
| 		} |  | ||||||
| 		else { |  | ||||||
| 			return ''; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -1,32 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Created by Error202 |  | ||||||
|  * Date: 21.06.2018 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| use yii\helpers\Html; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @var $this \yii\web\View |  | ||||||
|  * @var $categories \common\modules\blog\entities\BlogCategory[] |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <!-- Categories Widget --> |  | ||||||
| <div class="card my-4"> |  | ||||||
| 	<h5 class="card-header"><?= Yii::t('blog_public', 'Categories') ?></h5>
 |  | ||||||
| 	<div class="card-body"> |  | ||||||
| 		<div class="row"> |  | ||||||
| 			<div class="col-lg-12"> |  | ||||||
| 				<ul class="list-unstyled mb-0 blog-categories-widget-list"> |  | ||||||
| 					<?php foreach ($categories as $category): ?> |  | ||||||
| 						<li> |  | ||||||
| 							<?= Html::a($category->translation->name, ['/blog/post/category', 'id' => $category->id]) ?> |  | ||||||
| 						</li> |  | ||||||
| 					<?php endforeach; ?> |  | ||||||
| 				</ul> |  | ||||||
| 			</div> |  | ||||||
| 		</div> |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
| @ -1,78 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| /* @var $item \common\modules\blog\widgets\CommentView */ |  | ||||||
| /* @var $child integer */ |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <div data-id="<?= $item->comment->id ?>" class="blog-comment <?= $child ? 'blog-comment-child' : 'blog-comment-parent' ?>" style="margin-left: <?= $child * 30 ?>px">
 |  | ||||||
| 
 |  | ||||||
| 	<div class="media mb-4"> |  | ||||||
| 		<img class="d-flex mr-3 rounded-circle blog-comment-avatar" src="<?= Yii::$app->avatar->show($item->comment->user->username) ?>" alt="">
 |  | ||||||
| 		<div class="media-body"> |  | ||||||
| 			<a name="comment_<?= $item->comment->id ?>"></a>
 |  | ||||||
| 			<h5 class="mt-0"><?= $item->comment->user->username ?> |  | ||||||
| 			<time class="blog-comment-time" datetime="<?= date('Y', $item->comment->created_at) ?>">
 |  | ||||||
| 				<?php |  | ||||||
| 				$date = ($item->comment->created_at > time() - 60*60*24*365*50 |  | ||||||
| 					? Yii::$app->formatter->asRelativeTime($item->comment->created_at) |  | ||||||
| 					: Yii::$app->formatter->asDatetime($item->comment->created_at)); |  | ||||||
| 				?> |  | ||||||
| 				<?= $date ?> |  | ||||||
| 			</time> |  | ||||||
| 			</h5> |  | ||||||
| 			<p> |  | ||||||
| 			<?php if ($item->comment->isActive()): ?> |  | ||||||
| 				<?= Yii::$app->formatter->asNtext($item->comment->text) ?> |  | ||||||
| 			<?php else: ?> |  | ||||||
| 				<i>Comment is deleted.</i> |  | ||||||
| 			<?php endif; ?> |  | ||||||
| 			</p> |  | ||||||
| 			<div class="blog-comment-footer"> |  | ||||||
| 				<?php if (!Yii::$app->user->isGuest): ?> |  | ||||||
| 					<div class="blog-comment-reply"><a href="#"><?= Yii::t('post', 'Reply') ?></a></div>
 |  | ||||||
| 				<?php endif; ?> |  | ||||||
| 			</div> |  | ||||||
| 			<div class="reply-block"></div> |  | ||||||
| 		</div> |  | ||||||
| 	</div> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	<!-- |  | ||||||
| 	<div class="post-comment-main"> |  | ||||||
| 		<div class="post-comment-header"> |  | ||||||
| 			<a name="comment_<?= $item->comment->id ?>"></a>
 |  | ||||||
| 			<h5 class="author-name"><?= $item->comment->user->username ?></h5>
 |  | ||||||
| 			<time class="post-comment-time" datetime="<?= date('Y', $item->comment->created_at) ?>">
 |  | ||||||
| 				<?php |  | ||||||
| 				$date = ($item->comment->created_at > time() - 60*60*24*365*50 |  | ||||||
| 					? Yii::$app->formatter->asRelativeTime($item->comment->created_at) |  | ||||||
| 					: Yii::$app->formatter->asDatetime($item->comment->created_at)); |  | ||||||
| 				?> |  | ||||||
| 				<?= $date ?> |  | ||||||
| 			</time> |  | ||||||
| 		</div> |  | ||||||
| 		<div class="post-comment-text"> |  | ||||||
| 			<p> |  | ||||||
| 				<?php if ($item->comment->isActive()): ?> |  | ||||||
| 					<?= Yii::$app->formatter->asNtext($item->comment->text) ?> |  | ||||||
| 				<?php else: ?> |  | ||||||
| 					<i>Comment is deleted.</i> |  | ||||||
| 				<?php endif; ?> |  | ||||||
| 			</p> |  | ||||||
| 		</div> |  | ||||||
| 		<div class="post-comment-footer"> |  | ||||||
| 			<?php if (!Yii::$app->user->isGuest): ?> |  | ||||||
| 				<div class="comment-reply"><span class="icon fa fa-comment"></span><a href="#"><?= Yii::t('post', 'Reply') ?></a></div>
 |  | ||||||
| 			<?php endif; ?> |  | ||||||
| 		</div> |  | ||||||
| 
 |  | ||||||
| 		<div class="reply-block"></div> |  | ||||||
| 
 |  | ||||||
| 	</div>--> |  | ||||||
| </div> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| <?php foreach ($item->children as $children): ?> |  | ||||||
| 	<?= $this->render('_comment', ['item' => $children, 'child' => $child + 1]) ?> |  | ||||||
| <?php endforeach; ?> |  | ||||||
| @ -1,103 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| use yii\bootstrap\ActiveForm; |  | ||||||
| use yii\helpers\Html; |  | ||||||
| 
 |  | ||||||
| /* @var $this yii\web\View */ |  | ||||||
| /* @var $post \common\modules\blog\entities\BlogPost */ |  | ||||||
| /* @var $items \common\modules\blog\widgets\CommentView[] */ |  | ||||||
| /* @var $count integer */ |  | ||||||
| /* @var $commentForm \common\modules\blog\forms\BlogCommentForm */ |  | ||||||
| 
 |  | ||||||
| $css = <<<CSS |  | ||||||
| a.reply-block-start { |  | ||||||
|     display: block; |  | ||||||
|     position: relative; |  | ||||||
|     top: -100px; |  | ||||||
|     visibility: hidden; |  | ||||||
| } |  | ||||||
| a#send-comment { |  | ||||||
| 	font-size: 14px; |  | ||||||
| 	font-weight: normal; |  | ||||||
| } |  | ||||||
| .heading-component { |  | ||||||
| 	margin-bottom: 20px; |  | ||||||
| } |  | ||||||
| CSS; |  | ||||||
| $this->registerCss( $css ); |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <div class="row"> |  | ||||||
| 	<div class="col-sm-12"> |  | ||||||
| 		<!-- Heading Component--> |  | ||||||
| 		<article class="heading-component"> |  | ||||||
| 			<div class="heading-component-inner"> |  | ||||||
| 				<h5 class="heading-component-title"> |  | ||||||
| 					<?= Yii::t( 'post', 'Comments: {count}', [ 'count' => $post->comments_count ] ) ?> |  | ||||||
| 
 |  | ||||||
| 					<?php if ( ! Yii::$app->user->isGuest ): ?> |  | ||||||
| 						<a id="send-comment" href="#reply-block-start" |  | ||||||
| 						   class="pull-right"><?= Yii::t( 'post', 'Send comment' ) ?></a>
 |  | ||||||
| 					<?php endif; ?> |  | ||||||
| 				</h5> |  | ||||||
| 			</div> |  | ||||||
| 		</article> |  | ||||||
| 
 |  | ||||||
| 		<?php if ( count( $items ) > 0 ): ?> |  | ||||||
| 			<div class="blog-post-comments"> |  | ||||||
| 				<?php foreach ( $items as $item ): ?> |  | ||||||
| 					<?= $this->render( '_comment', [ 'item' => $item, 'child' => 0 ] ) ?> |  | ||||||
| 				<?php endforeach; ?> |  | ||||||
| 			</div> |  | ||||||
| 		<?php endif; ?> |  | ||||||
| 
 |  | ||||||
| 		<?php if ( ! Yii::$app->user->isGuest ): ?> |  | ||||||
| 
 |  | ||||||
| 			<div id="reply-container"> |  | ||||||
| 				<a name="reply-block-start" class="reply-block-start"></a> |  | ||||||
| 				<div id="reply-block" class="leave-reply"> |  | ||||||
| 
 |  | ||||||
| 					<?php $form = ActiveForm::begin( [ |  | ||||||
| 						'action' => [ 'comment', 'id' => $post->id ], |  | ||||||
| 					] ); ?> |  | ||||||
| 
 |  | ||||||
| 					<?= Html::activeHiddenInput( $commentForm, 'parentId' ) ?> |  | ||||||
| 					<?= $form->field( $commentForm, 'text' )->textarea( [ 'rows' => 5 ] )->label( Yii::t( 'post', 'Comment' ) ) ?> |  | ||||||
| 
 |  | ||||||
| 					<div class="form-group"> |  | ||||||
| 						<?= Html::submitButton( Yii::t( 'post', 'Submit' ), [ 'class' => 'btn btn-primary' ] ) ?> |  | ||||||
| 					</div> |  | ||||||
| 
 |  | ||||||
| 					<?php ActiveForm::end(); ?> |  | ||||||
| 				</div> |  | ||||||
| 			</div> |  | ||||||
| 		<?php else: ?> |  | ||||||
| 			<div style="text-align: center; padding: 20px;"> |  | ||||||
| 					<?= Yii::t('post', 'Please {login} for writing a comment.', ['login' => Html::a(Yii::t('auth', 'Log in'), ['/auth/auth/login'])]) ?> |  | ||||||
| 			</div> |  | ||||||
| 		<?php endif; ?> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
| 
 |  | ||||||
| <?php $this->registerJs( " |  | ||||||
|     jQuery(document).on('click', '.blog-post-comments .blog-comment-reply', function () { |  | ||||||
|         var link = jQuery(this); |  | ||||||
|         var form = jQuery('#reply-block'); |  | ||||||
|         var comment = link.closest('.blog-comment'); |  | ||||||
|         jQuery('#blogcommentform-parentid').val(comment.data('id')); |  | ||||||
|         form.detach().appendTo(comment.find('.reply-block:first')); |  | ||||||
|         return false; |  | ||||||
|     }); |  | ||||||
|      |  | ||||||
|     jQuery(document).on('click', '#send-comment', function () { |  | ||||||
|         var form = jQuery('#reply-block'); |  | ||||||
|         jQuery('#blogcommentform-parentid').val(''); |  | ||||||
|         form.detach().appendTo('#reply-container'); |  | ||||||
|         //return false; |  | ||||||
|     }); |  | ||||||
| " ); ?> |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|   |  | ||||||
| @ -1,128 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Created by Error202 |  | ||||||
|  * Date: 10.07.2018 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @var $this \yii\web\View |  | ||||||
|  * @var $model \core\forms\menu\MenuItemForm |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| use yii\widgets\ActiveForm; |  | ||||||
| use yii\helpers\Html; |  | ||||||
| use yii\web\JsExpression; |  | ||||||
| use yii\helpers\Url; |  | ||||||
| 
 |  | ||||||
| $block_name = Yii::t('blog', 'Blog'); |  | ||||||
| $block_title_attr = Yii::t('blog', 'Blog'); |  | ||||||
| 
 |  | ||||||
| $js = <<<JS |  | ||||||
| 	function selectBlogPostOn() { |  | ||||||
|     	$("#post_select").removeAttr('disabled'); |  | ||||||
|     	updateBlogUrl('post'); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	function selectBlogPostOff() { |  | ||||||
|     	$("#post_select").attr('disabled', 'disabled'); |  | ||||||
|     	updateBlogUrl('blog'); |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	function updateBlogUrl(type) { |  | ||||||
|     	if (type === 'blog') { |  | ||||||
|     	    $("#blog_menu_item_url").val('/blog/post/index'); |  | ||||||
|     	    $("#blog_menu_item_url_params").val(''); |  | ||||||
|     	    $("#blog_menu_item_name").val('{$block_name}'); |  | ||||||
|     	    $("#blog_menu_item_title_attr").val('$block_title_attr'); |  | ||||||
|     	} |  | ||||||
|     	else { |  | ||||||
|     	    var select = $("#post_select"); |  | ||||||
|     	    var data = select.select2('data'); |  | ||||||
|     	    var selected_post = select.val(); |  | ||||||
|     	    $("#blog_menu_item_url").val('/blog/post/post/'); |  | ||||||
|     	    $("#blog_menu_item_url_params").val('{"id":'+selected_post+'}'); |  | ||||||
|     	    $("#blog_menu_item_name").val(data[0].text); |  | ||||||
|     	    $("#blog_menu_item_title_attr").val(data[0].text); |  | ||||||
|     	} |  | ||||||
| 	} |  | ||||||
| JS; |  | ||||||
| $this->registerJs($js, $this::POS_HEAD); |  | ||||||
| 
 |  | ||||||
| $fetchUrl = Url::to( [ '/blog/manage/post/post-search' ] ); |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <div class="menu_item_widget"> |  | ||||||
| 
 |  | ||||||
| 	<div class="form-group"> |  | ||||||
| 		<div class="radio"> |  | ||||||
| 			<?= Html::label(Html::radio('blog_item_type', true, [ |  | ||||||
| 				'value' => 'blog_home', |  | ||||||
| 				'onclick' => new JsExpression('selectBlogPostOff()'), |  | ||||||
| 			]) . Yii::t('blog', 'Blog Home')) ?> |  | ||||||
| 		</div> |  | ||||||
| 
 |  | ||||||
| 		<div class="radio"> |  | ||||||
| 			<?= Html::label(Html::radio('blog_item_type', false, [ |  | ||||||
| 					'value' => 'blog_post', |  | ||||||
| 					'onclick' => new JsExpression('selectBlogPostOn()'), |  | ||||||
| 				]) . Yii::t('blog', 'Blog Post')) ?> |  | ||||||
| 		</div> |  | ||||||
| 
 |  | ||||||
| 		<div> |  | ||||||
| 			<?= \kartik\widgets\Select2::widget([ |  | ||||||
| 				'name' => 'post_select', |  | ||||||
| 			    'value' => '', |  | ||||||
| 			    'options' => [ |  | ||||||
| 			    	'placeholder' => Yii::t('blog', 'Select post...'), |  | ||||||
| 				    'id' => 'post_select', |  | ||||||
| 				    'onchange' => new JsExpression("updateBlogUrl('post')"), |  | ||||||
| 			    ], |  | ||||||
| 				'pluginOptions' => [ |  | ||||||
| 					'disabled' => true, |  | ||||||
| 					'ajax' => [ |  | ||||||
| 						'url' => $fetchUrl, |  | ||||||
| 						'dataType' => 'json', |  | ||||||
| 						'data' => new JsExpression('function(params) { return {q:params.term}; }') |  | ||||||
| 					], |  | ||||||
| 					'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), |  | ||||||
| 					'templateResult' => new JsExpression('function(tag) { return tag.text; }'), |  | ||||||
| 					'templateSelection' => new JsExpression('function (tag) { return tag.text; }'), |  | ||||||
| 				], |  | ||||||
| 			]) ?> |  | ||||||
| 		</div> |  | ||||||
| 	</div> |  | ||||||
| 
 |  | ||||||
| <?php $form = ActiveForm::begin(); ?> |  | ||||||
| 
 |  | ||||||
| 	<?= $form->field($model, 'name')->hiddenInput([ |  | ||||||
| 		'id' => 'blog_menu_item_name', |  | ||||||
| 	])->label(false) ?> |  | ||||||
| 
 |  | ||||||
| 	<?= $form->field($model, 'title_attr')->hiddenInput([ |  | ||||||
| 		'id' => 'blog_menu_item_title_attr', |  | ||||||
| 	])->label(false) ?> |  | ||||||
| 
 |  | ||||||
| 	<?= $form->field($model, 'module')->hiddenInput([ |  | ||||||
| 	])->label(false) ?> |  | ||||||
| 
 |  | ||||||
| 	<?= $form->field($model, 'menu_id')->hiddenInput([ |  | ||||||
| 	])->label(false) ?> |  | ||||||
| 
 |  | ||||||
| 	<?= $form->field($model, 'url')->hiddenInput([ |  | ||||||
| 		'id' => 'blog_menu_item_url', |  | ||||||
| 	])->label(false) ?> |  | ||||||
| 
 |  | ||||||
| 	<?= $form->field($model, 'url_params')->hiddenInput([ |  | ||||||
| 		'value' => '', |  | ||||||
| 		'id' => 'blog_menu_item_url_params', |  | ||||||
| 	])->label(false) ?> |  | ||||||
| 
 |  | ||||||
| <div class="form-group"> |  | ||||||
| <?= Html::submitButton(Yii::t('buttons', 'Add to menu'), [ |  | ||||||
| 	'class' => 'btn btn-info btn-sm pull-right' |  | ||||||
| ]) ?> |  | ||||||
| </div> |  | ||||||
| 
 |  | ||||||
| <?php ActiveForm::end(); ?> |  | ||||||
| 
 |  | ||||||
| </div> |  | ||||||
| @ -1,38 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @var $this \yii\web\View |  | ||||||
|  * @var $view string |  | ||||||
|  * @var $posts \common\modules\blog\entities\BlogPost[] |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <div class="row"> |  | ||||||
| 	<div class="col-sm-12 owl-carousel-outer-navigation"> |  | ||||||
| 		<!-- Heading Component--> |  | ||||||
| 		<article class="heading-component"> |  | ||||||
| 			<div class="heading-component-inner"> |  | ||||||
| 				<h5 class="heading-component-title"><?= Yii::t('post', 'Related') ?> |  | ||||||
| 				</h5> |  | ||||||
| 				<div class="owl-carousel-arrows-outline"> |  | ||||||
| 					<div class="owl-nav"> |  | ||||||
| 						<button class="owl-arrow owl-arrow-prev" id="relative-button-prev"></button> |  | ||||||
| 						<button class="owl-arrow owl-arrow-next" id="relative-button-next"></button> |  | ||||||
| 					</div> |  | ||||||
| 				</div> |  | ||||||
| 			</div> |  | ||||||
| 		</article> |  | ||||||
| 
 |  | ||||||
| 		<!-- Blog Carousel--> |  | ||||||
| 		<div id="relative_carousel" class="owl-carousel row"> |  | ||||||
| 				<?php foreach ($posts as $post): ?> |  | ||||||
| 
 |  | ||||||
| 					<?= $this->render($view . '_item', [ |  | ||||||
| 						'post' => $post |  | ||||||
| 					]) ?> |  | ||||||
| 
 |  | ||||||
| 				<?php endforeach; ?> |  | ||||||
| 		</div> |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
| @ -1,21 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Created by Error202 |  | ||||||
|  * Date: 21.06.2018 |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| use yii\helpers\Html; |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * @var $this \yii\web\View |  | ||||||
|  * @var $tags array |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| ?> |  | ||||||
| 
 |  | ||||||
| <hr> |  | ||||||
| <ul class="list-unstyled"> |  | ||||||
| <?php foreach ($tags as $tag): ?> |  | ||||||
| 	<li class="list-inline-item"><i class="fa fa-tag" aria-hidden="true"></i> <?= Html::a($tag['name'], ['/blog/post/tag', 'id' => $tag['id']]) ?></li>
 |  | ||||||
| <?php endforeach; ?> |  | ||||||
| </ul> |  | ||||||
					Loading…
					
					
				
		Reference in new issue