/** * Gets the data from an OPML file and turns it into a data object * as expected by PF * Prefers a post object, but can take a post ID. * * @global $pf Used to access the feed_object() method * */ public function get_data_object($aOPML) { set_time_limit(0); $feed_obj = new PF_Feeds_Schema(); if (is_numeric($aOPML)) { $aOPML = get_post($aOPML); } pf_log('Invoked: PF_OPML_Subscribe::get_data_object()'); $aOPML_url = $aOPML->guid; if (empty($aOPML_url) || is_wp_error($aOPML_url) || !$aOPML_url) { $aOPML_id = $aOPML->ID; $aOPML_url - get_post_meta($aOPML_id, 'feedUrl', true); } pf_log('Getting OPML Feed at ' . $aOPML_url); $OPML_reader = new OPML_reader(); $opml_array = $OPML_reader->get_OPML_data($aOPML_url, false); $c = 0; $opmlObject = array(); foreach ($opml_array as $feedObj) { $id = md5($aOPML_url . '_opml_sub_for_' . $feedObj['xmlUrl']); #if ( false === ( $rssObject['opml_' . $c] = get_transient( 'pf_' . $id ) ) ) { # Adding this as a 'quick' type so that we can process the list quickly. if ($feedObj['type'] == 'rss') { $feedObj['type'] = 'rss-quick'; } if (!empty($feedObj['text'])) { $contentObj = new pf_htmlchecker($feedObj['text']); $feedObj['text'] = $contentObj->closetags($feedObj['text']); } if (!empty($feedObj['title'])) { $contentObj = new pf_htmlchecker($feedObj['title']); $feedObj['title'] = $contentObj->closetags($feedObj['title']); } if ($feedObj['title'] == '') { $feedObj['title'] = $feedObj['text']; } $check = $feed_obj->create($feedObj['xmlUrl'], array('type' => $feedObj['type'], 'title' => $feedObj['title'], 'htmlUrl' => $feedObj['htmlUrl'], 'description' => $feedObj['text'], 'type' => 'rss-quick')); pf_log('Creating subscription to ' . $feedObj['xmlUrl'] . ' from OPML Feed at ' . $aOPML_url); #var_dump($check); die(); $content = 'Subscribed: ' . $feedObj['title'] . ' - ' . $feedObj['type'] . ' - ' . $feedObj['text']; $source = $feedObj['htmlUrl']; if (empty($source)) { $source = $feedObj['xmlUrl']; } $opmlObject['opml_' . $c] = pf_feed_object($feedObj['title'], 'OPML Subscription ' . $aOPML_url, date('r'), 'OPML Subscription', $content, $source, '', $id, date('r'), ''); pf_log('Setting new transient for ' . $feedObj['xmlUrl'] . ' of ' . $source . '.'); set_transient('pf_' . $id, $opmlObject['opml_' . $c], 60 * 10); $c++; #} } return $opmlObject; }
/** * Gets the data from an RSS feed and turns it into a data object * as expected by PF * * @global $pf Used to access the feed_object() method */ public function get_data_object($aFeed) { pf_log('Invoked: PF_RSS_Import::get_data_object()'); $aFeed_url = $aFeed->guid; # $aFeed_id = $aFeed->ID; # $aFeed_url = get_post_meta($aFeed_id, 'feedUrl', true); # if(empty($aFeed_url) || is_wp_error($aFeed_url) || !$aFeed_url){ # $aFeed_url = $aFeed->post_title; # update_post_meta($aFeed_id, 'feedUrl', $aFeed_url); # } pf_log('Getting RSS Feed at ' . $aFeed_url); add_filter('wp_feed_cache_transient_lifetime', array($this, 'return_cachetime')); $theFeed = fetch_feed($aFeed_url); remove_filter('wp_feed_cache_transient_lifetime', array($this, 'return_cachetime')); # pf_log( 'Getting RSS Feed at '.$aFeed_url ); if (!$theFeed || empty($theFeed) || is_wp_error($theFeed)) { pf_log('Can not use Simple Pie to retrieve the feed'); pf_log($theFeed); $alert = $this->set_to_alert($aFeed->ID, $theFeed); pf_log('Set to alert resulted in:'); pf_log($alert); return false; } $theFeed->set_timeout(60); $rssObject = array(); $c = 0; pf_log('Begin processing the feed.'); foreach ($theFeed->get_items() as $item) { pf_log('Feed looping through for the ' . $c . ' time.'); $check_date = $item->get_date('U'); $dead_date = time() - 60 * 60 * 24 * 60; //Get the unixdate for two months ago. if ($check_date <= $dead_date) { pf_log('Feed item too old. Skip it.'); } else { $id = md5($item->get_link() . $item->get_title()); //die(); pf_log('Now on feed ID ' . $id . '.'); //print_r($item_categories_string); die(); if ($item->get_source()) { $sourceObj = $item->get_source(); # Get the link of what created the RSS entry. $source = $sourceObj->get_link(0, 'alternate'); # Check if the feed item creator is an aggregator. $agStatus = $this->is_from_aggregator($source); } else { # If we can't get source information then don't do anything. $agStatus = false; } # If there is less than 160 characters of content, than it isn't really giving us meaningful information. # So we'll want to get the good stuff from the source. if (strlen($item->get_content()) < 160) { $agStatus = true; } //override switch while rest is not working. //$agStatus = false; //This is where we switch off auto readability //And leave it to an AJAX function instead. // if ($agStatus){ // # Get the origin post link. // $realLink = $item->get_link(); // # Try and get the actual content of the post. // $realContent = $pf->get_content_through_aggregator($realLink); // # If we can't get the actual content, then just use what we've got from the RSS feed. // if (!$realContent){ $item_content = $item->get_content(); // } else { // $item_content = $realContent; //print_r($realContent); // } // } else { // $item_content = $item->get_content(); // } $iFeed = $item->get_feed(); if (!$agStatus) { $authors = $this->get_rss_authors($item); } else { $authors = 'aggregation'; } $item_categories = array(); $item_categories = $item->get_categories(); $itemTerms = array(); if (!empty($item_categories)) { foreach ($item_categories as $item_category) { $itemTerms[] = $item_category->get_term(); } $item_categories_string = implode(',', $itemTerms); } else { $item_categories_string = ''; } //one final cleanup of the content. $contentObj = new pf_htmlchecker($item_content); $item_content = $contentObj->closetags($item_content); #print_r($c); $rssObject['rss_' . $c] = pf_feed_object($item->get_title(), $iFeed->get_title(), $item->get_date('r'), $authors, $item_content, $item->get_link(), '', $id, $item->get_date('Y-m-d'), $item_categories_string); pf_log('Setting new object for ' . $item->get_title() . ' of ' . $iFeed->get_title() . '.'); } $c++; # What the hell RSS feed? This is just ridiculous. if ($c > 300) { break; } } //$this->advance_feeds(); return $rssObject; }
/** * Fetch a collection of feed items and format for use in the reader. * * @param int $pageTop First item to display on the page. Note that it * is decremented by 1, so should not be 0. * @param int $pagefull Number of items to show per page. * @param int $fromUnixTime Feed items will only be returned when their * publish date is later than this. Must be in * UNIX format. * @param bool $limitless True to show all feed items. Skips pagination, * but obeys $fromUnixTime. Default: false. * @param string $limit Limit to feed items with certain relationships * set. Note that relationships are relative to * logged-in user. (starred|nominated) * @return array */ public static function archive_feed_to_display($args = array()) { // Backward compatibility. $func_args = func_get_args(); if (!is_array($func_args[0]) || 1 < count($func_args)) { $args = array('start' => $func_args[0]); if (isset($func_args[1])) { $args['posts_per_page'] = $func_args[1]; } if (isset($func_args[2])) { $args['from_unix_time'] = $func_args[2]; } if (isset($func_args[3])) { $args['no_limit'] = $func_args[3]; } if (isset($func_args[4])) { $args['relationship'] = $func_args[4]; } } else { $args = func_get_arg(0); } // Make sure default values are set. $r = array_merge(array('start' => 0, 'posts_per_page' => 20, 'from_unix_time' => 0, 'no_limit' => false, 'relationship' => false, 'search_terms' => '', 'exclude_archived' => false), $args); if (empty($r['from_unix_time']) || $r['from_unix_time'] < 100) { $r['from_unix_time'] = 0; } $r['start'] = $r['start'] - 1; if (!$r['posts_per_page']) { $user_obj = wp_get_current_user(); $user_id = $user_obj->ID; $r['posts_per_page'] = get_user_option('pf_pagefull', $user_id); if (empty($r['posts_per_page'])) { $r['posts_per_page'] = 20; } } $post_args = array('post_type' => pf_feed_item_post_type(), 'meta_key' => 'sortable_item_date', 'meta_value' => $r['from_unix_time'], 'meta_type' => 'SIGNED', 'meta_compare' => '>', 'orderby' => 'meta_value', 'order' => 'DESC', 'posts_per_page' => $r['posts_per_page'], 'offset' => $r['start']); if ($r['no_limit']) { $post_args['posts_per_page'] = -1; } if (!empty($r['relationship'])) { switch ($r['relationship']) { case 'starred': $rel_items = pf_get_relationships_for_user('star', get_current_user_id()); break; case 'nominated': $rel_items = pf_get_relationships_for_user('nominate', get_current_user_id()); break; } if (!empty($rel_items)) { $post_args['post__in'] = wp_list_pluck($rel_items, 'item_id'); } } if (!empty($r['reveal'])) { switch ($r['reveal']) { case 'no_hidden': $rel_items = pf_get_relationships_for_user('archive', get_current_user_id()); break; } if (!empty($rel_items)) { $posts_in = wp_list_pluck($rel_items, 'item_id'); if (!empty($post_args['post__in'])) { $post_args['post__in'] = array_merge($post_args['post__in'], $posts_in); } else { $post_args['post__in'] = $posts_in; } } } if (!empty($r['exclude_archived'])) { $archived = pf_get_relationships_for_user('archive', get_current_user_id()); $post_args['post__not_in'] = wp_list_pluck($archived, 'item_id'); } if (!empty($r['search_terms'])) { /* * Quote so as to get only exact matches. This is for * backward compatibility - might want to remove it for * a more flexible search. */ $post_args['s'] = '"' . $r['search_terms'] . '"'; } if (isset($_GET['feed'])) { $post_args['post_parent'] = $_GET['feed']; } elseif (isset($_GET['folder'])) { $parents_in_folder = new WP_Query(array('post_type' => pressforward()->pf_feeds->post_type, 'fields' => 'ids', 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'tax_query' => array(array('taxonomy' => pressforward()->pf_feeds->tag_taxonomy, 'field' => 'term_id', 'terms' => $_GET['folder'])))); #var_dump('<pre>'); var_dump($parents_in_folder); die(); $post_args['post_parent__in'] = $parents_in_folder->posts; } $feed_items = new WP_Query($post_args); $feedObject = array(); $c = 0; foreach ($feed_items->posts as $post) { $post_id = $post->ID; $item_id = get_post_meta($post_id, 'item_id', true); $source_title = get_post_meta($post_id, 'source_title', true); $item_date = get_post_meta($post_id, 'item_date', true); $item_author = get_post_meta($post_id, 'item_author', true); $item_link = get_post_meta($post_id, 'item_link', true); $item_feat_img = get_post_meta($post_id, 'item_feat_img', true); $item_wp_date = get_post_meta($post_id, 'item_wp_date', true); $item_tags = get_post_meta($post_id, 'item_tags', true); $source_repeat = get_post_meta($post_id, 'source_repeat', true); $readable_status = get_post_meta($post_id, 'readable_status', true); $contentObj = new pf_htmlchecker($post->post_content); $item_content = $contentObj->closetags($post->post_content); $feedObject['rss_archive_' . $c] = pf_feed_object($post->post_title, $source_title, $item_date, $item_author, $item_content, $item_link, $item_feat_img, $item_id, $item_wp_date, $item_tags, date('o-m-d\\TH:i:sO', strtotime($post->post_date)), $source_repeat, $post_id, $readable_status); $c++; } return $feedObject; }
$archived_status_string = ''; $archived_user_string_match = 'archived_' . $current_user_id; foreach ($archived_status as $user_archived_status) { if ($user_archived_status == $archived_user_string_match) { $archived_status_string = 'archived'; $dependent_style = 'display:none;'; } } } elseif (1 == pf_get_relationship_value('archive', $nom_id, $user_id)) { $archived_status_string = 'archived'; $dependent_style = 'display:none;'; } else { $dependent_style = ''; $archived_status_string = ''; } $item = pf_feed_object(get_the_title(), get_post_meta($nom_id, 'source_title', true), $date_posted, $item_authorship, get_the_content(), $nom_permalink, get_the_post_thumbnail($nom_id), $rss_item_id, get_post_meta($nom_id, 'item_wp_date', true), $nom_tags, $date_nomed, $source_repeat, $nom_id, '1'); $this->form_of_an_item($item, $c, 'nomination', $metadata); /** echo '<article class="feed-item entry nom-container ' . $archived_status_string . pf_nom_class_tagger(array($submitter_slug, $nom_id, $item_authorship, $nom_tag_slugs, $nominators, $nomed_tag_slugs, $rss_item_id )) . '" id="' . get_the_ID() . '" style="' . $dependent_style . '" tabindex="' . $c . '">'; ?> <header> <?php echo '<h1 class="item_title"><a href="#modal-' . get_the_ID() . '" class="item-expander" role="button" data-toggle="modal" data-backdrop="false">' . get_the_title() . '</a></h1>'; ?> <div class="sortable-hidden-meta" style="display:none;"> <?php _e('UNIX timestamp from source RSS', 'pf'); echo ': <span class="sortable_source_timestamp">' . $timestamp_item_posted . '</span><br />'; _e('UNIX timestamp last modified', 'pf'); echo ': <span class="sortable_mod_timestamp">' . $timestamp_nom_last_modified . '</span><br />'; _e('UNIX timestamp date nominated', 'pf'); echo ': <span class="sortable_nom_timestamp">' . $timestamp_unix_date_nomed . '</span><br />';