set_useragent() public method

Set the user agent string
public set_useragent ( string $ua = SIMPLEPIE_USERAGENT )
$ua string New user agent string.
function tweetimport_import_twitter_feed($twitter_account)
{
  require_once (ABSPATH . WPINC . '/class-feed.php');

  $feed = new SimplePie();

  $account_parts = explode ('/', $twitter_account['twitter_name'], 2);



  if ($twitter_account['account_type'] == 1): //Account is Favorites
    $feed->set_feed_url(str_replace('#=#USER#=#', $account_parts[0], TWEETIMPORT_API_FAVORITES_URL));
  elseif ($twitter_account['account_type'] == 0 && count($account_parts) == 1): //User timeline
      $feed->set_feed_url(str_replace('#=#USER#=#', $account_parts[0], TWEETIMPORT_API_USER_TIMELINE_URL));
  elseif ($twitter_account['account_type'] == 2 && count($account_parts) == 2): //Account is list
      $feed_url = str_replace('#=#USER#=#', $account_parts[0], TWEETIMPORT_API_LIST_URL);
      $feed_url = str_replace('#=#LIST#=#', $account_parts[1], $feed_url);
      $feed->set_feed_url($feed_url);
  else :
      return '<strong>ERROR: Account information not correct. Account type wrong?</strong>';
  endif;

  $feed->set_useragent('Tweet Import http://skinju.com/wordpress/tweetimport');
  $feed->set_cache_class('WP_Feed_Cache');
  $feed->set_file_class('WP_SimplePie_File');
  $feed->enable_cache(true);
  $feed->set_cache_duration (apply_filters('tweetimport_cache_duration', 880));
  $feed->enable_order_by_date(false);
  $feed->init();
  $feed->handle_content_type();

  if ($feed->error()):
   return '<strong>ERROR: Feed Reading Error.</strong>';
  endif;

  $rss_items = $feed->get_items();

  $imported_count = 0;
  foreach ($rss_items as $item)
  {
    $item = apply_filters ('tweetimport_tweet_before_new_post', $item); //return false to stop processing an item.
    if (!$item) continue;

    $processed_description = $item->get_description();

    //Get the twitter author from the beginning of the tweet text
    $twitter_author = trim(preg_replace("~^(\w+):(.*?)$~", "\\1", $processed_description));

    if ($twitter_account['strip_name'] == 1):
      $processed_description = preg_replace("~^(\w+):(.*?)~i", "\\2", $processed_description);
    endif;

    if ($twitter_account['names_clickable'] == 1):
      $processed_description = preg_replace("~@(\w+)~", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $processed_description);
      $processed_description = preg_replace("~^(\w+):~", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>:", $processed_description);
    endif;

    if ($twitter_account['hashtags_clickable'] == 1):
      if ($twitter_account['hashtags_clickable_twitter'] == 1):
          $processed_description = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $processed_description);
      else:
        $processed_description = preg_replace("/#(\w+)/", "<a href=\"" . skinju_get_tag_link("\\1") . "\">#\\1</a>", $processed_description);
      endif;
    endif;

  $processed_description = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $processed_description);
  $processed_description = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $processed_description);

    $new_post = array('post_title' => trim (substr (preg_replace("~{$account_parts[0]}: ~i", "", $item->get_title()), 0, 25) . '...'),
                      'post_content' => trim ($processed_description),
                      'post_date' => $item->get_date('Y-m-d H:i:s'),
                      'post_author' => $twitter_account['author'],
                      'post_category' => array($twitter_account['category']),
                      'post_status' => 'publish');

    $new_post = apply_filters('tweetimport_new_post_before_create', $new_post); // Offer the chance to manipulate new post data. return false to skip
    if (!$new_post) continue;
    $new_post_id = wp_insert_post($new_post);

    $imported_count++;

    add_post_meta ($new_post_id, 'tweetimport_twitter_author', $twitter_author, true); 
    add_post_meta ($new_post_id, 'tweetimport_date_imported', date ('Y-m-d H:i:s'), true);
    add_post_meta ($new_post_id, 'tweetimport_twitter_id', $item->get_id(), true);
    add_post_meta ($new_post_id, 'tweetimport_twitter_id', $item->get_id(), true);
    add_post_meta ($new_post_id, '_tweetimport_twitter_id_hash', $item->get_id(true), true);
    add_post_meta ($new_post_id, 'tweetimport_twitter_post_uri', $item->get_link(0));
    add_post_meta ($new_post_id, 'tweetimport_author_avatar', $item->get_link(0, 'image'));

    preg_match_all ('~#([A-Za-z0-9_]+)(?=\s|\Z)~', $item->get_description(), $out);
    if ($twitter_account['add_tag']) $out[0][] = $twitter_account['add_tag'];
    wp_set_post_tags($new_post_id, implode (',', $out[0]));
  }

  return $imported_count;
}
function rssmaker_plugin_action($_, $myUser)
{
    if ($_['action'] == 'show_folder_rss') {
        header('Content-Type: text/xml; charset=utf-8');
        $feedManager = new Feed();
        $feeds = $feedManager->loadAll(array('folder' => $_['id']));
        $items = array();
        foreach ($feeds as $feed) {
            $parsing = new SimplePie();
            $parsing->set_feed_url($feed->getUrl());
            $parsing->init();
            $parsing->set_useragent('Mozilla/4.0 Leed (LightFeed Agregator) ' . VERSION_NAME . ' by idleman http://projet.idleman.fr/leed');
            $parsing->handle_content_type();
            // UTF-8 par défaut pour SimplePie
            $items = array_merge($parsing->get_items(), $items);
        }
        $link = 'http://projet.idleman.fr/leed';
        echo '<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
	<channel>
				<title>Leed dossier ' . $_['name'] . '</title>
				<atom:link href="' . $link . '" rel="self" type="application/rss+xml"/>
				<link>' . $link . '</link>
				<description>Aggrégation des flux du dossier leed ' . $_['name'] . '</description>
				<language>fr-fr</language>
				<copyright>DWTFYW</copyright>
				<pubDate>' . date('r', gmstrftime(time())) . '</pubDate>
				<lastBuildDate>' . date('r', gmstrftime(time())) . '</lastBuildDate>
				<sy:updatePeriod>hourly</sy:updatePeriod>
				<sy:updateFrequency>1</sy:updateFrequency>
				<generator>Leed (LightFeed Agregator) ' . VERSION_NAME . '</generator>';
        usort($items, 'rssmaker_plugin_compare');
        foreach ($items as $item) {
            echo '<item>
				<title><![CDATA[' . $item->get_title() . ']]></title>
				<link>' . $item->get_permalink() . '</link>
				<pubDate>' . date('r', gmstrftime(strtotime($item->get_date()))) . '</pubDate>
				<guid isPermaLink="true">' . $item->get_permalink() . '</guid>

				<description>
				<![CDATA[
				' . $item->get_description() . '
				]]>
				</description>
				<content:encoded><![CDATA[' . $item->get_content() . ']]></content:encoded>

				<dc:creator>' . ('' == $item->get_author() ? 'Anonyme' : $item->get_author()->name) . '</dc:creator>
				</item>';
        }
        echo '</channel></rss>';
    }
}
 function get_rss_feed($url)
 {
     require_once ABSPATH . WPINC . '/class-feed.php';
     $feed = new SimplePie();
     $feed->set_sanitize_class('WP_SimplePie_Sanitize_KSES');
     $feed->sanitize = new WP_SimplePie_Sanitize_KSES();
     $feed->set_useragent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36');
     $feed->set_cache_class('WP_Feed_Cache');
     $feed->set_file_class('WP_SimplePie_File');
     $feed->set_feed_url($url);
     $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
     do_action_ref_array('wp_feed_options', array(&$feed, $url));
     $feed->init();
     $feed->handle_content_type();
     if ($feed->error()) {
         return new WP_Error('simplepie-error', $feed->error());
     }
     return $feed;
 }
示例#4
0
<?php

