function createTemplate($dir, $name, $type) { $browser = $this->getBrowser(); $filesystem = $browser->getFileSystem(); // check path WFUtility::checkPath($dir); // check name WFUtility::checkPath($name); // check for extension in destination name if (preg_match('#\\.(php|php(3|4|5)|phtml|pl|py|jsp|asp|htm|html|shtml|sh|cgi)\\b#i', $name)) { JError::raiseError(403, 'RESTRICTED'); } // get data $data = JRequest::getVar('data', '', 'POST', 'STRING', JREQUEST_ALLOWRAW); $data = rawurldecode($data); $name = JFile::makeSafe($name) . '.html'; $path = WFUtility::makePath($dir, $name); // Remove any existing template div $data = preg_replace('/<div(.*?)class="mceTmpl"([^>]*?)>([\\s\\S]*?)<\\/div>/i', '$3', $data); if ($type == 'template') { $data = '<div class="mceTmpl">' . $data . '</div>'; } if ($filesystem->exists($path)) { $this->_result['error'] = WFText::_('WF_TEMPLATEMANAGER_FILE_EXISTS'); } else { $content = "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"; $content .= "<head>\n"; $content .= "<title>" . $name . "</title>\n"; $content .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"; $content .= "</head>\n"; $content .= "<body>\n"; $content .= $data; $content .= "\n</body>\n"; $content .= "</html>"; if (!$filesystem->write($path, stripslashes($content))) { $browser->setResult(WFText::_('WF_TEMPLATEMANAGER_WRITE_ERROR'), 'error'); } } return $browser->getResult(); }
/** * Convert a url to path * * @param string $url * @return string */ private function urlToPath($url) { jimport('joomla.filesystem.path'); $root = JURI::root(true); // remove root from url if (!empty($root)) { $url = substr($url, strlen($root)); } return WFUtility::makePath(JPATH_SITE, JPath::clean($url)); }
public function getDimensions($file) { $browser = $this->getBrowser(); $filesystem = $browser->getFileSystem(); $width = ''; $height = ''; if ($filesystem->get('local')) { $path = WFUtility::makePath($filesystem->getBaseDir(), rawurldecode($file)); $ext = JFile::getExt($path); switch($ext) { case 'mp3': $width = 200; $height = 16; break; case 'swf': $data = @getimagesize($path); if ($data) { $width = $data[0]; $height = $data[1]; } break; default: $meta = $this->id3Data($path); $width = preg_match('/[^0-9]/', $meta['x']) ? '' : $meta['x']; $height = preg_match('/[^0-9]/', $meta['y']) ? '' : $meta['y']; break; } } return array( 'width' => $width, 'height' => $height ); }
private function createCacheThumb($file) { jimport('joomla.filesystem.file'); $browser = $this->getBrowser(); $editor = $this->getImageEditor(); // check path WFUtility::checkPath($file); $file = WFUtility::makePath($browser->getBaseDir(), $file); // default for list thumbnails $width = 100; $height = 100; $quality = 75; $data = @getimagesize($file); $mime = $data['mime']; if ($data[0] < $width && $data[1] < $height) { return $this->outputImage($file, $mime); } // try exif thumbnail if ($mime == 'image/jpeg' || $mime == 'image/tiff') { $exif = exif_thumbnail($file, $width, $height, $type); if ($exif !== false) { header("Content-type: " . image_type_to_mime_type($type)); die($exif); } } $thumb = $this->getCacheThumbPath($file, $width, $height); if (JFile::exists($thumb)) { return $this->outputImage($thumb, $mime); } $coords = $this->cropThumbnail($data[0], $data[1], $width, $height); if (self::checkMem($data)) { if ($editor->resize($file, $thumb, $width, $height, $quality, $coords['sx'], $coords['sy'], $coords['sw'], $coords['sh'])) { if (JFile::exists($thumb)) { return $this->outputImage($thumb, $mime); } } } // exit with no data exit; }
/** * Upload a file. * @return array $error on failure or uploaded file name on success */ public function upload() { // Check for request forgeries WFToken::checkToken() or die; // check for feature access if (!$this->checkFeature('upload')) { JError::raiseError(403, 'Access to this resource is restricted'); } $filesystem = $this->getFileSystem(); jimport('joomla.filesystem.file'); header('Content-Type: text/json;charset=UTF-8'); header("Expires: Wed, 4 Apr 1984 13:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M_Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // get uploaded file $file = JRequest::getVar('file', '', 'files', 'array'); // validate file data $this->validateUploadedFile($file); // get file name $name = JRequest::getVar('name', $file['name']); // decode name $name = rawurldecode($name); // check name if (WFUtility::validateFileName($name) === false) { throw new InvalidArgumentException('Upload Failed: The file name contains an invalid extension.'); } // check file name WFUtility::checkPath($name); // get extension from file name $ext = WFUtility::getExtension($file['name']); // trim extension $ext = trim($ext); // check extension exists if (empty($ext) || $ext === $file['name']) { throw new InvalidArgumentException('Upload Failed: The file name does not contain a valid extension.'); } // strip extension $name = WFUtility::stripExtension($name); // make file name 'web safe' $name = WFUtility::makeSafe($name, $this->get('websafe_mode', 'utf-8'), $this->get('websafe_spaces'), $this->get('websafe_textcase')); // check name if (WFUtility::validateFileName($name) === false) { throw new InvalidArgumentException('Upload Failed: The file name contains an invalid extension.'); } // target directory $dir = JRequest::getVar('upload-dir'); // deocode directory $dir = rawurldecode($dir); // check destination path WFUtility::checkPath($dir); $upload = $this->get('upload'); // Check file number limits if (!empty($upload['total_files'])) { if ($filesystem->countFiles($dir, true) > $upload['total_files']) { throw new InvalidArgumentException(WFText::_('WF_MANAGER_FILE_LIMIT_ERROR')); } } // Check total file size limit if (!empty($upload['total_size'])) { $size = $filesystem->getTotalSize($dir); if ($size / 1024 / 1024 > $upload['total_size']) { throw new InvalidArgumentException(WFText::_('WF_MANAGER_FILE_SIZE_LIMIT_ERROR')); } } // add random string if ($upload['add_random']) { $name = $name . '_' . substr(md5(uniqid(rand(), 1)), 0, 5); } // rebuild file name - name + extension $name = $name . '.' . $ext; // create a filesystem result object $result = new WFFileSystemResult(); $complete = false; $contentType = JRequest::getVar('CONTENT_TYPE', '', 'SERVER'); // relative path $relative = WFUtility::makePath($dir, $name); // Only multipart uploading is supported for now if ($contentType && strpos($contentType, "multipart") !== false) { $result = $filesystem->upload('multipart', trim($file['tmp_name']), $dir, $name); if (!$result->state) { if (empty($result->message)) { $result->message = WFText::_('WF_MANAGER_UPLOAD_ERROR'); } $result->code = 103; } @unlink($file['tmp_name']); $complete = true; } else { $result->state = false; $result->code = 103; $result->message = WFText::_('WF_MANAGER_UPLOAD_ERROR'); $complete = true; } // upload finished if ($complete) { if ($result instanceof WFFileSystemResult) { if ($result->state === true) { $this->setResult($this->fireEvent('onUpload', array($result->path, $relative))); $this->setResult(basename($result->path), 'files'); } else { $this->setResult($result->message, 'error'); } } die(json_encode($this->getResult())); } }
public function is_dir($path) { $path = WFUtility::makePath($this->getBaseDir(), $path); return is_dir($path); }
/** * Get the full base url * @return string base url */ public function getBaseURL() { return WFUtility::makePath(JURI::root(true), $this->getRootDir()); }
/** * Convert a url to path * * @access public * @param string The url to convert * @return Full path to file * @since 1.5 */ function urlToPath($url) { jimport('joomla.filesystem.path'); $bool = strpos($url, JURI::root()) === false; return WFUtility::makePath(JPATH_SITE, JPath::clean(str_replace(JURI::root($bool), '', $url))); }
/** * Get the full base url * @return string base url */ function getBaseURL() { return WFUtility::makePath(JURI::root(true), 'images'); }
function getDimensions($file) { $browser = $this->getBrowser(); $filesystem = $browser->getFileSystem(); $width = ''; $height = ''; if ($filesystem->get('local')) { $path = WFUtility::makePath($filesystem->getBaseDir(), rawurldecode($file)); $ext = JFile::getExt($path); $meta = $this->id3Data($path); $width = preg_match('/[^0-9]/', $meta['x']) ? '' : $meta['x']; $height = preg_match('/[^0-9]/', $meta['y']) ? '' : $meta['y']; if ($ext == 'mp3') { $width = 200; $height = 16; } } return array('width' => $width, 'height' => $height); }
function write($file, $content) { $path = WFUtility::makePath($this->getBaseDir(), rawurldecode($file)); return JFile::write($path, $content); }