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 ); }
/** * 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)); }
private function getUploadValue() { $upload = trim(ini_get('upload_max_filesize')); $post = trim(ini_get('post_max_size')); $upload = WFUtility::convertSize($upload); $post = WFUtility::convertSize($post); if (intval($upload) <= intval($post)) { return $upload; } return $post; }
/** * Validate an image path and extension * @param type $path Image path * @throws InvalidArgumentException */ private static function validateImagePath($path) { // nothing to validate if (empty($path)) { return false; } // check file WFUtility::checkPath($path); // check name for extensions if (preg_match('#\\.(php|php(3|4|5)|phtml|pl|py|jsp|asp|htm|html|shtml|sh|cgi)\\b#i', basename($path))) { throw new InvalidArgumentException('Invalid file name'); } // check extension - must be an image if (preg_match('#\\.(jpeg|jpg|png|gif|bmp)$#', basename($path)) === false) { throw new InvalidArgumentException('Invalid file extension'); } }
public function loadTemplate($file) { $browser = $this->getBrowser(); $filesystem = $browser->getFileSystem(); // check path WFUtility::checkPath($file); $content = $filesystem->read($file); // Remove body etc. if (preg_match('/<body[^>]*>([\\s\\S]+?)<\\/body>/', $content, $matches)) { $content = trim($matches[1]); } // Replace variables $content = preg_replace_callback('/\\{\\$(.+?)\\}/i', array($this, 'replaceVars'), $content); return $content; }
public function is_dir($path) { $path = WFUtility::makePath($this->getBaseDir(), $path); return is_dir($path); }
public static function changeCase($string, $case) { if (!function_exists('mb_strtolower') || !function_exists('mb_strtoupper')) { return $string; } if (is_array($string)) { array_walk($string, function (&$value, $key, $case) { $value = WFUtility::changeCase($value, $case); }, $case); } else { switch ($case) { case 'lowercase': $string = mb_strtolower($string); break; case 'uppercase': $string = mb_strtoupper($string); break; } } return $string; }
/** * Return the full user directory path. Create if required * * @param string The base path * @access public * @return Full path to folder */ public function getRootDir() { static $root; if (!isset($root)) { $user = JFactory::getUser(); $wf = WFEditor::getInstance(); $profile = $wf->getProfile(); // Get base directory as shared parameter $root = $this->get('dir', ''); // Remove whitespace $root = trim($root); if (!empty($root)) { // Convert slashes / Strip double slashes $root = preg_replace('/[\\\\]+/', '/', $root); // Remove first leading slash $root = ltrim($root, '/'); // Force default directory if base param starts with a variable or a . eg $id if (preg_match('/[\\.\\$]/', $root[0])) { $root = 'images'; } jimport('joomla.user.helper'); // Joomla! 1.6+ if (method_exists('JUserHelper', 'getUserGroups')) { $groups = JUserHelper::getUserGroups($user->id); // get the first group $group_id = array_shift(array_keys($groups)); // Joomla! 2.5? if (is_int($group_id)) { // usergroup table $group = JTable::getInstance('Usergroup'); $group->load($group_id); // usertype $usertype = $group->title; } else { $usertype = $group_id; } } else { $usertype = $user->usertype; } // Replace any path variables $pattern = array('/\\$id/', '/\\$username/', '/\\$user(group|type)/', '/\\$(group|profile)/', '/\\$day/', '/\\$month/', '/\\$year/'); $replace = array($user->id, $user->username, $usertype, $profile->name, date('d'), date('m'), date('Y')); $root = preg_replace($pattern, $replace, $root); // split into path parts to preserve / $parts = explode('/', $root); $textcase = $wf->getParam('editor.websafe_textcase'); if (!empty($textcase)) { $textcase = array_shift($textcase); } // clean path parts $parts = WFUtility::makeSafe($parts, $wf->getParam('editor.websafe_mode', 'utf-8'), $wf->getParam('editor.websafe_allow_spaces', 0), $textcase); //join path parts $root = implode('/', $parts); } } return $root; }
/** * Get the full base url * @return string base url */ function getBaseURL() { return WFUtility::makePath(JURI::root(true), 'images'); }
/** * 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))); }
/** * New folder base function. A wrapper for the JFolder::create function * @param string $folder The folder to create * @return boolean true on success */ function folderCreate($folder) { // check folder path WFUtility::checkPath($folder); $filesystem = $this->getFileSystem(); return $filesystem->folderCreate($folder); }
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); }
function getFileDetails($file) { $browser = $this->getBrowser(); $filesystem = $browser->getFileSystem(); // get array with folder date and content count eg: array('date'=>'00-00-000', 'folders'=>1, 'files'=>2); $details = $filesystem->getFileDetails($file); $data = array('size' => WFUtility::formatSize($details['size']), 'date' => WFUtility::formatDate($details['modified'], $this->getParam('filemanager.date_format', '%d/%m/%Y, %H:%M'))); return $data; }
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($dim[0], $dim[1], $width, $height); if ($this->checkMem($dim[0] * $dim[1])) { 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; }