Conditions | 32 |
Paths | 5491 |
Total Lines | 174 |
Code Lines | 125 |
Lines | 56 |
Ratio | 32.18 % |
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 |
||
68 | function drawDirs_Files($list, &$manager) |
||
69 | { |
||
70 | global $relative, $afruViewType, $IMConfig, $insertMode,$backend_url_enc; |
||
71 | |||
72 | switch ($afruViewType) { |
||
73 | case 'listview': |
||
74 | $maxNameLength = 30; |
||
75 | ?> |
||
76 | <table class="listview" id="listview"> |
||
77 | <thead> |
||
78 | <tr><th>Name</th><th>Size</th><th>Image Size</th><th>Date Modified</th><th> </th></tr></thead> |
||
79 | <tbody> |
||
80 | <?php |
||
81 | // start of foreach for draw listview folders . |
||
82 | foreach($list[0] as $path => $dir) |
||
83 | { ?> |
||
84 | <tr> |
||
85 | <td><span style="width:20px;"><img src="<?php print $IMConfig['base_url'];?>icons/folder_small.gif" alt="" /></span> |
||
86 | <a href="<?php print $backend_url_enc; ?>__function=images&mode=<?php echo $insertMode;?>&dir=<?php echo rawurlencode($path); ?>&viewtype=<?php echo $afruViewType; ?>" onclick="updateDir('<?php echo $path; ?>')" title="<?php echo $dir['entry']; ?>"> |
||
87 | <?php |
||
88 | View Code Duplication | if(strlen($dir['entry'])>$maxNameLength) echo substr($dir['entry'],0,$maxNameLength)."..."; else echo $dir['entry']; |
|
89 | ?> |
||
90 | </a></td> |
||
91 | <td colspan="2" >Folder</td> |
||
92 | |||
93 | <td ><?php echo date($IMConfig['date_format'],$dir['stat']['mtime']); ?></td> |
||
94 | |||
95 | <td class="actions" > |
||
96 | <?php |
||
97 | View Code Duplication | if($IMConfig['allow_delete']) |
|
98 | { |
||
99 | ?> |
||
100 | <a href="<?php print $backend_url_enc; ?>__function=images&mode=<?php echo $insertMode;?>&dir=<?php echo $relative; ?>&deld=<?php echo rawurlencode($path); ?>&viewtype=<?php echo $afruViewType; ?>" title="Trash" onclick="return confirmDeleteDir('<?php echo $dir['entry']; ?>', <?php echo $dir['count']; ?>);" style="border:0px;"><img src="<?php print $IMConfig['base_url'];?>img/edit_trash.gif" height="15" width="15" alt="Trash" border="0" /></a> |
||
101 | <?php |
||
102 | } |
||
103 | ?> |
||
104 | <?php if ($IMConfig['allow_rename']) { ?> |
||
105 | <a href="#" title="Rename" onclick="renameDir('<?php echo rawurlencode($dir['entry']);?>'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_rename.gif" height="15" width="15" alt="Rename" border="0" /></a> |
||
106 | <?php } ?> |
||
107 | View Code Duplication | <?php if ($IMConfig['allow_cut_copy_paste']) { ?> |
|
108 | <a href="#" title="Cut" onclick="copyDir('<?php echo rawurlencode($dir['entry']);?>','move'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_cut.gif" height="15" width="15" alt="Cut" /></a> |
||
109 | <a href="#" title="Copy" onclick="copyDir('<?php echo rawurlencode($dir['entry']);?>','copy'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_copy.gif" height="15" width="15" alt="Copy" /></a> |
||
110 | <?php } ?> |
||
111 | </td> |
||
112 | </tr> |
||
113 | <?php |
||
114 | } // end of foreach for draw listview folders . |
||
115 | |||
116 | clearstatcache(); |
||
117 | |||
118 | // start of foreach for draw listview files . |
||
119 | foreach($list[1] as $entry => $file) |
||
120 | { |
||
121 | ?> |
||
122 | <tr> |
||
123 | <td> |
||
124 | <a href="#" class="thumb" style="cursor: pointer;vertical-align:middle;" ondblclick="this.onclick();window.top.onOK();" onclick="selectImage('<?php echo $file['relative'];?>', '<?php echo preg_replace('#\..{3,4}$#', '', $entry); ?>', <?php echo $file['image'][0];?>, <?php echo $file['image'][1]; ?>);return false;" title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>" <?php if ($insertMode == 'image') { ?> onmouseover="showPreview('<?php echo $file['relative'];?>')" onmouseout="showPreview(window.parent.document.getElementById('f_url').value)" <?php } ?> > |
||
125 | <span style="width:20px;vertical-align:middle;"><img src="<?php print $IMConfig['base_url']; if(is_file('icons/'.$file['ext'].'_small.gif')) echo "icons/".$file['ext']."_small.gif"; else echo $IMConfig['default_listicon']; ?>" alt="" style="border:none;" /></span><span style="vertical-align:middle;"> |
||
126 | <?php |
||
127 | if(strlen($entry)>$maxNameLength) echo substr($entry,0,$maxNameLength)."..."; else echo $entry; |
||
128 | ?></span> |
||
129 | </a></td> |
||
130 | <td><?php echo Files::formatSize($file['stat']['size']); ?></td> |
||
131 | View Code Duplication | <td><?php if($file['image'][0] > 0){ echo $file['image'][0].'x'.$file['image'][1]; } ?></td> |
|
132 | <td ><?php echo date($IMConfig['date_format'],$file['stat']['mtime']); ?></td> |
||
133 | <td class="actions"> |
||
134 | View Code Duplication | <?php if($IMConfig['img_library'] && $IMConfig['allow_edit_image'] && $file['image'][0] > 0) { ?> |
|
135 | <a href="javascript:;" title="Edit" onclick="editImage('<?php echo rawurlencode($file['relative']);?>');"><img src="<?php print $IMConfig['base_url'];?>img/edit_pencil.gif" height="15" width="15" alt="Edit" border="0" /></a> |
||
136 | <?php } ?> |
||
137 | <?php |
||
138 | View Code Duplication | if($IMConfig['allow_delete']) |
|
139 | { |
||
140 | ?> |
||
141 | <a href="<?php print $backend_url_enc; ?>__function=images&dir=<?php echo $relative; ?>&delf=<?php echo rawurlencode($file['relative']);?>&mode=<?php echo $insertMode;?>&viewtype=<?php echo $afruViewType; ?>" title="Trash" onclick="return confirmDeleteFile('<?php echo $entry; ?>');"><img src="<?php print $IMConfig['base_url'];?>img/edit_trash.gif" height="15" width="15" alt="Trash" border="0" /></a> |
||
142 | <?php |
||
143 | } |
||
144 | ?> |
||
145 | View Code Duplication | <?php if ($IMConfig['allow_rename']) { ?> |
|
146 | <a href="#" title="Rename" onclick="renameFile('<?php echo rawurlencode($file['relative']);?>'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_rename.gif" height="15" width="15" alt="Rename" border="0" /></a> |
||
147 | <?php } ?> |
||
148 | View Code Duplication | <?php if ($IMConfig['allow_cut_copy_paste']) { ?> |
|
149 | <a href="#" title="Cut" onclick="copyFile('<?php echo rawurlencode($entry);?>','move'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_cut.gif" height="15" width="15" alt="Cut" /></a> |
||
150 | <a href="#" title="Copy" onclick="copyFile('<?php echo rawurlencode($entry);?>','copy'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_copy.gif" height="15" width="15" alt="Copy" /></a> |
||
151 | <?php } ?> |
||
152 | </td> |
||
153 | </tr> |
||
154 | <?php |
||
155 | }//end of foreach of draw listview files |
||
156 | ?> |
||
157 | </tbody> |
||
158 | </table> |
||
159 | <?php |
||
160 | break; |
||
161 | case 'thumbview': // thumbview is default |
||
162 | default: |
||
163 | $maxFileNameLength=16; |
||
164 | $maxFolderNameLength=16; |
||
165 | // start of foreach for draw thumbview folders. |
||
166 | foreach($list[0] as $path => $dir) |
||
167 | { ?> |
||
168 | <div class="dir_holder"> |
||
169 | <a class="dir" href="<?php print $backend_url_enc;?>__function=images&mode=<?php echo $insertMode;?>&dir=<?php echo rawurlencode($path); ?>&viewtype=<?php echo $afruViewType; ?>" onclick="updateDir('<?php echo $path; ?>')" title="<?php echo $dir['entry']; ?>"><img src="<?php print $IMConfig['base_url'];?>img/folder.gif" height="80" width="80" alt="<?php echo $dir['entry']; ?>" /></a> |
||
170 | |||
171 | <div class="fileName"> |
||
172 | View Code Duplication | <?php if(strlen($dir['entry']) > $maxFolderNameLength) |
|
173 | echo substr($dir['entry'], 0, $maxFolderNameLength) . "..."; |
||
174 | else |
||
175 | echo $dir['entry']; ?> |
||
176 | </div> |
||
177 | <div class="edit"> |
||
178 | <?php |
||
179 | View Code Duplication | if($IMConfig['allow_delete']) |
|
180 | { |
||
181 | ?> |
||
182 | <a href="<?php print $backend_url_enc;?>__function=images&mode=<?php echo $insertMode;?>&dir=<?php echo $relative; ?>&deld=<?php echo rawurlencode($path); ?>&viewtype=<?php echo $afruViewType; ?>" title="Trash" onclick="return confirmDeleteDir('<?php echo $dir['entry']; ?>', <?php echo $dir['count']; ?>);"><img src="<?php print $IMConfig['base_url'];?>img/edit_trash.gif" height="15" width="15" alt="Trash" /></a> |
||
183 | <?php |
||
184 | } |
||
185 | ?> |
||
186 | <?php if ($IMConfig['allow_rename']) { ?> |
||
187 | <a href="#" title="Rename" onclick="renameDir('<?php echo rawurlencode($dir['entry']);?>'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_rename.gif" height="15" width="15" alt="Rename" border="0" /></a> |
||
188 | <?php } ?> |
||
189 | View Code Duplication | <?php if ($IMConfig['allow_cut_copy_paste']) { ?> |
|
190 | <a href="#" title="Cut" onclick="copyDir('<?php echo rawurlencode($dir['entry']);?>','move'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_cut.gif" height="15" width="15" alt="Cut" /></a> |
||
191 | <a href="#" title="Copy" onclick="copyDir('<?php echo rawurlencode($dir['entry']);?>','copy'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_copy.gif" height="15" width="15" alt="Copy" /></a> |
||
192 | <?php } ?> |
||
193 | </div> |
||
194 | </div> |
||
195 | <?php |
||
196 | } // end of foreach for draw thumbview folders. |
||
197 | |||
198 | |||
199 | // start of foreach for draw thumbview files. |
||
200 | foreach($list[1] as $entry => $file) |
||
201 | { |
||
202 | $afruimgdimensions=$manager->checkImageSize($file['relative']); |
||
203 | $thisFileNameLength = $maxFileNameLength; |
||
204 | ?> |
||
205 | <div class="thumb_holder" id="holder_<?php echo asc2hex($entry) ?>"> |
||
206 | <a href="#" class="thumb" style="cursor: pointer;" ondblclick="this.onclick();window.top.onOK();" onclick="selectImage('<?php echo $file['relative'];?>', '<?php echo preg_replace('#\..{3,4}$#', '', $entry); ?>', <?php echo $file['image'][0];?>, <?php echo $file['image'][1]; ?>);return false;" title="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>"> |
||
207 | <img src="<?php print $manager->getThumbnail($file['relative']); ?>" alt="<?php echo $entry; ?> - <?php echo Files::formatSize($file['stat']['size']); ?>" /> |
||
208 | </a> |
||
209 | <div class="fileName"> |
||
210 | <?php |
||
211 | if(strlen($entry) > $thisFileNameLength + 3) echo strtolower(substr($entry,0,$thisFileNameLength))."..."; else echo $entry; |
||
212 | ?> |
||
213 | </div> |
||
214 | <div class="edit"> |
||
215 | View Code Duplication | <?php if($IMConfig['img_library'] && $IMConfig['allow_edit_image'] && $file['image'][0] > 0 ) |
|
216 | { ?> |
||
217 | <a href="javascript:;" title="Edit" onclick="editImage('<?php echo rawurlencode($file['relative']);?>');"><img src="<?php print $IMConfig['base_url'];?>img/edit_pencil.gif" height="15" width="15" alt="Edit" /></a> |
||
218 | <?php $thisFileNameLength -= 3; } ?> |
||
219 | <?php |
||
220 | View Code Duplication | if($IMConfig['allow_delete']) |
|
221 | { |
||
222 | ?> |
||
223 | <a href="<?php print $backend_url_enc; ?>__function=images&mode=<?php echo $insertMode;?>&dir=<?php echo $relative; ?>&delf=<?php echo rawurlencode($file['relative']);?>&viewtype=<?php echo $afruViewType; ?>" title="Trash" onclick="return confirmDeleteFile('<?php echo $entry; ?>');"><img src="<?php print $IMConfig['base_url'];?>img/edit_trash.gif" height="15" width="15" alt="Trash" /></a> |
||
224 | <?php |
||
225 | } |
||
226 | ?> |
||
227 | <?php if ($IMConfig['allow_rename']) { ?> |
||
228 | <a href="#" title="Rename" onclick="renameFile('<?php echo rawurlencode($file['relative']);?>'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_rename.gif" height="15" width="15" alt="Rename" /></a> |
||
229 | <?php $thisFileNameLength -= 3; } ?> |
||
230 | View Code Duplication | <?php if ($IMConfig['allow_cut_copy_paste']) { ?> |
|
231 | <a href="#" title="Cut" onclick="copyFile('<?php echo rawurlencode($entry);?>','move'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_cut.gif" height="15" width="15" alt="Cut" /></a> |
||
232 | <a href="#" title="Copy" onclick="copyFile('<?php echo rawurlencode($entry);?>','copy'); return false;"><img src="<?php print $IMConfig['base_url'];?>img/edit_copy.gif" height="15" width="15" alt="Copy" /></a> |
||
233 | <?php $thisFileNameLength -= 6; } ?> |
||
234 | |||
235 | </div> |
||
236 | </div> |
||
237 | <?php |
||
238 | }//end of foreach of draw thumbview files |
||
239 | |||
240 | } |
||
241 | }//end of function drawDirs_Files |
||
242 | |||
421 |
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.