├── 123 3232 ├── tests ├── unit │ ├── fixtures │ │ └── .gitkeep │ ├── templates │ │ └── fixtures │ │ │ └── .gitkeep │ ├── _bootstrap.php │ ├── _config.php │ ├── _console.php │ ├── models │ │ ├── UserTest.php │ │ ├── ContactFormTest.php │ │ └── LoginFormTest.php │ ├── yii │ └── yii.bat ├── _log │ └── .gitignore ├── _data │ └── dump.sql ├── acceptance │ ├── _bootstrap.php │ ├── AboutCept.php │ ├── HomeCept.php │ ├── _config.php │ ├── _console.php │ ├── yii │ ├── yii.bat │ ├── LoginCept.php │ └── ContactCept.php ├── functional │ ├── _bootstrap.php │ ├── AboutCept.php │ ├── HomeCept.php │ ├── _console.php │ ├── yii │ ├── _config.php │ ├── yii.bat │ ├── LoginCept.php │ └── ContactCept.php ├── .gitignore ├── _helpers │ ├── CodeHelper.php │ ├── TestHelper.php │ └── WebHelper.php ├── _pages │ ├── AboutPage.php │ ├── LoginPage.php │ └── ContactPage.php ├── unit.suite.yml ├── _config.php ├── _console_bootstrap.php ├── functional.suite.yml ├── _bootstrap.php ├── acceptance.suite.yml └── README.md ├── web ├── upload │ ├── link │ │ └── index.html │ ├── post │ │ └── 201405 │ │ │ ├── index.html │ │ │ ├── 205552uzwxzw325orjx3qo.png │ │ │ ├── 212544b329ehtrzklgihgx.png │ │ │ ├── 212620sf43xw8177kwg8f7.png │ │ │ └── 213342zi7511i8tstt75ei.png │ └── avatar │ │ ├── default.png │ │ └── 182124gwttlmaad0ms2t7t.png ├── assets │ └── .gitignore ├── robots.txt ├── favicon.ico ├── img │ └── bootstrap-formhelpers-countries.flags.png ├── .htaccess ├── index.php ├── index-test.php ├── js │ └── jquery.cookie-1.4.1.min.js └── css │ └── site.css ├── runtime └── .gitignore ├── README.md ├── modules └── admin │ ├── views │ ├── layouts │ │ ├── column1.php │ │ └── main.php │ ├── post │ │ ├── _comments.php │ │ ├── create.php │ │ ├── update.php │ │ ├── view.php │ │ ├── _search.php │ │ └── index.php │ ├── user │ │ ├── create.php │ │ ├── update.php │ │ ├── _form.php │ │ ├── view.php │ │ ├── index.php │ │ └── _search.php │ ├── nav │ │ ├── create.php │ │ ├── update.php │ │ ├── _search.php │ │ ├── index.php │ │ ├── view.php │ │ └── _form.php │ ├── tag │ │ ├── create.php │ │ ├── update.php │ │ ├── _form.php │ │ ├── _search.php │ │ ├── index.php │ │ └── view.php │ ├── link │ │ ├── create.php │ │ ├── update.php │ │ ├── _search.php │ │ ├── view.php │ │ ├── _form.php │ │ └── index.php │ ├── page │ │ ├── create.php │ │ ├── update.php │ │ ├── _search.php │ │ ├── index.php │ │ ├── view.php │ │ └── _form.php │ ├── lookup │ │ ├── create.php │ │ ├── update.php │ │ ├── _form.php │ │ ├── _search.php │ │ ├── index.php │ │ └── view.php │ ├── source │ │ ├── create.php │ │ ├── update.php │ │ ├── _form.php │ │ ├── _search.php │ │ ├── index.php │ │ └── view.php │ ├── writer │ │ ├── create.php │ │ ├── _form.php │ │ ├── update.php │ │ ├── _search.php │ │ ├── index.php │ │ └── view.php │ ├── comment │ │ ├── create.php │ │ ├── update.php │ │ ├── index.php │ │ ├── _form.php │ │ ├── _search.php │ │ └── view.php │ ├── category │ │ ├── create.php │ │ ├── update.php │ │ ├── _search.php │ │ ├── index.php │ │ ├── view.php │ │ └── _form.php │ └── default │ │ ├── error.php │ │ ├── access.php │ │ ├── email.php │ │ ├── login.php │ │ ├── image.php │ │ ├── ftp.php │ │ ├── index.php │ │ ├── signup.php │ │ └── info.php │ ├── assets │ └── AppAsset.php │ ├── models │ ├── SignupForm.php │ ├── AccessForm.php │ └── InfoForm.php │ ├── Module.php │ └── components │ └── Controller.php ├── config ├── db.php ├── params.php ├── console.php └── web.php ├── views ├── site │ ├── about.php │ ├── error.php │ ├── resetPassword.php │ ├── requestPasswordResetToken.php │ ├── signup.php │ ├── login.php │ └── contact.php ├── user │ └── view.php ├── page │ └── view.php └── post │ ├── _comment.php │ └── index.php ├── codeception.yml ├── .gitignore ├── yii.bat ├── widgets ├── LinkWidget.php ├── TagCloud.php ├── HotArticles.php ├── CategoryWidget.php ├── RecommendArticles.php └── Alert.php ├── assets └── AppAsset.php ├── mail └── layouts │ └── html.php ├── yii ├── commands └── HelloController.php ├── models ├── Writer.php ├── config.php ├── Source.php ├── UserForm.php ├── search │ ├── WriterSearch.php │ ├── TagSearch.php │ ├── SourceSearch.php │ ├── NavSearch.php │ ├── CategorySearch.php │ ├── PageSearch.php │ ├── UserSearch.php │ ├── CommentSearch.php │ ├── LookupSearch.php │ └── LinkSearch.php ├── ResetPasswordForm.php ├── Link.php ├── PasswordResetRequestForm.php ├── Nav.php ├── ContactForm.php ├── LoginForm.php ├── Page.php ├── SignupForm.php └── Lookup.php ├── components ├── Controller.php ├── AutocompleteAction.php └── ToggleAction.php ├── composer.json ├── LICENSE.md ├── controllers └── PageController.php └── messages └── config.php /123 3232: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /tests/unit/fixtures/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/upload/link/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/upload/post/201405/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /runtime/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /tests/_log/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /tests/unit/templates/fixtures/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/assets/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /web/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: -------------------------------------------------------------------------------- /tests/_data/dump.sql: -------------------------------------------------------------------------------- 1 | /* Replace this file with actual dump of your database */ -------------------------------------------------------------------------------- /web/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djfly/dcms2/HEAD/web/favicon.ico -------------------------------------------------------------------------------- /tests/unit/_bootstrap.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that about works'); 7 | AboutPage::openBy($I); 8 | $I->see('About', 'h1'); 9 | -------------------------------------------------------------------------------- /tests/functional/AboutCept.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that about works'); 7 | AboutPage::openBy($I); 8 | $I->see('About', 'h1'); 9 | -------------------------------------------------------------------------------- /modules/admin/views/layouts/column1.php: -------------------------------------------------------------------------------- 1 | 2 | beginContent('@app/views/layouts/main.php'); ?> 3 |
4 | 5 |
6 | endContent(); ?> -------------------------------------------------------------------------------- /tests/unit.suite.yml: -------------------------------------------------------------------------------- 1 | # Codeception Test Suite Configuration 2 | 3 | # suite for unit (internal) tests. 4 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. 5 | 6 | class_name: CodeGuy 7 | modules: 8 | enabled: 9 | - CodeHelper 10 | -------------------------------------------------------------------------------- /config/db.php: -------------------------------------------------------------------------------- 1 | 'yii\db\Connection', 5 | 'dsn' => 'mysql:host=127.0.0.1;dbname=dcms2', 6 | 'username' => 'root', 7 | 'password' => '', 8 | 'charset' => 'utf8', 9 | 'tablePrefix' => 'tbl_', 10 | ]; 11 | -------------------------------------------------------------------------------- /tests/acceptance/HomeCept.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that home page works'); 5 | $I->amOnPage(Yii::$app->homeUrl); 6 | $I->see('My Company'); 7 | $I->seeLink('About'); 8 | $I->click('About'); 9 | $I->see('This is the About page.'); 10 | -------------------------------------------------------------------------------- /tests/functional/HomeCept.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that home page works'); 5 | $I->amOnPage(Yii::$app->homeUrl); 6 | $I->see('My Company'); 7 | $I->seeLink('About'); 8 | $I->click('About'); 9 | $I->see('This is the About page.'); 10 | -------------------------------------------------------------------------------- /web/.htaccess: -------------------------------------------------------------------------------- 1 | Options +FollowSymLinks 2 | IndexIgnore */* 3 | RewriteEngine on 4 | 5 | # if a directory or a file exists, use it directly 6 | RewriteCond %{REQUEST_FILENAME} !-f 7 | RewriteCond %{REQUEST_FILENAME} !-d 8 | 9 | # otherwise forward it to index.php 10 | RewriteRule . index.php -------------------------------------------------------------------------------- /tests/_config.php: -------------------------------------------------------------------------------- 1 | [ 7 | 'mail' => [ 8 | 'useFileTransport' => true, 9 | ], 10 | 'urlManager' => [ 11 | 'showScriptName' => true, 12 | ], 13 | ], 14 | ]; 15 | -------------------------------------------------------------------------------- /config/params.php: -------------------------------------------------------------------------------- 1 | ['admin'], 5 | 'adminEmail' => 'admin@admin.com', 6 | 'user.passwordResetTokenExpire' => 3600, 7 | 'pagebreakHtml' => '#p# pagebreak #e#', 8 | 'disallow_comment' => 0, 9 | 'postUpload' => 'upload/post/', 10 | 'commentNeedApproval' => false, 11 | 'tagCloudCount' => 30, 12 | ]; 13 | -------------------------------------------------------------------------------- /tests/unit/_config.php: -------------------------------------------------------------------------------- 1 | [ 8 | 'db' => [ 9 | 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_unit', 10 | ], 11 | ], 12 | ] 13 | ); 14 | -------------------------------------------------------------------------------- /tests/unit/_console.php: -------------------------------------------------------------------------------- 1 | [ 8 | 'db' => [ 9 | 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_unit', 10 | ], 11 | ], 12 | ] 13 | ); 14 | -------------------------------------------------------------------------------- /tests/acceptance/_config.php: -------------------------------------------------------------------------------- 1 | [ 8 | 'db' => [ 9 | 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_acceptance', 10 | ], 11 | ], 12 | ] 13 | ); 14 | -------------------------------------------------------------------------------- /tests/acceptance/_console.php: -------------------------------------------------------------------------------- 1 | [ 8 | 'db' => [ 9 | 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_acceptance', 10 | ], 11 | ], 12 | ] 13 | ); 14 | -------------------------------------------------------------------------------- /tests/functional/_console.php: -------------------------------------------------------------------------------- 1 | [ 8 | 'db' => [ 9 | 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_functional', 10 | ], 11 | ], 12 | ] 13 | ); 14 | -------------------------------------------------------------------------------- /tests/unit/models/UserTest.php: -------------------------------------------------------------------------------- 1 | loadFixtures(['user']); 14 | } 15 | 16 | // TODO add test methods here 17 | } 18 | -------------------------------------------------------------------------------- /modules/admin/views/post/_comments.php: -------------------------------------------------------------------------------- 1 | 5 | 6 | $comment, 8 | 'attributes' => [ 9 | 'id', 10 | 'author', 11 | 'create_time:datetime', 12 | 'content:ntext', 13 | 14 | ], 15 | ]) ?> 16 | -------------------------------------------------------------------------------- /views/site/about.php: -------------------------------------------------------------------------------- 1 | title = 'About'; 8 | $this->params['breadcrumbs'][] = $this->title; 9 | ?> 10 |
11 |

title) ?>

12 | 13 |

14 | This is the About page. You may modify the following file to customize its content: 15 |

16 | 17 | 18 |
19 | -------------------------------------------------------------------------------- /codeception.yml: -------------------------------------------------------------------------------- 1 | paths: 2 | tests: tests 3 | log: tests/_log 4 | data: tests/_data 5 | helpers: tests/_helpers 6 | settings: 7 | bootstrap: _bootstrap.php 8 | suite_class: \PHPUnit_Framework_TestSuite 9 | memory_limit: 1024M 10 | log: true 11 | colors: true 12 | modules: 13 | config: 14 | Db: 15 | dsn: '' 16 | user: '' 17 | password: '' 18 | dump: tests/_data/dump.sql 19 | -------------------------------------------------------------------------------- /web/index.php: -------------------------------------------------------------------------------- 1 | run(); 14 | -------------------------------------------------------------------------------- /tests/_console_bootstrap.php: -------------------------------------------------------------------------------- 1 | run(); 17 | exit($exitCode); 18 | -------------------------------------------------------------------------------- /tests/acceptance/yii: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | run(); 17 | exit($exitCode); 18 | -------------------------------------------------------------------------------- /tests/functional/yii: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | run(); 17 | exit($exitCode); 18 | -------------------------------------------------------------------------------- /tests/functional/_config.php: -------------------------------------------------------------------------------- 1 | [ 12 | 'db' => [ 13 | 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_functional', 14 | ], 15 | ], 16 | ] 17 | ); 18 | -------------------------------------------------------------------------------- /tests/functional.suite.yml: -------------------------------------------------------------------------------- 1 | # Codeception Test Suite Configuration 2 | 3 | # suite for functional (integration) tests. 4 | # emulate web requests and make application process them. 5 | # (tip: better to use with frameworks). 6 | 7 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. 8 | #basic/web/index.php 9 | class_name: TestGuy 10 | modules: 11 | enabled: 12 | - Filesystem 13 | - TestHelper 14 | - Yii2 15 | config: 16 | Yii2: 17 | configFile: 'tests/functional/_config.php' 18 | -------------------------------------------------------------------------------- /tests/_pages/LoginPage.php: -------------------------------------------------------------------------------- 1 | guy->fillField('input[name="LoginForm[username]"]', $username); 18 | $this->guy->fillField('input[name="LoginForm[password]"]', $password); 19 | $this->guy->click('login-button'); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /web/index-test.php: -------------------------------------------------------------------------------- 1 | run(); 17 | -------------------------------------------------------------------------------- /modules/admin/views/user/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 11 | 'modelClass' => 'User', 12 | ]); 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Users'), 'url' => ['index']]; 14 | $this->params['breadcrumbs'][] = $this->title; 15 | ?> 16 |
17 | 18 |

title) ?>

19 | 20 | render('_form', [ 21 | 'model' => $model, 22 | ]) ?> 23 | 24 |
25 | -------------------------------------------------------------------------------- /modules/admin/views/nav/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 11 | 'modelClass' => 'Nav', 12 | ]); 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Navs'), 'url' => ['index']]; 14 | $this->params['breadcrumbs'][] = $this->title; 15 | ?> 16 | 25 | -------------------------------------------------------------------------------- /modules/admin/views/tag/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 11 | 'modelClass' => 'Tag', 12 | ]); 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Tags'), 'url' => ['index']]; 14 | $this->params['breadcrumbs'][] = $this->title; 15 | ?> 16 |
17 | 18 |

title) ?>

