/** * apply watermark on image; * Only for PRO version * @param string $sourceImage * @param string $destination * @param integer $watermarkAlpha * @param string $waterMarkImage; * @param array $watermarkResize; * @param array $watermarkAlignment horizontal, vertical; * @return nothing; * @access public */ function watermark($sourceImage, $destination, $watermarkImage, $watermarkAlpha, $watermarkResize, $watermarkAlignment) { $this->checkFolder($sourceImage, 'write', 'watermark'); $this->checkFolder($watermarkImage, 'read', 'watermark'); $watermarkAlpha = 100 - (int) $watermarkAlpha; if (!$this->is_readable($sourceImage)) { $this->setError('PHP_IMAGE_READ_ERR', array(), array($sourceImage)); } if (!$this->is_readable($watermarkImage)) { $this->setError('PHP_IMAGE_READ_ERR', array(), array($watermarkImage)); } $this->validateFile($watermarkImage, 'watermark'); $this->validateFile($sourceImage, 'watermark'); if ($this->hasError()) { return; } foreach ($this->orderLib as $key => $lib) { if (isset($GLOBALS['KT_prefered_image_lib']) && $GLOBALS['KT_prefered_image_lib'] != '' && $GLOBALS['KT_prefered_image_lib'] != $lib) { continue; } $lib = 'watermark_' . $lib; if ($rez = $this->{$lib}($sourceImage, $destination, $watermarkImage, $watermarkAlpha, $watermarkResize, $watermarkAlignment)) { KT_setFilePermissions($destination); break; } } if ($rez != true) { if ($GLOBALS['KT_prefered_image_lib'] == '') { $this->setError('WATERMARK_NO_LIB', array(), array($this->getGdNoSupport())); } else { $this->setError('WATERMARK_NO_LIB', array(), array($this->getLibraryError($GLOBALS['KT_prefered_image_lib']))); } } else { $this->setError('', array(), array()); } }
/** * Handle the uploaded file by moving it to a destination file. * The destination file = folder + fileName * @param string fileName the name for saving the uploaded file; * @param string $oldFileName the previous file name, or null on insert * @return string file name if succeded or null if not; * @access public */ function uploadFile($fileName, $oldFileName = "") { if ($this->hasError()) { return; } $this->checkUpload(); $this->checkFolder(); $this->checkSize(); $this->checkExtensions(); $this->checkFileName($fileName); if ($this->hasError()) { return; } if ($this->fileExists) { $folder = KT_realpath($this->folder); $fileName = KT_replaceSpecialChars($fileName, 'filter'); $destinationName = KT_realpath($folder . $fileName, false); if (file_exists($destinationName)) { if (strtolower($fileName) != strtolower($oldFileName)) { // if the destination file really exists if (!$this->autoRename) { $this->setError('UPLOAD_FILE_EXISTS', array(), array($fileName)); return; } else { $destinationName = $this->getTempName($destinationName); } } } if ($oldFileName != '') { @unlink($folder . DIRECTORY_SEPARATOR . $oldFileName); } if (!@move_uploaded_file($this->fileInfo['tmp_name'], $destinationName)) { unlink($this->fileInfo['tmp_name']); $this->setError('PHP_UPLOAD_MOVE_TMP_ERROR', array(), array()); return; } else { $arr = split("[\\/]", $destinationName); $this->destinationName = $destinationName; KT_setFilePermissions($this->destinationName); return array_pop($arr); } } }
/** * copy a folder * @param string $folder the path to the folder * @param string $parentFolder the parent of the copied folder * @return nothing * @access public */ function copyFolder($folder, $parentFolder) { $folder = $this->preparePath($folder); $folder = KT_realpath($folder); $parentFolder = $this->preparePath($parentFolder); $parentFolder = KT_realpath($parentFolder); if (!$this->checkRights($folder, 'read')) { $this->setError('PHP_FOLDER_COPY_RIGHTS', array(), array($folder)); return; } if (!$this->checkRights($parentFolder, 'write')) { $this->setError('PHP_FOLDER_COPY_RIGHTS', array(), array($parentFolder)); return; } $destFolder = $parentFolder . basename($folder); $this->createFolder($destFolder); if ($this->hasError()) { $err = $this->getError(); $this->setError('PHP_FOLDER_COPY', array(), array($destFolder, $err[1])); return; } $destFolder = KT_realpath($destFolder); $d = dir($folder); while (false !== ($entry = $d->read())) { if ($entry == '.' || $entry == '..') { continue; } if (is_dir($folder . $entry)) { $this->copyFolder($folder . $entry, $destFolder); } else { @copy($folder . $entry, $destFolder . $entry); KT_setFilePermissions($destFolder . $entry); } } $d->close(); }