get_favicon() public method

Get the favicon for the current feed
Deprecation: Use your own favicon handling instead
public get_favicon ( )
Example #1
0
 /**
  * Handles all of the heavy lifting for getting the feed, parsing it, and managing customizations.
  *
  * @access private
  * @param mixed $url Either a single feed URL (as a string) or an array of feed URLs (as an array of strings).
  * @param array $options An associative array of options that the function should take into account when rendering the markup.
  * <ul>
  *     <li>string $classname  - The classname that the <div> surrounding the feed should have. Defaults to nb-list for newsblocks::listing() and nb-wide for newsblocks::wide().</li>
  *     <li>string $copyright - The copyright string to use for a feed. Not part of the standard output, but it's available if you want to use it. Defaults to NULL with multifeeds; Use $item->get_feed()->get_copyright() instead.</li>
  *     <li>string $date_format - The format to use when displaying dates on items. Uses values from http://php.net/strftime, NOT http://php.net/date.</li>
  *     <li>string $description - The description for the feed (not the item). Not part of the standard output, but it's available if you want to use it. Defaults to NULL with multifeeds; Use $item->get_feed()->get_description() instead.</li>
  *     <li>string $direction - The direction of the text. Valid values are "ltr" and "rtl". Defaults to "ltr".</li>
  *     <li>string $favicon - The favicon URL to use for the feed. Since favicon URLs aren't actually located in feeds, SimplePie guesses. Sometimes that guess is wrong. Give it the correct favicon with this option. Defaults to NULL with multifeeds; Use $item->get_feed()->get_favicon() instead.</li>
  *     <li>string $id - The ID attribute that the <div> surrounding the feed should have. This value should be unique per feed. Defaults to a SHA1 hash value based on the URL(s).</li>
  *     <li>string $item_classname - The classname for the items. Useful for styling with CSS. Also useful for JavaScript in creating custom tooltips for a feed. Defaults to "tips".</li>
  *     <li>integer $items - The number of items to show (the rest are hidden until "More" is clicked). Defaults to 10.</li>
  *     <li>string $language - The language of the feed. Not part of the standard output, but it's available if you want to use it. Defaults to NULL with multifeeds; Use $item->get_feed()->get_language() instead.</li>
  *     <li>integer $length - The maximum character length of the item description in the tooltip. Defaults to 200.</li>
  *     <li>string $more - The text to use for the "More" link. Defaults to "More &raquo;"</li>
  *     <li>boolean $more_move - Whether the "More" link should move when it's clicked. Defaults to FALSE (i.e. stays in the same place).</li>
  *     <li>boolean $more_fx - Whether the secondary list should slide or simply appear/disappear when the "More" link is clicked. Defaults to TRUE (i.e. slides).</li>
  *     <li>string $permalink - The permalink for the feed (not the item). Defaults to NULL with multifeeds; Use $item->get_feed()->get_permalink() instead.</li>
  *     <li>boolean $show_title - Whether to show the title of the feed. Defaults to TRUE.</li>
  *     <li>integer $since - A Unix timestamp. Anything posted more recently than this timestamp will get the "New" image applied to it. Defaults to 24 hours ago.</li>
  *     <li>$string $title - The title for the feed (not the item). Defaults to multiple titles with multifeeds, so you should manually set it in that case.</li>
  * </ul>
  * @return string The (X)HTML markup to display on the page.
  */
 function data($url, $options = null)
 {
     // Create a new SimplePie instance with this feed
     $feed = new SimplePie();
     $feed->set_feed_url($url);
     $feed->init();
     // Prep URL values to hash later.
     if (!is_array($url)) {
         $hash_str = array($url);
     } else {
         $hash_str = $url;
     }
     // Set the default values.
     $classname = null;
     $copyright = $feed->get_copyright();
     $date_format = '%a, %e %b %Y, %I:%M %p';
     $description = $feed->get_description();
     $direction = 'ltr';
     $favicon = $feed->get_favicon();
     $id = 'a' . sha1(implode('', $hash_str));
     $item_classname = 'tips';
     $items = 10;
     $language = $feed->get_language();
     $length = 200;
     $more = 'More &raquo;';
     $more_move = false;
     $more_fx = true;
     $permalink = $feed->get_permalink();
     $show_title = true;
     $since = time() - 24 * 60 * 60;
     // 24 hours ago.
     $title = $feed->get_title();
     // Override defaults with passed-in values.
     extract($options);
     // Set values for those that are still null
     if (!$favicon) {
         $favicon = NB_FAVICON_DEFAULT;
     }
     if (!$title) {
         if (is_array($url)) {
             $feed_title = array();
             foreach ($url as $u) {
                 $feed_title[] = newsblocks::name($u);
             }
             $title = implode(', ', $feed_title);
         }
     }
     // Send the data back to the calling function.
     return array('classname' => $classname, 'copyright' => $copyright, 'date_format' => $date_format, 'description' => $description, 'direction' => $direction, 'favicon' => $favicon, 'feed' => $feed, 'id' => $id, 'item_classname' => $item_classname, 'items' => $items, 'language' => $language, 'length' => $length, 'more' => $more, 'more_move' => $more_move, 'more_fx' => $more_fx, 'permalink' => $permalink, 'show_title' => $show_title, 'since' => $since, 'title' => $title);
 }
Example #2
0
 function addSubscription($xml, $tags)
 {
     // OPML Required attributes: text,xmlUrl,type
     // Optional attributes: title, htmlUrl, language, title, version
     if ($xml['type'] != 'rss' && $xml['type'] != 'atom') {
         $title = (string) $xml['text'];
         echo "RSS type not supported for: {$title}<br>";
     } else {
         // description
         $title = (string) $xml['text'];
         // RSS URL
         $data['url'] = (string) $xml['xmlUrl'];
         //check if feed_name already exists in database
         $database->query("SELECT count(*) as count FROM t_feeds WHERE feed_name = :name");
         $database->bind(':name', $title);
         $row = $database->single();
         $count = $row['count'];
         if ($count > 0) {
             echo "SKIPPED: {$title}<br>";
         } else {
             echo "ADDED: {$title} {$data['url']} <br>";
             //Get favoicon for each rss feed
             if (isset($_POST['favoicon'])) {
                 $getfavoicon = htmlspecialchars($_POST['favoicon']);
             } else {
                 $getfavoicon = NULL;
                 $favicon = NULL;
             }
             //get favoicon
             if ($getfavoicon == 'Yes') {
                 $feed = new SimplePie($data[url]);
                 $feed->init();
                 $feed->handle_content_type();
                 $favicon = $feed->get_favicon();
             }
             $database->beginTransaction();
             $database->query("INSERT INTO t_feeds (feed_name, url, favicon) VALUES (:feed_name, :url, :favicon)");
             $database->bind(':feed_name', $title);
             $database->bind(':url', $data['url']);
             $database->bind(':favicon', $favicon);
             $database->execute();
             $database->endTransaction();
         }
     }
 }
Example #3
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;
 }
Example #4
0
    ?>
">My Yahoo!</a>, <a href="<?php 
    echo $feed->subscribe_feed();
    ?>
