Conditions | 8 |
Paths | 64 |
Total Lines | 175 |
Code Lines | 137 |
Lines | 5 |
Ratio | 2.86 % |
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 |
||
28 | function createcat($cid = 0) |
||
29 | { |
||
30 | include_once '../class/wfl_lists.php'; |
||
31 | include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
32 | |||
33 | global $xoopsDB, $wfmyts, $xoopsModuleConfig, $totalcats, $xoopsModule; |
||
34 | |||
35 | $lid = 0; |
||
36 | $title = ''; |
||
37 | $imgurl = ''; |
||
38 | $description = ''; |
||
39 | $pid = ''; |
||
40 | $weight = 0; |
||
41 | $nohtml = 0; |
||
42 | $nosmiley = 0; |
||
43 | $noxcodes = 0; |
||
44 | $noimages = 0; |
||
45 | $nobreak = 1; |
||
46 | $spotlighttop = 0; |
||
47 | $spotlighthis = 0; |
||
48 | $client_id = 0; |
||
49 | $banner_id = 0; |
||
50 | $heading = _AM_WFL_CCATEGORY_CREATENEW; |
||
51 | $totalcats = wfl_totalcategory(); |
||
52 | |||
53 | if ($cid) { |
||
54 | $sql = "SELECT * FROM " . $xoopsDB -> prefix('wflinks_cat') . " WHERE cid=$cid"; |
||
55 | $cat_arr = $xoopsDB -> fetchArray($xoopsDB -> query($sql)); |
||
56 | $title = $wfmyts -> htmlSpecialChars($cat_arr['title']); |
||
57 | $imgurl = $wfmyts -> htmlSpecialChars($cat_arr['imgurl']); |
||
58 | $description = $wfmyts -> htmlSpecialChars($cat_arr['description']); |
||
59 | $nohtml = intval($cat_arr['nohtml']); |
||
60 | $nosmiley = intval($cat_arr['nosmiley']); |
||
61 | $noxcodes = intval($cat_arr['noxcodes']); |
||
62 | $noimages = intval($cat_arr['noimages']); |
||
63 | $nobreak = intval($cat_arr['nobreak']); |
||
64 | $spotlighthis = intval($cat_arr['spotlighthis']); |
||
65 | $spotlighttop = intval($cat_arr['spotlighttop']); |
||
66 | $weight = $cat_arr['weight']; |
||
67 | $client_id = $cat_arr['client_id']; |
||
68 | $banner_id = $cat_arr['banner_id']; |
||
69 | $heading = _AM_WFL_CCATEGORY_MODIFY; |
||
70 | |||
71 | $gperm_handler = & xoops_gethandler('groupperm'); |
||
72 | $groups = $gperm_handler -> getGroupIds('WFLinkCatPerm', $cid, $xoopsModule -> getVar('mid')); |
||
73 | $groups = $groups; |
||
74 | } else { |
||
75 | $groups = true; |
||
76 | } |
||
77 | |||
78 | $sform = new XoopsThemeForm($heading, "op", xoops_getenv('PHP_SELF')); |
||
79 | $sform -> setExtra('enctype="multipart/form-data"'); |
||
80 | |||
81 | $sform -> addElement(new XoopsFormText(_AM_WFL_FCATEGORY_TITLE, 'title', 50, 80, $title), true); |
||
82 | $sform -> addElement(new XoopsFormText(_AM_WFL_FCATEGORY_WEIGHT, 'weight', 10, 80, $weight), false); |
||
83 | |||
84 | if ($totalcats > 0 && $cid) { |
||
85 | $mytreechose = new XoopsTree($xoopsDB -> prefix('wflinks_cat'), "cid", "pid"); |
||
86 | ob_start(); |
||
87 | $mytreechose -> makeMySelBox("title", "title", $cat_arr['pid'], 1, "pid"); |
||
88 | $sform -> addElement(new XoopsFormLabel(_AM_WFL_FCATEGORY_SUBCATEGORY, ob_get_contents())); |
||
89 | ob_end_clean(); |
||
90 | } else { |
||
91 | $mytreechose = new XoopsTree($xoopsDB -> prefix('wflinks_cat'), 'cid', 'pid'); |
||
92 | ob_start(); |
||
93 | $mytreechose -> makeMySelBox("title", "title", $cid, 1, "pid"); |
||
94 | $sform -> addElement(new XoopsFormLabel(_AM_WFL_FCATEGORY_SUBCATEGORY, ob_get_contents())); |
||
95 | ob_end_clean(); |
||
96 | } |
||
97 | |||
98 | $graph_array = & wflLists :: getListTypeAsArray(XOOPS_ROOT_PATH . "/" . $xoopsModuleConfig['catimage'], $type = "images"); |
||
99 | $indeximage_select = new XoopsFormSelect('', 'imgurl', $imgurl); |
||
100 | $indeximage_select -> addOptionArray($graph_array); |
||
101 | $indeximage_select -> setExtra("onchange='showImgSelected(\"image\", \"imgurl\", \"" . $xoopsModuleConfig['catimage'] . "\", \"\", \"" . XOOPS_URL . "\")'"); |
||
102 | $indeximage_tray = new XoopsFormElementTray(_AM_WFL_FCATEGORY_CIMAGE, ' '); |
||
103 | $indeximage_tray -> addElement($indeximage_select); |
||
104 | View Code Duplication | if (!empty($imgurl)) { |
|
105 | $indeximage_tray -> addElement(new XoopsFormLabel('', "<br /><br /><img src='" . XOOPS_URL . "/" . $xoopsModuleConfig['catimage'] . "/" . $imgurl . "' name='image' id='image' alt='' />")); |
||
106 | } else { |
||
107 | $indeximage_tray -> addElement(new XoopsFormLabel('', "<br /><br /><img src='" . XOOPS_URL . "/uploads/blank.gif' name='image' id='image' alt='' />")); |
||
108 | } |
||
109 | $sform -> addElement($indeximage_tray); |
||
110 | |||
111 | $editor = wfl_getWysiwygForm( _AM_WFL_FCATEGORY_DESCRIPTION, 'description', $description, 15, 60, ''); |
||
112 | $sform -> addElement( $editor, false ); |
||
113 | |||
114 | // Select Client/Sponsor |
||
115 | $client_select = new XoopsFormSelect( _AM_WFL_CATSPONSOR, 'client_id', $client_id, false); |
||
116 | $sql = "SELECT cid, name FROM " . $xoopsDB -> prefix('bannerclient') . " ORDER BY name ASC"; |
||
117 | $result = $xoopsDB -> query($sql); |
||
118 | $client_array = array(); |
||
119 | $client_array[0] = ' '; |
||
120 | while ($myrow = $xoopsDB -> fetchArray($result)) { |
||
121 | $client_array[$myrow['cid']] = $myrow['name']; |
||
122 | } |
||
123 | $client_select -> addOptionArray($client_array); |
||
124 | $client_select -> setDescription(_AM_WFL_CATSPONSORDSC); |
||
125 | $sform -> addElement( $client_select ); |
||
126 | |||
127 | // Select Banner |
||
128 | $banner_select = new XoopsFormSelect( _AM_WFL_BANNERID, 'banner_id', $banner_id, false); |
||
129 | $sql = "SELECT bid, cid FROM " . $xoopsDB -> prefix('banner') . " ORDER BY bid ASC"; |
||
130 | $result = $xoopsDB -> query($sql); |
||
131 | $banner_array = array(); |
||
132 | $banner_array[0] = ' '; |
||
133 | while ($myrow = $xoopsDB -> fetchArray($result)) { |
||
134 | $banner_array[$myrow['bid']] = $myrow['bid']; |
||
135 | } |
||
136 | $banner_select -> addOptionArray($banner_array); |
||
137 | $banner_select -> setDescription(_AM_WFL_BANNERIDDSC); |
||
138 | $sform -> addElement( $banner_select ); |
||
139 | |||
140 | $options_tray = new XoopsFormElementTray(_AM_WFL_TEXTOPTIONS, '<br />'); |
||
141 | |||
142 | $html_checkbox = new XoopsFormCheckBox('', 'nohtml', $nohtml); |
||
143 | $html_checkbox -> addOption(1, _AM_WFL_DISABLEHTML); |
||
144 | $options_tray -> addElement($html_checkbox); |
||
145 | |||
146 | $smiley_checkbox = new XoopsFormCheckBox('', 'nosmiley', $nosmiley); |
||
147 | $smiley_checkbox -> addOption(1, _AM_WFL_DISABLESMILEY); |
||
148 | $options_tray -> addElement($smiley_checkbox); |
||
149 | |||
150 | $xcodes_checkbox = new XoopsFormCheckBox('', 'noxcodes', $noxcodes); |
||
151 | $xcodes_checkbox -> addOption(1, _AM_WFL_DISABLEXCODE); |
||
152 | $options_tray -> addElement($xcodes_checkbox); |
||
153 | |||
154 | $noimages_checkbox = new XoopsFormCheckBox('', 'noimages', $noimages); |
||
155 | $noimages_checkbox -> addOption(1, _AM_WFL_DISABLEIMAGES); |
||
156 | $options_tray -> addElement($noimages_checkbox); |
||
157 | |||
158 | $breaks_checkbox = new XoopsFormCheckBox('', 'nobreak', $nobreak); |
||
159 | $breaks_checkbox -> addOption(1, _AM_WFL_DISABLEBREAK); |
||
160 | $options_tray -> addElement($breaks_checkbox); |
||
161 | $sform -> addElement($options_tray); |
||
162 | |||
163 | // $sform -> addElement(new XoopsFormSelectGroup(_AM_WFL_FCATEGORY_GROUPPROMPT, "groups", true, $groups, 5, true)); |
||
164 | |||
165 | $sform -> addElement(new XoopsFormHidden('cid', $cid)); |
||
166 | |||
167 | $sform -> addElement(new XoopsFormHidden('spotlighttop', $cid)); |
||
168 | |||
169 | $button_tray = new XoopsFormElementTray('', ''); |
||
170 | $hidden = new XoopsFormHidden('op', 'save'); |
||
171 | $button_tray -> addElement($hidden); |
||
172 | |||
173 | if (!$cid) { |
||
174 | $butt_create = new XoopsFormButton('', '', _AM_WFL_BSAVE, 'submit'); |
||
175 | $butt_create -> setExtra('onclick="this.form.elements.op.value=\'addCat\'"'); |
||
176 | $button_tray -> addElement($butt_create); |
||
177 | |||
178 | $butt_clear = new XoopsFormButton('', '', _AM_WFL_BRESET, 'reset'); |
||
179 | $button_tray -> addElement($butt_clear); |
||
180 | |||
181 | $butt_cancel = new XoopsFormButton('', '', _AM_WFL_BCANCEL, 'button'); |
||
182 | $butt_cancel -> setExtra('onclick="history.go(-1)"'); |
||
183 | $button_tray -> addElement($butt_cancel); |
||
184 | } else { |
||
185 | $butt_create = new XoopsFormButton('', '', _AM_WFL_BMODIFY, 'submit'); |
||
186 | $butt_create -> setExtra('onclick="this.form.elements.op.value=\'addCat\'"'); |
||
187 | $button_tray -> addElement($butt_create); |
||
188 | |||
189 | $butt_delete = new XoopsFormButton('', '', _AM_WFL_BDELETE, 'submit'); |
||
190 | $butt_delete -> setExtra('onclick="this.form.elements.op.value=\'del\'"'); |
||
191 | $button_tray -> addElement($butt_delete); |
||
192 | |||
193 | $butt_cancel = new XoopsFormButton('', '', _AM_WFL_BCANCEL, 'button'); |
||
194 | $butt_cancel -> setExtra('onclick="history.go(-1)"'); |
||
195 | $button_tray -> addElement($butt_cancel); |
||
196 | } |
||
197 | $sform -> addElement($button_tray); |
||
198 | $sform -> display(); |
||
199 | |||
200 | $result2 = $xoopsDB -> query("SELECT COUNT(*) FROM " . $xoopsDB -> prefix('wflinks_cat') . ""); |
||
201 | list($numrows) = $xoopsDB -> fetchRow($result2); |
||
202 | } |
||
203 | |||
427 |
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.