예제 #1
0
 /**
  * Main class method. Resize the image and apply the watermark;
  * @return string error string or url to thumbnail
  * @access public
  */
 function Execute()
 {
     $ret = "";
     $relpath = $this->relpath;
     $folder = KT_TransformToUrlPath($this->folder);
     $fileName = KT_DynamicData($this->renameRule, null);
     $fileName = KT_TransformToUrlPath($fileName, false);
     $fullFolder = KT_realpath($folder, true);
     $fullFileName = KT_realpath($fullFolder . $fileName, false);
     $path_info = KT_pathinfo($fullFileName);
     $thumbnailFolder = $path_info['dirname'] . '/thumbnails/';
     if (substr($fullFileName, 0, strlen($fullFolder)) != $fullFolder) {
         if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') {
             $baseFileName = dirname($fullFileName);
             $errorMsg = KT_getResource("FOLDER_DEL_SECURITY_ERROR_D", "tNG", array($baseFileName, $fullFolder));
             $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />" . $errorMsg . "<img style=\"display:none\" src=\"" . $relpath . "includes/tng/styles/cannot_thumbnail.gif";
         } else {
             $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif";
         }
     } else {
         if ($this->getFileName() !== false) {
             // make the resize
             $proportional = $this->keepProportion;
             $width = $this->width;
             $height = $this->height;
             if (!$this->watermark) {
                 $thumbnailName = $path_info['filename'] . '_' . $width . 'x' . $height . (isset($path_info['extension']) ? '.' . $path_info['extension'] : '');
             } else {
                 $hash = tNG_watermarkHash(KT_realpath($this->watermarkImage, false), $this->watermarkAlpha, $this->watermarkResize, $this->watermarkAlignment);
                 $thumbnailName = $path_info['filename'] . '_' . $width . 'x' . $height . '_w_' . $hash . (isset($path_info['extension']) ? '.' . $path_info['extension'] : '');
             }
             $thumbnailFullName = $thumbnailFolder . $thumbnailName;
             if (!file_exists(KT_realpath($thumbnailFullName, false))) {
                 $imageObj = new KT_image();
                 $imageObj->setPreferedLib($GLOBALS['tNG_prefered_image_lib']);
                 $imageObj->addCommand($GLOBALS['tNG_prefered_imagemagick_path']);
                 $imageObj->thumbnail($fullFileName, $thumbnailFolder, $thumbnailName, (int) $width, (int) $height, $proportional);
                 if ($imageObj->hasError()) {
                     $errorArr = $imageObj->getError();
                     if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') {
                         $errMsg = $errorArr[1];
                         $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />" . $errMsg . "<img style=\"display:none\" src=\"" . $relpath . "includes/tng/styles/cannot_thumbnail.gif";
                     } else {
                         $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif";
                     }
                     return $ret;
                 } else {
                     // apply watermark
                     if ($this->watermark) {
                         // delete other watermarks for same picture
                         tNG_deleteThumbnails($thumbnailFolder, $path_info['filename'] . '_' . $width . 'x' . $height, $hash);
                         $imageObj = new KT_image();
                         $imageObj->setPreferedLib($GLOBALS['tNG_prefered_image_lib']);
                         $imageObj->addCommand($GLOBALS['tNG_prefered_imagemagick_path']);
                         $imageObj->watermark($thumbnailFullName, $thumbnailFullName, KT_realpath($this->watermarkImage, false), $this->watermarkAlpha, $this->watermarkResize, $this->watermarkAlignment);
                         if ($imageObj->hasError()) {
                             @unlink($thumbnailFullName);
                             $arrError = $imageObj->getError();
                             $errObj = new tNG_error('IMG_WATERMARK', array(), array($arrError[1]));
                             if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') {
                                 $errMsg = $arrError[1];
                                 $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />" . $errMsg . "<img style=\"display:none\" src=\"" . $relpath . "includes/tng/styles/cannot_thumbnail.gif";
                             } else {
                                 $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif";
                             }
                             return $ret;
                         }
                     }
                 }
                 $thumbnailURL = $this->folder . KT_DynamicData($this->renameRule, null);
                 $thumbnailURL = dirname($thumbnailURL) . "/thumbnails/" . $thumbnailName;
                 $ret = KT_CanonizeRelPath($thumbnailURL);
                 if (!$imageObj->hasError()) {
                     //$ret .= '?' . md5(filectime($ret));
                 }
             } else {
                 $thumbnailURL = $this->folder . KT_DynamicData($this->renameRule, null);
                 $thumbnailURL = dirname($thumbnailURL) . "/thumbnails/" . $thumbnailName;
                 $ret = KT_CanonizeRelPath($thumbnailURL);
             }
         } else {
             $ret = $relpath . "includes/tng/styles/img_not_found.gif";
         }
     }
     return $ret;
 }
