AAAAhelpers/.htaccess000066600000000177151371540620010021 0ustar00 Order allow,deny Deny from all helpers/index.html000066600000000037151371540620010213 0ustar00 helpers/media.php000066600000006033151371540620010010 0ustar00get('upload_extensions')); if (!in_array($format, $allowable)) { $err = JText('COM_MEDIA_ERROR_WARNFILETYPE'); return false; } $maxSize = (int) ($params->get('upload_maxsize', 0) * 1024 * 1024); if ($maxSize > 0 && (int) $file['size'] > $maxSize) { $err = JText('COM_MEDIA_ERROR_WARNFILETOOLARGE'); return false; } return true; } public static function parseSize($size) { if ($size < 1024) { return JText::sprintf('COM_MEDIA_FILESIZE_BYTES', $size); } elseif ($size < 1024 * 1024) { return JText::sprintf('COM_MEDIA_FILESIZE_KILOBYTES', sprintf('%01.2f', $size / 1024.0)); } else { return JText::sprintf('COM_MEDIA_FILESIZE_MEGABYTES', sprintf('%01.2f', $size / (1024.0 * 1024))); } } function imageResize($width, $height, $target) { //takes the larger size of the width and height and applies the //formula accordingly...this is so this script will work //dynamically with any size image if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); //returns the new sizes in html image tag format...this is so you //can plug this function inside an image tag and just get the return "width=\"$width\" height=\"$height\""; } function countFiles($dir) { $total_file = 0; $total_dir = 0; if (is_dir($dir)) { $d = dir($dir); while (false !== ($entry = $d->read())) { if (substr($entry, 0, 1) != '.' && is_file($dir . DIRECTORY_SEPARATOR . $entry) && strpos($entry, '.html') === false && strpos($entry, '.php') === false) { $total_file++; } if (substr($entry, 0, 1) != '.' && is_dir($dir . DIRECTORY_SEPARATOR . $entry)) { $total_dir++; } } $d->close(); } return array ($total_file, $total_dir); } } media.php000066600000005265151371540620006354 0ustar00authorise('core.edit', $asset) && !$user->authorise('core.create', $asset) && count($user->getAuthorisedCategories($asset, 'core.create')) == 0 && !($user->id==$author && $user->authorise('core.edit.own', $asset))) { return JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR')); } // Set the path definitions define('COM_MEDIA_BASE', JPATH_ROOT.'/'.$params->get('image_path', 'images')); define('COM_MEDIA_BASEURL', JURI::root().'/'.$params->get('image_path', 'images')); $lang = JFactory::getLanguage(); $lang->load('com_media', JPATH_ADMINISTRATOR, null, false, true) || $lang->load('com_media', JPATH_SITE, null, false, true); // Load the admin HTML view require_once JPATH_COMPONENT_ADMINISTRATOR.'/helpers/media.php'; // Require the base controller require_once JPATH_COMPONENT.'/controller.php'; // Make sure the user is authorized to view this page $user = JFactory::getUser(); $app = JFactory::getApplication(); $cmd = JRequest::getCmd('task', null); if (strpos($cmd, '.') != false) { // We have a defined controller/task pair -- lets split them out list($controllerName, $task) = explode('.', $cmd); // Define the controller name and path $controllerName = strtolower($controllerName); $controllerPath = JPATH_COMPONENT_ADMINISTRATOR.'/controllers/'.$controllerName.'.php'; // If the controller file path exists, include it ... else lets die with a 500 error if (file_exists($controllerPath)) { require_once $controllerPath; } else { JError::raiseError(500, JText::_('JERROR_INVALID_CONTROLLER')); } } else { // Base controller, just set the task :) $controllerName = null; $task = $cmd; } // Set the name for the controller and instantiate it $controllerClass = 'MediaController'.ucfirst($controllerName); if (class_exists($controllerClass)) { $controller = new $controllerClass(); } else { JError::raiseError(500, JText::_('JERROR_INVALID_CONTROLLER_CLASS')); } // Set the model and view paths to the administrator folders $controller->addViewPath(JPATH_COMPONENT_ADMINISTRATOR.'/views'); $controller->addModelPath(JPATH_COMPONENT_ADMINISTRATOR.'/models'); // Perform the Request task $controller->execute($task); // Redirect if set by the controller $controller->redirect(); controller.php000066600000003377151371540620007462 0ustar00getType(); // Get/Create the view $view = $this->getView($vName, $vType); $view->addTemplatePath(JPATH_COMPONENT_ADMINISTRATOR.'/views/'.strtolower($vName).'/tmpl'); // Get/Create the model if ($model = $this->getModel($mName)) { // Push the model into the view (as default) $view->setModel($model, true); } // Set the layout $view->setLayout($vLayout); // Display the view $view->display(); return $this; } function ftpValidate() { // Set FTP credentials, if given JClientHelper::setCredentialsFromRequest('ftp'); } } .htaccess000066600000000177151371540620006357 0ustar00 Order allow,deny Deny from all index.html000066600000000037151371540620006551 0ustar00 views/index.html000066600000000037151372052670007712 0ustar00 views/media/.htaccess000066600000000177151372052670010577 0ustar00 Order allow,deny Deny from all views/media/tmpl/index.html000066600000000037151372052670011745 0ustar00 views/media/tmpl/default_folders.php000066600000001275151372052670013630 0ustar00 views/media/tmpl/.htaccess000066600000000177151372052670011553 0ustar00 Order allow,deny Deny from all views/media/tmpl/default_navigation.php000066600000001764151372052670014334 0ustar00getUserStateFromRequest('media.list.layout', 'layout', 'thumbs', 'word'); ?> views/media/tmpl/default.php000066600000010103151372052670012100 0ustar00
loadTemplate('folders'); ?>
authorise('core.create', 'com_media')) and $this->require_ftp): ?>
authorise('core.create', 'com_media')): ?>
authorise('core.create', 'com_media')):?>
config->get('upload_maxsize')=='0' ? JText::_('COM_MEDIA_UPLOAD_FILES_NOLIMIT') : JText::sprintf('COM_MEDIA_UPLOAD_FILES', $this->config->get('upload_maxsize')); ?>
views/media/view.html.php000066600000006771151372052670011435 0ustar00getUserStateFromRequest('media.list.layout', 'layout', 'thumbs', 'word'); $document = JFactory::getDocument(); $document->setBuffer($this->loadTemplate('navigation'), 'modules', 'submenu'); JHtml::_('behavior.framework', true); JHtml::_('script', 'media/mediamanager.js', true, true); JHtml::_('stylesheet', 'media/mediamanager.css', array(), true); if ($lang->isRTL()) : JHtml::_('stylesheet', 'media/mediamanager_rtl.css', array(), true); endif; JHtml::_('behavior.modal'); $document->addScriptDeclaration(" window.addEvent('domready', function() { document.preview = SqueezeBox; });"); JHtml::_('script', 'system/mootree.js', true, true, false, false); JHtml::_('stylesheet', 'system/mootree.css', array(), true); if ($lang->isRTL()) : JHtml::_('stylesheet', 'media/mootree_rtl.css', array(), true); endif; if (DIRECTORY_SEPARATOR == '\\') { $base = str_replace(DIRECTORY_SEPARATOR, "\\\\", COM_MEDIA_BASE); } else { $base = COM_MEDIA_BASE; } $js = " var basepath = '".$base."'; var viewstyle = '".$style."'; " ; $document->addScriptDeclaration($js); /* * Display form for FTP credentials? * Don't set them here, as there are other functions called before this one if there is any file write operation */ $ftp = !JClientHelper::hasCredentials('ftp'); $session = JFactory::getSession(); $state = $this->get('state'); $this->assignRef('session', $session); $this->assignRef('config', $config); $this->assignRef('state', $state); $this->require_ftp = $ftp; $this->folders_id = ' id="media-tree"'; $this->folders = $this->get('folderTree'); // Set the toolbar $this->addToolbar(); parent::display($tpl); echo JHtml::_('behavior.keepalive'); } /** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { // Get the toolbar object instance $bar = JToolBar::getInstance('toolbar'); $user = JFactory::getUser(); // Set the titlebar text JToolBarHelper::title(JText::_('COM_MEDIA'), 'mediamanager.png'); // Add a delete button if ($user->authorise('core.delete', 'com_media')) { $title = JText::_('JTOOLBAR_DELETE'); $dhtml = " $title"; $bar->appendButton('Custom', $dhtml, 'delete'); JToolBarHelper::divider(); } // Add a delete button if ($user->authorise('core.admin', 'com_media')) { JToolBarHelper::preferences('com_media', 450, 800, 'JToolbar_Options', '', 'window.location.reload()'); JToolBarHelper::divider(); } JToolBarHelper::help('JHELP_CONTENT_MEDIA_MANAGER'); } function getFolderLevel($folder) { $this->folders_id = null; $txt = null; if (isset($folder['children']) && count($folder['children'])) { $tmp = $this->folders; $this->folders = $folder; $txt = $this->loadTemplate('folders'); $this->folders = $tmp; } return $txt; } } views/media/index.html000066600000000037151372052670010771 0ustar00 views/images/tmpl/index.html000066600000000037151372052670012133 0ustar00 views/images/tmpl/default.php000066600000012020151372052670012266 0ustar00
folderList; ?>
state->get('field.id')):?> state->get('field.id')):?>
authorise('core.create', 'com_media')): ?>
config->get('upload_maxsize')=='0' ? JText::_('COM_MEDIA_UPLOAD_FILES_NOLIMIT') : JText::sprintf('COM_MEDIA_UPLOAD_FILES', $this->config->get('upload_maxsize')); ?>
views/images/tmpl/.htaccess000066600000000177151372052670011741 0ustar00 Order allow,deny Deny from all views/images/view.html.php000066600000002365151372052670011616 0ustar00isRTL()) { JHtml::_('stylesheet', 'media/popup-imagemanager_rtl.css', array(), true); } /* * Display form for FTP credentials? * Don't set them here, as there are other functions called before this one if there is any file write operation */ $ftp = !JClientHelper::hasCredentials('ftp'); $this->session = JFactory::getSession(); $this->config = $config; $this->state = $this->get('state'); $this->folderList = $this->get('folderList'); $this->require_ftp = $ftp; parent::display($tpl); } } views/images/.htaccess000066600000000177151372052670010765 0ustar00 Order allow,deny Deny from all views/images/index.html000066600000000037151372052670011157 0ustar00 views/medialist/.htaccess000066600000000177151372052670011473 0ustar00 Order allow,deny Deny from all views/medialist/view.html.php000066600000005222151372052670012317 0ustar00getUserStateFromRequest('media.list.layout', 'layout', 'thumbs', 'word'); $lang = JFactory::getLanguage(); JHtml::_('behavior.framework', true); $document = JFactory::getDocument(); $document->addStyleSheet('../media/media/css/medialist-'.$style.'.css'); if ($lang->isRTL()) : $document->addStyleSheet('../media/media/css/medialist-'.$style.'_rtl.css'); endif; $document->addScriptDeclaration(" window.addEvent('domready', function() { window.parent.document.updateUploader(); $$('a.img-preview').each(function(el) { el.addEvent('click', function(e) { new Event(e).stop(); window.top.document.preview.fromElement(el); }); }); });"); $images = $this->get('images'); $documents = $this->get('documents'); $folders = $this->get('folders'); $state = $this->get('state'); // Check for invalid folder name if (empty($state->folder)) { $dirname = JRequest::getVar('folder', '', '', 'string'); if (!empty($dirname)) { $dirname = htmlspecialchars($dirname, ENT_COMPAT, 'UTF-8'); if ($lang->hasKey('COM_MEDIA_ERROR_UNABLE_TO_BROWSE_FOLDER_WARNDIRNAME')) { JError::raiseWarning(100, JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_BROWSE_FOLDER_WARNDIRNAME', $dirname)); } else { JError::raiseWarning(100, sprintf('Unable to browse: %s. Directory name must only contain alphanumeric characters and no spaces.', $dirname)); } } } $this->baseURL = JURI::root(); $this->assignRef('images', $images); $this->assignRef('documents', $documents); $this->assignRef('folders', $folders); $this->assignRef('state', $state); parent::display($tpl); } function setFolder($index = 0) { if (isset($this->folders[$index])) { $this->_tmp_folder = &$this->folders[$index]; } else { $this->_tmp_folder = new JObject; } } function setImage($index = 0) { if (isset($this->images[$index])) { $this->_tmp_img = &$this->images[$index]; } else { $this->_tmp_img = new JObject; } } function setDoc($index = 0) { if (isset($this->documents[$index])) { $this->_tmp_doc = &$this->documents[$index]; } else { $this->_tmp_doc = new JObject; } } } views/medialist/index.html000066600000000037151372052670011665 0ustar00 views/medialist/tmpl/thumbs_folder.php000066600000003402151372052670014211 0ustar00
authorise('core.delete', 'com_media')):?> 16, 'height' => 16, 'border' => 0), true); ?>
_tmp_folder->name, 0, 10) . (strlen($this->_tmp_folder->name) > 10 ? '...' : ''); ?>
views/medialist/tmpl/thumbs_doc.php000066600000003470151372052670013510 0ustar00trigger('onContentBeforeDisplay', array('com_media.file', &$this->_tmp_doc, &$params)); ?>
authorise('core.delete', 'com_media')):?> 16, 'height' => 16), true); ?>
_tmp_doc->title; ?>
trigger('onContentAfterDisplay', array('com_media.file', &$this->_tmp_doc, &$params)); ?> views/medialist/tmpl/thumbs_img.php000066600000004140151372052670013512 0ustar00trigger('onContentBeforeDisplay', array('com_media.file', &$this->_tmp_img, &$params)); ?>
authorise('core.delete', 'com_media')):?> 16, 'height' => 16), true); ?>
escape(substr($this->_tmp_img->title, 0, 10) . (strlen($this->_tmp_img->title) > 10 ? '...' : '')); ?>
trigger('onContentAfterDisplay', array('com_media.file', &$this->_tmp_img, &$params)); ?> views/medialist/tmpl/details_doc.php000066600000003530151372052670013630 0ustar00trigger('onContentBeforeDisplay', array('com_media.file', &$this->_tmp_doc, &$params)); ?> _tmp_doc->icon_16, $this->_tmp_doc->title, null, true, true) ? JHtml::_('image', $this->_tmp_doc->icon_16, $this->_tmp_doc->title, array('width' => 16, 'height' => 16), true) : JHtml::_('image', 'media/con_info.png', $this->_tmp_doc->title, array('width' => 16, 'height' => 16), true);?> _tmp_doc->title; ?>   _tmp_doc->size); ?> authorise('core.delete', 'com_media')):?> 16, 'height' => 16, 'border' => 0), true);?> trigger('onContentAfterDisplay', array('com_media.file', &$this->_tmp_doc, &$params)); ?> views/medialist/tmpl/details_img.php000066600000004121151372052670013634 0ustar00trigger('onContentBeforeDisplay', array('com_media.file', &$this->_tmp_img, &$params)); ?> _tmp_img->path_relative, JText::sprintf('COM_MEDIA_IMAGE_TITLE', $this->_tmp_img->title, MediaHelper::parseSize($this->_tmp_img->size)), array('width' => $this->_tmp_img->width_16, 'height' => $this->_tmp_img->height_16)); ?> escape($this->_tmp_img->title); ?> _tmp_img->width, $this->_tmp_img->height); ?> _tmp_img->size); ?> authorise('core.delete', 'com_media')):?> 16, 'height' => 16), true); ?> trigger('onContentAfterDisplay', array('com_media.file', &$this->_tmp_img, &$params)); ?> views/medialist/tmpl/details_up.php000066600000001674151372052670013516 0ustar00 16, 'height' => 16), true); ?> ..     authorise('core.delete', 'com_media')):?>   views/medialist/tmpl/index.html000066600000000037151372052670012641 0ustar00 views/medialist/tmpl/details_folder.php000066600000003146151372052670014341 0ustar00 _tmp_folder->name, array('width' => 16, 'height' => 16), true); ?> _tmp_folder->name; ?>     authorise('core.delete', 'com_media')):?> 16, 'height' => 16), true); ?> views/medialist/tmpl/.htaccess000066600000000177151372052670012447 0ustar00 Order allow,deny Deny from all views/medialist/tmpl/thumbs_up.php000066600000001647151372052670013373 0ustar00
 
