Ejemplo n.º 1
0
 /**
  * Set the upload path
  *
  * @param   string  $path  Path to set to
  * @return  object
  */
 public function setUploadDir($path)
 {
     $path = str_replace(' ', '_', trim($path));
     $path = Util::normalizePath($path);
     $this->uploadDir = $path ? $path : $this->uploadDir;
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Set the upload path
  *
  * @param   string  $path  Path to set to
  * @return  void
  */
 public function setUploadDir($path)
 {
     $path = trim($path);
     $path = \Hubzero\Filesystem\Util::normalizePath($path);
     $path = str_replace(' ', '_', $path);
     $this->_uploadDir = $path ? $path : $this->_uploadDir;
 }
Ejemplo n.º 3
0
 /**
  * Display an image.
  *
  * @param   string	$src  The source of the image
  *
  * @return  string  A <img> element if the specified file exists, otherwise, a null string
  *
  * @since   2.5
  */
 public static function image($src)
 {
     $src = preg_replace('#[^A-Z0-9\\-_\\./]#i', '', $src);
     $file = JPATH_SITE . '/' . $src;
     \Hubzero\Filesystem\Util::checkPath($file);
     if (!file_exists($file)) {
         return '';
     }
     return '<img src="' . Request::root() . $src . '" alt="" />';
 }
Ejemplo n.º 4
0
 /**
  * Set the upload path
  *
  * @param   string  $path  Path to set to
  * @return  object
  */
 public function setUploadDir($path)
 {
     $path = str_replace(' ', '_', trim($path));
     $path = Util::normalizePath($path);
     if (substr($path, 0, strlen(PATH_APP)) == PATH_APP) {
         $path = substr($path, strlen(PATH_APP));
     }
     $this->uploadDir = $path ? $path : $this->uploadDir;
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * Method to auto-populate the model state.
  *
  * Note. Calling getState in this method will result in recursion.
  *
  * @return  void
  * @since   1.6
  */
 protected function populateState()
 {
     // Set the component (option) we are dealing with.
     $component = Request::getCmd('component');
     $this->setState('component.option', $component);
     // Set an alternative path for the configuration file.
     if ($path = Request::getString('path')) {
         $path = Filesystem::cleanPath(PATH_ROOT . '/' . $path);
         \Hubzero\Filesystem\Util::checkCheck($path);
         $this->setState('component.path', $path);
     }
 }
Ejemplo n.º 6
0
 /**
  * Get the options for the list.
  *
  * @param   object  &$node  XMLElement node object containing the settings for the element
  * @return  string
  */
 protected function _getOptions(&$node)
 {
     $v = (int) $node['client_id'];
     $clientId = $v ? $v : 0;
     $options = array();
     $path1 = null;
     $path2 = null;
     // Load template entries for each menuid
     $db = \App::get('db');
     $query = $db->getQuery(true);
     $query->select('template');
     $query->from('#__template_styles');
     $query->where('client_id = ' . (int) $clientId);
     $query->where('home = 1');
     $db->setQuery($query);
     $template = $db->loadResult();
     if ($module = (string) $node['module']) {
         $base = $clientId == 1 ? JPATH_ADMINISTRATOR : JPATH_SITE;
         $module = preg_replace('#\\W#', '', $module);
         $path1 = $base . '/modules/' . $module . '/tmpl';
         $path2 = $base . '/templates/' . $template . '/html/' . $module;
         $options[] = Builder\Select::option('', '');
     }
     if ($path1 && $path2) {
         $path1 = Util::normalizePath($path1);
         $path2 = Util::normalizePath($path2);
         $files = App::get('filesystem')->files($path1, '^[^_]*\\.php$');
         foreach ($files as $file) {
             $options[] = Builder\Select::option(App::get('filesystem')->extension($file));
         }
         if (is_dir($path2) && ($files = App::get('filesystem')->files($path2, '^[^_]*\\.php$'))) {
             $options[] = Builder\Select::optgroup(App::get('language')->txt('JOPTION_FROM_DEFAULT'));
             foreach ($files as $file) {
                 $options[] = Builder\Select::option(App::get('filesystem')->extension($file));
             }
             $options[] = Builder\Select::optgroup(App::get('language')->txt('JOPTION_FROM_DEFAULT'));
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::_getOptions($node), $options);
     return $options;
 }
Ejemplo n.º 7
0
 /**
  * Get the options for the list.
  *
  * @param   object  &$node  XMLElement node object containing the settings for the element
  * @return  array
  */
 protected function _getOptions(&$node)
 {
     $options = array();
     $path1 = null;
     $path2 = null;
     // Load template entries for each menuid
     $db = \App::get('db');
     $query = 'SELECT template' . ' FROM #__template_styles' . ' WHERE client_id = 0 AND home = 1';
     $db->setQuery($query);
     $template = $db->loadResult();
     $view = (string) $node['view'];
     $extn = (string) $node['extension'];
     if ($view && $extn) {
         $view = preg_replace('#\\W#', '', $view);
         $extn = preg_replace('#\\W#', '', $extn);
         $path1 = PATH_CORE . '/components/' . $extn . '/site/views/' . $view . '/tmpl';
         $path2 = PATH_ROOT . '/templates/' . $template . '/html/' . $extn . '/' . $view;
         $options[] = Builder\Select::option('', App::get('language')->txt('JOPTION_USE_MENU_REQUEST_SETTING'));
     }
     if ($path1 && $path2) {
         $path1 = Util::normalizePath($path1);
         $path2 = Util::normalizePath($path2);
         $files = App::get('filesystem')->files($path1, '^[^_]*\\.php$');
         foreach ($files as $file) {
             $options[] = Builder\Select::option(App::get('filesystem')->extension($file));
         }
         if (is_dir($path2) && ($files = App::get('filesystem')->files($path2, '^[^_]*\\.php$'))) {
             $options[] = Builder\Select::optgroup(App::get('language')->txt('JOPTION_FROM_DEFAULT_TEMPLATE'));
             foreach ($files as $file) {
                 $options[] = Builder\Select::option(App::get('filesystem')->extension($file));
             }
             $options[] = Builder\Select::optgroup(App::get('language')->txt('JOPTION_FROM_DEFAULT_TEMPLATE'));
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::_getOptions($node), $options);
     return $options;
 }
Ejemplo n.º 8
0
 /**
  * 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 = Filesystem::files($basePath);
         $folderList = Filesystem::directories($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 \Hubzero\Base\Object();
                 $tmp->name = $file;
                 $tmp->title = $file;
                 $tmp->path = str_replace(DIRECTORY_SEPARATOR, '/', \Hubzero\Filesystem\Util::normalizePath($basePath . '/' . $file));
                 $tmp->path_relative = str_replace($mediaBase, '', $tmp->path);
                 $tmp->size = filesize($tmp->path);
                 $ext = strtolower(Filesystem::extension($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
                     // 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 \Hubzero\Base\Object();
             $tmp->name = basename($folder);
             $tmp->path = str_replace(DIRECTORY_SEPARATOR, '/', \Hubzero\Filesystem\Util::normalizePath($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;
 }
Ejemplo n.º 9
0
 /**
  * Upload a file
  *
  * @since 1.5
  */
 function upload()
 {
     $params = Component::params('com_media');
     // Check for request forgeries
     if (!Session::checkToken(['get', 'post'], true)) {
         $response = array('status' => '0', 'error' => Lang::txt('JINVALID_TOKEN'));
         echo json_encode($response);
         return;
     }
     // Get the user
     $log = JLog::getInstance('upload.error.php');
     // Get some data from the request
     $file = Request::getVar('Filedata', '', 'files', 'array');
     $folder = Request::getVar('folder', '', '', 'path');
     $return = Request::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' => Lang::txt('COM_MEDIA_ERROR_WARNFILETOOLARGE'));
         echo json_encode($response);
         return;
     }
     // Set FTP credentials, if given
     JClientHelper::setCredentialsFromRequest('ftp');
     // Make the filename safe
     $file['name'] = Filesystem::clean($file['name']);
     if (isset($file['name'])) {
         // The request is valid
         $err = null;
         $filepath = \Hubzero\Filesystem\Util::normalizePath(COM_MEDIA_BASE . '/' . $folder . '/' . strtolower($file['name']));
         if (!MediaHelper::canUpload($file, $err)) {
             $log->addEntry(array('comment' => 'Invalid: ' . $filepath . ': ' . $err));
             $response = array('status' => '0', 'error' => Lang::txt($err));
             echo json_encode($response);
             return;
         }
         // Trigger the onContentBeforeSave event.
         $object_file = new \Hubzero\Base\Object($file);
         $object_file->filepath = $filepath;
         $result = Event::trigger('content.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' => Lang::txts('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors = $object_file->getErrors()), implode('<br />', $errors)));
             echo json_encode($response);
             return;
         }
         if (Filesystem::exists($filepath)) {
             // File exists
             $log->addEntry(array('comment' => 'File exists: ' . $filepath . ' by user_id ' . User::get('id')));
             $response = array('status' => '0', 'error' => Lang::txt('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::get('id')));
             $response = array('status' => '0', 'error' => Lang::txt('COM_MEDIA_ERROR_CREATE_NOT_PERMITTED'));
             echo json_encode($response);
             return;
         }
         $file = (array) $object_file;
         if (!Filesystem::upload($file['tmp_name'], $file['filepath'])) {
             // Error in upload
             $log->addEntry(array('comment' => 'Error on upload: ' . $filepath));
             $response = array('status' => '0', 'error' => Lang::txt('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE'));
             echo json_encode($response);
             return;
         } else {
             // Trigger the onContentAfterSave event.
             Event::trigger('content.onContentAfterSave', array('com_media.file', &$object_file, true));
             $log->addEntry(array('comment' => $folder));
             $response = array('status' => '1', 'error' => Lang::txt('COM_MEDIA_UPLOAD_COMPLETE', substr($file['filepath'], strlen(COM_MEDIA_BASE))));
             echo json_encode($response);
             return;
         }
     } else {
         $response = array('status' => '0', 'error' => Lang::txt('COM_MEDIA_ERROR_BAD_REQUEST'));
         echo json_encode($response);
         return;
     }
 }
Ejemplo n.º 10
0
 /**
  * Add a directory where Html should search for helpers. You may
  * either pass a string or an array of directories.
  *
  * @param   string  $path  A path to search.
  * @return  array   An array with directory elements
  */
 public function addIncludePath($path = '')
 {
     // Force path to array
     settype($path, 'array');
     // Loop through the path directories
     foreach ($path as $dir) {
         if (!empty($dir) && !in_array($dir, self::$paths)) {
             array_unshift(self::$paths, \Hubzero\Filesystem\Util::normalizePath($dir));
         }
     }
     return self::$paths;
 }
Ejemplo n.º 11
0
 /**
  * Method to get an array of data items.
  *
  * @return	mixed	An array of data items on success, false on failure.
  * @since	1.6
  */
 public function getItems()
 {
     if (!isset($this->items)) {
         $lang = Lang::getRoot();
         $search = $this->getState('filter.search');
         $state = $this->getState('filter.state');
         $clientId = $this->getState('filter.client_id');
         $filter_template = $this->getState('filter.template');
         $type = $this->getState('filter.type');
         $ordering = $this->getState('list.ordering');
         $direction = $this->getState('list.direction');
         $limitstart = $this->getState('list.start');
         $limit = $this->getState('list.limit');
         $client = JApplicationHelper::getClientInfo($clientId);
         if ($type != 'template') {
             // Get the database object and a new query object.
             $query = $this->_db->getQuery(true);
             $query->select('DISTINCT(position) as value');
             $query->from('#__modules');
             $query->where($this->_db->quoteName('client_id') . ' = ' . (int) $clientId);
             if ($search) {
                 $query->where('position LIKE ' . $this->_db->quote('%' . $this->_db->escape($search, true) . '%'));
             }
             $this->_db->setQuery($query);
             $positions = $this->_db->loadObjectList('value');
             // Check for a database error.
             if ($error = $this->_db->getErrorMsg()) {
                 $this->setError($error);
                 return false;
             }
             foreach ($positions as $value => $position) {
                 $positions[$value] = array();
             }
         } else {
             $positions = array();
         }
         // Load the positions from the installed templates.
         foreach (ModulesHelper::getTemplates($clientId) as $template) {
             $path = \Hubzero\Filesystem\Util::normalizePath($client->path . '/templates/' . $template->element . '/templateDetails.xml');
             if (file_exists($path)) {
                 $xml = simplexml_load_file($path);
                 if (isset($xml->positions[0])) {
                     $lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, true) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, true);
                     foreach ($xml->positions[0] as $position) {
                         $value = (string) $position['value'];
                         $label = (string) $position;
                         if (!$value) {
                             $value = $label;
                             $label = preg_replace('/[^a-zA-Z0-9_\\-]/', '_', 'TPL_' . $template->element . '_POSITION_' . $value);
                             $altlabel = preg_replace('/[^a-zA-Z0-9_\\-]/', '_', 'COM_MODULES_POSITION_' . $value);
                             if (!$lang->hasKey($label) && $lang->hasKey($altlabel)) {
                                 $label = $altlabel;
                             }
                         }
                         if ($type == 'user' || $state != '' && $state != $template->enabled) {
                             unset($positions[$value]);
                         } elseif (preg_match(chr(1) . $search . chr(1) . 'i', $value) && ($filter_template == '' || $filter_template == $template->element)) {
                             if (!isset($positions[$value])) {
                                 $positions[$value] = array();
                             }
                             $positions[$value][$template->name] = $label;
                         }
                     }
                 }
             }
         }
         $this->total = count($positions);
         if ($limitstart >= $this->total) {
             $limitstart = $limitstart < $limit ? 0 : $limitstart - $limit;
             $this->setState('list.start', $limitstart);
         }
         if ($ordering == 'value') {
             if ($direction == 'asc') {
                 ksort($positions);
             } else {
                 krsort($positions);
             }
         } else {
             if ($direction == 'asc') {
                 asort($positions);
             } else {
                 arsort($positions);
             }
         }
         $this->items = array_slice($positions, $limitstart, $limit ? $limit : null);
     }
     return $this->items;
 }
Ejemplo n.º 12
0
 /**
  * List all group files
  *
  * @return  array
  */
 public function listfilesTask()
 {
     // set the neeced layout
     $this->view->setLayout('filelist');
     //get request vars
     $this->view->folders = array();
     $this->view->files = array();
     $this->view->type = \Hubzero\Utility\Sanitize::paranoid(Request::getWord('type', ''));
     $this->view->relpath = Request::getVar('path', '/');
     // make sure we default to uploads folder for non-super groups
     if ($this->group->get('type') != 3 && (!$this->view->relpath || $this->view->relpath == '/')) {
         $this->view->relpath = '/uploads';
     }
     $this->view->relpath = \Hubzero\Filesystem\Util::normalizePath($this->view->relpath);
     $this->view->relpath = explode('/', $this->view->relpath);
     foreach ($this->view->relpath as $i => $p) {
         $this->view->relpath[$i] = preg_replace('/[^a-zA-Z0-9_\\-]/', '', $p);
     }
     $this->view->relpath = implode(DS, $this->view->relpath);
     //build path to the group folder
     $this->path = rtrim($this->path, DS) . $this->view->relpath;
     // if we have a directory
     if (is_dir($this->path)) {
         //get list of files
         $folders = Filesystem::directories($this->path, '.', false);
         $files = Filesystem::files($this->path, '.', false);
         // filter by type
         if (isset($this->view->type) && $this->view->type != '') {
             foreach ($files as $k => $file) {
                 $fileInfo = pathinfo($file);
                 $ext = strtolower($fileInfo['extension']);
                 if ($this->view->type == 'images' && !in_array($ext, array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff'))) {
                     unset($files[$k]);
                 } else {
                     if ($this->view->type == 'files' && in_array($ext, array('jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff'))) {
                         unset($files[$k]);
                     }
                 }
             }
         }
         //reset array keys
         $this->view->folders = array_values($folders);
         $this->view->files = array_values($files);
     }
     // pass vars to view
     //$this->view->config = $this->config;
     $this->view->group = $this->group;
     $this->view->path = $this->path;
     // get view notifications
     $this->view->notifications = $this->getNotifications() ? $this->getNotifications() : array();
     //display view
     $this->view->display();
 }
Ejemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function mimetype($path)
 {
     if (!($contents = $this->read($path))) {
         return false;
     }
     return Util::guessMimeType($path, $contents);
 }
Ejemplo n.º 14
0
 /**
  * Method to get the field input for module layouts.
  *
  * @return  string  The field input.
  */
 protected function getInput()
 {
     // Get the client id.
     $clientId = $this->element['client_id'];
     if (is_null($clientId) && $this->form instanceof Form) {
         $clientId = $this->form->getValue('client_id');
     }
     $clientId = (int) $clientId;
     $client = ClientManager::client($clientId);
     // Get the module.
     $module = (string) $this->element['module'];
     if (empty($module) && $this->form instanceof Form) {
         $module = $this->form->getValue('module');
     }
     $module = preg_replace('#\\W#', '', $module);
     // Get the template.
     $template = (string) $this->element['template'];
     $template = preg_replace('#\\W#', '', $template);
     // Get the style.
     if ($this->form instanceof Form) {
         $template_style_id = $this->form->getValue('template_style_id');
     }
     $template_style_id = preg_replace('#\\W#', '', $template_style_id);
     // If an extension and view are present build the options.
     if ($module && $client) {
         // Load language file
         $lang = App::get('language');
         $lang->load($module . '.sys', $client->path, null, false, true) || $lang->load($module . '.sys', $client->path . '/modules/' . $module, null, false, true);
         // Get the database object and a new query object.
         $db = App::get('db');
         $query = $db->getQuery(true);
         // Build the query.
         $query->select('element, name');
         $query->from('#__extensions as e');
         $query->where('e.client_id = ' . (int) $clientId);
         $query->where('e.type = ' . $db->quote('template'));
         $query->where('e.enabled = 1');
         if ($template) {
             $query->where('e.element = ' . $db->quote($template));
         }
         if ($template_style_id) {
             $query->join('LEFT', '#__template_styles as s on s.template=e.element');
             $query->where('s.id=' . (int) $template_style_id);
         }
         // Set the query and load the templates.
         $db->setQuery($query);
         $templates = $db->loadObjectList('element');
         // Check for a database error.
         if ($db->getErrorNum()) {
             App::abort(500, $db->getErrorMsg());
         }
         // Build the search paths for module layouts.
         $module_path = Util::normalizePath($client->path . '/modules/' . $module . '/tmpl');
         // Prepare array of component layouts
         $module_layouts = array();
         // Prepare the grouped list
         $groups = array();
         // Add the layout options from the module path.
         if (is_dir($module_path) && ($module_layouts = App::get('filesystem')->files($module_path, '^[^_]*\\.php$'))) {
             // Create the group for the module
             $groups['_'] = array();
             $groups['_']['id'] = $this->id . '__';
             $groups['_']['text'] = $lang->txt('JOPTION_FROM_MODULE');
             $groups['_']['items'] = array();
             foreach ($module_layouts as $file) {
                 // Add an option to the module group
                 $value = App::get('filesystem')->name($file);
                 $text = $lang->hasKey($key = strtoupper($module . '_LAYOUT_' . $value)) ? JText::_($key) : $value;
                 $groups['_']['items'][] = Dropdown::option('_:' . $value, $text);
             }
         }
         // Loop on all templates
         if ($templates) {
             foreach ($templates as $template) {
                 // Load language file
                 $lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, true) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, true);
                 $template_path = Util::normalizePath($client->path . '/templates/' . $template->element . '/html/' . $module);
                 // Add the layout options from the template path.
                 if (is_dir($template_path) && ($files = App::get('filesystem')->files($template_path, '^[^_]*\\.php$'))) {
                     foreach ($files as $i => $file) {
                         // Remove layout that already exist in component ones
                         if (in_array($file, $module_layouts)) {
                             unset($files[$i]);
                         }
                     }
                     if (count($files)) {
                         // Create the group for the template
                         $groups[$template->element] = array();
                         $groups[$template->element]['id'] = $this->id . '_' . $template->element;
                         $groups[$template->element]['text'] = $lang->txt('JOPTION_FROM_TEMPLATE', $template->name);
                         $groups[$template->element]['items'] = array();
                         foreach ($files as $file) {
                             // Add an option to the template group
                             $value = App::get('filesystem')->name($file);
                             $text = $lang->hasKey($key = strtoupper('TPL_' . $template->element . '_' . $module . '_LAYOUT_' . $value)) ? $lang->txt($key) : $value;
                             $groups[$template->element]['items'][] = Dropdown::option($template->element . ':' . $value, $text);
                         }
                     }
                 }
             }
         }
         // Compute attributes for the grouped list
         $attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
         // Prepare HTML code
         $html = array();
         // Compute the current selected values
         $selected = array($this->value);
         // Add a grouped list
         $html[] = Dropdown::groupedlist($groups, $this->name, array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected));
         return implode($html);
     }
     return '';
 }
Ejemplo n.º 15
0
 /**
  * Method to get a list of items.
  *
  * @return	mixed	An array of objects on success, false on failure.
  */
 public function getItems()
 {
     // Get the list of items from the database.
     $items = parent::getItems();
     // Initialise variables.
     $client = \Hubzero\Base\ClientManager::client($this->getState('filter.client_id', 0));
     $client->path = PATH_CORE;
     $lang = Lang::getRoot();
     // Loop through the results to add the XML metadata,
     // and load language support.
     foreach ($items as &$item) {
         $path = \Hubzero\Filesystem\Util::normalizePath($client->path . '/modules/' . $item->module . '/' . $item->module . '.xml');
         if (file_exists($path)) {
             $item->xml = simplexml_load_file($path);
         } else {
             $item->xml = null;
         }
         // 1.5 Format; Core files or language packs then
         // 1.6 3PD Extension Support
         $lang->load($item->module . '.sys', PATH_APP . DS . 'bootstrap' . DS . $client->name, null, false, true) || $lang->load($item->module . '.sys', PATH_APP . '/modules/' . $item->module, null, false, true) || $lang->load($item->module . '.sys', $client->path . '/modules/' . $item->module, null, false, true);
         $item->name = Lang::txt($item->name);
         if (isset($item->xml) && ($text = trim($item->xml->description))) {
             $item->desc = Lang::txt($text);
         } else {
             $item->desc = Lang::txt('COM_MODULES_NODESCRIPTION');
         }
     }
     $items = \Hubzero\Utility\Arr::sortObjects($items, 'name', 1, true, $lang->getLocale());
     // TODO: Use the cached XML from the extensions table?
     return $items;
 }
Ejemplo n.º 16
0
 /**
  * Makes directory name safe to use.
  *
  * @param   string  $directory  The directory to sanitise.
  * @return  string  The sanitised string.
  */
 public function cleanDirectory($directory)
 {
     return Util::normalizeDirectory($directory);
 }
Ejemplo n.º 17
0
 /**
  * Lists all files and folders for a given directory
  *
  * @return  void
  */
 public function listTask()
 {
     $dir = Request::getVar('dir', '');
     // Build upload path
     $path = $this->path . ($dir ? DS . trim($dir, DS) : '');
     $path = Util::normalizePath($path);
     $folders = array();
     $docs = array();
     if (is_dir($path)) {
         // Loop through all files and separate them into arrays of images, folders, and other
         $dirIterator = new \DirectoryIterator($path);
         foreach ($dirIterator as $file) {
             if ($file->isDot()) {
                 continue;
             }
             if ($file->isDir()) {
                 $name = $file->getFilename();
                 $folders[$path . DS . $name] = $name;
                 continue;
             }
             if ($file->isFile()) {
                 $name = $file->getFilename();
                 if ('cvs' == strtolower($name) || '.svn' == strtolower($name)) {
                     continue;
                 }
                 $docs[$path . DS . $name] = $name;
             }
         }
         ksort($folders);
         ksort($docs);
     }
     $this->view->set('docs', $docs)->set('folders', $folders)->set('group', $this->group)->set('path', $path)->set('dir', $dir)->setErrors($this->getErrors())->setLayout('list')->display();
 }
Ejemplo n.º 18
0
 /**
  * Method to store the source file contents.
  *
  * @param	array	The souce data to save.
  *
  * @return	boolean	True on success, false otherwise and internal error set.
  * @since	1.6
  */
 public function save($data)
 {
     // Get the template.
     $template = $this->getTemplate();
     if (empty($template)) {
         return false;
     }
     $fileName = $this->getState('filename');
     $client = JApplicationHelper::getClientInfo($template->client_id);
     $filePath = \Hubzero\Filesystem\Util::normalizePath($client->path . '/templates/' . $template->element . '/' . $fileName);
     // Set FTP credentials, if given.
     JClientHelper::setCredentialsFromRequest('ftp');
     $ftp = JClientHelper::getCredentials('ftp');
     // Try to make the template file writeable.
     if (!$ftp['enabled'] && JPath::isOwner($filePath) && !Filesystem::setPermissions($filePath, '0644')) {
         $this->setError(Lang::txt('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_WRITABLE'));
         return false;
     }
     // Trigger the onExtensionBeforeSave event.
     $result = Event::trigger('extension.onExtensionBeforeSave', array('com_templates.source', &$data, false));
     if (in_array(false, $result, true)) {
         $this->setError($table->getError());
         return false;
     }
     // [!] HUBZERO - Force line endings to be consistent with the server environment
     $data['source'] = preg_replace('~\\R~u', PHP_EOL, $data['source']);
     $return = Filesystem::write($filePath, $data['source']);
     // Try to make the template file unwriteable.
     if (!$ftp['enabled'] && JPath::isOwner($filePath) && !Filesystem::setPermissions($filePath, '0444')) {
         $this->setError(Lang::txt('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_UNWRITABLE'));
         return false;
     } elseif (!$return) {
         $this->setError(Lang::txt('COM_TEMPLATES_ERROR_FAILED_TO_SAVE_FILENAME', $fileName));
         return false;
     }
     // Trigger the onExtensionAfterSave event.
     Event::trigger('extension.onExtensionAfterSave', array('com_templates.source', &$table, false));
     return true;
 }
Ejemplo n.º 19
0
 /**
  * Create a folder
  *
  * @param string $path Path of the folder to create
  * @since 1.5
  */
 public function create()
 {
     // Check for request forgeries
     Session::checkToken(['get', 'post']);
     $folder = Request::getCmd('foldername', '');
     $folderCheck = Request::getVar('foldername', null, '', 'string', JREQUEST_ALLOWRAW);
     $parent = Request::getVar('folderbase', '', '', 'path');
     $this->setRedirect('index.php?option=com_media&folder=' . $parent . '&tmpl=' . Request::getCmd('tmpl', 'index'));
     if (strlen($folder) > 0) {
         if (!User::authorise('core.create', 'com_media')) {
             // User is not authorised to delete
             Notify::warning(Lang::txt('JLIB_APPLICATION_ERROR_CREATE_NOT_PERMITTED'));
             return false;
         }
         // Set FTP credentials, if given
         JClientHelper::setCredentialsFromRequest('ftp');
         Request::setVar('folder', $parent);
         if ($folderCheck !== null && $folder !== $folderCheck) {
             $this->setMessage(Lang::txt('COM_MEDIA_ERROR_UNABLE_TO_CREATE_FOLDER_WARNDIRNAME'));
             return false;
         }
         $path = \Hubzero\Filesystem\Util::normalizePath(COM_MEDIA_BASE . '/' . $parent . '/' . $folder);
         if (!is_dir($path) && !is_file($path)) {
             // Trigger the onContentBeforeSave event.
             $object_file = new \Hubzero\Base\Object(array('filepath' => $path));
             $result = Event::trigger('content.onContentBeforeSave', array('com_media.folder', &$object_file, true));
             if (in_array(false, $result, true)) {
                 // There are some errors in the plugins
                 Notify::warning(Lang::txts('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors = $object_file->getErrors()), implode('<br />', $errors)));
                 return false;
             }
             Filesystem::makeDirectory($path);
             $data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>";
             Filesystem::write($path . "/index.html", $data);
             // Trigger the onContentAfterSave event.
             Event::trigger('content.onContentAfterSave', array('com_media.folder', &$object_file, true));
             $this->setMessage(Lang::txt('COM_MEDIA_CREATE_COMPLETE', substr($path, strlen(COM_MEDIA_BASE))));
         }
         Request::setVar('folder', $parent ? $parent . '/' . $folder : $folder);
     }
 }