Beispiel #1
0
 /**
  * Throw file upload error, return true if error has been thrown, false if error has been catched
  *
  * @param int $number
  * @param string $text
  * @access public
  */
 public function throwError($number, $uploaded = false, $exit = true)
 {
     if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
         return false;
     }
     $oRegistry =& QFinder_Connector_Core_Factory::getInstance("Core_Registry");
     $sFileName = $oRegistry->get("FileUpload_fileName");
     $sFileUrl = $oRegistry->get("FileUpload_url");
     $sEncodedFileName = QFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($sFileName);
     header('Content-Type: text/html; charset=utf-8');
     $errorMessage = QFinder_Connector_Utils_Misc::getErrorMessage($number, $sEncodedFileName);
     if (!$uploaded) {
         $sFileName = "";
         $sEncodedFileName = "";
     }
     if (!empty($_GET['response_type']) && $_GET['response_type'] == 'txt') {
         echo $sFileName . "|" . $errorMessage;
     } else {
         echo "<script type=\"text/javascript\">";
         if (!empty($_GET['QFinderFuncNum'])) {
             if (!$uploaded) {
                 $sFileUrl = "";
                 $sFileName = "";
             }
             $funcNum = preg_replace("/[^0-9]/", "", $_GET['QFinderFuncNum']);
             echo "window.parent.QFinder.tools.callFunction({$funcNum}, '" . str_replace("'", "\\'", $sFileUrl . $sFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "');";
         } else {
             echo "window.parent.OnUploadCompleted('" . str_replace("'", "\\'", $sEncodedFileName) . "', '" . str_replace("'", "\\'", $errorMessage) . "') ;";
         }
         echo "</script>";
     }
     if ($exit) {
         exit;
     }
 }
Beispiel #2
0
 /**
  * Get ResourceType configuration
  *
  * @param string $resourceTypeNode
  * @return array
  *
  */
 function __construct($resourceTypeNode)
 {
     if (isset($resourceTypeNode["name"])) {
         $this->_name = $resourceTypeNode["name"];
     }
     if (isset($resourceTypeNode["url"])) {
         $this->_url = $resourceTypeNode["url"];
     }
     if (!strlen($this->_url)) {
         $this->_url = "/";
     } else {
         if (substr($this->_url, -1, 1) != "/") {
             $this->_url .= "/";
         }
     }
     if (isset($resourceTypeNode["maxSize"])) {
         $this->_maxSize = QFinder_Connector_Utils_Misc::returnBytes((string) $resourceTypeNode["maxSize"]);
     }
     if (isset($resourceTypeNode["directory"])) {
         $this->_directory = $resourceTypeNode["directory"];
     }
     if (!strlen($this->_directory)) {
         $this->_directory = resolveUrl($this->_url);
     }
     if (isset($resourceTypeNode["allowedExtensions"])) {
         if (is_array($resourceTypeNode["allowedExtensions"])) {
             foreach ($resourceTypeNode["allowedExtensions"] as $e) {
                 $this->_allowedExtensions[] = strtolower(trim((string) $e));
             }
         } else {
             $resourceTypeNode["allowedExtensions"] = trim((string) $resourceTypeNode["allowedExtensions"]);
             if (strlen($resourceTypeNode["allowedExtensions"])) {
                 $extensions = explode(",", $resourceTypeNode["allowedExtensions"]);
                 foreach ($extensions as $e) {
                     $this->_allowedExtensions[] = strtolower(trim($e));
                 }
             }
         }
     }
     if (isset($resourceTypeNode["deniedExtensions"])) {
         if (is_array($resourceTypeNode["deniedExtensions"])) {
             foreach ($resourceTypeNode["deniedExtensions"] as $extension) {
                 $this->_deniedExtensions[] = strtolower(trim((string) $e));
             }
         } else {
             $resourceTypeNode["deniedExtensions"] = trim((string) $resourceTypeNode["deniedExtensions"]);
             if (strlen($resourceTypeNode["deniedExtensions"])) {
                 $extensions = explode(",", $resourceTypeNode["deniedExtensions"]);
                 foreach ($extensions as $e) {
                     $this->_deniedExtensions[] = strtolower(trim($e));
                 }
             }
         }
     }
 }
