Example #1
0
 /**
  * Process uploaded images.
  * Save to gallery.
  * @param Bulletin $model
  * @param CUploadedFile[] $images
  */
 public static function processImages($model, $images)
 {
     if (isset($images) && count($images) > 0) {
         // configure and save gallery model
         $gallery = new Gallery();
         $gallery->name = false;
         $gallery->description = false;
         $gallery->versions = array('small' => array('resize' => array(150, null)), 'medium' => array('resize' => array(800, null)));
         $gallery->save();
         $model->gallery_id = $gallery->id;
         $model->save();
         // go through each uploaded image
         foreach ($images as $imageFile) {
             $galleryPhoto = new GalleryPhoto();
             $galleryPhoto->gallery_id = $gallery->id;
             $galleryPhoto->name = '';
             $galleryPhoto->description = '';
             $galleryPhoto->file_name = $imageFile->getName();
             $galleryPhoto->save();
             $galleryPhoto->setImage($imageFile->getTempName());
         }
     }
 }
 /**
  * Method to update images name/description via AJAX.
  * On success returns JSON array od objects with new image info.
  * @throws CHttpException
  */
 public function actionChangeData()
 {
     if (!isset($_POST['photo'])) {
         throw new CHttpException(400, 'Nothing, to save');
     }
     $data = $_POST['photo'];
     $criteria = new CDbCriteria();
     $criteria->index = 'id';
     $criteria->addInCondition('id', array_keys($data));
     /** @var $models GalleryPhoto[] */
     $models = GalleryPhoto::model()->findAll($criteria);
     foreach ($data as $id => $attributes) {
         if (isset($attributes['name'])) {
             $models[$id]->name = $attributes['name'];
         }
         if (isset($attributes['description'])) {
             $models[$id]->description = $attributes['description'];
         }
         $models[$id]->save();
     }
     $resp = array();
     foreach ($models as $model) {
         $resp[] = array('id' => $model->id, 'rank' => $model->rank, 'name' => (string) $model->name, 'description' => (string) $model->description, 'preview' => $model->getPreview());
     }
     echo CJSON::encode($resp);
 }
    /**
     * Triggers to perform upgrade tasks using a special key from the db upgrade routine
     * If we have to move files or remove something specifically during an upgrade
     * @param $id
     */
    public function runTask($id)
    {
        Yii::log("Running upgrade task {$id}.", 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
        switch ($id) {
            case 416:
                //Place any header images in our new gallery library
                Gallery::LoadGallery(1);
                $d = dir(YiiBase::getPathOfAlias('webroot') . "/images/header");
                while (false !== ($filename = $d->read())) {
                    if ($filename[0] != ".") {
                        $model = new GalleryPhoto();
                        $model->gallery_id = 1;
                        $model->file_name = $filename;
                        $model->name = '';
                        $model->description = '';
                        $model->save();
                        $arrImages["/images/header/" . $filename] = CHtml::image(Yii::app()->request->baseUrl . "/images/header/" . $filename);
                        $src = YiiBase::getPathOfAlias('webroot') . "/images/header/" . $filename;
                        $fileinfo = mb_pathinfo($filename);
                        $model->thumb_ext = $fileinfo['extension'];
                        $model->save();
                        $imageFile = new CUploadedFile($filename, $src, "image/" . $fileinfo['extension'], getimagesize($src), null);
                        if (Yii::app()->params['LIGHTSPEED_MT'] == '1') {
                            $model->setS3Image($imageFile);
                        } else {
                            $model->setImage($imageFile);
                        }
                    }
                }
                break;
            case 417:
                //Remove wsconfig.php reference from /config/main.php
                if (Yii::app()->params['LIGHTSPEED_MT'] == 1) {
                    return;
                }
                //only applies to single tenant
                $main_config = file_get_contents(YiiBase::getPathOfAlias('webroot') . "/config/main.php");
                // @codingStandardsIgnoreStart
                $main_config = str_replace('if (file_exists(dirname(__FILE__).\'/wsconfig.php\'))
	$wsconfig = require(dirname(__FILE__).\'/wsconfig.php\');
else $wsconfig = array();', '//For customization, let\'s look in custom/config for a main.php which will be merged
//Use this instead of modifying this main.php directly
if(file_exists(realpath(dirname(__FILE__)."/../custom").\'/config/main.php\'))
	$arrCustomConfig = require(realpath(dirname(__FILE__)."/../custom").\'/config/main.php\');
else
	$arrCustomConfig = array();', $main_config);
                $main_config = str_replace('),$wsconfig);', '),
	$arrCustomConfig
);', $main_config);
                // @codingStandardsIgnoreEnd
                file_put_contents(YiiBase::getPathOfAlias('webroot') . "/config/main.php", $main_config);
                break;
            case 423:
                // add cart/cancel url rule for sim payment methods (ex. moneris) that require hardcoded cancel urls
                $main_config = file_get_contents(YiiBase::getPathOfAlias('webroot') . "/config/main.php");
                // check to see if the entry is already there and write it if it isn't
                $position = strpos($main_config, 'cart/cancel');
                if (!$position) {
                    $comments = "\r\r\t\t\t\t\t\t// moneris simple integration requires a hardcoded cancel URL\r\t\t\t\t\t\t// any other methods that require something similar we can add a cart/cancel rule like this one\r\t\t\t\t\t\t";
                    $pos = strpos($main_config, "sro/view',") + strlen("sro/view',");
                    $main_config = substr_replace($main_config, $comments . "'cart/cancel/<order_id:\\WO-[0-9]+>&<cancelTXN:(.*)>'=>'cart/cancel',\t\t\t\t\t\t", $pos, 0);
                    file_put_contents(YiiBase::getPathOfAlias('webroot') . "/config/main.php", $main_config);
                }
                break;
            case 427:
                // Add URL mapping for custom pages
                // If the store's on multi-tenant server, do nothing
                if (Yii::app()->params['LIGHTSPEED_MT'] > 0) {
                    return;
                }
                $main_config = file_get_contents(YiiBase::getPathOfAlias('webroot') . "/config/main.php");
                $search_string = "'<id:(.*)>/pg'";
                // Check if the entry already exists. If not, add the mapping.
                if (strpos($main_config, $search_string) === false) {
                    $position = strpos($main_config, "'<feed:[\\w\\d\\-_\\.()]+>.xml' => 'xml/<feed>', //xml feeds");
                    $custompage_mapping = "'<id:(.*)>/pg'=>array('custompage/index', 'caseSensitive'=>false,'parsingOnly'=>true), //Custom Page\r\t\t\t\t\t\t";
                    $main_config = substr_replace($main_config, $custompage_mapping, $position, 0);
                    file_put_contents(YiiBase::getPathOfAlias('webroot') . "/config/main.php", $main_config);
                }
                break;
            case 447:
                // Remove bootstrap, add in separate main.php
                // If the store's on multi-tenant server, do nothing
                if (Yii::app()->params['LIGHTSPEED_MT'] > 0) {
                    return;
                }
                $main_config = file_get_contents(YiiBase::getPathOfAlias('webroot') . "/config/main.php");
                // @codingStandardsIgnoreStart
                //Remove preloading bootstrap, loaded now in Controller.php on demand if needed
                $main_config = str_replace("\t\t\t'bootstrap',\n", "", $main_config);
                //Bootstrap is loaded on demand now
                $main_config = str_replace("//Twitter bootstrap\n\t\t\t\t'bootstrap'=>array(\n\t\t\t\t\t'class'=>'ext.bootstrap.components.Bootstrap',\n\t\t\t\t\t'responsiveCss'=>true,\n\t\t\t\t),", "", $main_config);
                //Remove old email strings and facebook strings, they're loaded elsewhere now
                $main_config = str_replace("//Email handling\n\t\t\t\t'email'=>require(dirname(__FILE__).'/wsemail.php'),\n", "", $main_config);
                //Remove old email strings and facebook strings, they're loaded elsewhere now
                $main_config = str_replace("//Facebook integration\n\t\t\t\t'facebook'=>require(dirname(__FILE__).'/wsfacebook.php'),\n", "", $main_config);
                //for any main.php that was missing all of this before
                $main_config = str_replace('),array());', '),
	$arrCustomConfig
);', $main_config);
                $main_config = str_replace('	\'params\'=>array(
		// this is used in contact page
		\'mainfile\'=>\'yes\',
	),

);', '	\'params\'=>array(
		// this is used in contact page
		\'mainfile\'=>\'yes\',
	)),
	$arrCustomConfig
);', $main_config);
                $main_config = str_replace('// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(', '// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return CMap::mergeArray(
	array(', $main_config);
                $search_string = "//For customization,";
                // Check if the entry already exists. If not, add the mapping.
                if (strpos($main_config, $search_string) === false) {
                    $main_config = str_replace('Yii::setPathOfAlias(\'extensions\', dirname(__FILE__).DIRECTORY_SEPARATOR.\'../core/protected/extensions\');

', 'Yii::setPathOfAlias(\'extensions\', dirname(__FILE__).DIRECTORY_SEPARATOR.\'../core/protected/extensions\');

//For customization, let\'s look in custom/config for a main.php which will be merged
//Use this instead of modifying this main.php directly
if(file_exists(realpath(dirname(__FILE__)."/../custom").\'/config/main.php\'))
	$arrCustomConfig = require(realpath(dirname(__FILE__)."/../custom").\'/config/main.php\');
else
	$arrCustomConfig = array();

', $main_config);
                }
                // @codingStandardsIgnoreEnd
                file_put_contents(YiiBase::getPathOfAlias('webroot') . "/config/main.php", $main_config);
                @unlink(YiiBase::getPathOfAlias('webroot') . "/config/wsemail.php");
                @unlink(YiiBase::getPathOfAlias('webroot') . "/config/wsfacebook.php");
                if (Yii::app()->theme) {
                    $arrActiveCss = Yii::app()->theme->info->cssfiles;
                    $arrActiveCss[] = Yii::app()->theme->config->CHILD_THEME;
                    Yii::app()->theme->config->activecss = $arrActiveCss;
                }
                break;
        }
    }
Example #4
0
 /** @return GalleryPhoto[] Photos from associated gallery */
 public function getGalleryPhotos()
 {
     $criteria = new CDbCriteria();
     $criteria->condition = 'gallery_id = :gallery_id';
     $criteria->params[':gallery_id'] = $this->getOwner()->{$this->idAttribute};
     $criteria->order = '`rank` asc';
     return GalleryPhoto::model()->findAll($criteria);
 }
Example #5
0
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         // Читаем конфигурацию каталога
         $galleryConfig = GalleryConfig::model()->findByPk(1);
         // Загружаем фотографии
         $photos = new GalleryPhoto();
         if ($photosUpload = CUploadedFile::getInstances($photos, 'image')) {
             foreach ($photosUpload as $file) {
                 $photo = new GalleryPhoto();
                 $photoName = md5(time() . $file->name) . '.' . $file->getExtensionName();
                 $photo->file = $photoName;
                 $file->saveAs($this->folder . '/' . $photoName);
                 $this->uploaded_photos[] = $photo;
                 Yii::app()->ih->load($this->folder . '/' . $photoName)->adaptiveThumb($galleryConfig->prev_x, $galleryConfig->prev_y)->save($this->folder . '/small/' . $photoName, false, 100)->reload()->adaptiveThumb(200, 135)->save($this->folder . '/medium/' . $photoName, false, 100);
             }
         }
         if ($this->isNewRecord) {
             $this->sort_order = $this->getMaxSortOrder() + 10;
         }
         if (!empty($this->uploaded_photos)) {
             foreach ($this->uploaded_photos as $photo) {
                 $photo->gallery_id = $this->id;
                 $photo->save();
             }
             if ($this->photos and $coverPhoto = $this->getCover()) {
                 $this->cover_photo_id = $coverPhoto->id;
             }
         }
         return true;
     } else {
         return false;
     }
 }
Example #6
0
 public function actionSortPhoto($galleryId)
 {
     if (isset($_POST['sortArr'])) {
         $sortData = $_POST['sortArr'];
         $photos = GalleryPhoto::model()->findAllByAttributes(array('gallery_id' => $galleryId), array('order' => 'sort_order'));
         foreach ($photos as $key => $photo) {
             $photo->sort_order = $sortData[$key];
             $photo->save('sort_order');
         }
     }
 }
Example #7
0
function _upload_default_header_to_s3()
{
    Gallery::LoadGallery(1);
    $d = dir(YiiBase::getPathOfAlias('webroot') . "/images/header");
    while (false !== ($filename = $d->read())) {
        if ($filename == "defaultheader.png") {
            $model = new GalleryPhoto();
            $model->gallery_id = 1;
            $model->file_name = $filename;
            $model->name = '';
            $model->description = '';
            $model->thumb_ext = 'png';
            $model->save();
            $arrImages["/images/header/" . $filename] = CHtml::image(Yii::app()->request->baseUrl . "/images/header/" . $filename);
            $src = YiiBase::getPathOfAlias('webroot') . "/images/header/" . $filename;
            $fileinfo = mb_pathinfo($filename);
            $imageFile = new CUploadedFile($filename, $src, "image/" . $fileinfo['extension'], getimagesize($src), null);
            if (Yii::app()->params['LIGHTSPEED_MT'] == '1') {
                $model->setS3Image($imageFile);
            }
            _xls_set_conf('HEADER_IMAGE', "//lightspeedwebstore.s3.amazonaws.com/" . _xls_get_conf('LIGHTSPEED_HOSTING_LIGHTSPEED_URL') . "/gallery/1/" . $model->id . ".png");
        }
    }
}
Example #8
0
 public static function getRandomPhoto()
 {
     $criteria = new CDbCriteria();
     $criteria->limit = 1;
     $criteria->select = "*, rand() as rand";
     $criteria->order = "rand";
     return GalleryPhoto::model()->find($criteria);
 }