Пример #1
0
 /**
  * Method to handle file upload thought XHR2
  * On success returns JSON object with image info.
  * @param $gallery_id string Gallery Id to upload images
  * @throws CHttpException
  */
 public function actionAjaxUpload($gallery_id = null)
 {
     $model = new GalleryPhoto();
     $model->gallery_id = $gallery_id;
     $imageFile = CUploadedFile::getInstanceByName('image');
     $model->file_name = $imageFile->getName();
     $model->thumb_ext = $model->getExtensionFromMime($imageFile);
     $model->save();
     if (Yii::app()->params['LIGHTSPEED_MT'] == '1') {
         $model->setS3Image($imageFile);
     } else {
         $model->setImage($imageFile);
     }
     header("Content-Type: application/json");
     echo CJSON::encode(array('id' => $model->id, 'rank' => $model->rank, 'name' => (string) $model->name, 'description' => (string) $model->description, 'preview' => $model->getPreview()));
 }
Пример #2
0
    /**
     * 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;
        }
    }
Пример #3
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");
        }
    }
}