mambax7 /
smartfaq
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 2 | |||
| 3 | /** |
||
| 4 | * Module: SmartFAQ |
||
| 5 | * Author: The SmartFactory <www.smartfactory.ca> |
||
| 6 | * Licence: GNU |
||
| 7 | */ |
||
| 8 | |||
| 9 | // ------------------------------------------------------------------------- // |
||
| 10 | // myblocksadmin.php // |
||
| 11 | // - XOOPS block admin for each modules - // |
||
| 12 | // GIJOE <http://www.peak.ne.jp/> // |
||
| 13 | // ------------------------------------------------------------------------- // |
||
| 14 | |||
| 15 | include_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php'; |
||
| 16 | include_once 'mygrouppermform.php'; |
||
| 17 | include_once(XOOPS_ROOT_PATH . '/class/xoopsblock.php'); |
||
| 18 | include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/functions.php'; |
||
| 19 | |||
| 20 | $xoops_system_path = XOOPS_ROOT_PATH . '/modules/system'; |
||
| 21 | |||
| 22 | // language files |
||
| 23 | $language = $xoopsConfig['language']; |
||
| 24 | if (!file_exists("$xoops_system_path/language/$language/admin/blocksadmin.php")) { |
||
| 25 | $language = 'english'; |
||
| 26 | } |
||
| 27 | |||
| 28 | // to prevent from notice that constants already defined |
||
| 29 | $error_reporting_level = error_reporting(0); |
||
| 30 | include_once("$xoops_system_path/constants.php"); |
||
| 31 | include_once("$xoops_system_path/language/$language/admin.php"); |
||
| 32 | include_once("$xoops_system_path/language/$language/admin/blocksadmin.php"); |
||
| 33 | include_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php'; |
||
| 34 | error_reporting($error_reporting_level); |
||
| 35 | |||
| 36 | $group_defs = file("$xoops_system_path/language/$language/admin/groups.php"); |
||
| 37 | foreach ($group_defs as $def) { |
||
| 38 | if (false !== strpos($def, '_AM_ACCESSRIGHTS') || false !== strpos($def, '_AM_ACTIVERIGHTS')) { |
||
| 39 | eval($def); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | // check $xoopsModule |
||
| 44 | if (!is_object($xoopsModule)) { |
||
| 45 | redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM); |
||
| 46 | } |
||
| 47 | |||
| 48 | // check access right (needs system_admin of BLOCK) |
||
| 49 | $syspermHandler = xoops_getHandler('groupperm'); |
||
| 50 | if (!$syspermHandler->checkRight('system_admin', XOOPS_SYSTEM_BLOCK, $xoopsUser->getGroups())) { |
||
| 51 | redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM); |
||
| 52 | } |
||
| 53 | |||
| 54 | // get blocks owned by the module |
||
| 55 | $block_arr = XoopsBlock::getByModule($xoopsModule->mid()); |
||
| 56 | |||
| 57 | function list_blocks() |
||
| 58 | { |
||
| 59 | global $block_arr, $xoopsModule; |
||
| 60 | |||
| 61 | // cachetime options |
||
| 62 | $cachetimes = array('0' => _NOCACHE, '30' => sprintf(_SECONDS, 30), '60' => _MINUTE, '300' => sprintf(_MINUTES, 5), '1800' => sprintf(_MINUTES, 30), '3600' => _HOUR, '18000' => sprintf(_HOURS, 5), '86400' => _DAY, '259200' => sprintf(_DAYS, 3), '604800' => _WEEK, '2592000' => _MONTH); |
||
| 63 | |||
| 64 | // displaying TH |
||
| 65 | sf_collapsableBar('toptable', 'toptableicon'); |
||
| 66 | echo "<img id='toptableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt='' /></a> " . _AM_SF_BLOCKS . '</h3>'; |
||
| 67 | echo "<div id='toptable'>"; |
||
| 68 | echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . _AM_SF_BLOCKSTXT . '</span>'; |
||
| 69 | |||
| 70 | echo " |
||
| 71 | <form action='admin.php' name='blockadmin' method='post'> |
||
| 72 | <table width='100%' class='outer' cellpadding='4' cellspacing='1'> |
||
| 73 | <tr valign='middle'> |
||
| 74 | <th>" . _AM_TITLE . "</th> |
||
| 75 | <th align='center' nowrap='nowrap'>" . _AM_SF_POSITION . "</th> |
||
| 76 | <th align='center'>" . _AM_WEIGHT . "</th> |
||
| 77 | <th align='center'>" . _AM_VISIBLEIN . "</th> |
||
| 78 | <th align='center'>" . _AM_BCACHETIME . "</th> |
||
| 79 | <th align='center'>" . _AM_ACTION . "</th> |
||
| 80 | </tr>\n"; |
||
| 81 | |||
| 82 | // blocks displaying loop |
||
| 83 | $class = 'even'; |
||
| 84 | foreach (array_keys($block_arr) as $i) { |
||
| 85 | $sseln = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = ''; |
||
| 86 | |||
| 87 | $weight = $block_arr[$i]->getVar('weight'); |
||
| 88 | $title = $block_arr[$i]->getVar('title'); |
||
| 89 | $name = $block_arr[$i]->getVar('name'); |
||
| 90 | $bcachetime = $block_arr[$i]->getVar('bcachetime'); |
||
| 91 | $bid = $block_arr[$i]->getVar('bid'); |
||
| 92 | |||
| 93 | // visible and side |
||
| 94 | if ($block_arr[$i]->getVar('visible') != 1) { |
||
| 95 | $sseln = " checked='checked' style='background-color:#FF0000;'"; |
||
| 96 | } else { |
||
| 97 | switch ($block_arr[$i]->getVar('side')) { |
||
| 98 | default: |
||
| 99 | case XOOPS_SIDEBLOCK_LEFT: |
||
| 100 | $ssel0 = " checked='checked' style='background-color:#00FF00;'"; |
||
| 101 | break; |
||
| 102 | case XOOPS_SIDEBLOCK_RIGHT: |
||
| 103 | $ssel1 = " checked='checked' style='background-color:#00FF00;'"; |
||
| 104 | break; |
||
| 105 | case XOOPS_CENTERBLOCK_LEFT: |
||
| 106 | $ssel2 = " checked='checked' style='background-color:#00FF00;'"; |
||
| 107 | break; |
||
| 108 | case XOOPS_CENTERBLOCK_RIGHT: |
||
| 109 | $ssel4 = " checked='checked' style='background-color:#00FF00;'"; |
||
| 110 | break; |
||
| 111 | case XOOPS_CENTERBLOCK_CENTER: |
||
| 112 | $ssel3 = " checked='checked' style='background-color:#00FF00;'"; |
||
| 113 | break; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | // bcachetime |
||
| 118 | $cachetime_options = ''; |
||
| 119 | foreach ($cachetimes as $cachetime => $cachetime_name) { |
||
| 120 | if ($bcachetime == $cachetime) { |
||
| 121 | $cachetime_options .= "<option value='$cachetime' selected='selected'>$cachetime_name</option>\n"; |
||
| 122 | } else { |
||
| 123 | $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n"; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | // target modules |
||
| 128 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 129 | $result = $db->query('SELECT module_id FROM ' . $db->prefix('block_module_link') . " WHERE block_id='$bid'"); |
||
| 130 | $selected_mids = array(); |
||
| 131 | while (list($selected_mid) = $db->fetchRow($result)) { |
||
| 132 | $selected_mids[] = (int)$selected_mid; |
||
| 133 | } |
||
| 134 | $moduleHandler = xoops_getHandler('module'); |
||
| 135 | $criteria = new CriteriaCompo(new Criteria('hasmain', 1)); |
||
| 136 | $criteria->add(new Criteria('isactive', 1)); |
||
| 137 | $module_list = $moduleHandler->getList($criteria); |
||
| 138 | $module_list[-1] = _AM_TOPPAGE; |
||
| 139 | $module_list[0] = _AM_ALLPAGES; |
||
| 140 | ksort($module_list); |
||
| 141 | $module_options = ''; |
||
| 142 | $myts = MyTextSanitizer::getInstance(); |
||
| 143 | foreach ($module_list as $mid => $mname) { |
||
| 144 | if (in_array($mid, $selected_mids)) { |
||
| 145 | $module_options .= "<option value='$mid' selected='selected'>" . $myts->displayTarea($mname) . "</option>\n"; |
||
| 146 | } else { |
||
| 147 | $module_options .= "<option value='$mid'>" . $myts->displayTarea($mname) . "</option>\n"; |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | // displaying part |
||
| 152 | echo " |
||
| 153 | <tr valign='middle'> |
||
| 154 | <td class='$class'> |
||
| 155 | $name |
||
| 156 | <br /> |
||
| 157 | <input type='text' name='title[$bid]' value='$title' size='20' /> |
||
| 158 | </td> |
||
| 159 | <td class='$class' align='center' nowrap='nowrap'> |
||
| 160 | <input type='radio' name='side[$bid]' value='" . XOOPS_SIDEBLOCK_LEFT . "'$ssel0 />-<input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_LEFT . "'$ssel2 /><input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_CENTER . "'$ssel3 /><input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_RIGHT . "'$ssel4 />-<input type='radio' name='side[$bid]' value='" . XOOPS_SIDEBLOCK_RIGHT . "'$ssel1 /> |
||
| 161 | <br /> |
||
| 162 | <br /> |
||
| 163 | <input type='radio' name='side[$bid]' value='-1'$sseln /> |
||
| 164 | " . _NONE . " |
||
| 165 | </td> |
||
| 166 | <td class='$class' align='center'> |
||
| 167 | <input type='text' name=weight[$bid] value='$weight' size='5' maxlength='5' style='text-align:right;' /> |
||
| 168 | </td> |
||
| 169 | <td class='$class' align='center'> |
||
| 170 | <select name='bmodule[$bid][]' size='5' multiple='multiple'> |
||
| 171 | $module_options |
||
| 172 | </select> |
||
| 173 | </td> |
||
| 174 | <td class='$class' align='center'> |
||
| 175 | <select name='bcachetime[$bid]' size='1'> |
||
| 176 | $cachetime_options |
||
| 177 | </select> |
||
| 178 | </td> |
||
| 179 | <td class='$class' align='center'> |
||
| 180 | <a href='admin.php?fct=blocksadmin&op=edit&bid=$bid'>" . _EDIT . "</a> |
||
| 181 | <input type='hidden' name='bid[$bid]' value='$bid' /> |
||
| 182 | </td> |
||
| 183 | </tr>\n"; |
||
| 184 | |||
| 185 | $class = ($class === 'even') ? 'odd' : 'even'; |
||
| 186 | } |
||
| 187 | |||
| 188 | echo " |
||
| 189 | <tr> |
||
| 190 | <td class='foot' align='center' colspan='6'> |
||
| 191 | <input type='hidden' name='fct' value='blocksadmin' /> |
||
| 192 | <input type='hidden' name='op' value='order' /> |
||
| 193 | <input type='submit' name='submit' value='" . _SUBMIT . "' /> |
||
| 194 | </td> |
||
| 195 | </tr> |
||
| 196 | </table> |
||
| 197 | </form>\n"; |
||
| 198 | echo '</div>'; |
||
| 199 | } |
||
| 200 | |||
| 201 | function list_groups() |
||
| 202 | { |
||
| 203 | global $xoopsModule, $block_arr; |
||
| 204 | $myts = MyTextSanitizer::getInstance(); |
||
| 205 | |||
| 206 | sf_collapsableBar('bottomtable', 'bottomtableicon'); |
||
| 207 | |||
| 208 | foreach (array_keys($block_arr) as $i) { |
||
| 209 | $item_list[$block_arr[$i]->getVar('bid')] = $block_arr[$i]->getVar('title'); |
||
| 210 | } |
||
| 211 | |||
| 212 | $form = new MyXoopsGroupPermForm('', 1, 'block_read', "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt='' /></a> " . _AM_SF_GROUPS . "</h3><div id='bottomtable'><span style=\"color: #567; margin: 3px 0 0 0; font-size: small; display: block; \">" . _AM_SF_GROUPSINFO . '</span>'); |
||
| 213 | $form->addAppendix('module_admin', $xoopsModule->mid(), $xoopsModule->name() . ' ' . _AM_ACTIVERIGHTS); |
||
| 214 | $form->addAppendix('module_read', $xoopsModule->mid(), $xoopsModule->name() . ' ' . _AM_ACCESSRIGHTS); |
||
| 215 | foreach ($item_list as $item_id => $item_name) { |
||
| 216 | $form->addItem($item_id, $myts->displayTarea($item_name)); |
||
| 217 | } |
||
| 218 | echo $form->render(); |
||
| 219 | echo '</div>'; |
||
| 220 | } |
||
| 221 | |||
| 222 | if (!empty($_POST['submit'])) { |
||
| 223 | include __DIR__ . '/mygroupperm.php'; |
||
| 224 | include_once("$xoops_system_path/language/$language/admin.php"); |
||
| 225 | redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/admin/myblocksadmin.php', 1, _AM_DBUPDATED); |
||
| 226 | } |
||
| 227 | |||
| 228 | xoops_cp_header(); |
||
| 229 | if (file_exists('./mymenu.php')) { |
||
| 230 | include('./mymenu.php'); |
||
| 231 | } |
||
| 232 | |||
| 233 | list_blocks(); |
||
| 234 | list_groups(); |
||
| 235 | xoops_cp_footer(); |
||
| 236 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.