Beispiel #1
0
 public function changeSlide($fileName)
 {
     // folder for uploaded files
     $tempFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['temp'];
     if (!is_writable($tempFolder)) {
         throw new CException('temporary folder is not exists or not writable. Path:' . $tempFolder);
     }
     $uploader = new FileUploader(Yii::app()->params['uploader']['allowedFileExtensions'], Yii::app()->params['uploader']['sizeLimit']);
     $result = $uploader->handleUpload($tempFolder);
     if (!isset($result['error'])) {
         $imageHandler = new CImageHandler();
         $imageHandler->load($tempFolder . $result['filename']);
         try {
             $imageHandler->cropAndScaleFromCenter(1040, 380);
             $imageHandler->save($this->getSliderImagePath($fileName));
             $this->response = array('fileName' => $fileName, 'imageSrc' => $this->getSliderImageSrc($fileName));
             return TRUE;
         } catch (CException $e) {
             $this->response = array('errorMessage' => $fileName . $e->getMessage());
             return FALSE;
         }
     } else {
         $this->response = array('errorMessage' => $result['error']);
         return FALSE;
     }
 }
Beispiel #2
0
 public function getThumb($width, $height)
 {
     $path = Yii::getPathOfAlias($this->path);
     $filePath = $path . DIRECTORY_SEPARATOR . 'thumb_' . $width . 'x' . $height . "_" . $this->name;
     $fileName = 'thumb_' . $width . 'x' . $height . "_" . $this->name;
     if (file_exists($filePath)) {
         return $fileName;
     } else {
         $image = new CImageHandler();
         if ($image->load($path . DIRECTORY_SEPARATOR . $this->name)) {
             $image->adaptiveThumb($width, $height)->save($filePath);
             return $fileName;
         } else {
             return null;
         }
     }
 }
