public function extract($archive, $destination, $options = array()) { // Initialise variables. $this->_data = null; $this->_metadata = null; if (!($this->_data = MFile::read($archive))) { $this->set('error.message', 'Unable to read archive'); return MError::raiseWarning(100, $this->get('error.message')); } if (!$this->_getTarInfo($this->_data)) { return MError::raiseWarning(100, $this->get('error.message')); } for ($i = 0, $n = count($this->_metadata); $i < $n; $i++) { $type = strtolower($this->_metadata[$i]['type']); if ($type == 'file' || $type == 'unix file') { $buffer = $this->_metadata[$i]['data']; $path = MPath::clean($destination . '/' . $this->_metadata[$i]['name']); // Make sure the destination folder exists if (!MFolder::create(dirname($path))) { $this->set('error.message', 'Unable to create destination'); return MError::raiseWarning(100, $this->get('error.message')); } if (MFile::write($path, $buffer) === false) { $this->set('error.message', 'Unable to write entry'); return MError::raiseWarning(100, $this->get('error.message')); } } } return true; }
public static function getStores() { mimport('framework.filesystem.folder'); $handlers = MFolder::files(dirname(__FILE__) . '/storage', '.php'); $names = array(); foreach ($handlers as $handler) { $name = substr($handler, 0, strrpos($handler, '.')); $class = 'MCacheStorage' . $name; if (!class_exists($class)) { include_once dirname(__FILE__) . '/storage/' . $name . '.php'; } if (call_user_func_array(array(trim($class), 'test'), array())) { $names[] = $name; } } return $names; }
protected function getOptions() { // Initialize variables. $options = array(); // Initialize some field attributes. $filter = (string) $this->element['filter']; $exclude = (string) $this->element['exclude']; $stripExt = (string) $this->element['stripext']; $hideNone = (string) $this->element['hide_none']; $hideDefault = (string) $this->element['hide_default']; // Get the path in which to search for file options. $path = (string) $this->element['directory']; if (!is_dir($path)) { $path = MPATH_ROOT . '/' . $path; } // Prepend some default options based on field attributes. if (!$hideNone) { $options[] = MHtml::_('select.option', '-1', MText::alt('MOPTION_DO_NOT_USE', preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname))); } if (!$hideDefault) { $options[] = MHtml::_('select.option', '', MText::alt('MOPTION_USE_DEFAULT', preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname))); } // Get a list of files in the search path with the given filter. $files = MFolder::files($path, $filter); // Build the options list from the list of files. if (is_array($files)) { foreach ($files as $file) { // Check to see if the file is in the exclude mask. if ($exclude) { if (preg_match(chr(1) . $exclude . chr(1), $file)) { continue; } } // If the extension is to be stripped, do it. if ($stripExt) { $file = MFile::stripExt($file); } $options[] = MHtml::_('select.option', $file, $file); } } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
public static function images($name, $active = null, $javascript = null, $directory = null, $extensions = "bmp|gif|jpg|png") { if (!$directory) { $directory = '/images/'; } if (!$javascript) { $javascript = "onchange=\"if (document.forms.adminForm." . $name . ".options[selectedIndex].value!='') {document.imagelib.src='..{$directory}' + document.forms.adminForm." . $name . ".options[selectedIndex].value} else {document.imagelib.src='media/system/images/blank.png'}\""; } mimport('framework.filesystem.folder'); $imageFiles = MFolder::files(MPATH_SITE . '/' . $directory); $images = array(MHtml::_('select.option', '', MText::_('MOPTION_SELECT_IMAGE'))); foreach ($imageFiles as $file) { if (preg_match('#(' . $extensions . ')$#', $file)) { $images[] = MHtml::_('select.option', $file); } } $images = MHtml::_('select.genericlist', $images, $name, array('list.attr' => 'class="inputbox" size="1" ' . $javascript, 'list.select' => $active)); return $images; }
public static function getConnectors() { // Instantiate variables. $connectors = array(); // Get a list of types. $types = MFolder::files(dirname(__FILE__) . '/database'); // Loop through the types and find the ones that are available. foreach ($types as $type) { // Ignore some files. if ($type == 'index.html' || stripos($type, 'importer') || stripos($type, 'exporter') || stripos($type, 'query') || stripos($type, 'exception')) { continue; } // Derive the class name from the type. $class = str_ireplace(array('.php', 'sql'), array('', 'SQL'), 'MDatabase' . ucfirst(trim($type))); // If the class doesn't exist, let's look for it and register it. if (!class_exists($class)) { // Derive the file path for the driver class. $path = dirname(__FILE__) . '/database/' . $type; // If the file exists register the class with our class loader. if (file_exists($path)) { MLoader::register($class, $path); } else { continue; } } // If the class still doesn't exist we have nothing left to do but look at the next type. We did our best. if (!class_exists($class)) { continue; } // Sweet! Our class exists, so now we just need to know if it passes it's test method. if (call_user_func_array(array($class, 'test'), array())) { // Connector names should not have file extensions. $connectors[] = str_ireplace('.php', '', $type); } } return $connectors; }
public function clean($group, $mode = null) { mimport('framework.filesystem.folder'); if (trim($group) == '') { $clmode = 'notgroup'; } if ($mode == null) { $clmode = 'group'; } switch ($mode) { case 'notgroup': $clmode = 'notingroup'; $success = self::$CacheLiteInstance->clean($group, $clmode); break; case 'group': if (is_dir($this->_root . '/' . $group)) { $clmode = $group; self::$CacheLiteInstance->setOption('cacheDir', $this->_root . '/' . $group . '/'); $success = self::$CacheLiteInstance->clean($group, $clmode); MFolder::delete($this->_root . '/' . $group); } else { $success = true; } break; default: if (is_dir($this->_root . '/' . $group)) { $clmode = $group; self::$CacheLiteInstance->setOption('cacheDir', $this->_root . '/' . $group . '/'); $success = self::$CacheLiteInstance->clean($group, $clmode); } else { $success = true; } break; } if ($success == true) { return $success; } else { return false; } }
protected function getInput() { // Get the client id. $clientId = $this->element['client_id']; if (is_null($clientId) && $this->form instanceof MForm) { $clientId = $this->form->getValue('client_id'); } $clientId = (int) $clientId; $client = MApplicationHelper::getClientInfo($clientId); // Get the module. $module = (string) $this->element['module']; if (empty($module) && $this->form instanceof MForm) { $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 MForm) { $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 = MFactory::getLanguage(); $lang->load($module . '.sys', $client->path, null, false, false) || $lang->load($module . '.sys', $client->path . '/modules/' . $module, null, false, false) || $lang->load($module . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load($module . '.sys', $client->path . '/modules/' . $module, $lang->getDefault(), false, false); // Get the database object and a new query object. $db = MFactory::getDBO(); $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()) { MError::raiseWarning(500, $db->getErrorMsg()); } // Build the search paths for module layouts. $module_path = MPath::clean($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 = MFolder::files($module_path, '^[^_]*\\.php$'))) { // Create the group for the module $groups['_'] = array(); $groups['_']['id'] = $this->id . '__'; $groups['_']['text'] = MText::sprintf('MOPTION_FROM_MODULE'); $groups['_']['items'] = array(); foreach ($module_layouts as $file) { // Add an option to the module group $value = MFile::stripExt($file); $text = $lang->hasKey($key = strtoupper($module . '_LAYOUT_' . $value)) ? MText::_($key) : $value; $groups['_']['items'][] = MHtml::_('select.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, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, $lang->getDefault(), false, false); $template_path = MPath::clean($client->path . '/templates/' . $template->element . '/html/' . $module); // Add the layout options from the template path. if (is_dir($template_path) && ($files = MFolder::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'] = MText::sprintf('MOPTION_FROM_TEMPLATE', $template->name); $groups[$template->element]['items'] = array(); foreach ($files as $file) { // Add an option to the template group $value = MFile::stripExt($file); $text = $lang->hasKey($key = strtoupper('TPL_' . $template->element . '_' . $module . '_LAYOUT_' . $value)) ? MText::_($key) : $value; $groups[$template->element]['items'][] = MHtml::_('select.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[] = MHtml::_('select.groupedlist', $groups, $this->name, array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected)); return implode($html); } else { return ''; } }
public static function getMStreams() { static $streams; if (!$streams) { $streams = array_map(array('MFile', 'stripExt'), MFolder::files(dirname(__FILE__) . '/streams', '.php')); } return $streams; }
protected function initFile() { // If the file doesn't already exist we need to create it and generate the file header. if (!is_file($this->path)) { // Make sure the folder exists in which to create the log file. MFolder::create(dirname($this->path)); // Build the log file header. $head = $this->generateFileHeader(); } else { $head = false; } // Open the file for writing (append mode). if (!($this->file = fopen($this->path, 'a'))) { // Throw exception. } if ($head) { if (!fputs($this->file, $head)) { throw new LogException(); } } }
public function postflight($type, $parent) { if (MFolder::copy(MPath::clean(MPATH_WP_PLG . '/miwosql/languages'), MPath::clean(MPATH_WP_CNT . '/miwi/languages'), null, true)) { MFolder::delete(MPath::clean(MPATH_WP_PLG . '/miwosql/languages')); } }
protected static function &_load($module_id = null) { /*if (self::$modules !== null) { return self::$modules; }*/ mimport('framework.filesystem.folder'); if (!MFolder::exists(MPATH_MODULES)) { self::$modules = 0; return self::$modules; } $folders = MFolder::folders(MPATH_MODULES); if (empty($folders)) { self::$modules = 0; return self::$modules; } self::$modules = array(); foreach ($folders as $folder) { if (strpos($folder, 'quickicons')) { continue; } $mod = new stdClass(); $mod->id = $folder; $mod->title = $folder; $mod->module = $folder; $mod->name = $folder; $mod->menuid = 0; $mod->position = $folder; $mod->user = 0; $mod->params = null; $mod->style = null; $mod->content = ''; $mod->showtitle = 0; $mod->control = ''; $params = MFactory::getWOption('widget_' . $folder . '_widget', false, $module_id); if ($params != null) { $mod->params = json_encode($params); } self::$modules[] = $mod; } return self::$modules; }
protected function getLayoutsFromViews($plugin, $view) { $options = array(); $layouts = array(); $layoutNames = array(); $app = MFactory::getApplication(); $path = ''; // Get the views for this component. if (is_dir(MPATH_WP_PLG . '/' . $plugin . '/site')) { $folders = MFolder::folders(MPATH_WP_PLG . '/' . $plugin . '/site', '^view[s]?$', false, true); } if (!empty($folders[0])) { $path = $folders[0] . '/' . $view . '/tmpl'; } if (is_dir($path)) { $layouts = array_merge($layouts, MFolder::files($path, '.xml$', false, true)); } else { return $options; } // Build list of standard layout names foreach ($layouts as $layout) { // Ignore private layouts. if (strpos(basename($layout), '_') === false) { // Get the layout name. $layoutNames[] = basename($layout, '.xml'); } } // Get the template layouts $tmpl = $app->getTemplate(); // Array to hold association between template file names and templates $templateName = array(); //@TODO : Do not forget that delete "com_" string if (is_dir(MPATH_THEMES . '/' . $tmpl . '/html/com_' . $plugin . '/' . $view)) { $templateLayouts = MFolder::files(MPATH_THEMES . '/' . $tmpl . '/html/com_' . $plugin . '/' . $view, '.xml$', false, true); foreach ($templateLayouts as $templateLayout) { // Get the layout name. $templateLayoutName = basename($templateLayout, '.xml'); // add to the list only if it is not a standard layout if (array_search($templateLayoutName, $layoutNames) === false) { $layouts[] = $templateLayout; // Set template name array so we can get the right template for the layout $templateName[$templateLayout] = $tmpl; } } } // Process the found layouts. foreach ($layouts as $layout) { $file = $layout; $array = array(); // Ignore private layouts. if (strpos(basename($layout), '_') === false) { $form = new MForm(basename($layout)); $form->loadFile($layout, true, '/metadata'); 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'])) { $array['title'] = trim((string) $menu['title']); } } } } // Add the layout to the options array. $array['form'] = $form; $options[$view . '_' . basename($layout, '.xml')] = $array; } } return $options; }
private function _extractNative($archive, $destination, $options) { $zip = zip_open($archive); if (is_resource($zip)) { // Make sure the destination folder exists if (!MFolder::create($destination)) { $this->set('error.message', 'Unable to create destination'); return false; } // Read files in the archive while ($file = @zip_read($zip)) { if (zip_entry_open($zip, $file, "r")) { if (substr(zip_entry_name($file), strlen(zip_entry_name($file)) - 1) != "/") { $buffer = zip_entry_read($file, zip_entry_filesize($file)); if (MFile::write($destination . '/' . zip_entry_name($file), $buffer) === false) { $this->set('error.message', 'Unable to write entry'); return false; } zip_entry_close($file); } } else { $this->set('error.message', MText::_('MLIB_FILESYSTEM_ZIP_UNABLE_TO_READ_ENTRY')); return false; } } @zip_close($zip); } else { $this->set('error.message', MText::_('MLIB_FILESYSTEM_ZIP_UNABLE_TO_OPEN_ARCHIVE')); return false; } return true; }
public static function upload($src, $dest, $use_streams = false) { // Ensure that the path is valid and clean $dest = MPath::clean($dest); // Create the destination directory if it does not exist $baseDir = dirname($dest); if (!file_exists($baseDir)) { mimport('framework.filesystem.folder'); MFolder::create($baseDir); } if ($use_streams) { $stream = MFactory::getStream(); if (!$stream->upload($src, $dest)) { MError::raiseWarning(21, MText::sprintf('MLIB_FILESYSTEM_ERROR_UPLOAD', $stream->getError())); return false; } return true; } else { // Initialise variables. $FTPOptions = MClientHelper::getCredentials('ftp'); $ret = false; if ($FTPOptions['enabled'] == 1) { // Connect the FTP client mimport('framework.client.ftp'); $ftp = MFTP::getInstance($FTPOptions['host'], $FTPOptions['port'], null, $FTPOptions['user'], $FTPOptions['pass']); // Translate path for the FTP account $dest = MPath::clean(str_replace(MPATH_ROOT, $FTPOptions['root'], $dest), '/'); // Copy the file to the destination directory if (is_uploaded_file($src) && $ftp->store($src, $dest)) { unlink($src); $ret = true; } else { MError::raiseWarning(21, MText::_('MLIB_FILESYSTEM_ERROR_WARNFS_ERR02')); } } else { if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) { // Short circuit to prevent file permission errors if (MPath::setPermissions($dest)) { $ret = true; } else { MError::raiseWarning(21, MText::_('MLIB_FILESYSTEM_ERROR_WARNFS_ERR01')); } } else { MError::raiseWarning(21, MText::_('MLIB_FILESYSTEM_ERROR_WARNFS_ERR02')); } } return $ret; } }
protected static function _load() { if (self::$plugins !== null) { return self::$plugins; } mimport('framework.filesystem.folder'); if (!MFolder::exists(MPATH_PLUGINS)) { self::$plugins = array(); return self::$plugins; } $folders = MFolder::folders(MPATH_PLUGINS); if (empty($folders)) { self::$plugins = array(); return self::$plugins; } self::$plugins = array(); foreach ($folders as $folder) { $folder = str_replace('plg_', '', $folder); list($type, $name) = explode('_', $folder); $plg = new stdClass(); $plg->type = $type; $plg->name = $name; $plg->params = null; $xml_file = MPATH_MIWI . '/plugins/plg_' . $type . '_' . $name . '/' . $name . '.xml'; if (file_exists($xml_file)) { $form = MForm::getInstance($folder . '_form', $xml_file, array(), false, 'config'); $field_sets = $form->getFieldsets(); if (!empty($field_sets)) { $params = array(); foreach ($field_sets as $name => $field_set) { foreach ($form->getFieldset($name) as $field) { $field_name = $field->get('fieldname'); $field_value = $field->get('value'); $params[$field_name] = $field_value; } } $plg->params = json_encode($params); } } self::$plugins[] = $plg; } return self::$plugins; }
public static function extract($archivename, $extractdir) { mimport('framework.filesystem.file'); mimport('framework.filesystem.folder'); $untar = false; $result = false; $ext = MFile::getExt(strtolower($archivename)); // Check if a tar is embedded...gzip/bzip2 can just be plain files! if (MFile::getExt(MFile::stripExt(strtolower($archivename))) == 'tar') { $untar = true; } switch ($ext) { case 'zip': $adapter = MArchive::getAdapter('zip'); if ($adapter) { $result = $adapter->extract($archivename, $extractdir); } break; case 'tar': $adapter = MArchive::getAdapter('tar'); if ($adapter) { $result = $adapter->extract($archivename, $extractdir); } break; case 'tgz': // This format is a tarball gzip'd $untar = true; case 'gz': case 'gzip': // This may just be an individual file (e.g. sql script) $adapter = MArchive::getAdapter('gzip'); if ($adapter) { $config = MFactory::getConfig(); $tmpfname = $config->get('tmp_path') . '/' . uniqid('gzip'); $gzresult = $adapter->extract($archivename, $tmpfname); if ($gzresult instanceof Exception) { @unlink($tmpfname); return false; } if ($untar) { // Try to untar the file $tadapter = MArchive::getAdapter('tar'); if ($tadapter) { $result = $tadapter->extract($tmpfname, $extractdir); } } else { $path = MPath::clean($extractdir); MFolder::create($path); $result = MFile::copy($tmpfname, $path . '/' . MFile::stripExt(MFile::getName(strtolower($archivename))), null, 1); } @unlink($tmpfname); } break; case 'tbz2': // This format is a tarball bzip2'd $untar = true; case 'bz2': case 'bzip2': // This may just be an individual file (e.g. sql script) $adapter = MArchive::getAdapter('bzip2'); if ($adapter) { $config = MFactory::getConfig(); $tmpfname = $config->get('tmp_path') . '/' . uniqid('bzip2'); $bzresult = $adapter->extract($archivename, $tmpfname); if ($bzresult instanceof Exception) { @unlink($tmpfname); return false; } if ($untar) { // Try to untar the file $tadapter = MArchive::getAdapter('tar'); if ($tadapter) { $result = $tadapter->extract($tmpfname, $extractdir); } } else { $path = MPath::clean($extractdir); MFolder::create($path); $result = MFile::copy($tmpfname, $path . '/' . MFile::stripExt(MFile::getName(strtolower($archivename))), null, 1); } @unlink($tmpfname); } break; default: MError::raiseWarning(10, MText::_('MLIB_FILESYSTEM_UNKNOWNARCHIVETYPE')); return false; break; } if (!$result || $result instanceof Exception) { return false; } return true; }
public function deleteUploads() { $uploads_dir = MPATH_MEDIA . '/' . $this->context; if (MFolder::exists($uploads_dir)) { return; } MFolder::delete($uploads_dir); }
protected function getInput() { // Initialize variables. // Get the client id. $clientId = $this->element['client_id']; if (is_null($clientId) && $this->form instanceof MForm) { $clientId = $this->form->getValue('client_id'); } $clientId = (int) $clientId; $client = MApplicationHelper::getClientInfo($clientId); // Get the extension. $extn = (string) $this->element['extension']; if (empty($extn) && $this->form instanceof MForm) { $extn = $this->form->getValue('extension'); } $extn = preg_replace('#\\W#', '', $extn); // Get the template. $template = (string) $this->element['template']; $template = preg_replace('#\\W#', '', $template); // Get the style. if ($this->form instanceof MForm) { $template_style_id = $this->form->getValue('template_style_id'); } $template_style_id = preg_replace('#\\W#', '', $template_style_id); // Get the view. $view = (string) $this->element['view']; $view = preg_replace('#\\W#', '', $view); // If a template, extension and view are present build the options. if ($extn && $view && $client) { // Load language file $lang = MFactory::getLanguage(); $lang->load($extn . '.sys', MPATH_ADMINISTRATOR, null, false, false) || $lang->load($extn . '.sys', MPATH_ADMINISTRATOR . '/components/' . $extn, null, false, false) || $lang->load($extn . '.sys', MPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load($extn . '.sys', MPATH_ADMINISTRATOR . '/components/' . $extn, $lang->getDefault(), false, false); // Get the database object and a new query object. $db = MFactory::getDBO(); $query = $db->getQuery(true); // Build the query. $query->select('e.element, e.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()) { MError::raiseWarning(500, $db->getErrorMsg()); } // Build the search paths for component layouts. $component_path = MPath::clean($client->path . '/components/' . $extn . '/views/' . $view . '/tmpl'); // Prepare array of component layouts $component_layouts = array(); // Prepare the grouped list $groups = array(); // Add a Use Global option if useglobal="true" in XML file if ($this->element['useglobal'] == 'true') { $groups[MText::_('MOPTION_FROM_STANDARD')]['items'][] = MHtml::_('select.option', '', MText::_('MGLOBAL_USE_GLOBAL')); } // Add the layout options from the component path. if (is_dir($component_path) && ($component_layouts = MFolder::files($component_path, '^[^_]*\\.xml$', false, true))) { // Create the group for the component $groups['_'] = array(); $groups['_']['id'] = $this->id . '__'; $groups['_']['text'] = MText::sprintf('MOPTION_FROM_COMPONENT'); $groups['_']['items'] = array(); foreach ($component_layouts as $i => $file) { // Attempt to load the XML file. if (!($xml = simplexml_load_file($file))) { unset($component_layouts[$i]); continue; } // Get the help data from the XML file if present. if (!($menu = $xml->xpath('layout[1]'))) { unset($component_layouts[$i]); continue; } $menu = $menu[0]; // Add an option to the component group $value = MFile::stripext(MFile::getName($file)); $component_layouts[$i] = $value; $text = isset($menu['option']) ? MText::_($menu['option']) : (isset($menu['title']) ? MText::_($menu['title']) : $value); $groups['_']['items'][] = MHtml::_('select.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, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, $lang->getDefault(), false, false); $template_path = MPath::clean($client->path . '/templates/' . $template->element . '/html/' . $extn . '/' . $view); // Add the layout options from the template path. if (is_dir($template_path) && ($files = MFolder::files($template_path, '^[^_]*\\.php$', false, true))) { // Files with corresponding XML files are alternate menu items, not alternate layout files // so we need to exclude these files from the list. $xml_files = MFolder::files($template_path, '^[^_]*\\.xml$', false, true); for ($j = 0, $count = count($xml_files); $j < $count; $j++) { $xml_files[$j] = MFile::stripext(MFile::getName($xml_files[$j])); } foreach ($files as $i => $file) { // Remove layout files that exist in the component folder or that have XML files if (in_array(MFile::stripext(MFile::getName($file)), $component_layouts) || in_array(MFile::stripext(MFile::getName($file)), $xml_files)) { unset($files[$i]); } } if (count($files)) { // Create the group for the template $groups[$template->name] = array(); $groups[$template->name]['id'] = $this->id . '_' . $template->element; $groups[$template->name]['text'] = MText::sprintf('MOPTION_FROM_TEMPLATE', $template->name); $groups[$template->name]['items'] = array(); foreach ($files as $file) { // Add an option to the template group $value = MFile::stripext(MFile::getName($file)); $text = $lang->hasKey($key = strtoupper('TPL_' . $template->name . '_' . $extn . '_' . $view . '_LAYOUT_' . $value)) ? MText::_($key) : $value; $groups[$template->name]['items'][] = MHtml::_('select.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[] = MHtml::_('select.groupedlist', $groups, $this->name, array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected)); return implode($html); } else { return ''; } }
protected static function _load($option) { if (isset(self::$components[$option]) and self::$components[$option] !== null) { return true; } mimport('framework.filesystem.folder'); $folders = MFolder::folders(MPATH_WP_PLG); if (empty($folders)) { self::$components[$option] = new stdClass(); return false; } self::$components = array(); $n = count($folders); for ($i = 0; $i < $n; $i++) { $folder = @$folders[$i]; if (empty($folder)) { continue; } if (substr($folder, 0, 4) != 'miwo') { continue; } $com = new stdClass(); $com->id = $i; $com->option = 'com_' . $folder; $com->params = MFactory::getWOption($folder); $com->enabled = 1; // Convert the params to an object. if (is_string($com->params)) { $temp = new MRegistry(); $temp->loadString($com->params); $com->params = $temp; } self::$components[$com->option] = $com; } return true; }
public static function parseXMLLanguageFiles($dir = null) { if ($dir == null) { return null; } $languages = array(); mimport('framework.filesystem.folder'); $files = MFolder::files($dir, '^([-_A-Za-z]*)\\.xml$'); foreach ($files as $file) { if ($content = file_get_contents("{$dir}/{$file}")) { if ($metadata = self::parseXMLLanguageFile("{$dir}/{$file}")) { $lang = str_replace('.xml', '', $file); $languages[$lang] = $metadata; } } } return $languages; }