Example #1
0
 /**
  * setter. set the folder name
  * @var object tNG
  * @access public
  */
 function setFolder($folder)
 {
     $folder = KT_TransformToUrlPath($folder, true);
     $pos = strpos($folder, '{');
     if ($pos !== false) {
         $this->folder = substr($folder, $pos);
         $this->baseFolder = substr($folder, 0, $pos);
     } else {
         $this->folder = '';
         $this->baseFolder = $folder;
     }
 }
Example #2
0
 /**
  * Setter. Sets the folder rename rule
  * @param string 
  * @access public
  */
 function setFolder($folder)
 {
     $this->folder = KT_TransformToUrlPath(KT_DynamicData($folder, null));
 }
 /**
  * Main class method. Return a fake recordset.
  * @var string 
  * @access private
  */
 function Execute()
 {
     $relFolder = KT_DynamicData($this->folder, '', '', false, array(), false);
     $relFolder = KT_TransformToUrlPath($relFolder, true);
     if (substr($relFolder, 0, 1) == '/') {
         $relFolder = substr($relFolder, 1);
     }
     $fullFolderPath = KT_realpath($this->baseFolder . $relFolder, true);
     if (substr($fullFolderPath, 0, strlen($this->baseFolder)) != $this->baseFolder) {
         if (isset($GLOBALS['tNG_debug_mode']) && $GLOBALS['tNG_debug_mode'] == "DEVELOPMENT") {
             die("Security error. The folder '" . $fullFolderPath . "' is out of base folder '" . $this->baseFolder . "'");
         } else {
             die("Security error. Access to this folder is forbidden.");
         }
     }
     $this->path = $fullFolderPath;
     $noOfEntries = 0;
     $startCountEntries = $this->page * $this->recordsPerPage;
     $this->totalNo = 0;
     if (file_exists($this->path)) {
         //read folders
         $folder = new KT_folder();
         $entries = $folder->readFolder($this->path, true);
         if ($folder->hasError()) {
             $err = $folder->getError();
             if (isset($GLOBALS['tNG_debug_mode']) && $GLOBALS['tNG_debug_mode'] == "DEVELOPMENT") {
                 $this->error = $err[1];
             } else {
                 $this->error = $err[0];
             }
         }
         $this->filesArr = $entries['files'];
         $tmpFilesArr = array();
         $tmpArr = array();
         for ($i = 0; $i < count($this->filesArr); $i++) {
             $this->filesArr[$i]['fullname'] = $relFolder . $this->filesArr[$i]['name'];
             $path_info = KT_pathinfo($this->filesArr[$i]['name']);
             $this->filesArr[$i]['extension'] = $path_info['extension'];
             $filetime = filectime($this->path . $this->filesArr[$i]['name']);
             $this->filesArr[$i]['date'] = $filetime;
             if (in_array(strtolower($this->filesArr[$i]['extension']), $this->allowedExtensions) || in_array("*", $this->allowedExtensions)) {
                 $tmpArr[] = $this->filesArr[$i][$this->orderField];
                 $tmpFilesArr[] = $this->filesArr[$i];
             }
         }
         $this->filesArr = $tmpFilesArr;
         $this->Sort($tmpArr);
         $this->totalNo = count($this->filesArr);
         if ($this->recordsPerPage > 0) {
             $from = $this->page * $this->recordsPerPage;
             $this->filesArr = array_slice($this->filesArr, $from, $this->recordsPerPage);
         }
         for ($i = 0; $i < count($this->filesArr); $i++) {
             $this->filesArr[$i]['date'] = KT_convertDate(date("Y-m-d H:i:s", $this->filesArr[$i]['date']), "yyyy-mm-dd HH:ii:ss", $GLOBALS['KT_screen_date_format'] . ' ' . $GLOBALS['KT_screen_time_format_internal']);
         }
         // create fake recordset
         $this->filesArr = $this->formatData($this->filesArr);
     }
     $KT_FakeRecordset = new KT_FakeRecordset($this->conn);
     $ret = $KT_FakeRecordset->getFakeRecordset($this->filesArr);
     if ($ret === NULL) {
         if (isset($GLOBALS['tNG_debug_mode']) && $GLOBALS['tNG_debug_mode'] == "DEVELOPMENT") {
             die("Internal error: cannot create fake recordset. " . $KT_FakeRecordset->getError());
         } else {
             die("Internal error: cannot create fake recordset.");
         }
     }
     return $ret;
 }
 /**
  * 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;
 }
Example #5
0
 /**
  * Setter. Sets the filename (could be a dynamic expression)
  * @param string filename
  * @return nothing
  * @access public
  */
 function setRenameRule($renameRule)
 {
     $renameRule = KT_TransformToUrlPath($renameRule, false);
     if ($this->renameRule == "") {
         $this->renameRule = $renameRule;
     } else {
         $this->renameRule .= $renameRule;
     }
 }