예제 #1
0
 function set_to_alert($id, $theFeed)
 {
     $error_to_alert = get_option(PF_SLUG . '_errors_until_alert', 3);
     $error_count = pf_retrieve_meta($id, PF_SLUG . '_feed_error_count');
     if (!is_numeric($error_count) || '' == $error_count) {
         $error_count = 0;
     }
     if ($error_count >= $error_to_alert) {
         the_alert_box()->switch_post_type($id);
         the_alert_box()->add_bug_type_to_post($id, __('Broken RSS feed.', 'pf'));
         $post_obj = get_post($id);
         $old_content = $post_obj->post_content;
         $update_result = pf_update_meta($id, PF_SLUG . '_feed_error_count', 0);
         if (is_wp_error($theFeed)) {
             $argup = array('ID' => $id, 'post_content' => $old_content . ' <p>' . $theFeed->get_error_message() . '</p>');
             $result = wp_update_post($argup);
         }
         return true;
     } else {
         $update_result = pf_update_meta($id, PF_SLUG . '_feed_error_count', $error_count + 1);
         return $update_result;
     }
 }
예제 #2
0
 function build_nomination()
 {
     // Verify nonce
     if (!wp_verify_nonce($_POST[PF_SLUG . '_nomination_nonce'], 'nomination')) {
         die(__("Nonce check failed. Please ensure you're supposed to be nominating stories.", 'pf'));
     }
     if ('' != get_option('timezone_string')) {
         date_default_timezone_set(get_option('timezone_string'));
     }
     //ref http://wordpress.stackexchange.com/questions/8569/wp-insert-post-php-function-and-custom-fields, http://wpseek.com/wp_insert_post/
     $time = current_time('mysql', $gmt = 0);
     //@todo Play with post_exists (wp-admin/includes/post.php ln 493) to make sure that submissions have not already been submitted in some other method.
     //Perhaps with some sort of "Are you sure you don't mean this... reddit style thing?
     //Should also figure out if I can create a version that triggers on nomination publishing to send to main posts.
     //There is some serious delay here while it goes through the database. We need some sort of loading bar.
     ob_start();
     //set up nomination check
     $item_wp_date = $_POST['item_wp_date'];
     $item_id = $_POST['item_id'];
     //die($item_wp_date);
     //Going to check posts first on the assumption that there will be more nominations than posts.
     $nom_check = $this->handle_post_nomination_status($item_id);
     pf_log('We handle the item into a nomination?');
     pf_log($nom_check);
     /** The system will only check for nominations of the item does not exist in posts. This will stop increasing the user and nomination count in nominations once they are sent to draft.
      **/
     if ($nom_check) {
         //Record first nominator and/or add a nomination to the user's count.
         $current_user = wp_get_current_user();
         if (0 == $current_user->ID) {
             //Not logged in.
             $userSlug = "external";
             $userName = __('External User', 'pf');
             $userID = 0;
         } else {
             // Logged in.
             self::user_nomination_meta();
         }
         $userID = $current_user->ID;
         $userString = $userID;
         //set up rest of nomination data
         $item_title = $_POST['item_title'];
         $item_content = $_POST['item_content'];
         $item_link = pf_retrieve_meta($_POST['item_post_id'], 'item_link');
         $readable_status = pf_retrieve_meta($_POST['item_post_id'], 'readable_status');
         $item_author = pf_retrieve_meta($_POST['item_post_id'], 'item_author');
         if ($readable_status != 1) {
             $read_args = array('force' => '', 'descrip' => $item_content, 'url' => $item_link, 'authorship' => $item_author);
             $item_content_obj = pressforward()->readability->get_readable_text($read_args);
             $item_content = htmlspecialchars_decode($item_content_obj['readable']);
         } else {
             $item_content = htmlspecialchars_decode($_POST['item_content']);
         }
         //No need to define every post arg right? I should only need the ones I'm pushing through. Well, I guess we will find out.
         $data = array('post_status' => 'draft', 'post_type' => 'nomination', 'post_title' => $item_title, 'post_content' => $item_content);
         $newNomID = wp_insert_post($data);
         if (1 == $readable_status && (!empty($item_content_obj['status']) && 'secured' != $item_content_obj['status'])) {
             pf_update_meta($_POST['item_post_id'], 'readable_status', 1);
         } elseif (1 != $readable_status) {
             pf_update_meta($_POST['item_post_id'], 'readable_status', 0);
         }
         if ($_POST['item_feat_img'] != '') {
             pressforward()->pf_feed_items->set_ext_as_featured($newNomID, $_POST['item_feat_img']);
         }
         //die($_POST['item_feat_img']);
         pf_update_meta($_POST['item_post_id'], 'nomination_count', 1);
         pf_update_meta($_POST['item_post_id'], 'submitted_by', $userString);
         pf_update_meta($_POST['item_post_id'], 'nominator_array', array($userID));
         pf_update_meta($_POST['item_post_id'], 'date_nominated', date('c'));
         pf_update_meta($_POST['item_post_id'], 'origin_item_ID', $item_id);
         pf_update_meta($_POST['item_post_id'], 'item_feed_post_id', $_POST['item_post_id']);
         pf_update_meta($_POST['item_post_id'], 'item_link', $_POST['item_link']);
         $item_date = $_POST['item_date'];
         if (empty($_POST['item_date'])) {
             $newDate = gmdate('Y-m-d H:i:s');
             $item_date = $newDate;
         }
         pf_update_meta($_POST['item_post_id'], 'posted_date', $item_date);
         pf_meta_transition_post($_POST['item_post_id'], $newNomID);
         $response = array('what' => 'nomination', 'action' => 'build_nomination', 'id' => $newNomID, 'data' => $item_title . ' nominated.', 'supplemental' => array('content' => $item_content, 'originID' => $item_id, 'nominater' => $userID, 'buffered' => ob_get_contents()));
         $xmlResponse = new WP_Ajax_Response($response);
         $xmlResponse->send();
         ob_end_flush();
         die;
     } else {
         pf_log('User nominated already.');
         die('nominated_already');
     }
 }
