PHP 公共方法分享180628
查看php 类的详情:方法、常量、属性( type(new \Illuminate\Http\Request());)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | /** * fixme 打印类详情 * @param $class object 对象 */ function type( $class ){ $ref = new \ReflectionClass( $class ); $br = '<br>' ; $consts = $ref ->getConstants(); //返回所有常量名和值 echo "----------------consts:---------------" . $br ; foreach ( $consts as $key => $val ) { echo "$key : $val" . $br ; } $props = $ref ->getDefaultProperties(); //返回类中所有属性与值类型 echo "--------------------props:--------------" . $br . $br ; foreach ( $props as $key => $val ) { echo "$key ::" . gettype ( $val ) . $br ; // 属性名和属性值 } $methods = $ref ->getMethods(); //返回类中所有方法与参数 echo "-----------------methods:---------------" . $br . $br ; foreach ( $methods as $method ) { $getParam = $method ->getParameters(); if (! count ( $getParam )) echo $method ->getName(); foreach ( $getParam as $key => $value ){ echo $method ->getName() . "::" . $value . ' + ' ; } echo $br ; } } |
core.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 | /** * 产生验证码 * * @param string $nchash 哈希数 * @return string */ function makeSeccode( $nchash ){ $seccode = random(6, 1); $seccodeunits = '' ; $s = sprintf( '%04s' , base_convert ( $seccode , 10, 23)); $seccodeunits = 'ABCEFGHJKMPRTVXY2346789' ; if ( $seccodeunits ) { $seccode = '' ; for ( $i = 0; $i < 4; $i ++) { $unit = ord( $s { $i }); $seccode .= ( $unit >= 0x30 && $unit <= 0x39) ? $seccodeunits [ $unit - 0x30] : $seccodeunits [ $unit - 0x57]; } } setNcCookie( 'seccode' . $nchash , encrypt( strtoupper ( $seccode ). "\t" .(time()). "\t" . $nchash ,MD5_KEY),3600); return $seccode ; } function getFlexigridArray( $in_array , $fields_array , $data , $format_array ) //多频道 { $out_array = $in_array ; if ( $out_array [ "operation" ]) { $out_array [ "operation" ] = "--" ; } if ( $fields_array && is_array ( $fields_array )) { foreach ( $fields_array as $key => $value ) { $k = "" ; if ( is_int ( $key )) { $k = $value ; } else { $k = $key ; } if ( is_array ( $data ) && array_key_exists ( $k , $data )) { $out_array [ $k ] = $data [ $k ]; if ( $format_array && in_array( $k , $format_array )) { $out_array [ $k ] = ncpriceformatb( $data [ $k ]); } } else { $out_array [ $k ] = "--" ; } } } return $out_array ; } function ncPriceFormatb( $price ) //多频道 { return number_format( $price , 2, "." , "" ); } /** * 验证验证码 * * @param string $nchash 哈希数 * @param string $value 待验证值 * @return boolean */ function checkSeccode( $nchash , $value ){ list( $checkvalue , $checktime , $checkidhash ) = explode ( "\t" , decrypt(cookie( 'seccode' . $nchash ),MD5_KEY)); $return = $checkvalue == strtoupper ( $value ) && $checkidhash == $nchash ; if (! $return ) setNcCookie( 'seccode' . $nchash , '' ,-3600); return $return ; } /** * 设置cookie QQ wap 登录 by 33h ao.co m * * @param string $name cookie 的名称 * @param string $value cookie 的值 * @param int $expire cookie 有效周期 * @param string $path cookie 的服务器路径 默认为 / * @param string $domain cookie 的域名 * @param string $secure 是否通过安全的 HTTPS 连接来传输 cookie,默认为false */ function setNc2Cookie( $name , $value , $expire = '3600' , $path = '' , $domain = '' , $secure =false){ if ( empty ( $path )) $path = '/' ; if ( empty ( $domain )) $domain = SUBDOMAIN_SUFFIX ? SUBDOMAIN_SUFFIX : '' ; $expire = intval ( $expire )? intval ( $expire ):( intval (SESSION_EXPIRE)? intval (SESSION_EXPIRE):3600); $result = setcookie( $name , $value , time()+ $expire , $path , $domain , $secure ); $_COOKIE [ $name ] = $value ; } /** * 设置cookie * * @param string $name cookie 的名称 * @param string $value cookie 的值 * @param int $expire cookie 有效周期 * @param string $path cookie 的服务器路径 默认为 / * @param string $domain cookie 的域名 * @param string $secure 是否通过安全的 HTTPS 连接来传输 cookie,默认为false */ function setNcCookie( $name , $value , $expire = '3600' , $path = '' , $domain = '' , $secure =false){ if ( empty ( $path )) $path = '/' ; if ( empty ( $domain )) $domain = SUBDOMAIN_SUFFIX ? SUBDOMAIN_SUFFIX : '' ; $name = defined( 'COOKIE_PRE' ) ? COOKIE_PRE. $name : strtoupper ( substr (md5(MD5_KEY),0,4)). '_' . $name ; $expire = intval ( $expire )? intval ( $expire ):( intval (SESSION_EXPIRE)? intval (SESSION_EXPIRE):3600); $result = setcookie( $name , $value , time()+ $expire , $path , $domain , $secure ); $_COOKIE [ $name ] = $value ; } /** * 取得COOKIE的值 * * @param string $name * @return unknown */ function cookie( $name = '' ){ $name = defined( 'COOKIE_PRE' ) ? COOKIE_PRE. $name : strtoupper ( substr (md5(MD5_KEY),0,4)). '_' . $name ; return $_COOKIE [ $name ]; } /** * 当访问的act或op不存在时调用此函数并退出脚本 * * @param string $act * @param string $op * @return void */ function requestNotFound( $act = null, $op = null) { showMessage( '您访问的页面不存在!' , SHOP_SITE_URL, 'exception' , 'error' , 1, 3000); exit ; } /** * 输出信息 * * @param string $msg 输出信息 * @param string/array $url 跳转地址 当$url为数组时,结构为 array('msg'=>'跳转连接文字','url'=>'跳转连接'); * @param string $show_type 输出格式 默认为html * @param string $msg_type 信息类型 succ 为成功,error为失败/错误 * @param string $is_show 是否显示跳转链接,默认是为1,显示 * @param int $time 跳转时间,默认为2秒 * @return string 字符串类型的返回结果 */ function showMessage( $msg , $url = '' , $show_type = 'html' , $msg_type = 'succ' , $is_show =1, $time =2000){ if (! class_exists ( 'Language' )) import( 'libraries.language' ); Language::read( 'core_lang_index' ); $lang = Language::getLangContent(); /** * 如果默认为空,则跳转至上一步链接 */ $url = ( $url != '' ? $url : getReferer()); $msg_type = in_array( $msg_type , array ( 'succ' , 'error' )) ? $msg_type : 'error' ; /** * 输出类型 */ switch ( $show_type ){ case 'json' : $return = '{' ; $return .= '"msg":"' . $msg . '",' ; $return .= '"url":"' . $url . '"' ; $return .= '}' ; echo $return ; break ; case 'exception' : echo '<!DOCTYPE html>' ; echo '<html>' ; echo '<head>' ; echo '<meta http-equiv="Content-Type" content="text/html; charset=' .CHARSET. '" />' ; echo '<title></title>' ; echo '<style type="text/css">' ; echo 'body { font-family: "Verdana";padding: 0; margin: 0;}' ; echo 'h2 { font-size: 12px; line-height: 30px; border-bottom: 1px dashed #CCC; padding-bottom: 8px;width:800px; margin: 20px 0 0 150px;}' ; echo 'dl { float: left; display: inline; clear: both; padding: 0; margin: 10px 20px 20px 150px;}' ; echo 'dt { font-size: 14px; font-weight: bold; line-height: 40px; color: #333; padding: 0; margin: 0; border-width: 0px;}' ; echo 'dd { font-size: 12px; line-height: 40px; color: #333; padding: 0px; margin:0;}' ; echo '</style>' ; echo '</head>' ; echo '<body>' ; echo '<h2>' . $lang [ 'error_info' ]. '</h2>' ; echo '<dl>' ; echo '<dd>' . $msg . '</dd>' ; echo '<dt><p /></dt>' ; echo '<dd>' . $lang [ 'error_notice_operate' ]. '</dd>' ; echo '<dd><p /><p /><p /><p /></dd>' ; echo '<dd><p /><p /><p /><p /></dd>' ; echo '</dl>' ; echo '</body>' ; echo '</html>' ; exit ; break ; case 'javascript' : echo "<script>" ; echo "alert('" . $msg . "');" ; echo "location.href='" . $url . "'" ; echo "</script>" ; exit ; break ; case 'tenpay' : echo "<html><head>" ; echo "<meta name=\"TENCENT_ONLINE_PAYMENT\" content=\"China TENCENT\">" ; echo "<script language=\"javascript\">" ; echo "window.location.href='" . $url . "';" ; echo "</script>" ; echo "</head><body></body></html>" ; exit ; break ; default : /** * 不显示右侧工具条 */ Tpl::output( 'hidden_nctoolbar' , 1); if ( is_array ( $url )){ foreach ( $url as $k => $v ){ $url [ $k ][ 'url' ] = $v [ 'url' ]? $v [ 'url' ]:getReferer(); } } /** * 读取信息布局的语言包 */ Language::read( "msg" ); /** * html输出形式 * 指定为指定项目目录下的error模板文件 */ Tpl::setDir( '' ); Tpl::output( 'html_title' ,Language::get( 'nc_html_title' )); Tpl::output( 'msg' , $msg ); Tpl::output( 'url' , $url ); Tpl::output( 'msg_type' , $msg_type ); Tpl::output( 'is_show' , $is_show ); Tpl::showpage( 'msg' , 'msg_layout' , $time ); } exit ; } /** * 消息提示,主要适用于普通页面AJAX提交的情况 * * @param string $message 消息内容 * @param string $url 提示完后的URL去向 * @param stting $alert_type 提示类型 error/succ/notice 分别为错误/成功/警示 * @param string $extrajs 扩展JS * @param int $time 停留时间 */ function showDialog( $message = '' , $url = '' , $alert_type = 'error' , $extrajs = '' , $time = 2){ if ( empty ( $_GET [ 'inajax' ])){ if ( $url == 'reload' ) $url = '' ; showMessage( $message . $extrajs , $url , 'html' , $alert_type ,1, $time *1000); } $message = str_replace ( "'" , "\\'" , strip_tags ( $message )); $paramjs = null; if ( $url == 'reload' ){ $paramjs = 'window.location.reload()' ; } elseif ( $url != '' ){ $paramjs = 'window.location.href =\'' . $url . '\'' ; } if ( $paramjs ){ $paramjs = 'function (){' . $paramjs . '}' ; } else { $paramjs = 'null' ; } $modes = array ( 'error' => 'alert' , 'succ' => 'succ' , 'notice' => 'notice' , 'js' => 'js' ); $cover = $alert_type == 'error' ? 1 : 0; $extra .= 'showDialog(\'' . $message . '\', \'' . $modes [ $alert_type ]. '\', null, ' .( $paramjs ? $paramjs : 'null' ). ', ' . $cover . ', null, null, null, null, ' .( is_numeric ( $time ) ? $time : 'null' ). ', null);' ; $extra = $extra ? '<script type="text/javascript" reload="1">' . $extra . '</script>' : '' ; if ( $extrajs != '' && substr (trim( $extrajs ),0,7) != '<script' ){ $extrajs = '<script type="text/javascript" reload="1">' . $extrajs . '</script>' ; } $extra .= $extrajs ; ob_end_clean(); @header( "Expires: -1" ); @header( "Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0" , FALSE); @header( "Pragma: no-cache" ); @header( "Content-type: text/xml; charset=" .CHARSET); $string = '<?xml version="1.0" encoding="' .CHARSET. '"?>' . "\r\n" ; $string .= '<root><![CDATA[' . $message . $extra . ']]></root>' ; echo $string ; exit ; } /** * 不显示信息直接跳转 * * @param string $url */ function redirect( $url = '' ){ if ( empty ( $url )){ if (! empty ( $_REQUEST [ 'ref_url' ])){ $url = $_REQUEST [ 'ref_url' ]; } else { $url = getReferer(); } } header( 'Location: ' . $url ); exit (); } /** * 取上一步来源地址 * * @param * @return string 字符串类型的返回结果 */ function getReferer(){ return empty ( $_SERVER [ 'HTTP_REFERER' ])? '' : $_SERVER [ 'HTTP_REFERER' ]; } /** * 取验证码hash值 * * @param * @return string 字符串类型的返回结果 */ function getNchash( $act = '' , $op = '' ){ $act = $act ? $act : $_GET [ 'act' ]; $op = $op ? $op : $_GET [ 'op' ]; if (C( 'captcha_status_login' )){ return substr (md5(SHOP_SITE_URL. $act . $op ),0,8); } else { return '' ; } } /** * 加密函数 * * @param string $txt 需要加密的字符串 * @param string $key 密钥 * @return string 返回加密结果 */ function encrypt( $txt , $key = '' ){ if ( empty ( $txt )) return $txt ; if ( empty ( $key )) $key = md5(MD5_KEY); $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_." ; $ikey = "-x6g6ZWm2G9g_vr0Bo.pOq3kRIxsZ6rm" ; $nh1 = rand(0,64); $nh2 = rand(0,64); $nh3 = rand(0,64); $ch1 = $chars { $nh1 }; $ch2 = $chars { $nh2 }; $ch3 = $chars { $nh3 }; $nhnum = $nh1 + $nh2 + $nh3 ; $knum = 0; $i = 0; while (isset( $key { $i })) $knum +=ord( $key { $i ++}); $mdKey = substr (md5(md5(md5( $key . $ch1 ). $ch2 . $ikey ). $ch3 ), $nhnum %8, $knum %8 + 16); $txt = base64_encode (time(). '_' . $txt ); $txt = str_replace ( array ( '+' , '/' , '=' ), array ( '-' , '_' , '.' ), $txt ); $tmp = '' ; $j =0; $k = 0; $tlen = strlen ( $txt ); $klen = strlen ( $mdKey ); for ( $i =0; $i < $tlen ; $i ++) { $k = $k == $klen ? 0 : $k ; $j = ( $nhnum + strpos ( $chars , $txt { $i })+ord( $mdKey { $k ++}))%64; $tmp .= $chars { $j }; } $tmplen = strlen ( $tmp ); $tmp = substr_replace( $tmp , $ch3 , $nh2 % ++ $tmplen ,0); $tmp = substr_replace( $tmp , $ch2 , $nh1 % ++ $tmplen ,0); $tmp = substr_replace( $tmp , $ch1 , $knum % ++ $tmplen ,0); return $tmp ; } /** * 解密函数 * * @param string $txt 需要解密的字符串 * @param string $key 密匙 * @return string 字符串类型的返回结果 */ function decrypt( $txt , $key = '' , $ttl = 0){ if ( empty ( $txt )) return $txt ; if ( empty ( $key )) $key = md5(MD5_KEY); $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_." ; $ikey = "-x6g6ZWm2G9g_vr0Bo.pOq3kRIxsZ6rm" ; $knum = 0; $i = 0; $tlen = @ strlen ( $txt ); while (isset( $key { $i })) $knum +=ord( $key { $i ++}); $ch1 = @ $txt { $knum % $tlen }; $nh1 = strpos ( $chars , $ch1 ); $txt = @substr_replace( $txt , '' , $knum % $tlen --,1); $ch2 = @ $txt { $nh1 % $tlen }; $nh2 = @ strpos ( $chars , $ch2 ); $txt = @substr_replace( $txt , '' , $nh1 % $tlen --,1); $ch3 = @ $txt { $nh2 % $tlen }; $nh3 = @ strpos ( $chars , $ch3 ); $txt = @substr_replace( $txt , '' , $nh2 % $tlen --,1); $nhnum = $nh1 + $nh2 + $nh3 ; $mdKey = substr (md5(md5(md5( $key . $ch1 ). $ch2 . $ikey ). $ch3 ), $nhnum % 8, $knum % 8 + 16); $tmp = '' ; $j =0; $k = 0; $tlen = @ strlen ( $txt ); $klen = @ strlen ( $mdKey ); for ( $i =0; $i < $tlen ; $i ++) { $k = $k == $klen ? 0 : $k ; $j = strpos ( $chars , $txt { $i })- $nhnum - ord( $mdKey { $k ++}); while ( $j <0) $j +=64; $tmp .= $chars { $j }; } $tmp = str_replace ( array ( '-' , '_' , '.' ), array ( '+' , '/' , '=' ), $tmp ); $tmp = trim( base64_decode ( $tmp )); if (preg_match( "/\d{10}_/s" , substr ( $tmp ,0,11))){ if ( $ttl > 0 && (time() - substr ( $tmp ,0,11) > $ttl )){ $tmp = null; } else { $tmp = substr ( $tmp ,11); } } return $tmp ; } /** * 取得IP * * * @return string 字符串类型的返回结果 */ function getIp(){ if (@ $_SERVER [ 'HTTP_CLIENT_IP' ] && $_SERVER [ 'HTTP_CLIENT_IP' ]!= 'unknown' ) { $ip = $_SERVER [ 'HTTP_CLIENT_IP' ]; } elseif (@ $_SERVER [ 'HTTP_X_FORWARDED_FOR' ] && $_SERVER [ 'HTTP_X_FORWARDED_FOR' ]!= 'unknown' ) { $ip = $_SERVER [ 'HTTP_X_FORWARDED_FOR' ]; } else { $ip = $_SERVER [ 'REMOTE_ADDR' ]; } return preg_match( '/^\d[\d.]+\d$/' , $ip ) ? $ip : '' ; } /** * 数据库模型实例化入口 * * @param string $model 模型名称 * @return obj 对象形式的返回结果 */ function Model( $model = null, $base_path = null){ static $_cache = array (); $cache_key = $model . '.' . $base_path ; if (! is_null ( $model ) && isset( $_cache [ $cache_key ])) return $_cache [ $cache_key ]; $base_path = $base_path == null ? BASE_DATA_PATH : $base_path ; $file_name = $base_path . '/model/' . $model . '.model.php' ; $class_name = $model . 'Model' ; if (! file_exists ( $file_name )){ return $_cache [ $cache_key ] = new Model( $model ); } else { require_once ( $file_name ); if (! class_exists ( $class_name )){ $error = 'Model Error: Class ' . $class_name . ' is not exists!' ; throw_exception( $error ); } else { return $_cache [ $cache_key ] = new $class_name (); } } } /** * 行为模型实例 * * @param string $model 模型名称 * @return obj 对象形式的返回结果 */ function Logic( $model = null, $base_path = null){ static $_cache = array (); $cache_key = $model . '.' . $base_path ; if (! is_null ( $model ) && isset( $_cache [ $cache_key ])) return $_cache [ $cache_key ]; $base_path = $base_path == null ? BASE_DATA_PATH : $base_path ; $file_name = $base_path . '/logic/' . $model . '.logic.php' ; $class_name = $model . 'Logic' ; if (! file_exists ( $file_name )){ return $_cache [ $cache_key ] = new Model( $model ); } else { require_once ( $file_name ); if (! class_exists ( $class_name )){ $error = 'Logic Error: Class ' . $class_name . ' is not exists!' ; throw_exception( $error ); } else { return $_cache [ $cache_key ] = new $class_name (); } } } /** * 读取目录列表 * 不包括 . .. 文件 三部分 * * @param string $path 路径 * @return array 数组格式的返回结果 */ function readDirList( $path ){ if ( is_dir ( $path )) { $handle = @opendir( $path ); $dir_list = array (); if ( $handle ){ while (false !== ( $dir = readdir( $handle ))){ if ( $dir != '.' && $dir != '..' && is_dir ( $path .DS. $dir )){ $dir_list [] = $dir ; } } return $dir_list ; } else { return false; } } else { return false; } } /** * 转换特殊字符 * * @param string $string 要转换的字符串 * @return string 字符串类型的返回结果 */ function replaceSpecialChar( $string ){ $str = str_replace ( "\r\n" , "" , $string ); $str = str_replace ( "\t" , " " , $string ); $str = str_replace ( "\n" , "" , $string ); return $string ; } /** * 编辑器内容 * * @param int $id 编辑器id名称,与name同名 * @param string $value 编辑器内容 * @param string $width 宽 带px * @param string $height 高 带px * @param string $style 样式内容 * @param string $upload_state 上传状态,默认是开启 */ function showEditor( $id , $value = '' , $width = '700px' , $height = '300px' , $style = 'visibility:hidden;' , $upload_state = "true" , $media_open =false, $type = 'all' ){ //是否开启多媒体 $media = '' ; if ( $media_open ){ $media = ", 'flash', 'media'" ; } switch ( $type ) { case 'basic' : $items = "['source', '|', 'fullscreen', 'undo', 'redo', 'cut', 'copy', 'paste', '|', 'about']" ; break ; case 'simple' : $items = "[ 'source' , '|' , 'fullscreen' , 'undo' , 'redo' , 'cut' , 'copy' , 'paste' , '|' , 'fontname' , 'fontsize' , 'forecolor' , 'hilitecolor' , 'bold' , 'italic' , 'underline' , 'removeformat' , 'justifyleft' , 'justifycenter' , 'justifyright' , 'insertorderedlist' , 'insertunorderedlist' , '|' , 'emoticons' , 'image' , 'link' , '|' , 'about' ]"; break ; default : $items = "[ 'source' , '|' , 'fullscreen' , 'undo' , 'redo' , 'print' , 'cut' , 'copy' , 'paste' , 'plainpaste' , 'wordpaste' , '|' , 'justifyleft' , 'justifycenter' , 'justifyright' , 'justifyfull' , 'insertorderedlist' , 'insertunorderedlist' , 'indent' , 'outdent' , 'subscript' , 'superscript' , '|' , 'selectall' , 'clearhtml' , 'quickformat' , '|' , 'formatblock' , 'fontname' , 'fontsize' , '|' , 'forecolor' , 'hilitecolor' , 'bold' , 'italic' , 'underline' , 'strikethrough' , 'lineheight' , 'removeformat' , '|' , 'image' ".$media." , 'table' , 'hr' , 'emoticons' , 'link' , 'unlink' , '|' , 'about' ]"; break ; } //图片、Flash、视频、文件的本地上传都可开启。默认只有图片,要启用其它的需要修改resource\kindeditor\php下的upload_json.php的相关参数 echo '<textarea id="' . $id . '" name="' . $id . '" style="width:' . $width . ';height:' . $height . ';' . $style . '">' . $value . '</textarea>' ; echo ' <script src= "'. RESOURCE_SITE_URL .'/kindeditor/kindeditor-min.js" charset= "utf-8" ></script> <script src= "'. RESOURCE_SITE_URL .'/kindeditor/lang/zh_CN.js" charset= "utf-8" ></script> <script> var KE; KindEditor.ready( function (K) { KE = K.create( "textarea[name=\''.$id.'\']" , { items : '.$items.' , cssPath : "' . RESOURCE_SITE_URL . '/kindeditor/themes/default/default.css" , allowImageUpload : '.$upload_state.' , allowFlashUpload : false, allowMediaUpload : false, allowFileManager : false, syncType: "form" , afterCreate : function () { var self = this; self.sync(); }, afterChange : function () { var self = this; self.sync(); }, afterBlur : function () { var self = this; self.sync(); } }); KE.appendHtml = function (id,val) { this.html(this.html() + val); if (this.isCreated) { var cmd = this.cmd; cmd.range.selectNodeContents(cmd.doc.body).collapse(false); cmd.select(); } return this; } }); </script> '; return true; } /** * 获取目录大小 * * @param string $path 目录 * @param int $size 目录大小 * @return int 整型类型的返回结果 */ function getDirSize( $path , $size =0){ $dir = @dir( $path ); if (! empty ( $dir ->path) && ! empty ( $dir ->handle)){ while ( $filename = $dir ->read()){ if ( $filename != '.' && $filename != '..' ){ if ( is_dir ( $path .DS. $filename )){ $size += getDirSize( $path .DS. $filename ); } else { $size += filesize ( $path .DS. $filename ); } } } } return $size ? $size : 0 ; } /** * 删除缓存目录下的文件或子目录文件 * * @param string $dir 目录名或文件名 * @return boolean */ function delCacheFile( $dir ){ //防止删除cache以外的文件 if ( strpos ( $dir , '..' ) !== false) return false; $path = BASE_DATA_PATH.DS. 'cache' .DS. $dir ; if ( is_dir ( $path )){ $file_list = array (); readFileList( $path , $file_list ); if (! empty ( $file_list )){ foreach ( $file_list as $v ){ if ( basename ( $v ) != 'index.html' )@unlink( $v ); } } } else { if ( basename ( $path ) != 'index.html' ) @unlink( $path ); } return true; } /** * 获取文件列表(所有子目录文件) * * @param string $path 目录 * @param array $file_list 存放所有子文件的数组 * @param array $ignore_dir 需要忽略的目录或文件 * @return array 数据格式的返回结果 */ function readFileList( $path ,& $file_list , $ignore_dir = array ()){ $path = rtrim( $path , '/' ); if ( is_dir ( $path )) { $handle = @opendir( $path ); if ( $handle ){ while (false !== ( $dir = readdir( $handle ))){ if ( $dir != '.' && $dir != '..' ){ if (!in_array( $dir , $ignore_dir )){ if ( is_file ( $path .DS. $dir )){ $file_list [] = $path .DS. $dir ; } elseif ( is_dir ( $path .DS. $dir )){ readFileList( $path .DS. $dir , $file_list , $ignore_dir ); } } } } @ closedir ( $handle ); // return $file_list; } else { return false; } } else { return false; } } /** * 价格格式化 * * @param int $price * @return string $price_format */ function ncPriceFormat( $price ) { $price_format = number_format( $price ,2, '.' , '' ); return $price_format ; } /** * 价格格式化 * * @param int $price * @return string $price_format */ function ncPriceFormatForList( $price ) { if ( $price >= 10000) { return number_format( floor ( $price /100)/100,2, '.' , '' ).L( 'ten_thousand' ); } else { return L( 'currency' ). $price ; } } /** * 二级域名解析 * @return int 店铺id */ function subdomain(){ $store_id = 0; /** * 获得系统配置,二级域名功能是否开启 */ if (C( 'enabled_subdomain' )== '1' ){ //开启了二级域名 $line = @ explode (SUBDOMAIN_SUFFIX, $_SERVER [ 'HTTP_HOST' ]); $line = trim( $line [0], '.' ); if ( empty ( $line ) || strtolower ( $line ) == 'www' ) return 0; $model_store = Model( 'store' ); $store_info = $model_store ->getStoreInfo( array ( 'store_domain' => $line )); //二级域名存在 if ( $store_info [ 'store_id' ] > 0){ $store_id = $store_info [ 'store_id' ]; $_GET [ 'store_id' ] = $store_info [ 'store_id' ]; } } return $store_id ; } /** * 通知邮件/通知消息 内容转换函数 * * @param string $message 内容模板 * @param array $param 内容参数数组 * @return string 通知内容 */ function ncReplaceText( $message , $param ){ if (! is_array ( $param )) return false; foreach ( $param as $k => $v ){ $message = str_replace ( '{$' . $k . '}' , $v , $message ); } return $message ; } /** * 字符串切割函数,一个字母算一个位置,一个字算2个位置 * * @param string $string 待切割的字符串 * @param int $length 切割长度 * @param string $dot 尾缀 */ function str_cut( $string , $length , $dot = '' ) { $string = str_replace ( array ( ' ' , '&' , '"' , '' ', ' “ ', ' ” ', ' — ', ' < ', ' > ', ' · ', ' … '), array(' ', ' & ', ' " ', "' ", '“' , '”' , '—' , '<' , '>' , '·' , '…' ), $string ); $strlen = strlen ( $string ); if ( $strlen <= $length ) return $string ; $maxi = $length - strlen ( $dot ); $strcut = '' ; if ( strtolower (CHARSET) == 'utf-8' ) { $n = $tn = $noc = 0; while ( $n < $strlen ) { $t = ord( $string [ $n ]); if ( $t == 9 || $t == 10 || (32 <= $t && $t <= 126)) { $tn = 1; $n ++; $noc ++; } elseif (194 <= $t && $t <= 223) { $tn = 2; $n += 2; $noc += 2; } elseif (224 <= $t && $t < 239) { $tn = 3; $n += 3; $noc += 2; } elseif (240 <= $t && $t <= 247) { $tn = 4; $n += 4; $noc += 2; } elseif (248 <= $t && $t <= 251) { $tn = 5; $n += 5; $noc += 2; } elseif ( $t == 252 || $t == 253) { $tn = 6; $n += 6; $noc += 2; } else { $n ++; } if ( $noc >= $maxi ) break ; } if ( $noc > $maxi ) $n -= $tn ; $strcut = substr ( $string , 0, $n ); } else { $dotlen = strlen ( $dot ); $maxi = $length - $dotlen ; for ( $i = 0; $i < $maxi ; $i ++) { $strcut .= ord( $string [ $i ]) > 127 ? $string [ $i ]. $string [++ $i ] : $string [ $i ]; } } $strcut = str_replace ( array ( '&' , '"' , " '", ' < ', ' > '), array(' & ', ' " ', ' '' , '<' , '>' ), $strcut ); return $strcut . $dot ; } /** * unicode转为utf8 * @param string $str 待转的字符串 * @return string */ function unicodeToUtf8( $str , $order = "little" ) { $utf8string = "" ; $n = strlen ( $str ); for ( $i =0; $i < $n ; $i ++ ) { if ( $order == "little" ) { $val = str_pad ( dechex (ord( $str [ $i +1])), 2, 0, STR_PAD_LEFT) . str_pad ( dechex (ord( $str [ $i ])), 2, 0, STR_PAD_LEFT); } else { $val = str_pad ( dechex (ord( $str [ $i ])), 2, 0, STR_PAD_LEFT) . str_pad ( dechex (ord( $str [ $i +1])), 2, 0, STR_PAD_LEFT); } $val = intval ( $val ,16); // 由于上次的.连接,导致$val变为字符串,这里得转回来。 $i ++; // 两个字节表示一个unicode字符。 $c = "" ; if ( $val < 0x7F) { // 0000-007F $c .= chr ( $val ); } elseif ( $val < 0x800) { // 0080-07F0 $c .= chr (0xC0 | ( $val / 64)); $c .= chr (0x80 | ( $val % 64)); } else { // 0800-FFFF $c .= chr (0xE0 | (( $val / 64) / 64)); $c .= chr (0x80 | (( $val / 64) % 64)); $c .= chr (0x80 | ( $val % 64)); } $utf8string .= $c ; } /* 去除bom标记 才能使内置的iconv函数正确转换 */ if (ord( substr ( $utf8string ,0,1)) == 0xEF && ord( substr ( $utf8string ,1,2)) == 0xBB && ord( substr ( $utf8string ,2,1)) == 0xBF) { $utf8string = substr ( $utf8string ,3); } return $utf8string ; } /* * 重写$_SERVER['REQUREST_URI'] */ function request_uri() { if (isset( $_SERVER [ 'REQUEST_URI' ])) { $uri = $_SERVER [ 'REQUEST_URI' ]; } else { if (isset( $_SERVER [ 'argv' ])) { $uri = $_SERVER [ 'PHP_SELF' ] . '?' . $_SERVER [ 'argv' ][0]; } else { $uri = $_SERVER [ 'PHP_SELF' ] . '?' . $_SERVER [ 'QUERY_STRING' ]; } } return $uri ; } /* * 自定义memory_get_usage() * * @return 内存使用额度,如果该方法无效,返回0 */ if (!function_exists( 'memory_get_usage' )){ function memory_get_usage(){ //目前程序不兼容5以下的版本 return 0; } } // 记录和统计时间(微秒) function addUpTime( $start , $end = '' , $dec =3) { static $_info = array (); if (! empty ( $end )) { // 统计时间 if (!isset( $_info [ $end ])) { $_info [ $end ] = microtime(TRUE); } return number_format(( $_info [ $end ]- $_info [ $start ]), $dec ); } else { // 记录时间 $_info [ $start ] = microtime(TRUE); } } /** * 取得系统配置信息 * * @param string $key 取得下标值 * @return mixed */ function C( $key ){ if ( strpos ( $key , '.' )){ $key = explode ( '.' , $key ); if (isset( $key [2])){ return $GLOBALS [ 'setting_config' ][ $key [0]][ $key [1]][ $key [2]]; } else { return $GLOBALS [ 'setting_config' ][ $key [0]][ $key [1]]; } } else { return $GLOBALS [ 'setting_config' ][ $key ]; } } /** * 取得商品默认大小图片 * * @param string $key 图片大小 small tiny * @return string */ function defaultGoodsImage( $key ){ $file = str_ireplace ( '.' , '_' . $key . '.' , C( 'default_goods_image' )); return ATTACH_COMMON.DS. $file ; } /** * 取得用户头像图片 * * @param string $member_avatar * @return string */ function getMemberAvatar( $member_avatar ){ if ( empty ( $member_avatar )) { return UPLOAD_SITE_URL.DS.ATTACH_COMMON.DS.C( 'default_user_portrait' ); } else { if ( file_exists (BASE_UPLOAD_PATH.DS.ATTACH_AVATAR.DS. $member_avatar )){ return UPLOAD_SITE_URL.DS.ATTACH_AVATAR.DS. $member_avatar ; } else { return UPLOAD_SITE_URL.DS.ATTACH_COMMON.DS.C( 'default_user_portrait' ); } } } /** * 成员头像 * @param string $member_id * @return string */ function getMemberAvatarForID( $id ){ if ( file_exists (BASE_UPLOAD_PATH. '/' .ATTACH_AVATAR. '/avatar_' . $id . '.jpg' )){ return UPLOAD_SITE_URL. '/' .ATTACH_AVATAR. '/avatar_' . $id . '.jpg' ; } else { return UPLOAD_SITE_URL. '/' .ATTACH_COMMON.DS.C( 'default_user_portrait' ); } } /** * 成员头像 v3-b12-1 * @param string $member_id * @return string */ function getMemberAvatarHttps( $member_avatar ) { if ( empty ( $member_avatar )) { return UPLOAD_SITE_URL_HTTPS . DS . ATTACH_COMMON . DS . c( 'default_user_portrait' ); } else if ( file_exists (BASE_UPLOAD_PATH . DS . ATTACH_AVATAR . DS . $member_avatar )) { return UPLOAD_SITE_URL_HTTPS . DS . ATTACH_AVATAR . DS . $member_avatar ; } else { return UPLOAD_SITE_URL_HTTPS . DS . ATTACH_COMMON . DS . c( 'default_user_portrait' ); } } /** * 取得店铺标志 * * @param string $img 图片名 * @param string $type 查询类型 store_logo/store_avatar * @return string */ function getStoreLogo( $img , $type = 'store_avatar' ){ if ( $type == 'store_avatar' ) { if ( empty ( $img )) { return UPLOAD_SITE_URL.DS.ATTACH_COMMON.DS.C( 'default_store_avatar' ); } else { return UPLOAD_SITE_URL.DS.ATTACH_STORE.DS. $img ; } } elseif ( $type == 'store_logo' ) { if ( empty ( $img )) { return UPLOAD_SITE_URL.DS.ATTACH_COMMON.DS.C( 'default_store_logo' ); } else { return UPLOAD_SITE_URL.DS.ATTACH_STORE.DS. $img ; } } } /** * 获取文章URL */ function getCMSArticleUrl( $article_id ) { if (URL_MODEL) { // 开启伪静态 return CMS_SITE_URL.DS. 'article-' . $article_id . '.html' ; } else { return CMS_SITE_URL.DS. 'index.php?act=article&op=article_detail&article_id=' . $article_id ; } } /** * 获取画报URL */ function getCMSPictureUrl( $picture_id ) { if (URL_MODEL) { // 开启伪静态 return CMS_SITE_URL.DS. 'picture-' . $picture_id . '.html' ; } else { return CMS_SITE_URL.DS. 'index.php?act=picture&op=picture_detail&picture_id=' . $picture_id ; } } /** * 获取文章图片URL */ function getCMSArticleImageUrl( $image_path , $image_name , $type = 'list' ) { if ( empty ( $image_name )) { return UPLOAD_SITE_URL.DS.ATTACH_CMS.DS. 'no_cover.png' ; } else { $image_array = unserialize( $image_name ); if (! empty ( $image_array [ 'name' ])) { $image_name = $image_array [ 'name' ]; } if (! empty ( $image_array [ 'path' ])) { $image_path = $image_array [ 'path' ]; } $ext_array = array ( 'list' , 'max' ); $file_path = ATTACH_CMS.DS. 'article' .DS. $image_path .DS. str_ireplace ( '.' , '_' . $type . '.' , $image_name ); if ( file_exists (BASE_PATH.DS. $file_name )) { $image_name = UPLOAD_SITE_URL.DS. $file_path ; } else { $image_name = UPLOAD_SITE_URL.DS.ATTACH_CMS.DS. 'no_cover.png' ; } return $image_name ; } } /** * 获取文章图片URL */ function getCMSImageName( $image_name_string ) { $image_array = unserialize( $image_name_string ); if (! empty ( $image_array [ 'name' ])) { $image_name = $image_array [ 'name' ]; } else { $image_name = $image_name_string ; } return $image_name ; } /** * 获取CMS专题图片 */ function getCMSSpecialImageUrl( $image_name = '' ) { return UPLOAD_SITE_URL.DS.ATTACH_CMS.DS. 'special' .DS. $image_name ; } /** * 获取CMS专题路径 */ function getCMSSpecialImagePath( $image_name = '' ) { return BASE_UPLOAD_PATH.DS.ATTACH_CMS.DS. 'special' .DS. $image_name ; } /** * 获取CMS首页图片 */ function getCMSIndexImageUrl( $image_name = '' ) { return UPLOAD_SITE_URL.DS.ATTACH_CMS.DS. 'index' .DS. $image_name ; } /** * 获取CMS首页图片路径 */ function getCMSIndexImagePath( $image_name = '' ) { return BASE_UPLOAD_PATH.DS.ATTACH_CMS.DS. 'index' .DS. $image_name ; } /** * 获取CMS专题Url */ function getCMSSpecialUrl( $special_id ) { return CMS_SITE_URL.DS. 'index.php?act=special&op=special_detail&special_id=' . $special_id ; } /** * 获取商城专题Url */ function getShopSpecialUrl( $special_id ) { return SHOP_SITE_URL.DS. 'index.php?act=special&op=special_detail&special_id=' . $special_id ; } /** * 获取CMS专题静态文件 */ function getCMSSpecialHtml( $special_id ) { $special_file = BASE_UPLOAD_PATH.DS.ATTACH_CMS.DS. 'special_html' .DS.md5( 'special' . intval ( $special_id )). '.html' ; if ( is_file ( $special_file )) { return $special_file ; } else { return false; } } /** * 获取微商城个人秀图片地址 */ function getMicroshopPersonalImageUrl( $personal_info , $type = '' ){ $ext_array = array ( 'list' , 'tiny' ); $personal_image_array = array (); $personal_image_list = explode ( ',' , $personal_info [ 'commend_image' ]); if (! empty ( $personal_image_list )){ foreach ( $personal_image_list as $value ) { if (! empty ( $type ) && in_array( $type , $ext_array )) { $file_name = str_replace ( '.' , '_' . $type . '.' , $value ); } else { $file_name = $value ; } $file_path = $personal_info [ 'commend_member_id' ].DS. $file_name ; if ( is_file (BASE_UPLOAD_PATH.DS.ATTACH_MICROSHOP.DS. $file_path )) { $personal_image_array [] = UPLOAD_SITE_URL.DS.ATTACH_MICROSHOP.DS. $file_path ; } else { $personal_image_array [] = getMicroshopDefaultImage(); } } } else { $personal_image_array [] = getMicroshopDefaultImage(); } return $personal_image_array ; } function getMicroshopDefaultImage() { return UPLOAD_SITE_URL. '/' .defaultGoodsImage( '240' ); } /** * 获取开店申请图片 */ function getStoreJoininImageUrl( $image_name = '' ) { return UPLOAD_SITE_URL.DS.ATTACH_STORE_JOININ.DS. $image_name ; } /** * 获取开店装修图片地址 */ function getStoreDecorationImageUrl( $image_name = '' , $store_id = null) { if ( empty ( $store_id )) { $image_name_array = explode ( '_' , $image_name ); $store_id = $image_name_array [0]; } $image_path = DS . ATTACH_STORE_DECORATION . DS . $store_id . DS . $image_name ; if ( is_file (BASE_UPLOAD_PATH . $image_path )) { return UPLOAD_SITE_URL . $image_path ; } else { return '' ; } } /** * 获取运单图片地址 */ function getWaybillImageUrl( $image_name = '' ) { $image_path = DS . ATTACH_WAYBILL . DS . $image_name ; if ( is_file (BASE_UPLOAD_PATH . $image_path )) { return UPLOAD_SITE_URL . $image_path ; } else { return UPLOAD_SITE_URL. '/' .defaultGoodsImage( '240' ); } } /** * 获取运单图片地址 */ function getMbSpecialImageUrl( $image_name = '' ) { $name_array = explode ( '_' , $image_name ); if ( count ( $name_array ) == 2) { $image_path = DS . ATTACH_MOBILE . DS . 'special' . DS . $name_array [0] . DS . $image_name ; } else { $image_path = DS . ATTACH_MOBILE . DS . 'special' . DS . $image_name ; } if ( is_file (BASE_UPLOAD_PATH . $image_path )) { return UPLOAD_SITE_URL . $image_path ; } else { return UPLOAD_SITE_URL. '/' .defaultGoodsImage( '240' ); } } /** * 加载文件 * * 使用require_once函数,只适用于加载框架内类库文件 * 如果文件名中包含"_"使用"#"代替 * * @example import('cache'); //require_once(BASE_PATH.'/framework/libraries/cache.php'); * @example import('libraries.cache'); //require_once(BASE_PATH.'/framework/libraries/cache.php'); * @example import('function.core'); //require_once(BASE_PATH.'/framework/function/core.php'); * @example import('.control.adv') //require_once(BASE_PATH.'/control/adv.php'); * * @param 要加载的文件 $libname * @param 文件扩展名 $file_ext */ function import( $libname , $file_ext = '.php' ){ //替换为目录符号/ if ( strstr ( $libname , '.' )){ $path = str_replace ( '.' , '/' , $libname ); } else { $path = 'libraries/' . $libname ; } // 基准目录,如果是顶级目录 if ( substr ( $libname ,0,1) == '.' ){ $base_dir = BASE_CORE_PATH. '/' ; $path = ltrim( str_replace ( 'libraries/' , '' , $path ), '/' ); } else { $base_dir = BASE_CORE_PATH. '/framework/' ; } //如果文件名中含有.使用#代替 if ( strstr ( $path , '#' )){ $path = str_replace ( '#' , '.' , $path ); } //返回安全路径 if (preg_match( '/^[\w\d\/_.]+$/i' , $path )){ $file = realpath ( $base_dir . $path . $file_ext ); } else { $file = false; } if (! $file ){ exit ( $path . $file_ext . ' isn\'t exists!' ); } else { require_once ( $file ); } } /** * 取得随机数 * * @param int $length 生成随机数的长度 * @param int $numeric 是否只产生数字随机数 1是0否 * @return string */ function random( $length , $numeric = 0) { $seed = base_convert (md5(microtime(). $_SERVER [ 'DOCUMENT_ROOT' ]), 16, $numeric ? 10 : 35); $seed = $numeric ? ( str_replace ( '0' , '' , $seed ). '012340567890' ) : ( $seed . 'zZ' . strtoupper ( $seed )); $hash = '' ; $max = strlen ( $seed ) - 1; for ( $i = 0; $i < $length ; $i ++) { $hash .= $seed {mt_rand(0, $max )}; } return $hash ; } /** * 返回模板文件所在完整目录 * * @param str $tplpath * @return string */ function template( $tplpath ){ if ( strpos ( $tplpath , ':' ) !== false){ $tpltmp = explode ( ':' , $tplpath ); return BASE_DATA_PATH. '/' . $tpltmp [0]. '/tpl/' . $tpltmp [1]. '.php' ; } else { return BASE_PATH. '/templates/' .TPL_NAME. '/' . $tplpath . '.php' ; } } /** * 检测FORM是否提交 * @param $check_token 是否验证token * @param $check_captcha 是否验证验证码 * @param $return_type 'alert','num' * @return boolean */ function chksubmit( $check_token = false, $check_captcha = false, $return_type = 'alert' ){ $submit = isset( $_POST [ 'form_submit' ]) ? $_POST [ 'form_submit' ] : $_GET [ 'form_submit' ]; if ( $submit != 'ok' ) return false; if ( $check_token && !Security::checkToken()){ if ( $return_type == 'alert' ){ showDialog( 'Token error!' ); } else { return -11; } } if ( $check_captcha ){ if (!checkSeccode( $_POST [ 'nchash' ], $_POST [ 'captcha' ])){ setNcCookie( 'seccode' . $_POST [ 'nchash' ], '' ,-3600); if ( $return_type == 'alert' ){ showDialog( '验证码错误!' ); } else { return -12; } } setNcCookie( 'seccode' . $_POST [ 'nchash' ], '' ,-3600); } return true; } /** * sns表情标示符替换为html */ function parsesmiles( $message ) { $smilescache_file = BASE_DATA_PATH.DS. 'smilies' .DS. 'smilies.php' ; if ( file_exists ( $smilescache_file )){ include $smilescache_file ; if ( strtoupper (CHARSET) == 'GBK' ) { $smilies_array = Language::getGBK( $smilies_array ); } if (! empty ( $smilies_array ) && is_array ( $smilies_array )) { $imagesurl = RESOURCE_SITE_URL.DS. 'js' .DS. 'smilies' .DS. 'images' .DS; $replace_arr = array (); foreach ( $smilies_array [ 'replacearray' ] AS $key => $smiley ) { $replace_arr [ $key ] = '<img src="' . $imagesurl . $smiley [ 'imagename' ]. '" title="' . $smiley [ 'desc' ]. '" border="0" alt="' . $imagesurl . $smiley [ 'desc' ]. '" />' ; } $message = preg_replace( $smilies_array [ 'searcharray' ], $replace_arr , $message ); } } return $message ; } /** * 输出validate的验证信息 * * @param array/string $error */ function showValidateError( $error ){ if (! empty ( $_GET [ 'inajax' ])){ foreach ( explode ( '<br/>' , $error ) as $v ) { if (trim( $v != '' )){ showDialog( $v , '' , 'error' , '' ,3); } } } else { showDialog( $error , '' , 'error' , '' ,3); } } /** * 延时加载分页功能,判断是否有更多连接和limitstart值和经过验证修改的$delay_eachnum值 * @param int $delay_eachnum 延时分页每页显示的条数 * @param int $delay_page 延时分页当前页数 * @param int $count 总记录数 * @param bool $ispage 是否在分页模式中实现延时分页(前台显示的两种不同效果) * @param int $page_nowpage 分页当前页数 * @param int $page_eachnum 分页每页显示条数 * @param int $page_limitstart 分页初始limit值 * @return array array('hasmore'=>'是否显示更多连接','limitstart'=>'加载的limit开始值','delay_eachnum'=>'经过验证修改的$delay_eachnum值'); */ function lazypage( $delay_eachnum , $delay_page , $count , $ispage =false, $page_nowpage =1, $page_eachnum =1, $page_limitstart =1){ //是否有多余 $hasmore = true; $limitstart = 0; if ( $ispage == true){ if ( $delay_eachnum < $page_eachnum ){ //当延时加载每页条数小于分页的每页条数时候实现延时加载,否则按照普通分页程序流程处理 $page_totlepage = ceil ( $count / $page_eachnum ); //计算limit的开始值 $limitstart = $page_limitstart + ( $delay_page -1)* $delay_eachnum ; if ( $page_totlepage > $page_nowpage ){ //当前不为最后一页 if ( $delay_page >= $page_eachnum / $delay_eachnum ){ $hasmore = false; } //判断如果分页的每页条数与延时加载每页的条数不能整除的处理 if ( $hasmore == false && $page_eachnum % $delay_eachnum >0){ $delay_eachnum = $page_eachnum % $delay_eachnum ; } } else { //当前最后一页 $showcount = ( $page_totlepage -1)* $page_eachnum + $delay_eachnum * $delay_page ; //已经显示的记录总数 if ( $count <= $showcount ){ $hasmore = false; } } } else { $hasmore = false; } } else { if ( $count <= $delay_page * $delay_eachnum ){ $hasmore = false; } //计算limit的开始值 $limitstart = ( $delay_page -1)* $delay_eachnum ; } return array ( 'hasmore' => $hasmore , 'limitstart' => $limitstart , 'delay_eachnum' => $delay_eachnum ); } /** * 文件数据读取和保存 字符串、数组 * * @param string $name 文件名称(不含扩展名) * @param mixed $value 待写入文件的内容 * @param string $path 写入cache的目录 * @param string $ext 文件扩展名 * @return mixed */ function F( $name , $value = null, $path = 'cache' , $ext = '.php' ) { if ( strtolower ( substr ( $path ,0,5)) == 'cache' ){ $path = 'data/' . $path ; } static $_cache = array (); if (isset( $_cache [ $name . $path ])) return $_cache [ $name . $path ]; $filename = BASE_ROOT_PATH. '/' . $path . '/' . $name . $ext ; if (! is_null ( $value )) { $dir = dirname( $filename ); if (! is_dir ( $dir )) mkdir ( $dir ); return write_file( $filename , $value ); } if ( is_file ( $filename )) { $_cache [ $name . $path ] = $value = include $filename ; } else { $value = false; } return $value ; } /** * 内容写入文件 * * @param string $filepath 待写入内容的文件路径 * @param string/array $data 待写入的内容 * @param string $mode 写入模式,如果是追加,可传入“append” * @return bool */ function write_file( $filepath , $data , $mode = null) { if (! is_array ( $data ) && ! is_scalar ( $data )) { return false; } $data = var_export( $data , true); $data = "<?php defined('InShopNC') or exit('Access Invalid!'); return " . $data . ";" ; $mode = $mode == 'append' ? FILE_APPEND : null; if (false === file_put_contents ( $filepath ,( $data ), $mode )){ return false; } else { return true; } } /** * 循环创建目录 * * @param string $dir 待创建的目录 * @param $mode 权限 * @return boolean */ function mk_dir( $dir , $mode = '0777' ) { if ( is_dir ( $dir ) || @ mkdir ( $dir , $mode )) return true; if (!mk_dir(dirname( $dir ), $mode )) return false; return @ mkdir ( $dir , $mode ); } /** * 封装分页操作到函数,方便调用 * * @param string $cmd 命令类型 * @param mixed $arg 参数 * @return mixed */ function pagecmd( $cmd = '' , $arg = '' ){ if (! class_exists ( 'page' )) import( 'page' ); static $page ; if ( $page == null){ $page = new Page(); } switch ( strtolower ( $cmd )) { case 'seteachnum' : $page ->setEachNum( $arg ); break ; case 'settotalnum' : $page ->setTotalNum( $arg ); break ; case 'setstyle' : $page ->setStyle( $arg ); break ; case 'show' : return $page ->show( $arg ); break ; case 'obj' : return $page ; break ; case 'gettotalnum' : return $page ->getTotalNum(); break ; case 'gettotalpage' : return $page ->getTotalPage(); break ; default : break ; } } /** * 抛出异常 * * @param string $error 异常信息 */ function throw_exception( $error ){ if (!defined( 'IGNORE_EXCEPTION' )){ showMessage( $error , '' , 'exception' ); } else { exit (); } } /** * 输出错误信息 * * @param string $error 错误信息 */ function halt( $error ){ showMessage( $error , '' , 'exception' ); } /** * 去除代码中的空白和注释 * * @param string $content 待压缩的内容 * @return string */ function compress_code( $content ) { $stripStr = '' ; //分析php源码 $tokens = token_get_all( $content ); $last_space = false; for ( $i = 0, $j = count ( $tokens ); $i < $j ; $i ++) { if ( is_string ( $tokens [ $i ])) { $last_space = false; $stripStr .= $tokens [ $i ]; } else { switch ( $tokens [ $i ][0]) { case T_COMMENT: //过滤各种PHP注释 case T_DOC_COMMENT: break ; case T_WHITESPACE: //过滤空格 if (! $last_space ) { $stripStr .= ' ' ; $last_space = true; } break ; default : $last_space = false; $stripStr .= $tokens [ $i ][1]; } } } return $stripStr ; } /** * 取得对象实例 * * @param object $class * @param string $method * @param array $args * @return object */ function get_obj_instance( $class , $method = '' , $args = array ()){ static $_cache = array (); $key = $class . $method .( empty ( $args ) ? null : md5(serialize( $args ))); if (isset( $_cache [ $key ])){ return $_cache [ $key ]; } else { if ( class_exists ( $class )){ $obj = new $class ; if (method_exists( $obj , $method )){ if ( empty ( $args )){ $_cache [ $key ] = $obj -> $method (); } else { $_cache [ $key ] = call_user_func_array( array (& $obj , $method ), $args ); } } else { $_cache [ $key ] = $obj ; } return $_cache [ $key ]; } else { throw_exception( 'Class ' . $class . ' isn\'t exists!' ); } } } /** * 返回以原数组某个值为下标的新数据 * * @param array $array * @param string $key * @param int $type 1一维数组2二维数组 * @return array */ function array_under_reset( $array , $key , $type =1){ if ( is_array ( $array )){ $tmp = array (); foreach ( $array as $v ) { if ( $type === 1){ $tmp [ $v [ $key ]] = $v ; } elseif ( $type === 2){ $tmp [ $v [ $key ]][] = $v ; } } return $tmp ; } else { return $array ; } } /** * KV缓存 读 * * @param string $key 缓存名称 * @param boolean $callback 缓存读取失败时是否使用回调 true代表使用cache.model中预定义的缓存项 默认不使用回调 * @param callable $callback 传递非boolean值时 通过is_callable进行判断 失败抛出异常 成功则将$key作为参数进行回调 * @return mixed */ function rkcache( $key , $callback = false) { if (C( 'cache_open' )) { $cacher = Cache::getInstance( 'cacheredis' ); } else { $cacher = Cache::getInstance( 'file' , null); } if (! $cacher ) { throw new Exception( 'Cannot fetch cache object!' ); } $value = $cacher ->get( $key ); if ( $value === false && $callback !== false) { if ( $callback === true) { $callback = array (Model( 'cache' ), 'call' ); } if (! is_callable ( $callback )) { throw new Exception( 'Invalid rkcache callback!' ); } $value = call_user_func( $callback , $key ); wkcache( $key , $value ); } return $value ; } /** * KV缓存 写 * * @param string $key 缓存名称 * @param mixed $value 缓存数据 若设为否 则下次读取该缓存时会触发回调(如果有) * @param int $expire 缓存时间 单位秒 null代表不过期 * @return boolean */ function wkcache( $key , $value , $expire = null) { if (C( 'cache_open' )) { $cacher = Cache::getInstance( 'cacheredis' ); } else { $cacher = Cache::getInstance( 'file' , null); } if (! $cacher ) { throw new Exception( 'Cannot fetch cache object!' ); } return $cacher ->set( $key , $value , null, $expire ); } /** * KV缓存 删 * * @param string $key 缓存名称 * @return boolean */ function dkcache( $key ) { if (C( 'cache_open' )) { $cacher = Cache::getInstance( 'cacheredis' ); } else { $cacher = Cache::getInstance( 'file' , null); } if (! $cacher ) { throw new Exception( 'Cannot fetch cache object!' ); } return $cacher ->rm( $key ); } /** * 读取缓存信息 * * @param string $key 要取得缓存键 * @param string $prefix 键值前缀 * @param string $fields 所需要的字段 * @return array/bool */ function rcache( $key = null, $prefix = '' , $fields = '*' ){ if ( $key ===null || !C( 'cache_open' )) return array (); $ins = Cache::getInstance( 'cacheredis' ); $cache_info = $ins ->hget( $key , $prefix , $fields ); if ( $cache_info === false) { //取单个字段且未被缓存 $data = array (); } elseif ( is_array ( $cache_info )) { //如果有一个键值为false(即未缓存),则整个函数返回空,让系统重新生成全部缓存 $data = $cache_info ; foreach ( $cache_info as $k => $v ) { if ( $v === false) { $data = array (); break ; } } } else { //string 取单个字段且被缓存 $data = array ( $fields => $cache_info ); } // 验证缓存是否过期 if (isset( $data [ 'cache_expiration_time' ]) && $data [ 'cache_expiration_time' ] < TIMESTAMP) { $data = array (); } return $data ; } /** * 写入缓存 * * @param string $key 缓存键值 * @param array $data 缓存数据 * @param string $prefix 键值前缀 * @param int $period 缓存周期 单位分,0为永久缓存 * @return bool 返回值 */ function wcache( $key = null, $data = array (), $prefix , $period = 0){ if ( $key ===null || !C( 'cache_open' ) || ! is_array ( $data )) return ; $period = intval ( $period ); if ( $period != 0) { $data [ 'cache_expiration_time' ] = TIMESTAMP + $period * 60; } $ins = Cache::getInstance( 'cacheredis' ); $ins ->hset( $key , $prefix , $data ); $cache_info = $ins ->hget( $key , $prefix ); return true; } /** * 删除缓存 * @param string $key 缓存键值 * @param string $prefix 键值前缀 * @return boolean */ function dcache( $key = null, $prefix = '' ){ if ( $key ===null || !C( 'cache_open' )) return true; $ins = Cache::getInstance( 'cacheredis' ); return $ins ->hdel( $key , $prefix ); } /** * 调用推荐位 * * @param int $rec_id 推荐位ID * @return string 推荐位内容 */ function rec( $rec_id = null){ import( 'function.rec_position' ); return rec_position( $rec_id ); } /** * 快速调用语言包 * * @param string $key * @return string */ function L( $key = '' ){ if ( class_exists ( 'Language' )){ if ( strpos ( $key , ',' ) !== false){ $tmp = explode ( ',' , $key ); $str = Language::get( $tmp [0]).Language::get( $tmp [1]); return isset( $tmp [2])? $str .Language::get( $tmp [2]) : $str ; } else { return Language::get( $key ); } } else { return null; } } /** * 加载完成业务方法的文件 * * @param string $filename * @param string $file_ext */ function loadfunc( $filename , $file_ext = '.php' ){ if (preg_match( '/^[\w\d\/_.]+$/i' , $filename . $file_ext )){ $file = realpath (BASE_PATH. '/framework/function/' . $filename . $file_ext ); } else { $file = false; } if (! $file ){ exit ( $filename . $file_ext . ' isn\'t exists!' ); } else { require_once ( $file ); } } /** * 实例化类 * * @param string $model_name 模型名称 * @return obj 对象形式的返回结果 */ function nc_class( $classname = null){ static $_cache = array (); if (! is_null ( $classname ) && isset( $_cache [ $classname ])) return $_cache [ $classname ]; $file_name = BASE_PATH. '/framework/libraries/' . $classname . '.class.php' ; $newname = $classname . 'Class' ; if ( file_exists ( $file_name )){ require_once ( $file_name ); if ( class_exists ( $newname )){ return $_cache [ $classname ] = new $newname (); } } throw_exception( 'Class Error: Class ' . $classname . ' is not exists!' ); } /** * 加载广告 * * @param $ap_id 广告位ID * @param $type 广告返回类型 html,js */ function loadadv( $ap_id = null, $type = 'html' ){ if (! is_numeric ( $ap_id )) return false; if (!function_exists( 'advshow' )) import( 'function.adv' ); return advshow( $ap_id , $type ); } /** * 格式化ubb标签 * * @param string $theme_content/$reply_content 话题内容/回复内容 * @return string */ function ubb( $ubb ){ $ubb = str_replace ( array ( '[B]' , '[/B]' , '[I]' , '[/I]' , '[U]' , '[/U]' , '[IMG]' , '[/IMG]' , '[/FONT]' , '[/FONT-SIZE]' , '[/FONT-COLOR]' ), array ( '<b>' , '</b>' , '<i>' , '</i>' , '<u>' , '</u>' , '<img class="pic" src="' , '"/>' , '</span>' , '</span>' , '</span>' ), preg_replace( array ( "/\[URL=(.*)\](.*)\[\/URL\]/iU" , "/\[FONT=([A-Za-z ]*)\]/iU" , "/\[FONT-SIZE=([0-9]*)\]/iU" , "/\[FONT-COLOR=([A-Za-z0-9]*)\]/iU" , "/\[SMILIER=([A-Za-z_]*)\/\]/iU" , "/\[FLASH\](.*)\[\/FLASH\]/iU" , "/\\n/i" ), array ( "<a href=\"$1\" target=\"_blank\">$2</a>" , "<span style=\"font-family:$1\">" , "<span style=\"font-size:$1px\">" , "<span style=\"color:#$1\">" , "<img src=\"" .CIRCLE_SITE_URL. '/templates/' .TPL_CIRCLE_NAME. "/images/smilier/$1.png\">" , "<embed src=\"$1\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" wmode=\"opaque\" width=\"480\" height=\"400\"></embed>" , "<br />" ), $ubb )); return $ubb ; } /** * 去掉ubb标签 * * @param string $theme_content/$reply_content 话题内容/回复内容 * @return string */ function removeUBBTag( $ubb ){ $ubb = str_replace ( array ( '[B]' , '[/B]' , '[I]' , '[/I]' , '[U]' , '[/U]' , '[/FONT]' , '[/FONT-SIZE]' , '[/FONT-COLOR]' ), array ( '' , '' , '' , '' , '' , '' , '' , '' , '' ), preg_replace( array ( "/\[URL=(.*)\](.*)\[\/URL\]/iU" , "/\[FONT=([A-Za-z ]*)\]/iU" , "/\[FONT-SIZE=([0-9]*)\]/iU" , "/\[FONT-COLOR=([A-Za-z0-9]*)\]/iU" , "/\[SMILIER=([A-Za-z_]*)\/\]/iU" , "/\[IMG\](.*)\[\/IMG\]/iU" , "/\[FLASH\](.*)\[\/FLASH\]/iU" , "<img class='pi' src=\"$1\"/>" , ), array ( "$2" , "" , "" , "" , "" , "" , "" , "" ), $ubb )); return $ubb ; } /** * 话题图片绝对路径 * * @param $param string 文件名称 * @return string */ function themeImagePath( $param ){ return BASE_UPLOAD_PATH. '/' .ATTACH_CIRCLE. '/theme/' . $param ; } /** * 话题图片url * * @param $param string * @return string */ function themeImageUrl( $param ){ return UPLOAD_SITE_URL. '/' .ATTACH_CIRCLE. '/theme/' . $param ; } /** * 圈子logo * * @param $param string 圈子id * @return string */ function circleLogo( $id ){ if ( file_exists (BASE_UPLOAD_PATH. '/' .ATTACH_CIRCLE. '/group/' . $id . '.jpg' )){ return UPLOAD_SITE_URL. '/' .ATTACH_CIRCLE. '/group/' . $id . '.jpg' ; } else { return UPLOAD_SITE_URL. '/' .ATTACH_CIRCLE. '/default_group_logo.gif' ; } } /** * sns 来自 * @param $param string $trace_from * @return string */ function snsShareFrom( $sign ) { switch ( $sign ) { case '1' : case '2' : return L( 'sns_from' ) . '<a target="_black" href="' . SHOP_SITE_URL . '">' . L( 'sns_shop' ) . '</a>' ; break ; case '3' : return L( 'sns_from' ) . '<a target="_black" href="' . MICROSHOP_SITE_URL . '">' . L( 'nc_modules_microshop' ) . '</a>' ; break ; case '4' : return L( 'sns_from' ) . '<a target="_black" href="' . CMS_SITE_URL . '">CMS</a>' ; break ; case '5' : return L( 'sns_from' ) . '<a target="_black" href="' . CIRCLE_SITE_URL . '">' . L( 'nc_circle' ) . '</a>' ; break ; } } /** * 输出聊天信息 * * @return string */ function getChat( $layout ){ if (!C( 'node_chat' ) || ! file_exists (BASE_CORE_PATH. '/framework/libraries/chat.php' )) return '' ; if (! class_exists ( 'Chat' )) import( 'libraries.chat' ); return Chat::getChatHtml( $layout ); } /** * 拼接动态URL,参数需要小写 * * 调用示例 * * 若指向网站首页,可以传空: * url() => 表示act和op均为index,返回当前站点网址 * * url('search,'index','array('cate_id'=>2)); 实际指向 index.php?act=search&op=index&cate_id=2 * 传递数组参数时,若act(或op)值为index,则可以省略 * 上面示例等同于 * url('search','',array('act'=>'search','cate_id'=>2)); * * @param string $act control文件名 * @param string $op op方法名 * @param array $args URL其它参数 * @param boolean $model 默认取当前系统配置 * @param string $site_url 生成链接的网址,默认取当前网址 * @return string */ function url( $act = '' , $op = '' , $args = array (), $model = false, $site_url = '' ){ //伪静态文件扩展名 $ext = '.html' ; //入口文件名 $file = 'index.php' ; // $site_url = empty($site_url) ? SHOP_SITE_URL : $site_url; $act = trim( $act ); $op = trim( $op ); $args = ! is_array ( $args ) ? array () : $args ; //定义变量存放返回url $url_string = '' ; if ( empty ( $act ) && empty ( $op ) && empty ( $args )) { return $site_url ; } $act = ! empty ( $act ) ? $act : 'index' ; $op = ! empty ( $op ) ? $op : 'index' ; $model = $model ? URL_MODEL : $model ; if ( $model ) { //伪静态模式 $url_perfix = "{$act}-{$op}" ; if (! empty ( $args )){ $url_perfix .= '-' ; } $url_string = $url_perfix .http_build_query( $args , '' , '-' ). $ext ; $url_string = str_replace ( '=' , '-' , $url_string ); } else { //默认路由模式 $url_perfix = "act={$act}&op={$op}" ; if (! empty ( $args )){ $url_perfix .= '&' ; } $url_string = $file . '?' . $url_perfix .http_build_query( $args ); } //将商品、店铺、分类、品牌、文章自动生成的伪静态URL使用短URL代替 $reg_match_from = array ( '/^category-index\.html$/' , '/^channel-index-id-(\\d+)\\.html$/' , '/^goods-index-goods_id-(\\d+)\\.html$/' , '/^show_store-index-store_id-(\d+)\.html$/' , '/^show_store-goods_all-store_id-(\d+)-stc_id-(\d+)-key-([0-5])-order-([0-2])-curpage-(\d+)\.html$/' , '/^article-show-article_id-(\d+)\.html$/' , '/^article-article-ac_id-(\d+)\.html$/' , '/^document-index-code-([a-z_]+)\.html$/' , '/^search-index-cate_id-(\d+)-b_id-([0-9_]+)-a_id-([0-9_]+)-key-([0-3])-order-([0-2])-type-([0-1])-gift-([0-1])-area_id-(\d+)-curpage-(\d+)\.html$/' , '/^brand-list-brand-(\d+)-key-([0-3])-order-([0-2])-type-([0-1])-gift-([0-1])-area_id-(\d+)-curpage-(\d+)\.html$/' , '/^brand-index\.html$/' , '/^promotion-index\\.html$/' , '/^promotion-index-gc_id-(\\d+)\\.html$/' , '/^show_groupbuy-index\.html$/' , '/^show_groupbuy-groupbuy_detail-group_id-(\d+)\.html$/' , '/^show_groupbuy-groupbuy_list-class-(\d+)-s_class-(\d+)-groupbuy_price-(\d+)-groupbuy_order_key-(\d+)-groupbuy_order-(\d+)-curpage-(\d+)\.html$/' , '/^show_groupbuy-groupbuy_soon-class-(\d+)-s_class-(\d+)-groupbuy_price-(\d+)-groupbuy_order_key-(\d+)-groupbuy_order-(\d+)-curpage-(\d+)\.html$/' , '/^show_groupbuy-groupbuy_history-class-(\d+)-s_class-(\d+)-groupbuy_price-(\d+)-groupbuy_order_key-(\d+)-groupbuy_order-(\d+)-curpage-(\d+)\.html$/' , '/^show_groupbuy-vr_groupbuy_list-vr_class-(\d+)-vr_s_class-(\d+)-vr_area-(\d+)-vr_mall-(\d+)-groupbuy_price-(\d+)-groupbuy_order_key-(\d+)-groupbuy_order-(\d+)-curpage-(\d+)\.html$/' , '/^show_groupbuy-vr_groupbuy_soon-vr_class-(\d+)-vr_s_class-(\d+)-vr_area-(\d+)-vr_mall-(\d+)-groupbuy_price-(\d+)-groupbuy_order_key-(\d+)-groupbuy_order-(\d+)-curpage-(\d+)\.html$/' , '/^show_groupbuy-vr_groupbuy_history-vr_class-(\d+)-vr_s_class-(\d+)-vr_area-(\d+)-vr_mall-(\d+)-groupbuy_price-(\d+)-groupbuy_order_key-(\d+)-groupbuy_order-(\d+)-curpage-(\d+)\.html$/' , '/^pointshop-index.html$/' , '/^pointprod-plist.html$/' , '/^pointprod-pinfo-id-(\d+).html$/' , '/^pointvoucher-index.html$/' , '/^pointgrade-index.html$/' , '/^pointgrade-exppointlog-curpage-(\d+).html$/' , '/^goods-comments_list-goods_id-(\d+)-type-([0-3])-curpage-(\d+).html$/' , '/^special-special_list.html$/' , '/^special-special_detail-special_id-(\d+).html$/' ); $reg_match_to = array ( 'category.html' , 'channel-\\1.html' , 'item-\\1.html' , 'shop-\\1.html' , 'shop_view-\\1-\\2-\\3-\\4-\\5.html' , 'article-\\1.html' , 'article_cate-\\1.html' , 'document-\\1.html' , 'cate-\\1-\\2-\\3-\\4-\\5-\\6-\\7-\\8-\\9.html' , 'brand-\\1-\\2-\\3-\\4-\\5-\\6-\\7.html' , 'brand.html' , 'promotion.html' , 'promotion-\\1.html' , 'groupbuy.html' , 'groupbuy_detail-\\1.html' , 'groupbuy_list-\\1-\\2-\\3-\\4-\\5-\\6.html' , 'groupbuy_soon-\\1-\\2-\\3-\\4-\\5-\\6.html' , 'groupbuy_history-\\1-\\2-\\3-\\4-\\5-\\6.html' , 'vr_groupbuy_list-\\1-\\2-\\3-\\4-\\5-\\6-\\7-\\8.html' , 'vr_groupbuy_soon-\\1-\\2-\\3-\\4-\\5-\\6-\\7-\\8.html' , 'vr_groupbuy_history-\\1-\\2-\\3-\\4-\\5-\\6-\\7-\\8.html' , 'integral.html' , 'integral_list.html' , 'integral_item-\\1.html' , 'voucher.html' , 'grade.html' , 'explog-\\1.html' , 'comments-\\1-\\2-\\3.html' , 'special.html' , 'special-\\1.html' ); $url_string = preg_replace( $reg_match_from , $reg_match_to , $url_string ); return rtrim( $site_url , '/' ). '/' . $url_string ; } /** * 商城会员中心使用的URL链接函数,强制使用动态传参数模式 * * @param string $act control文件名 * @param string $op op方法名 * @param array $args URL其它参数 * @param string $store_domian 店铺二级域名 * @return string */ function urlShop( $act = '' , $op = '' , $args = array (), $store_domain = '' ){ // 如何使自营店则返回javascript:; // if ($act == 'show_store' && $op != 'goods_all') { // static $ownShopIds = null; // if ($ownShopIds === null) { // $ownShopIds = Model('store')->getOwnShopIds(); // } // if (isset($args['store_id']) && in_array($args['store_id'], $ownShopIds)) { // return 'javascript:;'; // } // } // 开启店铺二级域名 if ( intval (C( 'enabled_subdomain' )) == 1 && ! empty ( $store_domain )){ return 'http://' . $store_domain . '.' .SUBDOMAIN_SUFFIX. '/' ; } // 默认标志为不开启伪静态 $rewrite_flag = false; // 如果平台开启伪静态开关,并且为伪静态模块,修改标志为开启伪静态 $rewrite_item = array ( 'category:index' , 'channel:index' , 'goods:index' , 'goods:comments_list' , 'search:index' , 'show_store:index' , 'show_store:goods_all' , 'article:show' , 'article:article' , 'document:index' , 'brand:list' , 'brand:index' , 'promotion:index' , 'show_groupbuy:index' , 'show_groupbuy:groupbuy_detail' , 'show_groupbuy:groupbuy_list' , 'show_groupbuy:groupbuy_soon' , 'show_groupbuy:groupbuy_history' , 'show_groupbuy:vr_groupbuy_list' , 'show_groupbuy:vr_groupbuy_soon' , 'show_groupbuy:vr_groupbuy_history' , 'pointshop:index' , 'pointvoucher:index' , 'pointprod:pinfo' , 'pointprod:plist' , 'pointgrade:index' , 'pointgrade:exppointlog' , 'store_snshome:index' , 'special:special_list' , 'special:special_detail' , ); if (URL_MODEL && in_array( $act . ':' . $op , $rewrite_item )) { $rewrite_flag = true; $tpl_args = array (); // url参数临时数组 switch ( $act . ':' . $op ) { case 'search:index' : if (! empty ( $args [ 'keyword' ])) { $rewrite_flag = false; break ; } $tpl_args [ 'cate_id' ] = empty ( $args [ 'cate_id' ]) ? 0 : $args [ 'cate_id' ]; $tpl_args [ 'b_id' ] = empty ( $args [ 'b_id' ]) || intval ( $args [ 'b_id' ]) == 0 ? 0 : $args [ 'b_id' ]; $tpl_args [ 'a_id' ] = empty ( $args [ 'a_id' ]) || intval ( $args [ 'a_id' ]) == 0 ? 0 : $args [ 'a_id' ]; $tpl_args [ 'key' ] = empty ( $args [ 'key' ]) ? 0 : $args [ 'key' ]; $tpl_args [ 'order' ] = empty ( $args [ 'order' ]) ? 0 : $args [ 'order' ]; $tpl_args [ 'type' ] = empty ( $args [ 'type' ]) ? 0 : $args [ 'type' ]; $tpl_args [ 'gift' ] = empty ( $args [ 'gift' ]) ? 0 : $args [ 'gift' ]; $tpl_args [ 'area_id' ] = empty ( $args [ 'area_id' ]) ? 0 : $args [ 'area_id' ]; $tpl_args [ 'curpage' ] = empty ( $args [ 'curpage' ]) ? 0 : $args [ 'curpage' ]; $args = $tpl_args ; break ; case 'show_store:goods_all' : if (isset( $args [ 'inkeyword' ])) { $rewrite_flag = false; break ; } $tpl_args [ 'store_id' ] = empty ( $args [ 'store_id' ]) ? 0 : $args [ 'store_id' ]; $tpl_args [ 'stc_id' ] = empty ( $args [ 'stc_id' ]) ? 0 : $args [ 'stc_id' ]; $tpl_args [ 'key' ] = empty ( $args [ 'key' ]) ? 0 : $args [ 'key' ]; $tpl_args [ 'order' ] = empty ( $args [ 'order' ]) ? 0 : $args [ 'order' ]; $tpl_args [ 'curpage' ] = empty ( $args [ 'curpage' ]) ? 0 : $args [ 'curpage' ]; $args = $tpl_args ; break ; case 'brand:list' : $tpl_args [ 'brand' ] = empty ( $args [ 'brand' ]) ? 0 : $args [ 'brand' ]; $tpl_args [ 'key' ] = empty ( $args [ 'key' ]) ? 0 : $args [ 'key' ]; $tpl_args [ 'order' ] = empty ( $args [ 'order' ]) ? 0 : $args [ 'order' ]; $tpl_args [ 'type' ] = empty ( $args [ 'type' ]) ? 0 : $args [ 'type' ]; $tpl_args [ 'gift' ] = empty ( $args [ 'gift' ]) ? 0 : $args [ 'gift' ]; $tpl_args [ 'area_id' ] = empty ( $args [ 'area_id' ]) ? 0 : $args [ 'area_id' ]; $tpl_args [ 'curpage' ] = empty ( $args [ 'curpage' ]) ? 0 : $args [ 'curpage' ]; $args = $tpl_args ; break ; case 'show_groupbuy:index' : case 'show_groupbuy:groupbuy_detail' : break ; case 'show_groupbuy:groupbuy_list' : case 'show_groupbuy:groupbuy_soon' : case 'show_groupbuy:groupbuy_history' : $tpl_args [ 'class' ] = empty ( $args [ 'class' ]) ? 0 : $args [ 'class' ]; $tpl_args [ 's_class' ] = empty ( $args [ 's_class' ]) ? 0 : $args [ 's_class' ]; $tpl_args [ 'groupbuy_price' ] = empty ( $args [ 'groupbuy_price' ]) ? 0 : $args [ 'groupbuy_price' ]; $tpl_args [ 'groupbuy_order_key' ] = empty ( $args [ 'groupbuy_order_key' ]) ? 0 : $args [ 'groupbuy_order_key' ]; $tpl_args [ 'groupbuy_order' ] = empty ( $args [ 'groupbuy_order' ]) ? 0 : $args [ 'groupbuy_order' ]; $tpl_args [ 'curpage' ] = empty ( $args [ 'curpage' ]) ? 0 : $args [ 'curpage' ]; $args = $tpl_args ; break ; case 'show_groupbuy:vr_groupbuy_list' : case 'show_groupbuy:vr_groupbuy_soon' : case 'show_groupbuy:vr_groupbuy_history' : $tpl_args [ 'vr_class' ] = empty ( $args [ 'vr_class' ]) ? 0 : $args [ 'vr_class' ]; $tpl_args [ 'vr_s_class' ] = empty ( $args [ 'vr_s_class' ]) ? 0 : $args [ 'vr_s_class' ]; $tpl_args [ 'vr_area' ] = empty ( $args [ 'vr_area' ]) ? 0 : $args [ 'vr_area' ]; $tpl_args [ 'vr_mall' ] = empty ( $args [ 'vr_mall' ]) ? 0 : $args [ 'vr_mall' ]; $tpl_args [ 'groupbuy_price' ] = empty ( $args [ 'groupbuy_price' ]) ? 0 : $args [ 'groupbuy_price' ]; $tpl_args [ 'groupbuy_order_key' ] = empty ( $args [ 'groupbuy_order_key' ]) ? 0 : $args [ 'groupbuy_order_key' ]; $tpl_args [ 'groupbuy_order' ] = empty ( $args [ 'groupbuy_order' ]) ? 0 : $args [ 'groupbuy_order' ]; $tpl_args [ 'curpage' ] = empty ( $args [ 'curpage' ]) ? 0 : $args [ 'curpage' ]; $args = $tpl_args ; break ; case 'goods:comments_list' : $tpl_args [ 'goods_id' ] = empty ( $args [ 'goods_id' ]) ? 0 : $args [ 'goods_id' ]; $tpl_args [ 'type' ] = empty ( $args [ 'type' ]) ? 0 : $args [ 'type' ]; $tpl_args [ 'curpage' ] = empty ( $args [ 'curpage' ]) ? 0 : $args [ 'curpage' ]; $args = $tpl_args ; break ; case 'pointgrade:exppointlog' : $tpl_args [ 'curpage' ] = empty ( $args [ 'curpage' ]) ? 0 : $args [ 'curpage' ]; $args = $tpl_args ; break ; case 'promotion:index' : $args = ( empty ( $args [ 'gc_id' ]) ? NULL : $args ); break ; default : break ; } } return url( $act , $op , $args , $rewrite_flag , SHOP_SITE_URL); } /** * 商城后台使用的URL链接函数,强制使用动态传参数模式 * * @param string $act control文件名 * @param string $op op方法名 * @param array $args URL其它参数 * @return string */ function urlAdmin( $act = '' , $op = '' , $args = array ()){ return url( $act , $op , $args , false, ADMIN_SITE_URL); } /** * CMS使用的URL链接函数,强制使用动态传参数模式 * * @param string $act control文件名 * @param string $op op方法名 * @param array $args URL其它参数 * @return string */ function urlCMS( $act = '' , $op = '' , $args = array ()){ return url( $act , $op , $args , false, CMS_SITE_URL); } /** * 圈子使用的URL链接函数,强制使用动态传参数模式 * * @param string $act control文件名 * @param string $op op方法名 * @param array $args URL其它参数 * @return string */ function urlCircle( $act = '' , $op = '' , $args = array ()){ return url( $act , $op , $args , false, CIRCLE_SITE_URL); } /** * 微商城使用的URL链接函数,强制使用动态传参数模式 * * @param string $act control文件名 * @param string $op op方法名 * @param array $args URL其它参数 * @return string */ function urlMicroshop( $act = '' , $op = '' , $args = array ()){ return url( $act , $op , $args , false, MICROSHOP_SITE_URL); } function urlMember( $act = '' , $op = '' , $args = array ()) { $rewrite_flag = false; $rewrite_item = array ( 'article:show' , 'article:article' ); if (URL_MODEL && in_array( $act . ':' . $op , $rewrite_item )) { $rewrite_flag = true; } return url( $act , $op , $args , $rewrite_flag , MEMBER_SITE_URL); } function urlLogin( $act = '' , $op = '' , $args = array ()) { return url( $act , $op , $args , false, LOGIN_SITE_URL); } /** * 验证是否为平台店铺 * * @return boolean */ function checkPlatformStore(){ return $_SESSION [ 'is_own_shop' ]; } /** * 验证是否为平台店铺 并且绑定了全部商品类目 * * @return boolean */ function checkPlatformStoreBindingAllGoodsClass(){ return checkPlatformStore() && $_SESSION [ 'bind_all_gc' ]; } /** * 获得店铺状态样式名称 * @param $param array $store_info * @return string */ function getStoreStateClassName( $store_info ) { $result = 'open' ; if ( intval ( $store_info [ 'store_state' ]) === 1) { $store_end_time = intval ( $store_info [ 'store_end_time' ]); if ( $store_end_time > 0) { if ( $store_end_time < TIMESTAMP) { $result = 'expired' ; } elseif (( $store_end_time - 864000) < TIMESTAMP) { //距离到期10天 $result = 'expire' ; } } } else { $result = 'close' ; } return $result ; } /** * 将字符部分加密并输出 * @param unknown $str * @param unknown $start 从第几个位置开始加密(从1开始) * @param unknown $length 连续加密多少位 * @return string */ function encryptShow( $str , $start , $length ) { $end = $start - 1 + $length ; $array = str_split ( $str ); foreach ( $array as $k => $v ) { if ( $k >= $start -1 && $k < $end ) { $array [ $k ] = '*' ; } } return implode( '' , $array ); } /** * 规范数据返回函数 * @param unknown $state * @param unknown $msg * @param unknown $data * @return multitype:unknown */ function callback( $state = true, $msg = '' , $data = array ()) { return array ( 'state' => $state , 'msg' => $msg , 'data' => $data ); } |
FTP.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | /** * 通过FTP同步图片到远程服务器 * * @param string $path 图片路径(upload/store/goods/4) * @param string $file 图片名称(含年月日2012/06/12/03f625d923bfb1ca84355007487ed68b.jpg) * @param boolean $ifdel 是否删除本地图片,目前淘宝导入的图片上传到远程时,不会删除本地图片 * @return string 远程图片路径部分 */ function remote_ftp( $path , $file , $ifdel = true){ ftpcmd( 'upload' , $path . '/' . $file ); $img_ext = explode ( ',' , GOODS_IMAGES_EXT); foreach ( $img_ext as $val ) { if (!ftpcmd( 'error' )) ftpcmd( 'upload' , $path . '/' . str_ireplace ( '.' , $val . '.' , $file )); } if (!ftpcmd( 'error' )) { if ( $ifdel ){ @unlink(BASE_PATH. '/' . $path . '/' . $file ); foreach ( $img_ext as $val ) { @unlink(BASE_PATH. '/' . $path . '/' . str_ireplace ( '.' , $val . '.' , $file )); } } return C( 'ftp_access_url' ). '/' . $path ; } return false; } function ftpcmd( $cmd , $arg1 = '' ) { import( 'libraries.ftp' ); static $ftp ; $ftpon = C( 'ftp_open' ); if (! $ftpon ) { return $cmd == 'error' ? -101 : 0; } elseif ( $ftp == null) { $ftp = & NcFtp::instance(); } if (! $ftp ->enabled) { return $ftp ->error(); } elseif ( $ftp ->enabled && ! $ftp ->connectid) { $ftp ->connect(); } switch ( $cmd ) { case 'upload' : return $ftp ->upload(BASE_PATH. '/' . $arg1 , $arg1 ); break ; case 'delete' : return $ftp ->ftp_delete( $arg1 ); break ; case 'close' : return $ftp ->ftp_close(); break ; case 'error' : return $ftp ->error(); break ; case 'object' : return $ftp ; break ; default : return false; } } function getremotefile( $file ) { @set_time_limit(0); $file = $file . '?' .time().rand(1000, 9999); $str = @implode( '' , @file( $file )); if (! $str ) { $str = dfsockopen( $file ); } return $str ; } function dfsockopen( $url , $limit = 0, $post = '' , $cookie = '' , $bysocket = FALSE, $ip = '' , $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE' , $allowcurl = TRUE) { return _dfsockopen( $url , $limit , $post , $cookie , $bysocket , $ip , $timeout , $block , $encodetype , $allowcurl ); } function _dfsockopen( $url , $limit = 0, $post = '' , $cookie = '' , $bysocket = FALSE, $ip = '' , $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE' , $allowcurl = TRUE) { $return = '' ; $matches = parse_url ( $url ); $scheme = $matches [ 'scheme' ]; $host = $matches [ 'host' ]; $path = $matches [ 'path' ] ? $matches [ 'path' ].( $matches [ 'query' ] ? '?' . $matches [ 'query' ] : '' ) : '/' ; $port = ! empty ( $matches [ 'port' ]) ? $matches [ 'port' ] : 80; if (function_exists( 'curl_init' ) && function_exists( 'curl_exec' ) && $allowcurl ) { $ch = curl_init(); $ip && curl_setopt( $ch , CURLOPT_HTTPHEADER, array ( "Host: " . $host )); curl_setopt( $ch , CURLOPT_URL, $scheme . '://' .( $ip ? $ip : $host ). ':' . $port . $path ); curl_setopt( $ch , CURLOPT_RETURNTRANSFER, 1); if ( $post ) { curl_setopt( $ch , CURLOPT_POST, 1); if ( $encodetype == 'URLENCODE' ) { curl_setopt( $ch , CURLOPT_POSTFIELDS, $post ); } else { parse_str ( $post , $postarray ); curl_setopt( $ch , CURLOPT_POSTFIELDS, $postarray ); } } if ( $cookie ) { curl_setopt( $ch , CURLOPT_COOKIE, $cookie ); } curl_setopt( $ch , CURLOPT_CONNECTTIMEOUT, $timeout ); curl_setopt( $ch , CURLOPT_TIMEOUT, $timeout ); $data = curl_exec( $ch ); $status = curl_getinfo( $ch ); $errno = curl_errno( $ch ); curl_close( $ch ); if ( $errno || $status [ 'http_code' ] != 200) { return ; } else { return ! $limit ? $data : substr ( $data , 0, $limit ); } } if ( $post ) { $out = "POST $path HTTP/1.0\r\n" ; $header = "Accept: */*\r\n" ; $header .= "Accept-Language: zh-cn\r\n" ; $boundary = $encodetype == 'URLENCODE' ? '' : '; boundary=' .trim( substr (trim( $post ), 2, strpos (trim( $post ), "\n" ) - 2)); $header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n" ; $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n" ; $header .= "Host: $host:$port\r\n" ; $header .= 'Content-Length: ' . strlen ( $post ). "\r\n" ; $header .= "Connection: Close\r\n" ; $header .= "Cache-Control: no-cache\r\n" ; $header .= "Cookie: $cookie\r\n\r\n" ; $out .= $header . $post ; } else { $out = "GET $path HTTP/1.0\r\n" ; $header = "Accept: */*\r\n" ; $header .= "Accept-Language: zh-cn\r\n" ; $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n" ; $header .= "Host: $host:$port\r\n" ; $header .= "Connection: Close\r\n" ; $header .= "Cookie: $cookie\r\n\r\n" ; $out .= $header ; } $fpflag = 0; if (! $fp = @fsocketopen(( $ip ? $ip : $host ), $port , $errno , $errstr , $timeout )) { $context = array ( 'http' => array ( 'method' => $post ? 'POST' : 'GET' , 'header' => $header , 'content' => $post , 'timeout' => $timeout , ), ); $context = stream_context_create( $context ); $fp = @ fopen ( $scheme . '://' .( $ip ? $ip : $host ). ':' . $port . $path , 'b' , false, $context ); $fpflag = 1; } if (! $fp ) { return '' ; } else { stream_set_blocking( $fp , $block ); stream_set_timeout( $fp , $timeout ); @fwrite( $fp , $out ); $status = stream_get_meta_data( $fp ); if (! $status [ 'timed_out' ]) { while (! feof ( $fp ) && ! $fpflag ) { if (( $header = @ fgets ( $fp )) && ( $header == "\r\n" || $header == "\n" )) { break ; } } $stop = false; while (! feof ( $fp ) && ! $stop ) { $data = fread ( $fp , ( $limit == 0 || $limit > 8192 ? 8192 : $limit )); $return .= $data ; if ( $limit ) { $limit -= strlen ( $data ); $stop = $limit <= 0; } } } @fclose( $fp ); return $return ; } } function fsocketopen( $hostname , $port = 80, & $errno , & $errstr , $timeout = 15) { $fp = '' ; if (function_exists( 'fsockopen' )) { $fp = @ fsockopen ( $hostname , $port , $errno , $errstr , $timeout ); } elseif (function_exists( 'pfsockopen' )) { $fp = @pfsockopen( $hostname , $port , $errno , $errstr , $timeout ); } elseif (function_exists( 'stream_socket_client' )) { $fp = @stream_socket_client( $hostname . ':' . $port , $errno , $errstr , $timeout ); } return $fp ; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
2017-06-28 tp5 日志管理