Esempio n. 1
0
 public function processUpload($album_id)
 {
     $config = cmsConfig::getInstance();
     $uploader = new cmsUploader();
     $result = $uploader->upload('qqfile');
     if ($result['success']) {
         if (!$uploader->isImage($result['path'])) {
             $result['success'] = false;
             $result['error'] = LANG_UPLOAD_ERR_MIME;
         }
     }
     if (!$result['success']) {
         if (!empty($result['path'])) {
             $uploader->remove($result['path']);
         }
         cmsTemplate::getInstance()->renderJSON($result);
         $this->halt();
     }
     $preset = array('width' => 600, 'height' => 460, 'is_square' => false, 'is_watermark' => false);
     if (!empty($this->options['preset'])) {
         $preset = cmsCore::getModel('images')->getPresetByName($this->options['preset']);
     }
     $result['paths'] = array('big' => $uploader->resizeImage($result['path'], array('width' => $preset['width'], 'height' => $preset['height'], 'square' => $preset['is_square'], 'quality' => $preset['is_watermark'] && !empty($preset['wm_image']) ? 100 : $preset['quality'])), 'normal' => $uploader->resizeImage($result['path'], array('width' => 160, 'height' => 160, 'square' => true)), 'small' => $uploader->resizeImage($result['path'], array('width' => 64, 'height' => 64, 'square' => true)), 'original' => $result['url']);
     if ($preset['is_watermark'] && !empty($preset['wm_image'])) {
         img_add_watermark($result['paths']['big'], $preset['wm_image']['original'], $preset['wm_origin'], $preset['wm_margin'], $preset['quality']);
     }
     $result['filename'] = basename($result['path']);
     if (empty($this->options['is_origs'])) {
         @unlink($result['path']);
         unset($result['paths']['original']);
     }
     unset($result['path']);
     $result['url'] = $config->upload_host . '/' . $result['paths']['small'];
     $result['id'] = $this->model->addPhoto($album_id, $result['paths']);
     cmsTemplate::getInstance()->renderJSON($result);
     $this->halt();
 }
Esempio n. 2
0
 /**
  * Загружает фото файл
  * @return array $file (filename, realfile)
  */
 public function uploadPhoto($old_file = '')
 {
     // если каталог загрузки не определен, возвращаем ложь
     if (!$this->upload_dir) {
         return false;
     }
     if (!empty($_FILES[$this->input_name]['name'])) {
         cmsCore::includeGraphics();
         $input_name = preg_replace('/[^a-zA-Zа-яёЁА-Я0-9\\.\\-_ ]/ui', '', mb_substr(basename(strval($_FILES[$this->input_name]['name'])), 0, 160));
         // расширение
         $ext = mb_strtolower(pathinfo($input_name, PATHINFO_EXTENSION));
         // имя файла без расширения
         $realfile = str_replace('.' . $ext, '', $input_name);
         if (!in_array($ext, array('jpg', 'jpeg', 'gif', 'png', 'bmp'))) {
             return false;
         }
         $this->filename = $this->filename ? $this->filename : md5(time() . $realfile) . '.' . $ext;
         $uploadphoto = $this->upload_dir . $this->filename;
         $uploadthumb['small'] = $this->upload_dir . $this->dir_small . $this->filename;
         $uploadthumb['medium'] = $this->upload_dir . $this->dir_medium . $this->filename;
         $uploadphoto = $this->upload_dir . $this->filename;
         $source = $_FILES[$this->input_name]['tmp_name'];
         $errorCode = $_FILES[$this->input_name]['error'];
         if (cmsCore::moveUploadedFile($source, $uploadphoto, $errorCode)) {
             // удаляем предыдущий файл если необходимо
             $this->deletePhotoFile($old_file);
             if (!$this->isImage($uploadphoto)) {
                 $this->deletePhotoFile($this->filename);
                 return false;
             }
             if (!$this->small_size_h) {
                 $this->small_size_h = $this->small_size_w;
             }
             if (!$this->medium_size_h) {
                 $this->medium_size_h = $this->medium_size_w;
             }
             // Гененрируем маленькое и среднее изображения
             if (!$this->only_medium) {
                 if (!is_dir($this->upload_dir . $this->dir_small)) {
                     @mkdir($this->upload_dir . $this->dir_small);
                 }
                 @img_resize($uploadphoto, $uploadthumb['small'], $this->small_size_w, $this->small_size_h, $this->thumbsqr);
             }
             if (!is_dir($this->upload_dir . $this->dir_medium)) {
                 @mkdir($this->upload_dir . $this->dir_medium);
             }
             @img_resize($uploadphoto, $uploadthumb['medium'], $this->medium_size_w, $this->medium_size_h, false, false);
             // Накладывать ватермарк
             if ($this->is_watermark) {
                 @img_add_watermark($uploadthumb['medium']);
             }
             if ($this->is_watermark) {
                 @img_add_watermark($uploadthumb['small']);
             }
             // сохранять оригинал
             if (!$this->is_saveorig) {
                 @unlink($uploadphoto);
             } elseif ($this->is_watermark) {
                 @img_add_watermark($uploadphoto);
             }
             $file['filename'] = $this->filename;
             $file['realfile'] = $realfile;
         } else {
             return false;
         }
     } else {
         return false;
     }
     return $file;
 }
