Conditions | 28 |
Paths | 3042 |
Total Lines | 216 |
Code Lines | 131 |
Lines | 12 |
Ratio | 5.56 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
79 | function list_blockinstances() |
||
80 | { |
||
81 | global $query4redirect , $block_arr , $xoopsGTicket ; |
||
82 | |||
83 | $myts =& MyTextSanitizer::getInstance() ; |
||
84 | |||
85 | // cachetime options |
||
86 | $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); |
||
87 | |||
88 | // displaying TH |
||
89 | echo " |
||
90 | <form action='admin.php' name='blockadmin' method='post'> |
||
91 | <table width='95%' class='outer' cellpadding='4' cellspacing='1'> |
||
92 | <tr valign='middle'> |
||
93 | <th>"._AM_TITLE."</th> |
||
94 | <th align='center' nowrap='nowrap'>"._AM_SIDE."</th> |
||
95 | <th align='center'>"._AM_WEIGHT."</th> |
||
96 | <th align='center'>"._AM_VISIBLEIN."</th> |
||
97 | <th align='center'>"._AM_BCACHETIME."</th> |
||
98 | <th align='right'>"._AM_ACTION."</th> |
||
99 | </tr>\n" ; |
||
100 | |||
101 | // get block instances |
||
102 | $crit = new Criteria("bid", "(".implode(",",array_keys($block_arr)).")", "IN"); |
||
103 | $criteria = new CriteriaCompo($crit); |
||
104 | $criteria->setSort('visible DESC, side ASC, weight'); |
||
105 | $instance_handler =& xoops_gethandler('blockinstance'); |
||
106 | $instances =& $instance_handler->getObjects($criteria, true, true); |
||
107 | |||
108 | //Get modules and pages for visible in |
||
109 | $module_list[_AM_SYSTEMLEVEL]["0-2"] = _AM_ADMINBLOCK; |
||
110 | $module_list[_AM_SYSTEMLEVEL]["0-1"] = _AM_TOPPAGE; |
||
111 | $module_list[_AM_SYSTEMLEVEL]["0-0"] = _AM_ALLPAGES; |
||
112 | $criteria = new CriteriaCompo(new Criteria('hasmain', 1)); |
||
113 | $criteria->add(new Criteria('isactive', 1)); |
||
114 | $module_handler =& xoops_gethandler('module'); |
||
115 | $module_main =& $module_handler->getObjects($criteria, true, true); |
||
116 | if (count($module_main) > 0) { |
||
117 | foreach (array_keys($module_main) as $mid) { |
||
118 | $module_list[$module_main[$mid]->getVar('name')][$mid."-0"] = _AM_ALLMODULEPAGES; |
||
119 | $pages = $module_main[$mid]->getInfo("pages"); |
||
120 | if ($pages == false) { |
||
121 | $pages = $module_main[$mid]->getInfo("sub"); |
||
122 | } |
||
123 | if (is_array($pages) && $pages != array()) { |
||
124 | foreach ($pages as $id => $pageinfo) { |
||
125 | $module_list[$module_main[$mid]->getVar('name')][$mid."-".$id] = $pageinfo['name']; |
||
126 | } |
||
127 | } |
||
128 | } |
||
129 | } |
||
130 | |||
131 | // blocks displaying loop |
||
132 | $class = 'even' ; |
||
133 | $block_configs = get_block_configs() ; |
||
134 | foreach( array_keys( $instances ) as $i ) { |
||
135 | $sseln = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = ""; |
||
136 | $scoln = $scol0 = $scol1 = $scol2 = $scol3 = $scol4 = "#FFFFFF"; |
||
137 | |||
138 | $weight = $instances[$i]->getVar("weight") ; |
||
139 | $title = $instances[$i]->getVar("title") ; |
||
140 | $bcachetime = $instances[$i]->getVar("bcachetime") ; |
||
141 | $bid = $instances[$i]->getVar("bid") ; |
||
142 | $name = $myts->makeTboxData4Edit( $block_arr[$bid]['name'] ) ; |
||
143 | |||
144 | $visiblein = $instances[$i]->getVisibleIn(); |
||
145 | |||
146 | // visible and side |
||
147 | if ( $instances[$i]->getVar("visible") != 1 ) { |
||
148 | $sseln = " checked='checked'"; |
||
149 | $scoln = "#FF0000"; |
||
150 | } else switch( $instances[$i]->getVar("side") ) { |
||
151 | default : |
||
152 | case XOOPS_SIDEBLOCK_LEFT : |
||
153 | $ssel0 = " checked='checked'"; |
||
154 | $scol0 = "#00FF00"; |
||
155 | break ; |
||
156 | case XOOPS_SIDEBLOCK_RIGHT : |
||
157 | $ssel1 = " checked='checked'"; |
||
158 | $scol1 = "#00FF00"; |
||
159 | break ; |
||
160 | case XOOPS_CENTERBLOCK_LEFT : |
||
161 | $ssel2 = " checked='checked'"; |
||
162 | $scol2 = "#00FF00"; |
||
163 | break ; |
||
164 | case XOOPS_CENTERBLOCK_RIGHT : |
||
165 | $ssel4 = " checked='checked'"; |
||
166 | $scol4 = "#00FF00"; |
||
167 | break ; |
||
168 | case XOOPS_CENTERBLOCK_CENTER : |
||
169 | $ssel3 = " checked='checked'"; |
||
170 | $scol3 = "#00FF00"; |
||
171 | break ; |
||
172 | } |
||
173 | |||
174 | // bcachetime |
||
175 | $cachetime_options = '' ; |
||
176 | View Code Duplication | foreach( $cachetimes as $cachetime => $cachetime_name ) { |
|
177 | if( $bcachetime == $cachetime ) { |
||
178 | $cachetime_options .= "<option value='$cachetime' selected='selected'>$cachetime_name</option>\n" ; |
||
179 | } else { |
||
180 | $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n" ; |
||
181 | } |
||
182 | } |
||
183 | |||
184 | $module_options = '' ; |
||
185 | foreach( $module_list as $mname => $module ) { |
||
186 | $module_options .= "<optgroup label='$mname'>\n" ; |
||
187 | foreach( $module as $mkey => $mval ) { |
||
188 | if( in_array( $mkey , $visiblein ) ) { |
||
189 | $module_options .= "<option value='$mkey' selected='selected'>$mval</option>\n" ; |
||
190 | } else { |
||
191 | $module_options .= "<option label='$mval' value='$mkey'>$mval</option>\n" ; |
||
192 | } |
||
193 | } |
||
194 | $module_options .= "</optgroup>\n" ; |
||
195 | } |
||
196 | |||
197 | // delete link if it is cloned block |
||
198 | $delete_link = "<br /><a href='".XOOPS_URL."/modules/system/admin.php?fct=blocksadmin&op=delete&id=$i&selmod=$mid'>"._DELETE."</a>" ; |
||
199 | |||
200 | // displaying part |
||
201 | echo " |
||
202 | <tr valign='middle'> |
||
203 | <td class='$class'> |
||
204 | $name |
||
205 | <br /> |
||
206 | <input type='text' name='title[$i]' value='$title' size='20' /> |
||
207 | </td> |
||
208 | <td class='$class' align='center' nowrap='nowrap' width='125px'> |
||
209 | <div style='float:left;background-color:$scol0;'> |
||
210 | <input type='radio' name='side[$i]' value='".XOOPS_SIDEBLOCK_LEFT."' style='background-color:$scol0;' $ssel0 /> |
||
211 | </div> |
||
212 | <div style='float:left;'>-</div> |
||
213 | <div style='float:left;background-color:$scol2;'> |
||
214 | <input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_LEFT."' style='background-color:$scol2;' $ssel2 /> |
||
215 | </div> |
||
216 | <div style='float:left;background-color:$scol3;'> |
||
217 | <input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_CENTER."' style='background-color:$scol3;' $ssel3 /> |
||
218 | </div> |
||
219 | <div style='float:left;background-color:$scol4;'> |
||
220 | <input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_RIGHT."' style='background-color:$scol4;' $ssel4 /> |
||
221 | </div> |
||
222 | <div style='float:left;'>-</div> |
||
223 | <div style='float:left;background-color:$scol1;'> |
||
224 | <input type='radio' name='side[$i]' value='".XOOPS_SIDEBLOCK_RIGHT."' style='background-color:$scol1;' $ssel1 /> |
||
225 | </div> |
||
226 | <br /> |
||
227 | <br /> |
||
228 | <div style='float:left;width:40px;'> </div> |
||
229 | <div style='float:left;background-color:$scoln;'> |
||
230 | <input type='radio' name='side[$i]' value='-1' style='background-color:$scoln;' $sseln /> |
||
231 | </div> |
||
232 | <div style='float:left;'>"._NONE."</div> |
||
233 | </td> |
||
234 | <td class='$class' align='center'> |
||
235 | <input type='text' name=weight[$i] value='$weight' size='3' maxlength='5' style='text-align:right;' /> |
||
236 | </td> |
||
237 | <td class='$class' align='center'> |
||
238 | <select name='bmodule[$i][]' size='5' multiple='multiple'> |
||
239 | $module_options |
||
240 | </select> |
||
241 | </td> |
||
242 | <td class='$class' align='center'> |
||
243 | <select name='bcachetime[$i]' size='1'> |
||
244 | $cachetime_options |
||
245 | </select> |
||
246 | </td> |
||
247 | <td class='$class' align='right'> |
||
248 | <a href='".XOOPS_URL."/modules/system/admin.php?fct=blocksadmin&op=edit&id=$i'>"._EDIT."</a>{$delete_link} |
||
249 | <input type='hidden' name='id[$i]' value='$i' /> |
||
250 | </td> |
||
251 | </tr>\n" ; |
||
252 | |||
253 | $class = ( $class == 'even' ) ? 'odd' : 'even' ; |
||
254 | } |
||
255 | |||
256 | // list block classes for add (not instances) |
||
257 | foreach( $block_arr as $bid => $block ) { |
||
258 | |||
259 | $description4show = '' ; |
||
260 | View Code Duplication | foreach( $block_configs as $bconf ) { |
|
261 | if( $block['show_func'] == $bconf['show_func'] && $block['func_file'] == $bconf['file'] && ( empty( $bconf['template'] ) || $block['template'] == $bconf['template'] ) ) { |
||
262 | if( ! empty( $bconf['description'] ) ) $description4show = $myts->makeTboxData4Show( $bconf['description'] ) ; |
||
263 | } |
||
264 | } |
||
265 | |||
266 | echo " |
||
267 | <tr> |
||
268 | <td class='$class' align='left'> |
||
269 | ".$myts->makeTboxData4Edit($block['name'])." |
||
270 | </td> |
||
271 | <td class='$class' align='left' colspan='4'> |
||
272 | $description4show |
||
273 | </td> |
||
274 | <td class='$class' align='center'> |
||
275 | <input type='submit' name='addblock[$bid]' value='"._ADD."' /> |
||
276 | </td> |
||
277 | </tr> |
||
278 | \n" ; |
||
279 | $class = ( $class == 'even' ) ? 'odd' : 'even' ; |
||
280 | } |
||
281 | |||
282 | echo " |
||
283 | <tr> |
||
284 | <td class='foot' align='center' colspan='6'> |
||
285 | <input type='hidden' name='query4redirect' value='$query4redirect' /> |
||
286 | <input type='hidden' name='fct' value='blocksadmin' /> |
||
287 | <input type='hidden' name='op' value='order2' /> |
||
288 | ".$xoopsGTicket->getTicketHtml( __LINE__ , 1800 , 'myblocksadmin' )." |
||
289 | <input type='submit' name='submit' value='"._SUBMIT."' /> |
||
290 | </td> |
||
291 | </tr> |
||
292 | </table> |
||
293 | </form>\n" ; |
||
294 | } |
||
295 | |||
342 |
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.