Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/noumo/easyii into test
Browse files Browse the repository at this point in the history
Conflicts:
	components/API.php
	controllers/PhotosController.php
	modules/article/api/Article.php
	modules/article/models/Category.php
	modules/article/models/Item.php
	modules/article/views/a/_form.php
	modules/article/views/a/index.php
	modules/article/views/items/_form.php
	modules/carousel/api/Carousel.php
	modules/catalog/CatalogModule.php
	modules/catalog/api/Catalog.php
	modules/catalog/models/Category.php
	modules/catalog/views/a/_form.php
	modules/catalog/views/items/_form.php
	modules/file/api/File.php
	modules/gallery/api/Gallery.php
	modules/gallery/models/Album.php
	modules/gallery/views/a/_form.php
	modules/guestbook/api/Guestbook.php
	modules/news/api/News.php
	modules/news/models/News.php
	modules/news/views/a/_form.php
	modules/page/api/Page.php
	modules/text/api/Text.php
	views/modules/settings.php
	widgets/views/photos.php
  • Loading branch information
noumo committed Apr 13, 2015
2 parents eb86b99 + 7e57211 commit 91945cc
Show file tree
Hide file tree
Showing 104 changed files with 434 additions and 412 deletions.
5 changes: 3 additions & 2 deletions assets/photos/photos.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ $(function(){
photosBody.on('input propertychange', '.photo-description', function(){
var saveBtn = $(this).siblings('.save-photo-description');
if(saveBtn.hasClass('disabled')){
saveBtn.removeClass('disabled').on('click', function(){
saveBtn.removeClass('disabled').on('click', function(e){
e.preventDefault();
var $this = $(this).unbind('click').addClass('disabled');
var tr = $this.closest('tr');
var text = $this.siblings('.photo-description').val();
$.post(
'/admin/photos/description/'+ tr.data('id'),
$this.attr('href'),
{description: text},
function(response){
if(response.result === 'success'){
Expand Down
2 changes: 1 addition & 1 deletion components/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function beforeAction($action)

if(Yii::$app->user->isGuest){
Yii::$app->user->setReturnUrl(Yii::$app->request->url);
return $this->redirect('/admin/sign/in');
return $this->redirect(['/admin/sign/in']);
}
else{

Expand Down
6 changes: 3 additions & 3 deletions controllers/AdminsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function actionIndex()
$data = new ActiveDataProvider([
'query' => Admin::find()->desc(),
]);
Yii::$app->user->setReturnUrl('/admin/admins');
Yii::$app->user->setReturnUrl(['/admin/admins']);

return $this->render('index', [
'data' => $data
Expand All @@ -35,7 +35,7 @@ public function actionCreate()
else{
if($model->save()){
$this->flash('success', Yii::t('easyii', 'Admin created'));
return $this->redirect('/admin/admins');
return $this->redirect(['/admin/admins']);
}
else{
$this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors()));
Expand All @@ -56,7 +56,7 @@ public function actionEdit($id)

if($model === null){
$this->flash('error', Yii::t('easyii', 'Not found'));
return $this->redirect('/admin/admins');
return $this->redirect(['/admin/admins']);
}

if ($model->load(Yii::$app->request->post())) {
Expand Down
4 changes: 2 additions & 2 deletions controllers/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function actionIndex()
Yii::$app->cache->flush();
Yii::$app->session->setFlash('root_password', $installForm->root_password);

return $this->redirect('/admin/install/finish');
return $this->redirect(['/admin/install/finish']);
}
else {
$installForm->robot_email = 'noreply@'.Yii::$app->request->serverName;
Expand All @@ -68,7 +68,7 @@ public function actionFinish()
'password' => $root_password,
]);
if($loginForm->login()){
return $this->redirect('/admin/');
return $this->redirect(['/admin/']);
}
}

Expand Down
6 changes: 3 additions & 3 deletions controllers/ModulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function actionCreate()
else{
if($model->save()){
$this->flash('success', Yii::t('easyii', 'Module created'));
return $this->redirect('/admin/modules');
return $this->redirect(['/admin/modules']);
}
else{
$this->flash('error', Yii::t('Create error. {0}', $model->formatErrors()));
Expand All @@ -72,7 +72,7 @@ public function actionEdit($id)

if($model === null){
$this->flash('error', Yii::t('easyii', 'Not found'));
return $this->redirect('/admin/modules');
return $this->redirect(['/admin/modules']);
}

if ($model->load(Yii::$app->request->post())) {
Expand Down Expand Up @@ -103,7 +103,7 @@ public function actionSettings($id)

if($model === null){
$this->flash('error', Yii::t('easyii', 'Not found'));
return $this->redirect('/admin/modules');
return $this->redirect(['/admin/modules']);
}

if (Yii::$app->request->post('Settings')) {
Expand Down
5 changes: 3 additions & 2 deletions controllers/PhotosController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace yii\easyii\controllers;

use Yii;
use yii\helpers\Url;
use yii\web\UploadedFile;
use yii\web\Response;

Expand Down Expand Up @@ -31,7 +32,7 @@ public function behaviors()
public function actionUpload($model, $item_id)
{
$success = null;

$photo = new Photo;
$photo->model = $model;
$photo->item_id = $item_id;
Expand All @@ -52,7 +53,7 @@ public function actionUpload($model, $item_id)
];
}
else{
@unlink(Yii::getAlias('@webroot').$photo->image);
@unlink(Yii::getAlias('@webroot') . str_replace(Url::base(true), '', $photo->image));
$this->error = Yii::t('easyii', 'Create error. {0}', $photo->formatErrors());
}
}
Expand Down
3 changes: 2 additions & 1 deletion controllers/RedactorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Yii;
use yii\web\HttpException;
use yii\helpers\FileHelper;
use yii\helpers\Url;
use yii\web\UploadedFile;
use yii\web\Response;

Expand Down Expand Up @@ -116,7 +117,7 @@ public function actionUpload($dir = '')
private function getResponse($fileName)
{
return [
'filelink' => 'http://'.Yii::$app->request->serverName.$fileName,
'filelink' => $fileName,
'filename' => basename($fileName)
];
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function actionEdit($id)

if($model === null || ($model->visibility < (IS_ROOT ? Setting::VISIBLE_ROOT : Setting::VISIBLE_ALL))){
$this->flash('error', Yii::t('easyii', 'Not found'));
return $this->redirect('/admin/settings');
return $this->redirect(['/admin/settings']);
}

if ($model->load(Yii::$app->request->post())) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/SignController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function actionIn()
$model = new models\LoginForm;

if (!Yii::$app->user->isGuest || ($model->load(Yii::$app->request->post()) && $model->login())) {
return $this->redirect(Yii::$app->user->getReturnUrl('/admin'));
return $this->redirect(Yii::$app->user->getReturnUrl(['/admin']));
} else {
return $this->render('in', [
'model' => $model,
Expand Down
3 changes: 3 additions & 0 deletions helpers/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use yii\web\UploadedFile;
use yii\web\HttpException;
use yii\helpers\FileHelper;
use yii\helpers\Url;
use yii\easyii\helpers\GD;

class Image
Expand All @@ -26,6 +27,8 @@ public static function upload(UploadedFile $fileInstance, $dir = '', $resizeWidt

static function createThumbnail($fileName, $width, $height = null, $crop = true)
{
$fileName = str_replace(Url::base(true), '', $fileName);

$webRoot = Yii::getAlias('@webroot');
if(!strstr($fileName, $webRoot)){
$fileName = $webRoot . $fileName;
Expand Down
3 changes: 2 additions & 1 deletion helpers/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use yii\helpers\Inflector;
use yii\helpers\StringHelper;
use yii\helpers\FileHelper;
use yii\helpers\Url;

class Upload
{
Expand All @@ -33,7 +34,7 @@ static function getUploadPath($dir)

static function getLink($fileName)
{
return str_replace('\\', '/', str_replace(Yii::getAlias('@webroot'), '', $fileName));
return Url::base(true) . str_replace('\\', '/', str_replace(Yii::getAlias('@webroot'), '', $fileName));
}

static function getFileName($fileInstanse, $namePostfix = true)
Expand Down
2 changes: 1 addition & 1 deletion media/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $(function(){
var checkbox = $(this);
checkbox.switcher('setDisabled', true);

$.getJSON(checkbox.data('link') + (checkbox.is(':checked') ? 'on' : 'off') + '/' + checkbox.data('id'), function(response){
$.getJSON(checkbox.data('link') + '/' + (checkbox.is(':checked') ? 'on' : 'off') + '/' + checkbox.data('id'), function(response){
if(response.result === 'error'){
alert(response.error);
}
Expand Down
2 changes: 1 addition & 1 deletion media/js/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ $(function(){
$('#easyii-navbar input').switcher({copy: {en: {yes: '', no: ''}}}).on('change', function(){
var checkbox = $(this);
checkbox.switcher('setDisabled', true);
location.href = '/admin/system/live-edit/'+(checkbox.is(':checked') ? 1 : 0);
location.href = checkbox.attr('data-link') + '/' + (checkbox.is(':checked') ? 1 : 0);
});;
});
3 changes: 0 additions & 3 deletions modules/article/ArticleModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ class ArticleModule extends \yii\easyii\components\Module

'enableShort' => true,
'shortMaxLength' => 255,

'categoryAutoSlug' => true,
'itemAutoSlug' => true,
];

public static $installConfig = [
Expand Down
2 changes: 1 addition & 1 deletion modules/article/api/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Yii;
use yii\data\ActiveDataProvider;
use yii\helpers\Url;
use yii\widgets\LinkPager;

use yii\easyii\widgets\Colorbox;
Expand Down Expand Up @@ -70,7 +71,6 @@ private function findItem($id_slug)
}

$item->updateCounters(['views' => 1]);

return new ArticleObject($item);
}
}
4 changes: 2 additions & 2 deletions modules/article/controllers/AController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function actionCreate($parent = null)
if($model->save()){

$this->flash('success', Yii::t('easyii/article', 'Category created'));
return $this->redirect('/admin/article/items/'.$model->primaryKey);
return $this->redirect(['/admin/article/items/index', 'id' => $model->primaryKey]);
}
else{
$this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors()));
Expand All @@ -84,7 +84,7 @@ public function actionCreate($parent = null)
public function actionEdit($id)
{
if(!($model = Category::findOne($id))){
return $this->redirect('/admin/article');
return $this->redirect(['/admin/article/']);
}

if ($model->load(Yii::$app->request->post())) {
Expand Down
10 changes: 5 additions & 5 deletions modules/article/controllers/ItemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function behaviors()
public function actionIndex($id)
{
if(!($model = Category::findOne($id))){
return $this->redirect('/admin/article');
return $this->redirect(['/admin/article']);
}

return $this->render('index', [
Expand All @@ -38,7 +38,7 @@ public function actionIndex($id)
public function actionCreate($id)
{
if(!($category = Category::findOne($id))){
return $this->redirect('/admin/article');
return $this->redirect(['/admin/article']);
}

$model = new Item;
Expand All @@ -62,7 +62,7 @@ public function actionCreate($id)

if ($model->save()) {
$this->flash('success', Yii::t('easyii/article', 'Article created'));
return $this->redirect('/admin/article/items/edit/' . $model->primaryKey);
return $this->redirect(['/admin/article/items/edit', 'id' => $model->primaryKey]);
} else {
$this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors()));
return $this->refresh();
Expand All @@ -80,7 +80,7 @@ public function actionCreate($id)
public function actionEdit($id)
{
if(!($model = Item::findOne($id))){
return $this->redirect('/admin/article');
return $this->redirect(['/admin/article']);
}

if ($model->load(Yii::$app->request->post())) {
Expand All @@ -100,7 +100,7 @@ public function actionEdit($id)

if ($model->save()) {
$this->flash('success', Yii::t('easyii/article', 'Article updated'));
return $this->redirect('/admin/article/items/edit/' . $model->primaryKey);
return $this->redirect(['/admin/article/items/edit', 'id' => $model->primaryKey]);
} else {
$this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
return $this->refresh();
Expand Down
30 changes: 7 additions & 23 deletions modules/article/models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ public function rules()
['image', 'image'],
['item_count', 'integer'],
['slug', 'match', 'pattern' => self::$SLUG_PATTERN, 'message' => Yii::t('easyii', 'Slug can contain only 0-9, a-z and "-" characters (max: 128).')],
['slug', 'default', 'value' => null],
['slug', 'unique', 'when' => function($model){
return $model->slug && !self::autoSlug();
}],
['slug', 'default', 'value' => null]
];
}

Expand All @@ -50,25 +47,18 @@ public function behaviors()
return [
SortableModel::className(),
'seoBehavior' => SeoBehavior::className(),
'sluggable' => [
'class' => SluggableBehavior::className(),
'attribute' => 'title',
'ensureUnique' => true
],
'tree' => [
'class' => NestedSetsBehavior::className(),
'treeAttribute' => 'tree'
]
];
}

public function beforeValidate()
{
if(self::autoSlug() && (!$this->isNewRecord || ($this->isNewRecord && $this->slug == ''))){
$this->attachBehavior('sluggable', [
'class' => SluggableBehavior::className(),
'attribute' => 'title',
'ensureUnique' => true
]);
}
return parent::beforeValidate();
}

public static function getTree()
{
$collection = self::find()->sort()->asArray()->all();
Expand Down Expand Up @@ -134,17 +124,11 @@ public function afterDelete()
{
parent::afterDelete();

foreach($this->getItems()->all() as $item){
foreach ($this->getItems()->all() as $item) {
$item->delete();
}

if($this->image) {
@unlink(Yii::getAlias('@webroot') . $this->image);
}
}

public static function autoSlug()
{
return Yii::$app->getModule('admin')->activeModules['article']->settings['categoryAutoSlug'];
}
}
Loading

0 comments on commit 91945cc

Please sign in to comment.