コード例 #1
0
ファイル: GalleryController.php プロジェクト: hipogea/zega
 /**
  * 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->setImage($imageFile->getTempName());
     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
 /**
  * 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->save();
     $model->setImage($imageFile->getTempName());
     // not "application/json", because  IE8 trying to save response as a file
     header("Content-Type: text/html");
     echo CJSON::encode(array('id' => $model->id, 'rank' => $model->rank, 'name' => (string) $model->name, 'description' => (string) $model->description, 'preview' => $model->getPreview()));
     if (method_exists(Yii::app()->request, 'setIsAjaxRequest')) {
         Yii::app()->request->setIsAjaxRequest(true);
     }
 }
コード例 #3
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()));
 }
コード例 #4
0
 public function actionAjaxUploadCustom($gallery_id = null, $image_id = null)
 {
     if (Yii::app()->getRequest()->getIsPostRequest()) {
         $model = new GalleryPhoto();
         $model->gallery_id = $gallery_id;
         if (isset($_POST['GalleryPhoto'])) {
             $model->attributes = $_POST['GalleryPhoto'];
         }
         $imageFile = dirname(__FILE__) . '/../../www/distributer_gallery/' . $image_id . '.png';
         $model->file_name = $image_id . '.png';
         $model->save();
         $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()));
     } else {
         throw new CHttpException(404);
     }
 }
コード例 #5
0
ファイル: ImagesHelper.php プロジェクト: kosenka/yboard
 /**
  * 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());
         }
     }
 }
コード例 #6
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;
        }
    }