1<?php 2/** 3 * XOOPS listing utilities 4 * 5 * You may not change or alter any portion of this comment or credits 6 * of supporting developers from this source code or any supporting source code 7 * which is considered copyrighted (c) material of the original comment or credit authors. 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * 12 * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) 13 * @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html) 14 * @package kernel 15 * @since 2.0.0 16 */ 17 18defined('XOOPS_ROOT_PATH') || exit('Restricted access'); 19 20if (!defined('XOOPS_LISTS_INCLUDED')) { 21 define('XOOPS_LISTS_INCLUDED', 1); 22 23 /** 24 * XoopsLists 25 * 26 * @author John Neill <catzwolf@xoops.org> 27 * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) 28 * @package kernel 29 * @subpackage form 30 * @access public 31 */ 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() 96 { 97 return XoopsLists::getDirListAsArray(XOOPS_ROOT_PATH . '/class/xoopseditor/'); 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) 106 { 107 $ignored = array( 108 'cvs', 109 '_darcs'); 110 $list = array(); 111 if (substr($dirname, -1) !== '/') { 112 $dirname .= '/'; 113 } 114 if ($handle = opendir($dirname)) { 115 while ($file = readdir($handle)) { 116 if (substr($file, 0, 1) === '.' || in_array(strtolower($file), $ignored)) { 117 continue; 118 } 119 if (is_dir($dirname . $file)) { 120 $list[$file] = $file; 121 } 122 } 123 closedir($handle); 124 asort($list); 125 reset($list); 126 } 127 128 return $list; 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 = '') 138 { 139 $filelist = array(); 140 if (substr($dirname, -1) === '/') { 141 $dirname = substr($dirname, 0, -1); 142 } 143 if (is_dir($dirname) && $handle = opendir($dirname)) { 144 while (false !== ($file = readdir($handle))) { 145 if (!preg_match('/^[\.]{1,2}$/', $file) && is_file($dirname . '/' . $file)) { 146 $file = $prefix . $file; 147 $filelist[$file] = $file; 148 } 149 } 150 closedir($handle); 151 asort($filelist); 152 reset($filelist); 153 } 154 155 return $filelist; 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() 292 { 293 $lang_list = array(); 294 $lang_list = XoopsLists::getDirListAsArray(XOOPS_ROOT_PATH . '/language/'); 295 296 return $lang_list; 297 } 298 299 /** 300 * XoopsLists::getCountryList() 301 * 302 * @return array 303 */ 304 public static function getCountryList() 305 { 306 xoops_loadLanguage('countries'); 307 $country_list = array( 308 '' => '-', 309 'AD' => _COUNTRY_AD, 310 'AE' => _COUNTRY_AE, 311 'AF' => _COUNTRY_AF, 312 'AG' => _COUNTRY_AG, 313 'AI' => _COUNTRY_AI, 314 'AL' => _COUNTRY_AL, 315 'AM' => _COUNTRY_AM, 316 'AN' => _COUNTRY_AN, 317 'AO' => _COUNTRY_AO, 318 'AQ' => _COUNTRY_AQ, 319 'AR' => _COUNTRY_AR, 320 'AS' => _COUNTRY_AS, 321 'AT' => _COUNTRY_AT, 322 'AU' => _COUNTRY_AU, 323 'AW' => _COUNTRY_AW, 324 'AX' => _COUNTRY_AX, 325 'AZ' => _COUNTRY_AZ, 326 'BA' => _COUNTRY_BA, 327 'BB' => _COUNTRY_BB, 328 'BD' => _COUNTRY_BD, 329 'BE' => _COUNTRY_BE, 330 'BF' => _COUNTRY_BF, 331 'BG' => _COUNTRY_BG, 332 'BH' => _COUNTRY_BH, 333 'BI' => _COUNTRY_BI, 334 'BJ' => _COUNTRY_BJ, 335 'BL' => _COUNTRY_BL, 336 'BM' => _COUNTRY_BM, 337 'BN' => _COUNTRY_BN, 338 'BO' => _COUNTRY_BO, 339 'BR' => _COUNTRY_BR, 340 'BS' => _COUNTRY_BS, 341 'BT' => _COUNTRY_BT, 342 'BV' => _COUNTRY_BV, 343 'BW' => _COUNTRY_BW, 344 'BY' => _COUNTRY_BY, 345 'BZ' => _COUNTRY_BZ, 346 'CA' => _COUNTRY_CA, 347 'CC' => _COUNTRY_CC, 348 'CD' => _COUNTRY_CD, 349 'CF' => _COUNTRY_CF, 350 'CG' => _COUNTRY_CG, 351 'CH' => _COUNTRY_CH, 352 'CI' => _COUNTRY_CI, 353 'CK' => _COUNTRY_CK, 354 'CL' => _COUNTRY_CL, 355 'CM' => _COUNTRY_CM, 356 'CN' => _COUNTRY_CN, 357 'CO' => _COUNTRY_CO, 358 'CR' => _COUNTRY_CR, 359 'CS' => _COUNTRY_CS, // Not listed in ISO 3166, former Serbia & Montenegro 360 'CU' => _COUNTRY_CU, 361 'CV' => _COUNTRY_CV, 362 'CX' => _COUNTRY_CX, 363 'CY' => _COUNTRY_CY, 364 'CZ' => _COUNTRY_CZ, 365 'DE' => _COUNTRY_DE, 366 'DJ' => _COUNTRY_DJ, 367 'DK' => _COUNTRY_DK, 368 'DM' => _COUNTRY_DM, 369 'DO' => _COUNTRY_DO, 370 'DZ' => _COUNTRY_DZ, 371 'EC' => _COUNTRY_EC, 372 'EE' => _COUNTRY_EE, 373 'EG' => _COUNTRY_EG, 374 'EH' => _COUNTRY_EH, 375 'ER' => _COUNTRY_ER, 376 'ES' => _COUNTRY_ES, 377 'ET' => _COUNTRY_ET, 378 'FI' => _COUNTRY_FI, 379 'FJ' => _COUNTRY_FJ, 380 'FK' => _COUNTRY_FK, 381 'FM' => _COUNTRY_FM, 382 'FO' => _COUNTRY_FO, 383 'FR' => _COUNTRY_FR, 384 'FX' => _COUNTRY_FX, // Not listed in ISO 3166 385 'GA' => _COUNTRY_GA, 386 'GB' => _COUNTRY_GB, 387 'GD' => _COUNTRY_GD, 388 'GE' => _COUNTRY_GE, 389 'GF' => _COUNTRY_GF, 390 'GG' => _COUNTRY_GG, 391 'GH' => _COUNTRY_GH, 392 'GI' => _COUNTRY_GI, 393 'GL' => _COUNTRY_GL, 394 'GM' => _COUNTRY_GM, 395 'GN' => _COUNTRY_GN, 396 'GP' => _COUNTRY_GP, 397 'GQ' => _COUNTRY_GQ, 398 'GR' => _COUNTRY_GR, 399 'GS' => _COUNTRY_GS, 400 'GT' => _COUNTRY_GT, 401 'GU' => _COUNTRY_GU, 402 'GW' => _COUNTRY_GW, 403 'GY' => _COUNTRY_GY, 404 'HK' => _COUNTRY_HK, 405 'HM' => _COUNTRY_HM, 406 'HN' => _COUNTRY_HN, 407 'HR' => _COUNTRY_HR, 408 'HT' => _COUNTRY_HT, 409 'HU' => _COUNTRY_HU, 410 'ID' => _COUNTRY_ID, 411 'IE' => _COUNTRY_IE, 412 'IL' => _COUNTRY_IL, 413 'IM' => _COUNTRY_IM, 414 'IN' => _COUNTRY_IN, 415 'IO' => _COUNTRY_IO, 416 'IQ' => _COUNTRY_IQ, 417 'IR' => _COUNTRY_IR, 418 'IS' => _COUNTRY_IS, 419 'IT' => _COUNTRY_IT, 420 'JM' => _COUNTRY_JM, 421 'JO' => _COUNTRY_JO, 422 'JP' => _COUNTRY_JP, 423 'KE' => _COUNTRY_KE, 424 'KG' => _COUNTRY_KG, 425 'KH' => _COUNTRY_KH, 426 'KI' => _COUNTRY_KI, 427 'KM' => _COUNTRY_KM, 428 'KN' => _COUNTRY_KN, 429 'KP' => _COUNTRY_KP, 430 'KR' => _COUNTRY_KR, 431 'KW' => _COUNTRY_KW, 432 'KY' => _COUNTRY_KY, 433 'KZ' => _COUNTRY_KZ, 434 'LA' => _COUNTRY_LA, 435 'LB' => _COUNTRY_LB, 436 'LC' => _COUNTRY_LC, 437 'LI' => _COUNTRY_LI, 438 'LK' => _COUNTRY_LK, 439 'LR' => _COUNTRY_LR, 440 'LS' => _COUNTRY_LS, 441 'LT' => _COUNTRY_LT, 442 'LU' => _COUNTRY_LU, 443 'LV' => _COUNTRY_LV, 444 'LY' => _COUNTRY_LY, 445 'MA' => _COUNTRY_MA, 446 'MC' => _COUNTRY_MC, 447 'MD' => _COUNTRY_MD, 448 'ME' => _COUNTRY_ME, 449 'MF' => _COUNTRY_MF, 450 'MG' => _COUNTRY_MG, 451 'MH' => _COUNTRY_MH, 452 'MK' => _COUNTRY_MK, 453 'ML' => _COUNTRY_ML, 454 'MM' => _COUNTRY_MM, 455 'MN' => _COUNTRY_MN, 456 'MO' => _COUNTRY_MO, 457 'MP' => _COUNTRY_MP, 458 'MQ' => _COUNTRY_MQ, 459 'MR' => _COUNTRY_MR, 460 'MS' => _COUNTRY_MS, 461 'MT' => _COUNTRY_MT, 462 'MU' => _COUNTRY_MU, 463 'MV' => _COUNTRY_MV, 464 'MW' => _COUNTRY_MW, 465 'MX' => _COUNTRY_MX, 466 'MY' => _COUNTRY_MY, 467 'MZ' => _COUNTRY_MZ, 468 'NA' => _COUNTRY_NA, 469 'NC' => _COUNTRY_NC, 470 'NE' => _COUNTRY_NE, 471 'NF' => _COUNTRY_NF, 472 'NG' => _COUNTRY_NG, 473 'NI' => _COUNTRY_NI, 474 'NL' => _COUNTRY_NL, 475 'NO' => _COUNTRY_NO, 476 'NP' => _COUNTRY_NP, 477 'NR' => _COUNTRY_NR, 478 'NT' => _COUNTRY_NT, // Not listed in ISO 3166 479 'NU' => _COUNTRY_NU, 480 'NZ' => _COUNTRY_NZ, 481 'OM' => _COUNTRY_OM, 482 'PA' => _COUNTRY_PA, 483 'PE' => _COUNTRY_PE, 484 'PF' => _COUNTRY_PF, 485 'PG' => _COUNTRY_PG, 486 'PH' => _COUNTRY_PH, 487 'PK' => _COUNTRY_PK, 488 'PL' => _COUNTRY_PL, 489 'PM' => _COUNTRY_PM, 490 'PN' => _COUNTRY_PN, 491 'PR' => _COUNTRY_PR, 492 'PS' => _COUNTRY_PS, 493 'PT' => _COUNTRY_PT, 494 'PW' => _COUNTRY_PW, 495 'PY' => _COUNTRY_PY, 496 'QA' => _COUNTRY_QA, 497 'RE' => _COUNTRY_RE, 498 'RO' => _COUNTRY_RO, 499 'RS' => _COUNTRY_RS, 500 'RU' => _COUNTRY_RU, 501 'RW' => _COUNTRY_RW, 502 'SA' => _COUNTRY_SA, 503 'SB' => _COUNTRY_SB, 504 'SC' => _COUNTRY_SC, 505 'SD' => _COUNTRY_SD, 506 'SE' => _COUNTRY_SE, 507 'SG' => _COUNTRY_SG, 508 'SH' => _COUNTRY_SH, 509 'SI' => _COUNTRY_SI, 510 'SJ' => _COUNTRY_SJ, 511 'SK' => _COUNTRY_SK, 512 'SL' => _COUNTRY_SL, 513 'SM' => _COUNTRY_SM, 514 'SN' => _COUNTRY_SN, 515 'SO' => _COUNTRY_SO, 516 'SR' => _COUNTRY_SR, 517 'ST' => _COUNTRY_ST, 518 'SU' => _COUNTRY_SU, // Not listed in ISO 3166 519 'SV' => _COUNTRY_SV, 520 'SY' => _COUNTRY_SY, 521 'SZ' => _COUNTRY_SZ, 522 'TC' => _COUNTRY_TC, 523 'TD' => _COUNTRY_TD, 524 'TF' => _COUNTRY_TF, 525 'TG' => _COUNTRY_TG, 526 'TH' => _COUNTRY_TH, 527 'TJ' => _COUNTRY_TJ, 528 'TK' => _COUNTRY_TK, 529 'TL' => _COUNTRY_TL, 530 'TM' => _COUNTRY_TM, 531 'TN' => _COUNTRY_TN, 532 'TO' => _COUNTRY_TO, 533 'TP' => _COUNTRY_TP, // Not listed in ISO 3166, has changed to TL 534 'TR' => _COUNTRY_TR, 535 'TT' => _COUNTRY_TT, 536 'TV' => _COUNTRY_TV, 537 'TW' => _COUNTRY_TW, 538 'TZ' => _COUNTRY_TZ, 539 'UA' => _COUNTRY_UA, 540 'UG' => _COUNTRY_UG, 541 //"UK" => _COUNTRY_UK, // Not listed in ISO 3166 542 'UM' => _COUNTRY_UM, 543 'US' => _COUNTRY_US, 544 'UY' => _COUNTRY_UY, 545 'UZ' => _COUNTRY_UZ, 546 'VA' => _COUNTRY_VA, 547 'VC' => _COUNTRY_VC, 548 'VE' => _COUNTRY_VE, 549 'VG' => _COUNTRY_VG, 550 'VI' => _COUNTRY_VI, 551 'VN' => _COUNTRY_VN, 552 'VU' => _COUNTRY_VU, 553 'WF' => _COUNTRY_WF, 554 'WS' => _COUNTRY_WS, 555 'YE' => _COUNTRY_YE, 556 'YT' => _COUNTRY_YT, 557 'YU' => _COUNTRY_YU, // Not listed in ISO 3166, former Yugoslavia 558 'ZA' => _COUNTRY_ZA, 559 'ZM' => _COUNTRY_ZM, 560 'ZR' => _COUNTRY_ZR, // Not listed in ISO 3166 561 'ZW' => _COUNTRY_ZW); 562 asort($country_list); 563 reset($country_list); 564 565 return $country_list; 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() 648 { 649 $db = XoopsDatabaseFactory::getDatabaseConnection(); 650 $myts = MyTextSanitizer::getInstance(); 651 $sql = sprintf('SELECT rank_id, rank_title FROM ' . $db->prefix('ranks') . ' WHERE rank_special = %u', 1); 652 $ret = array(); 653 $result = $db->query($sql); 654 while (false !== ($myrow = $db->fetchArray($result))) { 655 $ret[$myrow['rank_id']] = $myts->htmlSpecialChars($myrow['rank_title']); 656 } 657 658 return $ret; 659 } 660 } 661} 662