Beispiel #3
0
 function __construct($accessControlNodes)
 {
     foreach ($accessControlNodes as $node) {
         $_folderView = isset($node['folderView']) ? QFinder_Connector_Utils_Misc::booleanValue($node['folderView']) : false;
         $_folderCreate = isset($node['folderCreate']) ? QFinder_Connector_Utils_Misc::booleanValue($node['folderCreate']) : false;
         $_folderRename = isset($node['folderRename']) ? QFinder_Connector_Utils_Misc::booleanValue($node['folderRename']) : false;
         $_folderDelete = isset($node['folderDelete']) ? QFinder_Connector_Utils_Misc::booleanValue($node['folderDelete']) : false;
         $_fileView = isset($node['fileView']) ? QFinder_Connector_Utils_Misc::booleanValue($node['fileView']) : false;
         $_fileUpload = isset($node['fileUpload']) ? QFinder_Connector_Utils_Misc::booleanValue($node['fileUpload']) : false;
         $_fileRename = isset($node['fileRename']) ? QFinder_Connector_Utils_Misc::booleanValue($node['fileRename']) : false;
         $_fileDelete = isset($node['fileDelete']) ? QFinder_Connector_Utils_Misc::booleanValue($node['fileDelete']) : false;
         $_role = isset($node['role']) ? $node['role'] : "*";
         $_resourceType = isset($node['resourceType']) ? $node['resourceType'] : "*";
         $_folder = isset($node['folder']) ? $node['folder'] : "/";
         $this->addACLEntry($_role, $_resourceType, $_folder, array($_folderView ? QFINDER_CONNECTOR_ACL_FOLDER_VIEW : 0, $_folderCreate ? QFINDER_CONNECTOR_ACL_FOLDER_CREATE : 0, $_folderRename ? QFINDER_CONNECTOR_ACL_FOLDER_RENAME : 0, $_folderDelete ? QFINDER_CONNECTOR_ACL_FOLDER_DELETE : 0, $_fileView ? QFINDER_CONNECTOR_ACL_FILE_VIEW : 0, $_fileUpload ? QFINDER_CONNECTOR_ACL_FILE_UPLOAD : 0, $_fileRename ? QFINDER_CONNECTOR_ACL_FILE_RENAME : 0, $_fileDelete ? QFINDER_CONNECTOR_ACL_FILE_DELETE : 0), array($_folderView ? 0 : QFINDER_CONNECTOR_ACL_FOLDER_VIEW, $_folderCreate ? 0 : QFINDER_CONNECTOR_ACL_FOLDER_CREATE, $_folderRename ? 0 : QFINDER_CONNECTOR_ACL_FOLDER_RENAME, $_folderDelete ? 0 : QFINDER_CONNECTOR_ACL_FOLDER_DELETE, $_fileView ? 0 : QFINDER_CONNECTOR_ACL_FILE_VIEW, $_fileUpload ? 0 : QFINDER_CONNECTOR_ACL_FILE_UPLOAD, $_fileRename ? 0 : QFINDER_CONNECTOR_ACL_FILE_RENAME, $_fileDelete ? 0 : QFINDER_CONNECTOR_ACL_FILE_DELETE));
     }
 }
Beispiel #4
0
 function __construct($thumbnailsNode)
 {
     if (extension_loaded('gd') && isset($thumbnailsNode['enabled'])) {
         $this->_isEnabled = QFinder_Connector_Utils_Misc::booleanValue($thumbnailsNode['enabled']);
     }
     if (isset($thumbnailsNode['directAccess'])) {
         $this->_directAccess = QFinder_Connector_Utils_Misc::booleanValue($thumbnailsNode['directAccess']);
     }
     if (isset($thumbnailsNode['bmpSupported'])) {
         $this->_bmpSupported = QFinder_Connector_Utils_Misc::booleanValue($thumbnailsNode['bmpSupported']);
     }
     if (isset($thumbnailsNode['maxWidth'])) {
         $_maxWidth = intval($thumbnailsNode['maxWidth']);
         if ($_maxWidth >= 0) {
             $this->_maxWidth = $_maxWidth;
         }
     }
     if (isset($thumbnailsNode['maxHeight'])) {
         $_maxHeight = intval($thumbnailsNode['maxHeight']);
         if ($_maxHeight >= 0) {
             $this->_maxHeight = $_maxHeight;
         }
     }
     if (isset($thumbnailsNode['quality'])) {
         $_quality = intval($thumbnailsNode['quality']);
         if ($_quality > 0 && $_quality <= 100) {
             $this->_quality = $_quality;
         }
     }
     if (isset($thumbnailsNode['url'])) {
         $this->_url = $thumbnailsNode['url'];
     }
     if (!strlen($this->_url)) {
         $this->_url = "/";
     } else {
         if (substr($this->_url, -1, 1) != "/") {
             $this->_url .= "/";
         }
     }
     if (isset($thumbnailsNode['directory'])) {
         $this->_directory = $thumbnailsNode['directory'];
     }
 }
