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 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388
|
--
-- $Id: blog.sql,v 1.20.2.7 2010/12/07 10:59:24 source Exp $
--
-- Blogger API support.
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2006 OpenLink Software
--
-- This project is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation; only version 2 of the License, dated June 1991.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
--
-- BLOG SERVER API
--
-- USER DEFINED TYPES
--set MACRO_SUBSTITUTION off;
--set IGNORE_PARAMS on;
create procedure BLOG.DBA.blog2_exec_no_error(in expr varchar) {
declare state, message, meta, result any;
exec(expr, state, message, vector(), 0, meta, result);
}
;
create procedure BLOG.DBA.blog2_check_and_create(in old_type_name varchar, in new_type_name varchar, in expr varchar)
{
declare state, message, meta, result any;
state := '00000';
exec(sprintf ('select new %s ()', old_type_name), state, message, vector(), 0, meta, result);
if (state = '00000')
expr := ('create type ' || new_type_name || ' under ' || old_type_name);
exec(expr, state, message, vector(), 0, meta, result);
}
;
create procedure BLOG2_DAV_PROP_SET (
in path varchar,
in propname varchar,
in propvalue any,
in auth_uname varchar := null,
in auth_pwd varchar := null,
in extern integer := 1,
in check_locks integer := 1,
in overwrite integer := 1
)
{
declare st, id any;
if ((path <> '') and (path[length(path)-1] = 47))
st := 'C';
else
st := 'R';
id := DAV_SEARCH_ID (path, st);
if (id < 0)
return id;
DAV_PROP_SET_RAW (id, st, propname, propvalue, overwrite, http_dav_uid ());
}
;
create procedure
BLOG2_UPDATE_TABLES_NAMES ()
{
if (registry_get ('__weblog2_tables_is_upgrated') = 'OK')
return;
BLOG.DBA.blog2_exec_no_error ('drop table DB.DBA.SYS_BLOGS_B_CONTENT_WORDS');
BLOG.DBA.blog2_exec_no_error ('drop trigger DB_DBA_SYS_BLOG_ATTACHES_FK_CHECK_INSERT');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.SYS_SYS_BLOGS_IN_SYS_BLOG_ATTACHES');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_ATTACHES_FK_CHECK_INSERT');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_ATTACHES_FK_CHECK_UPDATE');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_INFO_PK_CHECK_DELETE');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_INFO_PK_CHECK_UPDATE');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.SYS_BLOG2_INFO_D');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOGS_VTD_log');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.SYS_BLOGS_FTT_D');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.SYS_SYS_BLOGS_RM_SYS_BLOG_ATTACHES');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_CHANNEL_FEEDS_FK_CHECK_INSERT');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_CHANNEL_FEEDS_FK_CHECK_UPDATE');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_CHANNEL_INFO_FK_DELETE');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_CHANNEL_INFO_PK_CHECK_UPDATE');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_SEARCH_ENGINE_FK_DELETE');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_SEARCH_ENGINE_FK_UPDATE');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_SEARCH_ENGINE_SETTINGS_FK_CHECK_INSERT');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_SEARCH_ENGINE_SETTINGS_FK_CHECK_UPDATE');
BLOG.DBA.blog2_exec_no_error ('drop trigger DB_DBA_SYS_BLOG_WEBLOG_HOSTS_FK_DELETE');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_WEBLOG_HOSTS_FK_UPDATE');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_WEBLOG_PING_FK_CHECK_INSERT');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOG_WEBLOG_PING_FK_CHECK_UPDATE');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOGS_VTI_log');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOGS_VTUB_log');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.DB_DBA_SYS_BLOGS_VTU_log');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.SYS_SYS_BLOGS_UP_SYS_BLOG_ATTACHES');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.SYS_BLOGS_D1');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.SYS_BLOGS_I1');
BLOG.DBA.blog2_exec_no_error ('drop trigger DBA.SYS_BLOGS_U1');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOGS rename BLOG.DBA.SYS_BLOGS');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_INFO rename BLOG.DBA.SYS_BLOG_INFO');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_REFFERALS rename BLOG.DBA.SYS_BLOG_REFFERALS');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_DOMAINS rename BLOG.DBA.SYS_BLOG_DOMAINS');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_VISITORS rename BLOG.DBA.SYS_BLOG_VISITORS');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_CLOUD_NOTIFICATION rename BLOG.DBA.SYS_BLOG_CLOUD_NOTIFICATION');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_CHANNELS rename BLOG.DBA.SYS_BLOG_CHANNELS');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_CHANNEL_CATEGORY rename BLOG.DBA.SYS_BLOG_CHANNEL_CATEGORY');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_CHANNEL_INFO rename BLOG.DBA.SYS_BLOG_CHANNEL_INFO');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_CHANNEL_FEEDS rename BLOG.DBA.SYS_BLOG_CHANNEL_FEEDS');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.BLOG_COMMENTS rename BLOG.DBA.BLOG_COMMENTS');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.MTYPE_CATEGORIES rename BLOG.DBA.MTYPE_CATEGORIES');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.MTYPE_BLOG_CATEGORY rename BLOG.DBA.MTYPE_BLOG_CATEGORY');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.MTYPE_TRACKBACK_PINGS rename BLOG.DBA.MTYPE_TRACKBACK_PINGS');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_ROUTING rename BLOG.DBA.SYS_ROUTING');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOGS_ROUTING_LOG rename BLOG.DBA.SYS_BLOGS_ROUTING_LOG');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_ROUTING_TYPE rename BLOG.DBA.SYS_ROUTING_TYPE');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_ROUTING_PROTOCOL rename BLOG.DBA.SYS_ROUTING_PROTOCOL');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_WEBLOG_UPDATES_PINGS rename BLOG.DBA.SYS_WEBLOG_UPDATES_PINGS');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_CONTACTS rename BLOG.DBA.SYS_BLOG_CONTACTS');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_WEBLOG_HOSTS rename BLOG.DBA.SYS_BLOG_WEBLOG_HOSTS');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_WEBLOG_PING rename BLOG.DBA.SYS_BLOG_WEBLOG_PING');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_SEARCH_ENGINE rename BLOG.DBA.SYS_BLOG_SEARCH_ENGINE');
BLOG.DBA.blog2_exec_no_error ('alter table DB.DBA.SYS_BLOG_SEARCH_ENGINE_SETTINGS rename BLOG.DBA.SYS_BLOG_SEARCH_ENGINE_SETTINGS');
BLOG.DBA.blog2_exec_no_error ('alter table SYS_BLOG_ATTACHES rename BLOG.DBA.SYS_BLOG_ATTACHES');
BLOG.DBA.blog2_exec_no_error ('update BLOG.DBA.SYS_BLOGS set B_STATE=2');
delete from "DB"."DBA"."SYS_SCHEDULED_EVENT" where SE_NAME = 'Weblog Ping notifications';
delete from "DB"."DBA"."SYS_SCHEDULED_EVENT" where SE_NAME = 'Weblog News aggregator';
delete from "DB"."DBA"."SYS_SCHEDULED_EVENT" where SE_NAME = 'Routing Jobs Queue';
DB.DBA.vhost_remove (lpath=>'/RPC2');
BLOG.DBA.blog2_exec_no_error ('drop user MT');
BLOG.DBA.blog2_exec_no_error ('drop procedure BLOG.DBA.BLOG_SEND_PINGS');
BLOG.DBA.blog2_exec_no_error ('drop procedure BLOG.DBA.BLOG_FEED_AGREGATOR');
BLOG.DBA.blog2_exec_no_error ('drop procedure BLOG.DBA.ROUTING_PROCESS_JOBS');
BLOG.DBA.blog2_exec_no_error (
'update BLOG.DBA.SYS_BLOG_INFO set BI_HAVE_COMUNITY_BLOG = 1 where BI_BLOG_ID = ''dav-blog-1''');
registry_set ('__weblog2_tables_is_upgrated', 'OK');
commit work;
}
;
BLOG2_UPDATE_TABLES_NAMES ()
;
USE "BLOG"
;
create procedure blog2_add_col(in tbl varchar, in col varchar, in coltype varchar) {
if(not exists(select 1 from DB.DBA.SYS_KEYS where KEY_TABLE = tbl))
return;
if(exists(
select
top 1 1
from
DB.DBA.SYS_COLS
where
upper("TABLE") = upper(tbl) and
upper("COLUMN") = upper(col)
)
) return;
exec (sprintf ('alter table %s add column %s %s', tbl, col, coltype));
}
;
create procedure blog2_modify_pk_safe (in tablename varchar, in pks any, in id_col varchar)
{
declare pks1 any;
pks1 := vector ();
for SELECT c."COLUMN" as COL
from DB.DBA.SYS_KEYS k, DB.DBA.SYS_KEY_PARTS kp, DB.DBA."SYS_COLS" c
where
name_part (k.KEY_TABLE, 0) = name_part (tablename, 0) and
name_part (k.KEY_TABLE, 1) = name_part (tablename, 1) and
name_part (k.KEY_TABLE, 2) = name_part (tablename, 2)
and __any_grants (k.KEY_TABLE)
and c."COLUMN" <> '_IDN'
and k.KEY_IS_MAIN = 1
and k.KEY_MIGRATE_TO is null
and kp.KP_KEY_ID = k.KEY_ID
and kp.KP_NTH < k.KEY_DECL_PARTS
and c.COL_ID = kp.KP_COL
order by kp.KP_NTH do
{
pks1 := vector_concat (pks1, vector (COL));
}
declare i, l int;
i := 0; l := length (pks);
if (length (pks1) = length (pks))
{
for (i := 0; i < l; i := i + 1)
{
if (casemode_strcmp (pks[i], pks1[i]) <> 0)
goto alterst;
}
--dbg_obj_print ('already done.');
return;
}
alterst:
declare altersql any;
altersql := sprintf ('alter table "%I"."%I"."%I" modify primary key (', name_part (tablename, 0), name_part (tablename, 1), name_part (tablename, 2));
for (i := 0; i < l; i := i + 1)
{
altersql := altersql || pks[i] || ',';
}
altersql := rtrim (altersql, ',');
altersql := altersql || ')';
--dbg_obj_print ('DOING PK MODIFY!', altersql);
if (id_col is not null)
{
--dbg_obj_print ('ID column unset');
update DB.DBA.SYS_COLS set COL_CHECK = '' where \COLUMN = id_col and \TABLE = tablename;
__ddl_changed (tablename);
}
--dbg_obj_print ('PK change');
exec (altersql);
if (id_col is not null)
{
--dbg_obj_print ('ID column set');
update DB.DBA.SYS_COLS set COL_CHECK = 'I' where \COLUMN = id_col and \TABLE = tablename;
__ddl_changed (tablename);
}
--dbg_obj_print ('done.');
}
;
blog2_exec_no_error ('create type "blogPost" as (
content varchar,
dateCreated datetime,
"postid" varchar,
userid any
) self as ref')
;
blog2_exec_no_error ('create type "blogRequest" under "blogPost"
as
(
user_name varchar,
passwd varchar,
appkey varchar,
blogid varchar default null,
postId varchar default null,
auth_userid integer,
blog_lhome varchar,
blog_phome varchar,
blog_owner int,
publish smallint,
struct BLOG.DBA."MWeblogPost",
header varchar default null
) self as ref
constructor method "blogRequest" (appkey varchar, blogid varchar, postId varchar, user_name varchar, passwd varchar)')
;
create constructor method
"blogRequest" (in appkey varchar, in blogid varchar, in postId varchar, in user_name varchar, in passwd varchar)
for "blogRequest"
{
self.appkey := appkey;
self.blogid := blogid;
self.postId := postId;
self.user_name := user_name;
self.passwd := passwd;
}
;
grant execute on "blogPost" to public
;
grant execute on "blogRequest" to public
;
--
-- WEBLOG META API STRUCT
--
DB.DBA.SOAP_DT_DEFINE ('MWeblogPost:ArrayOfstring',
'<complexType name="ArrayOfstring" targetNamespace="MWeblogPost"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://soapinterop.org/xsd">
<complexContent>
<restriction base="enc:Array">
<sequence>
<element name="item" type="string" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
</sequence>
<attributeGroup ref="enc:commonAttributes"/>
<attribute ref="enc:arrayType" wsdl:arrayType="string[]"/>
</restriction>
</complexContent>
</complexType>')
;
blog2_exec_no_error ('create type
BLOG.DBA."MWeblogEnclosure" as
(
"length" int,
"type" varchar,
url varchar
)')
;
blog2_exec_no_error ('create type
BLOG.DBA."MWeblogSource" as
(
name varchar,
url varchar
)')
;
-- Represents also the "item" element of RSS2
blog2_check_and_create ('DB.DBA.MWeblogPost', 'BLOG.DBA."MWeblogPost"',
'create type BLOG.DBA."MWeblogPost" as
(
categories any __soap_type ''MWeblogPost:ArrayOfstring'',
dateCreated datetime,
description varchar,
enclosure BLOG.DBA."MWeblogEnclosure",
permaLink varchar,
postid any,
source MWeblogSource,
title varchar,
userid any,
link varchar,
author varchar,
comments varchar,
guid varchar
)')
;
blog2_exec_no_error ( --'DB.DBA.MTWeblogPost', 'BLOG.DBA."MTWeblogPost"',
'create type BLOG.DBA."MTWeblogPost" under BLOG.DBA."MWeblogPost" as
(
mt_allow_comments int,
mt_allow_pings int,
mt_convert_breaks varchar,
mt_excerpt varchar,
mt_tb_ping_urls any __soap_type ''MWeblogPost:ArrayOfstring'',
mt_text_more varchar,
mt_keywords varchar
)')
;
grant execute on BLOG.DBA."MTWeblogPost" to public
;
grant execute on BLOG.DBA."MWeblogPost" to public
;
grant execute on BLOG.DBA."MWeblogSource" to public
;
grant execute on BLOG.DBA."MWeblogEnclosure" to public
;
-- TABLE SCHEMA
blog2_exec_no_error ('create table SYS_BLOGS (
B_APPKEY varchar,
B_BLOG_ID varchar,
B_CONTENT long varchar,
B_TITLE long varchar,
B_POST_ID varchar,
B_TS datetime,
B_USER_ID integer,
B_META BLOG.DBA."MWeblogPost",
B_CONTENT_ID integer identity,
B_COMMENTS_NO integer default 0,
B_TRACKBACK_NO integer default 0,
B_REF varchar default null,
B_MODIFIED timestamp,
B_STATE integer,
B_IS_ACTIVE integer default 0,
B_HAVE_ENCLOSURE integer default 0,
B_ENCLOSURE_TYPE varchar default null,
B_RFC_ID varchar default null,
B_RFC_HEADER long varchar,
B_VER int default 1,
primary key (B_BLOG_ID, B_TS, B_POST_ID)
)');
blog2_add_col('BLOG.DBA.SYS_BLOGS', 'B_STATE', 'integer');
blog2_add_col('BLOG.DBA.SYS_BLOGS', 'B_TITLE', 'varchar');
blog2_add_col('BLOG.DBA.SYS_BLOGS', 'B_IS_ACTIVE', 'integer default 0');
blog2_add_col('BLOG.DBA.SYS_BLOGS', 'B_HAVE_ENCLOSURE', 'integer default 0');
blog2_add_col('BLOG.DBA.SYS_BLOGS', 'B_ENCLOSURE_TYPE', 'varchar default null');
blog2_add_col('BLOG.DBA.SYS_BLOGS', 'B_RFC_ID', 'varchar');
blog2_add_col('BLOG.DBA.SYS_BLOGS', 'B_RFC_HEADER', 'long varchar');
blog2_add_col('BLOG.DBA.SYS_BLOGS', 'B_VER', 'int default 1');
blog2_exec_no_error ('create index SYS_BLOGS_CONTENT_ID on SYS_BLOGS (B_CONTENT_ID)');
blog2_exec_no_error ('create unique index SYS_BLOGS_POST_ID on SYS_BLOGS (B_POST_ID)');
blog2_exec_no_error ('create unique index SYS_BLOGS_B_BLOG_ID_B_POST_ID on SYS_BLOGS (B_BLOG_ID, B_POST_ID)');
blog2_exec_no_error ('create index SYS_BLOGS_RFC_ID on SYS_BLOGS (B_RFC_ID)');
--blog2_exec_no_error ('create index SYS_BLOGS_HAVE_ENCLOSURE on BLOG.DBA.SYS_BLOGS (B_HAVE_ENCLOSURE)')
--;
blog2_exec_no_error ('create table BLOG_POST_LINKS (
PL_BLOG_ID varchar,
PL_POST_ID varchar,
PL_LINK varchar,
PL_TITLE varchar,
PL_PING int default 0,
foreign key (PL_BLOG_ID, PL_POST_ID) references SYS_BLOGS (B_BLOG_ID, B_POST_ID) on delete cascade,
primary key (PL_BLOG_ID, PL_POST_ID, PL_LINK)
)');
blog2_add_col('BLOG.DBA.BLOG_POST_LINKS', 'PL_PING', 'int default 0');
blog2_exec_no_error ('create table BLOG_COMMENT_LINKS (
CL_BLOG_ID varchar,
CL_POST_ID varchar,
CL_CID int,
CL_LINK varchar,
CL_TITLE varchar,
CL_PING int default 0,
foreign key (CL_BLOG_ID, CL_POST_ID) references SYS_BLOGS (B_BLOG_ID, B_POST_ID) on delete cascade,
primary key (CL_BLOG_ID, CL_POST_ID, CL_CID, CL_LINK)
)');
blog2_exec_no_error ('create table BLOG_POST_ENCLOSURES (
PE_BLOG_ID varchar,
PE_POST_ID varchar,
PE_URL varchar,
PE_TYPE varchar,
PE_LEN int,
foreign key (PE_BLOG_ID, PE_POST_ID) references SYS_BLOGS (B_BLOG_ID, B_POST_ID) on delete cascade,
primary key (PE_BLOG_ID, PE_POST_ID, PE_URL)
)');
blog2_exec_no_error ('create table SYS_BLOG_INFO
(
BI_BLOG_ID varchar,
BI_OWNER integer,
BI_HOME varchar,
BI_P_HOME varchar,
BI_DEFAULT_PAGE varchar,
BI_TITLE varchar,
BI_COPYRIGHTS varchar,
BI_DISCLAIMER varchar,
BI_WRITERS any,
BI_READERS any,
BI_PINGS any,
BI_ABOUT varchar,
BI_E_MAIL varchar,
BI_TZ int default null,
BI_SHOW_CONTACT int default 1,
BI_SHOW_REGIST int default 1,
BI_COMMENTS int default 1,
BI_QUOTA int default null,
BI_HOME_PAGE varchar default '''',
BI_FILTER varchar default ''*default*'',
BI_PHOTO varchar,
BI_KEYWORDS varchar,
BI_COMMENTS_NOTIFY int default 0,
BI_ADD_YOUR_BLOG int default 0,
BI_RSS_VERSION varchar default ''2.0'',
BI_OPTIONS long varbinary,
BI_WAI_MEMBER_MODEL int,
BI_TB_NOTIFY int default 0,
BI_LAST_UPDATE datetime,
BI_BLOG_SEQ integer identity,
BI_DASHBOARD long varchar,
BI_SHOW_AS_NEWS int default 0,
BI_ICON varchar,
BI_TEMPLATE varchar,
BI_AUDIO varchar,
BI_CSS varchar,
BI_INCLUSION integer,
BI_DEL_USER varchar,
BI_DEL_PASS varchar,
BI_WAI_NAME varchar,
BI_HAVE_COMUNITY_BLOG int,
BI_AUTO_TAGGING int default 1,
primary key (BI_BLOG_ID)
)')
;
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_WAI_MEMBER_MODEL', 'int');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_ICON', 'varchar');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_BLOG_SEQ', 'integer identity');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_DASHBOARD', 'long varchar');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_SHOW_AS_NEWS', 'int default 0');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_TEMPLATE', 'varchar');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_AUDIO', 'varchar');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_CSS', 'varchar');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_INCLUSION', 'integer');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_DEL_USER', 'varchar');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_DEL_PASS', 'varchar');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_WAI_NAME', 'varchar');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_HAVE_COMUNITY_BLOG', 'int');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_TB_NOTIFY', 'int');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_LAST_UPDATE', 'datetime');
blog2_add_col('BLOG.DBA.SYS_BLOG_INFO', 'BI_AUTO_TAGGING', 'int default 1');
blog2_exec_no_error ('create unique index SYS_BLOG_INFO_WAI on BLOG.DBA.SYS_BLOG_INFO (BI_WAI_NAME)');
blog2_exec_no_error ('create table SYS_BLOG_REFFERALS
(
BR_URI varchar,
BR_TITLE varchar,
BR_BLOG_ID varchar,
BR_POST_ID varchar,
primary key (BR_BLOG_ID, BR_POST_ID, BR_URI)
)')
;
blog2_exec_no_error ('create table SYS_BLOG_VISITORS
(
BV_ID varchar,
BV_BLOG_ID varchar,
BV_NAME varchar,
BV_E_MAIL varchar,
BV_IP varchar,
BV_HOME varchar,
BV_NOTIFY int default 0,
BV_POST_ID varchar default '''',
BV_VIA_DOMAIN varchar default null,
primary key (BV_E_MAIL, BV_BLOG_ID, BV_POST_ID)
)');
blog2_exec_no_error ('create index SYS_BLOG_VISITORS_E_MAIL on SYS_BLOG_VISITORS (BV_E_MAIL)');
blog2_exec_no_error ('create unique index SYS_BLOG_VISITORS_ID on SYS_BLOG_VISITORS (BV_ID)');
blog2_add_col('BLOG.DBA.SYS_BLOG_VISITORS', 'BV_VIA_DOMAIN', 'varchar')
;
blog2_exec_no_error ('create table SYS_BLOG_CLOUD_NOTIFICATION
(
BCN_URL varchar,
BCN_BLOG_ID varchar,
BCN_TS datetime,
BCN_PROTO varchar,
BCN_METHOD varchar,
BCN_USER_DATA any,
primary key (BCN_BLOG_ID, BCN_URL)
)')
;
blog2_exec_no_error ('create table SYS_BLOG_CHANNELS (
BC_BLOG_ID varchar,
BC_CHANNEL_URI varchar,
BC_AGGREGATE int,
BC_LOCAL_RES varchar,
BC_CATEGORY varchar,
BC_CAT_ID int,
BC_SHARED int,
BC_REL varchar,
primary key (BC_BLOG_ID, BC_CHANNEL_URI)
)')
;
blog2_add_col('BLOG.DBA.SYS_BLOG_CHANNELS', 'BC_SHARED', 'int')
;
blog2_add_col('BLOG.DBA.SYS_BLOG_CHANNELS', 'BC_REL', 'varchar')
;
blog2_exec_no_error ('create index SYS_BLOG_CHANNELS_I1 on SYS_BLOG_CHANNELS (BC_BLOG_ID, BC_CAT_ID)');
blog2_exec_no_error ('create table SYS_BLOG_CHANNEL_CATEGORY (
BCC_ID integer identity,
BCC_BLOG_ID varchar,
BCC_NAME varchar,
BCC_IS_BLOG int default 0,
primary key (BCC_BLOG_ID, BCC_NAME)
)');
;
blog2_exec_no_error ('create table SYS_BLOG_CHANNEL_INFO
(
BCD_CHANNEL_URI varchar,
BCD_HOME_URI varchar,
BCD_TITLE varchar,
BCD_FORMAT varchar,
BCD_UPDATE_PERIOD varchar default ''hourly'',
BCD_LANG varchar default ''us-en'',
BCD_UPDATE_FREQ int default 1,
BCD_LAST_UPDATE datetime,
BCD_UPDATE integer,
BCD_TAG varchar,
BCD_ERROR_LOG long varchar default null,
BCD_SOURCE_URI varchar default null,
BCD_IS_BLOG integer default 1,
BCD_AUTHOR_NAME varchar,
BCD_AUTHOR_EMAIL varchar,
primary key (BCD_CHANNEL_URI)
)')
;
--blog2_add_col('BLOG.DBA.SYS_BLOG_CHANNEL_INFO', 'BCD_XFN_KEYWORDS', 'varchar')
--;
blog2_add_col('BLOG.DBA.SYS_BLOG_CHANNEL_INFO', 'BCD_AUTHOR_NAME', 'varchar')
;
blog2_add_col('BLOG.DBA.SYS_BLOG_CHANNEL_INFO', 'BCD_AUTHOR_EMAIL', 'varchar')
;
create trigger SYS_BLOG_CHANNEL_INFO_UPDATE after insert on SYS_BLOG_CHANNEL_INFO referencing new as N
{
declare period, freq, uri any;
declare upd int;
uri := N.BCD_CHANNEL_URI;
period := lower (coalesce (N.BCD_UPDATE_PERIOD, 'daily'));
freq := coalesce (N.BCD_UPDATE_FREQ, 1);
-- Hourly, Daily, Weekly, Monthly, Yearly
upd := case period
when 'hourly' then 60
when 'daily' then 1440
when 'weekly' then 10080
when 'monthly' then 43200
when 'yearly' then 525600
else 1440 end;
upd := upd / freq;
set triggers off;
update SYS_BLOG_CHANNEL_INFO set BCD_UPDATE = upd, BCD_UPDATE_FREQ = freq where BCD_CHANNEL_URI = uri;
set triggers on;
}
;
blog2_exec_no_error ('create table SYS_BLOG_CHANNEL_FEEDS
(
CF_ID int,
CF_CHANNEL_URI varchar references SYS_BLOG_CHANNEL_INFO (BCD_CHANNEL_URI) on delete cascade,
CF_TITLE varchar,
CF_DESCRIPTION long varchar,
CF_LINK varchar,
CF_GUID varchar,
CF_PUBDATE datetime,
CF_COMMENT_API varchar,
CF_COMMENT_RSS varchar,
primary key (CF_CHANNEL_URI, CF_ID)
)')
;
blog2_add_col('BLOG.DBA.SYS_BLOG_CHANNEL_FEEDS', 'CF_READ', 'int')
;
blog2_exec_no_error ('create view BLOG_CHANNELS (BC_BLOG_ID, BC_TITLE, BC_HOME_URI, BC_RSS_URI,
BC_FORM, BC_UPD, BC_LANG, BC_FREQ, BC_SOURCE)
as select BC_BLOG_ID, BCD_TITLE, BCD_HOME_URI, BCD_CHANNEL_URI,
BCD_FORMAT, BCD_UPDATE_PERIOD, BCD_LANG , BCD_UPDATE_FREQ, BCD_SOURCE_URI
from SYS_BLOG_CHANNELS, SYS_BLOG_CHANNEL_INFO where BC_CHANNEL_URI = BCD_CHANNEL_URI')
;
blog2_exec_no_error ('create table BLOG_COMMENTS
(
BM_BLOG_ID varchar,
BM_POST_ID varchar,
BM_ID integer identity,
BM_COMMENT long varchar,
BM_NAME varchar,
BM_E_MAIL varchar,
BM_HOME_PAGE varchar,
BM_ADDRESS varchar,
BM_TS datetime,
BM_IS_SPAM int,
BM_IS_PUB int,
BM_POSTED_VIA varchar,
BM_TITLE varchar,
BM_RFC_ID varchar,
BM_RFC_HEADER long varchar,
BM_REF_ID int default null,
BM_RFC_REFERENCES varchar default null,
BM_OPENID_SIG long varbinary default null,
BM_OWN_COMMENT int default 0,
primary key (BM_BLOG_ID, BM_POST_ID, BM_ID)
)')
;
blog2_exec_no_error ('create index BLOG_COMMENTS_FK on BLOG_COMMENTS (BM_BLOG_ID, BM_POST_ID)')
;
blog2_exec_no_error ('create index BLOG_COMMENTS_POST on BLOG_COMMENTS (BM_POST_ID)')
;
blog2_exec_no_error ('create index BLOG_COMMENTS_POST_TS on BLOG_COMMENTS (BM_TS)');
blog2_add_col('BLOG.DBA.BLOG_COMMENTS', 'BM_IS_SPAM', 'int')
;
blog2_add_col('BLOG.DBA.BLOG_COMMENTS', 'BM_IS_PUB', 'int')
;
blog2_add_col('BLOG.DBA.BLOG_COMMENTS', 'BM_POSTED_VIA', 'varchar')
;
blog2_add_col('BLOG.DBA.BLOG_COMMENTS', 'BM_RFC_ID', 'varchar')
;
blog2_add_col('BLOG.DBA.BLOG_COMMENTS', 'BM_RFC_HEADER', 'long varchar')
;
blog2_add_col('BLOG.DBA.BLOG_COMMENTS', 'BM_TITLE', 'varchar')
;
blog2_add_col('BLOG.DBA.BLOG_COMMENTS', 'BM_REF_ID', 'int default null')
;
blog2_add_col('BLOG.DBA.BLOG_COMMENTS', 'BM_RFC_REFERENCES', 'varchar default null')
;
blog2_add_col('BLOG.DBA.BLOG_COMMENTS', 'BM_OPENID_SIG', 'long varbinary default null')
;
blog2_add_col('BLOG.DBA.BLOG_COMMENTS', 'BM_OWN_COMMENT', 'int default 0')
;
blog2_exec_no_error ('create index BLOG_COMMENTS_PUB on BLOG_COMMENTS (BM_BLOG_ID, BM_POST_ID, BM_IS_PUB)')
;
blog2_exec_no_error ('create table MTYPE_CATEGORIES (
MTC_ID varchar,
MTC_BLOG_ID varchar,
MTC_NAME varchar,
MTC_ROUTING int default 0,
MTC_DEFAULT int default 0,
MTC_KEYWORDS long varchar,
MTC_SHARED int,
primary key (MTC_BLOG_ID, MTC_ID))')
;
blog2_add_col('BLOG.DBA.MTYPE_CATEGORIES', 'MTC_SHARED', 'int')
;
blog2_exec_no_error ('create table MTYPE_BLOG_CATEGORY (
MTB_CID varchar,
MTB_POST_ID varchar,
MTB_BLOG_ID varchar,
MTB_PRIMARY int,
MTB_IS_AUTO int default 0,
primary key (MTB_CID, MTB_POST_ID, MTB_BLOG_ID))')
;
blog2_exec_no_error ('create table MTYPE_TRACKBACK_PINGS
(
MP_POST_ID varchar not null,
MP_URL varchar not null,
MP_TITLE varchar,
MP_EXCERPT varchar,
MP_BLOG_NAME varchar,
MP_IP varchar,
MP_TS timestamp,
MP_ID int identity,
MP_IS_SPAM int,
MP_IS_PUB int,
MP_VIA_DOMAIN varchar
)')
;
blog2_add_col('BLOG.DBA.MTYPE_TRACKBACK_PINGS', 'MP_ID', 'int identity')
;
blog2_add_col('BLOG.DBA.MTYPE_TRACKBACK_PINGS', 'MP_IS_SPAM', 'int')
;
blog2_add_col('BLOG.DBA.MTYPE_TRACKBACK_PINGS', 'MP_IS_PUB', 'int')
;
blog2_add_col('BLOG.DBA.MTYPE_TRACKBACK_PINGS', 'MP_VIA_DOMAIN', 'varchar')
;
-- Routing Table Structure:
blog2_exec_no_error ('create table SYS_ROUTING
(
R_JOB_ID int primary key,
R_U_ID int,
R_TYPE_ID int,
R_PROTOCOL_ID int,
R_DESTINATION varchar,
R_DESTINATION_ID any,
R_AUTH_USER varchar,
R_AUTH_PWD varchar,
R_ITEM_ID varchar,
R_FREQUENCY integer default 60,
R_LAST_ROUND datetime,
R_EXCEPTION_TAG varchar,
R_EXCEPTION_ID varchar,
R_INCLUSION_ID varchar,
R_KEEP_REMOTE int default 0,
R_MAX_ERRORS int default -1,
R_ITEM_MAX_RETRANSMITS int default 1
)')
;
blog2_add_col('BLOG.DBA.SYS_ROUTING', 'R_KEEP_REMOTE', 'int default 0')
;
blog2_add_col('BLOG.DBA.SYS_ROUTING', 'R_MAX_ERRORS', 'int default -1')
;
blog2_add_col('BLOG.DBA.SYS_ROUTING', 'R_ITEM_MAX_RETRANSMITS', 'int default 1')
;
update SYS_ROUTING set R_KEEP_REMOTE = 0 where R_KEEP_REMOTE is null
;
update SYS_ROUTING set R_MAX_ERRORS = -1, R_ITEM_MAX_RETRANSMITS = 1 where R_MAX_ERRORS is null
;
blog2_exec_no_error ('create index SYS_ROUTING_ITEM on SYS_ROUTING (R_ITEM_ID, R_DESTINATION_ID, R_TYPE_ID)');
blog2_exec_no_error ('create table SYS_BLOGS_ROUTING_LOG
(
RL_JOB_ID int,
RL_POST_ID varchar,
RL_F_POST_ID varchar,
RL_TYPE varchar,
RL_PROCESSED int default 0,
RL_COMMENT_ID integer default -1,
RL_ERROR long varchar,
RL_TS timestamp,
RL_RETRANSMITS int default 1,
primary key (RL_JOB_ID, RL_POST_ID, RL_COMMENT_ID)
)')
;
blog2_add_col('BLOG.DBA.SYS_BLOGS_ROUTING_LOG', 'RL_TS', 'timestamp')
;
blog2_add_col('BLOG.DBA.SYS_BLOGS_ROUTING_LOG', 'RL_RETRANSMITS', 'int default 1')
;
UPDATE SYS_BLOGS_ROUTING_LOG set RL_COMMENT_ID = -1 where RL_COMMENT_ID is NULL
;
UPDATE SYS_BLOGS_ROUTING_LOG set RL_RETRANSMITS = 1 where RL_RETRANSMITS is null and RL_PROCESSED <> 2
;
UPDATE SYS_BLOGS_ROUTING_LOG set RL_RETRANSMITS = 0 where RL_RETRANSMITS is null and RL_PROCESSED = 2
;
-- Routing Type Table Structure:
blog2_exec_no_error ('create table SYS_ROUTING_TYPE
(
RT_ID int primary key,
RT_NAME varchar,
RT_TYPE_DESCRIPTION varchar
)')
;
insert soft SYS_ROUTING_TYPE (RT_ID, RT_NAME, RT_TYPE_DESCRIPTION) values (1, 'Upstream', 'Web Log Upstream')
;
insert soft SYS_ROUTING_TYPE (RT_ID, RT_NAME, RT_TYPE_DESCRIPTION) values (2, 'E-mail', 'E-mail notification')
;
insert soft SYS_ROUTING_TYPE (RT_ID, RT_NAME, RT_TYPE_DESCRIPTION) values (3, 'del.icio.us', 'del.icio.us notification')
;
insert soft SYS_ROUTING_TYPE (RT_ID, RT_NAME, RT_TYPE_DESCRIPTION) values (4, 'Ping', 'Weblog ping')
;
-- Routing Procotol Table Structure:
blog2_exec_no_error ('create table SYS_ROUTING_PROTOCOL
(
RP_ID int primary key,
RP_NAME varchar,
RP_INVOCATION_SIGNATURE varchar
)')
;
insert soft SYS_ROUTING_PROTOCOL (RP_ID, RP_NAME, RP_INVOCATION_SIGNATURE)
values (1,'Blogger','')
;
insert soft SYS_ROUTING_PROTOCOL (RP_ID, RP_NAME, RP_INVOCATION_SIGNATURE)
values (2,'MetaWeblog','')
;
insert soft SYS_ROUTING_PROTOCOL (RP_ID, RP_NAME, RP_INVOCATION_SIGNATURE)
values (3,'MoveableType','')
;
insert soft SYS_ROUTING_PROTOCOL (RP_ID, RP_NAME, RP_INVOCATION_SIGNATURE)
values (4,'SMTP','')
;
insert soft SYS_ROUTING_PROTOCOL (RP_ID, RP_NAME, RP_INVOCATION_SIGNATURE)
values (5,'Atom','')
;
insert soft SYS_ROUTING_PROTOCOL (RP_ID, RP_NAME, RP_INVOCATION_SIGNATURE)
values (6,'REST','')
;
insert soft SYS_ROUTING_PROTOCOL (RP_ID, RP_NAME, RP_INVOCATION_SIGNATURE)
values (7,'XML-RPC','')
;
-- WEBLOG PING
blog2_exec_no_error ('create table SYS_WEBLOG_UPDATES_PINGS
(
WU_NAME varchar,
WU_URL varchar,
WU_TS datetime,
WU_IP varchar,
WU_CHANGES_URL varchar,
WU_RSS varchar,
primary key (WU_URL)
)')
;
blog2_add_col('BLOG.DBA.SYS_WEBLOG_UPDATES_PINGS', 'WU_CHANGES_URL', 'varchar')
;
blog2_add_col('BLOG.DBA.SYS_WEBLOG_UPDATES_PINGS', 'WU_RSS', 'varchar')
;
blog2_exec_no_error ('create index SYS_WEBLOG_UPDATES_PINGS_TS on SYS_WEBLOG_UPDATES_PINGS (WU_TS)')
;
blog2_exec_no_error ('create table SYS_BLOG_CONTACTS
(
BF_ID integer identity,
BF_BLOG_ID varchar,
BF_NAME varchar,
BF_FAMILY_NAME varchar,
BF_PHONE varchar,
BF_YAHOO_CHAT_ID varchar,
BF_MSN_CHAT_ID varchar,
BF_NICK varchar,
BF_FIRST_NAME varchar,
BF_TITLE varchar,
BF_MBOX varchar,
BF_WORKPLACE_HOMEPAGE varchar,
BF_ICQ_CHAT_ID varchar,
BF_SURNAME varchar,
BF_HOMEPAGE varchar,
BF_WEBLOG varchar,
BF_RSS varchar,
BF_WORKINFO_HOMEPAGE varchar,
primary key (BF_BLOG_ID, BF_ID)
)')
;
blog2_exec_no_error ('create table SYS_BLOG_WEBLOG_HOSTS
(
WH_URL varchar,
WH_NAME varchar,
WH_PROTO varchar,
WH_ID integer identity,
WH_METHOD varchar default \'weblogUpdates.ping\',
primary key (WH_URL, WH_PROTO, WH_METHOD)
)')
;
blog2_add_col('BLOG.DBA.SYS_BLOG_WEBLOG_HOSTS', 'WH_METHOD', 'varchar default \'weblogUpdates.ping\'');
blog2_exec_no_error ('create table SYS_BLOG_WEBLOG_PING
(
WP_URL varchar,
WP_BLOG_ID varchar,
WP_HOSTS_ID int references SYS_BLOG_WEBLOG_HOSTS (WH_ID) on update cascade on delete cascade,
primary key (WP_BLOG_ID, WP_HOSTS_ID)
)')
;
blog2_add_col('BLOG.DBA.SYS_BLOG_WEBLOG_PING', 'WP_HOSTS_ID', 'int');
blog2_exec_no_error ('
create table BLOG_WEBLOG_PING_LOG
(
WPL_JOB_ID int references SYS_ROUTING (R_JOB_ID) on delete cascade,
WPL_HOSTS_ID int references SYS_BLOG_WEBLOG_HOSTS (WH_ID) on update cascade on delete cascade,
WPL_STAT int default 0, -- 1 sent, 2 error, 0 pending
WPL_TS timestamp,
WPL_SENT datetime,
WPL_ERROR long varchar,
primary key (WPL_TS, WPL_JOB_ID, WPL_HOSTS_ID)
)')
;
blog2_exec_no_error ('create index BLOG_WEBLOG_PING_LOG_STAT on BLOG_WEBLOG_PING_LOG (WPL_JOB_ID, WPL_HOSTS_ID, WPL_STAT)');
create procedure BLOG_WEBLOG_PING_UPGRADE ()
{
declare jid int;
declare last datetime;
if (registry_get ('__BLOG_WEBLOG_PING_UPGRADE_done') = 'done2')
return;
last := registry_get ('blogger.last.ping');
set triggers off;
for select WH_URL, WH_PROTO, WH_METHOD, WAI_ID, WAI_NAME
from SYS_BLOG_WEBLOG_PING, SYS_BLOG_WEBLOG_HOSTS, SYS_BLOG_INFO, DB.DBA.WA_INSTANCE
where WP_HOSTS_ID = WH_ID and WP_BLOG_ID = BI_BLOG_ID and WAI_NAME = BI_WAI_NAME do
{
declare s_id int;
s_id := (select SH_ID from ODS..SVC_HOST where SH_URL = WH_URL and SH_PROTO = WH_PROTO and SH_METHOD = WH_METHOD);
if (s_id is not null)
insert soft ODS..APP_PING_REG (AP_HOST_ID, AP_WAI_ID) values (s_id, WAI_ID);
else
log_message (sprintf ('Can''t upgrade reference of %s to %s %s', WAI_NAME, WH_URL, WH_PROTO));
}
for select distinct BI_WAI_NAME from BLOG_WEBLOG_PING_LOG, SYS_BLOG_INFO, SYS_ROUTING, SYS_BLOG_WEBLOG_PING
where WPL_STAT = 0 and WP_BLOG_ID = BI_BLOG_ID and WPL_JOB_ID = R_JOB_ID
and WPL_HOSTS_ID = WP_HOSTS_ID and R_ITEM_ID = WP_BLOG_ID and R_TYPE_ID = 4
do
{
ODS..APP_PING (BI_WAI_NAME);
}
delete from SYS_ROUTING where R_TYPE_ID = 4;
delete from SYS_BLOG_WEBLOG_PING;
delete from BLOG_WEBLOG_PING_LOG;
blog2_exec_no_error ('drop trigger SYS_BLOG_WEBLOG_PING_I');
blog2_exec_no_error ('drop trigger SYS_BLOG_WEBLOG_PING_D');
set triggers on;
registry_set ('__BLOG_WEBLOG_PING_UPGRADE_done', 'done2');
}
;
BLOG_WEBLOG_PING_UPGRADE ();
blog2_exec_no_error ('create unique index SYS_BLOG_WEBLOG_HOSTS_ID on SYS_BLOG_WEBLOG_HOSTS (WH_ID)');
insert soft SYS_BLOG_WEBLOG_HOSTS (WH_URL, WH_NAME, WH_PROTO) values ('', 'disabled', '');
insert soft SYS_BLOG_WEBLOG_HOSTS (WH_URL, WH_NAME, WH_PROTO) values ('http://rpc.weblogs.com/RPC2', 'Weblog.com', 'xml-rpc');
insert soft SYS_BLOG_WEBLOG_HOSTS (WH_URL, WH_NAME, WH_PROTO) values ('http://rpc.weblogs.com/weblogUpdates', 'Weblog.com', 'soap');
insert soft SYS_BLOG_WEBLOG_HOSTS (WH_URL, WH_NAME, WH_PROTO) values ('http://ping.blo.gs/', 'blo.gs', 'xml-rpc');
insert soft SYS_BLOG_WEBLOG_HOSTS (WH_URL, WH_NAME, WH_PROTO) values ('http://rpc.technorati.com/rpc/ping', 'technorati', 'xml-rpc');
insert soft SYS_BLOG_WEBLOG_HOSTS (WH_URL, WH_NAME, WH_PROTO) values ('http://ping.rootblog.com/rpc.php', 'RootBlog', 'xml-rpc');
insert soft SYS_BLOG_WEBLOG_HOSTS (WH_URL, WH_NAME, WH_PROTO) values ('http://rpc.blogrolling.com/pinger/', 'blogrolling', 'xml-rpc')
;
insert soft SYS_BLOG_WEBLOG_HOSTS (WH_URL, WH_NAME, WH_PROTO) values ('http://www.blogshares.com/rpc.php', 'blogshares', 'xml-rpc');
insert soft SYS_BLOG_WEBLOG_HOSTS (WH_URL, WH_NAME, WH_PROTO) values ('http://api.my.yahoo.com/RPC2', 'My Yahoo', 'xml-rpc');
insert soft SYS_BLOG_WEBLOG_HOSTS (WH_URL, WH_NAME, WH_PROTO) values ('http://api.moreover.com/RPC2', 'Moreover', 'xml-rpc');
insert soft SYS_BLOG_WEBLOG_HOSTS (WH_URL, WH_NAME, WH_PROTO, WH_METHOD) values ('http://rpc.weblogs.com/RPC2', 'Weblog.com (extended)', 'xml-rpc', 'weblogUpdates.extendedPing');
insert soft SYS_BLOG_WEBLOG_HOSTS (WH_URL, WH_NAME, WH_PROTO, WH_METHOD) values ('http://geourl.org/ping/?p=', 'GeoURL', 'REST', 'ping');
blog2_exec_no_error ('create table SYS_BLOG_SEARCH_ENGINE (
SE_NAME varchar,
SE_HOOK varchar,
primary key (SE_NAME)
)')
;
insert soft SYS_BLOG_SEARCH_ENGINE (SE_NAME, SE_HOOK) values ('Google', 'BLOG.DBA.BLOG_SEARCH_GOOGLE')
;
insert soft SYS_BLOG_SEARCH_ENGINE (SE_NAME, SE_HOOK) values ('Amazon', 'BLOG.DBA.BLOG_SEARCH_AMAZON')
;
blog2_exec_no_error ('create table SYS_BLOG_SEARCH_ENGINE_SETTINGS (
SS_NAME varchar references SYS_BLOG_SEARCH_ENGINE on update cascade on delete cascade,
SS_BLOG_ID varchar,
SS_KEY varchar,
SS_MAX_ROWS int,
primary key (SS_NAME, SS_BLOG_ID)
)');
;
blog2_exec_no_error ('create table BLOG_TAG (
BT_BLOG_ID varchar,
BT_POST_ID varchar,
BT_ID integer identity,
BT_TAGS varchar,
primary key (BT_BLOG_ID, BT_POST_ID))');
blog2_exec_no_error ('create index BLOG_TAG_POST_ID on BLOG..BLOG_TAG (BT_POST_ID)');
create procedure BLOG.DBA.BLOG_TAG_BT_TAGS_INDEX_HOOK (inout vtb any, inout d_id integer)
{
declare tags, blogid, postid, tarr, data any;
declare exit handler for not found { return 0; };
--dbg_printf ('BLOG.DBA.BLOG_TAG_BT_TAGS_INDEX_HOOK');
select BT_TAGS, BT_BLOG_ID, BT_POST_ID into tags, blogid, postid from BLOG_TAG where BT_ID = d_id;
tarr := split_and_decode (tags, 0, '\0\0,');
foreach (any elm in tarr) do
{
elm := trim(elm);
elm := replace (elm, ' ', '_');
vt_batch_feed (vtb, elm, 0);
}
vt_batch_feed (vtb, 'b'||replace (blogid, '-','_'), 0);
vt_batch_feed_offband (vtb, serialize (vector (blogid, postid)), 0);
return 1;
}
;
create procedure BLOG.DBA.BLOG_TAG_BT_TAGS_UNINDEX_HOOK (inout vtb any, inout d_id integer)
{
declare tags, blogid, postid, tarr, data any;
declare exit handler for not found { return 0; };
--dbg_printf ('BLOG.DBA.BLOG_TAG_BT_TAGS_UNINDEX_HOOK');
select BT_TAGS, BT_BLOG_ID, BT_POST_ID into tags, blogid, postid from BLOG_TAG where BT_ID = d_id;
tarr := split_and_decode (tags, 0, '\0\0,');
foreach (any elm in tarr) do
{
elm := trim(elm);
elm := replace (elm, ' ', '_');
vt_batch_feed (vtb, elm, 1);
}
vt_batch_feed (vtb, 'b'||replace (blogid, '-','_'), 1);
vt_batch_feed_offband (vtb, serialize (vector (blogid, postid)), 1);
return 1;
}
;
blog2_exec_no_error ('CREATE TEXT INDEX ON BLOG_TAG (BT_TAGS) WITH KEY BT_ID
CLUSTERED WITH (BT_BLOG_ID, BT_POST_ID) USING FUNCTION LANGUAGE \'x-ViDoc\'');
blog2_exec_no_error(
'create table SYS_BLOG_ATTACHES (
BA_M_BLOG_ID varchar references SYS_BLOG_INFO,
BA_C_BLOG_ID varchar references SYS_BLOG_INFO,
BA_FLAG varchar,
primary key (BA_M_BLOG_ID, BA_C_BLOG_ID))'
)
;
blog2_add_col('BLOG.DBA.SYS_BLOG_ATTACHES', 'BA_LAST_UPDATE', 'timestamp')
;
create trigger SYS_BLOG_ATTACHES_D after delete on SYS_BLOG_ATTACHES referencing old as O
{
if (not exists (select 1 from SYS_BLOG_ATTACHES where BA_M_BLOG_ID = O.BA_M_BLOG_ID))
update SYS_BLOG_INFO set BI_HAVE_COMUNITY_BLOG = 0 where BI_BLOG_ID = O.BA_M_BLOG_ID;
}
;
create procedure BLOG_GET_TAGS (in blogid any, in postid any)
{
declare ret any;
ret := (select BT_TAGS from BLOG_TAG where BT_BLOG_ID = blogid and BT_POST_ID = postid);
return coalesce (ret, '');
};
create procedure BLOG_TAGS_STAT (in blogid any)
{
declare tag varchar;
declare post_id int;
declare arr any;
result_names (post_id, tag);
for select BT_TAGS, BT_POST_ID from BLOG_TAG where BT_BLOG_ID = blogid do
{
arr := split_and_decode (BT_TAGS, 0, '\0\0,');
foreach (any elm in arr) do
{
declare tmp any;
tmp := trim (elm, ' ,');
if (length (tmp))
result (BT_POST_ID, tmp);
}
}
}
;
grant execute on BLOG.DBA.BLOG_TAGS_STAT to SPARQL_SELECT
;
blog2_exec_no_error ('create procedure view BLOG_TAGS_STAT as BLOG.DBA.BLOG_TAGS_STAT (blogid) (BT_POST_ID varchar, BT_TAG varchar)');
create procedure BLOG_TAGS_STAT_EXT (in blogid any, in community int)
{
declare tag varchar;
declare post_id int;
declare arr any;
result_names (post_id, tag);
if (community)
{
for select BT_TAGS, BT_POST_ID from BLOG_TAG, (select BI_BLOG_ID as BA_C_BLOG_ID, BI_BLOG_ID as BA_M_BLOG_ID from BLOG..SYS_BLOG_INFO where BI_BLOG_ID = blogid union all select * from (select BA_C_BLOG_ID, BA_M_BLOG_ID from BLOG.DBA.SYS_BLOG_ATTACHES where BA_M_BLOG_ID = blogid) name1) name2 where BT_BLOG_ID = BA_C_BLOG_ID do
{
arr := split_and_decode (BT_TAGS, 0, '\0\0,');
foreach (any elm in arr) do
{
result (BT_POST_ID, trim (elm, ' ,\t'));
}
}
}
else
{
for select BT_TAGS, BT_POST_ID from BLOG_TAG where BT_BLOG_ID = blogid do
{
arr := split_and_decode (BT_TAGS, 0, '\0\0,');
foreach (any elm in arr) do
{
result (BT_POST_ID, trim (elm, ' ,\t'));
}
}
}
}
;
blog2_exec_no_error ('create procedure view BLOG_TAGS_STAT_EXT as BLOG.DBA.BLOG_TAGS_STAT_EXT (blogid, community) (BT_POST_ID varchar, BT_TAG varchar)');
create procedure BLOG_POST_TAGS_STAT (in postid any)
{
declare tag varchar;
declare post_id int;
declare arr any;
result_names (tag);
for select BT_TAGS from BLOG_TAG where BT_POST_ID = postid do
{
arr := split_and_decode (BT_TAGS, 0, '\0\0,');
foreach (any elm in arr) do
{
result (trim (elm, ' ,'));
}
}
}
;
blog2_exec_no_error ('create procedure view BLOG_POST_TAGS_STAT as BLOG.DBA.BLOG_POST_TAGS_STAT (postid) (BT_TAG varchar)');
create procedure BLOG_POST_TAGS_STAT_2 (in postid any, in blogid any)
{
declare tag varchar;
declare post_id int;
declare arr any;
result_names (tag);
for select BT_TAGS from BLOG_TAG where BT_BLOG_ID = blogid and BT_POST_ID = postid do
{
arr := split_and_decode (BT_TAGS, 0, '\0\0,');
foreach (any elm in arr) do
{
result (trim (elm, ' ,'));
}
}
}
;
blog2_exec_no_error ('create procedure view BLOG_POST_TAGS_STAT_2 as BLOG.DBA.BLOG_POST_TAGS_STAT_2 (postid, blogid) (BT_TAG varchar)');
-- NNTP support functions
create procedure blog_wide2utf (inout str any)
{
if (iswidestring (str))
return charset_recode (str, '_WIDE_', 'UTF-8' );
return str;
}
;
create procedure blog_utf2wide (inout str any)
{
if (isstring (str))
return charset_recode (str, 'UTF-8', '_WIDE_');
return str;
}
;
create procedure decode_nntp_subj (inout str varchar)
{
declare match varchar;
declare inx int;
inx := 50;
str := replace (str, '\t', '');
match := regexp_match ('=\\?[^\\?]+\\?[A-Z]\\?[^\\?]+\\?=', str);
while (match is not null and inx > 0)
{
declare enc, ty, dat, tmp, cp, dec any;
cp := match;
tmp := regexp_match ('^=\\?[^\\?]+\\?[A-Z]\\?', match);
match := substring (match, length (tmp)+1, length (match) - length (tmp) - 2);
enc := regexp_match ('=\\?[^\\?]+\\?', tmp);
tmp := replace (tmp, enc, '');
enc := trim (enc, '?=');
ty := trim (tmp, '?');
if (ty = 'B')
{
dec := decode_base64 (match);
}
else if (ty = 'Q')
{
dec := uudecode (match, 12);
}
else
{
dec := '';
}
declare exit handler for sqlstate '2C000'
{
return;
};
dec := charset_recode (dec, enc, 'UTF-8');
str := replace (str, cp, dec);
--dbg_printf ('encoded=[%s] enc=[%s] type=[%s] decoded=[%s]', match, enc, ty, dec);
match := regexp_match ('=\\?[^\\?]+\\?[A-Z]\\?[^\\?]+\\?=', str);
inx := inx - 1;
}
};
create procedure SPLIT_MAIL_ADDR (in author any, out person any, out email any)
{
declare pos int;
person := '';
pos := strchr (author, '<');
if (pos is not NULL)
{
person := "LEFT" (author, pos);
email := subseq (author, pos, length (author));
email := replace (email, '<', '');
email := replace (email, '>', '');
person := trim (replace (person, '"', ''));
--email := replace (email, '{at}', '@');
}
else
{
pos := strchr (author, '(');
if (pos is not NULL)
{
email := trim ("LEFT" (author, pos));
person := subseq (author, pos, length (author));
person := replace (person, '(', '');
person := replace (person, ')', '');
}
}
}
;
create procedure BLOG..MAKE_RFC_ID (in postid varchar, in commid int := null)
{
declare ret, _hash, host any;
_hash := md5(registry_get ('WeblogServerID'));
host := sys_stat ('st_host_name');
if (commid is null)
ret := sprintf ('<%s.%s@%s>', postid, _hash, host);
else
ret := sprintf ('<%s.%d.%s@%s>', postid, commid, _hash, host);
return ret;
}
;
create procedure BLOG_MAKE_MAIL_SUBJECT (in txt any, in id varchar := null)
{
declare enc any;
enc := encode_base64 (blog_wide2utf (txt));
enc := replace (enc, '\r\n', '');
txt := concat ('Subject: =?UTF-8?B?', enc, '?=\r\n');
if (id is not null)
txt := concat (txt, 'X-Virt-BlogID: ', registry_get ('WeblogServerID'), ';', id, '\r\n');
return txt;
}
;
create procedure MAKE_POST_RFC_HEADER (in mid varchar, in refs varchar, in gid varchar,
in title varchar, in rec datetime, in author_mail varchar)
{
declare ses any;
ses := string_output ();
-- dbg_obj_print ('mid=',mid,' refs=',refs,' gid=',gid, ' title=', title, ' rec=', rec, ' author_mail=', author_mail);
http (BLOG_MAKE_MAIL_SUBJECT (title), ses);
http (sprintf ('Date: %s\r\n', DB.DBA.date_rfc1123 (rec)), ses);
http (sprintf ('Message-Id: %s\r\n', mid), ses);
if (refs is not null)
http (sprintf ('References: %s\r\n', refs), ses);
http (sprintf ('From: %s\r\n', author_mail), ses);
http ('Content-Type: text/html; charset=UTF-8\r\n', ses);
http (sprintf ('Newsgroups: %s\r\n\r\n', gid), ses);
ses := string_output_string (ses);
return ses;
};
create procedure BLOG_NEWS_UPGRADE ()
{
if (registry_get ('__BLOG_NEWS_UPGRADE_done') = 'done')
return;
declare mid, rfc_head any;
for select B_BLOG_ID as bid, B_POST_ID as id, B_TITLE as title, B_TS as post_date, U_E_MAIL as author
from SYS_BLOGS, DB.DBA.SYS_USERS
where B_USER_ID = U_ID do
{
mid := BLOG..MAKE_RFC_ID (id);
rfc_head := MAKE_POST_RFC_HEADER (mid, null, bid, title, post_date, author);
set triggers off;
update SYS_BLOGS set B_RFC_ID = mid, B_RFC_HEADER = rfc_head where B_BLOG_ID = bid and B_POST_ID = id;
set triggers on;
}
update BLOG_COMMENTS set BM_BLOG_ID = (select B_BLOG_ID from SYS_BLOGS where B_POST_ID = BM_POST_ID)
where not exists (select 1 from SYS_BLOGS where B_BLOG_ID = BM_BLOG_ID and B_POST_ID = BM_POST_ID);
for select B_TITLE as title, B_POST_ID as pid, BM_ID as id, B_RFC_ID as refs,
B_BLOG_ID as bid, BM_TS as post_date, BM_E_MAIL as author
from BLOG_COMMENTS, SYS_BLOGS where B_BLOG_ID = BM_BLOG_ID and B_POST_ID = BM_POST_ID do
{
title := 'Re:' || title;
mid := BLOG..MAKE_RFC_ID (pid, id);
rfc_head := MAKE_POST_RFC_HEADER (mid, refs, bid, title, post_date, author);
set triggers off;
update BLOG_COMMENTS set BM_RFC_ID = mid, BM_RFC_HEADER = rfc_head, BM_TITLE = title
where BM_BLOG_ID = bid and BM_POST_ID = pid and BM_ID = id;
set triggers on;
}
set triggers off;
update SYS_BLOG_INFO set BI_SHOW_AS_NEWS = 0;
set triggers on;
registry_set ('__BLOG_NEWS_UPGRADE_done', 'done');
};
BLOG_NEWS_UPGRADE ()
;
create procedure BLOG_VER_UPGRADE ()
{
if (registry_get ('__BLOG_VER_UPGRADE_done') = 'done')
return;
set triggers off;
update SYS_BLOGS set B_VER = 1 where B_VER is null;
set triggers on;
registry_set ('__BLOG_VER_UPGRADE_done', 'done');
};
BLOG_VER_UPGRADE ();
create procedure BLOG_ADD_LINKS (in blogid varchar, in postid varchar, inout content any)
{
declare xt, xp any;
declare tit, href, cls any;
declare me, blog_iri, _inst varchar;
delete from BLOG_POST_LINKS where PL_BLOG_ID = blogid and PL_POST_ID = postid;
if (content is null)
return;
else if (isentity (content))
xt := content;
else
xt := xtree_doc (content, 2, '', 'UTF-8');
xp := xpath_eval ('//a[starts-with (@href,"http") and not(img)]', xt, 0);
foreach (any elm in xp) do
{
tit := cast (xpath_eval ('string()', elm) as varchar);
href := cast (xpath_eval ('@href', elm) as varchar);
cls := cast (xpath_eval ('@class', elm) as varchar);
insert soft BLOG_POST_LINKS (PL_BLOG_ID,PL_POST_ID,PL_LINK,PL_TITLE, PL_PING) values (blogid,postid,href,tit,
case when cls = 'auto-href' then 1 else 0 end);
}
xp := xpath_eval ('//a[starts-with (@href,"http") and not(img) and @class = "auto-href"]', xt, 0);
me := sioc..blog_post_iri (blogid, postid);
_inst := (select BI_WAI_NAME from BLOG..SYS_BLOG_INFO where BI_BLOG_ID = blogid);
blog_iri := sioc..blog_iri (_inst);
-- do this conditionally
if (exists (select 1 from SEMPING..PING_RULES where PR_IRI = blog_iri))
{
foreach (any elm in xp) do
{
href := cast (xpath_eval ('@href', elm) as varchar);
SEMPING..CLI_PING (me, href);
}
}
};
create procedure BLOG_LINKS_UPGRADE ()
{
if (registry_get ('__BLOG_LINK_UPGRADE_done') = 'done')
return;
for select B_BLOG_ID, B_POST_ID, B_CONTENT from BLOG..SYS_BLOGS do
{
BLOG_ADD_LINKS (B_BLOG_ID, B_POST_ID, B_CONTENT);
}
registry_set ('__BLOG_LINK_UPGRADE_done', 'done');
};
BLOG_LINKS_UPGRADE ();
create procedure BLOG_ADD_COMMENT_LINKS (in blogid varchar, in postid varchar, in cid int, inout content any)
{
declare xt, xp any;
declare tit, href, cls any;
declare me, blog_iri, _inst varchar;
delete from BLOG_COMMENT_LINKS where CL_BLOG_ID = blogid and CL_POST_ID = postid and CL_CID = cid;
if (content is null)
return;
else if (isentity (content))
xt := content;
else
xt := xtree_doc (content, 2, '', 'UTF-8');
xp := xpath_eval ('//a[starts-with (@href,"http") and not(img)]', xt, 0);
foreach (any elm in xp) do
{
tit := cast (xpath_eval ('string()', elm) as varchar);
href := cast (xpath_eval ('@href', elm) as varchar);
cls := cast (xpath_eval ('@class', elm) as varchar);
insert soft BLOG_COMMENT_LINKS (CL_BLOG_ID,CL_POST_ID, CL_CID, CL_LINK,CL_TITLE, CL_PING) values (blogid,postid,cid,href,tit,
case when cls = 'auto-href' then 1 else 0 end);
}
xp := xpath_eval ('//a[starts-with (@href,"http") and not(img) and @class = "auto-href"]', xt, 0);
me := sioc..blog_comment_iri (blogid, postid, cid);
_inst := (select BI_WAI_NAME from BLOG..SYS_BLOG_INFO where BI_BLOG_ID = blogid);
blog_iri := sioc..blog_iri (_inst);
-- do this conditionally
if (0 and exists (select 1 from SEMPING..PING_RULES where PR_IRI = blog_iri))
{
foreach (any elm in xp) do
{
href := cast (xpath_eval ('@href', elm) as varchar);
SEMPING..CLI_PING (me, href);
}
}
};
create procedure BLOG_ENCL_UPGRADE ()
{
if (registry_get ('__BLOG_ENCL_UPGRADE_done') = 'done')
return;
for select B_BLOG_ID, B_POST_ID, B_CONTENT, B_META, B_HAVE_ENCLOSURE from BLOG..SYS_BLOGS do
{
declare meta BLOG.DBA."MWeblogPost";
declare enc BLOG.DBA."MWeblogEnclosure";
if (B_HAVE_ENCLOSURE = 1)
{
meta := B_META;
enc := meta.enclosure;
if (length (enc."url"))
{
insert into BLOG_POST_ENCLOSURES (PE_BLOG_ID, PE_POST_ID, PE_URL, PE_TYPE, PE_LEN)
values (B_BLOG_ID, B_POST_ID, enc."url", enc."type", enc."length");
}
}
}
registry_set ('__BLOG_ENCL_UPGRADE_done', 'done');
};
BLOG_ENCL_UPGRADE ();
-- TRIGGERS
create trigger BLOG_COMMENTS_I after insert on MTYPE_TRACKBACK_PINGS referencing new as N
{
declare opts, appr, ratelim, rate, owner, id, postid, blogid any;
declare is_spam, published int;
postid := N.MP_POST_ID;
id := N.MP_ID;
select deserialize (blob_to_string (BI_OPTIONS)), BI_OWNER, BI_BLOG_ID into opts, owner, blogid
from BLOG..SYS_BLOG_INFO, BLOG..SYS_BLOGS
where BI_BLOG_ID = B_BLOG_ID and B_POST_ID = postid;
if (not isarray (opts))
opts := vector ();
appr := get_keyword ('CommentApproval', opts, 0);
ratelim := get_keyword ('SpamRateLimit', opts, '1.00');
rate := DB.DBA.spam_filter_message (N.MP_TITLE||' '||N.MP_EXCERPT, owner);
is_spam := gte (rate,ratelim);
published := equ (appr, 0);
if (is_spam or appr = 1)
{
published := 0;
goto skip;
}
update SYS_BLOGS set B_TRACKBACK_NO = B_TRACKBACK_NO + 1 where B_POST_ID = N.MP_POST_ID;
skip:
set triggers off;
update BLOG..MTYPE_TRACKBACK_PINGS set MP_IS_PUB = published, MP_IS_SPAM = is_spam
where MP_POST_ID = postid and MP_ID = id;
set triggers on;
return;
}
;
create trigger BLOG_COMMENTS_U after update on MTYPE_TRACKBACK_PINGS referencing old as O, new as N
{
if (N.MP_IS_PUB = 1 and O.MP_IS_PUB = 0)
update SYS_BLOGS set B_TRACKBACK_NO = B_TRACKBACK_NO + 1 where B_POST_ID = N.MP_POST_ID;
}
;
create trigger BLOG_COMMENTS_D after delete on MTYPE_TRACKBACK_PINGS
{
if (MP_IS_PUB = 1)
update SYS_BLOGS set B_TRACKBACK_NO = B_TRACKBACK_NO - 1 where B_POST_ID = MP_POST_ID;
}
;
create trigger BLOG_COMMENTS_NO_I after insert on BLOG_COMMENTS referencing new as N
{
declare opts, appr, ratelim, rate, owner, id, postid, blogid, domain, home, title, orgblogid any;
declare is_spam, published int;
declare mid, rfc, refs, comment_title varchar;
declare oid_sig, oid_is_valid int;
declare post_iri, body varchar;
blogid := N.BM_BLOG_ID;
postid := N.BM_POST_ID;
id := N.BM_ID;
oid_is_valid := 0;
if (N.BM_RFC_ID is null)
mid := BLOG..MAKE_RFC_ID (N.BM_POST_ID, N.BM_ID);
else
mid := N.BM_RFC_ID;
whenever not found goto ret;
select deserialize (blob_to_string (BI_OPTIONS)), BI_OWNER, BI_HOME, B_TITLE, BI_BLOG_ID, B_RFC_ID
into opts, owner, home, title, orgblogid, refs from BLOG..SYS_BLOG_INFO, BLOG..SYS_BLOGS
where B_POST_ID = N.BM_POST_ID and B_BLOG_ID = BI_BLOG_ID;
body := BLOG.DBA.CONTENT_ANNOTATE (owner, N.BM_COMMENT);
BLOG_ADD_COMMENT_LINKS (orgblogid, postid, id, body);
comment_title := 'Re:' || title;
if (N.BM_REF_ID)
{
declare p_id, p_refs any;
declare exit handler for not found;
select BM_RFC_ID, BM_RFC_REFERENCES into p_id, p_refs from BLOG..BLOG_COMMENTS
where BM_BLOG_ID = orgblogid and BM_POST_ID = N.BM_POST_ID and BM_ID = N.BM_REF_ID;
if (p_refs is null)
p_refs := refs;
refs := p_refs || ' ' || p_id;
}
if (N.BM_RFC_HEADER is null)
rfc := MAKE_POST_RFC_HEADER (mid, refs, orgblogid, comment_title, N.BM_TS, N.BM_E_MAIL);
else
rfc := N.BM_RFC_HEADER;
domain := null;
whenever not found goto nfc;
select top 1 BM_POSTED_VIA into domain from BLOG_COMMENTS where BM_BLOG_ID = orgblogid and BM_POST_ID = postid
and BM_POSTED_VIA is not null order by BM_ID;
nfc:
if (domain is null and is_http_ctx ())
{
declare lines any;
lines := http_request_header ();
if (isarray (lines))
domain := http_request_header (lines, 'Host', null, null);
}
if (N.BM_OWN_COMMENT = 1)
{
is_spam := 0;
published := 1;
appr := 0;
goto own_comm;
}
if (not isarray (opts))
opts := vector ();
appr := get_keyword ('CommentApproval', opts, 0);
oid_sig := get_keyword ('OpenID', opts, 0);
ratelim := get_keyword ('SpamRateLimit', opts, '1.00');
if (oid_sig and length (N.BM_OPENID_SIG))
oid_is_valid := OPENID..check_signature (N.BM_OPENID_SIG);
if (not oid_is_valid)
{
rate := DB.DBA.spam_filter_message (N.BM_COMMENT, owner);
is_spam := gte (rate,ratelim);
published := equ (appr, 0);
}
else
{
is_spam := 0;
published := 1;
appr := 0;
}
if (is_spam or appr = 1)
{
published := 0;
goto skip;
}
own_comm:;
set triggers off;
update SYS_BLOGS set B_COMMENTS_NO = B_COMMENTS_NO + 1 where B_POST_ID = N.BM_POST_ID;
post_iri := sioc..blog_comment_iri (orgblogid, postid, N.BM_ID);
update BLOG.DBA.SYS_BLOG_INFO
set BI_LAST_UPDATE = now (),
BI_DASHBOARD = make_dasboard_item ('comment', N.BM_TS, title, N.BM_NAME, post_iri, N.BM_COMMENT, BI_DASHBOARD, N.BM_ID, 'insert', null, N.BM_E_MAIL)
where BI_BLOG_ID = orgblogid;
set triggers on;
for select R_JOB_ID from SYS_ROUTING where R_ITEM_ID = orgblogid and R_TYPE_ID in (1,2) do
{
insert into SYS_BLOGS_ROUTING_LOG (RL_JOB_ID, RL_POST_ID, RL_TYPE, RL_COMMENT_ID)
values (R_JOB_ID, N.BM_POST_ID, 'CI', N.BM_ID);
}
skip:
set triggers off;
update BLOG..BLOG_COMMENTS set BM_IS_PUB = published, BM_IS_SPAM = is_spam, BM_POSTED_VIA = domain, BM_BLOG_ID = orgblogid,
BM_RFC_ID = mid, BM_RFC_HEADER = rfc, BM_TITLE = comment_title, BM_RFC_REFERENCES = refs, BM_COMMENT = body
where BM_BLOG_ID = blogid and BM_POST_ID = postid and BM_ID = id;
set triggers on;
ret:
return;
}
;
create trigger BLOG_COMMENTS_NO_U after update on BLOG_COMMENTS referencing old as O, new as N
{
declare home, title varchar;
declare post_iri varchar;
if (N.BM_IS_PUB = 1)
{
select BI_HOME, B_TITLE into home, title from BLOG..SYS_BLOG_INFO, BLOG..SYS_BLOGS where
B_BLOG_ID = BI_BLOG_ID and B_POST_ID = N.BM_POST_ID and BI_BLOG_ID = N.BM_BLOG_ID;
set triggers off;
if (O.BM_IS_PUB = 0)
{
update SYS_BLOGS set B_COMMENTS_NO = B_COMMENTS_NO + 1 where B_POST_ID = N.BM_POST_ID;
}
post_iri := sioc..blog_comment_iri (N.BM_BLOG_ID, N.BM_POST_ID, N.BM_ID);
update BLOG.DBA.SYS_BLOG_INFO
set BI_LAST_UPDATE = now (),
BI_DASHBOARD = make_dasboard_item ('comment', N.BM_TS, title, N.BM_NAME, post_iri, N.BM_COMMENT, BI_DASHBOARD, N.BM_ID, 'insert', null, N.BM_E_MAIL)
where BI_BLOG_ID = N.BM_BLOG_ID;
set triggers on;
for select R_JOB_ID from SYS_ROUTING where R_ITEM_ID = N.BM_BLOG_ID and R_TYPE_ID in (1,2) do
{
insert into SYS_BLOGS_ROUTING_LOG (RL_JOB_ID, RL_POST_ID, RL_TYPE, RL_COMMENT_ID)
values (R_JOB_ID, N.BM_POST_ID, 'CI', N.BM_ID);
}
}
}
;
create trigger BLOG_COMMENTS_NO_D after delete on BLOG_COMMENTS referencing old as O
{
if (O.BM_IS_PUB = 1)
{
set triggers off;
update SYS_BLOGS set B_COMMENTS_NO = B_COMMENTS_NO - 1 where B_POST_ID = O.BM_POST_ID and B_BLOG_ID = O.BM_BLOG_ID;
set triggers on;
}
delete from SYS_BLOGS_ROUTING_LOG where RL_COMMENT_ID = O.BM_ID;
delete from BLOG_COMMENT_LINKS where CL_BLOG_ID = O.BM_BLOG_ID and CL_POST_ID = O.BM_POST_ID and CL_CID = O.BM_ID;
set triggers off;
update BLOG.DBA.SYS_BLOG_INFO
set BI_DASHBOARD =
make_dasboard_item ('comment', null, null, null, null, '', BI_DASHBOARD, O.BM_ID, 'delete')
where BI_BLOG_ID = O.BM_BLOG_ID;
-- update all that have BM_REF_ID == O.BM_ID
update BLOG..BLOG_COMMENTS set BM_REF_ID = O.BM_REF_ID where BM_BLOG_ID = O.BM_BLOG_ID and
BM_POST_ID = O.BM_POST_ID and BM_REF_ID = O.BM_ID;
set triggers on;
}
;
create trigger SYS_ROUTING_D after delete on SYS_ROUTING
{
delete from SYS_BLOGS_ROUTING_LOG where RL_JOB_ID = R_JOB_ID;
}
;
create procedure BLOG_CHECK_QUOTA (in uid int)
{
declare qn, qm int;
declare opts any;
if (uid = http_dav_uid ())
return 1;
whenever not found goto endf;
select deserialize(blob_to_string(U_OPTS)) into opts from "DB"."DBA"."SYS_USERS" where U_ID = uid;
if (not isarray(opts))
opts := vector ();
qn := get_keyword ('WeblogQuotaMaxPosts', opts, 'unlimited');
qm := get_keyword ('WeblogQuotaMaxSize', opts, 'unlimited');
if (isinteger (qn) and qn > 0)
{
declare tot int;
select count (*) into tot from SYS_BLOGS where B_USER_ID = uid;
if (tot > qn)
{
return 0;
}
}
if (isinteger (qm) and qm > 0)
{
declare tot int;
select sum (length (B_CONTENT)) into tot from SYS_BLOGS where B_USER_ID = uid;
if (tot > qm)
{
return 0;
}
}
endf:
return 1;
}
;
create trigger SYS_BLOGS_I_Q after insert on SYS_BLOGS order 1
{
if (not BLOG_CHECK_QUOTA (B_USER_ID))
{
rollback work;
signal ('42000', 'Weblog quota exceeded.');
}
}
;
create trigger SYS_BLOGS_U_Q after update on SYS_BLOGS order 1 referencing old as O, new as N
{
if (not BLOG_CHECK_QUOTA (N.B_USER_ID))
{
rollback work;
signal ('42000', 'Weblog quota exceeded.');
}
}
;
create trigger SYS_BLOGS_I_L after insert on SYS_BLOGS order 10
{
for select R_JOB_ID, R_TYPE_ID as tid, R_DESTINATION_ID, R_ITEM_MAX_RETRANSMITS from SYS_ROUTING
where R_ITEM_ID = B_BLOG_ID and R_TYPE_ID in (1, 2, 3) do
{
-- insert a record in log
insert soft SYS_BLOGS_ROUTING_LOG (RL_JOB_ID, RL_POST_ID, RL_TYPE, RL_RETRANSMITS)
values (R_JOB_ID, B_POST_ID, 'I', R_ITEM_MAX_RETRANSMITS);
}
}
;
create trigger SYS_BLOGS_U_L after update on SYS_BLOGS order 10 referencing old as O, new as N
{
for select R_JOB_ID, R_TYPE_ID as tid, R_DESTINATION_ID, R_ITEM_MAX_RETRANSMITS from SYS_ROUTING
where R_ITEM_ID = N.B_BLOG_ID and R_TYPE_ID in (1, 3) do
{
-- mark for update if it's already sent to target
update SYS_BLOGS_ROUTING_LOG set RL_TYPE = 'U', RL_PROCESSED = 0, RL_RETRANSMITS = R_ITEM_MAX_RETRANSMITS
where RL_JOB_ID = R_JOB_ID and RL_POST_ID = N.B_POST_ID and RL_TYPE in ('I', 'U')
and RL_F_POST_ID is not null and RL_COMMENT_ID = -1;
if (row_count () = 0)
{
insert soft SYS_BLOGS_ROUTING_LOG (RL_JOB_ID, RL_POST_ID, RL_TYPE, RL_RETRANSMITS)
values (R_JOB_ID, N.B_POST_ID, 'I', R_ITEM_MAX_RETRANSMITS);
}
}
}
;
create trigger SYS_BLOGS_D_L after delete on SYS_BLOGS order 10
{
for select R_JOB_ID, R_ITEM_MAX_RETRANSMITS from SYS_ROUTING where R_ITEM_ID = B_BLOG_ID and R_TYPE_ID in (1, 3) do
{
-- mark for delete if already sent to target
update SYS_BLOGS_ROUTING_LOG set RL_TYPE = 'D', RL_PROCESSED = 0, RL_RETRANSMITS = R_ITEM_MAX_RETRANSMITS
where RL_JOB_ID = R_JOB_ID and RL_POST_ID = B_POST_ID and RL_F_POST_ID is not null
and RL_COMMENT_ID = -1;
-- delete if it's not already sent
delete from SYS_BLOGS_ROUTING_LOG where RL_JOB_ID = R_JOB_ID and RL_POST_ID = B_POST_ID
and RL_F_POST_ID is null;
}
}
;
create trigger SYS_USERS_BLOG_D after delete on "DB"."DBA"."SYS_USERS" order 90
{
delete from SYS_BLOG_INFO where BI_OWNER = U_ID;
}
;
create trigger SYS_BLOGS_D after delete on SYS_BLOGS
{
delete from MTYPE_BLOG_CATEGORY where MTB_POST_ID = B_POST_ID and MTB_BLOG_ID = B_BLOG_ID;
delete from BLOG_COMMENTS where BM_POST_ID = B_POST_ID and BM_BLOG_ID = B_BLOG_ID;
delete from MTYPE_TRACKBACK_PINGS where MP_POST_ID = B_POST_ID;
delete from SYS_BLOG_REFFERALS where BR_BLOG_ID = B_BLOG_ID and BR_POST_ID = B_POST_ID;
delete from SYS_BLOG_VISITORS where BV_BLOG_ID = B_BLOG_ID and BV_POST_ID = B_POST_ID;
delete from BLOG_TAG where BT_BLOG_ID = B_BLOG_ID and BT_POST_ID = B_POST_ID;
}
;
create trigger SYS_BLOG_INFO_D after delete on SYS_BLOG_INFO
{
delete from SYS_BLOGS where B_BLOG_ID = BI_BLOG_ID;
delete from SYS_BLOG_CHANNELS where BC_BLOG_ID = BI_BLOG_ID;
delete from MTYPE_CATEGORIES where MTC_BLOG_ID = BI_BLOG_ID;
delete from SYS_ROUTING where R_ITEM_ID = BI_BLOG_ID and R_TYPE_ID = 1;
delete from SYS_BLOG_SEARCH_ENGINE_SETTINGS where SS_BLOG_ID = BI_BLOG_ID;
}
;
-- UPGRADE CODE
create procedure SYS_BLOGS_UPGRADE ()
{
declare id, nid, ver any;
declare cr cursor for select B_POST_ID from SYS_BLOGS where B_CONTENT_ID is null;
whenever not found goto nf;
-- skip if upgrated
if (registry_get ('Weblog_version') = '1.1')
return;
open cr;
while (1)
{
fetch cr into id;
update SYS_BLOGS set B_CONTENT_ID = atoi (id) where current of cr;
}
nf:
close cr;
if (not exists (select top 1 1 from SYS_BLOG_INFO))
{
for select cast (U_ID as varchar) as B_BLOG_ID, U_NAME, U_FULL_NAME, U_ID
from WS.WS.SYS_DAV_USER
where exists (select 1 from WS.WS.SYS_DAV_RES where RES_FULL_PATH = '/DAV/'||U_NAME||'/blog/rss.xml') do
{
declare owner, title, home, phome, uid, name any;
owner := U_ID;
title := U_FULL_NAME || '\'s Weblog';
home := '/blog/' || U_NAME || '/blog/';
phome := '/DAV/' || U_NAME || '/blog/';
insert into SYS_BLOG_INFO (BI_BLOG_ID, BI_OWNER, BI_HOME, BI_TITLE, BI_DEFAULT_PAGE, BI_P_HOME)
values (B_BLOG_ID, owner, home, title, 'index.vsp', phome);
}
}
update SYS_BLOG_INFO set BI_P_HOME = '/DAV/' || substring (BI_HOME, 7, length (BI_HOME)) where BI_P_HOME is null and BI_HOME like '/blog/%';
update SYS_BLOG_INFO set BI_SHOW_CONTACT = 1, BI_SHOW_REGIST = 1, BI_COMMENTS = 1, BI_HOME_PAGE = '' where BI_HOME_PAGE is null;
set triggers off;
update SYS_BLOGS set B_TRACKBACK_NO = 0 where B_TRACKBACK_NO is null;
update SYS_BLOGS set B_TS = B_TS where B_MODIFIED is null;
set triggers on;
update SYS_BLOG_INFO set BI_FILTER = '*default*' where BI_FILTER is null;
delete from SYS_BLOG_INFO where not exists (select 1 from "DB"."DBA"."SYS_USERS" where U_ID = BI_OWNER);
update SYS_BLOG_CHANNEL_INFO set BCD_IS_BLOG = 1 where BCD_IS_BLOG is null and BCD_FORMAT not in ('OPML', 'OCS');
update SYS_BLOG_INFO set BI_E_MAIL = (select U_E_MAIL from "DB"."DBA"."SYS_USERS" where U_ID = BI_OWNER) where BI_E_MAIL is null;
declare f_cat_id int;
for select BC_CHANNEL_URI url, BCD_IS_BLOG, BC_BLOG_ID bid from SYS_BLOG_CHANNELS, SYS_BLOG_CHANNEL_INFO
where BC_CHANNEL_URI = BCD_CHANNEL_URI and BC_CAT_ID IS NULL and not BCD_FORMAT in ('OCS', 'OPML') do
{
if (BCD_IS_BLOG)
{
if (not exists (select 1 from SYS_BLOG_CHANNEL_CATEGORY
where BCC_NAME = 'Blog Roll' and BCC_BLOG_ID = bid))
{
insert into SYS_BLOG_CHANNEL_CATEGORY (BCC_BLOG_ID, BCC_NAME) values (bid, 'Blog Roll');
}
f_cat_id := (select BCC_ID from SYS_BLOG_CHANNEL_CATEGORY
where BCC_NAME = 'Blog Roll' and BCC_BLOG_ID = bid);
}
else
{
if (not exists (select 1 from SYS_BLOG_CHANNEL_CATEGORY
where BCC_NAME = 'Channel Roll' and BCC_BLOG_ID = bid))
{
insert into SYS_BLOG_CHANNEL_CATEGORY (BCC_BLOG_ID, BCC_NAME) values (bid, 'Channel Roll');
}
f_cat_id := (select BCC_ID from SYS_BLOG_CHANNEL_CATEGORY
where BCC_NAME = 'Channel Roll' and BCC_BLOG_ID = bid);
}
update SYS_BLOG_CHANNELS set BC_CAT_ID = f_cat_id where BC_CHANNEL_URI = url and BC_BLOG_ID = bid;
}
ver := '1.1';
registry_set ('Weblog_version', ver);
registry_set ('WeblogServerID', uuid ());
return;
}
;
create procedure SYS_BLOGS_UPGRADE_1 ()
{
declare id int;
if (registry_get ('__SYS_BLOGS_UPGRADE_1_done') = 'done')
return;
if (exists (select 1 from SYS_BLOGS where B_IS_ACTIVE is null))
{
set triggers off;
update SYS_BLOGS set B_IS_ACTIVE = 0 where B_IS_ACTIVE is null;
update SYS_BLOGS set B_IS_ACTIVE = 1
where xpath_contains (B_CONTENT, '[__quiet BuildStandalone=ENABLE xmlns:sql="urn:schemas-openlink-com:xml-sql" ] //sql:*');
--for select B_POST_ID as id, B_BLOG_ID as bid, B_CONTENT as cnt from SYS_BLOGS
--where xpath_contains (B_CONTENT, '[__quiet BuildStandalone=ENABLE] //tr[not ancestor::table]|//td[not ancestor::table') do
-- {
-- update SYS_BLOGS set B_CONTENT = '<table>'||blob_to_string (cnt)||'</table>'
-- where B_BLOG_ID = bid and B_POST_ID = id;
-- }
set triggers on;
}
if (not exists (select 1 from SYS_BLOG_INFO where BI_BLOG_SEQ is null))
return;
id := 1;
set triggers off;
for select BI_BLOG_ID as bid from SYS_BLOG_INFO where BI_BLOG_SEQ is null do
{
update SYS_BLOG_INFO set BI_BLOG_SEQ = id where BI_BLOG_ID = bid;
id := id + 1;
}
DB.DBA.SET_IDENTITY_COLUMN ('BLOG.DBA.SYS_BLOG_INFO', 'BI_BLOG_SEQ', id);
set triggers on;
registry_set ('__SYS_BLOGS_UPGRADE_1_done', 'done');
}
;
SYS_BLOGS_UPGRADE ()
;
SYS_BLOGS_UPGRADE_1 ();
create procedure BLOG.DBA.SYS_BLOGS_B_CONTENT_INDEX_HOOK (inout vtb any, inout d_id integer)
{
declare title, blogid varchar;
declare wai_id int;
select B_TITLE, B_BLOG_ID into title, blogid from SYS_BLOGS where B_CONTENT_ID = d_id;
wai_id := (select WAI_ID from DB.DBA.WA_INSTANCE, BLOG.DBA.SYS_BLOG_INFO where BI_WAI_NAME = WAI_NAME and BI_BLOG_ID = blogid);
--dbg_obj_print ('BLOG.DBA.SYS_BLOGS_B_CONTENT_INDEX_HOOK', title);
if (length (title))
vt_batch_feed (vtb, title, 0);
if (wai_id is not null)
vt_batch_feed (vtb, sprintf ('^B%d', wai_id), 0);
return 0;
};
create procedure BLOG.DBA.SYS_BLOGS_B_CONTENT_UNINDEX_HOOK (inout vtb any, inout d_id integer)
{
declare title, blogid varchar;
declare wai_id int;
select B_TITLE, B_BLOG_ID into title, blogid from SYS_BLOGS where B_CONTENT_ID = d_id;
wai_id := (select WAI_ID from DB.DBA.WA_INSTANCE, BLOG.DBA.SYS_BLOG_INFO where BI_WAI_NAME = WAI_NAME and BI_BLOG_ID = blogid);
--dbg_obj_print ('BLOG.DBA.SYS_BLOGS_B_CONTENT_UNINDEX_HOOK', title);
if (length (title))
vt_batch_feed (vtb, title, 1);
if (wai_id is not null)
vt_batch_feed (vtb, sprintf ('^B%d', wai_id), 1);
return 0;
};
DB.DBA.vt_create_text_index ('BLOG.DBA.SYS_BLOGS', 'B_CONTENT', 'B_CONTENT_ID', 2, 0, vector ('B_BLOG_ID','B_POST_ID','B_TS'), 1, '*ini*', 'UTF-8')
;
DB.DBA.vt_create_ftt ('BLOG.DBA.SYS_BLOGS', 'B_CONTENT_ID', 'B_CONTENT', 2)
;
DB.DBA.vt_create_text_index ('BLOG.DBA.BLOG_COMMENTS', 'BM_COMMENT', 'BM_ID', 2, 0, null, null, '*ini*', 'UTF-8')
;
DB.DBA.vt_create_ftt ('BLOG.DBA.BLOG_COMMENTS', 'BM_ID', 'BM_COMMENT', 2)
;
create trigger SYS_BLOGS_I_C after insert on SYS_BLOGS_B_CONTENT_HIT
{
declare blogid, postid, catid, did, qid varchar;
whenever not found goto endf;
did := TTH_D_ID;
qid := TTH_T_ID;
select top 1 B_POST_ID, B_BLOG_ID, TT_PREDICATE into postid, blogid, catid
from SYS_BLOGS, SYS_BLOGS_B_CONTENT_QUERY
where TT_ID = qid and TT_CD = B_BLOG_ID and B_CONTENT_ID = did;
{
insert soft MTYPE_BLOG_CATEGORY (MTB_CID, MTB_POST_ID, MTB_BLOG_ID, MTB_IS_AUTO)
values (catid, postid, blogid, 1);
}
endf:
return;
}
;
create trigger MTYPE_CATEGORIES_D after delete on MTYPE_CATEGORIES referencing old as O
{
delete from MTYPE_BLOG_CATEGORY where MTB_BLOG_ID = O.MTC_BLOG_ID and MTB_CID = O.MTC_ID;
delete from SYS_BLOGS_B_CONTENT_QUERY where TT_CD = O.MTC_BLOG_ID and TT_PREDICATE = O.MTC_ID;
}
;
create procedure FTI_MAKE_OR_SEARCH_STRING (in exp varchar)
{
declare exp1 varchar;
declare war, vt any;
declare m, n int;
if (length (exp) < 2)
return null;
exp := trim (exp, ' ');
if (strchr (exp, ' ') is null)
return concat ('"', trim (exp, '"'), '"');
exp1 := '';
if (strchr (exp, '"') is not null or
strchr (exp, '''') is not null)
{
declare tmp, w varchar;
tmp := exp;
w := regexp_match ('["][^"]+["]|[''][^'']+['']|[^"'' ]+', tmp, 1);
while (w is not null)
{
w := trim (w, '"'' ');
if (upper(w) not in ('AND', 'NOT', 'NEAR', 'OR')
and length (w) > 1
and not vt_is_noise (w, 'utf-8', 'x-any'))
exp1 := concat (exp1, sprintf ('"%s" OR ', w));
w := regexp_match ('["][^"]+["]|[''][^'']+['']|[^"'' ]+', tmp, 1);
}
if (length (exp1) > 5)
{
exp1 := substring (exp1, 1, length (exp1) - 4);
goto end_parse;
}
}
vt := vt_batch (100, 'x-any', 'UTF-8');
vt_batch_feed (vt, exp, 0, 0);
war := vt_batch_strings_array (vt);
m := length (war);
n := 0;
exp1 := '(';
while (n < m)
{
declare word1 varchar;
if (war[n] not in ('AND', 'NOT', 'NEAR', 'OR')
and length (war[n]) > 1
and not vt_is_noise (war[n], 'utf-8', 'x-any'))
{
word1 := war[n];
if (strchr (word1, '.') is not null or regexp_match ('[A-Za-z_][A-Za-z0-9_-]*', word1) is null)
word1 := concat ('"', word1, '"');
exp1 := concat (exp1, word1, ' OR ');
}
n := n + 2;
}
if (length (exp1) > 4)
{
exp1 := substring (exp1, 1, length (exp1) - 4);
exp1 := concat (exp1, ')');
}
else
exp1 := null;
end_parse:
return exp1;
}
;
--
-- BLOGGER SERVER HANDLERS
--
-- XML-RPC interface
create
procedure "blogger_auth" (in req "blogRequest")
{
declare authenticated int;
authenticated := 0;
if (__proc_exists ('authenticate_' || req.appkey))
{
call ('authenticate_' || req.appkey) (req);
return;
}
else
{
declare hdr varchar;
hdr := http_request_header (http_request_header (), 'X-Virt-BlogID');
set isolation = 'committed';
declare pwd varchar;
declare id int;
whenever not found goto nf;
select U_PWD, U_ID into pwd, id from WS.WS.SYS_DAV_USER where U_NAME = req.user_name with (prefetch 1);
if (isstring (pwd))
{
if ((pwd[0] = 0 and pwd_magic_calc (req.user_name, req.passwd) = pwd)
or (pwd[0] <> 0 and pwd = req.passwd))
{
declare own, home, inst_name any;
declare bid varchar;
own := null; home := null; bid := null;
if (isstring (req.blogid))
{
select BI_HOME, BI_OWNER, BI_WAI_NAME into home, own, inst_name from SYS_BLOG_INFO where BI_BLOG_ID = req.blogid with (prefetch 1);
bid := req.blogid;
}
else if (isstring (req.postId))
{
whenever not found goto nfpost;
select BI_HOME, BI_OWNER, BI_BLOG_ID, BI_WAI_NAME into home, own, bid, inst_name from SYS_BLOG_INFO, SYS_BLOGS
where B_POST_ID = req.postId and BI_BLOG_ID = B_BLOG_ID with (prefetch 1);
req.blogid := bid;
nfpost:;
}
if (own is not null)
{
req.blog_owner := own;
}
if (home is not null)
{
req.blog_lhome := home;
req.blog_phome := http_physical_path_resolve (home);
}
if (own <> id and id <> http_dav_uid ())
{
declare dummy int;
if (not exists (select 1 from DB.DBA.WA_MEMBER where WAM_USER = id and WAM_INST = inst_name and WAM_MEMBER_TYPE = 2))
select 1 into dummy from "DB"."DBA"."SYS_ROLE_GRANTS" where GI_SUPER = id and GI_SUB = own with (prefetch 1);
}
if (bid is not null and hdr = concat (registry_get ('WeblogServerID'), ';', bid))
signal ('42000', 'Replica to same blog and server is not allowed');
--update WS.WS.SYS_DAV_USER set U_LOGIN_TIME = now () where U_NAME = req.user_name;
req.auth_userid := id;
authenticated := 1;
}
}
commit work;
}
if (authenticated)
return;
nf:
rollback work;
signal ('42000', 'Access denied');
}
;
create
procedure "blogger.newPost" (
in appkey varchar,
in blogId varchar,
in "username" varchar,
in "password" varchar,
in content nvarchar,
in publish smallint,
out postId varchar
)
{
declare req "blogRequest";
req := new "blogRequest" ();
req.appkey := appkey;
req.user_name := "username";
req.passwd := "password";
req.blogId := blogId;
req.content := blog_wide2utf (content);
req.publish := publish;
if (req.publish = 0)
req.publish := 1;
else if (req.publish = 1)
req.publish := 2;
"blogger_auth" (req);
if (__proc_exists ('newPost_' || req.appkey))
{
call ('newPost_' || req.appkey) (req);
}
else
{
declare dummy, title any;
if (length (trim (content)) = 0)
signal ('22023', 'Empty posts are not allowed');
req.postId := cast (sequence_next ('blogger.postid') as varchar);
if (req.postId = '0') -- start from 1
req.postId := cast (sequence_next ('blogger.postid') as varchar);
dummy := null;
title := BLOG_GET_TITLE (dummy, req.content);
insert into SYS_BLOGS (B_APPKEY, B_BLOG_ID, B_CONTENT, B_POST_ID, B_USER_ID, B_TS, B_STATE, B_TITLE)
values (req.appkey, req.blogid, req.content, req.postId, req.auth_userid, now (), req.publish, title);
}
postId := req.postId;
}
;
create
procedure "blogger.editPost" (
in appkey varchar,
in postId varchar,
in "username" varchar,
in "password" varchar,
in content nvarchar,
in publish smallint
)
{
declare req "blogRequest";
req := new "blogRequest" ();
req.appkey := appkey;
req.user_name := "username";
req.passwd := "password";
req.postId := postId;
req.content := blog_wide2utf (content);
req.publish := publish;
if (req.publish = 0)
req.publish := 1;
else if (req.publish = 1)
req.publish := 2;
"blogger_auth" (req);
if (__proc_exists ('editPost_' || req.appkey))
call ('editPost_' || req.appkey) (req);
else
{
if (length (trim (content)) = 0)
signal ('22023', 'Empty posts are not allowed');
update SYS_BLOGS set B_CONTENT = req.content, B_STATE = req.publish where B_POST_ID = req.postId;
}
return soap_boolean (1);
}
;
create
procedure "blogger.deletePost" (
in appkey varchar,
in postId varchar,
in "username" varchar,
in "password" varchar,
in publish smallint
)
{
declare req "blogRequest";
req := new "blogRequest" ();
req.appkey := appkey;
req.user_name := "username";
req.passwd := "password";
req.postId := postId;
req.publish := publish;
"blogger_auth" (req);
if (__proc_exists ('deletePost_' || req.appkey))
call ('deletePost_' || req.appkey) (req);
else
delete from SYS_BLOGS where B_POST_ID = req.postId;
return soap_boolean (1);
}
;
create
procedure "blogger.getPost" (
in appkey varchar,
in postId varchar,
in "username" varchar,
in "password" varchar
)
{
declare req "blogRequest";
declare res "blogPost";
req := new "blogRequest" ();
req.appkey := appkey;
req.user_name := "username";
req.passwd := "password";
req.postId := postId;
"blogger_auth" (req);
if (__proc_exists ('getPost_' || req.appkey))
{
res := call ('getPost_' || req.appkey) (req);
return res;
}
else
{
set isolation = 'committed';
declare content, datecreated, userid any;
declare post "blogPost";
whenever not found goto nf;
select sprintf ('%s', blob_to_string (B_CONTENT)), B_TS, B_USER_ID into content, datecreated, userid
from SYS_BLOGS where B_POST_ID = req.postId with (prefetch 1);
post := new "blogPost" ();
post.content := blog_utf2wide (content);
post.dateCreated := datecreated;
post."postid" := req.postId;
post.userid := (select U_NAME from "DB"."DBA"."SYS_USERS" where U_ID = userid);
return post;
nf:
signal ('22023', 'Cannot find a post with Id = ' || req.postId);
}
}
;
create
procedure "blogger.getRecentPosts" (
in appkey varchar,
in blogId varchar,
in "username" varchar,
in "password" varchar,
in numberOfPosts int
)
{
declare req "blogRequest";
declare res "blogPost";
req := new "blogRequest" ();
req.appkey := appkey;
req.user_name := "username";
req.passwd := "password";
req.blogId := blogId;
"blogger_auth" (req);
if (__proc_exists ('getRecentPosts_' || req.appkey))
{
res := call ('getRecentPosts_' || req.appkey) (req, numberOfPosts);
return res;
}
else
{
set isolation = 'committed';
declare ret, elm any;
declare post "blogPost";
ret := vector ();
for select B_CONTENT, B_TS, B_USER_ID, B_POST_ID
from SYS_BLOGS where B_BLOG_ID = req.blogId order by B_TS desc do
{
post := new "blogPost" ();
post.content := blog_utf2wide (sprintf ('%s', blob_to_string (B_CONTENT)));
post.dateCreated := B_TS;
post."postid" := B_POST_ID;
post.userid := (select U_NAME from "DB"."DBA"."SYS_USERS" where U_ID = B_USER_ID);
ret := vector_concat (ret, vector (post));
numberOfPosts := numberOfPosts - 1;
if (numberOfPosts <= 0)
goto endg;
}
endg:
return ret;
}
}
;
--
-- blogger extensions
--
create
procedure "blogger.getUsersBlogs" (
in appkey varchar,
in "username" varchar,
in "password" varchar
)
{
declare req "blogRequest";
req := new "blogRequest" ();
req.appkey := appkey;
req.user_name := "username";
req.passwd := "password";
"blogger_auth" (req);
if (__proc_exists ('getUsersBlogs_' || req.appkey))
return call ('getUsersBlogs_' || req.appkey) (req);
else
{
set isolation = 'committed';
declare ret any;
declare host, path, url varchar;
ret := vector ();
host := http_request_header (http_request_header (), 'Host', null);
if (isstring (host) and strchr (host, ':') is null)
{
declare hp varchar;
declare hpa any;
hp := sys_connected_server_address ();
hpa := split_and_decode (hp, 0, '\0\0:');
host := host || ':' || hpa[1];
}
if (host is null)
host := sys_connected_server_address ();
-- own blogs
for select BI_TITLE, BI_DEFAULT_PAGE, BI_HOME, BI_BLOG_ID from SYS_BLOG_INFO
where BI_OWNER = req.auth_userid do
{
declare str any;
url := 'http://' || host || BI_HOME;
str := soap_box_structure ('url', url, 'blogid', BI_BLOG_ID, 'blogName', BI_TITLE);
ret := vector_concat (ret, vector (str));
}
-- granted blogs
for select BI_TITLE, BI_DEFAULT_PAGE, BI_HOME, BI_BLOG_ID from SYS_BLOG_INFO, "DB"."DBA"."SYS_ROLE_GRANTS"
where BI_OWNER = GI_SUB and GI_SUPER = req.auth_userid do
{
declare str any;
url := 'http://' || host || BI_HOME;
str := soap_box_structure ('url', url, 'blogid', BI_BLOG_ID, 'blogName', BI_TITLE);
ret := vector_concat (ret, vector (str));
}
return ret;
}
}
;
create procedure
date_rfc1123 (in dt datetime)
{
return soap_print_box (dt, '', 1);
}
;
create procedure
date_iso8601 (in dt datetime)
{
return soap_print_box (dt, '', 0);
}
;
create
procedure "blogger.getTemplate" (
in appkey varchar,
in blogId varchar,
in "username" varchar,
in "password" varchar,
in templateType varchar
)
{
declare req "blogRequest";
req := new "blogRequest" ();
req.appkey := appkey;
req.blogId := blogId;
req.user_name := "username";
req.passwd := "password";
"blogger_auth" (req);
if (__proc_exists ('getTemplate_' || req.appkey))
return call ('getTemplate_' || req.appkey) (req);
declare path, cont, nam varchar;
if (lower (templateType) = 'main')
nam := 'default.xsl';
else
nam := templateType || '_template.html';
path := rtrim(req.blog_phome, '/') || '/' || nam;
cont := (select blob_to_string (RES_CONTENT) from WS.WS.SYS_DAV_RES where RES_FULL_PATH = path);
return cont;
}
;
create
procedure "blogger.setTemplate" (
in appkey varchar,
in blogId varchar,
in "username" varchar,
in "password" varchar,
in template varchar,
in templateType varchar
)
{
declare req "blogRequest";
req := new "blogRequest" ();
req.appkey := appkey;
req.blogId := blogId;
req.user_name := "username";
req.passwd := "password";
req.content := template;
"blogger_auth" (req);
if (__proc_exists ('setTemplate_' || req.appkey))
return call ('setTemplate_' || req.appkey) (req);
declare path, cont, perms, nam varchar;
declare dav_uid, dav_grp varchar;
if (req.blog_owner <> req.auth_userid)
{
dav_uid := http_dav_uid ();
dav_grp := req.blog_owner;
perms := '110110100N';
}
else
{
dav_uid := req.auth_userid;
dav_grp := null;
perms := '110100100N';
}
if (lower (templateType) = 'main')
nam := 'default.xsl';
else
nam := templateType || '_template.html';
path := rtrim(req.blog_phome, '/') || '/' || nam;
DB.DBA.DAV_RES_UPLOAD (path, template, '', perms, dav_uid, dav_grp, req.user_name, req.passwd);
return soap_boolean (1);
}
;
create
procedure "blogger.getUserInfo" (
in appkey varchar,
in "username" varchar,
in "password" varchar
)
{
declare req "blogRequest";
req := new "blogRequest" ();
req.appkey := appkey;
req.user_name := "username";
req.passwd := "password";
"blogger_auth" (req);
if (__proc_exists ('getUserInfo_' || req.appkey))
return call ('getUserInfo_' || req.appkey) (req);
declare name, host, path, url, email varchar;
host := http_request_header (http_request_header (), 'Host', null);
path := coalesce (DB.DBA.USER_GET_OPTION (req.user_name, 'HOME'), '/DAV/');
name := coalesce (DB.DBA.USER_GET_OPTION (req.user_name, 'FULL_NAME'), '');
email := coalesce (DB.DBA.USER_GET_OPTION (req.user_name, 'E-MAIL'), '');
url := 'http://' || host || path || 'blog';
return soap_box_structure ('nickname',req.user_name,'userid',req.user_name,'url',url,'email',
email,'lastname',name,'firstname', '');
}
;
--
-- META WEBLOG
--
create procedure
"metaWeblog.newPost" (
in blogid varchar,
in "username" varchar,
in "password" varchar,
in struct BLOG.DBA."MTWeblogPost",
in publish smallint)
returns varchar
{
declare req "blogRequest";
req := new "blogRequest" ();
req.appkey := 'META_WEBLOG';
req.user_name := "username";
req.passwd := "password";
req.blogId := blogid;
req.struct := struct;
req.publish := publish;
if (req.publish = 0)
req.publish := 1;
else if (req.publish = 1)
req.publish := 2;
"blogger_auth" (req);
if (__proc_exists ('newPost_' || req.appkey))
call ('newPost_' || req.appkey) (req);
else
{
declare cnt, title any;
declare pings, cats any;
req.postId := cast (sequence_next ('blogger.postid') as varchar);
if (req.postId = '0') -- start from 1
req.postId := cast (sequence_next ('blogger.postid') as varchar);
if (struct.dateCreated is null)
struct.dateCreated := now ();
struct.postid := req.postId;
struct.userid := req.user_name;
cnt := blog_wide2utf (struct.description);
pings := struct.mt_tb_ping_urls;
cats := struct.categories;
--struct.mt_tb_ping_urls := null;
struct.description := null;
if (length (trim (cnt)) = 0)
signal ('22023', 'Empty posts are not allowed');
foreach (varchar cat in cats) do
{
declare category_id int;
whenever not found goto nextcat;
select MTC_ID into category_id from MTYPE_CATEGORIES where MTC_NAME = cat and MTC_BLOG_ID = req.blogid;
insert replacing MTYPE_BLOG_CATEGORY (MTB_CID , MTB_POST_ID, MTB_BLOG_ID, MTB_PRIMARY)
values (category_id, struct.postId, req.blogid, 0);
nextcat:;
}
title := BLOG_GET_TITLE (struct, cnt);
insert into SYS_BLOGS (B_APPKEY, B_BLOG_ID, B_CONTENT, B_POST_ID, B_USER_ID, B_TS, B_META, B_STATE, B_TITLE)
values (req.appkey, req.blogid,
cnt, struct.postId, req.auth_userid, struct.dateCreated, struct, req.publish, title);
struct.description := cnt;
struct.mt_tb_ping_urls := pings;
BLOG_SEND_TB_PINGS (struct);
}
return req.postId;
}
;
create procedure
"metaWeblog.editPost"
(
in postid varchar,
in "username" varchar,
in "password" varchar,
in struct BLOG.DBA."MTWeblogPost",
in publish smallint)
returns smallint
{
declare req "blogRequest";
req := new "blogRequest" ();
req.appkey := 'META_WEBLOG';
req.user_name := "username";
req.passwd := "password";
req.postId := postId;
req.struct := struct;
req.publish := publish;
if (req.publish = 0)
req.publish := 1;
else if (req.publish = 1)
req.publish := 2;
"blogger_auth" (req);
if (__proc_exists ('editPost_' || req.appkey))
call ('editPost_' || req.appkey) (req);
else
{
declare cnt, ts, userid, pings, cats, pub any;
whenever not found goto nf;
select B_TS, B_USER_ID, B_STATE into ts, userid, pub from SYS_BLOGS where B_POST_ID = req.postId;
struct.postid := req.postId;
struct.userid := (select U_NAME from "DB"."DBA"."SYS_USERS" where U_ID = userid);
struct.dateCreated := ts;
cnt := blog_wide2utf (struct.description);
pings := struct.mt_tb_ping_urls;
--struct.mt_tb_ping_urls := null;
struct.description := null;
if (length (trim (cnt)) = 0)
signal ('22023', 'Empty posts are not allowed');
cats := struct.categories;
--dbg_obj_print (cats, req.publish);
if (pub = 2 or req.publish = 1)
{
delete from MTYPE_BLOG_CATEGORY where MTB_BLOG_ID = req.blogid and MTB_POST_ID = req.postId;
}
foreach (varchar cat in cats) do
{
declare category_id int;
whenever not found goto nextcat;
select MTC_ID into category_id from MTYPE_CATEGORIES where MTC_NAME = cat and MTC_BLOG_ID = req.blogid;
insert replacing MTYPE_BLOG_CATEGORY (MTB_CID , MTB_POST_ID, MTB_BLOG_ID, MTB_PRIMARY)
values (category_id, struct.postId, req.blogid, 0);
nextcat:;
}
update SYS_BLOGS
set B_CONTENT = cnt, B_META = struct, B_STATE = req.publish
where B_POST_ID = req.postId;
struct.description := cnt;
struct.mt_tb_ping_urls := pings;
BLOG_SEND_TB_PINGS (struct);
nf:;
}
return soap_boolean (1);
}
;
create procedure
BLOG_SEND_TB_PINGS (inout struct BLOG.DBA."MTWeblogPost")
{
declare urls any;
declare i, l int;
declare post varchar;
declare tit, url, exc, blog varchar;
declare ss any;
urls := struct.mt_tb_ping_urls;
i := 0; l := length (urls);
if (not l)
goto ef;
whenever not found goto ef;
select 'http://' || BLOG_GET_HOST () || BI_HOME, BI_TITLE into url, blog from SYS_BLOG_INFO, SYS_BLOGS where BI_BLOG_ID = B_BLOG_ID and B_POST_ID = struct.postid;
url := concat (url, '?id=', struct.postid);
tit := struct.title;
exc := case when struct.mt_excerpt is null or struct.mt_excerpt = '' then substring (struct.description, 1, 125) else struct.mt_excerpt end;
commit work;
ss := string_output ();
http (sprintf ('url=%U&blog_name=%U', url, blog) ,ss);
http ('&title=', ss);
http_escape (tit, 8, ss);
http ('&excerpt=', ss);
http_escape (exc, 8, ss);
--post := sprintf ('title=%U&url=%U&excerpt=%U&blog_name=%U', tit, url, exc, blog);
post := string_output_string (ss);
while (i < l)
{
{
declare nuri, arr varchar;
declare exit handler for sqlstate '*' { goto nexti; };
arr := WS.WS.PARSE_URI (cast (urls[i] as varchar));
if (lower(arr[0]) = 'http')
{
nuri := sprintf ('http://%s%s%s%s', arr[1], arr[2], case arr[4] when '' then '' else '?' end, arr[4]);
http_get (nuri, null, 'POST', null, post);
}
}
nexti:;
i := i + 1;
}
ef:;
return;
}
;
create procedure
BLOG_MAKE_TITLE (inout _content any)
{
declare cont, tit, content varchar;
declare xt any;
content := blob_to_string (_content);
cont := substring (content, 1, 50);
xt := xml_tree_doc (xml_tree (content, 2, '', 'UTF-8'));
tit := cast (xpath_eval ('//*[ text() != "" and not descendant::*[ text() != "" ] ]', xt, 1) as varchar);
if (tit is null)
{
tit := regexp_match ('(<[^<])?+[^<]+(</?[^>]+>)?', content);
if (tit is not null)
tit := trim(regexp_replace (tit, '<[^>]+>', '', 1, null));
}
else
{
declare ss any;
ss := string_output ();
http_value (tit, null, ss);
tit := string_output_string (ss);
}
if (tit is null)
tit := regexp_match ('[^\\r\\n]+', content);
if (tit is null)
tit := cont;
return substring (tit, 1, 512);
}
;
create procedure
BLOG_GET_TITLE (inout meta any, inout content any)
{
declare m_title any;
if (meta is not null and udt_instance_of (meta, 'BLOG.DBA.MTWeblogPost'))
{
declare _in BLOG.DBA."MTWeblogPost";
_in := meta;
m_title := _in.title;
}
else if (meta is not null and udt_instance_of (meta, 'DB.DBA.MTWeblogPost'))
{
declare _in DB.DBA."MTWeblogPost";
_in := meta;
m_title := _in.title;
}
if (meta is not null and length (m_title) > 0)
return m_title;
return BLOG_MAKE_TITLE (content);
}
;
create procedure
BLOG_GET_TEXT_TITLE (inout B_META any, inout B_CONTENT any)
{
declare tit varchar;
declare ntit nvarchar;
tit := BLOG_GET_TITLE (B_META, B_CONTENT);
if (iswidestring (tit))
tit := blog_wide2utf (tit);
ntit := xpath_eval ('string(//*)', xml_tree_doc (xml_tree (tit, 2, '', 'UTF-8')), 1);
if (length (ntit))
tit := blog_wide2utf(ntit);
return tit;
}
;
create procedure
"metaWeblog.getPost"
(
in postid varchar,
in "username" varchar,
in "password" varchar
)
returns any
{
declare req "blogRequest";
declare res "MWeblogPost";
req := new "blogRequest" ();
req.appkey := 'META_WEBLOG';
req.user_name := "username";
req.passwd := "password";
req.postId := postId;
"blogger_auth" (req);
if (__proc_exists ('getPost_' || req.appkey))
res := call ('getPost_' || req.appkey) (req);
else
{
declare userid, content, dt any;
whenever not found goto nf;
select B_META, B_USER_ID, B_CONTENT, B_TS into res, userid, content, dt from SYS_BLOGS
where B_POST_ID = req.postId;
if (res is null)
{
res := new "MTWeblogPost" ();
res.postid := req.postId;
res.title := BLOG_MAKE_TITLE (content);
}
res.author := (select U_NAME from "DB"."DBA"."SYS_USERS" where U_ID = userid);
res.userid := res.author;
res.dateCreated := dt;
res.title := blog_utf2wide (res.title);
res.description := blog_utf2wide (blob_to_string (content));
res.categories := (select DB..vector_agg(MTC_NAME) from MTYPE_BLOG_CATEGORY, MTYPE_CATEGORIES
where MTB_BLOG_ID = MTC_BLOG_ID and MTC_ID = MTB_CID and MTB_POST_ID = req.postId);
}
return res;
nf:
signal ('22023', 'Cannot find a post with Id = ' || req.postId);
}
;
create
procedure "metaWeblog.getRecentPosts" (
in blogId varchar,
in "username" varchar,
in "password" varchar,
in numberOfPosts int
)
{
declare req "blogRequest";
declare ret any;
declare res "MTWeblogPost";
req := new "blogRequest" ();
req.appkey := 'META_WEBLOG';
req.user_name := "username";
req.passwd := "password";
req.blogId := blogId;
"blogger_auth" (req);
if (__proc_exists ('getRecentPosts_' || req.appkey))
{
ret := call ('getRecentPosts_' || req.appkey) (req, numberOfPosts);
return ret;
}
else
{
declare elm any;
declare post "blogPost";
ret := vector ();
for select B_META, B_TS, B_USER_ID, B_POST_ID, B_CONTENT
from SYS_BLOGS where B_BLOG_ID = req.blogId order by B_TS desc do
{
res := B_META;
if (res is null)
{
res := new "MTWeblogPost" ();
res.postid := B_POST_ID;
res.title := BLOG_MAKE_TITLE (B_CONTENT);
}
res.userid := (select U_NAME from "DB"."DBA"."SYS_USERS" where U_ID = B_USER_ID);
res.author := res.userid;
res.dateCreated := B_TS;
res.title := blog_utf2wide (res.title);
res.description := blog_utf2wide (blob_to_string (B_CONTENT));
res.categories := (select DB..vector_agg(MTC_NAME) from MTYPE_BLOG_CATEGORY, MTYPE_CATEGORIES
where MTB_BLOG_ID = MTC_BLOG_ID and MTC_ID = MTB_CID and MTB_POST_ID = B_POST_ID);
-- kludge for enclosures
if (udt_is_available ('DB.DBA.MWeblogPost'))
{
res.enclosure := null;
}
-- kludge for zempt
if (res.mt_convert_breaks = '')
res.mt_convert_breaks := null;
if (res.mt_excerpt = '')
res.mt_excerpt := null;
if (res.mt_text_more = '')
res.mt_text_more := null;
if (res.mt_keywords = '')
res.mt_keywords := null;
if (length (res.mt_tb_ping_urls) = 0)
res.mt_tb_ping_urls := null;
ret := vector_concat (ret, vector (res));
numberOfPosts := numberOfPosts - 1;
if (numberOfPosts <= 0)
goto endg;
}
endg:
return ret;
}
}
;
create procedure
"metaWeblog.getCategories"
(
in blogid varchar,
in "username" varchar,
in "password" varchar
)
returns any
{
declare req "blogRequest";
declare res any;
req := new "blogRequest" ();
req.appkey := 'META_WEBLOG';
req.user_name := "username";
req.passwd := "password";
req.blogId := blogid;
"blogger_auth" (req);
if (__proc_exists ('getCategories_' || req.appkey))
return call ('getCategories_' || req.appkey) (req);
else
{
res := vector ();
for select MTC_ID, MTC_NAME from MTYPE_CATEGORIES where MTC_BLOG_ID = blogid do
{
declare url any;
declare host varchar;
host := BLOG_GET_HOST ();
url := 'http://' || host || req.blog_phome;
url := rtrim (url, '/');
res := vector_concat (res,
vector (soap_box_structure ('description',MTC_NAME,
'htmlUrl', url || '/index.vsp?cat=' || cast (MTC_ID as varchar),
'rssUrl', url || '/rss.xml?cat=' || cast (MTC_ID as varchar))));
}
}
return res;
}
;
create procedure
"metaWeblog.newMediaObject"
(
in blogid varchar,
in "username" varchar,
in "password" varchar,
in struct any
)
returns any
{
declare url, name, typ, cnt, host, rc, dav_grp, dav_uid any;
declare req "blogRequest";
declare res any;
req := new "blogRequest" ();
req.appkey := 'META_WEBLOG';
req.user_name := "username";
req.passwd := "password";
req.blogId := blogid;
"blogger_auth" (req);
name := get_keyword ('name', struct);
typ := get_keyword ('type', struct);
cnt := get_keyword ('bits', struct);
DB.DBA.DAV_MAKE_DIR (req.blog_phome || 'media/', req.blog_owner, null, '110100100R');
dav_grp := http_nogroup_gid ();
dav_uid := req.blog_owner;
rc := DB.DBA.DAV_RES_UPLOAD (req.blog_phome || 'media/'||name, cnt, typ, '110100100R', dav_uid, dav_grp,
req.user_name, req.passwd);
if (rc < 0)
signal ('22023', DB.DBA.DAV_PERROR (rc));
host := BLOG_GET_HOST ();
url := 'http://' || host || req.blog_lhome || 'media/' || name;
return soap_box_structure ('url', url);
}
;
--
-- BLOGGER CLIENT API
--
create procedure
blogger.new_Post (in uri varchar, in req "blogRequest", in content varchar)
{
declare ret any;
declare postid varchar;
ret := DB.DBA.XMLRPC_CALL (uri, 'blogger.newPost',
vector (req.appkey, req.blogid, req.user_name, req.passwd, content, soap_boolean (1))
, req.header);
ret := xml_tree_doc (ret);
ret := xml_cut (xpath_eval ('//Param1', ret, 1));
postid := soap_box_xml_entity_validating (ret, 'string');
return postid;
}
;
create procedure
blogger.delete_Post (in uri varchar, in req "blogRequest")
{
declare ret any;
ret := DB.DBA.XMLRPC_CALL (uri, 'blogger.deletePost',
vector (req.appkey, req.postId, req.user_name, req.passwd, soap_boolean (1))
, req.header);
return 1;
}
;
create procedure
blogger.edit_Post (in uri varchar, in req "blogRequest", in content varchar)
{
declare ret any;
ret := DB.DBA.XMLRPC_CALL (uri, 'blogger.editPost',
vector (req.appkey, req.postId, req.user_name, req.passwd, content, soap_boolean (1))
, req.header);
return 1;
}
;
create procedure
blogger.get_Post (in uri varchar, in req "blogRequest")
{
declare ret any;
declare post any;
ret := DB.DBA.XMLRPC_CALL (uri, 'blogger.getPost',
vector (req.appkey, req.postId, req.user_name, req.passwd));
ret := xml_tree_doc (ret);
ret := xml_cut (xpath_eval ('//Param1', ret, 1));
post := soap_box_xml_entity_validating (ret, '', 0, 'BLOG.DBA.blogPost');
return post;
}
;
create procedure
blogger.get_Recent_Posts (in uri varchar, in req "blogRequest", in lim int)
{
declare ret, xe, arr any;
declare i, l int;
declare post any;
ret := DB.DBA.XMLRPC_CALL (uri, 'blogger.getRecentPosts',
vector (req.appkey, req.blogid, req.user_name, req.passwd, lim));
ret := xml_tree_doc (ret);
xe := xpath_eval ('//Param1/item', ret, 0);
arr := vector (); i := 0; l := length (xe);
while (i < l)
{
ret := xml_cut (xe[i]);
post := soap_box_xml_entity_validating (ret, '', 0, 'BLOG.DBA.blogPost');
arr := vector_concat (arr, vector(post));
i := i + 1;
}
enf:
return arr;
}
;
create procedure
blogger.get_Users_Blogs (in uri varchar, in req "blogRequest")
{
declare ret, xe, arr any;
declare i, l int;
declare post any;
commit work; -- VERY IMPORTANT TO AVOID DEADLOCK DURING SELF CALLING !!!
ret := DB.DBA.XMLRPC_CALL (uri, 'blogger.getUsersBlogs',
vector (req.appkey, req.user_name, req.passwd));
ret := xml_tree_doc (ret);
xe := xpath_eval ('//Param1/item', ret, 0);
arr := vector (); i := 0; l := length (xe);
while (i < l)
{
declare blogid, blogname, url varchar;
ret := xml_cut (xe[i]);
blogid := cast (xpath_eval ('//blogid/text()', ret, 1) as varchar);
blogname := cast (xpath_eval ('//blogname/text()|//blogName/text()', ret, 1) as varchar);
url := cast (xpath_eval ('//url/text()', ret, 1) as varchar);
post := soap_box_structure ('blogid', blogid, 'blogname', blogname, 'url', url);
arr := vector_concat (arr, vector(post));
i := i + 1;
}
enf:
return arr;
}
;
create procedure
metaweblog.new_Post (in uri varchar, in req "blogRequest")
{
declare ret any;
declare postid varchar;
ret := DB.DBA.XMLRPC_CALL (uri, 'metaWeblog.newPost',
vector (req.blogid, req.user_name, req.passwd, req.struct, soap_boolean (1))
, req.header);
ret := xml_tree_doc (ret);
ret := xml_cut (xpath_eval ('//Param1', ret, 1));
postid := soap_box_xml_entity_validating (ret, 'string');
return postid;
}
;
create procedure
metaweblog.edit_Post (in uri varchar, in req "blogRequest")
{
declare ret any;
ret := DB.DBA.XMLRPC_CALL (uri, 'metaWeblog.editPost',
vector (req.postId, req.user_name, req.passwd, req.struct, soap_boolean (1))
, req.header);
return 1;
}
;
create procedure
metaweblog.get_Post (in uri varchar, in req "blogRequest")
{
declare ret any;
declare post any;
ret := DB.DBA.XMLRPC_CALL (uri, 'metaWeblog.getPost',
vector (req.postId, req.user_name, req.passwd));
ret := xml_tree_doc (ret);
ret := xml_cut (xpath_eval ('//Param1', ret, 1));
post := soap_box_xml_entity_validating (ret, '', 0, 'BLOG.DBA.MWeblogPost');
return post;
}
;
-- xmlStorageSystem API
create procedure
xmlStorageSystem.geterror (in code int)
{
declare err any;
declare ret varchar;
err := vector (
-1, 'The path (target of operation) is not valid',
-2, 'The destination (path) is not valid',
-3, 'Overwrite flag is not set and destination exists',
-4, 'The target is resource, but source is collection (in copy move operations)',
-5, 'Permissions are not valid',
-6, 'uid is not valid',
-7, 'gid is not valid',
-8, 'Target is locked',
-9, 'Destination is locked',
-10, 'Property name is reserved (protected or private)',
-11, 'Property does not exists',
-12, 'Authentication failed',
-13, 'Operation is forbidden (the authenticated user do not have a permissions for the action)',
-14, 'the target type is not valid',
-15, 'The umask is not valid',
-16, 'The property already exists',
-17, 'Invalid property value',
-18, 'no such user',
-19, 'no home directory'
);
ret := get_keyword (code, err, 'Misc.error');
return ret;
}
;
create procedure
xmlStorageSystem.allextensions ()
{
declare res any;
res := vector ();
for select T_EXT from WS.WS.SYS_DAV_RES_TYPES do
{
res := vector_concat (res, vector (T_EXT));
}
return res;
}
;
-- SOAP methods
create procedure
xmlStorageSystem."registerUser"
(
in email varchar,
in name varchar,
in "password" varchar,
in clientPort integer,
in userAgent varchar,
in serialNumber varchar,
out Result any
)
{
declare stat, msg, u_id any;
if (not exists (select 1 from "DB"."DBA"."SYS_USERS" where U_NAME = email))
{
declare pwd, rc, rc1 any;
declare exit handler for sqlstate '*'
{
rollback work;
stat := 1;
msg := __SQL_MESSAGE;
goto errf;
};
u_id := DB.DBA.USER_CREATE (email, "password",
vector ('E-MAIL', email, 'FULL_NAME', name, 'HOME', '/DAV/' || email || '/',
'DAV_ENABLE' , 1, 'SQL_ENABLE', 0, 'clientPort', clientPort,
'maxBytesPerUser', 41943040, 'maxFileSize', 1048576));
pwd := (select pwd_magic_calc (U_NAME, U_PWD, 1) from WS.WS.SYS_DAV_USER where U_NAME = 'dav');
rc := DB.DBA.DAV_COL_CREATE ('/DAV/' || email || '/', '110100000R', email, null, 'dav', pwd);
rc1 := DB.DBA.DAV_COL_CREATE ('/DAV/' || email || '/blog/', '110100100R', email, null, 'dav', pwd);
if (rc <= 0)
signal ('.....', xmlStorageSystem.geterror (rc));
if (rc1 <= 0)
signal ('.....', xmlStorageSystem.geterror (rc1));
stat := 0;
msg := 'Welcome ' || name;
}
else
{
stat := 1;
msg := 'Duplicate name for user.';
}
errf:
Result := soap_box_structure
(
'usernum', email,
'flError', soap_boolean(stat),
'message', msg
);
}
;
create procedure xmlStorageSystem.authenticate (in name1 varchar, inout pwd1 varchar, out base varchar)
{
declare pwd varchar;
declare id int;
whenever not found goto nf;
select pwd_magic_calc (U_NAME, U_PWD, 1), U_ID into pwd, id from WS.WS.SYS_DAV_USER where U_NAME = name1;
if (isstring (pwd))
{
if (md5 (pwd) = pwd1)
{
pwd1 := pwd;
base := DB.DBA.USER_GET_OPTION (name1, 'HOME') || 'blog';
return id;
}
}
nf:
return 0;
}
;
-- XXX: some parameters needed as max ....
create procedure
xmlStorageSystem."getServerCapabilities"
(
in email varchar,
in "password" varchar,
out Result any
)
{
declare base varchar;
if (not xmlStorageSystem.authenticate (email, "password", base))
{
Result := soap_box_structure
(
'flError', soap_boolean(1),
'message', 'Can\'t access because user does not exist or password is incorrect.'
);
return;
}
declare host varchar;
declare quota, maxfs, maxt int;
host := http_request_header (http_request_header (), 'Host', null);
quota := coalesce ((select sum (length (RES_CONTENT)) from WS.WS.SYS_DAV_RES where
RES_FULL_PATH like base || '%'), 0);
maxfs := coalesce (DB.DBA.USER_GET_OPTION (email, 'maxFileSize'), 1048576);
maxt := coalesce (DB.DBA.USER_GET_OPTION (email, 'maxBytesPerUser'), 41943040);
Result := soap_box_structure
(
'community', vector (),
'ctBytesInUse', quota,
'flError', soap_boolean(0),
'flSearchableCommunity', soap_boolean (0),
'legalFileExtensions', xmlStorageSystem.allextensions (),
'maxBytesPerUser', maxt,
'maxFileSize', maxfs,
'message', 'Nice to see you again',
'minutesBetweenPings', 20,
'staticUrls', vector (),
'urlRankingsByPageReads', '',
'weblogUpdates', null,
'yourUpstreamFolderUrl', 'http://' || host || base || '/'
);
}
;
create procedure
xmlStorageSystem."saveMultipleFiles"
(
in email varchar,
in "password" varchar,
in relativepathList any,
in fileTextList any,
out Result any
)
{
declare base varchar;
declare own int;
if (not (own := xmlStorageSystem.authenticate (email, "password", base)))
{
Result := soap_box_structure
(
'flError', soap_boolean(1),
'message', 'Can\'t access because user does not exist or password is incorrect.'
);
return;
}
declare arr any;
declare host, msg varchar;
declare i, l, rc1 int;
declare maxfs, maxt, quota int;
host := http_request_header (http_request_header (), 'Host', null);
arr := vector ();
quota := (select sum (length (RES_CONTENT)) from WS.WS.SYS_DAV_RES where
RES_FULL_PATH like base || '%');
maxfs := coalesce (DB.DBA.USER_GET_OPTION (email, 'maxFileSize'), 1048576);
maxt := coalesce (DB.DBA.USER_GET_OPTION (email, 'maxBytesPerUser'), 41943040);
quota := maxt - quota;
i := 0; l := length (relativepathList);
rc1 := 0; msg := '';
while (i < l)
{
declare rc int;
declare pat any;
declare rel, cont varchar;
rel := relativepathList[i];
if (rel not like '/%')
rel := '/' || rel;
cont := fileTextList[i];
quota := quota - length (cont);
if (length (cont) > maxfs or quota < 0)
{
rc1 := 1;
msg := 'Storage limit exceeded.';
arr := vector_concat (arr, vector (''));
goto nextf;
}
-- TODO: make such thing in DAV API !
pat := WS.WS.PARENT_PATH (WS.WS.HREF_TO_ARRAY (
substring (base || rel, 5, length (base || rel)), ''
));
WS.WS.MKPATH (pat, own, null, '110100100N');
rc := DB.DBA.DAV_RES_UPLOAD (base || rel, cont, '', '110100100N',
email, null, email, "password");
if (rc < 0)
{
rc1 := 1;
msg := xmlStorageSystem.geterror (rc);
}
else
arr := vector_concat (arr, vector ('http://' || host || base || rel));
nextf:
i := i + 1;
}
Result := soap_box_structure
(
'flError', soap_boolean(rc1),
'message', msg,
'urllist', arr,
'yourUpstreamFolderUrl', 'http://' || host || base || '/'
);
}
;
create procedure
xmlStorageSystem."deleteMultipleFiles"
(
in email varchar,
in "password" varchar,
in relativepathList any,
out Result any
)
{
declare base varchar;
declare own int;
if (not (own := xmlStorageSystem.authenticate (email, "password", base)))
{
Result := soap_box_structure
(
'flError', soap_boolean(1),
'message', 'Can\'t access because user does not exist or password is incorrect.'
);
return;
}
declare arr any;
declare host varchar;
declare i, l int;
arr := vector ();
i := 0; l := length (relativepathList);
while (i < l)
{
declare rc int;
declare rel varchar;
rel := relativepathList[i];
if (rel not like '/%')
rel := '/' || rel;
rc := DB.DBA.DAV_DELETE (base || rel, 0, email, "password");
if (rc <> 1)
arr := vector_concat (arr, vector (sprintf ('%s: %s', rel, xmlStorageSystem.geterror (rc))));
else
arr := vector_concat (arr, vector (''));
i := i + 1;
}
Result := soap_box_structure
(
'flError', soap_boolean(0),
'message', '',
'errorList', arr
);
}
;
-- obsoleted
create procedure
xmlStorageSystem."getMyDirectory"
(
in email varchar,
in "password" varchar,
out Result any
)
{
declare base, host varchar;
declare own int;
declare arr any;
declare i int;
if (not (own := xmlStorageSystem.authenticate (email, "password", base)))
{
Result := soap_box_structure
(
'flError', soap_boolean(1),
'message', 'Can\'t access because user does not exist or password is incorrect.'
);
return;
}
host := http_request_header (http_request_header (), 'Host', null);
arr := vector (composite(), '<soap_box_structure>');
for select RES_FULL_PATH, length (RES_CONTENT) as RES_LEN,
RES_CR_TIME, RES_MOD_TIME from WS.WS.SYS_DAV_RES where RES_OWNER = own and RES_FULL_PATH like base || '%'
do
{
declare elm any;
declare rel, url varchar;
url := 'http://' || host || RES_FULL_PATH;
rel := substring (RES_FULL_PATH, length (base) + 1, length (RES_FULL_PATH));
i := i + 1;
elm := soap_box_structure ('relativePath', rel, 'size', RES_LEN, 'url', url, 'whenCreated', RES_CR_TIME, 'whenLastUploaded', RES_MOD_TIME);
arr := vector_concat (arr, vector (sprintf ('file%05d',i), elm));
}
if (i = 0)
arr := soap_box_structure ();
Result := soap_box_structure
(
'directory', arr,
'flError', soap_boolean(0),
'message', '',
'yourUpstreamFolderUrl', 'http://' || host || base || '/'
);
}
;
create procedure
xmlStorageSystem."mailPasswordToUser"
(
in email varchar,
out Result any
)
{
declare base, host, wmast, oeml varchar;
declare own int;
declare arr, pwd any;
declare exit handler for sqlstate '*' {
rollback work;
Result := soap_box_structure
(
'flError', soap_boolean(1),
'message', 'Mail service is not available on that server.'
);
return;
};
whenever not found goto ef;
select pwd_magic_calc (U_NAME, U_PASSWORD, 1), U_E_MAIL into pwd, oeml from "DB"."DBA"."SYS_USERS"
where U_NAME = email;
wmast := coalesce ((select U_E_MAIL from "DB"."DBA"."SYS_USERS"
where U_ID = http_dav_uid ()), 'webmaster@example.domain');
smtp_send (null, wmast, oeml, 'The password for user '||email||' is ' ||pwd|| '.');
ef:
Result := soap_box_structure
(
'flError', soap_boolean(0),
'message', ''
);
}
;
create procedure
xmlStorageSystem."requestNotification"
(
in notifyProcedure varchar,
in port integer,
in path varchar,
in protocol varchar,
in urlList any,
in userinfo any,
out Result any
)
{
declare i, l, rc int;
declare url, msg varchar;
if (protocol not in ('soap', 'xml-rpc'))
{
rc := 1;
msg := 'Not valid protocol identifier';
goto endf;
}
i := 0; l := length (urlList); rc := 0;
url := sprintf ('http://%s:%d%s', http_client_ip (), port, path);
while (i < l)
{
declare hinfo, bid, pdir any;
hinfo := WS.WS.PARSE_URI (urlList[i]);
bid := (select top 1 BI_BLOG_ID from SYS_BLOG_INFO where
BI_HOME = substring (hinfo[2], 1, length (BI_HOME)) order by length (BI_HOME) desc);
if (bid is null)
{
rollback work;
rc := 1;
msg := 'Not valid url';
goto endf;
}
insert replacing SYS_BLOG_CLOUD_NOTIFICATION
(BCN_URL, BCN_BLOG_ID, BCN_TS, BCN_PROTO, BCN_METHOD, BCN_USER_DATA)
values (url, bid, now (), protocol, notifyProcedure, userinfo);
i := i + 1;
}
endf:
Result := soap_box_structure
(
'flError', soap_boolean(rc),
'message', msg
);
}
;
create procedure
xmlStorageSystem."ping"
(
in email varchar,
in "password" varchar,
in status integer,
in clientPort integer,
in userinfo any,
out Result any
)
{
declare base varchar;
declare own int;
if (not (own := xmlStorageSystem.authenticate (email, "password", base)))
{
Result := soap_box_structure
(
'flError', soap_boolean(1),
'message', 'Can\'t access because user does not exist or password is incorrect.'
);
return;
}
declare host varchar;
host := http_request_header (http_request_header (), 'Host', null);
Result := soap_box_structure
(
'flError', soap_boolean(0),
'message', '',
'yourUpstreamFolderUrl', 'http://' || host || base || '/'
);
}
;
grant execute on xmlStorageSystem."registerUser" to DBA
;
grant execute on xmlStorageSystem."getServerCapabilities" to DBA
;
grant execute on xmlStorageSystem."saveMultipleFiles" to DBA
;
grant execute on xmlStorageSystem."deleteMultipleFiles" to DBA
;
grant execute on xmlStorageSystem."getMyDirectory" to DBA
;
grant execute on xmlStorageSystem."mailPasswordToUser" to DBA
;
grant execute on xmlStorageSystem."requestNotification" to DBA
;
grant execute on xmlStorageSystem."ping" to DBA
;
-- XXX: this is obsoleted
--struct xmlStorageSystem.rssPleaseNotify (notifyProcedure, port, path, protocol, urlList)
--
-- XML-RPC wrappers
-- they needed because in XML-RPC method contains the prefix, just like user owner
--
create procedure
BLOG.DBA."xmlStorageSystem.registerUser"
(
in email varchar,
in name varchar,
in "password" varchar,
in clientPort integer,
in userAgent varchar,
in serialNumber varchar,
out Result any
)
{
xmlStorageSystem."registerUser" (email, name, "password", clientPort, userAgent, serialNumber, Result);
}
;
create procedure
BLOG.DBA."xmlStorageSystem.getServerCapabilities"
(
in email varchar,
in "password" varchar,
out Result any
)
{
xmlStorageSystem."getServerCapabilities" (email, "password", Result);
}
;
create procedure
BLOG.DBA."xmlStorageSystem.saveMultipleFiles"
(
in email varchar,
in "password" varchar,
in relativepathList any,
in fileTextList any,
out Result any
)
{
xmlStorageSystem."saveMultipleFiles" (email, "password", relativepathList, fileTextList, Result);
}
;
create procedure
BLOG.DBA."xmlStorageSystem.deleteMultipleFiles"
(
in email varchar,
in "password" varchar,
in relativepathList any,
out Result any
)
{
xmlStorageSystem."deleteMultipleFiles" (email, "password", relativepathList, Result);
}
;
create procedure
BLOG.DBA."xmlStorageSystem.mailPasswordToUser"
(
in email varchar,
out Result any
)
{
xmlStorageSystem."mailPasswordToUser" (email, Result);
}
;
create procedure
BLOG.DBA."xmlStorageSystem.requestNotification"
(
in notifyProcedure varchar,
in port integer,
in path varchar,
in protocol varchar,
in urlList any,
in userinfo any,
out Result any
)
{
xmlStorageSystem."requestNotification" (notifyProcedure, port, path, protocol, urlList, userinfo, Result);
}
;
create procedure
BLOG.DBA."xmlStorageSystem.ping"
(
in email varchar,
in "password" varchar,
in status integer,
in clientPort integer,
in userinfo any,
out Result any
)
{
xmlStorageSystem."ping" (email, "password", status, clientPort, userinfo, Result);
}
;
--
-- Movable Type API
--
create procedure
"mt.supportedMethods" ()
{
return vector (
'blogger.newPost',
'blogger.editPost',
'blogger.deletePost',
'blogger.getPost',
'blogger.getRecentPosts',
'blogger.getUsersBlogs',
'blogger.getTemplate',
'blogger.setTemplate',
'blogger.getUserInfo',
'metaWeblog.newPost',
'metaWeblog.editPost',
'metaWeblog.getPost',
'metaWeblog.getRecentPosts',
'metaWeblog.getCategories',
'metaWeblog.newMediaObject',
'mt.getRecentPostTitles',
'mt.getCategoryList',
'mt.setPostCategories',
'mt.getPostCategories',
'mt.getTrackbackPings',
'mt.publishPost',
'mt.supportedMethods',
'mt.supportedTextFilters',
'subsHarmonizer.setup',
'subsHarmonizer.startup',
'subsHarmonizer.subscribe',
'subsHarmonizer.unsubscribe',
'xmlStorageSystem.getServerCapabilities',
'xmlStorageSystem.saveMultipleFiles',
'xmlStorageSystem.deleteMultipleFiles',
'xmlStorageSystem.getMyDirectory',
'xmlStorageSystem.mailPasswordToUser',
'xmlStorageSystem.requestNotification',
'xmlStorageSystem.ping'
);
}
;
create procedure "mt.supportedTextFilters" ()
{
return vector (soap_box_structure ('key', '0', 'label', 'default'));
}
;
create procedure
"mt.getRecentPostTitles" (in blogid varchar, in "username" varchar, in "password" varchar, in numberOfPosts int)
{
declare req "blogRequest";
req := new "blogRequest" ();
req.user_name := "username";
req.passwd := "password";
req.blogId := blogid;
"blogger_auth" (req);
{
declare ret, elm any;
declare post, userid, tit any;
ret := vector ();
for select B_CONTENT, B_TS, B_USER_ID, B_POST_ID, B_META
from SYS_BLOGS where B_BLOG_ID = req.blogId order by B_TS desc do
{
tit := BLOG_GET_TEXT_TITLE (B_META, B_CONTENT);
userid := (select U_NAME from "DB"."DBA"."SYS_USERS" where U_ID = B_USER_ID);
post := soap_box_structure ('dateCreated', B_TS,'userid', userid,'postid', B_POST_ID, 'title', tit);
ret := vector_concat (ret, vector (post));
numberOfPosts := numberOfPosts - 1;
if (numberOfPosts <= 0)
goto endg;
}
endg:
return ret;
}
}
;
create procedure
"mt.getCategoryList" (in blogid varchar, in "username" varchar, in "password" varchar)
{
declare req "blogRequest";
req := new "blogRequest" ();
req.user_name := "username";
req.passwd := "password";
req.blogId := blogid;
"blogger_auth" (req);
declare ret, post any;
ret := vector ();
for select MTC_ID, MTC_NAME from MTYPE_CATEGORIES where MTC_BLOG_ID = req.blogId do
{
post := soap_box_structure ('categoryId', MTC_ID, 'categoryName', MTC_NAME);
ret := vector_concat (ret, vector (post));
}
-- Zempt kludge
if (length(ret) = 0)
ret := vector (soap_box_structure ('categoryId', '0', 'categoryName', 'default'));
return ret;
}
;
create procedure
"mt.setPostCategories" (in postid varchar, in "username" varchar, in "password" varchar, in categories any)
{
declare req "blogRequest";
req := new "blogRequest" ();
req.user_name := "username";
req.passwd := "password";
req.postId := postid;
"blogger_auth" (req);
declare i, l int;
declare blogId varchar;
declare meta BLOG.DBA."MWeblogPost";
declare cats, cat_name any;
whenever not found goto error_end;
select B_BLOG_ID, B_META into blogId, meta from SYS_BLOGS where B_POST_ID = postid;
delete from MTYPE_BLOG_CATEGORY where MTB_BLOG_ID = blogId and MTB_POST_ID = postid;
i := 0; l := length (categories); cats := vector ();
while (i < l)
{
declare cat any;
declare categoryId varchar;
declare isPrimary int;
cat := categories[i];
categoryId := get_keyword ('categoryId', cat);
isPrimary := get_keyword ('isPrimary', cat);
whenever not found goto nextcat;
select MTC_NAME into cat_name from MTYPE_CATEGORIES where MTC_ID = categoryId and MTC_BLOG_ID = blogId;
insert replacing MTYPE_BLOG_CATEGORY (MTB_CID , MTB_POST_ID, MTB_BLOG_ID, MTB_PRIMARY)
values (categoryId, postid, blogId, isPrimary);
cats := vector_concat (cats, vector (cat_name));
nextcat:
i := i + 1;
}
if (length (cats) > 0)
{
meta.categories := cats;
update SYS_BLOGS set B_META = meta where B_POST_ID = postid;
}
return soap_boolean (1);
error_end:
signal ('22023', sprintf ('No post with #%s', postid));
}
;
create procedure
"mt.getPostCategories" (in postid varchar, in "username" varchar, in "password" varchar)
{
declare req "blogRequest";
req := new "blogRequest" ();
req.user_name := "username";
req.passwd := "password";
req.postId := postid;
"blogger_auth" (req);
declare ret, post any;
ret := vector ();
for select MTB_CID, MTC_NAME, coalesce (MTB_PRIMARY, 0) as MTB_PRIMARY from BLOG..MTYPE_BLOG_CATEGORY,
BLOG..MTYPE_CATEGORIES where
MTB_POST_ID = postid and MTB_CID = MTC_ID and MTC_BLOG_ID = MTB_BLOG_ID do {
post := soap_box_structure ('categoryName', MTC_NAME, 'categoryId', MTB_CID,
'isPrimary', soap_boolean (MTB_PRIMARY));
ret := vector_concat (ret, vector (post));
}
-- Zempt kludge
if (length(ret) = 0)
ret := vector (soap_box_structure ('categoryName','default', 'categoryId','0','isPrimary',soap_boolean (0)));
return ret;
}
;
create procedure
"mt.getTrackbackPings" (in postid varchar)
{
declare ret any;
ret := vector ();
for select MP_TITLE, MP_URL, MP_IP from MTYPE_TRACKBACK_PINGS where MP_POST_ID = postid
do
{
declare stru any;
stru := soap_box_structure ('pingTitle', MP_TITLE, 'pingURL', MP_URL, 'pingIP' , MP_IP);
ret := vector_concat (ret, vector (stru));
}
return ret;
}
;
create procedure
"mt.publishPost" (in postid varchar, in "username" varchar, in "password" varchar)
{
return soap_boolean (1);
}
;
-- DEFAULT BLOG SITE
create procedure
BLOG_UPLOAD_FILE (in f varchar, in dir varchar, in pwd any)
{
declare cnt varchar;
declare rc any;
if (isstring (file_stat (http_root () || f)))
{
cnt := file_to_string (http_root () || f);
if (not exists (select 1 from WS.WS.SYS_DAV_RES
where RES_FULL_PATH = dir || f and md5(blob_to_string (RES_CONTENT)) = md5(cnt)))
{
rc := DB.DBA.DAV_MAKE_DIR (dir||f, http_dav_uid (), null, '110100100N');
rc := DB.DBA.DAV_RES_UPLOAD_STRSES_INT (dir || f, cnt, '', '110100100N', http_dav_uid (), null, 'dav', pwd, 0);
return rc;
}
}
return 0;
}
;
create procedure
BLOG_GET_HOST ()
{
declare ret varchar;
declare default_host varchar;
if (is_http_ctx ())
{
ret := http_request_header (http_request_header (), 'Host', null, sys_connected_server_address ());
if (isstring (ret) and strchr (ret, ':') is null)
{
declare hp varchar;
declare hpa any;
hp := sys_connected_server_address ();
hpa := split_and_decode (hp, 0, '\0\0:');
if (hpa[1] <> '80')
ret := ret || ':' || hpa[1];
}
}
else
{
default_host := cfg_item_value (virtuoso_ini_path (), 'URIQA', 'DefaultHost');
if (default_host is not null)
return default_host;
ret := sys_stat ('st_host_name');
if (server_http_port () <> '80')
ret := ret ||':'|| server_http_port ();
}
return ret;
}
;
create procedure
BLOG_GET_HOME_DIR (inout home varchar)
{
if (is_http_ctx ())
{
declare p varchar;
p := http_path ();
if (concat (home , 'gems/rss.xml') = p)
return home;
if (p like '%/gems/rss.xml')
return substring (p, 1, length (p) - 12);
else
return home;
}
else
return home;
}
;
create procedure
BLOG_TIDY_HTML (inout cnt any, in filter varchar := null)
{
return BLOG_POST_RENDER (cnt, filter);
}
;
create procedure
BLOG_POST_RENDER (inout cnt any, in filter varchar := null, in owner int := null)
{
declare ss any;
declare xt any;
declare davacc any;
declare add_table int;
add_table := 0;
davacc := connection_get ('DAVUserID');
ss := string_output ();
xt := xml_tree_doc (xml_tree (cnt, 2, '', 'UTF-8'));
xml_tree_doc_encoding (xt, 'utf-8');
if (filter = '*default*')
xt := xslt (BLOG2_GET_PPATH_URL ('widgets/blog_tidy.xsl'), xt);
else if (isstring (filter) and filter <> '' and xslt_is_sheet (filter))
xt := xslt (filter, xt);
if (xpath_eval ('//tr[not ancestor::table]|//td[not ancestor::table]', xt) is not null)
add_table := 1;
xml_tree_doc_set_output (xt, 'xhtml');
if (owner is null or xpath_eval ('[ xmlns:sql="urn:schemas-openlink-com:xml-sql" ] //sql:*', xt, 1) is null)
{
http_value (xt, null, ss);
}
else
{
declare dummy int;
declare exit handler for sqlexception, not found
{
http_value (xt, null, ss);
goto endprint;
};
select set_user_id (U_NAME, 1) into dummy from "DB"."DBA"."SYS_USERS" where U_ID = owner;
connection_set ('DAVUserID', owner);
xml_template (xt, null, ss);
}
endprint:
connection_set ('DAVUserID', davacc);
if (add_table)
return '<table>'||string_output_string (ss)||'</table>';
else
return string_output_string (ss);
}
;
create procedure BLOG_META_KWD_NORMALIZE (in str varchar)
{
declare tmp, part varchar;
declare res varchar;
tmp := cast (str as varchar);
res := ''; part := null;
while (1)
{
part := regexp_match ('[^\ ,;]+([\ \t][0-9\.]*[,;]*)*', tmp, 1);
if (part is null)
return rtrim (res, ', ');
res := concat (res, rtrim (part, ', '), ', ');
}
return res;
}
;
create procedure
BLOG_FEED_AGREGATOR (in rs int := 0)
{
declare uri, format, tag varchar;
declare rc, err int;
declare bm any;
declare cr static cursor for select BCD_CHANNEL_URI, BCD_FORMAT, BCD_TAG
from SYS_BLOG_CHANNEL_INFO where (BCD_LAST_UPDATE is null
or dateadd ('minute', BCD_UPDATE, BCD_LAST_UPDATE) < now ()) and BCD_ERROR_LOG is null;
-- no longer supported in blog2
return;
if (rs)
result_names (uri, rc);
bm := null; err := 0;
whenever not found goto enf;
open cr (exclusive, prefetch 1);
fetch cr first into uri, format, tag;
while (1)
{
bm := bookmark (cr);
err := 0;
close cr;
if (format in ('OCS', 'OPML'))
{
err := 1;
goto next;
}
{
declare exit handler for sqlstate '*' {
rollback work;
if (__SQL_STATE <> '40001')
{
update SYS_BLOG_CHANNEL_INFO set BCD_ERROR_LOG = __SQL_STATE || ' ' || __SQL_MESSAGE
where BCD_CHANNEL_URI = uri;
commit work;
}
else
resignal;
err := 1;
goto next;
};
rc := BLOG.DBA.BLOG_FEED_URI (uri, format, tag);
if (rs)
result (uri, rc);
}
update SYS_BLOG_CHANNEL_INFO set BCD_LAST_UPDATE = now (), BCD_TAG = tag, BCD_ERROR_LOG = null
where BCD_CHANNEL_URI = uri;
commit work;
next:
open cr (exclusive, prefetch 1);
fetch cr bookmark bm into uri, format, tag;
if (err)
fetch cr next into uri, format, tag;
}
enf:
close cr;
return;
}
;
create procedure
BLOG_FEED_URI (in uri varchar, in format varchar, inout tag varchar)
{
declare content varchar;
declare hdr any;
declare xt any;
declare items any;
declare i, l int;
declare new_tag, typef, olduri varchar;
olduri := uri;
again:
content := http_get (uri, hdr);
if (hdr[0] not like 'HTTP/1._ 200 %')
{
if (hdr[0] like 'HTTP/1._ 30_ %')
{
uri := http_request_header (hdr, 'Location');
if (isstring (uri))
goto again;
}
signal ('22023', trim(hdr[0], '\r\n'), 'BLOG0');
return 0;
}
new_tag := http_request_header (hdr, 'ETag');
typef := http_request_header (hdr, 'Content-Type', null, 'text/xml');
if (not isstring (new_tag))
new_tag := md5 (content);
if (new_tag = tag)
return 0;
tag := new_tag;
BLOG_STORE_CHANNEL_FEED (olduri, content, typef);
--return 0;
-- get content-type, response; handle redirect; handle not found; handle not modified
xt := xml_tree_doc (xml_tree (content));
-- RSS formats
if (xpath_eval ('/rss/channel/item|/RDF/item', xt) is not null)
{
items := xpath_eval ('/rss/channel/item|/RDF/item', xt, 0);
i := 0; l := length (items);
while (i < l)
{
BLOG_PROCESS_RSS_ITEM (xml_cut (items[i]), olduri);
i := i + 1;
}
}
else if (xpath_eval ('/feed/entry', xt) is not null)
{
items := xpath_eval ('/feed/entry', xt, 0);
i := 0; l := length (items);
while (i < l)
{
BLOG_PROCESS_ATOM_ITEM (xml_cut (items[i]), olduri);
i := i + 1;
}
}
return i;
}
;
create procedure BLOG_STORE_CHANNEL_FEED (in uri varchar, inout content any, in typef varchar,
in target_folder varchar := null)
{
declare suff, qs varchar;
declare nfo any;
nfo := WS.WS.PARSE_URI (uri);
suff := 'rss_feeds/' || nfo[1] || nfo[2];
if (nfo[4] <> '')
{
--declare i, l int;
--qs := split_and_decode (nfo[4]);
--i := 0; l := length (qs);
--while (i < l)
-- {
-- if (qs[i+1] is not null)
-- suff := suff || '/' || qs[i+1];
-- else
-- suff := suff || '/' || qs[i];
-- i := i + 2;
-- }
suff := suff || '/' || DB.DBA.SYS_ALFANUM_NAME (nfo[4]);
}
if (target_folder is not null)
{
declare arr any;
arr := WS.WS.HREF_TO_ARRAY (nfo[2], '');
suff := 'rss_feeds/' || target_folder || '/' || arr [length (arr)-1];
}
if (typef <> 'text/xml')
typef := http_mime_type (nfo[2]);
for select BC_BLOG_ID as _BC_BLOG_ID, BI_P_HOME, BI_OWNER, BCD_TITLE from SYS_BLOG_CHANNELS, SYS_BLOG_INFO, SYS_BLOG_CHANNEL_INFO where BCD_CHANNEL_URI = BC_CHANNEL_URI and BC_CHANNEL_URI = uri and BI_BLOG_ID = BC_BLOG_ID do
{
declare pat, bid varchar;
declare rc int;
bid := _BC_BLOG_ID;
pat := BI_P_HOME || suff;
rc := DB.DBA.DAV_MAKE_DIR (pat, BI_OWNER, null, '110100100R');
rc := DB.DBA.DAV_RES_UPLOAD_STRSES_INT (pat, content, typef, '110100100R', BI_OWNER, null, null, null, 0);
rc := DB.DBA.BLOG2_DAV_PROP_SET (pat, 'displayName', BCD_TITLE, null, null, 0);
rc := DB.DBA.BLOG2_DAV_PROP_SET (pat, 'sourceURL', uri, null, null, 0);
update SYS_BLOG_CHANNELS set BC_LOCAL_RES = pat where BC_BLOG_ID = bid and BC_CHANNEL_URI = uri;
}
}
;
create procedure
BLOG_PROCESS_RSS_ITEM (inout xt any, inout uri varchar)
{
declare title, description, link, guid, pubdate varchar;
declare nid int;
declare comment_api, comment_rss varchar;
title := serialize_to_UTF8_xml(xpath_eval ('string(/item/title)', xt, 1));
description := serialize_to_UTF8_xml(xpath_eval ('string(/item/description)', xt, 1));
link := cast (xpath_eval ('/item/link', xt, 1) as varchar);
guid := cast (xpath_eval ('/item/guid', xt, 1) as varchar);
pubdate := cast (xpath_eval ('/item/pubDate', xt, 1) as varchar);
comment_api := cast (xpath_eval ('[ xmlns:wfw="http://wellformedweb.org/CommentAPI/" ] /item/wfw:comment', xt, 1) as varchar);
comment_rss := cast (xpath_eval ('[ xmlns:wfw="http://wellformedweb.org/CommentAPI/" ] /item/wfw:commentRss', xt, 1) as varchar);
if (guid is null)
guid := link;
if (exists (select 1 from SYS_BLOG_CHANNEL_FEEDS where CF_CHANNEL_URI = uri and CF_GUID = guid))
return;
nid := 0;
for select top 1 CF_ID from SYS_BLOG_CHANNEL_FEEDS where CF_CHANNEL_URI = uri order by CF_ID desc for update do
{
nid := CF_ID;
}
nid := nid + 1;
insert into SYS_BLOG_CHANNEL_FEEDS
(CF_ID, CF_CHANNEL_URI, CF_TITLE, CF_DESCRIPTION, CF_LINK, CF_GUID, CF_PUBDATE, CF_COMMENT_API, CF_COMMENT_RSS)
values
(nid, uri, title, description, link, guid, now (), comment_api, comment_rss);
}
;
create procedure
BLOG_PROCESS_ATOM_ITEM (inout xt any, inout uri varchar)
{
declare title, description, link, guid, pubdate varchar;
declare nid int;
declare comment_api, comment_rss varchar;
title := cast (xpath_eval ('/entry/title', xt, 1) as varchar);
description := cast (xpath_eval ('/entry/content', xt, 1) as varchar);
link := cast (xpath_eval ('/entry/link[@rel="alternate"]/@href', xt, 1) as varchar);
guid := cast (xpath_eval ('/entry/id', xt, 1) as varchar);
pubdate := cast (xpath_eval ('/entry/created', xt, 1) as varchar);
comment_api := NULL;
comment_rss := NULL;
if (guid is null)
guid := link;
if (exists (select 1 from SYS_BLOG_CHANNEL_FEEDS where CF_CHANNEL_URI = uri and CF_GUID = guid))
return;
nid := 0;
for select top 1 CF_ID from SYS_BLOG_CHANNEL_FEEDS where CF_CHANNEL_URI = uri order by CF_ID desc for update do
{
nid := CF_ID;
}
nid := nid + 1;
insert into SYS_BLOG_CHANNEL_FEEDS
(CF_ID, CF_CHANNEL_URI, CF_TITLE, CF_DESCRIPTION, CF_LINK, CF_GUID, CF_PUBDATE, CF_COMMENT_API, CF_COMMENT_RSS)
values
(nid, uri, title, description, link, guid, now (), comment_api, comment_rss);
}
;
--insert soft "DB"."DBA"."SYS_SCHEDULED_EVENT" (SE_NAME, SE_START, SE_SQL, SE_INTERVAL)
-- values ('Weblog News aggregator', now(), 'BLOG.DBA.BLOG_FEED_AGREGATOR (0)', 10)
--;
delete from "DB"."DBA"."SYS_SCHEDULED_EVENT" where SE_NAME = 'Weblog Ping notifications';
blog2_exec_no_error ('drop procedure BLOG.DBA.BLOG_SEND_PINGS');
insert soft "DB"."DBA"."SYS_SCHEDULED_EVENT" (SE_NAME, SE_START, SE_SQL, SE_INTERVAL)
values ('Weblog notifications', now(), 'BLOG.DBA.BLOG_SEND_NOTIFICATIONS ()', 10)
;
-- MAIL NOTIFICATION AND POP3 retrieval
create procedure BLOG_SEND_NOTIFICATIONS ()
{
declare nw, last datetime;
declare opts any;
declare mailgw varchar;
declare start_blog varchar;
declare _BI_HOME, _BI_OWNER, _BI_BLOG_ID, _BI_TITLE, _BI_PINGS, _BI_OPTIONS, _U_NAME any;
set isolation='committed';
mailgw := '';
start_blog := '';
nw := now ();
last := registry_get ('blogger.last.ping');
if (isstring (last))
{
last := stringdate (last);
}
else
{
last := stringdate ('1970-01-01');
}
declare wmast, replyto, repltext varchar;
wmast := coalesce ((select U_E_MAIL from "DB"."DBA"."SYS_USERS" where U_ID = http_dav_uid ()), 'webmaster@example.domain');
commit work;
whenever not found goto enf;
while (1)
{
--dbg_obj_print ('pinging current blog: ', _BI_BLOG_ID, _U_NAME);
select top 1 BI_HOME, BI_OWNER, BI_BLOG_ID, BI_TITLE, BI_PINGS, BI_OPTIONS, U_NAME
into
_BI_HOME, _BI_OWNER, _BI_BLOG_ID, _BI_TITLE, _BI_PINGS, _BI_OPTIONS, _U_NAME
from SYS_BLOG_INFO, "DB"."DBA"."SYS_USERS"
where U_ID = BI_OWNER and BI_BLOG_ID > start_blog order by BI_BLOG_ID with (prefetch 1);
start_blog := _BI_BLOG_ID;
declare pop3s, pop3u, pop3p varchar;
opts := deserialize (blob_to_string (_BI_OPTIONS));
if (not isarray (opts) or isstring (opts))
opts := vector ();
pop3s := get_keyword ('POP3Server', opts, '');
pop3u := get_keyword ('POP3Account', opts, '');
pop3p := get_keyword ('POP3Passwd', opts, '');
BLOG_GET_MAIL_VIA_POP3 (pop3s, pop3u, pop3p, _U_NAME);
commit work;
}
enf:
--dbg_obj_print ('done');
-- check the mail for comment API gateway
{
declare pop3s, pop3u, pop3p, _u_name1 varchar;
_u_name1 := registry_get ('blogger.commentAPI.email');
if (isstring (_u_name1) and exists (select 1 from WS.WS.SYS_DAV_USER where U_NAME = _u_name1))
{
pop3s := DB.DBA.USER_GET_OPTION (_u_name1, 'POP3Server');
pop3u := DB.DBA.USER_GET_OPTION (_u_name1, 'POP3Account');
pop3p := DB.DBA.USER_GET_OPTION (_u_name1, 'POP3Passwd');
mailgw := DB.DBA.USER_GET_OPTION (_u_name1, 'E-MAIL');
BLOG_GET_MAIL_VIA_POP3 (pop3s, pop3u, pop3p, _u_name1);
commit work;
}
}
delete from SYS_BLOG_CLOUD_NOTIFICATION where dateadd ('hour', 25, BCN_TS) < now ();
commit work;
for select BCN_URL, BCN_BLOG_ID, BCN_TS, BCN_PROTO, BCN_METHOD, BCN_USER_DATA
from SYS_BLOG_CLOUD_NOTIFICATION do
{
if (exists (select 1 from SYS_BLOGS where B_BLOG_ID = BCN_BLOG_ID and B_TS > last))
{
declare exit handler for sqlstate '*' { goto next1; };
if (BCN_PROTO = 'xml-rpc')
DB.DBA.XMLRPC_CALL (BCN_URL, BCN_METHOD, vector (BCN_USER_DATA));
else if (BCN_PROTO = 'soap')
DB.DBA.SOAP_CLIENT (url=>BCN_URL, operation=>BCN_METHOD, parameters=>vector (), soap_action=>'');
}
next1:;
}
replyto := '';
if (mailgw <> '')
{
replyto := 'Reply-To:'||mailgw||'\r\n';
}
BLOG_SEND_EMAIL_NOTIFICATIONS (last, wmast, replyto);
registry_set ('blogger.last.ping', datestring (nw));
BLOG_SEND_TB_NOTIFY (wmast);
return;
}
;
create procedure BLOG_SEND_EMAIL_NOTIFICATIONS (in last any, in wmast varchar, in replyto varchar)
{
declare opts any;
declare def_host varchar;
declare BI_E_MAIL, BI_HOME, U_FULL_NAME, BM_E_MAIL, BM_POST_ID, BM_COMMENT, BM_POSTED_VIA, BM_NAME,
B_CONTENT, B_META, BI_OPTIONS, B_BLOG_ID, BI_COMMENTS_NOTIFY, BM_IS_SPAM, BM_IS_PUB, BM_ID, BI_BLOG_ID, BM_TS any;
declare own_comment int;
set isolation='committed';
whenever not found goto enf;
def_host := BLOG_GET_HOST ();
while (1)
{
select top 1 bi.BI_E_MAIL, bi.BI_HOME, u.U_FULL_NAME, bc.BM_E_MAIL, bc.BM_POST_ID, bc.BM_COMMENT, bc.BM_POSTED_VIA, bc.BM_NAME,
b.B_CONTENT, b.B_META, bi.BI_OPTIONS, b.B_BLOG_ID, bi.BI_COMMENTS_NOTIFY, bc.BM_IS_SPAM, bc.BM_IS_PUB, bc.BM_ID,
bi.BI_BLOG_ID, bc.BM_TS, bc.BM_OWN_COMMENT
into
BI_E_MAIL, BI_HOME, U_FULL_NAME, BM_E_MAIL, BM_POST_ID, BM_COMMENT, BM_POSTED_VIA, BM_NAME, B_CONTENT,
B_META, BI_OPTIONS, B_BLOG_ID, BI_COMMENTS_NOTIFY, BM_IS_SPAM, BM_IS_PUB, BM_ID, BI_BLOG_ID, BM_TS,
own_comment
from
BLOG_COMMENTS bc, SYS_BLOG_INFO bi, SYS_BLOGS b, "DB"."DBA"."SYS_USERS" u where
bi.BI_COMMENTS_NOTIFY > 0 and bc.BM_BLOG_ID = bi.BI_BLOG_ID and bi.BI_OWNER = u.U_ID
and b.B_POST_ID = bc.BM_POST_ID and b.B_BLOG_ID = bi.BI_BLOG_ID
and bc.BM_TS > last order by bc.BM_TS option (order) with (prefetch 1);
last := BM_TS;
if (own_comment = 1)
{
goto next2;
}
--dbg_obj_print ('sending comment mail:', BI_BLOG_ID, BM_ID, BM_E_MAIL, BI_E_MAIL);
declare exit handler for sqlstate '*' {
log_message ('BLOG NF: '|| __SQL_MESSAGE);
goto next2;
};
declare tit any;
declare msg, p1, p2, p3 any;
declare _mime_parts any;
declare post_url, comment_url, tp, host, appr_url varchar;
opts := deserialize (blob_to_string (BI_OPTIONS));
if (not isarray (opts) or isstring (opts))
opts := vector ();
tit := BLOG_GET_TEXT_TITLE (B_META, B_CONTENT);
tit := cast (tit as varchar);
host := def_host;
commit work;
post_url := sprintf ('http://%s%s?id=%s', host, BI_HOME, BM_POST_ID);
comment_url := sprintf ('http://%s/mt-tb/Http/comments?id=%s', host, BM_POST_ID);
appr_url := sprintf ('http://%s/weblog/public/c_confirm.vspx?blogid=%U&postid=%U&commentid=%d', host, BI_BLOG_ID,
BM_POST_ID, BM_ID);
if (BI_COMMENTS_NOTIFY = 1)
{
_mime_parts := DB.DBA.MIME_PART ('text/html; charset=UTF-8', 'inline', null,
BLOG_COMMENT_NF_HTML_FORM (post_url, comment_url, tit, U_FULL_NAME, BI_E_MAIL, BM_NAME, BM_E_MAIL, blob_to_string (BM_COMMENT), B_BLOG_ID, BM_POST_ID, BM_IS_PUB, BM_IS_SPAM, appr_url));
}
else if (BI_COMMENTS_NOTIFY = 2)
{
_mime_parts := DB.DBA.MIME_PART ('text/html; charset=UTF-8', 'inline', null,
BLOG_COMMENT_NF_HTML (post_url, comment_url, tit, U_FULL_NAME, BI_E_MAIL, BM_NAME, BM_E_MAIL, blob_to_string (BM_COMMENT), B_BLOG_ID, BM_POST_ID, BM_IS_PUB, BM_IS_SPAM, appr_url));
}
else if (BI_COMMENTS_NOTIFY = 4)
{
declare part_txt, part_html, part_form any;
part_txt := DB.DBA.MIME_PART ('text/plain; charset=UTF-8', null, null, BLOG_COMMENT_NF_TEXT (post_url, comment_url, tit, U_FULL_NAME, BI_E_MAIL, BM_NAME, BM_E_MAIL, blob_to_string (BM_COMMENT), B_BLOG_ID, BM_POST_ID, BM_IS_PUB, BM_IS_SPAM, appr_url));
part_html := DB.DBA.MIME_PART ('text/html; charset=UTF-8', null, null, BLOG_COMMENT_NF_HTML (post_url, comment_url, tit, U_FULL_NAME, BI_E_MAIL, BM_NAME, BM_E_MAIL, blob_to_string (BM_COMMENT), B_BLOG_ID, BM_POST_ID, BM_IS_PUB, BM_IS_SPAM, appr_url));
part_form := DB.DBA.MIME_PART ('text/html; charset=UTF-8', 'attachment', 'base64', BLOG_COMMENT_NF_FORM (post_url, comment_url, tit, U_FULL_NAME, BI_E_MAIL, BM_NAME, BM_E_MAIL, blob_to_string (BM_COMMENT), B_BLOG_ID, BM_POST_ID, BM_IS_PUB, BM_IS_SPAM, appr_url));
_mime_parts := vector (part_txt, part_html, part_form);
}
else
{
_mime_parts := BLOG_COMMENT_NF_TEXT (post_url, comment_url, tit, U_FULL_NAME, BI_E_MAIL, BM_NAME, BM_E_MAIL, blob_to_string (BM_COMMENT), B_BLOG_ID, BM_POST_ID, BM_IS_PUB, BM_IS_SPAM, appr_url);
replyto := concat (replyto, 'Content-Type: text/plain; charset=UTF-8\r\n');
}
msg := concat (replyto, BLOG_MAKE_MAIL_SUBJECT ('[Weblog notification] '||tit), DB.DBA.MIME_BODY (_mime_parts));
smtp_send (null, wmast, BI_E_MAIL, msg);
next2:;
}
enf:;
--dbg_obj_print ('done.');
}
;
create procedure BLOG_GET_MAIL_VIA_POP3 (in pop3s varchar, in pop3u varchar, in pop3p varchar, in _u_name varchar)
{
if (pop3s <> '' and pop3u <> '' and pop3p <> '')
{
declare res any;
declare inx, len, cert int;
declare mess, elm any;
declare exit handler for sqlstate '*' { goto nextu; };
commit work;
if (pop3s like '%:995')
cert := 1;
else
cert := 0;
res := pop3_get (pop3s, pop3u, pop3p, 999999999, '', null, cert);
inx := 0; len := length (res);
while (inx < len)
{
mess := aref (aref (res, inx), 1);
elm := mail_header (mess, 'Message-Id');
if (not exists (select 1 from "DB"."DBA"."MAIL_MESSAGE" where MM_MSG_ID = elm and MM_OWN = _u_name))
{
DB.DBA.NEW_MAIL (_u_name, mess);
commit work;
}
inx := inx + 1;
}
}
nextu:;
return;
}
;
create procedure BLOG_SEND_TB_NOTIFY (in wmast varchar)
{
declare nw, last datetime;
declare opts any;
declare mailgw varchar;
declare def_host varchar;
declare BI_E_MAIL, BI_HOME, U_FULL_NAME, MP_POST_ID, MP_EXCERPT, MP_URL, MP_TITLE, MP_BLOG_NAME, MP_VIA_DOMAIN, B_CONTENT, B_TITLE, B_BLOG_ID, MP_IS_SPAM, MP_IS_PUB, MP_TS any;
def_host := BLOG_GET_HOST ();
mailgw := '';
nw := now ();
last := registry_get ('blogger.last.tb_notification');
if (isstring (last))
{
last := stringdate (last);
}
else
{
last := stringdate ('1970-01-01');
}
declare replyto, repltext varchar;
set isolation='committed';
whenever not found goto enf;
while (1)
{
select top 1 bi.BI_E_MAIL, bi.BI_HOME, u.U_FULL_NAME, tb.MP_POST_ID, tb.MP_EXCERPT, tb.MP_URL,
tb.MP_TITLE, tb.MP_BLOG_NAME, tb.MP_VIA_DOMAIN,
b.B_CONTENT, b.B_TITLE, b.B_BLOG_ID, tb.MP_IS_SPAM, tb.MP_IS_PUB, tb.MP_TS
into
BI_E_MAIL, BI_HOME, U_FULL_NAME, MP_POST_ID, MP_EXCERPT, MP_URL, MP_TITLE, MP_BLOG_NAME, MP_VIA_DOMAIN,
B_CONTENT, B_TITLE, B_BLOG_ID, MP_IS_SPAM, MP_IS_PUB, MP_TS
from
SYS_BLOG_INFO bi, "DB"."DBA"."SYS_USERS" u, MTYPE_TRACKBACK_PINGS tb, SYS_BLOGS b where
b.B_POST_ID = tb.MP_POST_ID and b.B_BLOG_ID = bi.BI_BLOG_ID and
bi.BI_TB_NOTIFY > 0 and bi.BI_OWNER = u.U_ID
and tb.MP_TS > last order by tb.MP_TS with (prefetch 1);
last := MP_TS;
--dbg_obj_print ('tb:', MP_POST_ID, MP_TITLE);
declare exit handler for sqlstate '*' {
log_message ('BLOG NF: '|| __SQL_MESSAGE);
goto next2;
};
declare tit any;
declare msg, p1, p2, p3 any;
declare _mime_parts any;
declare post_url, tb_url, tp, host varchar;
MP_EXCERPT := blob_to_string (MP_EXCERPT);
commit work;
tit := cast (B_TITLE as varchar);
host := def_host;
post_url := sprintf ('http://%s%s?id=%s', host, BI_HOME, MP_POST_ID);
tb_url := sprintf ('http://%s//mt-tb/Http/trackback?id=%s', host, MP_POST_ID);
_mime_parts := DB.DBA.MIME_PART ('text/plain; charset=UTF-8', null, null,
BLOG_TB_NF_TEXT (post_url, tb_url, tit, U_FULL_NAME, BI_E_MAIL, MP_BLOG_NAME, MP_URL,
MP_EXCERPT, B_BLOG_ID, MP_POST_ID, MP_TITLE, MP_IS_PUB, MP_IS_SPAM, ''));
replyto := '';
msg := concat (replyto, BLOG_MAKE_MAIL_SUBJECT ('[Weblog trackback/pingback notification] '||tit),
DB.DBA.MIME_BODY (_mime_parts));
smtp_send (null, wmast, BI_E_MAIL, msg);
next2:;
}
enf:
--dbg_obj_print ('done tb');
registry_set ('blogger.last.tb_notification', datestring (nw));
return;
}
;
-- end of MAIL notification and POP3 retrieval
create procedure
BLOG_COMMENT_NF_HTML (
in post_url varchar,
in comment_url varchar,
in title varchar,
in b_name varchar,
in b_mail varchar,
in v_name varchar,
in v_mail varchar,
in comment_body varchar,
in blogid varchar,
in postid varchar,
in pub int,
in spam int,
in appr_url varchar
)
{
declare ses any;
ses := string_output ();
http ('<html>\n', ses);
http (' <p>Your blog post\n', ses);
http (sprintf (' <a href="%s#comments">"%s"</a> has just been updated with a post from\n',post_url,title), ses);
http (sprintf (' <a href="mailto:%s">%s</a>.</p>\n',v_mail,v_name), ses);
if (not pub)
http ('<p>The comment was moderated and needs your approval.</p>', ses);
else
http ('<p>The comment was published on your blog.</p>', ses);
if (spam)
http ('<p>The comment was rated as a SPAM.</p>', ses);
if (spam or not pub)
{
http (sprintf ('<p>To accept the comment click on following link : <a href="%s&action=accept">%s</a></p>',
appr_url, appr_url), ses);
http (sprintf ('<p>To reject the comment click on following link : <a href="%s&action=delete">%s</a></p>',
appr_url, appr_url), ses);
http (sprintf ('<p>To read the comment before approval click on following link : <a href="%s">%s</a></p>',
appr_url, appr_url), ses);
}
if (not spam)
{
http (' <p>Comment Post Contents:</p>\n', ses);
http (' <div>', ses);
http (comment_body, ses);
http (' </div>\n', ses);
}
if (pub)
{
http (' <p>You can use the reply to this mail to directly update the blog\n', ses);
http (' comment thread by including the following line anywhere in this mail\'s\n', ses);
http (' reply body:<br />\n', ses);
http (sprintf (' @blogId@=%s @postId@=%s</p>\n',blogid,postid), ses);
}
http ('</html>\n', ses);
return string_output_string (ses);
}
;
create procedure
BLOG_COMMENT_NF_HTML_FORM (
in post_url varchar,
in comment_url varchar,
in title varchar,
in b_name varchar,
in b_mail varchar,
in v_name varchar,
in v_mail varchar,
in comment_body varchar,
in blogid varchar,
in postid varchar,
in pub int,
in spam int,
in appr_url varchar
)
{
declare ses any;
ses := string_output ();
http ('<html>\n', ses);
http (' <div>\n', ses);
http (' <p>Your blog post\n', ses);
http (sprintf (' <a href="%s#comments">"%s"</a> has just been updated with a post from\n',post_url,title), ses);
http (sprintf (' <a href="mailto:%s">%s</a>.</p>\n',v_mail,v_name), ses);
if (not pub)
http ('<p>The comment was moderated and needs your approval.</p>', ses);
else
http ('<p>The comment was published on your blog.</p>', ses);
if (spam)
http ('<p>The comment was rated as a SPAM.</p>', ses);
if (spam or not pub)
{
http (sprintf ('<p>To accept the comment click on following link : <a href="%s&action=accept">%s</a></p>',
appr_url, appr_url), ses);
http (sprintf ('<p>To reject the comment click on following link : <a href="%s&action=delete">%s</a></p>',
appr_url, appr_url), ses);
http (sprintf ('<p>To read the comment before approval click on following link : <a href="%s">%s</a></p>',
appr_url, appr_url), ses);
}
if (not spam)
{
http (' <p>Comment Post Contents:</p>\n', ses);
http (' <div>', ses);
http (comment_body, ses);
http (' </div>\n', ses);
}
if (pub)
{
http (' <p>You can post a reply to this Comment using the form below:<br /></p>\n', ses);
http (sprintf (' <form method="get" action="%s">\n <input type="hidden" name="id" value="%s" />\n',
comment_url, postid), ses);
http (' <table border="0">\n', ses);
http (' <tr>\n', ses);
http (' <td>Title:</td>\n', ses);
http (' <td>\n', ses);
http (sprintf (' <input type="text" name="title" value="Re: %s" size="63" />\n',title), ses);
http (' </td>\n', ses);
http (' </tr>\n', ses);
http (' <tr>\n', ses);
http (' <td>Author:</td>\n', ses);
http (' <td>\n', ses);
http (sprintf (' <input type="text" name="author" value="%s (%s)" size="63" />\n',b_name,b_mail), ses);
http (' </td>\n', ses);
http (' </tr>\n', ses);
http (' <tr>\n', ses);
http (' <td>Link:</td>\n', ses);
http (' <td>\n', ses);
http (sprintf (' <input type="text" name="link" value="%s" size="63" />\n',post_url), ses);
http (' </td>\n', ses);
http (' </tr>\n', ses);
http (' <tr>\n', ses);
http (' <td colspan="2">Comment:</td>\n', ses);
http (' </tr>\n', ses);
http (' <tr>\n', ses);
http (' <td colspan="2">\n', ses);
http (' <textarea name="description" rows="10" cols="60" ></textarea>\n', ses);
http (' </td>\n', ses);
http (' </tr>\n', ses);
http (' <tr>\n', ses);
http (' <td colspan="2">\n', ses);
http (' <input type="submit" name="post" value="Post" />\n', ses);
http (' </td>\n', ses);
http (' </tr>\n', ses);
http (' </table>\n', ses);
http (' </form>\n', ses);
http (' </div>\n', ses);
}
http ('</html>\n', ses);
return string_output_string (ses);
}
;
create procedure
BLOG_COMMENT_NF_FORM (
in post_url varchar,
in comment_url varchar,
in title varchar,
in b_name varchar,
in b_mail varchar,
in v_name varchar,
in v_mail varchar,
in comment_body varchar,
in blogid varchar,
in postid varchar,
in pub int,
in spam int,
in appr_url varchar
)
{
declare ses any;
ses := string_output ();
http (sprintf (' <form method="post" action="%s">\n', comment_url), ses);
http (' <table border="0">\n', ses);
http (' <tr>\n', ses);
http (' <td>Title:</td>\n', ses);
http (' <td>\n', ses);
http (sprintf (' <input type="text" name="title" value="Re: %s" size="63" />\n',title), ses);
http (' </td>\n', ses);
http (' </tr>\n', ses);
http (' <tr>\n', ses);
http (' <td>Author:</td>\n', ses);
http (' <td>\n', ses);
http (sprintf (' <input type="text" name="author" value="%s (%s)" size="63" />\n',b_name,b_mail), ses);
http (' </td>\n', ses);
http (' </tr>\n', ses);
http (' <tr>\n', ses);
http (' <td>Link:</td>\n', ses);
http (' <td>\n', ses);
http (sprintf (' <input type="text" name="link" value="%s" size="63" />\n',post_url), ses);
http (' </td>\n', ses);
http (' </tr>\n', ses);
http (' <tr>\n', ses);
http (' <td colspan="2">Comment:</td>\n', ses);
http (' </tr>\n', ses);
http (' <tr>\n', ses);
http (' <td colspan="2">\n', ses);
http (' <textarea name="description" rows="10" cols="60" ></textarea>\n', ses);
http (' </td>\n', ses);
http (' </tr>\n', ses);
http (' <tr>\n', ses);
http (' <td colspan="2">\n', ses);
http (' <input type="submit" name="post" value="Post" />\n', ses);
http (' </td>\n', ses);
http (' </tr>\n', ses);
http (' </table>\n', ses);
http (' </form>\n', ses);
return string_output_string (ses);
}
;
create procedure
BLOG_COMMENT_NF_TEXT (
in post_url varchar,
in comment_url varchar,
in title varchar,
in b_name varchar,
in b_mail varchar,
in v_name varchar,
in v_mail varchar,
in comment_body varchar,
in blogid varchar,
in postid varchar,
in pub int,
in spam int,
in appr_url varchar
)
{
declare ses any;
ses := string_output ();
http (sprintf ('Your blog post "%s" (%s) has just been updated with a post from %s (%s) .\n',title,post_url,v_name,v_mail), ses);
if (not pub)
http ('The comment was moderated and needs your approval.\n', ses);
else
http ('The comment was published on your blog.\n', ses);
if (spam)
http ('The comment was rated as a SPAM.\n', ses);
if (spam or not pub)
{
http (sprintf ('To accept the comment click on following link : %s&action=accept\n',
appr_url), ses);
http (sprintf ('To reject the comment click on following link : %s&action=delete\n',
appr_url), ses);
http (sprintf ('To read the comment before approval click on following link : %s\n',
appr_url), ses);
}
if (not spam)
{
http ('\nComment Post Contents:\n', ses);
http ('\n', ses);
http (comment_body, ses);
http ('\n', ses);
http ('\n', ses);
}
if (pub)
{
http ('You can use the reply to this mail to directly update the blog\n', ses);
http ('comment thread by including the following line anywhere in this mail\'s\n', ses);
http ('reply body:\n', ses);
http (sprintf ('@blogId=%s@ @postId=%s@\n',blogid,postid), ses);
}
return string_output_string (ses);
}
;
create procedure
BLOG_TB_NF_TEXT (
in post_url varchar,
in tb_url varchar,
in title varchar,
in b_name varchar,
in b_mail varchar,
in v_name varchar,
in v_url varchar,
in tb_body varchar,
in blogid varchar,
in postid varchar,
in tb_tit varchar,
in pub int,
in spam int,
in appr_url varchar
)
{
declare ses any;
ses := string_output ();
http (sprintf ('Your blog post "%s" (%s) has just been updated\r\n with a trackback/pingback from %s (%s) .\r\n',title,post_url,v_name,v_url), ses);
if (not pub)
http ('The trackback/pingback was moderated and needs your approval.\n', ses);
else
http ('The trackback/pingback was published on your blog.\n', ses);
if (spam)
http ('The trackback/pingback was rated as a SPAM.\n', ses);
else if (not spam)
{
http ('\r\nTrackback Contents:\r\n', ses);
http (tb_tit || '\r\n', ses);
http ('\r\n', ses);
http (tb_body, ses);
}
return string_output_string (ses);
}
;
create procedure
BLOG_USERS_BLOGS_P (IN URI VARCHAR, IN NAME VARCHAR, IN PASSWD VARCHAR)
{
declare i, l int;
declare blogid, blogname, url varchar;
declare arr any;
arr := blogger.get_Users_Blogs (uri, blogRequest ('appKey', '', '', name, passwd));
i := 0; l := length (arr);
result_names (blogid, blogname, url);
while (i < l)
{
blogid := get_keyword ('blogid', arr[i]);
blogname := get_keyword ('blogname', arr[i]);
url := get_keyword ('url', arr[i]);
result (blogid, blogname, url);
i := i + 1;
}
}
;
blog2_exec_no_error ('create procedure view BLOG_USERS_BLOGS as
BLOG.DBA.BLOG_USERS_BLOGS_P (URI, NAME, PASSWD) (BLOGID VARCHAR, BLOGNAME VARCHAR, URL VARCHAR)')
;
insert soft "DB"."DBA"."SYS_SCHEDULED_EVENT" (SE_NAME, SE_START, SE_SQL, SE_INTERVAL)
values ('Routing Jobs Queue', now(), 'BLOG.DBA.ROUTING_PROCESS_JOBS ()', 10)
;
create procedure ROUTING_PROCESS_JOBS()
{
declare bm any;
declare rc, err int;
declare job_id, type_id, proto_id, dst, dst_id, a_usr, a_pwd, item_id, tag, eid, iid, send_delete, max_err any;
declare n datetime;
declare cr static cursor for select R_JOB_ID, R_TYPE_ID, R_PROTOCOL_ID,
R_DESTINATION, R_DESTINATION_ID, R_AUTH_USER, R_AUTH_PWD, R_ITEM_ID, R_EXCEPTION_TAG, R_EXCEPTION_ID,
R_INCLUSION_ID, R_KEEP_REMOTE, R_MAX_ERRORS
from SYS_ROUTING where R_LAST_ROUND is null or dateadd ('minute', R_FREQUENCY, R_LAST_ROUND) < n;
n := now ();
bm := null; err := 0;
whenever not found goto enf;
open cr (exclusive, prefetch 1);
fetch cr first into job_id, type_id, proto_id, dst, dst_id, a_usr, a_pwd, item_id, tag, eid, iid, send_delete, max_err;
while (1)
{
bm := bookmark (cr);
err := 0;
close cr;
{
declare exit handler for sqlstate '*'
{
rollback work;
if (__SQL_STATE = '40001')
resignal;
if (1) log_message (__SQL_STATE || ':' || __SQL_MESSAGE );
err := 1;
goto next;
};
send_delete := equ (send_delete, 0);
commit work;
if (type_id in (1, 2, 3))
{
if (dst is null or dst = '')
{
if ((select max(WS_USE_DEFAULT_SMTP) from DB.DBA.WA_SETTINGS) = 1)
dst := cfg_item_value(virtuoso_ini_path(), 'HTTPServer', 'DefaultMailServer');
else
dst := (select max(WS_SMTP) from DB.DBA.WA_SETTINGS);
}
-- do the work only if max error is not reached or it's unlimited
if (max_err > 0 or max_err = -1)
{
rc := ROUTING_PROCESS_BLOGS (job_id, proto_id, dst, dst_id, a_usr, a_pwd, item_id, tag, eid, iid, send_delete);
if (rc <> 0 and max_err > 0)
max_err := max_err - 1;
}
}
}
update SYS_ROUTING set R_LAST_ROUND = now (), R_MAX_ERRORS = max_err where R_JOB_ID = job_id;
commit work;
next:
open cr (exclusive, prefetch 1);
fetch cr bookmark bm into job_id, type_id, proto_id, dst, dst_id, a_usr, a_pwd, item_id, tag, eid, iid, send_delete, max_err;
if (err)
fetch cr next into job_id, type_id, proto_id, dst, dst_id, a_usr, a_pwd, item_id, tag, eid, iid, send_delete, max_err;
}
enf:
close cr;
return;
}
;
create procedure BLOG_DELICIOUS_ADD (in post_id varchar, in base any, in uid any, in pwd any)
{
declare t_url, d_url, t_tags, t_desc, tim, tmp any;
declare host, url, hdr, fnd any;
fnd := 0;
t_tags := '';
for select BT_TAGS from BLOG..BLOG_TAG where BT_POST_ID = post_id do
{
fnd := 1;
-- replace the space with + and remove trailing and leading quotes
t_tags := BT_TAGS;
}
if (not fnd)
goto nf;
t_tags := trim (t_tags, ', ');
t_tags := replace (t_tags, ',', ' ');
whenever not found goto nf;
select B_TITLE, B_MODIFIED into t_desc, tim from SYS_BLOGS where B_POST_ID = post_id;
t_url := base || '?id=' || post_id;
tim := dt_set_tz(tim, 0);
d_url := sprintf('https://api.del.icio.us/v1/posts/add?url=%U&description=%U&extended=%U&tags=%U&dt=%U',
t_url, t_desc, '', t_tags, date_iso8601 (tim));
DB.DBA.HTTP_CLIENT_EXT (url=>d_url, uid=>uid, pwd=>pwd, http_method=>'POST', headers=>hdr);
if (isarray (hdr) and length (hdr))
{
tmp := trim (hdr[0], '\r\n ');
if (tmp not like 'HTTP/1._ 20_%')
signal ('42000', tmp);
}
return t_url;
nf:
return null;
}
;
create procedure BLOG_DELICIOUS_DEL (in url any, in uid any, in pwd any)
{
declare d_url, hdr, tmp any;
if (url is null)
return;
d_url := sprintf('https://api.del.icio.us/v1/posts/delete?url=%U', url);
DB.DBA.HTTP_CLIENT_EXT (url=>d_url, uid=>uid, pwd=>pwd, http_method=>'POST', headers=>hdr);
if (isarray (hdr) and length (hdr))
{
tmp := trim (hdr[0], '\r\n ');
if (tmp not like 'HTTP/1._ 20_%')
signal ('42000', tmp);
}
return null;
}
;
create procedure
BLOG_MESSAGE_OR_META_DATA (inout meta any, inout uid int,
inout content any, inout postid varchar, inout tms datetime)
{
if (meta is not null)
{
return meta;
}
declare res BLOG.DBA."MTWeblogPost";
res := new BLOG.DBA."MTWeblogPost" ();
res.userid := (select U_NAME from "DB"."DBA"."SYS_USERS" where U_ID = uid);
res.description := blob_to_string (content);
res.author := (select U_E_MAIL from "DB"."DBA"."SYS_USERS" where U_ID = uid);
res.dateCreated := tms;
res.mt_allow_pings := 0;
res.mt_allow_comments := 0;
res.postid := postid;
return res;
}
;
create procedure
cell_fmt (in v any, in a any, in today any := null, in cal any := null)
{
declare tod, real_tod, ret varchar;
tod := null;
real_tod := null;
if (year(now()) = year(cal) and month(now()) = month(cal))
{
if (cast(v as varchar) = cast(dayofmonth(now()) as varchar))
{
real_tod := 'caltoday';
}
}
if (today is not null and cal is not null)
{
if (year (cal) = year (today) and month(today) = month (cal))
{
tod := cast (dayofmonth (today) as varchar);
}
}
if (tod = v and position (v,a))
ret := 'calactive calselected';
else if (tod = v and not position (v,a))
ret := 'calnotactive calselected';
else if ((tod = v or position (v,a)) and length(a) > 0)
ret := 'calactive';
else
ret := 'calnotactive';
if (real_tod is not null)
return concat(ret, ' caltoday');
else
return ret;
}
;
create procedure BLOG..blog_date_fmt (in d datetime, in n int := null)
{
declare tz int;
declare s varchar;
--d := dt_set_tz (d, 0);
tz := 0; s := '';
if (n is not null)
{
--d := dateadd ('hour', n, d);
tz := abs(n);
s := case when n < 0 then '-' when n >= 0 then '+' else '' end;
}
if (tz <> 0)
return sprintf ('%02d/%02d/%04d %02d:%02d GMT%s%02d00',
month(d), dayofmonth(d), year(d), hour(d), minute(d), s, tz);
return sprintf ('%02d/%02d/%04d %02d:%02d GMT',
month(d), dayofmonth(d), year(d), hour(d), minute(d));
}
;
create procedure BLOG_RSS_FEEDS_P (in blogid varchar, in uri varchar)
{
declare CF_ID int;
declare CF_CHANNEL_URI, CF_TITLE, CF_DESCRIPTION, CF_LINK, CF_GUID varchar;
declare CF_PUBDATE datetime;
result_names (CF_ID, CF_CHANNEL_URI, CF_TITLE, CF_DESCRIPTION, CF_LINK, CF_GUID, CF_PUBDATE);
for select RES_CONTENT from WS.WS.SYS_DAV_RES, SYS_BLOG_CHANNELS where
BC_BLOG_ID = blogid and BC_CHANNEL_URI = uri and BC_LOCAL_RES = RES_FULL_PATH do
{
declare xt, pc any;
declare i, l int;
xt := xml_tree_doc (xml_tree (RES_CONTENT));
pc := xpath_eval ('/rss/channel/item|/RDF/item', xt, 0);
i := 0; l := length (pc);
while (i < l)
{
declare elm any;
elm := xml_cut (pc[i]);
CF_CHANNEL_URI := uri;
CF_TITLE := cast (xpath_eval ('/item/title', elm, 1) as varchar);
CF_DESCRIPTION := cast (xpath_eval ('/item/description', elm, 1) as varchar);
CF_LINK := cast (xpath_eval ('/item/link', elm, 1) as varchar);
CF_GUID := cast (xpath_eval ('/item/guid', elm, 1) as varchar);
if (CF_GUID is null)
CF_GUID := CF_LINK;
CF_PUBDATE := cast (xpath_eval ('/item/pubDate', elm, 1) as varchar);
result (i, CF_CHANNEL_URI, CF_TITLE, CF_DESCRIPTION, CF_LINK, CF_GUID, CF_PUBDATE);
i := i + 1;
}
}
}
;
blog2_exec_no_error ('create procedure view BLOG_RSS_FEEDS as BLOG_RSS_FEEDS_P (BLOGID, URI)
(CF_ID int,
CF_CHANNEL_URI varchar,
CF_TITLE varchar,
CF_DESCRIPTION varchar,
CF_LINK varchar,
CF_GUID varchar,
CF_PUBDATE varchar)
');
create procedure
blog_user_password_check (in name varchar, in pass varchar)
{
declare rc int;
rc := 0;
if (exists (select 1 from "DB"."DBA"."SYS_USERS" where U_NAME = name and U_DAV_ENABLE = 1
and U_IS_ROLE = 0 and pwd_magic_calc (U_NAME, U_PASSWORD, 1) = pass))
{
rc := 1;
}
commit work;
return rc;
}
;
create procedure
WEBLOGUPDATES_COUNT ()
{
declare cnt int;
select count (*) into cnt from SYS_WEBLOG_UPDATES_PINGS;
return cnt;
}
;
create procedure
WEBLOGUPDATES_WHEN (in t datetime, in w int := 1)
{
declare d datetime;
d := coalesce ((select top 1 WU_TS from SYS_WEBLOG_UPDATES_PINGS order by WU_TS desc), now ());
if (w)
return datediff ('second', t, d);
else
return d;
}
;
create procedure
"weblogUpdates.ping" (
in weblogname varchar,
in weblogurl varchar,
in changesurl varchar := null,
out Result any
)
{
declare stat int;
declare msg varchar;
stat := 0;
msg := '';
if (exists (select 1 from SYS_WEBLOG_UPDATES_PINGS where
WU_URL = weblogurl and datediff ('minute', WU_TS, now ()) < 5 ))
{
stat := 1;
msg := 'Pings must be sent in 5 minutes interval or greater.';
}
else
{
declare dummy varchar;
declare exit handler for sqlstate '*' {
msg := __SQL_MESSAGE;
goto enf;
};
dummy := http_get (weblogurl);
insert replacing SYS_WEBLOG_UPDATES_PINGS (WU_NAME, WU_URL, WU_TS, WU_IP, WU_CHANGES_URL)
values (weblogname, weblogurl, now (), http_client_ip (), changesurl);
}
enf:
Result := soap_box_structure
(
'flError', soap_boolean(stat),
'message', msg
);
}
;
create procedure
"weblogUpdates.extendedPing" (
in weblogname varchar,
in weblogurl varchar,
in changesurl varchar := null,
in rssUrl varchar,
out Result any
)
{
declare stat int;
declare msg varchar;
stat := 0;
msg := '';
if (exists (select 1 from SYS_WEBLOG_UPDATES_PINGS where
WU_URL = weblogurl and datediff ('minute', WU_TS, now ()) < 5 ))
{
stat := 1;
msg := 'Pings must be sent in 5 minutes interval or greater.';
}
else
{
declare dummy varchar;
declare exit handler for sqlstate '*' {
msg := __SQL_MESSAGE;
goto enf;
};
dummy := http_get (weblogurl);
insert replacing SYS_WEBLOG_UPDATES_PINGS (WU_NAME, WU_URL, WU_TS, WU_IP, WU_CHANGES_URL, WU_RSS)
values (weblogname, weblogurl, now (), http_client_ip (), changesurl, rssUrl);
}
enf:
Result := soap_box_structure
(
'flError', soap_boolean(stat),
'message', msg
);
}
;
create procedure
subsharmonizer_get_blog (inout req "blogRequest")
{
declare id varchar;
whenever not found goto nf;
select BI_BLOG_ID into id from SYS_BLOG_INFO where BI_OWNER = req.auth_userid;
return id;
nf:
signal ('42000', 'Fatal, the authenticated user have no blogs associated.');
}
;
create procedure
subsharmonizer_add_channel (in blogid varchar, in url varchar)
{
if (not exists (select 1 from BLOG..SYS_BLOG_CHANNEL_INFO where BCD_CHANNEL_URI = url))
{
declare cont varchar;
declare xt, ct any;
declare hp, proto any;
declare tit, home varchar;
declare format, upd_per, lang, src_uri, src_tit, dir_uri, chan_cat varchar;
declare upd_freq integer;
hp := WS.WS.PARSE_URI (url);
proto := lower(hp[0]);
if (proto <> 'http')
cont := XML_URI_GET (url, '');
else
{
declare ur, ou, hdr varchar;
ur := url; ou := ur;
try_again:
cont := http_get (ur, hdr);
if (hdr[0] like 'HTTP/1._ 30_ %')
{
ur := http_request_header (hdr, 'Location');
if (ur <> ou)
{
ou := ur;
goto try_again;
}
}
}
{
declare exit handler for sqlstate '*' { goto htmlp; };
xt := xml_tree_doc (xml_tree (cont, 0));
goto donep;
}
xt := xml_tree_doc (xml_tree (cont, 2));
donep:;
if (xpath_eval ('/rss|/RDF/channel', xt, 1) is not null)
{
xt := xml_cut (xpath_eval ('/rss/channel[1]|/RDF/channel[1]', xt, 1));
tit := cast (xpath_eval ('/channel/title/text()', xt, 1) as varchar);
home := cast (xpath_eval ('/channel/link/text()', xt, 1) as varchar);
format := 'http://my.netscape.com/rdf/simple/0.9/';
lang := cast (xpath_eval ('/channel/language/text()', xt, 1) as varchar);
upd_per := 'hourly';
upd_freq := 1;
insert soft BLOG..SYS_BLOG_CHANNEL_INFO
(BCD_CHANNEL_URI,BCD_TITLE, BCD_HOME_URI,BCD_FORMAT, BCD_UPDATE_PERIOD, BCD_LANG, BCD_UPDATE_FREQ)
values (url, tit, home, format, upd_per, lang, upd_freq);
}
htmlp:;
}
if (exists (select 1 from BLOG..SYS_BLOG_CHANNEL_INFO where BCD_CHANNEL_URI = url))
insert soft SYS_BLOG_CHANNELS (BC_BLOG_ID, BC_CHANNEL_URI) values (blogid, url);
}
;
create procedure
BLOG.DBA."subsHarmonizer.setup" (in "username" varchar, in "password" varchar,
in "array" any __soap_type 'MWeblogPost:ArrayOfstring')
{
declare req "blogRequest";
declare blogid varchar;
req := new "blogRequest" ();
req.user_name := "username";
req.passwd := "password";
"blogger_auth" (req);
blogid := subsharmonizer_get_blog (req);
declare i, l int;
i := 0; l := length ("array");
while (i < l)
{
declare exit handler for sqlstate '*' { goto nextc; };
subsharmonizer_add_channel (blogid, cast("array"[i] as varchar));
nextc:
i := i + 1;
}
return soap_boolean (0);
}
;
create procedure
BLOG.DBA."subsHarmonizer.subscribe" (in "username" varchar, in "password" varchar,
in "array" any __soap_type 'MWeblogPost:ArrayOfstring')
{
declare req "blogRequest";
declare blogid varchar;
req := new "blogRequest" ();
req.user_name := "username";
req.passwd := "password";
"blogger_auth" (req);
blogid := subsharmonizer_get_blog (req);
declare i, l int;
i := 0; l := length ("array");
while (i < l)
{
subsharmonizer_add_channel (blogid, cast ("array"[i] as varchar));
i := i + 1;
}
return soap_boolean (0);
}
;
create procedure
BLOG.DBA."subsHarmonizer.unsubscribe" (in "username" varchar, in "password" varchar,
in "array" any __soap_type 'MWeblogPost:ArrayOfstring')
{
declare req "blogRequest";
declare blogid varchar;
req := new "blogRequest" ();
req.user_name := "username";
req.passwd := "password";
"blogger_auth" (req);
blogid := subsharmonizer_get_blog (req);
declare i, l int;
i := 0; l := length ("array");
while (i < l)
{
delete from SYS_BLOG_CHANNELS where BC_BLOG_ID = blogid and BC_CHANNEL_URI = cast("array"[i] as varchar);
i := i + 1;
}
return soap_boolean (0);
}
;
create procedure
BLOG.DBA."subsHarmonizer.startup" (in "username" varchar, in "password" varchar)
__soap_type 'MWeblogPost:ArrayOfstring'
{
declare req "blogRequest";
declare blogid varchar;
declare res any;
req := new "blogRequest" ();
req.user_name := "username";
req.passwd := "password";
"blogger_auth" (req);
blogid := subsharmonizer_get_blog (req);
res := vector ();
for select BC_CHANNEL_URI from SYS_BLOG_CHANNELS where BC_BLOG_ID = blogid do
{
res := vector_concat (res, vector (BC_CHANNEL_URI));
}
return res;
}
;
create procedure
BLOG_GET_SUBJECT (in postid varchar, in blogid varchar)
{
declare subj varchar;
subj := '';
for select MTC_NAME from MTYPE_CATEGORIES, MTYPE_BLOG_CATEGORY
where MTB_CID = MTC_ID and MTC_BLOG_ID = MTB_BLOG_ID and MTB_POST_ID = postid and MTB_BLOG_ID = blogid do
{
subj := subj || MTC_NAME || ' ';
}
return trim (subj);
}
;
create procedure
BLOG_TAGS_RENDER (in _postid varchar, in _blogid varchar)
{
declare ses any;
ses := string_output ();
for select BT_TAG from BLOG..BLOG_POST_TAGS_STAT_2 where blogid = _blogid and postid = _postid
do
{
http_value (BT_TAG, 'category', ses);
}
return string_output_string (ses);
};
create procedure
BLOG_ENCLOSURE_RENDER (inout meta any)
{
declare mt BLOG.DBA."MWeblogPost";
declare enc BLOG.DBA."MWeblogEnclosure";
mt := meta;
if (meta is null or mt.enclosure is null)
return '';
enc := mt.enclosure;
if (enc."length" < 1)
return '';
return sprintf ('<enclosure url="%V" length="%d" type="%s" />',
enc.url,
enc."length",
enc."type"
);
}
;
create procedure BLOG_REFFERAL_REGISTER (in blogid varchar, in lines any, in params any)
{
declare postid, url, title any;
url := http_request_header (lines, 'Referer');
postid := get_keyword ('id', params);
if (isstring (url) and exists (select 1 from SYS_BLOGS where B_BLOG_ID = blogid and B_POST_ID = postid))
{
declare hinfo any;
hinfo := WS.WS.PARSE_URI (url);
if (hinfo[0] = 'http' and hinfo[1] <> '' and hinfo [2] <> '')
{
url := 'http://' || hinfo[1] || hinfo [2];
insert soft SYS_BLOG_REFFERALS (BR_BLOG_ID,BR_POST_ID,BR_URI) values (blogid, postid, url);
}
}
}
;
create procedure
BLOG_SET_OPTION (in name varchar, inout opts any, in value any)
{
if (__tag (opts) <> 193)
opts := vector ();
if (position (name, opts))
aset (opts, position (name, opts), value);
else
opts := vector_concat (opts, vector (name, value));
}
;
create procedure
BLOG_HTMLIZE_TEXT (in txt varchar) returns varchar
{
declare inx, txt_len integer;
inx := 0;
txt_len := length (txt);
while (inx < txt_len)
{
if (inx < txt_len - 4 and
subseq (txt, inx, inx + 4) = '\r\n\r\n')
{
txt := concat (subseq (txt, 0, inx), '\r\n<p>\r\n', subseq (txt, inx + 4, txt_len));
inx := inx + length ('\r\n<p>\r\n') - 1;
txt_len := length (txt);
}
else if (inx < txt_len - 2 and
subseq (txt, inx, inx + 2) = '\n\n')
{
txt := concat (subseq (txt, 0, inx), '\n<p>\n', subseq (txt, inx + 2, txt_len));
inx := inx + length ('\n<p>\n') - 1;
txt_len := length (txt);
}
else if (inx < txt_len - 2 and
subseq (txt, inx, inx + 2) = '\r\n')
{
txt := concat (subseq (txt, 0, inx), '<br />\r\n', subseq (txt, inx + 2, txt_len));
inx := inx + length ('\n<br />\n') - 1;
txt_len := length (txt);
}
else if (inx < txt_len - 1 and
subseq (txt, inx, inx + 1) = '\n')
{
txt := concat (subseq (txt, 0, inx), '<br />\n', subseq (txt, inx + 1, txt_len));
inx := inx + length ('\n<br />\n') - 1;
txt_len := length (txt);
}
inx := inx + 1;
}
return txt;
}
;
create procedure MOBBLOGGING_DISPLAY_MIME (inout doc varchar, inout ses varchar, in params any,
inout parsed_message varchar, in msg varchar, in path varchar,
in call_page varchar, in part integer, in do_update integer,
inout file_name varchar, in changed_name varchar)
{
--no_c_escapes-
declare path_part, body, attrs, parts, entry_path varchar;
declare inx integer;
entry_path := path;
if (not isarray(parsed_message))
return;
attrs := aref (parsed_message, 0);
body := aref (parsed_message, 1);
parts := aref (parsed_message, 2);
if (isarray (body))
{
if (aref (body, 1) > aref (body, 0))
{
declare body_submsg varchar;
body_submsg := aref (body, 2);
if (not isarray (body_submsg))
{
declare body_type, body_enc, body_file varchar;
if (isarray (attrs))
{
body_type := lcase (get_keyword_ucase ('Content-Type', attrs));
body_enc := lcase (get_keyword_ucase ('Content-Transfer-Encoding', attrs));
body_file := get_keyword_ucase ('filename', attrs);
file_name := body_file;
}
else
{
body_type := null;
body_enc := null;
}
if (length (body_type) = 0)
body_type := 'text/plain';
if (length (body_enc) = 0)
body_enc := null;
if (length (body_file) = 0)
body_file := null;
if (isnull (body_type))
body_type := 'text/plain';
if (subseq (body_type, 0, 9) = 'multipart')
body_type := 'text/plain';
if ((subseq (body_type, 0, 5) = 'image' and
(subseq (body_type, 6, 9) = 'gif' or subseq (body_type, 6, 10) = 'jpeg'))
or body_type = 'application/octet-stream')
{
if (body_file is null)
body_file := concat ('body.', subseq (body_type, 5, length (body_type)));
http ('<IMG src=\"/INLINEFILE/');
http_url (body_file);
http ('?VSP=');
http_url (sprintf ('%s' ,call_page));
http ('&msg=');
http_url (doc);
http ('&downloadpath=');
http_url (concat (entry_path, '/d/', body_file));
http ('&page=1');
http ('&subj2=');
http_url (get_keyword ('subj', params, ''));
http ('&part=');
http (cast (part as varchar));
http ('&do_update=');
http (cast (do_update as varchar));
http ('&changed_name=');
http_url (changed_name);
http ('"></IMG>');
}
}
}
if (isarray (aref (body, 3)))
{
http_value (subseq (msg, aref (aref (body, 3), 0), aref (aref (body, 3), 1)), null, ses);
}
}
if (isarray (parts))
{
inx := 0;
while (inx < length (parts))
{
if (inx = part)
MOBBLOGGING_DISPLAY_MIME (doc, ses, params, aref (parts, inx), msg,
sprintf ('%s/%d', path, inx), call_page, part,
do_update, file_name, changed_name);
inx := inx + 1;
}
}
}
;
create procedure BLOG_UPDATE_IMAGES_TO_USER_DIR (in uid int, in image_body varchar, in image_name varchar)
{
declare nam, folder, ret varchar;
declare dav_pwd any;
whenever not found goto ef;
select U_NAME into nam from "DB"."DBA"."SYS_USERS" where U_ID = uid;
folder := '/DAV/'||nam||'/blog/images/';
DB.DBA.DAV_MAKE_DIR (folder, http_dav_uid (), uid, '110110100N');
ret := folder || image_name;
DB.DBA.DAV_RES_UPLOAD_STRSES_INT (ret, image_body, '', '110100100N', uid, null, null, null, 0);
ef:;
return ret ;
}
;
create procedure BLOG_INSERT_MESSAGE (in _uid integer, in params any, in img_path varchar,
in mime varchar := 'image/any')
{
declare postId varchar;
declare blogId varchar;
declare bcont varchar;
postId := cast (sequence_next ('blogger.postid') as varchar);
if (postId = '0')
postId := cast (sequence_next ('blogger.postid') as varchar);
blogId := (select BI_BLOG_ID from SYS_BLOG_INFO where BI_OWNER = _uid);
declare res "MTWeblogPost";
res := new "MTWeblogPost" ();
res.postid := postId;
res.title := get_keyword ('subj2', params, '');
res.author := (select U_NAME from "DB"."DBA"."SYS_USERS" where U_ID = _uid);
res.userid := res.author;
res.dateCreated := now ();
if (mime like 'image/%')
{
bcont := '<div><a href="http://'||BLOG_GET_HOST ()|| img_path || '">' ||
'<img src="http://'||BLOG_GET_HOST () || img_path || '" width="200" border="0" /></a></div><div><pre>'
|| get_keyword ('changed_name', params, '') || ' </pre></div>';
}
else
{
bcont := '<div><a href="http://'||BLOG_GET_HOST ()|| img_path || '">' ||
res.title ||'</a></div><div><pre>'
|| get_keyword ('changed_name', params, '') || ' </pre></div>';
}
insert into SYS_BLOGS (B_APPKEY, B_BLOG_ID, B_CONTENT, B_POST_ID, B_USER_ID, B_TS, B_META, B_TITLE)
values ('', blogId, bcont, postId, _uid, now (), res, res.title);
}
;
create procedure MOBBLOGGING_IS_MOB_MESSAGE (in _msg any)
{
declare parsed_message, parts, line any;
declare idx, len, ret integer;
parsed_message := mime_tree (_msg);
if (isarray(parsed_message) and length(parsed_message) > 2)
parts := aref (parsed_message, 2);
else
return 0;
if (not isarray (parts))
return 0;
len := length (parts);
idx := 0;
ret := 0;
while (idx < len)
{
line := parts[idx][0];
if (isarray (line))
{
if ((get_keyword_ucase ('filename', line, '') <> '')
and (get_keyword_ucase ('Content-Disposition', line, '') = 'attachment')
and ((get_keyword_ucase ('Content-Type', line, '') like 'image/%'))
or ((get_keyword_ucase ('Content-Type', line, '') = 'application/octet-stream')))
ret := 1;
}
idx := idx + 1;
}
return ret;
}
;
create procedure MOBBLOGGING_GET_MOB_MESSAGE
(
in _msg any,
in opts any
)
{
declare parsed_message, amime, res any;
declare rc integer;
declare msg_header any;
parsed_message := mime_tree (_msg);
if (not isarray (opts))
opts := vector ();
amime := get_keyword ('MoblogMIMETypes', opts, 'image/%');
amime := split_and_decode (amime, 0, '\0\0,');
res := null;
msg_header := NULL;
BLOG_MOBLOG_PROCESS_PARTS (parsed_message, _msg, amime, res, msg_header);
return res;
}
;
create procedure
BLOG_MOBLOG_PROCESS_PARTS (in parts any, inout body varchar, inout amime any, out result any, inout msg_header any)
{
declare name1, mime1, name, mime, enc, content varchar;
declare i, l, i1, l1, is_allowed int;
declare part any;
declare mailer varchar;
if (not isarray (result))
result := vector ();
if (not isarray (parts) or not isarray (parts[0]))
return 0;
-- test if there is an moblog compliant image
part := parts[0];
if (msg_header is null)
msg_header := part;
name1 := get_keyword_ucase ('filename', part, '');
if (name1 = '')
name1 := get_keyword_ucase ('name', part, '');
mime1 := get_keyword_ucase ('Content-Type', part, '');
mailer := get_keyword_ucase ('X-Mailer', msg_header, '');
if ((mime1 = 'application/octet-stream' and name1 <> '') or
(mailer = 'Symbian OS Email Version 6.1' and mime1 = 'text/plain' and name1 <> ''))
{
mime1 := http_mime_type (name1);
}
is_allowed := 0;
i1 := 0; l1 := length (amime);
while (i1 < l1)
{
declare elm any;
elm := trim(amime [i1]);
if (mime1 like elm)
{
is_allowed := 1;
i1 := l1;
}
i1 := i1 + 1;
}
if (
is_allowed and
name1 <> '' and
get_keyword_ucase ('Content-Disposition', part, '') = 'attachment'
)
{
name := name1;
mime := mime1;
enc := get_keyword_ucase ('Content-Transfer-Encoding', part, '');
content := subseq (body, parts[1][0], parts[1][1]);
if (enc = 'base64')
content := decode_base64 (content);
result := vector_concat (result, vector (vector (name, mime, content)));
return 1;
}
-- process the parts
if (not isarray (parts[2]))
return 0;
i := 0; l := length (parts[2]);
while (i < l)
{
BLOG_MOBLOG_PROCESS_PARTS (parts[2][i], body, amime, result, msg_header);
i := i + 1;
}
return 0;
}
;
create procedure
BLOG_MOBLOG_PROCESS_MSG (in own varchar, in id int, in fld varchar, in body any, in is_mb any)
{
-- Weblog2
return DB.DBA.BLOG2_MOBLOG_PROCESS_MSG(own, id, fld, body, is_mb);
}
;
create procedure MOBBLOGGING_MSG_GET_BODY (in _msg any)
{
declare parsed_message, body any;
declare _beg, _end integer;
parsed_message := mime_tree (_msg);
body := aref (parsed_message, 1);
if (isarray (body))
{
return substring (_msg, body[0] + 1, body[1] - body[0]);
}
return '';
}
;
create procedure MOBBLOGGING_MSG_GET_PART (in _msg any, in part integer)
{
declare parsed_message, parts any;
declare _beg, _end integer;
parsed_message := mime_tree (_msg);
parts := aref (parsed_message, 2);
if (isarray (parts))
{
if (length (parts) <= part)
return '';
parts := parts [part];
parts := parts [1];
return substring (_msg, parts[0] + 1, parts[1] - parts[0]);
}
return '';
}
;
-- SOAP API for subscriptions, pings etc.
create procedure
GET_URL_AND_REDIRECTS (inout url varchar, inout hdr any)
{
declare content varchar;
declare olduri varchar;
olduri := url;
again:
content := http_get (url, hdr);
if (hdr[0] not like 'HTTP/1._ 200 %')
{
if (hdr[0] like 'HTTP/1._ 30_ %')
{
declare base varchar;
base := url;
url := http_request_header (hdr, 'Location');
if (isstring (url))
{
url := WS.WS.EXPAND_URL (base, url);
goto again;
}
}
signal ('22023', trim(hdr[0], '\r\n'), 'BLOG1');
return NULL;
}
url := olduri;
return content;
}
;
create procedure
GET_BLOG_POSTS (in uri varchar, in store_in_dav int := 1, in target_folder varchar := null)
{
declare content, url varchar;
declare hdr any;
declare xt any;
declare items any;
declare i, l int;
declare typef varchar;
url := uri;
content := GET_URL_AND_REDIRECTS (url, hdr);
typef := http_request_header (hdr, 'Content-Type', null, 'text/xml');
if (store_in_dav)
{
BLOG_STORE_CHANNEL_FEED (url, content, typef, target_folder);
}
else
{
xt := xml_tree_doc (xml_tree (content));
items := xpath_eval ('/rss/channel/item|/RDF/item', xt, 0);
i := 0; l := length (items);
while (i < l)
{
BLOG_PROCESS_RSS_ITEM (xml_cut (items[i]), url);
i := i + 1;
}
}
}
;
create procedure
SUBSCRIBE_DATA_CHANNEL (
in blogid varchar,
in uid varchar,
in pwd varchar,
in title varchar,
in home varchar,
in rss varchar,
in format varchar,
in lang varchar,
in update_period varchar,
in update_frequency int,
in is_blog int)
{
declare req "blogRequest";
req := new "blogRequest" ();
req.appkey := 'appKey';
req.user_name := uid;
req.passwd := pwd;
req.blogId := blogid;
"blogger_auth" (req);
insert replacing SYS_BLOG_CHANNELS (BC_CHANNEL_URI, BC_BLOG_ID) values (rss, blogid);
insert replacing SYS_BLOG_CHANNEL_INFO
(BCD_TITLE, BCD_HOME_URI, BCD_CHANNEL_URI, BCD_FORMAT, BCD_UPDATE_PERIOD,
BCD_LANG, BCD_UPDATE_FREQ, BCD_SOURCE_URI, BCD_IS_BLOG)
values (title, home, rss, format,
update_period, lang, update_frequency, NULL, is_blog);
}
;
create procedure
BLOG_AUTO_DISCOVER (
in uri varchar,
out rss varchar,
out commentapi varchar,
out trackback varchar __soap_type 'MWeblogPost:ArrayOfstring',
out pingback varchar,
out foaf varchar,
out suggested_links any __soap_type 'MWeblogPost:ArrayOfstring'
)
{
declare content varchar;
declare url varchar;
declare hdr any;
declare xt any;
url := uri;
suggested_links := vector ();
content := GET_URL_AND_REDIRECTS (url, hdr);
xt := xml_tree_doc (xml_tree (content, 2));
rss := xpath_eval ('/html/head/link[@rel="alternate" and @type="application/rss+xml"]/@href', xt, 1);
pingback := xpath_eval ('/html/head/link[@rel="pingback"]/@href', xt, 1);
foaf := xpath_eval ('/html/head/link[@rel="meta" and @type="application/rdf+xml"]/@href', xt, 1);
commentapi := xpath_eval ('/html/head/link[@rel="service.comment" and @type="text/xml"]/@href', xt, 1);
trackback := GET_BLOG_TB_URLS (xt);
if (rss is null)
{
declare hrefs any;
declare urls, target any;
declare i, l int;
urls := vector ();
xt := xml_tree_doc (xml_tree (content, 66, url, current_charset ()));
hrefs := xpath_eval ('//a/@href[ . like "%.rss" or . like "%.rdf" or . like "%.xml" or . like "%rss.xml" ]', xt, 0);
i := 0; l := length (hrefs);
while (i < l)
{
declare elm any;
elm := cast (hrefs[i] as varchar);
target := WS.WS.EXPAND_URL (url, elm);
if (not position (target, urls))
urls := vector_concat (urls, vector (target));
i := i + 1;
}
if (length (urls))
suggested_links := urls;
}
-- syndic8 calls
if (rss is null)
{
declare ids, resp, xp any;
declare urls any;
declare i, l int;
urls := vector ();
declare exit handler for sqlstate '*' { return; };
resp := DB.DBA.XMLRPC_CALL ('http://www.syndic8.com/xmlrpc.php','syndic8.FindSites',vector (uri));
xp := xpath_eval('/methodResponse/Param1', xml_tree_doc (resp), 1);
ids := soap_box_xml_entity (xp, vector (), 11);
i := 0; l := length (ids);
while (i < l)
{
declare struct, dataurl, status varchar;
resp := DB.DBA.XMLRPC_CALL ('http://www.syndic8.com/xmlrpc.php','syndic8.GetFeedInfo',vector (ids[i]));
xp := xpath_eval('/methodResponse/Param1', xml_tree_doc (resp), 1);
struct := soap_box_xml_entity (xp, vector (), 11);
dataurl := get_keyword ('dataurl', struct);
status := get_keyword ('status', struct);
if (status = 'Syndicated' and not position (dataurl, suggested_links))
urls := vector_concat (urls, vector (dataurl));
i := i + 1;
}
if (length (urls))
suggested_links := vector_concat (suggested_links, urls);
}
}
;
create procedure GET_BLOG_TB_URLS (inout xt any)
{
declare tb any;
tb := vector ();
if (not xslt_is_sheet ('--internal-blog-tb-urls-'))
{
xslt_sheet ('--internal-blog-tb-urls-',
xml_tree_doc (
'<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >'||
' <xsl:output method="text" />'||
' <xsl:template match="comment()" >'||
' <comment>'||
' <xsl:value-of select="."/>'||
' </comment>'||
' </xsl:template>'||
' <xsl:template match="text()" />'||
'</xsl:stylesheet>')
);
}
declare xp, ss any;
xp := xslt ('--internal-blog-tb-urls-', xt);
ss := string_output ();
http_value (xp, null, ss);
ss := string_output_string (ss);
xp := xml_tree_doc (xml_tree(ss, 2));
tb := xpath_eval ('[xmlns:tb="http://madskills.com/public/xml/rss/module/trackback/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"] /comment/rdf:rdf/rdf:description/@tb:ping', xp, 0);
return tb;
}
;
create procedure
BLOG_COMMENT_POST (
in comment_uri varchar,
in title varchar,
in author varchar,
in link varchar,
in description varchar)
{
declare rss varchar;
declare hdr any;
rss := sprintf ('<?xml version="1.0" encoding="%s"?><item><title>%V</title><author>%V</author><link>%V</link><description>%V</description></item>', current_charset (), title, author, link, description);
{
declare exit handler for sqlstate '*' { return __SQL_MESSAGE; };
http_get (comment_uri, hdr, 'POST', 'Content-Type: text/xml', rss);
}
if (length (hdr) > 0 and (hdr[0] like 'HTTP/1._ 200 %' or hdr[0] like 'HTTP/1._ 3__ %'))
{
return 'Comment is posted successfully';
}
else
return 'Comment is NOT posted successfully, please verify URL.';
}
;
create procedure
BLOG_TRACKBACK_PING (
in tb_uri varchar,
in title varchar,
in link varchar,
in excerpt varchar,
in blog_name varchar
)
returns integer
{
declare post, ret, xp, rc any;
post := sprintf ('title=%U&url=%U&excerpt=%U&blog_name=%U', title, link, excerpt, blog_name);
ret := http_get (tb_uri, null, 'POST', null, post);
xp := xml_tree_doc (ret);
rc := cast (xpath_eval ('/response/error', xp) as varchar);
rc := atoi (rc);
if (rc <> 0)
{
rc := cast (xpath_eval ('/response/message', xp) as varchar);
signal ('22023', rc);
}
return rc;
}
;
create procedure
BLOG_PINGBACK_PING (in pingback_uri varchar, in source_uri varchar, in target_uri varchar)
{
declare rc any;
declare message any;
message := '';
rc := DB.DBA.XMLRPC_CALL (pingback_uri, 'pingback.ping', vector (source_uri, target_uri));
if (isarray(rc))
{
declare xt any;
xt := xml_tree_doc (rc);
message := cast (xpath_eval ('string(//*)', xml_cut(xt), 1) as varchar);
}
return message;
}
;
create procedure
BLOG_WEBLOG_PING (in blog_name varchar, in blog_uri varchar, out error varchar, out message varchar)
{
declare rc any;
rc := DB.DBA.XMLRPC_CALL ('http://rpc.weblogs.com/RPC2', 'weblogUpdates.ping', vector (blog_name, blog_uri));
if (isarray(rc))
{
declare xt any;
xt := xml_tree_doc (rc);
error := cast (xpath_eval ('//flerror/text()', xml_cut(xt), 1) as varchar);
message := cast (xpath_eval ('//message/text()', xml_cut(xt), 1) as varchar);
}
}
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE)
values ('http://www.openlinksw.com/virtuoso/blog/api:ArrayOfRssFeed',
'<complexType name="ArrayOfRssFeed" targetNamespace="http://www.openlinksw.com/virtuoso/blog/api"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.openlinksw.com/virtuoso/blog/api">
<complexContent>
<restriction base="enc:Array">
<sequence>
<element name="item" type="tns:RssFeedStruct" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attributeGroup ref="enc:commonAttributes"/>
<attribute ref="enc:arrayType" wsdl:arrayType="tns:RssFeedStruct[]"/>
</restriction>
</complexContent>
</complexType>', 0)
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE)
values ('http://www.openlinksw.com/virtuoso/blog/api:RssFeedStruct',
'<complexType name="RssFeedStruct" targetNamespace="http://www.openlinksw.com/virtuoso/blog/api"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.openlinksw.com/virtuoso/blog/api">
<all>
<element name="title" type="string" nillable="true" />
<element name="blog" type="string" nillable="true" />
<element name="rss" type="string" nillable="true" />
<element name="format" type="string" nillable="true" />
<element name="lang" type="string" nillable="true" />
<element name="updatePeriod" type="string" nillable="true" />
<element name="updateFrequency" type="int" nillable="true" />
</all>
</complexType>', 0)
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE)
values ('http://www.openlinksw.com/virtuoso/blog/api:ArrayOfUserBlogs',
'<complexType name="ArrayOfUserBlogs" targetNamespace="http://www.openlinksw.com/virtuoso/blog/api"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.openlinksw.com/virtuoso/blog/api">
<complexContent>
<restriction base="enc:Array">
<sequence>
<element name="item" type="tns:UserBlogsStruct" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attributeGroup ref="enc:commonAttributes"/>
<attribute ref="enc:arrayType" wsdl:arrayType="tns:UserBlogsStruct[]"/>
</restriction>
</complexContent>
</complexType>', 0)
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE)
values ('http://www.openlinksw.com/virtuoso/blog/api:UserBlogsStruct',
'<complexType name="UserBlogsStruct" targetNamespace="http://www.openlinksw.com/virtuoso/blog/api"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.openlinksw.com/virtuoso/blog/api">
<all>
<element name="url" type="string" nillable="true" />
<element name="blogid" type="string" nillable="true" />
<element name="blogName" type="string" nillable="true" />
</all>
</complexType>', 0)
;
create procedure
GET_BLOG_FEED (in uri varchar)
returns any __SOAP_TYPE 'http://www.openlinksw.com/virtuoso/blog/api:ArrayOfRssFeed'
{
declare tit, rss, format, lang, upd_per, upd_freq, home, email, src_tit any;
declare links, channels any;
declare cont varchar;
declare xt, ct any;
declare hp, proto any;
declare low int;
declare newelm any;
retr:
low := 0;
hp := WS.WS.PARSE_URI (uri);
proto := lower(hp[0]);
if (proto <> 'http')
cont := XML_URI_GET (uri, '');
else
{
declare ur, ou, hdr varchar;
ur := uri; ou := ur;
try_again:
cont := http_get (ur, hdr);
if (hdr[0] like 'HTTP/1._ 30_ %')
{
ur := http_request_header (hdr, 'Location');
if (ur <> ou)
{
ou := ur;
goto try_again;
}
}
}
{
declare exit handler for sqlstate '*' { goto htmlp; };
xt := xml_tree_doc (xml_tree (cont, 0));
goto donep;
}
htmlp:;
xt := xml_tree_doc (xml_tree (cont, 2));
low := 1;
donep:;
-- HTML feed
if (xpath_eval ('/html', xt, 1) is not null)
{
tit := cast (xpath_eval ('//title[1]/text()', xt, 1) as varchar);
rss := cast (xpath_eval ('//head/link[ @rel="alternate" and @type="application/rss+xml" ]/@href', xt, 1) as varchar);
home := uri;
format := '';
lang := '';
upd_per := '';
upd_freq := 1;
if (rss is not null)
{
uri := rss;
goto retr;
}
else
signal ('.....', 'Unknown format');
}
-- RSS feed
else if (xpath_eval ('/rss|/RDF/channel', xt, 1) is not null)
{
xt := xml_cut (xpath_eval ('/rss/channel[1]|/RDF/channel[1]', xt, 1));
tit := cast (xpath_eval ('/channel/title/text()', xt, 1) as varchar);
home := cast (xpath_eval ('/channel/link/text()', xt, 1) as varchar);
email := cast (xpath_eval ('/channel/managingEditor/text()', xt, 1) as varchar);
rss := uri;
format := 'http://my.netscape.com/rdf/simple/0.9/';
lang := cast (xpath_eval ('/channel/language/text()', xt, 1) as varchar);
upd_per := 'hourly';
upd_freq := 1;
channels := vector (soap_box_structure ('title', tit, 'blog', home, 'rss', rss, 'format', format, 'lang', lang, 'updatePeriod', upd_per, 'updateFrequency', upd_freq));
}
-- OCS directory
else if (xpath_eval ('[ xmlns:ocs="http://alchemy.openjava.org/ocs/directory#" xmlns:ocs1="http://InternetAlchemy.org/ocs/directory#" ] /RDF//ocs:format|/RDF//ocs1:format', xt, 1) is not null)
{
tit := '';
declare cnls any;
declare ns varchar;
declare i, l int;
ns := '[ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" ' ||
' xmlns:ocs="http://alchemy.openjava.org/ocs/directory#" ' ||
' xmlns:ocs1="http://InternetAlchemy.org/ocs/directory#" ' ||
' xmlns:dc="http://purl.org/metadata/dublin_core#" ] ';
cnls := xpath_eval (ns || '/rdf:RDF/rdf:description[1]/rdf:description', xt, 0);
src_tit := xpath_eval (ns || '/rdf:RDF/rdf:description[1]/dc:title/text()', xt, 1);
i := 0; l := length (cnls);
channels := vector ();
while (i < l)
{
declare title, about varchar;
declare formats any;
tit := xpath_eval (ns||'/rdf:description/dc:title/text()', xml_cut (cnls[i]), 1);
home := xpath_eval (ns||'/rdf:description/@about', xml_cut (cnls[i]), 1);
formats := xpath_eval (ns||'/rdf:description/rdf:description[ocs:format or ocs1:format]',
xml_cut (cnls[i]), 0);
declare j,k int;
j := 0; k := length(formats);
while (j < k)
{
xt := xml_cut(formats[j]);
rss := cast(xpath_eval ('/description/@about', xt, 1) as varchar);
format := cast(xpath_eval ('/description/format/text()', xt, 1) as varchar);
lang := cast(xpath_eval ('/description/language/text()', xt, 1) as varchar);
upd_per := cast(xpath_eval ('/description/updatePeriod/text()', xt, 1) as varchar);
upd_freq := coalesce (xpath_eval ('/description/updateFrequency/text()', xt, 1), '1');
upd_freq := atoi (cast (upd_freq as varchar));
newelm := soap_box_structure ('title', tit, 'blog', home, 'rss', rss, 'format', format, 'lang', lang, 'updatePeriod', upd_per, 'updateFrequency', upd_freq);
channels := vector_concat (channels, vector (newelm));
j := j + 1;
}
i := i + 1;
}
}
-- OPML file
else if (xpath_eval ('/opml', xt, 1) is not null)
{
channels := vector ();
tit := xpath_eval ('/opml/head/title/text()', xt, 1);
if (low)
links := xpath_eval ('/opml/body/outline[ @htmlurl and @xmlurl ]', xt, 0);
else
links := xpath_eval ('/opml/body/outline[ @htmlUrl and @xmlUrl ]', xt, 0);
declare i, l int;
i := 0; l := length (links);
while (i < l)
{
declare _xt any;
_xt := xml_cut (links[i]);
rss := xpath_eval ('/outline/@xmlUrl|/outline/@xmlurl', _xt, 1);
home := xpath_eval ('/outline/@htmlUrl|/outline/@htmlurl', _xt, 1);
lang := xpath_eval ('/outline/@language', _xt, 1);
tit := xpath_eval ('/outline/@text|/outline/@title', _xt, 1);
format := 'http://my.netscape.com/rdf/simple/0.9/';
upd_per := 'daily';
upd_freq := 1;
i := i + 1;
newelm := soap_box_structure ('title', tit, 'blog', home, 'rss', rss, 'format', format, 'lang', lang, 'updatePeriod', upd_per, 'updateFrequency', upd_freq);
channels := vector_concat (channels, vector (newelm));
}
}
else
{
signal ('.....', 'Unknown format');
}
return channels;
}
;
create procedure
GET_USER_BLOGS (
in "username" varchar,
in "password" varchar
)
__soap_type 'http://www.openlinksw.com/virtuoso/blog/api:ArrayOfUserBlogs'
{
return "blogger.getUsersBlogs" ('appKey', "username", "password");
}
;
create procedure BLOG_API_PROC_LIST (in q varchar := 'DB')
{
declare arr any;
declare i, l int;
declare P_NAME, P_LNAME, P_OWNER varchar;
arr := BLOG.DBA."mt.supportedMethods" ();
arr := vector_concat (arr, vector ('DAV_COL_CREATE','DAV_RES_UPLOAD','DAV_DELETE','DAV_COPY','DAV_MOVE'));
i := 0; l := length (arr);
result_names (P_NAME, P_OWNER, P_LNAME);
while (i < l and q = 'DB')
{
result ('BLOG.DBA.'||arr[i], 'DBA', arr[i]);
i := i + 1;
}
}
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE) values (
'http://www.openlinksw.com/virtuoso/blog/api:ArrayOfWebDAVResource',
'<complexType name="ArrayOfWebDAVResource"
targetNamespace="http://www.openlinksw.com/virtuoso/blog/api"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.openlinksw.com/virtuoso/blog/api">
<complexContent>
<restriction base="enc:Array">
<sequence>
<element name="item" type="tns:WebDAVResourceStruct" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attributeGroup ref="enc:commonAttributes"/>
<attribute ref="enc:arrayType" wsdl:arrayType="tns:WebDAVResourceStruct[]"/>
</restriction>
</complexContent>
</complexType>', 0)
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE) values (
'http://www.openlinksw.com/virtuoso/blog/api:WebDAVResourceStruct',
'<complexType name="WebDAVResourceStruct"
targetNamespace="http://www.openlinksw.com/virtuoso/blog/api"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.openlinksw.com/virtuoso/blog/api">
<all>
<element name="fullPath" type="string" />
<element name="Name" type="string" />
<element name="type" type="string" />
<element name="length" type="int" nillable="true" />
<element name="created" type="dateTime" nillable="true" />
<element name="lastModified" type="dateTime" nillable="true" />
<element name="permissions" type="string" nillable="true" />
<element name="ownerName" type="string" nillable="true" />
<element name="groupName" type="string" nillable="true" />
<element name="contentType" type="string" nillable="true" />
<element name="displayName" type="string" nillable="true" minOccurs="0" />
<element name="sourceURL" type="string" nillable="true" minOccurs="0" />
</all>
</complexType>', 0)
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE) values (
'http://www.openlinksw.com/virtuoso/blog/api:ArrayOfRssFeedEntry',
'<complexType name="ArrayOfRssFeedEntry"
targetNamespace="http://www.openlinksw.com/virtuoso/blog/api"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.openlinksw.com/virtuoso/blog/api">
<complexContent>
<restriction base="enc:Array">
<sequence>
<element name="item" type="tns:RssFeedEntry" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attributeGroup ref="enc:commonAttributes"/>
<attribute ref="enc:arrayType" wsdl:arrayType="tns:RssFeedEntry[]"/>
</restriction>
</complexContent>
</complexType>', 0)
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE) values (
'http://www.openlinksw.com/virtuoso/blog/api:RssFeedEntry',
'<complexType name="RssFeedEntry"
targetNamespace="http://www.openlinksw.com/virtuoso/blog/api"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.openlinksw.com/virtuoso/blog/api">
<all>
<element name="title" type="string" nillable="true" minOccurs="1" />
<element name="URL" type="string" nillable="true" minOccurs="1" />
</all>
</complexType>', 0)
;
create procedure
GET_RSS_URL_COLLECTION (in "username" varchar, in "password" varchar)
__soap_type 'http://www.openlinksw.com/virtuoso/blog/api:ArrayOfRssFeedEntry'
{
declare ret any;
declare req "blogRequest";
req := new "blogRequest" ();
req.appkey := 'appKey';
req.user_name := "username";
req.passwd := "password";
"blogger_auth" (req);
ret := vector ();
for select BCD_TITLE, BCD_CHANNEL_URI
from BLOG..SYS_BLOG_CHANNEL_INFO, SYS_BLOG_CHANNELS, SYS_BLOG_INFO
where BC_CHANNEL_URI = BCD_CHANNEL_URI and BI_BLOG_ID = BC_BLOG_ID and BI_OWNER = req.auth_userid do
{
ret := vector_concat (ret, vector (soap_box_structure ('title', BCD_TITLE, 'URL', BCD_CHANNEL_URI)));
}
return ret;
}
;
create procedure
DELETE_RSS_FEED (in rssUrl varchar, in "username" varchar, in "password" varchar)
{
declare ret any;
declare req "blogRequest";
req := new "blogRequest" ();
req.appkey := 'appKey';
req.user_name := "username";
req.passwd := "password";
"blogger_auth" (req);
delete from SYS_BLOG_CHANNELS where BC_CHANNEL_URI = rssUrl and BC_BLOG_ID in
(select BI_BLOG_ID from SYS_BLOG_INFO where BI_OWNER = req.auth_userid);
return row_count();
}
;
create procedure
GET_DAV_DIRECTORY
(
in "location" varchar,
in "username" varchar,
in "password" varchar
)
__soap_type 'http://www.openlinksw.com/virtuoso/blog/api:ArrayOfWebDAVResource'
{
declare res any;
res := vector ();
for select FULL_PATH, NAME, TYPE, RLENGTH, CR_TIME, MOD_TIME, PERMS, OWNER, GRP, MIME_TYPE, ID
from "DB"."DBA"."DAV_DIR" where path = "location" and auth_uid = "username" and auth_pwd = "password" do
{
declare elm any;
declare uname, gname, dname, src varchar;
dname := NAME;
src := '';
uname := (select U_NAME from "DB"."DBA"."SYS_USERS" where U_ID = OWNER);
gname := (select U_NAME from "DB"."DBA"."SYS_USERS" where U_ID = GRP);
if (TYPE = 'r')
{
dname := coalesce ((select PROP_VALUE from WS.WS.SYS_DAV_PROP where PROP_PARENT_ID = ID and PROP_TYPE = 'R' and PROP_NAME = 'displayName'), NAME);
src := coalesce ((select PROP_VALUE from WS.WS.SYS_DAV_PROP where PROP_PARENT_ID = ID and PROP_TYPE = 'R' and PROP_NAME = 'sourceURL'), '');
}
elm := soap_box_structure
(
'fullPath', FULL_PATH,
'Name', NAME,
'type', TYPE,
'length', RLENGTH,
'created', CR_TIME,
'lastModified', MOD_TIME,
'permissions', PERMS,
'ownerName', uname,
'groupName', gname,
'contentType', MIME_TYPE,
'displayName', dname,
'sourceURL', src
);
res := vector_concat (res, vector (elm));
}
return res;
}
;
create procedure
BLOG_GET_TIME_LINE ()
{
declare lines any;
declare tim, ol varchar;
ol := stringdate ('1970-01-01');
if (not is_http_ctx ())
return ol;
lines := http_request_header ();
tim := http_request_header(lines, 'X-Feed-Items-New-Than');
if (isstring (tim))
ol := http_string_date (tim);
return ol;
}
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE) values
('urn:GoogleSearch:GoogleSearchResult','<complexType name="GoogleSearchResult"
xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:GoogleSearch" xmlns:typens="urn:GoogleSearch">
<all>
<element name="documentFiltering" type="boolean"/>
<element name="searchComments" type="string"/>
<element name="estimatedTotalResultsCount" type="int"/>
<element name="estimateIsExact" type="boolean"/>
<element name="resultElements" type="typens:ResultElementArray"/>
<element name="searchQuery" type="string"/>
<element name="startIndex" type="int"/>
<element name="endIndex" type="int"/>
<element name="searchTips" type="string"/>
<element name="directoryCategories" type="typens:DirectoryCategoryArray"/>
<element name="searchTime" type="double"/>
</all>
</complexType>', 0)
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE) values
('urn:GoogleSearch:ResultElement','<xsd:complexType name="ResultElement"
targetNamespace="urn:GoogleSearch" xmlns:typens="urn:GoogleSearch" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:all>
<xsd:element name="summary" type="xsd:string"/>
<xsd:element name="URL" type="xsd:string"/>
<xsd:element name="snippet" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="cachedSize" type="xsd:string"/>
<xsd:element name="relatedInformationPresent" type="xsd:boolean"/>
<xsd:element name="hostName" type="xsd:string"/>
<xsd:element name="directoryCategory" type="typens:DirectoryCategory"/>
<xsd:element name="directoryTitle" type="xsd:string"/>
</xsd:all>
</xsd:complexType>', 0)
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE) values
('urn:GoogleSearch:ResultElementArray','<xsd:complexType name="ResultElementArray"
targetNamespace="urn:GoogleSearch" xmlns:typens="urn:GoogleSearch" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="typens:ResultElement[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>', 0)
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE) values
('urn:GoogleSearch:DirectoryCategoryArray','<xsd:complexType name="DirectoryCategoryArray"
targetNamespace="urn:GoogleSearch"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:typens="urn:GoogleSearch"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="typens:DirectoryCategory[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>', 0)
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE) values
('urn:GoogleSearch:DirectoryCategory','<xsd:complexType name="DirectoryCategory"
targetNamespace="urn:GoogleSearch"
xmlns:typens="urn:GoogleSearch"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:all>
<xsd:element name="fullViewableName" type="xsd:string"/>
<xsd:element name="specialEncoding" type="xsd:string"/>
</xsd:all>
</xsd:complexType>', 0)
;
create procedure blog_search_google (in q any, in k any, in n int := 10)
{
declare res, xt, arr, o any;
declare i, l int;
declare title, URL varchar;
o := vector ();
if (length (k) = 0 or length (q) = 0)
return o;
declare exit handler for sqlstate '*' { return vector (); };
res := soap_call_new ('api.google.com', '/search/beta2', 'urn:GoogleSearch', 'doGoogleSearch',
vector ('key', k,
'q', q,
vector ('start', 'int'), 0,
'maxResults', n,
'filter', soap_boolean (0),
'restrict', '',
'safeSearch', soap_boolean(0),
'lr', '',
'ie', '',
'oe', ''),
11, null, null, 'urn:GoogleSearchAction');
xt := xml_tree_doc (res);
xt := xpath_eval ('//return', xt, 1);
res := soap_box_xml_entity_validating (xml_cut (xt), 'urn:GoogleSearch:GoogleSearchResult');
arr := get_keyword ('resultElements', res, vector ());
i := 0; l := length (arr);
while (i < l)
{
declare elm any;
elm := arr[i];
title := get_keyword ('title', elm);
URL := get_keyword ('URL', elm);
o := vector_concat (o , vector (vector (title, URL)));
i := i + 1;
}
return o;
}
;
insert soft "DB"."DBA"."SYS_SOAP_DATATYPES" (SDT_NAME, SDT_SCH, SDT_TYPE) values
('http://soap.amazon.com:KeywordRequest',
'<xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema"
name="KeywordRequest" targetNamespace="http://soap.amazon.com">
<xs:complexContent>
<xs:restriction base="enc:Struct" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/">
<xs:sequence>
<xs:element name="keyword" type="xs:string" nillable="0" minOccurs="1" maxOccurs="1" />
<xs:element name="page" type="xs:string" nillable="0" minOccurs="1" maxOccurs="1" />
<xs:element name="mode" type="xs:string" nillable="0" minOccurs="1" maxOccurs="1" />
<xs:element name="tag" type="xs:string" nillable="0" minOccurs="1" maxOccurs="1" />
<xs:element name="type" type="xs:string" nillable="0" minOccurs="1" maxOccurs="1" />
<xs:element name="devtag" type="xs:string" nillable="0" minOccurs="1" maxOccurs="1" />
<xs:element name="sort" type="xs:string" nillable="0" minOccurs="0" maxOccurs="1" />
<xs:element name="locale" type="xs:string" nillable="0" minOccurs="0" maxOccurs="1" />
<xs:element name="price" type="xs:string" nillable="0" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>', 0)
;
create procedure blog_search_amazon (in q any, in k any, in n int := 10)
{
declare res, xt, arr, o, pars any;
declare i, l int;
declare title, URL varchar;
o := vector ();
if (length (k) = 0 or length (q) = 0)
return o;
declare exit handler for sqlstate '*' { return vector (); };
pars := soap_box_structure (
'keyword', q,
'page', '1',
'mode', 'books',
'tag', 'webservices-20',
'devtag', k,
'type', 'heavy');
res := soap_call_new ('soap.amazon.com','/onca/soap3', 'http://soap.amazon.com', 'KeywordSearchRequest',
vector (vector('KeywordSearchRequest', 'http://soap.amazon.com:KeywordRequest'), pars), 11,
NULL, NULL, '"http://soap.amazon.com"', 0);
xt := xml_tree_doc (res);
arr := xpath_eval ('//Details/Details[ProductName]', xt, 0);
i := 0; l := __min (length (arr), n);
while (i < l)
{
declare elm any;
elm := xml_cut (arr[i]);
title := cast(xpath_eval ('ProductName/text()', elm) as varchar);
URL := cast (xpath_eval ('Url/text()', elm) as varchar);
if (title is not null and URL is not null)
o := vector_concat (o , vector (vector (title, URL)));
i := i + 1;
}
return o;
}
;
create trigger SYS_BLOG_CHANNELS_D_C after delete on SYS_BLOG_CHANNELS referencing old as O
{
if (not exists (select 1 from SYS_BLOG_CHANNELS where BC_BLOG_ID <> O.BC_BLOG_ID and BC_CHANNEL_URI = O.BC_CHANNEL_URI))
{
delete from SYS_BLOG_CHANNEL_INFO where BCD_CHANNEL_URI = O.BC_CHANNEL_URI;
}
}
;
create procedure BLOG2_FEED_SUBSCRIBE
(in blogid varchar,
in feed_url any,
in home_url any,
in title any,
in format any,
in lang any,
in upd_per any,
in freq any,
in cat any,
in foaf varchar,
in email varchar
)
{
declare cat_id int;
declare f_is_blog int;
if (lower(feed_url) not like 'http://%')
{
signal ('22023', 'Feed Url is not valid');
}
if (cat <> '' and not exists (select 1 from BLOG.DBA.SYS_BLOG_CHANNEL_CATEGORY where BCC_NAME = cat and BCC_BLOG_ID = blogid))
{
f_is_blog := 0;
if (strstr (lower (cat), 'blog roll') is not null)
f_is_blog := 1;
insert into BLOG.DBA.SYS_BLOG_CHANNEL_CATEGORY (BCC_BLOG_ID, BCC_NAME, BCC_IS_BLOG)
values (blogid, cat, f_is_blog);
}
cat_id := (select BCC_ID from BLOG.DBA.SYS_BLOG_CHANNEL_CATEGORY where BCC_NAME = cat and BCC_BLOG_ID = blogid);
insert replacing BLOG.DBA.SYS_BLOG_CHANNELS (BC_CHANNEL_URI, BC_BLOG_ID, BC_CAT_ID) values (feed_url, blogid, cat_id);
insert replacing BLOG.DBA.SYS_BLOG_CHANNEL_INFO
(BCD_TITLE, BCD_HOME_URI, BCD_CHANNEL_URI, BCD_IS_BLOG, BCD_SOURCE_URI,
BCD_FORMAT, BCD_UPDATE_PERIOD, BCD_LANG, BCD_UPDATE_FREQ)
values (title, home_url, feed_url, f_is_blog, null, format, upd_per, lang, freq);
if (foaf = '1')
{
insert replacing SYS_BLOG_CONTACTS (BF_BLOG_ID, BF_NAME, BF_NICK, BF_MBOX, BF_HOMEPAGE, BF_WEBLOG, BF_RSS)
values (blogid, title, '', email, home_url, home_url, feed_url);
}
}
;
create procedure BLOG_GET_ATOM_URL_P (in url any)
{
declare hdr, cnt, atomp, was_html, xt any;
declare post_uri, blogname, blog_url varchar;
result_names (post_uri, blogname, blog_url);
if (not length (url))
return;
was_html := 0;
declare exit handler for sqlstate '*'
{
rollback work;
return null;
}
;
again:
--if (was_html)
-- return null;
commit work;
cnt := GET_URL_AND_REDIRECTS (url, hdr);
xt := xml_tree_doc(xml_tree(cnt, 2, '', 'UTF-8'));
if (xpath_eval ('/html', xt) is not null)
{
-- try to get atom apis
blog_url := url;
url := cast (xpath_eval ('/html/head/link[@rel="alternate" and @type="application/atomserv+xml"]/@href', xt) as varchar);
was_html := 1;
goto again;
}
else if (xpath_eval ('/service', xt) is not null)
{
atomp := cast (xpath_eval ('/service/workspace/collection/@href', xt) as varchar);
blogname := coalesce (xpath_eval ('string (/service/workspace/collection/@title)', xt), '');
blogname := blog_wide2utf (blogname);
result (atomp, blogname, blog_url);
}
else if (0 and xpath_eval ('/feed', xt) is not null) -- XXX: disabled
{
-- probably is atom
atomp := cast (xpath_eval ('/feed/link[@rel="self" and @type="application/atom+xml"]/@href', xt) as varchar);
blogname := coalesce (xpath_eval ('string (/feed/title)', xt), '');
blogname := blog_wide2utf (blogname);
blog_url := cast (xpath_eval ('/feed/link[@rel="alternate" and @type="text/html"]/@href', xt) as varchar);
result (atomp, blogname, blog_url);
}
return atomp;
}
;
blog2_exec_no_error ('create procedure view BLOG_GET_ATOM_URL
as BLOG.DBA.BLOG_GET_ATOM_URL_P (URL) (post_uri varchar, blogname varchar, blog_url varchar)')
;
create procedure
ROUTING_PROCESS_BLOGS (in job_id int, in proto_id int, in dst varchar, in dst_id any,
in a_usr varchar, in a_pwd varchar, in item_id any,
in tag varchar, in eid varchar, in iid varchar, in send_delete int)
{
declare eids, post_stat, post_err, iids any;
declare _RL_POST_ID, _RL_F_POST_ID, _RL_TYPE, _RL_COMMENT_ID, _RL_RETRANSMITS any;
declare tags any;
declare rc int;
while (1) {
post_stat := 1;
post_err := null;
{
whenever not found goto enf;
select top 1 RL_POST_ID, RL_F_POST_ID, RL_TYPE, RL_COMMENT_ID, RL_RETRANSMITS
into _RL_POST_ID, _RL_F_POST_ID, _RL_TYPE, _RL_COMMENT_ID, _RL_RETRANSMITS
from SYS_BLOGS_ROUTING_LOG where RL_JOB_ID = job_id and RL_PROCESSED = 0;
}
declare post_id, typ, ntype, fpostid varchar;
declare req BLOG.DBA."blogRequest";
declare _B_USER_ID, _B_CONTENT, _B_POST_ID, _B_TS, _B_TITLE any;
declare _B_META "MWeblogPost";
declare _BM_COMMENT, _BM_NAME, _BM_E_MAIL, _BM_HOME_PAGE, _BM_ADDRESS any;
_B_CONTENT := null;
_BM_COMMENT := null;
_BM_NAME := null;
_BM_E_MAIL := null;
_BM_HOME_PAGE := null;
_BM_ADDRESS := null;
{
whenever not found goto nextstep;
select B_META, B_USER_ID, B_CONTENT, B_POST_ID, B_TS, B_TITLE into
_B_META, _B_USER_ID, _B_CONTENT, _B_POST_ID, _B_TS, _B_TITLE
from SYS_BLOGS where B_BLOG_ID = item_id and B_POST_ID = _RL_POST_ID;
tags := '';
for select BT_TAG from BLOG_POST_TAGS_STAT where postid = _RL_POST_ID do
{
tags := tags || sprintf ('<a href="index.vspx?tag=%s" rel="tag" style="display:none;">%s</a>', BT_TAG, BT_TAG);
}
if (_B_CONTENT is not null)
{
_B_CONTENT := blob_to_string (_B_CONTENT);
if (length (tags))
_B_CONTENT := _B_CONTENT || tags;
if (proto_id = 1 and length (_B_TITLE))
{
_B_CONTENT := '<div><div style="display:none;">'||_B_TITLE||'</div>'||_B_CONTENT||'</div>';
}
}
else
_B_CONTENT := '';
if (_B_META is not null)
{
_B_META.description := blog_utf2wide (blob_to_string (_B_CONTENT));
}
nextstep:;
}
post_id := _RL_POST_ID;
fpostid := _RL_F_POST_ID;
{
declare exit handler for sqlstate '*' {
_RL_RETRANSMITS := _RL_RETRANSMITS - 1;
post_stat := 2;
if (1) log_message (__SQL_STATE || ':' || __SQL_MESSAGE );
post_err := __SQL_MESSAGE;
goto next_rec;
};
req := new "blogRequest" ();
req.appkey := 'appKey';
req.blogid := dst_id;
req.postId := _RL_F_POST_ID;
req.user_name := a_usr;
req.passwd := a_pwd;
req.header := 'X-Virt-BlogID: ' || registry_get ('WeblogServerID') || ';' || item_id || '\r\n';
eids := coalesce (split_and_decode (eid, 0, '\0\0;'), vector ());
iid := trim (iid, '; ');
iids := coalesce (split_and_decode (iid, 0, '\0\0;'), vector ());
if (_RL_TYPE in ('I', 'U'))
{
if ((length (iids) and not exists
(select 1 from MTYPE_BLOG_CATEGORY where position (MTB_CID, iids)
and MTB_POST_ID = post_id and MTB_BLOG_ID = item_id))
or
exists (select 1 from MTYPE_BLOG_CATEGORY where position (MTB_CID, eids) and
MTB_POST_ID = post_id and MTB_BLOG_ID = item_id))
{
if (0) log_message (sprintf ('Routing denied for post %s', post_id));
if (_RL_TYPE = 'U')
{
_RL_TYPE := 'D';
update SYS_BLOGS_ROUTING_LOG set RL_TYPE = 'D'
where RL_JOB_ID = job_id and RL_POST_ID = post_id and RL_COMMENT_ID = _RL_COMMENT_ID;
}
else
{
update SYS_BLOGS_ROUTING_LOG set RL_TYPE = 'D', RL_PROCESSED = 1
where RL_JOB_ID = job_id and RL_POST_ID = post_id and RL_COMMENT_ID = _RL_COMMENT_ID;
goto next;
}
}
doit:
req.struct := BLOG_MESSAGE_OR_META_DATA (_B_META, _B_USER_ID, _B_CONTENT, _B_POST_ID, _B_TS);
}
if (_RL_COMMENT_ID <> -1)
{
declare exit handler for sqlstate '*'
{
if (0) log_message (__SQL_STATE || ':' || __SQL_MESSAGE );
};
select BM_COMMENT, BM_NAME, BM_E_MAIL, BM_HOME_PAGE, BM_ADDRESS into
_BM_COMMENT, _BM_NAME, _BM_E_MAIL, _BM_HOME_PAGE, _BM_ADDRESS
from BLOG_COMMENTS where BM_BLOG_ID = item_id and BM_POST_ID = _RL_POST_ID and BM_ID = _RL_COMMENT_ID;
if (_BM_COMMENT is not null)
_BM_COMMENT := blob_to_string (_BM_COMMENT);
else
_BM_COMMENT := '';
}
commit work;
--dbg_printf ('upstream : [%s] proto=%d job=%d', dst, proto_id, job_id);
if (proto_id = 1) -- Blogger
{
if (_RL_TYPE = 'I')
fpostid := blogger.new_Post (dst, req, blog_utf2wide (_B_CONTENT));
else if (_RL_TYPE = 'U')
blogger.edit_Post (dst, req, blog_utf2wide (_B_CONTENT));
else if (_RL_TYPE = 'D' and send_delete)
blogger.delete_Post (dst, req);
}
else if (proto_id = 2) -- MetaWeblog
{
if (_RL_TYPE = 'I')
fpostid := metaweblog.new_Post (dst, req);
else if (_RL_TYPE = 'U')
metaweblog.edit_Post (dst, req);
else if (_RL_TYPE = 'D' and send_delete)
blogger.delete_Post (dst, req);
}
else if (proto_id = 3) -- MoveableType
{
if (_RL_TYPE = 'I')
fpostid := metaweblog.new_Post (dst, req);
else if (_RL_TYPE = 'U')
metaweblog.edit_Post (dst, req);
else if (_RL_TYPE = 'D' and send_delete)
blogger.delete_Post (dst, req);
}
else if (proto_id = 5) -- Atom
{
if (_RL_TYPE = 'I')
fpostid := atom.new_Post (dst_id, req);
else if (_RL_TYPE = 'U')
atom.edit_Post (req.postId, req);
else if (_RL_TYPE = 'D' and send_delete)
atom.delete_Post (req.postId, req);
}
else if (proto_id = 4)
{
declare oemail, emails, hdrs, _bi_home, _bi_title, host varchar;
declare mime_parts any;
select BI_E_MAIL, BI_HOME, BI_TITLE into oemail, _bi_home, _bi_title from SYS_BLOG_INFO where BI_BLOG_ID = item_id;
commit work;
if (_RL_TYPE = 'I')
{
mime_parts := vector (0,
DB.DBA.MIME_PART ('text/html; charset=UTF-8', null, null, _B_CONTENT));
hdrs := BLOG_MAKE_MAIL_SUBJECT ('[Weblog post] '||_B_TITLE);
for select BV_NAME, BV_E_MAIL, BV_POST_ID, BV_VIA_DOMAIN from SYS_BLOG_VISITORS
where BV_NOTIFY = 1 and BV_BLOG_ID = item_id and length (BV_E_MAIL)
and (BV_POST_ID = _RL_POST_ID or length (BV_POST_ID) = 0)
do
{
host := BLOG_GET_HOST ();
mime_parts[0] := DB.DBA.MIME_PART ('text/plain; charset=UTF-8', null, null,
sprintf ('%s,\r\nThere\'s a new post %s (http://%s%s?id=%s)\r\n in %s (http://%s%s).\r\n\r\nTo stop receiving notifications click\r\nhttp://%s/weblog/public/r_unsubscribe.vspx?e=%U&b=%U&p=%U\r\n',
coalesce (BV_NAME, 'Dear subscriber'),
_B_TITLE,
host, _bi_home, _RL_POST_ID,
_bi_title,
host, _bi_home,
host,
BV_E_MAIL, item_id, BV_POST_ID));
smtp_send (dst, oemail, BV_E_MAIL, concat (hdrs, DB.DBA.MIME_BODY (mime_parts)));
}
update SYS_BLOGS_ROUTING_LOG set RL_TYPE = 'D'
where RL_JOB_ID = job_id and RL_POST_ID = post_id and RL_COMMENT_ID = _RL_COMMENT_ID;
}
else if (_RL_TYPE = 'CI')
{
mime_parts := vector (0,
DB.DBA.MIME_PART ('text/html; charset=UTF-8', null, null, _BM_COMMENT));
hdrs := BLOG_MAKE_MAIL_SUBJECT ('[Weblog post comment] Re: '||_B_TITLE||' from '||coalesce (_BM_NAME, _BM_E_MAIL, '<unknown sender>'));
for select BV_NAME, BV_E_MAIL,BV_POST_ID, BV_VIA_DOMAIN from SYS_BLOG_VISITORS
where BV_NOTIFY = 1 and BV_BLOG_ID = item_id
and (BV_POST_ID = _RL_POST_ID or length (BV_POST_ID) = 0)
do
{
if (BV_E_MAIL = _BM_E_MAIL)
goto next_mail;
host := BLOG_GET_HOST ();
mime_parts[0] := DB.DBA.MIME_PART ('text/plain; charset=UTF-8', null, null,
sprintf ('%s,\r\nThere\'s a new comment Re. %s (http://%s%s?id=%s) in %s (http://%s%s).\r\n\r\nTo stop receiving notifications click \r\nhttp://%s/weblog/public/r_unsubscribe.vspx?e=%U&b=%U&p=%U\r\n',
coalesce (BV_NAME, 'Dear subscriber'),
_B_TITLE,
host, _bi_home, _RL_POST_ID,
_bi_title,
host, _bi_home,
host,
BV_E_MAIL, item_id, BV_POST_ID));
smtp_send (dst, oemail, BV_E_MAIL, concat (hdrs, DB.DBA.MIME_BODY (mime_parts)));
next_mail:;
}
update SYS_BLOGS_ROUTING_LOG set RL_TYPE = 'D'
where RL_JOB_ID = job_id and RL_POST_ID = post_id and RL_COMMENT_ID = _RL_COMMENT_ID;
}
}
else if (proto_id = 6)
{
if (_RL_TYPE = 'I')
{
fpostid := BLOG_DELICIOUS_ADD (post_id, dst_id, a_usr, a_pwd);
}
else if (_RL_TYPE = 'U')
{
BLOG_DELICIOUS_DEL (fpostid, a_usr, a_pwd);
fpostid := BLOG_DELICIOUS_ADD (post_id, dst_id, a_usr, a_pwd);
}
else if (_RL_TYPE = 'D' and send_delete)
{
BLOG_DELICIOUS_DEL (fpostid, a_usr, a_pwd);
}
}
}
next_rec:;
update SYS_BLOGS_ROUTING_LOG set RL_F_POST_ID = fpostid, RL_PROCESSED = post_stat, RL_ERROR = post_err,
RL_RETRANSMITS = _RL_RETRANSMITS
where RL_JOB_ID = job_id and RL_POST_ID = post_id and RL_COMMENT_ID = _RL_COMMENT_ID;
next:;
}
enf:
delete from SYS_BLOGS_ROUTING_LOG where RL_PROCESSED = 1 and RL_TYPE = 'D';
update SYS_BLOGS_ROUTING_LOG set RL_PROCESSED = 0 where RL_JOB_ID = job_id and RL_RETRANSMITS > 0 and RL_PROCESSED = 2;
rc := row_count ();
return rc;
}
;
create procedure BLOG..not_same_day (inout d1 any, inout d2 any)
{
if (dayofyear (d1) = dayofyear (d2) and year (d1) = year (d2))
{
return 0;
}
return 1;
}
;
create procedure BLOG..not_same_month (inout d1 any, inout d2 any)
{
if (month (d1) = month (d2) and year (d1) = year (d2))
{
return 0;
}
return 1;
}
;
create procedure DB.DBA.BLOG_MAIL_VALIDATE (in login any)
{
declare opts, dummy, bid, sec, U_NAME any;
whenever not found goto noblog;
if (regexp_match ('^[A-Za-z0-9 _@\.]+-blog-[0-9]+\.[A-Za-z0-9]+\$', login) is not null)
{
bid := regexp_match ('^[A-Za-z0-9 _@\.]+-blog-[0-9]+\.', login);
sec := substring (login, length (bid) + 1, length (login));
bid := rtrim (bid, '.');
--dbg_obj_print (login, bid, sec);
SELECT BI_OPTIONS into opts from BLOG..SYS_BLOG_INFO where BI_BLOG_ID = bid;
opts := deserialize (blob_to_string (opts));
if (isarray (opts) and get_keyword ('MoblogSecret', opts, '') = sec)
{
result (bid);
return 1;
}
}
noblog:
return 0;
}
;
create procedure BLOG.DBA.MOBLOG_MAIL_VALIDATE (in login any)
{
declare opts, dummy, bid, sec, U_NAME, rc any;
result_names (U_NAME);
whenever not found goto nouser;
SELECT u.U_NAME into dummy FROM WS.WS.SYS_DAV_USER u WHERE u.U_NAME = login AND U_ACCOUNT_DISABLED=0;
result (dummy);
return 1;
nouser:
rc := DB.DBA.BLOG_MAIL_VALIDATE (login);
return rc;
}
;
create procedure BLOG..ADD_CONTACT_FROM_FEED (in url1 any, in blogid any)
{
declare res, url, hdr, home, tit any;
declare xt, xp, mail, author any;
whenever not found goto nff;
select BCD_HOME_URI, BCD_TITLE into home, tit from BLOG.DBA.SYS_BLOG_CHANNEL_INFO where BCD_CHANNEL_URI = url1;
declare exit handler for sqlstate '*'
{
rollback work;
return;
};
url := url1;
commit work;
res := GET_URL_AND_REDIRECTS (url, hdr);
xt := xtree_doc (res, 2, '', 'UTF-8');
if (xpath_eval ('/feed', xt) is not null)
{
mail := xpath_eval ('/feed/author/email/text()', xt);
author := xpath_eval ('/feed/author/name/text()', xt);
}
else if (xpath_eval ('/rss', xt) is not null)
{
mail := xpath_eval ('/channel/managingEditor/text()', xt);
author := tit;
}
else
{
return 0;
}
insert soft BLOG.DBA.SYS_BLOG_CONTACTS (BF_BLOG_ID, BF_NAME, BF_MBOX, BF_HOMEPAGE, BF_WEBLOG, BF_RSS) values
(blogid, author, mail, home, home, url1);
nff:;
}
;
create procedure BLOG..BLOG_TAGS_RESULT (in data any)
{
declare tag varchar;
declare n int;
result_names (tag, n);
foreach (any t in data) do
{
result (t[0], t[1]);
}
}
;
create procedure BLOG..CHANNELS_UPGRADE ()
{
if (not exists (select 1 from BLOG..SYS_BLOG_CHANNEL_INFO where BCD_AUTHOR_NAME is null))
return;
update BLOG..SYS_BLOG_CHANNEL_INFO set BCD_AUTHOR_NAME = BCD_TITLE, BCD_AUTHOR_EMAIL = '' where BCD_AUTHOR_NAME is null;
}
;
BLOG..CHANNELS_UPGRADE ()
;
create procedure BLOG..BLOG_MAKE_ENCLOSURE (in url any)
{
declare enc BLOG.DBA."MWeblogEnclosure";
declare h, ourl, len any;
if (not length (url))
return null;
enc := new BLOG.DBA."MWeblogEnclosure" ();
enc.url := url;
h := null;
again:
ourl := url;
http_get (url, h, 'HEAD');
if (h[0] like 'HTTP/1._ 30_ %')
{
url := http_request_header (h, 'Location');
if (isstring (url))
goto again;
}
else if (h[0] not like 'HTTP/1._ 200 %')
signal ('22023', trim(h[0], '\r\n'), 'BLOG2');
len := http_request_header (h, 'Content-Length');
if (not isstring (len))
len := '0';
enc."length" := atoi (len);
enc."type" := http_request_header (h, 'Content-Type');
if (enc."length" < 1)
signal ('22023', 'The supplied URL do not reference any valid resource (content length is zero bytes)');
return enc;
}
;
-- BlogAPI
create procedure BLOG_API_INIT ()
{
if (not exists (select 1 from "DB"."DBA"."SYS_USERS" where U_NAME = 'BLOG_API'))
{
DB.DBA.USER_CREATE ('BLOG_API', uuid(), vector ('DISABLED', 1, 'LOGIN_QUALIFIER', 'BLOG'));
}
}
;
BLOG_API_INIT ()
;
create procedure "Search"
(
in blogId varchar,
in q nvarchar,
in maxResults int := 10,
in startDate datetime := null,
in endDate datetime := null,
in category varchar := null,
in tags varchar := null
)
returns DB.DBA.XMLType
{
declare xt DB.DBA.XMLType;
declare ses, xd any;
declare home, host varchar;
ses := string_output ();
set http_charset='utf-8';
set_user_id ('dba');
q := blog_wide2utf (q);
if (not isinteger (maxResults))
maxResults := 10;
if (maxResults < 0 or maxResults > 1000)
signal ('22023', 'Invalid maxResults input, must be greater than 0 and less than 1000.');
declare exit handler for not found
{
signal ('22023', 'No such blog');
};
select BI_HOME into home from SYS_BLOG_INFO where BI_BLOG_ID = blogId;
host := BLOG_GET_HOST ();
http ('<result>', ses);
-- BEGIN
{
declare stat, msg, dta, mdta, h, pars, dexp, twhere, atb any;
declare qstr, qry varchar;
qstr := DB.DBA.FTI_MAKE_SEARCH_STRING (q);
dexp := '';
pars := vector ('', blogId, blogId, qstr);
if (startDate is not null)
{
dexp := ' and B_TS >= ? ';
pars := vector_concat (pars, vector (startDate));
}
if (endDate is not null)
{
dexp := dexp || ' and B_TS <= ? ';
pars := vector_concat (pars, vector (endDate));
}
if (length (category))
{
dexp := dexp || ' and exists (select 1 from BLOG..MTYPE_BLOG_CATEGORY, BLOG..MTYPE_CATEGORIES
where MTB_CID = MTC_ID and MTC_BLOG_ID = MTB_BLOG_ID and MTB_POST_ID = B_POST_ID and
strcasestr (MTC_NAME, ?) is not null)';
pars := vector_concat (pars, vector (category));
}
atb := '';
twhere := '';
if (length (tags))
{
atb := ' BLOG..BLOG_TAG a, ';
twhere :=
sprintf (' contains (BT_TAGS,
''[__lang "x-ViDoc"] %s and %s'', offband, BT_POST_ID) and BT_POST_ID = B_POST_ID and ',
DB.DBA.FTI_MAKE_SEARCH_STRING (tags), 'b'||replace(blogId, '-', '_'));
}
qry := 'select top ' || cast (maxResults as varchar) ||
' NULL, concat (?,\'?id=\', B_POST_ID), B_TITLE,
B_USER_ID, B_TS, B_MODIFIED, b.SCORE, B_POST_ID
from ' || atb || ' BLOG..SYS_BLOGS b,
(select BI_BLOG_ID as BA_C_BLOG_ID, BI_BLOG_ID as BA_M_BLOG_ID
from BLOG..SYS_BLOG_INFO where BI_BLOG_ID = ? union all
select * from (select BA_C_BLOG_ID, BA_M_BLOG_ID
from BLOG.DBA.SYS_BLOG_ATTACHES where BA_M_BLOG_ID = ?) name1) name2
where ' || twhere || 'B_BLOG_ID = BA_C_BLOG_ID and contains (B_CONTENT, ?) ' || dexp || '
order by ';
qry := qry || ' b.SCORE desc';
stat := '00000';
exec (qry, stat, msg, pars, 0, null, null, h);
if (stat <> '00000')
signal (stat, msg);
while (0 = exec_next (h, null, null, dta))
{
--dbg_obj_print (dta);
http ('<entry>', ses);
http (sprintf ('<title><![CDATA[%s]]></title>', dta[2]), ses);
http (sprintf ('<link>http://%s%sindex.vspx%s</link>', host, home, dta[1]), ses);
http (sprintf ('<published>%s</published>', DB.DBA.date_iso8601 (dta[4])), ses);
http (sprintf ('<score>%d</score>', dta[6]), ses);
http (sprintf ('<id>%s</id>', dta[7]),ses);
http ('</entry>', ses);
}
exec_close (h);
}
-- END
http ('</result>', ses);
ses := string_output_string (ses);
xd := xtree_doc (ses, 0, '', 'UTF-8');
xml_tree_doc_encoding (xd, 'UTF-8');
xt := new DB.DBA.XMLType (xd);
return xt;
};
grant execute on "Search" to BLOG_API;
create procedure BLOG_ARCH_DATE_POSTS (in blogid varchar, in sel varchar := null, in community int)
{
declare dta, mdta, h, pars any;
declare sqlstr, arch_str varchar;
declare d1, d2 any;
arch_str := '';
sel := trim (sel);
if (sel is not null and length (sel))
{
if (sel like '%-%-%')
{
d1 := stringdate (sel);
d2 := dateadd ('day', 1, d1);
}
else if (sel like '%-%')
{
d1 := stringdate (sel || '-01');
d2 := dateadd ('month', 1, d1);
}
else
{
d1 := stringdate (sel || '-01-01');
d2 := dateadd ('year', 1, d1);
}
arch_str := sprintf (' and B_TS >= \'%s\' and B_TS < \'%s\' ',
datestring (cast (d1 as date)), datestring (cast (d2 as date)));
}
if (community)
{
pars := vector (blogid, blogid);
sqlstr := 'select B_TS, B_TITLE, B_POST_ID from BLOG..SYS_BLOGS, (select BI_BLOG_ID as BA_C_BLOG_ID, BI_BLOG_ID as BA_M_BLOG_ID from BLOG..SYS_BLOG_INFO where BI_BLOG_ID = ? union all select * from (select BA_C_BLOG_ID, BA_M_BLOG_ID from BLOG.DBA.SYS_BLOG_ATTACHES where BA_M_BLOG_ID = ?) name1) name2 where B_BLOG_ID = BA_C_BLOG_ID ';
}
else
{
pars := vector (blogid);
sqlstr := 'select B_TS, B_TITLE, B_POST_ID from BLOG..SYS_BLOGS where B_BLOG_ID = ?';
}
sqlstr := sqlstr || arch_str;
exec (sqlstr, null, null, pars, 0, mdta, null, h);
exec_result_names (mdta[0]);
while (0 = exec_next (h, null, null, dta))
exec_result (dta);
exec_close (h);
};
blog2_exec_no_error ('create procedure view BLOG_ARCH_DATE_POSTS as BLOG.DBA.BLOG_ARCH_DATE_POSTS (blogid, sel, community)
(B_TS datetime, B_TITLE varchar, B_POST_ID varchar)');
create procedure get_date_array (in dt date)
{
declare i, l int;
declare m, y, w, d int;
declare dw, dm int;
declare arr, res any;
arr := vector ('','','','','','','');
i := 0;
m := month (dt);
y := year (dt);
dm := BLOG..GET_DAYS_IN_MONTH (dt);
res := vector ();
i := 1;
while (i <= dm)
{
declare tmp date;
whenever sqlstate '*' goto endd;
tmp := stringdate (sprintf ('%d-%d-%d', y, m, i));
if (i > 1 and dayofmonth (tmp) = 1)
goto endd;
dw := dayofweek(tmp);
aset (arr, dw - 1, cast (i as varchar));
if (0 = mod (dw, 7))
{
res := vector_concat (res, vector (arr));
arr := vector ('','','','','','','');
}
i := i + 1;
}
endd:
res := vector_concat (res, vector (arr));
return res;
}
;
create procedure make_dasboard_item
(in what varchar, in tim datetime, in title varchar, in uname varchar, in url varchar, in comment varchar,
in dash any, in id any := -1, in action varchar := 'insert', in u_name varchar := null, in mail varchar := null)
{
declare ret any;
declare ses, ses1 any;
if (not __proc_exists ('DB.DBA.WA_NEW_BLOG_IN'))
return null;
--dbg_printf ('make_dasboard_item what=[%s] action=[%s] id=[%s]', what, action, cast(id as varchar));
if (isinteger (mail))
mail := '';
ses := string_output ();
ses1 := string_output ();
http ('<blog-db>', ses);
if (what = 'post' and isstring (id))
id := atoi (id);
if (dash is not null)
{
declare xt, xp any;
declare i, l int;
xt := xtree_doc (dash);
xp := xpath_eval ('/blog-db/*', xt, 0);
l := length (xp);
if (l = 10 and action = 'insert')
i := 1;
else
i := 0;
if (l > 10)
l := 10;
for (;i < l; i := i + 1)
{
declare pid, cwhat any;
pid := xpath_eval ('number(@id)', xp[i]);
cwhat := cast (xpath_eval ('local-name ()', xp[i]) as varchar);
if (pid is null)
pid := -2;
if (action = 'insert' or pid <> id or cwhat <> what)
http (serialize_to_UTF8_xml (xp[i]), ses1);
--else
-- dbg_printf ('skiping what=[%s] id=[%d]', cwhat, pid);
}
}
if (action = 'insert' or action = 'update')
{
ret := null;
if (what = 'post')
{
ret := sprintf (
'<post id="%d">'||
'<title><![CDATA[%s]]></title>'||
'<dt>%s</dt>'||
'<link>%V</link>'||
'<from><![CDATA[%s]]></from>'||
'<uid><![CDATA[%s]]></uid>'||
'</post>'
, id, title, date_iso8601 (tim), url, uname, u_name);
}
else if (what = 'comment')
{
ret := sprintf (
'<comment id="%d">'||
'<dt>%s</dt>'||
'<from><![CDATA[%s]]></from>'||
'<for><![CDATA[%s]]></for>'||
'<link>%V</link>'||
'<title><![CDATA[%s]]></title>'||
'<email><![CDATA[%s]]></email>'||
'</comment>',
id, date_iso8601 (tim), uname, title, url, trim(regexp_replace (blob_to_string (comment), '<[^>]+>', '', 1, null)), mail
);
}
http (ret, ses);
}
http (string_output_string (ses1), ses);
http ('</blog-db>', ses);
ret := string_output_string (ses);
return ret;
};
create procedure SUGGEST_TB_URLS (in txt any)
{
declare xt, xp, ret any;
xt := xml_tree_doc (xml_tree (txt, 2));
xp := xpath_eval ('//a[@href]/@href', xt, 0);
commit work;
ret := vector ();
foreach (any link in xp) do
{
declare hdr, content, trackback any;
hdr := null;
declare exit handler for sqlstate '*'
{
goto nextl;
};
content := GET_URL_AND_REDIRECTS (cast (link as varchar), hdr);
xt := xml_tree_doc (xml_tree (content, 2));
trackback := GET_BLOG_TB_URLS (xt);
foreach (any tb in trackback) do
{
ret := vector_concat (ret, vector (vector(tb)));
}
nextl:;
}
return ret;
};
create procedure
metaweblog.get_Recent_Posts (in uri varchar, in req "blogRequest", in lim int)
{
declare ret, xe, arr any;
declare i, l int;
declare post any;
ret := DB.DBA.XMLRPC_CALL (uri, 'metaWeblog.getRecentPosts',
vector (req.blogid, req.user_name, req.passwd, lim));
ret := xml_tree_doc (ret);
xe := xpath_eval ('//Param1/item', ret, 0);
arr := vector (); i := 0; l := length (xe);
while (i < l)
{
ret := xml_cut (xe[i]);
post := soap_box_xml_entity_validating (ret, '', 0, 'BLOG.DBA.MTWeblogPost');
arr := vector_concat (arr, vector(post));
i := i + 1;
}
enf:
return arr;
}
;
create procedure IMPORT_PARSE_FEED (inout xt any)
{
declare title, content, published, postid, tmp, posts any;
declare res "MTWeblogPost";
declare i int;
posts := null;
if (xpath_eval ('/rss', xt) is not null)
{
tmp := xpath_eval ('/rss/channel/item', xt, 0);
posts := make_array (length (tmp), 'any');
i := 0;
foreach (any x in tmp) do
{
title := xpath_eval ('string(title)', x);
content := xpath_eval ('string(description)', x);
published := cast (xpath_eval ('string(pubDate)', x) as varchar);
postid := xpath_eval ('string(postid)', x);
res := new "MTWeblogPost" ();
res.title := title;
if (length (published))
res.dateCreated := http_string_date (published);
res.postid := postid;
res.description := content;
posts[i] := res;
i := i + 1;
}
}
else if (xpath_eval ('/feed', xt) is not null)
{
tmp := xpath_eval ('/feed/entry', xt, 0);
posts := make_array (length (tmp), 'any');
i := 0;
foreach (any x in tmp) do
{
title := xpath_eval ('string(title)', x);
content := xpath_eval ('string(content)', x);
published := cast (xpath_eval ('string(published)', x) as varchar);
postid := xpath_eval ('string(id)', x);
res := new "MTWeblogPost" ();
res.title := title;
if (length (published))
res.dateCreated := stringdate (published);
res.postid := postid;
res.description := content;
posts[i] := res;
i := i + 1;
}
}
else if (xpath_eval ('/RDF', xt) is not null)
{
tmp := xpath_eval ('/RDF/item', xt, 0);
posts := make_array (length (tmp), 'any');
i := 0;
foreach (any x in tmp) do
{
title := xpath_eval ('string(title)', x);
content := xpath_eval ('string(description)', x);
published := cast (xpath_eval ('string(date)', x) as varchar);
postid := xpath_eval ('string(@about)', x);
res := new "MTWeblogPost" ();
res.title := title;
if (length (published))
res.dateCreated := stringdate (published);
res.postid := postid;
res.description := content;
posts[i] := res;
i := i + 1;
}
}
return posts;
}
;
create procedure IMPORT_INSERT_POSTS (inout posts any, in blogid any, in user_id any)
{
foreach (any x in posts) do
{
declare title, content, pub, id any;
declare meta "MTWeblogPost";
id := cast (sequence_next ('blogger.postid') as varchar);
if (udt_instance_of ('BLOG.DBA.MTWeblogPost', x))
{
declare p "MTWeblogPost";
p := x;
title := blog_wide2utf (p.title);
content := blog_wide2utf (p.description);
pub := p.dateCreated;
meta := x;
meta.title := title;
meta.description := null;
}
else
{
declare p "blogPost";
p := x;
title := null;
content := blog_wide2utf (p.content);
pub := p.dateCreated;
meta := null;
}
insert into BLOG.DBA.SYS_BLOGS (B_APPKEY, B_POST_ID, B_BLOG_ID, B_TS, B_CONTENT, B_USER_ID, B_META, B_STATE, B_TITLE)
values ('Import', id, blogid, pub, content, user_id, meta, 2, title);
}
}
;
create procedure
IMPORT_BLOG (in blogid varchar, in user_id int, in url varchar, in api varchar, in bid varchar, in uid varchar, in pwd varchar, in hub varchar := null)
{
declare tmp, xt, cnt, hdr, rc any;
declare posts any;
url := cast (url as varchar);
api := cast (api as varchar);
bid := cast (bid as varchar);
uid := cast (uid as varchar);
pwd := cast (pwd as varchar);
rc := 0;
if (length (bid) = 0) -- import from a feed
{
cnt := BLOG..GET_URL_AND_REDIRECTS (url, hdr);
xt := xtree_doc (cnt);
posts := IMPORT_PARSE_FEED (xt);
}
else -- import using an api
{
if (api = 'MetaWeblog' or api = 'MoveableType')
{
posts := metaweblog.get_Recent_Posts (url, BLOG.DBA."blogRequest" ('appKey', bid, '', uid, pwd), 100);
}
else -- use blogger
{
posts := blogger.get_Recent_Posts (url, BLOG.DBA."blogRequest" ('appKey', bid, '', uid, pwd), 100);
}
}
IMPORT_INSERT_POSTS (posts, blogid, user_id);
if (length (hub))
{
declare token, subsu, callback, head, ret varchar;
declare inst int;
inst := (select WAI_ID from BLOG.DBA.SYS_BLOG_INFO, DB.DBA.WA_INSTANCE where BI_WAI_NAME = WAI_NAME and BI_BLOG_ID = blogid);
PSH.DBA.ods_cli_subscribe (inst, hub, 'subscribe', url);
}
return length (posts);
};
create procedure PSH.DBA.ods_weblog_psh_cbk (in url varchar, in content any, in inst any)
{
declare xt, posts, blogid, user_id any;
for select BI_BLOG_ID, BI_OWNER from BLOG.DBA.SYS_BLOG_INFO, DB.DBA.WA_INSTANCE where BI_WAI_NAME = WAI_NAME and WAI_ID = inst do
{
blogid := BI_BLOG_ID;
user_id := BI_OWNER;
}
xt := xtree_doc (content);
posts := IMPORT_PARSE_FEED (xt);
IMPORT_INSERT_POSTS (posts, blogid, user_id);
}
;
-- /* re-tagging */
create procedure blog_tag2str (inout tags any)
{
declare s any;
declare i int;
s := string_output ();
for (i := 0; i < length (tags); i := i + 2)
{
http (sprintf ('%s,', tags[i]), s);
}
return rtrim(string_output_string (s), ', ');
}
;
create procedure RE_TAG_POST (in blogid varchar, in post_id varchar, in user_id int, in inst_id int,
inout content any, in keep_existing int, inout xt any, in job int := null, in rules any := null, in auto_tag int := 1)
{
declare moat_tags, tags, tagstr, comp_tags, existing_tags any;
declare flag varchar;
if (rules is null)
rules := DB.DBA.user_tag_rules (user_id);
if (auto_tag)
{
tags := DB.DBA.tag_document_with_moat (content, 0, rules);
}
else
tags := vector ();
moat_tags := tags;
tagstr := blog_tag2str (tags);
if (keep_existing)
{
--dbg_obj_print ('>>>add tags');
existing_tags := coalesce (
(select BT_TAGS from BLOG..BLOG_TAG where BT_BLOG_ID = blogid and BT_POST_ID = post_id), '');
existing_tags := split_and_decode (existing_tags, 0, '\0\0,');
if (existing_tags is null)
existing_tags := vector ();
comp_tags := vector ();
foreach (any t in existing_tags) do
{
t := trim(lower (cast (t as varchar)));
if (length(t) and not position (t, comp_tags))
comp_tags := vector_concat (comp_tags, vector (t));
}
foreach (any t in comp_tags) do
{
t := trim(lower (cast (t as varchar)));
if (length (t) and not position (t, tags))
tagstr := tagstr || ', ' || t;
}
tags := vector_concat (tags, comp_tags);
}
--dbg_obj_print ('existing_tags', existing_tags);
--dbg_obj_print ('tags', tags);
{
declare xp any;
if (xt is null)
xt := xtree_doc (content, 2, '', 'UTF-8');
xp := xpath_eval ('//a[@rel="tag"]/text()', xt, 0);
--dbg_obj_print ('embedded', xp);
foreach (any t in xp) do
{
t := trim(lower (cast (t as varchar)));
if (length (t) and not position (t, tags))
tagstr := tagstr || ', ' || t;
}
}
tagstr := trim (tagstr, ', ');
--dbg_obj_print ('tagstr',tagstr);
flag := null;
if (length (tagstr))
{
delete from BLOG..BLOG_TAG where BT_BLOG_ID = blogid and BT_POST_ID = post_id;
delete from moat.DBA.moat_meanings where m_inst = inst_id and m_id = post_id;
for (declare i, l int, i := 0, l := length (moat_tags); i < l; i := i + 2)
{
declare tag, arr any;
tag := moat_tags[i];
arr := moat_tags[i+1];
foreach (any turi in arr) do
{
insert replacing moat.DBA.moat_meanings (m_inst, m_id, m_tag, m_uri, m_iri)
values (inst_id, post_id, tag, turi,
iri_to_id (sioc..blog_post_iri (blogid, post_id)));
}
}
insert replacing BLOG..BLOG_TAG (BT_BLOG_ID, BT_POST_ID, BT_TAGS) values (blogid, post_id, tagstr);
if (job is not null)
{
if (exists (select 1 from BLOG..SYS_BLOGS_ROUTING_LOG where RL_JOB_ID = job and RL_POST_ID = post_id))
flag := 'U';
else
flag := 'I';
}
}
else
{
if (job is not null and exists (select 1 from BLOG..SYS_BLOGS_ROUTING_LOG where RL_JOB_ID = job and RL_POST_ID = post_id))
flag := 'D';
delete from BLOG..BLOG_TAG where BT_BLOG_ID = blogid and BT_POST_ID = post_id;
}
return flag;
}
;
CREATE FUNCTION BLOG..GET_DAYS_IN_MONTH (in pDate DATETIME) RETURNS INT
{
RETURN CASE WHEN MONTH(pDate) IN (1, 3, 5, 7, 8, 10, 12) THEN 31
WHEN MONTH(pDate) IN (4, 6, 9, 11) THEN 30
ELSE CASE WHEN (mod (YEAR(pDate), 4) = 0 AND
mod (YEAR(pDate), 100) <> 0) OR
(mod (YEAR(pDate), 400) = 0)
THEN 29
ELSE 28
END
END;
}
;
create procedure BLOG..BLOG_RESOLVE_REFS (in txt any)
{
declare a any;
a := regexp_replace (txt, '((http://|https://|mailto:|ftp:)[^ ]+)', '<a href="\\1">\\1</a>', 1, null);
a := regexp_replace (a, '(@)([[:alnum:]]+)(:)', '\\1<a href="/dataspace/person/\\2">\\2</a>\\3', 1, null);
a := regexp_replace (a, '([[:alnum:]]+)(@)([[:alnum:]]+\\.[[:alnum:]]+)', '<a href="mailto:\\1@\\3">\\1@\\3</a>', 1, null);
return '<div>' || a || '</div>';
}
;
|