Esempio n. 1
0
/** 
 * Rename the folder for the multiple uploaded files/images on insert
 * Only for PRO version
 * @param object tNG transaction object
 * @param string reference for the key in session for the rename rule
 * @return mix null or error object
 * @access private
 */
function Trigger_MultipleUploadRename(&$tNG, $uploadObj)
{
    $reference = $uploadObj->reference;
    $ret = null;
    if (!isset($_SESSION['tng_upload'][$reference]) || count($_SESSION['tng_upload'][$reference]) == 0) {
        return $ret;
    }
    $pk = $tNG->getPrimaryKeyValue();
    // make the rename on insert
    if ($tNG->transactionType == '_insert') {
        $hash = $_SESSION['tng_upload'][$reference]['properties'];
        if (isset($tNG->multipleIdx) && $tNG->multipleIdx > 0) {
            $hashFile = $_SESSION['tng_upload'][$reference]['files'][$tNG->multipleIdx];
        } else {
            $hashFile = $_SESSION['tng_upload'][$reference]['files'][1];
        }
        if (isset($hash['pkRule']) && isset($hashFile['pk']) && isset($hash['folderRule'])) {
            $folderExistent = str_replace('{' . $hash['pkRule'] . '}', $hashFile['pk'], $hash['folderRule']);
            if (!file_exists($folderExistent)) {
                if (isset($tNG->multipleIdx) && $tNG->multipleIdx > 0) {
                    $_SESSION['tng_upload'][$reference]['files'][$tNG->multipleIdx] = null;
                } else {
                    $_SESSION['tng_upload'][$reference]['files'][1] = null;
                }
                return $ret;
            }
            $arr = explode('/', $folderExistent);
            if (substr($folderExistent, -1, 1) == '/' || substr($folderExistent, -1, 1) == '\\') {
                array_pop($arr);
            }
            $folderExistent = array_pop($arr);
            $folder = str_replace('{' . $hash['pkRule'] . '}', $pk, $hash['folderRule']);
            $arr = explode('/', $folder);
            if (substr($folder, -1, 1) == '/' || substr($folder, -1, 1) == '\\') {
                array_pop($arr);
            }
            $new = array_pop($arr);
            $f = implode('/', $arr) . '/';
            $fld = new KT_folder();
            $fld->renameFolder($f, $folderExistent, $new);
            if ($fld->hasError()) {
                $err = $fld->getError();
                return new tNG_error("%s", array($err[0]), array($err[1]));
            } else {
                if (isset($tNG->multipleIdx) && $tNG->multipleIdx > 0) {
                    $_SESSION['tng_upload'][$reference]['files'][$tNG->multipleIdx] = null;
                } else {
                    $_SESSION['tng_upload'][$reference]['files'][1] = null;
                }
            }
        }
    }
    // cleanup session on update;
    if ($tNG->transactionType == '_update') {
        if (isset($tNG->multipleIdx) && $tNG->multipleIdx > 0) {
            $_SESSION['tng_upload'][$reference]['files'][$tNG->multipleIdx] = null;
        } else {
            $_SESSION['tng_upload'][$reference]['files'][1] = null;
        }
    }
    return $ret;
}
Esempio n. 2
0
 /**
  * executes tidy and gets the value
  * @param string column name from transaction
  * @param string string to test
  * @return boolean true if tidy executed succesfully
  * @access private
  */
 function execTidy($colName, $value)
 {
     $arg_test = array('--version');
     if (isset($_SESSION['TidyContent']['ExecPath'])) {
         $loc = array($_SESSION['TidyContent']['ExecPath']);
     } else {
         $loc = $GLOBALS['TidyContent_TidyLocations'];
         if (isset($GLOBALS['KT_prefered_tidy_path'])) {
             array_unshift($loc, $GLOBALS['KT_prefered_tidy_path'] . 'tidy');
             array_unshift($loc, $GLOBALS['KT_prefered_tidy_path'] . 'tidy.exe');
         }
     }
     $shell = new KT_shell();
     $shell->execute($loc, $arg_test);
     if ($shell->hasError()) {
         $arr = $shell->getError();
         $this->setErrorMsg($arr[0], $arr[1]);
         return false;
     }
     $execPath = $shell->getExecutedCommand();
     if (!isset($_SESSION['TidyContent']['ExecPath']) && $execPath != '') {
         $_SESSION['TidyContent']['ExecPath'] = $execPath;
         $loc = array($execPath);
     }
     $tidyEncoding = 'raw';
     if (strtolower($this->outEncoding) == 'iso-8859-1') {
         $tidyEncoding = 'ascii';
     }
     if (strpos(strtolower($this->outEncoding), 'utf-8') !== false) {
         $tidyEncoding = 'utf8';
     }
     $string = $value;
     $string = str_replace(" ", " ", $string);
     $string = str_replace(" ", " ", $string);
     if (!file_exists($this->folderName)) {
         $folder = new KT_folder();
         $folder->createFolder($this->folderName);
         if ($folder->hasError()) {
             $arr = $folder->getError();
             $this->setErrorMsg($arr[0], $arr[1]);
             return false;
         }
     }
     $f = tempnam(substr($this->folderName, 0, -1), 'tidy');
     if ($f === false) {
         $err = KT_getResource('ERROR_TIDY_CONTENT', 'tNG', array());
         $this->setErrorMsg($err, $err);
         return false;
     }
     $fout = $f . '_out';
     $file = new KT_file();
     $file->writeFile($f, 'append', $string);
     if ($file->hasError()) {
         $arr = $file->getError();
         $this->setErrorMsg($arr[0], $arr[1]);
         return false;
     }
     $path = $GLOBALS['TidyContent_TidyConfiguration'];
     $arg = array("-config", $path, '-' . $tidyEncoding, "-o", $fout, $f);
     $shell = new KT_shell();
     $output = $shell->execute($loc, $arg);
     if ($shell->hasError() && !file_exists($fout)) {
         $arr = $shell->getError();
         $this->setErrorMsg($arr[0], $arr[1]);
         @unlink($f);
         @unlink($fout);
         return false;
     }
     $file = new KT_file();
     $content = $file->readFile($fout);
     if ($file->hasError()) {
         $arr = $file->getError();
         $this->setErrorMsg($arr[0], $arr[1]);
         @unlink($f);
         @unlink($fout);
         return false;
     }
     $file->deleteFile($f);
     if ($file->hasError()) {
         $arr = $file->getError();
         $this->setErrorMsg($arr[0], $arr[1]);
         @unlink($fout);
         return false;
     }
     $file->deleteFile($fout);
     if ($file->hasError()) {
         $arr = $file->getError();
         $this->setErrorMsg($arr[0], $arr[1]);
         return false;
     }
     $content = str_replace(" ", " ", $content);
     $content = str_replace(" ", " ", $content);
     $content = $this->cleanContent($content);
     $this->tidiedValues[$colName] = $content;
     return true;
 }