Beispiel #5
0
 /**
  * Throw file upload error, return true if error has been thrown, false if error has been catched
  *
  * @param int $number
  * @param string $text
  * @access public
  */
 public function throwError($number, $uploaded = false, $exit = true)
 {
     if ($this->_catchAllErrors || in_array($number, $this->_skipErrorsArray)) {
         return false;
     }
     $oRegistry =& QFinder_Connector_Core_Factory::getInstance("Core_Registry");
     $sFileName = $oRegistry->get("FileUpload_fileName");
     $sFileUrl = $oRegistry->get("FileUpload_url");
     $sEncodedFileName = QFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($sFileName);
     header('Content-Type: text/html; charset=utf-8');
     /**
      * echo <script> is not called before QFinder_Connector_Utils_Misc::getErrorMessage
      * because PHP has problems with including files that contain BOM character.
      * Having BOM character after <script> tag causes a javascript error.
      */
     echo "<script type=\"text/javascript\">";
     if (!empty($_GET['CKEditor'])) {
         $errorMessage = QFinder_Connector_Utils_Misc::getErrorMessage($number, $sEncodedFileName);
         if (!$uploaded) {
             $sFileUrl = "";
             $sFileName = "";
             $sEncodedFileName = "";
         }
         $funcNum = preg_replace("/[^0-9]/", "", $_GET['CKEditorFuncNum']);
         echo "window.parent.CKEDITOR.tools.callFunction({$funcNum}, '" . str_replace("'", "\\'", $sFileUrl . QFinder_Connector_Utils_Misc::encodeURIComponent($sEncodedFileName)) . "', '" . str_replace("'", "\\'", $errorMessage) . "');";
     } else {
         if (!$uploaded) {
             echo "window.parent.OnUploadCompleted(" . $number . ", '', '', '') ;";
         } else {
             echo "window.parent.OnUploadCompleted(" . $number . ", '" . str_replace("'", "\\'", $sFileUrl . QFinder_Connector_Utils_Misc::encodeURIComponent($sEncodedFileName)) . "', '" . str_replace("'", "\\'", $sEncodedFileName) . "', '') ;";
         }
     }
     echo "</script>";
     if ($exit) {
         exit;
     }
 }
Beispiel #6
0
 /**
  * handle request and build XML
  * @access protected
  *
  */
 protected function buildXml()
 {
     $_config =& QFinder_Connector_Core_Factory::getInstance("Core_Config");
     if (!$this->_currentFolder->checkAcl(QFINDER_CONNECTOR_ACL_FILE_VIEW)) {
         $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
     }
     // Map the virtual path to the local server path.
     $_sServerDir = $this->_currentFolder->getServerPath();
     // Create the "Files" node.
     $oFilesNode = new Qfinder_Connector_Utils_XmlNode("Files");
     $this->_connectorNode->addChild($oFilesNode);
     if (!is_dir($_sServerDir)) {
         $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_FOLDER_NOT_FOUND);
     }
     $files = array();
     $thumbFiles = array();
     if ($dh = @opendir($_sServerDir)) {
         while (($file = readdir($dh)) !== false) {
             if ($file != "." && $file != ".." && !is_dir($_sServerDir . $file)) {
                 $files[] = $file;
             }
         }
         closedir($dh);
     } else {
         $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
     }
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     if (sizeof($files) > 0) {
         $_thumbnailsConfig = $_config->getThumbnailsConfig();
         $_thumbServerPath = '';
         $_showThumbs = !empty($_GET['showThumbs']) && $_GET['showThumbs'] == 1;
         if ($_thumbnailsConfig->getIsEnabled() && ($_thumbnailsConfig->getDirectAccess() || $_showThumbs)) {
             $_thumbServerPath = $this->_currentFolder->getThumbsServerPath();
         }
         natcasesort($files);
         $i = 0;
         foreach ($files as $file) {
             $filemtime = @filemtime($_sServerDir . $file);
             //otherwise file doesn't exist or we can't get it's filename properly
             if ($filemtime !== false) {
                 $filename = QFinder_Connector_Utils_Misc::mbBasename($file);
                 if (!$resourceTypeInfo->checkExtension($filename, false)) {
                     continue;
                 }
                 if ($resourceTypeInfo->checkIsHiddenFile($filename)) {
                     continue;
                 }
                 $oFileNode[$i] = new Qfinder_Connector_Utils_XmlNode("File");
                 $oFilesNode->addChild($oFileNode[$i]);
                 $oFileNode[$i]->addAttribute("name", QFinder_Connector_Utils_FileSystem::convertToConnectorEncoding(QFinder_Connector_Utils_Misc::mbBasename($file)));
                 $oFileNode[$i]->addAttribute("date", @date("YmdHi", $filemtime));
                 if (!empty($_thumbServerPath) && preg_match(QFINDER_REGEX_IMAGES_EXT, $filename)) {
                     if (file_exists($_thumbServerPath . $filename)) {
                         $oFileNode[$i]->addAttribute("thumb", $filename);
                     } elseif ($_showThumbs) {
                         $oFileNode[$i]->addAttribute("thumb", "?" . $filename);
                     }
                 }
                 $size = filesize($_sServerDir . $file);
                 if ($size && $size < 1024) {
                     $size = 1;
                 } else {
                     $size = (int) round($size / 1024);
                 }
                 $oFileNode[$i]->addAttribute("size", $size);
                 $i++;
             }
         }
     }
 }