">Desktop Reader</a></p>


				<!-- Let's begin looping through each individual news item in the feed. -->
				<?php 
    foreach ($feed->get_items() as $item) {
        ?>
					<div class="chunk">

						<?php 
        // Let's add a favicon for each item. If one doesn't exist, we'll use an alternate one.
        if (!($favicon = $feed->get_favicon())) {
            $favicon = './for_the_demo/favicons/alternate.png';
        }
        ?>

						<!-- If the item has a permalink back to the original post (which 99% of them do), link the item's title to it. -->
						<h4><img src="<?php 
        echo $favicon;
        ?>
" alt="Favicon" class="favicon" /><?php 
        if ($item->get_permalink()) {
            echo '<a href="' . $item->get_permalink() . '">';
        }
        echo $item->get_title(true);
        if ($item->get_permalink()) {
            echo '</a>';
 function fetchFeeds($opt = null)
 {
     global $serendipity;
     set_time_limit(360);
     ignore_user_abort(true);
     $_SESSION['serendipityRightPublish'] = true;
     $serendipity['noautodiscovery'] = true;
     $this->setupDB();
     $feeds = $this->getFeeds($opt);
     $engine = $this->get_config('engine', 'onyx');
     if ($engine == 'onyx') {
         require_once (defined('S9Y_PEAR_PATH') ? S9Y_PEAR_PATH : S9Y_INCLUDE_PATH . 'bundled-libs/') . 'Onyx/RSS.php';
     } elseif ($engine == 'magpierss') {
         // CLSC: NEW "MagpieRSS" include
         require_once dirname(__FILE__) . '/magpierss/rss_fetch.inc';
     } elseif ($engine == 'simplepie') {
         //hwa: NEW "SimplePie" include
         require_once dirname(__FILE__) . '/simplepie/simplepie.inc';
     }
     $cache_authors = array();
     $cache_entries = array();
     $cache_md5 = array();
     $sql_cache_authors = serendipity_db_Query("SELECT authorid, realname\n                                                 FROM {$serendipity['dbPrefix']}authors");
     if (is_array($sql_cache_authors)) {
         foreach ($sql_cache_authors as $idx => $author) {
             $cache_authors[$author['realname']] = $author['authorid'];
         }
     }
     if ($this->debug) {
         printf("DEBUG: cache_authors['realname'] = authorid has %d entries\n", count($cache_authors));
     }
     if ($opt['store_seperate']) {
         $sql_cache_entries = serendipity_db_query("SELECT e.feedid, e.id, e.entrydate, e.entrytitle\n                                                         FROM {$serendipity['dbPrefix']}aggregator_feedlist AS e");
         if (is_array($sql_cache_entries)) {
             foreach ($sql_cache_entries as $idx => $entry) {
                 $cache_entries[$entry['entrytitle']][$entry['feedid']][$entry['entrydate']] = $entry['id'];
             }
         }
     } else {
         $sql_cache_entries = serendipity_db_query("SELECT e.id, e.timestamp, e.authorid, e.title, ep.value\n                                                         FROM {$serendipity['dbPrefix']}entries AS e,\n                                                              {$serendipity['dbPrefix']}entryproperties AS ep\n                                                        WHERE e.id = ep.entryid\n                                                          AND ep.property = 'ep_aggregator_feed'");
         if (is_array($sql_cache_entries)) {
             foreach ($sql_cache_entries as $idx => $entry) {
                 $cache_entries[$entry['title']][$entry['authorid']][$entry['timestamp']] = $entry['id'];
             }
         }
     }
     if ($this->debug) {
         printf("DEBUG: cache_entries['title']['authorid']['timestamp'] = entryid has %d entries.\n", count($cache_entries));
     }
     $sql_cache_md5 = serendipity_db_query("SELECT entryid, md5, timestamp\n                                                     FROM {$serendipity['dbPrefix']}aggregator_md5");
     if (is_array($sql_cache_md5)) {
         foreach ($sql_cache_md5 as $idx => $entry) {
             $cache_md5[$entry['md5']]['entryid'] = $entry['entryid'];
             $cache_md5[$entry['md5']]['timestamp'] = $entry['timestamp'];
         }
     }
     if ($this->debug) {
         printf("DEBUG: cache_md5['md5'] = entryid has %d entries.\n", count($cache_md5));
     }
     foreach ($feeds as $feed) {
         if (!$opt['store_seperate']) {
             printf("Read %s.\n", $feed['feedurl']);
         }
         flush();
         $feed_authorid = $cache_authors[$feed['feedname']];
         if (empty($feed_authorid)) {
             $feed_authorid = 0;
         }
         if ($this->debug) {
             printf("DEBUG: Current authorid = %d\n", $feed_authorid);
         }
         $stack = array();
         if ($engine == 'onyx') {
             if (empty($feed['charset'])) {
                 $this->checkCharset($feed);
             }
             # test multiple likely charsets
             $charsets = array($feed['charset'], "ISO-8859-1", "utf-8");
             $retry = false;
             foreach ($charsets as $ch) {
                 if ($retry) {
                     printf("DEBUG: Retry with charset %s instead of %s\n", $ch, $feed['charset']);
                 }
                 $retry = true;
                 $c = new Onyx_RSS($ch);
                 # does it parse? if so, all is fine...
                 if ($c->parse($feed['feedurl'])) {
                     break;
                 }
             }
             while ($item = $c->getNextItem()) {
                 /* Okay this is where things get tricky. Everybody
                  * encodes their information differently. For now I'm going to focus on
                  * s9y weblogs. */
                 $fake_timestamp = false;
                 $date = $this->parseDate($item['pubdate']);
                 if ($this->debug) {
                     printf("DEBUG: pubDate %s = %s\n", $item['pubdate'], $date);
                 }
                 if ($date == -1) {
                     // Fallback to try for dc:date
                     $date = $this->parseDate($item['dc:date']);
                     if ($this->debug) {
                         printf("DEBUG: falling back to dc:date % s= %s\n", $item['dc:date'], $date);
                     }
                 }
                 if ($date == -1) {
                     // Couldn't figure out the date string. Set it to "now" and hope that the md5hash will get it.
                     $date = time();
                     $fake_timestamp = true;
                     if ($this->debug) {
                         printf("DEBUG: falling back to time() = %s\n", $date);
                     }
                 }
                 if (empty($item['title'])) {
                     if ($this->debug) {
                         printf("DEBUG: skip item: title was empty for %s\n", print_r($item, true));
                     }
                     continue;
                 }
                 $this->decode($c->rss['encoding'], $item);
                 $item['date'] = $date;
                 $stack[] = $item;
             }
         } elseif ($engine == 'magpierss') {
             // ----------------------------------------------------------
             // CLSC: New MagpieRSS code start
             // ----------------------------------------------------------
             $rss = fetch_rss($feed['feedurl']);
             foreach ($rss->items as $item) {
                 $fake_timestamp = false;
                 $date = $item['pubdate'];
                 if ($this->debug) {
                     printf("DEBUG: pubdate = %s\n", $item['pubdate'], $date);
                 }
                 // ----------------------------------------------------------
                 // CLSC:        Try a few different types of timestamp fields
                 //                So that we might get lucky even with non-standard feeds
                 // ----------------------------------------------------------
                 if ($date == "") {
                     // CLSC: magpie syntax for nested fields
                     $date = $item['dc']['date'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to [dc][date] = %s\n", $item['dc:date'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['modified'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to modified = %s\n", $item['modified'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['PubDate'];
                     if ($this->debug) {
                         printf("DEBUG: falling back PubDate = %s\n", $item['PubDate'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['created'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to created = %s\n", $item['created'], $date);
                     }
                 }
                 if ($date == "") {
                     // CLSC: not proper magpie syntax but still catches some
                     $date = $item['dc:date'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to dc:date = %s\n", $item['dc:date'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['updated'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to updated = %s\n", $item['updated'], $date);
                     }
                 }
                 if ($date == "") {
                     $date = $item['published'];
                     if ($this->debug) {
                         printf("DEBUG: falling back to published = %s\n", $item['published'], $date);
                     }
                 }
                 if ($date == "") {
                     // ----------------------------------------------------------
                     //    CLSC:        If none of the above managed to identify a date:
                     //                 Set date to "now" and hope that the md5hash will get it.
                     // ----------------------------------------------------------
                     $date = time();
                     $fake_timestamp = true;
                     if ($this->debug) {
                         printf("DEBUG: falling back to time() = %s\n", $date);
                     }
                 }
                 // CLSC: if date is set to "now" parseDate can't parse it.
                 if ($fake_timestamp != true) {
                     $date = $this->parseDate($date);
                 }
                 if ($item['title'] == "") {
                     if ($this->debug) {
                         printf("DEBUG: skip item: title was empty for %s\n", print_r($item, true));
                     }
                     continue;
                 }
                 $item['date'] = $date;
                 $stack[] = $item;
                 // ----------------------------------------------------------
                 //    CLSC: New MagpieRSS code end
                 // ----------------------------------------------------------
             }
         } elseif ($engine == 'simplepie') {
             // hwa: new SimplePie code  ; lifted from the SimplePie demo
             $simplefeed = new SimplePie();
             $simplefeed->cache = false;
             $simplefeed->set_feed_url($feed['feedurl']);
             // Initialize the whole SimplePie object.  Read the feed, process it, parse it, cache it, and
             // all that other good stuff.  The feed's information will not be available to SimplePie before
             // this is called.
             $success = $simplefeed->init();
             // We'll make sure that the right content type and character encoding gets set automatically.
             // This function will grab the proper character encoding, as well as set the content type to text/html.
             $simplefeed->set_output_encoding(LANG_CHARSET);
             $simplefeed->handle_content_type();
             $item['new_feedicon'] = $simplefeed->get_favicon();
             // error handling
             if ($simplefeed->error()) {
                 if (!$opt['store_seperate']) {
                     printf('<p><b>ERROR:</b> ' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($simplefeed->error()) : htmlspecialchars($simplefeed->error(), ENT_COMPAT, LANG_CHARSET)) . "</p>\r\n");
                 }
             }
             if ($success) {
                 foreach ($simplefeed->get_items() as $simpleitem) {
                     // map SimplePie items to s9y items
                     $item['title'] = $simpleitem->get_title();
                     $item['date'] = $simpleitem->get_date('U');
                     $item['pubdate'] = $simpleitem->get_date('U');
                     $item['description'] = $simpleitem->get_description();
                     $item['content'] = $simpleitem->get_content();
                     $item['link'] = $simpleitem->get_permalink();
                     $item['author'] = $simpleitem->get_author();
                     //if ($this->debug) {
                     //  printf("DEBUG: SimplePie item: author: $item['author'], title: $item['title'], date: $item['date']\n");
                     //}
                     $stack[] = $item;
                 }
             } else {
                 if (!$opt['store_seperate']) {
                     printf('<p><b>ERROR:</b> ' . print_r($success, true) . "</p>\r\n");
                 }
             }
         }
         while (list($key, $item) = each($stack)) {
             if ($opt['store_seperate']) {
                 $ep_id = $cache_entries[$item['title']][$feed['feedid']][$item['date']];
                 if ($this->debug) {
                     printf("DEBUG: lookup cache_entries[%s][%s][%s] finds %s.\n", $item['title'], $feed['feedid'], $item['date'], empty($ep_id) ? "nothing" : $ep_id);
                 }
             } else {
                 $ep_id = $cache_entries[$item['title']][$feed_authorid][$item['date']];
                 if ($this->debug) {
                     printf("DEBUG: lookup cache_entries[%s][%s][%s] finds %s.\n", $item['title'], $feed_authorid, $item['date'], empty($ep_id) ? "nothing" : $ep_id);
                 }
             }
             if (!empty($ep_id) and serendipity_db_bool($this->get_config('ignore_updates'))) {
                 if ($this->debug) {
                     printf("DEBUG: entry %s is known and ignore_updates is set.\n", $ep_id);
                 }
                 continue;
             }
             # NOTE: If $ep_id is NULL or EMPTY, it means that an entry with this title does not
             #       yet exist. Later on we check if a similar entry with the body exists and skip
             #       updates in this case. Else it means that the new entry needs to be inserted
             #       as a new one.
             # The entry is probably new?
             $entry = array('id' => $ep_id, 'title' => $item['title'], 'timestamp' => $item['date'], 'extended' => '', 'isdraft' => serendipity_db_bool($this->get_config('publishflag')) ? 'false' : 'true', 'allow_comments' => serendipity_db_bool($this->get_config('allow_comments')) ? 'true' : 'false', 'categories' => $feed['categoryids'], 'author' => $feed['feedname'], 'authorid' => $feed_authorid);
             // ----------------------------------------------------------
             //    CLSC: Added a few flavours
             if ($item['content:encoded']) {
                 $entry['body'] = $item['content:encoded'];
             } elseif ($item['description']) {
                 $entry['body'] = $item['description'];
             } elseif ($item['content']['encoded']) {
                 $entry['body'] = $item['content']['encoded'];
             } elseif ($item['atom_content']) {
                 $entry['body'] = $item['atom_content'];
             } elseif ($item['content']) {
                 $entry['body'] = $item['content'];
             }
             $md5hash = md5($feed_authorid . $item['title'] . $entry['body']);
             # Check 1: Have we seen this MD5?
             if ($this->debug) {
                 printf("DEBUG: lookup cache_md5[%s] finds %s.\n", $md5hash, empty($cache_md5[$md5hash]) ? "nothing" : $cache_md5[$md5hash]['entryid']);
             }
             # If we have this md5, title and body for this article
             # are unchanged. We do not need to do anything.
             if (isset($cache_md5[$md5hash])) {
                 continue;
             }
             # Check 2 (conditional: expire enabled?):
             #         Is this article too old?
             if ($this->get_config('expire') > 0) {
                 $expire = time() - 86400 * $this->get_config('expire');
                 if ($item['date'] < $expire) {
                     if ($this->debug) {
                         printf("DEBUG: '%s' is too old (%s < %s).\n", $item['title'], $item['date'], $expire);
                     }
                     continue;
                 }
             }
             # Check 3: Does this article match our expressions?
             if (!empty($feed['match_expression'])) {
                 $expressions = explode("~", $feed['match_expression']);
                 $match = 0;
                 foreach ($expressions as $expression) {
                     $expression = ltrim(rtrim($expression));
                     if (preg_match("~{$expression}~imsU", $entry['title'] . $entry['body'])) {
                         $match = 1;
                     }
                 }
                 if ($match == 0) {
                     continue;
                 }
             }
             $feed['articleurl'] = $item['link'];
             if ($item['author']) {
                 $feed['author'] = $item['author'];
             } elseif ($item['dc:creator']) {
                 $feed['author'] = $item['dc:creator'];
             }
             // Store as property
             // Plugins might need this.
             $serendipity['POST']['properties'] = array('fake' => 'fake');
             $markups = explode('^', $this->get_config('markup'));
             if (is_array($markups)) {
                 foreach ($markups as $markup) {
                     $serendipity['POST']['properties']['disable_markups'][] = $markup;
                 }
             }
             if ($opt['store_seperate']) {
                 if ($entry['id'] > 0) {
                     serendipity_db_query("UPDATE {$serendipity['dbPrefix']}aggregator_feedlist \n                        SET feedid      = '" . $feed['feedid'] . "',\n                            categoryid  = '" . $feed['categoryids'][0] . "',\n                            entrydate   = '" . serendipity_db_escape_string($entry['timestamp']) . "',\n                            entrytitle  = '" . serendipity_db_escape_string($entry['title']) . "',\n                            entrybody   = '" . serendipity_db_escape_string($entry['body']) . "',\n                            entryurl    = '" . serendipity_db_escape_string($item['link']) . "'\n                        WHERE id = " . $entry['id']);
                     $entryid = $entry['id'];
                 } else {
                     serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}aggregator_feedlist (\n                            feedid,\n                            categoryid,\n                            entrydate,\n                            entrytitle,\n                            entrybody,\n                            entryurl\n                        ) VALUES (\n                            '" . $feed['feedid'] . "',\n                            '" . $feed['categoryids'][0] . "',\n                            '" . serendipity_db_escape_string($entry['timestamp']) . "',\n                            '" . serendipity_db_escape_string($entry['title']) . "',\n                            '" . serendipity_db_escape_string($entry['body']) . "',\n                            '" . serendipity_db_escape_string($item['link']) . "'\n                        )");
                     $entryid = serendipity_db_insert_id();
                 }
                 $this->feedupdate_finish($feed, $entryid);
             } else {
                 $entryid = serendipity_updertEntry($entry);
                 $this->insertProperties($entryid, $feed, $md5hash);
             }
             if (!$opt['store_seperate']) {
                 printf(" Save '%s' as %s.\n", $item['title'], $entryid);
             }
         }
         if (!$opt['store_seperate']) {
             printf("Finish feed.\n");
         }
     }
     if (!$opt['store_seperate']) {
         printf("Finish planetarium.\n");
     }
 }
Example #6
0
 function save_options($validate = true)
 {
     $urls = $this->get_url();
     if (!is_array($urls)) {
         $urls = array($urls);
     }
     $url = $urls[0];
     if (is_array($url)) {
         $url = $url[0];
     }
     $feed = new SimplePie();
     $feed->enable_cache(false);
     if ($validate) {
         $data = $this->lifestream->file_get_contents($url);
         $feed->set_raw_data($data);
         $feed->enable_order_by_date(false);
         $feed->force_feed(true);
         $success = $feed->init();
     }
     if ($this->get_option('auto_icon') == 2 && ($url = $feed->get_favicon())) {
         if ($this->lifestream->validate_image($url)) {
             $this->update_option('icon_url', $url);
         } else {
             $this->update_option('icon_url', '');
         }
     }
     // elseif ($this->get_option('icon_url'))
     // {
     //  if (!$this->lifestream->validate_image($this->get_option('icon_url')))
     //  {
     //	  throw new Lifestream_Error($this->lifestream->__('The icon url is not a valid image.'));
     //  }
     // }
     parent::save_options();
 }
Example #7
0
 /**
  * Edit feed
  *
  * @param	integer	$feed_id
  * @param	array	$data
  * @return	boolean	true on succes, or false on fail
  */
 public function edit_feed($feed_id, $data)
 {
     if (!$this->check_token()) {
         return false;
     }
     $sm = vivvo_lite_site::get_instance();
     if ($sm->user and $sm->user->can('MANAGE_PLUGIN', 'feed_importer')) {
         if (!vivvo_hooks_manager::call('feed_edit', array(&$feed_id, &$data))) {
             return vivvo_hooks_manager::get_status();
         }
         $feed_list = new Feeds_list();
         $feed_list->search(array());
         if (!empty($data['feed'])) {
             $remove_keys = array_diff(array_keys($feed_list->list), array_keys($data['feed']));
         } else {
             $remove_keys = array_keys($feed_list->list);
         }
         if (!empty($remove_keys)) {
             $feed_list->sql_delete_list($this->_post_master, $remove_keys);
         }
         $edit_keys = $feed_list->get_list_ids();
         $feed_check = array();
         require_once VIVVO_FS_INSTALL_ROOT . 'lib/simplepie/simplepie.php';
         if (is_array($edit_keys) and !empty($edit_keys)) {
             foreach ($edit_keys as $edit_key) {
                 if (!in_array($data['feed'][$edit_key]['feed'], $feed_check)) {
                     $feed_check[] = $data['feed'][$edit_key]['feed'];
                     $feed_list->list[$edit_key]->set_feed($data['feed'][$edit_key]['feed']);
                     $feed_list->list[$edit_key]->set_category_id($data['feed'][$edit_key]['category_id']);
                     $feed_list->list[$edit_key]->set_author($data['feed'][$edit_key]['author']);
                     $simplepie = new SimplePie();
                     $simplepie->enable_cache(false);
                     $simplepie->set_feed_url($data['feed'][$edit_key]['feed']);
                     @$simplepie->init();
                     if (!$simplepie->error()) {
                         $feed_list->list[$edit_key]->set_favicon($simplepie->get_favicon());
                         $this->_post_master->set_data_object($feed_list->list[$edit_key]);
                         $this->_post_master->sql_update();
                     }
                 } else {
                     $this->_post_master->set_data_object($feed_list->list[$edit_key]);
                     $this->_post_master->sql_delete();
                 }
             }
         }
         if (is_array($data['new_feed']) and !empty($data['new_feed'])) {
             foreach ($data['new_feed'] as $add_key => $value) {
                 if (!in_array($data['new_feed'][$add_key]['feed'], $feed_check)) {
                     $feed_check[] = $data['new_feed'][$add_key]['feed'];
                     $new_feed_object = new Feeds();
                     $new_feed_object->set_feed($data['new_feed'][$add_key]['feed']);
                     $new_feed_object->set_category_id($data['new_feed'][$add_key]['category_id']);
                     $new_feed_object->set_author($data['new_feed'][$add_key]['author']);
                     $simplepie = new SimplePie();
                     $simplepie->enable_cache(false);
                     $simplepie->set_feed_url($data['new_feed'][$add_key]['feed']);
                     @$simplepie->init();
                     if (!$simplepie->error()) {
                         $new_feed_object->set_favicon($simplepie->get_favicon());
                         $this->_post_master->set_data_object($new_feed_object);
                         $this->_post_master->sql_insert();
                     }
                 }
             }
         }
         return true;
     } else {
         $this->set_error_code(10103);
         // you don't have sufficient privileges for this action
         return false;
     }
 }
Example #8
0
function getFaviconURL($location)
{
    if (!$location) {
        return false;
    } else {
        $temp = new SimplePie();
        $temp->set_feed_url($location);
        $temp->init();
        if ($temp->get_favicon()) {
            return $temp->get_favicon();
        }
        $url_parts = parse_url($location);
        $full_url = "http://{$url_parts['host']}";
        if (isset($url_parts['port'])) {
            $full_url .= ":{$url_parts['port']}";
        }
        $favicon_url = $full_url . "/favicon.ico";
    }
    return $favicon_url;
}
/**
 * The actual function that can be called on webpages.
 */
function SimplePieWP($feed_url, $options = null)
{
    // Quit if the SimplePie class isn't loaded.
    if (!class_exists('SimplePie')) {
        die('<p style="font-size:16px; line-height:1.5em; background-color:#c00; color:#fff; padding:10px; border:3px solid #f00; text-align:left;"><img src="' . SIMPLEPIE_PLUGINDIR_WEB . '/images/error.png" /> There is a problem with the SimplePie Plugin for WordPress. Check your <a href="' . WP_CPANEL . '" style="color:#ff0; text-decoration:underline;">Installation Status</a> for more information.</p>');
    }
    if (isset($locale) && !empty($locale) && $locale != 'auto') {
        setlocale(LC_TIME, $locale);
    }
    // Default general settings
    $template = get_option('simplepie_template');
    $items = get_option('simplepie_items');
    $items_per_feed = get_option('simplepie_items_per_feed');
    $date_format = get_option('simplepie_date_format');
    $enable_cache = get_option('simplepie_enable_cache');
    $set_cache_location = get_option('simplepie_set_cache_location');
    $set_cache_duration = get_option('simplepie_set_cache_duration');
    $enable_order_by_date = get_option('simplepie_enable_order_by_date');
    $set_timeout = get_option('simplepie_set_timeout');
    // Default text-shortening settings
    $truncate_feed_title = get_option('simplepie_truncate_feed_title');
    $truncate_feed_description = get_option('simplepie_truncate_feed_description');
    $truncate_item_title = get_option('simplepie_truncate_item_title');
    $truncate_item_description = get_option('simplepie_truncate_item_description');
    // Default advanced settings
    $processing = get_option('simplepie_processing');
    $locale = get_option('simplepie_locale');
    $local_date_format = get_option('simplepie_local_date_format');
    $strip_htmltags = get_option('simplepie_strip_htmltags');
    $strip_attributes = get_option('simplepie_strip_attributes');
    $set_max_checked_feeds = get_option('simplepie_set_max_checked_feeds');
    // Overridden settings
    if ($options) {
        // Fix the template location if one was passed in.
        if (isset($options['template']) && !empty($options['template'])) {
            $options['template'] = SIMPLEPIE_PLUGINDIR . '/templates/' . strtolower(str_replace(' ', '_', $options['template'])) . '.tmpl';
        }
        // Fix the processing location if one was passed in.
        if (isset($options['processing']) && !empty($options['processing'])) {
            $options['processing'] = SIMPLEPIE_PLUGINDIR . '/processing/' . strtolower(str_replace(' ', '_', $options['processing'])) . '.php';
        }
        extract($options);
    }
    // Load post-processing file.
    if ($processing && $processing != '') {
        include_once $processing;
    }
    // If template doesn't exist, die.
    if (!file_exists($template) || !is_readable($template)) {
        die('<p style="font-size:16px; line-height:1.5em; background-color:#c00; color:#fff; padding:10px; border:3px solid #f00; text-align:left;"><img src="' . SIMPLEPIE_PLUGINDIR_WEB . '/images/error.png" /> The SimplePie template file is not readable by WordPress. Check the <a href="' . WP_CPANEL . '" style="color:#ff0; text-decoration:underline;">WordPress Control Panel</a> for more information.</p>');
    }
    // Initialize SimplePie
    $feed = new SimplePie();
    $feed->set_feed_url($feed_url);
    $feed->enable_cache($enable_cache);
    $feed->set_item_limit($items_per_feed);
    $feed->set_cache_location($set_cache_location);
    $feed->set_cache_duration($set_cache_duration);
    $feed->enable_order_by_date($enable_order_by_date);
    $feed->set_timeout($set_timeout);
    $feed->strip_htmltags(explode(' ', $strip_htmltags));
    $feed->strip_attributes(explode(' ', $strip_attributes));
    $feed->set_max_checked_feeds($set_max_checked_feeds);
    $feed->init();
    // Load up the selected template file
    $handle = fopen($template, 'r');
    $tmpl = fread($handle, filesize($template));
    fclose($handle);
    /**************************************************************************************************************/
    // ERRORS
    // I'm absolutely sure that there is a better way to do this.
    // Define what we're looking for
    $error_start_tag = '{IF_ERROR_BEGIN}';
    $error_end_tag = '{IF_ERROR_END}';
    $error_start_length = strlen($error_start_tag);
    $error_end_length = strlen($error_end_tag);
    // Find what we're looking for
    $error_start_pos = strpos($tmpl, $error_start_tag);
    $error_end_pos = strpos($tmpl, $error_end_tag);
    $error_length_pos = $error_end_pos - $error_start_pos;
    // Grab what we're looking for
    $error_string = substr($tmpl, $error_start_pos + $error_start_length, $error_length_pos - $error_start_length);
    $replacable_string = $error_start_tag . $error_string . $error_end_tag;
    if ($error_message = $feed->error()) {
        $tmpl = str_replace($replacable_string, $error_string, $tmpl);
        $tmpl = str_replace('{ERROR_MESSAGE}', SimplePie_WordPress::post_process('ERROR_MESSAGE', $error_message), $tmpl);
    } elseif ($feed->get_item_quantity() == 0) {
        $tmpl = str_replace($replacable_string, $error_string, $tmpl);
        $tmpl = str_replace('{ERROR_MESSAGE}', SimplePie_WordPress::post_process('ERROR_MESSAGE', 'There are no items in this feed.'), $tmpl);
    } else {
        $tmpl = str_replace($replacable_string, '', $tmpl);
    }
    /**************************************************************************************************************/
    // FEED
    // FEED_AUTHOR_EMAIL
    if ($author = $feed->get_author()) {
        if ($email = $author->get_email()) {
            $tmpl = str_replace('{FEED_AUTHOR_EMAIL}', SimplePie_WordPress::post_process('FEED_AUTHOR_EMAIL', $email), $tmpl);
        } else {
            $tmpl = str_replace('{FEED_AUTHOR_EMAIL}', '', $tmpl);
        }
    } else {
        $tmpl = str_replace('{FEED_AUTHOR_EMAIL}', '', $tmpl);
    }
    // FEED_AUTHOR_LINK
    if ($author = $feed->get_author()) {
        if ($link = $author->get_link()) {
            $tmpl = str_replace('{FEED_AUTHOR_LINK}', SimplePie_WordPress::post_process('FEED_AUTHOR_LINK', $link), $tmpl);
        } else {
            $tmpl = str_replace('{FEED_AUTHOR_LINK}', '', $tmpl);
        }
    } else {
        $tmpl = str_replace('{FEED_AUTHOR_LINK}', '', $tmpl);
    }
    // FEED_AUTHOR_NAME
    if ($author = $feed->get_author()) {
        if ($name = $author->get_name()) {
            $tmpl = str_replace('{FEED_AUTHOR_NAME}', SimplePie_WordPress::post_process('FEED_AUTHOR_NAME', $name), $tmpl);
        } else {
            $tmpl = str_replace('{FEED_AUTHOR_NAME}', '', $tmpl);
        }
    } else {
        $tmpl = str_replace('{FEED_AUTHOR_NAME}', '', $tmpl);
    }
    // FEED_CONTRIBUTOR_EMAIL
    if ($contributor = $feed->get_contributor()) {
        if ($email = $contributor->get_email()) {
            $tmpl = str_replace('{FEED_CONTRIBUTOR_EMAIL}', SimplePie_WordPress::post_process('FEED_CONTRIBUTOR_EMAIL', $email), $tmpl);
        } else {
            $tmpl = str_replace('{FEED_CONTRIBUTOR_EMAIL}', '', $tmpl);
        }
    } else {
        $tmpl = str_replace('{FEED_CONTRIBUTOR_EMAIL}', '', $tmpl);
    }
    // FEED_CONTRIBUTOR_LINK
    if ($contributor = $feed->get_contributor()) {
        if ($link = $contributor->get_link()) {
            $tmpl = str_replace('{FEED_CONTRIBUTOR_LINK}', SimplePie_WordPress::post_process('FEED_CONTRIBUTOR_LINK', $link), $tmpl);
        } else {
            $tmpl = str_replace('{FEED_CONTRIBUTOR_LINK}', '', $tmpl);
        }
    } else {
        $tmpl = str_replace('{FEED_CONTRIBUTOR_LINK}', '', $tmpl);
    }
    // FEED_CONTRIBUTOR_NAME
    if ($contributor = $feed->get_contributor()) {
        if ($name = $contributor->get_name()) {
            $tmpl = str_replace('{FEED_CONTRIBUTOR_NAME}', SimplePie_WordPress::post_process('FEED_CONTRIBUTOR_NAME', $name), $tmpl);
        } else {
            $tmpl = str_replace('{FEED_CONTRIBUTOR_NAME}', '', $tmpl);
        }
    } else {
        $tmpl = str_replace('{FEED_CONTRIBUTOR_NAME}', '', $tmpl);
    }
    // FEED_COPYRIGHT
    if ($copyright = $feed->get_copyright()) {
        $tmpl = str_replace('{FEED_COPYRIGHT}', SimplePie_WordPress::post_process('FEED_COPYRIGHT', $copyright), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_COPYRIGHT}', '', $tmpl);
    }
    // FEED_DESCRIPTION
    if ($description = $feed->get_description()) {
        $tmpl = str_replace('{FEED_DESCRIPTION}', SimplePie_WordPress::post_process('FEED_DESCRIPTION', $description), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_DESCRIPTION}', '', $tmpl);
    }
    // FEED_ENCODING
    if ($encoding = $feed->get_encoding()) {
        $tmpl = str_replace('{FEED_ENCODING}', SimplePie_WordPress::post_process('FEED_ENCODING', $encoding), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_ENCODING}', '', $tmpl);
    }
    // FEED_FAVICON
    if ($favicon = $feed->get_favicon()) {
        $tmpl = str_replace('{FEED_FAVICON}', SimplePie_WordPress::post_process('FEED_FAVICON', $favicon), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_FAVICON}', '', $tmpl);
    }
    // FEED_IMAGE_HEIGHT
    if ($image_height = $feed->get_image_height()) {
        $tmpl = str_replace('{FEED_IMAGE_HEIGHT}', SimplePie_WordPress::post_process('FEED_IMAGE_HEIGHT', $image_height), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_IMAGE_HEIGHT}', '', $tmpl);
    }
    // FEED_IMAGE_LINK
    if ($image_link = $feed->get_image_link()) {
        $tmpl = str_replace('{FEED_IMAGE_LINK}', SimplePie_WordPress::post_process('FEED_IMAGE_LINK', $image_link), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_IMAGE_LINK}', '', $tmpl);
    }
    // FEED_IMAGE_TITLE
    if ($image_title = $feed->get_image_title()) {
        $tmpl = str_replace('{FEED_IMAGE_TITLE}', SimplePie_WordPress::post_process('FEED_IMAGE_TITLE', $image_title), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_IMAGE_TITLE}', '', $tmpl);
    }
    // FEED_IMAGE_URL
    if ($image_url = $feed->get_image_url()) {
        $tmpl = str_replace('{FEED_IMAGE_URL}', SimplePie_WordPress::post_process('FEED_IMAGE_URL', $image_url), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_IMAGE_URL}', '', $tmpl);
    }
    // FEED_IMAGE_WIDTH
    if ($image_width = $feed->get_image_width()) {
        $tmpl = str_replace('{FEED_IMAGE_WIDTH}', SimplePie_WordPress::post_process('FEED_IMAGE_WIDTH', $image_width), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_IMAGE_WIDTH}', '', $tmpl);
    }
    // FEED_LANGUAGE
    if ($language = $feed->get_language()) {
        $tmpl = str_replace('{FEED_LANGUAGE}', SimplePie_WordPress::post_process('FEED_LANGUAGE', $language), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_LANGUAGE}', '', $tmpl);
    }
    // FEED_LATITUDE
    if ($latitude = $feed->get_latitude()) {
        $tmpl = str_replace('{FEED_LATITUDE}', SimplePie_WordPress::post_process('FEED_LATITUDE', $latitude), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_LATITUDE}', '', $tmpl);
    }
    // FEED_LONGITUDE
    if ($longitude = $feed->get_longitude()) {
        $tmpl = str_replace('{FEED_LONGITUDE}', SimplePie_WordPress::post_process('FEED_LONGITUDE', $longitude), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_LONGITUDE}', '', $tmpl);
    }
    // FEED_PERMALINK
    if ($permalink = $feed->get_permalink()) {
        $tmpl = str_replace('{FEED_PERMALINK}', SimplePie_WordPress::post_process('FEED_PERMALINK', $permalink), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_PERMALINK}', '', $tmpl);
    }
    // FEED_TITLE
    if ($title = $feed->get_title()) {
        $tmpl = str_replace('{FEED_TITLE}', SimplePie_WordPress::post_process('FEED_TITLE', $title), $tmpl);
    } else {
        $tmpl = str_replace('{FEED_TITLE}', '', $tmpl);
    }
    // SUBSCRIBE_URL
    if ($subscribe_url = $feed->subscribe_url()) {
        $tmpl = str_replace('{SUBSCRIBE_URL}', SimplePie_WordPress::post_process('SUBSCRIBE_URL', $subscribe_url), $tmpl);
    } else {
        $tmpl = str_replace('{SUBSCRIBE_URL}', '', $tmpl);
    }
    // TRUNCATE_FEED_DESCRIPTION
    if ($description = $feed->get_description()) {
        $tmpl = str_replace('{TRUNCATE_FEED_DESCRIPTION}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_FEED_DESCRIPTION', $description), $truncate_feed_description), $tmpl);
    } else {
        $tmpl = str_replace('{TRUNCATE_FEED_DESCRIPTION}', '', $tmpl);
    }
    // TRUNCATE_FEED_TITLE
    if ($title = $feed->get_title()) {
        $tmpl = str_replace('{TRUNCATE_FEED_TITLE}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_FEED_TITLE', $title), $truncate_feed_title), $tmpl);
    } else {
        $tmpl = str_replace('{TRUNCATE_FEED_TITLE}', '', $tmpl);
    }
    /**************************************************************************************************************/
    // ITEMS
    // Separate out the pre-item template
    $tmpl = explode('{ITEM_LOOP_BEGIN}', $tmpl);
    $pre_tmpl = $tmpl[0];
    // Separate out the item template
    $tmpl = explode('{ITEM_LOOP_END}', $tmpl[1]);
    $item_tmpl = $tmpl[0];
    // Separate out the post-item template
    $post_tmpl = $tmpl[1];
    // Clear out the variable
    unset($tmpl);
    // Start putting the output string together.
    $tmpl = $pre_tmpl;
    // Loop through all of the items that we're supposed to.
    foreach ($feed->get_items(0, $items) as $item) {
        // Get a reference to the parent $feed object.
        $parent = $item->get_feed();
        // Get a working copy of the item template.  We don't want to edit the original.
        $working_item = $item_tmpl;
        // ITEM_CONTRIBUTOR_EMAIL
        if ($contributor = $item->get_contributor()) {
            if ($email = $contributor->get_email()) {
                $working_item = str_replace('{ITEM_CONTRIBUTOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_CONTRIBUTOR_EMAIL', $email), $working_item);
            } else {
                $working_item = str_replace('{ITEM_CONTRIBUTOR_EMAIL}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_CONTRIBUTOR_EMAIL}', '', $working_item);
        }
        // ITEM_CONTRIBUTOR_LINK
        if ($contributor = $item->get_contributor()) {
            if ($link = $contributor->get_link()) {
                $working_item = str_replace('{ITEM_CONTRIBUTOR_LINK}', SimplePie_WordPress::post_process('ITEM_CONTRIBUTOR_LINK', $link), $working_item);
            } else {
                $working_item = str_replace('{ITEM_CONTRIBUTOR_LINK}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_CONTRIBUTOR_LINK}', '', $working_item);
        }
        // ITEM_CONTRIBUTOR_NAME
        if ($contributor = $item->get_contributor()) {
            if ($name = $contributor->get_name()) {
                $working_item = str_replace('{ITEM_CONTRIBUTOR_NAME}', SimplePie_WordPress::post_process('ITEM_CONTRIBUTOR_NAME', $name), $working_item);
            } else {
                $working_item = str_replace('{ITEM_CONTRIBUTOR_NAME}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_CONTRIBUTOR_NAME}', '', $working_item);
        }
        // ITEM_COPYRIGHT
        if ($copyright = $item->get_copyright()) {
            $working_item = str_replace('{ITEM_COPYRIGHT}', SimplePie_WordPress::post_process('ITEM_COPYRIGHT', $copyright), $working_item);
        } else {
            $working_item = str_replace('{ITEM_COPYRIGHT}', '', $working_item);
        }
        // ITEM_PARENT_AUTHOR_EMAIL
        if ($author = $parent->get_author()) {
            if ($email = $author->get_email()) {
                $working_item = str_replace('{ITEM_PARENT_AUTHOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_PARENT_AUTHOR_EMAIL', $email), $working_item);
            } else {
                $working_item = str_replace('{ITEM_PARENT_AUTHOR_EMAIL}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_PARENT_AUTHOR_EMAIL}', '', $working_item);
        }
        // ITEM_PARENT_AUTHOR_LINK
        if ($author = $parent->get_author()) {
            if ($link = $author->get_link()) {
                $working_item = str_replace('{ITEM_PARENT_AUTHOR_LINK}', SimplePie_WordPress::post_process('ITEM_PARENT_AUTHOR_LINK', $link), $working_item);
            } else {
                $working_item = str_replace('{ITEM_PARENT_AUTHOR_LINK}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_PARENT_AUTHOR_LINK}', '', $working_item);
        }
        // ITEM_PARENT_AUTHOR_NAME
        if ($author = $parent->get_author()) {
            if ($name = $author->get_name()) {
                $working_item = str_replace('{ITEM_PARENT_AUTHOR_NAME}', SimplePie_WordPress::post_process('ITEM_PARENT_AUTHOR_NAME', $name), $working_item);
            } else {
                $working_item = str_replace('{ITEM_PARENT_AUTHOR_NAME}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_PARENT_AUTHOR_NAME}', '', $working_item);
        }
        // ITEM_PARENT_CONTRIBUTOR_EMAIL
        if ($contributor = $parent->get_contributor()) {
            if ($email = $contributor->get_email()) {
                $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_PARENT_CONTRIBUTOR_EMAIL', $email), $working_item);
            } else {
                $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_EMAIL}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_EMAIL}', '', $working_item);
        }
        // ITEM_PARENT_CONTRIBUTOR_LINK
        if ($contributor = $parent->get_contributor()) {
            if ($link = $contributor->get_link()) {
                $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_LINK}', SimplePie_WordPress::post_process('ITEM_PARENT_CONTRIBUTOR_LINK', $link), $working_item);
            } else {
                $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_LINK}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_LINK}', '', $working_item);
        }
        // ITEM_PARENT_CONTRIBUTOR_NAME
        if ($contributor = $parent->get_contributor()) {
            if ($name = $contributor->get_name()) {
                $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_NAME}', SimplePie_WordPress::post_process('ITEM_PARENT_CONTRIBUTOR_NAME', $name), $working_item);
            } else {
                $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_NAME}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_PARENT_CONTRIBUTOR_NAME}', '', $working_item);
        }
        // ITEM_AUTHOR_EMAIL
        if ($author = $item->get_author()) {
            if ($email = $author->get_email()) {
                $working_item = str_replace('{ITEM_AUTHOR_EMAIL}', SimplePie_WordPress::post_process('ITEM_AUTHOR_EMAIL', $email), $working_item);
            } else {
                $working_item = str_replace('{ITEM_AUTHOR_EMAIL}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_AUTHOR_EMAIL}', '', $working_item);
        }
        // ITEM_AUTHOR_LINK
        if ($author = $item->get_author()) {
            if ($link = $author->get_link()) {
                $working_item = str_replace('{ITEM_AUTHOR_LINK}', SimplePie_WordPress::post_process('ITEM_AUTHOR_LINK', $link), $working_item);
            } else {
                $working_item = str_replace('{ITEM_AUTHOR_LINK}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_AUTHOR_LINK}', '', $working_item);
        }
        // ITEM_AUTHOR_NAME
        if ($author = $item->get_author()) {
            if ($name = $author->get_name()) {
                $working_item = str_replace('{ITEM_AUTHOR_NAME}', SimplePie_WordPress::post_process('ITEM_AUTHOR_NAME', $name), $working_item);
            } else {
                $working_item = str_replace('{ITEM_AUTHOR_NAME}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_AUTHOR_NAME}', '', $working_item);
        }
        // ITEM_CATEGORY
        if ($category = $item->get_category()) {
            if ($label = $category->get_label()) {
                $working_item = str_replace('{ITEM_CATEGORY}', SimplePie_WordPress::post_process('ITEM_CATEGORY', $label), $working_item);
            } else {
                $working_item = str_replace('{ITEM_CATEGORY}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_CATEGORY}', '', $working_item);
        }
        // ITEM_CONTENT
        if ($content = $item->get_content()) {
            $working_item = str_replace('{ITEM_CONTENT}', SimplePie_WordPress::post_process('ITEM_CONTENT', $content), $working_item);
        } else {
            $working_item = str_replace('{ITEM_CONTENT}', '', $working_item);
        }
        // ITEM_DATE
        if ($date = $item->get_date($date_format)) {
            $working_item = str_replace('{ITEM_DATE}', SimplePie_WordPress::post_process('ITEM_DATE', $date), $working_item);
        } else {
            $working_item = str_replace('{ITEM_DATE}', '', $working_item);
        }
        // ITEM_DATE_UTC
        if ($date = $item->get_date('U')) {
            $date = gmdate($date_format, $date);
            $working_item = str_replace('{ITEM_DATE_UTC}', SimplePie_WordPress::post_process('ITEM_DATE_UTC', $date), $working_item);
        } else {
            $working_item = str_replace('{ITEM_DATE_UTC}', '', $working_item);
        }
        // ITEM_DESCRIPTION
        if ($description = $item->get_description()) {
            $working_item = str_replace('{ITEM_DESCRIPTION}', SimplePie_WordPress::post_process('ITEM_DESCRIPTION', $description), $working_item);
        } else {
            $working_item = str_replace('{ITEM_DESCRIPTION}', '', $working_item);
        }
        // ITEM_ENCLOSURE_EMBED
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->native_embed()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_EMBED}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_EMBED', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_EMBED}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_EMBED}', '', $working_item);
        }
        // ITEM_ENCLOSURE_EXTENSION
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_extension()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_EXTENSION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_EXTENSION', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_EXTENSION}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_EXTENSION}', '', $working_item);
        }
        // ITEM_ENCLOSURE_HANDLER
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_handler()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_HANDLER}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_HANDLER', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_HANDLER}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_HANDLER}', '', $working_item);
        }
        // ITEM_ENCLOSURE_LENGTH
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_length()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_LENGTH}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_LENGTH', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_LENGTH}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_LENGTH}', '', $working_item);
        }
        // ITEM_ENCLOSURE_LINK
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_link()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_LINK}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_LINK', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_LINK}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_LINK}', '', $working_item);
        }
        // ITEM_ENCLOSURE_REAL_TYPE
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_real_type()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_REAL_TYPE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_REAL_TYPE', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_REAL_TYPE}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_REAL_TYPE}', '', $working_item);
        }
        // ITEM_ENCLOSURE_SIZE
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_size()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_SIZE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_SIZE', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_SIZE}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_SIZE}', '', $working_item);
        }
        // ITEM_ENCLOSURE_TYPE
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_type()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_TYPE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_TYPE', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_TYPE}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_TYPE}', '', $working_item);
        }
        // ITEM_ENCLOSURE_BITRATE
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_bitrate()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_BITRATE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_BITRATE', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_BITRATE}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_BITRATE}', '', $working_item);
        }
        // ITEM_ENCLOSURE_CHANNELS
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_channels()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_CHANNELS}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_CHANNELS', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_CHANNELS}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_CHANNELS}', '', $working_item);
        }
        // ITEM_ENCLOSURE_DESCRIPTION
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_description()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_DESCRIPTION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_DESCRIPTION', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_DESCRIPTION}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_DESCRIPTION}', '', $working_item);
        }
        // ITEM_ENCLOSURE_DURATION
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_duration()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_DURATION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_DURATION', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_DURATION}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_DURATION}', '', $working_item);
        }
        // ITEM_ENCLOSURE_EXPRESSION
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_expression()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_EXPRESSION}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_EXPRESSION', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_EXPRESSION}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_EXPRESSION}', '', $working_item);
        }
        // ITEM_ENCLOSURE_FRAMERATE
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_framerate()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_FRAMERATE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_FRAMERATE', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_FRAMERATE}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_FRAMERATE}', '', $working_item);
        }
        // ITEM_ENCLOSURE_HASH
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_hash()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_HASH}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_HASH', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_HASH}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_HASH}', '', $working_item);
        }
        // ITEM_ENCLOSURE_HEIGHT
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_height()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_HEIGHT}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_HEIGHT', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_HEIGHT}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_HEIGHT}', '', $working_item);
        }
        // ITEM_ENCLOSURE_LANGUAGE
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_language()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_LANGUAGE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_LANGUAGE', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_LANGUAGE}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_LANGUAGE}', '', $working_item);
        }
        // ITEM_ENCLOSURE_MEDIUM
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_medium()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_MEDIUM}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_MEDIUM', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_MEDIUM}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_MEDIUM}', '', $working_item);
        }
        // ITEM_ENCLOSURE_PLAYER
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_player()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_PLAYER}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_PLAYER', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_PLAYER}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_PLAYER}', '', $working_item);
        }
        // ITEM_ENCLOSURE_SAMPLINGRATE
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_sampling_rate()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_SAMPLINGRATE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_SAMPLINGRATE', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_SAMPLINGRATE}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_SAMPLINGRATE}', '', $working_item);
        }
        // ITEM_ENCLOSURE_THUMBNAIL
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_thumbnail()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_THUMBNAIL}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_THUMBNAIL', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_THUMBNAIL}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_THUMBNAIL}', '', $working_item);
        }
        // ITEM_ENCLOSURE_TITLE
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_title()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_TITLE}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_TITLE', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_TITLE}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_TITLE}', '', $working_item);
        }
        // ITEM_ENCLOSURE_WIDTH
        if ($enclosure = $item->get_enclosure()) {
            if ($encltemp = $enclosure->get_width()) {
                $working_item = str_replace('{ITEM_ENCLOSURE_WIDTH}', SimplePie_WordPress::post_process('ITEM_ENCLOSURE_WIDTH', $encltemp), $working_item);
            } else {
                $working_item = str_replace('{ITEM_ENCLOSURE_WIDTH}', '', $working_item);
            }
        } else {
            $working_item = str_replace('{ITEM_ENCLOSURE_WIDTH}', '', $working_item);
        }
        // ITEM_ID
        if ($id = $item->get_id()) {
            $working_item = str_replace('{ITEM_ID}', SimplePie_WordPress::post_process('ITEM_ID', $id), $working_item);
        } else {
            $working_item = str_replace('{ITEM_ID}', '', $working_item);
        }
        // ITEM_ID
        if ($latitude = $item->get_latitude()) {
            $working_item = str_replace('{ITEM_LATITUDE}', SimplePie_WordPress::post_process('ITEM_LATITUDE', $latitude), $working_item);
        } else {
            $working_item = str_replace('{ITEM_LATITUDE}', '', $working_item);
        }
        // ITEM_LOCAL_DATE
        if ($local_date = $item->get_local_date($local_date_format)) {
            $working_item = str_replace('{ITEM_LOCAL_DATE}', SimplePie_WordPress::post_process('ITEM_LOCAL_DATE', $local_date), $working_item);
        } else {
            $working_item = str_replace('{ITEM_LOCAL_DATE}', '', $working_item);
        }
        // ITEM_LOCAL_DATE_UTC
        if ($local_date = $item->get_date('U')) {
            $local_date = gmdate('U', $local_date);
            $local_date = strftime($local_date_format, $local_date);
            $working_item = str_replace('{ITEM_LOCAL_DATE_UTC}', SimplePie_WordPress::post_process('ITEM_LOCAL_DATE_UTC', $local_date), $working_item);
        } else {
            $working_item = str_replace('{ITEM_LOCAL_DATE_UTC}', '', $working_item);
        }
        // ITEM_LONGITUDE
        if ($longitude = $item->get_longitude()) {
            $working_item = str_replace('{ITEM_LONGITUDE}', SimplePie_WordPress::post_process('ITEM_LONGITUDE', $longitude), $working_item);
        } else {
            $working_item = str_replace('{ITEM_LONGITUDE}', '', $working_item);
        }
        // ITEM_PERMALINK
        if ($permalink = $item->get_permalink()) {
            $working_item = str_replace('{ITEM_PERMALINK}', SimplePie_WordPress::post_process('ITEM_PERMALINK', $permalink), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PERMALINK}', '', $working_item);
        }
        // ITEM_TITLE
        if ($title = $item->get_title()) {
            $working_item = str_replace('{ITEM_TITLE}', SimplePie_WordPress::post_process('ITEM_TITLE', $title), $working_item);
        } else {
            $working_item = str_replace('{ITEM_TITLE}', '', $working_item);
        }
        // ITEM_PARENT_COPYRIGHT
        if ($copyright = $parent->get_copyright()) {
            $working_item = str_replace('{ITEM_PARENT_COPYRIGHT}', SimplePie_WordPress::post_process('ITEM_PARENT_COPYRIGHT', $copyright), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_COPYRIGHT}', '', $working_item);
        }
        // ITEM_PARENT_DESCRIPTION
        if ($description = $parent->get_description()) {
            $working_item = str_replace('{ITEM_PARENT_DESCRIPTION}', SimplePie_WordPress::post_process('ITEM_PARENT_DESCRIPTION', $description), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_DESCRIPTION}', '', $working_item);
        }
        // ITEM_PARENT_ENCODING
        if ($encoding = $parent->get_encoding()) {
            $working_item = str_replace('{ITEM_PARENT_ENCODING}', SimplePie_WordPress::post_process('ITEM_PARENT_ENCODING', $encoding), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_ENCODING}', '', $working_item);
        }
        // ITEM_PARENT_FAVICON
        if ($favicon = $parent->get_favicon()) {
            $working_item = str_replace('{ITEM_PARENT_FAVICON}', SimplePie_WordPress::post_process('ITEM_PARENT_FAVICON', $favicon), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_FAVICON}', '', $working_item);
        }
        // ITEM_PARENT_IMAGE_HEIGHT
        if ($image_height = $parent->get_image_height()) {
            $working_item = str_replace('{ITEM_PARENT_IMAGE_HEIGHT}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_HEIGHT', $image_height), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_IMAGE_HEIGHT}', '', $working_item);
        }
        // ITEM_PARENT_IMAGE_LINK
        if ($image_link = $parent->get_image_link()) {
            $working_item = str_replace('{ITEM_PARENT_IMAGE_LINK}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_LINK', $image_link), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_IMAGE_LINK}', '', $working_item);
        }
        // ITEM_PARENT_IMAGE_TITLE
        if ($image_title = $parent->get_image_title()) {
            $working_item = str_replace('{ITEM_PARENT_IMAGE_TITLE}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_TITLE', $image_title), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_IMAGE_TITLE}', '', $working_item);
        }
        // ITEM_PARENT_IMAGE_URL
        if ($image_url = $parent->get_image_url()) {
            $working_item = str_replace('{ITEM_PARENT_IMAGE_URL}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_URL', $image_url), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_IMAGE_URL}', '', $working_item);
        }
        // ITEM_PARENT_IMAGE_WIDTH
        if ($image_width = $parent->get_image_width()) {
            $working_item = str_replace('{ITEM_PARENT_IMAGE_WIDTH}', SimplePie_WordPress::post_process('ITEM_PARENT_IMAGE_WIDTH', $image_width), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_IMAGE_WIDTH}', '', $working_item);
        }
        // ITEM_PARENT_LANGUAGE
        if ($language = $parent->get_language()) {
            $working_item = str_replace('{ITEM_PARENT_LANGUAGE}', SimplePie_WordPress::post_process('ITEM_PARENT_LANGUAGE', $language), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_LANGUAGE}', '', $working_item);
        }
        // ITEM_PARENT_LATITUDE
        if ($latitude = $parent->get_latitude()) {
            $working_item = str_replace('{ITEM_PARENT_LATITUDE}', SimplePie_WordPress::post_process('ITEM_PARENT_LATITUDE', $latitude), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_LATITUDE}', '', $working_item);
        }
        // ITEM_PARENT_LONGITUDE
        if ($longitude = $parent->get_longitude()) {
            $working_item = str_replace('{ITEM_PARENT_LONGITUDE}', SimplePie_WordPress::post_process('ITEM_PARENT_LONGITUDE', $longitude), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_LONGITUDE}', '', $working_item);
        }
        // ITEM_PARENT_PERMALINK
        if ($permalink = $parent->get_permalink()) {
            $working_item = str_replace('{ITEM_PARENT_PERMALINK}', SimplePie_WordPress::post_process('ITEM_PARENT_PERMALINK', $permalink), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_PERMALINK}', '', $working_item);
        }
        // ITEM_PARENT_TITLE
        if ($title = $parent->get_title()) {
            $working_item = str_replace('{ITEM_PARENT_TITLE}', SimplePie_WordPress::post_process('ITEM_PARENT_TITLE', $title), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_TITLE}', '', $working_item);
        }
        // ITEM_PARENT_SUBSCRIBE_URL
        if ($subscribe_url = $parent->subscribe_url()) {
            $working_item = str_replace('{ITEM_PARENT_SUBSCRIBE_URL}', SimplePie_WordPress::post_process('ITEM_PARENT_SUBSCRIBE_URL', $subscribe_url), $working_item);
        } else {
            $working_item = str_replace('{ITEM_PARENT_SUBSCRIBE_URL}', '', $working_item);
        }
        // TRUNCATE_ITEM_DESCRIPTION
        if ($description = $item->get_description()) {
            $working_item = str_replace('{TRUNCATE_ITEM_DESCRIPTION}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_DESCRIPTION', $description), $truncate_item_description), $working_item);
        } else {
            $working_item = str_replace('{TRUNCATE_ITEM_DESCRIPTION}', '', $working_item);
        }
        // TRUNCATE_ITEM_TITLE
        if ($title = $item->get_title()) {
            $working_item = str_replace('{TRUNCATE_ITEM_TITLE}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_TITLE', $title), $truncate_item_title), $working_item);
        } else {
            $working_item = str_replace('{TRUNCATE_ITEM_TITLE}', '', $working_item);
        }
        // TRUNCATE_ITEM_PARENT_DESCRIPTION
        if ($description = $parent->get_description()) {
            $working_item = str_replace('{TRUNCATE_ITEM_PARENT_DESCRIPTION}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_PARENT_DESCRIPTION', $description), $truncate_feed_description), $working_item);
        } else {
            $working_item = str_replace('{TRUNCATE_ITEM_PARENT_DESCRIPTION}', '', $working_item);
        }
        // TRUNCATE_ITEM_PARENT_TITLE
        if ($title = $parent->get_title()) {
            $working_item = str_replace('{TRUNCATE_ITEM_PARENT_TITLE}', SimplePie_Truncate(SimplePie_WordPress::post_process('TRUNCATE_ITEM_PARENT_TITLE', $title), $truncate_feed_title), $working_item);
        } else {
            $working_item = str_replace('{TRUNCATE_ITEM_PARENT_TITLE}', '', $working_item);
        }
        $tmpl .= $working_item;
    }
    /**************************************************************************************************************/
    // LAST STUFF
    // Start by removing all line breaks and tabs.
    $tmpl = preg_replace('/(\\n|\\r|\\t)/i', "", $tmpl);
    // PLUGIN_DIR
    $tmpl = str_replace('{PLUGIN_DIR}', SIMPLEPIE_PLUGINDIR_WEB, $tmpl);
    $tmpl .= $post_tmpl;
    // Kill the object to prevent memory leaks.
    $feed->__destruct();
    unset($feed);
    unset($encltemp);
    unset($working_item);
    // Return the data back to the page.
    return $tmpl;
}
Example #10
0
    /**
     * Processing the parameters into placeholders
     * @param string    $spie   snippet parameters
     * @return array    placeholders
     */
    private function _setSimplePieModxPlaceholders($spie) {
        /**
         * @link http://github.com/simplepie/simplepie/tree/one-dot-two
         */
        if (!file_exists($spie['simplePieClassFile'])) {
            return 'File ' . $spie['simplePieClassFile'] . ' does not exist.';
        }
        include_once $spie['simplePieClassFile'];
        $feed = new SimplePie();
        $joinKey = 0;
        foreach ($spie['setFeedUrl'] as $setFeedUrl) {
            $feed->set_cache_location($spie['setCacheLocation']);
            $feed->set_feed_url($setFeedUrl);

            if (isset($spie['setInputEncoding'])) {
                $feed->set_input_encoding($spie['setInputEncoding']);
            }
            if (isset($spie['setOutputEncoding'])) {
                $feed->set_output_encoding($spie['setOutputEncoding']);
            }
            // if no cURL, try fsockopen
            if (isset($spie['forceFSockopen'])) {
                $feed->force_fsockopen(true);
            }
            if (isset($spie['enableCache']))
                $feed->enable_cache($spie['enableCache']);
            if (isset($spie['enableOrderByDate']))
                $feed->enable_order_by_date($spie['enableOrderByDate']);
            if (isset($spie['setCacheDuration']))
                $feed->set_cache_duration($spie['setCacheDuration']);
            if (!empty($spie['setFaviconHandler']))
                $feed->set_favicon_handler($spie['setFaviconHandler'][0], $spie['setFaviconHandler'][1]);
            if (!empty($spie['setImageHandler'])) {
                // handler_image.php?image=67d5fa9a87bad230fb03ea68b9f71090
                $feed->set_image_handler($spie['setImageHandler'][0], $spie['setImageHandler'][1]);
            }

            // disabled since these are all splitted into a single fetching
            // it's  been used with different way, see below looping
//            if (isset($spie['setItemLimit']))
//                $feed->set_item_limit((int) $spie['setItemLimit']);

            if (isset($spie['setJavascript']))
                $feed->set_javascript($spie['setJavascript']);
            if (isset($spie['stripAttributes']))
                $feed->strip_attributes(array_merge($feed->strip_attributes, $spie['stripAttributes']));
            if (isset($spie['stripComments']))
                $feed->strip_comments($spie['stripComments']);
            if (isset($spie['stripHtmlTags']))
                $feed->strip_htmltags(array_merge($feed->strip_htmltags, $spie['stripHtmlTags']));

            /**
             * Initiating the Feeding.
             * This always be placed AFTER all the settings above.
             */
            if (!$feed->init()) {
                echo $feed->error();
                return FALSE;
            }

            $countItems = count($feed->get_items());
            if (1 > $countItems) {
                continue;
            }

            $feed->handle_content_type();

            $countLimit = 0;
            foreach ($feed->get_items($getItemStart, $getItemEnd) as $item) {

                if (isset($spie['setItemLimit']) && $spie['setItemLimit'] == $countLimit)
                    continue;

                $phArray[$joinKey]['favicon'] = $feed->get_favicon();
                $phArray[$joinKey]['link'] = $item->get_link();
                $phArray[$joinKey]['title'] = $item->get_title();
                $phArray[$joinKey]['description'] = $item->get_description();
                $phArray[$joinKey]['content'] = $item->get_content();

                $phArray[$joinKey]['permalink'] = $item->get_permalink();
                $parsedUrl = parse_url($phArray[$joinKey]['permalink']);
                $implodedParsedUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host'];
                $imageLink = $feed->get_image_link() != '' ? $feed->get_image_link() : $implodedParsedUrl;
                $phArray[$joinKey]['imageLink'] = $imageLink;

                $phArray[$joinKey]['imageTitle'] = $feed->get_image_title();
                $phArray[$joinKey]['imageUrl'] = $feed->get_image_url();
                $phArray[$joinKey]['imageWidth'] = $feed->get_image_width();
                $phArray[$joinKey]['imageHeight'] = $feed->get_image_height();

                $phArray[$joinKey]['date'] = $item->get_date($spie['dateFormat']);
                $phArray[$joinKey]['localDate'] = $item->get_local_date($spie['localDateFormat']);
                $phArray[$joinKey]['copyright'] = $item->get_copyright();

                $phArray[$joinKey]['latitude'] = $feed->get_latitude();
                $phArray[$joinKey]['longitude'] = $feed->get_longitude();

                $phArray[$joinKey]['language'] = $feed->get_language();
                $phArray[$joinKey]['encoding'] = $feed->get_encoding();

                if ($item->get_authors()) {
                    foreach ($item->get_authors() as $authorObject) {
                        $authorName = $authorObject->get_name();
                        $authorLink = $authorObject->get_link();
                        $authorEmail = $authorObject->get_email();
                    }
                    $phArray[$joinKey]['authorName'] = $authorName;
                    $phArray[$joinKey]['authorLink'] = $authorLink;
                    $phArray[$joinKey]['authorEmail'] = $authorEmail;
                }

                $category = $item->get_category();
                if ($category) {
                    $phArray[$joinKey]['category'] = htmlspecialchars_decode($category->get_label(), ENT_QUOTES);
                }

                $contributor = $item->get_contributor();
                $phArray[$joinKey]['contributor'] = '';
                if ($contributor) {
                    $phArray[$joinKey]['contributor'] = $contributor->get_name();
                }

                if ($feed->get_type() & SIMPLEPIE_TYPE_NONE) {
                    $phArray[$joinKey]['getType'] = 'Unknown';
                } elseif ($feed->get_type() & SIMPLEPIE_TYPE_RSS_ALL) {
                    $phArray[$joinKey]['getType'] = 'RSS';
                } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ATOM_ALL) {
                    $phArray[$joinKey]['getType'] = 'Atom';
                } elseif ($feed->get_type() & SIMPLEPIE_TYPE_ALL) {
                    $phArray[$joinKey]['getType'] = 'Supported';
                }
				
				// Media from Flickr RSS stream
				if ($enclosure = $item->get_enclosure()) {
						$phArray[$joinKey]['itemImageThumbnailUrl'] = $enclosure->get_thumbnail();
						$phArray[$joinKey]['itemImageWidth'] = $enclosure->get_width();
						$phArray[$joinKey]['itemImageHeight'] = $enclosure->get_height();
				}
				

                $countLimit++;
                $joinKey++;
            } // foreach ($feed->get_items($getItemStart, $getItemEnd) as $item)
        } // foreach ($spie['setFeedUrl'] as $setFeedUrl)
        return $this->_filterModxTags($phArray);
    }
