Example #1
0
 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;
 }
Example #2
0
 public function getAll()
 {
     parent::getAll();
     $path = $this->_root;
     mimport('framework.filesystem.folder');
     $folders = MFolder::folders($path);
     $data = array();
     foreach ($folders as $folder) {
         $files = MFolder::files($path . '/' . $folder);
         $item = new MCacheStorageHelper($folder);
         foreach ($files as $file) {
             $item->updateSize(filesize($path . '/' . $folder . '/' . $file) / 1024);
         }
         $data[$folder] = $item;
     }
     return $data;
 }
Example #3
0
 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;
 }
Example #4
0
 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;
 }
Example #5
0
 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;
 }
Example #6
0
 public function deleteLangs()
 {
     # Admin
     $admin_lang_dir = MPATH_WP_CNT . '/miwi/languages/admin';
     if (MFolder::exists($admin_lang_dir)) {
         $lang_folders = MFolder::folders($admin_lang_dir);
         foreach ($lang_folders as $lang_folder) {
             $files = MFolder::files($admin_lang_dir . '/' . $lang_folder);
             foreach ($files as $file) {
                 if (strpos($file, $this->context) !== false) {
                     MFile::delete($admin_lang_dir . '/' . $lang_folder . '/' . $file);
                 }
             }
         }
     }
     # Site
     $site_lang_dir = MPATH_WP_CNT . '/miwi/languages/site';
     if (MFolder::exists($site_lang_dir)) {
         $lang_folders = MFolder::folders($site_lang_dir);
         foreach ($lang_folders as $lang_folder) {
             $files = MFolder::files($site_lang_dir . '/' . $lang_folder);
             foreach ($files as $file) {
                 if (strpos($file, $this->context) !== false) {
                     MFile::delete($site_lang_dir . '/' . $lang_folder . '/' . $file);
                 }
             }
         }
     }
 }
Example #7
0
 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 '';
     }
 }
Example #8
0
 public static function getMStreams()
 {
     static $streams;
     if (!$streams) {
         $streams = array_map(array('MFile', 'stripExt'), MFolder::files(dirname(__FILE__) . '/streams', '.php'));
     }
     return $streams;
 }
Example #9
0
 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 '';
     }
 }
Example #10
0
 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;
 }
Example #11
0
 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;
 }