Beispiel #7
0
 /**
  * @link http://pl.php.net/manual/pl/function.imagecreatefromjpeg.php
  * function posted by e dot a dot schultz at gmail dot com
  *
  * @static
  * @access public
  * @param string $filename
  * @return boolean
  */
 public static function setMemoryForImage($imageWidth, $imageHeight, $imageBits, $imageChannels)
 {
     $MB = 1048576;
     // number of bytes in 1M
     $K64 = 65536;
     // number of bytes in 64K
     $TWEAKFACTOR = 2.4;
     // Or whatever works for you
     $memoryNeeded = round(($imageWidth * $imageHeight * $imageBits * $imageChannels / 8 + $K64) * $TWEAKFACTOR) + 3 * $MB;
     //ini_get('memory_limit') only works if compiled with "--enable-memory-limit" also
     //Default memory limit is 8MB so well stick with that.
     //To find out what yours is, view your php.ini file.
     $memoryLimit = QFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit')) / $MB;
     // There are no memory limits, nothing to do
     if ($memoryLimit == -1) {
         return true;
     }
     if (!$memoryLimit) {
         $memoryLimit = 8;
     }
     $memoryLimitMB = $memoryLimit * $MB;
     if (function_exists('memory_get_usage')) {
         if (memory_get_usage() + $memoryNeeded > $memoryLimitMB) {
             $newLimit = $memoryLimit + ceil((memory_get_usage() + $memoryNeeded - $memoryLimitMB) / $MB);
             if (@ini_set('memory_limit', $newLimit . 'M') === false) {
                 return false;
             }
         }
     } else {
         if ($memoryNeeded + 3 * $MB > $memoryLimitMB) {
             $newLimit = $memoryLimit + ceil((3 * $MB + $memoryNeeded - $memoryLimitMB) / $MB);
             if (false === @ini_set('memory_limit', $newLimit . 'M')) {
                 return false;
             }
         }
     }
     return true;
 }
