├── assets ├── gdd │ ├── gddflvplayer.swf │ ├── index.php │ └── jquery.flash.min.js ├── flowplayer │ ├── flowplayer-3.2.18.swf │ ├── flowplayer.controls-3.2.16.swf │ ├── index.php │ └── example │ │ ├── style.css │ │ └── index.html ├── GddAsset.php └── FlowAsset.php ├── Module.php ├── views ├── file │ ├── create.php │ ├── update.php │ ├── _itemIndex.php │ ├── _search.php │ ├── index.php │ ├── view.php │ ├── _form.php │ └── admin.php ├── post │ ├── create.php │ ├── update.php │ ├── index.php │ ├── _search.php │ ├── _itemIndex.php │ ├── view.php │ ├── admin.php │ └── _form.php ├── banner │ ├── create.php │ ├── update.php │ ├── _search.php │ ├── view.php │ ├── _form.php │ └── index.php ├── gallery │ ├── create.php │ ├── update.php │ ├── _search.php │ ├── view.php │ ├── index.php │ ├── _itemTag.php │ ├── _itemAll.php │ ├── admin.php │ └── _form.php ├── category │ ├── create.php │ ├── update.php │ ├── _search.php │ ├── view.php │ ├── _form.php │ └── index.php ├── page │ ├── create.php │ ├── update.php │ ├── _search.php │ ├── view.php │ ├── index.php │ └── _form.php └── default │ └── index.php ├── migrations ├── m150411_164028_amilna_blog_static_script.php ├── m150330_225351_amilna_blog_banner_imageonly.php ├── m150311_000744_amilna_blog_static.php └── m150205_031747_amilna_blog.php ├── npm-debug.log ├── composer.json ├── README.md ├── LICENSE ├── controllers ├── DefaultController.php ├── CategoryController.php ├── PageController.php ├── BannerController.php └── FileController.php └── models ├── BlogCatPos.php ├── File.php ├── StaticPage.php ├── Gallery.php ├── Category.php ├── Post.php ├── Banner.php ├── CategorySearch.php ├── FileSearch.php ├── BannerSearch.php ├── GallerySearch.php └── StaticPageSearch.php /assets/gdd/gddflvplayer.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amilna/blog/HEAD/assets/gdd/gddflvplayer.swf -------------------------------------------------------------------------------- /assets/flowplayer/flowplayer-3.2.18.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amilna/blog/HEAD/assets/flowplayer/flowplayer-3.2.18.swf -------------------------------------------------------------------------------- /assets/flowplayer/flowplayer.controls-3.2.16.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amilna/blog/HEAD/assets/flowplayer/flowplayer.controls-3.2.16.swf -------------------------------------------------------------------------------- /assets/GddAsset.php: -------------------------------------------------------------------------------- 1 | 14 | * @since 2.0 15 | */ 16 | class GddAsset extends AssetBundle 17 | { 18 | public $sourcePath = '@amilna/blog/assets/gdd'; 19 | } 20 | -------------------------------------------------------------------------------- /assets/FlowAsset.php: -------------------------------------------------------------------------------- 1 | 14 | * @since 2.0 15 | */ 16 | class FlowAsset extends AssetBundle 17 | { 18 | public $sourcePath = '@amilna/blog/assets/flowplayer'; 19 | } 20 | -------------------------------------------------------------------------------- /Module.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /views/file/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 10 | 'modelClass' => Yii::t('app','File'), 11 | ]); 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Files'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_form', [ 20 | 'model' => $model, 21 | ]) ?> 22 | 23 |
24 | -------------------------------------------------------------------------------- /views/post/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 10 | 'modelClass' => Yii::t('app','Post'), 11 | ]); 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Posts'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_form', [ 20 | 'model' => $model, 21 | ]) ?> 22 | 23 |
24 | -------------------------------------------------------------------------------- /views/banner/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 10 | 'modelClass' => Yii::t('app','Banner'), 11 | ]); 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Banners'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 | 24 | -------------------------------------------------------------------------------- /views/gallery/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 10 | 'modelClass' => Yii::t('app','Gallery'), 11 | ]); 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Galleries'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 | 24 | -------------------------------------------------------------------------------- /views/category/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 10 | 'modelClass' => Yii::t('app','Category'), 11 | ]); 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Categories'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_form', [ 20 | 'model' => $model, 21 | ]) ?> 22 | 23 |
24 | -------------------------------------------------------------------------------- /views/page/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 10 | 'modelClass' => Yii::t('app','Static Page'), 11 | ]); 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Static Pages'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_form', [ 20 | 'model' => $model, 21 | ]) ?> 22 | 23 |
24 | -------------------------------------------------------------------------------- /views/file/update.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Update {modelClass}: ', [ 9 | 'modelClass' => Yii::t('app','File'), 10 | ]) . ' ' . $model->title; 11 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Files'), 'url' => ['index']]; 12 | $this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; 13 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_form', [ 20 | 'model' => $model, 21 | ]) ?> 22 | 23 |
24 | -------------------------------------------------------------------------------- /views/post/update.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Update {modelClass}: ', [ 9 | 'modelClass' => Yii::t('app','Post'), 10 | ]) . ' ' . $model->title; 11 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Posts'), 'url' => ['index']]; 12 | $this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; 13 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_form', [ 20 | 'model' => $model, 21 | ]) ?> 22 | 23 |
24 | -------------------------------------------------------------------------------- /assets/flowplayer/example/style.css: -------------------------------------------------------------------------------- 1 | 2 | body { 3 | background-color:#fff; 4 | font-family:"Lucida Grande","bitstream vera sans","trebuchet ms",verdana,arial; 5 | text-align:center; 6 | } 7 | 8 | #page { 9 | background-color:#efefef; 10 | width:600px; 11 | margin:50px auto; 12 | padding:20px 150px 20px 50px; 13 | min-height:600px; 14 | border:2px solid #fff; 15 | outline:1px solid #ccc; 16 | text-align:left; 17 | } 18 | 19 | h1, h2 { 20 | letter-spacing:-1px; 21 | color:#2D5AC3; 22 | font-weight:normal; 23 | margin-bottom:-10px; 24 | } 25 | 26 | h1 { 27 | font-size:22px; 28 | } 29 | 30 | h2 { 31 | font-size:18px; 32 | } 33 | 34 | .less { 35 | color:#999; 36 | font-size:12px; 37 | } 38 | 39 | a { 40 | color:#295c72; 41 | } 42 | -------------------------------------------------------------------------------- /views/banner/update.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Update {modelClass}: ', [ 9 | 'modelClass' => Yii::t('app','Banner'), 10 | ]) . ' ' . $model->title; 11 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Banners'), 'url' => ['index']]; 12 | $this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; 13 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); 14 | ?> 15 | 24 | -------------------------------------------------------------------------------- /migrations/m150411_164028_amilna_blog_static_script.php: -------------------------------------------------------------------------------- 1 | addColumn( $this->db->tablePrefix.'blog_static', 'scripts', Schema::TYPE_TEXT . '' ); 11 | } 12 | 13 | public function safeDown() 14 | { 15 | echo "m150411_164028_amilna_blog_static_script cannot be reverted.\n"; 16 | 17 | return false; 18 | } 19 | 20 | /* 21 | // Use safeUp/safeDown to run migration code within a transaction 22 | public function safeUp() 23 | { 24 | } 25 | 26 | public function safeDown() 27 | { 28 | } 29 | */ 30 | } 31 | -------------------------------------------------------------------------------- /views/gallery/update.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Update {modelClass}: ', [ 9 | 'modelClass' => Yii::t('app','Gallery'), 10 | ]) . ' ' . $model->title; 11 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Galleries'), 'url' => ['index']]; 12 | $this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; 13 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); 14 | ?> 15 | 24 | -------------------------------------------------------------------------------- /views/category/update.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Update {modelClass}: ', [ 9 | 'modelClass' => Yii::t('app','Category'), 10 | ]) . ' ' . $model->title; 11 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Categories'), 'url' => ['index']]; 12 | $this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; 13 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_form', [ 20 | 'model' => $model, 21 | ]) ?> 22 | 23 |
24 | -------------------------------------------------------------------------------- /views/page/update.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Update {modelClass}: ', [ 9 | 'modelClass' => Yii::t('app','Static Page'), 10 | ]) . ' ' . $model->title; 11 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Static Pages'), 'url' => ['index']]; 12 | $this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; 13 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_form', [ 20 | 'model' => $model, 21 | ]) ?> 22 | 23 |
24 | -------------------------------------------------------------------------------- /migrations/m150330_225351_amilna_blog_banner_imageonly.php: -------------------------------------------------------------------------------- 1 | addColumn( $this->db->tablePrefix.'blog_banner', 'image_only', Schema::TYPE_BOOLEAN.' NOT NULL DEFAULT FALSE' ); 11 | } 12 | 13 | public function safeDown() 14 | { 15 | echo "m150330_225351_amilna_blog_banner_imageonly cannot be reverted.\n"; 16 | 17 | return false; 18 | } 19 | 20 | /* 21 | // Use safeUp/safeDown to run migration code within a transaction 22 | public function safeUp() 23 | { 24 | } 25 | 26 | public function safeDown() 27 | { 28 | } 29 | */ 30 | } 31 | -------------------------------------------------------------------------------- /npm-debug.log: -------------------------------------------------------------------------------- 1 | 0 info it worked if it ends with ok 2 | 1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'test' ] 3 | 2 info using npm@1.4.28 4 | 3 info using node@v0.10.32 5 | 4 error Error: ENOENT, open '/home/iyo/www/yii2/advanced/vendor/amilna/yii2-blog/package.json' 6 | 5 error If you need help, you may report this *entire* log, 7 | 5 error including the npm and node versions, at: 8 | 5 error 9 | 6 error System Linux 3.16.0-4-amd64 10 | 7 error command "/usr/local/bin/node" "/usr/local/bin/npm" "test" 11 | 8 error cwd /home/iyo/www/yii2/advanced/vendor/amilna/yii2-blog 12 | 9 error node -v v0.10.32 13 | 10 error npm -v 1.4.28 14 | 11 error path /home/iyo/www/yii2/advanced/vendor/amilna/yii2-blog/package.json 15 | 12 error code ENOENT 16 | 13 error errno 34 17 | 14 verbose exit [ 34, true ] 18 | -------------------------------------------------------------------------------- /views/file/_itemIndex.php: -------------------------------------------------------------------------------- 1 | getModule('blog'); 9 | ?> 10 | 11 |
12 | 13 |
14 |
15 |

title,$model->file,["target"=>"blank"]) ?>

16 |
time))) ?>
17 | 18 |

description) ?>

19 |

20 | file,['class'=>'btn btn-small btn-default',"target"=>"blank"]) ?> 21 |

22 |
23 |
24 |
25 | 26 |
'; 30 | } 31 | 32 | if (($index+1) % 4 == 0) 33 | { 34 | echo '
'; 35 | } 36 | ?> 37 | -------------------------------------------------------------------------------- /views/category/_search.php: -------------------------------------------------------------------------------- 1 | 10 | 11 | 40 | -------------------------------------------------------------------------------- /views/file/_search.php: -------------------------------------------------------------------------------- 1 | 10 | 11 | 42 | -------------------------------------------------------------------------------- /views/page/_search.php: -------------------------------------------------------------------------------- 1 | 10 | 11 | 42 | -------------------------------------------------------------------------------- /views/page/view.php: -------------------------------------------------------------------------------- 1 | title = $model->title; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | 15 | ?> 16 |
17 | 28 | content ?> 29 | 35 |
36 | 37 | 42 | registerJs($this->blocks['STATIC_SCRIPTS'], yii\web\View::POS_END); 45 | -------------------------------------------------------------------------------- /views/file/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Files'); 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Blog'), 'url' => ['/blog/default']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | 15 | $dataProvider->pagination = [ 16 | 'pageSize'=> 12, 17 | ]; 18 | ?> 19 |
20 | 21 |

title) ?>

22 | render('_search', ['model' => $searchModel]); ?> 23 | 24 | $dataProvider, 26 | 'itemOptions' => ['class' => 'col-md-3 col-sm-4 item','tag'=>'div'], 27 | //'summary'=>Yii::t('app','List of account codes where increase on receipt or revenues'), 28 | 'itemView'=>'_itemIndex', 29 | 'options' => ['class' => 'row text-center list-view'], 30 | 'layout'=>"{items}\n{pager}", 31 | //'pager' => ['class' => \kop\y2sp\ScrollPager::className()], 32 | ]) ?> 33 | 34 |
35 | 36 | -------------------------------------------------------------------------------- /views/gallery/_search.php: -------------------------------------------------------------------------------- 1 | 10 | 11 | 44 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "amilna/yii2-blog", 3 | "description": "Blogging module support for Yii2", 4 | "type": "yii2-extension", 5 | "keywords": ["yii2","extension","blog"], 6 | "license": "BSD-3-Clause", 7 | "authors": [ 8 | { 9 | "name": "Satrio Arditama", 10 | "email": "iyo@amilna.com" 11 | } 12 | ], 13 | "minimum-stability": "dev", 14 | "prefer-stable": true, 15 | "require": { 16 | "yiisoft/yii2": "*", 17 | "kartik-v/yii2-mpdf": "*", 18 | "kartik-v/yii2-widgets": "*", 19 | "kartik-v/yii2-date-range": "*", 20 | "kartik-v/yii2-grid": "*", 21 | "vova07/yii2-imperavi-widget": "dev-master", 22 | "himiklab/yii2-colorbox-widget" : "*", 23 | "iutbay/yii2-fontawesome": "*", 24 | "iutbay/yii2-kcfinder" : "dev-master", 25 | "amilna/yii2-yap": "dev-master", 26 | "kop/yii2-scroll-pager": "dev-master" 27 | }, 28 | "repositories":[ 29 | { 30 | "type": "vcs", 31 | "url": "https://github.com/aaiyo/yii2-kcfinder" 32 | }, 33 | { 34 | "type": "vcs", 35 | "url": "https://github.com/aaiyo/yii2-imperavi-widget" 36 | } 37 | ], 38 | "autoload": { 39 | "psr-4": { 40 | "amilna\\blog\\": "" 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /views/post/index.php: -------------------------------------------------------------------------------- 1 | title = (!empty($_GET["category"])?$_GET["category"]:Yii::t('app', 'Posts')); 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Blog'), 'url' => ['/blog/default']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | 15 | $dataProvider->pagination = [ 16 | 'pageSize'=> 12, 17 | ]; 18 | ?> 19 |
20 | 21 |

title) ?>

22 | render('_search', ['model' => $searchModel]); ?> 23 | 24 | $dataProvider, 26 | 'itemOptions' => ['class' => 'col-md-4 col-sm-6 item','tag'=>'div'], 27 | //'summary'=>Yii::t('app','List of account codes where increase on receipt or revenues'), 28 | 'itemView'=>'_itemIndex', 29 | 'options' => ['class' => 'row text-center list-view'], 30 | 'layout'=>"{items}
{pager}", 31 | //'pager' => ['class' => \kop\y2sp\ScrollPager::className()], 32 | ]) ?> 33 | 34 |
35 | 36 | -------------------------------------------------------------------------------- /views/file/view.php: -------------------------------------------------------------------------------- 1 | title = $model->title; 10 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Files'), 'url' => ['index']]; 11 | $this->params['breadcrumbs'][] = $this->title; 12 | ?> 13 |
14 | 15 |

title) ?>

16 | 17 |

18 | $model->id], ['class' => 'btn btn-primary']) ?> 19 | $model->id], [ 20 | 'class' => 'btn btn-danger', 21 | 'data' => [ 22 | 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), 23 | 'method' => 'post', 24 | ], 25 | ]) ?> 26 |

27 | 28 | $model, 30 | 'attributes' => [ 31 | 'id', 32 | 'title', 33 | 'description', 34 | 'file:ntext', 35 | 'tags', 36 | 'status:boolean', 37 | 'time', 38 | 'isdel', 39 | ], 40 | ]) ?> 41 | 42 |
43 | -------------------------------------------------------------------------------- /views/banner/_search.php: -------------------------------------------------------------------------------- 1 | 10 | 11 | 48 | -------------------------------------------------------------------------------- /views/post/_search.php: -------------------------------------------------------------------------------- 1 | 10 | 11 |
12 | 13 | ['index'], 15 | 'method' => 'get', 16 | ]); ?> 17 | 18 | field($model, 'id') ?> 19 | 20 | field($model, 'title') ?> 21 | 22 | field($model, 'description') ?> 23 | 24 | field($model, 'content') ?> 25 | 26 | field($model, 'tags') ?> 27 | 28 | field($model, 'image') ?> 29 | 30 | field($model, 'author_id') ?> 31 | 32 | field($model, 'isfeatured')->checkbox() ?> 33 | 34 | field($model, 'status') ?> 35 | 36 | field($model, 'time') ?> 37 | 38 | field($model, 'isdel') ?> 39 | 40 |
41 | 'btn btn-primary']) ?> 42 | 'btn btn-default']) ?> 43 |
44 | 45 | 46 | 47 |
48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Blog for Yii 2 | ============ 3 | Blogging module support for Yii2 (includes banner and gallery, support mysql and postgresql) 4 | 5 | Installation 6 | ------------ 7 | 8 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). 9 | 10 | Since this package do not have stable release on packagist, you should use these settings in your composer.json file : 11 | 12 | ```json 13 | "minimum-stability": "dev", 14 | "prefer-stable": true, 15 | "repositories":[ 16 | 17 | { 18 | "type": "vcs", 19 | "url": "https://github.com/aaiyo/yii2-kcfinder" 20 | } 21 | ] 22 | ``` 23 | After, either run 24 | 25 | ``` 26 | php composer.phar require --prefer-dist amilna/yii2-blog "dev-master" 27 | ``` 28 | 29 | or add 30 | 31 | ``` 32 | "amilna/yii2-blog": "dev-master" 33 | ``` 34 | 35 | to the require section of your `composer.json` file. 36 | 37 | run migration for database 38 | 39 | ``` 40 | ./yii migrate --migrationPath=@amilna/blog/migrations 41 | ``` 42 | 43 | add in modules section of main config 44 | 45 | ``` 46 | 'gridview' => [ 47 | 'class' => 'kartik\grid\Module', 48 | ], 49 | 'blog' => [ 50 | 'class' => 'amilna\blog\Module', 51 | /* 'userClass' => 'dektrium\user\models\User', // example if use another user class */ 52 | ], 53 | ``` 54 | 55 | Usage 56 | ----- 57 | 58 | Once the extension is installed, check the url: 59 | [your application base url]/index.php/blog 60 | 61 | 62 | -------------------------------------------------------------------------------- /assets/gdd/index.php: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 13 | */ ?> 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 |
24 | 25 | 26 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /views/category/view.php: -------------------------------------------------------------------------------- 1 | title = $model->title; 10 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Categories'), 'url' => ['index']]; 11 | $this->params['breadcrumbs'][] = $this->title; 12 | 13 | $module = Yii::$app->getModule('blog'); 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 |

20 | $model->id], ['class' => 'btn btn-primary']) ?> 21 | $model->id], [ 22 | 'class' => 'btn btn-danger', 23 | 'data' => [ 24 | 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), 25 | 'method' => 'post', 26 | ], 27 | ]) ?> 28 |

