Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like XoopsFormRendererBootstrap3 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use XoopsFormRendererBootstrap3, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class XoopsFormRendererBootstrap3 implements XoopsFormRendererInterface |
||
| 22 | { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Render support for XoopsFormButton |
||
| 26 | * |
||
| 27 | * @param XoopsFormButton $element form element |
||
| 28 | * |
||
| 29 | * @return string rendered form element |
||
| 30 | */ |
||
| 31 | public function renderFormButton(XoopsFormButton $element) |
||
| 32 | { |
||
| 33 | return "<input type='" . $element->getType() . "' class='btn btn-default' name='" |
||
| 34 | . $element->getName() . "' id='" . $element->getName() . "' value='" . $element->getValue() |
||
| 35 | . "' title='" . $element->getValue() . "'" . $element->getExtra() . ' />'; |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Render support for XoopsFormButtonTray |
||
| 40 | * |
||
| 41 | * @param XoopsFormButtonTray $element form element |
||
| 42 | * |
||
| 43 | * @return string rendered form element |
||
| 44 | */ |
||
| 45 | View Code Duplication | public function renderFormButtonTray(XoopsFormButtonTray $element) |
|
| 46 | { |
||
| 47 | $ret = ''; |
||
| 48 | if ($element->_showDelete) { |
||
| 49 | $ret .= '<input type="submit" class="btn btn-danger" name="delete" id="delete" value="' . _DELETE |
||
| 50 | . '" onclick="this.form.elements.op.value=\'delete\'"> '; |
||
| 51 | } |
||
| 52 | $ret .= '<input type="button" class="btn btn-danger" value="' . _CANCEL |
||
| 53 | . '" onClick="history.go(-1);return true;" /> ' |
||
| 54 | . '<input type="reset" class="btn btn-warning" name="reset" id="reset" value="' . _RESET . '" /> ' |
||
| 55 | . '<input type="' . $element->getType() . '" class="btn btn-success" name="' . $element->getName() |
||
| 56 | . '" id="' . $element->getName() . '" value="' . $element->getValue() . '"' . $element->getExtra() |
||
| 57 | . ' />'; |
||
| 58 | |||
| 59 | return $ret; |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Render support for XoopsFormCheckBox |
||
| 64 | * |
||
| 65 | * @param XoopsFormCheckBox $element form element |
||
| 66 | * |
||
| 67 | * @return string rendered form element |
||
| 68 | */ |
||
| 69 | public function renderFormCheckBox(XoopsFormCheckBox $element) |
||
| 70 | { |
||
| 71 | $elementName = $element->getName(); |
||
| 72 | $elementId = $elementName; |
||
| 73 | $elementOptions = $element->getOptions(); |
||
| 74 | if (count($elementOptions) > 1 && substr($elementName, -2, 2) !== '[]') { |
||
| 75 | $elementName .= '[]'; |
||
| 76 | $element->setName($elementName); |
||
| 77 | } |
||
| 78 | |||
| 79 | View Code Duplication | switch ((int) ($element->columns)) { |
|
| 80 | case 0: |
||
| 81 | return $this->renderCheckedInline($element, 'checkbox', $elementId, $elementName); |
||
| 82 | case 1: |
||
| 83 | return $this->renderCheckedOneColumn($element, 'checkbox', $elementId, $elementName); |
||
| 84 | default: |
||
| 85 | return $this->renderCheckedColumnar($element, 'checkbox', $elementId, $elementName); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Render a inline checkbox or radio element |
||
| 91 | * |
||
| 92 | * @param XoopsFormCheckBox|XoopsFormRadio $element element being rendered |
||
| 93 | * @param string $type 'checkbox' or 'radio; |
||
| 94 | * @param string $elementId input 'id' attribute of element |
||
| 95 | * @param string $elementName input 'name' attribute of element |
||
| 96 | * @return string |
||
| 97 | */ |
||
| 98 | protected function renderCheckedInline($element, $type, $elementId, $elementName) |
||
| 99 | { |
||
| 100 | $class = $type . '-inline'; |
||
| 101 | $ret = ''; |
||
| 102 | |||
| 103 | $idSuffix = 0; |
||
| 104 | $elementValue = $element->getValue(); |
||
| 105 | $elementOptions = $element->getOptions(); |
||
| 106 | foreach ($elementOptions as $value => $name) { |
||
| 107 | ++$idSuffix; |
||
| 108 | $ret .= '<label class="' . $class . '">'; |
||
| 109 | $ret .= "<input type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='" |
||
| 110 | . htmlspecialchars(strip_tags($name), ENT_QUOTES) . "' value='" |
||
| 111 | . htmlspecialchars($value, ENT_QUOTES) . "'"; |
||
| 112 | |||
| 113 | if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) { |
||
| 114 | $ret .= ' checked'; |
||
| 115 | } |
||
| 116 | $ret .= $element->getExtra() . ' />' . $name . $element->getDelimeter(); |
||
| 117 | $ret .= '</label>'; |
||
| 118 | } |
||
| 119 | |||
| 120 | return $ret; |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Render a single column checkbox or radio element |
||
| 125 | * |
||
| 126 | * @param XoopsFormCheckBox|XoopsFormRadio $element element being rendered |
||
| 127 | * @param string $type 'checkbox' or 'radio; |
||
| 128 | * @param string $elementId input 'id' attribute of element |
||
| 129 | * @param string $elementName input 'name' attribute of element |
||
| 130 | * @return string |
||
| 131 | */ |
||
| 132 | View Code Duplication | protected function renderCheckedOneColumn($element, $type, $elementId, $elementName) |
|
| 133 | { |
||
| 134 | $class = $type; |
||
| 135 | $ret = ''; |
||
| 136 | |||
| 137 | $idSuffix = 0; |
||
| 138 | $elementValue = $element->getValue(); |
||
| 139 | $elementOptions = $element->getOptions(); |
||
| 140 | foreach ($elementOptions as $value => $name) { |
||
| 141 | ++$idSuffix; |
||
| 142 | $ret .= '<div class="' . $class . '">'; |
||
| 143 | $ret .= '<label>'; |
||
| 144 | $ret .= "<input type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='" |
||
| 145 | . htmlspecialchars(strip_tags($name), ENT_QUOTES) . "' value='" |
||
| 146 | . htmlspecialchars($value, ENT_QUOTES) . "'"; |
||
| 147 | |||
| 148 | if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) { |
||
| 149 | $ret .= ' checked'; |
||
| 150 | } |
||
| 151 | $ret .= $element->getExtra() . ' />' . $name . $element->getDelimeter(); |
||
| 152 | $ret .= '</label>'; |
||
| 153 | $ret .= '</div>'; |
||
| 154 | } |
||
| 155 | |||
| 156 | return $ret; |
||
| 157 | } |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Render a multicolumn checkbox or radio element |
||
| 161 | * |
||
| 162 | * @param XoopsFormCheckBox|XoopsFormRadio $element element being rendered |
||
| 163 | * @param string $type 'checkbox' or 'radio; |
||
| 164 | * @param string $elementId input 'id' attribute of element |
||
| 165 | * @param string $elementName input 'name' attribute of element |
||
| 166 | * @return string |
||
| 167 | */ |
||
| 168 | View Code Duplication | protected function renderCheckedColumnar($element, $type, $elementId, $elementName) |
|
| 169 | { |
||
| 170 | $class = $type; |
||
| 171 | $ret = ''; |
||
| 172 | |||
| 173 | $idSuffix = 0; |
||
| 174 | $elementValue = $element->getValue(); |
||
| 175 | $elementOptions = $element->getOptions(); |
||
| 176 | foreach ($elementOptions as $value => $name) { |
||
| 177 | ++$idSuffix; |
||
| 178 | $ret .= '<div class="' . $class . ' col-md-2">'; |
||
| 179 | $ret .= '<label>'; |
||
| 180 | $ret .= "<input type='" . $type . "' name='{$elementName}' id='{$elementId}{$idSuffix}' title='" |
||
| 181 | . htmlspecialchars(strip_tags($name), ENT_QUOTES) . "' value='" |
||
| 182 | . htmlspecialchars($value, ENT_QUOTES) . "'"; |
||
| 183 | |||
| 184 | if (is_array($elementValue) ? in_array($value, $elementValue): $value == $elementValue) { |
||
| 185 | $ret .= ' checked'; |
||
| 186 | } |
||
| 187 | $ret .= $element->getExtra() . ' />' . $name . $element->getDelimeter(); |
||
| 188 | $ret .= '</label>'; |
||
| 189 | $ret .= '</div>'; |
||
| 190 | } |
||
| 191 | |||
| 192 | return $ret; |
||
| 193 | } |
||
| 194 | /** |
||
| 195 | * Render support for XoopsFormColorPicker |
||
| 196 | * |
||
| 197 | * @param XoopsFormColorPicker $element form element |
||
| 198 | * |
||
| 199 | * @return string rendered form element |
||
| 200 | */ |
||
| 201 | public function renderFormColorPicker(XoopsFormColorPicker $element) |
||
| 202 | { |
||
| 203 | View Code Duplication | if (isset($GLOBALS['xoTheme'])) { |
|
| 204 | $GLOBALS['xoTheme']->addScript('include/spectrum.js'); |
||
| 205 | $GLOBALS['xoTheme']->addStylesheet('include/spectrum.css'); |
||
| 206 | } else { |
||
| 207 | echo '<script type="text/javascript" src="' . XOOPS_URL . '/include/spectrum.js"></script>'; |
||
| 208 | echo '<link rel="stylesheet" type="text/css" href="' . XOOPS_URL . '/include/spectrum.css">'; |
||
| 209 | } |
||
| 210 | return '<input class="form-control" style="width: 25%;" type="color" name="' . $element->getName() |
||
| 211 | . "' title='" . $element->getTitle() . "' id='" . $element->getName() |
||
| 212 | . '" size="7" maxlength="7" value="' . $element->getValue() . '"' . $element->getExtra() . ' />'; |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Render support for XoopsFormDhtmlTextArea |
||
| 217 | * |
||
| 218 | * @param XoopsFormDhtmlTextArea $element form element |
||
| 219 | * |
||
| 220 | * @return string rendered form element |
||
| 221 | */ |
||
| 222 | public function renderFormDhtmlTextArea(XoopsFormDhtmlTextArea $element) |
||
| 223 | { |
||
| 224 | static $js_loaded; |
||
| 225 | |||
| 226 | xoops_loadLanguage('formdhtmltextarea'); |
||
| 227 | $ret = ''; |
||
| 228 | // actions |
||
| 229 | $ret .= $this->renderFormDhtmlTAXoopsCode($element) . "<br>\n"; |
||
| 230 | // fonts |
||
| 231 | $ret .= $this->renderFormDhtmlTATypography($element); |
||
| 232 | // length checker |
||
| 233 | |||
| 234 | $ret .= "<br>\n"; |
||
| 235 | // the textarea box |
||
| 236 | $ret .= "<textarea class='form-control' id='" . $element->getName() . "' name='" . $element->getName() |
||
| 237 | . "' title='" . $element->getTitle() . "' onselect=\"xoopsSavePosition('" . $element->getName() |
||
| 238 | . "');\" onclick=\"xoopsSavePosition('" . $element->getName() |
||
| 239 | . "');\" onkeyup=\"xoopsSavePosition('" . $element->getName() . "');\" cols='" |
||
| 240 | . $element->getCols() . "' rows='" . $element->getRows() . "'" . $element->getExtra() |
||
| 241 | . '>' . $element->getValue() . "</textarea>\n"; |
||
| 242 | |||
| 243 | View Code Duplication | if (empty($element->skipPreview)) { |
|
| 244 | if (empty($GLOBALS['xoTheme'])) { |
||
| 245 | $element->js .= implode('', file(XOOPS_ROOT_PATH . '/class/textsanitizer/image/image.js')); |
||
| 246 | } else { |
||
| 247 | $GLOBALS['xoTheme']->addScript( |
||
| 248 | '/class/textsanitizer/image/image.js', |
||
| 249 | array('type' => 'text/javascript') |
||
| 250 | ); |
||
| 251 | } |
||
| 252 | $button = "<button type='button' class='btn btn-primary' onclick=\"form_instantPreview('" . XOOPS_URL |
||
| 253 | . "', '" . $element->getName() . "','" . XOOPS_URL . "/images', " . (int)$element->doHtml . ", '" |
||
| 254 | . $GLOBALS['xoopsSecurity']->createToken() . "')\" title='" . _PREVIEW . "'>" . _PREVIEW . "</button>"; |
||
| 255 | |||
| 256 | $ret .= '<br>' . "<div id='" . $element->getName() . "_hidden' style='display: block;'> " |
||
| 257 | . ' <fieldset>' . ' <legend>' . $button . '</legend>' |
||
| 258 | . " <div id='" . $element->getName() . "_hidden_data'>" . _XOOPS_FORM_PREVIEW_CONTENT |
||
| 259 | . '</div>' . ' </fieldset>' . '</div>'; |
||
| 260 | } |
||
| 261 | // Load javascript |
||
| 262 | View Code Duplication | if (empty($js_loaded)) { |
|
| 263 | $javascript = ($element->js ? '<script type="text/javascript">' . $element->js . '</script>' : '') |
||
| 264 | . '<script type="text/javascript" src="' . XOOPS_URL . '/include/formdhtmltextarea.js"></script>'; |
||
| 265 | $ret = $javascript . $ret; |
||
| 266 | $js_loaded = true; |
||
| 267 | } |
||
| 268 | |||
| 269 | return $ret; |
||
| 270 | } |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Render xoopscode buttons for editor, include calling text sanitizer extensions |
||
| 274 | * |
||
| 275 | * @param XoopsFormDhtmlTextArea $element form element |
||
| 276 | * |
||
| 277 | * @return string rendered buttons for xoopscode assistance |
||
| 278 | */ |
||
| 279 | View Code Duplication | protected function renderFormDhtmlTAXoopsCode(XoopsFormDhtmlTextArea $element) |
|
| 280 | { |
||
| 281 | $textarea_id = $element->getName(); |
||
| 282 | $code = ''; |
||
| 283 | $code .= "<div class='row'><div class='col-md-12'>"; |
||
| 284 | $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeUrl(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERURL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_URL . "'><span class='fa fa-fw fa-link' aria-hidden='true'></span></button>"; |
||
| 285 | $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeEmail(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTEREMAIL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_EMAIL . "'><span class='fa fa-fw fa-envelope-o' aria-hidden='true'></span></button>"; |
||
| 286 | $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeImg(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERIMGURL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ENTERIMGPOS, ENT_QUOTES) . "\", \"" . htmlspecialchars(_IMGPOSRORL, ENT_QUOTES) . "\", \"" . htmlspecialchars(_ERRORIMGPOS, ENT_QUOTES) . "\", \"" . htmlspecialchars(_XOOPS_FORM_ALT_ENTERWIDTH, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_IMG . "'><span class='fa fa-fw fa-file-image-o' aria-hidden='true'></span></button>"; |
||
| 287 | $code .= "<button type='button' class='btn btn-default btn-sm' onclick='openWithSelfMain(\"" . XOOPS_URL . "/imagemanager.php?target={$textarea_id}\",\"imgmanager\",400,430);' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_IMAGE . "'><span class='fa fa-file-image-o' aria-hidden='true'></span><small> Manager</small></button>"; |
||
| 288 | $code .= "<button type='button' class='btn btn-default btn-sm' onclick='openWithSelfMain(\"" . XOOPS_URL . "/misc.php?action=showpopups&type=smilies&target={$textarea_id}\",\"smilies\",300,475);' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_SMILEY . "'><span class='fa fa-fw fa-smile-o' aria-hidden='true'></span></button>"; |
||
| 289 | |||
| 290 | $myts = MyTextSanitizer::getInstance(); |
||
| 291 | |||
| 292 | $extensions = array_filter($myts->config['extensions']); |
||
| 293 | foreach (array_keys($extensions) as $key) { |
||
| 294 | $extension = $myts->loadExtension($key); |
||
| 295 | @list($encode, $js) = $extension->encode($textarea_id); |
||
| 296 | if (empty($encode)) { |
||
| 297 | continue; |
||
| 298 | } |
||
| 299 | $code .= $encode; |
||
| 300 | if (!empty($js)) { |
||
| 301 | $element->js .= $js; |
||
| 302 | } |
||
| 303 | } |
||
| 304 | $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeCode(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERCODE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_CODE . "'><span class='fa fa-fw fa-code' aria-hidden='true'></span></button>"; |
||
| 305 | $code .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsCodeQuote(\"{$textarea_id}\", \"" . htmlspecialchars(_ENTERQUOTE, ENT_QUOTES) . "\");' onmouseover='style.cursor=\"hand\"' title='" . _XOOPS_FORM_ALT_QUOTE . "'><span class='fa fa-fw fa-quote-right' aria-hidden='true'></span></button>"; |
||
| 306 | $code .= "</div></div>"; |
||
| 307 | |||
| 308 | $xoopsPreload = XoopsPreload::getInstance(); |
||
| 309 | $xoopsPreload->triggerEvent('core.class.xoopsform.formdhtmltextarea.codeicon', array(&$code)); |
||
| 310 | |||
| 311 | return $code; |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Render typography controls for editor (font, size, color) |
||
| 316 | * |
||
| 317 | * @param XoopsFormDhtmlTextArea $element form element |
||
| 318 | * |
||
| 319 | * @return string rendered typography controls |
||
| 320 | */ |
||
| 321 | protected function renderFormDhtmlTATypography(XoopsFormDhtmlTextArea $element) |
||
| 322 | { |
||
| 323 | $textarea_id = $element->getName(); |
||
| 324 | $hiddentext = $element->_hiddenText; |
||
| 325 | |||
| 326 | $fontarray = !empty($GLOBALS['formtextdhtml_fonts']) ? $GLOBALS['formtextdhtml_fonts'] : array( |
||
| 327 | 'Arial', |
||
| 328 | 'Courier', |
||
| 329 | 'Georgia', |
||
| 330 | 'Helvetica', |
||
| 331 | 'Impact', |
||
| 332 | 'Verdana', |
||
| 333 | 'Haettenschweiler'); |
||
| 334 | |||
| 335 | $colorArray = array( |
||
| 336 | 'Black' => '000000', |
||
| 337 | 'Blue' => '38AAFF', |
||
| 338 | 'Brown' => '987857', |
||
| 339 | 'Green' => '79D271', |
||
| 340 | 'Grey' => '888888', |
||
| 341 | 'Orange' => 'FFA700', |
||
| 342 | 'Paper' => 'E0E0E0', |
||
| 343 | 'Purple' => '363E98', |
||
| 344 | 'Red' => 'FF211E', |
||
| 345 | 'White' => 'FEFEFE', |
||
| 346 | 'Yellow' => 'FFD628', |
||
| 347 | ); |
||
| 348 | |||
| 349 | $fontStr = '<div class="row"><div class="col-md-12"><div class="btn-group" role="toolbar">'; |
||
| 350 | $fontStr .= '<div class="btn-group">' |
||
| 351 | . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. _SIZE .'"' |
||
| 352 | . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' |
||
| 353 | . '<span class = "glyphicon glyphicon-text-height"></span><span class="caret"></span></button>' |
||
| 354 | . '<ul class="dropdown-menu">'; |
||
| 355 | //. _SIZE . ' <span class="caret"></span></button><ul class="dropdown-menu">'; |
||
| 356 | View Code Duplication | foreach ($GLOBALS['formtextdhtml_sizes'] as $value => $name) { |
|
| 357 | $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'size\', \'' . $value . '\', \'' |
||
| 358 | . $textarea_id . '\', \'' . $hiddentext . '\');">' . $name . '</a></li>'; |
||
| 359 | } |
||
| 360 | $fontStr .= '</ul></div>'; |
||
| 361 | |||
| 362 | $fontStr .= '<div class="btn-group">' |
||
| 363 | . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. _FONT .'"' |
||
| 364 | . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' |
||
| 365 | . '<span class = "glyphicon glyphicon-font"></span><span class="caret"></span></button>' |
||
| 366 | . '<ul class="dropdown-menu">'; |
||
| 367 | //. _FONT . ' <span class="caret"></span></button><ul class="dropdown-menu">'; |
||
| 368 | View Code Duplication | foreach ($fontarray as $font) { |
|
| 369 | $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'font\', \'' . $font . '\', \'' |
||
| 370 | . $textarea_id . '\', \'' . $hiddentext . '\');">' . $font . '</a></li>'; |
||
| 371 | } |
||
| 372 | $fontStr .= '</ul></div>'; |
||
| 373 | |||
| 374 | $fontStr .= '<div class="btn-group">' |
||
| 375 | . '<button type="button" class="btn btn-default btn-sm dropdown-toggle" title="'. _COLOR .'"' |
||
| 376 | . ' data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' |
||
| 377 | . '<span class = "glyphicon glyphicon-text-color"></span><span class="caret"></span></button>' |
||
| 378 | . '<ul class="dropdown-menu">'; |
||
| 379 | //. _COLOR . ' <span class="caret"></span></button><ul class="dropdown-menu">'; |
||
| 380 | foreach ($colorArray as $color => $hex) { |
||
| 381 | $fontStr .= '<li><a href="javascript:xoopsSetElementAttribute(\'color\', \'' . $hex . '\', \'' |
||
| 382 | . $textarea_id . '\', \'' . $hiddentext . '\');">' |
||
| 383 | . '<span style="color:#' . $hex . ';">' . $color .'</span></a></li>'; |
||
| 384 | } |
||
| 385 | $fontStr .= '</ul></div>'; |
||
| 386 | $fontStr .= '</div>'; |
||
| 387 | |||
| 388 | //$styleStr = "<div class='row'><div class='col-md-12'>"; |
||
| 389 | $styleStr = "<div class='btn-group' role='group'>"; |
||
| 390 | $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeBold(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_BOLD . "' aria-label='Left Align'><span class='fa fa-bold' aria-hidden='true'></span></button>"; |
||
| 391 | $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeItalic(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_ITALIC . "' aria-label='Left Align'><span class='fa fa-italic' aria-hidden='true'></span></button>"; |
||
| 392 | $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeUnderline(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_UNDERLINE . "' aria-label='Left Align'>" . '<span class="fa fa-underline"></span></button>'; |
||
| 393 | $styleStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeLineThrough(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_LINETHROUGH . "' aria-label='Left Align'>" . '<span class="fa fa-strikethrough"></span></button>'; |
||
| 394 | $styleStr .= "</div>"; |
||
| 395 | |||
| 396 | $alignStr = "<div class='btn-group' role='group'>"; |
||
| 397 | $alignStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeLeft(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_LEFT . "' aria-label='Left Align'><span class='fa fa-align-left' aria-hidden='true'></span></button>"; |
||
| 398 | $alignStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeCenter(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_CENTER . "' aria-label='Left Align'><span class='fa fa-align-center' aria-hidden='true'></span></button>"; |
||
| 399 | $alignStr .= "<button type='button' class='btn btn-default btn-sm' onclick='xoopsMakeRight(\"{$hiddentext}\", \"{$textarea_id}\");' title='" . _XOOPS_FORM_ALT_RIGHT . "' aria-label='Left Align'><span class='fa fa-align-right' aria-hidden='true'></span></button>"; |
||
| 400 | $alignStr .= "</div>"; |
||
| 401 | |||
| 402 | $fontStr .= " {$styleStr} {$alignStr} \n"; |
||
| 403 | |||
| 404 | $fontStr .= "<button type='button' class='btn btn-default btn-sm' onclick=\"XoopsCheckLength('" |
||
| 405 | . $element->getName() . "', '" . @$element->configs['maxlength'] . "', '" |
||
|
|
|||
| 406 | . _XOOPS_FORM_ALT_LENGTH . "', '" . _XOOPS_FORM_ALT_LENGTH_MAX . "');\" title='" |
||
| 407 | . _XOOPS_FORM_ALT_CHECKLENGTH . "'><span class='fa fa-check-square-o' aria-hidden='true'></span></button>"; |
||
| 408 | $fontStr .= "</div></div>"; |
||
| 409 | |||
| 410 | return $fontStr; |
||
| 411 | } |
||
| 412 | |||
| 413 | /** |
||
| 414 | * Render support for XoopsFormElementTray |
||
| 415 | * |
||
| 416 | * @param XoopsFormElementTray $element form element |
||
| 417 | * |
||
| 418 | * @return string rendered form element |
||
| 419 | */ |
||
| 420 | View Code Duplication | public function renderFormElementTray(XoopsFormElementTray $element) |
|
| 421 | { |
||
| 422 | $count = 0; |
||
| 423 | $ret = '<span class="form-inline">'; |
||
| 424 | foreach ($element->getElements() as $ele) { |
||
| 425 | if ($count > 0) { |
||
| 426 | $ret .= $element->getDelimeter(); |
||
| 427 | } |
||
| 428 | if ($ele->getCaption() != '') { |
||
| 429 | $ret .= $ele->getCaption() . ' '; |
||
| 430 | } |
||
| 431 | $ret .= $ele->render() . NWLINE; |
||
| 432 | if (!$ele->isHidden()) { |
||
| 433 | ++$count; |
||
| 434 | } |
||
| 435 | } |
||
| 436 | /* |
||
| 437 | if (substr_count($ret, '<div class="form-group form-inline">') > 0) { |
||
| 438 | $ret = str_replace('<div class="form-group form-inline">', '', $ret); |
||
| 439 | $ret = str_replace('</div>', '', $ret); |
||
| 440 | } |
||
| 441 | if (substr_count($ret, '<div class="checkbox-inline">') > 0) { |
||
| 442 | $ret = str_replace('<div class="checkbox-inline">', '', $ret); |
||
| 443 | } |
||
| 444 | */ |
||
| 445 | $ret .= '</span>'; |
||
| 446 | return $ret; |
||
| 447 | } |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Render support for XoopsFormFile |
||
| 451 | * |
||
| 452 | * @param XoopsFormFile $element form element |
||
| 453 | * |
||
| 454 | * @return string rendered form element |
||
| 455 | */ |
||
| 456 | View Code Duplication | public function renderFormFile(XoopsFormFile $element) |
|
| 457 | { |
||
| 458 | return '<input type="hidden" name="MAX_FILE_SIZE" value="' . $element->getMaxFileSize() . '" />' |
||
| 459 | . '<input class="form-control-static" type="file" name="' . $element->getName() |
||
| 460 | . '" id="' . $element->getName() |
||
| 461 | . '" title="' . $element->getTitle() . '" ' . $element->getExtra() . ' />' |
||
| 462 | . '<input type="hidden" name="xoops_upload_file[]" id="xoops_upload_file[]" value="' |
||
| 463 | . $element->getName() . '" />'; |
||
| 464 | } |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Render support for XoopsFormLabel |
||
| 468 | * |
||
| 469 | * @param XoopsFormLabel $element form element |
||
| 470 | * |
||
| 471 | * @return string rendered form element |
||
| 472 | */ |
||
| 473 | public function renderFormLabel(XoopsFormLabel $element) |
||
| 474 | { |
||
| 475 | return '<div class="form-control-static">' . $element->getValue() . '</div>'; |
||
| 476 | } |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Render support for XoopsFormPassword |
||
| 480 | * |
||
| 481 | * @param XoopsFormPassword $element form element |
||
| 482 | * |
||
| 483 | * @return string rendered form element |
||
| 484 | */ |
||
| 485 | public function renderFormPassword(XoopsFormPassword $element) |
||
| 486 | { |
||
| 487 | return '<input class="form-control" type="password" name="' |
||
| 488 | . $element->getName() . '" id="' . $element->getName() . '" size="' . $element->getSize() |
||
| 489 | . '" maxlength="' . $element->getMaxlength() . '" value="' . $element->getValue() . '"' |
||
| 490 | . $element->getExtra() . ' ' . ($element->autoComplete ? '' : 'autocomplete="off" ') . '/>'; |
||
| 491 | } |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Render support for XoopsFormRadio |
||
| 495 | * |
||
| 496 | * @param XoopsFormRadio $element form element |
||
| 497 | * |
||
| 498 | * @return string rendered form element |
||
| 499 | */ |
||
| 500 | public function renderFormRadio(XoopsFormRadio $element) |
||
| 501 | { |
||
| 502 | |||
| 503 | $elementName = $element->getName(); |
||
| 504 | $elementId = $elementName; |
||
| 505 | |||
| 506 | View Code Duplication | switch ((int) ($element->columns)) { |
|
| 507 | case 0: |
||
| 508 | return $this->renderCheckedInline($element, 'radio', $elementId, $elementName); |
||
| 509 | case 1: |
||
| 510 | return $this->renderCheckedOneColumn($element, 'radio', $elementId, $elementName); |
||
| 511 | default: |
||
| 512 | return $this->renderCheckedColumnar($element, 'radio', $elementId, $elementName); |
||
| 513 | } |
||
| 514 | } |
||
| 515 | |||
| 516 | /** |
||
| 517 | * Render support for XoopsFormSelect |
||
| 518 | * |
||
| 519 | * @param XoopsFormSelect $element form element |
||
| 520 | * |
||
| 521 | * @return string rendered form element |
||
| 522 | */ |
||
| 523 | View Code Duplication | public function renderFormSelect(XoopsFormSelect $element) |
|
| 547 | } |
||
| 548 | /** |
||
| 549 | * Render support for XoopsFormText |
||
| 550 | * |
||
| 551 | * @param XoopsFormText $element form element |
||
| 552 | * |
||
| 553 | * @return string rendered form element |
||
| 554 | */ |
||
| 555 | View Code Duplication | public function renderFormText(XoopsFormText $element) |
|
| 561 | } |
||
| 562 | |||
| 563 | /** |
||
| 564 | * Render support for XoopsFormTextArea |
||
| 565 | * |
||
| 566 | * @param XoopsFormTextArea $element form element |
||
| 567 | * |
||
| 568 | * @return string rendered form element |
||
| 569 | */ |
||
| 570 | View Code Duplication | public function renderFormTextArea(XoopsFormTextArea $element) |
|
| 571 | { |
||
| 572 | return "<textarea class='form-control' name='" |
||
| 573 | . $element->getName() . "' id='" . $element->getName() . "' title='" . $element->getTitle() |
||
| 574 | . "' rows='" . $element->getRows() . "' cols='" . $element->getCols() . "'" |
||
| 575 | . $element->getExtra() . '>' . $element->getValue() . '</textarea>'; |
||
| 576 | } |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Render support for XoopsFormTextDateSelect |
||
| 580 | * |
||
| 581 | * @param XoopsFormTextDateSelect $element form element |
||
| 582 | * |
||
| 583 | * @return string rendered form element |
||
| 584 | */ |
||
| 585 | public function renderFormTextDateSelect(XoopsFormTextDateSelect $element) |
||
| 706 | } |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Render support for XoopsThemeForm |
||
| 710 | * |
||
| 711 | * @param XoopsThemeForm $form form to render |
||
| 712 | * |
||
| 713 | * @return string rendered form |
||
| 714 | */ |
||
| 715 | public function renderThemeForm(XoopsThemeForm $form) |
||
| 716 | { |
||
| 717 | $ele_name = $form->getName(); |
||
| 718 | |||
| 719 | $ret = '<div>'; |
||
| 720 | $ret .= '<form class="form-horizontal" name="' . $ele_name . '" id="' . $ele_name . '" action="' |
||
| 721 | . $form->getAction() . '" method="' . $form->getMethod() |
||
| 722 | . '" onsubmit="return xoopsFormValidate_' . $ele_name . '();"' . $form->getExtra() . '>' |
||
| 723 | . '<h3>' . $form->getTitle() . '</h3>'; |
||
| 724 | $hidden = ''; |
||
| 725 | |||
| 726 | foreach ($form->getElements() as $element) { |
||
| 727 | if (!is_object($element)) { // see $form->addBreak() |
||
| 728 | $ret .= $element; |
||
| 729 | continue; |
||
| 730 | } |
||
| 731 | if ($element->isHidden()) { |
||
| 732 | $hidden .= $element->render(); |
||
| 733 | continue; |
||
| 734 | } |
||
| 735 | |||
| 736 | $ret .= '<div class="form-group">'; |
||
| 737 | if (($caption = $element->getCaption()) != '') { |
||
| 738 | $ret .= '<label for="' . $element->getName() . '" class="col-md-2 control-label">' |
||
| 739 | . $element->getCaption() |
||
| 740 | . ($element->isRequired() ? '<span class="caption-required">*</span>' : '') |
||
| 741 | . '</label>'; |
||
| 742 | } else { |
||
| 743 | $ret .= '<div class="col-md-2"> </div>'; |
||
| 744 | } |
||
| 745 | $ret .= '<div class="col-md-10">'; |
||
| 746 | $ret .= $element->render(); |
||
| 747 | if (($desc = $element->getDescription()) != '') { |
||
| 748 | $ret .= '<p class="help-block">' . $desc . '</p>'; |
||
| 749 | } |
||
| 750 | $ret .= '</div>'; |
||
| 751 | $ret .= '</div>'; |
||
| 752 | } |
||
| 753 | $ret .= $hidden; |
||
| 754 | $ret .= '</form></div>'; |
||
| 755 | $ret .= $form->renderValidationJS(true); |
||
| 756 | |||
| 757 | return $ret; |
||
| 758 | } |
||
| 759 | |||
| 760 | /** |
||
| 761 | * Support for themed addBreak |
||
| 762 | * |
||
| 763 | * @param XoopsThemeForm $form |
||
| 764 | * @param string $extra pre-rendered content for break row |
||
| 765 | * @param string $class class for row |
||
| 766 | * |
||
| 767 | * @return void |
||
| 768 | */ |
||
| 769 | public function addThemeFormBreak(XoopsThemeForm $form, $extra, $class) |
||
| 773 | } |
||
| 774 | } |
||
| 775 |