Beispiel #8
0
 /**
  * send response (save uploaded file, resize if required)
  * @access public
  *
  */
 public function sendResponse()
 {
     $iErrorNumber = QFINDER_CONNECTOR_ERROR_NONE;
     $_config =& QFinder_Connector_Core_Factory::getInstance("Core_Config");
     $oRegistry =& QFinder_Connector_Core_Factory::getInstance("Core_Registry");
     $oRegistry->set("FileUpload_fileName", "unknown file");
     $uploadedFile = array_shift($_FILES);
     if (!isset($uploadedFile['name'])) {
         $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_UPLOADED_INVALID);
     }
     $sUnsafeFileName = QFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding(QFinder_Connector_Utils_Misc::mbBasename($uploadedFile['name']));
     $sFileName = QFinder_Connector_Utils_FileSystem::secureFileName($sUnsafeFileName);
     if ($sFileName != $sUnsafeFileName) {
         $iErrorNumber = QFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED;
     }
     $oRegistry->set("FileUpload_fileName", $sFileName);
     $this->checkConnector();
     $this->checkRequest();
     if (!$this->_currentFolder->checkAcl(QFINDER_CONNECTOR_ACL_FILE_UPLOAD)) {
         $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
     }
     $_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
     if (!QFinder_Connector_Utils_FileSystem::checkFileName($sFileName) || $_resourceTypeConfig->checkIsHiddenFile($sFileName)) {
         $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_INVALID_NAME);
     }
     $resourceTypeInfo = $this->_currentFolder->getResourceTypeConfig();
     if (!$resourceTypeInfo->checkExtension($sFileName)) {
         $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_INVALID_EXTENSION);
     }
     $oRegistry->set("FileUpload_fileName", $sFileName);
     $oRegistry->set("FileUpload_url", $this->_currentFolder->getUrl());
     $maxSize = $resourceTypeInfo->getMaxSize();
     if (!$_config->checkSizeAfterScaling() && $maxSize && $uploadedFile['size'] > $maxSize) {
         $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
     }
     $htmlExtensions = $_config->getHtmlExtensions();
     $sExtension = QFinder_Connector_Utils_FileSystem::getExtension($sFileName);
     if ($htmlExtensions && !QFinder_Connector_Utils_Misc::inArrayCaseInsensitive($sExtension, $htmlExtensions) && ($detectHtml = QFinder_Connector_Utils_FileSystem::detectHtml($uploadedFile['tmp_name'])) === true) {
         $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
     }
     $secureImageUploads = $_config->getSecureImageUploads();
     if ($secureImageUploads && ($isImageValid = QFinder_Connector_Utils_FileSystem::isImageValid($uploadedFile['tmp_name'], $sExtension)) === false) {
         $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
     }
     switch ($uploadedFile['error']) {
         case UPLOAD_ERR_OK:
             break;
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
             break;
         case UPLOAD_ERR_PARTIAL:
         case UPLOAD_ERR_NO_FILE:
             $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
             break;
         case UPLOAD_ERR_NO_TMP_DIR:
             $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_UPLOADED_NO_TMP_DIR);
             break;
         case UPLOAD_ERR_CANT_WRITE:
             $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
             break;
         case UPLOAD_ERR_EXTENSION:
             $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
             break;
     }
     $sServerDir = $this->_currentFolder->getServerPath();
     while (true) {
         $sFilePath = QFinder_Connector_Utils_FileSystem::combinePaths($sServerDir, $sFileName);
         if (file_exists($sFilePath)) {
             $sFileName = QFinder_Connector_Utils_FileSystem::autoRename($sServerDir, $sFileName);
             $oRegistry->set("FileUpload_fileName", $sFileName);
             $iErrorNumber = QFINDER_CONNECTOR_ERROR_UPLOADED_FILE_RENAMED;
         } else {
             if (false === move_uploaded_file($uploadedFile['tmp_name'], $sFilePath)) {
                 $iErrorNumber = QFINDER_CONNECTOR_ERROR_ACCESS_DENIED;
             } else {
                 if (isset($detectHtml) && $detectHtml === -1 && QFinder_Connector_Utils_FileSystem::detectHtml($sFilePath) === true) {
                     @unlink($sFilePath);
                     $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_UPLOADED_WRONG_HTML_FILE);
                 } else {
                     if (isset($isImageValid) && $isImageValid === -1 && QFinder_Connector_Utils_FileSystem::isImageValid($sFilePath, $sExtension) === false) {
                         @unlink($sFilePath);
                         $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_UPLOADED_CORRUPT);
                     }
                 }
             }
             if (is_file($sFilePath) && ($perms = $_config->getChmodFiles())) {
                 $oldumask = umask(0);
                 chmod($sFilePath, $perms);
                 umask($oldumask);
             }
             break;
         }
     }
     if (!$_config->checkSizeAfterScaling()) {
         $this->_errorHandler->throwError($iErrorNumber, true, false);
     }
     //resize image if required
     require_once QFINDER_CONNECTOR_LIB_DIR . "/CommandHandler/Thumbnail.php";
     $_imagesConfig = $_config->getImagesConfig();
     if ($_imagesConfig->getMaxWidth() > 0 && $_imagesConfig->getMaxHeight() > 0 && $_imagesConfig->getQuality() > 0) {
         QFinder_Connector_CommandHandler_Thumbnail::createThumb($sFilePath, $sFilePath, $_imagesConfig->getMaxWidth(), $_imagesConfig->getMaxHeight(), $_imagesConfig->getQuality(), true);
     }
     if ($_config->checkSizeAfterScaling()) {
         //check file size after scaling, attempt to delete if too big
         clearstatcache();
         if ($maxSize && filesize($sFilePath) > $maxSize) {
             @unlink($sFilePath);
             $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_UPLOADED_TOO_BIG);
         } else {
             $this->_errorHandler->throwError($iErrorNumber, true, false);
         }
     }
     QFinder_Connector_Core_Hooks::run('AfterFileUpload', array(&$this->_currentFolder, &$uploadedFile, &$sFilePath));
 }