29 | 30 | $model, 32 | 'attributes' => [ 33 | 'id', 34 | 'title', 35 | 'parent_id', 36 | 'description:ntext', 37 | [ 38 | 'attribute'=>'image', 39 | 'format'=>'html', 40 | 'value'=>(!empty($model->image)?(Html::img(str_replace("/".$module->uploadDir."/","/".$module->uploadDir."/.thumbs/",$model->image))):''), 41 | ], 42 | 'status:boolean', 43 | //'isdel', 44 | ], 45 | ]) ?> 46 | 47 |
48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, amilna 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of amilna nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /controllers/DefaultController.php: -------------------------------------------------------------------------------- 1 | render('index'); 15 | } 16 | 17 | public function actions() 18 | { 19 | $module = Yii::$app->getModule('blog'); 20 | $url = Yii::getAlias($module->uploadURL); 21 | $path = Yii::getAlias($module->uploadDir); 22 | 23 | return [ 24 | 'image-upload' => [ 25 | 'class' => 'vova07\imperavi\actions\UploadAction', 26 | 'url' => $url.'/images', // Directory URL address, where files are stored. 27 | 'path' => $path.'/images' // Or absolute path to directory where files are stored. 28 | ], 29 | 'images-get' => [ 30 | 'class' => 'vova07\imperavi\actions\GetAction', 31 | 'url' => $url.'/images', // Directory URL address, where files are stored. 32 | 'path' => $path.'/images', // Or absolute path to directory where files are stored. 33 | 'type' => GetAction::TYPE_IMAGES, 34 | ], 35 | 'file-upload' => [ 36 | 'class' => 'vova07\imperavi\actions\UploadAction', 37 | 'url' => $url.'/files', // Directory URL address, where files are stored. 38 | 'path' => $path.'/files' // Or absolute path to directory where files are stored. 39 | ], 40 | 'files-get' => [ 41 | 'class' => 'vova07\imperavi\actions\GetAction', 42 | 'url' => $url.'/files', // Directory URL address, where files are stored. 43 | 'path' => $path.'/files', // Or absolute path to directory where files are stored. 44 | 'type' => GetAction::TYPE_FILES, 45 | ], 46 | 47 | ]; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /migrations/m150311_000744_amilna_blog_static.php: -------------------------------------------------------------------------------- 1 | createTable($this->db->tablePrefix.'blog_static', [ 11 | 'id' => 'pk', 12 | 'title' => Schema::TYPE_STRING . '(65) NOT NULL', 13 | 'description' => Schema::TYPE_STRING . '(155) NOT NULL', 14 | 'content' => Schema::TYPE_TEXT . ' NOT NULL', 15 | 'tags' => Schema::TYPE_STRING . '', 16 | 'status' => Schema::TYPE_SMALLINT. ' NOT NULL DEFAULT 1', 17 | 'time' => Schema::TYPE_TIMESTAMP. ' NOT NULL DEFAULT NOW()', 18 | 'isdel' => Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0', 19 | ]); 20 | 21 | $this->createTable($this->db->tablePrefix.'blog_files', [ 22 | 'id' => 'pk', 23 | 'title' => Schema::TYPE_STRING . '(65) NOT NULL', 24 | 'description' => Schema::TYPE_STRING . '(155) NOT NULL', 25 | 'file' => Schema::TYPE_TEXT . ' NOT NULL', 26 | 'tags' => Schema::TYPE_STRING . '', 27 | 'status' => Schema::TYPE_BOOLEAN.' NOT NULL DEFAULT TRUE', 28 | 'time' => Schema::TYPE_TIMESTAMP. ' NOT NULL DEFAULT NOW()', 29 | 'isdel' => Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0', 30 | ]); 31 | } 32 | 33 | public function down() 34 | { 35 | echo "m150311_000744_amilna_blog_static cannot be reverted.\n"; 36 | 37 | return false; 38 | } 39 | 40 | /* 41 | // Use safeUp/safeDown to run migration code within a transaction 42 | public function safeUp() 43 | { 44 | } 45 | 46 | public function safeDown() 47 | { 48 | } 49 | */ 50 | } 51 | -------------------------------------------------------------------------------- /views/banner/view.php: -------------------------------------------------------------------------------- 1 | title = $model->title; 10 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Banners'), 'url' => ['index']]; 11 | $this->params['breadcrumbs'][] = $this->title; 12 | 13 | $module = Yii::$app->getModule('blog'); 14 | ?> 15 | 20 | 63 | -------------------------------------------------------------------------------- /views/post/_itemIndex.php: -------------------------------------------------------------------------------- 1 | getModule('blog'); 9 | ?> 10 | 11 |
12 | 13 |
uploadURL."/",$module->uploadURL."/.thumbs/",$model->image)."')":"")?>" > 14 | image != null) 16 | { 17 | //echo Html::tag("div","",["style"=>'height:100%;width:100px;background-size:cover;background-image:url("'.str_replace($module->uploadURL."/",$module->uploadURL."/.thumbs/",$model->image).'")']); 18 | /*?> 19 | uploadURL."/.thumbs/",$model->image) ?>" alt="title ?>" style="float:left;padding: 0 5px 5px 0;"> 20 | 23 |
;background:#ffffff;padding:20px;"> 24 |

title,["//blog/post/view","id"=>$model->id,"title"=>$model->title]) ?>

25 |
author?$model->author->username:"") ?> time))) ?>
26 | 27 |

description) ?>

28 |

29 | $model->id,"title"=>$model->title],['class'=>'btn btn-small btn-default']) ?> 30 |

31 |
32 |
33 |
34 | 35 |
'; 39 | } 40 | if (($index+1) % 3 == 0) 41 | { 42 | echo '
'; 43 | } 44 | ?> 45 | -------------------------------------------------------------------------------- /views/gallery/view.php: -------------------------------------------------------------------------------- 1 | title = $model->title; 10 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Galleries'), 'url' => ['index']]; 11 | $this->params['breadcrumbs'][] = $this->title; 12 | 13 | if ($model->type == 1) 14 | { 15 | \amilna\blog\assets\FlowAsset::register($this); 16 | } 17 | ?> 18 | 69 | -------------------------------------------------------------------------------- /assets/flowplayer/example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Minimal Flowplayer setup 17 | 18 | 19 | 20 |
21 | 22 |

Minimal Flowplayer setup

23 | 24 |

View commented source code to get familiar with Flowplayer installation.

25 | 26 | 27 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | 44 | 45 |

46 | If you are running these examples locally and not on some webserver you must edit your 47 | 48 | Flash security settings. 49 |

50 | 51 |

52 | Select "Edit locations" > "Add location" > "Browse for files" and select 53 | flowplayer-x.x.x.swf you just downloaded. 54 |

55 | 56 | 57 |

Documentation

58 | 59 |

60 | Flowplayer installation 61 |

62 | 63 |

64 | Flowplayer configuration 65 |

66 | 67 |

68 | See this identical page on Flowplayer website 69 |

70 | 71 |
72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /views/default/index.php: -------------------------------------------------------------------------------- 1 | 6 |
7 | 8 |
9 |

Yii2 Extensions for Blogging

10 |

Congratulations!

11 | 12 | 13 |

You have successfully installed Blog extension for your Yii-powered application.

14 | 15 |

"btn btn-lg btn-success"])?>

16 |
17 | 18 |
19 | 20 |
21 |
22 |

Post

23 | 24 |

Discrete entries of written work, especially with regard to its style or quality, typically displayed in reverse chronological order (the most recent post appears first).

25 | 26 |

"btn btn-primary"])?> 27 | "btn btn-warning"])?>

28 |
29 |
30 |

Gallery

31 | 32 |

Page that acts like a room or building for the display of works of art (especially images).

33 | 34 |

"btn btn-primary"])?> 35 | "btn btn-warning"])?>

36 |
37 |
38 |

Banner

39 | 40 |

Manage heading or advertisement appearing on a web page in the form of a bar, column, or box.

41 | 42 |

"btn btn-primary"])?>

43 |
44 |
45 |
46 |
47 |

Pages

48 | 49 |

Static pages, very usefull for site information or company profiles.

50 | 51 |

"btn btn-primary"])?>

52 |
53 |
54 |

File

55 | 56 |

Manage files that available to be downloaded by users.

57 | 58 |

"btn btn-primary"])?>

59 |
60 |
61 | 62 |
63 |
64 | -------------------------------------------------------------------------------- /assets/gdd/jquery.flash.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | jquery.flash v1.3.1 - 02/01/10 3 | (c)2009 Stephen Belanger - MIT/GPL. 4 | http://docs.jquery.com/License 5 | */ 6 | Array.prototype.indexOf=function(o,i){for(var j=this.length,i=i<0?i+j<0?0:i+j:i||0;i';}var p=navigator.plugins;if(p&&p.length){var f=p['Shockwave Flash'];if(f){has=true;if(f.description)cv=f.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split(".");}if(p['Shockwave Flash 2.0']){has=true;cv='2.0.0.11';}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");cv=[6,0,21];has=true;}catch(e){};try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){};}if(axo!=null){cv=axo.GetVariable("$version").split(" ")[1].split(",");has=true;ie=true;}}$(this).each(function(){if(has){var e=$(this),s=$.extend({'id':e.attr('id'),'class':e.attr('class'),'width':e.width(),'height':e.height(),'src':e.attr('href'),'classid':'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000','pluginspace':'http://get.adobe.com/flashplayer','availattrs':['id','class','width','height','src'],'availparams':['src','bgcolor','quality','allowscriptaccess','allowfullscreen','flashvars','wmode'],'version':'9.0.24'},opt),a=s.availattrs,b=s.availparams,rv=s.version.split('.'),o='parseInt(rv[i])){break;}if(parseInt(cv[i])';for(k in b){var n=(k==b.indexOf('src'))?'movie':b[k];o+=s[b[k]]?param(n,s[b[k]]):'';};o+='';e.replaceWith(o);}return this;});}}); 7 | // jQuery-typing 8 | // 9 | // Version: 0.2.0 10 | // Website: http://narf.pl/jquery-typing/ 11 | // License: public domain 12 | // Author: Maciej Konieczny 13 | (function(f){function l(g,h){function d(a){if(!e){e=true;c.start&&c.start(a,b)}}function i(a,j){if(e){clearTimeout(k);k=setTimeout(function(){e=false;c.stop&&c.stop(a,b)},j>=0?j:c.delay)}}var c=f.extend({start:null,stop:null,delay:400},h),b=f(g),e=false,k;b.keypress(d);b.keydown(function(a){if(a.keyCode===8||a.keyCode===46)d(a)});b.keyup(i);b.blur(function(a){i(a,0)})}f.fn.typing=function(g){return this.each(function(h,d){l(d,g)})}})(jQuery); -------------------------------------------------------------------------------- /models/BlogCatPos.php: -------------------------------------------------------------------------------- 1 | dynTableName; 28 | } 29 | 30 | /** 31 | * @inheritdoc 32 | */ 33 | public function rules() 34 | { 35 | return [ 36 | [['category_id', 'post_id'], 'required'], 37 | [['category_id', 'post_id', 'isdel'], 'integer'] 38 | ]; 39 | } 40 | 41 | /** 42 | * @inheritdoc 43 | */ 44 | public function attributeLabels() 45 | { 46 | return [ 47 | 'category_id' => Yii::t('app', 'Category ID'), 48 | 'post_id' => Yii::t('app', 'Post ID'), 49 | 'isdel' => Yii::t('app', 'Isdel'), 50 | ]; 51 | } 52 | 53 | public function itemAlias($list,$item = false,$bykey = false) 54 | { 55 | $lists = [ 56 | /* example list of item alias for a field with name field 57 | 'afield'=>[ 58 | 0=>Yii::t('app','an alias of 0'), 59 | 1=>Yii::t('app','an alias of 1'), 60 | ], 61 | */ 62 | ]; 63 | 64 | if (isset($lists[$list])) 65 | { 66 | if ($bykey) 67 | { 68 | $nlist = []; 69 | foreach ($lists[$list] as $k=>$i) 70 | { 71 | $nlist[$i] = $k; 72 | } 73 | $list = $nlist; 74 | } 75 | else 76 | { 77 | $list = $lists[$list]; 78 | } 79 | 80 | if ($item !== false) 81 | { 82 | return (isset($list[$item])?$list[$item]:false); 83 | } 84 | else 85 | { 86 | return $list; 87 | } 88 | } 89 | else 90 | { 91 | return false; 92 | } 93 | } 94 | 95 | 96 | /** 97 | * @return \yii\db\ActiveQuery 98 | */ 99 | public function getCategory() 100 | { 101 | return $this->hasOne(Category::className(), ['id' => 'category_id']); 102 | } 103 | 104 | /** 105 | * @return \yii\db\ActiveQuery 106 | */ 107 | public function getPost() 108 | { 109 | return $this->hasOne(Post::className(), ['id' => 'post_id']); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /views/gallery/index.php: -------------------------------------------------------------------------------- 1 | request->queryParams; 16 | 17 | $this->title = Yii::t('app', 'Galleries'); 18 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Blog'), 'url' => ['/blog/default']]; 19 | if (isset($req["GallerySearch"]["tag"])) 20 | { 21 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Galleries'), 'url' => ['/blog/gallery']]; 22 | $this->title = ucwords($req["GallerySearch"]["tag"]); 23 | } 24 | $this->params['breadcrumbs'][] = $this->title; 25 | 26 | $this->params['cboxTarget'] = []; 27 | $module = Yii::$app->getModule('blog'); 28 | 29 | ?> 30 | 36 | 37 | 72 | 73 | $this->params['cboxTarget'], 75 | 'coreStyle' => 1 76 | ]) ?> 77 | -------------------------------------------------------------------------------- /models/File.php: -------------------------------------------------------------------------------- 1 | dynTableName; 31 | } 32 | 33 | /** 34 | * @inheritdoc 35 | */ 36 | public function rules() 37 | { 38 | return [ 39 | [['title', 'description', 'file'], 'required'], 40 | [['file'], 'string'], 41 | [['status'], 'boolean'], 42 | [['isdel'], 'integer'], 43 | [['tags','time'], 'safe'], 44 | [['title'], 'string', 'max' => 65], 45 | [['description'], 'string', 'max' => 155], 46 | ['title', 'match', 'pattern' => '/^[a-zA-Z0-9 \-\(\)]+$/', 'message' => 'Title can only contain alphanumeric characters, spaces and dashes.'], 47 | //[['tags'], 'string', 'max' => 255] 48 | ]; 49 | } 50 | 51 | /** 52 | * @inheritdoc 53 | */ 54 | public function attributeLabels() 55 | { 56 | return [ 57 | 'id' => Yii::t('app', 'ID'), 58 | 'title' => Yii::t('app', 'Title'), 59 | 'description' => Yii::t('app', 'Description'), 60 | 'file' => Yii::t('app', 'File'), 61 | 'tags' => Yii::t('app', 'Tags'), 62 | 'status' => Yii::t('app', 'Status'), 63 | 'time' => Yii::t('app', 'Time'), 64 | 'isdel' => Yii::t('app', 'Isdel'), 65 | ]; 66 | } 67 | 68 | public function itemAlias($list,$item = false,$bykey = false) 69 | { 70 | $lists = [ 71 | /* example list of item alias for a field with name field */ 72 | 73 | 'status'=>[ 74 | 0=>Yii::t('app','No'), 75 | 1=>Yii::t('app','Yes'), 76 | ], 77 | ]; 78 | 79 | if (isset($lists[$list])) 80 | { 81 | if ($bykey) 82 | { 83 | $nlist = []; 84 | foreach ($lists[$list] as $k=>$i) 85 | { 86 | $nlist[$i] = $k; 87 | } 88 | $list = $nlist; 89 | } 90 | else 91 | { 92 | $list = $lists[$list]; 93 | } 94 | 95 | if ($item !== false) 96 | { 97 | return (isset($list[$item])?$list[$item]:false); 98 | } 99 | else 100 | { 101 | return $list; 102 | } 103 | } 104 | else 105 | { 106 | return false; 107 | } 108 | } 109 | 110 | public function getTags() 111 | { 112 | $models = $this->find()->all(); 113 | $tags = []; 114 | foreach ($models as $m) 115 | { 116 | $ts = explode(",",$m->tags); 117 | foreach ($ts as $t) 118 | { 119 | if (!in_array($t,$tags)) 120 | { 121 | $tags[$t] = $t; 122 | } 123 | } 124 | } 125 | return $tags; 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /models/StaticPage.php: -------------------------------------------------------------------------------- 1 | dynTableName; 30 | } 31 | 32 | /** 33 | * @inheritdoc 34 | */ 35 | public function rules() 36 | { 37 | return [ 38 | [['title', 'description', 'content' ,'status'], 'required'], 39 | [['content','scripts'], 'string'], 40 | [['status', 'isdel'], 'integer'], 41 | [['tags', 'time'], 'safe'], 42 | [['title'], 'string', 'max' => 65], 43 | [['description'], 'string', 'max' => 155], 44 | ['title', 'match', 'pattern' => '/^[a-zA-Z0-9 \-\(\)]+$/', 'message' => 'Title can only contain alphanumeric characters, spaces and dashes.'], 45 | //[['tags'], 'string', 'max' => 255] 46 | ]; 47 | } 48 | 49 | /** 50 | * @inheritdoc 51 | */ 52 | public function attributeLabels() 53 | { 54 | return [ 55 | 'id' => Yii::t('app', 'ID'), 56 | 'title' => Yii::t('app', 'Title'), 57 | 'description' => Yii::t('app', 'Description'), 58 | 'content' => Yii::t('app', 'Content'), 59 | 'tags' => Yii::t('app', 'Tags'), 60 | 'status' => Yii::t('app', 'Status'), 61 | 'scripts' => Yii::t('app', 'Scripts'), 62 | 'time' => Yii::t('app', 'Time'), 63 | 'isdel' => Yii::t('app', 'Isdel'), 64 | ]; 65 | } 66 | 67 | public function itemAlias($list,$item = false,$bykey = false) 68 | { 69 | $lists = [ 70 | /* example list of item alias for a field with name field */ 71 | 'status'=>[ 72 | 0=>Yii::t('app','Draft'), 73 | 1=>Yii::t('app','Published'), 74 | 2=>Yii::t('app','Archived'), 75 | ], 76 | 77 | ]; 78 | 79 | if (isset($lists[$list])) 80 | { 81 | if ($bykey) 82 | { 83 | $nlist = []; 84 | foreach ($lists[$list] as $k=>$i) 85 | { 86 | $nlist[$i] = $k; 87 | } 88 | $list = $nlist; 89 | } 90 | else 91 | { 92 | $list = $lists[$list]; 93 | } 94 | 95 | if ($item !== false) 96 | { 97 | return (isset($list[$item])?$list[$item]:false); 98 | } 99 | else 100 | { 101 | return $list; 102 | } 103 | } 104 | else 105 | { 106 | return false; 107 | } 108 | } 109 | 110 | public function getTags() 111 | { 112 | $models = $this->find()->all(); 113 | $tags = []; 114 | foreach ($models as $m) 115 | { 116 | $ts = explode(",",$m->tags); 117 | foreach ($ts as $t) 118 | { 119 | if (!in_array($t,$tags)) 120 | { 121 | $tags[$t] = $t; 122 | } 123 | } 124 | } 125 | return $tags; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /models/Gallery.php: -------------------------------------------------------------------------------- 1 | dynTableName; 31 | } 32 | 33 | /** 34 | * @inheritdoc 35 | */ 36 | public function rules() 37 | { 38 | return [ 39 | [['title', 'description', 'image', 'type'], 'required'], 40 | [['url'], 'string'], 41 | [['status'], 'boolean'], 42 | [['type', 'isdel'], 'integer'], 43 | [['tags','time'], 'safe'], 44 | [['title'], 'string', 'max' => 65], 45 | [['description'], 'string', 'max' => 155], 46 | //[['tags'], 'string', 'max' => 255] 47 | ]; 48 | } 49 | 50 | /** 51 | * @inheritdoc 52 | */ 53 | public function attributeLabels() 54 | { 55 | return [ 56 | 'id' => Yii::t('app', 'ID'), 57 | 'title' => Yii::t('app', 'Title'), 58 | 'description' => Yii::t('app', 'Description'), 59 | 'image' => Yii::t('app', 'Image'), 60 | 'url' => Yii::t('app', 'Url'), 61 | 'tags' => Yii::t('app', 'Tags'), 62 | 'status' => Yii::t('app', 'Enable'), 63 | 'type' => Yii::t('app', 'Type'), 64 | 'time' => Yii::t('app', 'Time'), 65 | 'isdel' => Yii::t('app', 'Isdel'), 66 | ]; 67 | } 68 | 69 | public function itemAlias($list,$item = false,$bykey = false) 70 | { 71 | $lists = [ 72 | /* example list of item alias for a field with name field */ 73 | 'type'=>[ 74 | 0=>Yii::t('app','Image'), 75 | 1=>Yii::t('app','Movie'), 76 | ], 77 | 'status'=>[ 78 | 0=>Yii::t('app','No'), 79 | 1=>Yii::t('app','Yes'), 80 | ], 81 | 82 | ]; 83 | 84 | if (isset($lists[$list])) 85 | { 86 | if ($bykey) 87 | { 88 | $nlist = []; 89 | foreach ($lists[$list] as $k=>$i) 90 | { 91 | $nlist[$i] = $k; 92 | } 93 | $list = $nlist; 94 | } 95 | else 96 | { 97 | $list = $lists[$list]; 98 | } 99 | 100 | if ($item !== false) 101 | { 102 | return (isset($list[$item])?$list[$item]:false); 103 | } 104 | else 105 | { 106 | return $list; 107 | } 108 | } 109 | else 110 | { 111 | return false; 112 | } 113 | } 114 | 115 | public function getTags() 116 | { 117 | $models = $this->find()->all(); 118 | $tags = []; 119 | foreach ($models as $m) 120 | { 121 | $ts = explode(",",$m->tags); 122 | foreach ($ts as $t) 123 | { 124 | if (!in_array($t,$tags)) 125 | { 126 | $tags[$t] = $t; 127 | } 128 | } 129 | } 130 | return $tags; 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /views/post/view.php: -------------------------------------------------------------------------------- 1 | title = $model->title; 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Posts'), 'url' => ['index']]; 14 | $this->params['breadcrumbs'][] = $this->title; 15 | 16 | $this->registerMetaTag(['name' => 'title', 'content' => Html::encode($model->title)]); 17 | $this->registerMetaTag(['name' => 'description', 'content' => Html::encode($model->description)]); 18 | 19 | $cat = new Category(); 20 | ?> 21 |
22 | 23 |

