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:
<?php
class Inbound_Metaboxes_Automation {
static $post_type;
static $rule_trigger;
static $rule_trigger_evaluate;
static $rule_trigger_filters;
static $rule_action_blocks;
static $Inbound_Automation;
static $rule;
static $triggers;
static $argument_filters;
static $actions;
static $db_lookup_filters;
public function __construct() {
self::$post_type = 'automation';
self::load_hooks();
}
public static function load_hooks() {
add_action('posts_selection', array(__CLASS__, 'load_rule'));
add_action( 'admin_menu', array( __CLASS__ , 'add_logs_page_support' ) );
add_action('add_meta_boxes', array(__CLASS__, 'define_metaboxes'));
add_filter('enter_title_here', array(__CLASS__, 'change_title_text'), 10, 2);
add_action('save_post', array(__CLASS__, 'save_automation'));
add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_admin_scripts'));
add_action('admin_print_footer_scripts', array(__CLASS__, 'print_admin_scripts'));
add_action('wp_ajax_automation_get_trigger_arguments', array(__CLASS__, 'ajax_load_trigger_arguments'));
add_action('wp_ajax_automation_get_db_lookup_filters', array(__CLASS__, 'ajax_load_db_lookup_filters'));
add_action('wp_ajax_automation_get_actions', array(__CLASS__, 'ajax_load_action_definitions'));
add_action('wp_ajax_automation_build_trigger_filter', array(__CLASS__, 'ajax_build_trigger_filter'));
add_action('wp_ajax_automation_build_db_lookup_filter', array(__CLASS__, 'ajax_build_db_lookup_filter'));
add_action('wp_ajax_automation_build_action', array(__CLASS__, 'ajax_build_action'));
add_action('wp_ajax_automation_build_action_block', array(__CLASS__, 'ajax_build_action_block'));
add_action('wp_ajax_automation_clear_logs', array(__CLASS__, 'ajax_clear_logs'));
add_filter( 'get_user_option_screen_layout_automation', array (__CLASS__, 'screen_layout_columns' ) );
}
public static function load_definitions() {
if (isset(self::$Inbound_Automation)) {
return;
}
self::$Inbound_Automation = inbound_automation_load_definitions();
self::$triggers = self::$Inbound_Automation->triggers;
self::$argument_filters = self::$Inbound_Automation->argument_filters;
self::$actions = self::$Inbound_Automation->actions;
self::$db_lookup_filters = self::$Inbound_Automation->db_lookup_filters;
}
public static function load_rule() {
global $post;
if (!isset($post) || $post->post_type != self::$post_type || !isset($_GET['post'])) {
return;
}
self::$rule = get_post_meta($post->ID, 'inbound_rule', true);
self::$rule_trigger = (isset(self::$rule['trigger'])) ? self::$rule['trigger'] : '';
self::$rule_trigger_evaluate = (isset(self::$rule['trigger_filters_evaluate'])) ? self::$rule['trigger_filters_evaluate'] : '';
self::$rule_trigger_filters = (isset(self::$rule['trigger_filters'])) ? self::$rule['trigger_filters'] : array();
self::$rule_action_blocks = (isset(self::$rule['action_blocks'])) ? self::$rule['action_blocks'] : array(1 =>array());
}
public static function define_metaboxes() {
global $post;
if ($post->post_type != self::$post_type) {
return;
}
add_meta_box(
'inbound_automation_settings',
__('Trigger', 'inbound-pro'),
array(__CLASS__, 'display_container'),
self::$post_type,
'normal',
'high'
);
if (!isset(self::$rule_action_blocks)) {
self::$rule_action_blocks = array( 1 =>array() );
}
foreach (self::$rule_action_blocks as $block_id => $block) {
add_meta_box(
'inbound_automation_actions_' . $block_id,
__('Actions', 'inbound-pro'),
array( __CLASS__ , 'print_actions'),
self::$post_type,
'normal',
'high',
array(
'block_id' => $block_id,
'block' => $block
)
);
}
add_meta_box(
'inbound_automation_logs',
__('Logs', 'inbound-pro'),
array(__CLASS__, 'print_logs_container'),
self::$post_type,
'normal',
'low'
);
}
public static function display_container() {
global $post;
self::load_definitions();
self::print_trigger_container();
}
public static function add_logs_page_support() {
add_submenu_page(
'automation',
__('Logs','inbound-pro'),
__('Logs','inbound-pro'),
'manage_options',
'inbound_rule_logs',
array( __CLASS__ , 'print_logs')
);
}
public static function print_trigger_container() {
?>
<div class='nav-container nav-reveal trigger-container' id='trigger-container'>
<table class='table-trigger-container'>
<tr class='tr-trigger-select'>
<td>
<h2 class='trigger-section-header'><?php _e('Define Trigger','mailer'); ?></h2>
<select class='trigger-dropdown form-control' id='trigger-dropdown' name='trigger'>
<?php
echo '<option value="-1" class="">Select Trigger</option>';
foreach (self::$triggers as $hook => $trigger) {
echo '<option
value="' . $hook . '"
class="' . (isset($trigger['icon_class']) ? $trigger['icon_class'] : '') . '"
' . (isset(self::$rule_trigger) && self::$rule_trigger == $hook ? 'selected="selected"' : '') . '
>' . $trigger['label'] . '</option>';
}
?>
</select>
</td>
</tr>
<tr class="tr-filter-select">
<td class='td-filter-add-dropdown' id='argument-filters-container'>
<h2 class='trigger-section-header' ><?php _e('Define Conditions' , 'mailer' ); ?></h2>
<div
class='trigger-filter-evaluate <?php if (!isset(self::$rule_trigger_filters) || count(self::$rule_trigger_filters) < 1) {
echo 'nav-hide';
} ?>'>
<div class="btn-group btn-group-evaluate" data-toggle="buttons">
<label
class="btn btn-default <?php if (!self::$rule_trigger_evaluate || self::$rule_trigger_evaluate == 'match-all') {
echo 'active';
} ?>">
<input type='radio' name='trigger_filters_evaluate'
value='match-all' <?php if (!self::$rule_trigger_evaluate || self::$rule_trigger_evaluate == 'match-all') {
echo 'checked="checked"';
} ?>> Match All
</label>
<label
class="btn btn-default <?php if (self::$rule_trigger_evaluate == 'match-any') {
echo 'active';
} ?>">
<input type='radio' name='trigger_filters_evaluate'
value='match-any' <?php if (self::$rule_trigger_evaluate == 'match-any') {
echo 'checked="checked"';
} ?>> Match Any
</label>
<label
class="btn btn-default <?php if (self::$rule_trigger_evaluate == 'match-none') {
echo 'active';
} ?>">
<input type='radio' name='trigger_filters_evaluate'
value='match-none' <?php if (self::$rule_trigger_evaluate == 'match-none') {
echo 'checked="checked"';
} ?>> Match None
</label>
</div>
<div class="btn-group add-filter">
<button type="button" class="btn btn-warning dropdown-toggle ladda-button"
data-style="expand-right" data-toggle="dropdown"
id='add-trigger-filter-button'>
<?php _e('Add Filter', 'mailer'); ?><span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-left trigger-filters" role="menu">
<li><a><?php _e(' Select a filter...', 'mailer'); ?></a></li>
</ul>
</div>
<?php
if (isset(self::$rule_trigger_filters)) {
foreach (self::$rule_trigger_filters as $child_id => $filter) {
$args = array('trigger_id' => self::$rule_trigger, 'trigger_filter_id' => $filter['trigger_filter_id'], 'child_id' => $child_id, 'defaults' => $filter);
$html = self::ajax_build_trigger_filter($args);
echo $html;
}
}
?>
</td>
</tr>
</table>
</div>
<?php
}
public static function print_logs_container() {
global $inbound_automation_logs, $post;
?>
<iframe
src="<?php echo admin_url('admin.php?page=inbound_rule_logs&rule_id='.$post->ID); ?>"
frameborder="0" style="height:100vh;width:100%;" width="100%">
</iframe>
<?php
}
public static function print_logs() {
global $inbound_automation_logs, $post;
$post = get_post($_GET['rule_id']);
$logs = array_reverse($inbound_automation_logs->get_logs($post->ID), true);
?>
<style>
html.wp-toolbar {
background:
padding-top:20px;
}
header,head,body {
background:
}
.tr-log-entry-content {
display: none;
}
width: 50px;
}
.tablesorter {
table-layout: fixed;
background:
max-width: 100%;
border-spacing: 0;
width: 100%;
margin: 10px 0;
border: 1px solid
border-collapse: separate;
*border-collapse: collapsed;
-webkit-box-shadow: 0 0 4px rgba(0, 0, 0, 0.10);
-moz-box-shadow: 0 0 4px rgba(0, 0, 0, 0.10);
box-shadow: 0 0 4px rgba(0, 0, 0, 0.10);
}
.tablesorter th, .tablesorter td {
padding: 8px;
line-height: 18px;
text-align: left;
border-top: 1px solid
word-wrap: break-word;
}
.tablesorter th {
background:
background: -webkit-gradient(linear, left top, left bottom, from(
background: -moz-linear-gradient(top,
text-shadow: 0 1px 0
font-weight: bold;
vertical-align: bottom;
}
.tablesorter td {
vertical-align: top;
}
.tablesorter thead:first-child tr th,
.tablesorter thead:first-child tr td {
border-top: 0;
}
.tablesorter tbody + tbody {
border-top: 2px solid
}
.tablesorter th + th,
.tablesorter td + td,
.tablesorter th + td,
.tablesorter td + th {
border-left: 1px solid
}
.tablesorter thead:first-child tr:first-child th,
.tablesorter tbody:first-child tr:first-child th,
.tablesorter tbody:first-child tr:first-child td {
border-top: 0;
}
display:none;
}
margin-left:0px !important;
}
</style>
<div class='nav-container logs-container' id='logs-container'>
<div class='clear-logs-container'>
<span class='button button-secondary' id='clear-logs' data-rule-id='<?php echo $post->ID; ?>'>
<?php _e( 'Clear logs' , 'inbound-pro' ); ?>
</span>
<span class='button button-secondary' id='refresh-logs' data-rule-id='<?php echo $post->ID; ?>'>
<?php _e( 'Refresh logs' , 'inbound-pro' ); ?>
</span>
</div>
<table class='tablesorter'>
<tr>
<th class=" sort-header" id='th-log-id'><?php _e('Log ID', 'inbound-pro'); ?></th>
<th class=" sort-header" id='th-log-title'><?php _e('Log Title', 'inbound-pro'); ?></th>
<th class=" sort-header" id='th-log-date'><?php _e('Log Date', 'inbound-pro'); ?></th>
<th class=" sort-header" id='th-log-date'><?php _e('Task ID', 'inbound-pro'); ?></th>
<th class=" sort-header" id='th-log-date'><?php _e('Log Type', 'inbound-pro'); ?></th>
<th class=" sort-header" id='th-log-expand'><?php _e('Expand', 'inbound-pro'); ?></th>
</tr>
<?php
$i = 0;
foreach ($logs as $key => $log) {
if ($i > 50) {
break;
}
echo '<tr class="tr-log-entry" data-id="' . $key . '">';
echo ' <td class="td-log log-title">' . $key . '</td>';
echo ' <td class="td-log log-title">' . $log['log_title'] . '</td>';
echo ' <td class="td-log log-datetime">' . $log['log_datetime'] . '</td>';
echo ' <td class="td-log log-datetime">' . $log['job_id'] . '</td>';
echo ' <td class="td-log log-datetime">' . $log['log_type'] . '</td>';
echo ' <td class="td-log log-datetime"><a href="javascript:void(0);" class="toggle-log-content" data-id="' . $key . '">+/-</a></td>';
echo '</tr>';
echo '<tr class="tr-log-entry-content" id="log-content-' . $key . '" data-id="' . $key . '">';
echo ' <td colspan=6 class="td-log-entry-content"data-id="' . $key . '" >';
echo stripslashes(base64_decode($log['log_content']));
echo ' </td>';
echo '</td>';
echo '</tr>';
$i++;
}
?>
</table>
</div>
<?php
}
public static function print_actions($post, $args) {
global $post;
$html = self::ajax_build_action_block($args['args']['block_id'], $action_priority = null, $args['args']['block']);
echo $html;
}
public static function save_automation($post_id) {
global $post;
if (!isset($post)) {
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!current_user_can('edit_post', $post_id)) {
return;
}
if ($post->post_type != self::$post_type) {
return;
}
self::load_definitions();
$rule = array();
$rule['trigger'] = $_POST['trigger'];
if (isset ($_POST['trigger_filter_value'])) {
$filters = array();
foreach ($_POST['trigger_filter_key'] as $id => $value) {
(isset($_POST['trigger_filter_id'][$id])) ? $filters[$id]['trigger_filter_id'] = $_POST['trigger_filter_id'][$id] : $filters[$id]['trigger_filter_id'] = null;
(isset($_POST['trigger_filter_key'][$id])) ? $filters[$id]['trigger_filter_key'] = $_POST['trigger_filter_key'][$id] : $filters[$id]['key'] = null;
(isset($_POST['trigger_filter_compare'][$id])) ? $filters[$id]['trigger_filter_compare'] = $_POST['trigger_filter_compare'][$id] : $filters[$id]['trigger_filter_compare'] = null;
(isset($_POST['trigger_filter_value'][$id])) ? $filters[$id]['trigger_filter_value'] = $_POST['trigger_filter_value'][$id] : $filters[$id]['value'] = null;
}
$rule['trigger_filters'] = $filters;
}
if (isset ($_POST['trigger_filters_evaluate'])) {
$rule['trigger_filters_evaluate'] = $_POST['trigger_filters_evaluate'];
}
if (isset ($_POST['action_block_id'])) {
$action_blocks = array();
foreach ($_POST['action_block_id'] as $block_id) {
$action_blocks[$block_id]['action_block_filters_evaluate'] = $_POST['action_block_filters_evaluate'][$block_id];
$filters = array();
if (isset($_POST['action_filter_value'][$block_id])) {
foreach ($_POST['action_filter_value'][$block_id] as $id => $filter_value) {
(isset($_POST['action_filter_id'][$block_id][$id])) ? $filters[$id]['action_filter_id'] = $_POST['action_filter_id'][$block_id][$id] : $filters[$id]['action_filter_id'] = null;
(isset($_POST['action_filter_key'][$block_id][$id])) ? $filters[$id]['action_filter_key'] = $_POST['action_filter_key'][$block_id][$id] : $filters[$id]['key'] = null;
(isset($_POST['action_filter_compare'][$block_id][$id])) ? $filters[$id]['action_filter_compare'] = $_POST['action_filter_compare'][$block_id][$id] : $filters[$id]['action_filter_compare'] = null;
(isset($_POST['action_filter_value'][$block_id][$id])) ? $filters[$id]['action_filter_value'] = $_POST['action_filter_value'][$block_id][$id] : $filters[$id]['value'] = null;
}
}
$action_blocks[$block_id]['filters'] = $filters;
$actions = array();
if (isset($_POST['action_name'][$block_id]['then'])) {
foreach ($_POST['action_name'][$block_id]['then'] as $child_id => $action_name) {
$this_action = self::$actions[$action_name];
if (!isset($this_action['settings'])) {
continue;
}
$actions[$child_id]['action_name'] = $action_name;
$actions[$child_id]['action_class_name'] = $this_action['class_name'];
foreach ($this_action['settings'] as $setting) {
if (isset($_POST[$setting['id']][$block_id]['then'][$child_id])) {
$actions[$child_id][$setting['id']] = $_POST[$setting['id']][$block_id]['then'][$child_id];
}
}
}
}
$action_blocks[$block_id]['actions']['then'] = $actions;
$actions = array();
if (isset($_POST['action_name'][$block_id]['else'])) {
foreach ($_POST['action_name'][$block_id]['else'] as $child_id => $action_name) {
$this_action = self::$actions[$action_name];
if (!isset($this_action['settings'])) {
continue;
}
$actions[$child_id]['action_name'] = $action_name;
$actions[$child_id]['action_class_name'] = $this_action['class_name'];
foreach ($this_action['settings'] as $setting) {
if (isset($_POST[$setting['id']][$block_id]['else'][$child_id])) {
$actions[$child_id][$setting['id']] = $_POST[$setting['id']][$block_id]['else'][$child_id];
}
}
}
}
if ($actions) {
$action_blocks[$block_id]['actions']['else'] = $actions;
}
}
$rule['action_blocks'] = $action_blocks;
}
$old_rule = get_post_meta($post_id, 'inbound_rule', true);
$rule['defer'] = ( isset( $old_rule['defer']) ) ? $old_rule['defer'] : 'on';
$rule['status'] = ( isset( $old_rule['status']) ) ? $old_rule['status'] : 'on';
update_post_meta($post_id, 'inbound_rule', $rule);
}
public static function change_title_text($text, $post) {
if ($post->post_type == self::$post_type) {
return __('Enter Rule Name Here', 'inbound-pro');
} else {
return $text;
}
}
public static function enqueue_admin_scripts($hook) {
global $post;
if ($hook == 'admin_page_inbound_rule_logs') {
$post = get_post( $_GET['rule_id']);
}
if (!isset($post) || $post->post_type != self::$post_type) {
return;
}
if ($hook == 'post-new.php' || $hook == 'post.php' || $hook == 'admin_page_inbound_rule_logs') {
wp_deregister_script('heartbeat');
wp_deregister_script('wp-compression-test');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-effects-core');
wp_enqueue_script('jquery-effects-highlight');
wp_enqueue_style('inbound_automation_admin_css', INBOUND_AUTOMATION_URLPATH . 'assets/css/admin/admin.post-edit.css');
wp_enqueue_style('automation-admin-jquery-ui-css', INBOUND_AUTOMATION_URLPATH . 'assets/css/jquery-ui.css');
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('spin-js', INBOUND_AUTOMATION_URLPATH . 'assets/libraries/Ladda/spin.min.js');
wp_enqueue_script('spin-js');
wp_register_script('ladda-js', INBOUND_AUTOMATION_URLPATH . 'assets/libraries/Ladda/ladda.min.js');
wp_enqueue_script('ladda-js');
wp_register_style('ladda-css', INBOUND_AUTOMATION_URLPATH . 'assets/libraries/Ladda/ladda-themeless.min.css');
wp_enqueue_style('ladda-css');
wp_register_style('fontawesome', INBOUNDNOW_SHARED_URLPATH . 'assets/fonts/fontawesome/css/font-awesome.min.css');
wp_enqueue_style('fontawesome');
wp_register_script('inbound-rules-js', INBOUND_AUTOMATION_URLPATH . 'assets/js/admin.rule-setup.js');
wp_enqueue_script('inbound-rules-js');
wp_localize_script('inbound-rules-js' , 'inbound_rules' , array('hook' => $hook ));
wp_enqueue_script('selectjs', INBOUNDNOW_SHARED_URLPATH . 'assets/includes/Select2/select2.min.js', array() , null , false );
wp_enqueue_style('selectjs', INBOUNDNOW_SHARED_URLPATH . 'assets/includes/Select2/select2.css');
wp_enqueue_script('sweetalert', INBOUND_AUTOMATION_URLPATH . 'assets/libraries/SweetAlert/dist/sweetalert.min.js');
wp_enqueue_style('sweetalert', INBOUND_AUTOMATION_URLPATH . 'assets/libraries/SweetAlert/dist/sweetalert.css');
}
}
public static function print_admin_scripts() {
global $post;
if (!isset($post) || $post->post_type != self::$post_type) {
return;
}
?>
<script>
jQuery(function () {
jQuery('[data-toggle="tooltip"]').tooltip()
});
</script>
<?php
}
public static function ajax_build_action_block($action_block_id = null, $action_priority = null, $block = null) {
self::load_definitions();
(isset($_REQUEST['action_block_id'])) ? $action_block_id = intval($_REQUEST['action_block_id']) : $action_block_id;
(isset($_REQUEST['action_block_priority'])) ? $action_block_id = intval($_REQUEST['action_block_priority']) : $action_block_id;
$html = '';
$html .= '<div class="action-block-wrapper" data-action-block="' . $action_block_id . '">';
$html .= "<div class='action-block' data-block-id='" . $action_block_id . "' >";
$html .= "<div class='action-block-div' data-action-block-priority='" . $action_priority . "'>";
$html .= " <input type='hidden' name='action_block_id[" . $action_block_id . "]' value='" . $action_block_id . "'>";
$html .= " <div id='action-block-filters' class='action-block-conditions'>";
$html .= " <h2 class='action-block-section-header'>" . __('Additional conditions', 'inbound-pro') . "</h2>";
$html .= ' <div class="dropdown-add-filters" data-block-id="' . $action_block_id . '">';
$html .= ' <span class="dropdown-toggle add-action-filters" data-block-id="' . $action_block_id . '" data-action-type="then" type="button" data-toggle="dropdown">';
$html .= ' <i class="fa fa-plus-circle"></i>';
$html .= ' </span>';
$html .= ' <ul class="dropdown-menu dropdown-menu-left action-filter-options" role="menu" aria-labelledby="menu1" >';
$html .= ' </ul>';
$html .= ' </div>';
$block['action_block_filters_evaluate'] = (isset($block['action_block_filters_evaluate'])) ? $block['action_block_filters_evaluate'] : 'match-all' ;
$html .= " <div class='action-block-filter-evaluate' style='display:inline;'>";
$html .= ' <div class="btn-group" data-toggle="buttons">';
$html .= ' <label class="btn btn-default ' . ( $block['action_block_filters_evaluate'] == 'match-all' ? 'active' : '' ) .'">';
$html .= ' <input type="radio" name="action_block_filters_evaluate[' . $action_block_id . ']" value="match-all" ' . ( $block['action_block_filters_evaluate'] == 'match-all' ? 'checked="checked"' : '' ) .' > ' . __('Match All', 'inbound-pro');
$html .= ' </label>';
$html .= ' <label class="btn btn-default ' . ( $block['action_block_filters_evaluate'] == 'match-any' ? 'active' : '' ) .'">';
$html .= ' <input type="radio" name="action_block_filters_evaluate[' . $action_block_id . ']" value="match-any" ' . ( $block['action_block_filters_evaluate'] == 'match-any' ? 'checked="checked"' : '' ) .'> ' . __('Match Any', 'inbound-pro');
$html .= ' </label>';
$html .= ' <label class="btn btn-default ' . ( $block['action_block_filters_evaluate'] == 'match-none' ? 'active' : '' ) .'" >';
$html .= ' <input type="radio" name="action_block_filters_evaluate[' . $action_block_id . ']" value="match-none" ' . ( $block['action_block_filters_evaluate'] == 'match-none' ? 'checked="checked"' : '' ) .'> ' . __('Match None', 'inbound-pro');
$html .= ' </label>';
$html .= ' </div>';
$html .= " </div>";
$html .= ' <div class="action-block-filters-container" data-action-block-id="' . $action_block_id . '" >';
if (isset($block['filters'])) {
if (count($block['filters'])<1) {
$html .= '<div class="well well-sm action-contitions-well"><i>'.__( 'No conditions set' , 'inbound-pro' ) .'</i></div>';
}
foreach ($block['filters'] as $child_id => $filter) {
$args = array('action_filter_id' => $filter['action_filter_id'], 'action_block_id' => $action_block_id, 'child_id' => $child_id, 'defaults' => $filter);
$html .= self::ajax_build_db_lookup_filter($args);
}
}
$html .= " </div>";
$html .= " </div>";
$html .= " <div class='action-block-actions'>";
$html .= " <h2 class='action-block-section-header'>" . __('Actions to perform if conditions are met', 'inbound-pro') . "</h2>";
$html .= ' <div class="dropdown-add-actions" data-block-id="' . $action_block_id . '" data-action-type="then" >';
$html .= ' <span class="dropdown-toggle add-actions" data-block-id="' . $action_block_id . '" data-action-type="then" type="button" data-toggle="dropdown">';
$html .= ' <i class="fa fa-plus-circle"></i>';
$html .= ' </span>';
$html .= ' <ul class="dropdown-menu dropdown-menu-left action-options" role="menu" aria-labelledby="menu1" >';
$html .= ' </ul>';
$html .= ' </div>';
$html .= " <div class='action-block-then-actions-container' >";
if (isset($block['actions']['then'])) {
foreach ($block['actions']['then'] as $child_id => $action) {
$args = array('action_name' => $action['action_name'], 'action_type' => 'then', 'action_block_id' => $action_block_id, 'child_id' => $child_id, 'input_action_name_name' => 'action_name', 'defaults' => $action);
$html .= self::ajax_build_action($args);
}
}
$html .= " </div>";
$html .= " </div>";
$html .= " <div class='action-block-actions'>";
$html .= " <h2 class='action-block-section-header'>" . __('Actions to perform if conditions are not met', 'inbound-pro') . "</h2>";
$html .= ' <div class="dropdown-add-actions" data-block-id="' . $action_block_id . '" data-action-type="else" >';
$html .= ' <span class="dropdown-toggle add-actions" data-block-id="' . $action_block_id . '" data-action-type="then" type="button" data-toggle="dropdown">';
$html .= ' <i class="fa fa-plus-circle"></i>';
$html .= ' </span>';
$html .= ' <ul class="dropdown-menu dropdown-menu-left action-options" role="menu" aria-labelledby="menu1" >';
$html .= ' </ul>';
$html .= ' </div>';
$html .= " <div class='action-block-else-actions-container'>";
if (isset($block['actions']['else'])) {
foreach ($block['actions']['else'] as $child_id => $action) {
$args = array('action_name' => $action['action_name'], 'action_type' => 'else', 'action_block_id' => $action_block_id, 'child_id' => $child_id, 'input_action_name_name' => 'action_name', 'defaults' => $action);
$html .= self::ajax_build_action($args);
}
}
$html .= " </div>";
$html .= " </div>";
$html .= "</div>";
$html .= "</div></div>";
if (defined('DOING_AJAX') && DOING_AJAX) {
echo $html;
die();
} else {
return $html;
}
}
public static function ajax_build_trigger_filter($args) {
$args = ( !is_array($args) || !$args ) ? array() : $args;
self::load_definitions();
$args['trigger_id'] = (isset($args['trigger_id'])) ? $args['trigger_id'] : sanitize_text_field($_REQUEST['trigger_id']);
$args['trigger_filter_id'] = (isset($args['trigger_filter_id'])) ? $args['trigger_filter_id'] : sanitize_text_field($_REQUEST['trigger_filter_id']);
$args['child_id'] = (isset($args['child_id'])) ? $args['child_id'] : sanitize_text_field($_REQUEST['child_id']);
$args['defaults'] = (isset($args['defaults'])) ? $args['defaults'] : sanitize_text_field($_REQUEST['defaults']);
if ($args['trigger_filter_id'] == '-1' && defined('DOING_AJAX') && DOING_AJAX) {
die();
} else if ($args['trigger_filter_id'] == '-1') {
return '';
}
$key_args = array(
'name' => 'trigger_filter_key',
'type' => self::$argument_filters[$args['trigger_id']][$args['trigger_filter_id']]['key_input_type'],
'options' => self::$argument_filters[$args['trigger_id']][$args['trigger_filter_id']]['keys'],
'child_id' => $args['child_id'],
'default' => $args['defaults'],
'class' => 'trigger-filter-key'
);
$compare_args = array('name' => 'trigger_filter_compare', 'type' => 'dropdown', 'options' => self::$argument_filters[$args['trigger_id']][$args['trigger_filter_id']]['compare'], 'child_id' => $args['child_id'], 'default' => $args['defaults'], 'class' => 'trigger-filter-compare');
$value_args = array('name' => 'trigger_filter_value', 'type' => self::$argument_filters[$args['trigger_id']][$args['trigger_filter_id']]['value_input_type'], 'options' => self::$argument_filters[$args['trigger_id']][$args['trigger_filter_id']]['values'], 'child_id' => $args['child_id'], 'default' => $args['defaults'], 'class' => 'trigger-filter-value');
$key_input = self::build_input($key_args);
$compare_input = self::build_input($compare_args);
$value_input = self::build_input($value_args);
$header_name = str_replace('_', ' ', $args['trigger_filter_id']);
$header_name = ucfirst(strtolower($header_name));
$html = "<div class='filter-container'>";
$html .= "<div><table class='table-filter' data-child-id='" . $args['child_id'] . "'>";
$html .= " <tr class='tr-filter'>";
$html .= " <td class='td-filter-key'>";
$html .= " <input type='hidden' name='trigger_filter_id[" . $args['child_id'] . "]' value='" . $args['trigger_filter_id'] . "'>";
$html .= $key_input;
$html .= " </td>";
$html .= " <td class='td-filter-compare'>";
$html .= $compare_input;
$html .= " </td>";
$html .= " <td class='td-filter-value'>";
$html .= $value_input;
$html .= " </td>";
$html .= " <td class='td-filter-delete'>";
$html .= ' <span class="btn btn-default btn-mini delete-filter" title="' . __('Delete Trigger Filter', 'inbound-pro') . '" id="bigtest"><i class="fa fa-times"></i></span>';
$html .= " </td>";
$html .= " </tr>";
$html .= "</table>";
$html .= "</div></div>";
if (defined('DOING_AJAX') && DOING_AJAX) {
echo $html;
die();
} else {
return $html;
}
}
public static function ajax_build_db_lookup_filter($args) {
$args = ( !is_array($args) || !$args ) ? array() : $args;
self::load_definitions();
$args['action_filter_id'] = (isset($args['action_filter_id'])) ? $args['action_filter_id'] : sanitize_text_field($_REQUEST['action_filter_id']);
$args['action_block_id'] = (isset($args['action_block_id'])) ? $args['action_block_id'] : intval($_REQUEST['action_block_id']);
$args['child_id'] = (isset($args['child_id'])) ? $args['child_id'] : sanitize_text_field($_REQUEST['child_id']);
$args['defaults'] = (isset($args['defaults'])) ? $args['defaults'] : sanitize_text_field($_REQUEST['defaults']);
$this_filter = $args['action_filter_id'];
if ($this_filter == '-1' && defined('DOING_AJAX') && DOING_AJAX) {
die();
} else if ($this_filter == '-1') {
return '';
}
$key_args = array('name' => 'action_filter_key', 'type' => self::$db_lookup_filters[$this_filter]['key_input_type'], 'options' => self::$db_lookup_filters[$this_filter]['keys'], 'action_block_id' => $args['action_block_id'], 'child_id' => $args['child_id'], 'default' => $args['defaults'], 'class' => 'action-filter-key');
$compare_args = array('name' => 'action_filter_compare', 'type' => 'dropdown', 'options' => self::$db_lookup_filters[$this_filter]['compare'], 'action_block_id' => $args['action_block_id'], 'child_id' => $args['child_id'], 'default' => $args['defaults'], 'class' => 'action-filter-compare');
$value_args = array('name' => 'action_filter_value', 'type' => self::$db_lookup_filters[$this_filter]['value_input_type'], 'options' => self::$db_lookup_filters[$this_filter]['values'], 'action_block_id' => $args['action_block_id'], 'child_id' => $args['child_id'], 'default' => $args['defaults'], 'class' => 'action-filter-value');
$key_input = self::build_input($key_args);
$compare_input = self::build_input($compare_args);
$value_input = self::build_input($value_args);
$header_name = str_replace('_', ' ', $this_filter);
$header_name = ucfirst(strtolower($header_name));
$html = "<div class='filter-container'>";
$html .= '<table class="table-filter" data-child-id="' . $args['child_id'] . '">';
$html .= " <tr class='tr-filter'>";
$html .= " <td class='td-filter-type'>";
$html .= " <input type='hidden' name='action_filter_id" . (isset($args['action_block_id']) && $args['action_block_id'] ? '[' . $args['action_block_id'] . ']' : '') . "[" . $args['child_id'] . "]' value='" . $this_filter . "'>";
$html .= $header_name . ':';
$html .= " </td>";
$html .= " <td class='td-filter-key'>";
$html .= $key_input;
$html .= " </td>";
$html .= " <td class='td-filter-compare'>";
$html .= $compare_input;
$html .= " </td>";
$html .= " <td class='td-filter-value'>";
$html .= $value_input;
$html .= " </td>";
$html .= " <td class='td-filter-delete'>";
$html .= ' <div class="action-filter-delete">';
$html .= ' <span class="delete-filter" title="' . __('Delete Action Filter', 'inbound-pro') . '" data-block-id="' . $args['action_block_id'] . '" data-child-id="' . $args['child_id'] . '">';
$html .= ' <i class="fa fa-times"></i>';
$html .= ' </span>';
$html .= ' </div>';
$html .= " </td>";
$html .= " </tr>";
$html .= "</table>";
$html .= "</div>";
if (defined('DOING_AJAX') && DOING_AJAX) {
echo $html;
die();
} else {
return $html;
}
}
public static function ajax_build_action($args) {
$args = ( !is_array($args) || !$args ) ? array() : $args;
self::load_definitions();
$args['action_name'] = (isset($args['action_name'])) ? $args['action_name'] : sanitize_text_field($_REQUEST['action_name']);
$args['action_type'] = (isset($args['action_type'])) ? $args['action_type'] : sanitize_text_field($_REQUEST['action_type']);
$args['action_block_id'] = (isset($args['action_block_id'])) ? $args['action_block_id'] : intval($_REQUEST['action_block_id']);
$args['child_id'] = (isset($args['child_id'])) ? $args['child_id'] : sanitize_text_field($_REQUEST['child_id']);
$args['defaults'] = (isset($args['defaults'])) ? $args['defaults'] : sanitize_text_field($_REQUEST['defaults']);
$this_action = $args['action_name'];
if ($this_action == '-1' && defined('DOING_AJAX') && DOING_AJAX) {
die();
} else if ($this_action == '-1') {
return '';
}
$header_name = str_replace('_', ' ', $this_action);
$header_name = ucfirst(strtolower($header_name));
$html = "<div class='action-sub-wrapper' data-action-type='" . $args['action_type'] . "' data-block-id='" . $args['action_block_id'] . "' data-child-id='" . $args['child_id'] . "'>";
$html .= "<h4>";
$html .= $header_name;
$html .= '<i class="fa fa-info-circle inbound_tooltip" data-toggle="tooltip" data-placement="right" title="'. self::$actions[$this_action]['description'].'"></i>';
$html .= ' <div class="action-buttons">';
$html .= ' <span class="up-action-order" title=" ' . __('Move up', 'inbound-pro') . '" data-block-id="' . $args['action_block_id'] . '" data-child-id="' . $args['child_id'] . '" data-action-type="'.$args['action_type'].'"><i class="fa fa-arrow-up"></i> </span>';
$html .= ' <span class="down-action-order" title=" ' . __('Move down', 'inbound-pro') . '" data-block-id="' . $args['action_block_id'] . '" data-child-id="' . $args['child_id'] . '" data-action-type="'.$args['action_type'].'"><i class="fa fa-arrow-down"></i> </span>';
$html .= ' <span class="delete-action" title=" ' . __('Delete Action Block', 'inbound-pro') . '" data-block-id="' . $args['action_block_id'] . '" data-child-id="' . $args['child_id'] . '" data-action-type="'.$args['action_type'].'"><i class="fa fa-times"></i> </span>';
$html .= ' </div>';
$html .= '</h4>';
$html .= '<div class="action-container">';
$html .= " <table class='table-action' data-child-id='" . $args['child_id'] . "'>";
$html .= " <tr class='tr-action'>";
$html .= " <td class='td-action-setting-label' colspan=2>";
$html .= " <input type='hidden' name='action_name[" . $args['action_block_id'] . "][" . $args['action_type'] . "][" . $args['child_id'] . "]' value='" . $this_action . "' data-id='action_name'>";
$html .= " </td>";
$html .= " </tr>";
foreach (self::$actions[$this_action]['settings'] as $setting) {
$setting['description'] = (isset($setting['description'])) ? $setting['description'] : '';
$setting_args = array('name' => $setting['id'], 'action_name' => $args['action_name'], 'action_type' => $args['action_type'], 'action_block_id' => $args['action_block_id'], 'type' => $setting['type'], 'child_id' => $args['child_id'], 'class' => $setting['id']);
if (isset($args['defaults'][$setting['id']])) {
$setting_args['default'][$setting['id']] = $args['defaults'][$setting['id']];
} else if (isset($setting['default'])) {
$setting_args['default'][$setting['id']] = $setting['default'];
}
(isset($setting['options']) && is_array($setting['options'])) ? $setting_args['options'] = $setting['options'] : $settings_args['options'] = null;
$setting_html = ( $setting_args['type'] == 'html' ) ? $setting['default'] : self::build_input($setting_args);
if ( $setting['type'] == 'html' ) {
}
$class = '';
if (isset($setting['hidden']) && $setting['hidden']) {
$class = 'hide-field';
}
$extras = '';
if (isset($setting['reveal']) && is_array($setting['reveal'])) {
$extras = ' data-reveal-selector="' . $setting['reveal']['selector'] . '" data-reveal-value="' . $setting['reveal']['value'] . '" ';
}
$html .= " <tr class='tr-action-child {$class}' " . $extras . " >";
$html .= " <td class='td-action-setting-label'>";
$html .= " " . $setting['label'];
$html .= " </td>";
$html .= " <td class='td-action-setting-value'>";
$html .= " " . $setting_html . '<i class="fa fa-info-circle inbound_tooltip" data-toggle="tooltip" data-placement="right" title="'. $setting['description'].'"></i>';
$html .= " </td>";
$html .= " </tr>";
}
$html .= "</table>";
$html .= "</div></div>";
if (defined('DOING_AJAX') && DOING_AJAX) {
echo $html;
die();
} else {
return $html;
}
}
public static function ajax_load_trigger_arguments() {
$target_trigger = sanitize_text_field($_REQUEST['trigger']);
self::load_definitions();
$filter_whitelist = array();
if (!isset(self::$triggers[$target_trigger]['arguments'])) {
echo json_encode(array(array('id' => '0', 'label' => 'Error: No Filters for Selected Trigger')));
exit;
}
foreach (self::$triggers[$target_trigger]['arguments'] as $filter) {
$filter_whitelist[] = array('id' => $filter['id'], 'label' => $filter['label']);
}
echo json_encode($filter_whitelist);
die();
}
public static function ajax_load_db_lookup_filters() {
if (!isset($_REQUEST['trigger'])) {
exit;
}
self::load_definitions();
$target_trigger = sanitize_text_field($_REQUEST['trigger']);
$filter_whitelist = array();
if (!isset(self::$triggers[$target_trigger]['db_lookup_filters'])) {
echo json_encode(array(array('id' => '0', 'label' => 'Error: No Filters for Selected Trigger')));
exit;
}
foreach (self::$triggers[$target_trigger]['db_lookup_filters'] as $filter) {
$filter_whitelist[] = array('id' => $filter['id'], 'label' => $filter['label']);
}
echo json_encode($filter_whitelist);
die();
}
public static function ajax_load_action_definitions() {
self::load_definitions();
$target_trigger = sanitize_text_field($_REQUEST['trigger']);
$action_whitelist = array();
if (!isset(self::$triggers[$target_trigger]['actions'])) {
echo json_encode(array(array('id' => '0', 'label' => 'Error: No Filters for Selected Trigger')));
exit;
}
foreach (self::$actions as $action) {
if (in_array($action['id'], self::$triggers[$target_trigger]['actions'])) {
$action_whitelist[] = array('id' => $action['id'], 'label' => $action['label']);
}
}
echo json_encode($action_whitelist);
die();
}
public static function ajax_clear_logs() {
update_post_meta( intval($_REQUEST['rule_id']) , '_automation_logs' , null );
echo 'cleared';
exit;
}
public static function build_input($args) {
$html = '';
$block_id = (isset($args['action_block_id'])) ? $args['action_block_id'] : '';
$child_id = (isset($args['child_id'])) ? $args['child_id'] : '';
$action_type = (isset($args['action_type'])) ? $args['action_type'] : '';
$name = $args['name'] . ($block_id ? '[' . $block_id . ']' : '') . ($action_type ? '[' . $action_type . ']' : '') . '[' . $args['child_id'] . ']';
$default = (isset($args['default'][$args['name']])) ? $args['default'][$args['name']] : '';
switch ($args['type']) {
case 'dropdown' :
$html .= '<select name="' . $name . '" class="' . $args['class'] . '" data-block-id="' . $block_id . '" data-child-id="' . $child_id . '" data-id="' . $args['name'] . '">';
foreach ($args['options'] as $id => $label) {
$label = (strlen($label) > 200) ? substr($label,0,200).'...' : $label;
$html .= '<option value="' . $id . '" ' . ($default == $id ? 'selected="selected"' : '') . '>' . $label . '</option>';
}
$html .= '</select>';
break;
case 'select2' :
if (!$default) {
$default = array();
}
$html .= '<select name="' . $name . '[]" class="' . $args['class'] . ' select2" data-block-id="' . $block_id . '" data-child-id="' . $child_id . '" data-id="' . $args['name'] . '" multiple>';
foreach ($args['options'] as $id => $label) {
$html .= '<option value="' . $id . '" ' . (in_array($id, $default) ? 'selected="selected"' : '') . '>' . $label . '</option>';
}
$html .= '</select>';
break;
case 'text':
$html .= '<input type="text" name="' . $name . '" value="' . str_replace('"' , '"' , $default) . '" data-block-id="' . $block_id . '" data-child-id="' . $child_id . '" data-id="' . $args['name'] . '">';
break;
case 'html':
$html .= $args['options'];
break;
case 'checkbox':
$html .= '<table >';
foreach ($args['options'] as $id => $label) {
$html .= '<tr>';
$html .= '<td data-field-type="checkbox">';
$html .= '<input type="checkbox" name="' . $name . '[]" class="' . $args['class'] . '" data-id="' . $args['name'] . '" value="' . $id . '" ' . (isset($args['default'][$args['name']]) && in_array($id, $args['default'][$args['name']]) ? 'checked="checked"' : '') . '>';
$html .= '<label for="' . $id . '"> ' . $label . '</label>';
$html .= '</td>';
$html .= "</tr>";
}
$html .= "</table>";
break;
}
return $html;
}
public static function screen_layout_columns( $columns ) {
return true;
}
}
function inbound_automation_metaboxes() {
new Inbound_Metaboxes_Automation;
}
add_action('plugins_loaded', 'inbound_automation_metaboxes', 21);