Beispiel #3
0
 public function actionUpload($id)
 {
     $model = $this->checkOwner($id);
     Yii::import("ext.EAjaxUpload.qqFileUploader");
     $allowedExtensions = param('allowedImgExtensions', array('jpg', 'jpeg', 'gif', 'png'));
     //$sizeLimit = param('maxImgFileSize', 8 * 1024 * 1024);
     $sizeLimit = Images::getMaxSizeLimit();
     $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
     $path = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::ORIGINAL_IMG_DIR);
     $pathMod = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::MODIFIED_IMG_DIR);
     $oldUMask = umask(0);
     if (!is_dir($path)) {
         @mkdir($path, 0777, true);
     }
     if (!is_dir($pathMod)) {
         @mkdir($pathMod, 0777, true);
     }
     umask($oldUMask);
     if (is_writable($path) && is_writable($pathMod)) {
         touch($path . DIRECTORY_SEPARATOR . 'index.htm');
         touch($pathMod . DIRECTORY_SEPARATOR . 'index.htm');
         $result = $uploader->handleUpload($path . DIRECTORY_SEPARATOR, false, uniqid());
         if (isset($result['success']) && $result['success']) {
             $resize = new CImageHandler();
             if ($resize->load($path . DIRECTORY_SEPARATOR . $result['filename'])) {
                 $resize->thumb(param('maxImageWidth', 1024), param('maxImageHeight', 768), Images::KEEP_PHOTO_PROPORTIONAL)->save();
                 $image = new Images();
                 $image->id_object = $model->id;
                 $image->id_owner = $model->owner_id;
                 $image->file_name = $result['filename'];
                 $image->save();
             } else {
                 $result['error'] = 'Wrong image type.';
                 @unlink($path . DIRECTORY_SEPARATOR . $result['filename']);
             }
         }
     } else {
         $result['error'] = 'Access denied.';
     }
     // to pass data through iframe you will need to encode all html tags
     $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     echo $result;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new News();
     $ih = new CImageHandler();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['News'])) {
         if (isset($_POST['News']['foto_main'])) {
             $model->foto_main = CUploadedFile::getInstance($model, 'foto_main');
             $path = Yii::getPathOfAlias('webroot') . '/upload/' . $model->foto_main->getName();
             $model->foto_main->saveAs($path);
             $ih->load($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $model->foto_main->getName())->resize(270, 270)->save($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $model->foto_main->getName());
             $model->foto_main = $model->foto_main->getName();
         }
         if (isset($_POST['News']['foto1'])) {
             $model->foto1 = CUploadedFile::getInstance($model, 'foto1');
             $path = Yii::getPathOfAlias('webroot') . '/upload/' . $model->foto1->getName();
             $model->foto1->saveAs($path);
             $ih->load($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $model->foto1->getName())->resize(477, 297)->save($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $model->foto1->getName())->reload()->adaptiveThumb(88, 84)->save($_SERVER['DOCUMENT_ROOT'] . '/upload/thumb_' . $model->foto1->getName());
             $model->foto1 = $model->foto1->getName();
         }
         if (isset($_POST['News']['foto2'])) {
             $model->foto2 = CUploadedFile::getInstance($model, 'foto2');
             $path = Yii::getPathOfAlias('webroot') . '/upload/' . $model->foto2->getName();
             $model->foto2->saveAs($path);
             $ih->load($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $model->foto2->getName())->resize(477, 297)->save($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $model->foto2->getName())->reload()->adaptiveThumb(88, 84)->save($_SERVER['DOCUMENT_ROOT'] . '/upload/thumb_' . $model->foto2->getName());
             $model->foto1 = $model->foto2->getName();
         }
         if (isset($_POST['News']['foto3'])) {
             $model->foto3 = CUploadedFile::getInstance($model, 'foto3');
             $path = Yii::getPathOfAlias('webroot') . '/upload/' . $model->foto3->getName();
             $model->foto3->saveAs($path);
             $ih->load($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $model->foto3->getName())->resize(477, 297)->save($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $model->foto3->getName())->reload()->adaptiveThumb(88, 84)->save($_SERVER['DOCUMENT_ROOT'] . '/upload/thumb_' . $model->foto3->getName());
             $model->foto3 = $model->foto3->getName();
         }
         if (isset($_POST['News']['foto4'])) {
             $model->foto4 = CUploadedFile::getInstance($model, 'foto4');
             $path = Yii::getPathOfAlias('webroot') . '/upload/' . $model->foto4->getName();
             $model->foto4->saveAs($path);
             $ih->load($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $model->foto4->getName())->resize(477, 297)->save($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $model->foto4->getName())->reload()->adaptiveThumb(88, 84)->save($_SERVER['DOCUMENT_ROOT'] . '/upload/thumb_' . $model->foto4->getName());
             $model->foto4 = $model->foto4->getName();
         }
         if (isset($_POST['News']['foto5'])) {
             $model->foto5 = CUploadedFile::getInstance($model, 'foto5');
             $path = Yii::getPathOfAlias('webroot') . '/upload/' . $model->foto5->getName();
             $model->foto5->saveAs($path);
             $ih->load($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $model->foto5->getName())->resize(477, 297)->save($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $model->foto5->getName())->reload()->adaptiveThumb(88, 84)->save($_SERVER['DOCUMENT_ROOT'] . '/upload/thumb_' . $model->foto5->getName());
             $model->foto5 = $model->foto5->getName();
         }
         $model->attributes = $_POST['News'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Banners();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Banners'])) {
         $model->attributes = $_POST['Banners'];
         $model->picture = CUploadedFile::getInstance($model, 'picture');
         $fileName = $model->picture->getName();
         if (is_file($_SERVER['DOCUMENT_ROOT'] . '/ban_pict/' . $fileName)) {
             $fileName = substr($fileName, 0, -4) . rand(1, 1000) . substr($fileName, -4);
         }
         $ih = new CImageHandler();
         $ih->load($model->picture->getTempName())->save($_SERVER['DOCUMENT_ROOT'] . '/ban_pict/' . $fileName);
         $model->picture = $fileName;
         if ($model->save()) {
             //$path=Yii::getPathOfAlias('webroot').'/users/'.Yii::app()->user->id.'/'.$model->picture->getName();
             //$model->picture->saveAs($path);
             $this->redirect(array('admin'));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Flo'])) {
         $model->attributes = $_POST['Flo'];
         if ($_POST['Flo']['picture'] != '') {
             unlink($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $model->picture);
             $model->picture = CUploadedFile::getInstance($model, 'picture');
             $fileName = $model->picture->getName();
             if (is_file($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $fileName)) {
                 $fileName = substr($fileName, 0, -4) . rand(1, 1000) . substr($fileName, -4);
             }
             $ih = new CImageHandler();
             $ih->load($model->picture->getTempName())->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $fileName);
             $model->picture = $fileName;
         }
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model, 'user' => Users::model()->findByPk(Yii::app()->user->id)));
 }
 public function run()
 {
     // folder for uploaded files
     $tempFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . $this->tempFolder;
     if (!is_writable($tempFolder)) {
         throw new CException('temporary folder is not exists or not writable. Path:' . $tempFolder);
     }
     $uploader = new FileUploader($this->allowedFileExtensions, $this->fileLimit);
     $result = $uploader->handleUpload($tempFolder);
     if (!isset($result['error'])) {
         $imageHandler = new CImageHandler();
         $imageHandler->load($tempFolder . $result['filename']);
         try {
             // if min/max weight/height are set - check those conditions
             $this->validateImageDimensions($imageHandler->getWidth(), $imageHandler->getHeight());
             $this->getController()->successfulAjaxResponse(array('fileName' => $imageHandler->getBaseFileName(), 'imageSrc' => '/application' . $this->tempFolder . $imageHandler->getBaseFileName()));
         } catch (CException $e) {
             $errorMsg = $imageHandler->getBaseFileName() . ' - ' . $e->getMessage();
             $this->getController()->unsuccessfulAjaxResponse(array('errorMessage' => $errorMsg));
         }
     } else {
         $this->getController()->unsuccessfulAjaxResponse(array('errorMessage' => $result['error']));
     }
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['Actions'])) {
         //print_r($_POST['Actions']);
         if ($_POST['Actions']['picture2'] != 'not') {
             if (!empty($_FILES['Actions']['name']['picture'])) {
                 if (is_file($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $model->picture)) {
                     unlink($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $model->picture);
                 }
                 if (is_file($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/304_' . $model->picture)) {
                     unlink($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/304_' . $model->picture);
                 }
                 if (is_file($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/267_' . $model->picture)) {
                     unlink($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/267_' . $model->picture);
                 }
                 if (is_file($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/568_' . $model->picture)) {
                     unlink($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/568_' . $model->picture);
                 }
                 if (is_file($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/721_' . $model->picture)) {
                     unlink($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/721_' . $model->picture);
                 }
                 $model->picture = CUploadedFile::getInstance($model, 'picture');
                 $fileName = $model->picture->getName();
                 if (is_file($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $fileName)) {
                     $fileName = substr($fileName, 0, -4) . rand(1, 1000) . substr($fileName, -4);
                 }
                 $ih = new CImageHandler();
                 $ih->load($model->picture->getTempName())->adaptiveThumb(304, 217)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/304_' . $fileName)->reload()->adaptiveThumb(267, 290)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/267_' . $fileName)->reload()->adaptiveThumb(568, 316)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/568_' . $fileName)->reload()->adaptiveThumb(721, 377)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/721_' . $fileName)->reload()->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $fileName);
                 //$model->picture=$fileName;
                 $_POST['Actions']['picture'] == $fileName;
             }
         } else {
             $_FILES['Actions']['name']['picture'] = $_POST['old_picture'];
             $_POST['Actions']['picture'] = $_POST['old_picture'];
         }
         if (isset($_POST['Actions']['price'])) {
             $_POST['Actions']['price'] = preg_replace("/\\s/", "", $_POST['Actions']['price']);
         }
         $model->attributes = $_POST['Actions'];
         //print_r($model->attributes);
         if ($model->save()) {
             $this->redirect(array('index'));
         } else {
             print_r($model->getErrors());
             die;
         }
     }
     $this->render('update', array('action' => $model, 'model' => Users::model()->findByPk(Yii::app()->user->id)));
 }
Beispiel #9
0
 public function actionUpload($id)
 {
     $model = $this->checkOwner($id);
     $maxImgs = 0;
     # unlimited
     $currImgCount = 0;
     if (issetModule('tariffPlans') && issetModule('paidservices')) {
         $sql = 'SELECT COUNT(id) FROM {{images}} WHERE id_object = ' . $model->id;
         $currImgCount = Yii::app()->db->createCommand($sql)->queryScalar();
         $userTariffInfo = TariffPlans::getTariffInfoByUserId($model->owner_id);
         $maxImgs = $userTariffInfo['limitPhotos'];
         if (Yii::app()->user->checkAccess("backend_access")) {
             # admin or moderator
             $maxImgs = 0;
         }
     }
     if ($maxImgs > 0 && $currImgCount >= $maxImgs) {
         $result['error'] = Yii::t("module_tariffPlans", "You are trying to download more than {num} pictures ( your tariff limit )", array("{num}" => $maxImgs));
         $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
         echo $result;
         Yii::app()->end();
     }
     Yii::import("ext.EAjaxUpload.qqFileUploader");
     $allowedExtensions = param('allowedImgExtensions', array('jpg', 'jpeg', 'gif', 'png'));
     //$sizeLimit = param('maxImgFileSize', 8 * 1024 * 1024);
     $sizeLimit = Images::getMaxSizeLimit();
     $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
     $path = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::ORIGINAL_IMG_DIR);
     $pathMod = Yii::getPathOfAlias('webroot.uploads.objects.' . $model->id . '.' . Images::MODIFIED_IMG_DIR);
     $oldUMask = umask(0);
     if (!is_dir($path)) {
         @mkdir($path, 0777, true);
     }
     if (!is_dir($pathMod)) {
         @mkdir($pathMod, 0777, true);
     }
     umask($oldUMask);
     if (is_writable($path) && is_writable($pathMod)) {
         touch($path . DIRECTORY_SEPARATOR . 'index.htm');
         touch($pathMod . DIRECTORY_SEPARATOR . 'index.htm');
         $result = $uploader->handleUpload($path . DIRECTORY_SEPARATOR, false, uniqid());
         if (isset($result['success']) && $result['success']) {
             $resize = new CImageHandler();
             if ($resize->load($path . DIRECTORY_SEPARATOR . $result['filename'])) {
                 $resize->thumb(param('maxImageWidth', 1024), param('maxImageHeight', 768), Images::KEEP_PHOTO_PROPORTIONAL)->save();
                 $image = new Images();
                 $image->id_object = $model->id;
                 $image->id_owner = $model->owner_id;
                 $image->file_name = $result['filename'];
                 if ($image->save() && $model->hasAttribute('count_img')) {
                     $model->count_img++;
                     $model->update('count_img');
                 }
             } else {
                 $result['error'] = 'Wrong image type.';
                 @unlink($path . DIRECTORY_SEPARATOR . $result['filename']);
             }
         }
     } else {
         $result['error'] = 'Access denied.';
     }
     // to pass data through iframe you will need to encode all html tags
     $result = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     echo $result;
 }
Beispiel #10
0
    }
}
?>
  
          </div>
      </div>
      <div class="middle_photo">
          
          <div class="cur_photo">           
          <?php 
echo '<div id="content_photo">';
if ($next != '') {
    echo '<a href="' . parse_url(Yii::app()->request->requestUri, PHP_URL_PATH) . '?photo=photo' . $next . '" class="next_item">';
}
if (!is_file($_SERVER['DOCUMENT_ROOT'] . '/users/' . $user->id . '/940_' . $current)) {
    $ih = new CImageHandler();
    $ih->load($_SERVER['DOCUMENT_ROOT'] . '/users/' . $user->id . '/' . $current)->resize(940, 680)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . $user->id . '/940_' . $current);
    echo '<img src="/users/' . $user->id . '/940_' . $current . '" alt="' . $user->name . ' - Фотограф - ' . Portfolio::model()->findByPk(Yii::app()->getRequest()->getParam('id'))->title . '">';
} else {
    echo '<img src="/users/' . $user->id . '/940_' . $current . '" alt="' . $user->name . ' - Фотограф - ' . Portfolio::model()->findByPk(Yii::app()->getRequest()->getParam('id'))->title . '">';
}
if ($next != '') {
    echo '</a>';
}
echo '<a href="/users/' . $user->id . '/' . $current . '" class="gallery__zoom" rel="big" data-img="/users/' . $user->id . '/' . $current . '"></a>';
echo '</div>';
?>
          </div>
 
    </div>
   </div>
 public function actionUpload($id)
 {
     //$id=Yii::app()->user->id;
     Yii::import("ext.Upload.qqFileUploader2");
     $folder = Yii::getPathOfAlias('webroot') . '/users/' . Yii::app()->user->id . '/';
     // folder for uploaded files
     $allowedExtensions = array("jpg", "jpeg", "gif", "png");
     //array("jpg","jpeg","gif","exe","mov" and etc...
     $sizeLimit = 8 * 1024 * 1024;
     // maximum file size in bytes
     $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
     $result = $uploader->handleUpload($folder);
     $fileSize = filesize($folder . $result['filename']);
     //GETTING FILE SIZE
     $fileName = $result['filename'];
     //GETTING FILE NAME
     //$img = CUploadedFile::getInstance($model,'image');
     $ih = new CImageHandler();
     $ih->load($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $fileName)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $fileName)->reload()->adaptiveThumb(350, 232)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/avto350_' . $fileName)->reload()->resize(304, 202)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/avto304_' . $fileName);
     Yii::import("application.modules.my.models.Files");
     $mFile = new Files();
     $mFile->uid = Yii::app()->user->id;
     $mFile->file = $fileName;
     $mFile->type = 'photo';
     $mFile->portfolio_id = $id;
     $mFile->source = 'avto';
     if ($mFile->save()) {
         //unlink($_SERVER['DOCUMENT_ROOT'] . '/users/'.Yii::app()->user->id.'/'.$fileName);
         $result['res'] = $mFile->id;
     }
     $return = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     echo $return;
     // it's array
     //echo $ret;
 }
 public function actionAddvideo()
 {
     $mFile = new Files();
     $mFile->uid = Yii::app()->user->id;
     $mFile->file = $_POST['video'];
     $mFile->type = 'video';
     $mFile->source = 'portfolio';
     $mFile->portfolio_id = $_POST['portfolio_id'];
     $str = parse_url($_POST['video']);
     //print_r($str);
     $path = explode('/', $str['path']);
     if ($str['host'] == 'youtu.be' || $str['host'] == 'www.youtube.com') {
         if ($str['host'] == 'youtu.be') {
             $code = $path[1];
         } elseif ($str['host'] == 'www.youtube.com') {
             $code = substr($str['query'], 2, 20);
         }
         $image = 'http://img.youtube.com/vi/' . $code . '/0.jpg';
     } elseif ($str['host'] == 'vimeo.com') {
         if (isset($path[3])) {
             $code = $path[3];
         } else {
             $code = $path[1];
         }
         if ($xml = simplexml_load_file('http://vimeo.com/api/v2/video/' . $code . '.xml')) {
             //$image = $xml->video->thumbnail_large ? (string) $xml->video->thumbnail_large: (string) $xml->video->thumbnail_medium;
             $image = $xml->video->thumbnail_medium;
         }
     }
     $ih = new CImageHandler();
     $ih->load($image)->adaptiveThumb(272, 162)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/video_' . $code . '.jpg');
     //$mFile->picture='video_'.$code;
     if ($mFile->save()) {
         $this->redirect($_POST['back']);
     }
 }
