dd
Showing
1 changed file
with
558 additions
and
0 deletions
| ... | @@ -527,3 +527,561 @@ function create_notification() | ... | @@ -527,3 +527,561 @@ function create_notification() |
| 527 | } | 527 | } |
| 528 | } | 528 | } |
| 529 | } | 529 | } |
| 530 | <?php | ||
| 531 | namespace Tz\WordPress\Tools\Notifications\Settings; | ||
| 532 | |||
| 533 | use Tz\Common; | ||
| 534 | use Tz\WordPress\Tools; | ||
| 535 | use Tz\WordPress\Tools\Notifications; | ||
| 536 | |||
| 537 | const CAPABILITY = 'manage_notifications'; | ||
| 538 | const MANAGE_SYSTEM_NOTIFICATIONS = 'create_system_notifications'; | ||
| 539 | const SETTING_NS = 'canspam_settings'; | ||
| 540 | const ADMIN_PAGE = 'canspam_admin'; | ||
| 541 | |||
| 542 | call_user_func( | ||
| 543 | function () { | ||
| 544 | $role = get_role('administrator'); | ||
| 545 | $role->add_cap(CAPABILITY); | ||
| 546 | $role->add_cap(MANAGE_SYSTEM_NOTIFICATIONS); | ||
| 547 | |||
| 548 | Vars::$settings = new Tools\WP_Option(SETTING_NS); | ||
| 549 | |||
| 550 | Tools\add_actions(__NAMESPACE__.'\Actions'); | ||
| 551 | } | ||
| 552 | ); | ||
| 553 | |||
| 554 | function display_page() | ||
| 555 | { | ||
| 556 | if (isset($_GET['action']) && $_GET['action'] == "edit") { | ||
| 557 | /** @var \StdClass $entry */ | ||
| 558 | $entry = get_post($_GET['page_id']); | ||
| 559 | |||
| 560 | $id = $entry->ID; | ||
| 561 | |||
| 562 | $details = get_post_meta($id, 'details', true); | ||
| 563 | $email = get_post_meta($id, 'email', true); | ||
| 564 | $system = get_post_meta($id, 'system', true); | ||
| 565 | $push = get_post_meta($id, 'push', true); | ||
| 566 | |||
| 567 | $entry->details = $details; | ||
| 568 | $entry->email = $email; | ||
| 569 | $entry->system = $system; | ||
| 570 | $entry->push = $push; | ||
| 571 | |||
| 572 | $validation = new Notifications\Validation; | ||
| 573 | |||
| 574 | $validation->set_rules('type', 'Notification Type', 'required'); | ||
| 575 | $validation->set_rules('title', 'Description', 'trim|required|min_length[4]'); | ||
| 576 | $validation->set_rules('sendto', 'Send To', 'required'); | ||
| 577 | |||
| 578 | $type_val = ($_POST && $_POST['type'] == 'scheduled') ? 'required' : ''; | ||
| 579 | $validation->set_rules('execute_date', 'Execute Date', $type_val); | ||
| 580 | |||
| 581 | $trigger_val = ($_POST && $_POST['type'] == 'triggered') ? 'required' : ''; | ||
| 582 | $validation->set_rules('trigger', 'Trigger', $trigger_val); | ||
| 583 | |||
| 584 | $validation->set_rules('system_message_type', 'System Message Type', 'trim'); | ||
| 585 | |||
| 586 | foreach (['en', 'fr'] as $lang) { | ||
| 587 | $validation->set_rules($lang.'_subject', 'Subject', 'trim'); | ||
| 588 | $validation->set_rules($lang.'_text', 'Text Version', 'trim|min_length[16]'); | ||
| 589 | $validation->set_rules($lang.'_html', 'HTML Version', 'trim|min_length[16]'); | ||
| 590 | $validation->set_rules($lang.'_system', 'System Message', 'trim|min_length[16]'); | ||
| 591 | } | ||
| 592 | |||
| 593 | //details | ||
| 594 | if ($validation->run() == true) { | ||
| 595 | |||
| 596 | // Clean up data before saving | ||
| 597 | Tools\tzClean($_POST); | ||
| 598 | |||
| 599 | $type = $_POST['type']; | ||
| 600 | $title = $_POST['title']; | ||
| 601 | $sendto = $_POST['sendto']; | ||
| 602 | $executeDate = ($type == 'scheduled' || $type == 'newsletter' ) ? $_POST['execute_date'] : '0000-00-00 00:00:00'; | ||
| 603 | $trigger = ($type == 'scheduled' || $type == 'newsletter' ) ? 'scheduled-cron-job' : $_POST['trigger']; | ||
| 604 | $style = $_POST['email_style']; | ||
| 605 | $emailData = []; | ||
| 606 | $systemMessageData = []; | ||
| 607 | $pushMessageData = []; | ||
| 608 | |||
| 609 | foreach (['en', 'fr'] as $lang) { | ||
| 610 | |||
| 611 | $subject = $_POST[$lang.'_subject']; | ||
| 612 | $text = $_POST[$lang.'_text']; | ||
| 613 | $html = $_POST[$lang.'_html']; | ||
| 614 | $attachments = []; | ||
| 615 | $upload_dir = wp_upload_dir(); | ||
| 616 | $uploadDir = $upload_dir['basedir'].'/notifications/'; | ||
| 617 | |||
| 618 | fixFilesArray($_FILES[$lang.'_attachment']); | ||
| 619 | |||
| 620 | foreach ($_FILES[$lang.'_attachment'] as $position => $file) { | ||
| 621 | // should output array with indices name, type, tmp_name, error, size | ||
| 622 | if ($file['name'] != '') { | ||
| 623 | move_uploaded_file($file['tmp_name'], $uploadDir.$file['name']); | ||
| 624 | $attachments[] = $file['name']; | ||
| 625 | } | ||
| 626 | } | ||
| 627 | |||
| 628 | // system | ||
| 629 | $systemMessageType = $_POST['system_message_type']; | ||
| 630 | $system = $_POST[$lang.'_system']; | ||
| 631 | |||
| 632 | $pushMessageTime = $_POST[$lang.'_push_notifications_time']; | ||
| 633 | $title = $_POST[$lang.'_push_notifications_title']; | ||
| 634 | $message = $_POST[$lang.'_push_notifications_message']; | ||
| 635 | $link = $_POST[$lang.'_push_notifications_link']; | ||
| 636 | $status = $_POST[$lang.'_push_notifications_status']; | ||
| 637 | |||
| 638 | |||
| 639 | if (count($entry->email[$lang.'_attachments']) > 0) { | ||
| 640 | $attachments = array_merge($entry->email[$lang.'_attachments'], $attachments); | ||
| 641 | } | ||
| 642 | |||
| 643 | $emailData = array_merge( | ||
| 644 | $emailData, | ||
| 645 | [ | ||
| 646 | $lang.'_subject' => $subject, | ||
| 647 | $lang.'_text' => $text, | ||
| 648 | $lang.'_html' => $html, | ||
| 649 | $lang.'_attachments' => $attachments | ||
| 650 | ] | ||
| 651 | ); | ||
| 652 | $systemMessageData = array_merge( | ||
| 653 | $systemMessageData, | ||
| 654 | [ | ||
| 655 | 'system_message_type' => $systemMessageType, | ||
| 656 | $lang.'_message' => $system | ||
| 657 | ] | ||
| 658 | ); | ||
| 659 | $pushMessageData = array_merge( | ||
| 660 | $pushMessageData, | ||
| 661 | [ | ||
| 662 | 'push_message_time' => $pushMessageTime, | ||
| 663 | $lang.'_title' => $title, | ||
| 664 | $lang.'_message' => $message, | ||
| 665 | $lang.'_link' => $link, | ||
| 666 | $lang.'_status' => $status | ||
| 667 | ] | ||
| 668 | ); | ||
| 669 | } | ||
| 670 | |||
| 671 | update_post_meta( | ||
| 672 | $id, | ||
| 673 | 'details', | ||
| 674 | [ | ||
| 675 | 'type' => $type, | ||
| 676 | 'sendto' => $sendto, | ||
| 677 | 'status' => $entry->details['status'], | ||
| 678 | 'trigger' => $trigger, | ||
| 679 | 'execute_date' => $executeDate | ||
| 680 | |||
| 681 | |||
| 682 | ] | ||
| 683 | ); | ||
| 684 | update_post_meta($id, 'send_status', $entry->details['status']); | ||
| 685 | update_post_meta($id, 'notif_type', $type); | ||
| 686 | // update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($executeDate)); | ||
| 687 | update_post_meta($id, 'execute_date', strtotime($executeDate)); | ||
| 688 | update_post_meta($id, 'trigger', $trigger); | ||
| 689 | |||
| 690 | update_post_meta($id, 'email', $emailData); | ||
| 691 | update_post_meta($id, 'system', $systemMessageData); | ||
| 692 | update_post_meta($id, 'style', $style); | ||
| 693 | update_post_meta($id, 'push', $pushMessageData); | ||
| 694 | |||
| 695 | $update = []; | ||
| 696 | $update['ID'] = $id; | ||
| 697 | $update['post_title'] = $title; | ||
| 698 | wp_update_post($update); | ||
| 699 | |||
| 700 | $id = $entry->ID; | ||
| 701 | |||
| 702 | $details = get_post_meta($id, 'details', true); | ||
| 703 | $email = get_post_meta($id, 'email', true); | ||
| 704 | $system = get_post_meta($id, 'system', true); | ||
| 705 | $push = get_post_meta($id, 'push', true); | ||
| 706 | |||
| 707 | $entry->details = $details; | ||
| 708 | $entry->email = $email; | ||
| 709 | $entry->system = $system; | ||
| 710 | $entry->push = $push; | ||
| 711 | |||
| 712 | $flash = '<strong>Notification Saved Successfully!</strong><br /><a href=""/wp-admin/admin.php?page=notifications">Click here</a> to view all notifications.</a>'; | ||
| 713 | require_once(__DIR__.'/views/form.php'); | ||
| 714 | } else { | ||
| 715 | require_once(__DIR__.'/views/form.php'); | ||
| 716 | } | ||
| 717 | } else { | ||
| 718 | if (isset($_GET['action']) && $_GET['action'] == 'delete') { | ||
| 719 | wp_delete_post($_GET['page_id'], true); | ||
| 720 | } elseif (isset($_GET['action']) && $_GET['action'] == 'archive') { | ||
| 721 | $id = $_GET['page_id']; | ||
| 722 | |||
| 723 | $postdata = get_post_meta($id, 'details', true); | ||
| 724 | $postdata['status'] = "archived"; | ||
| 725 | |||
| 726 | update_post_meta($id, 'details', $postdata); | ||
| 727 | update_post_meta($id, 'send_status', $postdata['status']); | ||
| 728 | } | ||
| 729 | |||
| 730 | // get all the notifications that status != "archived"; | ||
| 731 | $notifications = []; | ||
| 732 | $notifications['triggered'] = []; | ||
| 733 | $notifications['scheduled'] = []; | ||
| 734 | |||
| 735 | $args = [ | ||
| 736 | 'post_type' => 'notifications', | ||
| 737 | 'numberposts' => -1, | ||
| 738 | 'orderby' => 'modified', | ||
| 739 | 'order' => 'desc', | ||
| 740 | 'meta_key' => 'send_status', | ||
| 741 | 'meta_compare' => '=', | ||
| 742 | 'meta_value' => 'pending' | ||
| 743 | ]; | ||
| 744 | |||
| 745 | $entries = get_posts($args); | ||
| 746 | |||
| 747 | foreach ($entries as $entry) { | ||
| 748 | $id = $entry->ID; | ||
| 749 | |||
| 750 | $details = get_post_meta($id, 'details', true); | ||
| 751 | $email = get_post_meta($id, 'email', true); | ||
| 752 | $system = get_post_meta($id, 'system', true); | ||
| 753 | $push = get_post_meta($id, 'push', true); | ||
| 754 | |||
| 755 | $entry->trigger = $details['trigger']; | ||
| 756 | $entry->status = isset($details['status']) ? $details['status'] : 'active'; | ||
| 757 | $entry->type = $details['type']; | ||
| 758 | $entry->sendto = $details['sendto']; | ||
| 759 | |||
| 760 | $entry->is_email = (($email['en_text'] != '' || $email['en_html'] != '')) || (($email['fr_text'] != '' || $email['fr_html'] != '')) ? true : false; | ||
| 761 | $entry->is_system = (isset($system['en_message']) && $system['en_message'] != '') || (isset($system['fr_message']) && $system['fr_message'] != '') ? true : false; | ||
| 762 | $entry->push = (isset($push['en_message']) && $push['en_title'] != '') || (isset($push['fr_message']) && $push['en_title'] != '') ? true : false; | ||
| 763 | $entry->execute_date = $details['execute_date']; | ||
| 764 | |||
| 765 | if ($entry->status != 'archived') { | ||
| 766 | $notifications[$entry->type][] = $entry; | ||
| 767 | } | ||
| 768 | } | ||
| 769 | |||
| 770 | require_once(__DIR__.'/views/admin.php'); | ||
| 771 | } | ||
| 772 | } | ||
| 773 | |||
| 774 | /** | ||
| 775 | * @param string $datetime | ||
| 776 | * | ||
| 777 | * @return int | ||
| 778 | */ | ||
| 779 | function mysqldatetime_to_timestamp($datetime = '') | ||
| 780 | { | ||
| 781 | // function is only applicable for valid MySQL DATETIME (19 characters) and DATE (10 characters) | ||
| 782 | $l = strlen($datetime); | ||
| 783 | if (!($l == 10 || $l == 19)) { | ||
| 784 | return 0; | ||
| 785 | } | ||
| 786 | |||
| 787 | // | ||
| 788 | $date = $datetime; | ||
| 789 | $hours = 0; | ||
| 790 | $minutes = 0; | ||
| 791 | $seconds = 0; | ||
| 792 | |||
| 793 | // DATETIME only | ||
| 794 | if ($l == 19) { | ||
| 795 | list($date, $time) = explode(" ", $datetime); | ||
| 796 | list($hours, $minutes, $seconds) = explode(":", $time); | ||
| 797 | } | ||
| 798 | |||
| 799 | list($year, $month, $day) = explode("-", $date); | ||
| 800 | |||
| 801 | return mktime($hours, $minutes, $seconds, $month, $day, $year); | ||
| 802 | } | ||
| 803 | |||
| 804 | /** | ||
| 805 | * @param $files | ||
| 806 | */ | ||
| 807 | function fixFilesArray(&$files) | ||
| 808 | { | ||
| 809 | $names = ['name' => 1, 'type' => 1, 'tmp_name' => 1, 'error' => 1, 'size' => 1]; | ||
| 810 | |||
| 811 | foreach ($files as $key => $part) { | ||
| 812 | // only deal with valid keys and multiple files | ||
| 813 | $key = (string)$key; | ||
| 814 | if (isset($names[$key]) && is_array($part)) { | ||
| 815 | foreach ($part as $position => $value) { | ||
| 816 | $files[$position][$key] = $value; | ||
| 817 | } | ||
| 818 | // remove old key reference | ||
| 819 | unset($files[$key]); | ||
| 820 | } | ||
| 821 | } | ||
| 822 | } | ||
| 823 | |||
| 824 | function notification_settings() | ||
| 825 | { | ||
| 826 | |||
| 827 | require_once(__DIR__.'/views/settings.php'); | ||
| 828 | } | ||
| 829 | |||
| 830 | function create_notification() | ||
| 831 | { | ||
| 832 | $validation = new Notifications\Validation; | ||
| 833 | |||
| 834 | $validation->set_rules('type', 'Notification Type', 'required'); | ||
| 835 | $validation->set_rules('title', 'Description', 'trim|required|min_length[4]'); | ||
| 836 | $validation->set_rules('sendto', 'Send To', 'required'); | ||
| 837 | |||
| 838 | $type_val = ($_POST && $_POST['type'] == 'scheduled') ? 'required' : ''; | ||
| 839 | $validation->set_rules('execute_date', 'Execute Date', $type_val); | ||
| 840 | |||
| 841 | $trigger_val = ($_POST && $_POST['type'] == 'triggered') ? 'required' : ''; | ||
| 842 | $validation->set_rules('trigger', 'Trigger', $trigger_val); | ||
| 843 | |||
| 844 | $validation->set_rules('system_message_type', 'System Message Type', 'trim'); | ||
| 845 | |||
| 846 | foreach (['en', 'fr'] as $lang) { | ||
| 847 | $validation->set_rules($lang.'_subject', 'Subject', 'trim'); | ||
| 848 | // $validation->set_rules($lang.'_text', 'Text Version', 'trim|min_length[16]'); | ||
| 849 | // $validation->set_rules($lang.'_html', 'HTML Version', 'trim|min_length[16]'); | ||
| 850 | $validation->set_rules($lang.'_text', 'Text Version', 'trim'); | ||
| 851 | $validation->set_rules($lang.'_html', 'HTML Version', 'trim'); | ||
| 852 | $validation->set_rules($lang.'_system', 'System Message', 'trim|min_length[16]'); | ||
| 853 | } | ||
| 854 | |||
| 855 | if ($_POST && ($_POST['en_subject'] == '' && $_POST['fr_subject'] == '' && $_POST['en_system'] == '' && $_POST['fr_system'] == '')) { | ||
| 856 | $form_error = true; | ||
| 857 | require_once(__DIR__.'/views/create.php'); | ||
| 858 | } else { | ||
| 859 | if ($validation->run() == true) { | ||
| 860 | |||
| 861 | // Clean up the data before saving | ||
| 862 | Tools\tzClean($_POST); | ||
| 863 | |||
| 864 | // ok, so now we need to create the notification. | ||
| 865 | class PostTemplate | ||
| 866 | { | ||
| 867 | var $post_title = ''; | ||
| 868 | var $post_content = ''; | ||
| 869 | var $post_status = 'publish'; | ||
| 870 | var $post_type = 'notifications'; | ||
| 871 | var $comment_status = 'closed'; | ||
| 872 | } | ||
| 873 | |||
| 874 | // details | ||
| 875 | $type = $_POST['type']; | ||
| 876 | $title = $_POST['title']; | ||
| 877 | $sendto = $_POST['sendto']; | ||
| 878 | $executeDate = ($type == 'scheduled' || $type == 'newsletter') ? $_POST['execute_date'] : '0000-00-00 00:00:00'; | ||
| 879 | $trigger = ($type == 'scheduled' || $type == 'newsletter') ? 'scheduled-cron-job' : $_POST['trigger']; | ||
| 880 | $style = $_POST['email_style']; | ||
| 881 | $emailData = []; | ||
| 882 | $systemMessageData = []; | ||
| 883 | $pushMessageData = []; | ||
| 884 | |||
| 885 | |||
| 886 | |||
| 887 | |||
| 888 | |||
| 889 | |||
| 890 | |||
| 891 | |||
| 892 | foreach (['en', 'fr'] as $lang) { | ||
| 893 | |||
| 894 | $subject = $_POST[$lang.'_subject']; | ||
| 895 | $text = $_POST[$lang.'_text']; | ||
| 896 | $html = strip_word_html($_POST[$lang.'_html']); | ||
| 897 | $attachments = []; | ||
| 898 | $uploadDir = wp_upload_dir()['basedir'].'/notifications/'; | ||
| 899 | |||
| 900 | fixFilesArray($_FILES[$lang.'_attachment']); | ||
| 901 | |||
| 902 | foreach ($_FILES[$lang.'_attachment'] as $position => $file) { | ||
| 903 | // should output array with indices name, type, tmp_name, error, size | ||
| 904 | if ($file['name'] != '') { | ||
| 905 | move_uploaded_file($file['tmp_name'], $uploadDir.$file['name']); | ||
| 906 | $attachments[] = $file['name']; | ||
| 907 | } | ||
| 908 | } | ||
| 909 | |||
| 910 | if($style == 'newsletter'){ | ||
| 911 | $newletter_id = -1; | ||
| 912 | $author_id = 1; | ||
| 913 | $slug = strtolower($subject); | ||
| 914 | |||
| 915 | if( null == get_page_by_title( $title ) ) { | ||
| 916 | |||
| 917 | // Set the page ID so that we know the page was created successfully | ||
| 918 | $post_id = wp_insert_post( | ||
| 919 | array( | ||
| 920 | 'comment_status' => 'closed', | ||
| 921 | 'ping_status' => 'closed', | ||
| 922 | 'post_author' => '1', | ||
| 923 | 'post_name' => $slug, | ||
| 924 | 'post_title' => $subject, | ||
| 925 | 'post_status' => 'publish', | ||
| 926 | 'post_type' => 'newsLetter', | ||
| 927 | 'post_content' => '<div id="newsletter">'.$html.'</div>' , | ||
| 928 | |||
| 929 | ) | ||
| 930 | ); | ||
| 931 | |||
| 932 | if ($post_id) { | ||
| 933 | // https://wpml.org/wpml-hook/wpml_element_type/ | ||
| 934 | $wpml_element_type = apply_filters( 'wpml_element_type', 'newsletter' ); | ||
| 935 | |||
| 936 | // get the language info of the original post | ||
| 937 | // https://wpml.org/wpml-hook/wpml_element_language_details/ | ||
| 938 | $get_language_args = array('element_id' => $post_id, 'element_type' => 'post_product' ); | ||
| 939 | $original_post_language_info = apply_filters( 'wpml_element_language_details', null, $get_language_args ); | ||
| 940 | |||
| 941 | $set_language_args = array( | ||
| 942 | 'element_id' => $post_id, | ||
| 943 | 'element_type' => $wpml_element_type, | ||
| 944 | 'trid' => $original_post_language_info->trid, | ||
| 945 | 'language_code' => $lang, | ||
| 946 | 'source_language_code' => $original_post_language_info->language_code | ||
| 947 | ); | ||
| 948 | |||
| 949 | do_action( 'wpml_set_element_language_details', $set_language_args ); | ||
| 950 | } | ||
| 951 | |||
| 952 | } else { | ||
| 953 | |||
| 954 | $post_id = -2; | ||
| 955 | |||
| 956 | } | ||
| 957 | |||
| 958 | } | ||
| 959 | |||
| 960 | // system | ||
| 961 | $systemMessageType = $_POST['system_message_type']; | ||
| 962 | $system = $_POST[$lang.'_system']; | ||
| 963 | |||
| 964 | $pushMessageTime = $_POST[$lang.'_push_notifications_time']; | ||
| 965 | $title = $_POST[$lang.'_push_notifications_title']; | ||
| 966 | $message = $_POST[$lang.'_push_notifications_message']; | ||
| 967 | $link = $_POST[$lang.'_push_notifications_link']; | ||
| 968 | $status = $_POST[$lang.'_push_notifications_status']; | ||
| 969 | |||
| 970 | |||
| 971 | |||
| 972 | $emailData = array_merge( | ||
| 973 | $emailData, | ||
| 974 | [ | ||
| 975 | $lang.'_subject' => $subject, | ||
| 976 | $lang.'_text' => $text, | ||
| 977 | $lang.'_html' => $html, | ||
| 978 | $lang.'_attachments' => $attachments, | ||
| 979 | |||
| 980 | ] | ||
| 981 | ); | ||
| 982 | $systemMessageData = array_merge( | ||
| 983 | $systemMessageData, | ||
| 984 | [ | ||
| 985 | 'system_message_type' => $systemMessageType, | ||
| 986 | $lang.'_message' => $system | ||
| 987 | ] | ||
| 988 | ); | ||
| 989 | $pushMessageData = array_merge( | ||
| 990 | $pushMessageData, | ||
| 991 | [ | ||
| 992 | 'push_message_time' => $pushMessageTime, | ||
| 993 | $lang.'_title' => $title, | ||
| 994 | $lang.'_message' => $message, | ||
| 995 | $lang.'_link' => $link, | ||
| 996 | $lang.'_status' => $status | ||
| 997 | ] | ||
| 998 | ); | ||
| 999 | |||
| 1000 | |||
| 1001 | $links[$lang] = get_permalink($post_id); | ||
| 1002 | |||
| 1003 | } | ||
| 1004 | |||
| 1005 | |||
| 1006 | |||
| 1007 | // make post... | ||
| 1008 | $notification = new PostTemplate(); | ||
| 1009 | $notification->post_title = $title; | ||
| 1010 | $notification->post_content = 'Notification created '.date( | ||
| 1011 | 'Y-m-d H:i:s' | ||
| 1012 | )." --- to be sent on $executeDate"; | ||
| 1013 | $notification->post_date_gmt = date('Y-m-d H:i:s', time()); | ||
| 1014 | |||
| 1015 | $id = wp_insert_post((array)$notification); | ||
| 1016 | |||
| 1017 | if($style == 'newsletter'){ | ||
| 1018 | update_post_meta($id, 'links', $links); | ||
| 1019 | } | ||
| 1020 | |||
| 1021 | update_post_meta( | ||
| 1022 | $id, | ||
| 1023 | 'details', | ||
| 1024 | [ | ||
| 1025 | 'type' => $type, | ||
| 1026 | 'sendto' => $sendto, | ||
| 1027 | 'status' => 'pending', | ||
| 1028 | 'trigger' => $trigger, | ||
| 1029 | 'execute_date' => $executeDate | ||
| 1030 | |||
| 1031 | ] | ||
| 1032 | ); | ||
| 1033 | update_post_meta($id, 'send_status', 'pending'); | ||
| 1034 | update_post_meta($id, 'notif_type', $type); | ||
| 1035 | // update_post_meta($id, 'execute_date', mysqldatetime_to_timestamp($executeDate)); | ||
| 1036 | update_post_meta($id, 'execute_date', strtotime($executeDate)); | ||
| 1037 | |||
| 1038 | update_post_meta($id, 'trigger', $trigger); | ||
| 1039 | |||
| 1040 | |||
| 1041 | update_post_meta($id, 'email', $emailData); | ||
| 1042 | update_post_meta($id, 'style', $style); | ||
| 1043 | update_post_meta($id, 'system', $systemMessageData); | ||
| 1044 | update_post_meta($id, 'push', $pushMessageData); | ||
| 1045 | |||
| 1046 | $flash = "<strong>Notification Saved Successfully!</strong><br /><a href='/wp-admin/admin.php?page=notifications'>Click here</a> to view all notifications.</a>"; | ||
| 1047 | require_once(__DIR__.'/views/create.php'); | ||
| 1048 | |||
| 1049 | |||
| 1050 | |||
| 1051 | |||
| 1052 | |||
| 1053 | |||
| 1054 | } else { | ||
| 1055 | require_once(__DIR__.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'create.php'); | ||
| 1056 | } | ||
| 1057 | } | ||
| 1058 | } | ||
| 1059 | |||
| 1060 | |||
| 1061 | |||
| 1062 | function strip_word_html($text, $allowed_tags = '<b><i><sup><sub><em><strong><u><br>') | ||
| 1063 | { | ||
| 1064 | |||
| 1065 | |||
| 1066 | mb_regex_encoding('UTF-8'); | ||
| 1067 | //replace MS special characters first | ||
| 1068 | $search = array('/‘/u', '/’/u', '/“/u', '/”/u', '/—/u'); | ||
| 1069 | $replace = array('\'', '\'', '"', '"', '-'); | ||
| 1070 | $text = preg_replace($search, $replace, $text); | ||
| 1071 | //make sure _all_ html entities are converted to the plain ascii equivalents - it appears | ||
| 1072 | //in some MS headers, some html entities are encoded and some aren't | ||
| 1073 | $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8'); | ||
| 1074 | |||
| 1075 | //on some of the ?newer MS Word exports, where you get conditionals of the form 'if gte mso 9', etc., it appears | ||
| 1076 | //that whatever is in one of the html comments prevents strip_tags from eradicating the html comment that contains | ||
| 1077 | //some MS Style Definitions - this last bit gets rid of any leftover comments */ | ||
| 1078 | $num_matches = preg_match_all("/\<!--/u", $text, $matches); | ||
| 1079 | if($num_matches){ | ||
| 1080 | $text = preg_replace('/\<!--(.)*--\>/isu', '', $text); | ||
| 1081 | } | ||
| 1082 | |||
| 1083 | |||
| 1084 | $text = preg_replace('/(?:width\=\"\d*\")\S/mxi', '>', $text); | ||
| 1085 | |||
| 1086 | return $text; | ||
| 1087 | } | ... | ... |
-
Please register or sign in to post a comment