| Total Complexity | 40 |
| Total Lines | 627 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like XoopsLists often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use XoopsLists, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | class XoopsLists |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * @return array |
||
| 36 | */ |
||
| 37 | public static function getTimeZoneList() |
||
| 38 | { |
||
| 39 | xoops_loadLanguage('timezone'); |
||
| 40 | |||
| 41 | $time_zone_list = array( |
||
| 42 | '-12' => _TZ_GMTM12, |
||
| 43 | '-11' => _TZ_GMTM11, |
||
| 44 | '-10' => _TZ_GMTM10, |
||
| 45 | '-9' => _TZ_GMTM9, |
||
| 46 | '-8' => _TZ_GMTM8, |
||
| 47 | '-7' => _TZ_GMTM7, |
||
| 48 | '-6' => _TZ_GMTM6, |
||
| 49 | '-5' => _TZ_GMTM5, |
||
| 50 | '-4' => _TZ_GMTM4, |
||
| 51 | '-3.5' => _TZ_GMTM35, |
||
| 52 | '-3' => _TZ_GMTM3, |
||
| 53 | '-2' => _TZ_GMTM2, |
||
| 54 | '-1' => _TZ_GMTM1, |
||
| 55 | '0' => _TZ_GMT0, |
||
| 56 | '1' => _TZ_GMTP1, |
||
| 57 | '2' => _TZ_GMTP2, |
||
| 58 | '3' => _TZ_GMTP3, |
||
| 59 | '3.5' => _TZ_GMTP35, |
||
| 60 | '4' => _TZ_GMTP4, |
||
| 61 | '4.5' => _TZ_GMTP45, |
||
| 62 | '5' => _TZ_GMTP5, |
||
| 63 | '5.5' => _TZ_GMTP55, |
||
| 64 | '6' => _TZ_GMTP6, |
||
| 65 | '7' => _TZ_GMTP7, |
||
| 66 | '8' => _TZ_GMTP8, |
||
| 67 | '9' => _TZ_GMTP9, |
||
| 68 | '9.5' => _TZ_GMTP95, |
||
| 69 | '10' => _TZ_GMTP10, |
||
| 70 | '11' => _TZ_GMTP11, |
||
| 71 | '12' => _TZ_GMTP12); |
||
| 72 | |||
| 73 | return $time_zone_list; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * gets list of themes folder from themes directory |
||
| 78 | */ |
||
| 79 | public static function getThemesList() |
||
| 80 | { |
||
| 81 | return XoopsLists::getDirListAsArray(XOOPS_THEME_PATH . '/'); |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * gets a list of module folders from the modules directory |
||
| 86 | */ |
||
| 87 | public static function getModulesList() |
||
| 88 | { |
||
| 89 | return XoopsLists::getDirListAsArray(XOOPS_ROOT_PATH . '/modules/'); |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * gets list of editors folder from xoopseditor directory |
||
| 94 | */ |
||
| 95 | public static function getEditorList() |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * gets list of name of directories inside a directory |
||
| 102 | * @param $dirname |
||
| 103 | * @return array |
||
| 104 | */ |
||
| 105 | public static function getDirListAsArray($dirname) |
||
| 129 | } |
||
| 130 | |||
| 131 | /** |
||
| 132 | * gets list of all files in a directory |
||
| 133 | * @param $dirname |
||
| 134 | * @param string $prefix |
||
| 135 | * @return array |
||
| 136 | */ |
||
| 137 | public static function getFileListAsArray($dirname, $prefix = '') |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * get list of files in a directory matching a list of extensions |
||
| 160 | * |
||
| 161 | * @param string $dirname file system directory to process |
||
| 162 | * @param string[] $extensions list of extensions to select |
||
| 163 | * @param string $prefix prefix sny matching files returned with this string |
||
| 164 | * |
||
| 165 | * @return string[] |
||
| 166 | */ |
||
| 167 | public static function getFileListByExtension($dirname, $extensions, $prefix = '') |
||
| 168 | { |
||
| 169 | $filelist = array(); |
||
| 170 | |||
| 171 | $extToLower = function($ext) { |
||
| 172 | return strtolower($ext); |
||
| 173 | }; |
||
| 174 | |||
| 175 | $extensionList = array_map($extToLower, $extensions); |
||
| 176 | |||
| 177 | if ($handle = opendir($dirname)) { |
||
| 178 | while (false !== ($file = readdir($handle))) { |
||
| 179 | $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); |
||
| 180 | if (in_array(strtolower($ext), $extensionList)) { |
||
| 181 | $file = $prefix . $file; |
||
| 182 | $filelist[$file] = $file; |
||
| 183 | } |
||
| 184 | } |
||
| 185 | closedir($handle); |
||
| 186 | asort($filelist); |
||
| 187 | reset($filelist); |
||
| 188 | } |
||
| 189 | |||
| 190 | return $filelist; |
||
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Get a list of image file names in a directory. |
||
| 195 | * This selects only the most common file extensions for web use, |
||
| 196 | * gif, jpeg/jpg, and png |
||
| 197 | * |
||
| 198 | * @param string $dirname file system directory to process |
||
| 199 | * @param string $prefix prefix sny matching files returned with this string |
||
| 200 | * |
||
| 201 | * @return string[] |
||
| 202 | */ |
||
| 203 | public static function getImgListAsArray($dirname, $prefix = '') |
||
| 204 | { |
||
| 205 | $extensions = array('gif','jpeg','jpg','png'); |
||
| 206 | return static::getFileListByExtension($dirname, $extensions, $prefix); |
||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * gets list of html file names in a certain directory |
||
| 211 | * @param $dirname |
||
| 212 | * @param string $prefix |
||
| 213 | * @return array |
||
| 214 | */ |
||
| 215 | public static function getHtmlListAsArray($dirname, $prefix = '') |
||
| 216 | { |
||
| 217 | $filelist = array(); |
||
| 218 | if ($handle = opendir($dirname)) { |
||
| 219 | while (false !== ($file = readdir($handle))) { |
||
| 220 | if (preg_match('/(\.htm|\.html|\.xhtml|\.tpl)$/i', $file) && !is_dir($file)) { |
||
| 221 | $file = $prefix . $file; |
||
| 222 | $filelist[$file] = $prefix . $file; |
||
| 223 | } |
||
| 224 | } |
||
| 225 | closedir($handle); |
||
| 226 | asort($filelist); |
||
| 227 | reset($filelist); |
||
| 228 | } |
||
| 229 | |||
| 230 | return $filelist; |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * gets list of avatar file names in a certain directory |
||
| 235 | * if directory is not specified, default directory will be searched |
||
| 236 | * @param string $avatar_dir |
||
| 237 | * @return array |
||
| 238 | */ |
||
| 239 | public static function getAvatarsList($avatar_dir = '') |
||
| 240 | { |
||
| 241 | $avatars = array(); |
||
| 242 | if ($avatar_dir != '') { |
||
| 243 | $avatars = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . '/images/avatar/' . $avatar_dir . '/', $avatar_dir . '/'); |
||
| 244 | } else { |
||
| 245 | $avatars = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . '/images/avatar/'); |
||
| 246 | } |
||
| 247 | |||
| 248 | return $avatars; |
||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | * gets list of all avatar image files inside default avatars directory |
||
| 253 | */ |
||
| 254 | public static function getAllAvatarsList() |
||
| 255 | { |
||
| 256 | $avatars = array(); |
||
| 257 | $dirlist = array(); |
||
|
|
|||
| 258 | $dirlist = XoopsLists::getDirListAsArray(XOOPS_ROOT_PATH . '/images/avatar/'); |
||
| 259 | if (count($dirlist) > 0) { |
||
| 260 | foreach ($dirlist as $dir) { |
||
| 261 | $avatars[$dir] = &XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . '/images/avatar/' . $dir . '/', $dir . '/'); |
||
| 262 | } |
||
| 263 | } else { |
||
| 264 | return false; |
||
| 265 | } |
||
| 266 | |||
| 267 | return $avatars; |
||
| 268 | } |
||
| 269 | |||
| 270 | /** |
||
| 271 | * gets list of subject icon image file names in a certain directory |
||
| 272 | * if directory is not specified, default directory will be searched |
||
| 273 | * @param string $sub_dir |
||
| 274 | * @return array |
||
| 275 | */ |
||
| 276 | public static function getSubjectsList($sub_dir = '') |
||
| 277 | { |
||
| 278 | $subjects = array(); |
||
| 279 | if ($sub_dir != '') { |
||
| 280 | $subjects = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . '/images/subject/' . $sub_dir, $sub_dir . '/'); |
||
| 281 | } else { |
||
| 282 | $subjects = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . '/images/subject/'); |
||
| 283 | } |
||
| 284 | |||
| 285 | return $subjects; |
||
| 286 | } |
||
| 287 | |||
| 288 | /** |
||
| 289 | * gets list of language folders inside default language directory |
||
| 290 | */ |
||
| 291 | public static function getLangList() |
||
| 297 | } |
||
| 298 | |||
| 299 | /** |
||
| 300 | * XoopsLists::getCountryList() |
||
| 301 | * |
||
| 302 | * @return array |
||
| 303 | */ |
||
| 304 | public static function getCountryList() |
||
| 566 | } |
||
| 567 | |||
| 568 | /** |
||
| 569 | * XoopsLists::getHtmlList() |
||
| 570 | * |
||
| 571 | * This Function is no longer being used by the core |
||
| 572 | * |
||
| 573 | * @return array |
||
| 574 | */ |
||
| 575 | public static function getHtmlList() |
||
| 576 | { |
||
| 577 | $html_list = array( |
||
| 578 | 'a' => '<a>', |
||
| 579 | 'abbr' => '<abbr>', |
||
| 580 | 'acronym' => '<acronym>', |
||
| 581 | 'address' => '<address>', |
||
| 582 | 'b' => '<b>', |
||
| 583 | 'bdo' => '<bdo>', |
||
| 584 | 'big' => '<big>', |
||
| 585 | 'blockquote' => '<blockquote>', |
||
| 586 | 'br' => '<br>', |
||
| 587 | 'caption' => '<caption>', |
||
| 588 | 'cite' => '<cite>', |
||
| 589 | 'code' => '<code>', |
||
| 590 | 'col' => '<col>', |
||
| 591 | 'colgroup' => '<colgroup>', |
||
| 592 | 'dd' => '<dd>', |
||
| 593 | 'del' => '<del>', |
||
| 594 | 'dfn' => '<dfn>', |
||
| 595 | 'div' => '<div>', |
||
| 596 | 'dl' => '<dl>', |
||
| 597 | 'dt' => '<dt>', |
||
| 598 | 'em' => '<em>', |
||
| 599 | 'font' => '<font>', |
||
| 600 | 'h1' => '<h1>', |
||
| 601 | 'h2' => '<h2>', |
||
| 602 | 'h3' => '<h3>', |
||
| 603 | 'h4' => '<h4>', |
||
| 604 | 'h5' => '<h5>', |
||
| 605 | 'h6' => '<h6>', |
||
| 606 | 'hr' => '<hr>', |
||
| 607 | 'i' => '<i>', |
||
| 608 | 'img' => '<img>', |
||
| 609 | 'ins' => '<ins>', |
||
| 610 | 'kbd' => '<kbd>', |
||
| 611 | 'li' => '<li>', |
||
| 612 | 'map' => '<map>', |
||
| 613 | 'object' => '<object>', |
||
| 614 | 'ol' => '<ol>', |
||
| 615 | 'p' => '<p>', |
||
| 616 | 'pre' => '<pre>', |
||
| 617 | 's' => '<s>', |
||
| 618 | 'samp' => '<samp>', |
||
| 619 | 'small' => '<small>', |
||
| 620 | 'span' => '<span>', |
||
| 621 | 'strike' => '<strike>', |
||
| 622 | 'strong' => '<strong>', |
||
| 623 | 'sub' => '<sub>', |
||
| 624 | 'sup' => '<sup>', |
||
| 625 | 'table' => '<table>', |
||
| 626 | 'tbody' => '<tbody>', |
||
| 627 | 'td' => '<td>', |
||
| 628 | 'tfoot' => '<tfoot>', |
||
| 629 | 'th' => '<th>', |
||
| 630 | 'thead' => '<thead>', |
||
| 631 | 'tr' => '<tr>', |
||
| 632 | 'tt' => '<tt>', |
||
| 633 | 'u' => '<u>', |
||
| 634 | 'ul' => '<ul>', |
||
| 635 | 'var' => '<var>'); |
||
| 636 | asort($html_list); |
||
| 637 | reset($html_list); |
||
| 638 | |||
| 639 | return $html_list; |
||
| 640 | } |
||
| 641 | |||
| 642 | /** |
||
| 643 | * XoopsLists::getUserRankList() |
||
| 644 | * |
||
| 645 | * @return array |
||
| 646 | */ |
||
| 647 | public static function getUserRankList() |
||
| 659 | } |
||
| 660 | } |
||
| 661 | } |
||
| 662 |