19 | 20 | render('_form', [ 21 | 'model' => $model, 22 | ]) ?> 23 | 24 |
25 | -------------------------------------------------------------------------------- /yii.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem ------------------------------------------------------------- 4 | rem Yii command line bootstrap script for Windows. 5 | rem 6 | rem @author Qiang Xue 7 | rem @link http://www.yiiframework.com/ 8 | rem @copyright Copyright © 2012 Yii Software LLC 9 | rem @license http://www.yiiframework.com/license/ 10 | rem ------------------------------------------------------------- 11 | 12 | @setlocal 13 | 14 | set YII_PATH=%~dp0 15 | 16 | if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe 17 | 18 | "%PHP_COMMAND%" "%YII_PATH%yii" %* 19 | 20 | @endlocal 21 | -------------------------------------------------------------------------------- /modules/admin/views/link/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 11 | 'modelClass' => 'Link', 12 | ]); 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Links'), 'url' => ['index']]; 14 | $this->params['breadcrumbs'][] = $this->title; 15 | ?> 16 | 25 | -------------------------------------------------------------------------------- /modules/admin/views/page/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 11 | 'modelClass' => 'Page', 12 | ]); 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Pages'), 'url' => ['index']]; 14 | $this->params['breadcrumbs'][] = $this->title; 15 | ?> 16 |
17 | 18 |

title) ?>

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

title) ?>

19 | 20 | render('_form', [ 21 | 'model' => $model, 22 | ]) ?> 23 | 24 |
25 | -------------------------------------------------------------------------------- /tests/unit/yii.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem ------------------------------------------------------------- 4 | rem Yii command line bootstrap script for Windows. 5 | rem 6 | rem @author Qiang Xue 7 | rem @link http://www.yiiframework.com/ 8 | rem @copyright Copyright © 2012 Yii Software LLC 9 | rem @license http://www.yiiframework.com/license/ 10 | rem ------------------------------------------------------------- 11 | 12 | @setlocal 13 | 14 | set YII_PATH=%~dp0 15 | 16 | if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe 17 | 18 | "%PHP_COMMAND%" "%YII_PATH%yii" %* 19 | 20 | @endlocal 21 | -------------------------------------------------------------------------------- /modules/admin/views/lookup/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 11 | 'modelClass' => 'Lookup', 12 | ]); 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Lookups'), 'url' => ['index']]; 14 | $this->params['breadcrumbs'][] = $this->title; 15 | ?> 16 |
17 | 18 |

title) ?>

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

title) ?>

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

title) ?>

19 | 20 | render('_form', [ 21 | 'model' => $model, 22 | ]) ?> 23 | 24 |
25 | -------------------------------------------------------------------------------- /tests/acceptance/yii.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem ------------------------------------------------------------- 4 | rem Yii command line bootstrap script for Windows. 5 | rem 6 | rem @author Qiang Xue 7 | rem @link http://www.yiiframework.com/ 8 | rem @copyright Copyright © 2012 Yii Software LLC 9 | rem @license http://www.yiiframework.com/license/ 10 | rem ------------------------------------------------------------- 11 | 12 | @setlocal 13 | 14 | set YII_PATH=%~dp0 15 | 16 | if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe 17 | 18 | "%PHP_COMMAND%" "%YII_PATH%yii" %* 19 | 20 | @endlocal 21 | -------------------------------------------------------------------------------- /tests/functional/yii.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem ------------------------------------------------------------- 4 | rem Yii command line bootstrap script for Windows. 5 | rem 6 | rem @author Qiang Xue 7 | rem @link http://www.yiiframework.com/ 8 | rem @copyright Copyright © 2012 Yii Software LLC 9 | rem @license http://www.yiiframework.com/license/ 10 | rem ------------------------------------------------------------- 11 | 12 | @setlocal 13 | 14 | set YII_PATH=%~dp0 15 | 16 | if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe 17 | 18 | "%PHP_COMMAND%" "%YII_PATH%yii" %* 19 | 20 | @endlocal 21 | -------------------------------------------------------------------------------- /modules/admin/views/comment/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 11 | 'modelClass' => 'Comment', 12 | ]); 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Comments'), 'url' => ['index']]; 14 | $this->params['breadcrumbs'][] = $this->title; 15 | ?> 16 |
17 | 18 |

title) ?>

19 | 20 | render('_form', [ 21 | 'model' => $model, 22 | ]) ?> 23 | 24 |
25 | -------------------------------------------------------------------------------- /widgets/LinkWidget.php: -------------------------------------------------------------------------------- 1 | where('visible=1')->orderBy(['position' => SORT_DESC])->limit($this->max)->all(); 15 | echo '

友情链接

    '; 16 | foreach($links as $key=>$value) 17 | { 18 | $link=Html::a(Html::encode($value->name), $value->url); 19 | echo Html::tag('li', $link); 20 | } 21 | echo "
"; 22 | } 23 | } -------------------------------------------------------------------------------- /modules/admin/views/category/create.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Create {modelClass}', [ 11 | 'modelClass' => 'Category', 12 | ]); 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Categories'), 'url' => ['index']]; 14 | $this->params['breadcrumbs'][] = $this->title; 15 | ?> 16 |
17 | 18 |

title) ?>

19 | 20 | render('_form', [ 21 | 'model' => $model, 22 | ]) ?> 23 | 24 |
25 | -------------------------------------------------------------------------------- /tests/_pages/ContactPage.php: -------------------------------------------------------------------------------- 1 | $value) { 17 | $inputType = $field === 'body' ? 'textarea' : 'input'; 18 | $this->guy->fillField($inputType . '[name="ContactForm[' . $field . ']"]', $value); 19 | } 20 | $this->guy->click('contact-button'); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /widgets/TagCloud.php: -------------------------------------------------------------------------------- 1 | findTagWeights($this->max); 18 | 19 | foreach($tags as $tag=>$weight) 20 | { 21 | $link=Html::a(Html::encode($tag), ['post/index','tag'=>$tag]); 22 | echo Html::tag('span', $link, [ 23 | 'class'=>'tag', 24 | 'style'=>"font-size:{$weight}pt", 25 | ])."\n"; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /modules/admin/views/default/error.php: -------------------------------------------------------------------------------- 1 | title = $name; 13 | ?> 14 |
15 | 16 |

title) ?>

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

23 | The above error occurred while the Web server was processing your request. 24 |

25 |

26 | Please contact us if you think this is a server error. Thank you. 27 |

28 | 29 |
30 | -------------------------------------------------------------------------------- /views/site/error.php: -------------------------------------------------------------------------------- 1 | title = $name; 13 | ?> 14 |
15 | 16 |

title) ?>

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

23 | The above error occurred while the Web server was processing your request. 24 |

25 |

26 | Please contact us if you think this is a server error. Thank you. 27 |

28 | 29 |
30 | -------------------------------------------------------------------------------- /assets/AppAsset.php: -------------------------------------------------------------------------------- 1 | 14 | * @since 2.0 15 | */ 16 | class AppAsset extends AssetBundle 17 | { 18 | public $basePath = '@webroot'; 19 | public $baseUrl = '@web'; 20 | public $css = [ 21 | 'css/main.css', 22 | ]; 23 | public $js = [ 24 | ]; 25 | public $depends = [ 26 | 'yii\web\YiiAsset', 27 | 'yii\bootstrap\BootstrapAsset', 28 | ]; 29 | } 30 | -------------------------------------------------------------------------------- /modules/admin/views/writer/_form.php: -------------------------------------------------------------------------------- 1 | 12 | 13 |
14 | 15 | 16 | 17 | field($model, 'name')->textInput(['maxlength' => 255]) ?> 18 | 19 |
20 | isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 21 |
22 | 23 | 24 | 25 |
26 | -------------------------------------------------------------------------------- /mail/layouts/html.php: -------------------------------------------------------------------------------- 1 | 9 | beginPage() ?> 10 | 11 | 12 | 13 | 14 | <?= Html::encode($this->title) ?> 15 | head() ?> 16 | 17 | 18 | beginBody() ?> 19 | 20 | endBody() ?> 21 | 22 | 23 | endPage() ?> 24 | -------------------------------------------------------------------------------- /widgets/HotArticles.php: -------------------------------------------------------------------------------- 1 | where('status=1')->orderBy(['views' => SORT_DESC])->limit($this->max)->all(); 15 | echo '

热门文章

16 | '; 17 | foreach($hots as $key=>$value) 18 | { 19 | $i=$key+1; 20 | $link=Html::a(Html::encode($value->title), ['post/view','id'=>$value->id]); 21 | echo Html::tag('tr', '"); 22 | } 23 | echo '
'.$i.'. '.$link."
'; 24 | } 25 | } -------------------------------------------------------------------------------- /modules/admin/views/nav/update.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Update {modelClass}: ', [ 11 | 'modelClass' => 'Nav', 12 | ]) . ' ' . $model->name; 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Navs'), 'url' => ['index']]; 14 | $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; 15 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); 16 | ?> 17 | 26 | -------------------------------------------------------------------------------- /modules/admin/views/tag/update.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Update {modelClass}: ', [ 11 | 'modelClass' => 'Tag', 12 | ]) . ' ' . $model->name; 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Tags'), 'url' => ['index']]; 14 | $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; 15 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); 16 | ?> 17 |
18 | 19 |

title) ?>

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

title) ?>

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

title) ?>

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

title) ?>

20 | 21 | render('_form', [ 22 | 'model' => $model, 23 | ]) ?> 24 | 25 |
26 | -------------------------------------------------------------------------------- /modules/admin/views/user/_form.php: -------------------------------------------------------------------------------- 1 | 12 | 13 |
14 | 15 | 16 | 17 | field($model, 'username')->textInput(['maxlength' => 255]) ?> 18 | 19 | field($model, 'email')->textInput(['maxlength' => 255]) ?> 20 | 21 |
22 | isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 23 |
24 | 25 | 26 | 27 |
28 | -------------------------------------------------------------------------------- /modules/admin/views/lookup/update.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Update {modelClass}: ', [ 11 | 'modelClass' => 'Lookup', 12 | ]) . $model->name; 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Lookups'), 'url' => ['index']]; 14 | $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; 15 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); 16 | ?> 17 |
18 | 19 |

title) ?>

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

title) ?>

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

title) ?>

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

title) ?>

20 | 21 | render('_form', [ 22 | 'model' => $model, 23 | ]) ?> 24 | 25 |
26 | -------------------------------------------------------------------------------- /modules/admin/assets/AppAsset.php: -------------------------------------------------------------------------------- 1 | 14 | * @since 2.0 15 | */ 16 | class AppAsset extends AssetBundle 17 | { 18 | public $basePath = '@webroot'; 19 | public $baseUrl = '@web'; 20 | public $css = [ 21 | 'css/site.css','css/bootstrap-formhelpers-countries.flags.css', 22 | ]; 23 | public $js = [ 24 | ]; 25 | public $depends = [ 26 | 'yii\web\YiiAsset', 27 | 'yii\bootstrap\BootstrapAsset', 28 | ]; 29 | } 30 | -------------------------------------------------------------------------------- /modules/admin/views/category/update.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Update {modelClass}: ', [ 11 | 'modelClass' => 'Category', 12 | ]) . $model->name; 13 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Categories'), 'url' => ['index']]; 14 | $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; 15 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); 16 | ?> 17 |
18 | 19 |

title) ?>

20 | 21 | render('_form', [ 22 | 'model' => $model, 23 | ]) ?> 24 | 25 |
26 | -------------------------------------------------------------------------------- /modules/admin/views/tag/_form.php: -------------------------------------------------------------------------------- 1 | 12 | 13 |
14 | 15 | 16 | 17 | field($model, 'name')->textInput(['maxlength' => 128]) ?> 18 | 19 | field($model, 'frequency')->textInput() ?> 20 | 21 |
22 | isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 23 |
24 | 25 | 26 | 27 |
28 | -------------------------------------------------------------------------------- /modules/admin/views/source/_form.php: -------------------------------------------------------------------------------- 1 | 11 | 12 |
13 | 14 | 15 | 16 | field($model, 'name')->textInput(['maxlength' => 255]) ?> 17 | 18 | field($model, 'url')->textInput(['maxlength' => 255]) ?> 19 | 20 |
21 | isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 22 |
23 | 24 | 25 | 26 |
27 | -------------------------------------------------------------------------------- /yii: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | run(); 24 | exit($exitCode); 25 | -------------------------------------------------------------------------------- /modules/admin/views/writer/_search.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 32 | -------------------------------------------------------------------------------- /tests/functional/LoginCept.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that login works'); 7 | 8 | $loginPage = LoginPage::openBy($I); 9 | 10 | $I->see('Login', 'h1'); 11 | 12 | $I->amGoingTo('try to login with empty credentials'); 13 | $loginPage->login('', ''); 14 | $I->expectTo('see validations errors'); 15 | $I->see('Username cannot be blank.'); 16 | $I->see('Password cannot be blank.'); 17 | 18 | $I->amGoingTo('try to login with wrong credentials'); 19 | $loginPage->login('admin', 'wrong'); 20 | $I->expectTo('see validations errors'); 21 | $I->see('Incorrect username or password.'); 22 | 23 | $I->amGoingTo('try to login with correct credentials'); 24 | $loginPage->login('admin', 'admin'); 25 | $I->expectTo('see user info'); 26 | $I->see('Logout (admin)'); 27 | -------------------------------------------------------------------------------- /commands/HelloController.php: -------------------------------------------------------------------------------- 1 | 18 | * @since 2.0 19 | */ 20 | class HelloController extends Controller 21 | { 22 | /** 23 | * This command echoes what you have entered as the message. 24 | * @param string $message the message to be echoed. 25 | */ 26 | public function actionIndex($message = 'hello world') 27 | { 28 | echo $message . "\n"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /views/site/resetPassword.php: -------------------------------------------------------------------------------- 1 | title = 'Reset password'; 11 | $this->params['breadcrumbs'][] = $this->title; 12 | ?> 13 |
14 |

title) ?>

15 | 16 |

Please choose your new password:

17 | 18 |
19 |
20 | 'reset-password-form']); ?> 21 | field($model, 'password')->passwordInput() ?> 22 |
23 | 'btn btn-primary']) ?> 24 |
25 | 26 |
27 |
28 |
29 | -------------------------------------------------------------------------------- /widgets/CategoryWidget.php: -------------------------------------------------------------------------------- 1 | children()->all(); 17 | $menuItems=[]; 18 | foreach($descendants as $key=>$value) 19 | { 20 | $menuItems[] = ['label' => $value->name, 'url' => ['post/index', 'id' => $value->id]]; 21 | } 22 | $menuItems[] = ['label' => '未分类', 'url' => ['post/index', 'id' => 0]]; 23 | echo '

分类