Example #11
0
 function get_articles()
 {
     $sm =& $this->_site_manager;
     require_once VIVVO_FS_INSTALL_ROOT . '/lib/simplepie/simplepie.php';
     $feed_r = new SimplePie();
     $feed_r->enable_cache(false);
     $feed_r->set_feed_url($this->get_feed());
     $feed_r->init();
     foreach ($feed_r->get_items() as $item) {
         $status = true;
         $guid = $item->get_item_tags('', 'guid');
         $guid = $guid[0]['data'];
         if ($guid != '') {
             $sql = 'SELECT count( * ) as count FROM ' . VIVVO_DB_PREFIX . 'Articles WHERE feed_data = \'' . md5($guid) . '\' LIMIT 1';
             $feed_data = md5($guid);
         } else {
             $sql = 'SELECT count( * ) as count FROM ' . VIVVO_DB_PREFIX . 'Articles WHERE feed_data = \'' . md5($item->get_title() . $item->get_permalink()) . '\'LIMIT 1';
             $feed_data = md5($item->get_title() . $item->get_permalink());
         }
         $res =& $sm->_db->query($sql);
         $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
         if ($row['count']) {
             $status = false;
         }
         if ($status) {
             require_once VIVVO_FS_INSTALL_ROOT . '/lib/vivvo/core/Articles.class.php';
             require_once VIVVO_FS_FRAMEWORK . 'vivvo_post.php';
             $article = new Articles($sm);
             if ($this->get_author() != '') {
                 $author = $this->get_author();
             } elseif ($item->get_author() != '') {
                 $author = $item->get_author();
             } else {
                 preg_match('/^http:\\/\\/(www\\.)?([^\\/]+)/', $item->get_permalink(), $author);
                 $author = $author[2];
             }
             if (VIVVO_PLUGIN_FEED_IMPORTER_FRIENDLY == 1) {
                 $sefriendly_url = strtolower(preg_replace('/[^a-zA-Z\\d\\-]/i', '_', $item->get_title()));
                 $keywords = preg_split("/[\\s_]+/", $sefriendly_url, VIVVO_PLUGIN_FEED_IMPORTER_MAX_WORD_NUM + 1, PREG_SPLIT_NO_EMPTY);
                 $output_string = '';
                 for ($i = 0; $i < VIVVO_PLUGIN_FEED_IMPORTER_MAX_WORD_NUM; $i++) {
                     $output_string .= '_' . $keywords[$i];
                 }
                 $sefriendly_url = trim($output_string, "_");
                 //If sefriendly exists
                 $sql = 'SELECT count( * ) as count FROM ' . VIVVO_DB_PREFIX . 'Articles WHERE sefriendly = \'' . secure_sql($sefriendly_url) . '\' LIMIT 1';
                 $res =& $sm->_db->query($sql);
                 $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
                 if ($row['count']) {
                     $sefriendly_url = '';
                 }
             } else {
                 $sefriendly_url = '';
             }
             $sql = 'SELECT max( order_num ) as max FROM ' . VIVVO_DB_PREFIX . 'Articles';
             $res =& $sm->_db->query($sql);
             if ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
                 $order_num = $row['max'] + 1;
             } else {
                 $order_num = 1;
             }
             $data = array('category_id' => $this->category_id, 'user_id' => VIVVO_PLUGIN_FEED_IMPORTER_USER_ID, 'author' => $author, 'title' => $item->get_title(), 'created' => $item->get_date('Y-m-d H:i:s'), 'body' => $item->get_description(), 'status' => VIVVO_PLUGIN_FEED_IMPORTER_STATUS, 'sefriendly' => $sefriendly_url, 'link' => $item->get_permalink(), 'order_num' => $order_num, 'feed_data' => $feed_data);
             $article->populate($data, true);
             $post_master = new vivvo_post_master($sm);
             $post_master->set_data_object($article);
             if ($post_master->sql_insert()) {
                 $this->set_count($this->get_count() + 1);
             }
         }
     }
     $this->set_favicon($feed_r->get_favicon());
 }
