Forgoes a substantial amount of data sanitization in favor of speed. This
turns SimplePie into a dumb parser of feeds.
public set_stupidly_fast ( boolean $set = false ) | ||
$set | boolean | Whether to set them or not |
function rss_to_activity_streams($data) { // $feed = new SimplePie(); $feed->set_raw_data($data); // unset($data); // $feed->set_stupidly_fast(true); $feed->init(); $feed->handle_content_type(); // $id = md5($url); $title = 'submit'; $link = 'http://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; $activityStream = new ActivityStreamsDoc($id, $title, $link); // foreach ($feed->get_items() as $item) { $author = $item->get_author(); if (!$author) { $author = $feed->get_author(); } // $activityStream->entry($item->get_id(), date("r", $item->get_date()), $author ? $author->get_name() : null, $author ? $author->get_link() : null, $item->get_title(), $item->get_permalink(), $item->get_description()); } return $activityStream; }
public function update() { $feed = new SimplePie(); $feed->set_feed_url('https://github.com/' . $this->user . '.atom'); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->init(); foreach ($feed->get_items() as $item) { $id = $item->get_id(); $title = substr($item->get_title(), strlen($this->user) + 1); $title = sprintf('<a href="%s">%s</a>', $item->get_permalink(), $title); $data = array( 'id' => $id, 'title' => $title, 'content' => $item->get_content(), 'source' => 'github', 'timestamp' => $item->get_date('U') ); /*$type = substr($id, 20, strpos($id, '/')); switch ($type) { case 'PushEvent': case 'IssueCommentEvent': case 'PullRequestEvent': case 'IssuesEvent': default: // no-op, standard stuff will work fine break; }*/ Murray_Entry::create($data); } }
public function update() { $feed = new SimplePie(); $feed->set_feed_url('http://api.twitter.com/1/statuses/user_timeline.atom?screen_name=' . $this->user); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->init(); foreach ($feed->get_items() as $item) { $title = substr($item->get_title(), strlen($this->user) + 2); $title = sprintf('<blockquote>%s</blockquote>', $title); $data = array( 'id' => $item->get_id(), 'title' => Twitter_Autolink::create($title) ->setTarget(false) ->setExternal(false) ->addLinks(), 'content' => '', 'source' => 'twitter', 'timestamp' => $item->get_date('U') ); Murray_Entry::create($data); } }
/** * _createSimplePie * * @param string &$feed Params * * @return object */ private function _createSimplePie(&$feed) { include_once JPATH_AUTOTWEET . '/libs/SimplePie_autoloader.php'; // Process the feed with SimplePie $simplePie = new SimplePie(); $simplePie->set_feed_url($feed->xtform->get('url')); $simplePie->set_stupidly_fast(true); $simplePie->enable_order_by_date(true); if ($feed->xtform->get('encoding', 'utf-8')) { $simplePie->set_input_encoding($feed->xtform->get('encoding')); } if ($feed->xtform->get('force_fsockopen')) { $simplePie->force_fsockopen(true); } $use_sp_cache = EParameter::getComponentParam(CAUTOTWEETNG, 'use_sp_cache', true); if ($use_sp_cache && is_writable(JPATH_CACHE)) { $simplePie->set_cache_location(JPATH_CACHE); $simplePie->enable_cache(true); } else { $simplePie->enable_cache(false); } $set_sp_timeout = EParameter::getComponentParam(CAUTOTWEETNG, 'set_sp_timeout', 10); if ($set_sp_timeout) { $simplePie->set_timeout((int) $set_sp_timeout); } $simplePie->init(); return $simplePie; }
public function addAllGroupFeed() { if (OW::getConfig()->getValue('grouprss', 'disablePosting') == '1') { return; } $commentService = BOL_CommentService::getInstance(); $newsfeedService = NEWSFEED_BOL_Service::getInstance(); $router = OW::getRouter(); $displayText = OW::getLanguage()->text('grouprss', 'feed_display_text'); $location = OW::getConfig()->getValue('grouprss', 'postLocation'); include_once 'autoloader.php'; $allFeeds = $this->feeddao->findAll(); foreach ($allFeeds as $feed) { $simplefeed = new SimplePie(); $simplefeed->set_feed_url($feed->feedUrl); $simplefeed->set_stupidly_fast(true); $simplefeed->enable_cache(false); $simplefeed->init(); $simplefeed->handle_content_type(); $items = $simplefeed->get_items(0, $feed->feedCount); foreach ($items as $item) { $content = UTIL_HtmlTag::autoLink($item->get_content()); if ($location == 'wall' && !$this->isDuplicateComment($feed->groupId, $content)) { $commentService->addComment('groups_wal', $feed->groupId, 'groups', $feed->userId, $content); } if (trim($location) == 'newsfeed' && !$this->isDuplicateFeed($feed->groupId, $content)) { $statusObject = $newsfeedService->saveStatus('groups', (int) $feed->groupId, $content); $content = UTIL_HtmlTag::autoLink($content); $action = new NEWSFEED_BOL_Action(); $action->entityId = $statusObject->id; $action->entityType = "groups-status"; $action->pluginKey = "newsfeed"; $data = array("string" => $content, "content" => "[ph:attachment]", "view" => array("iconClass" => "ow_ic_comment"), "attachment" => array("oembed" => null, "url" => null, "attachId" => null), "data" => array("userId" => $feed->userId), "actionDto" => null, "context" => array("label" => $displayText, "url" => $router->urlForRoute('groups-view', array('groupId' => $feed->groupId)))); $action->data = json_encode($data); $actionObject = $newsfeedService->saveAction($action); $activity = new NEWSFEED_BOL_Activity(); $activity->activityType = NEWSFEED_BOL_Service::SYSTEM_ACTIVITY_CREATE; $activity->activityId = $feed->userId; $activity->actionId = $actionObject->id; $activity->privacy = NEWSFEED_BOL_Service::PRIVACY_EVERYBODY; $activity->userId = $feed->userId; $activity->visibility = NEWSFEED_BOL_Service::VISIBILITY_FULL; $activity->timeStamp = time(); $activity->data = json_encode(array()); $activityObject = $newsfeedService->saveActivity($activity); $newsfeedService->addActivityToFeed($activity, 'groups', $feed->groupId); } } $simplefeed->__destruct(); unset($feed); } }
protected function update_from_feed($url, $title_format, $title_start = 0) { $feed = new SimplePie(); $feed->set_feed_url($url); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->init(); foreach ($feed->get_items() as $item) { $title = substr($item->get_title(), $title_start); $title = sprintf($title_format, $item->get_permalink(), $title); $data = array( 'id' => $item->get_id(), 'title' => $title, 'content' => '', 'source' => 'reddit', 'timestamp' => $item->get_date('U') ); Murray_Entry::create($data); } }
public function update() { $feed = new SimplePie(); $feed->set_feed_url('http://ws.audioscrobbler.com/1.0/user/' . $this->user . '/recenttracks.rss'); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->init(); foreach ($feed->get_items() as $item) { $title = sprintf('listened to <a href="%s">%s</a>', $item->get_permalink(), $item->get_title()); $data = array( 'id' => $item->get_id(), 'title' => $title, 'content' => '', 'source' => 'lastfm', 'timestamp' => $item->get_date('U') ); Murray_Entry::create($data); } }
/** * Add a new feed to the database * * Adds the specified feed name and URL to the global <tt>$data</tt> array. If no name is set * by the user, it fetches one from the feed. If the URL specified is a HTML page and not a * feed, it lets SimplePie do autodiscovery and uses the XML url returned. * * @since 1.0 * @uses $data Contains all feeds, this is what we add the new feed to * * @param string $url URL to feed or website (if autodiscovering) * @param string $name Title/Name of feed * @param string $cat Category to add feed to * @param bool $return If true, return the new feed's details. Otherwise, use the global $data array * @return bool True if succeeded, false if failed */ function add_feed($url, $name = '', $cat = 'default', $return = false) { if (empty($url)) { throw new Exception(_r("Couldn't add feed: No feed URL supplied"), Errors::get_code('admin.feeds.no_url')); } require_once LILINA_INCPATH . '/contrib/simplepie/simplepie.inc'; $feed_info = new SimplePie(); $feed_info->set_useragent('Lilina/' . LILINA_CORE_VERSION . '; (' . get_option('baseurl') . '; http://getlilina.org/; Allow Like Gecko) SimplePie/' . SIMPLEPIE_BUILD); $feed_info->set_stupidly_fast(true); $feed_info->enable_cache(false); $feed_info->set_feed_url(urldecode($url)); $feed_info->init(); $feed_error = $feed_info->error(); $feed_url = $feed_info->subscribe_url(); if (!empty($feed_error)) { //No feeds autodiscovered; throw new Exception(sprintf(_r("Couldn't add feed: %s is not a valid URL or the server could not be accessed. Additionally, no feeds could be found by autodiscovery."), $url), Errors::get_code('admin.feeds.invalid_url')); } if (empty($name)) { //Get it from the feed $name = $feed_info->get_title(); } if ($return === true) { return array('feed' => $feed_url, 'url' => $feed_info->get_link(), 'name' => $name, 'cat' => $cat); } global $data; $data['feeds'][] = array('feed' => $feed_url, 'url' => $feed_info->get_link(), 'name' => $name, 'cat' => $cat); save_feeds(); return sprintf(_r('Added feed "%1$s"'), $name); }
protected function upgrade_single($feed) { require_once LILINA_INCPATH . '/contrib/simplepie.class.php'; $sp = new SimplePie(); $sp->set_useragent(LILINA_USERAGENT . ' SimplePie/' . SIMPLEPIE_BUILD); $sp->set_stupidly_fast(true); $sp->set_cache_location(get_option('cachedir')); $sp->set_favicon_handler(get_option('baseurl') . '/lilina-favicon.php'); $sp->set_feed_url($feed['feed']); $sp->init(); if (!isset($feed['icon'])) { $feed['icon'] = $sp->get_favicon(); } return $feed; }
function lmm_dashboard_widget() { global $wpdb; $lmm_options = get_option('leafletmapsmarker_options'); $table_name_markers = $wpdb->prefix . 'leafletmapsmarker_markers'; $widgets = get_option('dashboard_widget_options'); $widget_id = 'lmm-admin-dashboard-widget'; $number_of_markers = isset($widgets[$widget_id]) && isset($widgets[$widget_id]['items']) ? absint($widgets[$widget_id]['items']) : 4; $result = $wpdb->get_results($wpdb->prepare("SELECT `id`,`markername`,`icon`,`createdon`,`createdby` FROM `{$table_name_markers}` ORDER BY `createdon` desc LIMIT %d", $number_of_markers), ARRAY_A); echo '<p><a style="background:#f99755;display:block;padding:5px;text-decoration:none;color:#2702c6;text-align:center;" href="' . LEAFLET_WP_ADMIN_URL . 'admin.php?page=leafletmapsmarker_pro_upgrade">' . __('Upgrade to pro version for even more features - click here to find out how you can start a free 30-day-trial easily', 'lmm') . '</a><hr style="border:0;height:1px;background-color:#d8d8d8;"/></p>'; if ($result != NULL) { echo '<table style="margin-bottom:5px;"><tr>'; foreach ($result as $row) { $icon = $row['icon'] == NULL ? LEAFLET_PLUGIN_URL . 'leaflet-dist/images/marker.png' : LEAFLET_PLUGIN_ICONS_URL . '/' . $row['icon']; echo '<td><a href="' . LEAFLET_WP_ADMIN_URL . 'admin.php?page=leafletmapsmarker_marker&id=' . $row['id'] . '" title="' . esc_attr__('edit marker', 'lmm') . '"><img src="' . $icon . '" style="width:80%;"></a>'; echo '<td style="vertical-align:top;line-height:1.2em;">'; echo '<a href="' . LEAFLET_WP_ADMIN_URL . 'admin.php?page=leafletmapsmarker_marker&id=' . $row['id'] . '" title="' . esc_attr__('edit marker', 'lmm') . '">' . htmlspecialchars(stripslashes($row['markername'])) . '</a><br/>' . __('created on', 'lmm') . ' ' . date("Y-m-d - h:m", strtotime($row['createdon'])) . ', ' . __('created by', 'lmm') . ' ' . $row['createdby']; echo '</td></tr>'; } echo '</table>'; } else { echo '<p style="margin-bottom:5px;">' . __('No marker created yet', 'lmm') . '</p>'; } if (!isset($widgets[$widget_id]['blogposts'])) { $show_rss = 1; } else { if (isset($widgets[$widget_id]['blogposts']) && $widgets[$widget_id]['blogposts'] == 1) { $show_rss = 0; } else { $show_rss = 1; } } //info: use custom name to prevent false malware detection by WordFence plugin function lmm_spc_custom_name($string) { return 'mapsmarker-dashboard-widget-rss-item-cache'; } if ($show_rss == 1) { require_once ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'class-simplepie.php'; $feed = new SimplePie(); if (file_exists(LEAFLET_PLUGIN_ICONS_DIR . DIRECTORY_SEPARATOR . 'readme-icons.txt')) { $feed->enable_cache(true); $feed->set_cache_location($location = LEAFLET_PLUGIN_ICONS_DIR); $feed->set_cache_name_function('lmm_spc_custom_name'); $feed->set_cache_duration(86400); } else { $feed->enable_cache(false); } $feed->set_feed_url('http://feeds.feedburner.com/MapsMarkerPro'); $feed->set_stupidly_fast(true); $feed->enable_order_by_date(true); $feed->init(); $feed->handle_content_type(); echo '<hr style="border:0;height:1px;background-color:#d8d8d8;"/><strong><p>' . __('Latest blog posts from www.mapsmarker.com', 'lmm') . '</p></strong>'; if ($feed->get_items() == NULL) { $blogpost_url = '<a href="https://www.mapsmarker.com/news" target="_blank">https://www.mapsmarker.com/news</a>'; echo sprintf(__('Feed could not be retrieved, please try again later or read the latest blog posts at %s', 'lmm'), $blogpost_url); } foreach ($feed->get_items(0, 3) as $item) { echo '<p style="margin:0.5em 0;">' . $item->get_date('j F Y') . ': <strong><a href="' . $item->get_permalink() . '?ref=dashboard">' . $item->get_title() . '</a></strong></p>' . PHP_EOL; } echo '<p><a style="text-decoration:none;" href="https://www.mapsmarker.com" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-website-home.png" width="16" height="16" alt="mapsmarker.com"> MapsMarker.com</a> <a href="' . LEAFLET_WP_ADMIN_URL . 'admin.php?page=leafletmapsmarker_pro_upgrade' . '"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-up16.png" width="16" height="16" alt="upgrade to pro"> ' . __('Upgrade to Pro', 'lmm') . '</a> <a style="text-decoration:none;" title="' . esc_attr__('MapsMarker affiliate program - sign up now and receive commissions up to 50%!', 'lmm') . '" href="https://www.mapsmarker.com/affiliates" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-affiliates.png" width="16" height="16" alt="affiliates"> ' . __('Affiliates', 'lmm') . '</a> <a style="text-decoration:none;" title="' . esc_attr__('MapsMarker reseller program - re-sell with a 20% discount!', 'lmm') . '" href="https://www.mapsmarker.com/reseller" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-resellers.png" width="16" height="16" alt="resellers"> ' . __('Resellers', 'lmm') . '</a> <a style="text-decoration:none;" href="https://www.mapsmarker.com/reviews" target="_blank" title="' . esc_attr__('please rate this plugin on wordpress.org', 'lmm') . '"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-star.png" width="16" height="16" alt="ratings"> ' . __('rate plugin', 'lmm') . '</a> <a href="https://translate.mapsmarker.com/projects/lmm" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-translations.png" width="16" height="16" alt="translations"> ' . __('translations', 'lmm') . '</a> <a href="https://twitter.com/mapsmarker" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-twitter.png" width="16" height="16" alt="twitter"> Twitter</a> <a href="https://facebook.com/mapsmarker" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-facebook.png" width="16" height="16" alt="facebook"> Facebook</a> <a href="https://www.mapsmarker.com/+" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-google-plus.png" width="16" height="16" alt="google+"> Google+</a> <a style="text-decoration:none;" href="https://www.mapsmarker.com/changelog" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-changelog-header.png" width="16" height="16" alt="changelog"> ' . __('Changelog', 'lmm') . '</a> <a href="https://feeds.feedburner.com/MapsMarker" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-rss.png" width="16" height="16" alt="rss"> RSS</a> <a href="http://feedburner.google.com/fb/a/mailverify?uri=MapsMarker" target="_blank"><img src="' . LEAFLET_PLUGIN_URL . 'inc/img/icon-rss-email.png" width="16" height="16" alt="rss-email"> ' . __('E-Mail', 'lmm') . '</a></p>'; } }
/** * Constructor * */ function GCal() { // depricated //global $TMPL; $this->EE =& get_instance(); /** --------------------------------------- /** Fetch parameters /** ---------------------------------------*/ $this->gcal_id = ($gcal_id = $this->EE->TMPL->fetch_param('gcal_id')) === FALSE ? $this->gcal_id : html_entity_decode($gcal_id); $this->refresh = ($refresh = $this->EE->TMPL->fetch_param('refresh')) === FALSE ? $this->refresh : $refresh; $this->limit = ($limit = $this->EE->TMPL->fetch_param('limit')) === FALSE ? $this->limit : $limit; $this->show_future = ($show_future = $this->EE->TMPL->fetch_param('show_future')) === FALSE ? $this->show_future : $show_future; $this->orderby = ($orderby = $this->EE->TMPL->fetch_param('orderby')) === FALSE ? $this->orderby : $orderby; $this->sort_order = ($sort_order = $this->EE->TMPL->fetch_param('sort_order')) === FALSE ? $this->sort_order : $sort_order; $this->startmin = ($startmin = $this->EE->TMPL->fetch_param('from')) === FALSE ? $this->startmin : $startmin; $this->startmax = ($startmax = $this->EE->TMPL->fetch_param('to')) === FALSE ? $this->startmax : $startmax; if (strlen($this->gcal_id) < 1) { $this->EE->TMPL->log_item("GCal error: Invalid URL"); $this->return_data = ''; return; } /** --------------------------------------- /** Create the full url /** ---------------------------------------*/ $url = 'http://www.google.com/calendar/feeds/' . $this->gcal_id . '/public/full?orderby=' . $this->orderby; $url .= '&sortorder=' . $this->sort_order . '&futureevents=' . $this->show_future; if ($this->startmin != '') { $this->startmin = urlencode(date('c', strtotime($this->startmin))); $url .= '&start-min=' . $this->startmin; } if ($this->startmax != '') { $this->startmax = urlencode(date('c', strtotime($this->startmax))); $url .= '&start-max=' . $this->startmax; } /** --------------------------------------- /** Fetch the XML from Google /** ---------------------------------------*/ if (($rawxml = $this->_check_cache($url)) === FALSE) { $this->cache_expired = TRUE; $this->EE->TMPL->log_item("Fetching Google Calendar remotely"); if (function_exists('curl_init')) { $rawxml = $this->_curl_fetch($url); } else { $rawxml = $this->_fsockopen_fetch($url); } } if ($rawxml == '' or substr($rawxml, 0, 5) != "<?xml") { $this->EE->TMPL->log_item("GCal error: Unable to retreive feed from Google => " . $rawxml); $this->return_data = ''; return; } /** --------------------------------------- /** Write cache /** ---------------------------------------*/ if ($this->cache_expired == TRUE) { $this->_write_cache($rawxml, $url); } /** --------------------------------------- /** Parse the XML with SimplePie /** ---------------------------------------*/ if (!class_exists('SimplePie')) { $this->EE->TMPL->log_item("GCal error: this plugin requires SimplePie v1.0 or greater"); $this->return_data = ''; return; } $feed = new SimplePie(); //$cache_dir = APP_CACHE.$this->cache_name.'/'; $cache_dir = APPPATH . 'cache/' . $this->cache_name . '/'; $feed->set_cache_location($cache_dir); $feed->set_stupidly_fast(TRUE); // skips some sanity checks; may not be a good idea ... ? $feed->set_feed_url($url); $feed->init(); $this->_load_events($feed); /** --------------------------------------- /** Go go go! /** ---------------------------------------*/ $this->return_data = $this->_parse_events(); }
public static function getFeedData($params) { $rssurl = str_replace("\n", ",", JString::trim($params->get('rssurl', ''))); $feedTimeout = (int) $params->get('feedTimeout', 10); $rssdateorder = (int) $params->get('rssdateorder', 1); $dformat = $params->get('dformat', '%d %b %Y %H:%M %P'); $rssperfeed = (int) $params->get('rssperfeed', 3); $textfilter = JString::trim($params->get('textfilter', '')); $pagination = (int) $params->get('pagination', 0); $totalfeeds = (int) $params->get('rssitems', 5); $filtermode = (int) $params->get('filtermode', 0); $showfeedinfo = (int) $params->get('showfeedinfo', 1); $input_encoding = JString::trim($params->get('inputencoding', '')); $showimage = (int) $params->get('rssimage', 1); $cacheTime = (int) $params->get('feedcache', 15) * 60; //minutes $orderBy = $params->get('orderby', 'date'); $tmzone = (int) $params->get('tmzone', 0) ? true : false; $cachePath = JPATH_SITE . DS . 'cache' . DS . 'mod_we_ufeed_display'; $start = $end = 0; if ($pagination) { $pagination_items = (int) $params->get('paginationitems', 5); $current_limit = modFeedShowHelper::getPage($params->get('mid', 0)); $start = ($current_limit - 1) * $pagination_items; $end = $current_limit * $pagination_items; } #Get clean array $rss_urls = @array_filter(explode(",", $rssurl)); #If only 1 link, use totalfeeds for total limit if (count($rss_urls) == 1) { $rssperfeed = $totalfeeds; } # Intilize RSS Doc if (!class_exists('SimplePie')) { jimport('simplepie.simplepie'); } //Parser Code $simplepie = new SimplePie(); $simplepie->set_cache_location($cachePath); $simplepie->set_cache_duration($cacheTime); $simplepie->set_stupidly_fast(true); $simplepie->force_feed(true); //$simplepie->force_fsockopen(false); //gives priority to CURL if is installed $simplepie->set_timeout($feedTimeout); $simplepie->set_item_limit($rssperfeed); $simplepie->enable_order_by_date(false); if ($input_encoding) { $simplepie->set_input_encoding($input_encoding); $simplepie->set_output_encoding('UTF-8'); } $simplepie->set_feed_url($rss_urls); $simplepie->init(); $rssTotalItems = (int) $simplepie->get_item_quantity($totalfeeds); if ((int) $params->get('debug', 0)) { echo "<h3>Total RSS Items:" . $rssTotalItems . "</h3>"; echo print_r($simplepie, true); #debug } if (get_class($simplepie) != 'SimplePie' || !$rssTotalItems) { return array("rsstotalitems" => 0, 'items' => false); } $feedItems = array(); #store all feeds items $counter = 1; foreach ($simplepie->get_items($start, $end) as $key => $feed) { #Word Filter if (!empty($textfilter) && $filtermode != 0) { $filter = modFeedShowHelper::filterItems($feed, $textfilter); #Include #Exclude if ($filtermode == 1 && !$filter || $filtermode == 2 && $filter) { $rssTotalItems--; continue; #Include } } $FeedValues[$key] = new stdClass(); # channel header and link $channel = $feed->get_feed(); $FeedValues[$key]->FeedTitle = $channel->get_title(); $FeedValues[$key]->FeedLink = $channel->get_link(); if ($showfeedinfo) { $FeedValues[$key]->FeedFavicon = 'http://g.etfv.co/' . urlencode($FeedValues[$key]->FeedLink); } $FeedValues[$key]->FeedDescription = $channel->get_description(); $FeedValues[$key]->FeedLogo = $channel->get_image_url(); #Item $FeedValues[$key]->ItemTitle = $feed->get_title(); $feeDateUNIX = $feed->get_date('U'); if ($feeDateUNIX < 1) { $feeDateUNIX = strtotime(trim(str_replace(",", "", $feed->get_date('')))); } $FeedValues[$key]->ItemDate = WEJM16 ? JHTML::_('date', $feeDateUNIX, $dformat, $tmzone) : JHtml::date($feeDateUNIX, $dformat, $tmzone); $FeedValues[$key]->ItemLink = $feed->get_link(); //$feed->get_permalink(); $FeedValues[$key]->ItemText = $feed->get_description(); $FeedValues[$key]->ItemFulltext = $feed->get_content(); $FeedValues[$key]->ItemEnclosure = $feed->get_enclosure(); $FeedValues[$key]->ItemEnclosures = $feed->get_enclosures(); if ($showimage) { $FeedValues[$key]->ItemImage = ""; } //for next version if ($orderBy == 'title') { $idx = str_replace(array(':', '-', '(', ')', '+', '*', ' '), '', JString::strtolower(strip_tags($FeedValues[$key]->ItemTitle))); //ORDER BY TITLE } else { $idx = $feeDateUNIX; //Order By date } if (isset($feedItems[$idx])) { $idx .= $counter; } #unique idx $feedItems[$idx] = $FeedValues[$key]; $counter++; } if ($rssdateorder == 1) { krsort($feedItems); } elseif ($rssdateorder == 2) { ksort($feedItems); } elseif ($rssdateorder == 3) { shuffle($feedItems); } if ((int) $params->get('debug', 0)) { echo "<p>Total RSS in Array:" . count($feedItems) . "</p>"; } return array("rsstotalitems" => $rssTotalItems, 'items' => $feedItems); }
/** * Test creating a very sparse post * * Only has the defaults, and nothing more * @dataProvider examplePostProvider * @param string $post Path to post template */ public function testPostFromTemplate($post) { // Grab the correct collection $available = self::getCollectionsFromDocument($this->document); $proper = null; foreach ($available as $name => $collection) { if (in_array(AtomPubHelper::AtomEntryMediaType, $collection['accepted'])) { $proper = $collection; break; } } $this->assertNotNull($proper); $collection = $proper; Gorilla::$runner->report(Gorilla_Runner::REPORT_INFO, 'Creating from ' . str_replace(Gorilla::$path, 'Gorilla', $post)); // Get the template data $data = file_get_contents($post); // Load it up $entry = AtomPubHelper_Entry::from_template($data); // Give it a random ID $entry->set_element('id', 'tag:ryanmccue.info,2012:' . sprintf("%06d%06d", rand(0, 100000), rand(0, 100000))); $entry->set_element('updated', date('c')); $headers = array('Content-Type' => AtomPubHelper::AtomEntryMediaType); // Generate a random slug (we'll check this later) $slug_num = sprintf("%06d", rand(0, 100000)); $slug = 'ape-' . $slug_num; $slug_re = '#ape.?' . $slug_num . '#i'; $headers['Slug'] = $slug; // Convert to XML $data = $entry->serialize_xml(); Gorilla::$runner->report(Gorilla_Runner::REPORT_DEBUG, "Submitting entry:\n" . $data); // And then POST it to create it $poster = Requests::post($collection['href'], $headers, $data, self::requestsOptions()); $this->assertEquals(201, $poster->status_code, 'Could not create new post: ' . $poster->body); $this->assertNotEmpty($poster->headers['location']); Gorilla::$runner->report(Gorilla_Runner::REPORT_INFO, 'Posting of new entry reported success, location: ' . $poster->headers['location']); // Check the data we got from the POST request Gorilla::$runner->report(Gorilla_Runner::REPORT_INFO, 'Examining the new entry as returned in the POST response'); $wrapped = AtomPubHelper::wrap_entry($poster->body); $sp = new SimplePie(); $sp->set_raw_data($wrapped); $sp->set_stupidly_fast(); $sp->init(); $this->assertNull($sp->error(), 'New entry is not well-formed: ' . $sp->error()); $remote_entry = $sp->get_item(0); $this->checkEntry($entry, $remote_entry); $found = false; foreach ($remote_entry->get_links() as $link) { if (preg_match($slug_re, $link) > 0) { $found = true; break; } } if ($found) { Gorilla::$runner->report(Gorilla_Runner::REPORT_INFO, 'Slug was used in server-generated URI'); } else { Gorilla::$runner->report(Gorilla_Runner::REPORT_WARNING, 'Slug not used in server-generated URI'); } // And now check at the new location! Gorilla::$runner->report(Gorilla_Runner::REPORT_INFO, 'Checking at the new location'); $new = Requests::get($poster->headers['location'], array(), array(), self::requestsOptions()); $this->assertEquals(200, $new->status_code, 'New post not found at location'); $wrapped = AtomPubHelper::wrap_entry($new->body); $sp = new SimplePie(); $sp->set_raw_data($wrapped); $sp->set_stupidly_fast(); $sp->init(); $this->assertNull($sp->error(), 'New entry is not well-formed: ' . $sp->error()); $remote_entry = $sp->get_item(0); $this->checkEntry($entry, $remote_entry); }
/** * Parses a feed with SimplePie * * @param boolean $stupidly_fast Set fast mode. Best for checks * @param integer $max Limit of items to fetch * @return SimplePie_Item Feed object **/ function fetchFeed($url, $stupidly_fast = false, $max = 0) { # SimplePie if (!class_exists('SimplePie')) { require_once WPOINC . 'simplepie/simplepie.class.php'; } $feed = new SimplePie(); $feed->enable_order_by_date(false); // thanks Julian Popov $feed->set_feed_url($url); $feed->set_item_limit($max); $feed->set_stupidly_fast($stupidly_fast); $feed->enable_cache(false); $feed->init(); $feed->handle_content_type(); return $feed; }
/** * Create a new SimplePie object * * Creates an instance of SimplePie with Items::$feeds * * @since 1.0 */ public function load() { global $lilina; require_once LILINA_INCPATH . '/contrib/simplepie/simplepie.inc'; $feed = new SimplePie(); $feed->set_useragent('Lilina/' . $lilina['core-sys']['version'] . '; (' . get_option('baseurl') . '; http://getlilina.org/; Allow Like Gecko) SimplePie/' . SIMPLEPIE_BUILD); $feed->set_stupidly_fast(true); $feed->set_cache_location(get_option('cachedir')); $feed->set_favicon_handler(get_option('baseurl') . '/lilina-favicon.php'); $feed = apply_filters('simplepie-config', $feed); $feed->set_feed_url($this->feeds); $feed->init(); /** We need this so we have something to work with. */ $feed->get_items(); if (!isset($feed->data['ordered_items'])) { $feed->data['ordered_items'] = $feed->data['items']; } /** Let's force sorting */ usort($feed->data['ordered_items'], array(&$feed, 'sort_items')); usort($feed->data['items'], array(&$feed, 'sort_items')); $this->simplepie = $feed; /** Free up memory just in case */ unset($feed); }
/** * Parses a feed with SimplePie * * @param boolean $stupidly_fast Set fast mode. Best for checks * @param integer $max Limit of items to fetch * @return SimplePie_Item Feed object **/ public static function fetchFeed($url, $stupidly_fast = false, $max = 0) { # SimplePie $cfg = get_option(WPeMatico::OPTION_KEY); if ($cfg['force_mysimplepie']) { include_once dirname(__FILE__) . '/lib/simplepie.inc.php'; } else { if (!class_exists('SimplePie')) { if (is_file(ABSPATH . WPINC . '/class-simplepie.php')) { include_once ABSPATH . WPINC . '/class-simplepie.php'; } else { if (is_file(ABSPATH . 'wp-admin/includes/class-simplepie.php')) { include_once ABSPATH . 'wp-admin/includes/class-simplepie.php'; } else { include_once dirname(__FILE__) . '/lib/simplepie.inc.php'; } } } } $feed = new SimplePie(); $feed->enable_order_by_date(false); $feed->set_feed_url($url); $feed->feed_url = rawurldecode($feed->feed_url); $feed->set_item_limit($max); $feed->set_stupidly_fast($stupidly_fast); if (!$stupidly_fast) { if ($cfg['simplepie_strip_htmltags']) { $strip_htmltags = sanitize_text_field($cfg['strip_htmltags']); $strip_htmltags = isset($strip_htmltags) && empty($strip_htmltags) ? $strip_htmltags = array() : explode(',', $strip_htmltags); $strip_htmltags = array_map('trim', $strip_htmltags); $feed->strip_htmltags($strip_htmltags); $feed->strip_htmltags = $strip_htmltags; } if ($cfg['simplepie_strip_attributes']) { $feed->strip_attributes($cfg['strip_htmlattr']); } } if (has_filter('wpematico_fetchfeed')) { $feed = apply_filters('wpematico_fetchfeed', $feed, $url); } $feed->enable_cache(false); $feed->init(); $feed->handle_content_type(); return $feed; }
public static function get_default_item() { $id = filter_input(INPUT_POST, 'id'); $value_default = filter_input(INPUT_POST, 'val_default'); if ($value_default == '') { return 'Do nothing!'; } $feed = new SimplePie(); $path = OGRAB_EDATA . 'item-' . $id . DS . 'row-default.dat'; $feed->set_feed_url($value_default); $feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE); $feed->set_timeout(20); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->enable_order_by_date(false); // we don't want to do anything to the feed $feed->set_url_replacements(array()); $result = $feed->init(); if (isset($_GET['x'])) { echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n"; echo "<p>URL: [{$value_default}]</p>"; echo "<p>Error: [{$feed->error}]</p>"; } $items = $feed->get_items(); $c_items = count($items); if ($c_items == 0) { echo "<p>Error: [{$feed->error}]</p>"; return array(); } $row = new stdclass(); $row->title = html_entity_decode($items[0]->get_title(), ENT_QUOTES, 'UTF-8'); # the title for the post $row->link = $items[0]->get_link(); # a single link for the post $row->description = $items[0]->get_description(); # the content of the post (prefers summaries) $row->author = $items[0]->get_author(); # a single author for the post $row->date = $items[0]->get_date('Y-m-d H:i:s'); $row->enclosures = $items[0]->get_enclosures(); if (!is_file($path)) { $source = new stdClass(); } else { $source = ogb_common::get_default_data('', $id); } $source->so = $row; $cache = serialize($source); if (isset($_GET['x2'])) { //echo "\n\n<br /><i><b>File:</b>".__FILE__.' <b>Line:</b>'.__LINE__."</i><br />\n\n"; echo '<br>Path: ' . $path; } ogbFile::write($path, $cache); exit; }
/** * Parses a feed with SimplePie * * @param boolean $stupidly_fast Set fast mode. Best for checks * @param integer $max Limit of items to fetch * @return SimplePie_Item Feed object **/ function fetchFeed($url, $stupidly_fast = false, $max = 0) { # SimplePie $cfg = get_option(WPeMatico :: OPTION_KEY); if ( $cfg['force_mysimplepie']){ include_once( dirname( __FILE__) . '/lib/simplepie.inc.php' ); }else{ if (!class_exists('SimplePie')) { if (is_file( ABSPATH . WPINC . '/class-simplepie.php')) include_once( ABSPATH. WPINC . '/class-simplepie.php' ); else if (is_file( ABSPATH.'wp-admin/includes/class-simplepie.php')) include_once( ABSPATH.'wp-admin/includes/class-simplepie.php' ); else include_once( dirname( __FILE__) . '/lib/simplepie.inc.php' ); } } $feed = new SimplePie(); $feed->enable_order_by_date(false); $feed->set_feed_url($url); $feed->set_item_limit($max); $feed->set_stupidly_fast($stupidly_fast); $feed->enable_cache(false); $feed->init(); $feed->handle_content_type(); return $feed; }
public static function get_items_feed($url, $params = null) { $feed = new SimplePie(); $mode = isset($params->mode) ? $params->mode : 0; if ($mode == 0) { $feed->set_feed_url($url); } else { $html = ogbFile::get_curl($url); $feed->set_raw_data($html); } $feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE); $feed->set_timeout(20); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->enable_order_by_date(false); // we don't want to do anything to the feed $feed->set_url_replacements(array()); $feed->force_feed(true); $result = $feed->init(); if (isset($_GET['x'])) { echo "\n\n<br /><i><b>File:</b>" . __FILE__ . ' <b>Line:</b>' . __LINE__ . "</i><br />\n\n"; echo "<p>URL: [{$url}]</p>"; echo "<p>Error: [{$feed->error}]</p>"; } $items = $feed->get_items(); $c_items = count($items); if ($c_items == 0) { echo "<p>Error: [{$feed->error}]</p>"; return array(); } for ($i = 0; $i < count($items); $i++) { $row = new stdclass(); $row->title = $items[$i]->get_title(); # the title for the post $row->link = $items[$i]->get_link(); # a single link for the post $row->description = $items[$i]->get_description(); # the content of the post (prefers summaries) $row->author = $items[$i]->get_author(); # a single author for the post $row->date = $items[$i]->get_date('Y-m-d H:i:s'); $row->enclosures = $items[$i]->get_enclosures(); $rows[] = $row; } return $rows; }
function rpf_fetch_feed($url, $max_items) { $url = str_replace(' ', '+', $url); # SimplePie if (!class_exists('SimplePie')) { require_once RPFINC . 'simplepie.class.php'; } $feed = new SimplePie(); $feed->enable_order_by_date(false); $feed->set_feed_url($url); $feed->set_item_limit($max_items); $feed->set_stupidly_fast(true); $feed->enable_cache(false); $feed->init(); $feed->handle_content_type(); return $feed; }
require_once 'simplepie/autoloader.php'; $feed_flipboard = new SimplePie(); if ($userstreams != NULL) { $sql = "SELECT * FROM streams where (required=1 and `group`='" . $_SESSION['usertype'] . "') or id in ({$userstreams})"; } else { $sql = "SELECT * FROM streams where `required`=1 and `group`='" . $_SESSION['usertype'] . "'"; } $result = $db->query($sql); $flipboardarray = array(); while ($row = $result->fetch_assoc()) { $fburl = htmlspecialchars($row['url'], ENT_QUOTES); array_push($flipboardarray, $fburl); } $db->close(); $feed_flipboard->set_cache_duration(1800); $feed_flipboard->set_stupidly_fast(true); $feed_flipboard->set_feed_url($flipboardarray); $streamcachesetting = constant("STREAM_CACHE"); $location = $_SERVER['DOCUMENT_ROOT'] . '/../private/stream/cache/feed/'; $feed_flipboard->set_cache_location($location); $feed_flipboard->enable_cache($streamcachesetting); $feed_flipboard->set_item_limit(10); $feed_flipboard->init(); $feed_flipboard->handle_content_type(); foreach ($feed_flipboard->get_items() as $item) { $title = $item->get_title(); $link = $item->get_link(); $date = $item->get_date(); $feedtitle = $item->get_feed()->get_title(); $date = strtotime($date); $linklabel = "Read Post";
/** * Fetches a feed by URL and caches it - using the SimplePie Library. * * @param string $feed_url This is the URL you want to parse. * @param int $cache_duration This is the number of seconds that you want to store the feedcache file for. * @param string $cache_location This is where you want the cached feeds to be stored. */ public static function fetchRSS($feed_url, $number_of_items = null, $cache_duration = null, $cache_location = null) { /** * SimplePie is a bunch of crap, and not e_strict, yet. hmpf! * Therefore we have to cheat with the error_reporting toggle. * @link: http://tech.groups.yahoo.com/group/simplepie-support/message/3289 */ $old_errorlevel = error_reporting(); error_reporting(0); // load simplepie include ROOT_LIBRARIES . 'simplepie/simplepie.inc'; // instantiate simplepie $simplepie = new \SimplePie(); // if cache_location was not specified manually if ($cache_location == null) { // we set it to the default cache directory for feeds $cache_location = ROOT_CACHE; // . 'feeds'; } // if cache_duration was not specified manually if ($cache_duration == null) { // we set it to the default cache duration time of 1800 $cache_duration = 1800; } // if number of items to fetch is null if ($number_of_items == null) { // we set it to the default value of 5 items $number_of_items = 5; } // finally: fetch the feed and cache it! $simplepie->set_feed_url($feed_url); $simplepie->set_cache_location($cache_location); $simplepie->set_cache_duration($cache_duration); $simplepie->set_timeout(5); $simplepie->set_output_encoding('UTF-8'); $simplepie->set_stupidly_fast(true); $simplepie->init(); $simplepie->handle_content_type(); // set old error reporting level error_reporting($old_errorlevel); return $simplepie; }
debug('--------'); debug("Attempting to process URL as feed"); // Send user agent header showing PHP (prevents a HTML response from feedburner) $http->userAgentDefault = HumbleHttpAgent::UA_PHP; // configure SimplePie HTTP extension class to use our HumbleHttpAgent instance SimplePie_HumbleHttpAgent::set_agent($http); $feed = new SimplePie(); // some feeds use the text/html content type - force_feed tells SimplePie to process anyway $feed->force_feed(true); $feed->set_file_class('SimplePie_HumbleHttpAgent'); //$feed->set_feed_url($url); // colons appearing in the URL's path get encoded $feed->feed_url = $url; $feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE); $feed->set_timeout(20); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->enable_order_by_date(false); // we don't want to do anything to the feed $feed->set_url_replacements(array()); // initialise the feed // the @ suppresses notices which on some servers causes a 500 internal server error $result = @$feed->init(); //$feed->handle_content_type(); //$feed->get_title(); if ($result && (!is_array($feed->data) || count($feed->data) == 0)) { die('Sorry, no feed items found'); } // from now on, we'll identify ourselves as a browser $http->userAgentDefault = HumbleHttpAgent::UA_BROWSER; // Enable caching for multiple downloader if (class_exists('HttpRequestPool')) {
/** * Load and process a feed using SimplePie * * @param string $feed Feed detail array, as returned by Feeds::get() * @return SimplePie */ public static function &load_feed($feed) { // This loads the useragent class_exists('HTTPRequest'); global $lilina; $sp = new SimplePie(); $sp->set_useragent(LILINA_USERAGENT . ' SimplePie/' . SIMPLEPIE_BUILD); $sp->set_stupidly_fast(true); $sp->set_cache_location(get_option('cachedir')); //$sp->set_cache_duration(0); $sp = apply_filters('simplepie-config', $sp); $sp->set_feed_url($feed['feed']); $sp->init(); /** We need this so we have something to work with. */ $sp->get_items(); if (!isset($sp->data['ordered_items'])) { $sp->data['ordered_items'] = $sp->data['items']; } /** Let's force sorting */ usort($sp->data['ordered_items'], array(&$sp, 'sort_items')); usort($sp->data['items'], array(&$sp, 'sort_items')); do_action_ref_array('iu-load-feed', array(&$sp, $feed)); return $sp; }