| Conditions | 8 |
| Paths | 64 |
| Total Lines | 175 |
| Code Lines | 134 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 37 | function createCat($cid = 0) |
||
| 38 | { |
||
| 39 | // require_once dirname(__DIR__) . '/class/wfllists.php'; |
||
| 40 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 41 | |||
| 42 | global $xoopsDB, $myts, $totalcats, $xoopsModule; |
||
| 43 | /** @var Wflinks\Helper $helper */ |
||
| 44 | $helper = Wflinks\Helper::getInstance(); |
||
| 45 | |||
| 46 | $lid = 0; |
||
|
|
|||
| 47 | $title = ''; |
||
| 48 | $imgurl = ''; |
||
| 49 | $description = ''; |
||
| 50 | $pid = ''; |
||
| 51 | $weight = 0; |
||
| 52 | $nohtml = 0; |
||
| 53 | $nosmiley = 0; |
||
| 54 | $noxcodes = 0; |
||
| 55 | $noimages = 0; |
||
| 56 | $nobreak = 1; |
||
| 57 | $spotlighttop = 0; |
||
| 58 | $spotlighthis = 0; |
||
| 59 | $client_id = 0; |
||
| 60 | $banner_id = 0; |
||
| 61 | $heading = _AM_WFL_CCATEGORY_CREATENEW; |
||
| 62 | $totalcats = Wflinks\Utility::getTotalCategory(); |
||
| 63 | |||
| 64 | if ($cid) { |
||
| 65 | $sql = 'SELECT * FROM ' . $xoopsDB->prefix('wflinks_cat') . " WHERE cid=$cid"; |
||
| 66 | $cat_arr = $xoopsDB->fetchArray($xoopsDB->query($sql)); |
||
| 67 | $title = htmlspecialchars($cat_arr['title'], ENT_QUOTES | ENT_HTML5); |
||
| 68 | $imgurl = htmlspecialchars($cat_arr['imgurl'], ENT_QUOTES | ENT_HTML5); |
||
| 69 | $description = htmlspecialchars($cat_arr['description'], ENT_QUOTES | ENT_HTML5); |
||
| 70 | $nohtml = (int)$cat_arr['nohtml']; |
||
| 71 | $nosmiley = (int)$cat_arr['nosmiley']; |
||
| 72 | $noxcodes = (int)$cat_arr['noxcodes']; |
||
| 73 | $noimages = (int)$cat_arr['noimages']; |
||
| 74 | $nobreak = (int)$cat_arr['nobreak']; |
||
| 75 | $spotlighthis = (int)$cat_arr['spotlighthis']; |
||
| 76 | $spotlighttop = (int)$cat_arr['spotlighttop']; |
||
| 77 | $weight = $cat_arr['weight']; |
||
| 78 | $client_id = $cat_arr['client_id']; |
||
| 79 | $banner_id = $cat_arr['banner_id']; |
||
| 80 | $heading = _AM_WFL_CCATEGORY_MODIFY; |
||
| 81 | |||
| 82 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 83 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 84 | $groups = $grouppermHandler->getGroupIds('WFLinkCatPerm', $cid, $xoopsModule->getVar('mid')); |
||
| 85 | $groups = $groups; |
||
| 86 | } else { |
||
| 87 | $groups = true; |
||
| 88 | } |
||
| 89 | |||
| 90 | $sform = new \XoopsThemeForm($heading, 'op', xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
| 91 | $sform->setExtra('enctype="multipart/form-data"'); |
||
| 92 | |||
| 93 | $sform->addElement(new \XoopsFormText(_AM_WFL_FCATEGORY_TITLE, 'title', 50, 80, $title), true); |
||
| 94 | $sform->addElement(new \XoopsFormText(_AM_WFL_FCATEGORY_WEIGHT, 'weight', 10, 80, $weight), false); |
||
| 95 | |||
| 96 | if ($totalcats > 0 && $cid) { |
||
| 97 | $mytreechose = new Wflinks\Tree($xoopsDB->prefix('wflinks_cat'), 'cid', 'pid'); |
||
| 98 | ob_start(); |
||
| 99 | $mytreechose->makeMySelBox('title', 'title', $cat_arr['pid'], 1, 'pid'); |
||
| 100 | $sform->addElement(new \XoopsFormLabel(_AM_WFL_FCATEGORY_SUBCATEGORY, ob_get_clean())); |
||
| 101 | } else { |
||
| 102 | $mytreechose = new Wflinks\Tree($xoopsDB->prefix('wflinks_cat'), 'cid', 'pid'); |
||
| 103 | ob_start(); |
||
| 104 | $mytreechose->makeMySelBox('title', 'title', $cid, 1, 'pid'); |
||
| 105 | $sform->addElement(new \XoopsFormLabel(_AM_WFL_FCATEGORY_SUBCATEGORY, ob_get_clean())); |
||
| 106 | } |
||
| 107 | |||
| 108 | $graph_array = Wflinks\Lists::getListTypeAsArray(XOOPS_ROOT_PATH . '/' . $helper->getConfig('catimage'), $type = 'images'); |
||
| 109 | $indeximage_select = new \XoopsFormSelect('', 'imgurl', $imgurl); |
||
| 110 | $indeximage_select->addOptionArray($graph_array); |
||
| 111 | $indeximage_select->setExtra("onchange='showImgSelected(\"image\", \"imgurl\", \"" . $helper->getConfig('catimage') . '", "", "' . XOOPS_URL . "\")'"); |
||
| 112 | $indeximage_tray = new \XoopsFormElementTray(_AM_WFL_FCATEGORY_CIMAGE, ' '); |
||
| 113 | $indeximage_tray->addElement($indeximage_select); |
||
| 114 | if (!empty($imgurl)) { |
||
| 115 | $indeximage_tray->addElement(new \XoopsFormLabel('', "<br><br><img src='" . XOOPS_URL . '/' . $helper->getConfig('catimage') . '/' . $imgurl . "' name='image' id='image' alt=''>")); |
||
| 116 | } else { |
||
| 117 | $indeximage_tray->addElement(new \XoopsFormLabel('', "<br><br><img src='" . XOOPS_URL . "/uploads/blank.gif' name='image' id='image' alt=''>")); |
||
| 118 | } |
||
| 119 | $sform->addElement($indeximage_tray); |
||
| 120 | |||
| 121 | $editor = Wflinks\Utility::getWysiwygForm(_AM_WFL_FCATEGORY_DESCRIPTION, 'description', $description, 15, 60, ''); |
||
| 122 | $sform->addElement($editor, false); |
||
| 123 | |||
| 124 | // Select Client/Sponsor |
||
| 125 | $client_select = new \XoopsFormSelect(_AM_WFL_CATSPONSOR, 'client_id', $client_id, false); |
||
| 126 | $sql = 'SELECT cid, name FROM ' . $xoopsDB->prefix('bannerclient') . ' ORDER BY name ASC'; |
||
| 127 | $result = $xoopsDB->query($sql); |
||
| 128 | $client_array = []; |
||
| 129 | $client_array[0] = ' '; |
||
| 130 | while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
||
| 131 | $client_array[$myrow['cid']] = $myrow['name']; |
||
| 132 | } |
||
| 133 | $client_select->addOptionArray($client_array); |
||
| 134 | $client_select->setDescription(_AM_WFL_CATSPONSORDSC); |
||
| 135 | $sform->addElement($client_select); |
||
| 136 | |||
| 137 | // Select Banner |
||
| 138 | $banner_select = new \XoopsFormSelect(_AM_WFL_BANNERID, 'banner_id', $banner_id, false); |
||
| 139 | $sql = 'SELECT bid, cid FROM ' . $xoopsDB->prefix('banner') . ' ORDER BY bid ASC'; |
||
| 140 | $result = $xoopsDB->query($sql); |
||
| 141 | $banner_array = []; |
||
| 142 | $banner_array[0] = ' '; |
||
| 143 | while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
||
| 144 | $banner_array[$myrow['bid']] = $myrow['bid']; |
||
| 145 | } |
||
| 146 | $banner_select->addOptionArray($banner_array); |
||
| 147 | $banner_select->setDescription(_AM_WFL_BANNERIDDSC); |
||
| 148 | $sform->addElement($banner_select); |
||
| 149 | |||
| 150 | $options_tray = new \XoopsFormElementTray(_AM_WFL_TEXTOPTIONS, '<br>'); |
||
| 151 | |||
| 152 | $html_checkbox = new \XoopsFormCheckBox('', 'nohtml', $nohtml); |
||
| 153 | $html_checkbox->addOption(1, _AM_WFL_DISABLEHTML); |
||
| 154 | $options_tray->addElement($html_checkbox); |
||
| 155 | |||
| 156 | $smiley_checkbox = new \XoopsFormCheckBox('', 'nosmiley', $nosmiley); |
||
| 157 | $smiley_checkbox->addOption(1, _AM_WFL_DISABLESMILEY); |
||
| 158 | $options_tray->addElement($smiley_checkbox); |
||
| 159 | |||
| 160 | $xcodes_checkbox = new \XoopsFormCheckBox('', 'noxcodes', $noxcodes); |
||
| 161 | $xcodes_checkbox->addOption(1, _AM_WFL_DISABLEXCODE); |
||
| 162 | $options_tray->addElement($xcodes_checkbox); |
||
| 163 | |||
| 164 | $noimages_checkbox = new \XoopsFormCheckBox('', 'noimages', $noimages); |
||
| 165 | $noimages_checkbox->addOption(1, _AM_WFL_DISABLEIMAGES); |
||
| 166 | $options_tray->addElement($noimages_checkbox); |
||
| 167 | |||
| 168 | $breaks_checkbox = new \XoopsFormCheckBox('', 'nobreak', $nobreak); |
||
| 169 | $breaks_checkbox->addOption(1, _AM_WFL_DISABLEBREAK); |
||
| 170 | $options_tray->addElement($breaks_checkbox); |
||
| 171 | $sform->addElement($options_tray); |
||
| 172 | |||
| 173 | // $sform -> addElement(new \XoopsFormSelectGroup(_AM_WFL_FCATEGORY_GROUPPROMPT, "groups", true, $groups, 5, true)); |
||
| 174 | |||
| 175 | $sform->addElement(new \XoopsFormHidden('cid', $cid)); |
||
| 176 | |||
| 177 | $sform->addElement(new \XoopsFormHidden('spotlighttop', $cid)); |
||
| 178 | |||
| 179 | $buttonTray = new \XoopsFormElementTray('', ''); |
||
| 180 | $hidden = new \XoopsFormHidden('op', 'save'); |
||
| 181 | $buttonTray->addElement($hidden); |
||
| 182 | |||
| 183 | if ($cid) { |
||
| 184 | $butt_create = new \XoopsFormButton('', '', _AM_WFL_BMODIFY, 'submit'); |
||
| 185 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'addCat\'"'); |
||
| 186 | $buttonTray->addElement($butt_create); |
||
| 187 | |||
| 188 | $butt_delete = new \XoopsFormButton('', '', _AM_WFL_BDELETE, 'submit'); |
||
| 189 | $butt_delete->setExtra('onclick="this.form.elements.op.value=\'del\'"'); |
||
| 190 | $buttonTray->addElement($butt_delete); |
||
| 191 | |||
| 192 | $butt_cancel = new \XoopsFormButton('', '', _AM_WFL_BCANCEL, 'button'); |
||
| 193 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
| 194 | $buttonTray->addElement($butt_cancel); |
||
| 195 | } else { |
||
| 196 | $butt_create = new \XoopsFormButton('', '', _AM_WFL_BSAVE, 'submit'); |
||
| 197 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'addCat\'"'); |
||
| 198 | $buttonTray->addElement($butt_create); |
||
| 199 | |||
| 200 | $butt_clear = new \XoopsFormButton('', '', _AM_WFL_BRESET, 'reset'); |
||
| 201 | $buttonTray->addElement($butt_clear); |
||
| 202 | |||
| 203 | $butt_cancel = new \XoopsFormButton('', '', _AM_WFL_BCANCEL, 'button'); |
||
| 204 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
| 205 | $buttonTray->addElement($butt_cancel); |
||
| 206 | } |
||
| 207 | $sform->addElement($buttonTray); |
||
| 208 | $sform->display(); |
||
| 209 | |||
| 210 | $result2 = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('wflinks_cat') . ''); |
||
| 211 | list($numrows) = $xoopsDB->fetchRow($result2); |
||
| 212 | } |
||
| 430 |