Beispiel #13
0
&nbsp;&nbsp;&nbsp;<?php 
echo Settings::dateFormat($model->date_ans);
?>
</time>
        <p><?php 
echo CHtml::encode($model->description);
?>
</p>
      
        <?php 
$gal = Files::model()->findAllByAttributes(array('uid' => $user->id, 'type' => 'photo'), array('limit' => '8'));
if (count($gal) > 0) {
    echo '<ul class="tender__proposal__item__info__gal clfx">';
    foreach ($gal as $photo) {
        if (!is_file($_SERVER['DOCUMENT_ROOT'] . '/users/' . $photo->uid . '/83_' . $photo->file)) {
            $ih = new CImageHandler();
            $ih->load($_SERVER['DOCUMENT_ROOT'] . '/users/' . $photo->uid . '/' . $photo->file)->adaptiveThumb(83, 83)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . $photo->uid . '/83_' . $photo->file);
        }
        echo '<li class="tender__proposal__item__info__gal__item"><a href="/id' . $photo->uid . '"><img src="/users/' . $photo->uid . '/83_' . $photo->file . '" alt=""></a></li>';
    }
    echo '</ul>';
}
?>
      
      </div>
      <div class="col-2 tender__proposal__item__contacts">
        <ul class="accaunt-contacts__list">
                      <li class="accaunt-contacts__item accaunt-tel"><span class="accaunt-contacts__link" id="phone_<?php 