Beispiel #9
0
 /**
  * handle request and build XML
  * @access protected
  *
  */
 protected function buildXml()
 {
     $_config =& QFinder_Connector_Core_Factory::getInstance("Core_Config");
     // Create the "ConnectorInfo" node.
     $_oConnInfo = new Qfinder_Connector_Utils_XmlNode("ConnectorInfo");
     $this->_connectorNode->addChild($_oConnInfo);
     $_oConnInfo->addAttribute("enabled", $_config->getIsEnabled() ? "true" : "false");
     if (!$_config->getIsEnabled()) {
         $this->_errorHandler->throwError(QFINDER_CONNECTOR_ERROR_CONNECTOR_DISABLED);
     }
     $_ln = '';
     $_lc = $_config->getLicenseKey() . '                                  ';
     $pos = strpos(QFINDER_CHARS, $_lc[0]) % 5;
     if ($pos == 1 || $pos == 4) {
         $_ln = $_config->getLicenseName();
     }
     $_oConnInfo->addAttribute("s", $_ln);
     $_oConnInfo->addAttribute("c", trim($_lc[11] . $_lc[0] . $_lc[8] . $_lc[12] . $_lc[26] . $_lc[2] . $_lc[3] . $_lc[25] . $_lc[1]));
     $_thumbnailsConfig = $_config->getThumbnailsConfig();
     $_thumbnailsEnabled = $_thumbnailsConfig->getIsEnabled();
     $_oConnInfo->addAttribute("thumbsEnabled", $_thumbnailsEnabled ? "true" : "false");
     if ($_thumbnailsEnabled) {
         $_oConnInfo->addAttribute("thumbsUrl", $_thumbnailsConfig->getUrl());
         $_oConnInfo->addAttribute("thumbsDirectAccess", $_thumbnailsConfig->getDirectAccess() ? "true" : "false");
         $_oConnInfo->addAttribute("thumbsWidth", $_thumbnailsConfig->getMaxWidth());
         $_oConnInfo->addAttribute("thumbsHeight", $_thumbnailsConfig->getMaxHeight());
     }
     $_imagesConfig = $_config->getImagesConfig();
     $_oConnInfo->addAttribute("imgWidth", $_imagesConfig->getMaxWidth());
     $_oConnInfo->addAttribute("imgHeight", $_imagesConfig->getMaxHeight());
     // Create the "ResourceTypes" node.
     $_oResourceTypes = new Qfinder_Connector_Utils_XmlNode("ResourceTypes");
     $this->_connectorNode->addChild($_oResourceTypes);
     // Create the "PluginsInfo" node.
     $_oPluginsInfo = new Qfinder_Connector_Utils_XmlNode("PluginsInfo");
     $this->_connectorNode->addChild($_oPluginsInfo);
     // Load the resource types in an array.
     $_aTypes = $_config->getDefaultResourceTypes();
     if (!sizeof($_aTypes)) {
         $_aTypes = $_config->getResourceTypeNames();
     }
     $_aTypesSize = sizeof($_aTypes);
     if ($_aTypesSize) {
         $phpMaxSize = 0;
         $max_upload = QFinder_Connector_Utils_Misc::returnBytes(ini_get('upload_max_filesize'));
         if ($max_upload) {
             $phpMaxSize = $max_upload;
         }
         $max_post = QFinder_Connector_Utils_Misc::returnBytes(ini_get('post_max_size'));
         if ($max_post) {
             $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $max_post) : $max_post;
         }
         //ini_get('memory_limit') only works if compiled with "--enable-memory-limit"
         $memory_limit = QFinder_Connector_Utils_Misc::returnBytes(@ini_get('memory_limit'));
         if ($memory_limit && $memory_limit != -1) {
             $phpMaxSize = $phpMaxSize ? min($phpMaxSize, $memory_limit) : $memory_limit;
         }
         $_oConnInfo->addAttribute("uploadMaxSize", $phpMaxSize);
         $_oConnInfo->addAttribute("uploadCheckImages", $_config->checkSizeAfterScaling() ? "false" : "true");
         for ($i = 0; $i < $_aTypesSize; $i++) {
             $_resourceTypeName = $_aTypes[$i];
             $_acl = $_config->getAccessControlConfig();
             $_aclMask = $_acl->getComputedMask($_resourceTypeName, "/");
             if (($_aclMask & QFINDER_CONNECTOR_ACL_FOLDER_VIEW) != QFINDER_CONNECTOR_ACL_FOLDER_VIEW) {
                 continue;
             }
             if (!isset($_GET['type']) || $_GET['type'] === $_resourceTypeName) {
                 //print $_resourceTypeName;
                 $_oTypeInfo = $_config->getResourceTypeConfig($_resourceTypeName);
                 //print_r($_oTypeInfo);
                 $_oResourceType[$i] = new Qfinder_Connector_Utils_XmlNode("ResourceType");
                 $_oResourceTypes->addChild($_oResourceType[$i]);
                 $_oResourceType[$i]->addAttribute("name", $_resourceTypeName);
                 $_oResourceType[$i]->addAttribute("url", $_oTypeInfo->getUrl());
                 $_oResourceType[$i]->addAttribute("allowedExtensions", implode(",", $_oTypeInfo->getAllowedExtensions()));
                 $_oResourceType[$i]->addAttribute("deniedExtensions", implode(",", $_oTypeInfo->getDeniedExtensions()));
                 $_oResourceType[$i]->addAttribute("hash", $_oTypeInfo->getHash());
                 $_oResourceType[$i]->addAttribute("hasChildren", QFinder_Connector_Utils_FileSystem::hasChildren('/', $_oTypeInfo) ? "true" : "false");
                 $_oResourceType[$i]->addAttribute("acl", $_aclMask);
                 $maxSize = $_oTypeInfo->getMaxSize();
                 if ($phpMaxSize) {
                     $maxSize = $maxSize ? min($maxSize, $phpMaxSize) : $phpMaxSize;
                 }
                 $_oResourceType[$i]->addAttribute("maxSize", $maxSize);
             }
         }
     }
     $config = $GLOBALS['config'];
     if (!empty($config['Plugins']) && is_array($config['Plugins'])) {
         $_oConnInfo->addAttribute("plugins", implode(",", $config['Plugins']));
     }
     QFinder_Connector_Core_Hooks::run('InitCommand', array(&$this->_connectorNode));
 }