예제 #2
0
    if (!isset($wasResized)) {
        $arr = explode('/', $hashFile['fullfilename']);
        $fileName = array_pop($arr);
        $hashThumbnail = tNG_watermarkHash($hash['watermark'], $hash['watermarkAlpha'], $hash['watermarkResize'], $hash['watermarkAlignment']);
        $folder = implode('/', $arr) . '/thumbnails/';
        $path_info = KT_pathinfo($fileName);
        $fileName = $path_info['filename'] . '_' . $size[0] . 'x' . $size[1] . '_w_' . $hashThumbnail . (isset($path_info['extension']) ? '.' . $path_info['extension'] : '');
        $thumbnailForDelete = $path_info['filename'] . '_' . $size[0] . 'x' . $size[1];
    }
    $image = new KT_image();
    $image->setPreferedLib($GLOBALS['tNG_prefered_image_lib']);
    $image->addCommand($GLOBALS['tNG_prefered_imagemagick_path']);
    if (!isset($wasResized)) {
        if (!file_exists('../../../' . $folder . $fileName)) {
            $image->watermark('../../../' . $hashFile['fullfilename'], '../../../' . $folder . $fileName, $hash['watermark'], $hash['watermarkAlpha'], $hash['watermarkResize'], $hash['watermarkAlignment']);
            tNG_deleteThumbnails('../../../' . $folder, $thumbnailForDelete, $hashThumbnail);
        }
    } else {
        $image->watermark('../../../' . $folder . $fileName, '../../../' . $folder . $fileName, $hash['watermark'], $hash['watermarkAlpha'], $hash['watermarkResize'], $hash['watermarkAlignment']);
    }
    if ($image->hasError()) {
        $err = $image->getError();
    }
    $hashFile['fullfilename'] = $fileName;
}
?>
<html>
<head>
	<title>Popup Image</title>
	<link href="../../../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
	<style>
예제 #3
0
        $err = $folderObj->getError();
        echo '<html><head><title>Multilpe Upload</title><link href="../../../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" /></head><body><div id="KT_tngerror"><label>' . KT_getResource('ERROR_LABEL', 'tNG') . '</label><div>';
        echo isset($GLOBALS['tNG_debug_mode']) && $GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT' ? $err[1] : $err[0];
        echo '</div></div></body></html>';
        exit;
    }
}
// delete selected file
if (isset($_POST['delete']) && isset($_SESSION['tng_upload_delete'][$_POST['delete']])) {
    $file = new KT_file();
    $file->deleteFile($folder . $_SESSION['tng_upload_delete'][$_POST['delete']]);
    if ($file->hasError()) {
        $err = $file->getError();
    } else {
        // delete thumbnails
        tNG_deleteThumbnails($folder . '/thumbnails/', $_SESSION['tng_upload_delete'][$_POST['delete']], '');
    }
    $_SESSION['tng_upload_delete'] = array();
    KT_redir(KT_getFullUri());
}
$_SESSION['tng_upload_delete'] = array();
// upload the files;
if (isset($_FILES['Filedata'])) {
    $folderObj = new KT_folder();
    $entries = $folderObj->readFolder($folder);
    if ($uploadHash['maxFiles'] == 0 || isset($uploadHash['maxFiles']) && isset($entries['files']) && count($entries['files']) < $uploadHash['maxFiles'] || !isset($uploadHash['maxFiles']) || !isset($entries['files'])) {
        $fileUpload = new KT_fileUpload();
        $fileUpload->setFileInfo('Filedata');
        $fileUpload->setFolder($folder);
        $fileUpload->setRequired(true);
        $fileUpload->setAllowedExtensions($uploadHash['allowedExtensions']);
예제 #4
0
 /**
  * in case of an update, the old thumbnail are deleted;
  * @var string the name of the folder
  * @var string the old name of the file
  * @access public
  */
 function deleteThumbnails($folder, $oldName)
 {
     tNG_deleteThumbnails($folder, $oldName, '');
 }