To change this template file, choose Tools | Templates and open the template in the editor.
 /**
  * testImage
  *
  * @return void
  */
 public function testImage()
 {
     $image = array('id' => 'e479b480-f60b-11e1-a21f-0800200c9a66', 'model' => 'Test', 'path' => 'test' . DS . 'path' . DS, 'extension' => 'jpg', 'adapter' => 'Local');
     $entity = $this->FileStorage->newEntity($image, ['accessibleFields' => ['*' => true]]);
     $result = $this->Storage->url($entity);
     $expected = 'Test/5c/39/33/e479b480f60b11e1a21f0800200c9a66/e479b480f60b11e1a21f0800200c9a66.jpg';
     $this->assertEquals($result, $expected);
 }
 /**
  * testFallbackImage
  *
  * @return void
  */
 public function testFallbackImage()
 {
     Configure::write('Media.fallbackImages.Test.t150', 't150fallback.png');
     $result = $this->Image->fallbackImage(array('fallback' => true), array(), 't150');
     $this->assertEqual($result, '<img src="/img/placeholder/t150.jpg" alt="" />');
     $result = $this->Image->fallbackImage(array('fallback' => 'something.png'), array(), 't150');
     $this->assertEqual($result, '<img src="/img/something.png" alt="" />');
     $result = $this->Image->fallbackImage(array(), array(), 't150');
     $this->assertEqual($result, '');
 }
 public static function RemoveFileOnly($pk, $fieldName)
 {
     $modelRemove = self::model()->findByPk($pk);
     if (is_null($modelRemove) || empty($modelRemove->{$fieldName})) {
         return;
     }
     $aDate = explode('-', $modelRemove->date_only);
     $pathUpload = ProGlobalEnquiry::$folderUpload . "/{$aDate['0']}/{$aDate['1']}/{$aDate['2']}";
     $ImageHelper = new ImageHelper();
     $ImageHelper->folder = '/' . $pathUpload;
     $ImageHelper->deleteFile($ImageHelper->folder . '/' . $modelRemove->{$fieldName});
 }
 /**
  * Override parent
  */
 function handleFileUpload($fileParameters, $id)
 {
     $filename = $this->fileDefaultName;
     if (array_key_exists($this->parameterFile, $fileParameters) and array_key_exists('name', $fileParameters[$this->parameterFile]) and $fileParameters[$this->parameterFile]['name'] != '') {
         $imageHelper = new ImageHelper();
         $filename = $imageHelper->upload($this->fileBasename, $id, $fileParameters[$this->parameterFile]);
         /*if ($filepath != "") {
         		$imageHelper = new SimpleImage();
         		$imageHelper->load($filepath);
         		$imageHelper->resize(100,100);
         		$imageHelper->save('../img/news/News-".$id."100x100.png');
         		}*/
     }
     return $filename;
 }
 public function actionDescription()
 {
     Yii::app()->page->setInfo(array("description" => $this->description, "keyWord" => $this->keyWord));
     $id = 0;
     $class = $this->classModel;
     if (!empty($_GET["slug"])) {
         $model = $class::fetchBySlug(trim($_GET["slug"]));
         if ($model->id > 0) {
             $_GET["id"] = $model->id;
             $id = $model->id;
         }
     }
     $error = Yii::t("page", "Произошла ошибка перехода на страницу, проверьте правильно написания адреса страницы");
     if ($id > 0) {
         $item = CatalogFirmsService::fetch($id);
         if ($item->id > 0) {
             CCModelHelper::colCounter($item);
             // Картинки тура
             $images = ImageHelper::getImages($item);
             Yii::app()->page->title = $item->name . " - " . Yii::t("page", "услуги от компании");
             $this->render('description', array("item" => $item, "images" => $images, "firmsService" => CatalogFirmsService::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("firm_id=:firm_id AND id!=:id")->setParams(array(":firm_id" => $item->firm_id, ":id" => $item->id))->setCache(0)), "firmsItems" => CatalogFirmsItems::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("firm_id=:firm_id")->setParams(array(":firm_id" => $item->firm_id))->setCache(0))));
         } else {
             throw new CHttpException("", $error);
         }
     } else {
         throw new CHttpException("", $error);
     }
 }
