protected function getInput() { // Initialize variables. $html = array(); // Initialize some field attributes. $class = $this->element['class'] ? ' class="radio ' . (string) $this->element['class'] . '"' : ' class="radio"'; // Start the radio field output. $html[] = '<fieldset id="' . $this->id . '"' . $class . '>'; // Get the field options. $options = $this->getOptions(); // Build the radio field output. foreach ($options as $i => $option) { // Initialize some option attributes. $checked = (string) $option->value == (string) $this->value ? ' checked="checked"' : ''; $class = !empty($option->class) ? ' class="' . $option->class . '"' : ''; $disabled = !empty($option->disable) ? ' disabled="disabled"' : ''; // Initialize some JavaScript option attributes. $onclick = !empty($option->onclick) ? ' onclick="' . $option->onclick . '"' : ''; $html[] = '<input type="radio" id="' . $this->id . $i . '" name="' . $this->name . '"' . ' value="' . htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . '/>'; $html[] = '<label for="' . $this->id . $i . '"' . $class . '>' . MText::alt($option->text, preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)) . '</label>'; } // End the radio field output. $html[] = '</fieldset>'; return implode($html); }
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; }
protected function getOptions() { // Initialize variables. $options = array(); foreach ($this->element->children() as $option) { // Only add <option /> elements. if ($option->getName() != 'option') { continue; } // Create a new option object based on the <option /> element. $tmp = MHtml::_('select.option', (string) $option['value'], MText::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\\-]/', '_', $this->fieldname)), 'value', 'text', (string) $option['disabled'] == 'true'); // Set some option attributes. $tmp->class = (string) $option['class']; // Set some JavaScript option attributes. $tmp->onclick = (string) $option['onclick']; // Add the option object to the result set. $options[] = $tmp; } reset($options); return $options; }
public static function existing($all = false, $translate = false) { if (empty(self::$items)) { $languages = array(); $langs = get_available_languages(); if (!in_array(get_locale(), $langs)) { $langs[] = get_locale(); } $i = 0; foreach ($langs as $lang) { $languages[$i] = new stdClass(); $languages[$i]->value = $lang; $languages[$i]->text = $lang; $i++; } self::$items = $languages; if ($all) { array_unshift(self::$items, new MObject(array('value' => '*', 'text' => $translate ? MText::alt('MALL', 'language') : 'MALL_LANGUAGE'))); } } return self::$items; }