Esempio n. 3
0
 /**
  * Check if the uploaded folder exists and has write permissions.
  * If the folder does not exists, try to create it.
  * If the folder does not have write permissions or if could not create it, set error.
  * @return nothing;
  * @access public
  */
 function checkFolder()
 {
     if ($this->fileExists) {
         $folder = new KT_folder();
         $folder->createFolder($this->folder);
         $right = $folder->checkRights($this->folder, 'write');
         if ($folder->hasError()) {
             $arr = $folder->getError();
             $this->setError('PHP_UPLOAD_FOLDER_ERROR', array($arr[0]), array($arr[1]));
         }
         if ($right !== true) {
             $this->setError('PHP_UPLOAD_CHECK_FOLDER_ERROR', array(), array($this->folder));
         }
     }
 }
 /**
  * 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;
 }
Esempio n. 5
0
 /**
  * Check if the folder exists and has write permissions.
  * If the folder does not exists, try to create it.
  * If the folder does not have write permissions or if could not create it, set error.	
  * @param string $path the path
  * @param string $right the right to check
  * @param string $from  from what function is called
  * @return boolean true if is installed or false if not;
  * @access private
  */
 function checkFolder($path, $right, $from)
 {
     if (strtolower(substr(PHP_OS, 0, 1)) == 'w') {
         $path = str_replace('/', '\\', $path);
     }
     if (preg_match("/\\./ims", $path)) {
         $arr = split("[/\\]", $path);
         array_pop($arr);
         $path = implode(DIRECTORY_SEPARATOR, $arr);
     }
     if (is_file($path)) {
         $arr = explode(DIRECTORY_SEPARATOR, $path);
         array_pop($arr);
         $path = implode(DIRECTORY_SEPARATOR, $arr);
     }
     $folder = new KT_folder();
     $folder->createFolder($path);
     if ($right != '') {
         $res = $folder->checkRights($path, $right);
         if ($res !== true) {
             $this->setError('PHP_IMAGE_CHECK_FOLDER_ERROR', array($from), array($from, $path, $right));
         }
     }
     if ($folder->hasError()) {
         $arr = $folder->getError();
         $this->setError('PHP_IMAGE_FOLDER_ERROR', array($from, $arr[0]), array($from, $arr[1]));
     }
 }
Esempio n. 6
0
$folder = $uploadHashFile['folder'];
if (substr($folder, -1, 1) != '/' || substr($folder, -1, 1) != '\\') {
    $folder .= '/';
}
if ($uploadHash['relPath'] != '') {
    if (substr($folder, 0, strlen($uploadHash['relPath'])) == $uploadHash['relPath']) {
        $folder = substr($folder, strlen($uploadHash['relPath']));
    }
}
$folder = '../../../' . $folder;
// create the folder if not exists
if (!file_exists($folder)) {
    $folderObj = new KT_folder();
    $folderObj->createFolder($folder);
    if ($folderObj->hasError()) {
        $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']], '');
Esempio n. 7
0
 /**
  * verify the rights on the folder of the given file;
  * @param string $file the absolute path of the file to be checked;
  * @param string $mode the right to be checked: read/write:
  * @param string $from the function that needs the check;
  * @return nothing;
  * @access private
  */
 function checkFolder($file, $mode, $from)
 {
     $folderName = $this->getFolder($file);
     $folder = new KT_folder();
     $folder->createFolder($folderName);
     switch ($mode) {
         case 'read':
             $right = $folder->checkRights($folderName, 'read');
             break;
         case 'write':
         default:
             $right = $folder->checkRights($folderName, 'write');
             break;
     }
     if ($folder->hasError()) {
         $arr = $folder->getError();
         $this->setError('PHP_FILE_FOLDER_ERROR', array($from, $arr[0]), array($from, $arr[1]));
     }
     if ($right !== true) {
         $this->setError('PHP_FILE_CHECK_FOLDER_ERROR', array($from), array($from, $mode, $folderName));
     }
 }
Esempio n. 8
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;
 }