Beispiel #6
0
 public static function getChildsId($id)
 {
     $data = array();
     $ids = array();
     if (!is_array($id)) {
         $id = array($id);
     }
 /**
  * Prepare asset for cropping.
  */
 public function actionPrepareForCrop()
 {
     $this->requireAjaxRequest();
     $elementId = craft()->request->getParam('elementId');
     // Get the asset file
     $asset = craft()->assets->getFileById($elementId);
     $source = $asset->getSource();
     $sourceType = $source->getSourceType();
     $file = $sourceType->getLocalCopy($asset);
     try {
         // Test if we will be able to perform image actions on this image
         if (!craft()->images->checkMemoryForImage($file)) {
             IOHelper::deleteFile($file);
             $this->returnErrorJson(Craft::t('The selected image is too large.'));
         }
         // Scale to fit 500x500 for fitting in CP modal
         craft()->images->loadImage($file)->scaleToFit(500, 500, false)->saveAs($file);
         list($width, $height) = ImageHelper::getImageSize($file);
         // If the file is in the format badscript.php.gif perhaps.
         if ($width && $height) {
             $html = craft()->templates->render('_components/tools/cropper_modal', array('imageUrl' => $asset->url, 'width' => $width, 'height' => $height, 'fileName' => $asset->filename));
             $this->returnJson(array('html' => $html));
         }
     } catch (Exception $exception) {
         $this->returnErrorJson($exception->getMessage());
     }
 }
Beispiel #8
0
 public static function getInstance()
 {
     if (null == self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function actionDescription()
 {
     Yii::app()->page->setInfo(array("description" => $this->description, "keyWord" => $this->keyWord));
     $id = 0;
     $class = $this->classModel;
     if (!empty($_GET["slug"])) {
         $model = $class::fetchBySlug(trim($_GET["slug"]));
         if ($model->id > 0) {
             $_GET["id"] = $model->id;
             $id = $model->id;
         } else {
             $arrId = explode("-", $_GET["slug"]);
             if (sizeof($arrId) > 0) {
                 $id = (int) $arrId[0];
             }
         }
     }
     $error = Yii::t("page", "Произошла ошибка перехода на страницу, проверьте правильно написания адреса страницы");
     if ($id > 0) {
         $item = CatalogTours::fetch($id);
         if ($item->id > 0) {
             LogHelper::saveCatLogTours($item->id);
             CCModelHelper::colCounter($item);
             // Картинки тура
             $images = ImageHelper::getImages($item);
             Yii::app()->page->title = $item->name . ", тур " . $item->category_id->name . ", " . $item->country_id->name;
             $this->render('description', array("item" => $item, "images" => $images, "otherTours" => CatalogTours::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("image>'' AND country_id=:country_id AND id!=:id AND firm_id!=:firm_id")->setParams(array(":country_id" => $item->country_id->id, ":id" => $item->id, ":firm_id" => $item->firm_id->id))->setOrderBy("col DESC")->setLimit(6)), "firmsTours" => CatalogTours::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("image>'' AND firm_id=:firm_id AND id!=:id")->setParams(array(":firm_id" => $item->firm_id->id, ":id" => $item->id))->setOrderBy("col DESC")->setLimit(6)), "tourCount" => CatalogTours::count(DBQueryParamsClass::CreateParams()->setConditions("country_id=:country")->setParams(array(":country" => $item->country_id->id))), "firmCount" => CatalogFirms::count(DBQueryParamsClass::CreateParams()->setConditions("country_id=:country")->setParams(array(":country" => $item->country_id->id)))));
         } else {
             throw new CHttpException("", $error);
         }
     } else {
         throw new CHttpException("", $error);
     }
 }
Beispiel #10
0
 public function init()
 {
     parent::init();
     $image = $this->params['content']->image;
     $image['filename'] = ImageHelper::resizeDown($image['filename'], $this->params['content']->width, $this->params['content']->height);
     $this->params['content']->image = $image;
 }
 /**
  * Returns an array of the width and height of the image.
  *
  * @return array
  */
 public function getSize()
 {
     if (!isset($this->size)) {
         $size = ImageHelper::getImageSize($this->path);
         $this->size = array($size[0], $size[1]);
     }
     return $this->size;
 }
Beispiel #12
0
 public function actionDescription()
 {
     Yii::app()->page->setInfo(array("description" => $this->description, "keyWord" => $this->keyWord));
     $id = 0;
     $class = $this->classModel;
     $slug = !empty($_GET["slug"]) ? $_GET["slug"] : "";
     if (!empty($_GET["slug"])) {
         $model = $class::fetchBySlug(trim($slug));
         if ($model->id > 0) {
             $_GET["id"] = $model->id;
             $id = $model->id;
         }
     }
     // Проверяем по ID
     if ($id == 0) {
         $ar = explode("-", $slug);
         if ((int) $ar[0] > 0) {
             $model = $class::fetch((int) $ar[0]);
             $id = $model->id;
         }
     }
     if ($id > 0) {
         if ($model->id > 0) {
             $item = $model;
         } else {
             $item = $class::fetch($id);
         }
         if ($item->id > 0) {
             $images = ImageHelper::getImages($item);
             $other = $class::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("category_id=:category_id AND id!=:id")->setParams(array(":category_id" => $item->category_id->id, ":id" => $item->id))->setOrderBy("id DESC")->setLimit(12));
             $tourCategory = $item->tour_category;
             if (!empty($tourCategory) && sizeof($tourCategory) > 0) {
                 $dopSQL = " AND ( ";
                 $m = 0;
                 foreach ($tourCategory as $tCategory) {
                     if ($m > 0) {
                         $dopSQL .= " OR ";
                     }
                     $dopSQL .= "category_id=" . $tCategory->id;
                     $m++;
                 }
                 $dopSQL .= ") ";
                 $tours = CatalogTours::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("country_id=:country_id " . $dopSQL)->setParams(array(":country_id" => $item->country_id->id))->setOrderBy("rating DESC")->setLimit(9));
             } elseif ($item->country_id->id > 0) {
                 $tours = CatalogTours::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("country_id=:country_id")->setParams(array(":country_id" => $item->country_id->id))->setOrderBy("rating DESC")->setLimit(10));
             } else {
                 $tours = array();
             }
             Yii::app()->page->title = $item->name;
             $this->render('description', array("item" => $item, "other" => $other, "images" => $images, "tours" => $tours, "hotelCount" => $class::count(DBQueryParamsClass::CreateParams()->setConditions("category_id=:category_id")->setParams(array(":category_id" => $item->category_id->id)))));
         } else {
             throw new CHttpException("Ошибка", Yii::t("page", "Ошибка перехода на страницу"));
         }
     } else {
         throw new CHttpException("Ошибка", Yii::t("page", "Ошибка перехода на страницу"));
     }
 }
 public function getThumb($size = null, $crop = true)
 {
     if (is_string($size)) {
         $size = ['width' => 64, 'height' => 64];
     }
     $dir = pathinfo($this->getPk(), PATHINFO_DIRNAME);
     $name = pathinfo($this->getPk(), PATHINFO_BASENAME);
     return ImageHelper::thumb($dir, $name, $size, $crop)->getSrc();
 }
