| Total Complexity | 79 |
| Total Lines | 658 |
| Duplicated Lines | 42.71 % |
| Changes | 0 | ||
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 XoopsFormRendererLegacy 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.
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 XoopsFormRendererLegacy, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class XoopsFormRendererLegacy 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='formButton' name='" . $element->getName() |
||
| 34 | . "' id='" . $element->getName() . "' value='" . $element->getValue() . "' title='" |
||
| 35 | . $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) |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Render support for XoopsFormCheckBox |
||
| 63 | * |
||
| 64 | * @param XoopsFormCheckBox $element form element |
||
| 65 | * |
||
| 66 | * @return string rendered form element |
||
| 67 | */ |
||
| 68 | public function renderFormCheckBox(XoopsFormCheckBox $element) |
||
| 69 | { |
||
| 70 | $ele_name = $element->getName(); |
||
| 71 | $ele_title = $element->getTitle(); |
||
| 72 | $ele_id = $ele_name; |
||
| 73 | $ele_value = $element->getValue(); |
||
| 74 | $ele_options = $element->getOptions(); |
||
| 75 | $ele_extra = $element->getExtra(); |
||
| 76 | $ele_delimiter = empty($element->columns) ? $element->getDelimeter() : ''; |
||
| 77 | |||
| 78 | if (count($ele_options) > 1 && substr($ele_name, -2, 2) !== '[]') { |
||
| 79 | $ele_name .= '[]'; |
||
| 80 | $element->setName($ele_name); |
||
| 81 | } |
||
| 82 | $ret = ''; |
||
| 83 | /*<label class="checkbox-inline"> |
||
| 84 | <input type="checkbox" id="inlineCheckbox1" value="option1"> 1 |
||
| 85 | </label>*/ |
||
| 86 | if (!empty($element->columns)) { |
||
| 87 | $ret .= '<table><tr>'; |
||
| 88 | } |
||
| 89 | $i = 0; |
||
| 90 | $id_ele = 0; |
||
| 91 | foreach ($ele_options as $value => $name) { |
||
| 92 | ++$id_ele; |
||
| 93 | View Code Duplication | if (!empty($element->columns)) { |
|
| 94 | if ($i % $element->columns == 0) { |
||
| 95 | $ret .= '<tr>'; |
||
| 96 | } |
||
| 97 | $ret .= '<td>'; |
||
| 98 | } |
||
| 99 | // $name may be a link, should we use $name in the title tag? |
||
| 100 | $ret .= '<input type="checkbox" name="' . $ele_name . '" id="' . $ele_id .$id_ele . '" ' |
||
| 101 | . ' title="' . $ele_title . '" value="' . htmlspecialchars($value, ENT_QUOTES) . '"'; |
||
| 102 | |||
| 103 | if (count($ele_value) > 0 && in_array($value, $ele_value)) { |
||
| 104 | $ret .= ' checked'; |
||
| 105 | } |
||
| 106 | $ret .= $ele_extra . ' />' . '<label name="xolb_' . $ele_name . '" for="' |
||
| 107 | . $ele_id . $id_ele . '" >' . $name . '</label>' . $ele_delimiter; |
||
| 108 | |||
| 109 | |||
| 110 | View Code Duplication | if (!empty($element->columns)) { |
|
| 111 | $ret .= '</td>'; |
||
| 112 | if (++$i % $element->columns == 0) { |
||
| 113 | $ret .= '</tr>'; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | View Code Duplication | if (!empty($element->columns)) { |
|
| 118 | if ($span = $i % $element->columns) { |
||
| 119 | $ret .= '<td colspan="' . ($element->columns - $span) . '"></td></tr>'; |
||
| 120 | } |
||
| 121 | $ret .= '</table>'; |
||
| 122 | } |
||
| 123 | |||
| 124 | return $ret; |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Render support for XoopsFormColorPicker |
||
| 129 | * |
||
| 130 | * @param XoopsFormColorPicker $element form element |
||
| 131 | * |
||
| 132 | * @return string rendered form element |
||
| 133 | */ |
||
| 134 | public function renderFormColorPicker(XoopsFormColorPicker $element) |
||
| 135 | { |
||
| 136 | View Code Duplication | if (isset($GLOBALS['xoTheme'])) { |
|
| 137 | $GLOBALS['xoTheme']->addScript("browse.php?Frameworks/jquery/jquery.js"); |
||
| 138 | $GLOBALS['xoTheme']->addScript('include/spectrum.js'); |
||
| 139 | $GLOBALS['xoTheme']->addStylesheet('include/spectrum.css'); |
||
| 140 | } else { |
||
| 141 | echo '<script type="text/javascript" src="' . XOOPS_URL . '/include/spectrum.js"></script>'; |
||
| 142 | echo '<link rel="stylesheet" type="text/css" href="' . XOOPS_URL . '/include/spectrum.css">'; |
||
| 143 | } |
||
| 144 | return "<input type='color' name='" . $element->getName() . "' title='" . $element->getTitle() |
||
| 145 | . "' id='" . $element->getName() . "' size='" . $element->getSize() . "' maxlength='" |
||
| 146 | . $element->getMaxlength() . "' value='" . $element->getValue() . "'" . $element->getExtra() |
||
| 147 | . ' />'; |
||
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Render support for XoopsFormDhtmlTextArea |
||
| 152 | * |
||
| 153 | * @param XoopsFormDhtmlTextArea $element form element |
||
| 154 | * |
||
| 155 | * @return string rendered form element |
||
| 156 | */ |
||
| 157 | public function renderFormDhtmlTextArea(XoopsFormDhtmlTextArea $element) |
||
| 158 | { |
||
| 159 | static $js_loaded; |
||
| 160 | |||
| 161 | xoops_loadLanguage('formdhtmltextarea'); |
||
| 162 | $ret = ''; |
||
| 163 | // actions |
||
| 164 | $ret .= $this->renderFormDhtmlTAXoopsCode($element) . "<br>\n"; |
||
| 165 | // fonts |
||
| 166 | $ret .= $this->renderFormDhtmlTATypography($element); |
||
| 167 | // length checker |
||
| 168 | $ret .= "<button type='button' class='btn btn-default' onclick=\"XoopsCheckLength('" . $element->getName() . "', '" . @$element->configs['maxlength'] . "', '" . _XOOPS_FORM_ALT_LENGTH . "', '" . _XOOPS_FORM_ALT_LENGTH_MAX . "');\" title='" . _XOOPS_FORM_ALT_CHECKLENGTH . "'><span class='fa fa-check-square-o' aria-hidden='true'></span></button> "; |
||
|
|
|||
| 169 | $ret .= "<br>\n"; |
||
| 170 | // the textarea box |
||
| 171 | $ret .= "<textarea id='" . $element->getName() . "' name='" . $element->getName() . "' title='" . $element->getTitle() . "' onselect=\"xoopsSavePosition('" . $element->getName() . "');\" onclick=\"xoopsSavePosition('" . $element->getName() . "');\" onkeyup=\"xoopsSavePosition('" . $element->getName() . "');\" cols='" . $element->getCols() . "' rows='" . $element->getRows() . "'" . $element->getExtra() . '>' . $element->getValue() . "</textarea><br>\n"; |
||
| 172 | |||
| 173 | View Code Duplication | if (empty($element->skipPreview)) { |
|
| 174 | if (empty($GLOBALS['xoTheme'])) { |
||
| 175 | $element->js .= implode('', file(XOOPS_ROOT_PATH . '/class/textsanitizer/image/image.js')); |
||
| 176 | } else { |
||
| 177 | $GLOBALS['xoTheme']->addScript('/class/textsanitizer/image/image.js', array('type' => 'text/javascript')); |
||
| 178 | } |
||
| 179 | $button = "<button type='button' class='btn btn-primary' onclick=\"form_instantPreview('" . XOOPS_URL . "', '" . $element->getName() . "','" . XOOPS_URL . "/images', " . (int)$element->doHtml . ", '" . $GLOBALS['xoopsSecurity']->createToken() . "')\" title='" . _PREVIEW . "'>" . _PREVIEW . "</button>"; |
||
| 180 | |||
| 181 | $ret .= '<br>' . "<div id='" . $element->getName() . "_hidden' style='display: block;'> " . ' <fieldset>' . ' <legend>' . $button . '</legend>' . " <div id='" . $element->getName() . "_hidden_data'>" . _XOOPS_FORM_PREVIEW_CONTENT . '</div>' . ' </fieldset>' . '</div>'; |
||
| 182 | } |
||
| 183 | // Load javascript |
||
| 184 | View Code Duplication | if (empty($js_loaded)) { |
|
| 185 | $javascript = ($element->js ? '<script type="text/javascript">' . $element->js . '</script>' : '') . '<script type="text/javascript" src="' . XOOPS_URL . '/include/formdhtmltextarea.js"></script>'; |
||
| 186 | $ret = $javascript . $ret; |
||
| 187 | $js_loaded = true; |
||
| 188 | } |
||
| 189 | |||
| 190 | return $ret; |
||
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Render xoopscode buttons for editor, include calling text sanitizer extensions |
||
| 195 | * |
||
| 196 | * @param XoopsFormDhtmlTextArea $element form element |
||
| 197 | * |
||
| 198 | * @return string rendered buttons for xoopscode assistance |
||
| 199 | */ |
||
| 200 | View Code Duplication | protected function renderFormDhtmlTAXoopsCode(XoopsFormDhtmlTextArea $element) |
|
| 201 | { |
||
| 202 | $textarea_id = $element->getName(); |
||
| 203 | $code = ''; |
||
| 204 | $code .= '<a name="moresmiley"></a>'; |
||
| 205 | $code .= "<button type='button' class='btn btn-default' 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>"; |
||
| 206 | $code .= "<button type='button' class='btn btn-default' 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>"; |
||
| 207 | $code .= "<button type='button' class='btn btn-default' 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>"; |
||
| 208 | $code .= "<button type='button' class='btn btn-default' 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><span style='font-size:75%;'> Manager</span></button>"; |
||
| 209 | $code .= "<button type='button' class='btn btn-default' 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>"; |
||
| 210 | |||
| 211 | $myts = MyTextSanitizer::getInstance(); |
||
| 212 | |||
| 213 | $extensions = array_filter($myts->config['extensions']); |
||
| 214 | foreach (array_keys($extensions) as $key) { |
||
| 215 | $extension = $myts->loadExtension($key); |
||
| 216 | @list($encode, $js) = $extension->encode($textarea_id); |
||
| 217 | if (empty($encode)) { |
||
| 218 | continue; |
||
| 219 | } |
||
| 220 | $code .= $encode; |
||
| 221 | if (!empty($js)) { |
||
| 222 | $element->js .= $js; |
||
| 223 | } |
||
| 224 | } |
||
| 225 | $code .= "<button type='button' class='btn btn-default' 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>"; |
||
| 226 | $code .= "<button type='button' class='btn btn-default' 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>"; |
||
| 227 | |||
| 228 | $xoopsPreload = XoopsPreload::getInstance(); |
||
| 229 | $xoopsPreload->triggerEvent('core.class.xoopsform.formdhtmltextarea.codeicon', array(&$code)); |
||
| 230 | |||
| 231 | return $code; |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Render typography controls for editor (font, size, color) |
||
| 236 | * |
||
| 237 | * @param XoopsFormDhtmlTextArea $element form element |
||
| 238 | * |
||
| 239 | * @return string rendered typography controls |
||
| 240 | */ |
||
| 241 | protected function renderFormDhtmlTATypography(XoopsFormDhtmlTextArea $element) |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Render support for XoopsFormElementTray |
||
| 292 | * |
||
| 293 | * @param XoopsFormElementTray $element form element |
||
| 294 | * |
||
| 295 | * @return string rendered form element |
||
| 296 | */ |
||
| 297 | View Code Duplication | public function renderFormElementTray(XoopsFormElementTray $element) |
|
| 298 | { |
||
| 299 | $count = 0; |
||
| 300 | $ret = ''; |
||
| 301 | foreach ($element->getElements() as $ele) { |
||
| 302 | if ($count > 0) { |
||
| 303 | $ret .= $element->getDelimeter(); |
||
| 304 | } |
||
| 305 | if ($ele->getCaption() != '') { |
||
| 306 | $ret .= $ele->getCaption() . ' '; |
||
| 307 | } |
||
| 308 | $ret .= $ele->render() . NWLINE; |
||
| 309 | if (!$ele->isHidden()) { |
||
| 310 | ++$count; |
||
| 311 | } |
||
| 312 | } |
||
| 313 | return $ret; |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Render support for XoopsFormFile |
||
| 318 | * |
||
| 319 | * @param XoopsFormFile $element form element |
||
| 320 | * |
||
| 321 | * @return string rendered form element |
||
| 322 | */ |
||
| 323 | View Code Duplication | public function renderFormFile(XoopsFormFile $element) |
|
| 330 | |||
| 331 | } |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Render support for XoopsFormLabel |
||
| 335 | * |
||
| 336 | * @param XoopsFormLabel $element form element |
||
| 337 | * |
||
| 338 | * @return string rendered form element |
||
| 339 | */ |
||
| 340 | public function renderFormLabel(XoopsFormLabel $element) |
||
| 341 | { |
||
| 342 | return $element->getValue(); |
||
| 343 | } |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Render support for XoopsFormPassword |
||
| 347 | * |
||
| 348 | * @param XoopsFormPassword $element form element |
||
| 349 | * |
||
| 350 | * @return string rendered form element |
||
| 351 | */ |
||
| 352 | public function renderFormPassword(XoopsFormPassword $element) |
||
| 353 | { |
||
| 354 | return '<input type="password" name="' . $element->getName() . '" id="' . $element->getName() . '" size="' |
||
| 355 | . $element->getSize() . '" maxlength="' . $element->getMaxlength() . '" value="' . $element->getValue() |
||
| 356 | . '"' . $element->getExtra() . ' ' . ($element->autoComplete ? '' : 'autocomplete="off" ') . '/>'; |
||
| 357 | } |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Render support for XoopsFormRadio |
||
| 361 | * |
||
| 362 | * @param XoopsFormRadio $element form element |
||
| 363 | * |
||
| 364 | * @return string rendered form element |
||
| 365 | */ |
||
| 366 | public function renderFormRadio(XoopsFormRadio $element) |
||
| 367 | { |
||
| 368 | $ret = ''; |
||
| 369 | $ele_name = $element->getName(); |
||
| 370 | $ele_title = $element->getTitle(); |
||
| 371 | $ele_value = $element->getValue(); |
||
| 372 | $ele_options = $element->getOptions(); |
||
| 373 | $ele_extra = $element->getExtra(); |
||
| 374 | $ele_delimiter = empty($element->columns) ? $element->getDelimeter() : ''; |
||
| 375 | if (!empty($element->columns)) { |
||
| 376 | $ret .= '<table><tr>'; |
||
| 377 | } |
||
| 378 | $i = 0; |
||
| 379 | $id_ele = 0; |
||
| 380 | foreach ($ele_options as $value => $name) { |
||
| 381 | ++$id_ele; |
||
| 382 | View Code Duplication | if (!empty($element->columns)) { |
|
| 383 | if ($i % $element->columns == 0) { |
||
| 384 | $ret .= '<tr>'; |
||
| 385 | } |
||
| 386 | $ret .= '<td>'; |
||
| 387 | } |
||
| 388 | |||
| 389 | $ret .= '<input type="radio" name="' . $ele_name . '" id="' . $ele_name . $id_ele |
||
| 390 | . '" title = "' . htmlspecialchars($ele_title, ENT_QUOTES) . '" value="' |
||
| 391 | . htmlspecialchars($value, ENT_QUOTES) . '"'; |
||
| 392 | if (isset($ele_value) && $value == $ele_value) { |
||
| 393 | $ret .= ' checked'; |
||
| 394 | } |
||
| 395 | $ret .= $ele_extra . ' />' . "<label name='xolb_{$ele_name}' for='" . $ele_name . $id_ele |
||
| 396 | . "'>" . $name . '</label>' . $ele_delimiter; |
||
| 397 | View Code Duplication | if (!empty($element->columns)) { |
|
| 398 | $ret .= '</td>'; |
||
| 399 | if (++$i % $element->columns == 0) { |
||
| 400 | $ret .= '</tr>'; |
||
| 401 | } |
||
| 402 | } |
||
| 403 | } |
||
| 404 | View Code Duplication | if (!empty($element->columns)) { |
|
| 405 | if ($span = $i % $element->columns) { |
||
| 406 | $ret .= '<td colspan="' . ($element->columns - $span) . '"></td></tr>'; |
||
| 407 | } |
||
| 408 | $ret .= '</table>'; |
||
| 409 | } |
||
| 410 | |||
| 411 | return $ret; |
||
| 412 | } |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Render support for XoopsFormSelect |
||
| 416 | * |
||
| 417 | * @param XoopsFormSelect $element form element |
||
| 418 | * |
||
| 419 | * @return string rendered form element |
||
| 420 | */ |
||
| 421 | View Code Duplication | public function renderFormSelect(XoopsFormSelect $element) |
|
| 444 | } |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Render support for XoopsFormText |
||
| 448 | * |
||
| 449 | * @param XoopsFormText $element form element |
||
| 450 | * |
||
| 451 | * @return string rendered form element |
||
| 452 | */ |
||
| 453 | View Code Duplication | public function renderFormText(XoopsFormText $element) |
|
| 459 | } |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Render support for XoopsFormTextArea |
||
| 463 | * |
||
| 464 | * @param XoopsFormTextArea $element form element |
||
| 465 | * |
||
| 466 | * @return string rendered form element |
||
| 467 | */ |
||
| 468 | public function renderFormTextArea(XoopsFormTextArea $element) |
||
| 469 | { |
||
| 470 | return "<textarea name='" . $element->getName() . "' id='" . $element->getName() . "' title='" |
||
| 471 | . $element->getTitle() . "' rows='" . $element->getRows() . "' cols='" . $element->getCols() |
||
| 472 | . "'" . $element->getExtra() . '>' . $element->getValue() . '</textarea>'; |
||
| 473 | } |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Render support for XoopsFormTextDateSelect |
||
| 477 | * |
||
| 478 | * @param XoopsFormTextDateSelect $element form element |
||
| 479 | * |
||
| 480 | * @return string rendered form element |
||
| 481 | */ |
||
| 482 | public function renderFormTextDateSelect(XoopsFormTextDateSelect $element) |
||
| 483 | { |
||
| 484 | static $included = false; |
||
| 485 | View Code Duplication | if (file_exists(XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php')) { |
|
| 486 | include_once XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/calendar.php'; |
||
| 487 | } else { |
||
| 488 | include_once XOOPS_ROOT_PATH . '/language/english/calendar.php'; |
||
| 489 | } |
||
| 490 | |||
| 491 | $ele_name = $element->getName(); |
||
| 492 | $ele_value = $element->getValue(false); |
||
| 493 | View Code Duplication | if (is_string($ele_value)) { |
|
| 494 | $display_value = $ele_value; |
||
| 495 | $ele_value = time(); |
||
| 496 | } else { |
||
| 497 | $display_value = date(_SHORTDATESTRING, $ele_value); |
||
| 498 | } |
||
| 499 | |||
| 500 | $jstime = formatTimestamp($ele_value, _SHORTDATESTRING); |
||
| 501 | View Code Duplication | if (isset($GLOBALS['xoTheme']) && is_object($GLOBALS['xoTheme'])) { |
|
| 502 | $GLOBALS['xoTheme']->addScript('include/calendar.js'); |
||
| 503 | $GLOBALS['xoTheme']->addStylesheet('include/calendar-blue.css'); |
||
| 504 | if (!$included) { |
||
| 505 | $included = true; |
||
| 506 | $GLOBALS['xoTheme']->addScript('', '', ' |
||
| 507 | var calendar = null; |
||
| 508 | |||
| 509 | function selected(cal, date) |
||
| 510 | { |
||
| 511 | cal.sel.value = date; |
||
| 512 | } |
||
| 513 | |||
| 514 | function closeHandler(cal) |
||
| 515 | { |
||
| 516 | cal.hide(); |
||
| 517 | Calendar.removeEvent(document, "mousedown", checkCalendar); |
||
| 518 | } |
||
| 519 | |||
| 520 | function checkCalendar(ev) |
||
| 521 | { |
||
| 522 | var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev); |
||
| 523 | for (; el != null; el = el.parentNode) |
||
| 524 | if (el == calendar.element || el.tagName == "A") break; |
||
| 525 | if (el == null) { |
||
| 526 | calendar.callCloseHandler(); Calendar.stopEvent(ev); |
||
| 527 | } |
||
| 528 | } |
||
| 529 | function showCalendar(id) |
||
| 530 | { |
||
| 531 | var el = xoopsGetElementById(id); |
||
| 532 | if (calendar != null) { |
||
| 533 | calendar.hide(); |
||
| 534 | } else { |
||
| 535 | var cal = new Calendar(true, "' . $jstime . '", selected, closeHandler); |
||
| 536 | calendar = cal; |
||
| 537 | cal.setRange(1900, 2100); |
||
| 538 | calendar.create(); |
||
| 539 | } |
||
| 540 | calendar.sel = el; |
||
| 541 | calendar.parseDate(el.value); |
||
| 542 | calendar.showAtElement(el); |
||
| 543 | Calendar.addEvent(document, "mousedown", checkCalendar); |
||
| 544 | |||
| 545 | return false; |
||
| 546 | } |
||
| 547 | |||
| 548 | Calendar._DN = new Array |
||
| 549 | ("' . _CAL_SUNDAY . '", |
||
| 550 | "' . _CAL_MONDAY . '", |
||
| 551 | "' . _CAL_TUESDAY . '", |
||
| 552 | "' . _CAL_WEDNESDAY . '", |
||
| 553 | "' . _CAL_THURSDAY . '", |
||
| 554 | "' . _CAL_FRIDAY . '", |
||
| 555 | "' . _CAL_SATURDAY . '", |
||
| 556 | "' . _CAL_SUNDAY . '"); |
||
| 557 | Calendar._MN = new Array |
||
| 558 | ("' . _CAL_JANUARY . '", |
||
| 559 | "' . _CAL_FEBRUARY . '", |
||
| 560 | "' . _CAL_MARCH . '", |
||
| 561 | "' . _CAL_APRIL . '", |
||
| 562 | "' . _CAL_MAY . '", |
||
| 563 | "' . _CAL_JUNE . '", |
||
| 564 | "' . _CAL_JULY . '", |
||
| 565 | "' . _CAL_AUGUST . '", |
||
| 566 | "' . _CAL_SEPTEMBER . '", |
||
| 567 | "' . _CAL_OCTOBER . '", |
||
| 568 | "' . _CAL_NOVEMBER . '", |
||
| 569 | "' . _CAL_DECEMBER . '"); |
||
| 570 | |||
| 571 | Calendar._TT = {}; |
||
| 572 | Calendar._TT["TOGGLE"] = "' . _CAL_TGL1STD . '"; |
||
| 573 | Calendar._TT["PREV_YEAR"] = "' . _CAL_PREVYR . '"; |
||
| 574 | Calendar._TT["PREV_MONTH"] = "' . _CAL_PREVMNTH . '"; |
||
| 575 | Calendar._TT["GO_TODAY"] = "' . _CAL_GOTODAY . '"; |
||
| 576 | Calendar._TT["NEXT_MONTH"] = "' . _CAL_NXTMNTH . '"; |
||
| 577 | Calendar._TT["NEXT_YEAR"] = "' . _CAL_NEXTYR . '"; |
||
| 578 | Calendar._TT["SEL_DATE"] = "' . _CAL_SELDATE . '"; |
||
| 579 | Calendar._TT["DRAG_TO_MOVE"] = "' . _CAL_DRAGMOVE . '"; |
||
| 580 | Calendar._TT["PART_TODAY"] = "(' . _CAL_TODAY . ')"; |
||
| 581 | Calendar._TT["MON_FIRST"] = "' . _CAL_DISPM1ST . '"; |
||
| 582 | Calendar._TT["SUN_FIRST"] = "' . _CAL_DISPS1ST . '"; |
||
| 583 | Calendar._TT["CLOSE"] = "' . _CLOSE . '"; |
||
| 584 | Calendar._TT["TODAY"] = "' . _CAL_TODAY . '"; |
||
| 585 | |||
| 586 | // date formats |
||
| 587 | Calendar._TT["DEF_DATE_FORMAT"] = "' . _SHORTDATESTRING . '"; |
||
| 588 | Calendar._TT["TT_DATE_FORMAT"] = "' . _SHORTDATESTRING . '"; |
||
| 589 | |||
| 590 | Calendar._TT["WK"] = ""; |
||
| 591 | '); |
||
| 592 | } |
||
| 593 | } |
||
| 594 | return '<input type="text" name="' . $ele_name . '" id="' . $ele_name . '" size="' |
||
| 595 | . $element->getSize() . '" maxlength="' . $element->getMaxlength() . '" value="' |
||
| 596 | . $display_value . '"' . $element->getExtra() |
||
| 597 | . ' /><input type="reset" value=" ... " onclick="return showCalendar(\'' . $ele_name |
||
| 598 | . '\');">'; |
||
| 599 | /* |
||
| 600 | return "<input type='text' name='" . $ele_name . "' id='" . $ele_name . "' size='" |
||
| 601 | . $element->getSize() . "' maxlength='" . $element->getMaxlength() . "' value='" |
||
| 602 | . $display_value . "'" . $element->getExtra() |
||
| 603 | . " /><input type='reset' value=' ... ' onclick='return showCalendar(\"" . $ele_name |
||
| 604 | . "\");'>"; |
||
| 605 | */ |
||
| 606 | } |
||
| 607 | |||
| 608 | /** |
||
| 609 | * Render support for XoopsThemeForm |
||
| 610 | * |
||
| 611 | * @param XoopsThemeForm $form form to render |
||
| 612 | * |
||
| 613 | * @return string rendered form |
||
| 614 | */ |
||
| 615 | public function renderThemeForm(XoopsThemeForm $form) |
||
| 658 | } |
||
| 659 | |||
| 660 | /** |
||
| 661 | * Support for themed addBreak |
||
| 662 | * |
||
| 663 | * @param XoopsThemeForm $form |
||
| 664 | * @param string $extra pre-rendered content for break row |
||
| 665 | * @param string $class class for row |
||
| 666 | * |
||
| 667 | * @return void |
||
| 668 | */ |
||
| 669 | public function addThemeFormBreak(XoopsThemeForm $form, $extra, $class) |
||
| 682 |