Пример #1
0
/**
 * Delete the thumbnails of an image.
 * @param string $folder absolute path of the folder which contains the image
 * @param string $file the image file name
 * @return nothing
 * @access public
 */
function GAL_deleteThumbnails($folder, $oldName)
{
    $thumbFolder = $folder . $GLOBALS['GAL_thumbnail_folder'];
    if ($oldName != '') {
        $path_info = KT_pathinfo($oldName);
        $regexp = '/' . preg_quote($path_info['filename'], '/') . '_\\d+x\\d+';
        if ($path_info['extension'] != "") {
            $regexp .= '\\.' . preg_quote($path_info['extension'], '/');
        }
        $regexp .= '/';
        $folderObj = new KT_folder();
        $entry = $folderObj->readFolder($thumbFolder, false);
        if (!$folderObj->hasError()) {
            foreach ($entry['files'] as $key => $fDetail) {
                if (preg_match($regexp, $fDetail['name'])) {
                    @unlink($thumbFolder . $fDetail['name']);
                }
            }
        }
        GAL_deleteImageInfo($folder, $oldName);
    }
}
Пример #2
0
 /**
  * garbage collector. remove from session entries older than 30 minutes;
  * @return string
  * @access public
  */
 function garbageCollector()
 {
     // cleanup orphan folders
     $arr = explode('/', $this->baseFolder . $this->folder);
     if (substr($this->folder, -1, 1) == '/' || substr($this->folder, -1, 1) == '\\') {
         array_pop($arr);
     }
     $new = array_pop($arr);
     $f = implode('/', $arr) . '/';
     $fld = new KT_folder();
     $arr = $fld->readFolder($f, false);
     //print_r($arr);
     if (isset($arr['folders']) && count($arr['folders'])) {
         foreach ($arr['folders'] as $entry) {
             if (preg_match("/^(.*)\\w{14}_\\w{8}(.*)/is", $entry['name'])) {
                 $fld = new KT_folder();
                 $files = $fld->readFolder($f . $entry['name']);
                 if (isset($files['files']) && count($files['files']) > 0) {
                     foreach ($files['files'] as $file) {
                         if (filectime($f . $entry['name'] . '/' . $file['name']) < time() - 60 * 30) {
                             $fld->deleteFolderNR($f . $entry['name']);
                             break;
                         }
                     }
                 } else {
                     $fld->deleteFolderNR($f . $entry['name']);
                 }
             }
         }
     }
     if (!isset($_SESSION['tng_upload'])) {
         return;
     }
     // clear old session values;
     foreach ($_SESSION['tng_upload'] as $id => $hash) {
         if (isset($hash['properties']) && $hash['properties']['time'] < time() - 60 * 30) {
             unset($_SESSION['tng_upload'][$id]);
         }
     }
 }
Пример #3
0
/**
 * Delete the thumbnails of an image.
 * @param string $folder absolute path of the folder which contains the image
 * @param string $file the image file name
 * @param string $md5 md5 string
 * @return nothing
 * @access public
 */
function tNG_deleteThumbnails($folder, $fileName, $md5)
{
    if ($fileName != '') {
        $path_info = KT_pathinfo($fileName);
        if ($md5 == '') {
            $regexp = '/^' . preg_quote($path_info['filename'], '/') . '_\\d+x\\d+(_w_(\\w+))?';
        } else {
            $regexp = '/^' . preg_quote($path_info['filename'], '/') . '(_w_(\\w+))?';
        }
        if ($path_info['extension'] != "") {
            $regexp .= '\\.' . preg_quote($path_info['extension'], '/');
        }
        $regexp .= '$/i';
        $folderObj = new KT_folder();
        $entry = $folderObj->readFolder($folder, false);
        if (!$folderObj->hasError()) {
            foreach ($entry['files'] as $key => $fDetail) {
                if (preg_match($regexp, $fDetail['name'], $matches)) {
                    if ($md5 != '') {
                        if (isset($matches[2]) && $matches[2] != $md5) {
                            @unlink($folder . $fDetail['name']);
                        }
                    } else {
                        @unlink($folder . $fDetail['name']);
                    }
                }
            }
        }
    }
}
 /**
  * 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;
 }
Пример #5
0
    $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']);
        $fileUpload->setAutoRename(true);
        $fileUpload->setMaxSize($uploadHash['maxSize']);
        $fileName = $fileUpload->uploadFile($_FILES['Filedata']['name'], '');
        if (!isset($_GET['isFlash']) && $fileUpload->hasError()) {
            $err = $fileUpload->getError();
        }
        if (isset($_GET['isFlash']) && $fileUpload->hasError()) {
            $err = $fileUpload->getError();
            !isset($_SESSION['tng_upload']['errorForFlash']) ? $_SESSION['tng_upload']['errorForFlash'] = '' : '';
Пример #6
0
 function getPhotoList()
 {
     if (!isset($this->config['photo_folder'])) {
         $arr = array('error' => 'Photo folder is not set. Please check to see if you have cookies enabled.');
         return $arr;
     }
     $folderName = KT_RealPath($this->config['photo_folder'], true);
     $thumb_path = $folderName . $GLOBALS['GAL_thumbnail_folder'];
     $folder = new KT_folder();
     $arr = $folder->readFolder($folderName, true);
     if ($folder->hasError()) {
         $errors = $folder->getError();
         $errorLevel = !empty($GLOBALS['tNG_debug_mode']) ? $GLOBALS['tNG_debug_mode'] == 'PRODUCTION' ? 0 : 1 : 1;
         $toret['error'] = $errors[$errorLevel];
         return $toret;
     }
     $ret = array();
     foreach ($arr['files'] as $key => $value) {
         $fullFileName = $folderName . $value['name'];
         $info = KT_pathinfo($fullFileName);
         if (GAL_isImage($fullFileName)) {
             $fullThumbnailName = $info['filename'] . '_' . $this->config['thumbnails']['width'] . 'x' . $this->config['thumbnails']['height'] . '.' . $info['extension'];
             $imageDetails = GAL_getImageInfo($folderName, $value['name']);
             clearstatcache();
             if ($imageDetails['dateLastModified'] != @filemtime($folderName . $value['name'])) {
                 GAL_deleteThumbnails($folderName, $value['name']);
                 GAL_getImageInfo($folderName, $value['name']);
             }
             # if this image has a thumbnail already.
             if (!file_exists($thumb_path . $fullThumbnailName)) {
                 $value['thumbnail'] = NULL;
             } else {
                 ob_start();
                 $thumbSizeArr = getimagesize($folderName . $GLOBALS['GAL_thumbnail_folder'] . $fullThumbnailName);
                 $error = ob_get_contents();
                 ob_end_clean();
                 if (is_array($thumbSizeArr)) {
                     $value['thumbnail'] = array('name' => $GLOBALS['GAL_thumbnail_folder'] . $fullThumbnailName, 'width' => $thumbSizeArr[0], 'height' => $thumbSizeArr[1]);
                 } else {
                     $value['thumbnail'] = array('error' => $error);
                 }
             }
             if (is_readable($fullFileName)) {
                 $imageSizeArr = getimagesize($fullFileName);
                 $value['width'] = $imageSizeArr[0];
                 $value['height'] = $imageSizeArr[1];
             } else {
                 $value['error'] = 'The ' . $fullFileName . ' is not readable';
             }
             $ret[] = $value;
         }
     }
     return $ret;
 }