function getFolderTreeJoomla($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 $folders = Filesystem::directories($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' => Lang::txt('COM_MEDIA_MEDIA'), 'relative' => '', 'absolute' => $base); return $tree; }
/** * Remove unused group folders * * @param object $job \Components\Cron\Models\Job * @return boolean */ public function cleanGroupFolders(\Components\Cron\Models\Job $job) { // get group params $groupParameters = Component::params('com_groups'); // get group upload path $groupUploadPath = ltrim($groupParameters->get('uploadpath', '/site/groups'), DS); // get group folders $groupFolders = Filesystem::directories(PATH_APP . DS . $groupUploadPath); // loop through each group folder foreach ($groupFolders as $groupFolder) { // load group object for each folder $hubzeroGroup = \Hubzero\User\Group::getInstance(trim($groupFolder)); // if we dont have a group object delete folder if (!is_object($hubzeroGroup)) { // delete folder Filesystem::delete(PATH_APP . DS . $groupUploadPath . DS . $groupFolder); } } // job is no longer active return true; }
/** * Method to get the folders * * @return array Languages folders * @since 1.6 */ protected function getFolders() { if (is_null($this->folders)) { $path = $this->getPath(); $this->folders = Filesystem::directories($path, '.', false, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'pdf_fonts', 'overrides')); } return $this->folders; }
protected function getTypeOptionsFromLayouts($component, $view) { // Initialise variables. $options = array(); $layouts = array(); $layoutNames = array(); $templateLayouts = array(); $lang = Lang::getRoot(); // Get the layouts from the view folder. $path = PATH_CORE . '/components/' . $component . '/views/' . $view . '/tmpl'; $path2 = PATH_CORE . '/components/' . $component . '/site/views/' . $view . '/tmpl'; if (Filesystem::exists($path)) { $layouts = array_merge($layouts, Filesystem::files($path, '.xml$', false, true)); } else { if (Filesystem::exists($path2)) { $layouts = array_merge($layouts, Filesystem::files($path2, '.xml$', false, true)); } else { return $options; } } // build list of standard layout names foreach ($layouts as $layout) { $layout = trim($layout, '/'); // Ignore private layouts. if (strpos(basename($layout), '_') === false) { $file = $layout; // Get the layout name. $layoutNames[] = Filesystem::name(basename($layout)); } } // get the template layouts // TODO: This should only search one template -- the current template for this item (default of specified) $folders = Filesystem::directories(JPATH_SITE . '/templates', '', false, true); // Array to hold association between template file names and templates $templateName = array(); foreach ($folders as $folder) { if (Filesystem::exists($folder . '/html/' . $component . '/' . $view)) { $template = basename($folder); $lang->load('tpl_' . $template . '.sys', JPATH_SITE, null, false, true) || $lang->load('tpl_' . $template . '.sys', JPATH_SITE . '/templates/' . $template, null, false, true); $templateLayouts = Filesystem::files($folder . '/html/' . $component . '/' . $view, '.xml$', false, true); foreach ($templateLayouts as $layout) { $file = trim($layout, '/'); // Get the layout name. $templateLayoutName = Filesystem::name(basename($layout)); // add to the list only if it is not a standard layout if (array_search($templateLayoutName, $layoutNames) === false) { $layouts[] = $layout; // Set template name array so we can get the right template for the layout $templateName[$layout] = basename($folder); } } } } // Process the found layouts. foreach ($layouts as $layout) { $layout = trim($layout, '/'); // Ignore private layouts. if (strpos(basename($layout), '_') === false) { $file = $layout; // Get the layout name. $layout = Filesystem::name(basename($layout)); // Create the menu option for the layout. $o = new \Hubzero\Base\Object(); $o->title = ucfirst($layout); $o->description = ''; $o->request = array('option' => $component, 'view' => $view); // Only add the layout request argument if not the default layout. if ($layout != 'default') { // If the template is set, add in format template:layout so we save the template name $o->request['layout'] = isset($templateName[$file]) ? $templateName[$file] . ':' . $layout : $layout; } // Load layout metadata if it exists. if (is_file($file)) { // Attempt to load the xml file. if ($xml = simplexml_load_file($file)) { // Look for the first view node off of the root node. if ($menu = $xml->xpath('layout[1]')) { $menu = $menu[0]; // If the view is hidden from the menu, discard it and move on to the next view. if (!empty($menu['hidden']) && $menu['hidden'] == 'true') { unset($xml); unset($o); continue; } // Populate the title and description if they exist. if (!empty($menu['title'])) { $o->title = trim((string) $menu['title']); } if (!empty($menu->message[0])) { $o->description = trim((string) $menu->message[0]); } } } } // Add the layout to the options array. $options[] = $o; } } return $options; }
/** * 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; }
/** * method to get the directory states * * @return array states of directories */ public function getDirectory() { if (is_null($this->directories)) { $this->directories = array(); $cparams = Component::params('com_media'); $this->_addDirectory('administrator/components', JPATH_ADMINISTRATOR . '/components'); $this->_addDirectory('administrator/language', JPATH_ADMINISTRATOR . '/language'); // List all admin languages $admin_langs = Filesystem::directories(JPATH_ADMINISTRATOR . '/language'); foreach ($admin_langs as $alang) { $this->_addDirectory('administrator/language/' . $alang, JPATH_ADMINISTRATOR . '/language/' . $alang); } // List all manifests folders $manifests = Filesystem::directories(JPATH_ADMINISTRATOR . '/manifests'); foreach ($manifests as $_manifest) { $this->_addDirectory('administrator/manifests/' . $_manifest, JPATH_ADMINISTRATOR . '/manifests/' . $_manifest); } $this->_addDirectory('administrator/modules', JPATH_ADMINISTRATOR . '/modules'); $this->_addDirectory('administrator/templates', JPATH_THEMES); $this->_addDirectory('components', JPATH_SITE . '/components'); $this->_addDirectory($cparams->get('image_path'), JPATH_SITE . '/' . $cparams->get('image_path')); $image_folders = Filesystem::directories(JPATH_SITE . '/' . $cparams->get('image_path')); // List all images folders foreach ($image_folders as $folder) { $this->_addDirectory('images/' . $folder, JPATH_SITE . '/' . $cparams->get('image_path') . '/' . $folder); } $this->_addDirectory('language', JPATH_SITE . '/language'); // List all site languages $site_langs = Filesystem::directories(JPATH_SITE . '/language'); foreach ($site_langs as $slang) { $this->_addDirectory('language/' . $slang, JPATH_SITE . '/language/' . $slang); } $this->_addDirectory('libraries', JPATH_LIBRARIES); $this->_addDirectory('media', JPATH_SITE . '/media'); $this->_addDirectory('modules', JPATH_SITE . '/modules'); $this->_addDirectory('plugins', JPATH_PLUGINS); $plugin_groups = Filesystem::directories(JPATH_PLUGINS); foreach ($plugin_groups as $folder) { $this->_addDirectory('plugins/' . $folder, JPATH_PLUGINS . '/' . $folder); } $this->_addDirectory('templates', JPATH_SITE . '/templates'); $this->_addDirectory('configuration.php', JPATH_CONFIGURATION . '/configuration.php'); $this->_addDirectory('cache', PATH_APP . '/cache/site', 'COM_ADMIN_CACHE_DIRECTORY'); $this->_addDirectory('administrator/cache', PATH_APP . '/cache/admin', 'COM_ADMIN_CACHE_DIRECTORY'); $this->_addDirectory(Config::get('log_path', PATH_CORE . '/log'), Config::get('log_path', PATH_CORE . '/log'), 'COM_ADMIN_LOG_DIRECTORY'); $this->_addDirectory(Config::get('tmp_path', PATH_CORE . '/tmp'), Config::get('tmp_path', PATH_CORE . '/tmp'), 'COM_ADMIN_TEMP_DIRECTORY'); } return $this->directories; }