Beispiel #14
0
 public function deleteImage($fieldName, $path, $oldImage)
 {
     if (!empty($oldImage)) {
         ImageHelper::deleteFile($path . '/' . $oldImage);
         if (array_key_exists($fieldName, $this->aImageSize) && is_array($this->aImageSize[$fieldName])) {
             $aSize = $this->aImageSize[$fieldName];
             foreach ($aSize as $key => $value) {
                 ImageHelper::deleteFile($path . '/' . $key . '/' . $oldImage);
             }
         }
     }
 }
 public function actionDescription()
 {
     $slug = Yii::app()->request->getParam("slug", "");
     if (!empty($slug)) {
         $item = CatalogAttractions::fetchBySlug($slug);
         if ($item->id > 0) {
             Yii::app()->page->setTitle($item->name);
             $list = CatalogAttractions::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("city_id=:cid AND id!=:id")->setParams(array(":cid" => $item->city_id->id, ":id" => $item->id))->setLimit(4));
             $images = ImageHelper::getImages($item);
             $this->render("description", array("item" => $item, "other" => $list, "images" => $images));
         }
     }
 }
Beispiel #16
0
 public function init()
 {
     parent::init();
     $keys = array_keys($this->params['content']->images);
     $image = $this->params['content']->images[$keys[rand(0, count($keys) - 1)]];
     $image['filename'] = ImageHelper::resizeDown($image['filename'], $this->params['content']->width, $this->params['content']->height);
     $this->params['image'] = $image;
     if (isset($image['data'][Yii::app()->language . '_caption'])) {
         $this->params['caption'] = $image['data'][Yii::app()->language . '_caption'];
     } else {
         $this->params['caption'] = $this->params['widget']->title;
     }
 }