'; 24 | echo Menu::widget([ 25 | 'options' => ['class' => 'side-menu list-unstyled'], 26 | 'items' => $menuItems, 27 | 'encodeLabels' => false 28 | ]); 29 | } 30 | } -------------------------------------------------------------------------------- /modules/admin/views/source/_search.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 34 | -------------------------------------------------------------------------------- /modules/admin/views/tag/_search.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 34 | -------------------------------------------------------------------------------- /config/console.php: -------------------------------------------------------------------------------- 1 | 'basic-console', 10 | 'basePath' => dirname(__DIR__), 11 | 'bootstrap' => ['log'], 12 | 'controllerNamespace' => 'app\commands', 13 | 'extensions' => require(__DIR__ . '/../vendor/yiisoft/extensions.php'), 14 | 'components' => [ 15 | 'cache' => [ 16 | 'class' => 'yii\caching\FileCache', 17 | ], 18 | 'log' => [ 19 | 'targets' => [ 20 | [ 21 | 'class' => 'yii\log\FileTarget', 22 | 'levels' => ['error', 'warning'], 23 | ], 24 | ], 25 | ], 26 | 'db' => $db, 27 | ], 28 | 'params' => $params, 29 | ]; 30 | -------------------------------------------------------------------------------- /modules/admin/models/SignupForm.php: -------------------------------------------------------------------------------- 1 | Yii::t('app', 'Allow Signup'), 33 | 'message' => Yii::t('app', 'Closed Signup display message'), 34 | 'signupVerifyWay' => Yii::t('app', 'Signup Verify Way'), 35 | 'holdUser' => Yii::t('app', 'Hold User Name'), 36 | ]; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /tests/_bootstrap.php: -------------------------------------------------------------------------------- 1 | 255] 31 | ]; 32 | } 33 | 34 | /** 35 | * @inheritdoc 36 | */ 37 | public function attributeLabels() 38 | { 39 | return [ 40 | 'id' => Yii::t('app', 'ID'), 41 | 'name' => Yii::t('app', 'Name'), 42 | ]; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /modules/admin/models/AccessForm.php: -------------------------------------------------------------------------------- 1 | ''] 21 | ]; 22 | } 23 | 24 | public function attributeLabels() 25 | { 26 | return [ 27 | 'ipAccess' => Yii::t('app', 'Allow IP List to access the backend') 28 | ]; 29 | } 30 | 31 | public static function allowIp($ip,$ipFilters) 32 | { 33 | if(empty($ipFilters)){ 34 | return true; 35 | } 36 | 37 | foreach($ipFilters as $filter) 38 | { 39 | if($filter==='*' || $filter===$ip || (($pos=strpos($filter,'*'))!==false && !strncmp($ip,$filter,$pos))){ 40 | return true; 41 | } 42 | } 43 | return false; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /modules/admin/views/lookup/_form.php: -------------------------------------------------------------------------------- 1 | 12 | 13 |
14 | 15 | 16 | 17 | field($model, 'name')->textInput(['maxlength' => 128]) ?> 18 | 19 | field($model, 'code')->textInput() ?> 20 | 21 | field($model, 'type')->textInput(['maxlength' => 128]) ?> 22 | 23 | field($model, 'position')->textInput() ?> 24 | 25 |
26 | isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-primary' : 'btn btn-primary']) ?> 27 |
28 | 29 | 30 | 31 |
32 | -------------------------------------------------------------------------------- /views/site/requestPasswordResetToken.php: -------------------------------------------------------------------------------- 1 | title = 'Request password reset'; 11 | $this->params['breadcrumbs'][] = $this->title; 12 | ?> 13 |
14 |

title) ?>

15 | 16 |

Please fill out your email. A link to reset password will be sent there.

17 | 18 |
19 |
20 | 'request-password-reset-form']); ?> 21 | field($model, 'email') ?> 22 |
23 | 'btn btn-primary']) ?> 24 |
25 | 26 |
27 |
28 |
29 | -------------------------------------------------------------------------------- /models/config.php: -------------------------------------------------------------------------------- 1 | 100] 32 | ]; 33 | } 34 | 35 | /** 36 | * @inheritdoc 37 | */ 38 | public function attributeLabels() 39 | { 40 | return [ 41 | 'key' => Yii::t('app', 'Key'), 42 | 'value' => Yii::t('app', 'Value'), 43 | ]; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /modules/admin/views/default/access.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Backend Access'); 10 | $this->params['breadcrumbs'][] = Yii::t('app', 'Backend Access'); 11 | ?> 12 |
13 |

title) ?>

14 | 'form-siteinfo']); ?> 15 | field($model, 'ipAccess')->textArea(['rows' => 3]) ?> 16 |
17 | 'btn btn-primary', 'name' => 'siteinfo-button']) ?> 18 |
19 | 127.0.0.1
113.139.20. *
Leave blank for all accessible IP

Current ip: {ip}

', ['ip' => Yii::$app->getRequest()->getUserIP()]) ?>
20 | 21 |
22 | 23 | -------------------------------------------------------------------------------- /modules/admin/views/lookup/_search.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 38 | -------------------------------------------------------------------------------- /modules/admin/views/default/email.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Email'); 10 | $this->params['breadcrumbs'][] = Yii::t('app', 'Email'); 11 | ?> 12 |
13 |

title) ?>

14 | 15 | field($model, 'host')->textInput() ?> 16 | field($model, 'port')->textInput() ?> 17 | field($model, 'auth')->inline()->radioList([1 => Yii::t('app', 'yes'), 0 => Yii::t('app', 'no')]) ?> 18 | field($model, 'from')->textInput() ?> 19 | field($model, 'username')->textInput() ?> 20 | field($model, 'password')->textInput() ?> 21 |
22 | 'btn btn-primary']) ?> 23 |
24 | 25 |
26 | 27 | -------------------------------------------------------------------------------- /modules/admin/views/default/login.php: -------------------------------------------------------------------------------- 1 | title = 'Login'; 11 | $this->params['breadcrumbs'][] = $this->title; 12 | ?> 13 | 31 | -------------------------------------------------------------------------------- /models/Source.php: -------------------------------------------------------------------------------- 1 | 255] 32 | ]; 33 | } 34 | 35 | /** 36 | * @inheritdoc 37 | */ 38 | public function attributeLabels() 39 | { 40 | return [ 41 | 'id' => Yii::t('app', 'ID'), 42 | 'name' => Yii::t('app', 'Name'), 43 | 'url' => Yii::t('app', 'Url'), 44 | ]; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/acceptance/LoginCept.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that login works'); 7 | 8 | $loginPage = LoginPage::openBy($I); 9 | 10 | $I->see('Login', 'h1'); 11 | 12 | $I->amGoingTo('try to login with empty credentials'); 13 | $loginPage->login('', ''); 14 | $I->expectTo('see validations errors'); 15 | $I->see('Username cannot be blank.'); 16 | $I->see('Password cannot be blank.'); 17 | 18 | $I->amGoingTo('try to login with wrong credentials'); 19 | $loginPage->login('admin', 'wrong'); 20 | if (method_exists($I, 'wait')) { 21 | $I->wait(3); // only for selenium 22 | } 23 | $I->expectTo('see validations errors'); 24 | $I->see('Incorrect username or password.'); 25 | 26 | $I->amGoingTo('try to login with correct credentials'); 27 | $loginPage->login('admin', 'admin'); 28 | if (method_exists($I, 'wait')) { 29 | $I->wait(3); // only for selenium 30 | } 31 | $I->expectTo('see user info'); 32 | $I->see('Logout (admin)'); 33 | -------------------------------------------------------------------------------- /widgets/RecommendArticles.php: -------------------------------------------------------------------------------- 1 | where('status=1 AND type=3')->orderBy(['views' => SORT_DESC])->limit($this->max)->all(); 15 | 16 | echo '

推荐文章

17 |
    '; 18 | foreach($hots as $key=>$value) 19 | { 20 | $thumbnail=Html::a(''.$value->title.'', ['post/view','id'=>$value->id], ['class' => 'pull-left']); 21 | $link=Html::a(Html::encode($value->title), ['post/view','id'=>$value->id], ['class' => 'media-heading']); 22 | $link=Html::tag('div', $link, ['class' => 'media-body']); 23 | echo Html::tag('li',$thumbnail.$link, ['class' => 'media']); 24 | } 25 | echo '
'; 26 | } 27 | } -------------------------------------------------------------------------------- /modules/admin/views/default/image.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Image'); 10 | $this->params['breadcrumbs'][] = Yii::t('app', 'Image'); 11 | ?> 12 |
13 |

title) ?>

14 | 15 | field($model, 'watermark')->fileInput() ?> 16 | field($model, 'watermarkPosition')->inline()->radioList([1 => Yii::t('app', 'left top'), 2 => Yii::t('app', 'right top'), 3 => Yii::t('app', 'left bottom'), 4 => Yii::t('app', 'right bottom'), 5 => Yii::t('app', 'center')]) ?> 17 | field($model, 'thumbnailWidth')->textInput() ?> 18 | field($model, 'thumbnailheight')->textInput() ?> 19 | field($model, 'thumbQuality')->textInput() ?> 20 |
21 | 'btn btn-primary']) ?> 22 |
23 | 24 |
25 | 26 | -------------------------------------------------------------------------------- /views/site/signup.php: -------------------------------------------------------------------------------- 1 | title = 'Signup'; 11 | $this->params['breadcrumbs'][] = $this->title; 12 | ?> 13 | 31 | -------------------------------------------------------------------------------- /modules/admin/views/default/ftp.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Ftp'); 10 | $this->params['breadcrumbs'][] = Yii::t('app', 'Ftp'); 11 | ?> 12 |
13 |

title) ?>

14 | 15 | field($model, 'ssl')->inline()->radioList([1 => Yii::t('app', 'yes'), 0 => Yii::t('app', 'no')]) ?> 16 | field($model, 'host')->textInput() ?> 17 | field($model, 'port')->textInput() ?> 18 | field($model, 'username')->textInput() ?> 19 | field($model, 'password')->textInput() ?> 20 | field($model, 'pasv')->inline()->radioList([1 => Yii::t('app', 'yes'), 0 => Yii::t('app', 'no')]) ?> 21 | field($model, 'outTime')->textInput() ?> 22 |
23 | 'btn btn-primary']) ?> 24 |
25 | 26 |
27 | 28 | -------------------------------------------------------------------------------- /modules/admin/views/writer/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Writers'); 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_search', ['model' => $searchModel]); ?> 20 | 21 |

22 | 'Writer', 24 | ]), ['create'], ['class' => 'btn btn-success']) ?> 25 |

26 | 27 | $dataProvider, 29 | 'filterModel' => $searchModel, 30 | 'columns' => [ 31 | ['class' => 'yii\grid\SerialColumn'], 32 | 33 | 'id', 34 | 'name', 35 | 36 | ['class' => 'yii\grid\ActionColumn'], 37 | ], 38 | ]); ?> 39 | 40 |
41 | -------------------------------------------------------------------------------- /modules/admin/views/user/view.php: -------------------------------------------------------------------------------- 1 | title = $model->username; 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Users'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 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 | 'username', 35 | 'email:email', 36 | 'role', 37 | 'status', 38 | 'created_at', 39 | 'updated_at', 40 | ], 41 | ]) ?> 42 | 43 |
44 | -------------------------------------------------------------------------------- /tests/acceptance.suite.yml: -------------------------------------------------------------------------------- 1 | # Codeception Test Suite Configuration 2 | 3 | # suite for acceptance tests. 4 | # perform tests in browser using the Selenium-like tools. 5 | # powered by Mink (http://mink.behat.org). 6 | # (tip: that's what your customer will see). 7 | # (tip: test your ajax and javascript by one of Mink drivers). 8 | 9 | # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. 10 | 11 | class_name: WebGuy 12 | modules: 13 | enabled: 14 | - WebHelper 15 | - PhpBrowser 16 | # you can use WebDriver instead of PhpBrowser to test javascript and ajax. 17 | # This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium 18 | # "restart" option is used by the WebDriver to start each time per test-file new session and cookies, 19 | # it is useful if you want to login in your app in each test. 20 | # - WebDriver 21 | config: 22 | PhpBrowser: 23 | url: 'http://localhost:8080' 24 | # WebDriver: 25 | # url: 'http://localhost' 26 | # browser: firefox 27 | # restart: true 28 | -------------------------------------------------------------------------------- /modules/admin/views/tag/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Tags'); 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_search', ['model' => $searchModel]); ?> 20 | 21 |

22 | 'Tag', 24 | ]), ['create'], ['class' => 'btn btn-success']) ?> 25 |

26 | 27 | $dataProvider, 29 | 'filterModel' => $searchModel, 30 | 'columns' => [ 31 | ['class' => 'yii\grid\SerialColumn'], 32 | 33 | 'id', 34 | 'name', 35 | 'frequency', 36 | 37 | ['class' => 'yii\grid\ActionColumn'], 38 | ], 39 | ]); ?> 40 | 41 |
42 | -------------------------------------------------------------------------------- /modules/admin/views/source/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Sources'); 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_search', ['model' => $searchModel]); ?> 20 | 21 |

22 | 'Source', 24 | ]), ['create'], ['class' => 'btn btn-success']) ?> 25 |

26 | 27 | $dataProvider, 29 | 'filterModel' => $searchModel, 30 | 'columns' => [ 31 | ['class' => 'yii\grid\SerialColumn'], 32 | 33 | 'id', 34 | 'name', 35 | 'url:url', 36 | 37 | ['class' => 'yii\grid\ActionColumn'], 38 | ], 39 | ]); ?> 40 | 41 |
42 | -------------------------------------------------------------------------------- /modules/admin/views/writer/view.php: -------------------------------------------------------------------------------- 1 | title = $model->name; 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Writers'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 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 | 'name', 35 | ], 36 | ]) ?> 37 | 38 |
39 | -------------------------------------------------------------------------------- /models/UserForm.php: -------------------------------------------------------------------------------- 1 | 255], 27 | ['avatar', 'file', 'skipOnEmpty' => true, 'types'=>'jpg, gif, png', 'maxSize'=>2097152, 'tooBig' => Yii::t('app','{file} files can not exceed 2MB. Please upload a small bit of the file.')], 28 | ]; 29 | } 30 | 31 | /** 32 | * @inheritdoc 33 | */ 34 | public function attributeLabels() 35 | { 36 | return [ 37 | 'email' => Yii::t('app', 'Email'), 38 | 'username' => Yii::t('app', 'Username'), 39 | 'avatar' => Yii::t('app', 'Avatar'), 40 | ]; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /modules/admin/views/nav/_search.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 44 | -------------------------------------------------------------------------------- /modules/admin/views/link/_search.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 44 | -------------------------------------------------------------------------------- /modules/admin/views/tag/view.php: -------------------------------------------------------------------------------- 1 | title = $model->name; 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Tags'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 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 | 'name', 35 | 'frequency', 36 | ], 37 | ]) ?> 38 | 39 |
40 | -------------------------------------------------------------------------------- /components/Controller.php: -------------------------------------------------------------------------------- 1 | config->get('siteInfo'); 16 | $route=Yii::$app->controller->id.'/'.$action->id; 17 | if(isset($siteInfo) &&!$siteInfo['closed'] && $this->isAdmin() && $route!=='site/error' && $route!=='site/login' && $route!=='site/logout'){ 18 | throw new ForbiddenHttpException(Yii::t('app', $siteInfo['message']?$siteInfo['message']:'Website was temporarily in closed.')); 19 | } 20 | return true; 21 | } else { 22 | return false; 23 | } 24 | } 25 | 26 | public function isAdmin() 27 | { 28 | if (!Yii::$app->user->isGuest) { 29 | return !in_array(Yii::$app->user->identity->username, Yii::$app->params['admin']); 30 | }else{ 31 | return false; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /modules/admin/views/lookup/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Lookups'); 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_search', ['model' => $searchModel]); ?> 20 | 21 |

22 | 'Lookup', 24 | ]), ['create'], ['class' => 'btn btn-success']) ?> 25 |

