/** * 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; }
function pf_noms_excerpt($text) { $text = apply_filters('the_content', $text); $text = str_replace('\\]\\]\\>', ']]>', $text); $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text); $contentObj = new pf_htmlchecker($text); $text = $contentObj->closetags($text); $text = strip_tags($text, '<p>'); $excerpt_length = 310; $words = explode(' ', $text, $excerpt_length + 1); if (count($words) > $excerpt_length) { array_pop($words); array_push($words, '...'); $text = implode(' ', $words); } return $text; }
/** * Essentially the PF 'loop' template. * $item = the each of the foreach * $c = count. * $format = format changes, to be used later or by plugins. **/ public function form_of_an_item($item, $c, $format = 'standard', $metadata = array()) { global $current_user; get_currentuserinfo(); if ('' !== get_option('timezone_string')) { //Allows plugins to introduce their own item format output. date_default_timezone_set(get_option('timezone_string')); } if (has_action('pf_output_items')) { do_action('pf_output_items', $item, $c, $format); return; } $itemTagsArray = explode(",", $item['item_tags']); $itemTagClassesString = ''; $user_id = $current_user->ID; foreach ($itemTagsArray as $itemTag) { $itemTagClassesString .= pf_slugger($itemTag, true, false, true); $itemTagClassesString .= ' '; } if ($format === 'nomination') { $feed_ited_id = $metadata['item_id']; $id_for_comments = $metadata['item_feed_post_id']; $id_for_comments = $metadata['item_feed_post_id']; $readStat = pf_get_relationship_value('read', $id_for_comments, $user_id); if (!$readStat) { $readClass = ''; } else { $readClass = 'article-read'; } if (!isset($metadata['nom_id']) || empty($metadata['nom_id'])) { $metadata['nom_id'] = md5($item['item_title']); } if (empty($id_for_comments)) { $id_for_comments = $metadata['nom_id']; } if (empty($metadata['item_id'])) { $metadata['item_id'] = md5($item['item_title']); } } else { $feed_ited_id = $item['item_id']; $id_for_comments = $item['post_id']; } $archive_status = pf_get_relationship_value('archive', $id_for_comments, wp_get_current_user()->ID); if (isset($_GET['pf-see'])) { } else { $_GET['pf-see'] = false; } if ($archive_status == 1 && 'archive-only' != $_GET['pf-see']) { $archived_status_string = 'archived'; $dependent_style = 'display:none;'; } elseif ($format === 'nomination' && 1 == pf_get_relationship_value('archive', $metadata['nom_id'], $user_id) && 'archive-only' != $_GET['pf-see']) { $archived_status_string = 'archived'; $dependent_style = 'display:none;'; } else { $dependent_style = ''; $archived_status_string = ''; } if ($format === 'nomination') { #$item = array_merge($metadata, $item); #var_dump($item); echo '<article class="feed-item entry nom-container ' . $archived_status_string . ' ' . get_pf_nom_class_tags(array($metadata['submitters'], $metadata['nom_id'], $metadata['authors'], $metadata['nom_tags'], $metadata['item_tags'], $metadata['item_id'])) . ' ' . $readClass . '" id="' . $metadata['nom_id'] . '" style="' . $dependent_style . '" tabindex="' . $c . '" pf-post-id="' . $metadata['nom_id'] . '" pf-item-post-id="' . $id_for_comments . '" pf-feed-item-id="' . $metadata['item_id'] . '" pf-schema="read" pf-schema-class="article-read">'; } else { $id_for_comments = $item['post_id']; $readStat = pf_get_relationship_value('read', $id_for_comments, $user_id); if (!$readStat) { $readClass = ''; } else { $readClass = 'article-read'; } echo '<article class="feed-item entry ' . pf_slugger($item['source_title'], true, false, true) . ' ' . $itemTagClassesString . ' ' . $readClass . '" id="' . $item['item_id'] . '" tabindex="' . $c . '" pf-post-id="' . $item['post_id'] . '" pf-feed-item-id="' . $item['item_id'] . '" pf-item-post-id="' . $id_for_comments . '" >'; } $readStat = pf_get_relationship_value('read', $id_for_comments, $user_id); echo '<div class="box-controls">'; if (current_user_can('manage_options')) { echo '<i class="icon-remove-sign pf-item-remove" pf-item-post-id="' . $id_for_comments . '" title="Delete"></i>'; } echo '<i class="icon-eye-close hide-item pf-item-archive schema-archive schema-actor" pf-item-post-id="' . $id_for_comments . '" title="Hide" pf-schema="archive"></i>'; if (!$readStat) { $readClass = ''; } else { $readClass = 'marked-read'; } echo '<i class="icon-ok-sign schema-read schema-actor schema-switchable ' . $readClass . '" pf-item-post-id="' . $id_for_comments . '" pf-schema="read" pf-schema-class="marked-read" title="Mark as Read"></i>'; echo '</div>'; ?> <header> <?php echo '<h1 class="item_title"><a href="#modal-' . $item['item_id'] . '" class="item-expander schema-actor" role="button" data-toggle="modal" data-backdrop="false" pf-schema="read" pf-schema-targets="schema-read">' . self::display_a($item['item_title'], 'title') . '</a></h1>'; echo '<p class="source_title">' . self::display_a($item['source_title'], 'source') . '</p>'; if ($format === 'nomination') { ?> <div class="sortable-hidden-meta" style="display:none;"> <?php _e('UNIX timestamp from source RSS', 'pf'); echo ': <span class="sortable_source_timestamp sortableitemdate">' . $metadata['timestamp_item_posted'] . '</span><br />'; _e('UNIX timestamp last modified', 'pf'); echo ': <span class="sortable_mod_timestamp">' . $metadata['timestamp_nom_last_modified'] . '</span><br />'; _e('UNIX timestamp date nominated', 'pf'); echo ': <span class="sortable_nom_timestamp">' . $metadata['timestamp_unix_date_nomed'] . '</span><br />'; _e('Slug for origin site', 'pf'); echo ': <span class="sortable_origin_link_slug">' . $metadata['source_slug'] . '</span><br />'; //Add an action here for others to provide additional sortables. echo '</div>'; } # Let's build an info box! //http://nicolasgallagher.com/pure-css-speech-bubbles/ $urlArray = parse_url($item['item_link']); $sourceLink = 'http://' . $urlArray['host']; //http://nicolasgallagher.com/pure-css-speech-bubbles/demo/ $ibox = '<div class="feed-item-info-box" id="info-box-' . $item['item_id'] . '">'; $ibox .= ' ' . __('Feed', 'pf') . ': <span class="feed_title">' . $item['source_title'] . '</span><br /> ' . __('Posted', 'pf') . ': <span class="feed_posted">' . date('M j, Y; g:ia', strtotime($item['item_date'])) . '</span><br /> ' . __('Retrieved', 'pf') . ': <span class="item_meta item_meta_added_date">' . date('M j, Y; g:ia', strtotime($item['item_added_date'])) . '</span><br /> ' . __('Authors', 'pf') . ': <span class="item_authors">' . $item['item_author'] . '</span><br /> ' . __('Origin', 'pf') . ': <span class="source_name"><a target ="_blank" href="' . $sourceLink . '">' . $sourceLink . '</a></span><br /> ' . __('Original Item', 'pf') . ': <span class="source_link"><a href="' . $item['item_link'] . '" class="item_url" target ="_blank">' . $item['item_title'] . '</a></span><br /> ' . __('Tags', 'pf') . ': <span class="item_tags">' . $item['item_tags'] . '</span><br /> ' . __('Times repeated in source', 'pf') . ': <span class="feed_repeat sortable_sources_repeat">' . $item['source_repeat'] . '</span><br /> '; if ($format === 'nomination') { $ibox .= __('Number of nominations received', 'pf') . ': <span class="sortable_nom_count">' . $metadata['nom_count'] . '</span><br />' . __('First submitted by', 'pf') . ': <span class="first_submitter">' . $metadata['submitters'] . '</span><br />' . __('Nominated on', 'pf') . ': <span class="nominated_on">' . date('M j, Y; g:ia', strtotime($metadata['date_nominated'])) . '</span><br />'; } $ibox .= '</div>'; echo $ibox; ?> <script type="text/javascript"> var pop_title_<?php echo $item['item_id']; ?> = ''; var pop_html_<?php echo $item['item_id']; ?> = jQuery('#<?php echo 'info-box-' . $item['item_id']; ?> '); </script> <?php $this->form_of_actions_btns($item, $c, false, $format, $metadata, $id_for_comments); ?> </header> <?php //echo '<a name="' . $c . '" style="display:none;"></a>'; /** echo '<script type="text/javascript"> jQuery(window).load(function() { jQuery("#' . $item['item_id'] . '").on("show", function () { jQuery("#excerpt' . $c . '").hide("slow"); }); jQuery("#' . $item['item_id'] . '").on("hide", function () { jQuery("#excerpt' . $c . '").show("slow"); }); }); </script>'; **/ ?> <div class="content"> <?php if ($item['item_feat_img'] != '' && $format != 'nomination') { echo '<div style="float:left; margin-right: 10px; margin-bottom: 10px;"><img src="' . $item['item_feat_img'] . '"></div>'; } ?> <div style="display:none;"> <?php echo '<div class="item_meta item_meta_date">Published on ' . $item['item_date'] . ' by <span class="item-authorship">' . $item['item_author'] . '</span>.</div>'; echo 'Unix timestamp for item date:<span class="sortableitemdate">' . strtotime($item['item_date']) . '</span> and for added to feed date <span class="sortablerssdate">' . strtotime($item['item_added_date']) . '</span>.'; ?> </div> <?php echo '<div class="item_excerpt" id="excerpt' . $c . '">'; if ($format === 'nomination') { echo '<p>' . pf_noms_excerpt($item['item_content']) . '</p>'; } else { echo '<p>' . self::display_a(pf_feed_excerpt($item['item_content']), 'graf') . '</p>'; } echo '</div>'; /** echo '<div id="collapse' . $c . '" class="accordion-body collapse">'; echo '<div class="accordion-inner">'; echo '<div class="row-fluid">'; echo '<div class="span12 item_content">'; echo '<div>' . $item['item_content'] . '</div>'; echo '<br />'; echo '<a target="_blank" href="' . $item['item_link'] . '">' . __('Read More', 'pf') . '</a>'; echo '<br />'; echo '<strong class="item-tags">' . __('Item Tags', 'pf') . '</strong>: ' . $item['item_tags'] . '.'; echo '<br />'; echo '</div><!-- end item_content span12 -->'; echo '</div><!-- End row-fluid -->'; echo '</div>'; echo '</div>'; //print_r($item); //print_r($ent = htmlentities($item['item_content'])); //print_r(html_entity_decode($ent)); **/ ?> </div><!-- End content --> <footer> <p class="pubdate"><?php echo date('F j, Y; g:i a', strtotime($item['item_date'])); ?> </p> </footer> <?php //Allows plugins to introduce their own item format output. if (has_action('pf_output_modal')) { do_action('pf_output_modal', $item, $c, $format); } else { ?> <!-- Begin Modal --> <div id="modal-<?php echo $item['item_id']; ?> " class="modal hide fade pfmodal" tabindex="-1" role="dialog" aria-labelledby="modal-<?php echo $item['item_id']; ?> -label" aria-hidden="true" pf-item-id="<?php echo $item['item_id']; ?> " pf-post-id="<?php echo $item['post_id']; ?> " pf-readability-status="<?php echo $item['readable_status']; ?> "> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button> <div class="modal-mobile-nav pull-right hidden-desktop"> <div class="mobile-goPrev pull-left"> </div> <div class="mobile-goNext pull-right"> </div> </div> <h3 id="modal-<?php echo $item['item_id']; ?> -label" class="modal_item_title source_title"><?php echo $item['item_title']; ?> </h3> </div> <div class="row-fluid modal-body-row"> <div class="modal-body span9" id="modal-body-<?php echo $item['item_id']; ?> "> <?php $contentObj = new pf_htmlchecker($item['item_content']); $text = $contentObj->closetags($item['item_content']); echo $text; ?> </div> <div class="modal-sidebar span3"> <div class="goPrev modal-side-item row-fluid"> </div> <div class="modal-comments modal-side-item row-fluid"> </div> <div class="goNext modal-side-item row-fluid"> </div> </div> </div> <div class="modal-footer"> <div class="row-fluid"> <div class="pull-left original-link"> <a target="_blank" href="<?php echo $item['item_link']; ?> "><?php _e('Read Original', 'pf'); ?> </a> <?php if ($format != 'nomination') { ?> | <a class="modal-readability-reset" target="#readable" href="<?php echo $item['item_link']; ?> " pf-item-id="<?php echo $item['item_id']; ?> " pf-post-id="<?php echo $item['post_id']; ?> " pf-modal-id="#modal-<?php echo $item['item_id']; ?> "><?php _e('Reset Readability', 'pf'); ?> </a> <?php } ?> </div> <div class="pull-right"><?php $this->form_of_actions_btns($item, $c, true, $format, $metadata, $id_for_comments); ?> </div><?php ?> </div> <div class="item-tags pull-left row-fluid"> <?php echo '<em>' . __('Source', 'pf') . ': ' . $item['source_title'] . '</em> | '; echo '<strong>' . __('Item Tags', 'pf') . '</strong>: ' . $item['item_tags']; ?> </div> </div> </div> <!-- End Modal --> </article><!-- End article --> <?php } }
/** * 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; }
/** * Runs a URL through Readability and hands back the stripped content * * @since 1.7 * @see http://www.keyvan.net/2010/08/php-readability/ * @param $url */ public static function readability_object($url) { set_time_limit(0); $url = pf_de_https($url); $url = str_replace('&', '&', $url); //print_r($url); print_r(' - Readability<br />'); // change from Boone - use wp_remote_get() instead of file_get_contents() $request = wp_remote_get($url, array('timeout' => '30')); if (is_wp_error($request)) { $content = 'error-secured'; //print_r($request); die(); return $content; } if (!empty($request['body'])) { $html = $request['body']; } else { $content = false; return $content; } //check if tidy exists to clean up the input. if (function_exists('tidy_parse_string')) { $tidy = tidy_parse_string($html, array(), 'UTF8'); $tidy->cleanRepair(); $html = $tidy->value; } // give it to Readability $readability = new Readability($html, $url); // print debug output? // useful to compare against Arc90's original JS version - // simply click the bookmarklet with FireBug's // console window open $readability->debug = false; // convert links to footnotes? $readability->convertLinksToFootnotes = false; // process it $result = $readability->init(); if ($result) { $content = $readability->getContent()->innerHTML; //$content = $contentOut->innerHTML; //if we've got tidy, let's use it. if (function_exists('tidy_parse_string')) { $tidy = tidy_parse_string($content, array('indent' => true, 'show-body-only' => true), 'UTF8'); $tidy->cleanRepair(); $content = $tidy->value; } $content = balanceTags($content, true); $content = ent2ncr($content); $content = convert_chars($content); $domRotated = 0; $dom = new domDocument('1.0', 'utf-8'); $dom->preserveWhiteSpace = true; $dom->substituteEntities = true; $dom->resolveExternals = true; $dom->loadXML('<fullContent>' . $content . '</fullContent>'); $images = $dom->getElementsByTagName('img'); foreach ($images as $image) { $img = $image->getAttribute('src'); if (strpos($img, '/') === 0 || strpos($img, 'http') != 0) { $urlArray = parse_url($url); if (strpos($img, 'http') != 0) { $urlBase = 'http://' . $urlArray['host'] . '/'; } else { $urlBase = 'http://' . $urlArray['host']; } if (!is_wp_error(wp_remote_head($urlBase . $img))) { $image->setAttribute('src', $urlBase . $img); $domRotated++; } elseif (!is_wp_error(wp_remote_head($url . $img))) { $image->setAttribute('src', $url . $img); $domRotated++; } else { $image->parentNode->removeChild($image); $domRotated++; } } } if ($domRotated > 0) { $content = $dom->saveXML(); $rel = '(<\\?xml version="1\\.0" encoding="utf-8"\\?>)'; $content = preg_replace("/" . $rel . "/is", ' ', $content); $rel = '(<\\?xml version="1\\.0"\\?>)'; $content = preg_replace("/" . $rel . "/is", ' ', $content); } if (120 > strlen($content)) { $content = false; } # $content = stripslashes($content); # print_r($content); # var_dump($content); die(); // this will also output doctype and comments at top level # $content = ""; # foreach($dom->childNodes as $node){ # $content .= $dom->saveXML($node)."\n"; # } } else { # If Readability can't get the content, send back a FALSE to loop with. $content = false; # and let's throw up an error via AJAX as well, so we know what's going on. //print_r($url . ' fails Readability.<br />'); } if ($content != false) { $contentObj = new pf_htmlchecker($content); $content = $contentObj->closetags($content); } return $content; }