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: 2387: 2388: 2389: 2390: 2391: 2392: 2393: 2394: 2395: 2396: 2397: 2398: 2399: 2400: 2401: 2402: 2403: 2404: 2405: 2406: 2407: 2408: 2409: 2410: 2411: 2412: 2413: 2414: 2415: 2416: 2417: 2418: 2419: 2420: 2421: 2422: 2423: 2424: 2425: 2426: 2427: 2428: 2429: 2430: 2431: 2432: 2433: 2434: 2435: 2436: 2437: 2438: 2439: 2440: 2441: 2442: 2443: 2444: 2445: 2446: 2447: 2448: 2449: 2450: 2451: 2452: 2453: 2454: 2455: 2456: 2457: 2458: 2459: 2460: 2461: 2462: 2463: 2464: 2465: 2466: 2467: 2468: 2469: 2470: 2471: 2472: 2473: 2474: 2475: 2476: 2477: 2478: 2479: 2480: 2481: 2482: 2483: 2484: 2485: 2486: 2487: 2488: 2489: 2490: 2491: 2492: 2493: 2494: 2495: 2496: 2497: 2498: 2499: 2500: 2501: 2502: 2503: 2504: 2505: 2506: 2507: 2508: 2509: 2510: 2511: 2512: 2513: 2514: 2515: 2516: 2517: 2518: 2519: 2520: 2521: 2522: 2523: 2524: 2525: 2526: 2527: 2528: 2529: 2530: 2531: 2532: 2533: 2534: 2535: 2536: 2537: 2538: 2539: 2540: 2541: 2542: 2543: 2544: 2545: 2546: 2547: 2548: 2549: 2550: 2551: 2552: 2553: 2554: 2555: 2556: 2557: 2558: 2559: 2560: 2561: 2562: 2563: 2564: 2565: 2566: 2567: 2568: 2569: 2570: 2571: 2572: 2573: 2574: 2575: 2576: 2577: 2578: 2579: 2580: 2581: 2582: 2583: 2584: 2585: 2586: 2587: 2588: 2589: 2590: 2591: 2592: 2593: 2594: 2595: 2596: 2597: 2598: 2599: 2600: 2601: 2602: 2603: 2604: 2605: 2606: 2607: 2608: 2609: 2610: 2611: 2612: 2613: 2614: 2615: 2616: 2617: 2618: 2619: 2620: 2621: 2622: 2623: 2624: 2625: 2626: 2627: 2628: 2629: 2630: 2631: 2632: 2633: 2634: 2635: 2636: 2637: 2638: 2639: 2640: 2641: 2642: 2643: 2644: 2645: 2646: 2647: 2648: 2649: 2650: 2651: 2652: 2653: 2654: 2655: 2656: 2657: 2658: 2659: 2660: 2661: 2662: 2663: 2664: 2665: 2666: 2667: 2668: 2669: 2670: 2671: 2672: 2673: 2674: 2675: 2676: 2677: 2678: 2679: 2680: 2681: 2682: 2683: 2684: 2685: 2686: 2687: 2688: 2689: 2690: 2691: 2692: 2693: 2694: 2695: 2696: 2697: 2698: 2699: 2700: 2701: 2702: 2703: 2704: 2705: 2706: 2707: 2708: 2709: 2710: 2711: 2712: 2713: 2714: 2715: 2716: 2717: 2718: 2719: 2720: 2721: 2722: 2723: 2724: 2725: 2726: 2727: 2728: 2729: 2730: 2731: 2732: 2733: 2734: 2735: 2736: 2737: 2738: 2739: 2740: 2741: 2742: 2743: 2744: 2745: 2746: 2747: 2748: 2749: 2750: 2751: 2752: 2753: 2754: 2755: 2756: 2757: 2758: 2759: 2760: 2761: 2762: 2763: 2764: 2765: 2766: 2767: 2768: 2769: 2770: 2771: 2772: 2773: 2774: 2775: 2776: 2777: 2778: 2779: 2780: 2781: 2782: 2783: 2784: 2785: 2786: 2787: 2788: 2789: 2790: 2791: 2792: 2793: 2794: 2795: 2796: 2797: 2798: 2799: 2800: 2801: 2802: 2803: 2804: 2805: 2806: 2807: 2808: 2809: 2810: 2811: 2812: 2813: 2814: 2815: 2816: 2817: 2818: 2819: 2820: 2821: 2822: 2823: 2824: 2825: 2826: 2827: 2828: 2829: 2830: 2831: 2832: 2833: 2834: 2835: 2836: 2837: 2838: 2839: 2840: 2841: 2842: 2843: 2844: 2845: 2846: 2847: 2848: 2849: 2850: 2851: 2852: 2853: 2854: 2855: 2856: 2857: 2858: 2859: 2860: 2861: 2862: 2863: 2864: 2865: 2866: 2867: 2868: 2869: 2870: 2871: 2872: 2873: 2874: 2875: 2876: 2877: 2878: 2879: 2880: 2881: 2882: 2883: 2884: 2885: 2886: 2887: 2888: 2889: 2890: 2891: 2892: 2893: 2894: 2895: 2896: 2897: 2898: 2899: 2900: 2901: 2902: 2903: 2904: 2905: 2906: 2907: 2908: 2909: 2910: 2911: 2912: 2913: 2914: 2915: 2916: 2917: 2918: 2919: 2920: 2921: 2922: 2923: 2924: 2925: 2926: 2927: 2928: 2929: 2930: 2931: 2932: 2933: 2934: 2935: 2936: 2937: 2938: 2939: 2940: 2941: 2942: 2943: 2944: 2945: 2946: 2947: 2948: 2949: 2950: 2951: 2952: 2953: 2954: 2955: 2956: 2957: 2958: 2959: 2960: 2961: 2962: 2963: 2964: 2965: 2966: 2967: 2968: 2969: 2970: 2971: 2972: 2973: 2974: 2975: 2976: 2977: 2978: 2979: 2980: 2981: 2982: 2983: 2984: 2985: 2986: 2987: 2988: 2989: 2990: 2991: 2992: 2993: 2994: 2995: 2996: 2997: 2998: 2999: 3000: 3001: 3002: 3003: 3004: 3005: 3006: 3007: 3008: 3009: 3010: 3011: 3012: 3013: 3014: 3015: 3016: 3017: 3018: 3019: 3020: 3021: 3022: 3023: 3024: 3025: 3026: 3027: 3028: 3029: 3030: 3031: 3032: 3033: 3034: 3035: 3036: 3037: 3038: 3039: 3040: 3041: 3042: 3043: 3044: 3045: 3046: 3047: 3048: 3049: 3050: 3051: 3052: 3053: 3054: 3055: 3056: 3057: 3058: 3059: 3060: 3061: 3062: 3063: 3064: 3065: 3066: 3067: 3068: 3069: 3070: 3071: 3072: 3073: 3074: 3075: 3076: 3077: 3078: 3079: 3080: 3081: 3082: 3083: 3084: 3085: 3086: 3087: 3088: 3089: 3090: 3091: 3092: 3093: 3094: 3095: 3096: 3097: 3098: 3099: 3100: 3101: 3102: 3103: 3104: 3105: 3106: 3107: 3108: 3109: 3110: 3111: 3112: 3113: 3114: 3115: 3116: 3117: 3118: 3119: 3120: 3121: 3122: 3123: 3124: 3125: 3126: 3127: 3128: 3129: 3130: 3131: 3132: 3133: 3134: 3135: 3136: 3137: 3138: 3139: 3140: 3141: 3142: 3143: 3144: 3145: 3146: 3147: 3148: 3149: 3150: 3151: 3152: 3153: 3154: 3155: 3156: 3157: 3158: 3159: 3160: 3161: 3162: 3163: 3164: 3165: 3166: 3167: 3168: 3169: 3170: 3171: 3172: 3173: 3174: 3175: 3176: 3177: 3178: 3179: 3180: 3181: 3182: 3183: 3184: 3185: 3186: 3187: 3188: 3189: 3190: 3191: 3192: 3193: 3194: 3195: 3196: 3197: 3198: 3199: 3200: 3201: 3202: 3203: 3204: 3205: 3206: 3207: 3208: 3209: 3210: 3211: 3212: 3213: 3214: 3215: 3216: 3217: 3218: 3219: 3220: 3221: 3222: 3223: 3224: 3225: 3226: 3227: 3228: 3229: 3230: 3231: 3232: 3233: 3234: 3235: 3236: 3237: 3238: 3239: 3240: 3241: 3242: 3243: 3244: 3245: 3246: 3247: 3248: 3249: 3250: 3251: 3252: 3253: 3254: 3255: 3256: 3257: 3258: 3259: 3260: 3261: 3262: 3263: 3264: 3265: 3266: 3267: 3268: 3269: 3270: 3271: 3272: 3273: 3274: 3275: 3276: 3277: 3278: 3279: 3280: 3281: 3282: 3283: 3284: 3285: 3286: 3287: 3288: 3289: 3290: 3291: 3292: 3293: 3294: 3295: 3296: 3297: 3298: 3299: 3300: 3301: 3302: 3303: 3304: 3305: 3306: 3307: 3308: 3309: 3310: 3311: 3312: 3313: 3314: 3315: 3316: 3317: 3318: 3319: 3320: 3321: 3322: 3323: 3324: 3325: 3326: 3327: 3328: 3329: 3330: 3331: 3332: 3333: 3334: 3335: 3336: 3337: 3338: 3339: 3340: 3341: 3342: 3343: 3344: 3345: 3346: 3347: 3348: 3349: 3350: 3351: 3352: 3353: 3354: 3355: 3356: 3357: 3358: 3359: 3360: 3361: 3362: 3363: 3364: 3365: 3366: 3367: 3368: 3369: 3370: 3371: 3372: 3373: 3374: 3375: 3376: 3377: 3378: 3379: 3380: 3381: 3382: 3383: 3384: 3385: 3386: 3387: 3388: 3389: 3390: 3391: 3392: 3393: 3394: 3395: 3396: 3397: 3398: 3399: 3400: 3401: 3402: 3403: 3404: 3405: 3406: 3407: 3408: 3409: 3410: 3411: 3412: 3413: 3414: 3415: 3416: 3417: 3418: 3419: 3420: 3421: 3422: 3423: 3424: 3425: 3426: 3427: 3428: 3429: 3430: 3431: 3432: 3433: 3434: 3435: 3436: 3437: 3438: 3439: 3440: 3441: 3442: 3443: 3444: 3445: 3446: 3447: 3448: 3449: 3450: 3451: 3452: 3453: 3454: 3455: 3456: 3457: 3458: 3459: 3460: 3461: 3462: 3463: 3464: 3465: 3466: 3467: 3468: 3469: 3470: 3471: 3472: 3473: 3474: 3475: 3476: 3477: 3478: 3479: 3480: 3481: 3482: 3483: 3484: 3485: 3486: 3487: 3488: 3489: 3490: 3491: 3492: 3493: 3494: 3495: 3496: 3497: 3498: 3499: 3500: 3501: 3502: 3503: 3504: 3505: 3506: 3507: 3508: 3509: 3510: 3511: 3512: 3513: 3514: 3515: 3516: 3517: 3518: 3519: 3520: 3521: 3522: 3523: 3524: 3525: 3526: 3527: 3528: 3529: 3530: 3531: 3532: 3533: 3534: 3535: 3536: 3537: 3538: 3539: 3540: 3541: 3542: 3543: 3544: 3545: 3546: 3547: 3548: 3549: 3550: 3551: 3552: 3553: 3554: 3555: 3556: 3557: 3558: 3559: 3560: 3561: 3562: 3563: 3564: 3565: 3566: 3567: 3568: 3569: 3570: 3571: 3572: 3573: 3574: 3575: 3576: 3577: 3578: 3579: 3580: 3581: 3582: 3583: 3584: 3585: 3586: 3587: 3588: 3589: 3590: 3591: 3592: 3593: 3594: 3595: 3596: 3597: 3598: 3599: 3600: 3601: 3602: 3603: 3604: 3605: 3606: 3607: 3608: 3609: 3610: 3611: 3612: 3613: 3614: 3615: 3616: 3617: 3618: 3619: 3620: 3621: 3622: 3623: 3624: 3625: 3626: 3627: 3628: 3629: 3630: 3631: 3632: 3633: 3634: 3635: 3636: 3637: 3638: 3639: 3640: 3641: 3642: 3643: 3644: 3645: 3646: 3647: 3648: 3649: 3650: 3651: 3652: 3653: 3654: 3655: 3656: 3657: 3658: 3659: 3660: 3661: 3662: 3663: 3664: 3665: 3666: 3667: 3668: 3669: 3670: 3671: 3672: 3673: 3674: 3675: 3676: 3677: 3678: 3679: 3680: 3681: 3682: 3683: 3684: 3685: 3686: 3687: 3688: 3689: 3690: 3691: 3692: 3693: 3694: 3695: 3696: 3697: 3698: 3699: 3700: 3701: 3702: 3703: 3704: 3705: 3706: 3707: 3708: 3709: 3710: 3711: 3712: 3713: 3714: 3715: 3716: 3717: 3718: 3719: 3720: 3721: 3722: 3723: 3724: 3725: 3726: 3727: 3728: 3729: 3730: 3731: 3732: 3733: 3734: 3735: 3736: 3737: 3738: 3739: 3740: 3741: 3742: 3743: 3744: 3745: 3746: 3747: 3748: 3749: 3750: 3751: 3752: 3753: 3754: 3755: 3756: 3757: 3758: 3759: 3760: 3761: 3762: 3763: 3764: 3765: 3766: 3767: 3768: 3769: 3770: 3771: 3772: 3773: 3774: 3775: 3776: 3777: 3778: 3779: 3780: 3781: 3782: 3783: 3784: 3785: 3786: 3787: 3788: 3789: 3790: 3791: 3792: 3793: 3794: 3795: 3796: 3797: 3798: 3799: 3800: 3801: 3802: 3803: 3804: 3805: 3806: 3807: 3808: 3809: 3810: 3811: 3812: 3813: 3814: 3815: 3816: 3817: 3818: 3819: 3820: 3821: 3822: 3823: 3824: 3825: 3826: 3827: 3828: 3829: 3830: 3831: 3832: 3833: 3834: 3835: 3836: 3837: 3838: 3839: 3840: 3841: 3842: 3843: 3844: 3845: 3846: 3847: 3848: 3849: 3850: 3851: 3852: 3853: 3854: 3855: 3856: 3857: 3858: 3859: 3860: 3861: 3862: 3863: 3864: 3865: 3866: 3867: 3868: 3869: 3870: 3871: 3872: 3873: 3874: 3875: 3876: 3877: 3878: 3879: 3880: 3881: 3882: 3883: 3884: 3885: 3886: 3887: 3888: 3889: 3890: 3891: 3892: 3893: 3894: 3895: 3896: 3897: 3898: 3899: 3900: 3901: 3902: 3903: 3904: 3905: 3906: 3907: 3908: 3909: 3910: 3911: 3912: 3913: 3914: 3915: 3916: 3917: 3918: 3919: 3920: 3921: 3922: 3923: 3924: 3925: 3926: 3927: 3928: 3929: 3930: 3931: 3932: 3933: 3934: 3935: 3936: 3937: 3938: 3939: 3940: 3941: 3942: 3943: 3944: 3945: 3946: 3947: 3948: 3949: 3950: 3951: 3952: 3953: 3954: 3955: 3956: 3957: 3958: 3959: 3960: 3961: 3962: 3963: 3964: 3965: 3966: 3967: 3968: 3969: 3970: 3971: 3972: 3973: 3974: 3975: 3976: 3977: 3978: 3979: 3980: 3981: 3982: 3983: 3984: 3985: 3986: 3987: 3988: 3989: 3990: 3991: 3992: 3993: 3994: 3995: 3996: 3997: 3998: 3999: 4000: 4001: 4002: 4003: 4004: 4005: 4006: 4007: 4008: 4009: 4010: 4011: 4012: 4013: 4014: 4015: 4016: 4017: 4018: 4019: 4020: 4021: 4022: 4023: 4024: 4025: 4026: 4027: 4028: 4029: 4030: 4031: 4032: 4033: 4034: 4035: 4036: 4037: 4038: 4039: 4040: 4041: 4042: 4043: 4044: 4045: 4046: 4047: 4048: 4049: 4050: 4051: 4052: 4053: 4054: 4055: 4056: 4057: 4058: 4059: 4060: 4061: 4062: 4063: 4064: 4065: 4066: 4067: 4068: 4069: 4070: 4071: 4072: 4073: 4074: 4075: 4076: 4077: 4078: 4079: 4080: 4081: 4082: 4083: 4084: 4085: 4086: 4087: 4088: 4089: 4090: 4091: 4092: 4093: 4094: 4095: 4096: 4097: 4098: 4099: 4100: 4101: 4102: 4103: 4104: 4105: 4106: 4107: 4108: 4109: 4110: 4111: 4112: 4113: 4114: 4115: 4116: 4117: 4118: 4119: 4120: 4121: 4122: 4123: 4124: 4125: 4126: 4127: 4128: 4129: 4130: 4131: 4132: 4133: 4134: 4135: 4136: 4137: 4138: 4139: 4140: 4141: 4142: 4143: 4144: 4145: 4146: 4147: 4148: 4149: 4150: 4151: 4152: 4153: 4154: 4155: 4156: 4157: 4158: 4159: 4160: 4161: 4162: 4163: 4164: 4165: 4166: 4167: 4168: 4169: 4170: 4171: 4172: 4173: 4174: 4175: 4176: 4177: 4178: 4179: 4180: 4181: 4182: 4183: 4184: 4185: 4186: 4187: 4188: 4189: 4190: 4191: 4192: 4193: 4194: 4195: 4196: 4197: 4198: 4199: 4200: 4201: 4202: 4203: 4204: 4205: 4206: 4207: 4208: 4209: 4210: 4211: 4212: 4213: 4214: 4215: 4216: 4217: 4218: 4219: 4220: 4221: 4222: 4223: 4224: 4225: 4226: 4227: 4228: 4229: 4230: 4231: 4232: 4233: 4234: 4235: 4236: 4237: 4238: 4239: 4240: 4241: 4242: 4243: 4244: 4245: 4246: 4247: 4248: 4249: 4250: 4251: 4252: 4253: 4254: 4255: 4256: 4257: 4258: 4259: 4260: 4261: 4262: 4263: 4264: 4265: 4266: 4267: 4268: 4269: 4270: 4271: 4272: 4273: 4274: 4275: 4276: 4277: 4278: 4279: 4280: 4281: 4282: 4283: 4284: 4285: 4286: 4287: 4288: 4289: 4290: 4291: 4292: 4293: 4294: 4295: 4296: 4297: 4298: 4299: 4300: 4301: 4302: 4303: 4304: 4305: 4306: 4307: 4308: 4309: 4310: 4311: 4312: 4313: 4314: 4315: 4316: 4317: 4318: 4319: 4320: 4321: 4322: 4323: 4324: 4325: 4326: 4327: 4328: 4329: 4330: 4331: 4332: 4333: 4334: 4335: 4336: 4337: 4338: 4339: 4340: 4341: 4342: 4343: 4344: 4345: 4346: 4347: 4348: 4349: 4350: 4351: 4352: 4353: 4354: 4355: 4356: 4357: 4358: 4359: 4360: 4361: 4362: 4363: 4364: 4365: 4366: 4367: 4368: 4369: 4370: 4371: 4372: 4373: 4374: 4375: 4376: 4377: 4378: 4379:
<?php
if (!defined('SMF'))
die('No direct access...');
function loadProfileFields($force_reload = false)
{
global $context, $profile_fields, $txt, $scripturl, $modSettings, $user_info, $smcFunc, $cur_profile, $language;
global $sourcedir, $profile_vars, $settings;
if (!empty($profile_fields) && !$force_reload)
return;
$profile_fields = array(
'avatar_choice' => array(
'type' => 'callback',
'callback_func' => 'avatar_select',
'preload' => 'profileLoadAvatarData',
'input_validate' => 'profileSaveAvatarData',
'save_key' => 'avatar',
),
'bday1' => array(
'type' => 'callback',
'callback_func' => 'birthdate',
'permission' => 'profile_extra',
'preload' => function() use ($cur_profile, &$context)
{
list ($uyear, $umonth, $uday) = explode('-', empty($cur_profile['birthdate']) || $cur_profile['birthdate'] === '1004-01-01' ? '--' : $cur_profile['birthdate']);
$context['member']['birth_date'] = array(
'year' => $uyear,
'month' => $umonth,
'day' => $uday,
);
return true;
},
'input_validate' => function(&$value) use (&$cur_profile, &$profile_vars)
{
if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0)
{
if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1)
$value = '1004-01-01';
else
$value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 1004 ? 1004 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '1004-01-01';
}
else
$value = '1004-01-01';
$profile_vars['birthdate'] = $value;
$cur_profile['birthdate'] = $value;
return false;
},
),
'birthdate' => array(
'type' => 'hidden',
'permission' => 'profile_extra',
'input_validate' => function(&$value) use ($cur_profile)
{
if (preg_match('/(\d{4})[\-\., ](\d{2})[\-\., ](\d{2})/', $value, $dates) === 1)
{
$value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '1004-01-01';
return true;
}
else
{
$value = empty($cur_profile['birthdate']) ? '1004-01-01' : $cur_profile['birthdate'];
return false;
}
},
),
'date_registered' => array(
'type' => 'date',
'value' => empty($cur_profile['date_registered']) ? $txt['not_applicable'] : strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
'label' => $txt['date_registered'],
'log_change' => true,
'permission' => 'moderate_forum',
'input_validate' => function(&$value) use ($txt, $user_info, $modSettings, $cur_profile, $context)
{
if (($value = strtotime($value)) === false)
{
$value = $cur_profile['date_registered'];
return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false));
}
elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600)))
$value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
else
$value = $cur_profile['date_registered'];
return true;
},
),
'email_address' => array(
'type' => 'email',
'label' => $txt['user_email_address'],
'subtext' => $txt['valid_email'],
'log_change' => true,
'permission' => 'profile_password',
'js_submit' => !empty($modSettings['send_validation_onChange']) ? '
form_handle.addEventListener(\'submit\', function(event)
{
if (this.email_address.value != "' . (!empty($cur_profile['email_address']) ? $cur_profile['email_address'] : '') . '")
{
alert(' . JavaScriptEscape($txt['email_change_logout']) . ');
return true;
}
}, false);' : '',
'input_validate' => function(&$value)
{
global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
if (strtolower($value) == strtolower($old_profile['email_address']))
return false;
$isValid = profileValidateEmail($value, $context['id_member']);
if ($isValid === true && !empty($modSettings['send_validation_onChange']) && !allowedTo('moderate_forum'))
{
require_once($sourcedir . '/Subs-Members.php');
$profile_vars['validation_code'] = generateValidationCode();
$profile_vars['is_activated'] = 2;
$context['profile_execute_on_save'][] = 'profileSendActivation';
unset($context['profile_execute_on_save']['reload_user']);
}
return $isValid;
},
),
'id_group' => array(
'type' => 'callback',
'callback_func' => 'group_manage',
'permission' => 'manage_membergroups',
'preload' => 'profileLoadGroups',
'log_change' => true,
'input_validate' => 'profileSaveGroups',
),
'id_theme' => array(
'type' => 'callback',
'callback_func' => 'theme_pick',
'permission' => 'profile_extra',
'enabled' => $modSettings['theme_allow'] || allowedTo('admin_forum'),
'preload' => function() use ($smcFunc, &$context, $cur_profile, $txt)
{
$request = $smcFunc['db_query']('', '
SELECT value
FROM {db_prefix}themes
WHERE id_theme = {int:id_theme}
AND variable = {string:variable}
LIMIT 1', array(
'id_theme' => $cur_profile['id_theme'],
'variable' => 'name',
)
);
list ($name) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
$context['member']['theme'] = array(
'id' => $cur_profile['id_theme'],
'name' => empty($cur_profile['id_theme']) ? $txt['theme_forum_default'] : $name
);
return true;
},
'input_validate' => function(&$value)
{
$value = (int) $value;
return true;
},
),
'lngfile' => array(
'type' => 'select',
'options' => function() use (&$context)
{
return $context['profile_languages'];
},
'label' => $txt['preferred_language'],
'permission' => 'profile_identity',
'preload' => 'profileLoadLanguages',
'enabled' => !empty($modSettings['userLanguage']),
'value' => empty($cur_profile['lngfile']) ? $language : $cur_profile['lngfile'],
'input_validate' => function(&$value) use (&$context, $cur_profile)
{
profileLoadLanguages();
if (isset($context['profile_languages'][$value]))
{
if ($context['user']['is_owner'] && empty($context['password_auth_failed']))
$_SESSION['language'] = $value;
return true;
}
else
{
$value = $cur_profile['lngfile'];
return false;
}
},
),
'member_name' => array(
'type' => allowedTo('admin_forum') && isset($_GET['changeusername']) ? 'text' : 'label',
'label' => $txt['username'],
'subtext' => allowedTo('admin_forum') && !isset($_GET['changeusername']) ? '[<a href="' . $scripturl . '?action=profile;u=' . $context['id_member'] . ';area=account;changeusername" style="font-style: italic;">' . $txt['username_change'] . '</a>]' : '',
'log_change' => true,
'permission' => 'profile_identity',
'prehtml' => allowedTo('admin_forum') && isset($_GET['changeusername']) ? '<div class="alert">' . $txt['username_warning'] . '</div>' : '',
'input_validate' => function(&$value) use ($sourcedir, $context, $user_info, $cur_profile)
{
if (allowedTo('admin_forum'))
{
require_once($sourcedir . '/Subs-Auth.php');
$resetPassword = true;
if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null)
$resetPassword = false;
if ($resetPassword)
resetPassword($context['id_member'], $value);
elseif ($value !== null)
{
validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)));
updateMemberData($context['id_member'], array('member_name' => $value));
call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $value, $_POST['passwrd1']));
}
}
return false;
},
),
'passwrd1' => array(
'type' => 'password',
'label' => ucwords($txt['choose_pass']),
'subtext' => $txt['password_strength'],
'size' => 20,
'value' => '',
'permission' => 'profile_password',
'save_key' => 'passwd',
'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile)
{
if ($value == '')
return false;
if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2'])
return 'bad_new_password';
require_once($sourcedir . '/Subs-Auth.php');
$passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email']));
if ($passwordErrors != null)
return 'password_' . $passwordErrors;
$value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value));
return true;
},
),
'passwrd2' => array(
'type' => 'password',
'label' => ucwords($txt['verify_pass']),
'size' => 20,
'value' => '',
'permission' => 'profile_password',
'is_dummy' => true,
),
'personal_text' => array(
'type' => 'text',
'label' => $txt['personal_text'],
'log_change' => true,
'input_attr' => array('maxlength="50"'),
'size' => 50,
'permission' => 'profile_blurb',
'input_validate' => function(&$value) use ($smcFunc)
{
if ($smcFunc['strlen']($value) > 50)
return 'personal_text_too_long';
return true;
},
),
'pm_prefs' => array(
'type' => 'callback',
'callback_func' => 'pm_settings',
'permission' => 'pm_read',
'preload' => function() use (&$context, $cur_profile)
{
$context['display_mode'] = $cur_profile['pm_prefs'] & 3;
$context['receive_from'] = !empty($cur_profile['pm_receive_from']) ? $cur_profile['pm_receive_from'] : 0;
return true;
},
'input_validate' => function(&$value) use (&$cur_profile, &$profile_vars)
{
$value = max(min($value, 2), 0);
$cur_profile['pm_receive_from'] = $profile_vars['pm_receive_from'] = max(min((int) $_POST['pm_receive_from'], 4), 0);
return true;
},
),
'posts' => array(
'type' => 'int',
'label' => $txt['profile_posts'],
'log_change' => true,
'size' => 7,
'permission' => 'moderate_forum',
'input_validate' => function(&$value)
{
if (!is_numeric($value))
return 'digits_only';
else
$value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0;
return true;
},
),
'real_name' => array(
'type' => allowedTo('profile_displayed_name_own') || allowedTo('profile_displayed_name_any') || allowedTo('moderate_forum') ? 'text' : 'label',
'label' => $txt['name'],
'subtext' => $txt['display_name_desc'],
'log_change' => true,
'input_attr' => array('maxlength="60"'),
'permission' => 'profile_displayed_name',
'enabled' => allowedTo('profile_displayed_name_own') || allowedTo('profile_displayed_name_any') || allowedTo('moderate_forum'),
'input_validate' => function(&$value) use ($context, $smcFunc, $sourcedir, $cur_profile)
{
$value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value));
if (trim($value) == '')
return 'no_name';
elseif ($smcFunc['strlen']($value) > 60)
return 'name_too_long';
elseif ($cur_profile['real_name'] != $value)
{
require_once($sourcedir . '/Subs-Members.php');
if (isReservedName($value, $context['id_member']))
return 'name_taken';
}
return true;
},
),
'secret_question' => array(
'type' => 'text',
'label' => $txt['secret_question'],
'subtext' => $txt['secret_desc'],
'size' => 50,
'permission' => 'profile_password',
),
'secret_answer' => array(
'type' => 'text',
'label' => $txt['secret_answer'],
'subtext' => $txt['secret_desc2'],
'size' => 20,
'postinput' => '<span class="smalltext"><a href="' . $scripturl . '?action=helpadmin;help=secret_why_blank" onclick="return reqOverlayDiv(this.href);"><span class="main_icons help"></span> ' . $txt['secret_why_blank'] . '</a></span>',
'value' => '',
'permission' => 'profile_password',
'input_validate' => function(&$value) use ($cur_profile)
{
$value = $value != '' ? hash_password($cur_profile['member_name'], $value) : '';
return true;
},
),
'signature' => array(
'type' => 'callback',
'callback_func' => 'signature_modify',
'permission' => 'profile_signature',
'enabled' => substr($modSettings['signature_settings'], 0, 1) == 1,
'preload' => 'profileLoadSignatureData',
'input_validate' => 'profileValidateSignature',
),
'show_online' => array(
'type' => 'check',
'label' => $txt['show_online'],
'permission' => 'profile_identity',
'enabled' => !empty($modSettings['allow_hideOnline']) || allowedTo('moderate_forum'),
),
'smiley_set' => array(
'type' => 'callback',
'callback_func' => 'smiley_pick',
'enabled' => !empty($modSettings['smiley_sets_enable']),
'permission' => 'profile_extra',
'preload' => function() use ($modSettings, &$context, &$txt, $cur_profile, $smcFunc, $settings, $language)
{
$context['member']['smiley_set']['id'] = empty($cur_profile['smiley_set']) ? '' : $cur_profile['smiley_set'];
$context['smiley_sets'] = explode(',', 'none,,' . $modSettings['smiley_sets_known']);
$set_names = explode("\n", $txt['smileys_none'] . "\n" . $txt['smileys_forum_board_default'] . "\n" . $modSettings['smiley_sets_names']);
$filenames = array();
$result = $smcFunc['db_query']('', '
SELECT f.filename, f.smiley_set
FROM {db_prefix}smiley_files AS f
JOIN {db_prefix}smileys AS s ON (s.id_smiley = f.id_smiley)
WHERE s.code = {string:smiley}',
array(
'smiley' => ':)',
)
);
while ($row = $smcFunc['db_fetch_assoc']($result))
$filenames[$row['smiley_set']] = $row['filename'];
$smcFunc['db_free_result']($result);
$no_smiley_sets = array_diff(explode(',', $modSettings['smiley_sets_known']), array_keys($filenames));
foreach ($no_smiley_sets as $set)
{
$allowedTypes = array('gif', 'png', 'jpg', 'jpeg', 'tiff', 'svg');
$images = glob(implode('/', array($modSettings['smileys_dir'], $set, '*.{' . (implode(',', $allowedTypes) . '}'))), GLOB_BRACE);
if (!empty($images))
{
$image = array_pop($images);
$filenames[$set] = pathinfo($image, PATHINFO_BASENAME);
}
else
{
loadLanguage('Errors', $language);
log_error(sprintf($txt['smiley_set_dir_not_found'], $set_names[array_search($set, $context['smiley_sets'])]));
$context['smiley_sets'] = array_filter($context['smiley_sets'], function($v) use ($set)
{
return $v != $set;
});
}
}
foreach ($context['smiley_sets'] as $i => $set)
{
$context['smiley_sets'][$i] = array(
'id' => $smcFunc['htmlspecialchars']($set),
'name' => $smcFunc['htmlspecialchars']($set_names[$i]),
'selected' => $set == $context['member']['smiley_set']['id']
);
if ($set === 'none')
$context['smiley_sets'][$i]['preview'] = $settings['images_url'] . '/blank.png';
elseif ($set === '')
{
$default_set = !empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default'];
$context['smiley_sets'][$i]['preview'] = implode('/', array($modSettings['smileys_url'], $default_set, $filenames[$default_set]));
}
else
$context['smiley_sets'][$i]['preview'] = implode('/', array($modSettings['smileys_url'], $set, $filenames[$set]));
if ($context['smiley_sets'][$i]['selected'])
{
$context['member']['smiley_set']['name'] = $set_names[$i];
$context['member']['smiley_set']['preview'] = $context['smiley_sets'][$i]['preview'];
}
$context['smiley_sets'][$i]['preview'] = $smcFunc['htmlspecialchars']($context['smiley_sets'][$i]['preview']);
}
return true;
},
'input_validate' => function(&$value)
{
global $modSettings;
$smiley_sets = explode(',', $modSettings['smiley_sets_known']);
if (!in_array($value, $smiley_sets) && $value != 'none')
$value = '';
return true;
},
),
'theme_settings' => array(
'type' => 'callback',
'callback_func' => 'theme_settings',
'permission' => 'profile_extra',
'is_dummy' => true,
'preload' => function() use (&$context, $user_info, $modSettings)
{
loadLanguage('Settings');
$context['allow_no_censored'] = false;
if ($user_info['is_admin'] || $context['user']['is_owner'])
$context['allow_no_censored'] = !empty($modSettings['allow_no_censored']);
return true;
},
),
'tfa' => array(
'type' => 'callback',
'callback_func' => 'tfa',
'permission' => 'profile_password',
'enabled' => !empty($modSettings['tfa_mode']),
'preload' => function() use (&$context, $cur_profile)
{
$context['tfa_enabled'] = !empty($cur_profile['tfa_secret']);
return true;
},
),
'time_format' => array(
'type' => 'callback',
'callback_func' => 'timeformat_modify',
'permission' => 'profile_extra',
'preload' => function() use (&$context, $user_info, $txt, $cur_profile, $modSettings)
{
$context['easy_timeformats'] = array(
array('format' => '', 'title' => $txt['timeformat_default']),
array('format' => '%B %d, %Y, %I:%M:%S %p', 'title' => $txt['timeformat_easy1']),
array('format' => '%B %d, %Y, %H:%M:%S', 'title' => $txt['timeformat_easy2']),
array('format' => '%Y-%m-%d, %H:%M:%S', 'title' => $txt['timeformat_easy3']),
array('format' => '%d %B %Y, %H:%M:%S', 'title' => $txt['timeformat_easy4']),
array('format' => '%d-%m-%Y, %H:%M:%S', 'title' => $txt['timeformat_easy5'])
);
$context['member']['time_format'] = $cur_profile['time_format'];
$context['current_forum_time'] = timeformat(time() - $user_info['time_offset'] * 3600, false);
$context['current_forum_time_js'] = strftime('%Y,' . ((int) strftime('%m', time() + $modSettings['time_offset'] * 3600) - 1) . ',%d,%H,%M,%S', time() + $modSettings['time_offset'] * 3600);
$context['current_forum_time_hour'] = (int) strftime('%H', forum_time(false));
return true;
},
),
'timezone' => array(
'type' => 'select',
'options' => smf_list_timezones(),
'disabled_options' => array_filter(array_keys(smf_list_timezones()), 'is_int'),
'permission' => 'profile_extra',
'label' => $txt['timezone'],
'value' => empty($cur_profile['timezone']) ? $modSettings['default_timezone'] : $cur_profile['timezone'],
'input_validate' => function($value)
{
$tz = smf_list_timezones();
if (!isset($tz[$value]))
return 'bad_timezone';
return true;
},
),
'usertitle' => array(
'type' => 'text',
'label' => $txt['custom_title'],
'log_change' => true,
'input_attr' => array('maxlength="50"'),
'size' => 50,
'permission' => 'profile_title',
'enabled' => !empty($modSettings['titlesEnable']),
'input_validate' => function(&$value) use ($smcFunc)
{
if ($smcFunc['strlen']($value) > 50)
return 'user_title_too_long';
return true;
},
),
'website_title' => array(
'type' => 'text',
'label' => $txt['website_title'],
'subtext' => $txt['include_website_url'],
'size' => 50,
'permission' => 'profile_website',
'link_with' => 'website',
),
'website_url' => array(
'type' => 'url',
'label' => $txt['website_url'],
'subtext' => $txt['complete_url'],
'size' => 50,
'permission' => 'profile_website',
'input_validate' => function(&$value)
{
if (strlen(trim($value)) > 0 && strpos($value, '://') === false)
$value = 'http://' . $value;
if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://'))
$value = '';
$value = (string) validate_iri(sanitize_iri($value));
return true;
},
'link_with' => 'website',
),
);
call_integration_hook('integrate_load_profile_fields', array(&$profile_fields));
$disabled_fields = !empty($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array();
foreach ($profile_fields as $key => $field)
{
if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission']))
unset($profile_fields[$key]);
if (isset($field['enabled']) && !$field['enabled'])
unset($profile_fields[$key]);
if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields)))
unset($profile_fields[$key]);
}
}
function setupProfileContext($fields)
{
global $profile_fields, $context, $cur_profile, $txt;
$context['profile_prehtml'] = '';
$context['profile_posthtml'] = '';
$context['profile_javascript'] = '';
$context['profile_onsubmit_javascript'] = '';
call_integration_hook('integrate_setup_profile_context', array(&$fields));
loadProfileFields(true);
foreach ($profile_fields as $key => $field)
if (isset($field['link_with']) && in_array($field['link_with'], $fields))
$fields[] = $key;
$i = 0;
$last_type = '';
foreach ($fields as $key => $field)
{
if (isset($profile_fields[$field]))
{
$cur_field = &$profile_fields[$field];
if (isset($cur_field['preload']) && !$cur_field['preload']())
continue;
if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden')
{
if (!isset($cur_field['label']))
$cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field;
if (!isset($cur_field['value']))
$cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : '';
$cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : '';
}
if (isset($context['profile_errors'][$field]))
$cur_field['is_error'] = true;
if (!empty($cur_field['js_submit']))
$context['profile_onsubmit_javascript'] .= $cur_field['js_submit'];
if (!empty($cur_field['js']))
$context['profile_javascript'] .= $cur_field['js'];
if (!empty($cur_field['prehtml']))
$context['profile_prehtml'] .= $cur_field['prehtml'];
if (!empty($cur_field['posthtml']))
$context['profile_posthtml'] .= $cur_field['posthtml'];
if ($cur_field['type'] != 'hidden')
{
$last_type = $cur_field['type'];
$context['profile_fields'][$field] = &$profile_fields[$field];
}
}
elseif ($field == 'hr' && $last_type != 'hr' && $last_type != '')
{
$last_type = 'hr';
$context['profile_fields'][$i++]['type'] = 'hr';
}
}
addInlineJavaScript('
var form_handle = document.forms.creator;
createEventListener(form_handle);
' . (!empty($context['require_password']) ? '
form_handle.addEventListener(\'submit\', function(event)
{
if (this.oldpasswrd.value == "")
{
event.preventDefault();
alert(' . (JavaScriptEscape($txt['required_security_reasons'])) . ');
return false;
}
}, false);' : ''), true);
if (!empty($context['profile_onsubmit_javascript']))
addInlineJavaScript($context['profile_onsubmit_javascript'], true);
if (!empty($context['profile_javascript']))
addInlineJavaScript($context['profile_javascript'], true);
unset($profile_fields);
}
function saveProfileFields()
{
global $profile_fields, $profile_vars, $context, $old_profile, $post_errors, $cur_profile;
loadProfileFields();
$old_profile = $cur_profile;
$context['profile_execute_on_save'] = array();
if ($context['user']['is_owner'])
$context['profile_execute_on_save']['reload_user'] = 'profileReloadUser';
$context['log_changes'] = array();
foreach ($profile_fields as $key => $field)
{
if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature'))
continue;
$db_key = isset($field['save_key']) ? $field['save_key'] : $key;
if (isset($field['input_validate']))
{
$is_valid = $field['input_validate']($_POST[$key]);
if ($is_valid !== true)
{
if ($is_valid !== false)
{
$post_errors[$key] = $is_valid;
$profile_fields[$key]['is_error'] = $is_valid;
}
$cur_profile[$key] = $_POST[$key];
continue;
}
}
$field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type'];
if ($field['cast_type'] == 'int')
$_POST[$key] = (int) $_POST[$key];
elseif ($field['cast_type'] == 'float')
$_POST[$key] = (float) $_POST[$key];
elseif ($field['cast_type'] == 'check')
$_POST[$key] = !empty($_POST[$key]) ? 1 : 0;
if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key]))
{
$profile_vars[$db_key] = $_POST[$key];
$cur_profile[$key] = $_POST[$key];
if (!empty($field['log_change']) && isset($old_profile[$key]))
$context['log_changes'][$key] = array(
'previous' => $old_profile[$key],
'new' => $_POST[$key],
);
}
if ($key == 'id_group' && $field['log_change'])
{
profileLoadGroups();
if ($_POST['id_group'] != $old_profile['id_group'])
{
$context['log_changes']['id_group'] = array(
'previous' => !empty($old_profile[$key]) && isset($context['member_groups'][$old_profile[$key]]) ? $context['member_groups'][$old_profile[$key]]['name'] : '',
'new' => !empty($_POST[$key]) && isset($context['member_groups'][$_POST[$key]]) ? $context['member_groups'][$_POST[$key]]['name'] : '',
);
}
$additional_groups = array(
'previous' => !empty($old_profile['additional_groups']) ? explode(',', $old_profile['additional_groups']) : array(),
'new' => !empty($_POST['additional_groups']) ? array_diff($_POST['additional_groups'], array(0)) : array(),
);
sort($additional_groups['previous']);
sort($additional_groups['new']);
if ($additional_groups['previous'] != $additional_groups['new'])
{
foreach ($additional_groups as $type => $groups)
{
foreach ($groups as $id => $group)
{
if (isset($context['member_groups'][$group]))
$additional_groups[$type][$id] = $context['member_groups'][$group]['name'];
else
unset($additional_groups[$type][$id]);
}
$additional_groups[$type] = implode(', ', $additional_groups[$type]);
}
$context['log_changes']['additional_groups'] = $additional_groups;
}
}
}
if ($context['user']['is_owner'])
$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own'));
else
$changeOther = allowedTo('profile_extra_any');
if ($changeOther && empty($post_errors))
{
makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
if (!empty($_REQUEST['sa']))
{
$custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true);
if (!empty($custom_fields_errors))
$post_errors = array_merge($post_errors, $custom_fields_errors);
}
}
unset($profile_fields);
}
function saveProfileChanges(&$profile_vars, &$post_errors, $memID)
{
global $user_profile, $context;
$old_profile = &$user_profile[$memID];
if ($context['user']['is_owner'])
{
$changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own'));
}
else
$changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any'));
$profile_bools = array();
$profile_ints = array();
$profile_floats = array();
$profile_strings = array(
'buddy_list',
'ignore_boards',
);
if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd']))
$_POST['ignore_brd'] = array();
unset($_POST['ignore_boards']);
if (isset($_POST['ignore_brd']))
{
if (!is_array($_POST['ignore_brd']))
$_POST['ignore_brd'] = array($_POST['ignore_brd']);
foreach ($_POST['ignore_brd'] as $k => $d)
{
$d = (int) $d;
if ($d != 0)
$_POST['ignore_brd'][$k] = $d;
else
unset($_POST['ignore_brd'][$k]);
}
$_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']);
unset($_POST['ignore_brd']);
}
if ($changeOther)
{
makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
if (!empty($_REQUEST['sa']))
makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
foreach ($profile_bools as $var)
if (isset($_POST[$var]))
$profile_vars[$var] = empty($_POST[$var]) ? '0' : '1';
foreach ($profile_ints as $var)
if (isset($_POST[$var]))
$profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : '';
foreach ($profile_floats as $var)
if (isset($_POST[$var]))
$profile_vars[$var] = (float) $_POST[$var];
foreach ($profile_strings as $var)
if (isset($_POST[$var]))
$profile_vars[$var] = $_POST[$var];
}
}
function makeThemeChanges($memID, $id_theme)
{
global $modSettings, $smcFunc, $context, $user_info;
$reservedVars = array(
'actual_theme_url',
'actual_images_url',
'base_theme_dir',
'base_theme_url',
'default_images_url',
'default_theme_dir',
'default_theme_url',
'default_template',
'images_url',
'number_recent_posts',
'smiley_sets_default',
'theme_dir',
'theme_id',
'theme_layers',
'theme_templates',
'theme_url',
);
if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0))
fatal_lang_error('no_access', false);
$request = $smcFunc['db_query']('', '
SELECT col_name
FROM {db_prefix}custom_fields
WHERE active = {int:is_active}',
array(
'is_active' => 1,
)
);
$custom_fields = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$custom_fields[] = $row['col_name'];
$smcFunc['db_free_result']($request);
$themeSetArray = array();
if (isset($_POST['options']) && is_array($_POST['options']))
{
foreach ($_POST['options'] as $opt => $val)
{
if (in_array($opt, $custom_fields))
continue;
if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
$val = max(0, min($val, 50));
elseif ($opt == 'allow_no_censored')
continue;
$themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val);
}
}
$erase_options = array();
if (isset($_POST['default_options']) && is_array($_POST['default_options']))
foreach ($_POST['default_options'] as $opt => $val)
{
if (in_array($opt, $custom_fields))
continue;
if ($opt == 'topics_per_page' || $opt == 'messages_per_page')
$val = max(0, min($val, 50));
elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner'])
continue;
$themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val);
$erase_options[] = $opt;
}
if (empty($context['password_auth_failed']))
{
if (!empty($themeSetArray))
{
$smcFunc['db_insert']('replace',
'{db_prefix}themes',
array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534'),
$themeSetArray,
array('id_member', 'id_theme', 'variable')
);
}
if (!empty($erase_options))
{
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}themes
WHERE id_theme != {int:id_theme}
AND variable IN ({array_string:erase_variables})
AND id_member = {int:id_member}',
array(
'id_theme' => 1,
'id_member' => $memID,
'erase_variables' => $erase_options
)
);
}
$themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']);
foreach ($themes as $t)
cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60);
}
}
function makeNotificationChanges($memID)
{
global $smcFunc, $sourcedir;
require_once($sourcedir . '/Subs-Notify.php');
if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards']))
{
foreach ($_POST['notify_boards'] as $index => $id)
$_POST['notify_boards'][$index] = (int) $id;
$_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0));
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}log_notify
WHERE id_board IN ({array_int:board_list})
AND id_member = {int:selected_member}',
array(
'board_list' => $_POST['notify_boards'],
'selected_member' => $memID,
)
);
}
elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics']))
{
foreach ($_POST['notify_topics'] as $index => $id)
$_POST['notify_topics'][$index] = (int) $id;
$_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0));
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}log_notify
WHERE id_topic IN ({array_int:topic_list})
AND id_member = {int:selected_member}',
array(
'topic_list' => $_POST['notify_topics'],
'selected_member' => $memID,
)
);
foreach ($_POST['notify_topics'] as $topic)
setNotifyPrefs($memID, array('topic_notify_' . $topic => 0));
}
elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics']))
{
$prefs = array();
foreach ($_POST['notify_topics'] as $topic)
$prefs[] = 'topic_notify_' . $topic;
deleteNotifyPrefs($memID, $prefs);
}
elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards']))
{
$prefs = array();
foreach ($_POST['notify_boards'] as $board)
$prefs[] = 'board_notify_' . $board;
deleteNotifyPrefs($memID, $prefs);
}
}
function makeCustomFieldChanges($memID, $area, $sanitize = true, $returnErrors = false)
{
global $context, $smcFunc, $user_profile, $user_info, $modSettings;
global $sourcedir;
$errors = array();
if ($sanitize && isset($_POST['customfield']))
$_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']);
$where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}';
$request = $smcFunc['db_query']('', '
SELECT col_name, field_name, field_desc, field_type, field_length, field_options, default_value, show_reg, mask, private
FROM {db_prefix}custom_fields
WHERE ' . $where . '
AND active = {int:is_active}',
array(
'is_active' => 1,
'area' => $area,
)
);
$changes = array();
$deletes = array();
$log_changes = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0))
continue;
if ($row['field_type'] == 'check')
$value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0;
elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio')
{
$value = $row['default_value'];
foreach (explode(',', $row['field_options']) as $k => $v)
if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k)
$value = $v;
}
else
{
$value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : '';
if ($row['field_length'])
$value = $smcFunc['substr']($value, 0, $row['field_length']);
if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none')
{
$value = $smcFunc['htmltrim']($value);
$valueReference = un_htmlspecialchars($value);
if (empty($value) && !is_numeric($value))
$value = '';
if ($row['mask'] == 'nohtml' && ($valueReference != strip_tags($valueReference) || $value != filter_var($value, FILTER_SANITIZE_STRING) || preg_match('/<(.+?)[\s]*\/?[\s]*>/si', $valueReference)))
{
if ($returnErrors)
$errors[] = 'custom_field_nohtml_fail';
else
$value = '';
}
elseif ($row['mask'] == 'email' && !empty($value) && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255))
{
if ($returnErrors)
$errors[] = 'custom_field_mail_fail';
else
$value = '';
}
elseif ($row['mask'] == 'number')
{
$value = (int) $value;
}
elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0)
{
if ($returnErrors)
$errors[] = 'custom_field_regex_fail';
else
$value = '';
}
unset($valueReference);
}
}
if (!isset($user_profile[$memID]['options'][$row['col_name']]))
$user_profile[$memID]['options'][$row['col_name']] = '';
if ($user_profile[$memID]['options'][$row['col_name']] != $value)
{
$log_changes[] = array(
'action' => 'customfield_' . $row['col_name'],
'log_type' => 'user',
'extra' => array(
'previous' => !empty($user_profile[$memID]['options'][$row['col_name']]) ? $user_profile[$memID]['options'][$row['col_name']] : '',
'new' => $value,
'applicator' => $user_info['id'],
'member_affected' => $memID,
),
);
if (empty($value))
{
$deletes[] = array('id_theme' => 1, 'variable' => $row['col_name'], 'id_member' => $memID);
unset($user_profile[$memID]['options'][$row['col_name']]);
}
else
{
$changes[] = array(1, $row['col_name'], $value, $memID);
$user_profile[$memID]['options'][$row['col_name']] = $value;
}
}
}
$smcFunc['db_free_result']($request);
$hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize, &$deletes));
if (!empty($hook_errors) && is_array($hook_errors))
$errors = array_merge($errors, $hook_errors);
if ((!empty($changes) || !empty($deletes)) && empty($context['password_auth_failed']) && empty($errors))
{
if (!empty($changes))
$smcFunc['db_insert']('replace',
'{db_prefix}themes',
array('id_theme' => 'int', 'variable' => 'string-255', 'value' => 'string-65534', 'id_member' => 'int'),
$changes,
array('id_theme', 'variable', 'id_member')
);
if (!empty($deletes))
foreach ($deletes as $delete)
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}themes
WHERE id_theme = {int:id_theme}
AND variable = {string:variable}
AND id_member = {int:id_member}',
$delete
);
if (!empty($log_changes) && !empty($modSettings['modlog_enabled']))
{
require_once($sourcedir . '/Logging.php');
logActions($log_changes);
}
}
if ($returnErrors)
return $errors;
}
function editBuddyIgnoreLists($memID)
{
global $context, $txt, $modSettings;
if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist']))
fatal_lang_error('no_access', false);
$context['can_moderate_forum'] = allowedTo('moderate_forum');
$context['can_send_email'] = allowedTo('moderate_forum');
$subActions = array(
'buddies' => array('editBuddies', $txt['editBuddies']),
'ignore' => array('editIgnoreList', $txt['editIgnoreList']),
);
$context['list_area'] = isset($_GET['sa']) && isset($subActions[$_GET['sa']]) ? $_GET['sa'] : 'buddies';
$context[$context['profile_menu_name']]['tab_data'] = array(
'title' => $txt['editBuddyIgnoreLists'],
'description' => $txt['buddy_ignore_desc'],
'icon' => 'profile_hd.png',
'tabs' => array(
'buddies' => array(),
'ignore' => array(),
),
);
loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest');
$context['sub_template'] = $subActions[$context['list_area']][0];
$call = call_helper($subActions[$context['list_area']][0], true);
if (!empty($call))
call_user_func($call, $memID);
}
function editBuddies($memID)
{
global $txt, $scripturl, $settings, $modSettings;
global $context, $user_profile, $memberContext, $smcFunc;
$buddiesArray = explode(',', $user_profile[$memID]['buddy_list']);
foreach ($buddiesArray as $k => $dummy)
if ($dummy == '')
unset($buddiesArray[$k]);
if (isset($_GET['remove']))
{
checkSession('get');
call_integration_hook('integrate_remove_buddy', array($memID));
$_SESSION['prf-save'] = $txt['could_not_remove_person'];
foreach ($buddiesArray as $key => $buddy)
if ($buddy == (int) $_GET['remove'])
{
unset($buddiesArray[$key]);
$_SESSION['prf-save'] = true;
}
$user_profile[$memID]['buddy_list'] = implode(',', $buddiesArray);
updateMemberData($memID, array('buddy_list' => $user_profile[$memID]['buddy_list']));
redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
}
elseif (isset($_POST['new_buddy']))
{
checkSession();
$_POST['new_buddy'] = strtr($smcFunc['htmlspecialchars']($_POST['new_buddy'], ENT_QUOTES), array('"' => '"'));
preg_match_all('~"([^"]+)"~', $_POST['new_buddy'], $matches);
$new_buddies = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST['new_buddy']))));
foreach ($new_buddies as $k => $dummy)
{
$new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => '''));
if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
unset($new_buddies[$k]);
}
call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies));
$_SESSION['prf-save'] = $txt['could_not_add_person'];
if (!empty($new_buddies))
{
$request = $smcFunc['db_query']('', '
SELECT id_member
FROM {db_prefix}members
WHERE member_name IN ({array_string:new_buddies}) OR real_name IN ({array_string:new_buddies})
LIMIT {int:count_new_buddies}',
array(
'new_buddies' => $new_buddies,
'count_new_buddies' => count($new_buddies),
)
);
if ($smcFunc['db_num_rows']($request) != 0)
$_SESSION['prf-save'] = true;
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (in_array($row['id_member'], $buddiesArray))
continue;
else
$buddiesArray[] = (int) $row['id_member'];
}
$smcFunc['db_free_result']($request);
$user_profile[$memID]['buddy_list'] = implode(',', $buddiesArray);
updateMemberData($memID, array('buddy_list' => $user_profile[$memID]['buddy_list']));
}
redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID);
}
$buddies = array();
$request = $smcFunc['db_query']('', '
SELECT col_name, field_name, field_desc, field_type, bbc, enclose
FROM {db_prefix}custom_fields
WHERE active = {int:active}
AND private < {int:private_level}',
array(
'active' => 1,
'private_level' => 2,
)
);
$context['custom_pf'] = array();
$disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
while ($row = $smcFunc['db_fetch_assoc']($request))
if (!isset($disabled_fields[$row['col_name']]))
$context['custom_pf'][$row['col_name']] = array(
'label' => $row['field_name'],
'type' => $row['field_type'],
'bbc' => !empty($row['bbc']),
'enclose' => $row['enclose'],
);
if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'None')
unset($context['custom_pf']['cust_gender']);
$smcFunc['db_free_result']($request);
if (!empty($buddiesArray))
{
$result = $smcFunc['db_query']('', '
SELECT id_member
FROM {db_prefix}members
WHERE id_member IN ({array_int:buddy_list})
ORDER BY real_name
LIMIT {int:buddy_list_count}',
array(
'buddy_list' => $buddiesArray,
'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1,
)
);
while ($row = $smcFunc['db_fetch_assoc']($result))
$buddies[] = $row['id_member'];
$smcFunc['db_free_result']($result);
}
$context['buddy_count'] = count($buddies);
loadMemberData($buddies, false, 'profile');
$context['buddies'] = array();
foreach ($buddies as $buddy)
{
loadMemberContext($buddy);
$context['buddies'][$buddy] = $memberContext[$buddy];
if (!empty($context['custom_pf']))
{
foreach ($context['custom_pf'] as $key => $column)
{
if (!isset($context['buddies'][$buddy]['options'][$key]))
{
$context['buddies'][$buddy]['options'][$key] = '';
continue;
}
if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key]))
$context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key]));
elseif ($column['type'] == 'check')
$context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes'];
if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key]))
$context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array(
'{SCRIPTURL}' => $scripturl,
'{IMAGES_URL}' => $settings['images_url'],
'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
'{INPUT}' => $context['buddies'][$buddy]['options'][$key],
));
}
}
}
if (isset($_SESSION['prf-save']))
{
if ($_SESSION['prf-save'] === true)
$context['saved_successful'] = true;
else
$context['saved_failed'] = $_SESSION['prf-save'];
unset($_SESSION['prf-save']);
}
call_integration_hook('integrate_view_buddies', array($memID));
}
function editIgnoreList($memID)
{
global $txt;
global $context, $user_profile, $memberContext, $smcFunc;
$ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']);
foreach ($ignoreArray as $k => $dummy)
if ($dummy == '')
unset($ignoreArray[$k]);
if (isset($_GET['remove']))
{
checkSession('get');
$_SESSION['prf-save'] = $txt['could_not_remove_person'];
foreach ($ignoreArray as $key => $id_remove)
if ($id_remove == (int) $_GET['remove'])
{
unset($ignoreArray[$key]);
$_SESSION['prf-save'] = true;
}
$user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray);
updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list']));
redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
}
elseif (isset($_POST['new_ignore']))
{
checkSession();
$_POST['new_ignore'] = strtr($smcFunc['htmlspecialchars']($_POST['new_ignore'], ENT_QUOTES), array('"' => '"'));
preg_match_all('~"([^"]+)"~', $_POST['new_ignore'], $matches);
$new_entries = array_unique(array_merge($matches[1], explode(',', preg_replace('~"[^"]+"~', '', $_POST['new_ignore']))));
foreach ($new_entries as $k => $dummy)
{
$new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => '''));
if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name'])))
unset($new_entries[$k]);
}
$_SESSION['prf-save'] = $txt['could_not_add_person'];
if (!empty($new_entries))
{
$request = $smcFunc['db_query']('', '
SELECT id_member
FROM {db_prefix}members
WHERE member_name IN ({array_string:new_entries}) OR real_name IN ({array_string:new_entries})
LIMIT {int:count_new_entries}',
array(
'new_entries' => $new_entries,
'count_new_entries' => count($new_entries),
)
);
if ($smcFunc['db_num_rows']($request) != 0)
$_SESSION['prf-save'] = true;
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (in_array($row['id_member'], $ignoreArray))
continue;
else
$ignoreArray[] = (int) $row['id_member'];
}
$smcFunc['db_free_result']($request);
$user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray);
updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list']));
}
redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
}
$ignored = array();
if (!empty($ignoreArray))
{
$result = $smcFunc['db_query']('', '
SELECT id_member
FROM {db_prefix}members
WHERE id_member IN ({array_int:ignore_list})
ORDER BY real_name
LIMIT {int:ignore_list_count}',
array(
'ignore_list' => $ignoreArray,
'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1,
)
);
while ($row = $smcFunc['db_fetch_assoc']($result))
$ignored[] = $row['id_member'];
$smcFunc['db_free_result']($result);
}
$context['ignore_count'] = count($ignored);
loadMemberData($ignored, false, 'profile');
$context['ignore_list'] = array();
foreach ($ignored as $ignore_member)
{
loadMemberContext($ignore_member);
$context['ignore_list'][$ignore_member] = $memberContext[$ignore_member];
}
if (isset($_SESSION['prf-save']))
{
if ($_SESSION['prf-save'] === true)
$context['saved_successful'] = true;
else
$context['saved_failed'] = $_SESSION['prf-save'];
unset($_SESSION['prf-save']);
}
}
function account($memID)
{
global $context, $txt;
loadThemeOptions($memID);
if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any')))
loadCustomFields($memID, 'account');
$context['sub_template'] = 'edit_options';
$context['page_desc'] = $txt['account_info'];
setupProfileContext(
array(
'member_name', 'real_name', 'date_registered', 'posts', 'lngfile', 'hr',
'id_group', 'hr',
'email_address', 'show_online', 'hr',
'tfa', 'hr',
'passwrd1', 'passwrd2', 'hr',
'secret_question', 'secret_answer',
)
);
}
function forumProfile($memID)
{
global $context, $txt;
loadThemeOptions($memID);
if (allowedTo(array('profile_forum_own', 'profile_forum_any')))
loadCustomFields($memID, 'forumprofile');
$context['sub_template'] = 'edit_options';
$context['page_desc'] = $txt['forumProfile_info'];
$context['show_preview_button'] = true;
setupProfileContext(
array(
'avatar_choice', 'hr', 'personal_text', 'hr',
'bday1', 'usertitle', 'signature', 'hr',
'website_title', 'website_url',
)
);
}
function getAvatars($directory, $level)
{
global $context, $txt, $modSettings, $smcFunc;
$result = array();
$dir = dir($modSettings['avatar_directory'] . (!empty($directory) ? '/' : '') . $directory);
$dirs = array();
$files = array();
if (!$dir)
return array();
while ($line = $dir->read())
{
if (in_array($line, array('.', '..', 'blank.png', 'index.php')))
continue;
if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line))
$dirs[] = $line;
else
$files[] = $line;
}
$dir->close();
natcasesort($dirs);
natcasesort($files);
if ($level == 0)
{
$result[] = array(
'filename' => 'blank.png',
'checked' => in_array($context['member']['avatar']['server_pic'], array('', 'blank.png')),
'name' => $txt['no_pic'],
'is_dir' => false
);
}
foreach ($dirs as $line)
{
$tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1);
if (!empty($tmp))
$result[] = array(
'filename' => $smcFunc['htmlspecialchars']($line),
'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false,
'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']',
'is_dir' => true,
'files' => $tmp
);
unset($tmp);
}
foreach ($files as $line)
{
$filename = substr($line, 0, (strlen($line) - strlen(strrchr($line, '.'))));
$extension = substr(strrchr($line, '.'), 1);
if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0)
continue;
$result[] = array(
'filename' => $smcFunc['htmlspecialchars']($line),
'checked' => $line == $context['member']['avatar']['server_pic'],
'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)),
'is_dir' => false
);
if ($level == 1)
$context['avatar_list'][] = $directory . '/' . $line;
}
return $result;
}
function theme($memID)
{
global $txt, $context;
loadTemplate('Settings');
loadSubTemplate('options');
call_integration_hook('integrate_theme_options');
loadThemeOptions($memID);
if (allowedTo(array('profile_extra_own', 'profile_extra_any')))
loadCustomFields($memID, 'theme');
$context['sub_template'] = 'edit_options';
$context['page_desc'] = $txt['theme_info'];
setupProfileContext(
array(
'id_theme', 'smiley_set', 'hr',
'time_format', 'timezone', 'hr',
'theme_settings',
)
);
}
function notification($memID)
{
global $txt, $context;
loadCSSFile('admin.css', array(), 'smf_admin');
$sa = array(
'alerts' => 'alert_configuration',
'markread' => 'alert_markread',
'topics' => 'alert_notifications_topics',
'boards' => 'alert_notifications_boards',
);
$subAction = !empty($_GET['sa']) && isset($sa[$_GET['sa']]) ? $_GET['sa'] : 'alerts';
$context['sub_template'] = $sa[$subAction];
$context[$context['profile_menu_name']]['tab_data'] = array(
'title' => $txt['notification'],
'help' => '',
'description' => $txt['notification_info'],
);
$sa[$subAction]($memID);
}
function alert_configuration($memID, $defaultSettings = false)
{
global $txt, $context, $modSettings, $smcFunc, $sourcedir;
if (!isset($context['token_check']))
$context['token_check'] = 'profile-nt' . $memID;
is_not_guest();
if (!$context['user']['is_owner'])
isAllowedTo('profile_extra_any');
if (!isset($context['action']))
$context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID;
loadThemeOptions($memID, $defaultSettings);
loadJavaScriptFile('alertSettings.js', array('minimize' => true), 'smf_alertSettings');
require_once($sourcedir . '/Subs-Notify.php');
$prefs = getNotifyPrefs($memID, '', $memID != 0);
$context['alert_prefs'] = !empty($prefs[$memID]) ? $prefs[$memID] : array();
$context['member'] += array(
'alert_timeout' => isset($context['alert_prefs']['alert_timeout']) ? $context['alert_prefs']['alert_timeout'] : 10,
'notify_announcements' => isset($context['alert_prefs']['announcements']) ? $context['alert_prefs']['announcements'] : 0,
);
$context['can_disable_announce'] = $memID == 0 || !empty($modSettings['allow_disableAnnounce']);
$alert_types = array(
'board' => array(
'topic_notify' => array('alert' => 'yes', 'email' => 'yes'),
'board_notify' => array('alert' => 'yes', 'email' => 'yes'),
),
'msg' => array(
'msg_mention' => array('alert' => 'yes', 'email' => 'yes'),
'msg_quote' => array('alert' => 'yes', 'email' => 'yes'),
'msg_like' => array('alert' => 'yes', 'email' => 'never'),
'unapproved_reply' => array('alert' => 'yes', 'email' => 'yes'),
),
'pm' => array(
'pm_new' => array('alert' => 'never', 'email' => 'yes', 'help' => 'alert_pm_new', 'permission' => array('name' => 'pm_read', 'is_board' => false)),
'pm_reply' => array('alert' => 'never', 'email' => 'yes', 'help' => 'alert_pm_new', 'permission' => array('name' => 'pm_send', 'is_board' => false)),
),
'groupr' => array(
'groupr_approved' => array('alert' => 'yes', 'email' => 'yes'),
'groupr_rejected' => array('alert' => 'yes', 'email' => 'yes'),
),
'moderation' => array(
'unapproved_attachment' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'approve_posts', 'is_board' => true)),
'unapproved_post' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'approve_posts', 'is_board' => true)),
'msg_report' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'moderate_board', 'is_board' => true)),
'msg_report_reply' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'moderate_board', 'is_board' => true)),
'member_report' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'moderate_forum', 'is_board' => false)),
'member_report_reply' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'moderate_forum', 'is_board' => false)),
),
'members' => array(
'member_register' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'moderate_forum', 'is_board' => false)),
'request_group' => array('alert' => 'yes', 'email' => 'yes'),
'warn_any' => array('alert' => 'yes', 'email' => 'yes', 'permission' => array('name' => 'issue_warning', 'is_board' => false)),
'buddy_request' => array('alert' => 'yes', 'email' => 'never'),
'birthday' => array('alert' => 'yes', 'email' => 'yes'),
),
'calendar' => array(
'event_new' => array('alert' => 'yes', 'email' => 'yes', 'help' => 'alert_event_new'),
),
'paidsubs' => array(
'paidsubs_expiring' => array('alert' => 'yes', 'email' => 'yes'),
),
);
$group_options = array(
'board' => array(
array('check', 'msg_auto_notify', 'label' => 'after'),
array('check', 'msg_receive_body', 'label' => 'after'),
array('select', 'msg_notify_pref', 'label' => 'before', 'opts' => array(
0 => $txt['alert_opt_msg_notify_pref_never'],
1 => $txt['alert_opt_msg_notify_pref_instant'],
2 => $txt['alert_opt_msg_notify_pref_first'],
3 => $txt['alert_opt_msg_notify_pref_daily'],
4 => $txt['alert_opt_msg_notify_pref_weekly'],
)),
array('select', 'msg_notify_type', 'label' => 'before', 'opts' => array(
1 => $txt['notify_send_type_everything'],
2 => $txt['notify_send_type_everything_own'],
3 => $txt['notify_send_type_only_replies'],
4 => $txt['notify_send_type_nothing'],
)),
),
'pm' => array(
array('select', 'pm_notify', 'label' => 'before', 'opts' => array(
1 => $txt['email_notify_all'],
2 => $txt['email_notify_buddies'],
)),
),
);
if (empty($modSettings['cal_enabled']))
unset($alert_types['calendar']);
if (empty($modSettings['paid_enabled']))
unset($alert_types['paidsubs']);
if (empty($modSettings['show_group_membership']))
unset($alert_types['groupr'], $alert_types['members']['request_group']);
if (empty($modSettings['enable_mentions']))
unset($alert_types['msg']['msg_mention']);
if (empty($modSettings['enable_likes']))
unset($alert_types['msg']['msg_like']);
if (empty($modSettings['enable_buddylist']))
unset($alert_types['members']['buddy_request']);
call_integration_hook('integrate_alert_types', array(&$alert_types, &$group_options));
if (!empty($memID))
{
require_once($sourcedir . '/Subs-Members.php');
$perms_cache = array();
$request = $smcFunc['db_query']('', '
SELECT COUNT(*)
FROM {db_prefix}group_moderators
WHERE id_member = {int:memID}',
array(
'memID' => $memID,
)
);
list ($can_mod) = $smcFunc['db_fetch_row']($request);
if (!isset($perms_cache['manage_membergroups']))
{
$members = membersAllowedTo('manage_membergroups');
$perms_cache['manage_membergroups'] = in_array($memID, $members);
}
if (!($perms_cache['manage_membergroups'] || $can_mod != 0))
unset($alert_types['members']['request_group']);
foreach ($alert_types as $group => $items)
{
foreach ($items as $alert_key => $alert_value)
{
if (!isset($alert_value['permission']))
continue;
if (!isset($perms_cache[$alert_value['permission']['name']]))
{
$in_board = !empty($alert_value['permission']['is_board']) ? 0 : null;
$members = membersAllowedTo($alert_value['permission']['name'], $in_board);
$perms_cache[$alert_value['permission']['name']] = in_array($memID, $members);
}
if (!$perms_cache[$alert_value['permission']['name']])
unset ($alert_types[$group][$alert_key]);
}
if (empty($alert_types[$group]))
unset ($alert_types[$group]);
}
}
$context['alert_types'] = $alert_types;
$context['alert_group_options'] = $group_options;
$context['alert_bits'] = array(
'alert' => 0x01,
'email' => 0x02,
);
if (isset($_POST['notify_submit']))
{
checkSession();
validateToken($context['token_check'], 'post');
$update_prefs = array();
foreach ($context['alert_group_options'] as $opt_group => $group)
{
foreach ($group as $this_option)
{
switch ($this_option[0])
{
case 'check':
$update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0;
break;
case 'select':
if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]]))
$update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]];
else
{
$keys = array_keys($this_option['opts']);
$first = array_shift($keys);
$update_prefs[$this_option[1]] = $first;
}
break;
}
}
}
foreach ($context['alert_types'] as $alert_group => $items)
{
foreach ($items as $item_key => $this_options)
{
$this_value = 0;
foreach ($context['alert_bits'] as $type => $bitvalue)
{
if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always')
$this_value |= $bitvalue;
}
$update_prefs[$item_key] = $this_value;
}
}
if (isset($_POST['opt_alert_timeout']))
$update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout'];
else
$update_prefs['alert_timeout'] = $context['alert_prefs']['alert_timeout'];
if (isset($_POST['notify_announcements']))
$update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements'];
else
$update_prefs['announcements'] = $context['alert_prefs']['announcements'];
setNotifyPrefs((int) $memID, $update_prefs);
foreach ($update_prefs as $pref => $value)
$context['alert_prefs'][$pref] = $value;
makeNotificationChanges($memID);
$context['profile_updated'] = $txt['profile_updated_own'];
}
createToken($context['token_check'], 'post');
}
function alert_markread($memID)
{
global $context, $db_show_debug, $smcFunc;
$db_show_debug = false;
$context['template_layers'] = array();
$context['sub_template'] = 'alerts_all_read';
loadLanguage('Alerts');
is_not_guest();
if (!$context['user']['is_owner'])
fatal_error('no_access');
checkSession('get');
$smcFunc['db_query']('', '
UPDATE {db_prefix}user_alerts
SET is_read = {int:now}
WHERE id_member = {int:current_member}
AND is_read = 0',
array(
'now' => time(),
'current_member' => $memID,
)
);
updateMemberData($memID, array('alerts' => 0));
}
function alert_mark($memID, $toMark, $read = 0)
{
global $smcFunc;
if (empty($toMark) || empty($memID))
return false;
$toMark = (array) $toMark;
$smcFunc['db_query']('', '
UPDATE {db_prefix}user_alerts
SET is_read = {int:read}
WHERE id_alert IN({array_int:toMark})',
array(
'read' => $read == 1 ? time() : 0,
'toMark' => $toMark,
)
);
$count = alert_count($memID, true);
updateMemberData($memID, array('alerts' => $count));
return $count;
}
function alert_delete($toDelete, $memID = false)
{
global $smcFunc;
if (empty($toDelete))
return false;
$toDelete = (array) $toDelete;
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}user_alerts
WHERE id_alert IN({array_int:toDelete})',
array(
'toDelete' => $toDelete,
)
);
if ($memID)
{
$count = alert_count($memID, true);
updateMemberData($memID, array('alerts' => $count));
return $count;
}
}
function alert_purge($memID = 0)
{
global $smcFunc, $user_info;
$memID = !empty($memID) && is_int($memID) ? $memID : $user_info['id'];
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}user_alerts
WHERE id_member = {int:memID}
AND is_read > 0',
array(
'memID' => $memID,
)
);
}
function alert_count($memID, $unread = false)
{
global $smcFunc, $user_info;
if (empty($memID))
return false;
$alerts = array();
$possible_topics = array();
$possible_msgs = array();
$possible_attachments = array();
$request = $smcFunc['db_query']('', '
SELECT id_alert, content_id, content_type, content_action
FROM {db_prefix}user_alerts
WHERE id_member = {int:id_member}
' . ($unread ? '
AND is_read = 0' : ''),
array(
'id_member' => $memID,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$alerts[$row['id_alert']] = $row;
if ($row['content_type'] == 'msg')
{
$alerts[$row['id_alert']]['visible'] = false;
$possible_msgs[$row['id_alert']] = $row['content_id'];
}
elseif (in_array($row['content_type'], array('topic', 'board')))
{
$alerts[$row['id_alert']]['visible'] = false;
$possible_topics[$row['id_alert']] = $row['content_id'];
}
else
$alerts[$row['id_alert']]['visible'] = true;
}
$smcFunc['db_free_result']($request);
if ((!isset($user_info['query_see_board']) || $user_info['id'] != $memID) && (!empty($possible_msgs) || !empty($possible_topics)))
$qb = build_query_board($memID);
else
{
$qb['query_see_topic_board'] = '{query_see_topic_board}';
$qb['query_see_message_board'] = '{query_see_message_board}';
}
if (!empty($possible_msgs))
{
$flipped_msgs = array();
foreach ($possible_msgs as $id_alert => $id_msg)
{
if (!isset($flipped_msgs[$id_msg]))
$flipped_msgs[$id_msg] = array();
$flipped_msgs[$id_msg][] = $id_alert;
}
$request = $smcFunc['db_query']('', '
SELECT m.id_msg
FROM {db_prefix}messages AS m
WHERE ' . $qb['query_see_message_board'] . '
AND m.id_msg IN ({array_int:msgs})',
array(
'msgs' => $possible_msgs,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
foreach ($flipped_msgs[$row['id_msg']] as $id_alert)
$alerts[$id_alert]['visible'] = true;
}
$smcFunc['db_free_result']($request);
}
if (!empty($possible_topics))
{
$flipped_topics = array();
foreach ($possible_topics as $id_alert => $id_topic)
{
if (!isset($flipped_topics[$id_topic]))
$flipped_topics[$id_topic] = array();
$flipped_topics[$id_topic][] = $id_alert;
}
$request = $smcFunc['db_query']('', '
SELECT t.id_topic
FROM {db_prefix}topics AS t
WHERE ' . $qb['query_see_topic_board'] . '
AND t.id_topic IN ({array_int:topics})',
array(
'topics' => $possible_topics,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
foreach ($flipped_topics[$row['id_topic']] as $id_alert)
$alerts[$id_alert]['visible'] = true;
}
$smcFunc['db_free_result']($request);
}
foreach ($alerts as $id_alert => $alert)
{
if (!$alert['visible'])
unset($alerts[$id_alert]);
}
return count($alerts);
}
function alert_notifications_topics($memID)
{
global $txt, $scripturl, $context, $modSettings, $sourcedir;
if (isset($_POST['edit_notify_topics']) || isset($_POST['remove_notify_topics']))
{
checkSession();
validateToken(str_replace('%u', $memID, 'profile-nt%u'), 'post');
makeNotificationChanges($memID);
$context['profile_updated'] = $txt['profile_updated_own'];
}
$context['token_check'] = str_replace('%u', $memID, 'profile-nt%u');
createToken($context['token_check'], 'post');
require_once($sourcedir . '/Subs-List.php');
$listOptions = array(
'id' => 'topic_notification_list',
'width' => '100%',
'items_per_page' => $modSettings['defaultMaxListItems'],
'no_items_label' => $txt['notifications_topics_none'] . '<br><br>' . $txt['notifications_topics_howto'],
'no_items_align' => 'left',
'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification;sa=topics',
'default_sort_col' => 'last_post',
'get_items' => array(
'function' => 'list_getTopicNotifications',
'params' => array(
$memID,
),
),
'get_count' => array(
'function' => 'list_getTopicNotificationCount',
'params' => array(
$memID,
),
),
'columns' => array(
'subject' => array(
'header' => array(
'value' => $txt['notifications_topics'],
'class' => 'lefttext',
),
'data' => array(
'function' => function($topic) use ($txt)
{
$link = $topic['link'];
if ($topic['new'])
$link .= ' <a href="' . $topic['new_href'] . '" class="new_posts">' . $txt['new'] . '</a>';
$link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>';
return $link;
},
),
'sort' => array(
'default' => 'ms.subject',
'reverse' => 'ms.subject DESC',
),
),
'started_by' => array(
'header' => array(
'value' => $txt['started_by'],
'class' => 'lefttext',
),
'data' => array(
'db' => 'poster_link',
),
'sort' => array(
'default' => 'real_name_col',
'reverse' => 'real_name_col DESC',
),
),
'last_post' => array(
'header' => array(
'value' => $txt['last_post'],
'class' => 'lefttext',
),
'data' => array(
'sprintf' => array(
'format' => '<span class="smalltext">%1$s<br>' . $txt['by'] . ' %2$s</span>',
'params' => array(
'updated' => false,
'poster_updated_link' => false,
),
),
),
'sort' => array(
'default' => 'ml.id_msg DESC',
'reverse' => 'ml.id_msg',
),
),
'alert' => array(
'header' => array(
'value' => $txt['notify_what_how'],
'class' => 'lefttext',
),
'data' => array(
'function' => function($topic) use ($txt)
{
$pref = $topic['notify_pref'];
$mode = !empty($topic['unwatched']) ? 0 : ($pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1));
return $txt['notify_topic_' . $mode];
},
),
),
'delete' => array(
'header' => array(
'value' => '<input type="checkbox" onclick="invertAll(this, this.form);">',
'style' => 'width: 4%;',
'class' => 'centercol',
),
'data' => array(
'sprintf' => array(
'format' => '<input type="checkbox" name="notify_topics[]" value="%1$d">',
'params' => array(
'id' => false,
),
),
'class' => 'centercol',
),
),
),
'form' => array(
'href' => $scripturl . '?action=profile;area=notification;sa=topics',
'include_sort' => true,
'include_start' => true,
'hidden_fields' => array(
'u' => $memID,
'sa' => $context['menu_item_selected'],
$context['session_var'] => $context['session_id'],
),
'token' => $context['token_check'],
),
'additional_rows' => array(
array(
'position' => 'bottom_of_list',
'value' => '<input type="submit" name="edit_notify_topics" value="' . $txt['notifications_update'] . '" class="button" />
<input type="submit" name="remove_notify_topics" value="' . $txt['notification_remove_pref'] . '" class="button" />',
'class' => 'floatright',
),
),
);
createList($listOptions);
}
function alert_notifications_boards($memID)
{
global $txt, $scripturl, $context, $sourcedir;
if (isset($_POST['edit_notify_boards']) || isset($_POSt['remove_notify_boards']))
{
checkSession();
validateToken(str_replace('%u', $memID, 'profile-nt%u'), 'post');
makeNotificationChanges($memID);
$context['profile_updated'] = $txt['profile_updated_own'];
}
$context['token_check'] = str_replace('%u', $memID, 'profile-nt%u');
createToken($context['token_check'], 'post');
require_once($sourcedir . '/Subs-List.php');
$listOptions = array(
'id' => 'board_notification_list',
'width' => '100%',
'no_items_label' => $txt['notifications_boards_none'] . '<br><br>' . $txt['notifications_boards_howto'],
'no_items_align' => 'left',
'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification;sa=boards',
'default_sort_col' => 'board_name',
'get_items' => array(
'function' => 'list_getBoardNotifications',
'params' => array(
$memID,
),
),
'columns' => array(
'board_name' => array(
'header' => array(
'value' => $txt['notifications_boards'],
'class' => 'lefttext',
),
'data' => array(
'function' => function($board) use ($txt)
{
$link = $board['link'];
if ($board['new'])
$link .= ' <a href="' . $board['href'] . '" class="new_posts">' . $txt['new'] . '</a>';
return $link;
},
),
'sort' => array(
'default' => 'name',
'reverse' => 'name DESC',
),
),
'alert' => array(
'header' => array(
'value' => $txt['notify_what_how'],
'class' => 'lefttext',
),
'data' => array(
'function' => function($board) use ($txt)
{
$pref = $board['notify_pref'];
$mode = $pref & 0x02 ? 3 : ($pref & 0x01 ? 2 : 1);
return $txt['notify_board_' . $mode];
},
),
),
'delete' => array(
'header' => array(
'value' => '<input type="checkbox" onclick="invertAll(this, this.form);">',
'style' => 'width: 4%;',
'class' => 'centercol',
),
'data' => array(
'sprintf' => array(
'format' => '<input type="checkbox" name="notify_boards[]" value="%1$d">',
'params' => array(
'id' => false,
),
),
'class' => 'centercol',
),
),
),
'form' => array(
'href' => $scripturl . '?action=profile;area=notification;sa=boards',
'include_sort' => true,
'include_start' => true,
'hidden_fields' => array(
'u' => $memID,
'sa' => $context['menu_item_selected'],
$context['session_var'] => $context['session_id'],
),
'token' => $context['token_check'],
),
'additional_rows' => array(
array(
'position' => 'bottom_of_list',
'value' => '<input type="submit" name="edit_notify_boards" value="' . $txt['notifications_update'] . '" class="button">
<input type="submit" name="remove_notify_boards" value="' . $txt['notification_remove_pref'] . '" class="button" />',
'class' => 'floatright',
),
),
);
createList($listOptions);
}
function list_getTopicNotificationCount($memID)
{
global $smcFunc, $user_info, $modSettings;
$request = $smcFunc['db_query']('', '
SELECT COUNT(*)
FROM {db_prefix}log_notify AS ln' . (!$modSettings['postmod_active'] && $user_info['query_see_board'] === '1=1' ? '' : '
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic)') . '
WHERE ln.id_member = {int:selected_member}' . ($user_info['query_see_topic_board'] === '1=1' ? '' : '
AND {query_see_topic_board}') . ($modSettings['postmod_active'] ? '
AND t.approved = {int:is_approved}' : ''),
array(
'selected_member' => $memID,
'is_approved' => 1,
)
);
list ($totalNotifications) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
return (int) $totalNotifications;
}
function list_getTopicNotifications($start, $items_per_page, $sort, $memID)
{
global $smcFunc, $scripturl, $user_info, $modSettings, $sourcedir;
require_once($sourcedir . '/Subs-Notify.php');
$prefs = getNotifyPrefs($memID);
$prefs = isset($prefs[$memID]) ? $prefs[$memID] : array();
$request = $smcFunc['db_query']('', '
SELECT
COALESCE(lt.id_msg, lmr.id_msg, -1) + 1 AS new_from, b.id_board, b.name,
t.id_topic, ms.subject, ms.id_member, COALESCE(mem.real_name, ms.poster_name) AS real_name_col,
ml.id_msg_modified, ml.poster_time, ml.id_member AS id_member_updated,
COALESCE(mem2.real_name, ml.poster_name) AS last_real_name,
lt.unwatched
FROM {db_prefix}log_notify AS ln
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = ln.id_topic' . ($modSettings['postmod_active'] ? ' AND t.approved = {int:is_approved}' : '') . ')
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board AND {query_see_board})
INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
INNER JOIN {db_prefix}messages AS ml ON (ml.id_msg = t.id_last_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = ms.id_member)
LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = ml.id_member)
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})
WHERE ln.id_member = {int:selected_member}
ORDER BY {raw:sort}
LIMIT {int:offset}, {int:items_per_page}',
array(
'current_member' => $user_info['id'],
'is_approved' => 1,
'selected_member' => $memID,
'sort' => $sort,
'offset' => $start,
'items_per_page' => $items_per_page,
)
);
$notification_topics = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
censorText($row['subject']);
$notification_topics[] = array(
'id' => $row['id_topic'],
'poster_link' => empty($row['id_member']) ? $row['real_name_col'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name_col'] . '</a>',
'poster_updated_link' => empty($row['id_member_updated']) ? $row['last_real_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_updated'] . '">' . $row['last_real_name'] . '</a>',
'subject' => $row['subject'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>',
'new' => $row['new_from'] <= $row['id_msg_modified'],
'new_from' => $row['new_from'],
'updated' => timeformat($row['poster_time']),
'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new',
'new_link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . '#new">' . $row['subject'] . '</a>',
'board_link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
'notify_pref' => isset($prefs['topic_notify_' . $row['id_topic']]) ? $prefs['topic_notify_' . $row['id_topic']] : (!empty($prefs['topic_notify']) ? $prefs['topic_notify'] : 0),
'unwatched' => $row['unwatched'],
);
}
$smcFunc['db_free_result']($request);
return $notification_topics;
}
function list_getBoardNotifications($start, $items_per_page, $sort, $memID)
{
global $smcFunc, $scripturl, $user_info, $sourcedir;
require_once($sourcedir . '/Subs-Notify.php');
$prefs = getNotifyPrefs($memID);
$prefs = isset($prefs[$memID]) ? $prefs[$memID] : array();
$request = $smcFunc['db_query']('', '
SELECT b.id_board, b.name, COALESCE(lb.id_msg, 0) AS board_read, b.id_msg_updated
FROM {db_prefix}log_notify AS ln
INNER JOIN {db_prefix}boards AS b ON (b.id_board = ln.id_board)
LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member})
WHERE ln.id_member = {int:selected_member}
AND {query_see_board}
ORDER BY {raw:sort}',
array(
'current_member' => $user_info['id'],
'selected_member' => $memID,
'sort' => $sort,
)
);
$notification_boards = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$notification_boards[] = array(
'id' => $row['id_board'],
'name' => $row['name'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>',
'new' => $row['board_read'] < $row['id_msg_updated'],
'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0),
);
$smcFunc['db_free_result']($request);
return $notification_boards;
}
function loadThemeOptions($memID, $defaultSettings = false)
{
global $context, $options, $cur_profile, $smcFunc;
if (isset($_POST['default_options']))
$_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options'];
if ($context['user']['is_owner'])
{
$context['member']['options'] = $options;
if (isset($_POST['options']) && is_array($_POST['options']))
foreach ($_POST['options'] as $k => $v)
$context['member']['options'][$k] = $v;
}
else
{
$request = $smcFunc['db_query']('', '
SELECT id_member, variable, value
FROM {db_prefix}themes
WHERE id_theme IN (1, {int:member_theme})
AND id_member IN (-1, {int:selected_member})',
array(
'member_theme' => !isset($cur_profile['id_theme']) && !empty($defaultSettings) ? 0 : (int) $cur_profile['id_theme'],
'selected_member' => $memID,
)
);
$temp = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($row['id_member'] == -1)
{
$temp[$row['variable']] = $row['value'];
continue;
}
if (isset($_POST['options'][$row['variable']]))
$row['value'] = $_POST['options'][$row['variable']];
$context['member']['options'][$row['variable']] = $row['value'];
}
$smcFunc['db_free_result']($request);
foreach ($temp as $k => $v)
{
if (!isset($context['member']['options'][$k]))
$context['member']['options'][$k] = $v;
}
}
}
function ignoreboards($memID)
{
global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir;
if (empty($modSettings['allow_ignore_boards']))
fatal_lang_error('ignoreboards_disallowed', 'user');
$request = $smcFunc['db_query']('order_by_board_order', '
SELECT b.id_cat, c.name AS cat_name, b.id_board, b.name, b.child_level,
' . (!empty($cur_profile['ignore_boards']) ? 'b.id_board IN ({array_int:ignore_boards})' : '0') . ' AS is_ignored
FROM {db_prefix}boards AS b
LEFT JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
WHERE {query_see_board}
AND redirect = {string:empty_string}',
array(
'ignore_boards' => !empty($cur_profile['ignore_boards']) ? explode(',', $cur_profile['ignore_boards']) : array(),
'empty_string' => '',
)
);
$context['num_boards'] = $smcFunc['db_num_rows']($request);
$context['categories'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (!isset($context['categories'][$row['id_cat']]))
$context['categories'][$row['id_cat']] = array(
'id' => $row['id_cat'],
'name' => $row['cat_name'],
'boards' => array()
);
$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
'id' => $row['id_board'],
'name' => $row['name'],
'child_level' => $row['child_level'],
'selected' => $row['is_ignored'],
);
}
$smcFunc['db_free_result']($request);
require_once($sourcedir . '/Subs-Boards.php');
sortCategories($context['categories']);
$temp_boards = array();
foreach ($context['categories'] as $category)
{
$context['categories'][$category['id']]['child_ids'] = array_keys($category['boards']);
$temp_boards[] = array(
'name' => $category['name'],
'child_ids' => array_keys($category['boards'])
);
$temp_boards = array_merge($temp_boards, array_values($category['boards']));
}
$max_boards = ceil(count($temp_boards) / 2);
if ($max_boards == 1)
$max_boards = 2;
$context['board_columns'] = array();
for ($i = 0; $i < $max_boards; $i++)
{
$context['board_columns'][] = $temp_boards[$i];
if (isset($temp_boards[$i + $max_boards]))
$context['board_columns'][] = $temp_boards[$i + $max_boards];
else
$context['board_columns'][] = array();
}
loadThemeOptions($memID);
}
function profileLoadLanguages()
{
global $context;
$context['profile_languages'] = array();
getLanguages();
foreach ($context['languages'] as $lang)
{
$context['profile_languages'][$lang['filename']] = strtr($lang['name'], array('-utf8' => ''));
}
ksort($context['profile_languages']);
return count($context['profile_languages']) > 1 ? true : false;
}
function profileLoadGroups()
{
global $cur_profile, $txt, $context, $smcFunc, $user_settings;
$context['member_groups'] = array(
0 => array(
'id' => 0,
'name' => $txt['no_primary_membergroup'],
'is_primary' => $cur_profile['id_group'] == 0,
'can_be_additional' => false,
'can_be_primary' => true,
)
);
$curGroups = explode(',', $cur_profile['additional_groups']);
$request = $smcFunc['db_query']('', '
SELECT group_name, id_group, hidden
FROM {db_prefix}membergroups
WHERE id_group != {int:moderator_group}
AND min_posts = {int:min_posts}' . (allowedTo('admin_forum') ? '' : '
AND group_type != {int:is_protected}') . '
ORDER BY min_posts, CASE WHEN id_group < {int:newbie_group} THEN id_group ELSE 4 END, group_name',
array(
'moderator_group' => 3,
'min_posts' => -1,
'is_protected' => 1,
'newbie_group' => 4,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($row['id_group'] == 1 && !allowedTo('admin_forum'))
continue;
$context['member_groups'][$row['id_group']] = array(
'id' => $row['id_group'],
'name' => $row['group_name'],
'is_primary' => $cur_profile['id_group'] == $row['id_group'],
'is_additional' => in_array($row['id_group'], $curGroups),
'can_be_additional' => true,
'can_be_primary' => $row['hidden'] != 2,
);
}
$smcFunc['db_free_result']($request);
$context['member']['group_id'] = $user_settings['id_group'];
return true;
}
function profileLoadSignatureData()
{
global $modSettings, $context, $txt, $cur_profile, $memberContext;
list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
$sig_limits = explode(',', $sig_limits);
$context['signature_enabled'] = isset($sig_limits[0]) ? $sig_limits[0] : 0;
$context['signature_limits'] = array(
'max_length' => isset($sig_limits[1]) ? $sig_limits[1] : 0,
'max_lines' => isset($sig_limits[2]) ? $sig_limits[2] : 0,
'max_images' => isset($sig_limits[3]) ? $sig_limits[3] : 0,
'max_smileys' => isset($sig_limits[4]) ? $sig_limits[4] : 0,
'max_image_width' => isset($sig_limits[5]) ? $sig_limits[5] : 0,
'max_image_height' => isset($sig_limits[6]) ? $sig_limits[6] : 0,
'max_font_size' => isset($sig_limits[7]) ? $sig_limits[7] : 0,
'bbc' => !empty($sig_bbc) ? explode(',', $sig_bbc) : array(),
);
$context['max_signature_length'] = $context['signature_limits']['max_length'];
$context['signature_warning'] = '';
if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height'])
$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']);
elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height'])
$context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']);
$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_character_set'] == 'UTF-8' || function_exists('iconv'))));
if (empty($context['do_preview']))
$context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '<', '>', '"', '''), $cur_profile['signature']);
else
{
$signature = !empty($_POST['signature']) ? $_POST['signature'] : '';
$validation = profileValidateSignature($signature);
if (empty($context['post_errors']))
{
loadLanguage('Errors');
$context['post_errors'] = array();
}
$context['post_errors'][] = 'signature_not_yet_saved';
if ($validation !== true && $validation !== false)
$context['post_errors'][] = $validation;
censorText($context['member']['signature']);
$context['member']['current_signature'] = $context['member']['signature'];
censorText($signature);
$context['member']['signature_preview'] = parse_bbc($signature, true, 'sig' . $memberContext[$context['id_member']]);
$context['member']['signature'] = $_POST['signature'];
}
if ($context['show_spellchecking'])
loadJavaScriptFile('spellcheck.js', array('defer' => false, 'minimize' => true), 'smf_spellcheck');
return true;
}
function profileLoadAvatarData()
{
global $context, $cur_profile, $modSettings, $scripturl;
$context['avatar_url'] = $modSettings['avatar_url'];
$context['member']['avatar'] += array(
'custom' => stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://') ? $cur_profile['avatar'] : 'http://',
'selection' => $cur_profile['avatar'] == '' || (stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) ? '' : $cur_profile['avatar'],
'allow_server_stored' => (empty($modSettings['gravatarEnabled']) || empty($modSettings['gravatarOverride'])) && (allowedTo('profile_server_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any'))),
'allow_upload' => (empty($modSettings['gravatarEnabled']) || empty($modSettings['gravatarOverride'])) && (allowedTo('profile_upload_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any'))),
'allow_external' => (empty($modSettings['gravatarEnabled']) || empty($modSettings['gravatarOverride'])) && (allowedTo('profile_remote_avatar') || (!$context['user']['is_owner'] && allowedTo('profile_extra_any'))),
'allow_gravatar' => !empty($modSettings['gravatarEnabled']) || !empty($modSettings['gravatarOverride']),
);
if ($context['member']['avatar']['allow_gravatar'] && (stristr($cur_profile['avatar'], 'gravatar://') || !empty($modSettings['gravatarOverride'])))
{
$context['member']['avatar'] += array(
'choice' => 'gravatar',
'server_pic' => 'blank.png',
'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11)
);
$context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']);
}
elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload'])
{
$context['member']['avatar'] += array(
'choice' => 'upload',
'server_pic' => 'blank.png',
'external' => 'http://'
);
$context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename'];
}
elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external'])
$context['member']['avatar'] += array(
'choice' => 'external',
'server_pic' => 'blank.png',
'external' => $cur_profile['avatar_original']
);
elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored'])
$context['member']['avatar'] += array(
'choice' => 'server_stored',
'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'],
'external' => 'http://'
);
else
$context['member']['avatar'] += array(
'choice' => 'none',
'server_pic' => 'blank.png',
'external' => 'http://'
);
if ($context['member']['avatar']['allow_server_stored'])
{
$context['avatar_list'] = array();
$context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array();
}
else
$context['avatars'] = array();
$context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1);
return !empty($context['member']['avatar']['allow_server_stored']) || !empty($context['member']['avatar']['allow_external']) || !empty($context['member']['avatar']['allow_upload']) || !empty($context['member']['avatar']['allow_gravatar']);
}
function profileSaveGroups(&$value)
{
global $profile_vars, $old_profile, $context, $smcFunc, $cur_profile;
if (!allowedTo('admin_forum'))
{
$request = $smcFunc['db_query']('', '
SELECT id_group
FROM {db_prefix}membergroups
WHERE group_type = {int:is_protected}',
array(
'is_protected' => 1,
)
);
$protected_groups = array(1);
while ($row = $smcFunc['db_fetch_assoc']($request))
$protected_groups[] = $row['id_group'];
$smcFunc['db_free_result']($request);
$protected_groups = array_unique($protected_groups);
}
if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0)
$value = (int) $value;
else
$value = $old_profile['id_group'];
if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups']))
{
$additional_groups = array();
foreach ($_POST['additional_groups'] as $group_id)
{
$group_id = (int) $group_id;
if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups)))
$additional_groups[] = $group_id;
}
$old_additional_groups = explode(',', $old_profile['additional_groups']);
foreach ($old_additional_groups as $group_id)
{
if (!empty($protected_groups) && in_array($group_id, $protected_groups))
$additional_groups[] = $group_id;
}
if (implode(',', $additional_groups) !== $old_profile['additional_groups'])
{
$profile_vars['additional_groups'] = implode(',', $additional_groups);
$cur_profile['additional_groups'] = implode(',', $additional_groups);
}
}
if (in_array(1, explode(',', $old_profile['additional_groups'])) || $old_profile['id_group'] == 1)
{
$stillAdmin = $value == 1 || (isset($additional_groups) && in_array(1, $additional_groups));
if (!$stillAdmin)
{
$request = $smcFunc['db_query']('', '
SELECT id_member
FROM {db_prefix}members
WHERE (id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0)
AND id_member != {int:selected_member}
LIMIT 1',
array(
'admin_group' => 1,
'selected_member' => $context['id_member'],
)
);
list ($another) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
if (empty($another))
fatal_lang_error('at_least_one_admin', 'critical');
}
}
if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups']))
{
if ($context['user']['is_owner'])
$_SESSION['mc']['time'] = 0;
else
updateSettings(array('settings_updated' => time()));
}
call_integration_hook('integrate_profile_profileSaveGroups', array($value, $additional_groups));
return true;
}
function profileSaveAvatarData(&$value)
{
global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context;
$memID = $context['id_member'];
$context['max_external_size_url'] = 255;
if (empty($memID) && !empty($context['password_auth_failed']))
return false;
require_once($sourcedir . '/ManageAttachments.php');
call_integration_hook('before_profile_save_avatar', array(&$value));
if ($value == 'external' && allowedTo('profile_remote_avatar') && strlen($_POST['userpicpersonal']) > $context['max_external_size_url'])
return 'bad_avatar_url_too_long';
$uploadDir = $modSettings['custom_avatar_dir'];
$id_folder = 1;
$downloadedExternalAvatar = false;
if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external']))
{
if (!is_writable($uploadDir))
fatal_lang_error('attachments_no_write', 'critical');
$url = parse_url($_POST['userpicpersonal']);
$contents = fetch_web_data($url['scheme'] . '://' . $url['host'] . (empty($url['port']) ? '' : ':' . $url['port']) . str_replace(' ', '%20', trim($url['path'])));
$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
if ($contents != false && $tmpAvatar = fopen($new_filename, 'wb'))
{
fwrite($tmpAvatar, $contents);
fclose($tmpAvatar);
$downloadedExternalAvatar = true;
$_FILES['attachment']['tmp_name'] = $new_filename;
}
}
if ($value == 'none')
{
$profile_vars['avatar'] = '';
$cur_profile['id_attach'] = 0;
$cur_profile['attachment_type'] = 0;
$cur_profile['filename'] = '';
removeAttachments(array('id_member' => $memID));
}
elseif ($value == 'server_stored' && allowedTo('profile_server_avatar'))
{
$profile_vars['avatar'] = strtr(empty($_POST['file']) ? (empty($_POST['cat']) ? '' : $_POST['cat']) : $_POST['file'], array('&' => '&'));
$profile_vars['avatar'] = preg_match('~^([\w _!@%*=\-#()\[\]&.,]+/)?[\w _!@%*=\-#()\[\]&.,]+$~', $profile_vars['avatar']) != 0 && preg_match('/\.\./', $profile_vars['avatar']) == 0 && file_exists($modSettings['avatar_directory'] . '/' . $profile_vars['avatar']) ? ($profile_vars['avatar'] == 'blank.png' ? '' : $profile_vars['avatar']) : '';
$cur_profile['id_attach'] = 0;
$cur_profile['attachment_type'] = 0;
$cur_profile['filename'] = '';
removeAttachments(array('id_member' => $memID));
}
elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled']))
{
if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL))
$profile_vars['avatar'] = 'gravatar://';
else
$profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : '');
removeAttachments(array('id_member' => $memID));
}
elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external']))
{
$cur_profile['id_attach'] = 0;
$cur_profile['attachment_type'] = 0;
$cur_profile['filename'] = '';
removeAttachments(array('id_member' => $memID));
$profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal']));
if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///')
$profile_vars['avatar'] = '';
elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://')
return 'bad_avatar_invalid_url';
elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external']))
{
$sizes = url_image_size($profile_vars['avatar']);
if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external']
&& !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external']
&& !empty($modSettings['avatar_max_height_external']))))
{
if ($modSettings['avatar_action_too_large'] == 'option_refuse')
return 'bad_avatar_too_large';
elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize')
{
require_once($sourcedir . '/Subs-Graphics.php');
if (downloadAvatar($profile_vars['avatar'], $memID, $modSettings['avatar_max_width_external'], $modSettings['avatar_max_height_external']))
{
$profile_vars['avatar'] = '';
$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
}
else
return 'bad_avatar';
}
}
}
}
elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar)
{
if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar)
{
if (!$downloadedExternalAvatar)
{
if (!is_writable($uploadDir))
fatal_lang_error('avatars_no_write', 'critical');
$new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true);
if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename))
fatal_lang_error('attach_timeout', 'critical');
$_FILES['attachment']['tmp_name'] = $new_filename;
}
$sizes = @getimagesize($_FILES['attachment']['tmp_name']);
if ($sizes === false)
{
@unlink($_FILES['attachment']['tmp_name']);
return 'bad_avatar';
}
elseif ((!empty($modSettings['avatar_max_width_upload']) && $sizes[0] > $modSettings['avatar_max_width_upload'])
|| (!empty($modSettings['avatar_max_height_upload']) && $sizes[1] > $modSettings['avatar_max_height_upload']))
{
if (!empty($modSettings['avatar_resize_upload']))
{
smf_chmod($_FILES['attachment']['tmp_name'], 0644);
require_once($sourcedir . '/Subs-Graphics.php');
if (!downloadAvatar($_FILES['attachment']['tmp_name'], $memID, $modSettings['avatar_max_width_upload'], $modSettings['avatar_max_height_upload']))
{
@unlink($_FILES['attachment']['tmp_name']);
return 'bad_avatar';
}
$cur_profile['id_attach'] = $modSettings['new_avatar_data']['id'];
$cur_profile['filename'] = $modSettings['new_avatar_data']['filename'];
$cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type'];
}
else
{
@unlink($_FILES['attachment']['tmp_name']);
return 'bad_avatar_too_large';
}
}
elseif (is_array($sizes))
{
require_once($sourcedir . '/Subs-Graphics.php');
if (!checkImageContents($_FILES['attachment']['tmp_name'], !empty($modSettings['avatar_paranoid'])))
{
if (empty($modSettings['avatar_reencode']) || (!reencodeImage($_FILES['attachment']['tmp_name'], $sizes[2])))
{
@unlink($_FILES['attachment']['tmp_name']);
return 'bad_avatar_fail_reencode';
}
$sizes = @getimagesize($_FILES['attachment']['tmp_name']);
if ($sizes === false)
{
@unlink($_FILES['attachment']['tmp_name']);
return 'bad_avatar';
}
}
$extensions = array(
'1' => 'gif',
'2' => 'jpg',
'3' => 'png',
'6' => 'bmp'
);
$extension = isset($extensions[$sizes[2]]) ? $extensions[$sizes[2]] : 'bmp';
$mime_type = 'image/' . ($extension === 'jpg' ? 'jpeg' : ($extension === 'bmp' ? 'x-ms-bmp' : $extension));
$destName = 'avatar_' . $memID . '_' . time() . '.' . $extension;
list ($width, $height) = getimagesize($_FILES['attachment']['tmp_name']);
$file_hash = '';
removeAttachments(array('id_member' => $memID));
$cur_profile['id_attach'] = $smcFunc['db_insert']('',
'{db_prefix}attachments',
array(
'id_member' => 'int', 'attachment_type' => 'int', 'filename' => 'string', 'file_hash' => 'string', 'fileext' => 'string', 'size' => 'int',
'width' => 'int', 'height' => 'int', 'mime_type' => 'string', 'id_folder' => 'int',
),
array(
$memID, 1, $destName, $file_hash, $extension, filesize($_FILES['attachment']['tmp_name']),
(int) $width, (int) $height, $mime_type, $id_folder,
),
array('id_attach'),
1
);
$cur_profile['filename'] = $destName;
$cur_profile['attachment_type'] = 1;
$destinationPath = $uploadDir . '/' . (empty($file_hash) ? $destName : $cur_profile['id_attach'] . '_' . $file_hash . '.dat');
if (!rename($_FILES['attachment']['tmp_name'], $destinationPath))
{
removeAttachments(array('id_member' => $memID));
fatal_lang_error('attach_timeout', 'critical');
}
smf_chmod($uploadDir . '/' . $destinationPath, 0644);
}
$profile_vars['avatar'] = '';
if (file_exists($_FILES['attachment']['tmp_name']))
@unlink($_FILES['attachment']['tmp_name']);
}
else
$profile_vars['avatar'] = '';
}
elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar'))
$profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address'])));
else
$profile_vars['avatar'] = '';
$cur_profile['avatar'] = $profile_vars['avatar'];
call_integration_hook('after_profile_save_avatar');
return false;
}
function profileValidateSignature(&$value)
{
global $sourcedir, $modSettings, $smcFunc, $txt;
require_once($sourcedir . '/Subs-Post.php');
if (!allowedTo('admin_forum'))
{
list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
$sig_limits = explode(',', $sig_limits);
$disabledTags = !empty($sig_bbc) ? explode(',', $sig_bbc) : array();
$unparsed_signature = strtr(un_htmlspecialchars($value), array("\r" => '', ''' => '\''));
if (!empty($sig_limits[2]) && substr_count($unparsed_signature, "\n") >= $sig_limits[2])
{
$txt['profile_error_signature_max_lines'] = sprintf($txt['profile_error_signature_max_lines'], $sig_limits[2]);
return 'signature_max_lines';
}
if (!empty($sig_limits[3]) && (substr_count(strtolower($unparsed_signature), '[img') + substr_count(strtolower($unparsed_signature), '<img')) > $sig_limits[3])
{
$txt['profile_error_signature_max_image_count'] = sprintf($txt['profile_error_signature_max_image_count'], $sig_limits[3]);
return 'signature_max_image_count';
}
$smiley_parsed = $unparsed_signature;
parsesmileys($smiley_parsed);
$smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img');
if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0)
return 'signature_allow_smileys';
elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4])
{
$txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]);
return 'signature_max_smileys';
}
if (!empty($sig_limits[7]) && preg_match_all('~\[size=([\d\.]+)?(px|pt|em|x-large|larger)~i', $unparsed_signature, $matches) !== false && isset($matches[2]))
{
foreach ($matches[1] as $ind => $size)
{
$limit_broke = 0;
if ($matches[2][$ind] == 'px' && $size > $sig_limits[7])
$limit_broke = $sig_limits[7] . 'px';
elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75))
$limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt';
elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16))
$limit_broke = ((float) $sig_limits[7] / 16) . 'em';
elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18)
$limit_broke = 'large';
if ($limit_broke)
{
$txt['profile_error_signature_max_font_size'] = sprintf($txt['profile_error_signature_max_font_size'], $limit_broke);
return 'signature_max_font_size';
}
}
}
if ((!empty($sig_limits[5]) || !empty($sig_limits[6])))
{
preg_match_all('~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?(\s+width=([\d]+))?\s*\](?:<br>)*([^<">]+?)(?:<br>)*\[/img\]~i', $unparsed_signature, $matches);
preg_match_all('~<img\s+src=(?:")?((?:http://|ftp://|https://|ftps://).+?)(?:")?(?:\s+alt=(?:")?(.*?)(?:")?)?(?:\s?/)?' . '>~i', $unparsed_signature, $matches2, PREG_PATTERN_ORDER);
if (!empty($matches2))
{
foreach ($matches2[0] as $ind => $dummy)
{
$matches[0][] = $matches2[0][$ind];
$matches[1][] = '';
$matches[2][] = '';
$matches[3][] = '';
$matches[4][] = '';
$matches[5][] = '';
$matches[6][] = '';
$matches[7][] = $matches2[1][$ind];
}
}
$replaces = array();
if (!empty($matches))
{
foreach ($matches[0] as $key => $image)
{
$width = -1;
$height = -1;
if ($matches[6][$key])
$matches[2][$key] = $matches[6][$key];
if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5])
{
$width = $sig_limits[5];
$matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]);
}
elseif ($matches[2][$key])
$width = $matches[2][$key];
if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6])
{
$height = $sig_limits[6];
if ($width != -1)
$width = $width * ($height / $matches[4][$key]);
}
elseif ($matches[4][$key])
$height = $matches[4][$key];
if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6]))
{
$sizes = url_image_size($matches[7][$key]);
if (is_array($sizes))
{
if ($sizes[0] > $sig_limits[5] && $sig_limits[5])
{
$width = $sig_limits[5];
$sizes[1] = $sizes[1] * ($width / $sizes[0]);
}
if ($sizes[1] > $sig_limits[6] && $sig_limits[6])
{
$height = $sig_limits[6];
if ($width == -1)
$width = $sizes[0];
$width = $width * ($height / $sizes[1]);
}
elseif ($width != -1)
$height = $sizes[1];
}
}
if ($width != -1 || $height != -1)
$replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]';
}
if (!empty($replaces))
$value = str_replace(array_keys($replaces), array_values($replaces), $value);
}
}
$disabledSigBBC = implode('|', $disabledTags);
if (!empty($disabledSigBBC))
{
if (preg_match('~\[(' . $disabledSigBBC . '[ =\]/])~i', $unparsed_signature, $matches) !== false && isset($matches[1]))
{
$disabledTags = array_unique($disabledTags);
$txt['profile_error_signature_disabled_bbc'] = sprintf($txt['profile_error_signature_disabled_bbc'], implode(', ', $disabledTags));
return 'signature_disabled_bbc';
}
}
}
preparsecode($value);
if (!allowedTo('admin_forum') && !empty($sig_limits[1]) && $smcFunc['strlen'](str_replace('<br>', "\n", $value)) > $sig_limits[1])
{
$_POST['signature'] = trim($smcFunc['htmlspecialchars'](str_replace('<br>', "\n", $value), ENT_QUOTES));
$txt['profile_error_signature_max_length'] = sprintf($txt['profile_error_signature_max_length'], $sig_limits[1]);
return 'signature_max_length';
}
return true;
}
function profileValidateEmail($email, $memID = 0)
{
global $smcFunc;
$email = strtr($email, array(''' => '\''));
if (trim($email) == '')
return 'no_email';
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
return 'bad_email';
$request = $smcFunc['db_query']('', '
SELECT id_member
FROM {db_prefix}members
WHERE ' . ($memID != 0 ? 'id_member != {int:selected_member} AND ' : '') . '
email_address = {string:email_address}
LIMIT 1',
array(
'selected_member' => $memID,
'email_address' => $email,
)
);
if ($smcFunc['db_num_rows']($request) > 0)
return 'email_taken';
$smcFunc['db_free_result']($request);
return true;
}
function profileReloadUser()
{
global $modSettings, $context, $cur_profile;
if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '')
setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt']));
loadUserSettings();
writeLog();
}
function profileSendActivation()
{
global $sourcedir, $profile_vars, $context, $scripturl, $smcFunc, $cookiename, $cur_profile, $language, $modSettings;
require_once($sourcedir . '/Subs-Post.php');
if (empty($profile_vars['email_address']))
return;
$replacements = array(
'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'],
'ACTIVATIONCODE' => $profile_vars['validation_code'],
'ACTIVATIONLINKWITHOUTCODE' => $scripturl . '?action=activate;u=' . $context['id_member'],
);
$emaildata = loadEmailTemplate('activate_reactivate', $replacements, empty($cur_profile['lngfile']) || empty($modSettings['userLanguage']) ? $language : $cur_profile['lngfile']);
sendmail($profile_vars['email_address'], $emaildata['subject'], $emaildata['body'], null, 'reactivate', $emaildata['is_html'], 0);
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}log_online
WHERE id_member = {int:selected_member}',
array(
'selected_member' => $context['id_member'],
)
);
$_SESSION['log_time'] = 0;
$_SESSION['login_' . $cookiename] = $smcFunc['json_encode'](array(0, '', 0));
if (isset($_COOKIE[$cookiename]))
$_COOKIE[$cookiename] = '';
loadUserSettings();
$context['user']['is_logged'] = false;
$context['user']['is_guest'] = true;
redirectexit('action=sendactivation');
}
function groupMembership($memID)
{
global $txt, $user_profile, $context, $smcFunc;
$curMember = $user_profile[$memID];
$context['primary_group'] = $curMember['id_group'];
$context['can_manage_membergroups'] = allowedTo('manage_membergroups');
$context['can_manage_protected'] = allowedTo('admin_forum');
$context['can_edit_primary'] = $context['can_manage_protected'];
$context['update_message'] = isset($_GET['msg']) && isset($txt['group_membership_msg_' . $_GET['msg']]) ? $txt['group_membership_msg_' . $_GET['msg']] : '';
$groups = explode(',', $curMember['additional_groups']);
$groups[] = $curMember['id_group'];
if (empty($groups))
$groups = array(0);
foreach ($groups as $k => $v)
$groups[$k] = (int) $v;
$request = $smcFunc['db_query']('', '
SELECT mg.id_group, mg.group_name, mg.description, mg.group_type, mg.online_color, mg.hidden,
COALESCE(lgr.id_member, 0) AS pending
FROM {db_prefix}membergroups AS mg
LEFT JOIN {db_prefix}log_group_requests AS lgr ON (lgr.id_member = {int:selected_member} AND lgr.id_group = mg.id_group AND lgr.status = {int:status_open})
WHERE (mg.id_group IN ({array_int:group_list})
OR mg.group_type > {int:nonjoin_group_id})
AND mg.min_posts = {int:min_posts}
AND mg.id_group != {int:moderator_group}
ORDER BY group_name',
array(
'group_list' => $groups,
'selected_member' => $memID,
'status_open' => 0,
'nonjoin_group_id' => 1,
'min_posts' => -1,
'moderator_group' => 3,
)
);
$context['groups'] = array(
'member' => array(),
'available' => array()
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups)))
$context['can_edit_primary'] = true;
if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group'])
continue;
$context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array(
'id' => $row['id_group'],
'name' => $row['group_name'],
'desc' => $row['description'],
'color' => $row['online_color'],
'type' => $row['group_type'],
'pending' => $row['pending'],
'is_primary' => $row['id_group'] == $context['primary_group'],
'can_be_primary' => $row['hidden'] != 2,
'can_leave' => $row['id_group'] != 1 && $row['group_type'] > 1 ? true : false,
);
}
$smcFunc['db_free_result']($request);
$context['groups']['member'][0] = array(
'id' => 0,
'name' => $txt['regular_members'],
'desc' => $txt['regular_members_desc'],
'type' => 0,
'is_primary' => $context['primary_group'] == 0 ? true : false,
'can_be_primary' => true,
'can_leave' => 0,
);
if (count($context['groups']['member']) < 2)
$context['can_edit_primary'] = false;
if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2)
$context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']];
}
function groupMembership2($profile_vars, $post_errors, $memID)
{
global $user_info, $context, $user_profile, $modSettings, $smcFunc;
if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership']))
isAllowedTo('manage_membergroups');
if (!isset($_REQUEST['gid']) && !isset($_POST['primary']))
fatal_lang_error('no_access', false);
checkSession(isset($_GET['gid']) ? 'get' : 'post');
$old_profile = &$user_profile[$memID];
$context['can_manage_membergroups'] = allowedTo('manage_membergroups');
$context['can_manage_protected'] = allowedTo('admin_forum');
$newPrimary = $old_profile['id_group'];
$addGroups = array_flip(explode(',', $old_profile['additional_groups']));
$canChangePrimary = $old_profile['id_group'] == 0 ? 1 : 0;
$changeType = isset($_POST['primary']) ? 'primary' : (isset($_POST['req']) ? 'request' : 'free');
$group_id = isset($_REQUEST['gid']) ? (int) $_REQUEST['gid'] : (int) $_POST['primary'];
$foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false;
if ($group_id == 1)
isAllowedTo('admin_forum');
else
{
$request = $smcFunc['db_query']('', '
SELECT group_type
FROM {db_prefix}membergroups
WHERE id_group = {int:current_group}
LIMIT {int:limit}',
array(
'current_group' => $group_id,
'limit' => 1,
)
);
list ($is_protected) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
if ($is_protected == 1)
isAllowedTo('admin_forum');
}
$request = $smcFunc['db_query']('', '
SELECT id_group, group_type, hidden, group_name
FROM {db_prefix}membergroups
WHERE id_group IN ({int:group_list}, {int:current_group})',
array(
'group_list' => $group_id,
'current_group' => $old_profile['id_group'],
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($row['id_group'] == $group_id)
{
$foundTarget = true;
$group_name = $row['group_name'];
if ($changeType == 'request' && $row['group_type'] != 2)
fatal_lang_error('no_access', false);
elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']]))
fatal_lang_error('no_access', false);
elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2)
fatal_lang_error('no_access', false);
if ($row['hidden'] == 2)
$canChangePrimary = false;
}
if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false)
$canChangePrimary = 1;
if ($changeType != 'primary' && $old_profile['id_group'] != 0)
$canChangePrimary = false;
if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0))
$canChangePrimary = false;
}
$smcFunc['db_free_result']($request);
if (!$foundTarget)
fatal_lang_error('no_access', false);
if ($context['can_manage_membergroups'] && !allowedTo('admin_forum'))
{
$request = $smcFunc['db_query']('', '
SELECT COUNT(permission)
FROM {db_prefix}permissions
WHERE id_group = {int:selected_group}
AND permission = {string:admin_forum}
AND add_deny = {int:not_denied}',
array(
'selected_group' => $group_id,
'not_denied' => 1,
'admin_forum' => 'admin_forum',
)
);
list ($disallow) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
if ($disallow)
isAllowedTo('admin_forum');
}
if ($changeType == 'request')
{
$request = $smcFunc['db_query']('', '
SELECT id_member
FROM {db_prefix}log_group_requests
WHERE id_member = {int:selected_member}
AND id_group = {int:selected_group}
AND status = {int:status_open}',
array(
'selected_member' => $memID,
'selected_group' => $group_id,
'status_open' => 0,
)
);
if ($smcFunc['db_num_rows']($request) != 0)
fatal_lang_error('profile_error_already_requested_group');
$smcFunc['db_free_result']($request);
$smcFunc['db_insert']('',
'{db_prefix}log_group_requests',
array(
'id_member' => 'int', 'id_group' => 'int', 'time_applied' => 'int', 'reason' => 'string-65534',
'status' => 'int', 'id_member_acted' => 'int', 'member_name_acted' => 'string', 'time_acted' => 'int', 'act_reason' => 'string',
),
array(
$memID, $group_id, time(), $_POST['reason'],
0, 0, '', 0, '',
),
array('id_request')
);
$data = $smcFunc['json_encode'](array('id_member' => $memID, 'member_name' => $user_info['name'], 'id_group' => $group_id, 'group_name' => $group_name, 'reason' => $_POST['reason'], 'time' => time()));
$smcFunc['db_insert']('insert', '{db_prefix}background_tasks',
array('task_file' => 'string-255', 'task_class' => 'string-255', 'task_data' => 'string', 'claimed_time' => 'int'),
array('$sourcedir/tasks/GroupReq-Notify.php', 'GroupReq_Notify_Background', $data, 0), array()
);
return $changeType;
}
elseif ($changeType == 'free')
{
if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id]))
{
if ($old_profile['id_group'] == $group_id)
$newPrimary = 0;
else
unset($addGroups[$group_id]);
}
else
{
if ($canChangePrimary)
{
if ($old_profile['id_group'] != 0)
$addGroups[$old_profile['id_group']] = -1;
$newPrimary = $group_id;
}
else
$addGroups[$group_id] = -1;
}
}
elseif ($canChangePrimary)
{
if ($old_profile['id_group'] != 0)
$addGroups[$old_profile['id_group']] = -1;
if (isset($addGroups[$group_id]))
unset($addGroups[$group_id]);
$newPrimary = $group_id;
}
foreach ($addGroups as $id => $dummy)
if (empty($id))
unset($addGroups[$id]);
$addGroups = implode(',', array_flip($addGroups));
if ($context['user']['is_owner'])
$_SESSION['mc']['time'] = 0;
else
updateSettings(array('settings_updated' => time()));
updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups));
return $changeType;
}
function tfasetup($memID)
{
global $user_info, $context, $user_settings, $sourcedir, $modSettings, $smcFunc;
require_once($sourcedir . '/Class-TOTP.php');
require_once($sourcedir . '/Subs-Auth.php');
loadJavaScriptFile('qrcode.js', array('force_current' => false, 'validate' => true));
if (empty($user_settings['tfa_secret']) && $context['user']['is_owner'])
{
if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
fatal_lang_error('login_ssl_required', false);
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' && !isset($_REQUEST['backup']) && !isset($_REQUEST['forced']))
{
$context['from_ajax'] = true;
$context['template_layers'] = array();
}
if (!empty($_REQUEST['save']) && !empty($_SESSION['tfa_secret']))
{
$code = $_POST['tfa_code'];
$totp = new \TOTP\Auth($_SESSION['tfa_secret']);
$totp->setRange(1);
$valid_code = strlen($code) == $totp->getCodeLength() && $totp->validateCode($code);
if (empty($context['password_auth_failed']) && $valid_code)
{
$backup = substr(sha1($smcFunc['random_int']()), 0, 16);
$backup_encrypted = hash_password($user_settings['member_name'], $backup);
updateMemberData($memID, array(
'tfa_secret' => $_SESSION['tfa_secret'],
'tfa_backup' => $backup_encrypted,
));
setTFACookie(3153600, $memID, hash_salt($backup_encrypted, $user_settings['password_salt']));
unset($_SESSION['tfa_secret']);
$context['tfa_backup'] = $backup;
$context['sub_template'] = 'tfasetup_backup';
return;
}
else
{
$context['tfa_secret'] = $_SESSION['tfa_secret'];
$context['tfa_error'] = !$valid_code;
$context['tfa_pass_value'] = $_POST['oldpasswrd'];
$context['tfa_value'] = $_POST['tfa_code'];
}
}
else
{
$totp = new \TOTP\Auth();
$secret = $totp->generateCode();
$_SESSION['tfa_secret'] = $secret;
$context['tfa_secret'] = $secret;
$context['tfa_backup'] = isset($_REQUEST['backup']);
}
$context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']);
}
else
redirectexit('action=profile;area=account;u=' . $memID);
}
function tfadisable($memID)
{
global $context, $modSettings, $smcFunc, $user_settings;
if (!empty($user_settings['tfa_secret']))
{
if (!empty($modSettings['force_ssl']) && !httpsOn())
fatal_lang_error('login_ssl_required', false);
elseif ($modSettings['tfa_mode'] == 3 && $context['user']['is_owner'])
fatal_lang_error('cannot_disable_tfa', false);
elseif ($modSettings['tfa_mode'] == 2 && $context['user']['is_owner'])
{
$groups = array($user_settings['id_group']);
if (!empty($user_settings['additional_groups']))
$groups = array_unique(array_merge($groups, explode(',', $user_settings['additional_groups'])));
$request = $smcFunc['db_query']('', '
SELECT id_group
FROM {db_prefix}membergroups
WHERE tfa_required = {int:tfa_required}
AND id_group IN ({array_int:groups})',
array(
'tfa_required' => 1,
'groups' => $groups,
)
);
$tfa_required_groups = $smcFunc['db_num_rows']($request);
$smcFunc['db_free_result']($request);
if (!empty($tfa_required_groups))
fatal_lang_error('cannot_disable_tfa2', false);
}
}
else
redirectexit('action=profile;area=account;u=' . $memID);
}
?>