26 | 27 | $dataProvider, 29 | 'filterModel' => $searchModel, 30 | 'columns' => [ 31 | ['class' => 'yii\grid\SerialColumn'], 32 | 33 | 'id', 34 | 'name', 35 | 'code', 36 | 'type', 37 | 'position', 38 | 39 | ['class' => 'yii\grid\ActionColumn'], 40 | ], 41 | ]); ?> 42 | 43 |
44 | -------------------------------------------------------------------------------- /modules/admin/views/source/view.php: -------------------------------------------------------------------------------- 1 | title = $model->name; 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Sources'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 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 | 'name', 35 | 'url:url', 36 | ], 37 | ]) ?> 38 | 39 |
40 | -------------------------------------------------------------------------------- /models/search/WriterSearch.php: -------------------------------------------------------------------------------- 1 | $query, 35 | ]); 36 | 37 | if (!($this->load($params) && $this->validate())) { 38 | return $dataProvider; 39 | } 40 | 41 | $query->andFilterWhere([ 42 | 'id' => $this->id, 43 | ]); 44 | 45 | $query->andFilterWhere(['like', 'name', $this->name]); 46 | 47 | return $dataProvider; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /modules/admin/views/lookup/view.php: -------------------------------------------------------------------------------- 1 | title = $model->name; 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Lookups'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 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 | 'name', 35 | 'code', 36 | 'type', 37 | 'position', 38 | ], 39 | ]) ?> 40 | 41 |
42 | -------------------------------------------------------------------------------- /modules/admin/views/user/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Users'); 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_search', ['model' => $searchModel]); ?> 20 | 21 |

22 | 'User', 24 | ]), ['create'], ['class' => 'btn btn-success']) ?> 25 |

26 | 27 | $dataProvider, 29 | 'filterModel' => $searchModel, 30 | 'columns' => [ 31 | ['class' => 'yii\grid\SerialColumn'], 32 | 33 | 'id', 34 | 'avatar:image', 35 | 'username', 36 | // 'auth_key', 37 | // 'password_hash', 38 | // 'password_reset_token', 39 | 'email:email', 40 | 'role', 41 | 'status', 42 | 'created_at', 43 | 'updated_at', 44 | 45 | ['class' => 'yii\grid\ActionColumn'], 46 | ], 47 | ]); ?> 48 | 49 |
50 | -------------------------------------------------------------------------------- /modules/admin/views/nav/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Navs'); 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 | 46 | -------------------------------------------------------------------------------- /modules/admin/views/category/_search.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 46 | -------------------------------------------------------------------------------- /modules/admin/views/user/_search.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 48 | -------------------------------------------------------------------------------- /modules/admin/views/page/_search.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 46 | -------------------------------------------------------------------------------- /modules/admin/views/comment/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Comments'); 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_search', ['model' => $searchModel]); ?> 20 | 21 | $dataProvider, 23 | 'filterModel' => $searchModel, 24 | 'columns' => [ 25 | ['class' => 'yii\grid\SerialColumn'], 26 | 27 | 'id', 28 | 'parent_id', 29 | 'type', 30 | 'content:ntext', 31 | 'up', 32 | 'down', 33 | 'status', 34 | 'create_time:datetime', 35 | 'author', 36 | 'email:email', 37 | 'url:url', 38 | 'ip', 39 | 'post_id', 40 | 'user_id', 41 | 42 | ['class' => 'yii\grid\ActionColumn'], 43 | ], 44 | ]); ?> 45 | 46 |
47 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | This folder contains various tests for the basic application. 2 | These tests are developed with [Codeception PHP Testing Framework](http://codeception.com/). 3 | 4 | After creating the basic application, follow these steps to prepare for the tests: 5 | 6 | 1. Install additional composer packages: 7 | 8 | ``` 9 | php composer.phar require --dev "codeception/codeception: 1.8.*@dev" "codeception/specify: *" "codeception/verify: *" 10 | ``` 11 | 2. In the file `_bootstrap.php`, modify the definition of the constant `TEST_ENTRY_URL` so 12 | that it points to the correct entry script URL. 13 | 3. Go to the application base directory and build the test suites: 14 | 15 | ``` 16 | vendor/bin/codecept build 17 | ``` 18 | 19 | Now you can run the tests with the following commands: 20 | 21 | ``` 22 | # run all available tests 23 | vendor/bin/codecept run 24 | # run acceptance tests 25 | vendor/bin/codecept run acceptance 26 | # run functional tests 27 | vendor/bin/codecept run functional 28 | # run unit tests 29 | vendor/bin/codecept run unit 30 | ``` 31 | 32 | Please refer to [Codeception tutorial](http://codeception.com/docs/01-Introduction) for 33 | more details about writing and running acceptance, functional and unit tests. 34 | -------------------------------------------------------------------------------- /models/search/TagSearch.php: -------------------------------------------------------------------------------- 1 | $query, 35 | ]); 36 | 37 | if (!($this->load($params) && $this->validate())) { 38 | return $dataProvider; 39 | } 40 | 41 | $query->andFilterWhere([ 42 | 'id' => $this->id, 43 | 'frequency' => $this->frequency, 44 | ]); 45 | 46 | $query->andFilterWhere(['like', 'name', $this->name]); 47 | 48 | return $dataProvider; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /components/AutocompleteAction.php: -------------------------------------------------------------------------------- 1 | tableName === null) { 23 | throw new InvalidConfigException(get_class($this) . '::$tableName must be defined.'); 24 | } 25 | if($this->field === null) { 26 | throw new InvalidConfigException(get_class($this) . '::$field must be defined.'); 27 | } 28 | parent::init(); 29 | } 30 | 31 | public function run() 32 | { 33 | $value = $this->searchPrefix . $_GET[$this->clientIdGetParamName] . $this->searchSuffix; 34 | $rows = \Yii::$app->db 35 | ->createCommand("SELECT {$this->field} AS value FROM {$this->tableName} WHERE {$this->field} LIKE :field ORDER BY {$this->field}") 36 | ->bindValues([':field' => $value]) 37 | ->queryAll(); 38 | 39 | echo Json::encode($rows); 40 | } 41 | } -------------------------------------------------------------------------------- /modules/admin/views/nav/view.php: -------------------------------------------------------------------------------- 1 | title = $model->name; 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Navs'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 | 45 | -------------------------------------------------------------------------------- /views/site/login.php: -------------------------------------------------------------------------------- 1 | title = 'Login'; 11 | $this->params['breadcrumbs'][] = $this->title; 12 | ?> 13 | -------------------------------------------------------------------------------- /models/search/SourceSearch.php: -------------------------------------------------------------------------------- 1 | $query, 35 | ]); 36 | 37 | if (!($this->load($params) && $this->validate())) { 38 | return $dataProvider; 39 | } 40 | 41 | $query->andFilterWhere([ 42 | 'id' => $this->id, 43 | ]); 44 | 45 | $query->andFilterWhere(['like', 'name', $this->name]) 46 | ->andFilterWhere(['like', 'url', $this->url]); 47 | 48 | return $dataProvider; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /modules/admin/views/category/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Categories'); 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | 19 | render('_search', ['model' => $searchModel]); ?> 20 | 21 |

22 | 'Category', 24 | ]), ['create'], ['class' => 'btn btn-success']) ?> 25 |

26 | 27 | $dataProvider, 29 | 'filterModel' => $searchModel, 30 | 'columns' => [ 31 | ['class' => 'yii\grid\SerialColumn'], 32 | 33 | 'id', 34 | 'root', 35 | 'lft', 36 | 'rgt', 37 | 'level', 38 | 'name', 39 | 'summary', 40 | 'created_at', 41 | 'updated_at', 42 | 43 | ['class' => 'yii\grid\ActionColumn'], 44 | ], 45 | ]); ?> 46 | 47 |
48 | -------------------------------------------------------------------------------- /modules/admin/views/link/view.php: -------------------------------------------------------------------------------- 1 | title = $model->name; 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Links'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 | 45 | -------------------------------------------------------------------------------- /web/js/jquery.cookie-1.4.1.min.js: -------------------------------------------------------------------------------- 1 | /*! jquery.cookie v1.4.1 | MIT */ 2 | !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?a(require("jquery")):a(jQuery)}(function(a){function b(a){return h.raw?a:encodeURIComponent(a)}function c(a){return h.raw?a:decodeURIComponent(a)}function d(a){return b(h.json?JSON.stringify(a):String(a))}function e(a){0===a.indexOf('"')&&(a=a.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\"));try{return a=decodeURIComponent(a.replace(g," ")),h.json?JSON.parse(a):a}catch(b){}}function f(b,c){var d=h.raw?b:e(b);return a.isFunction(c)?c(d):d}var g=/\+/g,h=a.cookie=function(e,g,i){if(void 0!==g&&!a.isFunction(g)){if(i=a.extend({},h.defaults,i),"number"==typeof i.expires){var j=i.expires,k=i.expires=new Date;k.setTime(+k+864e5*j)}return document.cookie=[b(e),"=",d(g),i.expires?"; expires="+i.expires.toUTCString():"",i.path?"; path="+i.path:"",i.domain?"; domain="+i.domain:"",i.secure?"; secure":""].join("")}for(var l=e?void 0:{},m=document.cookie?document.cookie.split("; "):[],n=0,o=m.length;o>n;n++){var p=m[n].split("="),q=c(p.shift()),r=p.join("=");if(e&&e===q){l=f(r,g);break}e||void 0===(r=f(r))||(l[q]=r)}return l};h.defaults={},a.removeCookie=function(b,c){return void 0===a.cookie(b)?!1:(a.cookie(b,"",a.extend({},c,{expires:-1})),!a.cookie(b))}}); -------------------------------------------------------------------------------- /modules/admin/views/page/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Pages'); 13 | $this->params['breadcrumbs'][] = $this->title; 14 | ?> 15 |
16 | 17 |

title) ?>

18 | render('_search', ['model' => $searchModel]); ?> 19 | 20 |

21 | 'Page', 23 | ]), ['create'], ['class' => 'btn btn-success']) ?> 24 |

25 | 26 | $dataProvider, 28 | 'filterModel' => $searchModel, 29 | 'columns' => [ 30 | ['class' => 'yii\grid\SerialColumn'], 31 | 32 | 'id', 33 | 'name', 34 | 'title', 35 | // 'content:ntext', 36 | // 'seo_title', 37 | // 'seo_keywords', 38 | // 'seo_description', 39 | // 'created_at', 40 | // 'updated_at', 41 | 42 | ['class' => 'yii\grid\ActionColumn'], 43 | ], 44 | ]); ?> 45 | 46 |
47 | -------------------------------------------------------------------------------- /modules/admin/views/comment/_form.php: -------------------------------------------------------------------------------- 1 | 12 | 13 |
14 | 15 | 16 | 17 | field($model, 'type')->dropDownList(['1' => Yii::t('app', 'Article'), '2' => Yii::t('app', 'Rom')]) ?> 18 | 19 | field($model, 'content')->textarea(['rows' => 6]) ?> 20 | 21 | field($model, 'author')->textInput(['maxlength' => 128]) ?> 22 | 23 | field($model, 'email')->textInput(['maxlength' => 128]) ?> 24 | 25 | field($model, 'url')->textInput(['maxlength' => 255]) ?> 26 | 27 | field($model, 'up')->textInput(['maxlength' => 255]) ?> 28 | 29 | field($model, 'down')->textInput(['maxlength' => 255]) ?> 30 | 31 | field($model, 'status')->textInput(['maxlength' => 255]) ?> 32 | 33 |
34 | isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 35 |
36 | 37 | 38 | 39 |
40 | -------------------------------------------------------------------------------- /modules/admin/views/category/view.php: -------------------------------------------------------------------------------- 1 | title = $model->name; 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Categories'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 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 | 'root', 35 | 'lft', 36 | 'rgt', 37 | 'level', 38 | 'name', 39 | 'summary', 40 | 'created_at', 41 | 'updated_at', 42 | ], 43 | ]) ?> 44 | 45 |
46 | -------------------------------------------------------------------------------- /modules/admin/views/page/view.php: -------------------------------------------------------------------------------- 1 | title = $model->name; 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Pages'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 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 | 'name', 35 | 'title', 36 | 'content:ntext', 37 | 'seo_title', 38 | 'seo_keywords', 39 | 'seo_description', 40 | 'created_at', 41 | 'updated_at', 42 | ], 43 | ]) ?> 44 | 45 |
46 | -------------------------------------------------------------------------------- /views/user/view.php: -------------------------------------------------------------------------------- 1 | 7 | 8 |
9 |
10 |

个人中心

11 |
  • 资料修改
12 |
13 |
14 | ['enctype'=>'multipart/form-data'] 16 | ]); ?> 17 | avatar) :?> 18 | 19 | 20 | 21 | 22 | field($userform, 'avatar')->fileInput() ?> 23 | field($userform, 'username')->textInput() ?> 24 | field($userform, 'email')->textInput() ?> 25 | field($userform, 'password')->passwordInput() ?> 26 |
27 | isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-primary' : 'btn btn-primary']) ?> 28 |
29 | 30 |
31 |
32 | 33 |
34 |
35 | -------------------------------------------------------------------------------- /modules/admin/models/InfoForm.php: -------------------------------------------------------------------------------- 1 | Yii::t('app', 'Site name'), 39 | 'siteUrl' => Yii::t('app', 'Site url'), 40 | 'siteTitle' => Yii::t('app', 'Site title'), 41 | 'siteKeywords' => Yii::t('app', 'Site keywords'), 42 | 'siteDescription' => Yii::t('app', 'Site description'), 43 | 'adminEmail' => Yii::t('app', 'Admin email'), 44 | 'siteCopyright' => Yii::t('app', 'Site copyright'), 45 | 'statCode' => Yii::t('app', 'Site code'), 46 | 'closed' => Yii::t('app', 'Site closed'), 47 | 'message' => Yii::t('app', 'Site closed display message'), 48 | ]; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /modules/admin/views/comment/_search.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 54 | -------------------------------------------------------------------------------- /modules/admin/views/comment/view.php: -------------------------------------------------------------------------------- 1 | title = $model->id; 12 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Comments'), 'url' => ['index']]; 13 | $this->params['breadcrumbs'][] = $this->title; 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 | 'parent_id', 35 | 'type', 36 | 'content:ntext', 37 | 'up', 38 | 'down', 39 | 'status', 40 | 'create_time:datetime', 41 | 'author', 42 | 'email:email', 43 | 'url:url', 44 | 'ip', 45 | 'post_id', 46 | 'user_id', 47 | ], 48 | ]) ?> 49 | 50 |
51 | -------------------------------------------------------------------------------- /models/search/NavSearch.php: -------------------------------------------------------------------------------- 1 | $query, 35 | ]); 36 | 37 | if (!($this->load($params) && $this->validate())) { 38 | return $dataProvider; 39 | } 40 | 41 | $query->andFilterWhere([ 42 | 'id' => $this->id, 43 | 'root' => $this->root, 44 | 'lft' => $this->lft, 45 | 'rgt' => $this->rgt, 46 | 'level' => $this->level, 47 | 'target' => $this->target, 48 | ]); 49 | 50 | $query->andFilterWhere(['like', 'name', $this->name]) 51 | ->andFilterWhere(['like', 'url', $this->url]); 52 | 53 | return $dataProvider; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /modules/admin/views/default/index.php: -------------------------------------------------------------------------------- 1 | title = 'Overview - DCMS2.0 - backend'; 14 | ?> 15 | 16 |
17 |
18 |

19 |
20 |
21 | 文章数量:count()?> 评论数量:count()?> 分类数量:count()?> 单页数量:count()?> 用户:count()?> 22 |
23 |
24 | 25 |
26 |
27 |

最新评论!

28 |
29 |
30 | 35 |
36 |
37 | 38 |
39 |
40 |

system

41 |
42 |
43 | 44 | powerby: DCMS v2.0
45 | author: ff
46 | official: website
47 |
48 |
49 | 50 | -------------------------------------------------------------------------------- /views/page/view.php: -------------------------------------------------------------------------------- 1 | title = $model->seo_title?$model->seo_title:$model->title; 9 | $this->registerMetaTag(['name' => 'keywords', 'content' => $model->seo_keywords?$model->seo_keywords:""]); 10 | $this->registerMetaTag(['name' => 'description', 'content' => $model->seo_description?$model->seo_description:""]); 11 | ?> 12 |
13 |
14 |