..
views/medialist/tmpl/details.php000066600000003227151372052670013006 0ustar00
authorise('core.delete', 'com_media')):?> loadTemplate('up'); ?> folders); $i<$n; $i++) : $this->setFolder($i); echo $this->loadTemplate('folder'); endfor; ?> documents); $i<$n; $i++) : $this->setDoc($i); echo $this->loadTemplate('doc'); endfor; ?> images); $i<$n; $i++) : $this->setImage($i); echo $this->loadTemplate('img'); endfor; ?>
views/medialist/tmpl/thumbs.php000066600000002174151372052670012663 0ustar00
loadTemplate('up'); ?> folders); $i<$n; $i++) : $this->setFolder($i); echo $this->loadTemplate('folder'); endfor; ?> documents); $i<$n; $i++) : $this->setDoc($i); echo $this->loadTemplate('doc'); endfor; ?> images); $i<$n; $i++) : $this->setImage($i); echo $this->loadTemplate('img'); endfor; ?>
views/medialist/tmpl/default.php000066600000000434151372052670013002 0ustar00 Order allow,deny Deny from all views/imageslist/view.html.php000066600000002720151372052670012505 0ustar00isRTL()) : JHtml::_('stylesheet', 'media/popup-imagelist_rtl.css', array(), true); endif; $document = JFactory::getDocument(); $document->addScriptDeclaration("var ImageManager = window.parent.ImageManager;"); $images = $this->get('images'); $folders = $this->get('folders'); $state = $this->get('state'); $this->baseURL = COM_MEDIA_BASEURL; $this->assignRef('images', $images); $this->assignRef('folders', $folders); $this->assignRef('state', $state); parent::display($tpl); } function setFolder($index = 0) { if (isset($this->folders[$index])) { $this->_tmp_folder = &$this->folders[$index]; } else { $this->_tmp_folder = new JObject; } } function setImage($index = 0) { if (isset($this->images[$index])) { $this->_tmp_img = &$this->images[$index]; } else { $this->_tmp_img = new JObject; } } } views/imageslist/.htaccess000066600000000177151372052670011661 0ustar00 Order allow,deny Deny from all views/imageslist/index.html000066600000000037151372052670012053 0ustar00 views/imageslist/tmpl/default_image.php000066600000002153151372052670014332 0ustar00trigger('onContentBeforeDisplay', array('com_media.file', &$this->_tmp_img, &$params)); ?>
baseURL.'/'.$this->_tmp_img->path_relative, JText::sprintf('COM_MEDIA_IMAGE_TITLE', $this->_tmp_img->title, MediaHelper::parseSize($this->_tmp_img->size)), array('width' => $this->_tmp_img->width_60, 'height' => $this->_tmp_img->height_60)); ?> _tmp_img->title; ?>
trigger('onContentAfterDisplay', array('com_media.file', &$this->_tmp_img, &$params)); ?> views/imageslist/tmpl/.htaccess000066600000000177151372052670012635 0ustar00 Order allow,deny Deny from all views/imageslist/tmpl/index.html000066600000000037151372052670013027 0ustar00 views/imageslist/tmpl/default.php000066600000001422151372052670013166 0ustar00 images) > 0 || count($this->folders) > 0) { ?>
folders); $i<$n; $i++) : $this->setFolder($i); echo $this->loadTemplate('folder'); endfor; ?> images); $i<$n; $i++) : $this->setImage($i); echo $this->loadTemplate('image'); endfor; ?>

