/** * Initialize component */ public static function initialize() { self::$initialized = true; if (isset(Yii::app()->settings) && Yii::app()->settings instanceof SSystemSettings) { self::$db_settings = Yii::app()->settings->get(self::$settings_key); } else { self::$db_settings = self::$defaults; } }
public function testSettings() { Yii::import('application.modules.store.components.StoreImagesConfig'); $this->assertEquals(StoreImagesConfig::get('path'), 'webroot.uploads.product'); // Test loading from db $r1 = rand(800, 2000); $r2 = rand(800, 2000); Yii::app()->settings->set(StoreImagesConfig::$settings_key, array('maximum_image_size' => $r1 . 'x' . $r2)); StoreImagesConfig::initialize(); $this->assertEquals(StoreImagesConfig::get('maximum_image_size'), array($r1, $r2)); }
/** * Draws watermark on image. * * @param $fullPath string to image */ public function watermark($fullPath) { // Add watermark; if (StoreImagesConfig::get('watermark_active')) { $pic = PhpThumbFactory::create($fullPath); $pos = StoreImagesConfig::get('watermark_position_vertical') . StoreImagesConfig::get('watermark_position_horizontal'); try { $watermark = PhpThumbFactory::create(Yii::getPathOfAlias('webroot.uploads') . '/watermark.png'); $pic->addWatermark($watermark, $pos, StoreImagesConfig::get('watermark_opacity'), 0, 0); $pic->save($fullPath); } catch (Exception $e) { // pass } } }
public function getUrl($size = false, $resizeMethod = false, $random = false) { if ($size !== false) { $thumbPath = Yii::getPathOfAlias(StoreImagesConfig::get('thumbPath')) . '/' . $size; if (!file_exists($thumbPath)) { mkdir($thumbPath, 0777, true); } // Path to source image $fullPath = Yii::getPathOfAlias('webroot') . $this->image; $imageName = explode('/', $this->image); $imageName = array_pop($imageName); // Path to thumb $thumbPath = $thumbPath . '/' . $imageName; if (!file_exists($thumbPath)) { // Resize if needed Yii::import('ext.phpthumb.PhpThumbFactory'); $sizes = explode('x', $size); $thumb = PhpThumbFactory::create($fullPath); if ($resizeMethod === false) { $resizeMethod = StoreImagesConfig::get('resizeThumbMethod'); } $thumb->{$resizeMethod}($sizes[0], $sizes[1])->save($thumbPath); } return StoreImagesConfig::get('thumbUrl') . $size . '/' . $imageName; } if ($random === true) { return StoreImagesConfig::get('url') . $this->image . '?' . rand(1, 10000); } return StoreImagesConfig::get('url') . $this->image; }
<?php /** * Images tabs */ Yii::import('ext.jqPrettyPhoto'); Yii::import('application.modules.store.components.StoreImagesConfig'); // Register view styles Yii::app()->getClientScript()->registerCss('infoStyles', "\n\ttable.imagesList {\n\t\tfloat: left;\n\t\twidth: 45%;\n\t\tmin-width:250px;\n\t\tmargin-right: 15px;\n\t\tmargin-bottom: 15px;\n\t}\n\tdiv.MultiFile-list {\n\t\tmargin-left:190px\n\t}\n"); // Upload button echo CHtml::openTag('div', array('class' => 'row')); echo CHtml::label(Yii::t('StoreModule.admin', 'Выберите изображения'), 'files'); $this->widget('system.web.widgets.CMultiFileUpload', array('name' => 'StoreProductImages', 'model' => $model, 'attribute' => 'files', 'accept' => implode('|', StoreImagesConfig::get('extensions')))); echo CHtml::closeTag('div'); // Images if ($model->images) { foreach ($model->images as $image) { $this->widget('zii.widgets.CDetailView', array('data' => $image, 'id' => 'ProductImage' . $image->id, 'htmlOptions' => array('class' => 'detail-view imagesList'), 'attributes' => array(array('label' => Yii::t('StoreModule.admin', 'Изображение'), 'type' => 'raw', 'value' => CHtml::link(CHtml::image($image->getUrl(false, false, true), CHtml::encode($image->name), array('height' => '150px')), $image->getUrl(false, false, true), array('target' => '_blank', 'class' => 'pretty', 'title' => CHtml::encode($model->name)))), 'id', array('name' => 'is_main', 'type' => 'raw', 'value' => CHtml::radioButton('mainImageId', $image->is_main, array('value' => $image->id))), array('name' => 'author', 'type' => 'raw', 'value' => $image->author ? CHtml::encode($image->author->username) : ''), 'date_uploaded', array('label' => Yii::t('StoreModule.admin', 'Название'), 'type' => 'raw', 'value' => CHtml::textField('image_titles[' . $image->id . ']', $image->title)), array('label' => Yii::t('StoreModule.admin', 'Действия'), 'type' => 'raw', 'value' => CHtml::ajaxLink(Yii::t('StoreModule.admin', 'Удалить'), $this->createUrl('deleteImage', array('id' => $image->id)), array('type' => 'POST', 'data' => array(Yii::app()->request->csrfTokenName => Yii::app()->request->csrfToken), 'success' => "js:\$('#ProductImage{$image->id}').hide().remove()"), array('id' => 'DeleteImageLink' . $image->id, 'confirm' => Yii::t('StoreModule.admin', 'Вы действительно хотите удалить это изображение?'))))))); } } // Fancybox ext $this->widget('application.extensions.fancybox.EFancyBox', array('target' => 'a.pretty', 'config' => array()));
/** * @return string Path to save product image */ public static function getSavePath() { return Yii::getPathOfAlias(StoreImagesConfig::get('path')); }
/** * @return string Path to save product image */ public static function getSavePath() { //return Yii::getPathOfAlias(Yii::app()->params['storeImages']['path']); return Yii::getPathOfAlias(StoreImagesConfig::get('path')); }
/** * @return string * */ public function getFilePath() { return Yii::getPathOfAlias(StoreImagesConfig::get('path')) . '/' . $this->name; }