Example #12
0
 /**
  * Imports articles from feed
  *
  * @return	array	Number of imported (index: 0) and updated (index: 1) articles
  */
 public function import_articles()
 {
     require_once VIVVO_FS_INSTALL_ROOT . 'lib/simplepie/simplepie.php';
     require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php';
     require_once VIVVO_FS_FRAMEWORK . 'vivvo_post.php';
     $sm = vivvo_lite_site::get_instance();
     $db = $sm->get_db();
     $post_master = new vivvo_post_master($sm);
     $simplepie = new SimplePie();
     $simplepie->enable_cache(false);
     $simplepie->set_feed_url($feed_url = $this->get_feed());
     $simplepie->enable_order_by_date(true);
     @$simplepie->init();
     if ($simplepie->error()) {
         return array(0, 0);
     }
     $now = date('Y-m-d H:i:00', $now_ts = time());
     $count_added = 0;
     $count_updated = 0;
     $imported = array();
     if (VIVVO_PLUGIN_FEED_IMPORTER_AUTO_DELETE) {
         $auto_delete_ts = VIVVO_PLUGIN_FEED_IMPORTER_AUTO_DELETE * 86400;
     } else {
         $auto_delete_ts = false;
     }
     if (VIVVO_PLUGIN_FEED_IMPORTER_AUTO_ARCHIVE) {
         $auto_archive_ts = VIVVO_PLUGIN_FEED_IMPORTER_AUTO_ARCHIVE * 86400;
     } else {
         $auto_archive_ts = false;
     }
     foreach ($simplepie->get_items() as $item) {
         if (($item_datetime = $item->get_date('Y-m-d H:i:00')) != null) {
             $item_datetime_ts = strtotime($item_datetime);
             // make sure not to import articles which should be deleted or archived
             if ($auto_delete_ts and $now_ts - $item_datetime_ts > $auto_delete_ts or $auto_archive_ts and $now_ts - $item_datetime_ts > $auto_archive_ts) {
                 continue;
             }
         }
         $guid = $item->get_item_tags('', 'guid');
         $guid = $guid[0]['data'];
         if (!$guid and !($guid = $item->get_title() . $item->get_permalink())) {
             continue;
             // can't determine reliable unique identifier
         }
         $feed_item_id = md5($feed_url . $guid);
         if (in_array($feed_item_id, $imported)) {
             continue;
             // already imported this one, feed has duplicate items?
         }
         $res = $db->query('SELECT id, created FROM ' . VIVVO_DB_PREFIX . "articles WHERE feed_item_id = '{$feed_item_id}' LIMIT 1");
         if (PEAR::isError($res)) {
             continue;
         }
         $update = false;
         if ($res->numRows() and $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
             if (VIVVO_PLUGIN_FEED_IMPORTER_UPDATE_ARTICLES and $item_datetime != null and time($row['created']) < $item_datetime_ts) {
                 $update = true;
             } else {
                 $res->free();
                 continue;
                 // timestamp not changed consider content is the same too...
             }
         }
         $res->free();
         $imported[] = $feed_item_id;
         if (!($author = $this->get_author()) and !($author = $item->get_author())) {
             if (preg_match('/^[^:]+:\\/\\/(www\\.)?([^\\/]+)/', $item->get_permalink(), $author)) {
                 $author = $author[2];
             } else {
                 $author = '';
             }
         }
         $article = new Articles($sm, array('category_id' => $this->category_id, 'user_id' => VIVVO_PLUGIN_FEED_IMPORTER_USER_ID, 'author' => $author, 'title' => $title = $item->get_title(), 'created' => $item_datetime ? $item_datetime : $now, 'body' => $item->get_description(), 'status' => VIVVO_PLUGIN_FEED_IMPORTER_STATUS, 'sefriendly' => make_sefriendly($title), 'link' => $item->get_permalink(), 'show_comment' => VIVVO_PLUGIN_FEED_IMPORTER_SHOW_COMMENT, 'feed_item_id' => $feed_item_id));
         $post_master->set_data_object($article);
         if ($update) {
             $article->set_id($row['id']);
             $post_master->sql_update() and $count_updated++;
         } elseif ($post_master->sql_insert()) {
             $count_added++;
         }
     }
     $this->set_favicon($simplepie->get_favicon());
     $this->set_count($this->get_count() + $count_added);
     if (VIVVO_PLUGIN_FEED_IMPORTER_USE_LOGO and $this->get_category() and $image_url = $simplepie->get_image_url() and preg_replace('/_\\d+(\\.[^.]+)$/', '$1', $this->category->get_image()) != ($basename = basename($image_url))) {
         class_exists('HTTP_Request2') or (require VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/framework/PEAR/HTTP/Request2.php');
         try {
             $request = new HTTP_Request2($image_url);
             $response = $request->send();
             if ($response->getStatus() == 200) {
                 $file_contents = $response->getBody();
                 $basename = $sm->get_file_manager()->random_file_name($basename);
                 file_put_contents(VIVVO_FS_INSTALL_ROOT . VIVVO_FS_FILES_DIR . $basename, $file_contents);
                 $this->category->set_image($basename);
                 $post_master->set_data_object($this->category);
                 $post_master->sql_update();
             }
         } catch (Exception $e) {
             if (defined('VIVVO_CRONJOB_MODE')) {
                 echo 'exception: ' . $e->getMessage() . PHP_EOL;
             }
         }
     }
     return array($count_added, $count_updated);
 }
Example #13
0
 function get()
 {
     $purifier_config = HTMLPurifier_Config::createDefault();
     $purifier_config->set('Cache.SerializerPath', 'cache');
     // TODO: This feature is very nice, but breaks titles now that we purify them. Titles only need their entities fixed, so we shouldn't really purify them allowing us to turn this back on
     #       $purifier_config->set('AutoFormat.Linkify', true);
     // Allow flash embeds in newer versions of purifier
     $purifier_config->set('HTML.SafeObject', true);
     $purifier_config->set('Output.FlashCompat', true);
     $purifier_config->set('HTML.FlashAllowFullScreen', true);
     $purifier = new HTMLPurifier($purifier_config);
     $query = 'SELECT * FROM lylina_feeds';
     $feeds = $this->db->GetAll($query);
     $pie = new SimplePie();
     $pie->enable_cache(false);
     $pie->set_sanitize_class('SimplePie_Sanitize_Null');
     $pie->set_autodiscovery_level(SIMPLEPIE_LOCATOR_ALL);
     $pie->enable_order_by_date(false);
     // Array storing feeds which need to be parsed
     $feeds_parse = array();
     // Keep track of how many we need to parse
     $feeds_count = 0;
     // Build array of feeds to fetch and their metadata
     foreach ($feeds as $feed) {
         // Track our cache
         $mod_time = -1;
         $cache_path = 'cache/' . md5($feed['url']) . '.xml';
         if (file_exists($cache_path)) {
             $mod_time = @filemtime($cache_path);
             $filemd5 = @md5_file($cache_path);
         } else {
             $mod_time = -1;
             $filemd5 = 0;
         }
         // If our cache is older than 5 minutes, or doesn't exist, fetch new feeds
         if (time() - $mod_time > 300 || $mod_time == -1) {
             #if(true) {
             $feeds_parse[$feeds_count] = array();
             $feeds_parse[$feeds_count]['url'] = $feed['url'];
             $feeds_parse[$feeds_count]['id'] = $feed['id'];
             $feeds_parse[$feeds_count]['name'] = $feed['name'];
             $feeds_parse[$feeds_count]['icon'] = $feed['favicon_url'];
             $feeds_parse[$feeds_count]['cache_path'] = $cache_path;
             $feeds_parse[$feeds_count]['filemd5'] = $filemd5;
             $feeds_parse[$feeds_count]['mod'] = $mod_time;
             $feeds_count++;
         }
     }
     // Get the data for feeds we need to parse
     $curl = new Curl_Get();
     $feeds_data = $curl->multi_get($feeds_parse);
     // Handle the data and parse the feeds
     for ($n = 0; $n < count($feeds_parse); $n++) {
         $data = $feeds_data[$n];
         $info = $feeds_parse[$n];
         // If we got an error back from Curl
         if (isset($data['error']) && $data['error'] > 0) {
             // Should be logged
             error_log("Curl error: " . $data['error']);
             // If the feed has been retrieved with content, we should save it
         } elseif ($data['data'] != NULL) {
             file_put_contents($info['cache_path'], $data['data']);
             // Otherwise we've gotten an error on the feed, or there is nothing new, let's freshen the cache
         } else {
             touch($info['cache_path']);
         }
     }
     // Clear the file stat cache so we get good data on feed mirror size changes
     clearstatcache();
     for ($n = 0; $n < count($feeds_parse); $n++) {
         $data = $feeds_data[$n];
         $info = $feeds_parse[$n];
         if ($data['data'] != NULL && md5_file($info['cache_path']) !== $info['filemd5']) {
             $pie->set_feed_url($info['cache_path']);
             $pie->init();
             // If SimplePie finds a new RSS URL, let's update our cache
             if ($pie->feed_url != $info['url']) {
                 $this->db->Execute('UPDATE lylina_items SET url=?, fallback_url=? WHERE id=?', array($pie->feed_url, $info['url'], $info['id']));
             }
             // Update the real feed title - users who already have the feed added won't see the change
             // This is to prevent garbage names from OPML imports, which eventually won't be a problem,
             // but it's probably a good idea to keep the global title current anyway
             if ($pie->get_title() != $info['name']) {
                 $this->db->Execute('UPDATE lylina_feeds SET name=? WHERE id=?', array($pie->get_title(), $info['id']));
             }
             // TODO: Favicon handling isn't real pretty
             // If we have a new favicon URL, no cache, or stale cache, update cache
             if (!file_exists('cache/' . md5($info['url']) . '.ico') || time() - filemtime('cache/' . md5($info['url']) . '.ico') > 7 * 24 * 60 * 60 || $pie->get_favicon() != $info['icon']) {
                 $this->update_favicon($info, $pie);
             }
             // If we can successfully parse the file, format them
             if ($pie->get_items()) {
                 $this->insert_items($info, $pie, $purifier);
             }
         } else {
             // TODO: Provide debugging
         }
     }
 }
 public function __construct($data, $boxname = "")
 {
     $this->spnrbData['templatename'] = "simplePieNewsreaderBox";
     $this->getBoxStatus($data);
     $this->spnrbData['boxID'] = $data['boxID'];
     if (SPNRBOX_BOXOPENED == true) {
         $this->spnrbData['Status'] = 1;
     }
     if (WBBCore::getUser()->getPermission('user.board.canViewSimplePieNewsreaderBox')) {
         require_once WBB_DIR . 'lib/data/boxes/SimplePieNewsReader/simplepie.inc';
         require_once WBB_DIR . 'lib/data/boxes/SimplePieNewsReader/idna_convert.class.php';
         // FILTER?
         if (SPNRBOX_FILTER && strlen(SPNRBOX_FILTERWORDS) >= 3) {
             require_once WBB_DIR . 'lib/data/boxes/SimplePieNewsReader/simplepie_filter.php';
             $feed = new SimplePie_Filter();
             if (!defined('SPNRBOX_FILTERCLASS')) {
                 define('SPNRBOX_FILTERCLASS', 'hightlight');
             }
             define('SPNRBOX_FILTERON', 1);
         } else {
             $feed = new SimplePie();
             define('SPNRBOX_FILTERON', 0);
         }
         // CACHE
         if (SPNRBOX_CACHEMAX != 0 && SPNRBOX_CACHEMIN != 0) {
             $feed->set_autodiscovery_cache_duration(SPNRBOX_CACHEMAX);
             $feed->set_cache_duration(SPNRBOX_CACHEMIN);
         } else {
             $feed->set_autodiscovery_cache_duration(9999999999);
             $feed->set_cache_duration(9999999999);
         }
         // CHARSET
         if (!defined('CHARSET')) {
             define('CHARSET', 'UTF-8');
         }
         if (!defined('SPNRBOX_CHARSET')) {
             define('SPNRBOX_CHARSET', 'UTF-8');
         }
         if (SPNRBOX_CHARSET == 'default') {
             $charset = CHARSET;
         } else {
             $charset = SPNRBOX_CHARSET;
         }
         $feed->set_cache_location(WBB_DIR . 'lib/data/boxes/SimplePieNewsReader/cache');
         $feed->set_favicon_handler(RELATIVE_WBB_DIR . 'lib/data/boxes/SimplePieNewsReader/handler_image.php');
         $feed->set_image_handler(RELATIVE_WBB_DIR . 'lib/data/boxes/SimplePieNewsReader/handler_image.php');
         $feed->set_output_encoding($charset);
         // BOOKMARKS
         $bookmarks = array();
         if (SPNRBOX_SHOWSOCIALBOOKMARKS) {
             $socialBookmarks = preg_split("/\r?\n/", SPNRBOX_SOCIALBOOKMARKS);
             $cntBookmark = 0;
             foreach ($socialBookmarks as $row) {
                 $row = trim($row);
                 if (preg_match("/\\|/", $row)) {
                     list($bookmarkTitle, $bookmarkUrl, $bookmarkImg, $bookmarkEncodeTitle, $bookmarkEncodeUrl) = preg_split("/\\|/", $row, 5);
                     $bookmarkTitle = trim($bookmarkTitle);
                     $bookmarkUrl = trim($bookmarkUrl);
                     $bookmarkImg = trim($bookmarkImg);
                     $bookmarkEncodeTitle = trim($bookmarkEncodeTitle);
                     $bookmarkEncodeUrl = trim($bookmarkEncodeUrl);
                     if (!empty($bookmarkTitle) && !empty($bookmarkUrl) && !empty($bookmarkImg) && isset($bookmarkEncodeTitle) && isset($bookmarkEncodeUrl)) {
                         $bookmarks[$cntBookmark]['bookmarkTitle'] = $bookmarkTitle;
                         $bookmarks[$cntBookmark]['bookmarkUrl'] = $bookmarkUrl;
                         $bookmarks[$cntBookmark]['bookmarkImg'] = $bookmarkImg;
                         $bookmarks[$cntBookmark]['bookmarkEncodeTitle'] = $bookmarkEncodeTitle == 1 ? 1 : 0;
                         $bookmarks[$cntBookmark]['bookmarkEncodeUrl'] = $bookmarkEncodeUrl == 1 ? 1 : 0;
                         $cntBookmark++;
                     }
                 }
             }
         }
         // THEMA ZUM FEED
         if (WCF::getUser()->getPermission('user.board.canViewThreadToFeed') && SPNRBOX_FEEDTOTHREAD) {
             require_once WBB_DIR . 'lib/data/board/Board.class.php';
             $accessibleBoards = explode(',', Board::getAccessibleBoards());
             $selectiveBoards = explode(',', SPNRBOX_FEEDTOTHREADBOARDID);
             $boardStructur = WCF::getCache()->get('board', 'boardStructure');
             if (count($selectiveBoards) != 0) {
                 $this->spnrbData['boardsForm'] = count($selectiveBoards) == 1 ? 'button' : 'list';
                 $cntBoards = 0;
                 $prefix = '';
                 foreach ($selectiveBoards as $k => $v) {
                     $tmp = Board::getBoard($v);
                     if ($tmp->boardType < 2 && in_array($v, $accessibleBoards)) {
                         $this->spnrbData['boards'][$cntBoards]['id'] = $tmp->boardID;
                         $this->spnrbData['boards'][$cntBoards]['type'] = $tmp->boardType;
                         $prefix = '';
                         foreach ($boardStructur as $boardDepth => $boardKey) {
                             if (in_array($this->spnrbData['boards'][$cntBoards]['id'], $boardKey)) {
                                 $prefix = str_repeat('--', $boardDepth);
                                 break;
                             }
                         }
                         $this->spnrbData['boards'][$cntBoards]['title'] = ($prefix != '' ? $prefix : '') . ' ' . $tmp->title;
                         $cntBoards++;
                     }
                 }
             } else {
                 $this->spnrbData['boardsForm'] = '';
             }
         }
         $feedUrls = preg_split('/\\r?\\n/', SPNRBOX_FEEDS);
         $cntFeedUrl = 0;
         foreach ($feedUrls as $k => $feedurl) {
             $feedurl = trim($feedurl);
             if (empty($feedurl)) {
                 continue;
             }
             $feed->set_feed_url($feedurl);
             $feed->init();
             $feed->handle_content_type();
             if (SPNRBOX_FILTERON) {
                 $feed->set_filter(SPNRBOX_FILTERWORDS, SPNRBOX_FILTERMODE);
             }
             if (!($favicon = $feed->get_favicon())) {
                 $favicon = RELATIVE_WBB_DIR . 'icon/alternate_favicon.png';
             }
             $this->spnrbData['spnrFeeds'][$cntFeedUrl]['id'] = $cntFeedUrl;
             $this->spnrbData['spnrFeeds'][$cntFeedUrl]['link'] = $feed->get_permalink();
             $this->spnrbData['spnrFeeds'][$cntFeedUrl]['title'] = $feed->get_title();
             $this->spnrbData['spnrFeeds'][$cntFeedUrl]['favicon'] = $favicon;
             $this->spnrbData['spnrFeeds'][$cntFeedUrl]['xml'] = $feedurl;
             $items = $feed->get_items();
             if (SPNRBOX_FILTERON) {
                 $items = $feed->filter($items);
             }
             $i = 0;
             foreach ($items as $item) {
                 if ($i >= SPNRBOX_NUMOFFEEDS) {
                     break;
                 }
                 $iFeed = $item->get_feed();
                 $this->spnrbData['spnrFeeds'][$cntFeedUrl]['iFeed'][$i]['id'] = $i;
                 $this->spnrbData['spnrFeeds'][$cntFeedUrl]['iFeed'][$i]['link'] = $item->get_permalink();
                 $this->spnrbData['spnrFeeds'][$cntFeedUrl]['iFeed'][$i]['title'] = html_entity_decode($item->get_title(), ENT_QUOTES, $charset);
                 $this->spnrbData['spnrFeeds'][$cntFeedUrl]['iFeed'][$i]['content'] = SPNRBOX_FILTERON ? $this->highlight(SPNRBOX_FILTERWORDS, $item->get_content(), SPNRBOX_FILTERCLASS) : $item->get_content();
                 $this->spnrbData['spnrFeeds'][$cntFeedUrl]['iFeed'][$i]['date'] = $item->get_date('d.m.Y - H:i:s');
                 $this->spnrbData['spnrFeeds'][$cntFeedUrl]['iFeed'][$i]['bookmarks'] = array();
                 if (count($bookmarks)) {
                     $x = 0;
                     foreach ($bookmarks as $bookmark) {
                         $search[0] = "/\\{TITLE\\}/";
                         $search[1] = "/\\{URL\\}/";
                         $replace[0] = $bookmark['bookmarkEncodeTitle'] == 1 ? rawurlencode(html_entity_decode($item->get_title(), ENT_QUOTES, $charset)) : html_entity_decode($item->get_title());
                         $replace[1] = $bookmark['bookmarkEncodeUrl'] == 1 ? rawurlencode(html_entity_decode($item->get_permalink(), ENT_QUOTES, $charset)) : html_entity_decode($item->get_permalink());
                         $this->spnrbData['spnrFeeds'][$cntFeedUrl]['iFeed'][$i]['bookmarks'][$x]['bookmarkTitle'] = htmlspecialchars($bookmark['bookmarkTitle']);
                         $this->spnrbData['spnrFeeds'][$cntFeedUrl]['iFeed'][$i]['bookmarks'][$x]['bookmarkUrl'] = preg_replace($search, $replace, html_entity_decode($bookmark['bookmarkUrl']));
                         $this->spnrbData['spnrFeeds'][$cntFeedUrl]['iFeed'][$i]['bookmarks'][$x]['bookmarkImg'] = RELATIVE_WBB_DIR . "icon/" . $bookmark['bookmarkImg'];
                         $x++;
                     }
                 }
                 if ($enclosure = $item->get_enclosure()) {
                     $this->spnrbData['spnrFeeds'][$cntFeedUrl]['iFeed'][$i]['enclosure'] = '<p>' . $enclosure->native_embed(array('audio' => RELATIVE_WBB_DIR . 'icon/place_audio.png', 'video' => RELATIVE_WBB_DIR . 'icon/place_video.png', 'mediaplayer' => RELATIVE_WBB_DIR . 'icon/mediaplayer.swf', 'alt' => '<img src="' . RELATIVE_WBB_DIR . 'icon/mini_podcast.png" class="download" border="0" title="Download Podcast (' . $enclosure->get_extension() . '; ' . $enclosure->get_size() . ' MB)" />', 'altclass' => 'download')) . '</p>';
                 }
                 $i++;
             }
             $cntFeedUrl++;
         }
     }
 }