title) ?>

24 | 25 |
26 | 27 |
28 |
29 |
30 |

author?$model->author->username:"") ?> time)) ?>

31 |
32 |
33 | image != null) 35 | { 36 | echo Html::img($model->image,["style"=>"width:100%;margin-bottom:20px;","alt"=>$model->title]); 37 | } 38 | ?> 39 |
40 |
41 | content,[ 42 | 'HTML.SafeIframe'=>true, 43 | 'URI.SafeIframeRegexp'=>'%^http(s)?://(www.youtube.com/embed/|player.vimeo.com/video/|'.str_replace(['http://','https://'],'',Yii::getAlias('@web')).')%' 44 | ]) ?> 45 | 46 |
47 |
48 |
49 | 50 | 51 |
52 | 54 | $model->id], ['class' => 'btn btn-primary']) ?> 55 | $model->id], [ 56 | 'class' => 'btn btn-danger', 57 | 'data' => [ 58 | 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'), 59 | 'method' => 'post', 60 | ], 61 | ]) ?> 62 |

63 | */ ?> 64 |

65 | 66 |
" method="get"> 67 |
68 | 69 | 70 | 71 | 72 |
73 |
74 |
75 |

76 |
    77 | getRecent() as $m) 79 | { 80 | echo '
  • '.Html::a($m->title,["//blog/post/view","id"=>$m->id,"title"=>$m->title]).'
  • '; 81 | } 82 | ?> 83 |
84 |
85 |

86 | 94 |
95 |

96 | 104 |
105 | 106 |
107 | 108 |
109 | -------------------------------------------------------------------------------- /views/gallery/_itemTag.php: -------------------------------------------------------------------------------- 1 | getModule('blog'); 11 | 12 | $this->params['cboxTarget']['.gallery_colorbox'] = [ 13 | 'maxWidth' => 800, 14 | 'maxHeight' => 600, 15 | 'rel'=>'gallery_colorbox', 16 | 'slideshow'=>true 17 | ]; 18 | 19 | $this->params['cboxTarget']['.hgallery_colorbox'] = [ 20 | 'maxWidth' => 800, 21 | 'maxHeight' => 600, 22 | 'rel'=>'hgallery_colorbox', 23 | 'slideshow'=>true 24 | ]; 25 | 26 | $gdd = Yii::$app->assetManager->getPublishedUrl((new \amilna\blog\assets\FlowAsset)->sourcePath); 27 | 28 | if ($model["type"] == 1 ) 29 | { 30 | $this->params['cboxTarget']['.gallery_colorbox'.$model["id"]] = [ 31 | 'innerWidth' => 640, 32 | 'innerHeight' => 390, 33 | //'rel'=>'gallery_colorbox'.$model["id"], 34 | //'slideshow'=>false, 35 | 'iframe' => true 36 | ]; 37 | 38 | $this->params['cboxTarget']['.hgallery_colorbox'.$model["id"]] = [ 39 | 'innerWidth' => 640, 40 | 'innerHeight' => 390, 41 | //'rel'=>'hgallery_colorbox'.$model["id"], 42 | //'slideshow'=>false, 43 | 'iframe' => true 44 | ]; 45 | 46 | } 47 | 48 | 49 | ?> 50 | 51 |
52 |
53 | (-1) ) 55 | { 56 | $class = 'gallery_colorbox'.($model["type"] == 1?$model["id"]:""); 57 | $imgclass = "col-xs-12"; 58 | 59 | 60 | if ($model["type"] == 1) 61 | { 62 | $model["url"] = (substr($model["url"],0,4) == "http"?$model["url"]:$gdd."?url=".$model["url"]."&image=".$model['data'][0]."&auto=true"); 63 | } 64 | 65 | $url = ($model["type"] == 1?$model["url"]:$model['data'][0]); 66 | $durl = $url; 67 | } 68 | else 69 | { 70 | $class = ""; 71 | $imgclass = "col-xs-6"; 72 | $durl= ["//blog/gallery/index","tag"=>strtolower($model['title'])]; 73 | $url = Yii::$app->urlManager->createUrl($durl); 74 | } 75 | ?> 76 | 77 | "; 81 | echo Html::img(str_replace($module->uploadURL."/",$module->uploadURL."/.thumbs/",$model['data'][0]),['class'=>$imgclass]); 82 | } 83 | else 84 | { 85 | $n = 0; 86 | foreach ($model['data'] as $data) 87 | { 88 | $n += 1; 89 | echo Html::img(str_replace($module->uploadURL."/",$module->uploadURL."/.thumbs/",$data),['class'=>$imgclass]); 90 | } 91 | } 92 | ?> 93 | 94 |
95 | 96 |
97 |

':''?> 'h'.$class]) ?>

98 |
":"") ?> 99 | 100 |
101 |
102 |
103 | 104 |
'; 108 | } 109 | 110 | if (($index+1) % 3 == 0) 111 | { 112 | echo '
'; 113 | } 114 | ?> 115 | -------------------------------------------------------------------------------- /views/category/_form.php: -------------------------------------------------------------------------------- 1 | getModule('blog'); 16 | 17 | if ($module->enableUpload) 18 | { 19 | // kcfinder options 20 | // http://kcfinder.sunhater.com/install#dynamic 21 | $kcfOptions = array_merge([], [ 22 | 'uploadURL' => Yii::getAlias($module->uploadURL), 23 | 'uploadDir' => Yii::getAlias($module->uploadDir), 24 | 'access' => [ 25 | 'files' => [ 26 | 'upload' => true, 27 | 'delete' => false, 28 | 'copy' => false, 29 | 'move' => false, 30 | 'rename' => false, 31 | ], 32 | 'dirs' => [ 33 | 'create' => true, 34 | 'delete' => false, 35 | 'rename' => false, 36 | ], 37 | ], 38 | 'types'=>[ 39 | 'files' => "", 40 | 'images' => "*img", 41 | ], 42 | 'thumbWidth' => 260, 43 | 'thumbHeight' => 260, 44 | ]); 45 | 46 | // Set kcfinder session options 47 | Yii::$app->session->set('KCFINDER', $kcfOptions); 48 | 49 | } 50 | 51 | /* @var $this yii\web\View */ 52 | /* @var $model amilna\blog\models\Category */ 53 | /* @var $form yii\widgets\ActiveForm */ 54 | 55 | $listParent = []+ArrayHelper::map(($model->isNewRecord?$model->parents():$model->parents($model->id)), 'id', 'title'); 56 | ?> 57 | 58 |
59 | 60 | 61 | 62 |
63 |
64 | 65 |
66 |
67 | field($model, 'title')->textInput(['maxlength' => 65,'placeholder'=>Yii::t('app','Title contain a seo keyword if possible')]) ?> 68 |
69 |
70 | field($model, 'status')->widget(SwitchInput::classname(), [ 71 | 'type' => SwitchInput::CHECKBOX, 72 | ]); 73 | ?> 74 |
75 |
76 | 77 | field($model, 'description')->textArea(['maxlength' => 155,'placeholder'=>Yii::t('app','This description also used as meta description')]) ?> 78 | 79 |
80 | 81 |
82 | field($model, 'parent_id')->widget(Select2::classname(), [ 83 | 'model'=>$model, 84 | 'attribute'=>'parent_id', 85 | 'data' => $listParent, 86 | 'options' => ['placeholder' => Yii::t('app','Select a account parent...')], 87 | 'pluginOptions' => [ 88 | 'allowClear' => true 89 | ], 90 | 'pluginEvents' => [ 91 | "change" => 'function() { 92 | }', 93 | ], 94 | ]);?> 95 | 96 | enableUpload) 98 | { 99 | echo $form->field($model, 'image')->widget(KCFinderInputWidget::className(), [ 100 | 'multiple' => false, 101 | 'kcfOptions'=>$kcfOptions, 102 | 'kcfBrowseOptions'=>[ 103 | 'type'=>'images', 104 | 'lng'=>substr(Yii::$app->language,0,2), 105 | ] 106 | ]); 107 | } 108 | else 109 | { 110 | echo $form->field($model, 'image')->textInput(['placeholder'=>Yii::t('app','Url of image')]); 111 | } 112 | ?> 113 | 114 | field($model, 'type')->textInput() */ 116 | ?> 117 |
118 |
119 | 120 | 121 |
122 | isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 123 |
124 | 125 | 126 | 127 |
128 | -------------------------------------------------------------------------------- /models/Category.php: -------------------------------------------------------------------------------- 1 | dynTableName; 34 | } 35 | 36 | /** 37 | * @inheritdoc 38 | */ 39 | public function rules() 40 | { 41 | return [ 42 | [['title', 'description'], 'required'], 43 | [['parent_id', 'isdel'], 'integer'], 44 | [['description'], 'string'], 45 | [['status'], 'boolean'], 46 | [['title'], 'string', 'max' => 65], 47 | [['image'], 'string', 'max' => 255], 48 | [['title'], 'unique'], 49 | ['title', 'match', 'pattern' => '/^[a-zA-Z0-9 \-\(\)]+$/', 'message' => 'Title can only contain alphanumeric characters, spaces and dashes.'], 50 | ]; 51 | } 52 | 53 | /** 54 | * @inheritdoc 55 | */ 56 | public function attributeLabels() 57 | { 58 | return [ 59 | 'id' => Yii::t('app', 'ID'), 60 | 'title' => Yii::t('app', 'Title'), 61 | 'parent_id' => Yii::t('app', 'Parent ID'), 62 | 'description' => Yii::t('app', 'Description'), 63 | 'image' => Yii::t('app', 'Image'), 64 | 'status' => Yii::t('app', 'Status'), 65 | 'isdel' => Yii::t('app', 'Isdel'), 66 | ]; 67 | } 68 | 69 | public function itemAlias($list,$item = false,$bykey = false) 70 | { 71 | $lists = [ 72 | /* example list of item alias for a field with name field 73 | 'afield'=>[ 74 | 0=>Yii::t('app','an alias of 0'), 75 | 1=>Yii::t('app','an alias of 1'), 76 | ], 77 | */ 78 | ]; 79 | 80 | if (isset($lists[$list])) 81 | { 82 | if ($bykey) 83 | { 84 | $nlist = []; 85 | foreach ($lists[$list] as $k=>$i) 86 | { 87 | $nlist[$i] = $k; 88 | } 89 | $list = $nlist; 90 | } 91 | else 92 | { 93 | $list = $lists[$list]; 94 | } 95 | 96 | if ($item !== false) 97 | { 98 | return (isset($list[$item])?$list[$item]:false); 99 | } 100 | else 101 | { 102 | return $list; 103 | } 104 | } 105 | else 106 | { 107 | return false; 108 | } 109 | } 110 | 111 | 112 | /** 113 | * @return \yii\db\ActiveQuery 114 | */ 115 | public function getBlogCatPos() 116 | { 117 | return $this->hasMany(BlogCatPos::className(), ['category_id' => 'id']); 118 | } 119 | 120 | /** 121 | * @return \yii\db\ActiveQuery 122 | */ 123 | public function getParent() 124 | { 125 | return $this->hasOne(Category::className(), ['id' => 'parent_id']); 126 | } 127 | 128 | /** 129 | * @return \yii\db\ActiveQuery 130 | */ 131 | public function getCategories() 132 | { 133 | return $this->hasMany(Category::className(), ['parent_id' => 'id']); 134 | } 135 | 136 | public function parents($id = false) 137 | { 138 | return $this->findBySql("SELECT id,title FROM ".$this->tableName().($id?" WHERE id != :id and status=true":" WHERE status=true")." order by title",($id?['id'=>$id]:[]))->all(); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /views/gallery/_itemAll.php: -------------------------------------------------------------------------------- 1 | getModule('blog'); 11 | 12 | $this->params['cboxTarget']['.gallery_colorbox'] = [ 13 | 'maxWidth' => 800, 14 | 'maxHeight' => 600, 15 | 'rel'=>'gallery_colorbox', 16 | 'slideshow'=>true 17 | ]; 18 | 19 | $this->params['cboxTarget']['.hgallery_colorbox'] = [ 20 | 'maxWidth' => 800, 21 | 'maxHeight' => 600, 22 | 'rel'=>'hgallery_colorbox', 23 | 'slideshow'=>true 24 | ]; 25 | 26 | $gdd = Yii::$app->assetManager->getPublishedUrl((new \amilna\blog\assets\FlowAsset)->sourcePath); 27 | 28 | if ($model["type"] == 1 ) 29 | { 30 | $this->params['cboxTarget']['.gallery_colorbox'.$model["id"]] = [ 31 | 'innerWidth' => 640, 32 | 'innerHeight' => 390, 33 | //'rel'=>'gallery_colorbox'.$model["id"], 34 | //'slideshow'=>false, 35 | 'iframe' => true 36 | ]; 37 | 38 | $this->params['cboxTarget']['.hgallery_colorbox'.$model["id"]] = [ 39 | 'innerWidth' => 640, 40 | 'innerHeight' => 390, 41 | //'rel'=>'hgallery_colorbox'.$model["id"], 42 | //'slideshow'=>false, 43 | 'iframe' => true 44 | ]; 45 | 46 | } 47 | 48 | 49 | ?> 50 | 51 |
52 |
53 |
54 | 55 | (-1) ) 57 | { 58 | $class = 'gallery_colorbox'.($model["type"] == 1?$model["id"]:""); 59 | $imgclass = "col-xs-12 nopadding"; 60 | 61 | 62 | if ($model["type"] == 1) 63 | { 64 | $model["url"] = (substr($model["url"],0,4) == "http"?$model["url"]:$gdd."?url=".$model["url"]."&image=".$model['data'][0]."&auto=true"); 65 | } 66 | 67 | $url = ($model["type"] == 1?$model["url"]:$model['data'][0]); 68 | $durl = $url; 69 | } 70 | else 71 | { 72 | $class = ""; 73 | $imgclass = "nopadding col-xs-".(12/pow(2,(count($model['data'])-1)/max(1,(count($model['data'])-1)))); 74 | $durl= ["//blog/gallery/index","tag"=>strtolower($model['title'])]; 75 | $url = Yii::$app->urlManager->createUrl($durl); 76 | } 77 | ?> 78 | 79 | "; 83 | echo Html::img(str_replace($module->uploadURL."/",$module->uploadURL."/.thumbs/",$model['data'][0]),['class'=>$imgclass]); 84 | } 85 | else 86 | { 87 | $n = 0; 88 | foreach ($model['data'] as $data) 89 | { 90 | $n += 1; 91 | echo Html::img(str_replace($module->uploadURL."/",$module->uploadURL."/.thumbs/",$data),['class'=>$imgclass]); 92 | } 93 | } 94 | ?> 95 | 96 |
97 |
98 | 99 |
100 |

':''?> 'h'.$class]) ?>

101 |
":"") ?> 102 | 103 |
104 |
105 |
106 | 107 |
'; 111 | } 112 | 113 | if (($index+1) % 3 == 0) 114 | { 115 | echo '
'; 116 | } 117 | ?> 118 | -------------------------------------------------------------------------------- /views/file/_form.php: -------------------------------------------------------------------------------- 1 | getModule('blog'); 16 | 17 | if ($module->enableUpload) 18 | { 19 | // kcfinder options 20 | // http://kcfinder.sunhater.com/install#dynamic 21 | $kcfOptions = array_merge([], [ 22 | 'uploadURL' => Yii::getAlias($module->uploadURL), 23 | 'uploadDir' => Yii::getAlias($module->uploadDir), 24 | 'access' => [ 25 | 'files' => [ 26 | 'upload' => true, 27 | 'delete' => true, 28 | 'copy' => true, 29 | 'move' => true, 30 | 'rename' => true, 31 | ], 32 | 'dirs' => [ 33 | 'create' => true, 34 | 'delete' => true, 35 | 'rename' => true, 36 | ], 37 | ], 38 | 'types'=>[ 39 | 'files' => "", 40 | 'images' => "*img", 41 | 'videos' => "ogg flv mp4", 42 | ], 43 | 'thumbWidth' => 200, 44 | 'thumbHeight' => 200, 45 | ]); 46 | 47 | // Set kcfinder session options 48 | Yii::$app->session->set('KCFINDER', $kcfOptions); 49 | 50 | } 51 | /* @var $this yii\web\View */ 52 | /* @var $model amilna\blog\models\Gallery */ 53 | /* @var $form yii\widgets\ActiveForm */ 54 | ?> 55 | 56 | 136 | -------------------------------------------------------------------------------- /migrations/m150205_031747_amilna_blog.php: -------------------------------------------------------------------------------- 1 | createTable($this->db->tablePrefix.'blog_category', [ 11 | 'id' => 'pk', 12 | 'title' => Schema::TYPE_STRING . '(65) NOT NULL', 13 | 'parent_id' => Schema::TYPE_INTEGER, 14 | 'description' => Schema::TYPE_TEXT.' NOT NULL', 15 | 'image' => Schema::TYPE_STRING.'', 16 | 'status' => Schema::TYPE_BOOLEAN.' NOT NULL DEFAULT TRUE', 17 | 'isdel' => Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0', 18 | ]); 19 | $this->createIndex($this->db->tablePrefix.'blog_category_title'.'_key', $this->db->tablePrefix.'blog_category', 'title', true); 20 | $this->addForeignKey( $this->db->tablePrefix.'blog_category_parent_id', $this->db->tablePrefix.'blog_category', 'parent_id', $this->db->tablePrefix.'blog_category', 'id', 'SET NULL', null ); 21 | 22 | $this->createTable($this->db->tablePrefix.'blog_post', [ 23 | 'id' => 'pk', 24 | 'title' => Schema::TYPE_STRING . '(65) NOT NULL', 25 | 'description' => Schema::TYPE_STRING . '(155) NOT NULL', 26 | 'content' => Schema::TYPE_TEXT . ' NOT NULL', 27 | 'tags' => Schema::TYPE_STRING . '', 28 | 'image' => Schema::TYPE_TEXT . '', 29 | 'author_id' => Schema::TYPE_INTEGER, 30 | 'isfeatured' => Schema::TYPE_BOOLEAN.' NOT NULL DEFAULT TRUE', 31 | 'status' => Schema::TYPE_SMALLINT. ' NOT NULL DEFAULT 1', 32 | 'time' => Schema::TYPE_TIMESTAMP. ' NOT NULL DEFAULT NOW()', 33 | 'isdel' => Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0', 34 | ]); 35 | $this->addForeignKey( $this->db->tablePrefix.'blog_post_author_id', $this->db->tablePrefix.'blog_post', 'author_id', $this->db->tablePrefix.'user', 'id', 'SET NULL', null ); 36 | 37 | $this->createTable($this->db->tablePrefix.'blog_cat_pos', [ 38 | 'category_id' => Schema::TYPE_INTEGER. ' NOT NULL', 39 | 'post_id' => Schema::TYPE_INTEGER. ' NOT NULL', 40 | 'isdel' => Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0', 41 | ]); 42 | $this->addForeignKey( $this->db->tablePrefix.'blog_cat_pos_category_id', $this->db->tablePrefix.'blog_cat_pos', 'category_id', $this->db->tablePrefix.'blog_category', 'id', 'CASCADE', null ); 43 | $this->addForeignKey( $this->db->tablePrefix.'blog_cat_pos_post_id', $this->db->tablePrefix.'blog_cat_pos', 'post_id', $this->db->tablePrefix.'blog_post', 'id', 'CASCADE', null ); 44 | 45 | $this->createTable($this->db->tablePrefix.'blog_gallery', [ 46 | 'id' => 'pk', 47 | 'title' => Schema::TYPE_STRING . '(65) NOT NULL', 48 | 'description' => Schema::TYPE_STRING . '(155) NOT NULL', 49 | 'image' => Schema::TYPE_TEXT . ' NOT NULL', 50 | 'url' => Schema::TYPE_STRING . '', 51 | 'tags' => Schema::TYPE_STRING . '', 52 | 'status' => Schema::TYPE_BOOLEAN.' NOT NULL DEFAULT TRUE', 53 | 'type' => Schema::TYPE_SMALLINT. ' NOT NULL', 54 | 'time' => Schema::TYPE_TIMESTAMP. ' NOT NULL DEFAULT NOW()', 55 | 'isdel' => Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0', 56 | ]); 57 | 58 | $this->createTable($this->db->tablePrefix.'blog_banner', [ 59 | 'id' => 'pk', 60 | 'title' => Schema::TYPE_STRING . '(65) NOT NULL', 61 | 'description' => Schema::TYPE_STRING . '(155) NOT NULL', 62 | 'image' => Schema::TYPE_TEXT . ' NOT NULL', 63 | 'front_image' => Schema::TYPE_TEXT . '', 64 | 'tags' => Schema::TYPE_STRING . '', 65 | 'url' => Schema::TYPE_STRING . '', 66 | 'status' => Schema::TYPE_BOOLEAN.' NOT NULL DEFAULT TRUE', 67 | 'position' => Schema::TYPE_SMALLINT. ' NOT NULL DEFAULT 0', 68 | 'time' => Schema::TYPE_TIMESTAMP. ' NOT NULL DEFAULT NOW()', 69 | 'isdel' => Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0', 70 | ]); 71 | } 72 | 73 | public function down() 74 | { 75 | echo "m150205_031747_amilna_blog cannot be reverted.\n"; 76 | 77 | return false; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /views/category/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Categories'); 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Blog'), 'url' => ['/blog/default']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | 15 | $module = Yii::$app->getModule('blog'); 16 | ?> 17 |
18 | 19 |

