public function Format($row, $fieldname, $value) { $files = $this->_context->getUploadFileNames(); if ($files[$fieldname] != "") { $fileProcessor = new UploadFilenameProcessor($this->_saveAs); $fileProcessor->setFilenameLocation(ForceFilenameLocation::DefinePath, FileUtil::GetTempDir()); // Save the files in a temporary directory $result = $this->_context->processUpload($fileProcessor, false, $fieldname); // Get a way to rename the files $fileinfo = pathinfo($result[0]); if ($this->_saveAs != "*") { $path_parts = pathinfo($this->_saveAs); } else { $path_parts = pathinfo($result[0]); } $newName = $this->_path . FileUtil::Slash() . $path_parts['filename'] . "." . $fileinfo["extension"]; // Put the image in the right place if (strpos(".jpg.gif.jpeg.png", "." . $fileinfo["extension"]) === false) { rename($result[0], $newName); } else { if ($this->_width > 0 || $this->_height > 0) { $image = new ImageUtil($result[0]); $image->resizeAspectRatio($this->_width, $this->_height, 255, 255, 255)->save($newName); } else { rename($result[0], $newName); } } return $newName; } else { return $row->getField($fieldname); } }
/** * * @param string $singlename */ public function __construct($singlename) { parent::__construct($singlename); if ($this->_context->CacheHashedDir()) { $this->setFilenameLocation(ForceFilenameLocation::DefinePath, $this->_context->CachePath() . $singlename[0] . FileUtil::Slash() . $singlename[1] . FileUtil::Slash()); if (!FileUtil::Exists($this->PathSuggested())) { FileUtil::ForceDirectories($this->PathSuggested()); } } else { $this->_filenameLocation = ForceFilenameLocation::PrivatePath; } }
/** *@param XMLFilenameProcessor $xmlfilename *@param string $path *@param string $strfilename *@return void *@desc *PageXml Constructor. Empty page. and PageXml Constructor. Create from XML. *PageXml Constructor. Create from file name and path. Do not use with XmlnukeDB repository. */ public function __construct($xmlfilename = null, $path = null, $strfilename = null) { if ($xmlfilename == null && $path == null && $strfilename == null) { $auxStr = "<page>\r\n" . "<meta>\r\n" . "<title/>\r\n" . "<abstract/>\r\n" . "<created>" . date("D M j Y G:i:s") . "</created>\r\n" . "<modified>" . date("D M j Y G:i:s") . "</modified>\r\n" . "<keyword>XMLSite ByJG</keyword>\r\n" . "<groupkeyword/>\r\n" . "</meta>\r\n" . "<group>\r\n" . "<id>__DEFAULT__</id>\r\n" . "<title/>\r\n" . "<keyword>all</keyword>\r\n" . "</group>\r\n" . "</page>"; $this->_xmlDoc = XmlUtil::CreateXmlDocumentFromStr($auxStr); $xpath = new DOMXPath($this->_xmlDoc); $this->_nodePage = $this->_xmlDoc->getElementsByTagName("page")->item(0); $this->_nodeGroup = $xpath->query("/page/group")->item(0); } else { if ($xmlfilename != null && $path == null && $strfilename == null) { $this->_xmlDoc = $xmlfilename->getContext()->getXMLDataBase()->getDocument($xmlfilename->FullQualifiedName()); } else { if ($xmlfilename == null && $path != null && $strfilename != null) { $xmlDoc = XmlUtil::CreateXmlDocument(); $xmlDoc->Load(FileUtil::AdjustSlashes($path . FileUtil::Slash() . $strfilename)); } } } }
/** *@return string *@desc Path to private directory */ public function PrivatePath() { // SystemRootPath is necessary to effort XMLNuke DATA directory may be located everywhere. return "lib" . FileUtil::Slash() . $this->_subpath; }
/** *@param *@return string *@desc */ public function PrivatePath() { return FileUtil::Slash($this->_context->CurrentSitePath(false), "snippet"); }
/** *@param *@return string *@desc */ public function SharedPath() { return $this->_context->SharedRootPath() . "setup" . FileUtil::Slash(); }
/** * @return string * @desc Return slash from a Operational System * If OperationSystem is WINDOWS the slash will be '\\' * If OperationSystem is UNIX the slash will be '/' */ public static function Slash($path = null, $append = null) { $slash = self::isWindowsOS() ? "\\" : "/"; if (empty($path)) { return $slash; } else { if (is_array($path)) { $path = array_values($path); for ($i = 0; $i < count($path); $i++) { $path[$i] = FileUtil::Slash($path[$i], $append); } return $path; } else { return $path . ($path[strlen($path) - 1] == $slash ? "" : $slash) . (!empty($append) ? $append . $slash : ''); } } }
/** *@param *@return string *@desc Implementing */ public function PrivatePath() { return FileUtil::Slash($this->_context->XmlPath(false), $this->getLanguageId()); }
/** *@param string $xml *@param string $xsl *@param string $languageId *@return string *@desc */ public function FullName($xml, $xsl, $languageId) { return str_replace(FileUtil::Slash(), "#", $xsl . "." . $languageId . "." . $xml); }
/** *@return string *@desc Path to private directory */ public function PrivatePath() { return FileUtil::Slash($this->_context->CurrentSitePath(), "upload"); }
/** *@param *@return string *@desc Implementing */ public function SharedPath() { return FileUtil::Slash($this->_context->SharedRootPath(), "xsl"); }
/** * Process a document Upload * * @param UploadFilenameProcessor $filenameProcessor * @param bool $useProcessorForName * @param string|array $field Contain the filename properties (if Array, or $filename if string) * @param array Valid Extensions * @return Array Filename saved. */ public function processUpload($filenameProcessor, $useProcessorForName, $field = null) { if (!$filenameProcessor instanceof UploadFilenameProcessor) { throw new UploadUtilException("processUpload must receive a UploadFilenameProcessor class"); } else { if (is_null($field)) { $ret = array(); foreach ($_FILES as $file => $property) { $ret[] = $this->processUpload($filenameProcessor, $useProcessorForName, $property); } return $ret; } else { if (is_string($field)) { $ret = array(); $ret[] = $this->processUpload($filenameProcessor, $useProcessorForName, $_FILES[$field]); return $ret; } else { if (is_array($field)) { if ($useProcessorForName) { $uploadfile = $filenameProcessor->FullQualifiedNameAndPath(); } else { $uploadfile = $filenameProcessor->PathSuggested() . FileUtil::Slash() . $field["name"]; } if (move_uploaded_file($field['tmp_name'], $uploadfile)) { return $uploadfile; } else { $message = "Unknow error: " . $field['error']; switch ($field['error']) { case UPLOAD_ERR_CANT_WRITE: $message = "Can't write"; break; case UPLOAD_ERR_EXTENSION: $message = "Extension is not permitted"; break; case UPLOAD_ERR_FORM_SIZE: $message = "Max post size reached"; break; case UPLOAD_ERR_INI_SIZE: $message = "Max system size reached"; break; case UPLOAD_ERR_NO_FILE: $message = "No file was uploaded"; break; case UPLOAD_ERR_NO_TMP_DIR: $message = "No temp dir"; break; case UPLOAD_ERR_PARTIAL: $message = "The uploaded file was only partially uploaded"; break; } throw new UploadUtilException($message); } } else { throw new UploadUtilException("Something is wrong with Upload file."); } } } } }