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:
<?php
if (!class_exists('Inbound_Mailer_Metaboxes')) {
class Inbound_Mailer_Metaboxes {
static $statistics;
static $sends;
static $variation_stats;
static $campaign_stats;
static $settings;
static $email_type;
static $range;
static $job_id;
function __construct() {
self::load_hooks();
}
public static function load_hooks() {
add_action('add_meta_boxes', array(__CLASS__, 'load_metaboxes'));
add_action('admin_notices', array(__CLASS__, 'add_template_select'));
add_action('admin_notices', array(__CLASS__, 'load_user_preferences'));
add_action('edit_form_after_title', array(__CLASS__, 'add_containers'), 5);
add_action('edit_form_after_title', array(__CLASS__, 'add_hidden_inputs'));
add_filter('enter_title_here', array(__CLASS__, 'change_title_placeholder_text'), 10, 2);
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_admin_scripts'));
add_action('admin_print_footer_scripts', array(__CLASS__, 'print_js_listeners'));
add_action('save_post', array(__CLASS__, 'action_save_data'));
add_filter('wp_insert_post_data', array(__CLASS__, 'check_post_stats'));
add_action( 'admin_notices' , array( __CLASS__ , 'generate_json' ) );
}
public static function load_user_preferences() {
global $post;
$screen = get_current_screen();
if (!isset($screen) || $screen->id != 'inbound-email' || ($screen->base != 'post' && $screen->base != 'post-new')) {
return;
}
self::$range = get_user_option(
'inbound_mailer_screen_option_range',
get_current_user_id()
);
self::$range = (self::$range) ? self::$range : 90;
self::$job_id = get_user_option(
'inbound_mailer_reporting_job_id_' .$post->ID,
get_current_user_id()
);
self::$job_id = (self::$job_id) ? self::$job_id : 0;
}
public static function load_metaboxes() {
global $post, $Inbound_Mailer_Variations;
if ($post->post_type != 'inbound-email') {
return;
}
$template_id = $Inbound_Mailer_Variations->get_current_template($post->ID);
if (isset($_GET['new-variation'])) {
$variations = $Inbound_Mailer_Variations->get_variations($post->ID, $vid = null);
$vid = key($variations);
$template_id = $Inbound_Mailer_Variations->get_current_template($post->ID, $vid);
}
add_meta_box('email-send-actions', __('Actions', 'inbound-pro'), array(__CLASS__, 'add_email_actions'), 'inbound-email', (isset($_GET['email-customizer']) ? 'normal' : 'side'), (isset($_GET['email-customizer']) ? 'low' : 'high'));
add_meta_box('email-send-type', __('Send Type', 'inbound-pro'), array(__CLASS__, 'add_email_type_select_toggle'), 'inbound-email', 'side', 'high');
add_meta_box('email-selected-template', __('Selected Template', 'inbound-pro'), array(__CLASS__, 'add_selected_tamplate_info'), 'inbound-email', 'side', 'high');
}
public static function load_statistics() {
global $post, $inbound_settings;
switch ($inbound_settings['mailer']['mail-service']) {
case 'sparkpost' :
self::$statistics = Inbound_SparkPost_Stats::get_sparkpost_webhook_stats();
break;
}
self::$campaign_stats = self::$statistics['totals'];
self::$variation_stats = (isset(self::$statistics['totals']['variations'])) ? self::$statistics['totals']['variations'] : array();
}
public static function load_send_stream() {
global $post, $inbound_settings;
switch ($inbound_settings['mailer']['mail-service']) {
case 'sparkpost' :
self::$sends = Inbound_SparkPost_Stats::get_send_stream();
break;
}
}
public static function load_graphs_JS() {
global $post;
$stats_json = str_replace("'","\'" , json_encode((object)self::$statistics));
?>
<script type='text/javascript'>
var Email_Graphs = (function () {
var stats;
var barchart;
var App = {
init: function (json) {
this.stats = JSON.parse(json);
console.log(this.stats);
console.log(this.stats.totals.variations);
Email_Graphs.load_bar_graph();
Email_Graphs.load_totals();
Email_Graphs.load_circle_graphs();
},
load_bar_graph: function () {
var chart = [
{
"key": "Opened",
"color": "#2475a6",
"values": []
}, {
"key": "Unopened",
"color": "#243BA6",
"values": []
}, {
"key": "Clicked",
"color": "#9f24a6",
"values": []
}
];
for (id in this.stats.totals.variations) {
chart[0]['values'].push({
"label": this.stats.totals.variations[id].label,
"value": this.stats.totals.variations[id].opens
});
chart[1]['values'].push({
"label": this.stats.totals.variations[id].label,
"value": this.stats.totals.variations[id].unopened
});
chart[2]['values'].push({
"label": this.stats.totals.variations[id].label,
"value": this.stats.totals.variations[id].clicks
});
}
jQuery('.barchart').show();
jQuery('.circle-stats').css('margin-top', '25px');
Email_Graphs.animate_bar_graph(chart);
},
animate_bar_graph: function (data) {
var width = jQuery('.statistics-reporting-container').parent().width();
nv.addGraph(function () {
var chart = nv.models.multiBarHorizontalChart()
.x(function (d) {
return d.label
})
.y(function (d) {
return d.value
})
.margin({top: 30, right: 20, bottom: 40, left: 40})
.showValues(true)
.tooltips(true)
.transitionDuration(350)
.stacked(true)
.showControls(false);
chart.yAxis
.tickFormat(d3.format(',1'));
d3.select('.statistics-reporting-container svg')
.datum(data)
.call(chart);
nv.utils.windowResize(chart.update);
chart.update
return chart;
}, function (chart) {
chart.update();
});
},
load_circle_graphs: function () {
Email_Graphs.setup_circle_graphs();
},
load_totals: function () {
if (this.stats.totals.sent > 0) {
jQuery('.sent-percentage').text('100%');
} else {
jQuery('.sent-percentage').text('0%');
}
jQuery('.opens-percentage').text(this.get_percentage(this.stats.totals.opens, this.stats.totals.sent) + '%');
jQuery('.clicks-percentage').text(this.get_percentage(this.stats.totals.clicks, this.stats.totals.sent) + '%')
jQuery('.unopened-percentage').text(this.get_percentage(this.stats.totals.unopened, this.stats.totals.sent) + '%')
jQuery('.bounces-percentage').text(this.get_percentage(this.stats.totals.bounces, this.stats.totals.sent) + '%')
jQuery('.rejects-percentage').text(this.get_percentage(this.stats.totals.rejects, this.stats.totals.sent) + '%')
jQuery('.unsubs-percentage').text(this.get_percentage(this.stats.totals.unsubs, this.stats.totals.sent) + '%')
jQuery('.mutes-percentage').text(this.get_percentage(this.stats.totals.mutes, this.stats.totals.sent) + '%')
jQuery('.sent-number').text(this.stats.totals.sent);
jQuery('.opens-number').text(this.stats.totals.opens);
jQuery('.clicks-number').text(this.stats.totals.clicks);
jQuery('.unopened-number').text(this.stats.totals.unopened);
jQuery('.bounces-number').text(this.stats.totals.bounces);
jQuery('.rejects-number').text(this.stats.totals.rejects);
jQuery('.unsubs-number').text(this.stats.totals.unsubs);
jQuery('.mutes-number').text(this.stats.totals.mutes);
},
get_percentage: function (count, total) {
if (total < 1) {
return '0';
} else {
return Math.round(( parseInt(count) / parseInt(total) ) * 100);
}
},
setup_circle_graphs: function () {
jQuery('.stat-group').each(function () {
that = jQuery(this);
var svgObj = that.find('.svg');
var perObj = that.find('.per');
var wide = that.width();
var center = wide / 2;
var radius = wide * 0.8 / 2;
var start = center - radius;
var per = perObj.text().replace("%", "") / 100;
var svg = Snap(svgObj.get(0));
var arc = svg.path("");
var circle = svg.circle(wide / 2, wide / 2, radius);
circle.attr({
stroke: '#dbdbdb',
fill: 'none',
strokeWidth: 3
});
perObj.text('');
var stat = {
center: center,
radius: radius,
start: start,
svgObj: svgObj,
per: per,
svg: svg,
arc: arc,
circle: circle
};
Email_Graphs.run_circle_charts(stat);
});
},
run_circle_charts: function (stat) {
var endpoint = stat.per * 360;
Snap.animate(0, endpoint, function (val) {
stat.arc.remove();
var curPer = Math.round(val / 360 * 100);
if (curPer == 100) {
stat.circle.attr({
stroke: "#199dab"
});
} else {
var d = val;
var dr = d - 90;
var radians = Math.PI * (dr) / 180;
var endx = stat.center + stat.radius * Math.cos(radians);
var endy = stat.center + stat.radius * Math.sin(radians);
var largeArc = d > 180 ? 1 : 0;
var path = "M" + stat.center + "," + stat.start + " A" + stat.radius + "," + stat.radius + " 0 " + largeArc + ",1 " + endx + "," + endy;
stat.arc = stat.svg.path(path);
stat.arc.attr({
stroke: '#199dab',
fill: 'none',
strokeWidth: 3
});
}
stat.svgObj.prev().html(curPer + '%');
}, 1500, mina.easeinout);
}
};
return App;
})();
var json = '<?php echo $stats_json; ?>';
Email_Graphs.init(json);
</script>
<?php
}
public static function add_template_select() {
global $inbound_email_data, $post, $current_url, $Inbound_Mailer_Variations;
$Templates = Inbound_Mailer_Load_Templates();
if (isset($post) && $post->post_type != 'inbound-email' || !isset($post)) {
return false;
}
$block = array( 'automated');
if (in_array($post->post_status, $block)) {
return;
}
(!strstr($current_url, 'post-new.php')) ? $toggle = "display:none" : $toggle = "";
$extension_data = $Templates->definitions;
unset($extension_data['mailer-controller']);
if (isset($_GET['new-variation'])) {
$variations = $Inbound_Mailer_Variations->get_variations($post->ID, $vid = null);
$vid = key($variations);
$template = $Inbound_Mailer_Variations->get_current_template($post->ID, $vid);
} else {
$template = $Inbound_Mailer_Variations->get_current_template($post->ID);
}
echo "<div class='mailer-template-selector-container' style='{$toggle}'>";
echo "<div class='mailer-selection-heading'>";
echo "<h1>" . __('Select Your Email Template!', 'inbound-pro') . "</h1>";
echo '<a class="button-secondary" style="display:none;" id="mailer-cancel-selection">Cancel Template Change</a>';
echo "</div>";
echo '<ul id="template-filter" >';
echo '<li><a href="#" data-filter=".template-item-boxes">All</a></li>';
$categories = array();
foreach ($Templates->template_categories as $cat) {
$category_slug = str_replace(' ', '-', $cat['value']);
$category_slug = strtolower($category_slug);
$cat['value'] = ucwords($cat['value']);
if (!in_array($cat['value'], $categories)) {
echo '<li><a href="#" data-filter=".' . $category_slug . '">' . $cat['value'] . '</a></li>';
$categories[] = $cat['value'];
}
}
echo "</ul>";
echo '<div id="templates-container" >';
foreach ($extension_data as $this_template => $data) {
if (!isset($data['info'])) {
continue;
}
if (isset($data['info']['data_type']) && $data['info']['data_type'] != 'email-template') {
continue;
}
$cats = explode(',', $data['info']['category']);
foreach ($cats as $key => $cat) {
$cat = trim($cat);
$cat = str_replace(' ', '-', $cat);
$cats[$key] = trim(strtolower($cat));
}
$cat_slug = implode(' ', $cats);
$thumbnail = self::get_template_thumbnail($this_template);
?>
<div id='template-item' class="<?php echo $cat_slug; ?> template-item-boxes">
<div id="template-box">
<div class="inbound-tooltip" title="<?php echo $data['info']['description']; ?>"></div>
<a class='template_select' href='#' label='<?php echo $data['info']['label']; ?>'
id='<?php echo $this_template; ?>'>
<img src="<?php echo $thumbnail; ?>" class='template-thumbnail'
alt="<?php echo $data['info']['label']; ?>"
id='inbound_email_<?php echo $this_template; ?>'>
</a>
<div id="template-title" style="text-align: center;
font-size: 14px; padding-top: 10px;"><?php echo $data['info']['label']; ?></div>
<!-- |<a href='#' label='<?php echo $data['info']['label']; ?>' id='<?php echo $this_template; ?>' class='template_select'>Select</a>
<a class='thickbox <?php echo $cat_slug;?>' href='<?php echo $data['info']['demo'];?>' id='inbound_email_preview_this_template'>Preview</a> -->
</div>
</div>
<?php
}
echo '</div>';
echo "<div class='clear'></div>";
echo "</div>";
}
public static function add_containers() {
global $post, $inbound_settings;
if (!$post || $post->post_type != 'inbound-email') {
return;
}
echo '<div class="mail-container" role="toolbar">';
self::add_countdown();
self::add_notifications();
self::add_statistics();
switch ($inbound_settings['mailer']['mail-service']) {
case 'sparkpost' :
if ( isset($_GET['debug']) && $_GET['debug'] ) {
self::list_transmissions();
break;
}
}
self::add_email_send_settings();
echo '<div class="quick-launch-container bs-callout bs-callout-clear">';
self::add_variation_buttons();
echo '</div>';
self::add_email_settings();
self::add_preview();
echo '</div>';
}
public static function add_email_settings() {
global $post, $Inbound_Mailer_Variations;
$Inbound_Mailer_Common_Settings = Inbound_Mailer_Common_Settings();
$email_settings = $Inbound_Mailer_Common_Settings->settings['email-settings'];
$next_available_variation_id = $Inbound_Mailer_Variations->get_next_available_variation_id($post->ID);
$current_variation_id = $Inbound_Mailer_Variations->get_current_variation_id();
if (isset($_GET['new-variation']) || isset($_GET['clone'])) {
$current_variation_id = $next_available_variation_id;
}
$letter = $Inbound_Mailer_Variations->vid_to_letter($post->ID, $current_variation_id);
?>
<div class="mail-headers-container bs-callout bs-callout-clear">
<?php
if (isset($_GET['inbvid'])) {
?>
<span id="delete-variation-button-container">
<button type="button" class="btn btn-danger btn-medium" id="action-trash-variation" title="<?php _e('Trash this variation','inbound-pro'); ?>." >
<i class="fa fa-trash-o"></i>
</button>
</span>
<?php
}
?>
<h4><?php _e(sprintf('Variation %s Headers', $letter), 'inbound-pro'); ?></h4>
<?php
self::render_settings('inbound-email', $email_settings, $post);
?>
</div>
<?php
}
public static function add_countdown() {
?>
<div class="countdown-container bs-callout bs-callout-clear">
<div class='scheduled-information-actions'>
</div>
<div class='scheduled-information-countdown'>
</div>
</div>
<?php
}
public static function add_notifications() {
global $post, $inbound_settings;
$pass = array( 'sending');
if (!in_array($post->post_status, $pass)) {
return;
}
echo '<div class="notifications-container bs-callout bs-callout-clear">';
echo '<h4>' . __('Please Wait', 'inbound-pro') . '</h4>';
echo '<p>'. sprintf(__('We are sending your email data to %s now. Depending on how many emails you are generating this might take a moment. If your emails are scheduled to be sent immediately then you can view your current send statistics below by refreshing the page.' , 'inbound-ro' ) , $inbound_settings['mailer']['mail-service'] ) ;
echo '</div>';
}
public static function add_statistics() {
global $post;
$pass = array('scheduled', 'sent', 'sending', 'automated');
if (!in_array($post->post_status, $pass)) {
return;
}
echo '<div class="statistics-reporting-container bs-callout bs-callout-clear">';
echo '<h4>' . __('Reporting', 'inbound-pro') . '</h4>';
self::load_statistics();
self::add_chart_bars();
self::add_numbers_totals();
self::add_email_details();
self::load_graphs_JS();
echo '</div>';
}
public static function list_transmissions() {
self::load_send_stream();
}
public static function add_send_stream() {
global $post,$Inbound_Mailer_Variations;
$pass = array('scheduled', 'sent', 'sending', 'automated');
if (!in_array($post->post_status, $pass)) {
return;
}
echo '<div class="statistics-reporting-container bs-callout bs-callout-clear">';
echo '<center><i>this stream is limited to the last 1000 sends</i></center><br>';
self::load_send_stream();
?>
<table id="stream" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th class='stream-recipient'><span><?php _e('Recipient', 'inbound-pro'); ?></span></th>
<th class='stream-variation'><span><?php _e('Variation', 'inbound-pro'); ?></span></th>
<th class='stream-sent'><span><?php _e('Status', 'inbound-pro'); ?></span></th>
<th class='stream-recipient'><span><?php _e('Opens', 'inbound-pro'); ?></span></th>
<th class='stream-opened'><span><?php _e('Cicked', 'inbound-pro'); ?></span></th>
</tr>
</thead>
<tbody>
<?php
$lead_search = "edit.php?s=EMAIL&post_status=all&post_type=wp-lead";
foreach (self::$sends as $send) {
$search = str_replace('EMAIL',$send['email'],$lead_search);
?>
<tr>
<td class="lalign">
<a href="<?php echo $search; ?>" target="_blank">
<?php echo $send['email']; ?>
</a>
</td>
<td><?php echo $Inbound_Mailer_Variations->vid_to_letter( $post->ID , $send['metadata']['variation_id']); ?></td>
<td><?php echo $send['state']; ?></td>
<td><?php echo $send['opens']; ?></td>
<td><?php echo $send['clicks']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<script type="text/javascript">
jQuery(function () {
jQuery('#stream').tablesorter();
});
</script>
<?php
echo '</div>';
}
public static function add_chart_bars() {
?>
<style>
.dhbc svg {
height: 200px;
width: 100%;
}
.barchart {
width: 100%;
display: none;
}
object {
width: 100%;
display: block;
height: auto;
}
</style>
<div class='barchart stat-row dhbc' style='width:100%;'>
<object>
<svg></svg>
</object>
</div>
<?php
}
public static function add_numbers_totals() {
global $post;
$job_id = (self::$job_id == 'last_send') ? Inbound_Mailer_Post_Type::get_last_job_id($post->ID) : self::$job_id ;
?>
<style>
.stat-number {
font-weight: 600;
}
</style>
<div class='big-number-stats'>
<div class="statistic-container">
<div class="stat-number-container">
<a href="<?php echo admin_url('/index.php?action=inbound_generate_report&class=Inbound_Mailer_Stats_Report&range='.self::$range.'&email_id=' . $post->ID . '&job_id=' . $job_id . '&event_name=sparkpost_delivery&show_graph=false&display_lead_table=true&title=Logs&tb_hide_nav=true&TB_iframe=true&width=1000&height=600'); ?>" class="thickbox inbound-thickbox" style="text-decoration: none;">
<label class="stat-label sent-label"><?php _e('Sent', 'inbound-pro'); ?></label>
<div class="stat-number sent-number">0</div>
<h1 class="stat-percentage sent-percentage">0%</h1>
</a>
</div>
</div>
<div class="statistic-container">
<div class="stat-number-container">
<a href="<?php echo admin_url('/index.php?action=inbound_generate_report&class=Inbound_Mailer_Stats_Report&range='.self::$range.'&email_id=' . $post->ID . '&job_id=' . $job_id . '&event_name=sparkpost_open&show_graph=false&display_lead_table=true&title=Logs&tb_hide_nav=true&TB_iframe=true&width=1000&height=600'); ?>" class="thickbox inbound-thickbox" style="text-decoration: none;">
<label class="stat-label opens-label"><?php _e('Opens', 'inbound-pro'); ?></label>
<div class="stat-number opens-number">0</div>
<h1 class="stat-percentage opens-percentage">0%</h1>
</a>
</div>
</div>
<div class="statistic-container">
<div class="stat-number-container">
<a href="<?php echo admin_url('/index.php?action=inbound_generate_report&class=Inbound_Mailer_Stats_Report&range='.self::$range.'&email_id=' . $post->ID . '&job_id=' . $job_id .'&event_name=sparkpost_click&show_graph=false&display_lead_table=true&title=Logs&tb_hide_nav=true&TB_iframe=true&width=1000&height=600'); ?>" class="thickbox inbound-thickbox" style="text-decoration: none;">
<label class="stat-label clicks-label"><?php _e('Clicks', 'inbound-pro'); ?></label>
<div class="stat-number clicks-number">0</div>
<h1 class="stat-percentage clicks-percentage">0%</h1>
</a>
</div>
</div>
<div class="statistic-container">
<div class="stat-number-container">
<a href="<?php echo admin_url('/index.php?action=inbound_generate_report&class=Inbound_Mailer_Stats_Report&range='.self::$range.'&email_id=' . $post->ID . '&job_id=' . $job_id .'&event_name=unopened&event_name_2=sparkpost_open&event_action=remove_opens&standing_total_graph=true&show_graph=false&display_lead_table=true&title=Logs&tb_hide_nav=true&TB_iframe=true&width=1000&height=600'); ?>" class="thickbox inbound-thickbox" style="text-decoration: none;">
<label class="stat-label unopened-label"><?php _e('Unopened', 'inbound-pro'); ?></label>
<div class="stat-number unopened-number">0</div>
<h1 class="stat-percentage unopened-percentage">0%</h1>
</a>
</div>
</div>
<div class="statistic-container">
<div class="stat-number-container">
<a href="<?php echo admin_url('/index.php?action=inbound_generate_report&class=Inbound_Mailer_Stats_Report&range='.self::$range.'&email_id=' . $post->ID . '&job_id=' . $job_id .'&event_name=sparkpost_bounce&show_graph=false&display_lead_table=true&title=Logs&tb_hide_nav=true&TB_iframe=true&width=1000&height=600'); ?>" class="thickbox inbound-thickbox" style="text-decoration: none;">
<label class="stat-label bounces-label"><?php _e('Bounces', 'inbound-pro'); ?></label>
<div class="stat-number bounces-number">0</div>
<h1 class="stat-percentage bounces-percentage">0%</h1>
</a>
</div>
</div>
<div class="statistic-container">
<div class="stat-number-container">
<a href="<?php echo admin_url('/index.php?action=inbound_generate_report&class=Inbound_Mailer_Stats_Report&range='.self::$range.'&email_id=' . $post->ID . '&job_id=' . $job_id .'&event_name=sparkpost_rejected&event_name_2=sparkpost_relay_rejection&event_action=merge&show_graph=false&display_lead_table=true&title=Logs&tb_hide_nav=true&TB_iframe=true&width=1000&height=600'); ?>" class="thickbox inbound-thickbox" style="text-decoration: none;">
<label class="stat-label rejects-label"><?php _e('Rejects', 'inbound-pro'); ?></label>
<div class="stat-number rejects-number">0</div>
<h1 class="stat-percentage rejects-percentage">0%</h1>
</a>
</div>
</div>
<div class="statistic-container">
<div class="stat-number-container">
<a href="<?php echo admin_url('/index.php?action=inbound_generate_report&class=Inbound_Mailer_Stats_Report&range='.self::$range.'&email_id=' . $post->ID . '&job_id=' . $job_id .'&event_name=inbound_unsubscribe&show_graph=false&display_lead_table=true&title=Logs&tb_hide_nav=true&TB_iframe=true&width=1000&height=600'); ?>" class="thickbox inbound-thickbox" style="text-decoration: none;">
<label class="stat-label unsubs-label"><?php _e('Unsubscribes', 'inbound-pro'); ?></label>
<div class="stat-number unsubs-number">0</div>
<h1 class="stat-percentage unsubs-percentage">0%</h1>
</a>
</div>
</div>
<div class="statistic-container">
<div class="stat-number-container">
<a href="<?php echo admin_url('/index.php?action=inbound_generate_report&class=Inbound_Mailer_Stats_Report&range='.self::$range.'&email_id=' . $post->ID . '&job_id=' . $job_id .'&event_name=inbound_mute&show_graph=false&display_lead_table=true&title=Logs&tb_hide_nav=true&TB_iframe=true&width=1000&height=600'); ?>" class="thickbox inbound-thickbox" style="text-decoration: none;">
<label class="stat-label mutes-label"><?php _e('Mutes', 'inbound-pro'); ?></label>
<div class="stat-number mutes-number">0</div>
<h1 class="stat-percentage mutes-percentage">0%</h1>
</a>
</div>
</div>
</div>
<?php
}
public static function add_email_details() {
global $post;
$settings = Inbound_Email_Meta::get_settings($post->ID);
?>
<style>
.email-send-details {
margin-top: 30px;
font-size:10px;
}
.email-details-td-label {
padding-left: 21px;
box-sizing: border-box;
margin-bottom: 12px;
text-transform: uppercase;
letter-spacing: 0.05em;
font-size: 13px;
line-height: 1.4em;
font-weight: 600;
}
.email-details-td-info {
padding-left: 20px;
}
.email-details-td-info .label-default{
display:flex;
font-size:12px !important;
font-weight:300!important;
background-color: cornflowerblue!important;
padding-left:10px;
padding-right:10px;
padding-top:4px;
padding-bottom:4px;
margin-bottom:3px;
}
</style>
<div class='email-send-details'>
<table>
<tr class='email-details-tr'>
<td class='email-details-td-label'>
<?php _e('Reporting Range', 'inbound-pro'); ?>:
</td>
<td class='email-details-td-info'>
<select name="inbound_mailer_screen_option_range" class="" id="inbound_mailer_screen_option_range" style="width:100px;" >
<?php
$ranges = array(1,7,30,90,365);
foreach ($ranges as $range) {
echo '<option value="'.$range.'" '. ( self::$range==$range ? 'selected="true"' : '' ).'">'.$range.' ' . __('days','inbound-pro') .'</option>';
}
?>
</select>
<i class="fa fa-question-circle inbound-tooltip" data-toggle="tooltip" data-placement="left" title="<?php _e('Select day range for calculating statistics.', 'inbound-pro') ?>"></i>
</td>
</tr>
<?php
if ($settings['email_type'] == 'automated') {
?>
<tr class='email-details-tr'>
<td class='email-details-td-label'>
<?php _e('Reporting by Job' , 'inbound-pro'); ?>:
</td>
<td class='email-details-td-info'>
<?php self::render_job_select(); ?>
<i class="fa fa-question-circle inbound-tooltip" data-toggle="tooltip" data-placement="left" title="<?php _e('Automated email statistics can be segmented by the marketing automation job id that powered their sending. If sent to individual leads then leave this set option set to Combined Report.', 'inbound-pro') ?>"></i>
</td>
</tr>
<?php
}
if ($settings['email_type'] == 'batch') {
?>
<tr class='email-details-tr'>
<td class='email-details-td-label'>
<?php _e('Send Date', 'inbound-pro'); ?>:
</td>
<td class='email-details-td-info'>
<?php
echo $settings['send_datetime'] . ' ' . $settings['timezone'];
?>
</td>
</tr>
<tr class='email-details-tr'>
<td class='email-details-td-label'>
<?php _e('Target Audiences', 'inbound-pro'); ?>:
</td>
<td class='email-details-td-info'>
<?php
foreach ($settings['recipients'] as $list_id) {
$list = Inbound_Leads::get_lead_list_by('id', $list_id);
echo "<a href='" . admin_url('edit.php?page=lead_management&post_type=wp-lead&wplead_list_category%5B%5D=' . $list_id . '&relation=AND&orderby=date&order=asc&s=&t=&submit=Search+Leads') . "' target='_blank' class='label label-default' style='text-decoration:none'>" . $list['name'] . " (" . $list['count'] . ")</a>";
}
?>
</td>
</tr>
<?php
}
?>
<tr class='email-details-tr'>
<td class='email-details-td-label'>
<?php _e('Variations', 'inbound-pro'); ?>:
</td>
<td class='email-details-td-info'>
<?php
foreach ($settings['variations'] as $vid => $variation) {
$letter = Inbound_Mailer_Variations::vid_to_letter($post->ID, $vid);
$permalink = add_query_arg(array('inbvid' => $vid), get_permalink($post->ID));
echo '<a href="' . $permalink . '" class="label label-default thickbox" title="' . __('Variation', 'inbound-pro') . ' ' . $letter . '" style="text-decoration:none">[' . $letter . '] ' . $variation['subject'] . '</a> ';
}
?>
</td>
</tr>
</table>
</div>
<?php
}
public static function add_variation_buttons() {
global $post, $Inbound_Mailer_Variations;
$next_available_variation_id = $Inbound_Mailer_Variations->get_next_available_variation_id($post->ID);
$current_variation_id = $Inbound_Mailer_Variations->get_current_variation_id();
if (isset($_GET['new-variation']) || isset($_GET['clone'])) {
$current_variation_id = $next_available_variation_id;
}
$variations = $Inbound_Mailer_Variations->get_variations($post->ID);
$var_id_marker = 1;
echo '<div class="variations-menu">';
echo ' <div class="btn-group variation-group">';
foreach ($variations as $vid => $variation) {
$permalink = $Inbound_Mailer_Variations->get_variation_permalink($post->ID, $vid);
$letter = $Inbound_Mailer_Variations->vid_to_letter($post->ID, $vid);
if ($current_variation_id == $vid && !isset($_GET['new-variation']) || $current_variation_id == $vid && isset($_GET['clone'])) {
$cur_class = 'btn-primary selected-variation';
} else {
$cur_class = 'btn-default';
}
echo '<a class="btn ' . $cur_class . '" href="?post=' . $post->ID . '&inbvid=' . $vid . '&action=edit" id="tab-' . $vid . '" data-permalink="' . $permalink . '" target="_parent" data-toggle="tooltip" data-placement="left" title="' . __('Variations', 'inbound-pro') . '">' . $letter . '</a>';
}
echo '</div>';
echo ' <div class="btn-group variation-group">';
if (!isset($_GET['new-variation'])) {
echo '<a class="btn btn-default " href="?post=' . $post->ID . '&inbvid=' . $next_available_variation_id . '&action=edit&new-variation=1" id="tabs-add-variation" title="' . __('Add New Variation', 'inbound-pro') . '"> <i data-code="f132" style="vertical-align:bottom;" class="dashicons dashicons-plus"></i></a>';
} else {
$letter = $Inbound_Mailer_Variations->vid_to_letter($post->ID, $next_available_variation_id);
echo '<a class="btn btn-primary selected-variation" href="?post=' . $post->ID . '&inbvid=' . $next_available_variation_id . '&action=edit" id="tabs-add-variation">' . $letter . '</a>';
echo '<a style="display:none;" class="btn btn-default " href="?post=' . $post->ID . '&action=edit&new-variation=1" id="tabs-add-variation-hidden" title="' . __('Add New Variation', 'inbound-pro') . '"> <i data-code="f132" style="vertical-align:bottom;" class="dashicons dashicons-plus"></i></a>';
}
echo '</div>';
echo '</div>';
}
public static function add_preview() {
global $post;
$url = get_permalink($post->ID);
$pass = array('scheduled', 'sent', 'sending', 'automation');
if (!in_array($post->post_status, $pass)) {
return;
}
?>
<script>
function iframeLoaded() {
var iFrameID = document.getElementById('iframe-email-preview');
if (iFrameID) {
iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + "px";
}
}
</script>
<div class="preview-container bs-callout bs-callout-clear">
<h4><?php _e('Preview', 'inbound-pro'); ?></h4>
<iframe src="<?php echo $url; ?>" id='iframe-email-preview' onload="iframeLoaded()"></iframe>
</div>
<?php
}
public static function add_email_send_settings() {
global $post;
echo '<div class="mail-send-settings-container bs-callout bs-callout-clear">';
echo '<h4 title="">' . __('Batch Send Settings', 'inbound-pro') . '</h4>';
self::add_batch_send_settings();
self::add_automation_send_settings();
echo '</div>';
}
public static function add_batch_send_settings() {
global $post;
$Inbound_Mailer_Common_Settings = Inbound_Mailer_Common_Settings();
$settings = $Inbound_Mailer_Common_Settings->settings['batch-send-settings'];
?>
<div class="send-settings batch-send-settings-container">
<?php
self::render_settings('inbound-email', $settings, $post);
?>
</div>
<?php
}
public static function add_automation_send_settings() {
?>
<div class="send-settings automated-send-settings-container">
</div>
<?php
}
public static function add_email_type_select_toggle() {
?>
<select class='form-control' name='inbound_email_type' id='email_type'>
<option value='batch' <?php (self::$email_type == 'batch') ? print 'selected="true"' : print ''; ?>>Batch
Email
</option>
<option value='automated' <?php (self::$email_type == 'automated') ? print 'selected="true"' : print ''; ?>>
Automation
</option>
</select>
<?php
}
public static function add_email_actions() {
global $post;
self::get_email_type();
if ($post->post_status == 'draft' || $post->post_status == 'publish') {
$post->post_status = 'unsent';
}
$status = $post->post_status;
?>
<div class='email-status'>
<div style='float:left;margin-top:11px;'>
<i class='current-status fa fa-info-circle'
title="<?php _e('Current Status', 'inbound-pro'); ?>"></i> <i><span
id='email-status-display'><?php echo $status; ?></span></i>
</div>
<div class='email-actions'>
<button type="button" class="btn btn-warning btn-medium email-action action-trash "
id="action-trash" title="<?php _e('Trash this email.', 'inbound-pro'); ?>"><i
class='fa fa-trash-o'></i></button>
<a href="<?php echo get_permalink($post->ID); ?>" class="btn btn-info email-action action-preview"
id="action-preview" target="_blank" title="<?php _e('Preview', 'inbound-pro'); ?>"><i
class='fa fa-eye'></i></a>
<button type="button" class="btn btn-default btn-medium email-action action-send-test-email"
id="action-send-test-email" title="<?php _e('Send a test email', 'inbound-pro'); ?>"><i
class='fa fa-user'></i></button>
<button type="button" class="btn btn-warning btn-medium email-action action-unschedule"
id="action-unschedule"><?php _e('Unschedule', 'inbound-pro'); ?></button>
<button type="button" class="btn btn-primary btn-medium email-action action-clone" id="action-clone"
title="<?php _e('Clone this email', 'inbound-pro'); ?>"><i class='fa fa-files-o'></i>
</button>
<button type="button" class="btn btn-danger btn-medium email-action action-cancel"
id="action-cancel-sending" title="<?php _e('Abort Send', 'inbound-pro'); ?>"><i
class='fa fa-ban'></i></button>
</div>
<div id="email-actions-continued">
<button type="button" class="btn btn-primary btn-medium email-action action-save ladda-button"
data-style="expand-right" data-spinner-color="#ffffff" id="action-save"
title="<?php _e('Save', 'inbound-pro'); ?>"><i
class='fa fa-save'></i> <?php _e('Save', 'inbound-pro'); ?>
</button>
<button type="button" class="btn btn-success btn-medium email-action action-send" id="action-send"
title="<?php _e('Send Email', 'inbound-pro'); ?>"><i
class='fa fa-send-o'></i> <?php _e('Send', 'inbound-pro'); ?>
</button>
<button type="button" class="btn btn-danger btn-medium email-action action-clear-stats" id="action-clear-stats"
title="<?php _e('Right now resetting stats will clear cached statistic objects and delete local events from lead records related to this email..', 'inbound-pro'); ?>"><i
class='fa fa-trash-o'></i> <?php _e('Reset Stats', 'inbound-pro'); ?>
</button>
</div>
</div>
<?php
}
public static function add_selected_tamplate_info() {
global $Inbound_Mailer_Variations, $post;
$vid = Inbound_Mailer_Variations::get_current_variation_id();
$template = $Inbound_Mailer_Variations->get_current_template($post->ID, $vid);
$thumbnail = self::get_template_thumbnail($template);
$post_link = Inbound_Mailer_Variations::get_variation_permalink($post->ID, $vid = null);
?>
<div class='selected-template-metabox'>
<img src='<?php echo $thumbnail; ?>' title='<?php echo $template; ?>' id='selected-template-image'><br>
<?php
$ignore = array('scheduled', 'sent', 'sending', 'automated');
if (!in_array($post->post_status, $ignore)) {
?>
<a class="button-primary"
id="inbound-mailer-change-template-button"><?php _e('Switch Templates', 'inbound-pro'); ?></a>
<br>
<a rel='<?php echo $post_link; ?>' id='cta-launch-front' class='button-primary '
href='<?php echo $post_link; ?>&email-customizer=on'><?php _e('Launch Visual Editor', 'inbound-pro'); ?></a>
<?php
}
?>
</div>
<?php
}
public static function get_email_type( $post_id = null) {
if (!$post_id) {
global $post;
$post_id = $post->ID;
}
$settings = Inbound_Email_Meta::get_settings($post_id);
if (isset($settings['email_type'])) {
self::$email_type = $settings['email_type'];
} else {
self::$email_type = 'batch';
}
return self::$email_type;
}
public static function get_template_thumbnail($template) {
if (file_exists(INBOUND_EMAIL_PATH . 'templates/' . $template . '/thumbnail.png')) {
$thumbnail = INBOUND_EMAIL_URLPATH . 'templates/' . $template . '/thumbnail.png';
} else if (file_exists(INBOUND_EMAIL_UPLOADS_PATH . $template . '/thumbnail.png')) {
$thumbnail = INBOUND_EMAIL_UPLOADS_URLPATH . $template . '/thumbnail.png';
} else if (file_exists(INBOUND_EMAIL_THEME_TEMPLATES_PATH . $template . '/thumbnail.png')) {
$thumbnail = INBOUND_EMAIL_THEME_TEMPLATES_URLPATH . $template . '/thumbnail.png';
} else {
$thumbnail = INBOUND_EMAIL_URLPATH . 'assets/images/nothumbnail.jpg';
}
return $thumbnail;
}
public static function add_hidden_inputs() {
global $post, $Inbound_Mailer_Variations;
if (!$post || $post->post_type != 'inbound-email') {
return;
}
if (isset($_REQUEST['frontend']) && $_REQUEST['frontend'] == 'true') {
echo '<input type="hidden" name="frontend" id="frontend-on" value="true" />';
}
$vid = Inbound_Mailer_Variations::get_current_variation_id();
$variations_status = $Inbound_Mailer_Variations->get_variation_status($post->ID, $vid);
echo '<input type="hidden" name="variation_status" value = "' . $variations_status . '">';
echo '<input type="hidden" name="inbvid" id="open_variation" value = "' . $vid . '">';
$template_id = $Inbound_Mailer_Variations->get_current_template($post->ID);
echo "<input type='hidden' name='selected_template' id='selected_template' value='" . $template_id . "'>";
echo "<input type='hidden' name='email_action' id='email_action' value='none'>";
}
public static function remove_wp_seo() {
}
public static function render_settings($settings_key, $custom_fields, $post) {
global $Inbound_Mailer_Variations;
$settings = Inbound_Email_Meta::get_settings($post->ID);
$variations = (isset($settings['variations'])) ? $settings['variations'] : null;
$vid = Inbound_Mailer_Variations::get_current_variation_id();
if (isset($_GET['new-variation'])) {
$variations = Inbound_Mailer_Variations::get_variations($post->ID);
end($variations);
$vid = key($variations);
}
echo '<div class="form-table" id="inbound-meta">';
foreach ($custom_fields as $field) {
$field_id = $field['id'];
$label_class = $field['id'] . "-label";
$type_class = " inbound-" . $field['type'];
$type_class_row = " inbound-" . $field['type'] . "-row";
$type_class_option = " inbound-" . $field['type'] . "-option";
$option_class = (isset($field['class'])) ? $field['class'] : '';
if (isset($variations[$vid][$field_id])) {
$meta = $variations[$vid][$field_id];
} else {
$meta = $field['default'];
}
if (isset($field['disable_variants']) && $field['disable_variants']) {
$field_id = 'inbound_' . $field['id'];
$meta = (isset($settings[$field['id']])) ? $settings[$field['id']] : $field['default'];
}
echo '<div class="' . $field['id'] . $type_class_row . ' div-' . $option_class . ' inbound-email-option-row inbound-meta-box-row">';
if ($field['type'] != "description-block" && $field['type'] != "custom-css") {
echo '<div id="inbound-' . $field_id . '" data-actual="' . $field_id . '" class="inbound-meta-box-label inbound-email-table-header ' . $label_class . $type_class . '"><label for="' . $field_id . '">' . $field['label'] . '</label></div>';
}
echo '<div class="inbound-email-option-td inbound-meta-box-option ' . $type_class_option . '" data-field-type="' . $field['type'] . '">';
switch ($field['type']) {
case 'description-block':
echo '<div id="' . $field_id . '" class="description-block">' . $field['description'] . '</div>';
break;
case 'datepicker':
$timezones = Inbound_Mailer_Scheduling::get_timezones();
$tz = (isset($settings['timezone'])) ? $settings['timezone'] : $field['default_timezone_abbr'];
echo '<div class="jquery-date-picker inbound-datepicker" id="date-picking" data-field-type="text">
<span class="datepair" data-language="javascript">
<input type="text" id="date-picker-' . $settings_key . '" class="date start" placeholder="' . __('Select Date', 'inbound-pro') . '"/></span>
<input id="time-picker-' . $settings_key . '" type="text" class="time time-picker " placeholder =" ' . __('Select Time', 'inbound-pro') . '" />
<input type="hidden" name="' . $field_id . '" id="' . $field_id . '" value="' . $meta . '" class="new-date" value="" >
';
echo '</div>';
echo '<select name="inbound_timezone" id="" class="" >';
foreach ($timezones as $key => $timezone) {
$tz_value = $timezone['abbr'] . '-' . $timezone['utc'];
$selected = ($tz == $tz_value) ? 'selected="true"' : '';
echo '<option value="' . $tz_value . '" ' . $selected . '> (' . $timezone['utc'] . ') ' . $timezone['name'] . '</option>';
}
echo '</select>';
break;
case 'text':
echo '<input type="text" class="' . $option_class . ' form-control" name="' . $field_id . '" id="' . $field_id . '" value="' . str_replace('"', '"',$meta ). '" size="30" />
<div class="inbound-tooltip" title="' . $field['description'] . '"></div>';
break;
case 'number':
echo '<input type="number" class="' . $option_class . '" name="' . $field_id . '" id="' . $field_id . '" value="' . $meta . '" size="30" />
<i class="fa fa-question-circle inbound-tooltip"title="' . $field['description'] . '"></i>';
break;
case 'textarea':
echo '<textarea name="' . $field_id . '" id="' . $field_id . '" cols="106" rows="6" style="width: 75%;">' . $meta . '</textarea>
<i class="fa fa-question-circle tooltip"title="' . $field['description'] . '"></i>';
break;
case 'wysiwyg':
echo "<div class='iframe-options iframe-options-" . $field_id . "' id='" . $field['id'] . "'>";
wp_editor($meta, $field_id, $settings = array('editor_class' => $field['id']));
echo '<p class="description">' . $field['description'] . '</p></div>';
break;
case 'media':
echo '<label for="upload_image" data-field-type="text">';
echo '<input name="' . $field_id . '" id="' . $field_id . '" type="text" size="36" name="upload_image" value="' . $meta . '" />';
echo '<input class="upload_image_button" id="uploader_' . $field_id . '" type="button" value="Upload Image" />';
echo '<p class="description">' . $field['description'] . '</p>';
break;
case 'checkbox':
$i = 1;
echo "<table class='inbound_email_check_box_table'>";
if (!isset($meta)) {
$meta = array();
} elseif (!is_array($meta)) {
$meta = array($meta);
}
foreach ($field['options'] as $value => $label) {
if ($i == 5 || $i == 1) {
echo "<tr>";
$i = 1;
}
echo '<td data-field-type="checkbox"><input type="checkbox" name="' . $field_id . '[]" id="' . $field_id . '" value="' . $value . '" ', in_array($value, $meta) ? ' checked="checked"' : '', '/>';
echo '<label for="' . $value . '"> ' . $label . '</label></td>';
if ($i == 4) {
echo "</tr>";
}
$i++;
}
echo "</table>";
echo '<div class="inbound-tooltip tool_checkbox" title="' . $field['description'] . '"></div>';
break;
case 'radio':
foreach ($field['options'] as $value => $label) {
echo '<input type="radio" name="' . $field_id . '" id="' . $field_id . '" value="' . $value . '" ', $meta == $value ? ' checked="checked"' : '', '/>';
echo '<label for="' . $value . '"> ' . $label . '</label> ';
}
echo '<i class="fa fa-question-circle inbound-tooltip"title="' . $field['description'] . '"></i>';
break;
case 'dropdown':
echo '<select name="' . $field_id . '" id="' . $field_id . '" class="' . $field['id'] . ' form-control">';
foreach ($field['options'] as $value => $label) {
echo '<option', $meta == $value ? ' selected="selected"' : '', ' value="' . $value . '">' . $label . '</option>';
}
echo '</select><i class="fa fa-question-circle inbound-tooltip"title="' . $field['description'] . '"></i>';
break;
case 'select2':
echo '<select name="' . $field_id . '[]" id="' . $field_id . '" class="' . $field['id'] . ' select2 select-lists" multiple>';
foreach ($field['options'] as $value => $label) {
$selected = (is_array($meta) && in_array($value, $meta)) ? 'selected="true"' : '';
echo '<option value="' . $value . '" ' . $selected . ' >' . $label . '</option>';
}
echo '</select><i class="fa fa-question-circle inbound-tooltip"title="' . $field['description'] . '"></i>';
echo '<script type="text/javascript"> jQuery("#'.$field_id.'").select2({width: "300px"});</script>';
break;
}
echo '</div></div>';
}
echo '</div>';
}
public static function render_job_select() {
global $wpdb, $post;
$table_name = $wpdb->prefix . "inbound_events";
$query = 'SELECT DISTINCT( job_id ) FROM '.$table_name . " WHERE email_id = '".$post->ID."' ORDER BY job_id DESC LIMIT 100";
$job_ids = $wpdb->get_results( $query , ARRAY_A );
echo '<select name="automation_job_id" id="automation_job_id" class="select2">';
echo '<option value="0" '.selected( 0 , self::$job_id , false ).'>'.__('Combined Report','inbound-pro').'</option>';
foreach( $job_ids as $key => $job) {
if (!$job['job_id']) {
continue;
}
if ($key === 0 ) {
echo '<option value="last_send" '.selected('last_send' , self::$job_id , false ).'>'.__('Last Send','inbound-pro').'</option>';
} else {
echo '<option value="'.$job['job_id'].'" '.selected( $job['job_id'] , self::$job_id , false).'>'.__('Send # ','inbound-pro').' '.$job['job_id'].'</option>';
}
}
echo '</select>';
echo '<script type="text/javascript"> jQuery("#automation_job_id").select2({width: "300px"});</script>';
}
public static function change_title_placeholder_text($text, $post) {
if ($post->post_type != 'inbound-email') {
return $text;
}
return __('Enter Email Description', 'inbound-pro');
}
public static function enqueue_admin_scripts() {
$screen = get_current_screen();
if (!isset($screen) || $screen->id != 'inbound-email' || ($screen->base != 'post' && $screen->base != 'post-new')) {
return;
}
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_register_script('bootstrap', INBOUNDNOW_SHARED_URLPATH . 'assets/includes/BootStrap/js/bootstrap.min.js');
wp_enqueue_script('bootstrap');
wp_register_style('bootstrap', INBOUNDNOW_SHARED_URLPATH . 'assets/includes/BootStrap/css/bootstrap.css');
wp_enqueue_style('bootstrap');
wp_register_script('d3', INBOUND_EMAIL_URLPATH . 'assets/libraries/d3/d3.v3.min.js');
wp_enqueue_script('d3');
wp_register_script('nvd3', INBOUND_EMAIL_URLPATH . 'assets/libraries/d3/nv.d3.js');
wp_enqueue_script('nvd3');
wp_register_style('d3-css', INBOUND_EMAIL_URLPATH . 'assets/libraries/d3/style.css');
wp_enqueue_style('d3-css');
wp_register_script('snap', INBOUND_EMAIL_URLPATH . 'assets/libraries/snap/snap.svg.js');
wp_enqueue_script('snap');
wp_register_style('fontawesome', INBOUNDNOW_SHARED_URLPATH . 'assets/fonts/fontawesome/css/font-awesome.min.css');
wp_enqueue_style('fontawesome');
wp_register_script('ladda-spin', INBOUND_EMAIL_URLPATH . 'assets/libraries/ladda/spin.min.js');
wp_enqueue_script('ladda-spin');
wp_register_script('ladda', INBOUND_EMAIL_URLPATH . 'assets/libraries/ladda/ladda.min.js');
wp_enqueue_script('ladda');
wp_register_style('ladda', INBOUND_EMAIL_URLPATH . 'assets/libraries/ladda/ladda-themeless.min.css');
wp_enqueue_style('ladda');
wp_enqueue_style('jquery-tablesorter', INBOUND_EMAIL_URLPATH . 'assets/libraries/jquery-tablesorter/styles.css');
wp_enqueue_script('jquery-tablesorter', INBOUND_EMAIL_URLPATH . 'assets/libraries/jquery-tablesorter/jquery.tablesorter.min.js');
}
public static function print_js_listeners() {
$screen = get_current_screen();
if (!isset($screen) || $screen->id != 'inbound-email' || $screen->parent_base != 'edit') {
return;
}
global $post;
$post->ID = (isset($_GET['post'])) ? (int) $_GET['post'] : $post->ID;
self::print_settings_class_JS();
?>
<script>
jQuery(document).ready(function () {
Settings.init();
jQuery('body').on('click', '.action-unschedule', function (e) {
Settings.unschedule_email();
});
jQuery('#action-send').on('click', function (e) {
Settings.send_email();
});
jQuery('#action-trash-variation').on('click', function (e) {
Settings.trash_variation();
});
jQuery('#action-trash').on('click', function (e) {
Settings.trash_email();
});
jQuery('#action-send-test-email').on('click', function (e) {
Settings.send_test_email();
});
jQuery('#action-clone').on('click', function (e) {
Settings.clone_email();
});
jQuery('#action-cancel-sending').on('click', function (e) {
Settings.cancel_send();
});
jQuery('#email_type').on('change', function () {
Settings.load_email_type();
});
jQuery('#mailer-change-template-button').live('click', function () {
Settings.load_template_selector();
});
jQuery('.template_select').click(function () {
Settings.select_template(jQuery(this));
});
jQuery('#mailer-cancel-selection').click(function () {
Settings.cancel_template_selection();
});
jQuery('#template-filter a').click(function () {
Settings.filter_templates( jQuery(this) );
});
jQuery('.action-save').click(function () {
Settings.save_email();
});
jQuery('.action-clear-stats').click(function () {
Settings.clear_stats();
});
jQuery('#inbound_mailer_screen_option_range').change(function () {
Settings.update_range( jQuery(this) );
});
jQuery('#automation_job_id').change(function () {
Settings.update_job_id( jQuery(this) );
});
Settings.load_email_type();
Settings.toggle_post_status('<?php echo $post->post_status; ?>');
});
window.setInterval(function() {
jQuery(window).off('beforeunload');
jQuery(window).unbind('beforeunload');
} , 3000 );
</script>
<?php
}
public static function print_settings_class_JS() {
global $post;
?>
<script>
var Settings = (function () {
var ladda_button;
var current_slug;
var interval_id;
var Init = {
init: function () {
jQuery('#submitdiv').hide();
jQuery('#postdivrich').hide();
Settings.current_slug = jQuery('#post_name').val();
jQuery('.btn-group a').tooltip();
jQuery('.inbound-tooltip').tooltip();
jQuery('#selected-template-image').tooltip();
jQuery('.email-action').tooltip();
jQuery('.current-status').tooltip();
jQuery('#submitdiv h3 span').text('<?php _e('Save', 'inbound-pro'); ?>');
},
toggle_post_status: function (post_status) {
jQuery('#email-status-display').text(post_status);
switch (post_status) {
case 'sent':
Settings.show_graphs();
Settings.show_clone_buttons();
Settings.show_save_button();
Settings.hide_preview();
Settings.hide_quick_lauch_container();
Settings.hide_header_settings();
Settings.hide_email_send_settings();
Settings.hide_send_buttons();
Settings.hide_send_test_email_button();
Settings.hide_email_send_type();
break;
case 'sending':
Settings.hide_preview();
Settings.hide_quick_lauch_container();
Settings.hide_header_settings();
Settings.hide_email_send_settings();
Settings.hide_template_settings();
Settings.hide_save_button();
Settings.hide_clear_stats_button();
Settings.show_graphs();
Settings.show_cancel_buttons();
Settings.show_trash_button();
break;
case 'scheduled':
Settings.show_notification();
Settings.show_countdown_container();
Settings.show_unschedule_buttons();
Settings.hide_trash_button();
Settings.hide_save_button();
Settings.hide_header_settings();
Settings.hide_template_settings();
Settings.hide_email_send_settings();
Settings.hide_quick_lauch_container();
Settings.update_countdown();
break;
case 'automated':
Settings.hide_send_buttons();
Settings.hide_email_send_settings();
jQuery('#action-preview').show();
Settings.show_send_test_email_button();
Settings.show_trash_button();
Settings.show_save_button();
Settings.show_quick_lauch_container();
Settings.show_header_settings();
Settings.show_template_settings();
Settings.show_graphs();
Settings.show_clear_stats_button();
jQuery('#hidden_post_status').val('automated');
jQuery('#post_status').val('automated');
break;
default:
jQuery('#action-preview').show();
Settings.hide_graphs();
Settings.show_send_button();
Settings.show_send_test_email_button();
Settings.show_header_settings();
Settings.show_email_send_settings();
Settings.show_quick_lauch_container();
Settings.show_template_settings();
Settings.show_trash_button();
Settings.show_save_button();
jQuery('#hidden_post_status').val('unsent');
jQuery('#post_status').val('unsent');
break;
}
},
show_header_settings: function () {
jQuery('.mail-headers-container').show();
},
hide_header_settings: function () {
jQuery('.mail-headers-container').hide();
},
show_email_send_settings: function () {
jQuery('.mail-send-settings-container').show();
},
hide_email_send_settings: function () {
jQuery('.mail-send-settings-container').hide();
},
show_email_send_type: function () {
jQuery('.mail-send-settings-container').show();
},
hide_email_send_type: function () {
jQuery('#email-send-type').hide();
},
show_quick_lauch_container: function () {
jQuery('.quick-launch-container').show();
},
hide_quick_lauch_container: function () {
jQuery('.quick-launch-container').hide();
},
show_graphs: function () {
jQuery('.statistics-reporting-container').show();
},
hide_graphs: function () {
jQuery('.statistics-reporting-container').hide();
},
show_graphs_barchart: function () {
jQuery('.barchart').show();
},
hide_graphs_barchart: function () {
jQuery('.barchart').hide();
},
show_preview: function () {
jQuery('.preview-container').show();
},
hide_preview: function () {
jQuery('.preview-container').hide();
},
show_template_settings: function () {
jQuery('#postbox-container-2').show();
},
hide_template_settings: function () {
jQuery('#postbox-container-2').hide();
},
show_notification: function () {
jQuery('.notifications-container').show();
},
show_countdown_container: function () {
jQuery('.countdown-container').show();
},
hide_countdown_container: function () {
jQuery('.countdown-container').hide();
},
show_save_button: function () {
jQuery('#action-save').show();
},
hide_save_button: function () {
jQuery('#action-save').hide();
},
show_clear_stats_button: function () {
jQuery('#action-clear-stats').show();
},
hide_clear_stats_button: function () {
jQuery('#action-clear-stats').hide();
},
show_trash_button: function () {
jQuery('#action-trash').show();
},
hide_trash_button: function () {
jQuery('#action-trash').hide();
},
show_unschedule_buttons: function () {
jQuery('#email_type').prop('disabled', 'true');
jQuery('.email-action').hide();
jQuery('#action-unschedule').show();
},
hide_unschedule_buttons: function () {
jQuery('#action-unschedule').hide();
},
show_cancel_buttons: function () {
jQuery('#email_type').prop('disabled', 'true');
jQuery('.email-action').hide();
jQuery('#action-cancel-sending').show();
},
hide_cancel_buttons: function () {
jQuery('#action-cancel-sending').hide();
},
show_send_button: function () {
jQuery('#action-send').show();
},
hide_send_buttons: function () {
jQuery('#action-send').hide();
},
show_send_test_email_button: function () {
jQuery('#action-send-test-email').show();
},
hide_send_test_email_button: function () {
jQuery('#action-send-test-email').hide();
},
show_clone_buttons: function () {
jQuery('#action-clone').show();
},
hide_clone_buttons: function () {
jQuery('#action-clone').hide();
},
update_countdown: function () {
var days, hours, minutes, seconds, message;
var target_date = new Date(jQuery('#inbound_send_datetime').val());
Settings.interval_id = setInterval(function () {
var current_date = new Date().getTime();
var seconds_left = (target_date - current_date) / 1000;
if (seconds_left.toString().indexOf('-')> -1 ) {
clearInterval(Settings.interval_id);
jQuery.ajax({
type: 'post',
url: ajaxurl,
data: {
action: 'inbound_mark_sent',
email_id: '<?php echo $post->ID; ?>'
},
success: function (result) {
window.location.reload();
}
});
}
days = parseInt(seconds_left / 86400);
seconds_left = seconds_left % 86400;
hours = parseInt(seconds_left / 3600);
seconds_left = seconds_left % 3600;
minutes = parseInt(seconds_left / 60);
seconds = parseInt(seconds_left % 60);
message = "<span class='send-countdown-label'><?php _e('Time until send:' , 'inbound-pro'); ?></span>";
jQuery('.scheduled-information-countdown').html(message + days + "d " + hours + "h " + minutes + "m " + seconds + "s ");
}, 1000);
},
load_email_type: function () {
var send_nature = jQuery('#email_type option:selected').val();
switch (send_nature) {
case 'automated':
Settings.toggle_post_status('automated');
break;
default:
Settings.toggle_post_status('unsent');
break;
}
},
validate_fields: function () {
if (!Settings.validate_headers()) {
return false;
}
if (!Settings.validate_recipients()) {
return false;
}
return true;
},
validate_headers: function () {
if (!jQuery('#subject').val()) {
swal("<?php _e('Email requires subject to send.' , 'inbound-pro'); ?>");
return false;
}
if (!jQuery('#from_name').val()) {
swal("<?php _e('Email requires from name to send.' , 'inbound-pro'); ?>");
return false;
}
if (!jQuery('#from_email').val()) {
swal("<?php _e('Email requires from email address to send.' , 'inbound-pro'); ?>");
return false;
}
return true;
},
validate_recipients: function () {
var selectedRecipients = jQuery('#inbound_recipients').val();
if (selectedRecipients) {
return true;
} else {
swal("<?php _e('Please set email recipients.' , 'inbound-pro'); ?>");
return false;
}
},
clone_email: function () {
swal({
title: "<?php _e( 'Are you sure?' , 'inbound-pro' ); ?>",
text: "<?php _e( 'Are you sure you want to clone this email?' , 'inbound-pro' ); ?>",
type: "info",
showCancelButton: true,
confirmButtonColor: "#2ea2cc",
confirmButtonText: "<?php _e( 'Yes, clone it!' , 'inbound-pro' ); ?>",
closeOnConfirm: false
}, function () {
swal({
title: "<?php _e('Please wait' , 'inbound-pro' ); ?>",
text: "<?php _e('We are cloning your email now.' , 'inbound-pro' ); ?>",
imageUrl: '<?php echo INBOUND_EMAIL_URLPATH; ?>/assets/images/loading_colorful.gif'
});
var redirect_url = "<?php echo admin_url('admin.php?action=inbound_email_clone_post&post=' . $post->ID ); ?>";
window.location = redirect_url;
});
},
send_test_email: function () {
if (!Settings.validate_headers()) {
return false;
}
jQuery('.action-save').click();
swal({
title: "<?php _e( 'Send Test Email' , 'inbound-pro' ); ?>",
text: "",
type: "info",
showCancelButton: true,
confirmButtonColor: "#2ea2cc",
confirmButtonText: "<?php _e( 'Send test email!' , 'inbound-pro' ); ?>",
closeOnConfirm: false,
inputField: {
placeholder: '<?php _e( 'Enter target e-mail address.' , 'inbound-pro' ); ?>',
padding: '20px',
width: '271px'
}
}, function (email_address) {
if (!email_address) {
return;
}
swal({
title: "<?php _e('Please wait' , 'inbound-pro' ); ?>",
text: "<?php _e('We are sending a test email now.' , 'inbound-pro' ); ?>",
imageUrl: '<?php echo INBOUND_EMAIL_URLPATH; ?>/assets/images/loading_colorful.gif'
});
jQuery.ajax({
type: "POST",
url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
data: {
action: 'inbound_send_test_email',
email_address: email_address,
email_id: '<?php echo $post->ID; ?>',
variation_id: jQuery('#open_variation').val()
},
dataType: 'html',
timeout: 20000,
success: function (response) {
alert(response);
jQuery('.confirm').click();
},
error: function (request, status, err) {
}
});
});
},
send_email: function () {
if (!Settings.validate_fields()) {
return false;
}
swal({
title: "<?php _e( 'Are you sure?' , 'inbound-pro' ); ?>",
text: "<?php _e( 'Are you sure you want to begin sending this email?' , 'inbound-pro' ); ?>",
type: "info",
showCancelButton: true,
confirmButtonColor: "#449d44",
confirmButtonText: "<?php _e( 'Yes, send it!' , 'inbound-pro' ); ?>",
closeOnConfirm: false
}, function () {
swal({
title: "<?php _e('Please wait' , 'inbound-pro' ); ?>",
text: "<?php _e('We are scheduling your email now.' , 'inbound-pro' ); ?>",
imageUrl: '<?php echo INBOUND_EMAIL_URLPATH; ?>/assets/images/loading_colorful.gif'
});
jQuery('#email_action').val('schedule');
jQuery('#hidden_post_status').val('sending');
jQuery('#post_status').val('sending');
Settings.save_email( true );
});
},
unschedule_email: function () {
swal({
title: "<?php _e( 'Are you sure?' , 'inbound-pro' ); ?>",
text: "<?php _e( 'Are you sure you want to unschedule this email? Please not that emails 10 minutes or less away from being sent will not be able to be unscheduled from SparkPost.' , 'inbound-pro' ); ?>",
type: "info",
showCancelButton: true,
confirmButtonColor: "#449d44",
confirmButtonText: "<?php _e( 'Yes, unschedule it!' , 'inbound-pro' ); ?>",
closeOnConfirm: false
}, function () {
swal({
title: "<?php _e('Please wait' , 'inbound-pro' ); ?>",
text: "<?php _e('We are unscheduling your email now.' , 'inbound-pro' ); ?>",
imageUrl: '<?php echo INBOUND_EMAIL_URLPATH; ?>/assets/images/loading_colorful.gif'
});
jQuery('#hidden_post_status').val('unsent');
jQuery('#post_status').val('unsent');
Settings.save_email();
jQuery.ajax({
type: 'post',
url: ajaxurl,
data: {
action: 'inbound_unschedule_email',
email_id: '<?php echo $post->ID; ?>'
},
success: function (result) {
window.location.reload();
}
});
});
},
schedule_email: function() {
jQuery.ajax({
type: 'post',
url: ajaxurl,
data: {
action: 'inbound_schedule_email',
email_id: '<?php echo $post->ID; ?>'
},
success: function (result) {
window.location.reload();
}
});
},
cancel_send: function () {
if (!Settings.validate_fields()) {
return false;
}
swal({
title: "<?php _e( 'Are you sure?' , 'inbound-pro' ); ?>",
text: "<?php _e( 'Cancelling this email will remove all unsent emails from our send queue. Cancel now to stop sending.' , 'inbound-pro' ); ?>",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#d9534f",
confirmButtonText: "<?php _e( 'Yes, cancel it now!' , 'inbound-pro' ); ?>",
closeOnConfirm: false
}, function () {
swal({
title: "<?php _e('Please wait' , 'inbound-pro' ); ?>",
text: "<?php _e('We are cancelling your email now.' , 'inbound-pro' ); ?>",
imageUrl: '<?php echo INBOUND_EMAIL_URLPATH; ?>/assets/images/loading_colorful.gif'
});
jQuery('#email_action').val('unschedule');
jQuery('#hidden_post_status').val('cancelled');
jQuery('#post_status').val('cancelled');
jQuery.ajax({
type: 'post',
url: ajaxurl,
data: {
action: 'inbound_unschedule_email',
email_id: '<?php echo $post->ID; ?>'
},
success: function (result) {
Settings.save_email( false , true );
}
});
});
},
trash_email: function () {
swal({
title: "<?php _e( 'Are you sure?' , 'inbound-pro' ); ?>",
text: "<?php _e( 'Trashing this email will remove all unsent emails from our send queue. And set it\'s status to \'trash\'.' , 'inbound-pro' ); ?>",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#d9534f",
confirmButtonText: "<?php _e( 'Yes, trash it now!' , 'inbound-pro' ); ?>",
closeOnConfirm: false
}, function () {
swal({
title: "<?php _e('Please wait' , 'inbound-pro' ); ?>",
text: "<?php _e('We are trashing your email now.' , 'inbound-pro' ); ?>",
imageUrl: '<?php echo INBOUND_EMAIL_URLPATH; ?>/assets/images/loading_colorful.gif'
});
jQuery('#email_action').val('trash');
jQuery('#post_status').append(jQuery('<option>', {
value: 'trash',
text: 'Trash'
}));
jQuery('#hidden_post_status').val('trash');
jQuery('#post_status').val('trash');
jQuery('#post').submit();
});
},
trash_variation: function () {
swal({
title: "<?php _e( 'Are you sure?' , 'inbound-pro' ); ?>",
text: "<?php _e( 'Trashing this variation will delete all it\'s content.' , 'inbound-pro' ); ?>",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#d9534f",
confirmButtonText: "<?php _e( 'Yes, trash it now!' , 'inbound-pro' ); ?>",
closeOnConfirm: false
}, function () {
swal({
title: "<?php _e('Please wait' , 'inbound-pro' ); ?>",
text: "<?php _e('We are trashing your variation now.' , 'inbound-pro' ); ?>",
imageUrl: '<?php echo INBOUND_EMAIL_URLPATH; ?>/assets/images/loading_colorful.gif'
});
jQuery('#email_action').val('trash-variation');
jQuery('#post').submit();
});
},
select_template: function (element) {
var template = element.attr('id');
var label = element.attr('label');
swal({
title: "Are you sure?",
text: "<?php _e( 'Are you sure you want to select this template?' , 'inbound-pro' ); ?>",
type: "info",
showCancelButton: true,
confirmButtonColor: "#449d44",
confirmButtonText: "<?php _e( 'Yes' , 'inbound-pro' ); ?>",
closeOnConfirm: false,
closeOnCancel: true
}, function () {
swal({
title: "<?php _e('Please wait' , 'inbound-pro' ); ?>",
text: "<?php _e('We are setting up your email now.' , 'inbound-pro' ); ?>",
imageUrl: '<?php echo INBOUND_EMAIL_URLPATH; ?>/assets/images/loading_colorful.gif',
closeOnConfirm: false,
showConfirmButton: false,
}, function () {
});
jQuery('#selected_template').val(template);
jQuery('#post').submit();
});
},
cancel_template_selection: function () {
jQuery(".mailer-template-selector-container").fadeOut(500, function () {
jQuery(".wrap").fadeIn(500, function () {
});
});
},
filter_templates: function ( element ) {
var selector = element.attr('data-filter');
jQuery(".template-item-boxes").fadeOut(500);
setTimeout(function () {
jQuery(selector).fadeIn(500);
}, 500);
return false;
},
load_template_selector: function () {
jQuery(".wrap").fadeOut(500, function () {
jQuery(".mailer-template-selector-container").fadeIn(500, function () {
jQuery('#mailer-cancel-selection').show();
});
});
},
save_email: function ( is_being_scheduled , reload ) {
Settings.ladda_button = Ladda.create(document.querySelector('#action-save'));
Settings.ladda_button.toggle();
var data = Settings.get_form_data();
data['action'] = 'save_inbound_email';
jQuery.ajax({
type: 'post',
url: ajaxurl,
data: data,
success: function (result) {
Settings.ladda_button.toggle();
jQuery('#tabs-add-variation-hidden').show();
if (typeof is_being_scheduled != 'undefined' && is_being_scheduled) {
Settings.schedule_email();
}
if (typeof reload != 'undefined' && reload) {
window.location.reload();
}
}
});
var new_slug = jQuery('#post_name').val();
if ( new_slug != Settings.current_slug ) {
var preview_url = jQuery('#action-preview').attr('href');
jQuery('#action-preview').attr('href' , preview_url.replace( Settings.current_slug , new_slug ) );
jQuery('#sample-permalink a').attr('href' , preview_url.replace( Settings.current_slug , new_slug ) );
var visual_editor_url = jQuery('#cta-launch-front').attr('href');
jQuery('#cta-launch-front').attr('href' , visual_editor_url.replace( Settings.current_slug , new_slug ) );
Settings.current_slug = new_slug;
}
},
clear_stats: function () {
swal({
title: "Are you sure?",
text: "<?php _e( 'Are you sure you want to clear all stats related to this email?' , 'inbound-pro' ); ?>",
type: "info",
showCancelButton: true,
confirmButtonColor: "#c9302c",
confirmButtonText: "<?php _e( 'Clear them now' , 'inbound-pro' ); ?>",
cancelButtonText: "<?php _e( 'Go back' , 'inbound-pro' ); ?>",
closeOnConfirm: false,
closeOnCancel: true
}, function () {
jQuery.ajax({
type: 'post',
url: ajaxurl,
data: {
'action' : 'clear_email_stats',
'email_id': '<?php echo $post->ID; ?>'
},
success: function (result) {
}
});
swal({
title: "<?php _e('Please wait' , 'inbound-pro' ); ?>",
text: "<?php _e('We are deleting the statistics and reloading the page.' , 'inbound-pro' ); ?>",
imageUrl: '<?php echo INBOUND_EMAIL_URLPATH; ?>/assets/images/loading_colorful.gif',
closeOnConfirm: false,
showConfirmButton: false,
}, function () {
});
window.location.reload();
});
},
update_range: function ( $this ) {
jQuery.ajax({
type: 'post',
url: ajaxurl,
data: {
'action' : 'inbound_email_update_range',
'range': $this.find('option:selected').val()
},
success: function (result) {
window.location.reload();
}
});
},
update_job_id: function ( $this ) {
swal({
title: "<?php _e('Please wait' , 'inbound-pro' ); ?>",
text: "<?php _e('A new report is being loaded.' , 'inbound-pro' ); ?>",
imageUrl: '<?php echo INBOUND_EMAIL_URLPATH; ?>/assets/images/loading_colorful.gif',
closeOnConfirm: false,
showConfirmButton: false,
}, function () {
});
jQuery.ajax({
type: 'post',
url: ajaxurl,
data: {
'action' : 'inbound_email_update_job_id',
'email_id': '<?php echo $post->ID; ?>',
'job_id': $this.find('option:selected').val()
},
success: function (result) {
window.location.reload();
}
});
},
get_form_data: function () {
var formData = jQuery('#post').serializeArray();
var o = {};
jQuery.each(formData, function () {
if (o[this.name] !== undefined && jQuery('input[name="'+this.name+'"').attr('type') != 'hidden') {
if (!o[this.name].push ) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
}
}
return Init;
})();
</script>
<?php
}
public static function action_save_data($inbound_email_id) {
unset($_POST['post_content']);
if (wp_is_post_revision($inbound_email_id)) {
return;
}
if (!isset($_POST['post_type']) || $_POST['post_type'] != 'inbound-email' || !isset($_POST['inbvid']) ) {
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
$email_settings = Inbound_Email_Meta::get_settings($_POST['post_ID']);
$email_settings['variations'][$_POST['inbvid']]['selected_template'] = $_POST['selected_template'];
Inbound_Email_Meta::update_settings($_POST['post_ID'], $email_settings);
remove_action('save_post', array(__CLASS__, 'action_save_data'));
Inbound_Mailer_Metaboxes::action_processing();
}
public static function action_processing() {
switch ($_POST['email_action']) {
case 'trash':
Inbound_Mailer_Scheduling::unschedule_email($_POST['post_ID']);
wp_trash_post($_POST['post_ID']);
header('Location:' . admin_url('edit.php?post_type=inbound-email'));
exit;
break;
case 'trash-variation':
Inbound_Mailer_Variations::delete_variation($_POST['post_ID'] , $_POST['inbvid']);
break;
case 'schedule':
break;
default:
wp_update_post(
array (
'ID' => $_POST['post_ID'],
'post_name' => $_POST['post_name']
)
);
break;
}
}
public static function check_post_stats($data) {
if ($data['post_type'] != 'inbound-email') {
return $data;
}
if ($data['post_status'] == 'publish') {
$data['post_status'] = 'unsent';
}
return $data;
}
public static function generate_json() {
global $post;
if ( !isset($_GET['inbound_generate_email_json'] ) ) {
return;
}
$settings = get_post_meta( $post->ID , 'inbound_settings' ,true );
$settings['is_sample_email'] = true;
unset($settings['recipients']);
echo json_encode($settings);exit;
}
}
new Inbound_Mailer_Metaboxes;
}