Spaces:
Sleeping
Sleeping
File size: 102,837 Bytes
07c3cdd | 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 | <?php
use ProcessMaker\Core\System;
/**
* class.bootstrap.php
*
* @package gulliver.system
*
*/
class Bootstrap
{
const hashFx = 'md5';
public static $includeClassPaths = array();
public static $includePaths = array();
protected $relativeIncludePaths = array();
//below here only approved methods
/**
* @deprecated 3.2.2, We keep this function only for backwards compatibility because is used in the plugin manager
*/
public static function autoloadClass($class)
{
}
/**
* @deprecated 3.2.2, We keep this function only for backwards compatibility because is used in the plugin manager
*/
public static function registerClass($className, $includePath)
{
}
/**
* @deprecated 3.2.2, We keep this function only for backwards compatibility because is used in the plugin manager
*/
public static function registerDir($name, $dir)
{
}
/*
* these functions still under revision
*/
public static function getSystemConfiguration($globalIniFile = '', $wsIniFile = '', $wsName = '')
{
return System::getSystemConfiguration($globalIniFile, $wsIniFile, $wsName);
}
/**
* @deprecated 3.2.2, We keep this function only for backwards compatibility because is used in the plugin manager
*/
public static function registerSystemClasses()
{
}
//below this line, still not approved methods
/**
* mk_dir , copied from class.G.php
*
* @return void
*/
public static function mk_dir($strPath, $rights = 0777)
{
$folder_path = array($strPath);
$oldumask = umask(0);
while (!@is_dir(dirname(end($folder_path))) && dirname(end($folder_path)) != '/' && dirname(end($folder_path)) != '.' && dirname(end($folder_path)) != '') {
array_push($folder_path, dirname(end($folder_path)));
// var_dump($folder_path);
// die;
}
while ($parent_folder_path = array_pop($folder_path)) {
if (!@is_dir($parent_folder_path)) {
if (!@mkdir($parent_folder_path, $rights)) {
// trigger_error ("Can't create folder
// \"$parent_folder_path\".", E_USER_WARNING);
umask($oldumask);
}
}
}
}
/**
* verify if all files & directories passed by param.
* are writable
*
* @author Erik Amaru Ortiz <erik@colosa.com>
* @param $resources array
* a list of files to verify write access
*/
public function verifyWriteAccess($resources)
{
$noWritable = array();
foreach ($resources as $i => $resource) {
if (!is_writable($resource)) {
$noWritable [] = $resource;
}
}
if (count($noWritable) > 0) {
$e = new Exception("Write access not allowed for ProcessMaker resources");
$e->files = $noWritable;
throw $e;
}
}
/**
* render a smarty template
*
* @author Erik Amaru Ortiz <erik@colosa.com>
* @param $template string
* containing the template filename on /gulliver/templates/
* directory
* @param $data associative
* array containig the template data
*/
public static function renderTemplate($template, $data = array())
{
if (!defined('PATH_THIRDPARTY')) {
throw new Exception('System constant (PATH_THIRDPARTY) is not defined!');
}
// file has absolute path
if (substr($template, 0, 1) != PATH_SEP) {
$template = PATH_TEMPLATE . $template;
}
if (! file_exists($template)) {
throw new Exception("Template: $template, doesn't exist!");
}
$filter = new InputFilter();
$smarty = new Smarty ();
$smarty->compile_dir = Bootstrap::sys_get_temp_dir();
$smarty->cache_dir = Bootstrap::sys_get_temp_dir();
$configDir = PATH_THIRDPARTY . 'smarty/configs';
$configDir = $filter->validateInput($configDir, 'path');
$smarty->config_dir = $configDir;
$templateDir = PATH_TEMPLATE;
$templateDir = $filter->validateInput($templateDir, 'path');
$smarty->template_dir = $templateDir;
$smarty->force_compile = true;
foreach ($data as $key => $value) {
$smarty->assign($key, $value);
}
$smarty->display($template);
}
/**
* @deprecated 3.2.2, We keep this function only for backwards compatibility because is used in the plugin manager
*/
public static function LoadSystem($strClass)
{
}
/**
* Get the temporal directory path on differents O.S.
* i.e. /temp -> linux, C:/Temp -> win
*
* @author <erik@colosa.com>
*/
public static function sys_get_temp_dir()
{
if (!function_exists('sys_get_temp_dir')) {
// Based on http://www.phpit.net/
// article/creating-zip-tar-archives-dynamically-php/2/
// Try to get from environment variable
if (!empty($_ENV ['TMP'])) {
return realpath($_ENV ['TMP']);
} elseif (!empty($_ENV ['TMPDIR'])) {
return realpath($_ENV ['TMPDIR']);
} elseif (!empty($_ENV ['TEMP'])) {
return realpath($_ENV ['TEMP']);
} else {
// Detect by creating a temporary file
// Try to use system's temporary directory as random name
// shouldn't exist
$temp_file = tempnam(Bootstrap::encryptOld(uniqid(rand(), true)), '');
if ($temp_file) {
$temp_dir = realpath(dirname($temp_file));
unlink($temp_file);
return $temp_dir;
} else {
return false;
}
}
} else {
return sys_get_temp_dir();
}
}
/**
* Transform a public URL into a local path.
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param string $url
* @param string $corvertionTable
* @param string $realPath
* = local path
* @return boolean
*/
public function virtualURI($url, $convertionTable, &$realPath)
{
foreach ($convertionTable as $urlPattern => $localPath) {
// $urlPattern = addcslashes( $urlPattern , '/');
$urlPattern = addcslashes($urlPattern, './');
$urlPattern = '/^' . str_replace(array('*', '?'), array('.*', '.?'), $urlPattern) . '$/';
if (preg_match($urlPattern, $url, $match)) {
if ($localPath === false) {
$realPath = $url;
return false;
}
if ($localPath != 'jsMethod') {
$realPath = $localPath . $match[1];
} else {
$realPath = $localPath;
}
return true;
}
}
$realPath = $url;
return false;
}
/**
* streaming a file
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $file
* @param boolean $download
* @param string $downloadFileName
* @return string
*/
public function streamFile($file, $download = false, $downloadFileName = '', $forceLoad = false)
{
$filter = new InputFilter();
$file = $filter->xssFilterHard($file);
$downloadFileName = $filter->xssFilterHard($downloadFileName);
$browserCacheFilesUid = G::browserCacheFilesGetUid();
if ($browserCacheFilesUid != null) {
$fileNameIni = $file = str_replace(".$browserCacheFilesUid", null, $file);
} else {
$fileNameIni = $file;
}
$folderarray = explode('/', $file);
$typearray = explode('.', basename($file));
$typefile = $typearray[count($typearray) - 1];
$filename = $file;
//trick to generate the translation.language.js file , merging two files
if (strtolower($typefile) == 'js' && $typearray[0] == 'translation') {
Bootstrap::sendHeaders($fileNameIni, "text/javascript", $download, $downloadFileName);
$output = Bootstrap::streamJSTranslationFile($filename, $typearray[count($typearray) - 2]);
echo $output;
return;
}
//trick to generate the big css file for ext style .
if (strtolower($typefile) == 'css' && $folderarray[count($folderarray) - 2] == 'css' && ! $forceLoad) {
Bootstrap::sendHeaders($fileNameIni, "text/css", $download, $downloadFileName);
$output = Bootstrap::streamCSSBigFile($typearray[0]);
echo $output;
return;
}
if (file_exists($filename)) {
switch (strtolower($typefile)) {
case 'swf':
Bootstrap::sendHeaders($fileNameIni, "application/x-shockwave-flash", $download, $downloadFileName);
break;
case 'js':
Bootstrap::sendHeaders($fileNameIni, "text/javascript", $download, $downloadFileName);
break;
case 'htm':
case 'html':
Bootstrap::sendHeaders($fileNameIni, "text/html", $download, $downloadFileName);
break;
case 'htc':
Bootstrap::sendHeaders($fileNameIni, "text/plain", $download, $downloadFileName);
break;
case 'json':
Bootstrap::sendHeaders($fileNameIni, "text/plain", $download, $downloadFileName);
break;
case 'gif':
Bootstrap::sendHeaders($fileNameIni, "image/gif", $download, $downloadFileName);
break;
case 'png':
Bootstrap::sendHeaders($fileNameIni, "image/png", $download, $downloadFileName);
break;
case 'jpg':
Bootstrap::sendHeaders($fileNameIni, "image/jpg", $download, $downloadFileName);
break;
case 'css':
Bootstrap::sendHeaders($fileNameIni, "text/css", $download, $downloadFileName);
break;
case 'xml':
Bootstrap::sendHeaders($fileNameIni, "text/xml", $download, $downloadFileName);
break;
case 'txt':
Bootstrap::sendHeaders($fileNameIni, "text/html", $download, $downloadFileName);
break;
case 'doc':
case 'pdf':
case 'pm':
case 'po':
Bootstrap::sendHeaders($fileNameIni, "application/octet-stream", $download, $downloadFileName);
break;
case 'php':
if ($download) {
Bootstrap::sendHeaders($fileNameIni, "text/plain", $download, $downloadFileName);
} else {
require_once ($filename);
return;
}
break;
case 'tar':
Bootstrap::sendHeaders($fileNameIni, "application/x-tar", $download, $downloadFileName);
break;
default:
//throw new Exception ( "Unknown type of file '$file'. " );
Bootstrap::sendHeaders($fileNameIni, "application/octet-stream", $download, $downloadFileName);
break;
}
} else {
if (strpos($file, 'gulliver') !== false) {
list ($path, $filename) = explode('gulliver', $file);
}
$_SESSION['phpFileNotFound'] = $file;
Bootstrap::header("location: /errors/error404.php?l=" . $_SERVER['REQUEST_URI']);
}
if (substr($filename, -10) == "ext-all.js") {
$filename = PATH_GULLIVER_HOME . 'js/ext/min/ext-all.js';
}
@readfile($filename);
}
/**
* Parsing the URI
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $urlLink
* @param array $arrayFriendlyUri
*
* @return string
*/
static public function parseURI($uri, array $arrayFriendlyUri = null)
{
// *** process the $_POST with magic_quotes enabled
// The magic_quotes_gpc feature has been DEPRECATED as of PHP 5.3.0.
if (get_magic_quotes_gpc() === 1) {
$_POST = g::strip_slashes($_POST);
}
$aRequestUri = explode('/', $uri);
$args = self::parseNormalUri($aRequestUri, $arrayFriendlyUri);
if (! empty($args)) {
define("SYS_LANG", $args ['SYS_LANG']);
define('SYS_SKIN', $args ['SYS_SKIN']);
define('SYS_COLLECTION', $args ['SYS_COLLECTION']);
define('SYS_TARGET', $args ['SYS_TARGET']);
if (array_key_exists('API_VERSION', $args)) {
define('API_VERSION', $args['API_VERSION']);
}
}
if ($args ['SYS_COLLECTION'] == 'js2') {
print "ERROR";
die();
}
}
/**
* isPMUnderUpdating, Used to set a file flag to check if PM is upgrading.
*
* @setFlag Contains the flag to set or unset the temporary file:
* 0 to delete the temporary file flag
* 1 to set the temporary file flag.
* 2 or bigger to check if the temporary file exists.
* @content Contains the content of the temporary file
* true to all workspace
* nameWorkspace to specific workspace
* return true if the file exists, otherwise false.
*/
public function isPMUnderUpdating($setFlag = 2, $content="true")
{
if (!defined('PATH_DATA')) {
return false;
}
$fileCheck = PATH_DATA . "UPDATE.dat";
if ($setFlag == 0) {
if (file_exists($fileCheck)) {
unlink($fileCheck);
}
} elseif ($setFlag == 1) {
$fp = fopen($fileCheck, 'w');
$line = fputs($fp, $content);
}
// checking temporary file
if ($setFlag >= 1) {
if (file_exists($fileCheck)) {
$res['action'] = true;
$fp = fopen($fileCheck, "r");
$res['workspace'] = fread($fp, filesize($fileCheck));
fclose($fp);
return $res;
}
}
return false;
}
/**
* parse a smarty template and return teh result as string
*
* @author Erik Amaru Ortiz <erik@colosa.com>
* @param $template string
* containing the template filename on /gulliver/templates/
* directory
* @param $data associative
* array containig the template data
* @return $content string containing the parsed template content
*/
public function parseTemplate($template, $data = array())
{
$content = '';
ob_start();
g::renderTemplate($template, $data);
$content = ob_get_contents();
ob_get_clean();
return $content;
}
/**
* @deprecated 3.2.2, We keep this function only for backwards compatibility because is used in the plugin manager
*/
public static function LoadClass($strClass)
{
}
/**
* @deprecated 3.2.2, We keep this function only for backwards compatibility because is used in the plugin manager
*/
public static function LoadThirdParty($sPath, $sFile)
{
}
/**
* Function LoadTranslationObject
* It generates a global Translation variable that will be used in all the
* system.
* Per script
*
* @author Hugo Loza. <hugo@colosa.com>
* @access public
* @param string lang
* @return void
*/
public static function LoadTranslationObject($lang = SYS_LANG)
{
$defaultTranslations = Array();
$foreignTranslations = Array();
// if the default translations table doesn't exist we can't proceed
if (!is_file(PATH_LANGUAGECONT . 'translation.en')) {
return null;
}
// load the translations table
require_once (PATH_LANGUAGECONT . 'translation.en');
$defaultTranslations = $translation;
// if some foreign language was requested and its translation file
// exists
if ($lang != 'en' && file_exists(PATH_LANGUAGECONT . 'translation.' . $lang)) {
require_once (PATH_LANGUAGECONT . 'translation.' . $lang); // load the foreign translations table
$foreignTranslations = $translation;
}
global $translation;
if (defined("SHOW_UNTRANSLATED_AS_TAG") && SHOW_UNTRANSLATED_AS_TAG != 0) {
$translation = $foreignTranslations;
} else {
$translation = array_merge($defaultTranslations, $foreignTranslations);
}
return true;
}
/**
* Function LoadTranslationPlugins
* It generates a global Translation variable for plugins
*
* Per script
*
* @author Brayan Pereyra <cochalo>. <brayan@colosa.com>
* @access public
* @param string lang
* @param array list plugins active
* @return void
*/
public static function LoadTranslationPlugins ($lang = SYS_LANG, $listPluginsActive)
{
if ( ! ( is_array ( $listPluginsActive ) ) ) {
return null;
}
foreach ($listPluginsActive['_aPluginDetails'] as $key => $value) {
$namePlugin = trim($key);
$translation = array();
if (!file_exists(PATH_LANGUAGECONT . $namePlugin . '.en')) {
Translation::generateFileTranslationPlugin($namePlugin, 'en');
}
if ( ($lang != 'en') && (!file_exists(PATH_LANGUAGECONT . $namePlugin . '.' . $lang)) ) {
Translation::generateFileTranslationPlugin($namePlugin, $lang);
}
if (file_exists(PATH_LANGUAGECONT . $namePlugin . '.' . $lang)) {
eval('global $translation'.$namePlugin.';');
require_once (PATH_LANGUAGECONT . $namePlugin . '.' . $lang);
} else {
if (file_exists(PATH_LANGUAGECONT . $namePlugin . '.en')) {
eval('global $translation'.$namePlugin.';');
require_once (PATH_LANGUAGECONT . $namePlugin . '.en');
}
}
}
return true;
}
/**
* Render Page
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param object $objContent
* @param string $strTemplate
* @param string $strSkin
* @return void
*/
public function RenderPage($strTemplate = "default", $strSkin = SYS_SKIN, $objContent = null, $layout = '')
{
global $G_CONTENT;
global $G_TEMPLATE;
global $G_SKIN;
global $G_PUBLISH;
$G_CONTENT = $objContent;
$G_TEMPLATE = $strTemplate;
$G_SKIN = $strSkin;
try {
$file = Bootstrap::ExpandPath('skinEngine') . 'skinEngine.php';
include $file;
$skinEngine = new SkinEngine($G_TEMPLATE, $G_SKIN, $G_CONTENT);
$skinEngine->setLayout($layout);
$skinEngine->dispatch();
} catch (Exception $e) {
global $G_PUBLISH;
if (is_null($G_PUBLISH)) {
$G_PUBLISH = new Publisher ();
}
if (count($G_PUBLISH->Parts) == 1) {
array_shift($G_PUBLISH->Parts);
}
global $oHeadPublisher;
$leimnudInitString = $oHeadPublisher->leimnudInitString;
$oHeadPublisher->clearScripts();
$oHeadPublisher->leimnudInitString = $leimnudInitString;
$oHeadPublisher->addScriptFile('/js/maborak/core/maborak.js');
$G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', null, array(
'MESSAGE' => $e->getMessage()
));
if (class_exists('SkinEngine')) {
$skinEngine = new SkinEngine('publish', 'blank', '');
$skinEngine->dispatch();
} else {
$token = strtotime("now");
PMException::registerErrorLog($e, $token);
G::outRes( G::LoadTranslation("ID_EXCEPTION_LOG_INTERFAZ", array($token)) );
die;
}
}
}
/**
* SendTemporalMessage
*
* @param string $msgID
* @param string $strType
* @param string $sType
* default value 'LABEL'
* @param date $time
* default value null
* @param integer $width
* default value null
* @param string $customLabels
* default value null
*
* @return void
*/
public function SendTemporalMessage($msgID, $strType, $sType = 'LABEL', $time = null, $width = null, $customLabels = null)
{
if (isset($width)) {
$_SESSION ['G_MESSAGE_WIDTH'] = $width;
}
if (isset($time)) {
$_SESSION ['G_MESSAGE_TIME'] = $time;
}
switch (strtolower($sType)) {
case 'label':
case 'labels':
$_SESSION ['G_MESSAGE_TYPE'] = $strType;
$_SESSION ['G_MESSAGE'] = nl2br(Bootstrap::LoadTranslation($msgID));
break;
case 'string':
$_SESSION ['G_MESSAGE_TYPE'] = $strType;
$_SESSION ['G_MESSAGE'] = nl2br($msgID);
break;
}
if ($customLabels != null) {
$message = $_SESSION ['G_MESSAGE'];
foreach ($customLabels as $key => $val) {
$message = str_replace('{' . nl2br($key) . '}', nl2br($val), $message);
}
$_SESSION ['G_MESSAGE'] = $message;
}
}
/**
* Redirect URL
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $parameter
* @return string
*/
public function header($parameter)
{
if (defined('ENABLE_ENCRYPT') && (ENABLE_ENCRYPT == 'yes') && (substr($parameter, 0, 9) == 'location:')) {
$url = Bootstrap::encrypt(substr($parameter, 10), URL_KEY);
header('location:' . $url);
} else {
header($parameter);
}
return;
}
/**
* Include all model plugin files
*
* LoadAllPluginModelClasses
*
* @author Hugo Loza <hugo@colosa.com>
* @access public
* @return void
*/
public function LoadAllPluginModelClasses()
{
// Get the current Include path, where the plugins directories should be
if (!defined('PATH_SEPARATOR')) {
define('PATH_SEPARATOR', (substr(PHP_OS, 0, 3) == 'WIN') ? ';' : ':' );
}
$path = explode(PATH_SEPARATOR, get_include_path());
foreach ($path as $possiblePath) {
if (strstr($possiblePath, "plugins")) {
$baseDir = $possiblePath . 'classes' . PATH_SEP . 'model';
if (file_exists($baseDir)) {
if ($handle = opendir($baseDir)) {
while (false !== ($file = readdir($handle))) {
if (strpos($file, '.php', 1) && !strpos($file, 'Peer.php', 1)) {
require_once ($baseDir . PATH_SEP . $file);
}
}
}
// Include also the extendGulliverClass that could have some
// new definitions for fields
if (file_exists($possiblePath . 'classes' . PATH_SEP . 'class.extendGulliver.php')) {
include_once $possiblePath . 'classes' . PATH_SEP . 'class.extendGulliver.php';
}
}
}
}
}
/**
* Expand the path using the path constants
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $strPath
* @return string
*/
public static function expandPath($strPath = '')
{
$res = "";
$res = PATH_CORE;
if ($strPath != "") {
$res .= $strPath . "/";
}
return $res;
}
/**
* function to calculate the time used to render a page
*/
public function logTimeByPage()
{
if (!defined(PATH_DATA)) {
return false;
}
$serverAddr = $_SERVER ['SERVER_ADDR'];
global $startingTime;
$endTime = microtime(true);
$time = $endTime - $startingTime;
$fpt = fopen(PATH_DATA . 'log/time.log', 'a');
fwrite($fpt, sprintf("%s.%03d %15s %s %5.3f %s\n", date('Y-m-d H:i:s'), $time, getenv('REMOTE_ADDR'), substr($serverAddr, - 4), $time, $_SERVER ['REQUEST_URI']));
fclose($fpt);
}
/**
* streaming a big JS file with small js files
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $file
* @param boolean $download
* @param string $downloadFileName
* @return string
*/
public function streamJSTranslationFile($filename, $locale = 'en')
{
$typearray = explode('.', basename($filename));
$typeCount = count($typearray);
$typeName = ($typeCount > 3) ? $typearray[1] : $typearray[0];
$typeName = trim($typeName);
$fileConst = ($typeName == 'translation') ? 'translation.' . $locale : 'translation.' . $typeName . '.' . $locale;
if ($typeName == 'translation') {
$defaultTranslations = Array();
$foreignTranslations = Array();
$calendarJs = '';
//load the translations table
if (is_file(PATH_LANGUAGECONT . 'translation.en')) {
require_once (PATH_LANGUAGECONT . 'translation.en');
$defaultTranslations = $translation;
}
//if some foreign language was requested and its translation file exists
if ($locale != 'en' && file_exists(PATH_LANGUAGECONT . 'translation.' . $locale)) {
require_once (PATH_LANGUAGECONT . 'translation.' . $locale); //load the foreign translations table
$foreignTranslations = $translation;
}
if (defined("SHOW_UNTRANSLATED_AS_TAG") && SHOW_UNTRANSLATED_AS_TAG != 0) {
$translation = $foreignTranslations;
} else {
$translation = array_merge($defaultTranslations, $foreignTranslations);
}
$calendarJsFile = PATH_GULLIVER_HOME . "js/widgets/js-calendar/lang/" . $locale . ".js";
if (!file_exists($calendarJsFile)) {
$calendarJsFile = PATH_GULLIVER_HOME . "js/widgets/js-calendar/lang/en.js";
}
$calendarJs = file_get_contents($calendarJsFile) . "\n";
return $calendarJs . 'var TRANSLATIONS = ' . Bootstrap::json_encode($translation) . ';';
} else {
unset($typearray[0]);
unset($typearray[count($typearray)]);
$newName = implode('.', $typearray);
if (file_exists(PATH_LANGUAGECONT . $newName)) {
require_once (PATH_LANGUAGECONT . $newName);
$return = '';
eval('$return = "var TRANSLATIONS_" . strtoupper($typeName) . " = " . Bootstrap::json_encode($translation' . $typeName . ') . ";";');
return $return;
}
return;
}
}
/**
* streaming a big JS file with small js files
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $file
* @return string
*/
public function streamCSSBigFile($filename)
{
header('Content-Type: text/css');
//First get Skin info
$filenameParts = explode("-", $filename);
$skinName = $filenameParts[0];
$skinVariant = "skin";
if (isset($filenameParts[1])) {
$skinVariant = strtolower($filenameParts[1]);
}
$configurationFile = '';
if ($skinName == "jscolors") {
$skinName = "classic";
}
if ($skinName == "xmlcolors") {
$skinName = "classic";
}
if ($skinName == "classic") {
$configurationFile = Bootstrap::ExpandPath("skinEngine") . 'base' . PATH_SEP . 'config.xml';
} else {
$configurationFile = "";
if (defined("PATH_CUSTOM_SKINS")) {
$configurationFile = PATH_CUSTOM_SKINS . $skinName . PATH_SEP . 'config.xml';
}
if (! is_file($configurationFile)) {
$configurationFile = Bootstrap::ExpandPath("skinEngine") . $skinName . PATH_SEP . 'config.xml';
}
}
$mtime = date('U');
$gmt_mtime = gmdate("D, d M Y H:i:s", $mtime) . " GMT";
header('Pragma: cache');
header('ETag: "' . Bootstrap::encryptOld($mtime . $filename) . '"');
header("Last-Modified: " . $gmt_mtime);
header('Cache-Control: public');
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 30 * 60 * 60 * 24) . " GMT"); //1 month
//header("Expires: " . gmdate("D, d M Y H:i:s", time () + 60*60*24 ) . " GMT"); //1 day - tempor
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) {
header('HTTP/1.1 304 Not Modified');
exit();
}
}
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
if (str_replace('"', '', stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) == Bootstrap::encryptOld($mtime . $filename)) {
header("HTTP/1.1 304 Not Modified");
exit();
}
}
//Read Configuration File
$xmlConfiguration = file_get_contents($configurationFile);
$xmlConfigurationObj = Bootstrap::xmlParser($xmlConfiguration);
$baseSkinDirectory = dirname($configurationFile);
$directorySize = Bootstrap::getDirectorySize($baseSkinDirectory);
$mtime = $directorySize['maxmtime'];
//if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor.
//$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
$outputHeader = "/* Autogenerated CSS file by gulliver framework \n";
$outputHeader .= " Skin: $filename\n";
$mtimeNow = date('U');
$gmt_mtimeNow = gmdate("D, d M Y H:i:s", $mtimeNow) . " GMT";
$outputHeader .= " Date: $gmt_mtimeNow*/\n";
$output = "";
//Base files
switch (strtolower($skinVariant)) {
case "extjs":
//Base
$baseCSSPath = PATH_SKIN_ENGINE . "base" . PATH_SEP . "baseCss" . PATH_SEP;
$output .= file_get_contents($baseCSSPath . 'ext-all-notheme.css');
//$output .= file_get_contents ( $publicExtPath . 'ext-all.css' );
//Classic Skin
$extJsSkin = 'xtheme-gray';
break;
default:
break;
}
//Get Browser Info
$infoBrowser = Bootstrap::get_current_browser();
$browserName = $infoBrowser['browser_working'];
if (isset($infoBrowser[$browserName . '_data'])) {
if ($infoBrowser[$browserName . '_data'][0] != "") {
$browserName = $infoBrowser[$browserName . '_data'][0];
}
}
//Read Configuration File
$xmlConfiguration = file_get_contents($configurationFile);
$xmlConfigurationObj = Bootstrap::xmlParser($xmlConfiguration);
if (!isset($xmlConfigurationObj->result['skinConfiguration']['__CONTENT__']['cssFiles']['__CONTENT__'][$skinVariant]['__CONTENT__'])) {
$xmlConfigurationObj->result['skinConfiguration']['__CONTENT__']['cssFiles']['__CONTENT__'][$skinVariant]['__CONTENT__'] = array('cssFile' => array());
}
$skinFilesArray = $xmlConfigurationObj->result['skinConfiguration']['__CONTENT__']['cssFiles']['__CONTENT__'][$skinVariant]['__CONTENT__']['cssFile'];
if (isset($skinFilesArray['__ATTRIBUTES__'])) {
$skinFilesArray = array($skinFilesArray);
}
foreach ($skinFilesArray as $keyFile => $cssFileInfo) {
$enabledBrowsers = explode(",", $cssFileInfo['__ATTRIBUTES__']['enabledBrowsers']);
$disabledBrowsers = explode(",", $cssFileInfo['__ATTRIBUTES__']['disabledBrowsers']);
if (((in_array($browserName, $enabledBrowsers)) || (in_array('ALL', $enabledBrowsers))) && (!(in_array($browserName, $disabledBrowsers)))) {
if ($cssFileInfo['__ATTRIBUTES__']['file'] == 'rtl.css') {
$oServerConf = & ServerConf::getSingleton();
if (!(defined('SYS_LANG'))) {
if (isset($_SERVER['HTTP_REFERER'])) {
$syss = explode('://', $_SERVER['HTTP_REFERER']);
$sysObjets = explode('/', $syss['1']);
$sysLang = $sysObjets['2'];
} else {
$sysLang = 'en';
}
} else {
$sysLang = SYS_LANG;
}
if ($oServerConf->isRtl($sysLang)) {
$output .= file_get_contents($baseSkinDirectory . PATH_SEP . 'css' . PATH_SEP . $cssFileInfo['__ATTRIBUTES__']['file']);
}
} else {
$output .= file_get_contents($baseSkinDirectory . PATH_SEP . 'css' . PATH_SEP . $cssFileInfo['__ATTRIBUTES__']['file']);
}
}
}
//Remove comments..
$regex = array("`^([\t\s]+)`ism" => '', "`^\/\*(.+?)\*\/`ism" => "", "`([\n\A;]+)\/\*(.+?)\*\/`ism" => "$1", "`([\n\A;\s]+)//(.+?)[\n\r]`ism" => "$1\n", "`(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+`ism" => "\n");
$output = preg_replace(array_keys($regex), $regex, $output);
$output = $outputHeader . $output;
return $output;
}
/**
* sendHeaders
*
* @param string $filename
* @param string $contentType
* default value ''
* @param boolean $download
* default value false
* @param string $downloadFileName
* default value ''
*
* @return void
*/
public function sendHeaders($filename, $contentType = '', $download = false, $downloadFileName = '')
{
if ($download) {
if ($downloadFileName == '') {
$aAux = explode('/', $filename);
$downloadFileName = $aAux [count($aAux) - 1];
}
header('Content-Disposition: attachment; filename="' . $downloadFileName . '"');
}
header('Content-Type: ' . $contentType);
// if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE
// behaivor.
$userAgent = strtolower($_SERVER ['HTTP_USER_AGENT']);
if (preg_match("/msie/i", $userAgent)) {
// if ( ereg("msie", $userAgent)) {
header('Pragma: cache');
if (file_exists($filename)) {
$mtime = filemtime($filename);
} else {
$mtime = date('U');
}
$gmt_mtime = gmdate("D, d M Y H:i:s", $mtime) . " GMT";
header('ETag: "' . Bootstrap::encryptOld($mtime . $filename) . '"');
header("Last-Modified: " . $gmt_mtime);
header('Cache-Control: public');
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60 * 10) . " GMT"); // ten
// minutes
return;
}
if (!$download) {
header('Pragma: cache');
if (file_exists($filename)) {
$mtime = filemtime($filename);
} else {
$mtime = date('U');
}
$gmt_mtime = gmdate("D, d M Y H:i:s", $mtime) . " GMT";
header('ETag: "' . Bootstrap::encryptOld($mtime . $filename) . '"');
header("Last-Modified: " . $gmt_mtime);
header('Cache-Control: public');
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 90 * 60 * 60 * 24) . " GMT");
if (isset($_SERVER ['HTTP_IF_MODIFIED_SINCE'])) {
if ($_SERVER ['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) {
header('HTTP/1.1 304 Not Modified');
exit();
}
}
if (isset($_SERVER ['HTTP_IF_NONE_MATCH'])) {
if (str_replace('"', '', stripslashes($_SERVER ['HTTP_IF_NONE_MATCH'])) == Bootstrap::encryptOld($mtime . $filename)) {
header("HTTP/1.1 304 Not Modified");
exit();
}
}
}
}
/**
* Get checksum from multiple files
*
* @author erik amaru ortiz <erik@colosa.com>
*/
public function getCheckSum($files)
{
$key = System::getVersion();
if (!is_array($files)) {
$tmp = $files;
$files = array();
$files[0] = $tmp;
}
$checkSum = '';
foreach ($files as $file) {
if (is_file($file)) {
$checkSum .= Bootstrap::encryptFileOld($file);
}
}
return Bootstrap::encryptOld($checkSum . $key);
}
/**
* Get checksum from multiple files
*
* @author erik amaru ortiz <erik@colosa.com>
*/
public function getCacheFileNameByPattern($path, $pattern)
{
if ($file = glob($path . $pattern)) {
preg_match('/[a-f0-9]{32}/', $file[0], $match);
} else {
$file[0] = '';
}
return array('filename' => $file[0], 'checksum' => (isset($match[0]) ? $match[0] : ''));
}
/**
* trimSourceCodeFile
*
* @param string $filename
*
* @return string $output
*/
public function trimSourceCodeFile($filename)
{
$handle = fopen($filename, "r");
$lastChar = '';
$firstChar = '';
$content = '';
$line = '';
if ($handle) {
while (!feof($handle)) {
//$line = trim( fgets($handle, 16096) ) . "\n" ;
$line = fgets($handle, 16096);
$content .= $line;
}
fclose($handle);
}
return $content;
$index = 0;
$output = '';
while ($index < strlen($content)) {
$car = $content[$index];
$index++;
if ($car == '/' && isset($content[$index]) && $content[$index] == '*') {
$endComment = false;
$index++;
while ($endComment == false && $index < strlen($content)) {
if ($content[$index] == '*' && isset($content[$index + 1]) && $content[$index + 1] == '/') {
$endComment = true;
$index++;
}
$index++;
}
$car = '';
}
$output .= $car;
}
return $output;
}
/**
* strip_slashes
* @param vVar
*/
public function strip_slashes($vVar)
{
if (is_array($vVar)) {
foreach ($vVar as $sKey => $vValue) {
if (is_array($vValue)) {
Bootstrap::strip_slashes($vVar[$sKey]);
} else {
$vVar[$sKey] = stripslashes($vVar[$sKey]);
}
}
} else {
$vVar = stripslashes($vVar);
}
return $vVar;
}
/**
* Function LoadTranslation
*
* @author Aldo Mauricio Veliz Valenzuela. <mauricio@colosa.com>
* @access public
* @param eter string msgID
* @param eter string file
* @param eter array data // erik: associative array within data input to replace for formatted string i.e "any messsage {replaced_label} that contains a replace label"
* @return string
*/
public function LoadTranslation($msgID, $lang = SYS_LANG, $data = null)
{
global $translation;
// if the second parameter ($lang) is an array, it was specified to use it as data
if (is_array($lang)) {
$data = $lang;
$lang = SYS_LANG;
}
if (isset($translation[$msgID])) {
$translationString = preg_replace("[\n|\r|\n\r]", ' ', $translation[$msgID]);
if (isset($data) && is_array($data)) {
foreach ($data as $label => $value) {
$translationString = str_replace('{' . $label . '}', $value, $translationString);
}
}
return $translationString;
} else {
if (defined("UNTRANSLATED_MARK")) {
$untranslatedMark = strip_tags(UNTRANSLATED_MARK);
} else {
$untranslatedMark = "**";
}
return $untranslatedMark . $msgID . $untranslatedMark;
}
}
/**
* Recursive version of glob php standard function
*
* @author Erik Amaru Ortiz <erik@colosa.com>
*
* @param $path path to scan recursively the write permission
* @param $flags to notive glob function
* @param $pattern pattern to filter some specified files
* @return <array> array containing the recursive glob results
*/
public function rglob($pattern = '*', $flags = 0, $path = '')
{
$paths = glob($path . '*', GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT);
$files = glob($path . $pattern, $flags);
foreach ($paths as $path) {
$files = array_merge($files, Bootstrap::rglob($pattern, $flags, $path));
}
return $files;
}
/**
* JSON encode
*
* @author Erik A.O. <erik@gmail.com, aortiz.erik@gmail.com>
*/
public function json_encode($Json)
{
if (function_exists('json_encode')) {
return json_encode($Json);
} else {
$oJSON = new Services_JSON();
return $oJSON->encode($Json);
}
}
/**
* JSON decode
*
* @author Erik A.O. <erik@gmail.com, aortiz.erik@gmail.com>
*/
public static function json_decode($Json)
{
if (function_exists('json_decode')) {
return json_decode($Json);
} else {
$oJSON = new Services_JSON();
return $oJSON->decode($Json);
}
}
/**
* ************************************* init **********************************************
* Xml parse collection functions
* Returns a associative array within the xml structure and data
*
* @author Erik Amaru Ortiz <erik@colosa.com>
*/
public function xmlParser(&$string)
{
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parse_into_struct($parser, $string, $vals, $index);
$mnary = array();
$ary = &$mnary;
foreach ($vals as $r) {
$t = $r['tag'];
if ($r['type'] == 'open') {
if (isset($ary[$t])) {
if (isset($ary[$t][0])) {
$ary[$t][] = array();
} else {
$ary[$t] = array($ary[$t], array());
}
$cv = &$ary[$t][count($ary[$t]) - 1];
} else {
$cv = &$ary[$t];
}
if (isset($r['attributes'])) {
foreach ($r['attributes'] as $k => $v) {
$cv['__ATTRIBUTES__'][$k] = $v;
}
}
// note by gustavo cruz gustavo[at]colosa[dot]com
// minor adjustments to validate if an open node have a value attribute.
// for example a dropdown has many childs, but also can have a value attribute.
if (isset($r['value']) && trim($r['value']) != '') {
$cv['__VALUE__'] = $r['value'];
}
// end added code
$cv['__CONTENT__'] = array();
$cv['__CONTENT__']['_p'] = &$ary;
$ary = &$cv['__CONTENT__'];
} elseif ($r['type'] == 'complete') {
if (isset($ary[$t])) {
if (isset($ary[$t][0])) {
$ary[$t][] = array();
} else {
$ary[$t] = array($ary[$t], array());
}
$cv = &$ary[$t][count($ary[$t]) - 1];
} else {
$cv = &$ary[$t];
}
if (isset($r['attributes'])) {
foreach ($r['attributes'] as $k => $v) {
$cv['__ATTRIBUTES__'][$k] = $v;
}
}
$cv['__VALUE__'] = (isset($r['value']) ? $r['value'] : '');
} elseif ($r['type'] == 'close') {
$ary = &$ary['_p'];
}
}
self::_del_p($mnary);
$obj_resp = new StdClass();
$obj_resp->code = xml_get_error_code($parser);
$obj_resp->message = xml_error_string($obj_resp->code);
$obj_resp->result = $mnary;
xml_parser_free($parser);
return $obj_resp;
}
/**
*
* @param unknown_type $path
* @param unknown_type $maxmtime
* @return Ambigous <number, unknown>
*/
public function getDirectorySize($path, $maxmtime = 0)
{
$totalsize = 0;
$totalcount = 0;
$dircount = 0;
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
$nextpath = $path . '/' . $file;
if ($file != '.' && $file != '..' && !is_link($nextpath) && $file != '.svn') {
if (is_dir($nextpath)) {
$dircount++;
$result = Bootstrap::getDirectorySize($nextpath, $maxmtime);
$totalsize += $result['size'];
$totalcount += $result['count'];
$dircount += $result['dircount'];
$maxmtime = $result['maxmtime'] > $maxmtime ? $result['maxmtime'] : $maxmtime;
} elseif (is_file($nextpath)) {
$totalsize += filesize($nextpath);
$totalcount++;
$mtime = filemtime($nextpath);
if ($mtime > $maxmtime) {
$maxmtime = $mtime;
}
}
}
}
}
closedir($handle);
$total['size'] = $totalsize;
$total['count'] = $totalcount;
$total['dircount'] = $dircount;
$total['maxmtime'] = $maxmtime;
return $total;
}
/**
* _del_p
*
* @param string &$ary
*
* @return void
*/
// _Internal: Remove recursion in result array
public function _del_p(&$ary)
{
foreach ($ary as $k => $v) {
if ($k === '_p') {
unset($ary[$k]);
} elseif (is_array($ary[$k])) {
self::_del_p($ary[$k]);
}
}
}
/**
* Refactor function
* @author Ralph A.
* @return multitype:array containing browser name and type
*/
public function get_current_browser()
{
static $a_full_assoc_data, $a_mobile_data, $browser_user_agent;
static $browser_working, $moz_type, $webkit_type;
//initialize all variables with default values to prevent error
$a_full_assoc_data = '';
$a_mobile_data = '';
$browser_temp = '';
$browser_working = '';
$mobile_test = '';
$moz_type = '';
$ua_type = 'bot'; // default to bot since you never know with bots
$webkit_type = '';
/*
make navigator user agent string lower case to make sure all versions get caught
isset protects against blank user agent failure. tolower also lets the script use
strstr instead of stristr, which drops overhead slightly.
*/
$browser_user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
// known browsers, list will be updated routinely, check back now and then
$a_browser_types = array(
array('opera', true, 'op', 'bro'),
array('msie', true, 'ie', 'bro'),
// webkit before gecko because some webkit ua strings say: like gecko
array('webkit', true, 'webkit', 'bro'),
// konq will be using webkit soon
array('konqueror', true, 'konq', 'bro'),
// covers Netscape 6-7, K-Meleon, Most linux versions, uses moz array below
array('gecko', true, 'moz', 'bro'),
array('netpositive', false, 'netp', 'bbro'), // beos browser
array('lynx', false, 'lynx', 'bbro'), // command line browser
array('elinks ', false, 'elinks', 'bbro'), // new version of links
array('elinks', false, 'elinks', 'bbro'), // alternate id for it
array('links2', false, 'links2', 'bbro'), // alternate links version
array('links ', false, 'links', 'bbro'), // old name for links
array('links', false, 'links', 'bbro'), // alternate id for it
array('w3m', false, 'w3m', 'bbro'), // open source browser, more features than lynx/links
array('webtv', false, 'webtv', 'bbro'), // junk ms webtv
array('amaya', false, 'amaya', 'bbro'), // w3c browser
array('dillo', false, 'dillo', 'bbro'), // linux browser, basic table support
array('ibrowse', false, 'ibrowse', 'bbro'), // amiga browser
array('icab', false, 'icab', 'bro'), // mac browser
array('crazy browser', true, 'ie', 'bro'), // uses ie rendering engine
// search engine spider bots:
array('bingbot', false, 'bing', 'bot'), // bing
array('exabot', false, 'exabot', 'bot'), // exabot
array('googlebot', false, 'google', 'bot'), // google
array('google web preview', false, 'googlewp', 'bot'), // google preview
array('mediapartners-google', false, 'adsense', 'bot'), // google adsense
array('yahoo-verticalcrawler', false, 'yahoo', 'bot'), // old yahoo bot
array('yahoo! slurp', false, 'yahoo', 'bot'), // new yahoo bot
array('yahoo-mm', false, 'yahoomm', 'bot'), // gets Yahoo-MMCrawler and Yahoo-MMAudVid bots
array('inktomi', false, 'inktomi', 'bot'), // inktomi bot
array('slurp', false, 'inktomi', 'bot'), // inktomi bot
array('fast-webcrawler', false, 'fast', 'bot'), // Fast AllTheWeb
array('msnbot', false, 'msn', 'bot'), // msn search
array('ask jeeves', false, 'ask', 'bot'), //jeeves/teoma
array('teoma', false, 'ask', 'bot'), //jeeves teoma
array('scooter', false, 'scooter', 'bot'), // altavista
array('openbot', false, 'openbot', 'bot'), // openbot, from taiwan
array('ia_archiver', false, 'ia_archiver', 'bot'), // ia archiver
array('zyborg', false, 'looksmart', 'bot'), // looksmart
array('almaden', false, 'ibm', 'bot'), // ibm almaden web crawler
array('baiduspider', false, 'baidu', 'bot'), // Baiduspider asian search spider
array('psbot', false, 'psbot', 'bot'), // psbot image crawler
array('gigabot', false, 'gigabot', 'bot'), // gigabot crawler
array('naverbot', false, 'naverbot', 'bot'), // naverbot crawler, bad bot, block
array('surveybot', false, 'surveybot', 'bot'), //
array('boitho.com-dc', false, 'boitho', 'bot'), //norwegian search engine
array('objectssearch', false, 'objectsearch', 'bot'), // open source search engine
array('answerbus', false, 'answerbus', 'bot'), // http://www.answerbus.com/, web questions
array('sohu-search', false, 'sohu', 'bot'), // chinese media company, search component
array('iltrovatore-setaccio', false, 'il-set', 'bot'),
// various http utility libaries
array('w3c_validator', false, 'w3c', 'lib'), // uses libperl, make first
array('wdg_validator', false, 'wdg', 'lib'), //
array('libwww-perl', false, 'libwww-perl', 'lib'),
array('jakarta commons-httpclient', false, 'jakarta', 'lib'),
array('python-urllib', false, 'python-urllib', 'lib'),
// download apps
array('getright', false, 'getright', 'dow'),
array('wget', false, 'wget', 'dow'), // open source downloader, obeys robots.txt
// netscape 4 and earlier tests, put last so spiders don't get caught
array('mozilla/4.', false, 'ns', 'bbro'),
array('mozilla/3.', false, 'ns', 'bbro'),
array('mozilla/2.', false, 'ns', 'bbro')
);
/*
moz types array
note the order, netscape6 must come before netscape, which is how netscape 7 id's itself.
rv comes last in case it is plain old mozilla. firefox/netscape/seamonkey need to be later
Thanks to: http://www.zytrax.com/tech/web/firefox-history.html
*/
$a_moz_types = array('bonecho', 'camino', 'epiphany', 'firebird', 'flock', 'galeon', 'iceape', 'icecat', 'k-meleon', 'minimo', 'multizilla', 'phoenix', 'songbird', 'swiftfox', 'seamonkey', 'shiretoko', 'iceweasel', 'firefox', 'minefield', 'netscape6', 'netscape', 'rv');
/*
webkit types, this is going to expand over time as webkit b$browser_namerowsers spread
konqueror is probably going to move to webkit, so this is preparing for that
It will now default to khtml. gtklauncher is the temp id for epiphany, might
change. Defaults to applewebkit, and will all show the webkit number.
*/
$a_webkit_types = array('arora', 'chrome', 'epiphany', 'gtklauncher', 'konqueror', 'midori', 'omniweb', 'safari', 'uzbl', 'applewebkit', 'webkit');
/*
run through the browser_types array, break if you hit a match, if no match, assume old browser
or non dom browser.
*/
$i_count = count($a_browser_types);
for ($i = 0; $i < $i_count; $i++) {
//unpacks browser array, assigns to variables, need to not assign til found in string
$browser_temp = $a_browser_types[$i][0]; // text string to id browser from array
if (strstr($browser_user_agent, $browser_temp)) {
$browser_working = $a_browser_types[$i][2]; // working name for browser
$ua_type = $a_browser_types[$i][3]; // sets whether bot or browser
switch ($browser_working) {
case 'moz':
// this is to pull out specific mozilla versions, firebird, netscape etc..
$j_count = count($a_moz_types);
for ($j = 0; $j < $j_count; $j++) {
if (strstr($browser_user_agent, $a_moz_types[$j])) {
$moz_type = $a_moz_types[$j];
break;
}
}
if ($moz_type == 'rv') {
$moz_type = 'mozilla';
}
break;
case 'webkit':
// this is to pull out specific webkit versions, safari, google-chrome etc..
$j_count = count($a_webkit_types);
for ($j = 0; $j < $j_count; $j++) {
if (strstr($browser_user_agent, $a_webkit_types[$j])) {
$webkit_type = $a_webkit_types[$j];
break;
}
}
break;
default:
break;
}
break;
}
}
$mobile_test = Bootstrap::check_is_mobile($browser_user_agent);
if ($mobile_test) {
$a_mobile_data = Bootstrap::get_mobile_data($browser_user_agent);
$ua_type = 'mobile';
}
$a_full_assoc_data = array(
'browser_working' => $browser_working,
'ua_type' => $ua_type,
'moz_data' => array($moz_type),
'webkit_data' => array($webkit_type),
'mobile_data' => array($a_mobile_data),
);
return $a_full_assoc_data;
}
/**
* track total script execution time
*/
public function script_time()
{
static $script_time;
$elapsed_time = '';
/*
note that microtime(true) requires php 5 or greater for microtime(true)
*/
if (sprintf("%01.1f", phpversion()) >= 5) {
if (is_null($script_time)) {
$script_time = microtime(true);
} else {
// note: (string)$var is same as strval($var)
// $elapsed_time = (string)( microtime(true) - $script_time );
$elapsed_time = (microtime(true) - $script_time);
$elapsed_time = sprintf("%01.8f", $elapsed_time);
$script_time = null; // can't unset a static variable
return $elapsed_time;
}
}
}
/**
*
* @param unknown_type $pv_browser_user_agent
* @param unknown_type $pv_search_string
* @param unknown_type $pv_b_break_last
* @param unknown_type $pv_extra_search
* @return string
*/
public function get_item_version($pv_browser_user_agent, $pv_search_string, $pv_b_break_last = '', $pv_extra_search = '')
{
$substring_length = 15;
$start_pos = 0; // set $start_pos to 0 for first iteration
$string_working_number = '';
for ($i = 0; $i < 4; $i++) {
//start the search after the first string occurrence
if (strpos($pv_browser_user_agent, $pv_search_string, $start_pos) !== false) {
$start_pos = strpos($pv_browser_user_agent, $pv_search_string, $start_pos) + strlen($pv_search_string);
if (!$pv_b_break_last || ( $pv_extra_search && strstr($pv_browser_user_agent, $pv_extra_search) )) {
break;
}
} else {
break;
}
}
$start_pos += Bootstrap::get_set_count('get');
$string_working_number = substr($pv_browser_user_agent, $start_pos, $substring_length);
$string_working_number = substr($string_working_number, 0, strcspn($string_working_number, ' );/'));
if (!is_numeric(substr($string_working_number, 0, 1))) {
$string_working_number = '';
}
return $string_working_number;
}
/**
*
* @param unknown_type $pv_type
* @param unknown_type $pv_value
*/
public function get_set_count($pv_type, $pv_value = '')
{
static $slice_increment;
$return_value = '';
switch ($pv_type) {
case 'get':
if (is_null($slice_increment)) {
$slice_increment = 1;
}
$return_value = $slice_increment;
$slice_increment = 1; // reset to default
return $return_value;
break;
case 'set':
$slice_increment = $pv_value;
break;
}
}
/**
* gets which os from the browser string
*/
public function get_os_data($pv_browser_string, $pv_browser_name, $pv_version_number)
{
// initialize variables
$os_working_type = '';
$os_working_number = '';
/*
packs the os array. Use this order since some navigator user agents will put 'macintosh'
in the navigator user agent string which would make the nt test register true
*/
$a_mac = array('intel mac', 'ppc mac', 'mac68k'); // this is not used currently
// same logic, check in order to catch the os's in order, last is always default item
$a_unix_types = array('dragonfly', 'freebsd', 'openbsd', 'netbsd', 'bsd', 'unixware', 'solaris', 'sunos', 'sun4', 'sun5', 'suni86', 'sun', 'irix5', 'irix6', 'irix', 'hpux9', 'hpux10', 'hpux11', 'hpux', 'hp-ux', 'aix1', 'aix2', 'aix3', 'aix4', 'aix5', 'aix', 'sco', 'unixware', 'mpras', 'reliant', 'dec', 'sinix', 'unix');
// only sometimes will you get a linux distro to id itself...
$a_linux_distros = array('ubuntu', 'kubuntu', 'xubuntu', 'mepis', 'xandros', 'linspire', 'winspire', 'jolicloud', 'sidux', 'kanotix', 'debian', 'opensuse', 'suse', 'fedora', 'redhat', 'slackware', 'slax', 'mandrake', 'mandriva', 'gentoo', 'sabayon', 'linux');
$a_linux_process = array('i386', 'i586', 'i686'); // not use currently
// note, order of os very important in os array, you will get failed ids if changed
$a_os_types = array('android', 'blackberry', 'iphone', 'palmos', 'palmsource', 'symbian', 'beos', 'os2', 'amiga', 'webtv', 'mac', 'nt', 'win', $a_unix_types, $a_linux_distros);
//os tester
$i_count = count($a_os_types);
for ($i = 0; $i < $i_count; $i++) {
// unpacks os array, assigns to variable $a_os_working
$os_working_data = $a_os_types[$i];
/*
assign os to global os variable, os flag true on success
!strstr($pv_browser_string, "linux" ) corrects a linux detection bug
*/
if (!is_array($os_working_data) && strstr($pv_browser_string, $os_working_data) && !strstr($pv_browser_string, "linux")) {
$os_working_type = $os_working_data;
switch ($os_working_type) {
// most windows now uses: NT X.Y syntax
case 'nt':
if (strstr($pv_browser_string, 'nt 6.1')) {
$os_working_number = 6.1;
} elseif (strstr($pv_browser_string, 'nt 6.0')) {
$os_working_number = 6.0;
} elseif (strstr($pv_browser_string, 'nt 5.2')) {
$os_working_number = 5.2;
} elseif (strstr($pv_browser_string, 'nt 5.1') || strstr($pv_browser_string, 'xp')) {
$os_working_number = 5.1; //
} elseif (strstr($pv_browser_string, 'nt 5') || strstr($pv_browser_string, '2000')) {
$os_working_number = 5.0;
} elseif (strstr($pv_browser_string, 'nt 4')) {
$os_working_number = 4;
} elseif (strstr($pv_browser_string, 'nt 3')) {
$os_working_number = 3;
}
break;
case 'win':
if (strstr($pv_browser_string, 'vista')) {
$os_working_number = 6.0;
$os_working_type = 'nt';
} elseif (strstr($pv_browser_string, 'xp')) {
$os_working_number = 5.1;
$os_working_type = 'nt';
} elseif (strstr($pv_browser_string, '2003')) {
$os_working_number = 5.2;
$os_working_type = 'nt';
} elseif (strstr($pv_browser_string, 'windows ce')) {// windows CE
$os_working_number = 'ce';
$os_working_type = 'nt';
} elseif (strstr($pv_browser_string, '95')) {
$os_working_number = '95';
} elseif (( strstr($pv_browser_string, '9x 4.9') ) || ( strstr($pv_browser_string, ' me') )) {
$os_working_number = 'me';
} elseif (strstr($pv_browser_string, '98')) {
$os_working_number = '98';
} elseif (strstr($pv_browser_string, '2000')) {// windows 2000, for opera ID
$os_working_number = 5.0;
$os_working_type = 'nt';
}
break;
case 'mac':
if (strstr($pv_browser_string, 'os x')) {
if (strstr($pv_browser_string, 'os x ')) {
$os_working_number = str_replace('_', '.', Bootstrap::get_item_version($pv_browser_string, 'os x'));
} else {
$os_working_number = 10;
}
} elseif (( $pv_browser_name == 'saf' ) || ( $pv_browser_name == 'cam' ) ||
( ( $pv_browser_name == 'moz' ) && ( $pv_version_number >= 1.3 ) ) ||
( ( $pv_browser_name == 'ie' ) && ( $pv_version_number >= 5.2 ) )) {
$os_working_number = 10;
}
break;
case 'iphone':
$os_working_number = 10;
break;
default:
break;
}
break;
} elseif (is_array($os_working_data) && ( $i == ( $i_count - 2 ) )) {
$j_count = count($os_working_data);
for ($j = 0; $j < $j_count; $j++) {
if (strstr($pv_browser_string, $os_working_data[$j])) {
$os_working_type = 'unix'; //if the os is in the unix array, it's unix, obviously...
$os_working_number = ( $os_working_data[$j] != 'unix' ) ? $os_working_data[$j] : ''; // assign sub unix version from the unix array
break;
}
}
} elseif (is_array($os_working_data) && ( $i == ( $i_count - 1 ))) {
$j_count = count($os_working_data);
for ($j = 0; $j < $j_count; $j++) {
if (strstr($pv_browser_string, $os_working_data[$j])) {
$os_working_type = 'lin';
// assign linux distro from the linux array, there's a default
//search for 'lin', if it's that, set version to ''
$os_working_number = ( $os_working_data[$j] != 'linux' ) ? $os_working_data[$j] : '';
break;
}
}
}
}
// pack the os data array for return to main function
$a_os_data = array($os_working_type, $os_working_number);
return $a_os_data;
}
/**
*
* @param unknown_type $pv_browser_user_agent
* @return string
*/
public function check_is_mobile($pv_browser_user_agent)
{
$mobile_working_test = '';
$a_mobile_search = array(
'android', 'epoc', 'linux armv', 'palmos', 'palmsource', 'windows ce', 'windows phone os', 'symbianos', 'symbian os', 'symbian', 'webos',
// devices - ipod before iphone or fails
'benq', 'blackberry', 'danger hiptop', 'ddipocket', ' droid', 'ipad', 'ipod', 'iphone', 'kindle', 'lge-cx', 'lge-lx', 'lge-mx', 'lge vx', 'lge ', 'lge-', 'lg;lx', 'nintendo wii', 'nokia', 'palm', 'pdxgw', 'playstation', 'sagem', 'samsung', 'sec-sgh', 'sharp', 'sonyericsson', 'sprint', 'zune', 'j-phone', 'n410', 'mot 24', 'mot-', 'htc-', 'htc_', 'htc ', 'sec-', 'sie-m', 'sie-s', 'spv ', 'vodaphone', 'smartphone', 'armv', 'midp', 'mobilephone',
// browsers
'avantgo', 'blazer', 'elaine', 'eudoraweb', 'iemobile', 'minimo', 'mobile safari', 'mobileexplorer', 'opera mobi', 'opera mini', 'netfront', 'opwv', 'polaris', 'semc-browser', 'up.browser', 'webpro', 'wms pie', 'xiino',
// services - astel out of business
'astel', 'docomo', 'novarra-vision', 'portalmmm', 'reqwirelessweb', 'vodafone'
);
// then do basic mobile type search, this uses data from: get_mobile_data()
$j_count = count($a_mobile_search);
for ($j = 0; $j < $j_count; $j++) {
if (strstr($pv_browser_user_agent, $a_mobile_search[$j])) {
$mobile_working_test = $a_mobile_search[$j];
break;
}
}
return $mobile_working_test;
}
/**
*
* @param unknown_type $pv_browser_user_agent
*/
public function get_mobile_data($pv_browser_user_agent)
{
$mobile_browser = '';
$mobile_browser_number = '';
$mobile_device = '';
$mobile_device_number = '';
$mobile_os = ''; // will usually be null, sorry
$mobile_os_number = '';
$mobile_server = '';
$mobile_server_number = '';
$a_mobile_browser = array('avantgo', 'blazer', 'elaine', 'eudoraweb', 'iemobile', 'minimo', 'mobile safari', 'mobileexplorer', 'opera mobi', 'opera mini', 'netfront', 'opwv', 'polaris', 'semc-browser', 'up.browser', 'webpro', 'wms pie', 'xiino');
$a_mobile_device = array('benq', 'blackberry', 'danger hiptop', 'ddipocket', ' droid', 'htc_dream', 'htc espresso', 'htc hero', 'htc halo', 'htc huangshan', 'htc legend', 'htc liberty', 'htc paradise', 'htc supersonic', 'htc tattoo', 'ipad', 'ipod', 'iphone', 'kindle', 'lge-cx', 'lge-lx', 'lge-mx', 'lge vx', 'lg;lx', 'nintendo wii', 'nokia', 'palm', 'pdxgw', 'playstation', 'sagem', 'samsung', 'sec-sgh', 'sharp', 'sonyericsson', 'sprint', 'zunehd', 'zune', 'j-phone', 'milestone', 'n410', 'mot 24', 'mot-', 'htc-', 'htc_', 'htc ', 'lge ', 'lge-', 'sec-', 'sie-m', 'sie-s', 'spv ', 'smartphone', 'armv', 'midp', 'mobilephone');
$a_mobile_os = array('android', 'epoc', 'cpu os', 'iphone os', 'palmos', 'palmsource', 'windows phone os', 'windows ce', 'symbianos', 'symbian os', 'symbian', 'webos', 'linux armv');
$a_mobile_server = array('astel', 'docomo', 'novarra-vision', 'portalmmm', 'reqwirelessweb', 'vodafone');
$k_count = count($a_mobile_browser);
for ($k = 0; $k < $k_count; $k++) {
if (strstr($pv_browser_user_agent, $a_mobile_browser[$k])) {
$mobile_browser = $a_mobile_browser[$k];
$mobile_browser_number = Bootstrap::get_item_version($pv_browser_user_agent, $mobile_browser);
break;
}
}
$k_count = count($a_mobile_device);
for ($k = 0; $k < $k_count; $k++) {
if (strstr($pv_browser_user_agent, $a_mobile_device[$k])) {
$mobile_device = trim($a_mobile_device[$k], '-_'); // but not space trims yet
if ($mobile_device == 'blackberry') {
Bootstrap::get_set_count('set', 0);
}
$mobile_device_number = Bootstrap::get_item_version($pv_browser_user_agent, $mobile_device);
$mobile_device = trim($mobile_device); // some of the id search strings have white space
break;
}
}
$k_count = count($a_mobile_os);
for ($k = 0; $k < $k_count; $k++) {
if (strstr($pv_browser_user_agent, $a_mobile_os[$k])) {
$mobile_os = $a_mobile_os[$k];
$mobile_os_number = str_replace('_', '.', Bootstrap::get_item_version($pv_browser_user_agent, $mobile_os));
break;
}
}
$k_count = count($a_mobile_server);
for ($k = 0; $k < $k_count; $k++) {
if (strstr($pv_browser_user_agent, $a_mobile_server[$k])) {
$mobile_server = $a_mobile_server[$k];
$mobile_server_number = Bootstrap::get_item_version($pv_browser_user_agent, $mobile_server);
break;
}
}
// just for cases where we know it's a mobile device already
if (!$mobile_os && ( $mobile_browser || $mobile_device || $mobile_server ) && strstr($pv_browser_user_agent, 'linux')) {
$mobile_os = 'linux';
$mobile_os_number = Bootstrap::get_item_version($pv_browser_user_agent, 'linux');
}
$a_mobile_data = array($mobile_device, $mobile_browser, $mobile_browser_number, $mobile_os, $mobile_os_number, $mobile_server, $mobile_server_number, $mobile_device_number);
return $a_mobile_data;
}
/**
*
* @param unknown_type $aRequestUri
* @param array $arrayFriendlyUri
*
* @return multitype:string mixed Ambigous <number, string>
*/
public function parseNormalUri($aRequestUri, array $arrayFriendlyUri = null)
{
if (substr($aRequestUri[1], 0, 3) == 'sys') {
define('SYS_TEMP', substr($aRequestUri[1], 3));
} else {
define("ENABLE_ENCRYPT", 'yes');
define('SYS_TEMP', $aRequestUri[1]);
$plain = '/sys' . SYS_TEMP;
for ($i = 2; $i < count($aRequestUri); $i++) {
$decoded = Bootstrap::decrypt(urldecode($aRequestUri[$i]), URL_KEY);
if ($decoded == 'sWì›') {
$decoded = $VARS[$i]; //this is for the string "../"
}
$plain .= '/' . $decoded;
}
$_SERVER["REQUEST_URI"] = $plain;
}
$work = explode('?', $_SERVER["REQUEST_URI"]);
if (count($work) > 1) {
define('SYS_CURRENT_PARMS', $work[1]);
} else {
define('SYS_CURRENT_PARMS', '');
}
define('SYS_CURRENT_URI', $work[0]);
if (!defined('SYS_CURRENT_PARMS')) {
define('SYS_CURRENT_PARMS', $work[1]);
}
$preArray = explode('&', SYS_CURRENT_PARMS);
$buffer = explode('.', $work[0]);
if (count($buffer) == 1) {
$buffer[1] = '';
}
//request type
define('REQUEST_TYPE', ($buffer[1] != "" ? $buffer[1] : 'html'));
$toparse = substr($buffer[0], 1, strlen($buffer[0]) - 1);
$uriVars = explode('/', $toparse);
unset($work);
unset($buffer);
unset($toparse);
array_shift($uriVars);
$args = array();
$element = array_shift($uriVars);
$args["SYS_LANG"] = (preg_match("/^[\w\-]+$/", $element))? $element : "";
$element = array_shift($uriVars);
$args["SYS_SKIN"] = (preg_match("/^[\w\-]+$/", $element))? $element : "";
$args["SYS_COLLECTION"] = array_shift($uriVars);
$args["SYS_TARGET"] = array_shift($uriVars);
//to enable more than 2 directories...in the methods structure
$key = $args['SYS_COLLECTION'] . '/' . $args['SYS_TARGET'];
$flagSysTarget = true;
if (!is_null($arrayFriendlyUri) && !empty($arrayFriendlyUri) && isset($arrayFriendlyUri[$key])) {
if (!preg_match($arrayFriendlyUri[$key], array_shift($uriVars))) {
$args['SYS_TARGET'] = false;
}
$flagSysTarget = false;
}
if ($flagSysTarget) {
while (!empty($uriVars)) {
$args['SYS_TARGET'] = $args['SYS_TARGET'] . '/' . array_shift($uriVars);
}
}
/* Fix to prevent use uxs skin outside siplified interface,
because that skin is not compatible with others interfaces */
if ($args['SYS_SKIN'] == 'uxs' && $args['SYS_COLLECTION'] != 'home' && $args['SYS_COLLECTION'] != 'cases') {
$config = System::getSystemConfiguration();
$args['SYS_SKIN'] = $config['default_skin'];
}
return $args;
}
/**
* * Encrypt and decrypt functions ***
*/
/**
* Encrypt string
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $string
* @param string $key
* @return string
*/
public function encrypt($string, $key)
{
//print $string;
// if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) {
if (strpos($string, '|', 0) !== false) {
return $string;
}
$result = '';
for ($i = 0; $i < strlen($string); $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key)) - 1, 1);
$char = chr(ord($char) + ord($keychar));
$result .= $char;
}
$result = base64_encode($result);
$result = str_replace('/', '°', $result);
$result = str_replace('=', '', $result);
return $result;
}
/**
* Decrypt string
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $string
* @param string $key
* @return string
*/
public function decrypt($string, $key)
{
// if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) {
//if (strpos($string, '|', 0) !== false) return $string;
$result = '';
$string = str_replace('°', '/', $string);
$string_jhl = explode("?", $string);
$string = base64_decode($string);
$string = base64_decode($string_jhl[0]);
for ($i = 0; $i < strlen($string); $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key)) - 1, 1);
$char = chr(ord($char) - ord($keychar));
$result .= $char;
}
if (!empty($string_jhl[1])) {
$result .= '?' . $string_jhl[1];
}
return $result;
}
/**
* @deprecated 3.2.2, We keep this function only for backwards compatibility because is used in the plugin manager
*/
public function getModel($model)
{
}
/**
* Create an encrypted unique identifier based on $id and the selected scope id.
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param string $scope
* @param string $id
* @return string
*/
public function createUID($scope, $id)
{
$e = $scope . $id;
$e = Bootstrap::encrypt($e, URL_KEY);
$e = str_replace(array('+', '/', '='), array('__', '_', '___'), base64_encode($e));
return $e;
}
/**
* (Create an encrypted unique identificator based on $id and the selected scope id.) ^-1
* getUIDName
*
* @author David S. Callizaya S. <davidsantos@colosa.com>
* @access public
* @param string $id
* @param string $scope
* @return string
*/
public function getUIDName($uid, $scope = '')
{
$e = str_replace(array('=', '+', '/'), array('___', '__', '_'), $uid);
$e = base64_decode($e);
$e = Bootstrap::decrypt($e, URL_KEY);
$e = substr($e, strlen($scope));
return $e;
}
/**
* Merge 2 arrays
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return array
*/
public function array_merges()
{
$array = array();
$arrays = & func_get_args();
foreach ($arrays as $array_i) {
if (is_array($array_i)) {
Bootstrap::array_merge_2($array, $array_i);
}
}
return $array;
}
/**
* Merge 2 arrays
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $array
* @param string $array_i
* @return array
*/
public function array_merge_2(&$array, &$array_i)
{
foreach ($array_i as $k => $v) {
if (is_array($v)) {
if (!isset($array[$k])) {
$array[$k] = array();
}
Bootstrap::array_merge_2($array[$k], $v);
} else {
if (isset($array[$k]) && is_array($array[$k])) {
$array[$k][0] = $v;
} else {
if (isset($array) && !is_array($array)) {
$temp = $array;
$array = array();
$array[0] = $temp;
}
$array[$k] = $v;
}
}
}
}
/**
* microtime_float
*
* @return array_sum(explode(' ',microtime()))
*/
/* public static */
public function microtime_float()
{
return array_sum(explode(' ', microtime()));
}
/**
* Return the System defined constants and Application variables
* Constants: SYS_*
* Sessions : USER_* , URS_*
*/
public function getSystemConstants($params = null)
{
$t1 = Bootstrap::microtime_float();
$sysCon = array();
if (defined("SYS_LANG")) {
$sysCon["SYS_LANG"] = SYS_LANG;
}
if (defined("SYS_SKIN")) {
$sysCon["SYS_SKIN"] = SYS_SKIN;
}
if (!empty(config("system.workspace"))) {
$sysCon["SYS_SYS"] = config("system.workspace");
}
$sysCon["APPLICATION"] = (isset($_SESSION["APPLICATION"])) ? $_SESSION["APPLICATION"] : "";
$sysCon["PROCESS"] = (isset($_SESSION["PROCESS"])) ? $_SESSION["PROCESS"] : "";
$sysCon["TASK"] = (isset($_SESSION["TASK"])) ? $_SESSION["TASK"] : "";
$sysCon["INDEX"] = (isset($_SESSION["INDEX"])) ? $_SESSION["INDEX"] : "";
$sysCon["USER_LOGGED"] = (isset($_SESSION["USER_LOGGED"])) ? $_SESSION["USER_LOGGED"] : "";
$sysCon["USR_USERNAME"] = (isset($_SESSION["USR_USERNAME"])) ? $_SESSION["USR_USERNAME"] : "";
//###############################################################################################
// Added for compatibility betweek aplication called from web Entry that uses just WS functions
//###############################################################################################
if ($params != null) {
if (isset($params->option)) {
switch ($params->option) {
case "STORED SESSION":
if (isset($params->SID)) {
$oSessions = new Sessions($params->SID);
$sysCon = array_merge($sysCon, $oSessions->getGlobals());
}
break;
}
}
if (isset($params->appData) && is_array($params->appData)) {
$sysCon["APPLICATION"] = $params->appData["APPLICATION"];
$sysCon["PROCESS"] = $params->appData["PROCESS"];
$sysCon["TASK"] = $params->appData["TASK"];
$sysCon["INDEX"] = $params->appData["INDEX"];
if (empty($sysCon["USER_LOGGED"])) {
$sysCon["USER_LOGGED"] = $params->appData["USER_LOGGED"];
$sysCon["USR_USERNAME"] = $params->appData["USR_USERNAME"];
}
}
}
return $sysCon;
}
/**
* Escapes special characters in a string for use in a SQL statement
* @author David Callizaya <calidavidx21@hotmail.com>
* @param string $sqlString The string to be escaped
* @param string $DBEngine Target DBMS
*/
public function sqlEscape($sqlString, $DBEngine = DB_ADAPTER)
{
$DBEngine = DB_ADAPTER;
switch ($DBEngine) {
case 'mysql':
$con = Propel::getConnection('workflow');
return mysql_real_escape_string(stripslashes($sqlString), $con->getResource());
break;
case 'myxml':
$sqlString = str_replace('"', '""', $sqlString);
return str_replace("'", "''", $sqlString);
break;
default:
return addslashes(stripslashes($sqlString));
break;
}
}
/**
* Load a template
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $strTemplateName
* @return void
*/
public function LoadTemplate($strTemplateName)
{
if ($strTemplateName == '') {
return;
}
$temp = $strTemplateName . ".php";
$file = Bootstrap::ExpandPath('templates') . $temp;
// Check if its a user template
if (file_exists($file)) {
//require_once( $file );
include ($file);
} else {
// Try to get the global system template
$file = PATH_TEMPLATE . PATH_SEP . $temp;
//require_once( $file );
if (file_exists($file)) {
include ($file);
}
}
}
/**
* verify path
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $strPath path
* @param boolean $createPath if true this public function will create the path
* @return boolean
*/
public static function verifyPath($strPath, $createPath = false)
{
$folder_path = strstr($strPath, '.') ? dirname($strPath) : $strPath;
if (file_exists($strPath) || @is_dir($strPath)) {
return true;
} else {
if ($createPath) {
//TODO:: Define Environment constants: Devel (0777), Production (0770), ...
Bootstrap::mk_dir($strPath, 0777);
} else {
return false;
}
}
return false;
}
/**
* getformatedDate
*
* @param date $date
* @param string $format default value 'yyyy-mm-dd',
* @param string $lang default value ''
*
* @return string $ret
*/
public function getformatedDate($date, $format = 'yyyy-mm-dd', $lang = '')
{
/**
* ******************************************************************************************************
* if the year is 2008 and the format is yy then -> 08
* if the year is 2008 and the format is yyyy then -> 2008
*
* if the month is 05 and the format is mm then -> 05
* if the month is 05 and the format is m and the month is less than 10 then -> 5 else digit normal
* if the month is 05 and the format is MM or M then -> May
*
* if the day is 5 and the format is dd then -> 05
* if the day is 5 and the format is d and the day is less than 10 then -> 5 else digit normal
* if the day is 5 and the format is DD or D then -> five
* *******************************************************************************************************
*/
//scape the literal
switch ($lang) {
case 'es':
$format = str_replace(' de ', '[of]', $format);
break;
}
//first we must formatted the string
$format = str_replace('yyyy', '{YEAR}', $format);
$format = str_replace('yy', '{year}', $format);
$format = str_replace('mm', '{YONTH}', $format);
$format = str_replace('m', '{month}', $format);
$format = str_replace('M', '{XONTH}', $format);
$format = str_replace('dd', '{DAY}', $format);
$format = str_replace('d', '{day}', $format);
$format = str_replace('h', '{h}', $format);
$format = str_replace('i', '{i}', $format);
$format = str_replace('s', '{s}', $format);
if ($lang === '') {
$lang = defined(SYS_LANG) ? SYS_LANG : 'en';
}
$aux = explode(' ', $date); //para dividir la fecha del dia
$date = explode('-', isset($aux[0]) ? $aux[0] : '00-00-00' ); //para obtener los dias, el mes, y el año.
$time = explode(':', isset($aux[1]) ? $aux[1] : '00:00:00' ); //para obtener las horas, minutos, segundos.
$year = (int) ((isset($date[0])) ? $date[0] : '0'); //year
$month = (int) ((isset($date[1])) ? $date[1] : '0'); //month
$day = (int) ((isset($date[2])) ? $date[2] : '0'); //day
$h = isset($time[0]) ? $time[0] : '00'; //hour
$i = isset($time[1]) ? $time[1] : '00'; //minute
$s = isset($time[2]) ? $time[2] : '00'; //second
$MONTHS = Array();
for ($i = 1; $i <= 12; $i++) {
$MONTHS[$i] = Bootstrap::LoadTranslation("ID_MONTH_$i", $lang);
}
$d = (int) $day;
$dd = Bootstrap::complete_field($day, 2, 1);
//missing D
$M = $MONTHS[$month];
$m = (int) $month;
$mm = Bootstrap::complete_field($month, 2, 1);
$yy = substr($year, strlen($year) - 2, 2);
$yyyy = $year;
$names = array('{day}', '{DAY}', '{month}', '{YONTH}', '{XONTH}', '{year}', '{YEAR}', '{h}', '{i}', '{s}' );
$values = array($d, $dd, $m, $mm, $M, $yy, $yyyy, $h, $i, $s );
$ret = str_replace($names, $values, $format);
//recovering the original literal
switch ($lang) {
case 'es':
$ret = str_replace('[of]', ' de ', $ret);
break;
}
return $ret;
}
/**
*
* @author Erik Amaru Ortiz <erik@colosa.com>
* @name complete_field($string, $lenght, $type={1:number/2:string/3:float})
*/
public function complete_field($campo, $long, $tipo)
{
$campo = trim($campo);
switch ($tipo) {
case 1: //number
$long = $long - strlen($campo);
for ($i = 1; $i <= $long; $i++) {
$campo = "0" . $campo;
}
break;
case 2: //string
$long = $long - strlen($campo);
for ($i = 1; $i <= $long; $i++) {
$campo = " " . $campo;
}
break;
case 3: //float
if ($campo != "0") {
$vals = explode(".", $long);
$ints = $vals[0];
$decs = $vals[1];
$valscampo = explode(".", $campo);
$intscampo = $valscampo[0];
$decscampo = $valscampo[1];
$ints = $ints - strlen($intscampo);
for ($i = 1; $i <= $ints; $i++) {
$intscampo = "0" . $intscampo;
}
//los decimales pueden ser 0 uno o dos
$decs = $decs - strlen($decscampo);
for ($i = 1; $i <= $decs; $i++) {
$decscampo = $decscampo . "0";
}
$campo = $intscampo . "." . $decscampo;
} else {
$vals = explode(".", $long);
$ints = $vals[0];
$decs = $vals[1];
$campo = "";
for ($i = 1; $i <= $ints; $i++) {
$campo = "0" . $campo;
}
$campod = "";
for ($i = 1; $i <= $decs; $i++) {
$campod = "0" . $campod;
}
$campo = $campo . "." . $campod;
}
break;
}
return $campo;
}
/**
* evalJScript
*
* @param string $c
*
* @return void
*/
public function evalJScript($c)
{
print ("<script language=\"javascript\">{$c}</script>");
}
/**
* Generate random number
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @return int
*/
public function generateUniqueID()
{
do {
$sUID = str_replace('.', '0', uniqid(rand(0, 999999999), true));
} while (strlen($sUID) != 32);
return $sUID;
//return strtoupper(substr(uniqid(rand(0, 9), false),0,14));
}
/**
* Encrypt URL
*
* @author Fernando Ontiveros Lira <fernando@colosa.com>
* @access public
* @param string $urlLink
* @return string
*/
public function encryptlink($url)
{
if (defined('ENABLE_ENCRYPT') && ENABLE_ENCRYPT == 'yes') {
return urlencode(Bootstrap::encrypt($url, URL_KEY));
} else {
return $url;
}
}
/**
* isWinOs
*
* @return true if the 3 first letters of PHP_OS got 'WIN', otherwise false.
*/
public function isWinOs()
{
return strtoupper(substr(PHP_OS, 0, 3)) == "WIN";
}
/**
* isNTOs
*
* @return true if PHP_OS is 'WINNT', otherwise false.
*/
public function isNTOs()
{
return PHP_OS == "WINNT";
}
/**
* isLinuxOs
*
* @return true if PHP_OS (upper text) got 'LINUX', otherwise false.
*/
public function isLinuxOs()
{
return strtoupper(PHP_OS) == "LINUX";
}
/**
* @deprecated 3.2.2, We keep this function only for backwards compatibility because is used in the plugin manager
*/
public static function initVendors()
{
}
public static function parseIniFile($filename)
{
$data = @parse_ini_file($filename, true);
$result = array();
if ($data === false) {
throw new Exception("Error parsing ini file: $filename");
}
foreach ($data as $key => $value) {
if (strpos($key, ':') !== false) {
list($key, $subSection) = explode(':', $key);
$result[trim($key)][trim($subSection)] = $value;
} else {
$result[$key] = $value;
}
}
return $result;
}
public static function displayMaveriksNotLoadedError()
{
if (! class_exists('\Maveriks\Util\ClassLoader')) {
require PATH_TRUNK . "framework/src/Maveriks/Pattern/Mvc/View.php";
require PATH_TRUNK . "framework/src/Maveriks/Pattern/Mvc/PhtmlView.php";
$message = "Please review your apache virtual host configuration file, and be sure you have the following rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>";
$view = new Maveriks\Pattern\Mvc\PhtmlView(PATH_TRUNK . "framework/src/templates/error.phtml");
$view->set("title", "Sistem Configuration Error");
$view->set("message", htmlentities($message));
echo $view->getOutput();
die();
}
}
public static function getPasswordHashConfig()
{
$config= new Configurations();
$passwordHashConfig = $config->getConfiguration('ENTERPRISE_SETTING_ENCRYPT', '');
if (!is_null($passwordHashConfig)) {
if (!is_array($passwordHashConfig)) {
$passwordHashConfig = array();
}
if (!isset($passwordHashConfig['current'])) {
$passwordHashConfig['current'] = 'md5';
}
if (!isset($passwordHashConfig['previous'])) {
$passwordHashConfig['previous'] = 'md5';
}
} else {
$passwordHashConfig = array('current' => 'md5', 'previous' => 'md5');
}
return $passwordHashConfig;
}
public static function getPasswordHashType()
{
$passwordHashConfig = Bootstrap::getPasswordHashConfig();
return $passwordHashConfig['current'];
}
public function hashPassword($pass, $hashType = '', $includeHashType = false)
{
if ($hashType == '') {
$hashType = Bootstrap::getPasswordHashType();
}
$var = hash($hashType, $pass);
if ($includeHashType) {
$var = $hashType . ':' . $var;
}
return $var;
}
/**
* Verify Hash password with password entered
*
* @param string $pass password
* @param string $userPass hash of password
* @return bool true or false
*/
public function verifyHashPassword($pass, $userPass)
{
global $RBAC;
$passwordHashConfig = Bootstrap::getPasswordHashConfig();
$hashTypeCurrent = $passwordHashConfig['current'];
$hashTypePrevious = $passwordHashConfig['previous'];
$acceptance = false;
if ($RBAC != null && $RBAC->loginWithHash()) {
//To enable compatibility with soap login
if ((Bootstrap::hashPassword($pass, $hashTypeCurrent) == $userPass) || ($pass === $hashTypeCurrent . ':' . $userPass)) {
$acceptance = true;
} else if ((Bootstrap::hashPassword($pass, $hashTypePrevious) == $userPass) || ($pass === $hashTypePrevious . ':' . $userPass)) {
$acceptance = true;
}
} else {
if (Bootstrap::hashPassword($pass, $hashTypeCurrent) == $userPass) {
$acceptance = true;
} else if (Bootstrap::hashPassword($pass, $hashTypePrevious) == $userPass) {
$acceptance = true;
}
}
return $acceptance;
}
/**
* @param $string
* @return mixed
*/
public function encryptOld ($string)
{
$consthashFx = self::hashFx;
return $consthashFx($string);
}
/**
* Set Language
*/
public static function setLanguage()
{
$acceptLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])?$_SERVER['HTTP_ACCEPT_LANGUAGE']:'en';
if (!defined('SYS_LANG')) {
$Translations = new \Translation;
$translationsTable = $Translations->getTranslationEnvironments();
$inLang = false;
foreach ($translationsTable as $locale) {
if ($locale['LOCALE'] == $acceptLanguage){
$inLang = true;
break;
}
}
$lang = $inLang?$acceptLanguage:'en';
define("SYS_LANG", $lang);
}
}
/**
* Set Language
*/
public static function isIE()
{
$isIE = false;
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$ua = htmlentities($_SERVER['HTTP_USER_AGENT'], ENT_QUOTES, 'UTF-8');
if (preg_match('~MSIE|Internet Explorer~i', $ua) || (strpos($ua, 'Trident/7.0; rv:11.0') !== false)) {
$isIE = true;
}
}
return $isIE;
}
/**
* Stores a message in the log file, if the file size exceeds
*
* @param string $channel
* @param string $message
* @param array $context
* @param string $file
* @param string $pathData
* @param string $ws workspace
*
* @return void
*/
public static function registerMonolog($channel, $level, $message, $context, $ws, $file = 'cron.log', $pathData = PATH_DATA)
{
$fileLog = $pathData .'sites'. PATH_SEP . $ws . PATH_SEP . 'log' . PATH_SEP . $file;
$registerLogger = &MonologProvider::getSingleton($channel, $fileLog);
$registerLogger->addLog($level, $message, $context);
}
/**
* Get the default information from the context
*
* @return array $aContext void
*/
public static function getDefaultContextLog(){
$sysSys = (!empty(config("system.workspace")))? config("system.workspace") : "Undefined";
$date = \ProcessMaker\Util\DateTime::convertUtcToTimeZone(date('Y-m-d H:m:s'));
$aContext = array(
'ip' => \G::getIpAddress()
,'timeZone' => $date
,'workspace' => $sysSys
);
return $aContext;
}
/**
* get DISABLE_PHP_UPLOAD_EXECUTION value defined in env.ini
* @return int
*/
public static function getDisablePhpUploadExecution()
{
$disablePhpUploadExecution = 0;
if (defined("DISABLE_PHP_UPLOAD_EXECUTION")) {
$disablePhpUploadExecution = (int) DISABLE_PHP_UPLOAD_EXECUTION;
}
return $disablePhpUploadExecution;
}
/**
* Record the action of executing a php file or attempting to upload a php
* file in server.
* @param type $channel
* @param type $level
* @param type $message
* @param type $fileName
*/
public static function registerMonologPhpUploadExecution($channel, $level, $message, $fileName)
{
$context = \Bootstrap::getDefaultContextLog();
$context['action'] = $channel;
$context['filename'] = $fileName;
if (defined("SYS_CURRENT_URI") && defined("SYS_CURRENT_PARMS")) {
$context['url'] = SYS_CURRENT_URI . '?' . SYS_CURRENT_PARMS;
}
$context['usrUid'] = isset($_SESSION['USER_LOGGED']) ? $_SESSION['USER_LOGGED'] : '';
$sysSys = !empty(config("system.workspace")) ? config("system.workspace") : "Undefined";
\Bootstrap::registerMonolog($channel, $level, $message, $context, $sysSys, 'processmaker.log');
}
/*
* Set the constant to related the Workspaces
*
* @param string $workspace
*
* @return void
*/
public static function setConstantsRelatedWs($wsName = null) {
if (empty(config("system.workspace")) && !is_null($wsName)) {
//If SYS_SYS exists, is not update with $wsName
define('SYS_SYS', $wsName);
config(["system.workspace" => $wsName]);
}
if (!empty(config("system.workspace")) && !defined('PATH_DATA_SITE')) {
define('PATH_DATA_SITE', PATH_DATA . 'sites' . PATH_SEP . config("system.workspace") . PATH_SEP);
}
if (defined('PATH_DATA_SITE') && !defined('PATH_WORKSPACE')) {
define('PATH_WORKSPACE', PATH_DATA_SITE);
}
set_include_path(get_include_path() . PATH_SEPARATOR . PATH_DATA_SITE);
}
}
|