public static function getHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) { global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect; $checkbox_class = $is_mandatory ? 'mandatoryField' : 'createboxInput'; $span_class = 'checkboxSpan'; if (array_key_exists('class', $other_args)) { $span_class .= ' ' . $other_args['class']; } $input_id = "input_{$sfgFieldNum}"; // get list delimiter - default is comma if (array_key_exists('delimiter', $other_args)) { $delimiter = $other_args['delimiter']; } else { $delimiter = ','; } $cur_values = SFUtils::getValuesArray($cur_value, $delimiter); if (($possible_values = $other_args['possible_values']) == null) { $possible_values = array(); } $text = ''; foreach ($possible_values as $key => $possible_value) { $cur_input_name = $input_name . '[' . $key . ']'; if (array_key_exists('value_labels', $other_args) && is_array($other_args['value_labels']) && array_key_exists($possible_value, $other_args['value_labels'])) { $label = $other_args['value_labels'][$possible_value]; } else { $label = $possible_value; } $checkbox_attrs = array('id' => $input_id, 'tabindex' => $sfgTabIndex, 'class' => $checkbox_class); if (in_array($possible_value, $cur_values)) { $checkbox_attrs['checked'] = 'checked'; } if ($is_disabled) { $checkbox_attrs['disabled'] = 'disabled'; } $checkbox_input = Html::input($cur_input_name, $possible_value, 'checkbox', $checkbox_attrs); // Make a span around each checkbox, for CSS purposes. $text .= "\t" . Html::rawElement('span', array('class' => $span_class), $checkbox_input . ' ' . $label) . "\n"; $sfgTabIndex++; $sfgFieldNum++; } $outerSpanID = "span_{$sfgFieldNum}"; $outerSpanClass = 'checkboxesSpan'; if ($is_mandatory) { $outerSpanClass .= ' mandatoryFieldSpan'; } if (array_key_exists('show on select', $other_args)) { $outerSpanClass .= ' sfShowIfChecked'; foreach ($other_args['show on select'] as $div_id => $options) { if (array_key_exists($outerSpanID, $sfgShowOnSelect)) { $sfgShowOnSelect[$outerSpanID][] = array($options, $div_id); } else { $sfgShowOnSelect[$outerSpanID] = array(array($options, $div_id)); } } } $text .= Html::hidden($input_name . '[is_list]', 1); $outerSpanAttrs = array('id' => $outerSpanID, 'class' => $outerSpanClass); $text = "\t" . Html::rawElement('span', $outerSpanAttrs, $text) . "\n"; return $text; }
/** * Returns the HTML code to be included in the output page for this input. */ public function getHtmlText() { global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect; $className = $this->mIsMandatory ? 'mandatoryField' : 'createboxInput'; if (array_key_exists('class', $this->mOtherArgs)) { $className .= ' ' . $this->mOtherArgs['class']; } $input_id = "input_{$sfgFieldNum}"; // get list delimiter - default is comma if (array_key_exists('delimiter', $this->mOtherArgs)) { $delimiter = $this->mOtherArgs['delimiter']; } else { $delimiter = ','; } $cur_values = SFUtils::getValuesArray($this->mCurrentValue, $delimiter); $className .= ' sfShowIfSelected'; if (($possible_values = $this->mOtherArgs['possible_values']) == null) { $possible_values = array(); } $optionsText = ''; foreach ($possible_values as $possible_value) { if (array_key_exists('value_labels', $this->mOtherArgs) && is_array($this->mOtherArgs['value_labels']) && array_key_exists($possible_value, $this->mOtherArgs['value_labels'])) { $optionLabel = $this->mOtherArgs['value_labels'][$possible_value]; } else { $optionLabel = $possible_value; } $optionAttrs = array('value' => $possible_value); if (in_array($possible_value, $cur_values)) { $optionAttrs['selected'] = 'selected'; } $optionsText .= Html::element('option', $optionAttrs, $optionLabel); } $selectAttrs = array('id' => $input_id, 'tabindex' => $sfgTabIndex, 'name' => $this->mInputName . '[]', 'class' => $className, 'multiple' => 'multiple'); if (array_key_exists('size', $this->mOtherArgs)) { $selectAttrs['size'] = $this->mOtherArgs['size']; } if ($this->mIsDisabled) { $selectAttrs['disabled'] = 'disabled'; } $text = Html::rawElement('select', $selectAttrs, $optionsText); $text .= Html::hidden($this->mInputName . '[is_list]', 1); if ($this->mIsMandatory) { $text = Html::rawElement('span', array('class' => 'inputSpan mandatoryFieldSpan'), $text); } if (array_key_exists('show on select', $this->mOtherArgs)) { foreach ($this->mOtherArgs['show on select'] as $div_id => $options) { if (array_key_exists($input_id, $sfgShowOnSelect)) { $sfgShowOnSelect[$input_id][] = array($options, $div_id); } else { $sfgShowOnSelect[$input_id] = array(array($options, $div_id)); } } } return $text; }
public static function getHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) { // escape if CategoryTree extension isn't included if (!function_exists('efCategoryTreeParserHook')) { return null; } global $sfgTabIndex, $sfgFieldNum, $wgCapitalLinks; $input_id = "input_{$sfgFieldNum}"; // get list delimiter - default is comma if (array_key_exists('delimiter', $other_args)) { $delimiter = $other_args['delimiter']; } else { $delimiter = ','; } $cur_values = SFUtils::getValuesArray($cur_value, $delimiter); if (array_key_exists('top category', $other_args)) { $top_category = $other_args['top category']; } else { // escape - we can't do anything return null; } $hideroot = array_key_exists('hideroot', $other_args); if (array_key_exists('depth', $other_args)) { $depth = $other_args['depth']; } else { $depth = '10'; } if (array_key_exists('height', $other_args)) { $height = $other_args['height']; } else { $height = '100'; } if (array_key_exists('width', $other_args)) { $width = $other_args['width']; } else { $width = '500'; } global $wgCategoryTreeMaxDepth; $wgCategoryTreeMaxDepth = 10; $tree = efCategoryTreeParserHook($top_category, array('mode' => 'categories', 'namespaces' => array(NS_CATEGORY), 'depth' => $depth, 'hideroot' => $hideroot)); // Some string that will hopefully never show up in a category, // template or field name. $dummy_str = 'REPLACE THIS STRING!'; $tree = preg_replace('/(<a class="CategoryTreeLabel.*>)(.*)(<\\/a>)/', '<input id="' . $input_id . '" tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[' . $dummy_str . ']" value="$2" type="checkbox"> $1$2$3', $tree); // replace values one at a time, by an incrementing index - // inspired by http://bugs.php.net/bug.php?id=11457 $i = 0; while (($a = strpos($tree, $dummy_str)) > 0) { $tree = substr($tree, 0, $a) . $i++ . substr($tree, $a + strlen($dummy_str)); } // set all checkboxes matching $cur_values to checked foreach ($cur_values as $value) { // Capitalize the first letter, if first letters // always get capitalized. if ($wgCapitalLinks) { global $wgContLang; $value = $wgContLang->ucfirst($value); } $tree = str_replace("value=\"{$value}\"", "value=\"{$value}\" checked=\"checked\"", $tree); } // if it's disabled, set all to disabled if ($is_disabled) { $tree = str_replace('type="checkbox"', 'type="checkbox" disabled', $tree); } // Get rid of all the 'no subcategories' messages. $tree = str_replace('<div class="CategoryTreeChildren" style="display:block"><i class="CategoryTreeNotice">' . wfMsg('categorytree-no-subcategories') . '</i></div>', '', $tree); $text = '<div style="overflow: auto; padding: 5px; border: 1px #aaaaaa solid; max-height: ' . $height . 'px; width: ' . $width . 'px;">' . $tree . '</div>'; $text .= Html::hidden($input_name . '[is_list]', 1); $spanClass = 'checkboxesSpan'; if ($is_mandatory) { $spanClass .= ' mandatoryFieldSpan'; } $text = "\n" . Html::rawElement('span', array('class' => $spanClass), $text) . "\n"; return $text; }
public static function getHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) { global $sfgTabIndex, $sfgFieldNum, $sfgShowOnSelect; $checkboxClass = $is_mandatory ? 'mandatoryField' : 'createboxInput'; $labelClass = 'checkboxLabel'; if (array_key_exists('class', $other_args)) { $labelClass .= ' ' . $other_args['class']; } $input_id = "input_{$sfgFieldNum}"; // get list delimiter - default is comma if (array_key_exists('delimiter', $other_args)) { $delimiter = $other_args['delimiter']; } else { $delimiter = ','; } $cur_values = SFUtils::getValuesArray($cur_value, $delimiter); if (($possible_values = $other_args['possible_values']) == null) { $possible_values = array(); } $text = ''; foreach ($possible_values as $key => $possible_value) { $cur_input_name = $input_name . '[' . $key . ']'; if (array_key_exists('value_labels', $other_args) && is_array($other_args['value_labels']) && array_key_exists($possible_value, $other_args['value_labels'])) { $label = $other_args['value_labels'][$possible_value]; } else { $label = $possible_value; } $checkbox_attrs = array('id' => $input_id, 'tabindex' => $sfgTabIndex, 'class' => $checkboxClass); if (in_array($possible_value, $cur_values)) { $checkbox_attrs['checked'] = 'checked'; } if ($is_disabled) { $checkbox_attrs['disabled'] = 'disabled'; } $checkbox_input = Html::input($cur_input_name, $possible_value, 'checkbox', $checkbox_attrs); // Put a <label> tag around each checkbox, for CSS // purposes as well as to clarify this element. $text .= "\t" . Html::rawElement('label', array('class' => $labelClass), $checkbox_input . ' ' . $label) . "\n"; $sfgTabIndex++; $sfgFieldNum++; } $outerSpanID = "span_{$sfgFieldNum}"; $outerSpanClass = 'checkboxesSpan'; if ($is_mandatory) { $outerSpanClass .= ' mandatoryFieldSpan'; } // @HACK! The current "select all/none" JS code doesn't work // when this input is part of a multiple-instance template, so // if that happens, just don't display those links. // Unfortunately, there's no easy way to know if we're in a // multiple-instance template, so look at the input name - if // it contains "[num][", we can assume that we are. // @TODO - get the JS working in multiple-instance templates - // this will probably require rewriting the checkboxes JS // to some extent, so the relevant part can be called each // time an instance is added. if (strpos($input_name, '[num][') !== false) { // Multiple-instance template; do nothing. } elseif (array_key_exists('show select all', $other_args) || count($possible_values) >= $GLOBALS['sfgCheckboxesSelectAllMinimum'] && !array_key_exists('hide select all', $other_args)) { $outerSpanClass .= ' select-all'; } if (array_key_exists('show on select', $other_args)) { $outerSpanClass .= ' sfShowIfChecked'; foreach ($other_args['show on select'] as $div_id => $options) { if (array_key_exists($outerSpanID, $sfgShowOnSelect)) { $sfgShowOnSelect[$outerSpanID][] = array($options, $div_id); } else { $sfgShowOnSelect[$outerSpanID] = array(array($options, $div_id)); } } } $text .= Html::hidden($input_name . '[is_list]', 1); $outerSpanAttrs = array('id' => $outerSpanID, 'class' => $outerSpanClass); $text = "\t" . Html::rawElement('span', $outerSpanAttrs, $text) . "\n"; return $text; }
public static function getHTML($cur_value, $input_name, $is_mandatory, $is_disabled, $other_args) { // Handle the now-deprecated 'category' and 'categories' // input types. if ($other_args['input type'] == 'category') { $inputType = "radio"; self::$multipleSelect = false; } elseif ($other_args['input type'] == 'categories') { $inputType = "checkbox"; self::$multipleSelect = true; } else { $is_list = array_key_exists('is_list', $other_args) && $other_args['is_list'] == true; if ($is_list) { $inputType = "checkbox"; self::$multipleSelect = true; } else { $inputType = "radio"; self::$multipleSelect = false; } } // get list delimiter - default is comma if (array_key_exists('delimiter', $other_args)) { $delimiter = $other_args['delimiter']; } else { $delimiter = ','; } $cur_values = SFUtils::getValuesArray($cur_value, $delimiter); if (array_key_exists('height', $other_args)) { $height = $other_args['height']; } else { $height = '100'; } if (array_key_exists('width', $other_args)) { $width = $other_args['width']; } else { $width = '500'; } $dummy_str = "REPLACE THIS TEXT"; $text = '<div class="sfTreeInput" id="' . $input_name . 'treeinput" style="height: ' . $height . 'px; width: ' . $width . 'px;">'; if (array_key_exists('depth', $other_args)) { $depth = $other_args['depth']; } else { $depth = '10'; } if (array_key_exists('top category', $other_args)) { $top_category = $other_args['top category']; $title = self::makeTitle($top_category); if ($title->getNamespace() != NS_CATEGORY) { return null; } $tree = SFTree::newFromTopCategory($top_category); $hideroot = array_key_exists('hideroot', $other_args); } elseif (array_key_exists('structure', $other_args)) { $structure = $other_args['structure']; $tree = SFTree::newFromWikiText($structure); $hideroot = true; } else { // Escape - we can't do anything. return null; } $inputText = self::treeToHTML($tree, $input_name, $cur_values, $hideroot, $depth, $inputType); // Replace values one at a time, by an incrementing index - // inspired by http://bugs.php.net/bug.php?id=11457 $i = 0; while (($a = strpos($inputText, $dummy_str)) > 0) { $inputText = substr($inputText, 0, $a) . $i++ . substr($inputText, $a + strlen($dummy_str)); } $text .= $inputText; $text .= '</div>'; return $text; }