Beispiel #10
0
 /**
  * Create thumbnail
  *
  * @param string $sourceFile
  * @param string $targetFile
  * @param int $maxWidth
  * @param int $maxHeight
  * @param boolean $preserverAspectRatio
  * @param boolean $bmpSupported
  * @return boolean
  * @static
  * @access public
  */
 public static function createThumb($sourceFile, $targetFile, $maxWidth, $maxHeight, $quality, $preserverAspectRatio, $bmpSupported = false)
 {
     $sourceImageAttr = @getimagesize($sourceFile);
     if ($sourceImageAttr === false) {
         return false;
     }
     $sourceImageWidth = isset($sourceImageAttr[0]) ? $sourceImageAttr[0] : 0;
     $sourceImageHeight = isset($sourceImageAttr[1]) ? $sourceImageAttr[1] : 0;
     $sourceImageMime = isset($sourceImageAttr["mime"]) ? $sourceImageAttr["mime"] : "";
     $sourceImageBits = isset($sourceImageAttr["bits"]) ? $sourceImageAttr["bits"] : 8;
     $sourceImageChannels = isset($sourceImageAttr["channels"]) ? $sourceImageAttr["channels"] : 3;
     if (!$sourceImageWidth || !$sourceImageHeight || !$sourceImageMime) {
         return false;
     }
     $iFinalWidth = $maxWidth == 0 ? $sourceImageWidth : $maxWidth;
     $iFinalHeight = $maxHeight == 0 ? $sourceImageHeight : $maxHeight;
     if ($sourceImageWidth <= $iFinalWidth && $sourceImageHeight <= $iFinalHeight) {
         if ($sourceFile != $targetFile) {
             copy($sourceFile, $targetFile);
         }
         return true;
     }
     if ($preserverAspectRatio) {
         // Gets the best size for aspect ratio resampling
         $oSize = QFinder_Connector_CommandHandler_Thumbnail::GetAspectRatioSize($iFinalWidth, $iFinalHeight, $sourceImageWidth, $sourceImageHeight);
     } else {
         $oSize = array('Width' => $iFinalWidth, 'Height' => $iFinalHeight);
     }
     QFinder_Connector_Utils_Misc::setMemoryForImage($sourceImageWidth, $sourceImageHeight, $sourceImageBits, $sourceImageChannels);
     switch ($sourceImageAttr['mime']) {
         case 'image/gif':
             if (@imagetypes() & IMG_GIF) {
                 $oImage = @imagecreatefromgif($sourceFile);
             } else {
                 $ermsg = 'GIF images are not supported';
             }
             break;
         case 'image/jpeg':
             if (@imagetypes() & IMG_JPG) {
                 $oImage = @imagecreatefromjpeg($sourceFile);
             } else {
                 $ermsg = 'JPEG images are not supported';
             }
             break;
         case 'image/png':
             if (@imagetypes() & IMG_PNG) {
                 $oImage = @imagecreatefrompng($sourceFile);
             } else {
                 $ermsg = 'PNG images are not supported';
             }
             break;
         case 'image/wbmp':
             if (@imagetypes() & IMG_WBMP) {
                 $oImage = @imagecreatefromwbmp($sourceFile);
             } else {
                 $ermsg = 'WBMP images are not supported';
             }
             break;
         case 'image/bmp':
             /*
              * This is sad that PHP doesn't support bitmaps.
              * Anyway, we will use our custom function at least to display thumbnails.
              * We'll not resize images this way (if $sourceFile === $targetFile),
              * because user defined imagecreatefrombmp and imagecreatebmp are horribly slow
              */
             if ($bmpSupported && @imagetypes() & IMG_JPG && $sourceFile != $targetFile) {
                 $oImage = QFinder_Connector_Utils_Misc::imageCreateFromBmp($sourceFile);
             } else {
                 $ermsg = 'BMP/JPG images are not supported';
             }
             break;
         default:
             $ermsg = $sourceImageAttr['mime'] . ' images are not supported';
             break;
     }
     if (isset($ermsg) || false === $oImage) {
         return false;
     }
     $oThumbImage = imagecreatetruecolor($oSize["Width"], $oSize["Height"]);
     if ($sourceImageAttr['mime'] == 'image/png') {
         $bg = imagecolorallocatealpha($oThumbImage, 255, 255, 255, 127);
         // (PHP 4 >= 4.3.2, PHP 5)
         imagefill($oThumbImage, 0, 0, $bg);
         imagealphablending($oThumbImage, false);
         imagesavealpha($oThumbImage, true);
     }
     //imagecopyresampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight);
     QFinder_Connector_Utils_Misc::fastImageCopyResampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight, (int) max(floor($quality / 20), 6));
     switch ($sourceImageAttr['mime']) {
         case 'image/gif':
             imagegif($oThumbImage, $targetFile);
             break;
         case 'image/jpeg':
         case 'image/bmp':
             imagejpeg($oThumbImage, $targetFile, $quality);
             break;
         case 'image/png':
             imagepng($oThumbImage, $targetFile);
             break;
         case 'image/wbmp':
             imagewbmp($oThumbImage, $targetFile);
             break;
     }
     $_config =& QFinder_Connector_Core_Factory::getInstance("Core_Config");
     if (file_exists($targetFile) && ($perms = $_config->getChmodFiles())) {
         $oldUmask = umask(0);
         chmod($targetFile, $perms);
         umask($oldUmask);
     }
     imageDestroy($oImage);
     imageDestroy($oThumbImage);
     return true;
 }
