XoopsModules25x /
myiframe
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * **************************************************************************** |
||
| 4 | * MYIFRAME - MODULE FOR XOOPS |
||
| 5 | * Copyright (c) Hervé Thouzard of Instant Zero (http://www.instant-zero.com) |
||
| 6 | * **************************************************************************** |
||
| 7 | */ |
||
| 8 | |||
| 9 | //include __DIR__ . '/../../../include/cp_header.php'; |
||
|
0 ignored issues
–
show
|
|||
| 10 | require_once __DIR__ . '/admin_header.php'; |
||
| 11 | include_once XOOPS_ROOT_PATH . '/modules/myiframe/include/functions.php'; |
||
| 12 | |||
| 13 | // Verify if the table is up to date |
||
| 14 | if (!myiframe_FieldExists('frame_frameid', $GLOBALS['xoopsDB']->prefix('myiframe'))) { |
||
| 15 | $result = $GLOBALS['xoopsDB']->queryF('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('myiframe') . ' CHANGE `frameid` `frame_frameid` INT( 8 ) NOT NULL AUTO_INCREMENT'); |
||
| 16 | $result = $GLOBALS['xoopsDB']->queryF('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('myiframe') . " CHANGE `created` `frame_created` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0'"); |
||
| 17 | $result = $GLOBALS['xoopsDB']->queryF('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('myiframe') . " CHANGE `uid` `frame_uid` MEDIUMINT( 8 ) UNSIGNED NOT NULL DEFAULT '0'"); |
||
| 18 | $result = $GLOBALS['xoopsDB']->queryF('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('myiframe') . ' CHANGE `longdesc` `frame_description` VARCHAR( 255 ) NOT NULL'); |
||
| 19 | $result = $GLOBALS['xoopsDB']->queryF('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('myiframe') . ' CHANGE `width` `frame_width` VARCHAR( 15 ) NOT NULL'); |
||
| 20 | $result = $GLOBALS['xoopsDB']->queryF('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('myiframe') . ' CHANGE `height` `frame_height` VARCHAR( 15 ) NOT NULL'); |
||
| 21 | $result = $GLOBALS['xoopsDB']->queryF('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('myiframe') . " CHANGE `align` `frame_align` SMALLINT( 2 ) NOT NULL DEFAULT '0'"); |
||
| 22 | $result = $GLOBALS['xoopsDB']->queryF('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('myiframe') . " CHANGE `frameborder` `frame_frameborder` SMALLINT( 3 ) NOT NULL DEFAULT '0'"); |
||
| 23 | $result = $GLOBALS['xoopsDB']->queryF('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('myiframe') . " CHANGE `marginwidth` `frame_marginwidth` SMALLINT( 3 ) NOT NULL DEFAULT '0'"); |
||
| 24 | $result = $GLOBALS['xoopsDB']->queryF('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('myiframe') . " CHANGE `marginheight` `frame_marginheight` SMALLINT( 3 ) NOT NULL DEFAULT '0'"); |
||
| 25 | $result = $GLOBALS['xoopsDB']->queryF('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('myiframe') . " CHANGE `scrolling` `frame_scrolling` SMALLINT( 1 ) NOT NULL DEFAULT '0'"); |
||
| 26 | $result = $GLOBALS['xoopsDB']->queryF('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('myiframe') . " CHANGE `hits` `frame_hits` INT( 8 ) UNSIGNED NOT NULL DEFAULT '0'"); |
||
| 27 | $result = $GLOBALS['xoopsDB']->queryF('ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('myiframe') . ' CHANGE `url` `frame_url` VARCHAR( 255 ) NOT NULL'); |
||
| 28 | header('Location : ' . XOOPS_URL . '/modules/system/admin.php?fct=modulesadmin&op=update&module=myiframe'); |
||
| 29 | } |
||
| 30 | |||
| 31 | $module_id = $xoopsModule->getVar('mid'); |
||
| 32 | $op = 'default'; |
||
| 33 | /** @var MyiframeMyiframeHandler $iframeHandler */ |
||
| 34 | $iframeHandler = xoops_getModuleHandler('myiframe', 'myiframe'); |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param $frameid |
||
| 38 | * @param $Action |
||
| 39 | * @param $FormTitle |
||
| 40 | * @param $longdesc |
||
| 41 | * @param $width |
||
| 42 | * @param $height |
||
| 43 | * @param $align |
||
| 44 | * @param $frameborder |
||
| 45 | * @param $marginwidth |
||
| 46 | * @param $marginheight |
||
| 47 | * @param $scrolling |
||
| 48 | * @param $url |
||
| 49 | * @param $LabelSubmitButton |
||
| 50 | */ |
||
| 51 | function addEditForm($frameid, $Action, $FormTitle, $longdesc, $width, $height, $align, $frameborder, $marginwidth, $marginheight, $scrolling, $url, $LabelSubmitButton) |
||
| 52 | { |
||
| 53 | include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 54 | global $xoopsModule; |
||
| 55 | |||
| 56 | $sform = new XoopsThemeForm($FormTitle, 'indexform', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/manage.php'); |
||
| 57 | $sform->addElement(new XoopsFormText(_AM_MYIFRAME_DESC, 'longdesc', 50, 255, $longdesc), false); |
||
| 58 | $sform->addElement(new XoopsFormText(_AM_MYIFRAME_WIDTH, 'width', 10, 15, $width), false); |
||
| 59 | $sform->addElement(new XoopsFormText(_AM_MYIFRAME_HEIGHT, 'height', 10, 15, $height), false); |
||
| 60 | |||
| 61 | $selalign = new XoopsFormSelect(_AM_MYIFRAME_ALIGN, 'align', $align); |
||
| 62 | $selalign->addOption(1, _AM_MYIFRAME_ALIGN_TOP); |
||
| 63 | $selalign->addOption(2, _AM_MYIFRAME_ALIGN_MIDDLE); |
||
| 64 | $selalign->addOption(3, _AM_MYIFRAME_ALIGN_BOTTOM); |
||
| 65 | $selalign->addOption(4, _AM_MYIFRAME_ALIGN_LEFT); |
||
| 66 | $selalign->addOption(5, _AM_MYIFRAME_ALIGN_RIGHT); |
||
| 67 | $selalign->setValue($align); |
||
| 68 | $sform->addElement($selalign); |
||
| 69 | |||
| 70 | $sform->addElement(new XoopsFormText(_AM_MYIFRAME_FRAMEBORDER, 'frameborder', 3, 3, $frameborder), false); |
||
| 71 | $sform->addElement(new XoopsFormText(_AM_MYIFRAME_MARGINWIDTH, 'marginwidth', 3, 3, $marginwidth), false); |
||
| 72 | $sform->addElement(new XoopsFormText(_AM_MYIFRAME_MARGINHEIGHT, 'marginheight', 3, 3, $marginheight), false); |
||
| 73 | |||
| 74 | $selscroll = new XoopsFormSelect(_AM_MYIFRAME_SCROLLING, 'scrolling', $scrolling); |
||
| 75 | $selscroll->addOption(1, _YES); |
||
| 76 | $selscroll->addOption(2, _NO); |
||
| 77 | $selscroll->addOption(3, _AM_MYIFRAME_AUTO); |
||
| 78 | $selscroll->setValue($scrolling); |
||
| 79 | $sform->addElement($selscroll); |
||
| 80 | |||
| 81 | $sform->addElement(new XoopsFormText(_AM_MYIFRAME_URL, 'url', 50, 255, $url), true); |
||
| 82 | $sform->addElement(new XoopsFormHidden('op', $Action), false); |
||
| 83 | if (!empty($frameid)) { |
||
| 84 | $sform->addElement(new XoopsFormHidden('frameid', $frameid), false); |
||
| 85 | } |
||
| 86 | |||
| 87 | $button_tray = new XoopsFormElementTray('', ''); |
||
| 88 | $submit_btn = new XoopsFormButton('', 'submit', $LabelSubmitButton, 'submit'); |
||
| 89 | $button_tray->addElement($submit_btn); |
||
| 90 | $cancel_btn = new XoopsFormButton('', 'reset', _AM_MYIFRAME_RESETBUTTON, 'reset'); |
||
| 91 | $button_tray->addElement($cancel_btn); |
||
| 92 | $sform->addElement($button_tray); |
||
| 93 | $sform->display(); |
||
| 94 | include_once __DIR__ . '/admin_footer.php'; |
||
| 95 | } |
||
| 96 | |||
| 97 | // ****************************************************************************************************************************************** |
||
| 98 | // **** Main ******************************************************************************************************************************** |
||
| 99 | // ****************************************************************************************************************************************** |
||
| 100 | |||
| 101 | if (isset($_POST['op'])) { |
||
| 102 | $op = $_POST['op']; |
||
| 103 | } elseif (isset($_GET['op'])) { |
||
| 104 | $op = $_GET['op']; |
||
| 105 | } |
||
| 106 | |||
| 107 | switch ($op) { |
||
| 108 | case 'verifybeforeedit': |
||
| 109 | if (isset($_POST['submit']) && $_POST['submit'] !== '') { |
||
| 110 | View Code Duplication | if ($_POST['longdesc'] === '') { |
|
| 111 | xoops_cp_header(); |
||
| 112 | $adminObject = \Xmf\Module\Admin::getInstance(); |
||
| 113 | $adminObject->displayNavigation(basename(__FILE__)); |
||
| 114 | echo "<table width='100%' border='0' cellspacing='1' class='outer'>\n"; |
||
| 115 | echo '<tr><td class="odd">'; |
||
| 116 | echo "<a href='manage.php'><h4>" . _AM_MYIFRAME_CONFIG . '</h4></a>'; |
||
| 117 | echo _AM_MYIFRAME_ERROR_ADD_INDEX; |
||
| 118 | echo '</td></tr></table>'; |
||
| 119 | include_once __DIR__ . '/admin_footer.php'; |
||
| 120 | xoops_cp_footer(); |
||
| 121 | exit(); |
||
| 122 | } |
||
| 123 | |||
| 124 | $frameid = $_POST['frameid']; |
||
| 125 | $frame = $iframeHandler->get($frameid); |
||
| 126 | $frame->unsetNew(); |
||
| 127 | $frame->setVar('frame_description', $_POST['longdesc']); |
||
| 128 | $frame->setVar('frame_width', $_POST['width']); |
||
| 129 | $frame->setVar('frame_height', $_POST['height']); |
||
| 130 | $frame->setVar('frame_align', $_POST['align']); |
||
| 131 | $frame->setVar('frame_frameborder', $_POST['frameborder']); |
||
| 132 | $frame->setVar('frame_marginwidth', $_POST['marginwidth']); |
||
| 133 | $frame->setVar('frame_marginheight', $_POST['marginheight']); |
||
| 134 | $frame->setVar('frame_scrolling', $_POST['scrolling']); |
||
| 135 | $frame->setVar('frame_url', $_POST['url']); |
||
| 136 | $frame->setVar('frame_uid', $xoopsUser->getVar('uid')); |
||
| 137 | $res = $iframeHandler->insert($frame); |
||
| 138 | if (!$res) { |
||
| 139 | redirect_header('manage.php', 1, _AM_MYIFRAME_ERROR_MODIFY_DB); |
||
| 140 | } |
||
| 141 | redirect_header('manage.php', 1, _AM_MYIFRAME_DBUPDATED); |
||
| 142 | } |
||
| 143 | break; |
||
| 144 | |||
| 145 | case 'edit': |
||
| 146 | xoops_cp_header(); |
||
| 147 | $adminObject = \Xmf\Module\Admin::getInstance(); |
||
| 148 | $adminObject->displayNavigation(basename(__FILE__)); |
||
| 149 | if (isset($_GET['frameid'])) { |
||
| 150 | $frameid = (int)$_GET['frameid']; |
||
| 151 | $frame = $iframeHandler->get($frameid); |
||
| 152 | addEditForm( |
||
| 153 | $frameid, |
||
| 154 | 'verifybeforeedit', |
||
| 155 | _AM_MYIFRAME_CONFIG, |
||
| 156 | $frame->getVar('frame_description', 'e'), |
||
| 157 | $frame->getVar('frame_width', 'e'), |
||
| 158 | $frame->getVar('frame_height', 'e'), |
||
| 159 | $frame->getVar('frame_align', 'e'), |
||
| 160 | $frame->getVar('frame_frameborder', 'e'), |
||
| 161 | $frame->getVar('frame_marginwidth', 'e'), |
||
| 162 | $frame->getVar('frame_marginheight', 'e'), |
||
| 163 | $frame->getVar('frame_scrolling', 'e'), |
||
| 164 | $frame->getVar('frame_url', 'e'), |
||
| 165 | _AM_MYIFRAME_UPDATE |
||
| 166 | ); |
||
| 167 | View Code Duplication | } else { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 168 | xoops_cp_header(); |
||
| 169 | $adminObject = \Xmf\Module\Admin::getInstance(); |
||
| 170 | $adminObject->displayNavigation(basename(__FILE__)); |
||
| 171 | echo "<table width='100%' border='0' cellspacing='1' class='outer'>\n"; |
||
| 172 | echo '<tr><td class="odd">'; |
||
| 173 | echo "<a href='manage.php'><h4>" . _AM_MYIFRAME_CONFIG . '</h4></a>'; |
||
| 174 | echo _AM_MYIFRAME_ERROR_ADD_INDEX; |
||
| 175 | echo "</td></tr></table>\n"; |
||
| 176 | include_once __DIR__ . '/admin_footer.php'; |
||
| 177 | xoops_cp_footer(); |
||
| 178 | exit(); |
||
| 179 | } |
||
| 180 | break; |
||
| 181 | |||
| 182 | case 'delete': |
||
| 183 | if (!isset($_POST['ok'])) { |
||
| 184 | xoops_cp_header(); |
||
| 185 | $adminObject = \Xmf\Module\Admin::getInstance(); |
||
| 186 | $adminObject->displayNavigation(basename(__FILE__)); |
||
| 187 | echo '<h4>' . _AM_MYIFRAME_CONFIG . '</h4>'; |
||
| 188 | xoops_confirm([ |
||
| 189 | 'op' => 'delete', |
||
| 190 | 'frameid' => (int)$_GET['frameid'], |
||
| 191 | 'ok' => 1 |
||
| 192 | ], 'manage.php', _AM_MYIFRAME_RUSUREDEL); |
||
| 193 | include_once __DIR__ . '/admin_footer.php'; |
||
| 194 | } else { |
||
| 195 | if (empty($_POST['frameid'])) { |
||
| 196 | redirect_header('manage.php', 2, _AM_MYIFRAME_ERROR_ADD_INDEX); |
||
| 197 | } |
||
| 198 | $frameid = (int)$_POST['frameid']; |
||
| 199 | $critere = new Criteria('frame_frameid', $frameid, '='); |
||
| 200 | $iframeHandler->deleteAll($critere); |
||
| 201 | redirect_header('manage.php', 1, _AM_MYIFRAME_DBUPDATED); |
||
| 202 | } |
||
| 203 | break; |
||
| 204 | |||
| 205 | case 'verifytoadd': |
||
| 206 | if (isset($_POST['submit']) && $_POST['submit'] !== '') { |
||
| 207 | if ($_POST['url'] === '') { |
||
| 208 | xoops_cp_header(); |
||
| 209 | $adminObject = \Xmf\Module\Admin::getInstance(); |
||
| 210 | $adminObject->displayNavigation(basename(__FILE__)); |
||
| 211 | echo "<table width='100%' border='0' cellspacing='1' class='outer'>\n"; |
||
| 212 | echo '<tr><td class="odd">'; |
||
| 213 | echo "<a href='manage.php'><h4>" . _AM_MYIFRAME_CONFIG . '</h4></a>'; |
||
| 214 | echo _AM_MYIFRAME_ERROR_ADD_INDEX; |
||
| 215 | echo "</td></tr></table>\n"; |
||
| 216 | include_once __DIR__ . '/admin_footer.php'; |
||
| 217 | xoops_cp_footer(); |
||
| 218 | $adminObject = \Xmf\Module\Admin::getInstance(); |
||
| 219 | $adminObject->displayNavigation(basename(__FILE__)); |
||
| 220 | exit(); |
||
| 221 | } |
||
| 222 | $frame = $iframeHandler->create(true); |
||
| 223 | $frame->setVar('frame_description', $_POST['longdesc']); |
||
| 224 | $frame->setVar('frame_width', $_POST['width']); |
||
| 225 | $frame->setVar('frame_height', $_POST['height']); |
||
| 226 | $frame->setVar('frame_align', $_POST['align']); |
||
| 227 | $frame->setVar('frame_frameborder', $_POST['frameborder']); |
||
| 228 | $frame->setVar('frame_marginwidth', $_POST['marginwidth']); |
||
| 229 | $frame->setVar('frame_marginheight', $_POST['marginheight']); |
||
| 230 | $frame->setVar('frame_scrolling', $_POST['scrolling']); |
||
| 231 | $frame->setVar('frame_url', $_POST['url']); |
||
| 232 | $frame->setVar('frame_created', time()); |
||
| 233 | $frame->setVar('frame_uid', $xoopsUser->getVar('uid')); |
||
| 234 | $res = $iframeHandler->insert($frame); |
||
| 235 | if (!$res) { |
||
| 236 | redirect_header('manage.php', 1, _AM_MYIFRAME_ERROR_ADD_INDEX); |
||
| 237 | } |
||
| 238 | redirect_header('manage.php', 1, _AM_MYIFRAME_ADDED_OK); |
||
| 239 | } |
||
| 240 | break; |
||
| 241 | |||
| 242 | case 'addframe': |
||
| 243 | xoops_cp_header(); |
||
| 244 | $adminObject = \Xmf\Module\Admin::getInstance(); |
||
| 245 | $adminObject->displayNavigation(basename(__FILE__)); |
||
| 246 | addEditForm(0, 'verifytoadd', _AM_MYIFRAME_CONFIG, '', '100%', '', '', '0', '0', '0', 1, '', _AM_MYIFRAME_ADDBUTTON); |
||
| 247 | break; |
||
| 248 | |||
| 249 | case 'default': |
||
| 250 | default: |
||
| 251 | xoops_cp_header(); |
||
| 252 | $adminObject = \Xmf\Module\Admin::getInstance(); |
||
| 253 | $adminObject->displayNavigation(basename(__FILE__)); |
||
| 254 | echo '<h4>' . _AM_MYIFRAME_CONFIG . "</h4><br />\n"; |
||
| 255 | echo "<table width='100%' border='0' cellspacing='1' class='outer'>\n"; |
||
| 256 | echo "<tr><th align='center'>" . _AM_MYIFRAME_ID . "</th><th align='center'>" . _AM_MYIFRAME_DESC . "</th><th align='center'>" . _AM_MYIFRAME_CREATED . "</th><th align='center'>" . _AM_MYIFRAME_HITS . "</th><th align='center'>" . _AM_MYIFRAME_ACTION . "</th></tr>\n"; |
||
| 257 | $critere = new Criteria('1', '1', '='); |
||
| 258 | $critere->setSort('frame_description'); |
||
| 259 | $frarray = $iframeHandler->getObjects($critere); |
||
| 260 | $class = 'even'; |
||
| 261 | $baseurl = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/manage.php'; |
||
| 262 | if (count($frarray) > 0) { |
||
| 263 | /** @var Myiframe $frame */ |
||
| 264 | foreach ($frarray as $frame) { |
||
| 265 | $action_edit = "<a href='" . $baseurl . '?op=edit&frameid=' . $frame->getVar('frame_frameid') . "'><img src='../assets/images/edit.png' alt='" . _AM_MYIFRAME_EDIT . "'></a>"; |
||
| 266 | $action_delete = "<a href='" . $baseurl . '?op=delete&frameid=' . $frame->getVar('frame_frameid') . "'><img src='../assets/images/delete.png' alt='" . _AM_MYIFRAME_DELETE . "'></a>"; |
||
| 267 | View Code Duplication | if (xoops_trim($frame->getVar('frame_description')) === '') { |
|
| 268 | $liendesc = $frame->getVar('frame_url'); |
||
| 269 | } else { |
||
| 270 | $liendesc = "<a href='" . XOOPS_URL . '/modules/myiframe/index.php?iframeid=' . $frame->getVar('frame_frameid') . "'>" . $frame->getVar('frame_description') . '</a>'; |
||
| 271 | } |
||
| 272 | echo "<tr class='" |
||
| 273 | . $class |
||
| 274 | . "'><td align='center'>" |
||
| 275 | . $frame->getVar('frame_frameid') |
||
| 276 | . "</td><td align='center'>" |
||
| 277 | . $liendesc |
||
| 278 | . "</td><td align='center'>" |
||
| 279 | . formatTimestamp($frame->getVar('frame_created')) |
||
| 280 | . "</td><td align='center'>" |
||
| 281 | . $frame->getVar('frame_hits') |
||
| 282 | . "</td><td align='center'>" |
||
| 283 | . $action_edit |
||
| 284 | . ' - ' |
||
| 285 | . $action_delete |
||
| 286 | . "</td></tr>\n"; |
||
| 287 | $class = ($class === 'even') ? 'odd' : 'even'; |
||
| 288 | } |
||
| 289 | } |
||
| 290 | echo "<tr class='" . $class . "'><td colspan='5' align='center'><form name='faddframe' method='post' action='manage.php'><input type='hidden' name='op' value='addframe'><input type='submit' name='submit' value='" . _AM_MYIFRAME_ADD . "'></td></tr>"; |
||
| 291 | echo '</table>'; |
||
| 292 | include_once __DIR__ . '/admin_footer.php'; |
||
| 293 | break; |
||
| 294 | } |
||
| 295 | |||
| 296 | xoops_cp_footer(); |
||
| 297 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.