echo $user->id;
?>
" data-phone="<?php 
 public function actionUpload()
 {
     Yii::import("ext.Upload.qqFileUploader2");
     if (!is_dir(Yii::getPathOfAlias('webroot') . '/freefotos/' . Yii::app()->user->id . '/')) {
         mkdir(Yii::getPathOfAlias('webroot') . '/freefotos/' . Yii::app()->user->id . '/');
     }
     $folder = Yii::getPathOfAlias('webroot') . '/freefotos/' . Yii::app()->user->id . '/';
     // folder for uploaded files
     $allowedExtensions = array("jpg", "jpeg", "gif", "png");
     //array("jpg","jpeg","gif","exe","mov" and etc...
     $sizeLimit = 24 * 1024 * 1024;
     // maximum file size in bytes
     $uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
     $result = $uploader->handleUpload($folder);
     $fileSize = filesize($folder . $result['filename']);
     //GETTING FILE SIZE
     $fileName = $result['filename'];
     //GETTING FILE NAME
     //$img = CUploadedFile::getInstance($model,'image');
     $ih = new CImageHandler();
     $ih->load($_SERVER['DOCUMENT_ROOT'] . '/freefotos/' . Yii::app()->user->id . '/' . $fileName)->adaptiveThumb(370, 370)->save($_SERVER['DOCUMENT_ROOT'] . '/freefotos/' . Yii::app()->user->id . '/370_' . $fileName)->reload()->watermark($_SERVER['DOCUMENT_ROOT'] . '/img/watermark2_big.png', 20, 20, CImageHandler::CORNER_LEFT_BOTTOM)->save($_SERVER['DOCUMENT_ROOT'] . '/freefotos/' . Yii::app()->user->id . '/' . $fileName);
     //->reload()
     //->resize(1024, 1024)
     //->save($_SERVER['DOCUMENT_ROOT'] . '/users/'.Yii::app()->user->id.'/1024_'.$fileName)
     //->save($_SERVER['DOCUMENT_ROOT'] . '/users/'.Yii::app()->user->id.'/'.$fileName);
     $mFile = new Freefoto();
     $mFile->name = $_GET['name'];
     $mFile->uid = Yii::app()->user->id;
     $mFile->photo = $fileName;
     $mFile->date = $_GET['date'];
     $mFile->city_id = $_GET['city_id'];
     if ($mFile->save()) {
         //unlink($_SERVER['DOCUMENT_ROOT'] . '/users/'.Yii::app()->user->id.'/'.$fileName);
         $result['res'] = $mFile->id;
     }
     $return = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     echo $return;
     // it's array
     //echo $ret;
 }
Beispiel #15
0
 /**
  * Upload and apply new avatar
  * @return bool
  * @throws CException
  */
 public static function uploadPhoto($userId)
 {
     // folder for uploaded files
     $tempFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['temp'];
     $photosFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['userPhotos'];
     $photosFolder .= $userId . DIRECTORY_SEPARATOR;
     if (!is_writable($tempFolder)) {
         throw new CException('temporary folder is not exists or not writable. Path:' . $tempFolder);
     }
     // Upload to temp folder
     $uploader = new FileUploader(Yii::app()->params['uploader']['allowedFileExtensions'], Yii::app()->params['uploader']['sizeLimit']);
     $result = $uploader->handleUpload($tempFolder);
     if (!isset($result['error'])) {
         // Move file to target folder and make thumbs
         $imageHandler = new CImageHandler();
         $imageHandler->load($tempFolder . $result['filename']);
         $imageHandler->save($photosFolder . $result['filename']);
         $imageHandler->cropAndScaleFromCenter(300, 300);
         $imageHandler->save($photosFolder . self::THUMB_PREFIX_SMALL . $result['filename']);
         $model = new Photos();
         $model->owner_id = $userId;
         $model->file_name = $result['filename'];
         $model->save();
         return array('originalSrc' => $model->getOriginal(), 'thumbSrc' => $model->getSmallThumbnail(), 'photoId' => $model->id);
     } else {
         throw new CException($result['error']);
     }
 }
/<?php 
        echo $item->picture;
        ?>
" class="accaunt-pro__equipment__item__img photo__zoom">
              <?php 
    } else {
        ?>
              <a href="#" class="accaunt-pro__equipment__item__img">
              <?php 
    }
    ?>
                <span>
                    <?php 
    if ($item->picture != '') {
        if (!is_file($_SERVER['DOCUMENT_ROOT'] . '/users/' . $model->id . '/280_' . $item->picture)) {
            $ih = new CImageHandler();
            $ih->load($_SERVER['DOCUMENT_ROOT'] . '/users/' . $model->id . '/' . $item->picture)->adaptiveThumb(280, 421)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . $model->id . '/280_' . $item->picture);
        }
        ?>
                    <img src="/users/<?php 
        echo $model->id;
        ?>
/280_<?php 
        echo $item->picture;
        ?>