页面

15 | ['class' => 'side-menu list-unstyled'], 17 | 'items' => $menuItems, 18 | 'encodeLabels' => false 19 | ]);?> 20 |
21 |
22 |
23 |

title) ?>

24 | content ?> 25 |
26 |
27 |
28 |
29 | 10]) ?> 30 |
31 | 10]) ?> 32 |
33 |

Tags

34 | Yii::$app->params['tagCloudCount']]) ?> 35 |
36 | 10]) ?> 37 |
38 |
39 |
40 | -------------------------------------------------------------------------------- /models/ResetPasswordForm.php: -------------------------------------------------------------------------------- 1 | _user = User::findByPasswordResetToken($token); 34 | if (!$this->_user) { 35 | throw new InvalidParamException('Wrong password reset token.'); 36 | } 37 | parent::__construct($config); 38 | } 39 | 40 | /** 41 | * @inheritdoc 42 | */ 43 | public function rules() 44 | { 45 | return [ 46 | ['password', 'required'], 47 | ['password', 'string', 'min' => 6], 48 | ]; 49 | } 50 | 51 | /** 52 | * Resets password. 53 | * 54 | * @return boolean if password was reset. 55 | */ 56 | public function resetPassword() 57 | { 58 | $user = $this->_user; 59 | $user->password = $this->password; 60 | $user->removePasswordResetToken(); 61 | return $user->save(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /models/search/CategorySearch.php: -------------------------------------------------------------------------------- 1 | $query, 35 | ]); 36 | 37 | if (!($this->load($params) && $this->validate())) { 38 | return $dataProvider; 39 | } 40 | 41 | $query->andFilterWhere([ 42 | 'id' => $this->id, 43 | 'root' => $this->root, 44 | 'lft' => $this->lft, 45 | 'rgt' => $this->rgt, 46 | 'level' => $this->level, 47 | 'created_at' => $this->created_at, 48 | 'updated_at' => $this->updated_at, 49 | ]); 50 | 51 | $query->andFilterWhere(['like', 'name', $this->name]) 52 | ->andFilterWhere(['like', 'summary', $this->summary]); 53 | 54 | return $dataProvider; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /modules/admin/views/default/signup.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Signup'); 10 | $this->params['breadcrumbs'][] = Yii::t('app', 'Signup'); 11 | $signup=Yii::$app->config->get("signup"); 12 | if (isset($signup["allowSignup"]) && $signup["allowSignup"]==1) { 13 | $this->registerJs('jQuery(".field-signupform-message").hide();'); 14 | } 15 | $this->registerJs(' 16 | jQuery("input[name=\"SignupForm[allowSignup]\"][checked]").val(); 17 | jQuery(document).on("click", "input[name=\"SignupForm[allowSignup]\"]",function(){ if (jQuery("input[name=\"SignupForm[allowSignup]\"]:checked").val()==1) {jQuery(".field-signupform-message").hide();}if (jQuery("input[name=\"SignupForm[allowSignup]\"]:checked").val()==0) {jQuery(".field-signupform-message").show();} 18 | }); 19 | '); 20 | ?> 21 |
22 |

title) ?>

23 | 24 | field($model, 'allowSignup')->inline()->radioList([1 => Yii::t('app', 'open'), 0 => Yii::t('app', 'close')]) ?> 25 | field($model, 'message')->textArea(['rows' => 3]) ?> 26 | field($model, 'holdUser')->textArea(['rows' => 3]) ?> 27 | field($model, 'signupVerifyWay')->radioList([1 => Yii::t('app', 'Normal'), 2 => Yii::t('app', 'Approve'), 3 => Yii::t('app', 'Verify By Email')]) ?> 28 |
29 | 'btn btn-primary']) ?> 30 |
31 | 32 |
33 | 34 | -------------------------------------------------------------------------------- /tests/functional/ContactCept.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that contact works'); 7 | 8 | $contactPage = ContactPage::openBy($I); 9 | 10 | $I->see('Contact', 'h1'); 11 | 12 | $I->amGoingTo('submit contact form with no data'); 13 | $contactPage->submit([]); 14 | $I->expectTo('see validations errors'); 15 | $I->see('Contact', 'h1'); 16 | $I->see('Name cannot be blank'); 17 | $I->see('Email cannot be blank'); 18 | $I->see('Subject cannot be blank'); 19 | $I->see('Body cannot be blank'); 20 | $I->see('The verification code is incorrect'); 21 | 22 | $I->amGoingTo('submit contact form with not correct email'); 23 | $contactPage->submit([ 24 | 'name' => 'tester', 25 | 'email' => 'tester.email', 26 | 'subject' => 'test subject', 27 | 'body' => 'test content', 28 | 'verifyCode' => 'testme', 29 | ]); 30 | $I->expectTo('see that email adress is wrong'); 31 | $I->dontSee('Name cannot be blank', '.help-inline'); 32 | $I->see('Email is not a valid email address.'); 33 | $I->dontSee('Subject cannot be blank', '.help-inline'); 34 | $I->dontSee('Body cannot be blank', '.help-inline'); 35 | $I->dontSee('The verification code is incorrect', '.help-inline'); 36 | 37 | $I->amGoingTo('submit contact form with correct data'); 38 | $contactPage->submit([ 39 | 'name' => 'tester', 40 | 'email' => 'tester@example.com', 41 | 'subject' => 'test subject', 42 | 'body' => 'test content', 43 | 'verifyCode' => 'testme', 44 | ]); 45 | $I->dontSeeElement('#contact-form'); 46 | $I->see('Thank you for contacting us. We will respond to you as soon as possible.'); 47 | -------------------------------------------------------------------------------- /modules/admin/views/link/_form.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 44 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yiisoft/yii2-app-basic", 3 | "description": "Yii 2 Basic Application Template", 4 | "keywords": ["yii2", "framework", "basic", "application template"], 5 | "homepage": "http://www.yiiframework.com/", 6 | "type": "project", 7 | "license": "BSD-3-Clause", 8 | "support": { 9 | "issues": "https://github.com/yiisoft/yii2/issues?state=open", 10 | "forum": "http://www.yiiframework.com/forum/", 11 | "wiki": "http://www.yiiframework.com/wiki/", 12 | "irc": "irc://irc.freenode.net/yii", 13 | "source": "https://github.com/yiisoft/yii2" 14 | }, 15 | "minimum-stability": "dev", 16 | "require": { 17 | "php": ">=5.4.0", 18 | "yiisoft/yii2": "*", 19 | "yiisoft/yii2-bootstrap": "*", 20 | "yiisoft/yii2-swiftmailer": "*", 21 | "yiisoft/yii2-imagine": "*", 22 | "yiisoft/yii2-elasticsearch": "*", 23 | "yiisoft/yii2-authclient": "*", 24 | "yiisoft/yii2-jui": "*", 25 | "djfly/kindeditor": "*" 26 | }, 27 | "require-dev": { 28 | "yiisoft/yii2-codeception": "*", 29 | "yiisoft/yii2-debug": "*", 30 | "yiisoft/yii2-gii": "*" 31 | }, 32 | "suggest": { 33 | "codeception/codeception": "Codeception, 1.8.*@dev is currently works well with Yii.", 34 | "codeception/specify": "BDD style code blocks for PHPUnit and Codeception", 35 | "codeception/verify": "BDD Assertions for PHPUnit and Codeception" 36 | }, 37 | "scripts": { 38 | "post-create-project-cmd": [ 39 | "yii\\composer\\Installer::setPermission" 40 | ] 41 | }, 42 | "config": { 43 | "process-timeout": 1800 44 | }, 45 | "extra": { 46 | "writable": [ 47 | "runtime", 48 | "web/assets" 49 | ], 50 | "executable": [ 51 | "yii" 52 | ] 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /modules/admin/Module.php: -------------------------------------------------------------------------------- 1 | controller->id.'/'.$action->id; 24 | 25 | if (!$this->checkAccess() && $route!=='site/error' && $route!=='site/login' && $route!=='site/logout') { 26 | throw new ForbiddenHttpException(Yii::t('app', 'You are not allowed to access this page.')); 27 | } else { 28 | $this->checkAccess(); 29 | return parent::beforeAction($action); 30 | } 31 | } 32 | 33 | /** 34 | * @return boolean whether the module can be accessed by the current user 35 | */ 36 | protected function checkAccess() 37 | { 38 | $ipAccess = Yii::$app->config->get('ipAccess'); 39 | if (!empty($ipAccess)) { 40 | $this->allowedIPs=explode("\r\n",$ipAccess); 41 | $ip = Yii::$app->getRequest()->getUserIP(); 42 | foreach ($this->allowedIPs as $filter) { 43 | if ($filter === '*' || $filter === $ip || (($pos = strpos($filter, '*')) !== false && !strncmp($ip, $filter, $pos))) { 44 | return true; 45 | } 46 | } 47 | }else{ 48 | return true; 49 | } 50 | 51 | return false; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /models/Link.php: -------------------------------------------------------------------------------- 1 | 255], 38 | ['logo', 'file', 'skipOnEmpty' => true, 'types'=>'jpg, gif, png', 'maxSize'=>2097152, 'tooBig' => Yii::t('app','{file} files can not exceed 2MB. Please upload a small bit of the file.')], 39 | 40 | ]; 41 | } 42 | 43 | /** 44 | * @inheritdoc 45 | */ 46 | public function attributeLabels() 47 | { 48 | return [ 49 | 'id' => Yii::t('app', 'ID'), 50 | 'name' => Yii::t('app', 'Name'), 51 | 'url' => Yii::t('app', 'Url'), 52 | 'logo' => Yii::t('app', 'Logo'), 53 | 'position' => Yii::t('app', 'Position'), 54 | 'target' => Yii::t('app', 'Target'), 55 | 'type' => Yii::t('app', 'Type'), 56 | 'visible' => Yii::t('app', 'Visible'), 57 | ]; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /models/PasswordResetRequestForm.php: -------------------------------------------------------------------------------- 1 | 'trim'], 21 | ['email', 'required'], 22 | ['email', 'email'], 23 | ['email', 'exist', 24 | 'targetClass' => '\app\models\User', 25 | 'filter' => ['status' => User::STATUS_ACTIVE], 26 | 'message' => 'There is no user with such email.' 27 | ], 28 | ]; 29 | } 30 | 31 | /** 32 | * Sends an email with a link, for resetting the password. 33 | * 34 | * @return boolean whether the email was send 35 | */ 36 | public function sendEmail() 37 | { 38 | /** @var User $user */ 39 | $user = User::findOne([ 40 | 'status' => User::STATUS_ACTIVE, 41 | 'email' => $this->email, 42 | ]); 43 | 44 | if ($user) { 45 | $user->generatePasswordResetToken(); 46 | if ($user->save()) { 47 | return \Yii::$app->mail->compose('passwordResetToken', ['user' => $user]) 48 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot']) 49 | ->setTo($this->email) 50 | ->setSubject('Password reset for ' . \Yii::$app->name) 51 | ->send(); 52 | } 53 | } 54 | 55 | return false; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /modules/admin/views/link/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Links'); 15 | $this->params['breadcrumbs'][] = $this->title; 16 | ?> 17 | 57 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The Yii framework is free software. It is released under the terms of 2 | the following BSD License. 3 | 4 | Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com) 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | * Neither the name of Yii Software LLC nor the names of its 18 | contributors may be used to endorse or promote products derived 19 | from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /tests/acceptance/ContactCept.php: -------------------------------------------------------------------------------- 1 | wantTo('ensure that contact works'); 7 | 8 | $contactPage = ContactPage::openBy($I); 9 | 10 | $I->see('Contact', 'h1'); 11 | 12 | $I->amGoingTo('submit contact form with no data'); 13 | $contactPage->submit([]); 14 | $I->expectTo('see validations errors'); 15 | $I->see('Contact', 'h1'); 16 | $I->see('Name cannot be blank'); 17 | $I->see('Email cannot be blank'); 18 | $I->see('Subject cannot be blank'); 19 | $I->see('Body cannot be blank'); 20 | $I->see('The verification code is incorrect'); 21 | 22 | $I->amGoingTo('submit contact form with not correct email'); 23 | $contactPage->submit([ 24 | 'name' => 'tester', 25 | 'email' => 'tester.email', 26 | 'subject' => 'test subject', 27 | 'body' => 'test content', 28 | 'verifyCode' => 'testme', 29 | ]); 30 | $I->expectTo('see that email adress is wrong'); 31 | $I->dontSee('Name cannot be blank', '.help-inline'); 32 | $I->see('Email is not a valid email address.'); 33 | $I->dontSee('Subject cannot be blank', '.help-inline'); 34 | $I->dontSee('Body cannot be blank', '.help-inline'); 35 | $I->dontSee('The verification code is incorrect', '.help-inline'); 36 | 37 | $I->amGoingTo('submit contact form with correct data'); 38 | $contactPage->submit([ 39 | 'name' => 'tester', 40 | 'email' => 'tester@example.com', 41 | 'subject' => 'test subject', 42 | 'body' => 'test content', 43 | 'verifyCode' => 'testme', 44 | ]); 45 | if (method_exists($I, 'wait')) { 46 | $I->wait(3); // only for selenium 47 | } 48 | $I->dontSeeElement('#contact-form'); 49 | $I->see('Thank you for contacting us. We will respond to you as soon as possible.'); 50 | -------------------------------------------------------------------------------- /models/search/PageSearch.php: -------------------------------------------------------------------------------- 1 | $query, 35 | ]); 36 | 37 | if (!($this->load($params) && $this->validate())) { 38 | return $dataProvider; 39 | } 40 | 41 | $query->andFilterWhere([ 42 | 'id' => $this->id, 43 | 'created_at' => $this->created_at, 44 | 'updated_at' => $this->updated_at, 45 | ]); 46 | 47 | $query->andFilterWhere(['like', 'name', $this->name]) 48 | ->andFilterWhere(['like', 'title', $this->title]) 49 | ->andFilterWhere(['like', 'content', $this->content]) 50 | ->andFilterWhere(['like', 'seo_title', $this->seo_title]) 51 | ->andFilterWhere(['like', 'seo_keywords', $this->seo_keywords]) 52 | ->andFilterWhere(['like', 'seo_description', $this->seo_description]); 53 | 54 | return $dataProvider; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /models/Nav.php: -------------------------------------------------------------------------------- 1 | NestedSetBehavior::className(), 29 | 'hasManyRoots' => true 30 | ], 31 | ]; 32 | } 33 | 34 | /** 35 | * @inheritdoc 36 | */ 37 | public static function tableName() 38 | { 39 | return '{{%nav}}'; 40 | } 41 | 42 | /** 43 | * @inheritdoc 44 | */ 45 | public function rules() 46 | { 47 | return [ 48 | [['target', 'parent'], 'integer'], 49 | [['name'], 'required'], 50 | [['name', 'url'], 'string', 'max' => 255] 51 | ]; 52 | } 53 | 54 | /** 55 | * @inheritdoc 56 | */ 57 | public function attributeLabels() 58 | { 59 | return [ 60 | 'id' => Yii::t('app', 'ID'), 61 | 'root' => Yii::t('app', 'Root'), 62 | 'lft' => Yii::t('app', 'Lft'), 63 | 'rgt' => Yii::t('app', 'Rgt'), 64 | 'level' => Yii::t('app', 'Level'), 65 | 'name' => Yii::t('app', 'Name'), 66 | 'url' => Yii::t('app', 'Url'), 67 | 'target' => Yii::t('app', 'Target'), 68 | 'Parent' => Yii::t('app', 'Parent'), 69 | ]; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /models/ContactForm.php: -------------------------------------------------------------------------------- 1 | 'Verification Code', 41 | ]; 42 | } 43 | 44 | /** 45 | * Sends an email to the specified email address using the information collected by this model. 46 | * @param string $email the target email address 47 | * @return boolean whether the model passes validation 48 | */ 49 | public function contact($email) 50 | { 51 | if ($this->validate()) { 52 | Yii::$app->mail->compose() 53 | ->setTo($email) 54 | ->setFrom([$this->email => $this->name]) 55 | ->setSubject($this->subject) 56 | ->setTextBody($this->body) 57 | ->send(); 58 | 59 | return true; 60 | } else { 61 | return false; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /controllers/PageController.php: -------------------------------------------------------------------------------- 1 | [ 25 | 'class' => AccessControl::className(), 26 | 'rules' => [ 27 | [ 28 | 'actions' => ['index', 'view', 'error',], 29 | 'allow' => true, 30 | ], 31 | 32 | ], 33 | ], 34 | ]; 35 | } 36 | 37 | /** 38 | * Displays a single Post model. 39 | * @param integer $id 40 | * @return mixed 41 | */ 42 | public function actionView($name) 43 | { 44 | $pages=Page::find()->all(); 45 | foreach($pages as $key=>$value) 46 | { 47 | $menuItems[] = ['label' => $value->name, 'url' => ['page/view', 'name' => $value->name]]; 48 | } 49 | return $this->render('view', [ 50 | 'model' => $this->findModel($name), 51 | 'pages' => $pages, 52 | 'menuItems' =>$menuItems 53 | ]); 54 | } 55 | 56 | protected function findModel($name) 57 | { 58 | if (($model = Page::findOne(['name' => $name])) !== null) { 59 | return $model; 60 | } else { 61 | throw new NotFoundHttpException('The requested page does not exist.'); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /views/post/_comment.php: -------------------------------------------------------------------------------- 1 | 14 | 15 |
16 | 17 | Url::toRoute(['post/comment-ajax', 'id' => $id]), 19 | 'beforeSubmit' => new \yii\web\JsExpression('function(form) { 20 | jQuery(".comment-submit").button("loading"); 21 | jQuery.ajax({ 22 | url: "'. Url::toRoute(['post/comment-ajax', 'id' => $id]) .'", 23 | type: "POST", 24 | dataType: "json", 25 | data: form.serialize(), 26 | success: function(response) { 27 | if (response!=0) { 28 | $(".comment-list .media-list").prepend(response); 29 | }else{ 30 | alert("提交失败"); 31 | } 32 | jQuery(".comment-submit").button("reset"); 33 | return false; 34 | }, 35 | error: function(response) { 36 | jQuery(".comment-submit").button("reset"); 37 | return false; 38 | } 39 | });return false; 40 | }') 41 | ]); ?> 42 | 43 | field($model, 'content')->textarea(['rows' => 6])->label(false)?> 44 | 45 |
46 | 'btn btn-default comment-submit', 'data-loading-text'=>"submitting..."]) ?> 47 |
48 | 49 | 50 | 51 |
52 | -------------------------------------------------------------------------------- /modules/admin/components/Controller.php: -------------------------------------------------------------------------------- 1 | user->identity->username, Yii::$app->params['admin']) || !$this->checkAccess()){ 18 | throw new ForbiddenHttpException(Yii::t('app', 'You are not allowed to access this page.')); 19 | } 20 | 21 | if (!Common::getLanguage()) { 22 | preg_match('/^([a-z\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches); 23 | Common::setLanguage($matches[1]); 24 | Yii::$app->language=$matches[1]; 25 | }else{ 26 | Yii::$app->language=Common::getLanguage(); 27 | } 28 | 29 | return true; 30 | } else { 31 | return false; 32 | } 33 | } 34 | 35 | /** 36 | * @return boolean whether the module can be accessed by the current user 37 | */ 38 | protected function checkAccess() 39 | { 40 | $ipAccess = Yii::$app->config->get('ipAccess'); 41 | if (!empty($ipAccess)) { 42 | $this->allowedIPs=explode("\r\n",$ipAccess); 43 | $ip = Yii::$app->getRequest()->getUserIP(); 44 | foreach ($this->allowedIPs as $filter) { 45 | if ($filter === '*' || $filter === $ip || (($pos = strpos($filter, '*')) !== false && !strncmp($ip, $filter, $pos))) { 46 | return true; 47 | } 48 | } 49 | }else{ 50 | return true; 51 | } 52 | 53 | return false; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /modules/admin/views/default/info.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Site Info'); 10 | $this->params['breadcrumbs'][] = Yii::t('app', 'Site Info'); 11 | $siteinfo=Yii::$app->config->get("siteInfo"); 12 | if (isset($siteinfo["closed"]) && $siteinfo["closed"]==1) { 13 | $this->registerJs('jQuery(".field-infoform-message").hide();'); 14 | } 15 | $this->registerJs(' 16 | jQuery("input[name=\"InfoForm[closed]\"][checked]").val(); 17 | jQuery(document).on("click", "input[name=\"InfoForm[closed]\"]",function(){ if (jQuery("input[name=\"InfoForm[closed]\"]:checked").val()==1) {jQuery(".field-infoform-message").hide();}if (jQuery("input[name=\"InfoForm[closed]\"]:checked").val()==0) {jQuery(".field-infoform-message").show();} 18 | }); 19 | '); 20 | ?> 21 |
22 |

title) ?>