title) ?>

20 | render('_search', ['model' => $searchModel]); ?> 21 | 22 | $dataProvider, 24 | 25 | 'containerOptions' => ['style'=>'overflow: auto'], // only set when $responsive = false 26 | //'caption'=>Yii::t('app', 'Category'), 27 | 'headerRowOptions'=>['class'=>'kartik-sheet-style','style'=>'background-color: #fdfdfd'], 28 | 'filterRowOptions'=>['class'=>'kartik-sheet-style skip-export','style'=>'background-color: #fdfdfd'], 29 | 'pjax' => true, 30 | 'bordered' => true, 31 | 'striped' => true, 32 | 'condensed' => true, 33 | 'responsive' => true, 34 | 'responsiveWrap' => false, 35 | 'hover' => true, 36 | 'showPageSummary' => true, 37 | 'pageSummaryRowOptions'=>['class'=>'kv-page-summary','style'=>'background-color: #fdfdfd'], 38 | 'tableOptions'=>["style"=>"margin-bottom:100px;"], 39 | 'panel' => [ 40 | 'type' => GridView::TYPE_DEFAULT, 41 | 'heading' => ' '.Yii::t('app', 'Category'), 42 | 'before'=>Html::a( 43 | ' '.Yii::t('app', 'Create'), 44 | ['create'], 45 | [ 'class' => 'btn btn-success', 46 | 'title'=>Yii::t('app', 'Create {modelClass}', [ 47 | 'modelClass' => Yii::t('app','Category'), 48 | ]) 49 | ] 50 | ).' '.Yii::t('app', 'Type in column input below to filter, or click column title to sort').'', 51 | ], 52 | 'toolbar' => [ 53 | ['content'=> 54 | Html::a('', ['index'], ['data-pjax'=>true, 'class' => 'btn btn-default', 'title'=>Yii::t('app', 'Reset Grid')]) 55 | ], 56 | '{export}', 57 | //'{toggleData}' 58 | ], 59 | 'beforeHeader'=>[ 60 | [ 61 | /* uncomment to use additional header 62 | 'columns'=>[ 63 | ['content'=>'Group 1', 'options'=>['colspan'=>6, 'class'=>'text-center','style'=>'background-color: #fdfdfd']], 64 | ['content'=>'Group 2', 'options'=>['colspan'=>6, 'class'=>'text-center','style'=>'background-color: #fdfdfd']], 65 | ], 66 | */ 67 | 'options'=>['class'=>'skip-export'] // remove this row from export 68 | ] 69 | ], 70 | 'floatHeader' => true, 71 | 'floatHeaderOptions'=>['position'=>'absolute','top'=>50], 72 | /*uncomment to use megeer some columns 73 | 'mergeColumns' => ['Column 1','Column 2','Column 3'], 74 | 'type'=>'firstrow', // or use 'simple' 75 | */ 76 | 77 | 'filterModel' => $searchModel, 78 | 'columns' => [ 79 | ['class' => 'kartik\grid\SerialColumn'], 80 | 81 | 'title', 82 | [ 83 | 'attribute'=>'parent_id', 84 | 'value'=>'parent.title', 85 | 'filterType'=>GridView::FILTER_SELECT2, 86 | 'filterWidgetOptions'=>[ 87 | 'data'=>ArrayHelper::map($searchModel->parents(),"id","title"), 88 | 'options' => ['placeholder' => Yii::t('app','Select a parent category...')], 89 | 'pluginOptions' => [ 90 | 'allowClear' => true 91 | ], 92 | 93 | ], 94 | ], 95 | 'description:ntext', 96 | [ 97 | 'attribute' => 'image', 98 | 'format'=>'html', 99 | 'value' => function($data) use ($module) { 100 | return ($data->image!= null?Html::img(str_replace("/".$module->uploadDir."/","/".$module->uploadDir."/.thumbs/",$data->image),['class'=>'pull-left','style'=>'margin:0 10px 10px 0']):''); 101 | }, 102 | ], 103 | // 'status:boolean', 104 | // 'isdel', 105 | 106 | ['class' => 'kartik\grid\ActionColumn'], 107 | ], 108 | ]); ?> 109 | 110 |
111 | -------------------------------------------------------------------------------- /views/file/admin.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Files'); 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Blog'), 'url' => ['/blog/default']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | render('_search', ['model' => $searchModel]); ?> 19 | 20 | $dataProvider, 22 | 23 | 'containerOptions' => ['style'=>'overflow: auto'], // only set when $responsive = false 24 | 'caption'=>Yii::t('app', 'File'), 25 | 'headerRowOptions'=>['class'=>'kartik-sheet-style','style'=>'background-color: #fdfdfd'], 26 | 'filterRowOptions'=>['class'=>'kartik-sheet-style skip-export','style'=>'background-color: #fdfdfd'], 27 | 'pjax' => true, 28 | 'bordered' => true, 29 | 'striped' => true, 30 | 'condensed' => true, 31 | 'responsive' => true, 32 | 'responsiveWrap' => false, 33 | 'hover' => true, 34 | 'showPageSummary' => true, 35 | 'pageSummaryRowOptions'=>['class'=>'kv-page-summary','style'=>'background-color: #fdfdfd'], 36 | 'tableOptions'=>["style"=>"margin-bottom:100px;"], 37 | 'panel' => [ 38 | 'type' => GridView::TYPE_DEFAULT, 39 | 'heading' => ' '.Yii::t('app', 'File'), 40 | 'before'=>Html::a( 41 | ' '.Yii::t('app', 'Create'), 42 | ['create'], 43 | [ 'class' => 'btn btn-success', 44 | 'title'=>Yii::t('app', 'Create {modelClass}', [ 45 | 'modelClass' => Yii::t('app','File'), 46 | ]) 47 | ] 48 | ).' '.Yii::t('app', 'Type in column input below to filter, or click column title to sort').'', 49 | ], 50 | 'toolbar' => [ 51 | ['content'=> 52 | Html::a('', ['admin'], ['data-pjax'=>true, 'class' => 'btn btn-default', 'title'=>Yii::t('app', 'Reset Grid')]) 53 | ], 54 | '{export}', 55 | //'{toggleData}' 56 | ], 57 | 'beforeHeader'=>[ 58 | [ 59 | /* uncomment to use additional header 60 | 'columns'=>[ 61 | ['content'=>'Group 1', 'options'=>['colspan'=>6, 'class'=>'text-center','style'=>'background-color: #fdfdfd']], 62 | ['content'=>'Group 2', 'options'=>['colspan'=>6, 'class'=>'text-center','style'=>'background-color: #fdfdfd']], 63 | ], 64 | */ 65 | 'options'=>['class'=>'skip-export'] // remove this row from export 66 | ] 67 | ], 68 | 'floatHeader' => true, 69 | 'floatHeaderOptions'=>['position'=>'absolute','top'=>50], 70 | /*uncomment to use megeer some columns 71 | 'mergeColumns' => ['Column 1','Column 2','Column 3'], 72 | 'type'=>'firstrow', // or use 'simple' 73 | */ 74 | 75 | 'filterModel' => $searchModel, 76 | 'columns' => [ 77 | ['class' => 'kartik\grid\SerialColumn'], 78 | 79 | //'id', 80 | 'title', 81 | 'description', 82 | 'tags', 83 | [ 84 | 'attribute'=>'status', 85 | 'value' => function($data){ 86 | return $data->itemAlias('status',$data->status?1:0); 87 | }, 88 | 'filterType'=>GridView::FILTER_SELECT2, 89 | 'filterWidgetOptions'=>[ 90 | 'data'=>$searchModel->itemAlias('status'), 91 | 'options' => ['placeholder' => Yii::t('app','Select a status type...')], 92 | 'pluginOptions' => [ 93 | 'allowClear' => true 94 | ], 95 | 96 | ], 97 | 98 | ], 99 | [ 100 | 'attribute' => 'file', 101 | 'format'=>'raw', 102 | 'value'=>function($data){ 103 | return Html::a(basename($data->file),$data->file,["class"=>"btn btn-xs btn-success btn-block","title"=>Yii::t("app","Click to download!"),"target"=>"blank"]); 104 | }, 105 | ], 106 | 107 | // 'time', 108 | // 'isdel', 109 | 110 | ['class' => 'kartik\grid\ActionColumn'], 111 | ], 112 | ]); ?> 113 | 114 |
115 | -------------------------------------------------------------------------------- /models/Post.php: -------------------------------------------------------------------------------- 1 | dynTableName; 37 | } 38 | /** 39 | * @inheritdoc 40 | */ 41 | public function rules() 42 | { 43 | return [ 44 | [['title', 'description', 'content','status'], 'required'], 45 | [['content', 'image'], 'string'], 46 | [['author_id', 'status', 'isdel'], 'integer'], 47 | [['isfeatured'], 'boolean'], 48 | [['tags','time'], 'safe'], 49 | [['title'], 'string', 'max' => 65], 50 | [['description'], 'string', 'max' => 155], 51 | ['title', 'match', 'pattern' => '/^[a-zA-Z0-9 \-\(\)]+$/', 'message' => 'Title can only contain alphanumeric characters, spaces and dashes.'], 52 | //[['tags'], 'string', 'max' => 255] 53 | ]; 54 | } 55 | 56 | /** 57 | * @inheritdoc 58 | */ 59 | public function attributeLabels() 60 | { 61 | return [ 62 | 'id' => Yii::t('app', 'ID'), 63 | 'title' => Yii::t('app', 'Title'), 64 | 'description' => Yii::t('app', 'Description'), 65 | 'content' => Yii::t('app', 'Content'), 66 | 'tags' => Yii::t('app', 'Tags'), 67 | 'image' => Yii::t('app', 'Image'), 68 | 'author_id' => Yii::t('app', 'Author ID'), 69 | 'isfeatured' => Yii::t('app', 'Featured'), 70 | 'status' => Yii::t('app', 'Status'), 71 | 'time' => Yii::t('app', 'Time'), 72 | 'isdel' => Yii::t('app', 'Isdel'), 73 | ]; 74 | } 75 | 76 | public function itemAlias($list,$item = false,$bykey = false) 77 | { 78 | $lists = [ 79 | /* example list of item alias for a field with name field */ 80 | 'status'=>[ 81 | 0=>Yii::t('app','Draft'), 82 | 1=>Yii::t('app','Published'), 83 | 2=>Yii::t('app','Archived'), 84 | ], 85 | 'isfeatured'=>[ 86 | false=>Yii::t('app','No'), 87 | true=>Yii::t('app','Featured'), 88 | ], 89 | 90 | ]; 91 | 92 | if (isset($lists[$list])) 93 | { 94 | if ($bykey) 95 | { 96 | $nlist = []; 97 | foreach ($lists[$list] as $k=>$i) 98 | { 99 | $nlist[$i] = $k; 100 | } 101 | $list = $nlist; 102 | } 103 | else 104 | { 105 | $list = $lists[$list]; 106 | } 107 | 108 | if ($item !== false) 109 | { 110 | return (isset($list[$item])?$list[$item]:false); 111 | } 112 | else 113 | { 114 | return $list; 115 | } 116 | } 117 | else 118 | { 119 | return false; 120 | } 121 | } 122 | 123 | 124 | /** 125 | * @return \yii\db\ActiveQuery 126 | */ 127 | public function getBlogCatPos() 128 | { 129 | return $this->hasMany(BlogCatPos::className(), ['post_id' => 'id'])->where("isdel=0"); 130 | } 131 | 132 | /** 133 | * @return \yii\db\ActiveQuery 134 | */ 135 | public function getAuthor() 136 | { 137 | $userClass = Yii::$app->getModule('blog')->userClass; 138 | return $this->hasOne($userClass::className(), ['id' => 'author_id']); 139 | } 140 | 141 | public function getTags() 142 | { 143 | $models = $this->find()->all(); 144 | $tags = []; 145 | foreach ($models as $m) 146 | { 147 | $ts = explode(",",$m->tags); 148 | foreach ($ts as $t) 149 | { 150 | if (!in_array($t,$tags)) 151 | { 152 | $tags[$t] = $t; 153 | } 154 | } 155 | } 156 | return $tags; 157 | } 158 | 159 | public function getRecent($limit = 5) 160 | { 161 | return PostSearch::find()->andWhere('status = 1')->orderBy('id desc')->limit($limit)->all(); 162 | } 163 | 164 | public function getArchived($limit = 6) 165 | { 166 | $res = $this->db->createCommand("SELECT 167 | substring(concat('',time) from 1 for 7) as month 168 | FROM ".$this->tableName()." as p 169 | WHERE isdel = 0 170 | GROUP BY month 171 | ORDER BY month desc 172 | LIMIT :limit") 173 | ->bindValues(["limit"=>$limit])->queryAll(); 174 | 175 | return ($res == null?[]:$res); 176 | } 177 | 178 | } 179 | -------------------------------------------------------------------------------- /views/page/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Static Pages'); 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Blog'), 'url' => ['/blog/default']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | render('_search', ['model' => $searchModel]); ?> 19 | 20 | $dataProvider, 22 | 23 | 'containerOptions' => ['style'=>'overflow: auto'], // only set when $responsive = false 24 | //'caption'=>Yii::t('app', 'Static Page'), 25 | 'headerRowOptions'=>['class'=>'kartik-sheet-style','style'=>'background-color: #fdfdfd'], 26 | 'filterRowOptions'=>['class'=>'kartik-sheet-style skip-export','style'=>'background-color: #fdfdfd'], 27 | 'pjax' => true, 28 | 'bordered' => true, 29 | 'striped' => true, 30 | 'condensed' => true, 31 | 'responsive' => true, 32 | 'responsiveWrap' => false, 33 | 'hover' => true, 34 | 'showPageSummary' => true, 35 | 'pageSummaryRowOptions'=>['class'=>'kv-page-summary','style'=>'background-color: #fdfdfd'], 36 | 'tableOptions'=>["style"=>"margin-bottom:100px;"], 37 | 'panel' => [ 38 | 'type' => GridView::TYPE_DEFAULT, 39 | 'heading' => ' '.Yii::t('app', 'Static Page'), 40 | 'before'=>Html::a( 41 | ' '.Yii::t('app', 'Create'), 42 | ['create'], 43 | [ 'class' => 'btn btn-success', 44 | 'title'=>Yii::t('app', 'Create {modelClass}', [ 45 | 'modelClass' => Yii::t('app','Static Page'), 46 | ]) 47 | ] 48 | ).' '.Yii::t('app', 'Type in column input below to filter, or click column title to sort').'', 49 | ], 50 | 'toolbar' => [ 51 | ['content'=> 52 | Html::a('', ['index'], ['data-pjax'=>true, 'class' => 'btn btn-default', 'title'=>Yii::t('app', 'Reset Grid')]) 53 | ], 54 | '{export}', 55 | //'{toggleData}' 56 | ], 57 | 'beforeHeader'=>[ 58 | [ 59 | /* uncomment to use additional header 60 | 'columns'=>[ 61 | ['content'=>'Group 1', 'options'=>['colspan'=>6, 'class'=>'text-center','style'=>'background-color: #fdfdfd']], 62 | ['content'=>'Group 2', 'options'=>['colspan'=>6, 'class'=>'text-center','style'=>'background-color: #fdfdfd']], 63 | ], 64 | */ 65 | 'options'=>['class'=>'skip-export'] // remove this row from export 66 | ] 67 | ], 68 | 'floatHeader' => true, 69 | 'floatHeaderOptions'=>['position'=>'absolute','top'=>50], 70 | /*uncomment to use megeer some columns 71 | 'mergeColumns' => ['Column 1','Column 2','Column 3'], 72 | 'type'=>'firstrow', // or use 'simple' 73 | */ 74 | 75 | 'filterModel' => $searchModel, 76 | 'columns' => [ 77 | ['class' => 'kartik\grid\SerialColumn'], 78 | 79 | [ 80 | 'attribute' => 'term', 81 | 'value' => 'title', 82 | ], 83 | 'description', 84 | //'content:ntext', 85 | 'tags', 86 | [ 87 | 'attribute' => 'time', 88 | 'value' => 'time', 89 | 'filterType'=>GridView::FILTER_DATE_RANGE, 90 | 'filterWidgetOptions'=>[ 91 | 'pluginOptions' => [ 92 | 'format' => 'YYYY-MM-DD HH:mm:ss', 93 | 'todayHighlight' => true, 94 | 'timePicker'=>true, 95 | 'timePickerIncrement'=>15, 96 | 'opens'=>'left' 97 | ], 98 | 'pluginEvents' => [ 99 | "apply.daterangepicker" => 'function() { 100 | $(this).change(); 101 | }', 102 | ], 103 | ], 104 | ], 105 | [ 106 | 'attribute'=>'status', 107 | 'value'=>function($data){ 108 | return $data->itemAlias('status',$data->status); 109 | }, 110 | 'filterType'=>GridView::FILTER_SELECT2, 111 | 'filterWidgetOptions'=>[ 112 | 'data'=>$searchModel->itemAlias('status'), 113 | 'options' => ['placeholder' => Yii::t('app','Filter by status...')], 114 | 'pluginOptions' => [ 115 | 'allowClear' => true 116 | ], 117 | 118 | ], 119 | ], 120 | // 'isdel', 121 | 122 | [ 123 | 'class' => 'kartik\grid\ActionColumn', 124 | 'buttons'=>[ 125 | 'view'=>function ($url, $model, $key) { 126 | return Html::a('',["view","id"=>$model->id,"title"=>$model->title],["title"=>Yii::t("yii","View")]); 127 | }, 128 | ] 129 | ], 130 | ], 131 | ]); ?> 132 | 133 |
134 | -------------------------------------------------------------------------------- /views/page/_form.php: -------------------------------------------------------------------------------- 1 | getModule('blog'); 16 | 17 | if ($module->enableUpload) 18 | { 19 | // kcfinder options 20 | // http://kcfinder.sunhater.com/install#dynamic 21 | $kcfOptions = array_merge([], [ 22 | 'uploadURL' => Yii::getAlias($module->uploadURL), 23 | 'uploadDir' => Yii::getAlias($module->uploadDir), 24 | 'access' => [ 25 | 'files' => [ 26 | 'upload' => true, 27 | 'delete' => false, 28 | 'copy' => false, 29 | 'move' => false, 30 | 'rename' => false, 31 | ], 32 | 'dirs' => [ 33 | 'create' => true, 34 | 'delete' => false, 35 | 'rename' => false, 36 | ], 37 | ], 38 | 'types'=>[ 39 | 'files' => "", 40 | 'images' => "*img", 41 | ], 42 | 'thumbWidth' => 260, 43 | 'thumbHeight' => 260, 44 | ]); 45 | 46 | // Set kcfinder session options 47 | Yii::$app->session->set('KCFINDER', $kcfOptions); 48 | } 49 | /* @var $this yii\web\View */ 50 | /* @var $model amilna\blog\models\Post */ 51 | /* @var $form yii\widgets\ActiveForm */ 52 | 53 | ?> 54 | 55 |
56 | 57 | 58 |
59 |
60 |
61 |
62 | field($model, 'title')->textInput(['maxlength' => 65,'placeholder'=>Yii::t('app','Title contain a seo keyword if possible')]) ?> 63 |
64 |
65 | field($model, 'description')->textArea(['maxlength' => 155,'placeholder'=>Yii::t('app','This description also used as meta description')]) ?> 66 | 67 | substr(Yii::$app->language,0,2), 70 | 'minHeight' => 400, 71 | 'toolbarFixedTopOffset'=>50, 72 | 'buttonSource'=> true, 73 | 'plugins' => [ 74 | 'imagemanager', 75 | 'filemanager', 76 | 'video', 77 | 'table', 78 | 'clips', 79 | 'fullscreen' 80 | ], 81 | 'buttons'=> ['html','formatting', 'bold', 'italic','underline','deleted', 'unorderedlist', 'orderedlist', 82 | 'outdent', 'indent', 'image', 'file', 'link', 'alignment', 'horizontalrule' 83 | ], 84 | 'replaceDivs'=> false, 85 | 'deniedTags'=> ['script'] 86 | ]; 87 | 88 | if ($module->enableUpload) 89 | { 90 | $isettings = array_merge($isettings,[ 91 | 'imageUpload' => Url::to(['//blog/default/image-upload']), 92 | 'fileUpload' => Url::to(['//blog/default/file-upload']), 93 | 'imageManagerJson' => Url::to(['//blog/default/images-get']), 94 | 'fileManagerJson' => Url::to(['//blog/default/files-get']), 95 | ]); 96 | } 97 | 98 | use vova07\imperavi\Widget; 99 | echo $form->field($model, 'content')->widget(Widget::className(), [ 100 | 'settings' => $isettings, 101 | 'options'=>["style"=>"width:100%"] 102 | ]); 103 | ?> 104 | 105 | enableScriptsPage) { ?> 106 | field($model, 'scripts')->textArea(['rows'=>6,'placeholder'=>Yii::t('app','JavaScripts')]) ?> 107 | 108 |
109 |
110 |
111 | field($model, 'time')->widget(DateTimePicker::classname(), [ 112 | 'options' => ['placeholder' => 'Select posting time ...','readonly'=>true], 113 | 'removeButton'=>false, 114 | 'convertFormat' => true, 115 | 'pluginOptions' => [ 116 | 'format' => 'yyyy-MM-dd HH:i:s', 117 | //'startDate' => '01-Mar-2014 12:00 AM', 118 | 'todayHighlight' => true, 119 | ] 120 | ]) 121 | ?> 122 | 123 | field($model, 'tags')->widget(Select2::classname(), [ 124 | 'options' => [ 125 | 'placeholder' => Yii::t('app','Put additional tags ...'), 126 | ], 127 | 'data'=>$model->getTags(), 128 | 'pluginOptions' => [ 129 | 'tags' => true, 130 | 'tokenSeparators'=>[','], 131 | ], 132 | ]) ?> 133 | 134 | field($model, 'status')->widget(Select2::classname(), [ 135 | 'data' => $model->itemAlias('status'), 136 | 'options' => ['placeholder' => Yii::t('app','Select post status...')], 137 | 'pluginOptions' => [ 138 | 'allowClear' => false 139 | ], 140 | 'pluginEvents' => [ 141 | ], 142 | ]); 143 | ?> 144 | 145 |
146 |
147 |
148 | 149 |
150 | isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 151 |
152 | 153 | 154 | 155 |
156 | -------------------------------------------------------------------------------- /models/Banner.php: -------------------------------------------------------------------------------- 1 | dynTableName; 33 | } 34 | 35 | /** 36 | * @inheritdoc 37 | */ 38 | public function rules() 39 | { 40 | return [ 41 | [['title', 'description', 'image'], 'required'], 42 | [['image', 'front_image'], 'string'], 43 | [['status','image_only'], 'boolean'], 44 | [['position', 'isdel'], 'integer'], 45 | [['tags','time'], 'safe'], 46 | [['title'], 'string', 'max' => 65], 47 | [['description'], 'string', 'max' => 155], 48 | [[ 'url'], 'string', 'max' => 255] 49 | ]; 50 | } 51 | 52 | /** 53 | * @inheritdoc 54 | */ 55 | public function attributeLabels() 56 | { 57 | return [ 58 | 'id' => Yii::t('app', 'ID'), 59 | 'title' => Yii::t('app', 'Title'), 60 | 'description' => Yii::t('app', 'Description'), 61 | 'image' => Yii::t('app', 'Image'), 62 | 'front_image' => Yii::t('app', 'Front Image'), 63 | 'tags' => Yii::t('app', 'Tags'), 64 | 'url' => Yii::t('app', 'Url'), 65 | 'status' => Yii::t('app', 'Status'), 66 | 'image_only' => Yii::t('app', 'Image Only'), 67 | 'position' => Yii::t('app', 'Position'), 68 | 'time' => Yii::t('app', 'Time'), 69 | 'isdel' => Yii::t('app', 'Isdel'), 70 | ]; 71 | } 72 | 73 | public function itemAlias($list,$item = false,$bykey = false) 74 | { 75 | $lists = [ 76 | /* example list of item alias for a field with name field */ 77 | 'status'=>[ 78 | 0=>Yii::t('app','No'), 79 | 1=>Yii::t('app','Yes'), 80 | ], 81 | 82 | ]; 83 | 84 | if (isset($lists[$list])) 85 | { 86 | if ($bykey) 87 | { 88 | $nlist = []; 89 | foreach ($lists[$list] as $k=>$i) 90 | { 91 | $nlist[$i] = $k; 92 | } 93 | $list = $nlist; 94 | } 95 | else 96 | { 97 | $list = $lists[$list]; 98 | } 99 | 100 | if ($item !== false) 101 | { 102 | return (isset($list[$item])?$list[$item]:false); 103 | } 104 | else 105 | { 106 | return $list; 107 | } 108 | } 109 | else 110 | { 111 | return false; 112 | } 113 | } 114 | 115 | public function getTags() 116 | { 117 | $models = Banner::find()->all(); 118 | $tags = []; 119 | foreach ($models as $m) 120 | { 121 | $ts = explode(",",$m->tags); 122 | foreach ($ts as $t) 123 | { 124 | if (!in_array($t,$tags)) 125 | { 126 | $tags[$t] = $t; 127 | } 128 | } 129 | } 130 | return $tags; 131 | } 132 | 133 | public function getLast() 134 | { 135 | $res = $this->db->createCommand("SELECT 136 | count(id) 137 | FROM ".Banner::tableName()." 138 | WHERE isdel = :isdel") 139 | ->bindValues(["isdel"=>0])->queryScalar(); 140 | 141 | return ($res == null?0:$res); 142 | } 143 | 144 | public function updatePosition($position) 145 | { 146 | 147 | $models = Banner::find()->where("id != :id",["id"=>$this->id])->orderBy("position")->all(); 148 | 149 | $pos = 0; 150 | $mis = false; 151 | $low = false; 152 | $up = false; 153 | $mod = "-"; 154 | $m = false; 155 | 156 | foreach ($models as $model) 157 | { 158 | $mis = ($mis === false && $model->position != $pos?$pos:$mis); 159 | $pos = $pos+1; 160 | $m = $model; 161 | } 162 | 163 | $alter = ($mis === false && $position > $pos?false:true); 164 | if ($m) { 165 | $mis = ($mis === false?$m->position+1:$mis); 166 | } 167 | 168 | $mod = ($position > $mis?"-":"+"); 169 | $low = ($position > $mis?$mis:$position); 170 | $up = ($position < $mis?$mis:$position+1); 171 | 172 | $res = true; 173 | if ($low !== false && $up !== false && $alter === true) 174 | { 175 | $res = $this->db->createCommand("UPDATE ".Banner::tableName()." 176 | SET position = (position".$mod."1) 177 | WHERE position >= :low AND position < :up AND id != :id") 178 | ->bindValues(["low"=>$low,"up"=>$up,"id"=>$this->id])->execute(); 179 | } 180 | return $res; 181 | } 182 | 183 | } 184 | -------------------------------------------------------------------------------- /controllers/CategoryController.php: -------------------------------------------------------------------------------- 1 | [ 21 | 'class' => VerbFilter::className(), 22 | 'actions' => [ 23 | 'delete' => ['post'], 24 | ], 25 | ], 26 | ]; 27 | } 28 | 29 | /** 30 | * Lists all Category models. 31 | * @params string $format, array $arraymap, string $term 32 | * @return mixed 33 | */ 34 | public function actionIndex($format= false,$arraymap= false,$term = false) 35 | { 36 | $searchModel = new CategorySearch(); 37 | $req = Yii::$app->request->queryParams; 38 | if ($term) { $req[basename(str_replace("\\","/",get_class($searchModel)))]["term"] = $term;} 39 | $dataProvider = $searchModel->search($req); 40 | 41 | if ($format == 'json') 42 | { 43 | $model = []; 44 | foreach ($dataProvider->getModels() as $d) 45 | { 46 | $obj = $d->attributes; 47 | if ($arraymap) 48 | { 49 | $map = explode(",",$arraymap); 50 | if (count($map) == 1) 51 | { 52 | $obj = (isset($d[$arraymap])?$d[$arraymap]:null); 53 | } 54 | else 55 | { 56 | $obj = []; 57 | foreach ($map as $a) 58 | { 59 | $k = explode(":",$a); 60 | $v = (count($k) > 1?$k[1]:$k[0]); 61 | $obj[$k[0]] = ($v == "Obj"?json_encode($d->attributes):(isset($d->$v)?$d->$v:null)); 62 | } 63 | } 64 | } 65 | 66 | if ($term) 67 | { 68 | if (!in_array($obj,$model)) 69 | { 70 | array_push($model,$obj); 71 | } 72 | } 73 | else 74 | { 75 | array_push($model,$obj); 76 | } 77 | } 78 | return \yii\helpers\Json::encode($model); 79 | } 80 | else 81 | { 82 | return $this->render('index', [ 83 | 'searchModel' => $searchModel, 84 | 'dataProvider' => $dataProvider, 85 | ]); 86 | } 87 | } 88 | 89 | /** 90 | * Displays a single Category model. 91 | * @param integer $id 92 | * @additionalParam string $format 93 | * @return mixed 94 | */ 95 | public function actionView($id,$format= false) 96 | { 97 | $model = $this->findModel($id); 98 | 99 | if ($format == 'json') 100 | { 101 | return \yii\helpers\Json::encode($model); 102 | } 103 | else 104 | { 105 | return $this->render('view', [ 106 | 'model' => $model, 107 | ]); 108 | } 109 | } 110 | 111 | /** 112 | * Creates a new Category model. 113 | * If creation is successful, the browser will be redirected to the 'view' page. 114 | * @return mixed 115 | */ 116 | public function actionCreate() 117 | { 118 | $model = new Category(); 119 | $model->isdel = 0; 120 | 121 | if ($model->load(Yii::$app->request->post()) && $model->save()) { 122 | return $this->redirect(['view', 'id' => $model->id]); 123 | } else { 124 | return $this->render('create', [ 125 | 'model' => $model, 126 | ]); 127 | } 128 | } 129 | 130 | /** 131 | * Updates an existing Category model. 132 | * If update is successful, the browser will be redirected to the 'view' page. 133 | * @param integer $id 134 | * @return mixed 135 | */ 136 | public function actionUpdate($id) 137 | { 138 | $model = $this->findModel($id); 139 | 140 | if ($model->load(Yii::$app->request->post()) && $model->save()) { 141 | return $this->redirect(['view', 'id' => $model->id]); 142 | } else { 143 | return $this->render('update', [ 144 | 'model' => $model, 145 | ]); 146 | } 147 | } 148 | 149 | /** 150 | * Deletes an existing Category model. 151 | * If deletion is successful, the browser will be redirected to the 'index' page. 152 | * @param integer $id 153 | * @return mixed 154 | */ 155 | public function actionDelete($id) 156 | { 157 | $model = $this->findModel($id); 158 | $model->isdel = 1; 159 | $model->save(); 160 | //$model->delete(); //this will true delete 161 | 162 | return $this->redirect(['index']); 163 | } 164 | 165 | /** 166 | * Finds the Category model based on its primary key value. 167 | * If the model is not found, a 404 HTTP exception will be thrown. 168 | * @param integer $id 169 | * @return Category the loaded model 170 | * @throws NotFoundHttpException if the model cannot be found 171 | */ 172 | protected function findModel($id) 173 | { 174 | if (($model = Category::findOne($id)) !== null) { 175 | return $model; 176 | } else { 177 | throw new NotFoundHttpException('The requested page does not exist.'); 178 | } 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /views/gallery/admin.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Galleries'); 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Blog'), 'url' => ['/blog/default']]; 14 | $this->params['breadcrumbs'][] = $this->title; 15 | 16 | $module = Yii::$app->getModule('blog'); 17 | ?> 18 | 23 | 24 | 154 | -------------------------------------------------------------------------------- /views/post/admin.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Posts'); 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Blog'), 'url' => ['/blog/default']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | render('_search', ['model' => $searchModel]); ?> 19 | 20 | $dataProvider, 22 | 23 | 'containerOptions' => ['style'=>'overflow: auto'], // only set when $responsive = false 24 | //'caption'=>Yii::t('app', 'Post'), 25 | 'headerRowOptions'=>['class'=>'kartik-sheet-style','style'=>'background-color: #fdfdfd'], 26 | 'filterRowOptions'=>['class'=>'kartik-sheet-style skip-export','style'=>'background-color: #fdfdfd'], 27 | 'pjax' => true, 28 | 'bordered' => true, 29 | 'striped' => true, 30 | 'condensed' => true, 31 | 'responsive' => true, 32 | 'responsiveWrap' => false, 33 | 'hover' => true, 34 | 'showPageSummary' => true, 35 | 'pageSummaryRowOptions'=>['class'=>'kv-page-summary','style'=>'background-color: #fdfdfd'], 36 | 'tableOptions'=>["style"=>"margin-bottom:100px;"], 37 | 'panel' => [ 38 | 'type' => GridView::TYPE_DEFAULT, 39 | 'heading' => ' '.Yii::t('app', 'Post'), 40 | 'before'=>Html::a( 41 | ' '.Yii::t('app', 'Create'), 42 | ['create'], 43 | [ 'class' => 'btn btn-success', 44 | 'title'=>Yii::t('app', 'Create {modelClass}', [ 45 | 'modelClass' => Yii::t('app','Post'), 46 | ]) 47 | ] 48 | ).' '.Yii::t('app', 'Type in column input below to filter, or click column title to sort').'', 49 | ], 50 | 'toolbar' => [ 51 | ['content'=> 52 | Html::a('', ['admin'], ['data-pjax'=>true, 'class' => 'btn btn-default', 'title'=>Yii::t('app', 'Reset Grid')]) 53 | ], 54 | '{export}', 55 | //'{toggleData}' 56 | ], 57 | 'beforeHeader'=>[ 58 | [ 59 | /* uncomment to use additional header 60 | 'columns'=>[ 61 | ['content'=>'Group 1', 'options'=>['colspan'=>6, 'class'=>'text-center','style'=>'background-color: #fdfdfd']], 62 | ['content'=>'Group 2', 'options'=>['colspan'=>6, 'class'=>'text-center','style'=>'background-color: #fdfdfd']], 63 | ], 64 | */ 65 | 'options'=>['class'=>'skip-export'] // remove this row from export 66 | ] 67 | ], 68 | 'floatHeader' => true, 69 | 'floatHeaderOptions'=>['position'=>'absolute','top'=>50], 70 | /*uncomment to use megeer some columns 71 | 'mergeColumns' => ['Column 1','Column 2','Column 3'], 72 | 'type'=>'firstrow', // or use 'simple' 73 | */ 74 | 75 | 'filterModel' => $searchModel, 76 | 'columns' => [ 77 | ['class' => 'kartik\grid\SerialColumn'], 78 | 79 | //'id', 80 | [ 81 | 'attribute' => 'term', 82 | 'value' => 'title', 83 | ], 84 | 'description', 85 | //'content:ntext', 86 | 'tags', 87 | [ 88 | 'attribute' => 'authorName', 89 | 'value' => 'author.username', 90 | ], 91 | [ 92 | 'attribute' => 'time', 93 | 'value' => 'time', 94 | 'filterType'=>GridView::FILTER_DATE_RANGE, 95 | 'filterWidgetOptions'=>[ 96 | 'pluginOptions' => [ 97 | 'format' => 'YYYY-MM-DD HH:mm:ss', 98 | 'todayHighlight' => true, 99 | 'timePicker'=>true, 100 | 'timePickerIncrement'=>15, 101 | 'opens'=>'left' 102 | ], 103 | 'pluginEvents' => [ 104 | "apply.daterangepicker" => 'function() { 105 | $(this).change(); 106 | }', 107 | ], 108 | ], 109 | ], 110 | [ 111 | 'attribute'=>'isfeatured', 112 | 'value'=>function($data){ 113 | return $data->itemAlias('isfeatured',$data->isfeatured?1:0); 114 | }, 115 | 'filterType'=>GridView::FILTER_SELECT2, 116 | 'filterWidgetOptions'=>[ 117 | 'data'=>$searchModel->itemAlias('isfeatured'), 118 | 'options' => ['placeholder' => Yii::t('app','Is Featured?')], 119 | 'pluginOptions' => [ 120 | 'allowClear' => true 121 | ], 122 | 123 | ], 124 | ], 125 | [ 126 | 'attribute'=>'status', 127 | 'value'=>function($data){ 128 | return $data->itemAlias('status',$data->status); 129 | }, 130 | 'filterType'=>GridView::FILTER_SELECT2, 131 | 'filterWidgetOptions'=>[ 132 | 'data'=>$searchModel->itemAlias('status'), 133 | 'options' => ['placeholder' => Yii::t('app','Filter by status...')], 134 | 'pluginOptions' => [ 135 | 'allowClear' => true 136 | ], 137 | 138 | ], 139 | ], 140 | // 'image:ntext', 141 | // 'author_id', 142 | 143 | 144 | 145 | // 'isdel', 146 | 147 | [ 148 | 'class' => 'kartik\grid\ActionColumn', 149 | 'buttons'=>[ 150 | 'view'=>function ($url, $model, $key) { 151 | return Html::a('',["view","id"=>$model->id,"title"=>$model->title],["title"=>Yii::t("yii","View")]); 152 | }, 153 | ] 154 | ], 155 | ], 156 | ]); ?> 157 | 158 |
159 | -------------------------------------------------------------------------------- /views/banner/_form.php: -------------------------------------------------------------------------------- 1 | getModule('blog'); 17 | if ($module->enableUpload) 18 | { 19 | // kcfinder options 20 | // http://kcfinder.sunhater.com/install#dynamic 21 | $kcfOptions = array_merge([], [ 22 | 'uploadURL' => Yii::getAlias($module->uploadURL), 23 | 'uploadDir' => Yii::getAlias($module->uploadDir), 24 | 'access' => [ 25 | 'files' => [ 26 | 'upload' => true, 27 | 'delete' => true, 28 | 'copy' => true, 29 | 'move' => true, 30 | 'rename' => true, 31 | ], 32 | 'dirs' => [ 33 | 'create' => true, 34 | 'delete' => true, 35 | 'rename' => true, 36 | ], 37 | ], 38 | 'types'=>[ 39 | 'files' => "", 40 | 'images' => "*img", 41 | ], 42 | 'thumbWidth' => 200, 43 | 'thumbHeight' => 200, 44 | ]); 45 | 46 | // Set kcfinder session options 47 | Yii::$app->session->set('KCFINDER', $kcfOptions); 48 | } 49 | 50 | /* @var $this yii\web\View */ 51 | /* @var $model amilna\blog\models\Banner */ 52 | /* @var $form yii\widgets\ActiveForm */ 53 | ?> 54 | 55 | 181 | -------------------------------------------------------------------------------- /models/CategorySearch.php: -------------------------------------------------------------------------------- 1 | where([Category::tableName().'.isdel' => 0]); 35 | } 36 | 37 | /** 38 | * @inheritdoc 39 | */ 40 | public function scenarios() 41 | { 42 | // bypass scenarios() implementation in the parent class 43 | return Model::scenarios(); 44 | } 45 | 46 | private function queryString($fields) 47 | { 48 | $params = []; 49 | foreach ($fields as $afield) 50 | { 51 | $field = $afield[0]; 52 | $tab = isset($afield[1])?$afield[1]:false; 53 | if (!empty($this->$field)) 54 | { 55 | if (substr($this->$field,0,2) == "< " || substr($this->$field,0,2) == "> " || substr($this->$field,0,2) == "<=" || substr($this->$field,0,2) == ">=" || substr($this->$field,0,2) == "<>") 56 | { 57 | array_push($params,[str_replace(" ","",substr($this->$field,0,2)), "lower(".($tab?$tab.".":"").$field.")", strtolower(trim(substr($this->$field,2)))]); 58 | } 59 | else 60 | { 61 | array_push($params,["like", "lower(".($tab?$tab.".":"").$field.")", strtolower($this->$field)]); 62 | } 63 | } 64 | } 65 | return $params; 66 | } 67 | 68 | private function queryNumber($fields) 69 | { 70 | $params = []; 71 | foreach ($fields as $afield) 72 | { 73 | $field = $afield[0]; 74 | $tab = isset($afield[1])?$afield[1]:false; 75 | if (!empty($this->$field)) 76 | { 77 | $number = explode(" ",trim($this->$field)); 78 | if (count($number) == 2) 79 | { 80 | if (in_array($number[0],['>','>=','<','<=','<>']) && is_numeric($number[1])) 81 | { 82 | array_push($params,[$number[0], ($tab?$tab.".":"").$field, $number[1]]); 83 | } 84 | } 85 | elseif (count($number) == 3) 86 | { 87 | if (is_numeric($number[0]) && is_numeric($number[2])) 88 | { 89 | array_push($params,['>=', ($tab?$tab.".":"").$field, $number[0]]); 90 | array_push($params,['<=', ($tab?$tab.".":"").$field, $number[2]]); 91 | } 92 | } 93 | elseif (count($number) == 1) 94 | { 95 | if (is_numeric($number[0])) 96 | { 97 | array_push($params,['=', ($tab?$tab.".":"").$field, str_replace(["<",">","="],"",$number[0])]); 98 | } 99 | } 100 | } 101 | } 102 | return $params; 103 | } 104 | 105 | private function queryTime($fields) 106 | { 107 | $params = []; 108 | foreach ($fields as $afield) 109 | { 110 | $field = $afield[0]; 111 | $tab = isset($afield[1])?$afield[1]:false; 112 | if (!empty($this->$field)) 113 | { 114 | $time = explode(" - ",$this->$field); 115 | if (count($time) > 1) 116 | { 117 | array_push($params,[">=", "concat('',".($tab?$tab.".":"").$field.")", $time[0]]); 118 | array_push($params,["<=", "concat('',".($tab?$tab.".":"").$field.")", $time[1]." 24:00:00"]); 119 | } 120 | else 121 | { 122 | if (substr($time[0],0,2) == "< " || substr($time[0],0,2) == "> " || substr($time[0],0,2) == "<=" || substr($time[0],0,2) == ">=" || substr($time[0],0,2) == "<>") 123 | { 124 | array_push($params,[str_replace(" ","",substr($time[0],0,2)), "concat('',".($tab?$tab.".":"").$field.")", trim(substr($time[0],2))]); 125 | } 126 | else 127 | { 128 | array_push($params,["like", "concat('',".($tab?$tab.".":"").$field.")", $time[0]]); 129 | } 130 | } 131 | } 132 | } 133 | return $params; 134 | } 135 | 136 | /** 137 | * Creates data provider instance with search query applied 138 | * 139 | * @param array $params 140 | * 141 | * @return ActiveDataProvider 142 | */ 143 | public function search($params) 144 | { 145 | $query = $this->find(); 146 | 147 | $query->joinWith([/*,blogcatpos,categories*/]); 148 | 149 | $dataProvider = new ActiveDataProvider([ 150 | 'query' => $query, 151 | ]); 152 | 153 | /* uncomment to sort by relations table on respective column 154 | $dataProvider->sort->attributes['blogcatposId'] = [ 155 | 'asc' => ['{{%blogcatpos}}.id' => SORT_ASC], 156 | 'desc' => ['{{%blogcatpos}}.id' => SORT_DESC], 157 | ]; 158 | $dataProvider->sort->attributes['categoriesId'] = [ 159 | 'asc' => ['{{%categories}}.id' => SORT_ASC], 160 | 'desc' => ['{{%categories}}.id' => SORT_DESC], 161 | ];*/ 162 | 163 | if (!($this->load($params) && $this->validate())) { 164 | return $dataProvider; 165 | } 166 | 167 | $params = self::queryNumber([['id',$this->tableName()],['parent_id'],['status'],['isdel']/*['id','{{%blogcatpos}}'],['id','{{%parent}}'],['id','{{%categories}}']*/]); 168 | foreach ($params as $p) 169 | { 170 | $query->andFilterWhere($p); 171 | } 172 | $params = self::queryString([['title'],['description'],['image']/*['id','{{%blogcatpos}}'],['id','{{%parent}}'],['id','{{%categories}}']*/]); 173 | foreach ($params as $p) 174 | { 175 | $query->andFilterWhere($p); 176 | } 177 | return $dataProvider; 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /models/FileSearch.php: -------------------------------------------------------------------------------- 1 | where([File::tableName().'.isdel' => 0]); 34 | } 35 | 36 | 37 | /** 38 | * @inheritdoc 39 | */ 40 | public function scenarios() 41 | { 42 | // bypass scenarios() implementation in the parent class 43 | return Model::scenarios(); 44 | } 45 | 46 | private function queryString($fields) 47 | { 48 | $params = []; 49 | foreach ($fields as $afield) 50 | { 51 | $field = $afield[0]; 52 | $tab = isset($afield[1])?$afield[1]:false; 53 | if (!empty($this->$field)) 54 | { 55 | if (substr($this->$field,0,2) == "< " || substr($this->$field,0,2) == "> " || substr($this->$field,0,2) == "<=" || substr($this->$field,0,2) == ">=" || substr($this->$field,0,2) == "<>") 56 | { 57 | array_push($params,[str_replace(" ","",substr($this->$field,0,2)), "lower(".($tab?$tab.".":"").$field.")", strtolower(trim(substr($this->$field,2)))]); 58 | } 59 | else 60 | { 61 | array_push($params,["like", "lower(".($tab?$tab.".":"").$field.")", strtolower($this->$field)]); 62 | } 63 | } 64 | } 65 | return $params; 66 | } 67 | 68 | private function queryNumber($fields) 69 | { 70 | $params = []; 71 | foreach ($fields as $afield) 72 | { 73 | $field = $afield[0]; 74 | $tab = isset($afield[1])?$afield[1]:false; 75 | if (!empty($this->$field)) 76 | { 77 | $number = explode(" ",trim($this->$field)); 78 | if (count($number) == 2) 79 | { 80 | if (in_array($number[0],['>','>=','<','<=','<>']) && is_numeric($number[1])) 81 | { 82 | array_push($params,[$number[0], ($tab?$tab.".":"").$field, $number[1]]); 83 | } 84 | } 85 | elseif (count($number) == 3) 86 | { 87 | if (is_numeric($number[0]) && is_numeric($number[2])) 88 | { 89 | array_push($params,['>=', ($tab?$tab.".":"").$field, $number[0]]); 90 | array_push($params,['<=', ($tab?$tab.".":"").$field, $number[2]]); 91 | } 92 | } 93 | elseif (count($number) == 1) 94 | { 95 | if (is_numeric($number[0])) 96 | { 97 | array_push($params,['=', ($tab?$tab.".":"").$field, str_replace(["<",">","="],"",$number[0])]); 98 | } 99 | } 100 | } 101 | } 102 | return $params; 103 | } 104 | 105 | private function queryTime($fields) 106 | { 107 | $params = []; 108 | foreach ($fields as $afield) 109 | { 110 | $field = $afield[0]; 111 | $tab = isset($afield[1])?$afield[1]:false; 112 | if (!empty($this->$field)) 113 | { 114 | $time = explode(" - ",$this->$field); 115 | if (count($time) > 1) 116 | { 117 | array_push($params,[">=", "concat('',".($tab?$tab.".":"").$field.")", $time[0]]); 118 | array_push($params,["<=", "concat('',".($tab?$tab.".":"").$field.")", $time[1]." 24:00:00"]); 119 | } 120 | else 121 | { 122 | if (substr($time[0],0,2) == "< " || substr($time[0],0,2) == "> " || substr($time[0],0,2) == "<=" || substr($time[0],0,2) == ">=" || substr($time[0],0,2) == "<>") 123 | { 124 | array_push($params,[str_replace(" ","",substr($time[0],0,2)), "concat('',".($tab?$tab.".":"").$field.")", trim(substr($time[0],2))]); 125 | } 126 | else 127 | { 128 | array_push($params,["like", "concat('',".($tab?$tab.".":"").$field.")", $time[0]]); 129 | } 130 | } 131 | } 132 | } 133 | return $params; 134 | } 135 | 136 | /** 137 | * Creates data provider instance with search query applied 138 | * 139 | * @param array $params 140 | * 141 | * @return ActiveDataProvider 142 | */ 143 | public function search($params) 144 | { 145 | $query = $this->find(); 146 | 147 | 148 | $query->joinWith([/**/]); 149 | 150 | $dataProvider = new ActiveDataProvider([ 151 | 'query' => $query, 152 | ]); 153 | 154 | /* uncomment to sort by relations table on respective column*/ 155 | 156 | if (!($this->load($params) && $this->validate())) { 157 | return $dataProvider; 158 | } 159 | 160 | $query->andFilterWhere([ 161 | 'status' => $this->status, 162 | /**/ 163 | ]); 164 | 165 | $params = self::queryNumber([['id',$this->tableName()],['isdel']]); 166 | foreach ($params as $p) 167 | { 168 | $query->andFilterWhere($p); 169 | } 170 | $params = self::queryString([['title'],['description'],['file'],['tags']]); 171 | foreach ($params as $p) 172 | { 173 | $query->andFilterWhere($p); 174 | } 175 | $params = self::queryTime([['time']]); 176 | foreach ($params as $p) 177 | { 178 | $query->andFilterWhere($p); 179 | } 180 | 181 | /* example to use search all in field1,field2,field3 or field4 182 | if ($this->term) 183 | { 184 | $query->andFilterWhere(["OR","lower(field1) like '%".strtolower($this->term)."%'", 185 | ["OR","lower(field2) like '%".strtolower($this->term)."%'", 186 | ["OR","lower(field3) like '%".strtolower($this->term)."%'", 187 | "lower(field4) like '%".strtolower($this->term)."%'" 188 | ] 189 | ] 190 | ]); 191 | } 192 | */ 193 | 194 | $query->andFilterWhere(["like","lower(concat(title,description,file))",strtolower($this->term)]); 195 | 196 | return $dataProvider; 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /controllers/PageController.php: -------------------------------------------------------------------------------- 1 | [ 21 | 'class' => VerbFilter::className(), 22 | 'actions' => [ 23 | 'delete' => ['post'], 24 | ], 25 | ], 26 | ]; 27 | } 28 | 29 | /** 30 | * Lists all StaticPage models. 31 | * @params string $format, array $arraymap, string $term 32 | * @return mixed 33 | */ 34 | public function actionIndex($format= false,$arraymap= false,$term = false) 35 | { 36 | $searchModel = new StaticPageSearch(); 37 | $req = Yii::$app->request->queryParams; 38 | if ($term) { $req[basename(str_replace("\\","/",get_class($searchModel)))]["term"] = $term;} 39 | $dataProvider = $searchModel->search($req); 40 | 41 | $query = $dataProvider->query; 42 | $query->andWhere(['status'=>[0,1,2]]); 43 | 44 | if ($format == 'json') 45 | { 46 | $model = []; 47 | foreach ($dataProvider->getModels() as $d) 48 | { 49 | $obj = $d->attributes; 50 | if ($arraymap) 51 | { 52 | $map = explode(",",$arraymap); 53 | if (count($map) == 1) 54 | { 55 | $obj = (isset($d[$arraymap])?$d[$arraymap]:null); 56 | } 57 | else 58 | { 59 | $obj = []; 60 | foreach ($map as $a) 61 | { 62 | $k = explode(":",$a); 63 | $v = (count($k) > 1?$k[1]:$k[0]); 64 | $obj[$k[0]] = ($v == "Obj"?json_encode($d->attributes):(isset($d->$v)?$d->$v:null)); 65 | } 66 | } 67 | } 68 | 69 | if ($term) 70 | { 71 | if (!in_array($obj,$model)) 72 | { 73 | array_push($model,$obj); 74 | } 75 | } 76 | else 77 | { 78 | array_push($model,$obj); 79 | } 80 | } 81 | return \yii\helpers\Json::encode($model); 82 | } 83 | else 84 | { 85 | return $this->render('index', [ 86 | 'searchModel' => $searchModel, 87 | 'dataProvider' => $dataProvider, 88 | ]); 89 | } 90 | } 91 | 92 | /** 93 | * Displays a single StaticPage model. 94 | * @param integer $id 95 | * @additionalParam string $format 96 | * @return mixed 97 | */ 98 | public function actionView($id,$format= false) 99 | { 100 | $model = $this->findModel($id); 101 | if ($model->status != 1) 102 | { 103 | return $this->redirect(['index']); 104 | } 105 | 106 | if ($format == 'json') 107 | { 108 | return \yii\helpers\Json::encode($model); 109 | } 110 | else 111 | { 112 | return $this->render('view', [ 113 | 'model' => $model, 114 | ]); 115 | } 116 | } 117 | 118 | /** 119 | * Creates a new StaticPage model. 120 | * If creation is successful, the browser will be redirected to the 'view' page. 121 | * @return mixed 122 | */ 123 | public function actionCreate() 124 | { 125 | $model = new StaticPage(); 126 | $model->time = date("Y-m-d H:i:s"); 127 | $model->isdel = 0; 128 | 129 | $post = Yii::$app->request->post(); 130 | if (isset($post['StaticPage']['tags'])) 131 | { 132 | if (is_array($post['StaticPage']['tags'])) 133 | { 134 | $post['StaticPage']['tags'] = implode(",",$post['StaticPage']['tags']); 135 | } 136 | } 137 | 138 | if ($model->load($post) && $model->save()) { 139 | return $this->redirect(['view', 'id' => $model->id]); 140 | } else { 141 | return $this->render('create', [ 142 | 'model' => $model, 143 | ]); 144 | } 145 | } 146 | 147 | /** 148 | * Updates an existing StaticPage model. 149 | * If update is successful, the browser will be redirected to the 'view' page. 150 | * @param integer $id 151 | * @return mixed 152 | */ 153 | public function actionUpdate($id) 154 | { 155 | $model = $this->findModel($id); 156 | $model->tags = !empty($model->tags)?explode(",",$model->tags):[]; 157 | 158 | $post = Yii::$app->request->post(); 159 | if (isset($post['StaticPage']['tags'])) 160 | { 161 | if (is_array($post['StaticPage']['tags'])) 162 | { 163 | $post['StaticPage']['tags'] = implode(",",$post['StaticPage']['tags']); 164 | } 165 | } 166 | 167 | if ($model->load($post) && $model->save()) { 168 | return $this->redirect(['view', 'id' => $model->id]); 169 | } else { 170 | return $this->render('update', [ 171 | 'model' => $model, 172 | ]); 173 | } 174 | } 175 | 176 | /** 177 | * Deletes an existing StaticPage model. 178 | * If deletion is successful, the browser will be redirected to the 'index' page. 179 | * @param integer $id 180 | * @return mixed 181 | */ 182 | public function actionDelete($id) 183 | { 184 | $model = $this->findModel($id); 185 | $model->isdel = 1; 186 | $model->save(); 187 | //$model->delete(); //this will true delete 188 | 189 | return $this->redirect(['index']); 190 | } 191 | 192 | /** 193 | * Finds the StaticPage model based on its primary key value. 194 | * If the model is not found, a 404 HTTP exception will be thrown. 195 | * @param integer $id 196 | * @return StaticPage the loaded model 197 | * @throws NotFoundHttpException if the model cannot be found 198 | */ 199 | protected function findModel($id) 200 | { 201 | if (($model = StaticPage::findOne($id)) !== null) { 202 | return $model; 203 | } else { 204 | throw new NotFoundHttpException('The requested page does not exist.'); 205 | } 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /views/post/_form.php: -------------------------------------------------------------------------------- 1 | getModule('blog'); 16 | if ($module->enableUpload) 17 | { 18 | // kcfinder options 19 | // http://kcfinder.sunhater.com/install#dynamic 20 | $kcfOptions = array_merge([], [ 21 | 'uploadURL' => Yii::getAlias($module->uploadURL), 22 | 'uploadDir' => Yii::getAlias($module->uploadDir), 23 | 'access' => [ 24 | 'files' => [ 25 | 'upload' => true, 26 | 'delete' => true, 27 | 'copy' => true, 28 | 'move' => true, 29 | 'rename' => true, 30 | ], 31 | 'dirs' => [ 32 | 'create' => true, 33 | 'delete' => true, 34 | 'rename' => true, 35 | ], 36 | ], 37 | 'types'=>[ 38 | 'files' => "", 39 | 'images' => "*img", 40 | ], 41 | 'thumbWidth' => 260, 42 | 'thumbHeight' => 260, 43 | ]); 44 | 45 | // Set kcfinder session options 46 | Yii::$app->session->set('KCFINDER', $kcfOptions); 47 | } 48 | 49 | /* @var $this yii\web\View */ 50 | /* @var $model amilna\blog\models\Post */ 51 | /* @var $form yii\widgets\ActiveForm */ 52 | 53 | $cat = new Category(); 54 | $listCategory = []+ArrayHelper::map($cat->parents(), 'id', 'title'); 55 | $category = []; 56 | foreach ($model->blogCatPos as $c) 57 | { 58 | array_push($category,$c->category_id); 59 | } 60 | ?> 61 | 62 |
63 | 64 | 65 |
66 |
67 |
68 |
69 | field($model, 'title')->textInput(['maxlength' => 65,'placeholder'=>Yii::t('app','Title contain a seo keyword if possible')]) ?> 70 |
71 |
72 | field($model, 'isfeatured')->widget(SwitchInput::classname(), [ 73 | 'type' => SwitchInput::CHECKBOX, 74 | ]); 75 | ?> 76 |
77 |
78 | field($model, 'description')->textArea(['maxlength' => 155,'placeholder'=>Yii::t('app','This description also used as meta description')]) ?> 79 | 80 | substr(Yii::$app->language,0,2), 83 | 'minHeight' => 400, 84 | 'toolbarFixedTopOffset'=>50, 85 | 'plugins' => [ 86 | 'imagemanager', 87 | 'filemanager', 88 | 'video', 89 | 'table', 90 | 'clips', 91 | 'fullscreen' 92 | ], 93 | 'buttons'=> ['formatting', 'bold', 'italic','underline','deleted', 'unorderedlist', 'orderedlist', 94 | 'outdent', 'indent', 'image', 'file', 'link', 'alignment', 'horizontalrule' 95 | ] 96 | ]; 97 | 98 | if ($module->enableUpload) 99 | { 100 | $isettings = array_merge($isettings,[ 101 | 'imageUpload' => Url::to(['//blog/default/image-upload']), 102 | 'fileUpload' => Url::to(['//blog/default/file-upload']), 103 | 'imageManagerJson' => Url::to(['//blog/default/images-get']), 104 | 'fileManagerJson' => Url::to(['//blog/default/files-get']), 105 | ]); 106 | } 107 | 108 | use vova07\imperavi\Widget; 109 | echo $form->field($model, 'content')->widget(Widget::className(), [ 110 | 'settings' => $isettings, 111 | 'options'=>["style"=>"width:100%"] 112 | ]); 113 | ?> 114 |
115 |
116 |
117 | field($model, 'time')->widget(DateTimePicker::classname(), [ 118 | 'options' => ['placeholder' => 'Select posting time ...','readonly'=>true], 119 | 'removeButton'=>false, 120 | 'convertFormat' => true, 121 | 'pluginOptions' => [ 122 | 'autoclose'=>true, 123 | 'format' => 'yyyy-MM-dd HH:i:s', 124 | //'startDate' => '01-Mar-2014 12:00 AM', 125 | 'todayHighlight' => true, 126 | ] 127 | ]) 128 | ?> 129 | 130 | field($model, 'tags')->widget(Select2::classname(), [ 131 | 'options' => [ 132 | 'placeholder' => Yii::t('app','Put additional tags ...'), 133 | ], 134 | 'data'=>$model->getTags(), 135 | 'pluginOptions' => [ 136 | 'tags' => true, 137 | 'tokenSeparators'=>[',',' '], 138 | ], 139 | ]) ?> 140 | 141 |
142 | 143 | 'Post[category]', 145 | 'data' => $listCategory, 146 | 'value'=>$category, 147 | 'options' => [ 148 | 'placeholder' => Yii::t('app','Select categories ...'), 149 | 'multiple' => true 150 | ], 151 | ]); 152 | ?> 153 |
154 | 155 | field($model, 'status')->widget(Select2::classname(), [ 156 | 'data' => $model->itemAlias('status'), 157 | 'options' => ['placeholder' => Yii::t('app','Select post status...')], 158 | 'pluginOptions' => [ 159 | 'allowClear' => false 160 | ], 161 | 'pluginEvents' => [ 162 | ], 163 | ]); 164 | ?> 165 | 166 | enableUpload) 168 | { 169 | echo $form->field($model, 'image')->widget(KCFinderInputWidget::className(), [ 170 | 'multiple' => false, 171 | 'kcfOptions'=>$kcfOptions, 172 | 'kcfBrowseOptions'=>[ 173 | 'type'=>'images', 174 | 'lng'=>substr(Yii::$app->language,0,2), 175 | ] 176 | ]); 177 | } 178 | else 179 | { 180 | echo $form->field($model, 'image')->textInput(['placeholder'=>Yii::t('app','Url of image')]); 181 | } 182 | 183 | ?> 184 |
185 |
186 |
187 | 188 |
189 | isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 190 |
191 | 192 | 193 | 194 |
195 | -------------------------------------------------------------------------------- /models/BannerSearch.php: -------------------------------------------------------------------------------- 1 | Yii::t('app', 'Search'), 34 | ]); 35 | } 36 | 37 | public static function find() 38 | { 39 | return parent::find()->where([Banner::tableName().'.isdel' => 0]); 40 | } 41 | 42 | /** 43 | * @inheritdoc 44 | */ 45 | public function scenarios() 46 | { 47 | // bypass scenarios() implementation in the parent class 48 | return Model::scenarios(); 49 | } 50 | 51 | private function queryString($fields) 52 | { 53 | $params = []; 54 | foreach ($fields as $afield) 55 | { 56 | $field = $afield[0]; 57 | $tab = isset($afield[1])?$afield[1]:false; 58 | if (!empty($this->$field)) 59 | { 60 | if (substr($this->$field,0,2) == "< " || substr($this->$field,0,2) == "> " || substr($this->$field,0,2) == "<=" || substr($this->$field,0,2) == ">=" || substr($this->$field,0,2) == "<>") 61 | { 62 | array_push($params,[str_replace(" ","",substr($this->$field,0,2)), "lower(".($tab?$tab.".":"").$field.")", strtolower(trim(substr($this->$field,2)))]); 63 | } 64 | else 65 | { 66 | array_push($params,["like", "lower(".($tab?$tab.".":"").$field.")", strtolower($this->$field)]); 67 | } 68 | } 69 | } 70 | return $params; 71 | } 72 | 73 | private function queryNumber($fields) 74 | { 75 | $params = []; 76 | foreach ($fields as $afield) 77 | { 78 | $field = $afield[0]; 79 | $tab = isset($afield[1])?$afield[1]:false; 80 | if (!empty($this->$field)) 81 | { 82 | $number = explode(" ",trim($this->$field)); 83 | if (count($number) == 2) 84 | { 85 | if (in_array($number[0],['>','>=','<','<=','<>']) && is_numeric($number[1])) 86 | { 87 | array_push($params,[$number[0], ($tab?$tab.".":"").$field, $number[1]]); 88 | } 89 | } 90 | elseif (count($number) == 3) 91 | { 92 | if (is_numeric($number[0]) && is_numeric($number[2])) 93 | { 94 | array_push($params,['>=', ($tab?$tab.".":"").$field, $number[0]]); 95 | array_push($params,['<=', ($tab?$tab.".":"").$field, $number[2]]); 96 | } 97 | } 98 | elseif (count($number) == 1) 99 | { 100 | if (is_numeric($number[0])) 101 | { 102 | array_push($params,['=', ($tab?$tab.".":"").$field, str_replace(["<",">","="],"",$number[0])]); 103 | } 104 | } 105 | } 106 | } 107 | return $params; 108 | } 109 | 110 | private function queryTime($fields) 111 | { 112 | $params = []; 113 | foreach ($fields as $afield) 114 | { 115 | $field = $afield[0]; 116 | $tab = isset($afield[1])?$afield[1]:false; 117 | if (!empty($this->$field)) 118 | { 119 | $time = explode(" - ",$this->$field); 120 | if (count($time) > 1) 121 | { 122 | array_push($params,[">=", "concat('',".($tab?$tab.".":"").$field.")", $time[0]]); 123 | array_push($params,["<=", "concat('',".($tab?$tab.".":"").$field.")", $time[1]." 24:00:00"]); 124 | } 125 | else 126 | { 127 | if (substr($time[0],0,2) == "< " || substr($time[0],0,2) == "> " || substr($time[0],0,2) == "<=" || substr($time[0],0,2) == ">=" || substr($time[0],0,2) == "<>") 128 | { 129 | array_push($params,[str_replace(" ","",substr($time[0],0,2)), "concat('',".($tab?$tab.".":"").$field.")", trim(substr($time[0],2))]); 130 | } 131 | else 132 | { 133 | array_push($params,["like", "concat('',".($tab?$tab.".":"").$field.")", $time[0]]); 134 | } 135 | } 136 | } 137 | } 138 | return $params; 139 | } 140 | 141 | /** 142 | * Creates data provider instance with search query applied 143 | * 144 | * @param array $params 145 | * 146 | * @return ActiveDataProvider 147 | */ 148 | public function search($params) 149 | { 150 | $query = $this->find(); 151 | 152 | 153 | $query->joinWith([/**/]); 154 | 155 | $dataProvider = new ActiveDataProvider([ 156 | 'query' => $query, 157 | ]); 158 | 159 | $dataProvider->sort->attributes['term'] = [ 160 | 'asc' => ['title' => SORT_ASC], 161 | 'desc' => ['title' => SORT_DESC], 162 | ]; 163 | 164 | if (!($this->load($params) && $this->validate())) { 165 | return $dataProvider; 166 | } 167 | 168 | $query->andFilterWhere([ 169 | 'status' => $this->status, 170 | /**/ 171 | ]); 172 | 173 | $params = self::queryNumber([['id',$this->tableName()],['position'],['isdel']]); 174 | foreach ($params as $p) 175 | { 176 | $query->andFilterWhere($p); 177 | } 178 | $params = self::queryString([['title'],['description'],['image'],['front_image'],['tags'],['url']]); 179 | foreach ($params as $p) 180 | { 181 | $query->andFilterWhere($p); 182 | } 183 | $params = self::queryTime([['time']]); 184 | foreach ($params as $p) 185 | { 186 | $query->andFilterWhere($p); 187 | } 188 | 189 | if ($this->term) 190 | { 191 | $query->andFilterWhere(["OR","lower(title) like '%".strtolower($this->term)."%'", 192 | ["OR","lower(description) like '%".strtolower($this->term)."%'", 193 | ["OR","lower(tags) like '%".strtolower($this->term)."%'", 194 | ["OR","lower(image) like '%".strtolower($this->term)."%'", 195 | "lower(front_image) like '%".strtolower($this->term)."%'" 196 | ] 197 | ] 198 | ] 199 | ]); 200 | } 201 | 202 | return $dataProvider; 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /models/GallerySearch.php: -------------------------------------------------------------------------------- 1 | Yii::t('app', 'Search'), 35 | ]); 36 | } 37 | 38 | public static function find() 39 | { 40 | return parent::find()->where([Gallery::tableName().'.isdel' => 0]); 41 | } 42 | 43 | /** 44 | * @inheritdoc 45 | */ 46 | public function scenarios() 47 | { 48 | // bypass scenarios() implementation in the parent class 49 | return Model::scenarios(); 50 | } 51 | 52 | private function queryString($fields) 53 | { 54 | $params = []; 55 | foreach ($fields as $afield) 56 | { 57 | $field = $afield[0]; 58 | $tab = isset($afield[1])?$afield[1]:false; 59 | if (!empty($this->$field)) 60 | { 61 | if (substr($this->$field,0,2) == "< " || substr($this->$field,0,2) == "> " || substr($this->$field,0,2) == "<=" || substr($this->$field,0,2) == ">=" || substr($this->$field,0,2) == "<>") 62 | { 63 | array_push($params,[str_replace(" ","",substr($this->$field,0,2)), "lower(".($tab?$tab.".":"").$field.")", strtolower(trim(substr($this->$field,2)))]); 64 | } 65 | else 66 | { 67 | array_push($params,["like", "lower(".($tab?$tab.".":"").$field.")", strtolower($this->$field)]); 68 | } 69 | } 70 | } 71 | return $params; 72 | } 73 | 74 | private function queryNumber($fields) 75 | { 76 | $params = []; 77 | foreach ($fields as $afield) 78 | { 79 | $field = $afield[0]; 80 | $tab = isset($afield[1])?$afield[1]:false; 81 | if (!empty($this->$field)) 82 | { 83 | $number = explode(" ",trim($this->$field)); 84 | if (count($number) == 2) 85 | { 86 | if (in_array($number[0],['>','>=','<','<=','<>']) && is_numeric($number[1])) 87 | { 88 | array_push($params,[$number[0], ($tab?$tab.".":"").$field, $number[1]]); 89 | } 90 | } 91 | elseif (count($number) == 3) 92 | { 93 | if (is_numeric($number[0]) && is_numeric($number[2])) 94 | { 95 | array_push($params,['>=', ($tab?$tab.".":"").$field, $number[0]]); 96 | array_push($params,['<=', ($tab?$tab.".":"").$field, $number[2]]); 97 | } 98 | } 99 | elseif (count($number) == 1) 100 | { 101 | if (is_numeric($number[0])) 102 | { 103 | array_push($params,['=', ($tab?$tab.".":"").$field, str_replace(["<",">","="],"",$number[0])]); 104 | } 105 | } 106 | } 107 | } 108 | return $params; 109 | } 110 | 111 | private function queryTime($fields) 112 | { 113 | $params = []; 114 | foreach ($fields as $afield) 115 | { 116 | $field = $afield[0]; 117 | $tab = isset($afield[1])?$afield[1]:false; 118 | if (!empty($this->$field)) 119 | { 120 | $time = explode(" - ",$this->$field); 121 | if (count($time) > 1) 122 | { 123 | array_push($params,[">=", "concat('',".($tab?$tab.".":"").$field.")", $time[0]]); 124 | array_push($params,["<=", "concat('',".($tab?$tab.".":"").$field.")", $time[1]." 24:00:00"]); 125 | } 126 | else 127 | { 128 | if (substr($time[0],0,2) == "< " || substr($time[0],0,2) == "> " || substr($time[0],0,2) == "<=" || substr($time[0],0,2) == ">=" || substr($time[0],0,2) == "<>") 129 | { 130 | array_push($params,[str_replace(" ","",substr($time[0],0,2)), "concat('',".($tab?$tab.".":"").$field.")", trim(substr($time[0],2))]); 131 | } 132 | else 133 | { 134 | array_push($params,["like", "concat('',".($tab?$tab.".":"").$field.")", $time[0]]); 135 | } 136 | } 137 | } 138 | } 139 | return $params; 140 | } 141 | 142 | /** 143 | * Creates data provider instance with search query applied 144 | * 145 | * @param array $params 146 | * 147 | * @return ActiveDataProvider 148 | */ 149 | public function search($params) 150 | { 151 | $query = $this->find(); 152 | 153 | 154 | $query->joinWith([/**/]); 155 | 156 | $dataProvider = new ActiveDataProvider([ 157 | 'query' => $query, 158 | ]); 159 | 160 | $dataProvider->sort->attributes['term'] = [ 161 | 'asc' => ['title' => SORT_ASC], 162 | 'desc' => ['title' => SORT_DESC], 163 | ]; 164 | 165 | if (!($this->load($params) && $this->validate())) { 166 | return $dataProvider; 167 | } 168 | 169 | $query->andFilterWhere([ 170 | 'status' => $this->status, 171 | 'type' => $this->type, 172 | 'isdel' => $this->isdel, 173 | /**/ 174 | ]); 175 | 176 | $params = self::queryNumber([['id',$this->tableName()]]); 177 | foreach ($params as $p) 178 | { 179 | $query->andFilterWhere($p); 180 | } 181 | $params = self::queryString([['title'],['description'],['url'],['tags']]); 182 | foreach ($params as $p) 183 | { 184 | $query->andFilterWhere($p); 185 | } 186 | $params = self::queryTime([['time']]); 187 | foreach ($params as $p) 188 | { 189 | $query->andFilterWhere($p); 190 | } 191 | 192 | if ($this->term) 193 | { 194 | $query->andFilterWhere(["OR","lower(title) like '%".strtolower($this->term)."%'", 195 | ["OR","lower(description) like '%".strtolower($this->term)."%'", 196 | ["OR","lower(tags) like '%".strtolower($this->term)."%'", 197 | "lower(url) like '%".strtolower($this->term)."%'" 198 | ] 199 | ] 200 | ]); 201 | } 202 | 203 | if ($this->tag) { 204 | $query->andFilterWhere(['like',"lower(concat(',',tags,','))",strtolower(",".$this->tag.",")]); 205 | } 206 | 207 | 208 | return $dataProvider; 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /models/StaticPageSearch.php: -------------------------------------------------------------------------------- 1 | Yii::t('app', 'Search'), 34 | ]); 35 | } 36 | 37 | /* uncomment to undisplay deleted records (assumed the table has column isdel) */ 38 | public static function find() 39 | { 40 | return parent::find()->where([StaticPage::tableName().'.isdel' => 0]); 41 | } 42 | 43 | /** 44 | * @inheritdoc 45 | */ 46 | public function scenarios() 47 | { 48 | // bypass scenarios() implementation in the parent class 49 | return Model::scenarios(); 50 | } 51 | 52 | private function queryString($fields) 53 | { 54 | $params = []; 55 | foreach ($fields as $afield) 56 | { 57 | $field = $afield[0]; 58 | $tab = isset($afield[1])?$afield[1]:false; 59 | if (!empty($this->$field)) 60 | { 61 | if (substr($this->$field,0,2) == "< " || substr($this->$field,0,2) == "> " || substr($this->$field,0,2) == "<=" || substr($this->$field,0,2) == ">=" || substr($this->$field,0,2) == "<>") 62 | { 63 | array_push($params,[str_replace(" ","",substr($this->$field,0,2)), "lower(".($tab?$tab.".":"").$field.")", strtolower(trim(substr($this->$field,2)))]); 64 | } 65 | else 66 | { 67 | array_push($params,["like", "lower(".($tab?$tab.".":"").$field.")", strtolower($this->$field)]); 68 | } 69 | } 70 | } 71 | return $params; 72 | } 73 | 74 | private function queryNumber($fields) 75 | { 76 | $params = []; 77 | foreach ($fields as $afield) 78 | { 79 | $field = $afield[0]; 80 | $tab = isset($afield[1])?$afield[1]:false; 81 | if (!empty($this->$field)) 82 | { 83 | $number = explode(" ",trim($this->$field)); 84 | if (count($number) == 2) 85 | { 86 | if (in_array($number[0],['>','>=','<','<=','<>']) && is_numeric($number[1])) 87 | { 88 | array_push($params,[$number[0], ($tab?$tab.".":"").$field, $number[1]]); 89 | } 90 | } 91 | elseif (count($number) == 3) 92 | { 93 | if (is_numeric($number[0]) && is_numeric($number[2])) 94 | { 95 | array_push($params,['>=', ($tab?$tab.".":"").$field, $number[0]]); 96 | array_push($params,['<=', ($tab?$tab.".":"").$field, $number[2]]); 97 | } 98 | } 99 | elseif (count($number) == 1) 100 | { 101 | if (is_numeric($number[0])) 102 | { 103 | array_push($params,['=', ($tab?$tab.".":"").$field, str_replace(["<",">","="],"",$number[0])]); 104 | } 105 | } 106 | } 107 | } 108 | return $params; 109 | } 110 | 111 | private function queryTime($fields) 112 | { 113 | $params = []; 114 | foreach ($fields as $afield) 115 | { 116 | $field = $afield[0]; 117 | $tab = isset($afield[1])?$afield[1]:false; 118 | if (!empty($this->$field)) 119 | { 120 | $time = explode(" - ",$this->$field); 121 | if (count($time) > 1) 122 | { 123 | array_push($params,[">=", "concat('',".($tab?$tab.".":"").$field.")", $time[0]]); 124 | array_push($params,["<=", "concat('',".($tab?$tab.".":"").$field.")", $time[1]." 24:00:00"]); 125 | } 126 | else 127 | { 128 | if (substr($time[0],0,2) == "< " || substr($time[0],0,2) == "> " || substr($time[0],0,2) == "<=" || substr($time[0],0,2) == ">=" || substr($time[0],0,2) == "<>") 129 | { 130 | array_push($params,[str_replace(" ","",substr($time[0],0,2)), "concat('',".($tab?$tab.".":"").$field.")", trim(substr($time[0],2))]); 131 | } 132 | else 133 | { 134 | array_push($params,["like", "concat('',".($tab?$tab.".":"").$field.")", $time[0]]); 135 | } 136 | } 137 | } 138 | } 139 | return $params; 140 | } 141 | 142 | /** 143 | * Creates data provider instance with search query applied 144 | * 145 | * @param array $params 146 | * 147 | * @return ActiveDataProvider 148 | */ 149 | public function search($params) 150 | { 151 | $query = $this->find(); 152 | 153 | 154 | $query->joinWith([/**/]); 155 | 156 | $dataProvider = new ActiveDataProvider([ 157 | 'query' => $query, 158 | ]); 159 | 160 | /* uncomment to sort by relations table on respective column*/ 161 | 162 | $dataProvider->sort->attributes['term'] = [ 163 | 'asc' => ['title' => SORT_ASC], 164 | 'desc' => ['title' => SORT_DESC], 165 | ]; 166 | 167 | if (!($this->load($params) && $this->validate())) { 168 | return $dataProvider; 169 | } 170 | 171 | $query->andFilterWhere([ 172 | 'status' => $this->status, 173 | 'isdel' => $this->isdel, 174 | /**/ 175 | ]); 176 | 177 | $params = self::queryNumber([['id',$this->tableName()]]); 178 | foreach ($params as $p) 179 | { 180 | $query->andFilterWhere($p); 181 | } 182 | $params = self::queryString([['title'],['description'],['content'],['tags']]); 183 | foreach ($params as $p) 184 | { 185 | $query->andFilterWhere($p); 186 | } 187 | $params = self::queryTime([['time']]); 188 | foreach ($params as $p) 189 | { 190 | $query->andFilterWhere($p); 191 | } 192 | 193 | $res = (is_int($this->term)?"{".$this->term."}":"{}"); 194 | 195 | if ($this->term) 196 | { 197 | $query->andFilterWhere(["OR","lower(title) like '%".strtolower($this->term)."%'", 198 | ["OR","lower(description) like '%".strtolower($this->term)."%'", 199 | ["OR","lower(tags) like '%".strtolower($this->term)."%'", 200 | ["OR","lower(content) like '%".strtolower($this->term)."%'", 201 | $this->tableName().".id = ANY ('".$res."')" 202 | ] 203 | ] 204 | ] 205 | ]); 206 | } 207 | 208 | return $dataProvider; 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /controllers/BannerController.php: -------------------------------------------------------------------------------- 1 | [ 22 | 'class' => VerbFilter::className(), 23 | 'actions' => [ 24 | 'delete' => ['post'], 25 | ], 26 | ], 27 | ]; 28 | } 29 | 30 | /** 31 | * Lists all Banner models. 32 | * @params string $format, array $arraymap, string $term 33 | * @return mixed 34 | */ 35 | public function actionIndex($format= false,$arraymap= false,$term = false) 36 | { 37 | 38 | $searchModel = new BannerSearch(); 39 | $req = Yii::$app->request->queryParams; 40 | if ($term) { $req[basename(str_replace("\\","/",get_class($searchModel)))]["term"] = $term;} 41 | $dataProvider = $searchModel->search($req); 42 | 43 | if ($format == 'json') 44 | { 45 | $model = []; 46 | foreach ($dataProvider->getModels() as $d) 47 | { 48 | $obj = $d->attributes; 49 | if ($arraymap) 50 | { 51 | $map = explode(",",$arraymap); 52 | if (count($map) == 1) 53 | { 54 | $obj = (isset($d[$arraymap])?$d[$arraymap]:null); 55 | } 56 | else 57 | { 58 | $obj = []; 59 | foreach ($map as $a) 60 | { 61 | $k = explode(":",$a); 62 | $v = (count($k) > 1?$k[1]:$k[0]); 63 | $obj[$k[0]] = ($v == "Obj"?json_encode($d->attributes):(isset($d->$v)?$d->$v:null)); 64 | } 65 | } 66 | } 67 | 68 | if ($term) 69 | { 70 | if (!in_array($obj,$model)) 71 | { 72 | array_push($model,$obj); 73 | } 74 | } 75 | else 76 | { 77 | array_push($model,$obj); 78 | } 79 | } 80 | return \yii\helpers\Json::encode($model); 81 | } 82 | else 83 | { 84 | $bannerProvider = new ActiveDataProvider([ 85 | 'models' => Banner::find()->where('status = true AND isdel = 0 order by position asc')->all(), 86 | 'pagination'=>false, 87 | /*'pagination' => [ 88 | 'pageSize' => 20, 89 | ],*/ 90 | ]); 91 | 92 | return $this->render('index', [ 93 | 'searchModel' => $searchModel, 94 | 'dataProvider' => $dataProvider, 95 | 'bannerProvider' => $bannerProvider, 96 | ]); 97 | } 98 | } 99 | 100 | /** 101 | * Displays a single Banner model. 102 | * @param integer $id 103 | * @additionalParam string $format 104 | * @return mixed 105 | */ 106 | public function actionView($id,$format= false) 107 | { 108 | $model = $this->findModel($id); 109 | 110 | if ($format == 'json') 111 | { 112 | return \yii\helpers\Json::encode($model); 113 | } 114 | else 115 | { 116 | return $this->render('view', [ 117 | 'model' => $model, 118 | ]); 119 | } 120 | } 121 | 122 | /** 123 | * Creates a new Banner model. 124 | * If creation is successful, the browser will be redirected to the 'view' page. 125 | * @return mixed 126 | */ 127 | public function actionCreate() 128 | { 129 | $model = new Banner(); 130 | $model->time = date("Y-m-d H:i:s"); 131 | $model->position = $model->getLast(); 132 | $model->isdel = 0; 133 | 134 | $post = Yii::$app->request->post(); 135 | if (isset($post['Banner']['tags'])) 136 | { 137 | if (is_array($post['Banner']['tags'])) 138 | { 139 | $post['Banner']['tags'] = implode(",",$post['Banner']['tags']); 140 | } 141 | } 142 | 143 | $transaction = Yii::$app->db->beginTransaction(); 144 | try { 145 | if ($model->load($post) && $model->save()) { 146 | $model->updatePosition($model->position); 147 | $transaction->commit(); 148 | return $this->redirect(['view', 'id' => $model->id]); 149 | } 150 | else 151 | { 152 | $transaction->rollBack(); 153 | } 154 | } catch (Exception $e) { 155 | $transaction->rollBack(); 156 | } 157 | 158 | return $this->render('create', [ 159 | 'model' => $model, 160 | ]); 161 | 162 | } 163 | 164 | /** 165 | * Updates an existing Banner model. 166 | * If update is successful, the browser will be redirected to the 'view' page. 167 | * @param integer $id 168 | * @return mixed 169 | */ 170 | public function actionUpdate($id) 171 | { 172 | $model = $this->findModel($id); 173 | 174 | $model->tags = !empty($model->tags)?explode(",",$model->tags):[]; 175 | 176 | $post = Yii::$app->request->post(); 177 | if (isset($post['Banner']['tags'])) 178 | { 179 | if (is_array($post['Banner']['tags'])) 180 | { 181 | $post['Banner']['tags'] = implode(",",$post['Banner']['tags']); 182 | } 183 | } 184 | 185 | $transaction = Yii::$app->db->beginTransaction(); 186 | try { 187 | if ($model->load($post) && $model->save()) { 188 | $model->updatePosition($model->position); 189 | $transaction->commit(); 190 | return $this->redirect(['view', 'id' => $model->id]); 191 | } 192 | else 193 | { 194 | $transaction->rollBack(); 195 | } 196 | } catch (Exception $e) { 197 | $transaction->rollBack(); 198 | } 199 | 200 | return $this->render('update', [ 201 | 'model' => $model, 202 | ]); 203 | 204 | } 205 | 206 | /** 207 | * Deletes an existing Banner model. 208 | * If deletion is successful, the browser will be redirected to the 'index' page. 209 | * @param integer $id 210 | * @return mixed 211 | */ 212 | public function actionDelete($id) 213 | { 214 | $model = $this->findModel($id); 215 | $model->isdel = 1; 216 | $model->save(); 217 | //$model->delete(); //this will true delete 218 | 219 | return $this->redirect(['index']); 220 | } 221 | 222 | /** 223 | * Finds the Banner model based on its primary key value. 224 | * If the model is not found, a 404 HTTP exception will be thrown. 225 | * @param integer $id 226 | * @return Banner the loaded model 227 | * @throws NotFoundHttpException if the model cannot be found 228 | */ 229 | protected function findModel($id) 230 | { 231 | if (($model = Banner::findOne($id)) !== null) { 232 | return $model; 233 | } else { 234 | throw new NotFoundHttpException('The requested page does not exist.'); 235 | } 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /views/gallery/_form.php: -------------------------------------------------------------------------------- 1 | getModule('blog'); 16 | if ($module->enableUpload) 17 | { 18 | // kcfinder options 19 | // http://kcfinder.sunhater.com/install#dynamic 20 | $kcfOptions = array_merge([], [ 21 | 'uploadURL' => Yii::getAlias($module->uploadURL), 22 | 'uploadDir' => Yii::getAlias($module->uploadDir), 23 | 'access' => [ 24 | 'files' => [ 25 | 'upload' => true, 26 | 'delete' => true, 27 | 'copy' => true, 28 | 'move' => true, 29 | 'rename' => true, 30 | ], 31 | 'dirs' => [ 32 | 'create' => true, 33 | 'delete' => true, 34 | 'rename' => true, 35 | ], 36 | ], 37 | 'types'=>[ 38 | 'files' => "", 39 | 'images' => "*img", 40 | 'videos' => "ogg flv mp4", 41 | ], 42 | 'thumbWidth' => 260, 43 | 'thumbHeight' => 260, 44 | ]); 45 | 46 | // Set kcfinder session options 47 | Yii::$app->session->set('KCFINDER', $kcfOptions); 48 | } 49 | 50 | /* @var $this yii\web\View */ 51 | /* @var $model amilna\blog\models\Gallery */ 52 | /* @var $form yii\widgets\ActiveForm */ 53 | ?> 54 | 55 | 166 | 167 | 168 | 217 | registerJs($this->blocks['VIDEOS'], yii\web\View::POS_END); 220 | -------------------------------------------------------------------------------- /controllers/FileController.php: -------------------------------------------------------------------------------- 1 | [ 21 | 'class' => VerbFilter::className(), 22 | 'actions' => [ 23 | 'delete' => ['post'], 24 | ], 25 | ], 26 | ]; 27 | } 28 | 29 | /** 30 | * Lists all File models. 31 | * @params string $format, array $arraymap, string $term 32 | * @return mixed 33 | */ 34 | public function actionIndex($format= false,$arraymap= false,$term = false) 35 | { 36 | $searchModel = new FileSearch(); 37 | $req = Yii::$app->request->queryParams; 38 | if ($term) { $req[basename(str_replace("\\","/",get_class($searchModel)))]["term"] = $term;} 39 | $req[basename(str_replace("\\","/",get_class($searchModel)))]["status"] = 1; 40 | $dataProvider = $searchModel->search($req); 41 | 42 | if ($format == 'json') 43 | { 44 | $model = []; 45 | foreach ($dataProvider->getModels() as $d) 46 | { 47 | $obj = $d->attributes; 48 | if ($arraymap) 49 | { 50 | $map = explode(",",$arraymap); 51 | if (count($map) == 1) 52 | { 53 | $obj = (isset($d[$arraymap])?$d[$arraymap]:null); 54 | } 55 | else 56 | { 57 | $obj = []; 58 | foreach ($map as $a) 59 | { 60 | $k = explode(":",$a); 61 | $v = (count($k) > 1?$k[1]:$k[0]); 62 | $obj[$k[0]] = ($v == "Obj"?json_encode($d->attributes):(isset($d->$v)?$d->$v:null)); 63 | } 64 | } 65 | } 66 | 67 | if ($term) 68 | { 69 | if (!in_array($obj,$model)) 70 | { 71 | array_push($model,$obj); 72 | } 73 | } 74 | else 75 | { 76 | array_push($model,$obj); 77 | } 78 | } 79 | return \yii\helpers\Json::encode($model); 80 | } 81 | else 82 | { 83 | return $this->render('index', [ 84 | 'searchModel' => $searchModel, 85 | 'dataProvider' => $dataProvider, 86 | ]); 87 | } 88 | } 89 | 90 | public function actionAdmin($format= false,$arraymap= false,$term = false) 91 | { 92 | $searchModel = new FileSearch(); 93 | $req = Yii::$app->request->queryParams; 94 | if ($term) { $req[basename(str_replace("\\","/",get_class($searchModel)))]["term"] = $term;} 95 | $dataProvider = $searchModel->search($req); 96 | 97 | if ($format == 'json') 98 | { 99 | $model = []; 100 | foreach ($dataProvider->getModels() as $d) 101 | { 102 | $obj = $d->attributes; 103 | if ($arraymap) 104 | { 105 | $map = explode(",",$arraymap); 106 | if (count($map) == 1) 107 | { 108 | $obj = (isset($d[$arraymap])?$d[$arraymap]:null); 109 | } 110 | else 111 | { 112 | $obj = []; 113 | foreach ($map as $a) 114 | { 115 | $k = explode(":",$a); 116 | $v = (count($k) > 1?$k[1]:$k[0]); 117 | $obj[$k[0]] = ($v == "Obj"?json_encode($d->attributes):(isset($d->$v)?$d->$v:null)); 118 | } 119 | } 120 | } 121 | 122 | if ($term) 123 | { 124 | if (!in_array($obj,$model)) 125 | { 126 | array_push($model,$obj); 127 | } 128 | } 129 | else 130 | { 131 | array_push($model,$obj); 132 | } 133 | } 134 | return \yii\helpers\Json::encode($model); 135 | } 136 | else 137 | { 138 | return $this->render('admin', [ 139 | 'searchModel' => $searchModel, 140 | 'dataProvider' => $dataProvider, 141 | ]); 142 | } 143 | } 144 | 145 | /** 146 | * Displays a single File model. 147 | * @param integer $id 148 | * @additionalParam string $format 149 | * @return mixed 150 | */ 151 | public function actionView($id,$format= false) 152 | { 153 | $model = $this->findModel($id); 154 | 155 | if ($format == 'json') 156 | { 157 | return \yii\helpers\Json::encode($model); 158 | } 159 | else 160 | { 161 | return $this->render('view', [ 162 | 'model' => $model, 163 | ]); 164 | } 165 | } 166 | 167 | /** 168 | * Creates a new File model. 169 | * If creation is successful, the browser will be redirected to the 'view' page. 170 | * @return mixed 171 | */ 172 | public function actionCreate() 173 | { 174 | $model = new File(); 175 | $model->time = date("Y-m-d H:i:s"); 176 | $model->isdel = 0; 177 | 178 | $post = Yii::$app->request->post(); 179 | if (isset($post['File']['tags'])) 180 | { 181 | if (is_array($post['File']['tags'])) 182 | { 183 | $post['File']['tags'] = implode(",",$post['File']['tags']); 184 | } 185 | } 186 | 187 | if ($model->load($post) && $model->save()) { 188 | return $this->redirect(['view', 'id' => $model->id]); 189 | } else { 190 | return $this->render('create', [ 191 | 'model' => $model, 192 | ]); 193 | } 194 | } 195 | 196 | /** 197 | * Updates an existing File model. 198 | * If update is successful, the browser will be redirected to the 'view' page. 199 | * @param integer $id 200 | * @return mixed 201 | */ 202 | public function actionUpdate($id) 203 | { 204 | $model = $this->findModel($id); 205 | 206 | $model->tags = !empty($model->tags)?explode(",",$model->tags):[]; 207 | 208 | $post = Yii::$app->request->post(); 209 | if (isset($post['File']['tags'])) 210 | { 211 | if (is_array($post['File']['tags'])) 212 | { 213 | $post['File']['tags'] = implode(",",$post['File']['tags']); 214 | } 215 | } 216 | 217 | 218 | if ($model->load($post) && $model->save()) { 219 | return $this->redirect(['view', 'id' => $model->id]); 220 | } else { 221 | return $this->render('update', [ 222 | 'model' => $model, 223 | ]); 224 | } 225 | } 226 | 227 | /** 228 | * Deletes an existing File model. 229 | * If deletion is successful, the browser will be redirected to the 'index' page. 230 | * @param integer $id 231 | * @return mixed 232 | */ 233 | public function actionDelete($id) 234 | { 235 | $model = $this->findModel($id); 236 | $model->isdel = 1; 237 | $model->save(); 238 | //$model->delete(); //this will true delete 239 | 240 | return $this->redirect(['index']); 241 | } 242 | 243 | /** 244 | * Finds the File model based on its primary key value. 245 | * If the model is not found, a 404 HTTP exception will be thrown. 246 | * @param integer $id 247 | * @return File the loaded model 248 | * @throws NotFoundHttpException if the model cannot be found 249 | */ 250 | protected function findModel($id) 251 | { 252 | if (($model = File::findOne($id)) !== null) { 253 | return $model; 254 | } else { 255 | throw new NotFoundHttpException('The requested page does not exist.'); 256 | } 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /views/banner/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Banners'); 15 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Blog'), 'url' => ['/blog/default']]; 16 | $this->params['breadcrumbs'][] = $this->title; 17 | 18 | $module = Yii::$app->getModule('blog'); 19 | ?> 20 | 25 | 223 | --------------------------------------------------------------------------------