if (!isset($_GET['uid']) or !is_numeric($_GET['uid'])) {
    die('Erreur: aucun id n\'a été spécifié!');
}
// Nécéssaire au bon déroulement de l'agrégation
set_time_limit(0);
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
// On charge SimplePie
include 'core/private/simplepie.php';
$simple = new SimplePie();
$simple->enable_cache(false);
// On désactive la mise en cache
$simple->set_useragent('Mozilla/5.0 (compatible; SimplePie.org; simple.tuxfamily.org)');
// User-Agent propre à SRR
$sqlite = new PDO('sqlite:core/private/data.db');
// On charge la base de données
$query = $sqlite->query('SELECT id,url,last_check FROM feeds WHERE user_id=' . $sqlite->quote($_GET['uid']));
// On récupère la liste des flux
$time = time();
while ($response = $query->fetch()) {
    if ($time > $response['last_check'] + 600) {
        $feed_id = $response['id'];
        $simple->set_feed_url($response['url']);
        $simple->init();
        $simple->handle_content_type();
        $error = 0;
        if ($simple->error()) {
            $error = 1;
        }
        foreach ($simple->get_items() as $item) {
/**
 * 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);
}
示例#6
0
function check_for_update($link)
{
    $releases_feed = "http://tt-rss.org/releases.rss";
    if (!CHECK_FOR_NEW_VERSION || $_SESSION["access_level"] < 10) {
        return;
    }
    error_reporting(0);
    if (ENABLE_SIMPLEPIE) {
        $rss = new SimplePie();
        $rss->set_useragent(SIMPLEPIE_USERAGENT . MAGPIE_USER_AGENT_EXT);
        //			$rss->set_timeout(MAGPIE_FETCH_TIME_OUT);
        $rss->set_feed_url($fetch_url);
        $rss->set_output_encoding('UTF-8');
        $rss->init();
    } else {
        $rss = fetch_rss($releases_feed);
    }
    error_reporting(DEFAULT_ERROR_LEVEL);
    if ($rss) {
        if (ENABLE_SIMPLEPIE) {
            $items = $rss->get_items();
        } else {
            $items = $rss->items;
            if (!$items || !is_array($items)) {
                $items = $rss->entries;
            }
            if (!$items || !is_array($items)) {
                $items = $rss;
            }
        }
        if (!is_array($items) || count($items) == 0) {
            return;
        }
        $latest_item = $items[0];
        if (ENABLE_SIMPLEPIE) {
            $last_title = $latest_item->get_title();
        } else {
            $last_title = $latest_item["title"];
        }
        $latest_version = trim(preg_replace("/(Milestone)|(completed)/", "", $last_title));
        if (ENABLE_SIMPLEPIE) {
            $release_url = sanitize_rss($link, $latest_item->get_link());
            $content = sanitize_rss($link, $latest_item->get_description());
        } else {
            $release_url = sanitize_rss($link, $latest_item["link"]);
            $content = sanitize_rss($link, $latest_item["description"]);
        }
        if (version_compare(VERSION, $latest_version) == -1) {
            return sprintf("New version of Tiny-Tiny RSS (%s) is available:", $latest_version) . "<div class='milestoneDetails'>{$content}</div>";
        } else {
            return false;
        }
    }
}
示例#7
0
 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;
 }
示例#8
0
function updateRSS()
{
    $db = DBCxn::get();
    $selectRSS = $db->query("SELECT id, rssLink, updateMd5 FROM rss");
    $selectRSS->setFetchMode(PDO::FETCH_ASSOC);
    $selectRSS = $selectRSS->fetchAll();
    //构建分析
    $feed = new SimplePie();
    $feed->enable_order_by_date(false);
    $feed->enable_cache(true);
    $feed->set_useragent('Mozilla/4.0 ' . SIMPLEPIE_USERAGENT);
    $feed->set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/cache');
    //拿出每个RSS调用分析函数
    foreach ($selectRSS as $rows) {
        $rssId = $rows['id'];
        //博客ID
        $updateMd5 = $rows['updateMd5'];
        //最后更新记录的md5值
        $feed->set_feed_url($rows['rssLink']);
        //feed地址做参数进行解析操作
        $feed->set_timeout(30);
        $feed->init();
        //如果feed出错,执行下一个
        if ($feed->error()) {
            continue;
        }
        readRSS($rssId, $updateMd5, $feed);
    }
    return true;
}
/**
 * Only permit execution from the command-line.
 */
if (php_sapi_name() !== 'cli') {
    echo "This script must be called from the command line.";
    exit(1);
}
require_once __DIR__ . '/vendor/autoload.php';
/**
 * Get the feed list and set up SimplePie.
 */
$simplepie = new SimplePie();
$feedUrls = array_filter(file(__DIR__ . '/feeds.csv', FILE_IGNORE_NEW_LINES));
$simplepie->set_feed_url($feedUrls);
$ua = 'Mozilla/4.0 (compatible; Sourdust Feed Aggregator https://github.com/samwilson/sourdust-feed-aggregator)';
$simplepie->set_useragent($ua);
/**
 * Set up caching.
 */
$cacheDir = __DIR__ . '/cache';
if (!is_dir($cacheDir)) {
    mkdir($cacheDir);
}
$simplepie->set_cache_location($cacheDir);
/**
 * Run the actual feed aggregation and check for errors.
 */
$simplepie->init();
if ($simplepie->error()) {
    echo "Errors:\n    " . join("\n    ", $simplepie->error()) . "\n";
}
 /**
  * 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;
 }
示例#11
0
function customSimplePie()
{
    $simplePie = new SimplePie();
    $simplePie->set_useragent(Minz_Translate::t('freshrss') . '/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ') ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION);
    $simplePie->set_cache_location(CACHE_PATH);
    $simplePie->set_cache_duration(1500);
    $simplePie->strip_htmltags(array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'link', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'plaintext', 'script', 'style'));
    $simplePie->strip_attributes(array_merge($simplePie->strip_attributes, array('autoplay', 'onload', 'onunload', 'onclick', 'ondblclick', 'onmousedown', 'onmouseup', 'onmouseover', 'onmousemove', 'onmouseout', 'onfocus', 'onblur', 'onkeypress', 'onkeydown', 'onkeyup', 'onselect', 'onchange', 'seamless')));
    $simplePie->add_attributes(array('img' => array('lazyload' => ''), 'audio' => array('preload' => 'none'), 'iframe' => array('postpone' => '', 'sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('postpone' => '', 'preload' => 'none')));
    $simplePie->set_url_replacements(array('a' => 'href', 'area' => 'href', 'audio' => 'src', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'iframe' => 'src', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite', 'q' => 'cite', 'source' => 'src', 'track' => 'src', 'video' => array('poster', 'src')));
    return $simplePie;
}
示例#12
0
 private function fetch_feed($url)
 {
     require_once ABSPATH . WPINC . '/class-feed.php';
     $feed = new SimplePie();
     $feed->set_sanitize_class('WP_SimplePie_Sanitize_KSES');
     // We must manually overwrite $feed->sanitize because SimplePie's
     // constructor sets it before we have a chance to set the sanitization class
     $feed->sanitize = new WP_SimplePie_Sanitize_KSES();
     $feed->set_cache_class('WP_Feed_Cache');
     $feed->set_file_class('WP_SimplePie_File');
     $feed->set_feed_url($url);
     $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url));
     do_action_ref_array('wp_feed_options', array(&$feed, $url));
     $feed->set_useragent(self::USER_AGENT);
     $feed->init();
     $feed->handle_content_type();
     if ($feed->error()) {
         return new WP_Error('simplepie-error', $feed->error());
     }
     return $feed;
 }
示例#13
0
/**
* Syndication import function. Imports headline data to a portal block.
*
* Rewritten December 19th 2004 by Michael Jervis (mike@*censored*ingbrit.com). Now
* utilises a Factory Pattern to open a URL and automaticaly retreive a feed
* object populated with feed data. Then import it into the portal block.
*
* @param    string  $bid            Block ID
* @param    string  $rdfurl         URL to get content from
* @param    int     $maxheadlines   Maximum number of headlines to display
* @return   void
* @see function COM_rdfCheck
*
*/
function COM_rdfImport($bid, $rdfurl, $maxheadlines = 0)
{
    global $_CONF, $_TABLES, $LANG21;
    require_once $_CONF['path'] . '/lib/simplepie/autoloader.php';
    $result = DB_query("SELECT rdf_last_modified, rdf_etag FROM {$_TABLES['blocks']} WHERE bid = " . (int) $bid);
    list($last_modified, $etag) = DB_fetchArray($result);
    // Load the actual feed handlers:
    $feed = new SimplePie();
    $feed->set_useragent('glFusion/' . GVERSION . ' ' . SIMPLEPIE_USERAGENT);
    $feed->set_feed_url($rdfurl);
    $feed->set_cache_location($_CONF['path'] . '/data/layout_cache');
    $rc = $feed->init();
    if ($rc == true) {
        $feed->handle_content_type();
        /* We have located a reader, and populated it with the information from
         * the syndication file. Now we will sort out our display, and update
         * the block.
         */
        if ($maxheadlines == 0) {
            if (!empty($_CONF['syndication_max_headlines'])) {
                $maxheadlines = $_CONF['syndication_max_headlines'];
            }
        }
        if ($maxheadlines == 0) {
            $number_of_items = $feed->get_item_quantity();
        } else {
            $number_of_items = $feed->get_item_quantity($maxheadlines);
        }
        $etag = '';
        $update = date('Y-m-d H:i:s');
        $last_modified = $update;
        $last_modified = DB_escapeString($last_modified);
        if (empty($last_modified)) {
            DB_query("UPDATE {$_TABLES['blocks']} SET rdfupdated = '{$update}', rdf_last_modified = NULL, rdf_etag = NULL WHERE bid = " . (int) $bid);
        } else {
            DB_query("UPDATE {$_TABLES['blocks']} SET rdfupdated = '{$update}', rdf_last_modified = '{$last_modified}', rdf_etag = '{$etag}' WHERE bid = " . (int) $bid);
        }
        for ($i = 0; $i < $number_of_items; $i++) {
            $item = $feed->get_item($i);
            $title = $item->get_title();
            if (empty($title)) {
                $title = $LANG21[61];
            }
            $link = $item->get_permalink();
            $enclosure = $item->get_enclosure();
            if ($link != '') {
                $content = COM_createLink($title, $link, $attr = array('target' => '_blank'));
            } elseif ($enclosure != '') {
                $content = COM_createLink($title, $enclosure, $attr = array('target' => '_blank'));
            } else {
                $content = $title;
            }
            $articles[] = $content;
        }
        // build a list
        $content = COM_makeList($articles, 'list-feed');
        $content = str_replace(array("\r", "\n"), '', $content);
        if (strlen($content) > 65000) {
            $content = $LANG21[68];
        }
        // Standard theme based function to put it in the block
        $result = DB_change($_TABLES['blocks'], 'content', DB_escapeString($content), 'bid', (int) $bid);
    } else {
        $err = $feed->error();
        COM_errorLog($err);
        $content = DB_escapeString($err);
        DB_query("UPDATE {$_TABLES['blocks']} SET content = '{$content}', rdf_last_modified = NULL, rdf_etag = NULL WHERE bid = " . (int) $bid);
    }
}
示例#14
0
文件: Feed.class.php 项目: Rorto/Leed
 function parse($syncId, &$nbEvents = 0, $enableCache = true, $forceFeed = false)
 {
     $nbEvents = 0;
     assert('is_int($syncId) && $syncId>0');
     if (empty($this->id) || 0 == $this->id) {
         /* Le flux ne dispose pas pas d'id !. Ça arrive si on appelle
            parse() sans avoir appelé save() pour un nouveau flux.
            @TODO: un create() pour un nouveau flux ? */
         $msg = 'Empty or null id for a feed! ' . 'See ' . __FILE__ . ' on line ' . __LINE__;
         error_log($msg, E_USER_ERROR);
         die($msg);
         // Arrêt, sinon création événements sans flux associé.
     }
     $feed = new SimplePie();
     $feed->enable_cache($enableCache);
     $feed->force_feed($forceFeed);
     $feed->set_feed_url($this->url);
     $feed->set_useragent('Mozilla/4.0 Leed (LightFeed Aggregator) ' . VERSION_NAME . ' by idleman http://projet.idleman.fr/leed');
     if (!$feed->init()) {
         $this->error = $feed->error;
         $this->lastupdate = $_SERVER['REQUEST_TIME'];
         $this->save();
         return false;
     }
     $feed->handle_content_type();
     // UTF-8 par défaut pour SimplePie
     if ($this->name == '') {
         $this->name = $feed->get_title();
     }
     if ($this->name == '') {
         $this->name = $this->url;
     }
     $this->website = $feed->get_link();
     $this->description = $feed->get_description();
     $items = $feed->get_items();
     $eventManager = new Event();
     $events = array();
     $iEvents = 0;
     foreach ($items as $item) {
         // Ne retient que les 100 premiers éléments de flux.
         if ($iEvents++ >= 100) {
             break;
         }
         // Si le guid existe déjà, on évite de le reparcourir.
         $alreadyParsed = $eventManager->load(array('guid' => $item->get_id(), 'feed' => $this->id));
         if (isset($alreadyParsed) && $alreadyParsed != false) {
             $events[] = $alreadyParsed->getId();
             continue;
         }
         // Initialisation des informations de l'événement (élt. de flux)
         $event = new Event();
         $event->setSyncId($syncId);
         $event->setGuid($item->get_id());
         $event->setTitle($item->get_title());
         $event->setPubdate($item->get_date());
         $event->setCreator('' == $item->get_author() ? '' : $item->get_author()->name);
         $event->setLink($item->get_permalink());
         $event->setFeed($this->id);
         $event->setUnread(1);
         // inexistant, donc non-lu
         //Gestion de la balise enclosure pour les podcasts et autre cochonneries :)
         $enclosure = $item->get_enclosure();
         if ($enclosure != null && $enclosure->link != '') {
             $enclosureName = substr($enclosure->link, strrpos($enclosure->link, '/') + 1, strlen($enclosure->link));
             $enclosureArgs = strpos($enclosureName, '?');
             if ($enclosureArgs !== false) {
                 $enclosureName = substr($enclosureName, 0, $enclosureArgs);
             }
             $enclosureFormat = isset($enclosure->handler) ? $enclosure->handler : substr($enclosureName, strrpos($enclosureName, '.') + 1);
             $enclosure = '<div class="enclosure"><h1>Fichier média :</h1><a href="' . $enclosure->link . '"> ' . $enclosureName . '</a> <span>(Format ' . strtoupper($enclosureFormat) . ', ' . Functions::convertFileSize($enclosure->length) . ')</span></div>';
         } else {
             $enclosure = '';
         }
         $event->setContent($item->get_content() . $enclosure);
         $event->setDescription($item->get_description() . $enclosure);
         if (trim($event->getDescription()) == '') {
             $event->setDescription(substr($event->getContent(), 0, 300) . '…<br><a href="' . $event->getLink() . '">Lire la suite de l\'article</a>');
         }
         if (trim($event->getContent()) == '') {
             $event->setContent($event->getDescription());
         }
         $event->setCategory($item->get_category());
         $event->save();
         $nbEvents++;
     }
     $listid = "";
     foreach ($events as $item) {
         $listid .= ',' . $item;
     }
     $query = 'UPDATE `' . MYSQL_PREFIX . 'event` SET syncId=' . $syncId . ' WHERE id in (0' . $listid . ');';
     $myQuery = $this->customQuery($query);
     $this->lastupdate = $_SERVER['REQUEST_TIME'];
     $this->save();
     return true;
 }
示例#15
0
function update_rss_feed($link, $feed, $ignore_daemon = false, $no_cache = false, $override_url = false)
{
    require_once "lib/simplepie/simplepie.inc";
    require_once "lib/magpierss/rss_fetch.inc";
    require_once 'lib/magpierss/rss_utils.inc';
    $debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug'];
    if (!$_REQUEST["daemon"] && !$ignore_daemon) {
        return false;
    }
    if ($debug_enabled) {
        _debug("update_rss_feed: start");
    }
    if (!$ignore_daemon) {
        if (DB_TYPE == "pgsql") {
            $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < NOW() - INTERVAL '120 seconds')";
        } else {
            $updstart_thresh_qpart = "(ttrss_feeds.last_update_started IS NULL OR ttrss_feeds.last_update_started < DATE_SUB(NOW(), INTERVAL 120 SECOND))";
        }
        $result = db_query($link, "SELECT id,update_interval,auth_login,\n\t\t\t\tauth_pass,cache_images,update_method,last_updated\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}' AND {$updstart_thresh_qpart}");
    } else {
        $result = db_query($link, "SELECT id,update_interval,auth_login,\n\t\t\t\tfeed_url,auth_pass,cache_images,update_method,last_updated,\n\t\t\t\tmark_unread_on_update, owner_uid, update_on_checksum_change,\n\t\t\t\tpubsub_state\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'");
    }
    if (db_num_rows($result) == 0) {
        if ($debug_enabled) {
            _debug("update_rss_feed: feed {$feed} NOT FOUND/SKIPPED");
        }
        return false;
    }
    $update_method = db_fetch_result($result, 0, "update_method");
    $last_updated = db_fetch_result($result, 0, "last_updated");
    $owner_uid = db_fetch_result($result, 0, "owner_uid");
    $mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update"));
    $update_on_checksum_change = sql_bool_to_bool(db_fetch_result($result, 0, "update_on_checksum_change"));
    $pubsub_state = db_fetch_result($result, 0, "pubsub_state");
    db_query($link, "UPDATE ttrss_feeds SET last_update_started = NOW()\n\t\t\tWHERE id = '{$feed}'");
    $auth_login = db_fetch_result($result, 0, "auth_login");
    $auth_pass = db_fetch_result($result, 0, "auth_pass");
    if ($update_method == 0) {
        $update_method = DEFAULT_UPDATE_METHOD + 1;
    }
    // 1 - Magpie
    // 2 - SimplePie
    // 3 - Twitter OAuth
    if ($update_method == 2) {
        $use_simplepie = true;
    } else {
        $use_simplepie = false;
    }
    if ($debug_enabled) {
        _debug("update method: {$update_method} (feed setting: {$update_method}) (use simplepie: {$use_simplepie})\n");
    }
    if ($update_method == 1) {
        $auth_login = urlencode($auth_login);
        $auth_pass = urlencode($auth_pass);
    }
    $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
    $fetch_url = db_fetch_result($result, 0, "feed_url");
    $feed = db_escape_string($feed);
    if ($auth_login && $auth_pass) {
        $url_parts = array();
        preg_match("/(^[^:]*):\\/\\/(.*)/", $fetch_url, $url_parts);
        if ($url_parts[1] && $url_parts[2]) {
            $fetch_url = $url_parts[1] . "://{$auth_login}:{$auth_pass}@" . $url_parts[2];
        }
    }
    if ($override_url) {
        $fetch_url = $override_url;
    }
    if ($debug_enabled) {
        _debug("update_rss_feed: fetching [{$fetch_url}]...");
    }
    // Ignore cache if new feed or manual update.
    $cache_age = is_null($last_updated) || $last_updated == '1970-01-01 00:00:00' ? -1 : get_feed_update_interval($link, $feed) * 60;
    if ($update_method == 3) {
        $rss = fetch_twitter_rss($link, $fetch_url, $owner_uid);
    } else {
        if ($update_method == 1) {
            define('MAGPIE_CACHE_AGE', $cache_age);
            define('MAGPIE_CACHE_ON', !$no_cache);
            define('MAGPIE_FETCH_TIME_OUT', 60);
            define('MAGPIE_CACHE_DIR', CACHE_DIR . "/magpie");
            $rss = @fetch_rss($fetch_url);
        } else {
            $simplepie_cache_dir = CACHE_DIR . "/simplepie";
            if (!is_dir($simplepie_cache_dir)) {
                mkdir($simplepie_cache_dir);
            }
            $rss = new SimplePie();
            $rss->set_useragent(SELF_USER_AGENT);
            #			$rss->set_timeout(10);
            $rss->set_feed_url($fetch_url);
            $rss->set_output_encoding('UTF-8');
            //$rss->force_feed(true);
            if ($debug_enabled) {
                _debug("feed update interval (sec): " . get_feed_update_interval($link, $feed) * 60);
            }
            $rss->enable_cache(!$no_cache);
            if (!$no_cache) {
                $rss->set_cache_location($simplepie_cache_dir);
                $rss->set_cache_duration($cache_age);
            }
            $rss->init();
        }
    }
    //		print_r($rss);
    if ($debug_enabled) {
        _debug("update_rss_feed: fetch done, parsing...");
    }
    $feed = db_escape_string($feed);
    if ($update_method == 2) {
        $fetch_ok = !$rss->error();
    } else {
        $fetch_ok = !!$rss;
    }
    if ($fetch_ok) {
        if ($debug_enabled) {
            _debug("update_rss_feed: processing feed data...");
        }
        //			db_query($link, "BEGIN");
        if (DB_TYPE == "pgsql") {
            $favicon_interval_qpart = "favicon_last_checked < NOW() - INTERVAL '12 hour'";
        } else {
            $favicon_interval_qpart = "favicon_last_checked < DATE_SUB(NOW(), INTERVAL 12 HOUR)";
        }
        $result = db_query($link, "SELECT title,icon_url,site_url,owner_uid,\n\t\t\t\t(favicon_last_checked IS NULL OR {$favicon_interval_qpart}) AS\n\t\t\t\t\t\tfavicon_needs_check\n\t\t\t\tFROM ttrss_feeds WHERE id = '{$feed}'");
        $registered_title = db_fetch_result($result, 0, "title");
        $orig_icon_url = db_fetch_result($result, 0, "icon_url");
        $orig_site_url = db_fetch_result($result, 0, "site_url");
        $favicon_needs_check = sql_bool_to_bool(db_fetch_result($result, 0, "favicon_needs_check"));
        $owner_uid = db_fetch_result($result, 0, "owner_uid");
        if ($use_simplepie) {
            $site_url = db_escape_string(trim($rss->get_link()));
        } else {
            $site_url = db_escape_string(trim($rss->channel["link"]));
        }
        // weird, weird Magpie
        if (!$use_simplepie) {
            if (!$site_url) {
                $site_url = db_escape_string($rss->channel["link_"]);
            }
        }
        $site_url = rewrite_relative_url($fetch_url, $site_url);
        $site_url = substr($site_url, 0, 250);
        if ($debug_enabled) {
            _debug("update_rss_feed: checking favicon...");
        }
        if ($favicon_needs_check) {
            check_feed_favicon($site_url, $feed, $link);
            db_query($link, "UPDATE ttrss_feeds SET favicon_last_checked = NOW()\n\t\t\t\t\tWHERE id = '{$feed}'");
        }
        if (!$registered_title || $registered_title == "[Unknown]") {
            if ($use_simplepie) {
                $feed_title = db_escape_string($rss->get_title());
            } else {
                $feed_title = db_escape_string($rss->channel["title"]);
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: registering title: {$feed_title}");
            }
            db_query($link, "UPDATE ttrss_feeds SET\n\t\t\t\t\ttitle = '{$feed_title}' WHERE id = '{$feed}'");
        }
        if ($site_url && $orig_site_url != $site_url) {
            db_query($link, "UPDATE ttrss_feeds SET\n\t\t\t\t\tsite_url = '{$site_url}' WHERE id = '{$feed}'");
        }
        //			print "I: " . $rss->channel["image"]["url"];
        if (!$use_simplepie) {
            $icon_url = db_escape_string(trim($rss->image["url"]));
        } else {
            $icon_url = db_escape_string(trim($rss->get_image_url()));
        }
        $icon_url = rewrite_relative_url($fetch_url, $icon_url);
        $icon_url = substr($icon_url, 0, 250);
        if ($icon_url && $orig_icon_url != $icon_url) {
            db_query($link, "UPDATE ttrss_feeds SET icon_url = '{$icon_url}' WHERE id = '{$feed}'");
        }
        if ($debug_enabled) {
            _debug("update_rss_feed: loading filters...");
        }
        $filters = load_filters($link, $feed, $owner_uid);
        //			if ($debug_enabled) {
        //				print_r($filters);
        //			}
        if ($use_simplepie) {
            $iterator = $rss->get_items();
        } else {
            $iterator = $rss->items;
            if (!$iterator || !is_array($iterator)) {
                $iterator = $rss->entries;
            }
            if (!$iterator || !is_array($iterator)) {
                $iterator = $rss;
            }
        }
        if (!is_array($iterator)) {
            /* db_query($link, "UPDATE ttrss_feeds
            			SET last_error = 'Parse error: can\'t find any articles.'
            			WHERE id = '$feed'"); */
            // clear any errors and mark feed as updated if fetched okay
            // even if it's blank
            if ($debug_enabled) {
                _debug("update_rss_feed: entry iterator is not an array, no articles?");
            }
            db_query($link, "UPDATE ttrss_feeds\n\t\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'");
            return;
            // no articles
        }
        if ($pubsub_state != 2 && PUBSUBHUBBUB_ENABLED) {
            if ($debug_enabled) {
                _debug("update_rss_feed: checking for PUSH hub...");
            }
            $feed_hub_url = false;
            if ($use_simplepie) {
                $links = $rss->get_links('hub');
                if ($links && is_array($links)) {
                    foreach ($links as $l) {
                        $feed_hub_url = $l;
                        break;
                    }
                }
            } else {
                $atom = $rss->channel['atom'];
                if ($atom) {
                    if ($atom['link@rel'] == 'hub') {
                        $feed_hub_url = $atom['link@href'];
                    }
                    if (!$feed_hub_url && $atom['link#'] > 1) {
                        for ($i = 2; $i <= $atom['link#']; $i++) {
                            if ($atom["link#{$i}@rel"] == 'hub') {
                                $feed_hub_url = $atom["link#{$i}@href"];
                                break;
                            }
                        }
                    }
                } else {
                    $feed_hub_url = $rss->channel['link_hub'];
                }
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: feed hub url: {$feed_hub_url}");
            }
            if ($feed_hub_url && function_exists('curl_init') && !ini_get("open_basedir")) {
                require_once 'lib/pubsubhubbub/subscriber.php';
                $callback_url = get_self_url_prefix() . "/public.php?op=pubsub&id={$feed}";
                $s = new Subscriber($feed_hub_url, $callback_url);
                $rc = $s->subscribe($fetch_url);
                if ($debug_enabled) {
                    _debug("update_rss_feed: feed hub url found, subscribe request sent.");
                }
                db_query($link, "UPDATE ttrss_feeds SET pubsub_state = 1\n\t\t\t\t\t\tWHERE id = '{$feed}'");
            }
        }
        if ($debug_enabled) {
            _debug("update_rss_feed: processing articles...");
        }
        foreach ($iterator as $item) {
            if ($_REQUEST['xdebug'] == 2) {
                print_r($item);
            }
            if ($use_simplepie) {
                $entry_guid = $item->get_id();
                if (!$entry_guid) {
                    $entry_guid = $item->get_link();
                }
                if (!$entry_guid) {
                    $entry_guid = make_guid_from_title($item->get_title());
                }
            } else {
                $entry_guid = $item["id"];
                if (!$entry_guid) {
                    $entry_guid = $item["guid"];
                }
                if (!$entry_guid) {
                    $entry_guid = $item["about"];
                }
                if (!$entry_guid) {
                    $entry_guid = $item["link"];
                }
                if (!$entry_guid) {
                    $entry_guid = make_guid_from_title($item["title"]);
                }
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: guid {$entry_guid}");
            }
            if (!$entry_guid) {
                continue;
            }
            $entry_timestamp = "";
            if ($use_simplepie) {
                $entry_timestamp = strtotime($item->get_date());
            } else {
                $rss_2_date = $item['pubdate'];
                $rss_1_date = $item['dc']['date'];
                $atom_date = $item['issued'];
                if (!$atom_date) {
                    $atom_date = $item['updated'];
                }
                if ($atom_date != "") {
                    $entry_timestamp = parse_w3cdtf($atom_date);
                }
                if ($rss_1_date != "") {
                    $entry_timestamp = parse_w3cdtf($rss_1_date);
                }
                if ($rss_2_date != "") {
                    $entry_timestamp = strtotime($rss_2_date);
                }
            }
            if ($entry_timestamp == "" || $entry_timestamp == -1 || !$entry_timestamp) {
                $entry_timestamp = time();
                $no_orig_date = 'true';
            } else {
                $no_orig_date = 'false';
            }
            $entry_timestamp_fmt = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
            if ($debug_enabled) {
                _debug("update_rss_feed: date {$entry_timestamp} [{$entry_timestamp_fmt}]");
            }
            if ($use_simplepie) {
                $entry_title = $item->get_title();
            } else {
                $entry_title = trim(strip_tags($item["title"]));
            }
            if ($use_simplepie) {
                $entry_link = $item->get_link();
            } else {
                // strange Magpie workaround
                $entry_link = $item["link_"];
                if (!$entry_link) {
                    $entry_link = $item["link"];
                }
            }
            $entry_link = rewrite_relative_url($site_url, $entry_link);
            if ($debug_enabled) {
                _debug("update_rss_feed: title {$entry_title}");
                _debug("update_rss_feed: link {$entry_link}");
            }
            if (!$entry_title) {
                $entry_title = date("Y-m-d H:i:s", $entry_timestamp);
            }
            $entry_link = strip_tags($entry_link);
            if ($use_simplepie) {
                $entry_content = $item->get_content();
                if (!$entry_content) {
                    $entry_content = $item->get_description();
                }
            } else {
                $entry_content = $item["content:escaped"];
                if (!$entry_content) {
                    $entry_content = $item["content:encoded"];
                }
                if (!$entry_content && is_array($entry_content)) {
                    $entry_content = $item["content"]["encoded"];
                }
                if (!$entry_content) {
                    $entry_content = $item["content"];
                }
                if (is_array($entry_content)) {
                    $entry_content = $entry_content[0];
                }
                // Magpie bugs are getting ridiculous
                if (trim($entry_content) == "Array") {
                    $entry_content = false;
                }
                if (!$entry_content) {
                    $entry_content = $item["atom_content"];
                }
                if (!$entry_content) {
                    $entry_content = $item["summary"];
                }
                if (!$entry_content || strlen($entry_content) < strlen($item["description"])) {
                    $entry_content = $item["description"];
                }
                // WTF
                if (is_array($entry_content)) {
                    $entry_content = $entry_content["encoded"];
                    if (!$entry_content) {
                        $entry_content = $entry_content["escaped"];
                    }
                }
            }
            if ($cache_images && is_writable(CACHE_DIR . '/images')) {
                $entry_content = cache_images($entry_content, $site_url, $debug_enabled);
            }
            if ($_REQUEST["xdebug"] == 2) {
                print "update_rss_feed: content: ";
                print $entry_content;
                print "\n";
            }
            $entry_content_unescaped = $entry_content;
            if ($use_simplepie) {
                $entry_comments = strip_tags($item->data["comments"]);
                if ($item->get_author()) {
                    $entry_author_item = $item->get_author();
                    $entry_author = $entry_author_item->get_name();
                    if (!$entry_author) {
                        $entry_author = $entry_author_item->get_email();
                    }
                    $entry_author = db_escape_string($entry_author);
                }
            } else {
                $entry_comments = strip_tags($item["comments"]);
                $entry_author = db_escape_string(strip_tags($item['dc']['creator']));
                if ($item['author']) {
                    if (is_array($item['author'])) {
                        if (!$entry_author) {
                            $entry_author = db_escape_string(strip_tags($item['author']['name']));
                        }
                        if (!$entry_author) {
                            $entry_author = db_escape_string(strip_tags($item['author']['email']));
                        }
                    }
                    if (!$entry_author) {
                        $entry_author = db_escape_string(strip_tags($item['author']));
                    }
                }
            }
            if (preg_match('/^[\\t\\n\\r ]*$/', $entry_author)) {
                $entry_author = '';
            }
            $entry_guid = db_escape_string(strip_tags($entry_guid));
            $entry_guid = mb_substr($entry_guid, 0, 250);
            $result = db_query($link, "SELECT id FROM\tttrss_entries\n\t\t\t\t\tWHERE guid = '{$entry_guid}'");
            $entry_content = db_escape_string($entry_content, false);
            $content_hash = "SHA1:" . sha1(strip_tags($entry_content));
            $entry_title = db_escape_string($entry_title);
            $entry_link = db_escape_string($entry_link);
            $entry_comments = mb_substr(db_escape_string($entry_comments), 0, 250);
            $entry_author = mb_substr($entry_author, 0, 250);
            if ($use_simplepie) {
                $num_comments = 0;
                #FIXME#
            } else {
                $num_comments = db_escape_string($item["slash"]["comments"]);
            }
            if (!$num_comments) {
                $num_comments = 0;
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: looking for tags [1]...");
            }
            // parse <category> entries into tags
            $additional_tags = array();
            if ($use_simplepie) {
                $additional_tags_src = $item->get_categories();
                if (is_array($additional_tags_src)) {
                    foreach ($additional_tags_src as $tobj) {
                        array_push($additional_tags, $tobj->get_term());
                    }
                }
                if ($debug_enabled) {
                    _debug("update_rss_feed: category tags:");
                    print_r($additional_tags);
                }
            } else {
                $t_ctr = $item['category#'];
                if ($t_ctr == 0) {
                    $additional_tags = array();
                } else {
                    if ($t_ctr > 0) {
                        $additional_tags = array($item['category']);
                        if ($item['category@term']) {
                            array_push($additional_tags, $item['category@term']);
                        }
                        for ($i = 0; $i <= $t_ctr; $i++) {
                            if ($item["category#{$i}"]) {
                                array_push($additional_tags, $item["category#{$i}"]);
                            }
                            if ($item["category#{$i}@term"]) {
                                array_push($additional_tags, $item["category#{$i}@term"]);
                            }
                        }
                    }
                }
                // parse <dc:subject> elements
                $t_ctr = $item['dc']['subject#'];
                if ($t_ctr > 0) {
                    array_push($additional_tags, $item['dc']['subject']);
                    for ($i = 0; $i <= $t_ctr; $i++) {
                        if ($item['dc']["subject#{$i}"]) {
                            array_push($additional_tags, $item['dc']["subject#{$i}"]);
                        }
                    }
                }
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: looking for tags [2]...");
            }
            /* taaaags */
            // <a href="..." rel="tag">Xorg</a>, //
            $entry_tags = null;
            preg_match_all("/<a.*?rel=['\"]tag['\"].*?\\>([^<]+)<\\/a>/i", $entry_content_unescaped, $entry_tags);
            $entry_tags = $entry_tags[1];
            $entry_tags = array_merge($entry_tags, $additional_tags);
            $entry_tags = array_unique($entry_tags);
            for ($i = 0; $i < count($entry_tags); $i++) {
                $entry_tags[$i] = mb_strtolower($entry_tags[$i], 'utf-8');
            }
            if ($debug_enabled) {
                //_debug("update_rss_feed: unfiltered tags found:");
                //print_r($entry_tags);
            }
            # sanitize content
            $entry_content = sanitize_article_content($entry_content);
            $entry_title = sanitize_article_content($entry_title);
            if ($debug_enabled) {
                _debug("update_rss_feed: done collecting data [TITLE:{$entry_title}]");
            }
            db_query($link, "BEGIN");
            if (db_num_rows($result) == 0) {
                if ($debug_enabled) {
                    _debug("update_rss_feed: base guid not found");
                }
                // base post entry does not exist, create it
                $result = db_query($link, "INSERT INTO ttrss_entries\n\t\t\t\t\t\t\t(title,\n\t\t\t\t\t\t\tguid,\n\t\t\t\t\t\t\tlink,\n\t\t\t\t\t\t\tupdated,\n\t\t\t\t\t\t\tcontent,\n\t\t\t\t\t\t\tcontent_hash,\n\t\t\t\t\t\t\tno_orig_date,\n\t\t\t\t\t\t\tdate_updated,\n\t\t\t\t\t\t\tdate_entered,\n\t\t\t\t\t\t\tcomments,\n\t\t\t\t\t\t\tnum_comments,\n\t\t\t\t\t\t\tauthor)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t('{$entry_title}',\n\t\t\t\t\t\t\t'{$entry_guid}',\n\t\t\t\t\t\t\t'{$entry_link}',\n\t\t\t\t\t\t\t'{$entry_timestamp_fmt}',\n\t\t\t\t\t\t\t'{$entry_content}',\n\t\t\t\t\t\t\t'{$content_hash}',\n\t\t\t\t\t\t\t{$no_orig_date},\n\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\tNOW(),\n\t\t\t\t\t\t\t'{$entry_comments}',\n\t\t\t\t\t\t\t'{$num_comments}',\n\t\t\t\t\t\t\t'{$entry_author}')");
            } else {
                // we keep encountering the entry in feeds, so we need to
                // update date_updated column so that we don't get horrible
                // dupes when the entry gets purged and reinserted again e.g.
                // in the case of SLOW SLOW OMG SLOW updating feeds
                $base_entry_id = db_fetch_result($result, 0, "id");
                db_query($link, "UPDATE ttrss_entries SET date_updated = NOW()\n\t\t\t\t\t\tWHERE id = '{$base_entry_id}'");
            }
            // now it should exist, if not - bad luck then
            $result = db_query($link, "SELECT\n\t\t\t\t\t\tid,content_hash,no_orig_date,title,\n\t\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(date_updated,1,19) as date_updated,\n\t\t\t\t\t\t" . SUBSTRING_FOR_DATE . "(updated,1,19) as updated,\n\t\t\t\t\t\tnum_comments\n\t\t\t\t\tFROM\n\t\t\t\t\t\tttrss_entries\n\t\t\t\t\tWHERE guid = '{$entry_guid}'");
            $entry_ref_id = 0;
            $entry_int_id = 0;
            if (db_num_rows($result) == 1) {
                if ($debug_enabled) {
                    _debug("update_rss_feed: base guid found, checking for user record");
                }
                // this will be used below in update handler
                $orig_content_hash = db_fetch_result($result, 0, "content_hash");
                $orig_title = db_fetch_result($result, 0, "title");
                $orig_num_comments = db_fetch_result($result, 0, "num_comments");
                $orig_date_updated = strtotime(db_fetch_result($result, 0, "date_updated"));
                $ref_id = db_fetch_result($result, 0, "id");
                $entry_ref_id = $ref_id;
                // check for user post link to main table
                // do we allow duplicate posts with same GUID in different feeds?
                if (get_pref($link, "ALLOW_DUPLICATE_POSTS", $owner_uid, false)) {
                    $dupcheck_qpart = "AND (feed_id = '{$feed}' OR feed_id IS NULL)";
                } else {
                    $dupcheck_qpart = "";
                }
                /* Collect article tags here so we could filter by them: */
                $article_filters = get_article_filters($filters, $entry_title, $entry_content, $entry_link, $entry_timestamp, $entry_author, $entry_tags);
                if ($debug_enabled) {
                    _debug("update_rss_feed: article filters: ");
                    if (count($article_filters) != 0) {
                        print_r($article_filters);
                    }
                }
                if (find_article_filter($article_filters, "filter")) {
                    db_query($link, "COMMIT");
                    // close transaction in progress
                    continue;
                }
                $score = calculate_article_score($article_filters);
                if ($debug_enabled) {
                    _debug("update_rss_feed: initial score: {$score}");
                }
                $query = "SELECT ref_id, int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}'\n\t\t\t\t\t\t\t{$dupcheck_qpart}";
                //					if ($_REQUEST["xdebug"]) print "$query\n";
                $result = db_query($link, $query);
                // okay it doesn't exist - create user entry
                if (db_num_rows($result) == 0) {
                    if ($debug_enabled) {
                        _debug("update_rss_feed: user record not found, creating...");
                    }
                    if ($score >= -500 && !find_article_filter($article_filters, 'catchup')) {
                        $unread = 'true';
                        $last_read_qpart = 'NULL';
                    } else {
                        $unread = 'false';
                        $last_read_qpart = 'NOW()';
                    }
                    if (find_article_filter($article_filters, 'mark') || $score > 1000) {
                        $marked = 'true';
                    } else {
                        $marked = 'false';
                    }
                    if (find_article_filter($article_filters, 'publish')) {
                        $published = 'true';
                    } else {
                        $published = 'false';
                    }
                    // N-grams
                    if (DB_TYPE == "pgsql" and defined('_NGRAM_TITLE_DUPLICATE_THRESHOLD')) {
                        $result = db_query($link, "SELECT COUNT(*) AS similar FROM\n\t\t\t\t\t\t\t\t\tttrss_entries,ttrss_user_entries\n\t\t\t\t\t\t\t\tWHERE ref_id = id AND updated >= NOW() - INTERVAL '7 day'\n\t\t\t\t\t\t\t\t\tAND similarity(title, '{$entry_title}') >= " . _NGRAM_TITLE_DUPLICATE_THRESHOLD . "\n\t\t\t\t\t\t\t\t\tAND owner_uid = {$owner_uid}");
                        $ngram_similar = db_fetch_result($result, 0, "similar");
                        if ($debug_enabled) {
                            _debug("update_rss_feed: N-gram similar results: {$ngram_similar}");
                        }
                        if ($ngram_similar > 0) {
                            $unread = 'false';
                        }
                    }
                    $result = db_query($link, "INSERT INTO ttrss_user_entries\n\t\t\t\t\t\t\t\t(ref_id, owner_uid, feed_id, unread, last_read, marked,\n\t\t\t\t\t\t\t\t\tpublished, score, tag_cache, label_cache, uuid)\n\t\t\t\t\t\t\tVALUES ('{$ref_id}', '{$owner_uid}', '{$feed}', {$unread},\n\t\t\t\t\t\t\t\t{$last_read_qpart}, {$marked}, {$published}, '{$score}', '', '', '')");
                    if (PUBSUBHUBBUB_HUB && $published == 'true') {
                        $rss_link = get_self_url_prefix() . "/public.php?op=rss&id=-2&key=" . get_feed_access_key($link, -2, false, $owner_uid);
                        $p = new Publisher(PUBSUBHUBBUB_HUB);
                        $pubsub_result = $p->publish_update($rss_link);
                    }
                    $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE\n\t\t\t\t\t\t\t\tref_id = '{$ref_id}' AND owner_uid = '{$owner_uid}' AND\n\t\t\t\t\t\t\t\tfeed_id = '{$feed}' LIMIT 1");
                    if (db_num_rows($result) == 1) {
                        $entry_int_id = db_fetch_result($result, 0, "int_id");
                    }
                } else {
                    if ($debug_enabled) {
                        _debug("update_rss_feed: user record FOUND");
                    }
                    $entry_ref_id = db_fetch_result($result, 0, "ref_id");
                    $entry_int_id = db_fetch_result($result, 0, "int_id");
                }
                if ($debug_enabled) {
                    _debug("update_rss_feed: RID: {$entry_ref_id}, IID: {$entry_int_id}");
                }
                $post_needs_update = false;
                $update_insignificant = false;
                if ($orig_num_comments != $num_comments) {
                    $post_needs_update = true;
                    $update_insignificant = true;
                }
                if ($content_hash != $orig_content_hash) {
                    $post_needs_update = true;
                    $update_insignificant = false;
                }
                if (db_escape_string($orig_title) != $entry_title) {
                    $post_needs_update = true;
                    $update_insignificant = false;
                }
                // if post needs update, update it and mark all user entries
                // linking to this post as updated
                if ($post_needs_update) {
                    if (defined('DAEMON_EXTENDED_DEBUG')) {
                        _debug("update_rss_feed: post {$entry_guid} needs update...");
                    }
                    //						print "<!-- post $orig_title needs update : $post_needs_update -->";
                    db_query($link, "UPDATE ttrss_entries\n\t\t\t\t\t\t\tSET title = '{$entry_title}', content = '{$entry_content}',\n\t\t\t\t\t\t\t\tcontent_hash = '{$content_hash}',\n\t\t\t\t\t\t\t\tupdated = '{$entry_timestamp_fmt}',\n\t\t\t\t\t\t\t\tnum_comments = '{$num_comments}'\n\t\t\t\t\t\t\tWHERE id = '{$ref_id}'");
                    if (!$update_insignificant) {
                        if ($mark_unread_on_update) {
                            db_query($link, "UPDATE ttrss_user_entries\n\t\t\t\t\t\t\t\t\tSET last_read = null, unread = true WHERE ref_id = '{$ref_id}'");
                        } else {
                            if ($update_on_checksum_change) {
                                db_query($link, "UPDATE ttrss_user_entries\n\t\t\t\t\t\t\t\t\tSET last_read = null WHERE ref_id = '{$ref_id}'\n\t\t\t\t\t\t\t\t\t\tAND unread = false");
                            }
                        }
                    }
                }
            }
            db_query($link, "COMMIT");
            if ($debug_enabled) {
                _debug("update_rss_feed: assigning labels...");
            }
            assign_article_to_labels($link, $entry_ref_id, $article_filters, $owner_uid);
            if ($debug_enabled) {
                _debug("update_rss_feed: looking for enclosures...");
            }
            // enclosures
            $enclosures = array();
            if ($use_simplepie) {
                $encs = $item->get_enclosures();
                if (is_array($encs)) {
                    foreach ($encs as $e) {
                        $e_item = array($e->link, $e->type, $e->length);
                        array_push($enclosures, $e_item);
                    }
                }
            } else {
                // <enclosure>
                $e_ctr = $item['enclosure#'];
                if ($e_ctr > 0) {
                    $e_item = array($item['enclosure@url'], $item['enclosure@type'], $item['enclosure@length']);
                    array_push($enclosures, $e_item);
                    for ($i = 0; $i <= $e_ctr; $i++) {
                        if ($item["enclosure#{$i}@url"]) {
                            $e_item = array($item["enclosure#{$i}@url"], $item["enclosure#{$i}@type"], $item["enclosure#{$i}@length"]);
                            array_push($enclosures, $e_item);
                        }
                    }
                }
                // <media:content>
                // can there be many of those? yes -fox
                $m_ctr = $item['media']['content#'];
                if ($m_ctr > 0) {
                    $e_item = array($item['media']['content@url'], $item['media']['content@medium'], $item['media']['content@length']);
                    array_push($enclosures, $e_item);
                    for ($i = 0; $i <= $m_ctr; $i++) {
                        if ($item["media"]["content#{$i}@url"]) {
                            $e_item = array($item["media"]["content#{$i}@url"], $item["media"]["content#{$i}@medium"], $item["media"]["content#{$i}@length"]);
                            array_push($enclosures, $e_item);
                        }
                    }
                }
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: article enclosures:");
                print_r($enclosures);
            }
            db_query($link, "BEGIN");
            foreach ($enclosures as $enc) {
                $enc_url = db_escape_string($enc[0]);
                $enc_type = db_escape_string($enc[1]);
                $enc_dur = db_escape_string($enc[2]);
                $result = db_query($link, "SELECT id FROM ttrss_enclosures\n\t\t\t\t\t\tWHERE content_url = '{$enc_url}' AND post_id = '{$entry_ref_id}'");
                if (db_num_rows($result) == 0) {
                    db_query($link, "INSERT INTO ttrss_enclosures\n\t\t\t\t\t\t\t(content_url, content_type, title, duration, post_id) VALUES\n\t\t\t\t\t\t\t('{$enc_url}', '{$enc_type}', '', '{$enc_dur}', '{$entry_ref_id}')");
                }
            }
            db_query($link, "COMMIT");
            // check for manual tags (we have to do it here since they're loaded from filters)
            foreach ($article_filters as $f) {
                if ($f["type"] == "tag") {
                    $manual_tags = trim_array(explode(",", $f["param"]));
                    foreach ($manual_tags as $tag) {
                        if (tag_is_valid($tag)) {
                            array_push($entry_tags, $tag);
                        }
                    }
                }
            }
            // Skip boring tags
            $boring_tags = trim_array(explode(",", mb_strtolower(get_pref($link, 'BLACKLISTED_TAGS', $owner_uid, ''), 'utf-8')));
            $filtered_tags = array();
            $tags_to_cache = array();
            if ($entry_tags && is_array($entry_tags)) {
                foreach ($entry_tags as $tag) {
                    if (array_search($tag, $boring_tags) === false) {
                        array_push($filtered_tags, $tag);
                    }
                }
            }
            $filtered_tags = array_unique($filtered_tags);
            if ($debug_enabled) {
                _debug("update_rss_feed: filtered article tags:");
                print_r($filtered_tags);
            }
            // Save article tags in the database
            if (count($filtered_tags) > 0) {
                db_query($link, "BEGIN");
                foreach ($filtered_tags as $tag) {
                    $tag = sanitize_tag($tag);
                    $tag = db_escape_string($tag);
                    if (!tag_is_valid($tag)) {
                        continue;
                    }
                    $result = db_query($link, "SELECT id FROM ttrss_tags\n\t\t\t\t\t\t\tWHERE tag_name = '{$tag}' AND post_int_id = '{$entry_int_id}' AND\n\t\t\t\t\t\t\towner_uid = '{$owner_uid}' LIMIT 1");
                    if ($result && db_num_rows($result) == 0) {
                        db_query($link, "INSERT INTO ttrss_tags\n\t\t\t\t\t\t\t\t\t(owner_uid,tag_name,post_int_id)\n\t\t\t\t\t\t\t\t\tVALUES ('{$owner_uid}','{$tag}', '{$entry_int_id}')");
                    }
                    array_push($tags_to_cache, $tag);
                }
                /* update the cache */
                $tags_to_cache = array_unique($tags_to_cache);
                $tags_str = db_escape_string(join(",", $tags_to_cache));
                db_query($link, "UPDATE ttrss_user_entries\n\t\t\t\t\t\tSET tag_cache = '{$tags_str}' WHERE ref_id = '{$entry_ref_id}'\n\t\t\t\t\t\tAND owner_uid = {$owner_uid}");
                db_query($link, "COMMIT");
            }
            if ($debug_enabled) {
                _debug("update_rss_feed: article processed");
            }
        }
        if (!$last_updated) {
            if ($debug_enabled) {
                _debug("update_rss_feed: new feed, catching it up...");
            }
            catchup_feed($link, $feed, false, $owner_uid);
        }
        if ($debug_enabled) {
            _debug("purging feed...");
        }
        purge_feed($link, $feed, 0, $debug_enabled);
        db_query($link, "UPDATE ttrss_feeds\n\t\t\t\tSET last_updated = NOW(), last_error = '' WHERE id = '{$feed}'");
        //			db_query($link, "COMMIT");
    } else {
        if ($use_simplepie) {
            $error_msg = mb_substr($rss->error(), 0, 250);
        } else {
            $error_msg = mb_substr(magpie_error(), 0, 250);
        }
        if ($debug_enabled) {
            _debug("update_rss_feed: error fetching feed: {$error_msg}");
        }
        $error_msg = db_escape_string($error_msg);
        db_query($link, "UPDATE ttrss_feeds SET last_error = '{$error_msg}',\n\t\t\t\t\tlast_updated = NOW() WHERE id = '{$feed}'");
    }
    if ($use_simplepie) {
        unset($rss);
    }
    if ($debug_enabled) {
        _debug("update_rss_feed: done");
    }
}
示例#16
0
 /**
  * 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);
 }
示例#17
0
 /**
  * called by do_ajax())
  * takes action when ajax request is made with URL from the comment form
  * send back 1 or 10 last posts depending on rules
  */
 function fetch_feed()
 {
     // check nonce
     //debugbreak();
     $options = $this->get_options();
     if (isset($options['use_nonce'])) {
         $checknonce = check_ajax_referer('fetch', false, false);
         if (!$checknonce) {
             die(' error! not authorized ' . strip_tags($_REQUEST['_ajax_nonce']));
         }
     }
     if (!$_POST['url']) {
         die('no url');
     }
     if (!defined('DOING_AJAX')) {
         define('DOING_AJAX', true);
     }
     // try to prevent deprecated notices
     @ini_set('display_errors', 0);
     @error_reporting(0);
     include_once ABSPATH . WPINC . '/class-simplepie.php';
     $num = 1;
     $url = esc_url($_POST['url']);
     $orig_url = $url;
     // add trailing slash (can help with some blogs)
     if (!strpos($url, '?')) {
         $url = trailingslashit($url);
     }
     // fetch 10 last posts?
     if (is_user_logged_in() && $options['whogets'] == 'registered' || !is_user_logged_in() && $options['whogets'] == 'everybody') {
         $num = 10;
     } elseif ($options['whogets'] == 'everybody') {
         $num = 10;
     } elseif (current_user_can('manage_options')) {
         $num = 10;
     }
     // check if request is for the blog we're on
     if (strstr($url, home_url())) {
         //DebugBreak();
         $posts = get_posts(array('numberposts' => 10));
         $return = array();
         $error = '';
         if ($posts) {
             foreach ($posts as $post) {
                 $return[] = array('type' => 'blog', 'title' => htmlspecialchars_decode(strip_tags($post->post_title)), 'link' => get_permalink($post->ID), 'p' => 'u');
             }
         } else {
             $error = __('Could not get posts for home blog', $this->plugin_domain);
         }
         // check for admin only notices to add
         $canreg = get_option('users_can_register');
         $whogets = $options['whogets'];
         if (!$canreg && $whogets == 'registered') {
             $return[] = array('type' => 'message', 'title' => __('Warning! You have set to show 10 posts for registered users but you have not enabled user registrations on your site. You should change the operational settings in the CommentLuv settings page to show 10 posts for everyone or enable user registrations', $this->plugin_domain), 'link' => '');
         }
         $response = json_encode(array('error' => $error, 'items' => $return));
         header("Content-Type: application/json");
         echo $response;
         exit;
     }
     // get simple pie ready
     $rss = new SimplePie();
     if (!$rss) {
         die(' error! no simplepie');
     }
     $rss->set_useragent('Commentluv /' . $this->version . ' (Feed Parser; http://www.commentluv.com; Allow like Gecko) Build/20110502');
     $rss->set_feed_url(add_query_arg(array('commentluv' => 'true'), $url));
     $rss->enable_cache(FALSE);
     // fetch the feed
     $rss->init();
     $su = $rss->subscribe_url();
     $ferror = $rss->error();
     // try a fall back and add /?feed=rss2 to the end of url if the found subscribe url hasn't already got it
     // also try known blogspot feed location if this is a blogspot url
     if ($ferror || strstr($ferror, 'could not be found') && !strstr($su, 'feed')) {
         unset($rss);
         $rss = new SimplePie();
         $rss->set_useragent('Commentluv /' . $this->version . ' (Feed Parser; http://www.commentluv.com; Allow like Gecko) Build/20110502');
         $rss->enable_cache(FALSE);
         // construct alternate feed url
         if (strstr($url, 'blogspot')) {
             $url = trailingslashit($url) . 'feeds/posts/default/';
         } else {
             $url = add_query_arg(array('feed' => 'atom'), $url);
         }
         $rss->set_feed_url($url);
         $rss->init();
         $ferror = $rss->error();
         if ($ferror || stripos($ferror, 'invalid')) {
             $suburl = $rss->subscribe_url() ? $rss->subscribe_url() : $orig_url;
             unset($rss);
             $rss = new SimplePie();
             $rss->set_useragent('Commentluv /' . $this->version . ' (Feed Parser; http://www.commentluv.com; Allow like Gecko) Build/20110502');
             $rss->enable_cache(FALSE);
             $rss->set_feed_url($orig_url);
             $rss->init();
             $ferror = $rss->error();
             // go back to original URL if error persisted
             if (stripos($ferror, 'invalid')) {
                 //get raw file to show any errors
                 @(include_once ABSPATH . WPINC . '/SimplePie/File.php');
                 if (class_exists('SimplePie_File')) {
                     $rawfile = new SimplePie_File($suburl, $rss->timeout, 5, null, $rss->useragent, $rss->force_fsockopen);
                 } elseif (class_exists($rss->file_class)) {
                     $rawfile = new $rss->file_class($suburl, $rss->timeout, 5, null, $rss->useragent, $rss->force_fsockopen);
                 }
                 if (isset($rawfile->body)) {
                     $rawfile = $rawfile->body;
                 } else {
                     $rawfile = __('Raw file could not be found', $this->plugin_domain);
                 }
             }
         }
     }
     $rss->handle_content_type();
     $gen = $rss->get_channel_tags('', 'generator');
     $prem_msg = $rss->get_channel_tags('', 'prem_msg');
     $g = $num;
     $p = 'u';
     $meta = array();
     //DebugBreak();
     if ($gen && strstr($gen[0]['data'], 'commentluv')) {
         $generator = $gen[0]['data'];
         $meta['generator'] = $generator;
         $pos = stripos($generator, 'v=');
         if (substr($generator, $pos + 2, 1) == '3') {
             $g = 15;
             $p = 'p';
         }
     }
     if ($prem_msg) {
         $prem_msg = $prem_msg[0]['data'];
     }
     //DebugBreak();
     $error = $rss->error();
     $meta['used_feed'] = $rss->subscribe_url();
     //DebugBreak();
     // no error, construct return json
     if (!$error) {
         $arr = array();
         // save meta
         $meta['used_feed'] = $rss->subscribe_url();
         $feed_items = $rss->get_items();
         foreach ($feed_items as $item) {
             //debugbreak();
             $type = 'blog';
             $itemtags = $item->get_item_tags('', 'type');
             if ($itemtags) {
                 $type = $itemtags[0]['data'];
             }
             $arr[] = array('type' => $type, 'title' => htmlspecialchars_decode(strip_tags($item->get_title())), 'link' => $item->get_permalink(), 'p' => $p);
             $g--;
             if ($g < 1) {
                 break;
             }
         }
         // add message to unregistered user if set
         if (!is_user_logged_in() && $options['unreg_user_text'] && $options['whogets'] != 'everybody' && $p == 'u') {
             if (get_option('users_can_register')) {
                 $arr[] = array('type' => 'message', 'title' => $options['unreg_user_text'], 'link' => '');
                 if (!strstr($options['unreg_user_text'], 'action=register')) {
                     $register_link = apply_filters('register', '<a href="' . site_url('wp-login.php?action=register', 'login') . '">' . __('Register') . '</a>');
                     $arr[] = array('type' => 'message', 'title' => $register_link, 'link' => '');
                 }
             }
             if ($options['whogets'] == 'registered' && get_option('users_can_regsiter')) {
                 $arr[] = array('type' => 'message', 'title' => __('If you are registered, you need to log in to get 10 posts to choose from', $this->plugin_domain), 'link' => '');
             }
         }
         if ($prem_msg) {
             $arr[] = array('type' => 'alert', 'title' => $prem_msg, 'link' => '');
         }
         $response = json_encode(array('error' => '', 'items' => $arr, 'meta' => $meta));
     } else {
         // had an error trying to read the feed
         $response = json_encode(array('error' => $error, 'meta' => $meta, 'rawfile' => htmlspecialchars($rawfile)));
     }
     unset($rss);
     header("Content-Type: application/json");
     echo $response;
     exit;
 }