23 | 'form-siteinfo']); ?> 24 | field($model, 'siteName') ?> 25 | field($model, 'siteUrl') ?> 26 | field($model, 'siteTitle') ?> 27 | field($model, 'siteKeywords') ?> 28 | field($model, 'siteDescription')->textArea(['rows' => 3]) ?> 29 | field($model, 'adminEmail') ?> 30 | field($model, 'siteCopyright')->textArea(['rows' => 3]) ?> 31 | field($model, 'statCode')->textArea(['rows' => 3]) ?> 32 | field($model, 'closed')->inline()->radioList([1 => Yii::t('app', 'open'), 0 => Yii::t('app', 'close')]) ?> 33 | field($model, 'message')->textArea(['rows' => 3]) ?> 34 |
35 | 'btn btn-primary', 'name' => 'siteinfo-button']) ?> 36 |
37 | 38 |
39 | 40 | -------------------------------------------------------------------------------- /models/search/UserSearch.php: -------------------------------------------------------------------------------- 1 | $query, 27 | ]); 28 | 29 | if (!($this->load($params) && $this->validate())) { 30 | return $dataProvider; 31 | } 32 | 33 | $this->addCondition($query, 'id'); 34 | $this->addCondition($query, 'username', true); 35 | $this->addCondition($query, 'auth_key', true); 36 | $this->addCondition($query, 'password_hash', true); 37 | $this->addCondition($query, 'password_reset_token', true); 38 | $this->addCondition($query, 'email', true); 39 | $this->addCondition($query, 'role'); 40 | $this->addCondition($query, 'status'); 41 | $this->addCondition($query, 'created_at'); 42 | $this->addCondition($query, 'updated_at'); 43 | return $dataProvider; 44 | } 45 | 46 | protected function addCondition($query, $attribute, $partialMatch = false) 47 | { 48 | if (($pos = strrpos($attribute, '.')) !== false) { 49 | $modelAttribute = substr($attribute, $pos + 1); 50 | } else { 51 | $modelAttribute = $attribute; 52 | } 53 | 54 | $value = $this->$modelAttribute; 55 | if (trim($value) === '') { 56 | return; 57 | } 58 | if ($partialMatch) { 59 | $query->andWhere(['like', $attribute, $value]); 60 | } else { 61 | $query->andWhere([$attribute => $value]); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /views/post/index.php: -------------------------------------------------------------------------------- 1 | title = $category->seo_title?$category->seo_title:$category->name; 14 | $this->registerMetaTag(['name' => 'keywords', 'content' => $category->seo_keywords?$category->seo_keywords:""]); 15 | $this->registerMetaTag(['name' => 'description', 'content' => $category->seo_description?$category->seo_description:$category->summary]); 16 | } 17 | ?> 18 |
19 |
20 | 21 |
22 |
23 |
24 | 25 |

name) ?>

26 | 27 | $dataProvider, 29 | 'itemOptions' => ['class' => 'item'], 30 | 'itemView' => function ($model, $key, $index, $widget) { 31 | return Html::a(Html::encode($model->title), ['view', 'id' => $model->id]); 32 | }, 33 | ]) ?> 34 |
35 |
36 |
37 |
38 | 10]) ?> 39 |
40 | 10]) ?> 41 |
42 |

Tags

43 | Yii::$app->params['tagCloudCount']]) ?> 44 |
45 | 10]) ?> 46 |
47 |
48 |
49 | -------------------------------------------------------------------------------- /models/search/CommentSearch.php: -------------------------------------------------------------------------------- 1 | $query, 35 | 'sort'=>['defaultOrder'=>['create_time' => SORT_DESC]] 36 | ]); 37 | 38 | if (!($this->load($params) && $this->validate())) { 39 | return $dataProvider; 40 | } 41 | 42 | $query->andFilterWhere([ 43 | 'id' => $this->id, 44 | 'parent_id' => $this->parent_id, 45 | 'type' => $this->type, 46 | 'up' => $this->up, 47 | 'down' => $this->down, 48 | 'status' => $this->status, 49 | 'create_time' => $this->create_time, 50 | 'post_id' => $this->post_id, 51 | 'user_id' => $this->user_id, 52 | ]); 53 | 54 | $query->andFilterWhere(['like', 'content', $this->content]) 55 | ->andFilterWhere(['like', 'author', $this->author]) 56 | ->andFilterWhere(['like', 'email', $this->email]) 57 | ->andFilterWhere(['like', 'url', $this->url]) 58 | ->andFilterWhere(['like', 'ip', $this->ip]); 59 | 60 | return $dataProvider; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /models/LoginForm.php: -------------------------------------------------------------------------------- 1 | hasErrors()) { 41 | $user = $this->getUser(); 42 | 43 | if (!$user || !$user->validatePassword($this->password)) { 44 | $this->addError('password', 'Incorrect username or password.'); 45 | } 46 | } 47 | } 48 | 49 | /** 50 | * Logs in a user using the provided username and password. 51 | * @return boolean whether the user is logged in successfully 52 | */ 53 | public function login() 54 | { 55 | if ($this->validate()) { 56 | return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0); 57 | } else { 58 | return false; 59 | } 60 | } 61 | 62 | /** 63 | * Finds user by [[username]] 64 | * 65 | * @return User|null 66 | */ 67 | public function getUser() 68 | { 69 | if ($this->_user === false) { 70 | $this->_user = User::findByUsername($this->username); 71 | } 72 | 73 | return $this->_user; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /tests/unit/models/ContactFormTest.php: -------------------------------------------------------------------------------- 1 | mail->fileTransportCallback = function ($mailer, $message) { 16 | return 'testing_message.eml'; 17 | }; 18 | } 19 | 20 | protected function tearDown() 21 | { 22 | unlink($this->getMessageFile()); 23 | parent::tearDown(); 24 | } 25 | 26 | public function testContact() 27 | { 28 | $model = $this->getMock('app\models\ContactForm', ['validate']); 29 | $model->expects($this->once())->method('validate')->will($this->returnValue(true)); 30 | 31 | $model->attributes = [ 32 | 'name' => 'Tester', 33 | 'email' => 'tester@example.com', 34 | 'subject' => 'very important letter subject', 35 | 'body' => 'body of current message', 36 | ]; 37 | 38 | $model->contact('admin@example.com'); 39 | 40 | $this->specify('email should be send', function () { 41 | expect('email file should exist', file_exists($this->getMessageFile()))->true(); 42 | }); 43 | 44 | $this->specify('message should contain correct data', function () use ($model) { 45 | $emailMessage = file_get_contents($this->getMessageFile()); 46 | 47 | expect('email should contain user name', $emailMessage)->contains($model->name); 48 | expect('email should contain sender email', $emailMessage)->contains($model->email); 49 | expect('email should contain subject', $emailMessage)->contains($model->subject); 50 | expect('email should contain body', $emailMessage)->contains($model->body); 51 | }); 52 | } 53 | 54 | private function getMessageFile() 55 | { 56 | return Yii::getAlias(Yii::$app->mail->fileTransportPath) . '/testing_message.eml'; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /modules/admin/views/nav/_form.php: -------------------------------------------------------------------------------- 1 | roots()->all(); 15 | $level = 0; 16 | 17 | $items[0] = Yii::t('app', 'Please select the parent node'); 18 | foreach ($Categories as $key => $value){ 19 | 20 | $items[$value->attributes['id']]=$value->attributes['name']; 21 | $children = $value->descendants()->all(); 22 | foreach ($children as $child){ 23 | $string = ' '; 24 | $string .= str_repeat('│ ', $child->level - $level - 1); 25 | if ($child->isLeaf() && !$child->next()->one()) { 26 | $string .= '└'; 27 | } else { 28 | 29 | $string .= '├'; 30 | } 31 | $string .= '─' . $child->name; 32 | $items[$child->id]=$string; 33 | } 34 | } 35 | 36 | if (!$model->isNewRecord) { 37 | $parent = $model->parent()->one(); 38 | } 39 | ?> 40 | 41 | 65 | -------------------------------------------------------------------------------- /modules/admin/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 |
17 | 18 |

title) ?>

19 | 20 |

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

