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 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; }
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 ''; } }
protected static function includeRelativeFiles($folder, $file, $relative, $detect_browser, $detect_debug) { // If http is present in filename if (strpos($file, 'http') === 0) { $includes = array($file); } else { // Extract extension and strip the file $strip = MFile::stripExt($file); $ext = MFile::getExt($file); // Detect browser and compute potential files if ($detect_browser) { $navigator = MBrowser::getInstance(); $browser = $navigator->getBrowser(); $major = $navigator->getMajor(); $minor = $navigator->getMinor(); // Try to include files named filename.ext, filename_browser.ext, filename_browser_major.ext, filename_browser_major_minor.ext // where major and minor are the browser version names $potential = array($strip, $strip . '_' . $browser, $strip . '_' . $browser . '_' . $major, $strip . '_' . $browser . '_' . $major . '_' . $minor); } else { $potential = array($strip); } // If relative search in template directory or media directory if ($relative) { // Get the template $app = MFactory::getApplication(); $template = $app->getTemplate(); // Prepare array of files $includes = array(); // For each potential files foreach ($potential as $strip) { $files = array(); // Detect debug mode if ($detect_debug && MFactory::getConfig()->get('debug')) { $files[] = $strip . '-uncompressed.' . $ext; } $files[] = $strip . '.' . $ext; // Loop on 1 or 2 files and break on first found foreach ($files as $file) { // If the file is in the template folder if (file_exists(MPATH_THEMES . "/{$template}/{$folder}/{$file}")) { $includes[] = MURI::base(true) . "/templates/{$template}/{$folder}/{$file}"; break; } else { // If the file contains any /: it can be in an media extension subfolder if (strpos($file, '/')) { // Divide the file extracting the extension as the first part before / list($extension, $file) = explode('/', $file, 2); // If the file yet contains any /: it can be a plugin if (strpos($file, '/')) { // Divide the file extracting the element as the first part before / list($element, $file) = explode('/', $file, 2); // Try to deal with plugins group in the media folder if (file_exists(MPATH_ROOT . "/media/{$extension}/{$element}/{$folder}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/media/{$extension}/{$element}/{$folder}/{$file}"; break; } elseif (file_exists(MPATH_ROOT . "/media/{$extension}/{$folder}/{$element}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/media/{$extension}/{$folder}/{$element}/{$file}"; break; } elseif (file_exists(MPATH_THEMES . "/{$template}/{$folder}/system/{$element}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/templates/{$template}/{$folder}/system/{$element}/{$file}"; break; } elseif (file_exists(MPATH_ROOT . "/media/system/{$folder}/{$element}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/media/system/{$folder}/{$element}/{$file}"; break; } } elseif (file_exists(MPATH_ROOT . "/media/{$extension}/{$folder}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/media/{$extension}/{$folder}/{$file}"; break; } elseif (file_exists(MPATH_THEMES . "/{$template}/{$folder}/system/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/templates/{$template}/{$folder}/system/{$file}"; break; } elseif (file_exists(MPATH_ROOT . "/media/system/{$folder}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/media/system/{$folder}/{$file}"; break; } } elseif (file_exists(MPATH_ROOT . "/media/system/{$folder}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/media/system/{$folder}/{$file}"; break; } } } } } else { $includes = array(); foreach ($potential as $strip) { // Detect debug mode if ($detect_debug && MFactory::getConfig()->get('debug') && file_exists(MPATH_ROOT . "/{$strip}-uncompressed.{$ext}")) { $includes[] = MURI::root(false) . "/{$strip}-uncompressed.{$ext}"; } elseif (file_exists(MPATH_ROOT . "/{$strip}.{$ext}")) { $includes[] = MURI::root(false) . "/{$strip}.{$ext}"; } } } } return $includes; }