Beispiel #17
0
 public function run()
 {
     $val = $this->model->{$this->attribute};
     if (!$this->model->isNewRecord && $val) {
         $id = $this->id . get_class($this);
         $files_data = $this->model->uploadFiles();
         $attribute_data = $files_data[$this->attribute];
         $directory = trim($attribute_data['dir'], '/');
         $preview = ImageHelper::thumb($directory, $val, array('width' => null, 'height' => 128));
         $preview .= CHtml::ajaxLink('X', array('/main/helpAdmin/saveAttribute'), array('type' => 'post', 'data' => array('model' => get_class($this->model), 'id' => $this->model->primaryKey, 'attribute' => $this->attribute, 'value' => '', 'unlink_file' => $directory . '/' . $val), 'success' => 'js:function() {$("#' . $id . '").remove();}'), array('class' => 'btn btn-danger delete-img'));
         echo CHtml::tag('div', array('id' => $id), $preview);
     }
     echo CHtml::activeFileField($this->model, $this->attribute, $this->htmlOptions);
 }
 protected function preparePartnerSlides()
 {
     $slides = array();
     $data = Yii::app()->db->createCommand(sprintf('SELECT  p.title, ph.filename, ph.title photo_title, ph.description photo_description
                                                         FROM partners p 
                                                         LEFT JOIN gallery g ON g.`gallery_id` = p.gallery_id
                                                         LEFT JOIN photo ph ON ph.gallery_id = g.gallery_id
                                                         WHERE p.is_active = 1 AND p.partner_id <> %d AND (ph.is_top <> 1 OR ph.is_top IS NULL)
                                                         ORDER BY ph.sort_order DESC', Yii::app()->params['partner_id']))->queryAll();
     foreach ($data as $slide) {
         $slides[] = array('url' => ImageHelper::imageUrl('', $slide['filename']), 'content' => sprintf('<img src=\'%s\' alt\'%s\' title=\'%s\'></img>', ImageHelper::imageUrl('partner_footer_frontend', $slide['filename']), ContentHelper::prepareStr($slide['title']), ContentHelper::prepareStr($slide['title'])));
     }
     return $slides;
 }
 public function init()
 {
     craft()->on('assets.onSaveAsset', function (Event $event) {
         $asset = $event->params['asset'];
         if (craft()->imageResizer->getSettings()->enabled) {
             // Only process if it's a new asset being saved.
             if ($event->params['isNewAsset']) {
                 // Is this a manipulatable image?
                 if (ImageHelper::isImageManipulatable(IOHelper::getExtension($asset->filename))) {
                     craft()->imageResizer->resize($asset);
                 }
             }
         }
     });
 }
 protected function prepareSlides()
 {
     $slides = array();
     $data = Yii::app()->db->createCommand('SELECT gp.*, p.title post_title, ph.filename, ph.title photo_title, ph.description photo_description, u.firstname, u.lastname
                                                         FROM galleryposts gp
                                                         LEFT JOIN users u ON u.user_id = gp.user_id                                                            
                                                         LEFT JOIN posting p ON p.post_id = gp.post_id
                                                         LEFT JOIN gallery g ON g.`gallery_id` = p.gallery_id
                                                         LEFT JOIN photo ph ON ph.gallery_id = g.gallery_id
                                                         WHERE gp.is_top = 1 AND gp.publication_date <= NOW()
                                                         ORDER BY ph.sort_order DESC')->queryAll();
     foreach ($data as $slide) {
         $slides[] = array('url' => ImageHelper::imageUrl('main_page_slider', $slide['filename']), 'content' => sprintf('<a href=\'%s\'><img src=\'%s\' alt=\'%s\' title=\'%s\'></img></a>', Yii::app()->createAbsoluteUrl('portfolio/default/view', array('id' => $slide['post_id'])), ImageHelper::imageUrl('main_page_slider', $slide['filename']), ContentHelper::prepareStr($slide['photo_description']), ContentHelper::prepareStr($slide['photo_description'])));
     }
     return $slides;
 }
 /**
  * Loads an image from a file system path.
  *
  * @param string $path
  *
  * @throws Exception
  * @return Image
  */
 public function loadImage($path)
 {
     if (!IOHelper::fileExists($path)) {
         throw new Exception(Craft::t('No file exists at the path “{path}”', array('path' => $path)));
     }
     list($width, $height) = ImageHelper::getImageSize($path);
     $svg = IOHelper::getFileContents($path);
     // If the size is defined by viewbox only, add in width and height attributes
     if (!preg_match(static::SVG_WIDTH_RE, $svg) && preg_match(static::SVG_HEIGHT_RE, $svg)) {
         $svg = preg_replace(static::SVG_TAG_RE, "<svg width=\"{$width}px\" height=\"{$height}px\" ", $svg);
     }
     $this->_height = $height;
     $this->_width = $width;
     $this->_svgContent = $svg;
     return $this;
 }
Beispiel #22
0
function gallery_itemYTShortcode($atts, $content = null)
{
    global $gwidth, $gheight, $gcolumns, $galleryArray, $cation_gallery, $border_gallery, $padding_item, $id_uniq, $hover_gallery;
    $galleryArray[] = array('src' => isset($atts['src']) ? $atts['src'] : '', 'tag' => isset($atts['tag']) && $atts['tag'] != '' ? $atts['tag'] : '', 'content' => $content);
    extract(ytshortcode_atts(array("title" => '', "src" => '', "video_addr" => '', "tag" => ''), $atts));
    if (strpos($video_addr, 'youtube.com')) {
        $src_pop = $video_addr;
        if ($src == "" || !is_file($src)) {
            $src = 'plugins/system/ytshortcodes/assets/images/youtube.png';
        }
    } elseif (strpos($video_addr, 'vimeo.com')) {
        $src_pop = $video_addr;
        if ($src == "" || !is_file($src)) {
            $src = 'plugins/system/ytshortcodes/assets/images/vimeo.jpg';
        }
    } else {
        $src_pop = "";
        if ($src == "" || !is_file($src)) {
            $src = 'plugins/system/ytshortcodes/assets/images/URL_IMAGES.png';
        }
    }
    $small_image = array('width' => $gwidth, 'height' => $gheight, 'function' => 'resize', 'function_mode' => 'fill');
    if (strpos($src, 'http://') !== false) {
        $simage = $src;
    } else {
        if (is_file($src) && strpos($src, 'http://') !== true) {
            $simage = JURI::base() . ImageHelper::init($src, $small_image)->src();
        } else {
            $simage = JURI::base(true) . '/' . $src;
        }
    }
    $gallery_item = '';
    $gallery_item .= "<li class='" . $id_uniq . " masonry-brick " . strtolower(str_replace(",", " ", $tag)) . $id_uniq . "' ";
    if ($gcolumns > 0) {
        $gallery_item .= " style=' " . $border_gallery . "'";
    }
    $gallery_item .= ">";
    $gallery_item .= "<div class='item-gallery' style='" . $padding_item . "'>";
    $gallery_item .= "<a title='" . $title . "' href='" . $simage . "' data-rel='prettyPhoto[bkpGallery]'>";
    $gallery_item .= "<div class='item-gallery-hover" . $hover_gallery . "'></div>";
    $gallery_item .= "<h3 class='item-gallery-title " . $cation_gallery . " '>" . parse_shortcode(str_replace(array("<br/>", "<br>", "<br />"), " ", $content)) . "</h3><div class='image-overlay'></div>";
    $gallery_item .= "<img src='" . $simage . "' title='" . $title . "' alt='" . $title . "' />";
    $gallery_item .= "</a>";
    $gallery_item .= "</div><h4 class='item-gallery-title " . $cation_gallery . " '>" . parse_shortcode(str_replace(array("<br/>", "<br>", "<br />"), " ", $content)) . "</h4>";
    $gallery_item .= "</li>";
    return str_replace("<br/>", " ", $gallery_item);
}
 /**
  * Upload a logo for the admin panel.
  *
  * @return null
  */
 public function actionUploadSiteImage()
 {
     $this->requireAjaxRequest();
     $this->requireAdmin();
     $type = craft()->request->getRequiredPost('type');
     if (!in_array($type, $this->_allowedTypes)) {
         $this->returnErrorJson(Craft::t('That is not an accepted site image type.'));
     }
     // Upload the file and drop it in the temporary folder
     $file = UploadedFile::getInstanceByName('image-upload');
     try {
         // Make sure a file was uploaded
         if ($file) {
             $fileName = AssetsHelper::cleanAssetName($file->getName());
             if (!ImageHelper::isImageManipulatable($file->getExtensionName())) {
                 throw new Exception(Craft::t('The uploaded file is not an image.'));
             }
             $folderPath = craft()->path->getTempUploadsPath();
             IOHelper::ensureFolderExists($folderPath);
             IOHelper::clearFolder($folderPath, true);
             move_uploaded_file($file->getTempName(), $folderPath . $fileName);
             // Test if we will be able to perform image actions on this image
             if (!craft()->images->checkMemoryForImage($folderPath . $fileName)) {
                 IOHelper::deleteFile($folderPath . $fileName);
                 $this->returnErrorJson(Craft::t('The uploaded image is too large'));
             }
             list($width, $height) = ImageHelper::getImageSize($folderPath . $fileName);
             if (IOHelper::getExtension($fileName) != 'svg') {
                 craft()->images->cleanImage($folderPath . $fileName);
             } else {
                 craft()->images->loadImage($folderPath . $fileName)->saveAs($folderPath . $fileName);
             }
             $constraint = 500;
             // If the file is in the format badscript.php.gif perhaps.
             if ($width && $height) {
                 // Never scale up the images, so make the scaling factor always <= 1
                 $factor = min($constraint / $width, $constraint / $height, 1);
                 $html = craft()->templates->render('_components/tools/cropper_modal', array('imageUrl' => UrlHelper::getResourceUrl('tempuploads/' . $fileName), 'width' => round($width * $factor), 'height' => round($height * $factor), 'factor' => $factor, 'constraint' => $constraint, 'fileName' => $fileName));
                 $this->returnJson(array('html' => $html));
             }
         }
     } catch (Exception $exception) {
         $this->returnErrorJson($exception->getMessage());
     }
     $this->returnErrorJson(Craft::t('There was an error uploading your photo'));
 }
 /**
  * Upload a logo for the admin panel.
  *
  * @return null
  */
 public function actionUploadLogo()
 {
     $this->requireAjaxRequest();
     $this->requireAdmin();
     // Upload the file and drop it in the temporary folder
     $file = $_FILES['image-upload'];
     try {
         // Make sure a file was uploaded
         if (!empty($file['name']) && !empty($file['size'])) {
             $folderPath = craft()->path->getTempUploadsPath();
             IOHelper::ensureFolderExists($folderPath);
             IOHelper::clearFolder($folderPath, true);
             $fileName = AssetsHelper::cleanAssetName($file['name']);
             move_uploaded_file($file['tmp_name'], $folderPath . $fileName);
             // Test if we will be able to perform image actions on this image
             if (!craft()->images->checkMemoryForImage($folderPath . $fileName)) {
                 IOHelper::deleteFile($folderPath . $fileName);
                 $this->returnErrorJson(Craft::t('The uploaded image is too large'));
             }
             list($width, $height) = ImageHelper::getImageSize($folderPath . $fileName);
             if (IOHelper::getExtension($fileName) != 'svg') {
                 craft()->images->cleanImage($folderPath . $fileName);
             } else {
                 // Resave svg files as png
                 $newFilename = preg_replace('/\\.svg$/i', '.png', $fileName);
                 craft()->images->loadImage($folderPath . $fileName, $width, $height)->saveAs($folderPath . $newFilename);
                 IOHelper::deleteFile($folderPath . $fileName);
                 $fileName = $newFilename;
             }
             $constraint = 500;
             // If the file is in the format badscript.php.gif perhaps.
             if ($width && $height) {
                 // Never scale up the images, so make the scaling factor always <= 1
                 $factor = min($constraint / $width, $constraint / $height, 1);
                 $html = craft()->templates->render('_components/tools/cropper_modal', array('imageUrl' => UrlHelper::getResourceUrl('tempuploads/' . $fileName), 'width' => round($width * $factor), 'height' => round($height * $factor), 'factor' => $factor, 'constraint' => $constraint, 'fileName' => $fileName));
                 $this->returnJson(array('html' => $html));
             }
         }
     } catch (Exception $exception) {
         $this->returnErrorJson($exception->getMessage());
     }
     $this->returnErrorJson(Craft::t('There was an error uploading your photo'));
 }
Beispiel #25
0
 public function resize($path, $width, $height, $options = array(), $htmlAttributes = array(), $return = false)
 {
     $filename = basename($path);
     $uploadsDir = dirname(basename($path));
     if ($uploadsDir === '.') {
         $uploadsDir = '';
     }
     $cacheDir = dirname($path);
     $options = Hash::merge(array('aspect' => true, 'adapter' => false, 'cacheDir' => $cacheDir, 'uploadsDir' => $uploadsDir), $options);
     $adapter = $options['adapter'];
     if ($adapter === 'LegacyLocalAttachment') {
         $options['cacheDir'] = 'resized';
         $options['resizedInd'] = '.resized-';
         $options['uploadsDir'] = 'uploads';
     }
     $result = parent::resize($path, $width, $height, $options, $htmlAttributes, $return);
     $data = compact('result', 'path', 'width', 'height', 'aspect', 'htmlAttributes', 'adapter');
     Croogo::dispatchEvent('Assets.AssetsImageHelper.resize', $this->_View, $data);
     return $result;
 }
 /**
  * Saves an asset source.
  */
 public function actionSaveTransform()
 {
     $this->requirePostRequest();
     $transform = new AssetTransformModel();
     $transform->id = craft()->request->getPost('transformId');
     $transform->name = craft()->request->getPost('name');
     $transform->handle = craft()->request->getPost('handle');
     $transform->width = craft()->request->getPost('width');
     $transform->height = craft()->request->getPost('height');
     $transform->mode = craft()->request->getPost('mode');
     $transform->position = craft()->request->getPost('position');
     $transform->quality = craft()->request->getPost('quality');
     $transform->format = craft()->request->getPost('format');
     if (empty($transform->format)) {
         $transform->format = null;
     }
     $errors = false;
     if (empty($transform->width) && empty($transform->height)) {
         craft()->userSession->setError(Craft::t('You must set at least one of the dimensions.'));
         $errors = true;
     }
     if (!empty($transform->quality) && (!is_numeric($transform->quality) || $transform->quality > 100 || $transform->quality < 1)) {
         craft()->userSession->setError(Craft::t('Quality must be a number between 1 and 100 (included).'));
         $errors = true;
     }
     if (!empty($transform->format) && !in_array($transform->format, ImageHelper::getWebSafeFormats())) {
         craft()->userSession->setError(Craft::t('That is not an allowed format.'));
         $errors = true;
     }
     if (!$errors) {
         // Did it save?
         if (craft()->assetTransforms->saveTransform($transform)) {
             craft()->userSession->setNotice(Craft::t('Transform saved.'));
             $this->redirectToPostedUrl($transform);
         } else {
             craft()->userSession->setError(Craft::t('Couldn’t save source.'));
         }
     }
     // Send the transform back to the template
     craft()->urlManager->setRouteVariables(array('transform' => $transform));
 }
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionEdit()
 {
     if (!empty($this->catalog)) {
         $message = "";
         $catalog = $this->catalog;
         $action = Yii::app()->request->getParam("action", "");
         if ($this->id) {
             $item = $catalog::fetch($this->id);
         } else {
             $item = new $catalog();
         }
         // Удаление картинки
         if ($action == "img_del") {
             $imageField = Yii::app()->request->getParam("field", "");
             if (!empty($imageField)) {
                 ImageHelper::deleteFile($item, $imageField);
                 $item->save();
                 $message = "Фото успешно удаленно";
             }
         }
         // Удаляем картинки в галлере
         if ($action == "gal_del") {
             $id = (int) Yii::app()->request->getParam("img_id", 0);
             if (!empty($id)) {
                 $imageModel = CatGallery::fetch($id);
                 if ($imageModel->id > 0) {
                     $imageModel->delete();
                     $message = "Фото успешно удаленно";
                 }
             }
         }
         $addGallery = new CatGallery();
         if ($item->id > 0) {
             $listImage = CatGallery::fetchAll(DBQueryParamsClass::CreateParams()->setConditions("catalog=:catalog AND item_id=:item_id")->setParams(array(":catalog" => $item->tableName(), ":item_id" => $item->id))->setOrderBy("pos, id")->setCache(0)->setLimit(-1));
         } else {
             $listImage = array();
         }
         $this->arrayParams["catalog"] = $catalog;
         $this->render('edit', array('arrayParams' => $this->arrayParams, 'controller' => $this, 'form' => $item, 'catalog' => SiteHelper::getCamelCase($item->tableName()), 'listImage' => $listImage, 'message' => $message, 'addGallery' => $addGallery));
     }
 }
Beispiel #28
0
    ?>
" alt="<?php 
    echo SiteHelper::getStringForTitle($tour->name . "," . $tour->category_id->name);
    ?>
" /></a>
        <?php 
} elseif (sizeof($listImages) > 0) {
    ?>
            <a href="<?php 
    echo SiteHelper::createUrl("/tours/description") . "/" . $tour->slug;
    ?>
.html" title="<?php 
    echo SiteHelper::getStringForTitle($tour->name . "," . $tour->category_id->name);
    ?>
"><img src="<?php 
    echo ImageHelper::getImage($listImages[0]->image, 2);
    ?>
" alt="<?php 
    echo SiteHelper::getStringForTitle($tour->name . "," . $tour->category_id->name);
    ?>
" /></a>
        <?php 
}
?>
    </div>
    <a href="<?php 
echo SiteHelper::createUrl("/tours/description") . "/" . $tour->slug;
?>
.html" title="<?php 
echo SiteHelper::getStringForTitle($tour->category_id->name . "," . $tour->name);
?>
 /**
  * @inheritDoc BaseAssetSourceType::processIndex()
  *
  * @param $sessionId
  * @param $offset
  *
  * @return mixed
  */
 public function processIndex($sessionId, $offset)
 {
     $indexEntryModel = craft()->assetIndexing->getIndexEntry($this->model->id, $sessionId, $offset);
     if (empty($indexEntryModel)) {
         return false;
     }
     $uriPath = $indexEntryModel->uri;
     $fileModel = $this->indexFile($uriPath);
     $this->_prepareForRequests();
     if ($fileModel) {
         $settings = $this->getSettings();
         craft()->assetIndexing->updateIndexEntryRecordId($indexEntryModel->id, $fileModel->id);
         $fileModel->size = $indexEntryModel->size;
         $fileInfo = $this->_s3->getObjectInfo($settings->bucket, $this->_getPathPrefix() . $uriPath);
         $targetPath = craft()->path->getAssetsImageSourcePath() . $fileModel->id . '.' . IOHelper::getExtension($fileModel->filename);
         $timeModified = new DateTime('@' . $fileInfo['time']);
         if ($fileModel->kind == 'image' && ($fileModel->dateModified != $timeModified || !IOHelper::fileExists($targetPath))) {
             $this->_s3->getObject($settings->bucket, $this->_getPathPrefix() . $indexEntryModel->uri, $targetPath);
             clearstatcache();
             list($width, $height) = ImageHelper::getImageSize($targetPath);
             $fileModel->width = $width;
             $fileModel->height = $height;
             // Store the local source or delete - maxCacheCloudImageSize is king.
             craft()->assetTransforms->storeLocalSource($targetPath, $targetPath);
             craft()->assetTransforms->queueSourceForDeletingIfNecessary($targetPath);
         }
         $fileModel->dateModified = $timeModified;
         craft()->assets->storeFile($fileModel);
         return $fileModel->id;
     }
     return false;
 }
Beispiel #30
0
 * @author YouTech Company http://www.smartaddons.com
 *
 */
defined('_JEXEC') or die;
// includes placehold
$yt_temp = JFactory::getApplication()->getTemplate();
include JPATH_BASE . '/templates/' . $yt_temp . '/includes/placehold.php';
$uniquied = 'sj_accordion_' . time() . rand();
JHtml::stylesheet('templates/' . JFactory::getApplication()->getTemplate() . '/html/mod_sj_content_accordion/css/sj-accordion.css');
if (!defined('SMART_JQUERY') && $params->get('include_jquery', 0) == "1") {
    JHtml::script('modules/mod_sj_content_accordion/assets/js/jquery-1.8.2.min.js');
    JHtml::script('modules/mod_sj_content_accordion/assets/js/jquery-noconflict.js');
    define('SMART_JQUERY', 1);
}
JHtml::script('modules/mod_sj_content_accordion/assets/js/jquery.sj_accordion.js');
ImageHelper::setDefault($params);
$item_first = (int) $params->get('item_first_display');
if ($item_first >= (int) count($list)) {
    $item_first = count($list);
} else {
    if ($item_first <= 0) {
        $item_first = 1;
    } else {
        $item_first = $item_first;
    }
}
if (!empty($list)) {
    ?>

<script type="text/javascript">
//<![CDATA[