" alt="" />
                    <?php 
    } else {
        ?>
                    <img src="/img/zaglushka.png" alt="" />
                    <?php 
 /**
  * Copy image from temporary folder to proper destination and create thumbnails
  */
 protected function saveImage()
 {
     $imageHandler = new CImageHandler();
     $imageHandler->load($this->getTempFolder(TRUE) . $this->image);
     $imageHandler->save($this->getImagesFolder(TRUE) . $imageHandler->getBaseFileName());
     $settings = $this->getThumbsSettings();
     if (!empty($settings)) {
         $imageHandler = new CImageHandler();
         $imageHandler->load($this->getTempFolder(TRUE) . $this->image);
         foreach ($settings as $prefix => $dimensions) {
             list($width, $height) = $dimensions;
             $imageHandler->thumb($width, $height)->save($this->getImagesFolder(TRUE) . $prefix . $imageHandler->getBaseFileName());
         }
     }
 }
 public function actionAddbanner()
 {
     $model = $this->loadModel(Yii::app()->user->id);
     Yii::import("ext.Banner.qqFileUploader3");
     $folder = 'users/' . Yii::app()->user->id . '/';
     // folder for uploaded files
     $allowedExtensions = array("jpg", "jpeg", "gif", "png");
     //array("jpg","jpeg","gif","exe","mov" and etc...
     $sizeLimit = 8 * 1024 * 1024;
     // maximum file size in bytes
     $uploader = new qqFileUploader3($allowedExtensions, $sizeLimit);
     $result = $uploader->handleUpload($folder);
     $return = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     $fileSize = filesize($folder . $result['filename']);
     //GETTING FILE SIZE
     $fileName = $result['filename'];
     //GETTING FILE NAME
     $ih = new CImageHandler();
     $ih->load($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $fileName)->resize(1920, 436, false)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/banner_' . $fileName);
     $model->top_banner = 'banner_' . $fileName;
     if ($model->save()) {
         //Yii::app()->user->photo = '100_'.$fileName;
         unlink($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/' . $fileName);
     }
     echo $return;
     // it's array
 }
 public function actionCrop()
 {
     //print_r($_POST); exit();
     if (is_file($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/370_' . $_POST['img_name'])) {
         unlink($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/370_' . $_POST['img_name']);
     }
     $ih = new CImageHandler();
     $ih->load($_SERVER['DOCUMENT_ROOT'] . $_POST['img'])->crop($_POST['w'], $_POST['h'], $_POST['x'], $_POST['y'])->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . Yii::app()->user->id . '/370_' . $_POST['img_name']);
     $this->redirect($_POST['back']);
     //$this->redirect('/my/portfolio');
 }
Beispiel #20
0
 public function beforeSave()
 {
     if ($this->fileInstance) {
         $path = Yii::getPathOfAlias($this->path) . DIRECTORY_SEPARATOR . $this->apartment_id;
         $name = $this->fileInstance->getName();
         $ext = $this->fileInstance->getExtensionName();
         while (file_exists($path . DIRECTORY_SEPARATOR . $name)) {
             $name = rand(0, 9) . $name;
         }
         $oldUMask = umask(0);
         if (!is_dir($path)) {
             @mkdir($path, 0777, true);
         }
         umask($oldUMask);
         if ($this->fileInstance->saveAs($path . DIRECTORY_SEPARATOR . $name)) {
             $this->name = $name;
             if ($ext == 'jpg' || $ext == 'png' || $ext == 'gif') {
                 $image = new CImageHandler();
                 if ($image->load($path . DIRECTORY_SEPARATOR . $name)) {
                     $this->width = $image->getWidth();
                     $this->height = $image->getHeight();
                 } else {
                     return false;
                 }
             }
         } else {
             return false;
         }
     }
     return parent::beforeSave();
 }
Beispiel #21
0
 /**
  * Upload and apply new avatar
  * @return bool
  * @throws CException
  */
 public function changeAvatar()
 {
     // folder for uploaded files
     $tempFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['temp'];
     $avatarsFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['userAvatars'];
     if (!is_writable($tempFolder)) {
         throw new CException('temporary folder is not exists or not writable. Path:' . $tempFolder);
     }
     // Upload to temp folder
     $uploader = new FileUploader(Yii::app()->params['uploader']['allowedFileExtensions'], Yii::app()->params['uploader']['sizeLimit']);
     $result = $uploader->handleUpload($tempFolder);
     if (!isset($result['error'])) {
         // Move file to target folder and make thumbs
         $imageHandler = new CImageHandler();
         $imageHandler->load($tempFolder . $result['filename']);
         try {
             $imageHandler->save($avatarsFolder . $result['filename']);
             $imageHandler->cropAndScaleFromCenter(self::SMALL_THUMB_WIDTH, self::SMALL_THUMB_HEIGHT);
             $imageHandler->save($avatarsFolder . self::THUMB_PREFIX_SMALL . $result['filename']);
             $imageHandler->load($tempFolder . $result['filename']);
             $imageHandler->cropAndScaleFromCenter(self::MICRO_THUMB_WIDTH, self::MICRO_THUMB_HEIGHT);
             $imageHandler->save($avatarsFolder . self::THUMB_PREFIX_MICRO . $result['filename']);
             if ($this->hasPhoto()) {
                 $this->_removeOldPhoto();
             }
             $this->photo = $result['filename'];
             $this->_response = array('originalSrc' => $this->getOriginalPhoto(), 'thumbSrc' => $this->getSmallThumbnail());
             $this->save(FALSE);
             return TRUE;
         } catch (CException $e) {
             $this->_response = array('errorMessage' => $e->getMessage());
             return FALSE;
         }
     } else {
         $this->_response = array('errorMessage' => $result['error']);
         return FALSE;
     }
 }
Beispiel #22
0
    private function addListingFromCSV($value, $isZip, $maxSorter, $selectedImportUser)
    {
        if (is_array($value)) {
            $model = new $this->modelName();
            $type = !empty($value['type']) ? $value['type'] : Apartment::TYPE_DEFAULT;
            $priceType = !empty($value['priceType']) ? $value['priceType'] : '';
            $objType = !empty($value['objType']) ? $value['objType'] : min(Apartment::getObjTypesArray());
            $countryName = !empty($value['countryName']) ? trim($value['countryName']) : null;
            $regionName = !empty($value['regionName']) ? trim($value['regionName']) : null;
            $cityName = !empty($value['cityName']) ? trim($value['cityName']) : null;
            $countryId = $countryInfo = $regionId = $regionInfo = $cityId = $cityInfo = 0;
            if (issetModule('location')) {
                if ($countryName) {
                    if (isFree()) {
                        $countryInfo = Country::model()->findByAttributes(array('name_' . Yii::app()->language => $countryName));
                    } else {
                        Yii::app()->setLanguage($this->defLang);
                        $countryInfo = Country::model()->findByAttributes(array('name_' . Yii::app()->language => $countryName));
                        Yii::app()->setLanguage($this->currLang);
                    }
                    if ($countryInfo && isset($countryInfo->id)) {
                        $countryId = $countryInfo->id;
                    }
                }
                if ($regionName) {
                    if (isFree()) {
                        $regionInfo = Region::model()->findByAttributes(array('name_' . Yii::app()->language => $regionName));
                    } else {
                        Yii::app()->setLanguage($this->defLang);
                        $regionInfo = Region::model()->findByAttributes(array('name_' . Yii::app()->language => $regionName));
                        Yii::app()->setLanguage($this->currLang);
                    }
                    if ($regionInfo && isset($regionInfo->id)) {
                        $regionId = $regionInfo->id;
                    }
                }
                if ($cityName) {
                    if (isFree()) {
                        $cityInfo = City::model()->findByAttributes(array('name_' . Yii::app()->language => $cityName));
                    } else {
                        Yii::app()->setLanguage($this->defLang);
                        $cityInfo = City::model()->findByAttributes(array('name_' . Yii::app()->language => $cityName));
                        Yii::app()->setLanguage($this->currLang);
                    }
                    if ($cityInfo && isset($cityInfo->id)) {
                        $cityId = $cityInfo->id;
                    }
                }
            } else {
                if ($cityName) {
                    Yii::import('application.modules.apartmentCity.models.ApartmentCity');
                    if (isFree()) {
                        $cityInfo = ApartmentCity::model()->findByAttributes(array('name_' . Yii::app()->language => $cityName));
                    } else {
                        Yii::app()->setLanguage($this->defLang);
                        $cityInfo = ApartmentCity::model()->findByAttributes(array('name_' . Yii::app()->language => $cityName));
                        Yii::app()->setLanguage($this->currLang);
                    }
                    if ($cityInfo && isset($cityInfo->id)) {
                        $cityId = $cityInfo->id;
                    }
                }
            }
            // if type for sale - set price type only for sale
            if ($type == Apartment::TYPE_SALE) {
                $priceType = Apartment::PRICE_SALE;
            }
            $isPricePoa = isset($value['isPricePoa']) ? $value['isPricePoa'] : 0;
            $price = !empty($value['price']) ? $value['price'] : '';
            $priceTo = !empty($value['priceTo']) ? $value['priceTo'] : '';
            $numberRooms = !empty($value['numberRooms']) ? $value['numberRooms'] : '';
            $floor = !empty($value['floor']) ? $value['floor'] : '';
            $floor_total = !empty($value['floorTotal']) ? $value['floorTotal'] : '';
            $square = !empty($value['square']) ? $value['square'] : '';
            $landSquare = !empty($value['landSquare']) ? $value['landSquare'] : '';
            $sleeps = !empty($value['sleeps']) ? $this->deleteChars($value['sleeps']) : '';
            if (isFree()) {
                $title = !empty($value['title']) ? $this->deleteChars($value['title']) : '';
                $description = !empty($value['description']) ? $this->deleteChars($value['description']) : '';
                $near = !empty($value['near']) ? $this->deleteChars($value['near']) : '';
                $address = !empty($value['location']) ? $this->deleteChars($value['location']) : '';
                $exchange = !empty($value['exchange']) ? $this->deleteChars($value['exchange']) : '';
            } else {
                if ($this->allLangs) {
                    foreach ($this->i18nMaskFields as $i18nMaskField) {
                        foreach ($this->allLangs as $lang) {
                            $title[$lang->name_iso] = $this->deleteChars($value['title_' . $lang->name_iso]);
                            $description[$lang->name_iso] = $this->deleteChars($value['description_' . $lang->name_iso]);
                            $near[$lang->name_iso] = $this->deleteChars($value['near_' . $lang->name_iso]);
                            $address[$lang->name_iso] = $this->deleteChars($value['location_' . $lang->name_iso]);
                            $exchange[$lang->name_iso] = $this->deleteChars($value['exchange_' . $lang->name_iso]);
                        }
                    }
                }
            }
            $lat = !empty($value['lat']) ? $value['lat'] : '';
            $lng = !empty($value['lng']) ? $value['lng'] : '';
            // references
            $adRef = array();
            $adRef['bathroom'] = !empty($value['bathroom']) ? explode($this->separatorElem, $value['bathroom']) : null;
            $adRef['safety'] = !empty($value['safety']) ? explode($this->separatorElem, $value['safety']) : null;
            $adRef['comfort'] = !empty($value['comfort']) ? explode($this->separatorElem, $value['comfort']) : null;
            $adRef['kitchen'] = !empty($value['kitchen']) ? explode($this->separatorElem, $value['kitchen']) : null;
            $adRef['employment'] = !empty($value['employment']) ? explode($this->separatorElem, $value['employment']) : null;
            $adRef['entertainment'] = !empty($value['entertainment']) ? explode($this->separatorElem, $value['entertainment']) : null;
            $adRef['services'] = !empty($value['services']) ? explode($this->separatorElem, $value['services']) : null;
            $adRef['terms'] = !empty($value['terms']) ? explode($this->separatorElem, $value['terms']) : null;
            $photos = !empty($value['photos']) ? explode($this->separatorElem, $value['photos']) : null;
            // insert into apartments table
            if (isFree()) {
                $sql = 'INSERT INTO {{apartment}} (type, obj_type_id, loc_country, loc_region, loc_city, city_id, date_updated, date_created, activity_always, is_price_poa, price, price_to, num_of_rooms, floor,
									floor_total, square, land_square, window_to, title_' . Yii::app()->language . ', description_' . Yii::app()->language . ',
									description_near_' . Yii::app()->language . ', exchange_to_' . Yii::app()->language . ',
									living_conditions, services, address_' . Yii::app()->language . ', berths, active, lat, lng,
									rating, is_special_offer, is_free_to, price_type, sorter, owner_active, owner_id)

								VALUES (:type, :objType, :locCountryId, :locRegionId, :locCityId, :cityId, NOW(), NOW(), :activityAlways, :isPricePoa, :price, :priceTo,:numberRooms, :floor,
									:floorTotal, :square, :landSquare, :windowTo, :title, :description,
									:descriptionNear, :exchangeTo,
									:livingConditions, :services, :address, :berths, :active, :lat, :lng,
									:rating, "", "", :priceType, :maxSorter, :ownerActive, :ownerId) ';
                $command = Yii::app()->db->createCommand($sql);
                $command->bindValue(":type", $type, PDO::PARAM_INT);
                $command->bindValue(":objType", $objType, PDO::PARAM_INT);
                $command->bindValue(":locCountryId", $countryId, PDO::PARAM_INT);
                $command->bindValue(":locRegionId", $regionId, PDO::PARAM_INT);
                $command->bindValue(":locCityId", $cityId, PDO::PARAM_INT);
                $command->bindValue(":cityId", $cityId, PDO::PARAM_INT);
                $command->bindValue(":activityAlways", 1, PDO::PARAM_INT);
                $command->bindValue(":isPricePoa", $isPricePoa, PDO::PARAM_INT);
                $command->bindValue(":price", $price, PDO::PARAM_STR);
                $command->bindValue(":priceTo", $priceTo, PDO::PARAM_STR);
                $command->bindValue(":numberRooms", $numberRooms, PDO::PARAM_INT);
                $command->bindValue(":floor", $floor, PDO::PARAM_INT);
                $command->bindValue(":floorTotal", $floor_total, PDO::PARAM_INT);
                $command->bindValue(":square", $square, PDO::PARAM_INT);
                $command->bindValue(":landSquare", $landSquare, PDO::PARAM_INT);
                $command->bindValue(":windowTo", 0, PDO::PARAM_INT);
                $command->bindValue(":title", $title, PDO::PARAM_STR);
                $command->bindValue(":description", $description, PDO::PARAM_STR);
                $command->bindValue(":descriptionNear", $near, PDO::PARAM_STR);
                $command->bindValue(":exchangeTo", $exchange, PDO::PARAM_STR);
                $command->bindValue(":livingConditions", 0, PDO::PARAM_INT);
                $command->bindValue(":services", 0, PDO::PARAM_INT);
                $command->bindValue(":address", $address, PDO::PARAM_STR);
                $command->bindValue(":berths", $sleeps, PDO::PARAM_STR);
                $command->bindValue(":active", 0, PDO::PARAM_INT);
                $command->bindValue(":lat", $lat, PDO::PARAM_STR);
                $command->bindValue(":lng", $lng, PDO::PARAM_STR);
                $command->bindValue(":rating", 0, PDO::PARAM_INT);
                $command->bindValue(":priceType", $priceType, PDO::PARAM_INT);
                $command->bindValue(":maxSorter", $maxSorter, PDO::PARAM_INT);
                $command->bindValue(":ownerActive", 1, PDO::PARAM_INT);
                $command->bindValue(":ownerId", $selectedImportUser, PDO::PARAM_INT);
                $command->execute();
                $lastId = Yii::app()->db->getLastInsertID();
            } else {
                $fieldsSQL = $placeholdersSQL = $valuesSQL = array();
                if ($this->allLangs) {
                    foreach ($this->allLangs as $lang) {
                        $fieldsSQL[] = 'title_' . $lang->name_iso;
                        $fieldsSQL[] = 'description_' . $lang->name_iso;
                        $fieldsSQL[] = 'description_near_' . $lang->name_iso;
                        $fieldsSQL[] = 'address_' . $lang->name_iso;
                        $fieldsSQL[] = 'exchange_to_' . $lang->name_iso;
                        $placeholdersSQL[] = ':title_' . $lang->name_iso;
                        $placeholdersSQL[] = ':description_' . $lang->name_iso;
                        $placeholdersSQL[] = ':description_near_' . $lang->name_iso;
                        $placeholdersSQL[] = ':address_' . $lang->name_iso;
                        $placeholdersSQL[] = ':exchange_to_' . $lang->name_iso;
                        $valuesSQL[':title_' . $lang->name_iso] = $this->deleteChars($title[$lang->name_iso]);
                        $valuesSQL[':description_' . $lang->name_iso] = $this->deleteChars($description[$lang->name_iso]);
                        $valuesSQL[':description_near_' . $lang->name_iso] = $this->deleteChars($near[$lang->name_iso]);
                        $valuesSQL[':address_' . $lang->name_iso] = $this->deleteChars($address[$lang->name_iso]);
                        $valuesSQL[':exchange_to_' . $lang->name_iso] = $this->deleteChars($exchange[$lang->name_iso]);
                    }
                }
                $sql = 'INSERT INTO {{apartment}} (
									type, obj_type_id, loc_country, loc_region, loc_city, city_id, date_updated, date_created, activity_always, is_price_poa, price, price_to, num_of_rooms, floor,
									floor_total, square, land_square, window_to,
									living_conditions, services, berths, active, lat, lng,
									rating, is_special_offer, is_free_to, price_type, sorter, owner_active, owner_id,
									' . implode(", ", $fieldsSQL) . '
									)
								VALUES (
									:type, :objType, :locCountryId, :locRegionId, :locCityId, :cityId, NOW(), NOW(), :activityAlways, :isPricePoa, :price, :priceTo,:numberRooms, :floor,
									:floorTotal, :square, :landSquare, :windowTo,
									:livingConditions, :services, :berths, :active, :lat, :lng,
									:rating, "", "", :priceType, :maxSorter, :ownerActive, :ownerId,
									' . implode(", ", $placeholdersSQL) . '
									) ';
                $command = Yii::app()->db->createCommand($sql);
                $command->bindValue(":type", $type, PDO::PARAM_INT);
                $command->bindValue(":objType", $objType, PDO::PARAM_INT);
                $command->bindValue(":locCountryId", $countryId, PDO::PARAM_INT);
                $command->bindValue(":locRegionId", $regionId, PDO::PARAM_INT);
                $command->bindValue(":locCityId", $cityId, PDO::PARAM_INT);
                $command->bindValue(":cityId", $cityId, PDO::PARAM_INT);
                $command->bindValue(":activityAlways", 1, PDO::PARAM_INT);
                $command->bindValue(":isPricePoa", $isPricePoa, PDO::PARAM_INT);
                $command->bindValue(":price", $price, PDO::PARAM_STR);
                $command->bindValue(":priceTo", $priceTo, PDO::PARAM_STR);
                $command->bindValue(":numberRooms", $numberRooms, PDO::PARAM_INT);
                $command->bindValue(":floor", $floor, PDO::PARAM_INT);
                $command->bindValue(":floorTotal", $floor_total, PDO::PARAM_INT);
                $command->bindValue(":square", $square, PDO::PARAM_INT);
                $command->bindValue(":landSquare", $landSquare, PDO::PARAM_INT);
                $command->bindValue(":windowTo", 0, PDO::PARAM_INT);
                $command->bindValue(":livingConditions", 0, PDO::PARAM_INT);
                $command->bindValue(":services", 0, PDO::PARAM_INT);
                $command->bindValue(":berths", $sleeps, PDO::PARAM_STR);
                $command->bindValue(":active", 0, PDO::PARAM_INT);
                $command->bindValue(":lat", $lat, PDO::PARAM_STR);
                $command->bindValue(":lng", $lng, PDO::PARAM_STR);
                $command->bindValue(":rating", 0, PDO::PARAM_INT);
                $command->bindValue(":priceType", $priceType, PDO::PARAM_INT);
                $command->bindValue(":maxSorter", $maxSorter, PDO::PARAM_INT);
                $command->bindValue(":ownerActive", 1, PDO::PARAM_INT);
                $command->bindValue(":ownerId", $selectedImportUser, PDO::PARAM_INT);
                foreach ($valuesSQL as $name => $value) {
                    $command->bindValue($name, $value, PDO::PARAM_STR);
                }
                $command->execute();
                $lastId = Yii::app()->db->getLastInsertID();
            }
            // insert references
            foreach ($adRef as $key => $value) {
                switch ($key) {
                    case 'comfort':
                        $refId = 1;
                        break;
                    case 'bathroom':
                        $refId = 2;
                        break;
                    case 'kitchen':
                        $refId = 3;
                        break;
                    case 'employment':
                        $refId = 4;
                        break;
                    case 'safety':
                        $refId = 5;
                        break;
                    case 'entertainment':
                        $refId = 7;
                        break;
                    case 'terms':
                        $refId = 9;
                        break;
                    case 'services':
                        $refId = 10;
                        break;
                }
                if (is_array($value) && count($value) > 0) {
                    foreach ($value as $item) {
                        // get reference id by name
                        if (isFree()) {
                            //$sql = "SELECT id FROM {{apartment_reference_values}} WHERE title_" . Yii::app()->language . " = '" . $item . "' AND reference_category_id = '" . $refId . "'";
                            //$valId = Yii::app()->db->createCommand($sql)->queryRow();
                            $valId = Yii::app()->db->createCommand()->select('id')->from('{{apartment_reference_values}}')->where('title_' . Yii::app()->language . ' = :title AND reference_category_id = :catId', array(':title' => $item, ':catId' => $refId))->queryRow();
                        } else {
                            Yii::app()->setLanguage($this->defLang);
                            //$sql = "SELECT id FROM {{apartment_reference_values}} WHERE title_" . Yii::app()->language . " = '" . $item . "' AND reference_category_id = '" . $refId . "'";
                            //$valId = Yii::app()->db->createCommand($sql)->queryRow();
                            $valId = Yii::app()->db->createCommand()->select('id')->from('{{apartment_reference_values}}')->where('title_' . Yii::app()->language . ' = :title AND reference_category_id = :catId', array(':title' => $item, ':catId' => $refId))->queryRow();
                            Yii::app()->setLanguage($this->currLang);
                        }
                        if (isset($valId['id']) && !empty($valId['id'])) {
                            $sql = 'INSERT INTO {{apartment_reference}} (reference_id, reference_value_id, apartment_id)
								VALUES (:refId, :refValId, :apId) ';
                            $command = Yii::app()->db->createCommand($sql);
                            $command->bindValue(":refId", $refId, PDO::PARAM_INT);
                            $command->bindValue(":refValId", $valId['id'], PDO::PARAM_INT);
                            $command->bindValue(":apId", $lastId, PDO::PARAM_INT);
                            $command->execute();
                        }
                    }
                }
            }
            // get and upload photos
            if (is_array($photos) && count($photos) > 0) {
                $arrFiles = $arrImgs = array();
                $IecsvFiles = array();
                foreach ($photos as $key => $item) {
                    if (!$isZip) {
                        if (stristr($item, "http")) {
                            $pathParts = pathinfo($item);
                            $file = $pathParts['basename'];
                            $fileExt = $pathParts['extension'];
                            $photoPath = $model->csvPath . DIRECTORY_SEPARATOR . $file;
                            // get file by cUrl
                            if (function_exists('curl_version')) {
                                $ch = curl_init();
                                $ch = curl_init();
                                curl_setopt($ch, CURLOPT_URL, $item);
                                $fp = fopen($photoPath, 'wb');
                                curl_setopt($ch, CURLOPT_FILE, $fp);
                                curl_setopt($ch, CURLOPT_HEADER, 0);
                                curl_exec($ch);
                                curl_close($ch);
                                fclose($fp);
                            } else {
                                // no CUrl, try differently
                                file_put_contents($photoPath, file_get_contents($item));
                            }
                            // reset file name - remove host. only filename and extension.
                            $item = $file;
                        }
                    } else {
                        // image from zip arhive
                        $photoPath = $model->csvPath . DIRECTORY_SEPARATOR . $item;
                    }
                    if (file_exists($photoPath)) {
                        $IecsvFiles[$key]['name'] = $item;
                        $IecsvFiles[$key]['tmp_name'] = $photoPath;
                    }
                }
                if (count($IecsvFiles) > 0) {
                    $apartment = Apartment::model()->findByPk($lastId);
                    $path = Yii::getPathOfAlias('webroot.uploads.objects.' . $apartment->id . '.' . Images::ORIGINAL_IMG_DIR);
                    $pathMod = Yii::getPathOfAlias('webroot.uploads.objects.' . $apartment->id . '.' . Images::MODIFIED_IMG_DIR);
                    $oldUMask = umask(0);
                    if (!is_dir($path)) {
                        @mkdir($path, 0777, true);
                    }
                    if (!is_dir($pathMod)) {
                        @mkdir($pathMod, 0777, true);
                    }
                    umask($oldUMask);
                    $result['error'] = '';
                    if (is_writable($path) && is_writable($pathMod)) {
                        touch($path . DIRECTORY_SEPARATOR . 'index.htm');
                        touch($pathMod . DIRECTORY_SEPARATOR . 'index.htm');
                        foreach ($IecsvFiles as $IecsvFile) {
                            if (copy($model->csvPath . DIRECTORY_SEPARATOR . $IecsvFile['name'], $path . DIRECTORY_SEPARATOR . $IecsvFile['name'])) {
                                $resize = new CImageHandler();
                                if ($resize->load($path . DIRECTORY_SEPARATOR . $IecsvFile['name'])) {
                                    $resize->thumb(param('maxImageWidth', 1024), param('maxImageHeight', 768), Images::KEEP_PHOTO_PROPORTIONAL)->save();
                                    $image = new Images();
                                    $image->id_object = $apartment->id;
                                    $image->id_owner = $apartment->owner_id;
                                    $image->file_name = $IecsvFile['name'];
                                    $image->save();
                                }
                            } else {
                                $result['error'] = 'No copy';
                            }
                        }
                    } else {
                        $result['error'] = 'Access denied.';
                    }
                }
            }
        }
    }
Beispiel #23
0
 public static function addImage($filePath, $objectId, $isMain, $ownerId)
 {
     $path = Yii::getPathOfAlias('webroot.uploads.objects.' . $objectId . '.' . Images::ORIGINAL_IMG_DIR);
     $pathMod = Yii::getPathOfAlias('webroot.uploads.objects.' . $objectId . '.' . Images::MODIFIED_IMG_DIR);
     $oldUMask = umask(0);
     if (!is_dir($path)) {
         @mkdir($path, 0777, true);
     }
     if (!is_dir($pathMod)) {
         @mkdir($pathMod, 0777, true);
     }
     umask($oldUMask);
     if (is_writable($path) && is_writable($pathMod)) {
         touch($path . DIRECTORY_SEPARATOR . 'index.htm');
         touch($pathMod . DIRECTORY_SEPARATOR . 'index.htm');
         $ext = $ext = pathinfo($filePath, PATHINFO_EXTENSION);
         $mewFName = md5($filePath) . '.' . $ext;
         $newFilePath = $path . DIRECTORY_SEPARATOR . $mewFName;
         $resize = new CImageHandler();
         echo $filePath . '<br/>';
         if ($resize->load($filePath)) {
             $resize->thumb(param('maxImageWidth', 1024), param('maxImageHeight', 768), Images::KEEP_PHOTO_PROPORTIONAL)->save($newFilePath);
             $image = new Images();
             $image->id_object = $objectId;
             $image->id_owner = $ownerId;
             $image->is_main = $isMain;
             $image->file_name = $mewFName;
             $image->save();
         } else {
             echo $newFilePath . ': Wrong image type.<br/>';
             @unlink($newFilePath);
         }
     }
 }
}
?>
 
          </ul>
          <?php 
$new_width = count($hall->files) * 600;
?>
          <div id="horisontal-slider">
              <div class="horisontal-slider__content" style="width: <?php 
echo $new_width;
?>
px !important;"> 
                <?php 
foreach ($hall->files as $file) {
    if (is_file($_SERVER['DOCUMENT_ROOT'] . '/users/hall_572_' . $model->id . '/' . $file->file)) {
        echo '<img src="/users/' . $model->id . '/hall_572_' . $file->file . '" alt="' . $model->name . ' - ' . Occupation::getName($model->occupation_id) . '">';
    } else {
        $ih = new CImageHandler();
        $ih->load($_SERVER['DOCUMENT_ROOT'] . '/users/' . $model->id . '/' . $file->file)->adaptiveThumb(572, 429)->save($_SERVER['DOCUMENT_ROOT'] . '/users/' . $model->id . '/hall_572_' . $file->file);
        echo '<img src="/users/' . $model->id . '/hall_572_' . $file->file . '" alt="' . $model->name . ' - ' . Occupation::getName($model->occupation_id) . '">';
    }
}
?>
              </div>
          </div>
      </section>
      
         

    </div>
  </div>