Conditions | 10 |
Paths | 128 |
Total Lines | 197 |
Code Lines | 151 |
Lines | 19 |
Ratio | 9.64 % |
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 |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @param int $cid |
||
44 | */ |
||
45 | function createCategory($cid = 0) |
||
46 | { |
||
47 | // require_once dirname(__DIR__) . '/class/xoopstube_lists.php'; |
||
48 | // require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
49 | |||
50 | global $myts, $totalcats, $xoopsModule; |
||
51 | |||
52 | $lid = 0; |
||
|
|||
53 | $title = ''; |
||
54 | $imgurl = ''; |
||
55 | $description = ''; |
||
56 | $pid = ''; |
||
57 | $weight = 0; |
||
58 | $nohtml = 0; |
||
59 | $nosmiley = 0; |
||
60 | $noxcodes = 0; |
||
61 | $noimages = 0; |
||
62 | $nobreak = 1; |
||
63 | $spotlighttop = 0; |
||
64 | $spotlighthis = 0; |
||
65 | $client_id = 0; |
||
66 | $banner_id = 0; |
||
67 | $heading = _AM_XOOPSTUBE_CCATEGORY_CREATENEW; |
||
68 | $totalcats = Utility::getTotalCategoryCount(); |
||
69 | |||
70 | if ($cid > 0) { |
||
71 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_cat') . ' WHERE cid=' . (int)$cid; |
||
72 | $cat_arr = $GLOBALS['xoopsDB']->fetchArray($GLOBALS['xoopsDB']->query($sql)); |
||
73 | $title = htmlspecialchars($cat_arr['title']); |
||
74 | $imgurl = htmlspecialchars($cat_arr['imgurl']); |
||
75 | $description = htmlspecialchars($cat_arr['description']); |
||
76 | $nohtml = (int)$cat_arr['nohtml']; |
||
77 | $nosmiley = (int)$cat_arr['nosmiley']; |
||
78 | $noxcodes = (int)$cat_arr['noxcodes']; |
||
79 | $noimages = (int)$cat_arr['noimages']; |
||
80 | $nobreak = (int)$cat_arr['nobreak']; |
||
81 | $spotlighthis = (int)$cat_arr['spotlighthis']; |
||
82 | $spotlighttop = (int)$cat_arr['spotlighttop']; |
||
83 | $weight = $cat_arr['weight']; |
||
84 | $client_id = $cat_arr['client_id']; |
||
85 | $banner_id = $cat_arr['banner_id']; |
||
86 | $heading = _AM_XOOPSTUBE_CCATEGORY_MODIFY; |
||
87 | |||
88 | /** @var \XoopsMemberHandler $memberHandler */ |
||
89 | $memberHandler = xoops_getHandler('member'); |
||
90 | $group_list = $memberHandler->getGroupList(); |
||
91 | /** @var \XoopsMemberHandler $memberHandler */ |
||
92 | $memberHandler = xoops_getHandler('member'); |
||
93 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
94 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
95 | $groups = $grouppermHandler->getGroupIds('XTubeCatPerm', $cid, $xoopsModule->getVar('mid')); |
||
96 | } else { |
||
97 | $groups = true; |
||
98 | } |
||
99 | echo '<br><br>'; |
||
100 | $sform = new \XoopsThemeForm($heading, 'op', xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
101 | $sform->setExtra('enctype="multipart/form-data"'); |
||
102 | |||
103 | $sform->addElement(new \XoopsFormText(_AM_XOOPSTUBE_FCATEGORY_TITLE, 'title', 50, 80, $title), true); |
||
104 | $sform->addElement(new \XoopsFormText(_AM_XOOPSTUBE_FCATEGORY_WEIGHT, 'weight', 10, 80, $weight), false); |
||
105 | |||
106 | if ($totalcats > 0 && $cid) { |
||
107 | $mytreechose = new Tree($GLOBALS['xoopsDB']->prefix('xoopstube_cat'), 'cid', 'pid'); |
||
108 | ob_start(); |
||
109 | $mytreechose->makeMySelBox('title', 'title', $cat_arr['pid'], 1, 'pid'); |
||
110 | $sform->addElement(new \XoopsFormLabel(_AM_XOOPSTUBE_FCATEGORY_SUBCATEGORY, ob_get_clean())); |
||
111 | } else { |
||
112 | $mytreechose = new Tree($GLOBALS['xoopsDB']->prefix('xoopstube_cat'), 'cid', 'pid'); |
||
113 | ob_start(); |
||
114 | $mytreechose->makeMySelBox('title', 'title', $cid, 1, 'pid'); |
||
115 | $sform->addElement(new \XoopsFormLabel(_AM_XOOPSTUBE_FCATEGORY_SUBCATEGORY, ob_get_clean())); |
||
116 | } |
||
117 | |||
118 | $graph_array = Lists::getListTypeAsArray(XOOPS_ROOT_PATH . '/' . $GLOBALS['xoopsModuleConfig']['catimage'], $type = 'images'); |
||
119 | $indexImageSelect = new \XoopsFormSelect('', 'imgurl', $imgurl); |
||
120 | $indexImageSelect->addOptionArray($graph_array); |
||
121 | $indexImageSelect->setExtra("onchange='showImgSelected(\"image\", \"imgurl\", \"" . $GLOBALS['xoopsModuleConfig']['catimage'] . '", "", "' . XOOPS_URL . "\")'"); |
||
122 | $indeximage_tray = new \XoopsFormElementTray(_AM_XOOPSTUBE_FCATEGORY_CIMAGE, ' '); |
||
123 | $indeximage_tray->addElement($indexImageSelect); |
||
124 | if ('' !== $imgurl && 1 != $imgurl) { |
||
125 | $indeximage_tray->addElement(new \XoopsFormLabel('', "<br><br><img src='" . XOOPS_URL . '/' . $GLOBALS['xoopsModuleConfig']['catimage'] . '/' . $imgurl . "' name='image' id='image' alt=''>")); |
||
126 | } else { |
||
127 | $indeximage_tray->addElement(new \XoopsFormLabel('', "<br><br><img src='" . XOOPS_URL . "/uploads/blank.gif' name='image' id='image' alt=''>")); |
||
128 | } |
||
129 | $sform->addElement($indeximage_tray); |
||
130 | |||
131 | // $editor = xtube_getWysiwygForm(_AM_XOOPSTUBE_FCATEGORY_DESCRIPTION, 'description', $description, 15, 60, ''); |
||
132 | // $sform->addElement($editor, false); |
||
133 | |||
134 | $optionsTrayNote = new \XoopsFormElementTray(_AM_XOOPSTUBE_FCATEGORY_DESCRIPTION, '<br>'); |
||
135 | if (class_exists('XoopsFormEditor')) { |
||
136 | $options['name'] = 'description'; |
||
137 | $options['value'] = $description; |
||
138 | $options['rows'] = 5; |
||
139 | $options['cols'] = '100%'; |
||
140 | $options['width'] = '100%'; |
||
141 | $options['height'] = '200px'; |
||
142 | $editor = new \XoopsFormEditor('', $GLOBALS['xoopsModuleConfig']['form_optionsuser'], $options, $nohtml = false, $onfailure = 'textarea'); |
||
143 | $optionsTrayNote->addElement($editor); |
||
144 | } else { |
||
145 | $editor = new \XoopsFormDhtmlTextArea('', 'description', $item->getVar('description', 'e'), '100%', '100%'); |
||
146 | $optionsTrayNote->addElement($editor); |
||
147 | } |
||
148 | |||
149 | $sform->addElement($optionsTrayNote, false); |
||
150 | |||
151 | // Select Client/Sponsor |
||
152 | $client_select = new \XoopsFormSelect(_AM_XOOPSTUBE_CATSPONSOR, 'client_id', $client_id, false); |
||
153 | $sql = 'SELECT cid, name FROM ' . $GLOBALS['xoopsDB']->prefix('bannerclient') . ' ORDER BY name ASC'; |
||
154 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
155 | $client_array = []; |
||
156 | $client_array[0] = ' '; |
||
157 | while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
158 | $client_array[$myrow['cid']] = $myrow['name']; |
||
159 | } |
||
160 | $client_select->addOptionArray($client_array); |
||
161 | |||
162 | $client_select->setDescription(_AM_XOOPSTUBE_CATSPONSORDSC); |
||
163 | $sform->addElement($client_select); |
||
164 | |||
165 | // Select Banner |
||
166 | $banner_select = new \XoopsFormSelect(_AM_XOOPSTUBE_BANNERID, 'banner_id', $banner_id, false); |
||
167 | $sql = 'SELECT bid, cid FROM ' . $GLOBALS['xoopsDB']->prefix('banner') . ' ORDER BY bid ASC'; |
||
168 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
169 | $banner_array = []; |
||
170 | $banner_array[0] = ' '; |
||
171 | while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
172 | $banner_array[$myrow['bid']] = $myrow['bid']; |
||
173 | } |
||
174 | $banner_select->addOptionArray($banner_array); |
||
175 | $banner_select->setDescription(_AM_XOOPSTUBE_BANNERIDDSC); |
||
176 | $sform->addElement($banner_select); |
||
177 | |||
178 | $options_tray = new \XoopsFormElementTray(_AM_XOOPSTUBE_TEXTOPTIONS, '<br>'); |
||
179 | |||
180 | $html_checkbox = new \XoopsFormCheckBox('', 'nohtml', $nohtml); |
||
181 | $html_checkbox->addOption(1, _AM_XOOPSTUBE_DISABLEHTML); |
||
182 | $options_tray->addElement($html_checkbox); |
||
183 | |||
184 | $smiley_checkbox = new \XoopsFormCheckBox('', 'nosmiley', $nosmiley); |
||
185 | $smiley_checkbox->addOption(1, _AM_XOOPSTUBE_DISABLESMILEY); |
||
186 | $options_tray->addElement($smiley_checkbox); |
||
187 | |||
188 | $xcodes_checkbox = new \XoopsFormCheckBox('', 'noxcodes', $noxcodes); |
||
189 | $xcodes_checkbox->addOption(1, _AM_XOOPSTUBE_DISABLEXCODE); |
||
190 | $options_tray->addElement($xcodes_checkbox); |
||
191 | |||
192 | $noimages_checkbox = new \XoopsFormCheckBox('', 'noimages', $noimages); |
||
193 | $noimages_checkbox->addOption(1, _AM_XOOPSTUBE_DISABLEIMAGES); |
||
194 | $options_tray->addElement($noimages_checkbox); |
||
195 | |||
196 | $breaks_checkbox = new \XoopsFormCheckBox('', 'nobreak', $nobreak); |
||
197 | $breaks_checkbox->addOption(1, _AM_XOOPSTUBE_DISABLEBREAK); |
||
198 | $options_tray->addElement($breaks_checkbox); |
||
199 | $sform->addElement($options_tray); |
||
200 | |||
201 | // $sform -> addElement(new \XoopsFormSelectGroup(_AM_XOOPSTUBE_FCATEGORY_GROUPPROMPT, "groups", true, $groups, 5, true)); |
||
202 | |||
203 | $sform->addElement(new \XoopsFormHidden('cid', (int)$cid)); |
||
204 | |||
205 | $sform->addElement(new \XoopsFormHidden('spotlighttop', (int)$cid)); |
||
206 | |||
207 | $buttonTray = new \XoopsFormElementTray('', ''); |
||
208 | $hidden = new \XoopsFormHidden('op', 'save'); |
||
209 | $buttonTray->addElement($hidden); |
||
210 | |||
211 | if (!$cid) { |
||
212 | $butt_create = new \XoopsFormButton('', '', _AM_XOOPSTUBE_BSAVE, 'submit'); |
||
213 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'addCat\'"'); |
||
214 | $buttonTray->addElement($butt_create); |
||
215 | |||
216 | $butt_clear = new \XoopsFormButton('', '', _AM_XOOPSTUBE_BRESET, 'reset'); |
||
217 | $buttonTray->addElement($butt_clear); |
||
218 | |||
219 | $butt_cancel = new \XoopsFormButton('', '', _AM_XOOPSTUBE_BCANCEL, 'button'); |
||
220 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
221 | $buttonTray->addElement($butt_cancel); |
||
222 | } else { |
||
223 | $butt_create = new \XoopsFormButton('', '', _AM_XOOPSTUBE_BMODIFY, 'submit'); |
||
224 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'addCat\'"'); |
||
225 | $buttonTray->addElement($butt_create); |
||
226 | |||
227 | $butt_delete = new \XoopsFormButton('', '', _AM_XOOPSTUBE_BDELETE, 'submit'); |
||
228 | $butt_delete->setExtra('onclick="this.form.elements.op.value=\'del\'"'); |
||
229 | $buttonTray->addElement($butt_delete); |
||
230 | |||
231 | $butt_cancel = new \XoopsFormButton('', '', _AM_XOOPSTUBE_BCANCEL, 'button'); |
||
232 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||
233 | $buttonTray->addElement($butt_cancel); |
||
234 | } |
||
235 | $sform->addElement($buttonTray); |
||
236 | $sform->display(); |
||
237 | |||
492 |