XoopsModules25x /
songlist
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 declare(strict_types=1); |
||||||
| 2 | |||||||
| 3 | use Xmf\Module\Admin; |
||||||
| 4 | use Xmf\Request; |
||||||
| 5 | use XoopsModules\Songlist\Helper; |
||||||
| 6 | use XoopsModules\Songlist\Form\FormController; |
||||||
| 7 | |||||||
| 8 | require_once __DIR__ . '/header.php'; |
||||||
| 9 | xoops_cp_header(); |
||||||
| 10 | |||||||
| 11 | $op = (!empty($_GET['op']) ? $_GET['op'] : (!empty($_POST['op']) ? $_POST['op'] : (!empty($_REQUEST['id']) ? 'edit' : 'list'))); |
||||||
| 12 | $fieldHandler = Helper::getInstance() |
||||||
| 13 | ->getHandler('Field'); |
||||||
| 14 | switch ($op) { |
||||||
| 15 | default: |
||||||
| 16 | case 'list': |
||||||
| 17 | $adminObject = Admin::getInstance(); |
||||||
| 18 | $adminObject->displayNavigation(basename(__FILE__)); |
||||||
| 19 | |||||||
| 20 | $fields = $fieldHandler->getObjects(null, false, false); |
||||||
| 21 | |||||||
| 22 | /** @var \XoopsModuleHandler $moduleHandler */ |
||||||
| 23 | $moduleHandler = xoops_getHandler('module'); |
||||||
| 24 | $modules = $moduleHandler->getObjects(null, true); |
||||||
| 25 | |||||||
| 26 | $categories = []; |
||||||
| 27 | $weights = []; |
||||||
| 28 | |||||||
| 29 | $GLOBALS['categoryHandler'] = Helper::getInstance() |
||||||
| 30 | ->getHandler('Category'); |
||||||
| 31 | $criteria = new \CriteriaCompo(); |
||||||
| 32 | $criteria->setSort('weight'); |
||||||
| 33 | $category = $GLOBALS['categoryHandler']->getObjects($criteria, true); |
||||||
| 34 | $fieldcategories = []; |
||||||
| 35 | if ($category) { |
||||||
| 36 | unset($criteria); |
||||||
| 37 | |||||||
| 38 | $categories[0] = ['cid' => 0, 'name' => _AM_SONGLIST_FIELDS_DEFAULT]; |
||||||
| 39 | if (count($category) > 0) { |
||||||
| 40 | foreach (array_keys($category) as $i) { |
||||||
| 41 | $categories[$category[$i]->getVar('cid')] = ['cid' => $category[$i]->getVar('cid'), 'name' => $category[$i]->getVar('name')]; |
||||||
| 42 | } |
||||||
| 43 | } |
||||||
| 44 | $GLOBALS['xoopsTpl']->assign('categories', $categories); |
||||||
| 45 | } |
||||||
| 46 | |||||||
| 47 | $valuetypes = [ |
||||||
| 48 | XOBJ_DTYPE_ARRAY => _AM_SONGLIST_FIELDS_ARRAY, |
||||||
| 49 | XOBJ_DTYPE_EMAIL => _AM_SONGLIST_FIELDS_EMAIL, |
||||||
| 50 | XOBJ_DTYPE_INT => _AM_SONGLIST_FIELDS_INT, |
||||||
| 51 | XOBJ_DTYPE_TXTAREA => _AM_SONGLIST_FIELDS_TXTAREA, |
||||||
| 52 | XOBJ_DTYPE_TXTBOX => _AM_SONGLIST_FIELDS_TXTBOX, |
||||||
| 53 | XOBJ_DTYPE_URL => _AM_SONGLIST_FIELDS_URL, |
||||||
| 54 | XOBJ_DTYPE_OTHER => _AM_SONGLIST_FIELDS_OTHER, |
||||||
| 55 | XOBJ_DTYPE_MTIME => _AM_SONGLIST_FIELDS_DATE, |
||||||
| 56 | ]; |
||||||
| 57 | |||||||
| 58 | $fieldtypes = [ |
||||||
| 59 | 'checkbox' => _AM_SONGLIST_FIELDS_CHECKBOX, |
||||||
| 60 | 'group' => _AM_SONGLIST_FIELDS_GROUP, |
||||||
| 61 | 'group_multi' => _AM_SONGLIST_FIELDS_GROUPMULTI, |
||||||
| 62 | 'language' => _AM_SONGLIST_FIELDS_LANGUAGE, |
||||||
| 63 | 'radio' => _AM_SONGLIST_FIELDS_RADIO, |
||||||
| 64 | 'select' => _AM_SONGLIST_FIELDS_SELECT, |
||||||
| 65 | 'select_multi' => _AM_SONGLIST_FIELDS_SELECTMULTI, |
||||||
| 66 | 'textarea' => _AM_SONGLIST_FIELDS_TEXTAREA, |
||||||
| 67 | 'dhtml' => _AM_SONGLIST_FIELDS_DHTMLTEXTAREA, |
||||||
| 68 | 'editor' => _AM_SONGLIST_FIELDS_EDITOR, |
||||||
| 69 | 'textbox' => _AM_SONGLIST_FIELDS_TEXTBOX, |
||||||
| 70 | 'timezone' => _AM_SONGLIST_FIELDS_TIMEZONE, |
||||||
| 71 | 'yesno' => _AM_SONGLIST_FIELDS_YESNO, |
||||||
| 72 | 'date' => _AM_SONGLIST_FIELDS_DATE, |
||||||
| 73 | 'datetime' => _AM_SONGLIST_FIELDS_DATETIME, |
||||||
| 74 | 'longdate' => _AM_SONGLIST_FIELDS_LONGDATE, |
||||||
| 75 | 'theme' => _AM_SONGLIST_FIELDS_THEME, |
||||||
| 76 | 'autotext' => _AM_SONGLIST_FIELDS_AUTOTEXT, |
||||||
| 77 | 'rank' => _AM_SONGLIST_FIELDS_RANK, |
||||||
| 78 | ]; |
||||||
| 79 | |||||||
| 80 | foreach (array_keys($fields) as $i) { |
||||||
| 81 | $fields[$i]['canEdit'] = $fields[$i]['field_config'] || $fields[$i]['field_show'] || $fields[$i]['field_edit']; |
||||||
| 82 | $fields[$i]['canDelete'] = $fields[$i]['field_config']; |
||||||
| 83 | $fields[$i]['fieldtype'] = $fieldtypes[$fields[$i]['field_type']]; |
||||||
| 84 | $fields[$i]['valuetype'] = $valuetypes[$fields[$i]['field_valuetype']]; |
||||||
| 85 | $fieldcategories[$i][] = $fields[$i]; |
||||||
| 86 | $weights[$i] = $fields[$i]['field_weight']; |
||||||
| 87 | } |
||||||
| 88 | //sort fields order in categories |
||||||
| 89 | // ray('$fields', $fields); |
||||||
| 90 | foreach (array_keys($fields) as $i) { |
||||||
| 91 | // ray('$i = ' . $i)->red(); |
||||||
| 92 | // ray('$weights: <br>' , $weights)->red(); |
||||||
| 93 | // ray('$fieldcategories: <br>' , $fieldcategories)->red(); |
||||||
| 94 | // ray('array_keys($fieldcategories)', array_keys($fieldcategories))->red(); |
||||||
| 95 | // ray('$categories: <br>', $categories)->red(); |
||||||
| 96 | // ray('$categories[$i]: <br>', $categories[$i])->red(); |
||||||
| 97 | |||||||
| 98 | array_multisort( |
||||||
| 99 | $weights |
||||||
| 100 | , |
||||||
| 101 | SORT_ASC |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 102 | , |
||||||
| 103 | array_keys($fieldcategories) |
||||||
|
0 ignored issues
–
show
array_keys($fieldcategories) cannot be passed to array_multisort() as the parameter $rest expects a reference.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 104 | , |
||||||
| 105 | SORT_ASC |
||||||
| 106 | , |
||||||
| 107 | $categories[$i] |
||||||
| 108 | ); |
||||||
| 109 | // ray($i)->blue(); |
||||||
| 110 | // ray('$weights: <br>', $weights)->blue(); |
||||||
| 111 | // ray('$fieldcategories: <br>', $fieldcategories)->blue(); |
||||||
| 112 | // ray(array_keys($fieldcategories))->blue(); |
||||||
| 113 | // ray('Categories: <br>', $categories)->blue(); |
||||||
| 114 | // ray('$categories[$i]: <br>', $categories[$i])->blue(); |
||||||
| 115 | } |
||||||
| 116 | |||||||
| 117 | ksort($categories); |
||||||
| 118 | $GLOBALS['xoopsTpl']->assign('fieldcategories', $fieldcategories); |
||||||
| 119 | $GLOBALS['xoopsTpl']->assign('token', $GLOBALS['xoopsSecurity']->getTokenHTML()); |
||||||
| 120 | $template_main = 'songlist_cpanel_fieldlist.tpl'; |
||||||
| 121 | break; |
||||||
| 122 | case 'new': |
||||||
| 123 | $adminObject = Admin::getInstance(); |
||||||
| 124 | $adminObject->displayNavigation(basename(__FILE__)); |
||||||
| 125 | $obj = $fieldHandler->create(); |
||||||
| 126 | $form = FormController::getFieldForm($obj); |
||||||
| 127 | $form->display(); |
||||||
| 128 | break; |
||||||
| 129 | case 'edit': |
||||||
| 130 | $adminObject = Admin::getInstance(); |
||||||
| 131 | $adminObject->displayNavigation(basename(__FILE__)); |
||||||
| 132 | $obj = $fieldHandler->get($_REQUEST['id']); |
||||||
| 133 | if (!$obj->getVar('field_config') && !$obj->getVar('field_show') && !$obj->getVar('field_edit')) { //If no configs exist |
||||||
| 134 | redirect_header('field.php', 2, _AM_SONGLIST_FIELDS_FIELDNOTCONFIGURABLE); |
||||||
| 135 | } |
||||||
| 136 | $form = FormController::getFieldForm($obj); |
||||||
| 137 | $form->display(); |
||||||
| 138 | break; |
||||||
| 139 | case 'reorder': |
||||||
| 140 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||||||
| 141 | redirect_header('field.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||||||
| 142 | } |
||||||
| 143 | |||||||
| 144 | if (Request::hasVar('field_ids', 'POST') && count($_POST['field_ids']) > 0) { |
||||||
| 145 | $oldweight = $_POST['oldweight']; |
||||||
| 146 | $oldcat = $_POST['oldcat']; |
||||||
| 147 | $oldcategories = $_POST['oldcategories']; |
||||||
| 148 | $categories = $_POST['categories']; |
||||||
| 149 | $weight = $_POST['weight']; |
||||||
| 150 | $ids = []; |
||||||
| 151 | foreach ($_POST['field_ids'] as $field_id) { |
||||||
| 152 | if ($oldweight[$field_id] != $weight[$field_id] || $oldcat[$field_id] != $category[$field_id] || count($oldcategories[$field_id]) != count(array_unique(array_merge($categories[$field_id], $oldcategories[$field_id])))) { |
||||||
| 153 | //if field has changed |
||||||
| 154 | $ids[] = (int)$field_id; |
||||||
| 155 | } |
||||||
| 156 | } |
||||||
| 157 | if (count($ids) > 0) { |
||||||
| 158 | $errors = []; |
||||||
| 159 | //if there are changed fields, fetch the fieldcategory objects |
||||||
| 160 | $fieldHandler = Helper::getInstance() |
||||||
| 161 | ->getHandler('Field'); |
||||||
| 162 | $fields = $fieldHandler->getObjects(new \Criteria('field_id', '(' . implode(',', $ids) . ')', 'IN'), true); |
||||||
| 163 | foreach ($ids as $i) { |
||||||
| 164 | $fields[$i]->setVar('field_weight', (int)$weight[$i]); |
||||||
| 165 | $fields[$i]->setVar('cids', $categories[$i]); |
||||||
| 166 | if (!$fieldHandler->insert($fields[$i])) { |
||||||
| 167 | $errors = array_merge($errors, $fields[$i]->getErrors()); |
||||||
| 168 | } |
||||||
| 169 | } |
||||||
| 170 | if (0 == count($errors)) { |
||||||
| 171 | //no errors |
||||||
| 172 | redirect_header('field.php', 2, sprintf(_AM_SONGLIST_FIELDS_SAVEDSUCCESS, _AM_SONGLIST_FIELDS_FIELDS)); |
||||||
| 173 | } else { |
||||||
| 174 | redirect_header('field.php', 3, implode('<br>', $errors)); |
||||||
| 175 | } |
||||||
| 176 | } |
||||||
| 177 | } |
||||||
| 178 | redirect_header('field.php', 2, sprintf(_AM_SONGLIST_FIELDS_SAVEDSUCCESS, _AM_SONGLIST_FIELDS_FIELDS)); |
||||||
| 179 | break; |
||||||
| 180 | case 'save': |
||||||
| 181 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||||||
| 182 | redirect_header('field.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||||||
| 183 | } |
||||||
| 184 | $redirect_to_edit = false; |
||||||
| 185 | if (Request::hasVar('id', 'REQUEST')) { |
||||||
| 186 | $obj = $fieldHandler->get($_REQUEST['id']); |
||||||
| 187 | if (!$obj->getVar('field_config') && !$obj->getVar('field_show') && !$obj->getVar('field_edit')) { //If no configs exist |
||||||
| 188 | redirect_header('fields.php', 2, _AM_SONGLIST_FIELDS_FIELDNOTCONFIGURABLE); |
||||||
| 189 | } |
||||||
| 190 | } else { |
||||||
| 191 | $obj = $fieldHandler->create(); |
||||||
| 192 | $obj->setVar('field_name', $_REQUEST['field_name']); |
||||||
| 193 | $obj->setVar('field_moduleid', $GLOBALS['songlistModule']->getVar('mid')); |
||||||
| 194 | $obj->setVar('field_show', 1); |
||||||
| 195 | $obj->setVar('field_edit', 1); |
||||||
| 196 | $obj->setVar('field_config', 1); |
||||||
| 197 | $redirect_to_edit = true; |
||||||
| 198 | } |
||||||
| 199 | $obj->setVar('field_title', $_REQUEST['field_title']); |
||||||
| 200 | $obj->setVar('field_description', $_REQUEST['field_description']); |
||||||
| 201 | if ($obj->getVar('field_config')) { |
||||||
| 202 | $obj->setVar('field_type', $_REQUEST['field_type']); |
||||||
| 203 | if (Request::hasVar('field_valuetype', 'REQUEST')) { |
||||||
| 204 | $obj->setVar('field_valuetype', $_REQUEST['field_valuetype']); |
||||||
| 205 | } |
||||||
| 206 | $options = $obj->getVar('field_options'); |
||||||
| 207 | |||||||
| 208 | if (Request::hasVar('removeOptions', 'REQUEST') && is_array($_REQUEST['removeOptions'])) { |
||||||
| 209 | foreach ($_REQUEST['removeOptions'] as $index) { |
||||||
| 210 | unset($options[$index]); |
||||||
| 211 | } |
||||||
| 212 | $redirect_to_edit = true; |
||||||
| 213 | } |
||||||
| 214 | |||||||
| 215 | if (Request::hasVar('addOption', 'REQUEST')) { |
||||||
| 216 | foreach ($_REQUEST['addOption'] as $option) { |
||||||
| 217 | if (empty($option['value'])) { |
||||||
| 218 | continue; |
||||||
| 219 | } |
||||||
| 220 | $options[$option['key']] = $option['value']; |
||||||
| 221 | $redirect_to_edit = true; |
||||||
| 222 | } |
||||||
| 223 | } |
||||||
| 224 | $obj->setVar('field_options', $options); |
||||||
| 225 | } |
||||||
| 226 | if ($obj->getVar('field_edit')) { |
||||||
| 227 | $required = Request::getInt('field_required', 0, 'REQUEST'); |
||||||
| 228 | $obj->setVar('field_required', $required); //0 = no, 1 = yes |
||||||
| 229 | if (Request::hasVar('field_maxlength', 'REQUEST')) { |
||||||
| 230 | $obj->setVar('field_maxlength', $_REQUEST['field_maxlength']); |
||||||
| 231 | } |
||||||
| 232 | if (Request::hasVar('field_default', 'REQUEST')) { |
||||||
| 233 | $field_default = $obj->getValueForSave($_REQUEST['field_default']); |
||||||
|
0 ignored issues
–
show
The method
getValueForSave() does not exist on XoopsObject. Did you maybe mean getValues()?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 234 | //Check for multiple selections |
||||||
| 235 | if (is_array($field_default)) { |
||||||
| 236 | $obj->setVar('field_default', serialize($field_default)); |
||||||
| 237 | } else { |
||||||
| 238 | $obj->setVar('field_default', $field_default); |
||||||
| 239 | } |
||||||
| 240 | } |
||||||
| 241 | } |
||||||
| 242 | |||||||
| 243 | $obj->setVar('field_weight', $_REQUEST['field_weight']); |
||||||
| 244 | $obj->setVar('cids', $_REQUEST['cids']); |
||||||
| 245 | |||||||
| 246 | if ($fieldHandler->insert($obj)) { |
||||||
| 247 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||||||
| 248 | $grouppermHandler = xoops_getHandler('groupperm'); |
||||||
| 249 | |||||||
| 250 | $perm_arr = []; |
||||||
| 251 | if ($obj->getVar('field_show')) { |
||||||
| 252 | $perm_arr[] = 'songlist_show'; |
||||||
| 253 | $perm_arr[] = 'songlist_visible'; |
||||||
| 254 | } |
||||||
| 255 | if ($obj->getVar('field_edit')) { |
||||||
| 256 | $perm_arr[] = 'songlist_edit'; |
||||||
| 257 | } |
||||||
| 258 | if ($obj->getVar('field_edit') || $obj->getVar('field_show')) { |
||||||
| 259 | $perm_arr[] = 'songlist_search'; |
||||||
| 260 | } |
||||||
| 261 | if (count($perm_arr) > 0) { |
||||||
| 262 | foreach ($perm_arr as $perm) { |
||||||
| 263 | $criteria = new \CriteriaCompo(new \Criteria('gperm_name', $perm)); |
||||||
| 264 | $criteria->add(new \Criteria('gperm_itemid', (int)$obj->getVar('field_id'))); |
||||||
| 265 | $criteria->add(new \Criteria('gperm_modid', (int)$GLOBALS['songlistModule']->getVar('mid'))); |
||||||
| 266 | if (isset($_REQUEST[$perm]) && is_array($_REQUEST[$perm])) { |
||||||
| 267 | $perms = $grouppermHandler->getObjects($criteria); |
||||||
| 268 | if (count($perms) > 0) { |
||||||
| 269 | foreach (array_keys($perms) as $i) { |
||||||
| 270 | $groups[$perms[$i]->getVar('gperm_groupid')] = $perms[$i]; |
||||||
| 271 | } |
||||||
| 272 | } else { |
||||||
| 273 | $groups = []; |
||||||
| 274 | } |
||||||
| 275 | foreach ($_REQUEST[$perm] as $grouoid) { |
||||||
| 276 | $grouoid = (int)$grouoid; |
||||||
| 277 | if (!isset($groups[$grouoid])) { |
||||||
| 278 | $perm_obj = $grouppermHandler->create(); |
||||||
| 279 | $perm_obj->setVar('gperm_name', $perm); |
||||||
| 280 | $perm_obj->setVar('gperm_itemid', (int)$obj->getVar('field_id')); |
||||||
| 281 | $perm_obj->setVar('gperm_modid', $GLOBALS['songlistModule']->getVar('mid')); |
||||||
| 282 | $perm_obj->setVar('gperm_groupid', $grouoid); |
||||||
| 283 | $grouppermHandler->insert($perm_obj); |
||||||
|
0 ignored issues
–
show
$perm_obj of type boolean is incompatible with the type XoopsObject expected by parameter $perm of XoopsGroupPermHandler::insert().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 284 | unset($perm_obj); |
||||||
| 285 | } |
||||||
| 286 | } |
||||||
| 287 | $removed_groups = array_diff(array_keys($groups), $_REQUEST[$perm]); |
||||||
| 288 | if (count($removed_groups) > 0) { |
||||||
| 289 | $criteria->add(new \Criteria('gperm_groupid', '(' . implode(',', $removed_groups) . ')', 'IN')); |
||||||
| 290 | $grouppermHandler->deleteAll($criteria); |
||||||
| 291 | } |
||||||
| 292 | unset($groups); |
||||||
| 293 | } else { |
||||||
| 294 | $grouppermHandler->deleteAll($criteria); |
||||||
| 295 | } |
||||||
| 296 | unset($criteria); |
||||||
| 297 | } |
||||||
| 298 | } |
||||||
| 299 | $url = $redirect_to_edit ? 'field.php?op=edit&id=' . $obj->getVar('field_id') : 'field.php'; |
||||||
| 300 | redirect_header($url, 3, sprintf(_AM_SONGLIST_FIELDS_SAVEDSUCCESS, _AM_SONGLIST_FIELDS_FIELD)); |
||||||
| 301 | } |
||||||
| 302 | |||||||
| 303 | echo $obj->getHtmlErrors(); |
||||||
| 304 | $form = FormController::getFieldForm($obj); |
||||||
| 305 | $form->display(); |
||||||
| 306 | break; |
||||||
| 307 | case 'delete': |
||||||
| 308 | $obj = $fieldHandler->get($_REQUEST['id']); |
||||||
| 309 | if (!$obj->getVar('field_config')) { |
||||||
| 310 | redirect_header('index.php', 2, _AM_SONGLIST_FIELDS_FIELDNOTCONFIGURABLE); |
||||||
| 311 | } |
||||||
| 312 | if (Request::hasVar('ok', 'REQUEST') && 1 == $_REQUEST['ok']) { |
||||||
| 313 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||||||
| 314 | redirect_header('field.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||||||
| 315 | } |
||||||
| 316 | if ($fieldHandler->delete($obj)) { |
||||||
| 317 | redirect_header('field.php', 3, sprintf(_AM_SONGLIST_FIELDS_DELETEDSUCCESS, _AM_SONGLIST_FIELDS_FIELD)); |
||||||
| 318 | } else { |
||||||
| 319 | echo $obj->getHtmlErrors(); |
||||||
| 320 | } |
||||||
| 321 | } else { |
||||||
| 322 | xoops_confirm(['ok' => 1, 'id' => $_REQUEST['id'], 'op' => 'delete'], $_SERVER['REQUEST_URI'], sprintf(_AM_SONGLIST_FIELDS_RUSUREDEL, $obj->getVar('field_title'))); |
||||||
|
0 ignored issues
–
show
It seems like
$obj->getVar('field_title') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 323 | } |
||||||
| 324 | break; |
||||||
| 325 | } |
||||||
| 326 | |||||||
| 327 | if (isset($template_main)) { |
||||||
| 328 | $GLOBALS['xoopsTpl']->display("db:{$template_main}"); |
||||||
| 329 | } |
||||||
| 330 | |||||||
| 331 | xoops_cp_footer(); |
||||||
| 332 |