Example #1
0
 /**
  * Creates thumb from model->image attribute with specified width and height.
  * @param int|null $width
  * @param int|null $height
  * @param bool $crop if false image will be resize instead of cropping
  * @return string
  */
 public function thumb($width = null, $height = null, $crop = true)
 {
     if ($this->image && ($width || $height)) {
         return Image::thumbFrontend($this->image, $width, $height, $crop);
     }
     return '';
 }
Example #2
0
 public function actionUpload($dir = '')
 {
     $fileInstance = UploadedFile::getInstanceByName('file');
     if ($fileInstance) {
         $file = Image::upload($fileInstance, $dir);
         if ($file) {
             return $this->getResponse($file);
         }
     }
     return ['error' => 'Unable to save image file'];
 }
Example #3
0
use common\populac\modules\gallery\api\Gallery;
use common\populac\modules\page\api\Page;
use yii\helpers\Html;
use yii\helpers\Url;
$page = Page::get('page-gallery');
$this->title = $page->model->title;
$this->params['breadcrumbs'][] = $this->title;
?>
<h1><?php 
echo $this->title;
?>
</h1>
<br/>

<?php 
foreach (Gallery::cats() as $album) {
    ?>
    <a class="center-block" href="<?php 
    echo Url::to(['ji_sheng_feng_cai/view', 'slug' => $album->slug]);
    ?>
">
        <?php 
    echo Html::img(Image::thumbFrontend($album->image, 160, 120));
    ?>
<br/><?php 
    echo $album->title;
    ?>
    </a>
    <br/>
<?php 
}
Example #4
0
 public function actionEdit($id)
 {
     if (!($model = Item::findOne($id))) {
         return $this->redirect(['/populac/' . $this->module->id]);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if (isset($_FILES) && $this->module->settings['articleThumb']) {
                 $model->image = UploadedFile::getInstance($model, 'image');
                 if ($model->image && $model->validate(['image'])) {
                     $model->image = Image::upload($model->image, 'article');
                 } else {
                     $model->image = $model->oldAttributes['image'];
                 }
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii/article', 'Article updated'));
                 return $this->redirect(['/populac/' . $this->module->id . '/items/edit', 'id' => $model->primaryKey]);
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
                 return $this->refresh();
             }
         }
     } else {
         return $this->render('edit', ['model' => $model]);
     }
 }
Example #5
0
 /**
  * Edit form
  *
  * @param $id
  * @return array|string|\yii\web\Response
  * @throws \yii\web\HttpException
  */
 public function actionEdit($id)
 {
     $class = $this->categoryClass;
     if (!($model = $class::findOne($id))) {
         return $this->redirect(['/populac/' . $this->moduleName]);
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if (isset($_FILES) && $this->module->settings['categoryThumb']) {
                 $model->image = UploadedFile::getInstance($model, 'image');
                 if ($model->image && $model->validate(['image'])) {
                     $model->image = Image::upload($model->image, $this->moduleName);
                 } else {
                     $model->image = $model->oldAttributes['image'];
                 }
             }
             if ($model->save()) {
                 $this->flash('success', Yii::t('easyii', 'Category updated'));
             } else {
                 $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors()));
             }
             return $this->refresh();
         }
     } else {
         return $this->render('@common/populac/views/category/edit', ['model' => $model]);
     }
 }
Example #6
0
use common\populac\widgets\Redactor;
$module = $this->context->module->id;
\common\populac\assets\AdminAsset::register($this);
$form = ActiveForm::begin(['enableAjaxValidation' => true, 'options' => ['enctype' => 'multipart/form-data', 'class' => 'model-form'], 'fieldConfig' => ['template' => "{label}\n<span class=\"col-md-10\">{input}</span>\n<span class=\"col-md-offset-2 col-md-10\">{error}</span>", 'labelOptions' => ['class' => 'col-md-2 control-label text-right']]]);
echo $form->field($model, 'title');
?>

<?php 
if ($this->context->module->settings['articleThumb']) {
    ?>
    <?php 
    if ($model->image) {
        ?>
        <div class="col-md-offset-2">
            <img src="<?php 
        echo Image::thumb($model->image, 240);
        ?>
">
            <a href="<?php 
        echo Url::to(['/populac/' . $module . '/items/clear-image', 'id' => $model->primaryKey]);
        ?>
"
               class="text-danger confirm-delete" title="<?php 
        echo Yii::t('easyii', 'Clear image');
        ?>
">
                <?php 
        echo Yii::t('easyii', 'Clear image');
        ?>
</a>
        </div>
Example #7
0
echo Yii::t('easyii', 'Image');
?>
</th>
        <th><?php 
echo Yii::t('easyii', 'Description');
?>
</th>
        <th width="150"></th>
    </tr>
    </thead>
    <tbody>
    <?php 
foreach ($photos as $photo) {
    ?>
        <?php 
    echo str_replace(['{{photo_id}}', '{{photo_thumb}}', '{{photo_image}}', '{{photo_description}}'], [$photo->primaryKey, Image::thumb($photo->image, Photo::PHOTO_THUMB_WIDTH, Photo::PHOTO_THUMB_HEIGHT), $photo->image, $photo->description], $photoTemplate);
    ?>
    <?php 
}
?>
    </tbody>
</table>
<p class="empty" style="display: <?php 
echo count($photos) ? 'none' : 'block';
?>
;"><?php 
echo Yii::t('easyii', 'No photos uploaded yet');
?>
.</p>

<?php 
Example #8
0
 public function actionImage($id)
 {
     $success = null;
     if ($photo = Photo::findOne($id)) {
         $oldImage = $photo->image;
         $photo->image = UploadedFile::getInstance($photo, 'image');
         if ($photo->image && $photo->validate(['image'])) {
             $photo->image = Image::upload($photo->image, 'photos', Photo::PHOTO_MAX_WIDTH);
             if ($photo->image) {
                 if ($photo->save()) {
                     @unlink(Yii::getAlias('@webroot') . $oldImage);
                     $success = ['message' => Yii::t('easyii', 'Photo uploaded'), 'photo' => ['image' => $photo->image, 'thumb' => Image::thumb($photo->image, Photo::PHOTO_THUMB_WIDTH, Photo::PHOTO_THUMB_HEIGHT)]];
                 } else {
                     @unlink(Yii::getAlias('@webroot') . $photo->image);
                     $this->error = Yii::t('easyii', 'Update error. {0}', $photo->formatErrors());
                 }
             } else {
                 $this->error = Yii::t('easyii', 'File upload error. Check uploads folder for write permissions');
             }
         } else {
             $this->error = Yii::t('easyii', 'File is incorrect');
         }
     } else {
         $this->error = Yii::t('easyii', 'Not found');
     }
     return $this->formatResponse($success);
 }