Esempio n. 3
0
             @unlink(PATH . "/images/catalog/{$imageurl}");
             @unlink(PATH . "/images/catalog/small/{$imageurl}.jpg");
             @unlink(PATH . "/images/catalog/medium/{$imageurl}.jpg");
         }
         $file = $_FILES["imgfile"]["name"];
         $path_parts = pathinfo($file);
         $ext = $path_parts['extension'];
         if (strstr($ext, 'php')) {
             die;
         }
         $file = md5($file . time()) . '.' . $ext;
         $item['imageurl'] = $file;
         if (@move_uploaded_file($tmp_name, PATH . "/images/catalog/{$file}")) {
             //create image thumbnails
             if ($cfg['watermark']) {
                 @img_add_watermark(PATH . "/images/catalog/{$file}");
             }
             @img_resize(PATH . "/images/catalog/{$file}", PATH . "/images/catalog/small/{$file}.jpg", 100, 100);
             @img_resize(PATH . "/images/catalog/{$file}", PATH . "/images/catalog/medium/{$file}.jpg", 250, 250);
             @chmod(PATH . "/images/catalog/{$file}", 0644);
             @chmod(PATH . "/images/catalog/small/{$file}.jpg", 0644);
             @chmod(PATH . "/images/catalog/medium/{$file}.jpg", 0644);
         } else {
             $msg = 'Ошибка загрузки изображения!';
         }
     }
     $model->updateItem($id, $item);
 }
 if (!isset($_SESSION['editlist']) || @sizeof($_SESSION['editlist']) == 0) {
     $inCore->redirect('?view=components&do=config&id=' . $_REQUEST['id'] . '&opt=list_items');
 } else {
Esempio n. 4
0
    if ($ext != 'jpg' && $ext != 'jpeg' && $ext != 'gif' && $ext != 'png' && $ext != 'bmp') {
        exit(0);
    }
    $lid = $inDB->get_fields('cms_user_photos', 'id>0', 'id', 'id DESC');
    $lastid = $lid['id'] + 1;
    $filename = md5($lastid . $realfile) . '.jpg';
    $uploadphoto = $uploaddir . $filename;
    $uploadthumb['small'] = $uploaddir . 'small/' . $filename;
    $uploadthumb['medium'] = $uploaddir . 'medium/' . $filename;
    $source = $_FILES['Filedata']['tmp_name'];
    $errorCode = $_FILES['Filedata']['error'];
    if ($inCore->moveUploadedFile($source, $uploadphoto, $errorCode)) {
        @img_resize($uploadphoto, $uploadthumb['small'], 96, 96, true);
        @img_resize($uploadphoto, $uploadthumb['medium'], 600, 600, false, false);
        if ($model->config['watermark']) {
            @img_add_watermark($uploadthumb['medium']);
        }
        @unlink($uploadphoto);
        $model->addUploadedPhoto($user_id, array('filename' => $realfile, 'imageurl' => $filename));
        if (cmsCore::inRequest('upload')) {
            cmsCore::redirect('/users/' . $inUser->login . '/photos/submit');
        }
    } else {
        header("HTTP/1.1 500 Internal Server Error");
        echo cmsCore::uploadError();
    }
    exit(0);
}
if ($pdo == 'submitphotos') {
    if (!$inUser->id) {
        cmsCore::error404();
Esempio n. 5
0
    $lid 					= $inDB->get_fields('cms_user_photos', 'id>0', 'id', 'id DESC');
    $lastid 				= $lid['id']+1;
    $filename 				= md5($lastid.$realfile).'.jpg';

    $uploadphoto 			= $uploaddir . $filename;
    $uploadthumb['small'] 	= $uploaddir . 'small/' . $filename;
    $uploadthumb['medium']	= $uploaddir . 'medium/' . $filename;

    $source					= $_FILES['Filedata']['tmp_name'];
    $errorCode				= $_FILES['Filedata']['error'];

    if ($inCore->moveUploadedFile($source, $uploadphoto, $errorCode)) {

        @img_resize($uploadphoto, $uploadthumb['small'], 96, 96, true);
        @img_resize($uploadphoto, $uploadthumb['medium'], 600, 600, false, false);
		if ($model->config['watermark']) { @img_add_watermark($uploadthumb['medium']); }
		@unlink($uploadphoto);

        $model->addUploadedPhoto($user_id, array('filename'=>$realfile, 'imageurl'=>$filename));
		if (cmsCore::inRequest('upload')) { cmsCore::redirect('/users/'.$inUser->login.'/photos/submit'); }

    } else {

        header("HTTP/1.1 500 Internal Server Error");
        echo cmsCore::uploadError();

    }

    exit(0);

}
Esempio n. 6
0
 /**
  * Этот метод устаревший, используйте функцию img_add_watermark
  */
 public function addWatermark($src_file, $wm_file, $wm_origin, $wm_margin, $quality = 90)
 {
     return img_add_watermark($src_file, $wm_file, $wm_origin, $wm_margin, $quality);
 }
Esempio n. 7
0
 public function processUpload($album_id)
 {
     $album_id = $album_id ? $album_id : $this->request->get('album_id', 0);
     $album = $this->model->getAlbum($album_id);
     if (!$album) {
         return $this->cms_template->renderJSON(array('success' => false, 'error' => sprintf(LANG_PHOTOS_SELECT_ALBUM, $album['ctype']['labels']['one'])));
     }
     if (!$album['is_public'] && $album['user_id'] != $this->cms_user->id && !$this->cms_user->is_admin) {
         return $this->cms_template->renderJSON(array('success' => false, 'error' => 'access error'));
     }
     // получаем пресеты, которые нужно создать
     $presets = cmsCore::getModel('images')->orderByList(array(array('by' => 'is_square', 'to' => 'asc'), array('by' => 'width', 'to' => 'desc')))->filterIsNull('is_internal')->getPresets();
     if (!$presets || empty($this->options['sizes'])) {
         return $this->cms_template->renderJSON(array('success' => false, 'error' => 'no presets'));
     }
     $result = $this->cms_uploader->upload('qqfile');
     if ($result['success']) {
         if (!$this->cms_uploader->isImage($result['path'])) {
             $result['success'] = false;
             $result['error'] = LANG_UPLOAD_ERR_MIME;
         }
     }
     if (!$result['success']) {
         if (!empty($result['path'])) {
             $this->cms_uploader->remove($result['path']);
         }
         return $this->cms_template->renderJSON($result);
     }
     $result['paths']['original'] = $result['url'];
     foreach ($presets as $p) {
         if (!in_array($p['name'], $this->options['sizes'], true)) {
             continue;
         }
         $path = $this->cms_uploader->resizeImage($result['path'], array('width' => $p['width'], 'height' => $p['height'], 'is_square' => $p['is_square'], 'quality' => $p['is_watermark'] && $p['wm_image'] ? 100 : $p['quality']));
         if (!$path) {
             continue;
         }
         if ($p['is_watermark'] && $p['wm_image']) {
             img_add_watermark($path, $p['wm_image']['original'], $p['wm_origin'], $p['wm_margin'], $p['quality']);
         }
         $result['paths'][$p['name']] = $path;
     }
     $result['filename'] = basename($result['path']);
     // основную exif информацию берём из оригинала
     $image_data = img_get_params($result['path']);
     // если оригинал удаляется, то размеры берём из пресета просмотра на странице
     $big_image_data = img_get_params($this->cms_config->upload_path . $result['paths'][$this->options['preset']]);
     // ориентацию берем из большого фото, т.к. оригиналы автоматически не поворачиваются
     $image_data['orientation'] = $big_image_data['orientation'];
     if (empty($this->options['is_origs'])) {
         @unlink($result['path']);
         unset($result['paths']['original']);
         $image_data['width'] = $big_image_data['width'];
         $image_data['height'] = $big_image_data['height'];
     }
     unset($result['path']);
     // маленкая картинка
     $last_image = end($result['paths']);
     $result['url'] = $this->cms_config->upload_host . '/' . $last_image;
     // большая картинка
     $first_image = reset($result['paths']);
     $result['big_url'] = $this->cms_config->upload_host . '/' . $first_image;
     $sizes = array();
     foreach ($result['paths'] as $name => $relpath) {
         $s = getimagesize($this->cms_config->upload_path . $relpath);
         if ($s === false) {
             continue;
         }
         $sizes[$name] = array('width' => $s[0], 'height' => $s[1]);
     }
     $date_photo = isset($image_data['exif']['date']) ? $image_data['exif']['date'] : false;
     $camera = isset($image_data['exif']['camera']) ? $image_data['exif']['camera'] : null;
     unset($image_data['exif']['date'], $image_data['exif']['camera'], $image_data['exif']['orientation']);
     $result['id'] = $this->model->addPhoto(array('album_id' => $album['id'], 'user_id' => $this->cms_user->id, 'image' => $result['paths'], 'date_photo' => $date_photo, 'camera' => $camera, 'width' => $image_data['width'], 'height' => $image_data['height'], 'sizes' => $sizes, 'is_private' => 2, 'orientation' => $image_data['orientation'], 'exif' => !empty($image_data['exif']) ? $image_data['exif'] : null));
     return $this->cms_template->renderJSON($result);
 }
Esempio n. 8
0
require_once '../../core/classes/db.class.php';
require_once '../../core/cms.php';
//header('X-Frame-Options: DENY');
$inDB = cmsDatabase::getInstance();
$inCore = cmsCore::getInstance();
$inPage = cmsPage::getInstance();
//set path to img
$upload_dir = PATH . "/upload/wysiwyg/";
$avatars_dir_rel = "/upload/wysiwyg/";
$upload_dir_handle = opendir($upload_dir);
$upload_imgs = array();
$hello = $_POST['toyou'];
echo $hello;
$img_with_watermark = $inDB->get_fields('cms_img_watermark_list', '', 'img_name');
var_dump($img_with_watermark);
exit;
while ($nextfile = readdir($upload_dir_handle)) {
    if ($nextfile != '.' && $nextfile != '..') {
        if (!in_array($nextfile, $img_with_watermark, true)) {
            $upload_imgs[] = $nextfile;
        }
    }
}
foreach ($upload_imgs as $upload_img) {
    $upload_img_src = $upload_dir . $upload_img['img_name'];
    //add watermark on img
    @img_add_watermark($upload_img_src);
    // add img with watermark in to db
    $sql = "INSERT INTO cms_img_watermark_list  (img_name) VALUE '" . $upload_img['img_name'] . "' ";
    $inDB->query($sql);
}
Esempio n. 9
0
         $realfile = $data_array['name'];
         $tmp_name = $data_array['tmp_name'];
         $lid = dbGetFields('cms_photo_files', 'id>0', 'id', 'id DESC');
         $lastid = $lid['id'] + 1;
         $filename = md5($realfile . '-' . $inUser->id . '-' . time()) . '.jpg';
         $uploadfile = $uploaddir . $realfile;
         $uploadphoto = $uploaddir . $filename;
         $uploadthumb = $uploaddir . 'small/' . $filename;
         $uploadthumb2 = $uploaddir . 'medium/' . $filename;
         $photo['filename'] = $filename;
         if (move_uploaded_file($tmp_name, $uploadphoto)) {
             $loaded_files[] = $realfile;
             @img_resize($uploadphoto, $uploadthumb, $album['thumb1'], $album['thumb1'], $album['thumbsqr']);
             @img_resize($uploadphoto, $uploadthumb2, $album['thumb2'], $album['thumb2'], false, $cfg['watermark']);
             if ($cfg['watermark']) {
                 @img_add_watermark($uploadphoto);
             }
             if (@(!$inCore->inRequest('saveorig'))) {
                 @unlink($uploadphoto);
             }
             if ($titlemode == 'number') {
                 $photo['title'] = 'Фото #' . sizeof($loaded_files);
             } else {
                 $photo['title'] = $realfile;
             }
             $model->addPhoto($photo);
         }
     }
 }
 echo '<div style="padding:20px">';
 if (sizeof($loaded_files)) {