Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
noumo committed Mar 23, 2015
1 parent 867d231 commit 79ad26b
Show file tree
Hide file tree
Showing 21 changed files with 320 additions and 242 deletions.
5 changes: 5 additions & 0 deletions behaviors/SeoBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public function afterDelete()
}
}

public function getSeo()
{
return $this->owner->hasOne(SeoText::className(), ['item_id' => $this->owner->primaryKey()[0]])->where(['model' => get_class($this->owner)]);
}

public function getSeo_h1()
{
return $this->seoText->h1;
Expand Down
13 changes: 0 additions & 13 deletions components/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ public static function __callStatic($method, $params)
return call_user_func_array([self::$classes[$name], 'api_' . $method], $params);
}

public static function cache($key, $duration, $callable)
{
$cache = Yii::$app->cache;
if($cache->exists($key)){
$data = $cache->get($key);
}
else{
$data = $callable();
$cache->set($key, $data, $duration);
}
return $data;
}

public function wrapLiveEdit($text, $path, $tag = 'span')
{
return '<'.$tag.' class="easyiicms-edit" data-edit="/admin/'.$this->module.'/'.$path.'">'.$text.'</'.$tag.'>';
Expand Down
46 changes: 46 additions & 0 deletions components/ApiObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
namespace yii\easyii\components;

use Yii;
use yii\easyii\helpers\GD;
use yii\easyii\helpers\Image;
use yii\easyii\helpers\Upload;
use yii\helpers\FileHelper;
use yii\widgets\LinkPager;

class ApiObject extends \yii\base\Object
{
public $source = [];
public $adp;
private $_seo;

public function __construct($model){
if(isset($model->seo)){
$this->_seo = $model->seo;
}

foreach($model->attributes as $attribute => $value){
if($this->canSetProperty($attribute)){
$this->{$attribute} = $value;
} else {
$this->source[$attribute] = $value;
}
}
}

public function thumb($width = null, $height = null, $crop = true)
{
if($this->image && ($width || $height)){
return Image::thumb(Yii::getAlias('@webroot') . $this->image, $width, $height, $crop);
}
return '';
}

public function getPages(){
return $this->adp ? LinkPager::widget(['pagination' => $this->adp->pagination]) : '';
}

public function seo($attribute){
return (!empty($this->_seo) && isset($this->_seo->{$attribute})) ? $this->_seo->{$attribute} : '';
}
}
19 changes: 19 additions & 0 deletions components/NSActiveQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace yii\easyii\components;

use creocoder\nestedsets\NestedSetsQueryBehavior;

class NSActiveQuery extends ActiveQuery
{
public function behaviors() {
return [
NestedSetsQueryBehavior::className(),
];
}

public function sort()
{
$this->orderBy('order_num DESC, lft ASC');
return $this;
}
}
10 changes: 10 additions & 0 deletions components/NSActiveRecord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace yii\easyii\components;

class NSActiveRecord extends ActiveRecord
{
public static function find()
{
return new NSActiveQuery(get_called_class());
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"yiisoft/yii2": "*",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-swiftmailer": "*",
"creocoder/yii2-nested-sets": "0.9.*",
"bower-asset/fancybox": "*",
"bower-asset/jquery.switcher": "*"
},
Expand Down
21 changes: 19 additions & 2 deletions helpers/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,39 @@ static function createThumbnail($fileName, $width, $height = null, $crop = true)
return self::copyResizedImage($fileName, $thumbFile, $width, $height, $crop) ? Upload::getLink($thumbFile) : false;
}

static function thumb($filename, $width = null, $height = null, $crop = true)
{
if(file_exists($filename))
{
$info = pathinfo($filename);
$thumbName = $info['filename'] . '-' . md5( filemtime($filename) . (int)$width . (int)$height . (int)$crop ) . '.' . $info['extension'];
$thumbFile = Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . Upload::$UPLOADS_DIR . DIRECTORY_SEPARATOR . 'thumbs' . DIRECTORY_SEPARATOR . $thumbName;
$thumbWebFile = '/' . Upload::$UPLOADS_DIR . '/thumbs/' . $thumbName;
if(file_exists($thumbFile)){
return $thumbWebFile;
}
elseif(FileHelper::createDirectory(dirname($thumbFile), 0777) && self::copyResizedImage($filename, $thumbFile, $width, $height, $crop)){
return $thumbWebFile;
}
}
return '';
}

static function copyResizedImage($inputFile, $outputFile, $width, $height = null, $crop = true)
{
if (extension_loaded('gd'))
{
$image = new GD($inputFile);

if($height) {
if($crop){
if($width && $crop){
$image->cropThumbnail($width, $height);
} else {
$image->resize($width, $height);
}
} else {
$image->resize($width);
}

return $image->save($outputFile);
}
elseif(extension_loaded('imagick'))
Expand Down
2 changes: 1 addition & 1 deletion helpers/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Upload
{
static $UPLOADS_DIR = 'uploads';
public static $UPLOADS_DIR = 'uploads';

public static function file(UploadedFile $fileInstance, $dir = '', $namePostfix = true)
{
Expand Down
14 changes: 13 additions & 1 deletion media/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ html{
color: #fff;
}

#admin-body .actions li i{
margin-right: 8px;
}
#admin-body .actions .glyphicon-menu-hamburger{
cursor: pointer;
font-size: 15px;
color: #777;
}
#admin-body .actions .glyphicon-menu-hamburger:hover{
color: #337ab7;
}

/*--------------- HELPERS ---------------*/

h4{
Expand All @@ -163,7 +175,7 @@ h4 b{
}

.confirm-delete{
color: #a94442;
color: #a94442 !important;
}
.color-red{
color: #a94442;
Expand Down
5 changes: 5 additions & 0 deletions messages/ru/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@
'Update' => 'Обновить',
'Move up' => 'Переместить выше',
'Move down' => 'Переместить ниже',
'Delete' => 'Удалить',
'Turn On' => 'Включить',
'Turn Off' => 'Выключить',
'Add subcategory' => 'Добавить подкатегорию',
'Anti-spam check' => 'Проверка на спам',
'Actions' => 'Действия',

'Not found' => 'Не найдено',
'Create error. {0}' => 'Ошибка при создании. {0}',
Expand Down
Loading

0 comments on commit 79ad26b

Please sign in to comment.