ggoffy /
modulebuilder
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||
| 2 | |||
| 3 | namespace XoopsModules\Modulebuilder\Files\Templates\Admin; |
||
| 4 | |||
| 5 | use XoopsModules\Modulebuilder; |
||
| 6 | use XoopsModules\Modulebuilder\{ |
||
| 7 | Files, |
||
| 8 | Constants |
||
| 9 | }; |
||
| 10 | |||
| 11 | /* |
||
| 12 | You may not change or alter any portion of this comment or credits |
||
| 13 | of supporting developers from this source code or any supporting source code |
||
| 14 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 15 | |||
| 16 | This program is distributed in the hope that it will be useful, |
||
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 19 | */ |
||
| 20 | /** |
||
| 21 | * modulebuilder module. |
||
| 22 | * |
||
| 23 | * @copyright XOOPS Project (https://xoops.org) |
||
| 24 | * @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
||
| 25 | * |
||
| 26 | * @since 2.5.0 |
||
| 27 | * |
||
| 28 | * @author Txmod Xoops https://xoops.org |
||
| 29 | * Goffy https://myxoops.org |
||
| 30 | * |
||
| 31 | */ |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Class TemplatesAdminPages. |
||
| 35 | */ |
||
| 36 | class TemplatesAdminPages extends Files\CreateFile |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * @var mixed |
||
| 40 | */ |
||
| 41 | private $hc = null; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var mixed |
||
| 45 | */ |
||
| 46 | private $sc = null; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @public function constructor |
||
| 50 | * @param null |
||
| 51 | */ |
||
| 52 | public function __construct() |
||
| 53 | { |
||
| 54 | parent::__construct(); |
||
| 55 | $this->hc = Modulebuilder\Files\CreateHtmlCode::getInstance(); |
||
| 56 | $this->sc = Modulebuilder\Files\CreateSmartyCode::getInstance(); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @static function getInstance |
||
| 61 | * @param null |
||
| 62 | * @return TemplatesAdminPages |
||
| 63 | */ |
||
| 64 | public static function getInstance() |
||
| 65 | { |
||
| 66 | static $instance = false; |
||
| 67 | if (!$instance) { |
||
| 68 | $instance = new self(); |
||
| 69 | } |
||
| 70 | |||
| 71 | return $instance; |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @public function write |
||
| 76 | * @param $module |
||
| 77 | * @param $table |
||
| 78 | * @param string $filename |
||
| 79 | */ |
||
| 80 | public function write($module, $table, $filename) |
||
| 81 | { |
||
| 82 | $this->setModule($module); |
||
| 83 | $this->setTable($table); |
||
| 84 | $this->setFileName($filename); |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @private function getTemplatesAdminPagesHeader |
||
| 89 | * @param string $moduleDirname |
||
| 90 | * @return string |
||
| 91 | */ |
||
| 92 | private function getTemplatesAdminPagesHeader($moduleDirname) |
||
| 93 | { |
||
| 94 | $ret = $this->hc->getHtmlComment('Header', '',"\n"); |
||
| 95 | $ret .= $this->sc->getSmartyIncludeFile($moduleDirname, 'header', true, '', '', "\n\n"); |
||
| 96 | |||
| 97 | return $ret; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @private function getTemplatesAdminPagesTableThead |
||
| 102 | * @param $tableSoleName |
||
| 103 | * @param $tableAutoincrement |
||
| 104 | * @param array $fields |
||
| 105 | * @param string $language |
||
| 106 | * @return string |
||
| 107 | */ |
||
| 108 | private function getTemplatesAdminPagesTableThead($tableSoleName, $tableAutoincrement, $fields, $language) |
||
| 109 | { |
||
| 110 | $th = ''; |
||
| 111 | $langHeadId = \mb_strtoupper($tableSoleName) . '_ID'; |
||
| 112 | if (1 == $tableAutoincrement) { |
||
| 113 | $lang = $this->sc->getSmartyConst($language, $langHeadId); |
||
| 114 | $th .= $this->hc->getHtmlTag('th', ['class' => 'center'], $lang, false, "\t\t\t\t"); |
||
| 115 | } |
||
| 116 | foreach (\array_keys($fields) as $f) { |
||
| 117 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 118 | $rpFieldName = $this->getRightString($fieldName); |
||
| 119 | $langFieldName = \mb_strtoupper($tableSoleName) . '_' . \mb_strtoupper($rpFieldName); |
||
| 120 | if (1 == $fields[$f]->getVar('field_inlist')) { |
||
| 121 | $lang = $this->sc->getSmartyConst($language, $langFieldName); |
||
| 122 | $th .= $this->hc->getHtmlTag('th', ['class' => 'center'], $lang, false, "\t\t\t\t"); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | $lang = $this->sc->getSmartyConst($language, 'FORM_ACTION'); |
||
| 127 | $th .= $this->hc->getHtmlTag('th', ['class' => 'center width5'], $lang, false, "\t\t\t\t"); |
||
| 128 | $tr = $this->hc->getHtmlTableRow($th, 'head', "\t\t\t"); |
||
| 129 | $ret = $this->hc->getHtmlTableThead($tr, '', "\t\t"); |
||
| 130 | |||
| 131 | return $ret; |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @private function getTemplatesAdminPagesTableTBody |
||
| 136 | * @param string $moduleDirname |
||
| 137 | * @param string $tableName |
||
| 138 | * @param $tableSoleName |
||
| 139 | * @param $tableAutoincrement |
||
| 140 | * @param array $fields |
||
| 141 | * @return string |
||
| 142 | * @internal param string $language |
||
| 143 | */ |
||
| 144 | private function getTemplatesAdminPagesTableTBody($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields) |
||
| 145 | { |
||
| 146 | $td = ''; |
||
| 147 | if (1 == $tableAutoincrement) { |
||
| 148 | $double = $this->sc->getSmartyDoubleVar($tableSoleName, 'id'); |
||
| 149 | $td .= $this->hc->getHtmlTableData($double, 'center', '',"\t\t\t\t"); |
||
| 150 | } |
||
| 151 | $fieldId = ''; |
||
| 152 | foreach (\array_keys($fields) as $f) { |
||
| 153 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 154 | $fieldElement = $fields[$f]->getVar('field_element'); |
||
| 155 | $rpFieldName = $this->getRightString($fieldName); |
||
| 156 | if (0 == $f) { |
||
| 157 | $fieldId = $fieldName; |
||
| 158 | } |
||
| 159 | if (1 == $fields[$f]->getVar('field_inlist')) { |
||
| 160 | switch ($fieldElement) { |
||
| 161 | case Constants::FIELD_ELE_TEXTAREA: |
||
| 162 | case Constants::FIELD_ELE_DHTMLTEXTAREA: |
||
| 163 | $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName . '_short'); |
||
| 164 | $td .= $this->hc->getHtmlTableData($double, 'center', '',"\t\t\t\t"); |
||
| 165 | break; |
||
| 166 | case Constants::FIELD_ELE_CHECKBOX: |
||
| 167 | $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
||
| 168 | $src = $this->sc->getSmartyNoSimbol('xoModuleIcons16') . $double . '.png'; |
||
| 169 | $img = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $tableName], '', true,'',''); |
||
| 170 | $td .= $this->hc->getHtmlTableData($img, 'center', '',"\t\t\t\t"); |
||
| 171 | break; |
||
| 172 | case Constants::FIELD_ELE_COLORPICKER: |
||
| 173 | // This is to be reviewed, as it was initially to style = "backgroung-color: #" |
||
| 174 | // Now with HTML5 is not supported inline style in the parameters of the HTML tag |
||
| 175 | // Old code was <span style="background-color: #<{\$list.{$rpFieldName}}>;">... |
||
| 176 | $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
||
| 177 | $color = "<span style='background-color:{$double};'> </span>"; |
||
| 178 | $td .= $this->hc->getHtmlTableData($color, 'center', '',"\t\t\t\t"); |
||
| 179 | break; |
||
| 180 | case Constants::FIELD_ELE_IMAGELIST: |
||
| 181 | $src = $this->sc->getSmartyNoSimbol('xoModuleIcons32'); |
||
| 182 | $src .= $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
||
| 183 | $img = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $tableName], '', true,'',''); |
||
| 184 | $td .= $this->hc->getHtmlTableData($img, 'center', '',"\t\t\t\t"); |
||
| 185 | break; |
||
| 186 | case Constants::FIELD_ELE_UPLOADIMAGE: |
||
| 187 | $single = $this->sc->getSmartySingleVar($moduleDirname . '_upload_url'); |
||
| 188 | $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
||
| 189 | $img = $this->hc->getHtmlTag('img', ['src' => $single . "/images/{$tableName}/" . $double, 'alt' => $tableName, 'style' => 'max-width:100px'], '', true, '', ''); |
||
| 190 | $td .= $this->hc->getHtmlTableData($img, 'center', '',"\t\t\t\t"); |
||
| 191 | break; |
||
| 192 | case Constants::FIELD_ELE_SELECTSTATUS: |
||
| 193 | $double = $this->sc->getSmartyDoubleVar($tableSoleName, 'status'); |
||
| 194 | $src = $this->sc->getSmartyNoSimbol('$modPathIcon16') . 'status' . $double . '.png'; |
||
| 195 | $imgAlt = $this->sc->getSmartyDoubleVar($tableSoleName, 'status_text'); |
||
| 196 | $img = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $imgAlt, 'title' => $imgAlt], '', true,'',''); |
||
| 197 | $td .= $this->hc->getHtmlTableData($img, 'center', '',"\t\t\t\t"); |
||
| 198 | break; |
||
| 199 | default: |
||
| 200 | if (0 != $f) { |
||
| 201 | $double = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
||
| 202 | $td .= $this->hc->getHtmlTableData($double, 'center', '',"\t\t\t\t"); |
||
| 203 | } |
||
| 204 | break; |
||
| 205 | } |
||
| 206 | } |
||
| 207 | } |
||
| 208 | $lang = $this->sc->getSmartyConst('', '_EDIT'); |
||
| 209 | $double = $this->sc->getSmartyDoubleVar($tableSoleName, 'id'); |
||
| 210 | $src = $this->sc->getSmartyNoSimbol('xoModuleIcons16 edit.png'); |
||
| 211 | $img = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $lang . ' ' . $tableName], '', true,'', ''); |
||
| 212 | $anchor = $this->hc->getHtmlTag('a', ['href' => $tableName . ".php?op=edit&{$fieldId}=" . $double . '&start=<{$start}>&limit=<{$limit}>', 'title' => $lang], $img, false, "\t\t\t\t\t"); |
||
| 213 | $lang = $this->sc->getSmartyConst('', '_CLONE'); |
||
| 214 | $double = $this->sc->getSmartyDoubleVar($tableSoleName, 'id'); |
||
| 215 | $src = $this->sc->getSmartyNoSimbol('xoModuleIcons16 editcopy.png'); |
||
| 216 | $img = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $lang . ' ' . $tableName], '', true,'', ''); |
||
| 217 | $anchor .= $this->hc->getHtmlTag('a', ['href' => $tableName . ".php?op=clone&{$fieldId}_source=" . $double, 'title' => $lang], $img, false, "\t\t\t\t\t"); |
||
| 218 | $lang = $this->sc->getSmartyConst('', '_DELETE'); |
||
| 219 | $double = $this->sc->getSmartyDoubleVar($tableSoleName, 'id'); |
||
| 220 | $src = $this->sc->getSmartyNoSimbol('xoModuleIcons16 delete.png'); |
||
| 221 | $img = $this->hc->getHtmlTag('img', ['src' => $src, 'alt' => $lang . ' ' . $tableName], '', true, '', ''); |
||
| 222 | $anchor .= $this->hc->getHtmlTag('a', ['href' => $tableName . ".php?op=delete&{$fieldId}=" . $double, 'title' => $lang], $img, false, "\t\t\t\t\t"); |
||
| 223 | $td .= $this->hc->getHtmlTag('td', ['class' => 'center width5'], "\n" . $anchor . "\t\t\t\t", false, "\t\t\t\t"); |
||
| 224 | $cycle = $this->sc->getSmartyNoSimbol('cycle values=\'odd, even\''); |
||
| 225 | $tr = $this->hc->getHtmlTableRow($td, $cycle, "\t\t\t"); |
||
| 226 | $foreach = $this->sc->getSmartyForeach($tableSoleName, $tableName . '_list', $tr, '','', "\t\t\t"); |
||
| 227 | $tbody = $this->hc->getHtmlTableTbody($foreach,'' , "\t\t"); |
||
| 228 | |||
| 229 | return $this->sc->getSmartyConditions($tableName . '_count', '', '', $tbody, '', false, false, "\t\t"); |
||
| 230 | } |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @private function getTemplatesAdminPagesTable |
||
| 234 | * @param string $moduleDirname |
||
| 235 | * @param string $tableName |
||
| 236 | * @param $tableSoleName |
||
| 237 | * @param $tableAutoincrement |
||
| 238 | * @param $fields |
||
| 239 | * @param string $language |
||
| 240 | * @return string |
||
| 241 | */ |
||
| 242 | private function getTemplatesAdminPagesTable($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language) |
||
| 243 | { |
||
| 244 | $tbody = $this->getTemplatesAdminPagesTableThead($tableSoleName, $tableAutoincrement, $fields, $language); |
||
| 245 | $tbody .= $this->getTemplatesAdminPagesTableTBody($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields); |
||
| 246 | |||
| 247 | return $this->hc->getHtmlTable($tbody, 'table table-bordered', "\t"); |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @private function getTemplatesAdminPages |
||
| 252 | * @param string $moduleDirname |
||
| 253 | * @param string $tableName |
||
| 254 | * @param $tableSoleName |
||
| 255 | * @param $tableAutoincrement |
||
| 256 | * @param $fields |
||
| 257 | * @param string $language |
||
| 258 | * @return string |
||
| 259 | */ |
||
| 260 | private function getTemplatesAdminPages($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language) |
||
| 261 | { |
||
| 262 | $htmlTable = $this->getTemplatesAdminPagesTable($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $language); |
||
| 263 | $htmlTable .= $this->hc->getHtmlTag('div', ['class' => 'clear'], ' ', false, "\t"); |
||
| 264 | $single = $this->sc->getSmartySingleVar('pagenav'); |
||
| 265 | $div = $this->hc->getHtmlTag('div', ['class' => 'xo-pagenav floatright'], $single, false, "\t\t"); |
||
| 266 | $div .= $this->hc->getHtmlTag('div', ['class' => 'clear spacer'], '', false, "\t\t", "\n"); |
||
| 267 | $htmlTable .= $this->sc->getSmartyConditions('pagenav', '', '', $div, '', '', '', "\t" ); |
||
| 268 | $ifList = $this->sc->getSmartyConditions($tableName . '_list', '', '', $htmlTable); |
||
| 269 | $single = $this->sc->getSmartySingleVar('form', "\t", "\n"); |
||
| 270 | $ifList .= $this->sc->getSmartyConditions('form', '', '', $single); |
||
| 271 | $single = $this->sc->getSmartySingleVar('error'); |
||
| 272 | $strong = $this->hc->getHtmlTag('strong', [], $single, false, '', ''); |
||
| 273 | $div = $this->hc->getHtmlTag('div', ['class' => 'errorMsg'], $strong, false, "\t", "\n"); |
||
| 274 | $ifList .= $this->sc->getSmartyConditions('error', '', '', $div); |
||
| 275 | $ifList .= $this->hc->getHtmlEmpty('', '', "\n"); |
||
| 276 | |||
| 277 | return $ifList; |
||
| 278 | } |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @private function getTemplatesAdminPagesFooter |
||
| 282 | * @param string $moduleDirname |
||
| 283 | * @return string |
||
| 284 | */ |
||
| 285 | private function getTemplatesAdminPagesFooter($moduleDirname) |
||
| 286 | { |
||
| 287 | $ret = $this->hc->getHtmlComment('Footer', '', "\n"); |
||
| 288 | $ret .= $this->sc->getSmartyIncludeFile($moduleDirname, 'footer', true); |
||
| 289 | |||
| 290 | return $ret; |
||
| 291 | } |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @public function render |
||
| 295 | * @param null |
||
| 296 | * @return bool|string |
||
| 297 | */ |
||
| 298 | public function render() |
||
| 299 | { |
||
| 300 | $module = $this->getModule(); |
||
| 301 | $table = $this->getTable(); |
||
| 302 | $filename = $this->getFileName(); |
||
| 303 | $moduleDirname = $module->getVar('mod_dirname'); |
||
| 304 | $language = $this->getLanguage($moduleDirname, 'AM', '', false); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 305 | $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'), 'field_order'); |
||
| 306 | $content = $this->getTemplatesAdminPagesHeader($moduleDirname); |
||
| 307 | $content .= $this->getTemplatesAdminPages($moduleDirname, $table->getVar('table_name'), $table->getVar('table_solename'), $table->getVar('table_autoincrement'), $fields, $language); |
||
| 308 | $content .= $this->getTemplatesAdminPagesFooter($moduleDirname); |
||
| 309 | |||
| 310 | $this->create($moduleDirname, 'templates/admin', $filename, $content, \_AM_MODULEBUILDER_FILE_CREATED, \_AM_MODULEBUILDER_FILE_NOTCREATED); |
||
| 311 | |||
| 312 | return $this->renderFile(); |
||
| 313 | } |
||
| 314 | } |
||
| 315 |