Ejemplo n.º 1
0
 protected function getOptions()
 {
     // Initialize variables.
     $options = array();
     // Initialize some field attributes.
     $key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
     $value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
     $translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
     $query = (string) $this->element['query'];
     // Get the database object.
     $db = MFactory::getDBO();
     // Set the query and get the result list.
     $db->setQuery($query);
     $items = $db->loadObjectlist();
     // Check for an error.
     if ($db->getErrorNum()) {
         MError::raiseWarning(500, $db->getErrorMsg());
         return $options;
     }
     // Build the field options.
     if (!empty($items)) {
         foreach ($items as $item) {
             if ($translate == true) {
                 $options[] = MHtml::_('select.option', $item->{$key}, MText::_($item->{$value}));
             } else {
                 $options[] = MHtml::_('select.option', $item->{$key}, $item->{$value});
             }
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Ejemplo n.º 2
0
 protected function getOptions()
 {
     MLog::add('MFormFieldEditors is deprecated. Use MFormFieldPlugins instead (with folder="editors").', MLog::WARNING, 'deprecated');
     // Get the database object and a new query object.
     $db = MFactory::getDBO();
     $query = $db->getQuery(true);
     // Build the query.
     $query->select('element AS value, name AS text');
     $query->from('#__extensions');
     $query->where('folder = ' . $db->quote('editors'));
     $query->where('enabled = 1');
     $query->order('ordering, name');
     // Set the query and load the options.
     $db->setQuery($query);
     $options = $db->loadObjectList();
     $lang = MFactory::getLanguage();
     foreach ($options as $i => $option) {
         $lang->load('plg_editors_' . $option->value, MPATH_ADMINISTRATOR, null, false, false) || $lang->load('plg_editors_' . $option->value, MPATH_PLUGINS . '/editors/' . $option->value, null, false, false) || $lang->load('plg_editors_' . $option->value, MPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load('plg_editors_' . $option->value, MPATH_PLUGINS . '/editors/' . $option->value, $lang->getDefault(), false, false);
         $options[$i]->text = MText::_($option->text);
     }
     // Check for a database error.
     if ($db->getErrorNum()) {
         MError::raiseWarning(500, $db->getErrorMsg());
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Ejemplo n.º 3
0
 public function __construct($default = array())
 {
     parent::__construct($default);
     $this->_db = MFactory::getDBO();
     $this->_table = MiwosqlHelper::getVar('tbl');
     $this->_query = MiwosqlHelper::getVar('qry');
     $this->registerTask('add', 'edit');
     $this->registerTask('new', 'edit');
 }
Ejemplo n.º 4
0
 function _buildViewWhere()
 {
     $db = MFactory::getDBO();
     $search = $this->mainframe->getUserStateFromRequest($this->option . '.queries.search', 'search', '', 'string');
     $search = MString::strtolower($search);
     $where = array();
     if ($search) {
         $where[] = 'LOWER(title) LIKE ' . $db->Quote('%' . $db->getEscaped($search, true) . '%', false);
     }
     $where = count($where) ? ' WHERE ' . implode(' AND ', $where) : '';
     return $where;
 }
Ejemplo n.º 5
0
 public static function published($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb', $publish_up = null, $publish_down = null)
 {
     if (is_array($prefix)) {
         $options = $prefix;
         $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
         $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
         $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
     }
     $states = array(1 => array('unpublish', 'MPUBLISHED', 'MLIB_HTML_UNPUBLISH_ITEM', 'MPUBLISHED', false, 'publish', 'publish'), 0 => array('publish', 'MUNPUBLISHED', 'MLIB_HTML_PUBLISH_ITEM', 'MUNPUBLISHED', false, 'unpublish', 'unpublish'), 2 => array('unpublish', 'MARCHIVED', 'MLIB_HTML_UNPUBLISH_ITEM', 'MARCHIVED', false, 'archive', 'archive'), -2 => array('publish', 'MTRASHED', 'MLIB_HTML_PUBLISH_ITEM', 'MTRASHED', false, 'trash', 'trash'));
     // Special state for dates
     if ($publish_up || $publish_down) {
         $nullDate = MFactory::getDBO()->getNullDate();
         $nowDate = MFactory::getDate()->toUnix();
         $tz = new DateTimeZone(MFactory::getUser()->getParam('timezone', MFactory::getConfig()->get('offset')));
         $publish_up = $publish_up != $nullDate ? MFactory::getDate($publish_up, 'UTC')->setTimeZone($tz) : false;
         $publish_down = $publish_down != $nullDate ? MFactory::getDate($publish_down, 'UTC')->setTimeZone($tz) : false;
         // Create tip text, only we have publish up or down settings
         $tips = array();
         if ($publish_up) {
             $tips[] = MText::sprintf('MLIB_HTML_PUBLISHED_START', $publish_up->format(MDate::$format, true));
         }
         if ($publish_down) {
             $tips[] = MText::sprintf('MLIB_HTML_PUBLISHED_FINISHED', $publish_down->format(MDate::$format, true));
         }
         $tip = empty($tips) ? false : implode('<br/>', $tips);
         // Add tips and special titles
         foreach ($states as $key => $state) {
             // Create special titles for published items
             if ($key == 1) {
                 $states[$key][2] = $states[$key][3] = 'MLIB_HTML_PUBLISHED_ITEM';
                 if ($publish_up > $nullDate && $nowDate < $publish_up->toUnix()) {
                     $states[$key][2] = $states[$key][3] = 'MLIB_HTML_PUBLISHED_PENDING_ITEM';
                     $states[$key][5] = $states[$key][6] = 'pending';
                 }
                 if ($publish_down > $nullDate && $nowDate > $publish_down->toUnix()) {
                     $states[$key][2] = $states[$key][3] = 'MLIB_HTML_PUBLISHED_EXPIRED_ITEM';
                     $states[$key][5] = $states[$key][6] = 'expired';
                 }
             }
             // Add tips to titles
             if ($tip) {
                 $states[$key][1] = MText::_($states[$key][1]);
                 $states[$key][2] = MText::_($states[$key][2]) . '::' . $tip;
                 $states[$key][3] = MText::_($states[$key][3]) . '::' . $tip;
                 $states[$key][4] = true;
             }
         }
         return self::state($states, $value, $i, array('prefix' => $prefix, 'translate' => !$tip), $enabled, true, $checkbox);
     }
     return self::state($states, $value, $i, $prefix, $enabled, true, $checkbox);
 }
Ejemplo n.º 6
0
 public static function userlist()
 {
     // Get the database object and a new query object.
     $db = MFactory::getDBO();
     $query = $db->getQuery(true);
     // Build the query.
     $query->select('a.ID AS value, a.display_name AS text');
     $query->from('#__users AS a');
     $query->where('a.user_status = 0');
     $query->order('a.display_name');
     // Set the query and load the options.
     $db->setQuery($query);
     $items = $db->loadObjectList();
     // Detect errors
     if ($db->getErrorNum()) {
         MError::raiseWarning(500, $db->getErrorMsg());
     }
     return $items;
 }
Ejemplo n.º 7
0
 public function test(&$element, $value, $group = null, &$input = null, &$form = null)
 {
     // If the field is empty and not required, the field is valid.
     $required = (string) $element['required'] == 'true' || (string) $element['required'] == 'required';
     if (!$required && empty($value)) {
         return true;
     }
     // Test the value against the regular expression.
     if (!parent::test($element, $value, $group, $input, $form)) {
         return false;
     }
     // Check if we should test for uniqueness.
     $unique = (string) $element['unique'] == 'true' || (string) $element['unique'] == 'unique';
     if ($unique) {
         // Get the database object and a new query object.
         $db = MFactory::getDBO();
         $query = $db->getQuery(true);
         // Build the query.
         $query->select('COUNT(*)');
         $query->from('#__users');
         $query->where('email = ' . $db->quote($value));
         // Get the extra field check attribute.
         $userId = $form instanceof MForm ? $form->getValue('id') : '';
         $query->where($db->quoteName('id') . ' <> ' . (int) $userId);
         // Set and query the database.
         $db->setQuery($query);
         $duplicate = (bool) $db->loadResult();
         // Check for a database error.
         if ($db->getErrorNum()) {
             MError::raiseWarning(500, $db->getErrorMsg());
         }
         if ($duplicate) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 8
0
 protected function &getEditor()
 {
     // Only create the editor if it is not already created.
     if (empty($this->editor)) {
         // Initialize variables.
         $editor = null;
         // Get the editor type attribute. Can be in the form of: editor="desired|alternative".
         $type = trim((string) $this->element['editor']);
         if ($type) {
             // Get the list of editor types.
             $types = explode('|', $type);
             // Get the database object.
             $db = MFactory::getDBO();
             // Iterate over teh types looking for an existing editor.
             foreach ($types as $element) {
                 // Build the query.
                 $query = $db->getQuery(true);
                 $query->select('element');
                 $query->from('#__extensions');
                 $query->where('element = ' . $db->quote($element));
                 $query->where('folder = ' . $db->quote('editors'));
                 $query->where('enabled = 1');
                 // Check of the editor exists.
                 $db->setQuery($query, 0, 1);
                 $editor = $db->loadResult();
                 // If an editor was found stop looking.
                 if ($editor) {
                     break;
                 }
             }
         }
         // Create the MEditor instance based on the given editor.
         $this->editor = MFactory::getEditor($editor ? $editor : null);
     }
     return $this->editor;
 }
Ejemplo n.º 9
0
 public function test(&$element, $value, $group = null, &$input = null, &$form = null)
 {
     // Get the database object and a new query object.
     $db = MFactory::getDBO();
     $query = $db->getQuery(true);
     // Build the query.
     $query->select('COUNT(*)');
     $query->from('#__users');
     $query->where('username = '******'id') : '';
     $query->where($db->quoteName('id') . ' <> ' . (int) $userId);
     // Set and query the database.
     $db->setQuery($query);
     $duplicate = (bool) $db->loadResult();
     // Check for a database error.
     if ($db->getErrorNum()) {
         MError::raiseWarning(500, $db->getErrorMsg());
     }
     if ($duplicate) {
         return false;
     }
     return true;
 }
Ejemplo n.º 10
0
 public function __construct(array &$options)
 {
     // Call the parent constructor.
     parent::__construct($options);
     // If both the database object and driver options are empty we want to use the system database connection.
     if (empty($this->options['db_object']) && empty($this->options['db_driver'])) {
         $this->dbo = MFactory::getDBO();
         $this->driver = MFactory::getConfig()->get('dbtype');
         $this->host = MFactory::getConfig()->get('host');
         $this->user = MFactory::getConfig()->get('user');
         $this->password = MFactory::getConfig()->get('password');
         $this->database = MFactory::getConfig()->get('db');
         $this->prefix = MFactory::getConfig()->get('dbprefix');
     } else {
         $this->driver = empty($this->options['db_driver']) ? 'mysql' : $this->options['db_driver'];
         $this->host = empty($this->options['db_host']) ? '127.0.0.1' : $this->options['db_host'];
         $this->user = empty($this->options['db_user']) ? 'root' : $this->options['db_user'];
         $this->password = empty($this->options['db_pass']) ? '' : $this->options['db_pass'];
         $this->database = empty($this->options['db_database']) ? 'logging' : $this->options['db_database'];
         $this->prefix = empty($this->options['db_prefix']) ? 'jos_' : $this->options['db_prefix'];
     }
     // The table name is independent of how we arrived at the connection object.
     $this->table = empty($this->options['db_table']) ? '#__log_entries' : $this->options['db_table'];
 }
Ejemplo n.º 11
0
 protected function getUserGroups()
 {
     // Initialise variables.
     $db = MFactory::getDBO();
     $query = $db->getQuery(true);
     $query->select('a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level, a.parent_id')->from('#__usergroups AS a')->leftJoin($db->quoteName('#__usergroups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt')->group('a.id, a.title, a.lft, a.rgt, a.parent_id')->order('a.lft ASC');
     $db->setQuery($query);
     $options = $db->loadObjectList();
     return $options;
 }
Ejemplo n.º 12
0
 protected static function _getUserGroups()
 {
     // Get a database object.
     $db = MFactory::getDBO();
     // Get the user groups from the database.
     $db->setQuery('SELECT a.id AS value, a.title AS text, b.id as parent' . ' FROM #__usergroups AS a' . ' LEFT JOIN #__usergroups AS b ON a.lft >= b.lft AND a.rgt <= b.rgt' . ' ORDER BY a.lft ASC, b.lft ASC');
     $result = $db->loadObjectList();
     $options = array();
     // Pre-compute additional values.
     foreach ($result as $option) {
         $end = end($options);
         if ($end === false || $end->value != $option->value) {
             $end = $option;
             $end->level = 0;
             $options[] = $end;
         } else {
             $end->level++;
         }
         $end->identities[] = $option->parent;
     }
     return $options;
 }
Ejemplo n.º 13
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 '';
     }
 }
Ejemplo n.º 14
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 '';
     }
 }
Ejemplo n.º 15
0
 public function isCheckedOut($with = 0, $against = null)
 {
     // Handle the non-static case.
     if (isset($this) && $this instanceof MTable && is_null($against)) {
         $against = $this->get('checked_out');
     }
     // The item is not checked out or is checked out by the same user.
     if (!$against || $against == $with) {
         return false;
     }
     $db = MFactory::getDBO();
     $db->setQuery('SELECT COUNT(userid)' . ' FROM ' . $db->quoteName('#__session') . ' WHERE ' . $db->quoteName('userid') . ' = ' . (int) $against);
     $checkedOut = (bool) $db->loadResult();
     // If a session exists for the user then it is checked out.
     return $checkedOut;
 }