views/imageslist/tmpl/default_folder.php000066600000001341151372052670014521 0ustar00
_tmp_folder->name, array('height' => 80, 'width' => 80), true); ?> _tmp_folder->name; ?>
access.xml000066600000001002151372052670006534 0ustar00
models/.htaccess000066600000000177151372052670007646 0ustar00 Order allow,deny Deny from all models/forms/.htaccess000066600000000177151372052670010774 0ustar00 Order allow,deny Deny from all models/forms/index.html000066600000000037151372052670011166 0ustar00 models/list.php000066600000010466151372052670007536 0ustar00setState('folder', $folder); $parent = str_replace("\\", "/", dirname($folder)); $parent = ($parent == '.') ? null : $parent; $this->setState('parent', $parent); $set = true; } return parent::getState($property, $default); } function getImages() { $list = $this->getList(); return $list['images']; } function getFolders() { $list = $this->getList(); return $list['folders']; } function getDocuments() { $list = $this->getList(); return $list['docs']; } /** * Build imagelist * * @param string $listFolder The image directory to display * @since 1.5 */ function getList() { static $list; // Only process the list once per request if (is_array($list)) { return $list; } // Get current path from request $current = $this->getState('folder'); // If undefined, set to empty if ($current == 'undefined') { $current = ''; } // Initialise variables. if (strlen($current) > 0) { $basePath = COM_MEDIA_BASE.'/'.$current; } else { $basePath = COM_MEDIA_BASE; } $mediaBase = str_replace(DIRECTORY_SEPARATOR, '/', COM_MEDIA_BASE.'/'); $images = array (); $folders = array (); $docs = array (); $fileList = false; $folderList = false; if (file_exists($basePath)) { // Get the list of files and folders from the given folder $fileList = JFolder::files($basePath); $folderList = JFolder::folders($basePath); } // Iterate over the files if they exist if ($fileList !== false) { foreach ($fileList as $file) { if (is_file($basePath.'/'.$file) && substr($file, 0, 1) != '.' && strtolower($file) !== 'index.html') { $tmp = new JObject(); $tmp->name = $file; $tmp->title = $file; $tmp->path = str_replace(DIRECTORY_SEPARATOR, '/', JPath::clean($basePath . '/' . $file)); $tmp->path_relative = str_replace($mediaBase, '', $tmp->path); $tmp->size = filesize($tmp->path); $ext = strtolower(JFile::getExt($file)); switch ($ext) { // Image case 'jpg': case 'png': case 'gif': case 'xcf': case 'odg': case 'bmp': case 'jpeg': case 'ico': $info = @getimagesize($tmp->path); $tmp->width = @$info[0]; $tmp->height = @$info[1]; $tmp->type = @$info[2]; $tmp->mime = @$info['mime']; if (($info[0] > 60) || ($info[1] > 60)) { $dimensions = MediaHelper::imageResize($info[0], $info[1], 60); $tmp->width_60 = $dimensions[0]; $tmp->height_60 = $dimensions[1]; } else { $tmp->width_60 = $tmp->width; $tmp->height_60 = $tmp->height; } if (($info[0] > 16) || ($info[1] > 16)) { $dimensions = MediaHelper::imageResize($info[0], $info[1], 16); $tmp->width_16 = $dimensions[0]; $tmp->height_16 = $dimensions[1]; } else { $tmp->width_16 = $tmp->width; $tmp->height_16 = $tmp->height; } $images[] = $tmp; break; // Non-image document default: $tmp->icon_32 = "media/mime-icon-32/".$ext.".png"; $tmp->icon_16 = "media/mime-icon-16/".$ext.".png"; $docs[] = $tmp; break; } } } } // Iterate over the folders if they exist if ($folderList !== false) { foreach ($folderList as $folder) { $tmp = new JObject(); $tmp->name = basename($folder); $tmp->path = str_replace(DIRECTORY_SEPARATOR, '/', JPath::clean($basePath . '/' . $folder)); $tmp->path_relative = str_replace($mediaBase, '', $tmp->path); $count = MediaHelper::countFiles($tmp->path); $tmp->files = $count[0]; $tmp->folders = $count[1]; $folders[] = $tmp; } } $list = array('folders' => $folders, 'docs' => $docs, 'images' => $images); return $list; } } models/index.html000066600000000037151372052670010040 0ustar00 models/manager.php000066600000007260151372052670010173 0ustar00setState('folder', $folder); $fieldid = JRequest::getCmd('fieldid', ''); $this->setState('field.id', $fieldid); $parent = str_replace("\\", "/", dirname($folder)); $parent = ($parent == '.') ? null : $parent; $this->setState('parent', $parent); $set = true; } return parent::getState($property, $default); } /** * Image Manager Popup * * @param string $listFolder The image directory to display * @since 1.5 */ function getFolderList($base = null) { // Get some paths from the request if (empty($base)) { $base = COM_MEDIA_BASE; } //corrections for windows paths $base = str_replace(DIRECTORY_SEPARATOR, '/', $base); $com_media_base_uni = str_replace(DIRECTORY_SEPARATOR, '/', COM_MEDIA_BASE); // Get the list of folders jimport('joomla.filesystem.folder'); $folders = JFolder::folders($base, '.', true, true); $document = JFactory::getDocument(); $document->setTitle(JText::_('COM_MEDIA_INSERT_IMAGE')); // Build the array of select options for the folder list $options[] = JHtml::_('select.option', "", "/"); foreach ($folders as $folder) { $folder = str_replace($com_media_base_uni, "", str_replace(DIRECTORY_SEPARATOR, '/', $folder)); $value = substr($folder, 1); $text = str_replace(DIRECTORY_SEPARATOR, "/", $folder); $options[] = JHtml::_('select.option', $value, $text); } // Sort the folder list array if (is_array($options)) { sort($options); } // Get asset and author id (use integer filter) $input = JFactory::getApplication()->input; $asset = $input->get('asset', 0, 'integer'); $author = $input->get('author', 0, 'integer'); // Create the drop-down folder select list $list = JHtml::_('select.genericlist', $options, 'folderlist', 'class="inputbox" size="1" onchange="ImageManager.setFolder(this.options[this.selectedIndex].value, '.$asset.', '.$author.')" ', 'value', 'text', $base); return $list; } function getFolderTree($base = null) { // Get some paths from the request if (empty($base)) { $base = COM_MEDIA_BASE; } $mediaBase = str_replace(DIRECTORY_SEPARATOR, '/', COM_MEDIA_BASE.'/'); // Get the list of folders jimport('joomla.filesystem.folder'); $folders = JFolder::folders($base, '.', true, true); $tree = array(); foreach ($folders as $folder) { $folder = str_replace(DIRECTORY_SEPARATOR, '/', $folder); $name = substr($folder, strrpos($folder, '/') + 1); $relative = str_replace($mediaBase, '', $folder); $absolute = $folder; $path = explode('/', $relative); $node = (object) array('name' => $name, 'relative' => $relative, 'absolute' => $absolute); $tmp = &$tree; for ($i=0, $n=count($path); $i<$n; $i++) { if (!isset($tmp['children'])) { $tmp['children'] = array(); } if ($i == $n-1) { // We need to place the node $tmp['children'][$relative] = array('data' =>$node, 'children' => array()); break; } if (array_key_exists($key = implode('/', array_slice($path, 0, $i+1)), $tmp['children'])) { $tmp = &$tmp['children'][$key]; } } } $tree['data'] = (object) array('name' => JText::_('COM_MEDIA_MEDIA'), 'relative' => '', 'absolute' => $base); return $tree; } } config.xml000066600000005606151372052670006556 0ustar00
media.xml000066600000002352151372052670006363 0ustar00 com_media Joomla! Project April 2006 (C) 2005 - 2014 Open Source Matters. All rights reserved. GNU General Public License version 2 or later; see LICENSE.txt admin@joomla.org www.joomla.org 2.5.0 COM_MEDIA_XML_DESCRIPTION controller.php index.html media.php helpers language/en-GB.com_media.ini config.xml controller.php index.html media.php controllers helpers models views language/en-GB.com_media.ini controllers/folder.php000066600000014207151372052670011116 0ustar00setRedirect($redirect); // Just return if there's nothing to do if (empty($paths)) { return true; } if (!$user->authorise('core.delete', 'com_media')) { // User is not authorised to delete JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED')); return false; } // Set FTP credentials, if given JClientHelper::setCredentialsFromRequest('ftp'); // Initialise variables. $ret = true; JPluginHelper::importPlugin('content'); $dispatcher = JDispatcher::getInstance(); if (count($paths)) { foreach ($paths as $path) { if ($path !== JFile::makeSafe($path)) { $dirname = htmlspecialchars($path, ENT_COMPAT, 'UTF-8'); JError::raiseWarning(100, JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FOLDER_WARNDIRNAME', substr($dirname, strlen(COM_MEDIA_BASE)))); continue; } $fullPath = JPath::clean(implode(DIRECTORY_SEPARATOR, array(COM_MEDIA_BASE, $folder, $path))); $object_file = new JObject(array('filepath' => $fullPath)); if (is_file($fullPath)) { // Trigger the onContentBeforeDelete event. $result = $dispatcher->trigger('onContentBeforeDelete', array('com_media.file', &$object_file)); if (in_array(false, $result, true)) { // There are some errors in the plugins JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors = $object_file->getErrors()), implode('
', $errors))); continue; } $ret &= JFile::delete($fullPath); // Trigger the onContentAfterDelete event. $dispatcher->trigger('onContentAfterDelete', array('com_media.file', &$object_file)); $this->setMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($fullPath, strlen(COM_MEDIA_BASE)))); } elseif (is_dir($fullPath)) { $contents = JFolder::files($fullPath, '.', true, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'index.html')); if (empty($contents)) { // Trigger the onContentBeforeDelete event. $result = $dispatcher->trigger('onContentBeforeDelete', array('com_media.folder', &$object_file)); if (in_array(false, $result, true)) { // There are some errors in the plugins JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors = $object_file->getErrors()), implode('
', $errors))); continue; } $ret &= !JFolder::delete($fullPath); // Trigger the onContentAfterDelete event. $dispatcher->trigger('onContentAfterDelete', array('com_media.folder', &$object_file)); $this->setMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($fullPath, strlen(COM_MEDIA_BASE)))); } else { //This makes no sense... JError::raiseWarning(100, JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FOLDER_NOT_EMPTY', substr($fullPath, strlen(COM_MEDIA_BASE)))); } } } return $ret; } } /** * Create a folder * * @param string $path Path of the folder to create * @since 1.5 */ public function create() { // Check for request forgeries JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $user = JFactory::getUser(); $folder = JRequest::getCmd('foldername', ''); $folderCheck = JRequest::getVar('foldername', null, '', 'string', JREQUEST_ALLOWRAW); $parent = JRequest::getVar('folderbase', '', '', 'path'); $this->setRedirect('index.php?option=com_media&folder='.$parent.'&tmpl='.JRequest::getCmd('tmpl', 'index')); if (strlen($folder) > 0) { if (!$user->authorise('core.create', 'com_media')) { // User is not authorised to delete JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_CREATE_NOT_PERMITTED')); return false; } // Set FTP credentials, if given JClientHelper::setCredentialsFromRequest('ftp'); JRequest::setVar('folder', $parent); if (($folderCheck !== null) && ($folder !== $folderCheck)) { $this->setMessage(JText::_('COM_MEDIA_ERROR_UNABLE_TO_CREATE_FOLDER_WARNDIRNAME')); return false; } $path = JPath::clean(COM_MEDIA_BASE . '/' . $parent . '/' . $folder); if (!is_dir($path) && !is_file($path)) { // Trigger the onContentBeforeSave event. $object_file = new JObject(array('filepath' => $path)); JPluginHelper::importPlugin('content'); $dispatcher = JDispatcher::getInstance(); $result = $dispatcher->trigger('onContentBeforeSave', array('com_media.folder', &$object_file, true)); if (in_array(false, $result, true)) { // There are some errors in the plugins JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors = $object_file->getErrors()), implode('
', $errors))); return false; } JFolder::create($path); $data = "\n\n\n"; JFile::write($path . "/index.html", $data); // Trigger the onContentAfterSave event. $dispatcher->trigger('onContentAfterSave', array('com_media.folder', &$object_file, true)); $this->setMessage(JText::sprintf('COM_MEDIA_CREATE_COMPLETE', substr($path, strlen(COM_MEDIA_BASE)))); } JRequest::setVar('folder', ($parent) ? $parent.'/'.$folder : $folder); } } } controllers/file.json.php000066600000011013151372052670011522 0ustar00 '0', 'error' => JText::_('JINVALID_TOKEN') ); echo json_encode($response); return; } // Get the user $user = JFactory::getUser(); $log = JLog::getInstance('upload.error.php'); // Get some data from the request $file = JRequest::getVar('Filedata', '', 'files', 'array'); $folder = JRequest::getVar('folder', '', '', 'path'); $return = JRequest::getVar('return-url', null, 'post', 'base64'); if ( $_SERVER['CONTENT_LENGTH']>($params->get('upload_maxsize', 0) * 1024 * 1024) || $_SERVER['CONTENT_LENGTH']>(int)(ini_get('upload_max_filesize'))* 1024 * 1024 || $_SERVER['CONTENT_LENGTH']>(int)(ini_get('post_max_size'))* 1024 * 1024 || $_SERVER['CONTENT_LENGTH']>(int)(ini_get('memory_limit'))* 1024 * 1024 ) { $response = array( 'status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE') ); echo json_encode($response); return; } // Set FTP credentials, if given JClientHelper::setCredentialsFromRequest('ftp'); // Make the filename safe $file['name'] = JFile::makeSafe($file['name']); if (isset($file['name'])) { // The request is valid $err = null; $filepath = JPath::clean(COM_MEDIA_BASE . '/' . $folder . '/' . strtolower($file['name'])); if (!MediaHelper::canUpload($file, $err)) { $log->addEntry(array('comment' => 'Invalid: '.$filepath.': '.$err)); $response = array( 'status' => '0', 'error' => JText::_($err) ); echo json_encode($response); return; } // Trigger the onContentBeforeSave event. JPluginHelper::importPlugin('content'); $dispatcher = JDispatcher::getInstance(); $object_file = new JObject($file); $object_file->filepath = $filepath; $result = $dispatcher->trigger('onContentBeforeSave', array('com_media.file', &$object_file, true)); if (in_array(false, $result, true)) { // There are some errors in the plugins $log->addEntry(array('comment' => 'Errors before save: '.$filepath.' : '.implode(', ', $object_file->getErrors()))); $response = array( 'status' => '0', 'error' => JText::plural('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors = $object_file->getErrors()), implode('
', $errors)) ); echo json_encode($response); return; } if (JFile::exists($filepath)) { // File exists $log->addEntry(array('comment' => 'File exists: '.$filepath.' by user_id '.$user->id)); $response = array( 'status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_FILE_EXISTS') ); echo json_encode($response); return; } elseif (!$user->authorise('core.create', 'com_media')) { // File does not exist and user is not authorised to create $log->addEntry(array('comment' => 'Create not permitted: '.$filepath.' by user_id '.$user->id)); $response = array( 'status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_CREATE_NOT_PERMITTED') ); echo json_encode($response); return; } $file = (array) $object_file; if (!JFile::upload($file['tmp_name'], $file['filepath'])) { // Error in upload $log->addEntry(array('comment' => 'Error on upload: '.$filepath)); $response = array( 'status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE') ); echo json_encode($response); return; } else { // Trigger the onContentAfterSave event. $dispatcher->trigger('onContentAfterSave', array('com_media.file', &$object_file, true)); $log->addEntry(array('comment' => $folder)); $response = array( 'status' => '1', 'error' => JText::sprintf('COM_MEDIA_UPLOAD_COMPLETE', substr($file['filepath'], strlen(COM_MEDIA_BASE))) ); echo json_encode($response); return; } } else { $response = array( 'status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_BAD_REQUEST') ); echo json_encode($response); return; } } } controllers/index.html000066600000000037151372052670011123 0ustar00 controllers/.htaccess000066600000000177151372052670010731 0ustar00 Order allow,deny Deny from all controllers/file.php000066600000021447151372052670010566 0ustar00folder = JRequest::getVar('folder', '', '', 'path'); // Set the redirect if ($return) { $this->setRedirect(base64_decode($return) . '&folder=' . $this->folder); } // Authorize the user if (!$this->authoriseUser('create')) { return false; } if ( $_SERVER['CONTENT_LENGTH']>($params->get('upload_maxsize', 0) * 1024 * 1024) || $_SERVER['CONTENT_LENGTH']>(int)(ini_get('upload_max_filesize'))* 1024 * 1024 || $_SERVER['CONTENT_LENGTH']>(int)(ini_get('post_max_size'))* 1024 * 1024 || (($_SERVER['CONTENT_LENGTH'] > (int) (ini_get('memory_limit')) * 1024 * 1024) && ((int) (ini_get('memory_limit')) != -1)) ) { JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE')); return false; } // Input is in the form of an associative array containing numerically indexed arrays // We want a numerically indexed array containing associative arrays // Cast each item as array in case the Filedata parameter was not sent as such $files = array_map( array($this, 'reformatFilesArray'), (array) $files['name'], (array) $files['type'], (array) $files['tmp_name'], (array) $files['error'], (array) $files['size'] ); // Perform basic checks on file info before attempting anything foreach ($files as &$file) { if ($file['error']==1) { JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE')); return false; } if ($file['size']>($params->get('upload_maxsize', 0) * 1024 * 1024)) { JError::raiseNotice(100, JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE')); return false; } if (JFile::exists($file['filepath'])) { // A file with this name already exists JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_FILE_EXISTS')); return false; } if (!isset($file['name'])) { // No filename (after the name was cleaned by JFile::makeSafe) $this->setRedirect('index.php', JText::_('COM_MEDIA_INVALID_REQUEST'), 'error'); return false; } } // Set FTP credentials, if given JClientHelper::setCredentialsFromRequest('ftp'); JPluginHelper::importPlugin('content'); $dispatcher = JDispatcher::getInstance(); foreach ($files as &$file) { // The request is valid $err = null; if (!MediaHelper::canUpload($file, $err)) { // The file can't be upload JError::raiseNotice(100, JText::_($err)); return false; } // Trigger the onContentBeforeSave event. $object_file = new JObject($file); $result = $dispatcher->trigger('onContentBeforeSave', array('com_media.file', &$object_file, true)); if (in_array(false, $result, true)) { // There are some errors in the plugins JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors = $object_file->getErrors()), implode('
', $errors))); return false; } if (!JFile::upload($file['tmp_name'], $file['filepath'])) { // Error in upload JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE')); return false; } else { // Trigger the onContentAfterSave event. $dispatcher->trigger('onContentAfterSave', array('com_media.file', &$object_file, true)); $this->setMessage(JText::sprintf('COM_MEDIA_UPLOAD_COMPLETE', substr($file['filepath'], strlen(COM_MEDIA_BASE)))); } } return true; } /** * Used as a callback for array_map, turns the multi-file input array into a sensible array of files * Also, removes illegal characters from the 'name' and sets a 'filepath' as the final destination of the file * * @param string - file name ($files['name']) * @param string - file type ($files['type']) * @param string - temporary name ($files['tmp_name']) * @param string - error info ($files['error']) * @param string - file size ($files['size']) * * @return array * @access protected */ protected function reformatFilesArray($name, $type, $tmp_name, $error, $size) { $name = JFile::makeSafe($name); return array( 'name' => $name, 'type' => $type, 'tmp_name' => $tmp_name, 'error' => $error, 'size' => $size, 'filepath' => JPath::clean(implode(DIRECTORY_SEPARATOR, array(COM_MEDIA_BASE, $this->folder, $name))) ); } /** * Check that the user is authorized to perform this action * * @param string $action - the action to be peformed (create or delete) * * @return boolean * @access protected */ protected function authoriseUser($action) { if (!JFactory::getUser()->authorise('core.' . strtolower($action), 'com_media')) { // User is not authorised JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_' . strtoupper($action) . '_NOT_PERMITTED')); return false; } return true; } /** * Deletes paths from the current path * * @since 1.5 */ public function delete() { JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN')); // Get some data from the request $tmpl = JRequest::getCmd('tmpl'); $paths = JRequest::getVar('rm', array(), '', 'array'); $folder = JRequest::getVar('folder', '', '', 'path'); $redirect = 'index.php?option=com_media&folder=' . $folder; if ($tmpl == 'component') { // We are inside the iframe $redirect .= '&view=mediaList&tmpl=component'; } $this->setRedirect($redirect); // Nothing to delete if (empty($paths)) { return true; } // Authorize the user if (!$this->authoriseUser('delete')) { return false; } // Set FTP credentials, if given JClientHelper::setCredentialsFromRequest('ftp'); JPluginHelper::importPlugin('content'); $dispatcher = JDispatcher::getInstance(); // Initialise variables. $ret = true; foreach ($paths as $path) { if ($path !== JFile::makeSafe($path)) { // filename is not safe $filename = htmlspecialchars($path, ENT_COMPAT, 'UTF-8'); JError::raiseWarning(100, JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FILE_WARNFILENAME', substr($filename, strlen(COM_MEDIA_BASE)))); continue; } $fullPath = JPath::clean(implode(DIRECTORY_SEPARATOR, array(COM_MEDIA_BASE, $folder, $path))); $object_file = new JObject(array('filepath' => $fullPath)); if (is_file($fullPath)) { // Trigger the onContentBeforeDelete event. $result = $dispatcher->trigger('onContentBeforeDelete', array('com_media.file', &$object_file)); if (in_array(false, $result, true)) { // There are some errors in the plugins JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors = $object_file->getErrors()), implode('
', $errors))); continue; } $ret &= JFile::delete($fullPath); // Trigger the onContentAfterDelete event. $dispatcher->trigger('onContentAfterDelete', array('com_media.file', &$object_file)); $this->setMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($fullPath, strlen(COM_MEDIA_BASE)))); } elseif (is_dir($fullPath)) { $contents = JFolder::files($fullPath, '.', true, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'index.html')); if (empty($contents)) { // Trigger the onContentBeforeDelete event. $result = $dispatcher->trigger('onContentBeforeDelete', array('com_media.folder', &$object_file)); if (in_array(false, $result, true)) { // There are some errors in the plugins JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors = $object_file->getErrors()), implode('
', $errors))); continue; } $ret &= JFolder::delete($fullPath); // Trigger the onContentAfterDelete event. $dispatcher->trigger('onContentAfterDelete', array('com_media.folder', &$object_file)); $this->setMessage(JText::sprintf('COM_MEDIA_DELETE_COMPLETE', substr($fullPath, strlen(COM_MEDIA_BASE)))); } else { // This makes no sense... JError::raiseWarning(100, JText::sprintf('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FOLDER_NOT_EMPTY', substr($fullPath, strlen(COM_MEDIA_BASE)))); } } } return $ret; } }