Пример #1
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;
 }
Пример #2
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;
 }
Пример #3
0
<?php

echo tc('Photos for listing');
?>
:<br/>
<?php 
echo '<div class="images-area-admin">';
if ($this->images) {
    $this->widget('application.modules.images.components.AdminViewImagesWidget', array('objectId' => $this->objectId, 'images' => $this->images, 'withMain' => $this->withMain));
} else {
    echo '<strong>' . tc('Photo gallery is empty.') . '</strong>';
}
echo '</div>';
$this->widget('ext.EAjaxUpload.EAjaxUpload', array('id' => 'uploadFile', 'config' => array('action' => Yii::app()->createUrl('/images/main/upload', array('id' => $this->objectId)), 'allowedExtensions' => param('allowedImgExtensions', array('jpg', 'jpeg', 'gif', 'png')), 'sizeLimit' => Images::getMaxSizeLimit(), 'minSizeLimit' => param('minImgFileSize', 5 * 1024), 'multiple' => true, 'onComplete' => "js:function(id, fileName, responseJSON){ reloadImagesArea(); }", 'messages' => array('typeError' => tc("{file} has invalid extension. Only {extensions} are allowed."), 'sizeError' => tc("{file} is too large, maximum file size is {sizeLimit}."), 'minSizeError' => tc("{file} is too small, minimum file size is {minSizeLimit}."), 'emptyError' => tc("{file} is empty, please select files again without it."), 'onLeave' => tc("The files are being uploaded, if you leave now the upload will be cancelled.")))));
$this->widget('ext.charcounter.CharCounter', array('target' => '.image-comment-input > textarea', 'count' => 255, 'config' => array('container' => '<div></div>', 'format' => CJavaScript::quote(tc('Characters left')) . ': %1')));
Yii::app()->clientScript->registerScript('images-reloader', '
		function reInitJs(){
			$(".images-area-admin .fancy").fancybox();
			$(".image-comment-input > textarea").charCounter(255, {
				container: "<div></div>",
				format: "' . CJavaScript::quote(tc('Characters left')) . ': %1"
			});
			if($(".images-area").find(".image-item").length == 0){
				$(".images-area-admin").html("' . CJavaScript::quote(tc('Photo gallery is empty.')) . '");
			}
		}

		$(".setAsMainLink").live("click", function(){
			var id = $(this).closest(".setAsMain").attr("link-id");
			$.ajax({
				url: "' . Yii::app()->controller->createUrl('/images/main/setMainImage') . '?id="+id,