30 | 31 | $model, 33 | 'attributes' => [ 34 | 'id', 35 | 'category_id', 36 | 'title', 37 | [ 38 | 'label'=> Yii::t('app', 'Type'), 39 | 'value'=>Lookup::item("{{post}}type",$model->type), 40 | ], 41 | 'thumbnail', 42 | 'url:url', 43 | 'summary', 44 | 'source', 45 | 'writer', 46 | 'content:ntext', 47 | 'tags', 48 | 'seo_title', 49 | 'seo_keywords', 50 | 'seo_description', 51 | 'published_at', 52 | 'views', 53 | 'likes', 54 | 'comment_count', 55 | 'disallow_comment', 56 | 'status', 57 | [ 58 | 'label'=> Yii::t('app', 'Status'), 59 | 'value'=>Lookup::item("{{post}}status",$model->status), 60 | ], 61 | 'created_by', 62 | 'updated_by', 63 | 'created_at', 64 | 'updated_at', 65 | ], 66 | ]) ?> 67 | 68 |
69 | -------------------------------------------------------------------------------- /web/css/site.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | height: 100%; 4 | } 5 | 6 | .wrap { 7 | min-height: 100%; 8 | height: auto; 9 | margin: 0 auto; 10 | padding: 0 0 60px; 11 | } 12 | 13 | .wrap > .container { 14 | padding: 70px 15px 20px; 15 | } 16 | 17 | a.list-group-item { 18 | color: #BBB; 19 | font-size: 22px; 20 | } 21 | 22 | .submenu a { 23 | background: #f5f5f5; 24 | border-radius: 0; 25 | font-size: 18px; 26 | } 27 | .submenu a:hover, .submenu a:active, .submenu a.active, .submenu a.active:hover, .submenu a.active:active { 28 | background: #44b5f6; 29 | border-color: #44b5f6; 30 | border-radius: 0; 31 | color: #fff; 32 | } 33 | 34 | .footer { 35 | height: 60px; 36 | background-color: #f5f5f5; 37 | border-top: 1px solid #ddd; 38 | padding-top: 20px; 39 | } 40 | 41 | .jumbotron { 42 | text-align: center; 43 | background-color: transparent; 44 | } 45 | 46 | .jumbotron .btn { 47 | font-size: 21px; 48 | padding: 14px 24px; 49 | } 50 | 51 | .not-set { 52 | color: #c55; 53 | font-style: italic; 54 | } 55 | 56 | /* add sorting icons to gridview sort links */ 57 | a.asc:after, a.desc:after { 58 | position: relative; 59 | top: 1px; 60 | display: inline-block; 61 | font-family: 'Glyphicons Halflings'; 62 | font-style: normal; 63 | font-weight: normal; 64 | line-height: 1; 65 | padding-left: 5px; 66 | } 67 | 68 | a.asc:after { 69 | content: /*"\e113"*/ "\e151"; 70 | } 71 | 72 | a.desc:after { 73 | content: /*"\e114"*/ "\e152"; 74 | } 75 | 76 | .sort-numerical a.asc:after { 77 | content: "\e153"; 78 | } 79 | 80 | .sort-numerical a.desc:after { 81 | content: "\e154"; 82 | } 83 | 84 | .sort-ordinal a.asc:after { 85 | content: "\e155"; 86 | } 87 | 88 | .sort-ordinal a.desc:after { 89 | content: "\e156"; 90 | } 91 | 92 | .grid-view th { 93 | white-space: nowrap; 94 | } 95 | 96 | .hint-block { 97 | display: block; 98 | margin-top: 5px; 99 | color: #999; 100 | } 101 | 102 | .error-summary { 103 | color: #a94442; 104 | background: #fdf7f7; 105 | border-left: 3px solid #eed3d7; 106 | padding: 10px 20px; 107 | margin: 0 0 15px 0; 108 | } -------------------------------------------------------------------------------- /models/search/LookupSearch.php: -------------------------------------------------------------------------------- 1 | Yii::t('app', 'ID'), 30 | 'name' => Yii::t('app', 'Name'), 31 | 'code' => Yii::t('app', 'Code'), 32 | 'type' => Yii::t('app', 'Type'), 33 | 'position' => Yii::t('app', 'Position'), 34 | ]; 35 | } 36 | 37 | public function search($params) 38 | { 39 | $query = Lookup::find(); 40 | $dataProvider = new ActiveDataProvider([ 41 | 'query' => $query, 42 | ]); 43 | 44 | if (!($this->load($params) && $this->validate())) { 45 | return $dataProvider; 46 | } 47 | 48 | $this->addCondition($query, 'id'); 49 | $this->addCondition($query, 'name', true); 50 | $this->addCondition($query, 'code'); 51 | $this->addCondition($query, 'type', true); 52 | $this->addCondition($query, 'position'); 53 | return $dataProvider; 54 | } 55 | 56 | protected function addCondition($query, $attribute, $partialMatch = false) 57 | { 58 | if (($pos = strrpos($attribute, '.')) !== false) { 59 | $modelAttribute = substr($attribute, $pos + 1); 60 | } else { 61 | $modelAttribute = $attribute; 62 | } 63 | 64 | $value = $this->$modelAttribute; 65 | if (trim($value) === '') { 66 | return; 67 | } 68 | if ($partialMatch) { 69 | $query->andWhere(['like', $attribute, $value]); 70 | } else { 71 | $query->andWhere([$attribute => $value]); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /config/web.php: -------------------------------------------------------------------------------- 1 | 'basic', 8 | 'basePath' => dirname(__DIR__), 9 | 'bootstrap' => ['log'], 10 | 'extensions' => require(__DIR__ . '/../vendor/yiisoft/extensions.php'), 11 | 'modules' => ['admin'=>'app\modules\admin\Module'], 12 | 'timeZone'=>'Asia/Chongqing', 13 | 'language' => 'zh-CN', 14 | 'components' => [ 15 | 'cache' => [ 16 | 'class' => 'yii\caching\FileCache', 17 | ], 18 | 'user' => [ 19 | 'identityClass' => 'app\models\User', 20 | 'enableAutoLogin' => true, 21 | ], 22 | 'errorHandler' => [ 23 | 'errorAction' => 'site/error', 24 | ], 25 | 'mail' => [ 26 | 'class' => 'yii\swiftmailer\Mailer', 27 | // 'useFileTransport' => true, 28 | 'transport' => [ 29 | 'class' => 'Swift_SmtpTransport', 30 | 'host' => 'smtp.qq.com', 31 | 'username' => '1234@qq.com', 32 | 'password' => 'password', 33 | 'port' => '465', 34 | 'encryption' => 'ssl', 35 | ], 36 | ], 37 | 'log' => [ 38 | 'traceLevel' => YII_DEBUG ? 3 : 0, 39 | 'targets' => [ 40 | [ 41 | 'class' => 'yii\log\FileTarget', 42 | 'levels' => ['error', 'warning'], 43 | ], 44 | ], 45 | ], 46 | 'urlManager' => [ 47 | 'enablePrettyUrl' => true, 48 | 'showScriptName' => false, 49 | ], 50 | 'config' => [ 51 | 'class' => 'app\components\Config', 52 | 'cacheID' =>'cache' 53 | ], 54 | 'db' => $db, 55 | ], 56 | 'params' => $params, 57 | ]; 58 | 59 | if (YII_ENV_DEV) { 60 | // configuration adjustments for 'dev' environment 61 | $config['bootstrap'][] = 'debug'; 62 | $config['modules']['debug'] = 'yii\debug\Module'; 63 | 64 | $config['bootstrap'][] = 'gii'; 65 | $config['modules']['gii'] = 'yii\gii\Module'; 66 | } 67 | 68 | return $config; 69 | -------------------------------------------------------------------------------- /models/Page.php: -------------------------------------------------------------------------------- 1 | [ 35 | 'class' => 'yii\behaviors\TimestampBehavior', 36 | 'attributes' => [ 37 | ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], 38 | ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'], 39 | ], 40 | ], 41 | ]; 42 | } 43 | 44 | /** 45 | * @inheritdoc 46 | */ 47 | public function rules() 48 | { 49 | return [ 50 | [['name', 'title', 'content'], 'required'], 51 | [['content'], 'string'], 52 | [['created_at', 'updated_at'], 'integer'], 53 | [['name', 'title', 'seo_title', 'seo_keywords', 'seo_description'], 'string', 'max' => 255] 54 | ]; 55 | } 56 | 57 | /** 58 | * @inheritdoc 59 | */ 60 | public function attributeLabels() 61 | { 62 | return [ 63 | 'id' => Yii::t('app', 'ID'), 64 | 'name' => Yii::t('app', 'Name'), 65 | 'title' => Yii::t('app', 'Title'), 66 | 'content' => Yii::t('app', 'Content'), 67 | 'seo_title' => Yii::t('app', 'Seo Title'), 68 | 'seo_keywords' => Yii::t('app', 'Seo Keywords'), 69 | 'seo_description' => Yii::t('app', 'Seo Description'), 70 | 'created_at' => Yii::t('app', 'Created At'), 71 | 'updated_at' => Yii::t('app', 'Updated At'), 72 | ]; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /modules/admin/views/post/_search.php: -------------------------------------------------------------------------------- 1 | 12 | 13 |
14 | 15 | ['index'], 17 | 'method' => 'get', 18 | ]); ?> 19 | 20 | field($model, 'id') ?> 21 | 22 | field($model, 'category_id') ?> 23 | 24 | field($model, 'title') ?> 25 | 26 | field($model, 'type') ?> 27 | 28 | field($model, 'thumbnail') ?> 29 | 30 | field($model, 'url') ?> 31 | 32 | field($model, 'summary') ?> 33 | 34 | field($model, 'source') ?> 35 | 36 | field($model, 'writer') ?> 37 | 38 | field($model, 'content') ?> 39 | 40 | field($model, 'tags') ?> 41 | 42 | field($model, 'seo_title') ?> 43 | 44 | field($model, 'seo_keywords') ?> 45 | 46 | field($model, 'seo_description') ?> 47 | 48 | field($model, 'published_at') ?> 49 | 50 | field($model, 'views') ?> 51 | 52 | field($model, 'likes') ?> 53 | 54 | field($model, 'comment_count') ?> 55 | 56 | field($model, 'disallow_comment') ?> 57 | 58 | field($model, 'status') ?> 59 | 60 | field($model, 'visibility') ?> 61 | 62 | field($model, 'created_by') ?> 63 | 64 | field($model, 'updated_by') ?> 65 | 66 | field($model, 'created_at') ?> 67 | 68 | field($model, 'updated_at') ?> 69 | 70 |
71 | 'btn btn-primary']) ?> 72 | 'btn btn-default']) ?> 73 |
74 | 75 | 76 | 77 |
78 | -------------------------------------------------------------------------------- /widgets/Alert.php: -------------------------------------------------------------------------------- 1 | getSession()->setFlash('error', 'This is the message'); 15 | * - \Yii::$app->getSession()->setFlash('success', 'This is the message'); 16 | * - \Yii::$app->getSession()->setFlash('info', 'This is the message'); 17 | * 18 | * @author Kartik Visweswaran 19 | * @author Alexander Makarov 20 | */ 21 | class Alert extends \yii\bootstrap\Widget 22 | { 23 | /** 24 | * @var array the alert types configuration for the flash messages. 25 | * This array is setup as $key => $value, where: 26 | * - $key is the name of the session flash variable 27 | * - $value is the bootstrap alert type (i.e. danger, success, info, warning) 28 | */ 29 | public $alertTypes = [ 30 | 'error' => 'alert-danger', 31 | 'danger' => 'alert-danger', 32 | 'success' => 'alert-success', 33 | 'info' => 'alert-info', 34 | 'warning' => 'alert-warning' 35 | ]; 36 | 37 | /** 38 | * @var array the options for rendering the close button tag. 39 | */ 40 | public $closeButton = []; 41 | 42 | public function init() 43 | { 44 | parent::init(); 45 | 46 | $session = \Yii::$app->getSession(); 47 | $flashes = $session->getAllFlashes(); 48 | $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : ''; 49 | 50 | foreach ($flashes as $type => $message) { 51 | if (isset($this->alertTypes[$type])) { 52 | /* initialize css class for each alert box */ 53 | $this->options['class'] = $this->alertTypes[$type] . $appendCss; 54 | 55 | /* assign unique id to each alert box */ 56 | $this->options['id'] = $this->getId() . '-' . $type; 57 | 58 | echo \yii\bootstrap\Alert::widget([ 59 | 'body' => $message, 60 | 'closeButton' => $this->closeButton, 61 | 'options' => $this->options, 62 | ]); 63 | 64 | $session->removeFlash($type); 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /modules/admin/views/page/_form.php: -------------------------------------------------------------------------------- 1 | 12 | 13 |
14 | 15 | 19 |
20 | 21 | 22 |
23 |
24 | 25 | 26 | field($model, 'name')->textInput(['maxlength' => 255]) ?> 27 | 28 | field($model, 'title')->textInput(['maxlength' => 255]) ?> 29 | 'page-content', 31 | 'model' => $model, 32 | 'attribute' => 'content', 33 | 'items' => [ 34 | 'langType' => Yii::$app->language=="zh-CN"?"zh_CN":Yii::$app->language, 35 | 'height' => '350px', 36 | 'themeType' => 'simple', 37 | 'pagebreakHtml' => Yii::$app->params['pagebreakHtml'], 38 | 'allowImageUpload' => true, 39 | 'allowFileManager' => true, 40 | 'uploadJson' => Url::toRoute('create-img-ajax'), 41 | 'fileManagerJson' => Url::toRoute('post/filemanager'), 42 | 43 | ], 44 | ])?> 45 | 46 | field($model, 'content')->textarea(['rows' => 6]) ?> 47 |
48 |
49 | field($model, 'seo_title')->textInput(['maxlength' => 255]) ?> 50 | 51 | field($model, 'seo_keywords')->textInput(['maxlength' => 255]) ?> 52 | 53 | field($model, 'seo_description')->textArea(['rows' => 5]) ?> 54 |
55 | 56 | 57 | 58 |
59 | isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 60 |
61 | 62 | 63 | 64 |
65 | -------------------------------------------------------------------------------- /models/SignupForm.php: -------------------------------------------------------------------------------- 1 | 'trim'], 24 | ['username', 'required'], 25 | ['username', 'unique', 'targetClass' => '\app\models\User', 'message' => Yii::t('app', 'This username has already been taken.')], 26 | ['username', 'string', 'min' => 2, 'max' => 255], 27 | ['username', 'validateHoldUser'], 28 | 29 | ['email', 'filter', 'filter' => 'trim'], 30 | ['email', 'required'], 31 | ['email', 'email'], 32 | ['email', 'unique', 'targetClass' => '\app\models\User', 'message' => Yii::t('app', 'This email address has already been taken.')], 33 | 34 | ['password', 'required'], 35 | ['password', 'string', 'min' => 5], 36 | ]; 37 | } 38 | 39 | public function validateHoldUser($attribute,$params) 40 | { 41 | if(!empty($this->$attribute)) 42 | { 43 | $config=Yii::$app->config->get("signup"); 44 | $names=explode(',', $config['holdUser']); 45 | if (!empty($names)) { 46 | $username=strtolower($this->$attribute); 47 | if(in_array($username, $names)){ 48 | $this->addError($attribute, Yii::t('app', 'This username has already been taken.')); 49 | } 50 | } 51 | } 52 | } 53 | 54 | /** 55 | * Signs user up. 56 | * 57 | * @return User|null the saved model or null if saving fails 58 | */ 59 | public function signup() 60 | { 61 | if ($this->validate()) { 62 | $user = new User(); 63 | $user->username = $this->username; 64 | $user->email = $this->email; 65 | $user->setPassword($this->password); 66 | $user->generateAuthKey(); 67 | $user->save(); 68 | return $user; 69 | } 70 | 71 | return null; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /modules/admin/views/post/index.php: -------------------------------------------------------------------------------- 1 | title = Yii::t('app', 'Posts'); 14 | $this->params['breadcrumbs'][] = $this->title; 15 | ?> 16 |
17 | 18 |

title) ?>

19 | 20 | render('_search', ['model' => $searchModel]); ?> 21 | 22 |

23 | 'Post', 25 | ]), ['create'], ['class' => 'btn btn-success']) ?> 26 |