예제 #3
0
 /**
  * Retrieve the item source's link.
  *
  * Retrieve the link for the item's source. Attempt to fully
  * resolve the URL for known aggregation services.
  *
  * @since 3.4.5
  *
  *
  */
 public static function get_source_link($post_id)
 {
     $url = pf_retrieve_meta($post_id, 'pf_source_link');
     if (empty($url)) {
         $url = pf_retrieve_meta($post_id, 'item_link');
     }
     $source_url = pressforward()->pf_feed_items->resolve_a_url($url);
     pf_update_meta($post_id, 'pf_source_link', $source_url);
     return $source_url;
 }
예제 #4
0
/**
 * Press It form handler.
 *
 * @package WordPress
 * @subpackage Press_This
 * @since 2.6.0
 *
 * @return int Post ID
 */
function nominate_it()
{
    $post = get_default_post_to_edit();
    $post = get_object_vars($post);
    $post_ID = $post['ID'] = (int) $_POST['post_id'];
    if (!current_user_can('edit_post', $post_ID)) {
        wp_die(__('You are not allowed to edit this post.'));
    }
    $post['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : '';
    $post['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : '';
    $post['post_title'] = isset($_POST['title']) ? $_POST['title'] : '';
    $content = isset($_POST['content']) ? $_POST['content'] : '';
    $upload = false;
    if (!empty($_POST['photo_src']) && current_user_can('upload_files')) {
        foreach ((array) $_POST['photo_src'] as $key => $image) {
            // see if files exist in content - we don't want to upload non-used selected files.
            if (strpos($_POST['content'], htmlspecialchars($image)) !== false) {
                $desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : '';
                $upload = media_sideload_image($image, $post_ID, $desc);
                // Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes
                if (!is_wp_error($upload)) {
                    $content = preg_replace('/<img ([^>]*)src=\\\\?(\\"|\')' . preg_quote(htmlspecialchars($image), '/') . '\\\\?(\\2)([^>\\/]*)\\/*>/is', $upload, $content);
                }
            }
        }
    }
    // set the post_content and status
    $post['post_content'] = $content;
    if (isset($_POST['publish']) && current_user_can('publish_posts')) {
        $post['post_status'] = 'publish';
    } elseif (isset($_POST['review'])) {
        $post['post_status'] = 'pending';
    } else {
        $post['post_status'] = 'draft';
    }
    $nom_check = false;
    // error handling for media_sideload
    if (is_wp_error($upload)) {
        wp_delete_post($post_ID);
        wp_die($upload);
        $nom_check = true;
    } else {
        // Post formats
        if (isset($_POST['post_format'])) {
            if (current_theme_supports('post-formats', $_POST['post_format'])) {
                set_post_format($post_ID, $_POST['post_format']);
            } elseif ('0' == $_POST['post_format']) {
                set_post_format($post_ID, false);
            }
        }
        # PF NOTE: Switching post type to nomination.
        $post['post_type'] = 'nomination';
        $post['post_date_gmt'] = gmdate('Y-m-d H:i:s');
        # PF NOTE: This is where the inital post is created.
        # PF NOTE: Put get_post_nomination_status here.
        $item_id = md5($_POST['item_link'] . $post['post_title']);
        if (!isset($_POST['item_date'])) {
            $newDate = gmdate('Y-m-d H:i:s');
            $item_date = $newDate;
        } else {
            $item_date = $_POST['item_date'];
        }
        $pf_nomination = new PF_Nominations();
        $nom_check = $pf_nomination->is_nominated($item_id);
        if (!$nom_check) {
            $post_ID = wp_update_post($post);
        }
    }
    # var_dump($_POST); die();
    if (!$nom_check) {
        $already_has_thumb = has_post_thumbnail($post_ID);
        if ($already_has_thumb) {
            $post_thumbnail_id = get_post_thumbnail_id($post_ID);
            $post_thumbnail_url = wp_get_attachment_image_src($attachment_id);
        } else {
            $post_thumbnail_url = false;
        }
        $pf_meta_args = array(pf_meta_for_entry('item_id', $post_ID), pf_meta_for_entry('origin_item_ID', $item_id), pf_meta_for_entry('item_link', $_POST['item_link']), pf_meta_for_entry('nomination_count', 1), pf_meta_for_entry('source_title', 'Bookmarklet'), pf_meta_for_entry('item_date', $item_date), pf_meta_for_entry('posted_date', $item_date), pf_meta_for_entry('date_nominated', $_POST['date_nominated']), pf_meta_for_entry('item_author', $_POST['authors']), pf_meta_for_entry('authors', $_POST['authors']), pf_meta_for_entry('item_link', $_POST['item_link']), pf_meta_for_entry('item_feat_img', $post_thumbnail_url), pf_meta_for_entry('nominator_array', array(get_current_user_id())), pf_meta_for_entry('item_wp_date', $item_date), pf_meta_for_entry('sortable_item_date', strtotime($item_date)), pf_meta_for_entry('item_tags', 'via bookmarklet'), pf_meta_for_entry('source_repeat', 1), pf_meta_for_entry('revertible_feed_text', $post['post_content']));
        pf_meta_establish_post($post_ID, $pf_meta_args);
    }
    if (isset($_POST['publish']) && $_POST['publish'] == "Send to Draft") {
        $post_check = $pf_nomination->is_nominated($item_id, 'post', false);
        if ($post_check != true) {
            pf_update_meta($post_ID, 'nom_id', $post_ID);
            $d_post = $post;
            $d_post['post_type'] = 'post';
            $d_post['post_status'] = 'draft';
            $newPostID = wp_insert_post($d_post, true);
            #var_dump($newPostID); die();
            #pf_meta_transition_post($post_ID, $newPostID);
            $already_has_thumb = has_post_thumbnail($post_ID);
            if ($already_has_thumb) {
                $post_thumbnail_id = get_post_thumbnail_id($post_ID);
                set_post_thumbnail($newPostID, $post_thumbnail_id);
            }
            pf_meta_transition_post($post_ID, $newPostID);
        }
    }
    #var_dump($post); die();
    return $post_ID;
}