Conditions | 34 |
Paths | 1204 |
Total Lines | 86 |
Code Lines | 42 |
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 |
||
119 | public static function map($template_set=null) |
||
120 | { |
||
121 | if (is_null($template_set)) |
||
122 | { |
||
123 | $template_set = $GLOBALS['egw_info']['server']['template_set']; |
||
124 | } |
||
125 | |||
126 | $cache_name = 'image_map_'.$template_set.'_svg'.(Header\UserAgent::mobile() ? '_mobile' : ''); |
||
127 | if (($map = Cache::getInstance(__CLASS__, $cache_name))) |
||
128 | { |
||
129 | return $map; |
||
130 | } |
||
131 | //$starttime = microtime(true); |
||
132 | |||
133 | // priority: : SVG->PNG->JPG->GIF->ICO |
||
134 | $img_types = array('svg','png','jpg','gif','ico'); |
||
135 | |||
136 | $map = array(); |
||
137 | foreach(scandir(EGW_SERVER_ROOT) as $app) |
||
138 | { |
||
139 | if ($app[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app) || !file_exists(EGW_SERVER_ROOT.'/'.$app.'/templates')) continue; |
||
140 | |||
141 | $app_map =& $map[$app]; |
||
142 | if (true) $app_map = array(); |
||
143 | $imagedirs = array(); |
||
144 | if (Header\UserAgent::mobile()) |
||
145 | { |
||
146 | $imagedirs[] = '/'.$app.'/templates/mobile/images'; |
||
147 | } |
||
148 | if ($app == 'api') |
||
149 | { |
||
150 | $imagedirs[] = $GLOBALS['egw']->framework->template_dir.'/images'; |
||
151 | } |
||
152 | else |
||
153 | { |
||
154 | $imagedirs[] = '/'.$app.'/templates/'.$template_set.'/images'; |
||
155 | } |
||
156 | if ($template_set != 'idots') $imagedirs[] = '/'.$app.'/templates/idots/images'; |
||
157 | $imagedirs[] = '/'.$app.'/templates/default/images'; |
||
158 | |||
159 | foreach($imagedirs as $imagedir) |
||
160 | { |
||
161 | if (!file_exists($dir = EGW_SERVER_ROOT.$imagedir) || !is_readable($dir)) continue; |
||
162 | |||
163 | foreach(scandir($dir) as $img) |
||
164 | { |
||
165 | if ($img[0] == '.') continue; |
||
166 | |||
167 | $subdir = null; |
||
168 | foreach(is_dir($dir.'/'.$img) ? scandir($dir.'/'.($subdir=$img)) : (array) $img as $img) |
||
|
|||
169 | { |
||
170 | $name = null; |
||
171 | if (!in_array($ext = self::get_extension($img, $name), $img_types) || empty($name)) continue; |
||
172 | |||
173 | if (isset($subdir)) $name = $subdir.'/'.$name; |
||
174 | |||
175 | if (!isset($app_map[$name]) || array_search($ext, $img_types) < array_search(self::get_extension($app_map[$name]), $img_types)) |
||
176 | { |
||
177 | $app_map[$name] = $imagedir.'/'.$name.'.'.$ext; |
||
178 | } |
||
179 | } |
||
180 | } |
||
181 | } |
||
182 | } |
||
183 | $app_map =& $map['vfs']; |
||
184 | if (true) $app_map = array(); |
||
185 | if (($dir = $GLOBALS['egw_info']['server']['vfs_image_dir']) && Vfs::file_exists($dir) && Vfs::is_readable($dir)) |
||
186 | { |
||
187 | foreach(Vfs::find($dir) as $img) |
||
188 | { |
||
189 | if (!in_array($ext = self::get_extension($img, $name), $img_types) || empty($name)) continue; |
||
190 | |||
191 | if (!isset($app_map[$name]) || array_search($ext, $img_types) < array_search(self::get_extension($app_map[$name]), $img_types)) |
||
192 | { |
||
193 | $app_map[$name] = Vfs::download_url($img); |
||
194 | } |
||
195 | } |
||
196 | } |
||
197 | else if ($dir) |
||
198 | { |
||
199 | return $map; |
||
200 | } |
||
201 | //error_log(__METHOD__."('$template_set') took ".(microtime(true)-$starttime).' secs'); |
||
202 | Cache::setInstance(__CLASS__, $cache_name, $map, 86400); // cache for one day |
||
203 | //echo "<p>template_set=".array2string($template_set)."</p>\n"; _debug_array($map); |
||
204 | return $map; |
||
205 | } |
||
225 |