示例#1
0
function tdomf_notify_admins_edit($edit_id, $form_id)
{
    global $wpdb, $tdomf_form_widgets_adminemail;
    // grab email addresses
    $email_list = tdomf_get_admin_emails($form_id);
    if ($email_list == "") {
        tdomf_log_message("Could not get any email addresses to notify. No moderation notification email sent.", TDOMF_LOG_BAD);
        return false;
    }
    $edit = tdomf_get_edit($edit_id);
    // Submitter Info
    //
    $can_ban_user = false;
    $submitter_string = "N/A";
    if ($edit->user_id != 0) {
        $submitter_string = $edit->data["user_login"];
        $can_ban_user = true;
    } else {
        if (isset($edit->data[TDOMF_KEY_NAME])) {
            $submitter_string = $edit->data[TDOMF_KEY_NAME];
            if (isset($edit->data[TDOMF_KEY_EMAIL])) {
                $submitter_string .= " (" . $edit->data[TDOMF_KEY_EMAIL] . ")";
            }
        }
    }
    // Title and content of post
    //
    if ($edit->revision_id != 0) {
        $post = get_post($edit->revision_id);
    } else {
        $post = get_post($edit->post_id);
    }
    $content = $post->post_content;
    $title = $post->post_title;
    $status = $post->post_status;
    // Links
    //
    $moderate_edit_link = tdomf_get_mod_posts_url(array());
    $approve_edit_link = tdomf_get_mod_posts_url(array('action' => 'approve_edit', 'edit_id' => $edit_id, 'nonce' => 'tdomf-approve_edit_' . $edit_id));
    $delete_edit_link = tdomf_get_mod_posts_url(array('action' => 'delete_edit', 'edit_id' => $edit_id, 'nonce' => 'tdomf-approve_edit_' . $edit_id));
    $compare_edit_link = get_bloginfo('wpurl') . "/wp-admin/revision.php?action=diff&right=" . $edit->revision_id . "&left=" . $edit->current_revision_id;
    $spamit_edit_link = tdomf_get_mod_posts_url(array('action' => 'hamit_edit', 'edit_id' => $edit_id, 'nonce' => 'tdomf-hamit_edit_' . $edit_id));
    $hamit_edit_link = tdomf_get_mod_posts_url(array('action' => 'spamit_edit', 'edit_id' => $edit_id, 'nonce' => 'tdomf-hamit_edit_' . $edit_id));
    $view_edit_link = get_bloginfo('wpurl') . "/wp-admin/revision.php?revision=" . $edit->revision_id;
    $view_post_link = get_permalink($edit->post_id);
    $is_spam = $edit->state == 'spam' && get_option(TDOMF_OPTION_SPAM);
    if ($can_ban_user) {
        $ban_user_link = get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_manage_menu&action=ban&user={$edit->user_id}";
    }
    $ban_ip_link = get_bloginfo('wpurl') . "/wp-admin/admin.php?page=tdomf_show_manage_menu&mode=ip&action=ban&ip={$edit->ip}";
    // Subject line
    //
    if ($is_spam) {
        $subject = sprintf(__("[SPAM] [%s] Please moderate this spam edit (%d)", "tdomf"), get_bloginfo('title'), $edit_id);
    } else {
        if ($edit->state == 'approved') {
            $subject = sprintf(__("[%s] Edit (%d) on Post '%s' has been approved", "tdomf"), get_bloginfo('title'), $edit_id, $title);
        } else {
            $subject = sprintf(__("[%s] Please moderate this new edit (%d) from '%s'", "tdomf"), get_bloginfo('title'), $edit_id, $submitter_name);
        }
    }
    // Email Body
    //
    if ($edit->state == 'approved') {
        $email_msg = sprintf(__("Edit (%d) on Post \"%s\" from %s has been published.\n\n", "tdomf"), $edit_id, $title, $submitter_string);
    } else {
        $email_msg = sprintf(__("A new edit (%d) on post with title \"%s\" from %s is awaiting your approval.\n\n", "tdomf"), $edit_id, $title, $submitter_string);
    }
    if ($is_spam) {
        $email_msg = __("This edit is considered SPAM\n\n", "tdomf");
    }
    $email_msg .= sprintf(__("Form ID: %d (\"%s\")\n", "tdomf"), $edit->form_id, tdomf_get_option_form(TDOMF_OPTION_NAME, $edit->form_id));
    $email_msg .= sprintf(__("Submitter IP: %s.\n\n", "tdomf"), $edit->ip);
    $email_msg .= sprintf(__("View Post: %s\n", "tdomf"), $view_post_link);
    $email_msg .= sprintf(__("View Edit: %s\n", "tdomf"), $view_edit_link);
    if ($edit->revision_id != 0 && $edit->current_revision_id != 0) {
        $email_msg .= sprintf(__("Compare with previous: %s.\n", "tdomf"), $compare_edit_link);
    }
    if ($edit->state != 'approved') {
        $email_msg .= sprintf(__("Approve edit (will also flag edit as not SPAM): %s\n", "tdomf"), $approve_edit_link);
        if (!$is_spam && get_option(TDOMF_OPTION_SPAM)) {
            $email_msg .= sprintf(__("Flag Edit as SPAM: %s\n", "tdomf"), $spamit_edit_link);
        } else {
            if ($is_spam) {
                $email_msg .= sprintf(__("Flag Edit as not SPAM: %s\n", "tdomf"), $hamit_edit_link);
            }
        }
        $email_msg .= sprintf(__("Ban IP: %s\n", "tdomf"), $ban_ip_link);
        if ($can_ban_user) {
            $email_msg .= sprintf(__("Ban User: %s\n", "tdomf"), $ban_user_link);
        }
        $email_msg .= sprintf(__("Delete Edit: %s\n", "tdomf"), $delete_edit_link);
    }
    $email_msg .= sprintf(__("You can moderate all edits from %s\n", "tdomf"), $moderate_edit_link);
    if ($is_spam) {
        $email_msg .= sprintf(__("\nTitle of the post: %s", "tdomf"), $title);
    }
    $email_msg .= sprintf(__("\nContent of the post: \n\n %s \n\n", "tdomf"), $content);
    // Widgets:adminemail
    //
    $widget_args = array("before_widget" => "", "after_widget" => "\n\n", "before_title" => "", "after_title" => "\n\n", "tdomf_form_id" => $form_id, "edit_id" => $edit_id);
    if ($edit->revision_id != 0) {
        $widget_args["post_ID"] = $edit->revision_id;
        $widget_args["tdomf_post_id"] = $edit->revision_id;
    } else {
        $widget_args["post_ID"] = $edit->post_id;
        $widget_args["tdomf_post_id"] = $edit->post_id;
    }
    $widget_order = tdomf_get_widget_order($form_id);
    foreach ($widget_order as $w) {
        if (isset($tdomf_form_widgets_adminemail[$w])) {
            $temp_message = call_user_func($tdomf_form_widgets_adminemail[$w]['cb'], $widget_args, $tdomf_form_widgets_adminemail[$w]['params']);
            if ($temp_message != NULL && trim($temp_message) != "") {
                $email_msg .= $temp_message;
            }
        }
    }
    $email_msg .= sprintf(__("Best Regards\nTDOMF @ %s", "tdomf"), get_bloginfo("title"));
    // prepare body
    //
    $email_msg = str_replace("\n", "\r\n", $email_msg);
    // Use custom from field
    //
    if (tdomf_get_option_form(TDOMF_OPTION_FROM_EMAIL, $form_id)) {
        // We can modify the "from" field by using the "header" option at the end!
        //
        $headers = "MIME-Version: 1.0\n" . "From: " . tdomf_get_option_form(TDOMF_OPTION_FROM_EMAIL, $form_id) . "\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
        return @wp_mail($email_list, $subject, $email_msg, $headers);
    } else {
        return @wp_mail($email_list, $subject, $email_msg);
    }
}
示例#2
0
         } else {
             $left_edit = tdomf_get_edit($left);
             $left_revision = @get_post($left_edit->revision_id);
         }
     }
 }
 if ($right == 'current') {
     $right_revision = $post;
 } else {
     if ($right == 'first') {
         $right_revision = @get_post($first_edit->current_revision_id);
     } else {
         if ($right == 'previous') {
             $right_revision = @get_post($edit->current_revision_id);
         } else {
             $right_edit = tdomf_get_edit($right);
             $right_revision = @get_post($right_edit->revision_id);
         }
     }
 }
 $table_code = "";
 $identical = true;
 foreach ($fields as $field => $title) {
     if ($render == 'wp') {
         if ($content = wp_text_diff($left_revision->{$field}, $right_revision->{$field})) {
             $identical = false;
             $table_code .= "<tr id='revision-field-" . $field . "'>\n<th scope='row'>" . $title . "</th>\n<td><div class='pre'>\n" . $content . "\n</div></td></tr>";
         } else {
             $table_code .= "<tr id='revision-field-" . $field . "'>\n<th scope='row'>" . $title . "</th><td><div class='pre'>" . htmlentities($left_revision->{$field}) . "</div></td></tr>\n";
         }
     } else {
function tdomf_moderation_handler()
{
    $message .= "";
    # this means a post was deleted
    #
    if (isset($_REQUEST['deleted'])) {
        $message .= __("Submissions deleted. ", "tdomf");
    }
    // bulk actions
    if (isset($_REQUEST['doaction']) && isset($_REQUEST['action']) && isset($_REQUEST['post'])) {
        $posts = $_REQUEST['post'];
        $action = $_REQUEST['action'];
        if ($action != -1 && is_array($posts) && !empty($posts)) {
            check_admin_referer('tdomf-moderate-bulk');
            switch ($action) {
                case 'spam_recheck':
                    $spam_list = array();
                    $ham_list = array();
                    foreach ($posts as $post) {
                        if (tdomf_check_submissions_spam($post)) {
                            $ham_list[] = $post;
                        } else {
                            $spam_list[] = $post;
                        }
                    }
                    tdomf_log_message('Akismet thinks these submissions are spam: ' . implode(", ", $spam_list));
                    $message .= sprintf(__("Marked these submissions as spam: %s.", "tdomf"), implode(", ", $spam_list));
                    tdomf_log_message('Akismet thinks these posts are not spam: ' . implode(", ", $ham_list));
                    $message .= " ";
                    $message .= sprintf(__("Marked these submissions as not spam: %s.", "tdomf"), implode(", ", $ham_list));
                    break;
                case 'delete':
                    foreach ($posts as $p) {
                        wp_delete_post($p);
                    }
                    tdomf_log_message('Deleted ' . implode(", ", $posts) . ' posts');
                    $message .= sprintf(__("Deleted submissions: %s", "tdomf"), implode(", ", $posts));
                    break;
                case 'publish_now':
                    $list = "";
                    foreach ($posts as $p) {
                        if (!get_post_meta($p, TDOMF_KEY_SPAM)) {
                            // if we're going to publish the post, then it's not spam!
                            tdomf_ham_post($p);
                        }
                        tdomf_publish_post($p, false);
                        $list .= "<a href=\"" . get_permalink($p) . "\">" . $p . "</a>, ";
                    }
                    tdomf_log_message("Published {$list} posts");
                    $message .= sprintf(__("Attempted to published these submissions immediately: %s", "tdomf"), $list);
                    break;
                case 'publish':
                    $list = "";
                    foreach ($posts as $p) {
                        if (!get_post_meta($p, TDOMF_KEY_SPAM)) {
                            // if we're going to publish the post, then it's not spam!
                            tdomf_ham_post($p);
                        }
                        tdomf_publish_post($p);
                        $list .= "<a href=\"" . get_permalink($p) . "\">" . $p . "</a>, ";
                    }
                    tdomf_log_message("Published or queued {$list} posts");
                    $message .= sprintf(__("Attempted to publish or queue these submissions: %s", "tdomf"), $list);
                    break;
                case 'unpublish':
                    foreach ($posts as $p) {
                        tdomf_unpublish_post($p);
                    }
                    tdomf_log_message("Un-published " . implode(", ", $posts) . " posts");
                    $message .= sprintf(__("Attempted to un-publish theses submissions: %s", "tdomf"), implode(", ", $posts));
                    break;
                case 'spamit':
                    $spams = array();
                    foreach ($posts as $p) {
                        if (!get_post_meta($p, TDOMF_KEY_SPAM)) {
                            tdomf_spam_post($p);
                            $spams[] = $p;
                        }
                    }
                    tdomf_log_message("Marked as spam " . implode(", ", $spams) . " posts");
                    $message .= sprintf(__("Marked these submissions as spam: %s", "tdomf"), implode(", ", $spams));
                    break;
                case 'hamit':
                    $hams = array();
                    foreach ($posts as $p) {
                        if (get_post_meta($p, TDOMF_KEY_SPAM)) {
                            tdomf_spam_post($p);
                            $hams[] = $p;
                        }
                    }
                    if (!empty($hams)) {
                        tdomf_log_message("Marked as ham " . implode(", ", $hams) . " posts");
                        $message .= sprintf(__("Marked these submissions as not spam: %s", "tdomf"), implode(", ", $hams));
                    }
                    break;
                case 'lock':
                    $locks = array();
                    foreach ($posts as $p) {
                        if (!get_post_meta($p, TDOMF_KEY_LOCK)) {
                            add_post_meta($p, TDOMF_KEY_LOCK, true, true);
                            $locks[] = $p;
                        }
                    }
                    if (!empty($locks)) {
                        tdomf_log_message("Locked " . implode(", ", $locks) . " posts");
                        $message .= sprintf(__("Locked these posts/pages from editing: %s", "tdomf"), implode(", ", $locks));
                    }
                    break;
                case 'unlock':
                    $locks = array();
                    foreach ($posts as $p) {
                        if (get_post_meta($p, TDOMF_KEY_LOCK)) {
                            delete_post_meta($p, TDOMF_KEY_LOCK);
                            $locks[] = $p;
                        }
                    }
                    if (!empty($locks)) {
                        tdomf_log_message("Unlocked " . implode(", ", $locks) . " posts");
                        $message .= sprintf(__("Unlocked these posts/pages: %s", "tdomf"), implode(", ", $locks));
                    }
                    break;
                case 'edit_spam_recheck':
                    $spam_list = array();
                    $ham_list = array();
                    $edit_spam_list = array();
                    $edit_ham_list = array();
                    foreach ($posts as $post) {
                        $last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
                        if ($last_edit != false && !empty($last_edit)) {
                            if (tdomf_check_edit_spam($last_edit[0]->edit_id, false)) {
                                $ham_list[] = $post;
                                $edit_ham_list[] = $last_edit[0]->edit_id;
                            } else {
                                $spam_list[] = $post;
                                $edit_spam_list[] = $last_edit[0]->edit_id;
                            }
                        }
                    }
                    tdomf_log_message('Akismet thinks these edits are spam: ' . implode(", ", $edit_spam_list));
                    $message .= sprintf(__("Marked last contribution on these submissions as spam: %s.", "tdomf"), implode(", ", $spam_list));
                    tdomf_log_message('Akismet thinks these edits are not spam: ' . implode(", ", $edit_ham_list));
                    $message .= " ";
                    $message .= sprintf(__("Marked last contribution on these submissions as not spam: %s.", "tdomf"), implode(", ", $ham_list));
                    break;
                case 'edit_approve':
                    $edit_list = array();
                    $post_list = array();
                    foreach ($posts as $post) {
                        $last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
                        if (!empty($last_edit) && $last_edit[0]->state != 'approved') {
                            $edit_list[] = $last_edit[0]->edit_id;
                            $post_list[] = $post;
                            $user_id = $last_edit[0]->user_id;
                            if ($last_edit[0]->state == 'spam') {
                                tdomf_hamit_edit($last_edit[0]);
                            }
                            wp_restore_post_revision($edit->revision_id);
                            tdomf_set_state_edit('approved', $last_edit[0]->edit_id);
                            if ($user_id > 0) {
                                tdomf_trust_user($user_id);
                            }
                        }
                    }
                    tdomf_log_message('These edits have been approved: ' . implode(", ", $edit_list));
                    $message .= sprintf(__("Approved contributions on these submissions: %s.", "tdomf"), implode(", ", $post_list));
                    break;
                case 'edit_revert':
                    $edit_list = array();
                    $post_list = array();
                    foreach ($posts as $post) {
                        $last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
                        if (!empty($last_edit) && $last_edit[0]->state == 'approved' && $last_edit[0]->revision_id != 0 && $last_edit[0]->current_revision_id != 0) {
                            $edit_list[] = $last_edit[0]->edit_id;
                            $post_list[] = $post;
                            wp_restore_post_revision($last_edit[0]->current_revision_id);
                            tdomf_set_state_edit('unapproved', $last_edit[0]->edit_id);
                        }
                    }
                    tdomf_log_message('These edits have been reverted: ' . implode(", ", $edit_list));
                    $message .= sprintf(__("Latest contribution on these submissions have been reverted: %s.", "tdomf"), implode(", ", $post_list));
                    break;
                case 'edit_delete':
                    $edit_list = array();
                    $post_list = array();
                    foreach ($posts as $post) {
                        $last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
                        if (!empty($last_edit) && $last_edit[0]->state != 'approved') {
                            $edit_list[] = $last_edit[0]->edit_id;
                            $post_list[] = $post;
                            if ($last_edit[0]->revision_id != 0) {
                                wp_delete_post_revision($edit->revision_id);
                                tdomf_log_message("Deleting revision " . $last_edit[0]->revision_id . " on post " . $post);
                            }
                            if ($last_edit[0]->current_revision_id != 0) {
                                wp_delete_post_revision($last_edit[0]->current_revision_id);
                                tdomf_log_message("Deleting revision " . $last_edit[0]->current_revision_id . " on post " . $post);
                            }
                        }
                        tdomf_delete_edits($edit_list);
                    }
                    tdomf_log_message('These edits have been deleted: ' . implode(", ", $edit_list));
                    $message .= sprintf(__("Latest contribution on these submissions have been deleted: %s.", "tdomf"), implode(", ", $post_list));
                    break;
                case 'edit_spamit':
                    $edit_list = array();
                    $post_list = array();
                    foreach ($posts as $post) {
                        $last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
                        if (!empty($last_edit) && $last_edit[0]->state != 'spam') {
                            $edit_list[] = $last_edit[0]->edit_id;
                            $post_list[] = $post;
                            tdomf_spamit_edit($last_edit[0]);
                        }
                    }
                    tdomf_log_message('These edits have been marked as spam: ' . implode(", ", $edit_list));
                    $message .= sprintf(__("Latest contribution on these submissions have been marked as spam: %s.", "tdomf"), implode(", ", $post_list));
                    break;
                case 'edit_hamit':
                    $edit_list = array();
                    $post_list = array();
                    foreach ($posts as $post) {
                        $last_edit = tdomf_get_edits(array('post_id' => $post, 'limit' => 1));
                        if (!empty($last_edit) && $last_edit[0]->state == 'soam') {
                            $edit_list[] = $last_edit[0]->edit_id;
                            $post_list[] = $post;
                            tdomf_hamit_edit($last_edit[0]);
                        }
                    }
                    tdomf_log_message('These edits have been marked as not spam: ' . implode(", ", $edit_list));
                    $message .= sprintf(__("Latest contribution on these submissions have been marked as not being spam: %s.", "tdomf"), implode(", ", $post_list));
                    break;
                default:
                    tdomf_log_message('Unexpected bulk action ' . $action . ' in moderation screen!', TDOMF_LOG_BAD);
                    $message .= sprintf(__("Unrecognised bulk action %s,", "tdomf"), $action);
                    break;
            }
        }
        // else no posts selected or bulk actions
        // individual actions
        // operations on posts/pages (submissions)
    } else {
        if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'publish_now') {
            $post_id = $_REQUEST['post'];
            check_admin_referer('tdomf-publish_' . $post_id);
            // if we're going to publish the post, then it's not spam!
            tdomf_ham_post($post_id);
            tdomf_publish_post($post_id, false);
            tdomf_log_message("Published post {$post_id}");
            $message .= sprintf(__("Published post <a href=\"%s\">%d</a>.", "tdomf"), get_permalink($post_id), $post_id);
        } else {
            if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'publish') {
                $post_id = $_REQUEST['post'];
                check_admin_referer('tdomf-publish_' . $post_id);
                // if we're going to publish the post, then it's not spam!
                tdomf_ham_post($post_id);
                tdomf_publish_post($post_id);
                tdomf_log_message("Published post {$post_id}");
                $message .= sprintf(__("Published post <a href=\"%s\">%d</a>.", "tdomf"), get_permalink($post_id), $post_id);
            } else {
                if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'unpublish') {
                    $post_id = $_REQUEST['post'];
                    check_admin_referer('tdomf-unpublish_' . $post_id);
                    tdomf_unpublish_post($post_id);
                    tdomf_log_message("Unpublished post {$post_id}");
                    $message .= sprintf(__("Unpublished post %d.", "tdomf"), $post_id);
                } else {
                    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'spamit') {
                        $post_id = $_REQUEST['post'];
                        check_admin_referer('tdomf-spamit_' . $post_id);
                        if (!get_post_meta($post_id, TDOMF_KEY_SPAM)) {
                            tdomf_spam_post($post_id);
                            tdomf_log_message("Post {$post_id} submitted as spam");
                            $message .= sprintf(__("Post %d flagged as spam", "tdomf"), $post_id);
                        } else {
                            $message .= sprintf(__("Did not flag post %d as being spam as it is already flagged appropriately.", "tdomf"), $post_id);
                        }
                    } else {
                        if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'hamit') {
                            $post_id = $_REQUEST['post'];
                            check_admin_referer('tdomf-hamit_' . $post_id);
                            if (get_post_meta($post_id, TDOMF_KEY_SPAM)) {
                                tdomf_ham_post($post_id);
                                tdomf_log_message("Post {$post_id} submitted as ham");
                                $message .= sprintf(__("Post %d flagged as not being spam", "tdomf"), $post_id);
                            } else {
                                $message .= sprintf(__("Did not flag post %d as not being spam as it is already flagged appropriately.", "tdomf"), $post_id);
                            }
                        } else {
                            if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'lock') {
                                $post_id = $_REQUEST['post'];
                                check_admin_referer('tdomf-lock_' . $post_id);
                                if (!get_post_meta($post_id, TDOMF_KEY_LOCK)) {
                                    add_post_meta($post_id, TDOMF_KEY_LOCK, true, true);
                                    tdomf_log_message("Post {$post_id} locked");
                                    $message .= sprintf(__("Post %d is now locked from editing", "tdomf"), $post_id);
                                } else {
                                    $message .= sprintf(__("Post %d is already locked from editing.", "tdomf"), $post_id);
                                }
                            } else {
                                if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'unlock') {
                                    $post_id = $_REQUEST['post'];
                                    check_admin_referer('tdomf-unlock_' . $post_id);
                                    if (get_post_meta($post_id, TDOMF_KEY_LOCK)) {
                                        delete_post_meta($post_id, TDOMF_KEY_LOCK);
                                        tdomf_log_message("Post {$post_id} unlocked");
                                        $message .= sprintf(__("Post %d is now unlocked.", "tdomf"), $post_id);
                                    } else {
                                        $message .= sprintf(__("Post %d is already unlocked.", "tdomf"), $post_id);
                                    }
                                } else {
                                    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'approve_edit') {
                                        $edit_id = $_REQUEST['edit'];
                                        check_admin_referer('tdomf-approve_edit_' . $edit_id);
                                        $edit = tdomf_get_edit($edit_id);
                                        if ($edit && ($edit->state == 'spam' || $edit->state == 'unapproved')) {
                                            if ($edit->state == 'spam') {
                                                tdomf_hamit_edit($edit);
                                            }
                                            wp_restore_post_revision($edit->revision_id);
                                            tdomf_set_state_edit('approved', $edit_id);
                                            if ($edit->user_id > 0) {
                                                tdomf_trust_user($edit->user_id);
                                            }
                                            tdomf_log_message("Edit {$edit_id} has been approved on post " . $edit->post_id);
                                            $message .= sprintf(__('Contribution to <a href="%s">Post %d</a> has been approved and published', "tdomf"), get_permalink($edit->post_id), $edit->post_id);
                                        } else {
                                            tdomf_log_message("Invalid {$action} performed on edit {$edit_id}", TDOMF_LOG_BAD);
                                            $message .= sprintf(__('Invalid action %s or invalid edit identifier %d!', 'tdomf'), $_REQUEST['action'], $edit_id);
                                        }
                                    } else {
                                        if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'revert_edit') {
                                            $edit_id = $_REQUEST['edit'];
                                            check_admin_referer('tdomf-revert_edit_' . $edit_id);
                                            $edit = tdomf_get_edit($edit_id);
                                            if ($edit && $edit->state == 'approved' && $edit->revision_id != 0 && $edit->current_revision_id != 0) {
                                                wp_restore_post_revision($edit->current_revision_id);
                                                tdomf_set_state_edit('unapproved', $edit_id);
                                                tdomf_log_message("Edit {$edit_id} on post " . $edit->post_id . " has been reverted");
                                                $message .= sprintf(__('Contribution to <a href="%s">Post %d</a> has reverted to previous revision', "tdomf"), get_permalink($edit->post_id), $edit->post_id);
                                            } else {
                                                tdomf_log_message("Invalid {$action} performed on edit {$edit_id}", TDOMF_LOG_BAD);
                                                $message .= sprintf(__('Invalid action %s or invalid edit identifier %d!', 'tdomf'), $_REQUEST['action'], $edit_id);
                                            }
                                        } else {
                                            if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete_edit') {
                                                $edit_id = $_REQUEST['edit'];
                                                check_admin_referer('tdomf-delete_edit_' . $edit_id);
                                                $edit = tdomf_get_edit($edit_id);
                                                if ($edit && $edit->state != 'approved') {
                                                    $post_id = $edit->post_id;
                                                    if ($edit->revision_id != 0) {
                                                        wp_delete_post_revision($edit->revision_id);
                                                        tdomf_log_message("Deleting revision {$revision_id} on post " . $post_id);
                                                    }
                                                    if ($edit->current_revision_id != 0) {
                                                        wp_delete_post_revision($edit->current_revision_id);
                                                        tdomf_log_message("Deleting revision {$current_revision_id} on post " . $post_id);
                                                    }
                                                    tdomf_delete_edits(array($edit_id));
                                                    tdomf_log_message("Edit {$edit_id} on post " . $post_id . " has been deleted");
                                                    $message .= sprintf(__('Contribution to <a href="%s">Post %d</a> has deleted', "tdomf"), get_permalink($edit->post_id), $edit->post_id);
                                                } else {
                                                    tdomf_log_message("Invalid {$action} performed on edit {$edit_id}", TDOMF_LOG_BAD);
                                                    $message .= sprintf(__('Invalid action %s or invalid edit identifier %d!', 'tdomf'), $_REQUEST['action'], $edit_id);
                                                }
                                            } else {
                                                if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'spamit_edit') {
                                                    $edit_id = $_REQUEST['edit'];
                                                    check_admin_referer('tdomf-spamit_edit_' . $edit_id);
                                                    $edit = tdomf_get_edit($edit_id);
                                                    if ($edit && $edit->state != 'spam') {
                                                        tdomf_spamit_edit($edit);
                                                        tdomf_log_message("Marking edit {$edit_id} as spam!");
                                                        $message .= sprintf(__('Contribution to <a href="%s">Post %d</a> has been flagged as spam', "tdomf"), get_permalink($edit->post_id), $edit->post_id);
                                                    } else {
                                                        tdomf_log_message("Invalid {$action} performed on edit {$edit_id}", TDOMF_LOG_BAD);
                                                        $message .= sprintf(__('Invalid action %s or invalid edit identifier %d!', 'tdomf'), $_REQUEST['action'], $edit_id);
                                                    }
                                                } else {
                                                    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'hamit_edit') {
                                                        $edit_id = $_REQUEST['edit'];
                                                        check_admin_referer('tdomf-hamit_edit_' . $edit_id);
                                                        $edit = tdomf_get_edit($edit_id);
                                                        if ($edit && $edit->state == 'spam') {
                                                            tdomf_spamit_edit($edit);
                                                            tdomf_log_message("Marking edit {$edit_id} as not spam!");
                                                            $message .= sprintf(__('Contribution to <a href="%s">Post %d</a> has been flagged as not being spam', "tdomf"), get_permalink($edit->post_id), $edit->post_id);
                                                        } else {
                                                            tdomf_log_message("Invalid {$action} performed on edit {$edit_id}", TDOMF_LOG_BAD);
                                                            $message .= sprintf(__('Invalid action %s or invalid edit identifier %d!', 'tdomf'), $_REQUEST['action'], $edit_id);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (!empty($message)) {
        ?>
      <div id="message" class="updated fade"><p><?php 
        echo $message;
        ?>
</p></div>
   <?php 
    }
}
示例#4
0
function tdomf_ham_edit($edit_id)
{
    if (!get_option(TDOMF_OPTION_SPAM)) {
        return;
    }
    $akismet_key = get_option(TDOMF_OPTION_SPAM_AKISMET_KEY);
    if (empty($akismet_key)) {
        tdomf_log_message("No Akismet key set, cannot submit spam for edit {$edit_id}!", TDOMF_LOG_ERROR);
        return;
    }
    $edit = tdomf_get_edit($edit_id);
    if (empty($edit)) {
        tdomf_log_message("Invalid edit data for {$edit_id}. Can't check if spam", TDOMF_LOG_ERROR);
        return true;
    }
    if ($edit->state != 'spam') {
        tdomf_log_message("Edit {$edit_id} is not spam!", TDOMF_LOG_BAD);
        return;
    }
    $query_data = array();
    if (!empty($edit->ip)) {
        $query_data['user_ip'] = $edit->ip;
    }
    if (!isset($edit->data['HTTP_USER_AGENT'])) {
        $query_data['user_agent'] = $edit->data['HTTP_USER_AGENT'];
    }
    if (!isset($edit->data['HTTP_REFERER'])) {
        $query_data['referrer'] = $edit->data['HTTP_REFERER'];
    }
    $query_data['blog'] = get_option('home');
    $query_data['comment_type'] = 'edit-entry';
    if ($edit->user_id != 0) {
        $user = get_userdata($edit->user_id);
        $query_data['comment_author_email'] = $user->user_email;
        if (!empty($user->user_url)) {
            $query_data['comment_author_url'] = $user->user_url;
        }
        $query_data['comment_author'] = $user->display_name;
    } else {
        if (isset($edit->data[TDOMF_KEY_NAME])) {
            $query_data['comment_author'] = $edit->data[TDOMF_KEY_NAME];
        }
        if (isset($edit->data[TDOMF_KEY_EMAIL])) {
            $query_data['comment_author_email'] = $edit->data[TDOMF_KEY_EMAIL];
        }
        if (isset($edit->data[TDOMF_KEY_WEB])) {
            $query_data['comment_author_url'] = $edit->data[TDOMF_KEY_WEB];
        }
    }
    # test - should trigger spam response
    #$query_data['comment_author'] = 'viagra-test-123';
    if ($edit->revision_id == 0) {
        $post_data = wp_get_single_post($edit->post_id, ARRAY_A);
    } else {
        $post_data = wp_get_single_post($edit->revision_id, ARRAY_A);
    }
    $query_data['comment_content'] = $post_data['post_content'];
    $query_string = '';
    foreach ($query_data as $key => $data) {
        $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
    }
    tdomf_log_message_extra("{$akismet_key}.rest.akismet.com/1.1/comment-check<br/>{$query_string}");
    $response = tdomf_akismet_send($query_string, $akismet_key . ".rest.akismet.com", "/1.1/submit-ham", 80);
    // unflag spam
    //
    tdomf_set_state_edit('unapproved', $edit_id);
    $spam_count = get_option(TDOMF_STAT_SPAM);
    if ($spam_count == false) {
        add_option(TDOMF_STAT_SPAM, 0);
    } else {
        update_option(TDOMF_STAT_SPAM, $spam_count--);
    }
    $edited_count = get_option(TDOMF_STAT_EDITED);
    if ($edited_count == false) {
        add_option(TDOMF_STAT_EDITED, 1);
    } else {
        update_option(TDOMF_STAT_EDITED, $edited_count++);
    }
    tdomf_log_message("Edit {$edit_id} has been submitted as ham to Akismet<br/><pre>" . var_export($response, true) . "</pre>");
}
 /** 
  * Updates fields and custom fields used by this widget
  * 
  * @return Boolean
  * @access private 
  */
 function updateFields($args)
 {
     extract($args);
     if (is_array($this->fields) || is_array($this->customFields)) {
         if (TDOMF_Widget::isEditForm($mode)) {
             $edit = tdomf_get_edit($edit_id);
             if (is_array($this->fields)) {
                 if (!isset($edit->data[TDOMF_KEY_FIELDS]) || !is_array($edit->data[TDOMF_KEY_FIELDS])) {
                     $edit->data[TDOMF_KEY_FIELDS] = $this->fields;
                 } else {
                     $currentFields = array_merge($edit->data[TDOMF_KEY_FIELDS], $this->fields);
                     $edit->data[TDOMF_KEY_FIELDS] = $currentFields;
                 }
             }
             if (is_array($this->customFields)) {
                 if (!isset($edit->data[TDOMF_KEY_CUSTOM_FIELDS]) || !is_array($edit->data[TDOMF_KEY_CUSTOM_FIELDS])) {
                     $edit->data[TDOMF_KEY_CUSTOM_FIELDS] = $this->customFields;
                 } else {
                     $currentFields = array_merge($edit->data[TDOMF_KEY_CUSTOM_FIELDS], $this->customFields);
                     $edit->data[TDOMF_KEY_CUSTOM_FIELDS] = $currentFields;
                 }
             }
             // do update once
             tdomf_set_data_edit($edit->data, $edit_id);
             // update the post id and not revision's list
             $id = $edit->post_id;
         } else {
             // submit form, so just update the post
             $id = $post_ID;
         }
         if (is_array($this->fields)) {
             $currentFields = get_post_meta($id, TDOMF_KEY_FIELDS, true);
             if (!is_array($currentFields)) {
                 add_post_meta($id, TDOMF_KEY_FIELDS, $this->fields, true);
             } else {
                 $currentFields = array_merge($currentFields, $this->fields);
                 update_post_meta($id, TDOMF_KEY_FIELDS, $currentFields);
             }
         }
         if (is_array($this->customFields)) {
             $currentFields = get_post_meta($id, TDOMF_KEY_CUSTOM_FIELDS, true);
             if (!is_array($currentFields)) {
                 add_post_meta($id, TDOMF_KEY_CUSTOM_FIELDS, $this->customFields, true);
             } else {
                 $currentFields = array_merge($currentFields, $this->customFields);
                 update_post_meta($id, TDOMF_KEY_CUSTOM_FIELDS, $currentFields);
             }
         }
     }
     return true;
 }
示例#6
0
     $form_tag = $form_id;
 }
 if (isset($_POST['tdomf_form' . $form_tag . '_send'])) {
     tdomf_log_message("Someone is attempting to submit something");
     $message = tdomf_validate_form($_POST, false);
     if ($message == NULL) {
         $args = $_POST;
         $args['ip'] = $_SERVER['REMOTE_ADDR'];
         $retVal = tdomf_create_post($args);
         // If retVal is an int it's a post id or an edit id
         $message = "<div class=\"tdomf_form_message\" id=\"tdomf_form" . $form_tag . "_message\" name=\"tdomf_form" . $form_tag . "_message\">";
         $publish = false;
         if (is_int($retVal)) {
             if ($is_edit) {
                 $edit_id = $retVal;
                 $edit = tdomf_get_edit($edit_id);
                 // @todo could probably test if $edit is real or not before proceeding
                 $post_id = $edit->post_id;
                 if ($edit->state == 'approved') {
                     $message .= tdomf_get_message_instance(TDOMF_OPTION_MSG_SUB_PUBLISH, $form_id, false, $post_id);
                     $publish = true;
                 } else {
                     if ($edit->state == 'spam') {
                         $message .= tdomf_get_message_instance(TDOMF_OPTION_MSG_SUB_SPAM, $form_id, false, $post_id);
                     } else {
                         // unapproved
                         $message .= tdomf_get_message_instance(TDOMF_OPTION_MSG_SUB_MOD, $form_id, false, $post_id);
                     }
                 }
             } else {
                 $post_id = $retVal;
示例#7
0
function tdomf_get_data_edit($edit_id)
{
    $edit = tdomf_get_edit($edit_id);
    return maybe_unserialize($edit->data);
}