27 | 28 | $dataProvider, 30 | 'filterModel' => $searchModel, 31 | 'columns' => [ 32 | ['class' => 'yii\grid\SerialColumn'], 33 | 34 | 'id', 35 | 'category_id', 36 | 'title', 37 | // 'url:url', 38 | // 'thumbnail', 39 | [ 40 | 'attribute'=>'type', 41 | 'value' => function ($data) { 42 | return Lookup::item("{{post}}type",$data->type); 43 | }, 44 | 'filter' => Lookup::items("{{post}}type"), 45 | ], 46 | // 'summary', 47 | // 'source', 48 | // 'writer', 49 | // 'content:ntext', 50 | // 'tags', 51 | // 'seo_title', 52 | // 'seo_keywords', 53 | // 'seo_description', 54 | 'published_at:date', 55 | 'views', 56 | 'likes', 57 | 'comment_count', 58 | // 'disallow_comment', 59 | [ 60 | 'attribute'=>'status', 61 | 'value' => function ($data) { 62 | return Lookup::item("{{post}}status",$data->status); 63 | }, 64 | 'filter' => Lookup::items("{{post}}status"), 65 | ], 66 | // 'created_by', 67 | // 'updated_by', 68 | // 'created_at', 69 | // 'updated_at', 70 | 71 | ['class' => 'yii\grid\ActionColumn'], 72 | ], 73 | ]); ?> 74 | 75 |
76 | -------------------------------------------------------------------------------- /tests/unit/models/LoginFormTest.php: -------------------------------------------------------------------------------- 1 | user->logout(); 16 | parent::tearDown(); 17 | } 18 | 19 | public function testLoginNoUser() 20 | { 21 | $model = $this->mockUser(null); 22 | 23 | $model->username = 'some_username'; 24 | $model->password = 'some_password'; 25 | 26 | $this->specify('user should not be able to login, when there is no identity', function () use ($model) { 27 | expect('model should not login user', $model->login())->false(); 28 | expect('user should not be logged in', Yii::$app->user->isGuest)->true(); 29 | }); 30 | } 31 | 32 | public function testLoginWrongPassword() 33 | { 34 | $model = $this->mockUser(new User); 35 | 36 | $model->username = 'demo'; 37 | $model->password = 'wrong-password'; 38 | 39 | $this->specify('user should not be able to login with wrong password', function () use ($model) { 40 | expect('model should not login user', $model->login())->false(); 41 | expect('error message should be set', $model->errors)->hasKey('password'); 42 | expect('user should not be logged in', Yii::$app->user->isGuest)->true(); 43 | }); 44 | } 45 | 46 | public function testLoginCorrect() 47 | { 48 | $model = $this->mockUser(new User(['password' => 'demo'])); 49 | 50 | $model->username = 'demo'; 51 | $model->password = 'demo'; 52 | 53 | $this->specify('user should be able to login with correct credentials', function () use ($model) { 54 | expect('model should login user', $model->login())->true(); 55 | expect('error message should not be set', $model->errors)->hasntKey('password'); 56 | expect('user should be logged in', Yii::$app->user->isGuest)->false(); 57 | }); 58 | } 59 | 60 | private function mockUser($user) 61 | { 62 | $loginForm = $this->getMock('app\models\LoginForm', ['getUser']); 63 | $loginForm->expects($this->any())->method('getUser')->will($this->returnValue($user)); 64 | 65 | return $loginForm; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /views/site/contact.php: -------------------------------------------------------------------------------- 1 | title = 'Contact'; 12 | $this->params['breadcrumbs'][] = $this->title; 13 | ?> 14 |
15 |

title) ?>

16 | 17 | session->hasFlash('contactFormSubmitted')): ?> 18 | 19 |
20 | Thank you for contacting us. We will respond to you as soon as possible. 21 |
22 | 23 |

24 | Note that if you turn on the Yii debugger, you should be able 25 | to view the mail message on the mail panel of the debugger. 26 | mail->useFileTransport): ?> 27 | Because the application is in development mode, the email is not sent but saved as 28 | a file under mail->fileTransportPath) ?>. 29 | Please configure the useFileTransport property of the mail 30 | application component to be false to enable email sending. 31 | 32 |

33 | 34 | 35 | 36 |

37 | If you have business inquiries or other questions, please fill out the following form to contact us. Thank you. 38 |

39 | 40 |
41 |
42 | 'contact-form']); ?> 43 | field($model, 'name') ?> 44 | field($model, 'email') ?> 45 | field($model, 'subject') ?> 46 | field($model, 'body')->textArea(['rows' => 6]) ?> 47 | field($model, 'verifyCode')->widget(Captcha::className(), [ 48 | 'template' => '
{image}
{input}
', 49 | ]) ?> 50 |
51 | 'btn btn-primary', 'name' => 'contact-button']) ?> 52 |
53 | 54 |
55 |
56 | 57 | 58 |
59 | -------------------------------------------------------------------------------- /models/search/LinkSearch.php: -------------------------------------------------------------------------------- 1 | Yii::t('app', 'ID'), 30 | 'name' => Yii::t('app', 'Name'), 31 | 'url' => Yii::t('app', 'Url'), 32 | 'logo' => Yii::t('app', 'Logo'), 33 | 'target' => Yii::t('app', 'Target'), 34 | 'type' => Yii::t('app', 'Type'), 35 | 'position' => Yii::t('app', 'Position'), 36 | 'visible' => Yii::t('app', 'Visible'), 37 | ]; 38 | } 39 | 40 | public function search($params) 41 | { 42 | $query = Link::find(); 43 | $dataProvider = new ActiveDataProvider([ 44 | 'query' => $query, 45 | ]); 46 | 47 | if (!($this->load($params) && $this->validate())) { 48 | return $dataProvider; 49 | } 50 | 51 | $this->addCondition($query, 'id'); 52 | $this->addCondition($query, 'name', true); 53 | $this->addCondition($query, 'url', true); 54 | $this->addCondition($query, 'logo', true); 55 | $this->addCondition($query, 'target'); 56 | $this->addCondition($query, 'type'); 57 | $this->addCondition($query, 'position'); 58 | $this->addCondition($query, 'visible'); 59 | return $dataProvider; 60 | } 61 | 62 | protected function addCondition($query, $attribute, $partialMatch = false) 63 | { 64 | if (($pos = strrpos($attribute, '.')) !== false) { 65 | $modelAttribute = substr($attribute, $pos + 1); 66 | } else { 67 | $modelAttribute = $attribute; 68 | } 69 | 70 | $value = $this->$modelAttribute; 71 | if (trim($value) === '') { 72 | return; 73 | } 74 | if ($partialMatch) { 75 | $query->andWhere(['like', $attribute, $value]); 76 | } else { 77 | $query->andWhere([$attribute => $value]); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /components/ToggleAction.php: -------------------------------------------------------------------------------- 1 | getRequest()->isPost) { 58 | $model = $this->loadModel($id); 59 | $model->$attribute = ($model->$attribute == $this->noValue) ? $this->yesValue : $this->noValue; 60 | $success = $model->save(false, [$attribute]); 61 | 62 | if (Yii::$app->getRequest()->isAjax) { 63 | echo $success ? $this->ajaxResponseOnSuccess : $this->ajaxResponseOnFailed; 64 | exit(0); 65 | } 66 | if ($this->redirectRoute !== null) { 67 | return $this->getController()->redirect($this->redirectRoute); 68 | } 69 | } else { 70 | throw new HttpException(Yii::t('app', 'Invalid request')); 71 | } 72 | } 73 | 74 | /** 75 | * Loads the requested data model. 76 | * 77 | * @param integer $id the model ID 78 | * 79 | * @return ActiveRecord the model instance. 80 | * @throws HttpException if the model cannot be found 81 | */ 82 | protected function loadModel($id) 83 | { 84 | $model= new $this->modelName; 85 | $model = $model::findOne($id); 86 | 87 | if (!$model) 88 | throw new HttpException(404, 'Unable to find the requested object.'); 89 | 90 | return $model; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /messages/config.php: -------------------------------------------------------------------------------- 1 | __DIR__ . '/..', 6 | // string, required, root directory containing message translations. 7 | 'messagePath' => __DIR__, 8 | // array, required, list of language codes that the extracted messages 9 | // should be translated to. For example, ['zh-CN', 'de']. 10 | 'languages' => ['ar', 'da', 'de', 'el', 'es', 'fa-IR', 'fr', 'it', 'ja', 'kz', 'lv', 'pl', 'pt-BR', 'pt-PT', 'ro', 'ru', 'sk', 'sr', 'sr-Latn', 'uk', 'zh-CN'], 11 | // string, the name of the function for translating messages. 12 | // Defaults to 'Yii::t'. This is used as a mark to find the messages to be 13 | // translated. You may use a string for single function name or an array for 14 | // multiple function names. 15 | 'translator' => 'Yii::t', 16 | // boolean, whether to sort messages by keys when merging new messages 17 | // with the existing ones. Defaults to false, which means the new (untranslated) 18 | // messages will be separated from the old (translated) ones. 19 | 'sort' => false, 20 | // boolean, whether the message file should be overwritten with the merged messages 21 | 'overwrite' => true, 22 | // boolean, whether to remove messages that no longer appear in the source code. 23 | // Defaults to false, which means each of these messages will be enclosed with a pair of '@@' marks. 24 | 'removeUnused' => false, 25 | // array, list of patterns that specify which files/directories should NOT be processed. 26 | // If empty or not set, all files/directories will be processed. 27 | // A path matches a pattern if it contains the pattern string at its end. For example, 28 | // '/a/b' will match all files and directories ending with '/a/b'; 29 | // the '*.svn' will match all files and directories whose name ends with '.svn'. 30 | // and the '.svn' will match all files and directories named exactly '.svn'. 31 | // Note, the '/' characters in a pattern matches both '/' and '\'. 32 | // See helpers/FileHelper::findFiles() description for more details on pattern matching rules. 33 | 'except' => [ 34 | '.svn', 35 | '.git', 36 | '.gitignore', 37 | '.gitkeep', 38 | '.hgignore', 39 | '.hgkeep', 40 | '/messages', 41 | ], 42 | // array, list of patterns that specify which files (not directories) should be processed. 43 | // If empty or not set, all files will be processed. 44 | // Please refer to "except" for details about the patterns. 45 | // If a file/directory matches both a pattern in "only" and "except", it will NOT be processed. 46 | 'only' => ['*.php'], 47 | // Generated file format. Can be "php", "db" or "po". 48 | 'format' => 'php', 49 | // Connection component ID for "db" format. 50 | //'db' => 'db', 51 | ]; 52 | -------------------------------------------------------------------------------- /modules/admin/views/category/_form.php: -------------------------------------------------------------------------------- 1 | roots()->all(); 16 | $level = 0; 17 | 18 | $items[0] = Yii::t('app', 'Please select the parent node'); 19 | foreach ($Categories as $key => $value){ 20 | 21 | $items[$value->attributes['id']]=$value->attributes['name']; 22 | $children = $value->descendants()->all(); 23 | foreach ($children as $child){ 24 | $string = ' '; 25 | $string .= str_repeat('│ ', $child->level - $level - 1); 26 | if ($child->isLeaf() && !$child->next()->one()) { 27 | $string .= '└'; 28 | } else { 29 | 30 | $string .= '├'; 31 | } 32 | $string .= '─' . $child->name; 33 | $items[$child->id]=$string; 34 | } 35 | } 36 | 37 | if (!$model->isNewRecord) { 38 | $parent = $model->parent()->one(); 39 | } 40 | 41 | ?> 42 | 43 |
44 | 45 | 49 |
50 | 51 | 52 |
53 |
54 | ['enctype'=>'multipart/form-data'] 56 | ]); ?> 57 | 58 | isNewRecord && isset($parent)) : ?> 59 | parent=$parent->id;?> 60 | field($model, 'parent')->dropDownList($items) ?> 61 | 62 | field($model, 'parent')->dropDownList($items) ?> 63 | 64 | 65 | field($model, 'name')->textInput(['maxlength' => 255]) ?> 66 | 67 | field($model, 'summary')->textArea(['rows' => 6]) ?> 68 |
69 |
70 | field($model, 'seo_title')->textInput(['maxlength' => 255]) ?> 71 | 72 | field($model, 'seo_keywords')->textInput(['maxlength' => 255]) ?> 73 | 74 | field($model, 'seo_description')->textArea(['rows' => 5]) ?> 75 |
76 |
77 | isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 78 |
79 | 80 | 81 | 82 |
83 | -------------------------------------------------------------------------------- /modules/admin/views/layouts/main.php: -------------------------------------------------------------------------------- 1 | 14 | beginPage() ?> 15 | 16 | 17 | 18 | 19 | 20 | <?= Html::encode($this->title) ?> 21 | head() ?> 22 | 23 | 24 | beginBody() ?> 25 |
26 | ' DCMS v2.0', 29 | 'brandUrl' => ['/admin/default/index'], 30 | 'options' => [ 31 | 'class' => 'navbar-default', 32 | ], 33 | ]); 34 | 35 | $menuItems = [ 36 | ['label' => \Yii::t('app', 'Site Home'), 'url' => ['/site/index'], 'linkOptions' => ['target' => '_blank']], 37 | ['label' => \Yii::t('app', 'Hello,welcome to use DCMS!'), 'url' => '#'], 38 | ]; 39 | if (Yii::$app->user->isGuest) { 40 | $menuItems[] = ['label' => \Yii::t('app', 'Login'), 'url' => ['/site/login']]; 41 | } else { 42 | $menuItems[] = [ 43 | 'label' => \Yii::t('app', 'Logout').' (' . Yii::$app->user->identity->username . ')', 44 | 'url' => ['/site/logout'], 45 | 'linkOptions' => ['data-method' => 'post'] 46 | ]; 47 | } 48 | if (Common::getLanguage()) { 49 | switch (Common::getLanguage()) { 50 | case 'en': 51 | $languageLable=' English'; 52 | break; 53 | case 'zh-CN': 54 | $languageLable=' 简体中文'; 55 | break; 56 | default: 57 | $languageLable=' English'; 58 | break; 59 | } 60 | 61 | } 62 | $menuItems[] = [ 63 | 'label' => Common::getLanguage()?$languageLable:\Yii::t('app', 'choose language'), 64 | 'url' => '#', 65 | 'items' => [ 66 | ['label' => ' English', 'url' => ['default/locale', 'language' => 'en']], 67 | ['label' => ' 简体中文', 'url' => ['default/locale', 'language' => 'zh-CN']], 68 | ] 69 | ]; 70 | echo Nav::widget([ 71 | 'options' => ['class' => 'navbar-nav navbar-right'], 72 | 'items' => $menuItems, 73 | 'encodeLabels' => false 74 | ]); 75 | NavBar::end(); 76 | ?> 77 | 78 | 79 | 80 | 81 |
82 | endBody() ?> 83 | 84 | 85 | endPage() ?> 86 | -------------------------------------------------------------------------------- /models/Lookup.php: -------------------------------------------------------------------------------- 1 | 128] 36 | ]; 37 | } 38 | 39 | /** 40 | * @inheritdoc 41 | */ 42 | public function attributeLabels() 43 | { 44 | return [ 45 | 'id' => Yii::t('app', 'ID'), 46 | 'name' => Yii::t('app', 'Name'), 47 | 'code' => Yii::t('app', 'Code'), 48 | 'type' => Yii::t('app', 'Type'), 49 | 'position' => Yii::t('app', 'Position'), 50 | ]; 51 | } 52 | 53 | /** 54 | * Returns the items for the specified type. 55 | * @param string item type (e.g. 'PostStatus'). 56 | * @return array item names indexed by item code. The items are order by their position values. 57 | * An empty array is returned if the item type does not exist. 58 | */ 59 | public static function items($type) 60 | { 61 | if(!isset(self::$_items[$type])) 62 | self::loadItems($type); 63 | return self::$_items[$type]; 64 | } 65 | 66 | /** 67 | * Returns the item name for the specified type and code. 68 | * @param string the item type (e.g. 'PostStatus'). 69 | * @param integer the item code (corresponding to the 'code' column value) 70 | * @return string the item name for the specified the code. False is returned if the item type or code does not exist. 71 | */ 72 | public static function item($type,$code) 73 | { 74 | if(!isset(self::$_items[$type])) 75 | self::loadItems($type); 76 | return isset(self::$_items[$type][$code]) ? self::$_items[$type][$code] : false; 77 | } 78 | 79 | /** 80 | * Loads the lookup items for the specified type from the database. 81 | * @param string the item type 82 | */ 83 | private static function loadItems($type) 84 | { 85 | self::$_items[$type]=array(); 86 | $models=self::find()->where(['type'=>$type])->orderBy([ 87 | 'position' => SORT_ASC])->all(); 88 | foreach($models as $model) 89 | self::$_items[$type][$model->code]=Yii::t('app', $model->name); 90 | } 91 | } 92 | --------------------------------------------------------------------------------