Beispiel #11
0
 /**
  * Checks whether the string is valid UTF8
  * @param string $string
  */
 public function asUTF8($string)
 {
     if (QFinder_Connector_Utils_Misc::isValidUTF8($string)) {
         return $string;
     }
     $ret = "";
     for ($i = 0; $i < strlen($string); $i++) {
         $ret .= QFinder_Connector_Utils_Misc::isValidUTF8($string[$i]) ? $string[$i] : "�";
     }
     return $ret;
 }
Beispiel #12
0
 /**
  * Load values from config
  *
  * @access private
  */
 private function loadValues()
 {
     if (function_exists('CheckAuthentication')) {
         $this->_isEnabled = CheckAuthentication();
     }
     if (isset($GLOBALS['config']['LicenseName'])) {
         $this->_licenseName = (string) $GLOBALS['config']['LicenseName'];
     }
     if (isset($GLOBALS['config']['LicenseKey'])) {
         $this->_licenseKey = (string) $GLOBALS['config']['LicenseKey'];
     }
     if (isset($GLOBALS['config']['FilesystemEncoding'])) {
         $this->_filesystemEncoding = (string) $GLOBALS['config']['FilesystemEncoding'];
     }
     if (isset($GLOBALS['config']['RoleSessionVar'])) {
         $this->_roleSessionVar = (string) $GLOBALS['config']['RoleSessionVar'];
     }
     if (isset($GLOBALS['config']['CheckDoubleExtension'])) {
         $this->_checkDoubleExtension = QFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckDoubleExtension']);
     }
     if (isset($GLOBALS['config']['DisallowUnsafeCharacters'])) {
         $this->_disallowUnsafeCharacters = QFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['DisallowUnsafeCharacters']);
     }
     if (isset($GLOBALS['config']['SecureImageUploads'])) {
         $this->_secureImageUploads = QFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['SecureImageUploads']);
     }
     if (isset($GLOBALS['config']['CheckSizeAfterScaling'])) {
         $this->_checkSizeAfterScaling = QFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['CheckSizeAfterScaling']);
     }
     if (isset($GLOBALS['config']['ForceAscii'])) {
         $this->_forceAscii = QFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['ForceAscii']);
     }
     if (isset($GLOBALS['config']['HtmlExtensions'])) {
         $this->_htmlExtensions = (array) $GLOBALS['config']['HtmlExtensions'];
     }
     if (isset($GLOBALS['config']['HideFolders'])) {
         $this->_hideFolders = (array) $GLOBALS['config']['HideFolders'];
     }
     if (isset($GLOBALS['config']['HideFiles'])) {
         $this->_hideFiles = (array) $GLOBALS['config']['HideFiles'];
     }
     if (isset($GLOBALS['config']['ChmodFiles'])) {
         $this->_chmodFiles = $GLOBALS['config']['ChmodFiles'];
     }
     if (isset($GLOBALS['config']['ChmodFolders'])) {
         $this->_chmodFolders = $GLOBALS['config']['ChmodFolders'];
     }
     if (isset($GLOBALS['config']['DefaultResourceTypes'])) {
         $_defaultResourceTypes = (string) $GLOBALS['config']['DefaultResourceTypes'];
         if (strlen($_defaultResourceTypes)) {
             $this->_defaultResourceTypes = explode(",", $_defaultResourceTypes);
         }
     }
     if (isset($GLOBALS['config']['TempDirectory'])) {
         $this->_tempDirectory = $GLOBALS['config']['TempDirectory'];
     }
     if (isset($GLOBALS['config']['XSendfile'])) {
         $this->_xsendfile = QFinder_Connector_Utils_Misc::booleanValue($GLOBALS['config']['XSendfile']);
     }
     if (isset($GLOBALS['config']['XSendfileNginx'])) {
         $this->_xsendfileNginx = (array) $GLOBALS['config']['XSendfileNginx'];
     }
 }
Beispiel #13
0
 /**
  * Get private zip plugin config
  *
  * @access protected
  * @return array
  */
 protected function getConfig()
 {
     $config = array();
     $config['zipMaxSize'] = 'default';
     if (isset($GLOBALS['config']['ZipMaxSize']) && (string) $GLOBALS['config']['ZipMaxSize'] != 'default') {
         $config['zipMaxSize'] = QFinder_Connector_Utils_Misc::returnBytes((string) $GLOBALS['config']['ZipMaxSize']);
     }
     return $config;
 }