/** * Create a new SimplePie object * * Creates an instance of SimplePie with Items::$feeds * * @since 1.0 */ public function load() { global $lilina; require_once LILINA_INCPATH . '/contrib/simplepie/simplepie.inc'; $feed = new SimplePie(); $feed->set_useragent('Lilina/' . $lilina['core-sys']['version'] . '; (' . get_option('baseurl') . '; http://getlilina.org/; Allow Like Gecko) SimplePie/' . SIMPLEPIE_BUILD); $feed->set_stupidly_fast(true); $feed->set_cache_location(get_option('cachedir')); $feed->set_favicon_handler(get_option('baseurl') . '/lilina-favicon.php'); $feed = apply_filters('simplepie-config', $feed); $feed->set_feed_url($this->feeds); $feed->init(); /** We need this so we have something to work with. */ $feed->get_items(); if (!isset($feed->data['ordered_items'])) { $feed->data['ordered_items'] = $feed->data['items']; } /** Let's force sorting */ usort($feed->data['ordered_items'], array(&$feed, 'sort_items')); usort($feed->data['items'], array(&$feed, 'sort_items')); $this->simplepie = $feed; /** Free up memory just in case */ unset($feed); }
$feed->enable_xml_dump(isset($_GET['xmldump']) ? true : false); } // Allow us to change the input encoding from the URL string if we want to. (optional) if (!empty($_GET['input'])) { $feed->set_input_encoding($_GET['input']); } // Allow us to choose to not re-order the items by date. (optional) if (!empty($_GET['orderbydate']) && $_GET['orderbydate'] == 'false') { $feed->enable_order_by_date(false); } // Allow us to cache images in feeds. This will also bypass any hotlink blocking put in place by the website. if (!empty($_GET['image']) && $_GET['image'] == 'true') { $feed->set_image_handler('./handler_image.php'); } // We'll enable the discovering and caching of favicons. $feed->set_favicon_handler('./handler_image.php'); // 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 = $feed->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. $feed->handle_content_type(); // When we end our PHP block, we want to make sure our DOCTYPE is on the top line to make // sure that the browser snaps into Standards Mode. ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"> <head> <title>SimplePie: Demo</title>
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; }
public function execute() { parent::execute(); if ($this->action == 'NewsreaderCache') { $urls = preg_split('/\\r?\\n/', SPNRBOX_FEEDS); $cache_location = WBB_DIR . 'lib/data/boxes/SimplePieNewsReader/cache'; // 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; } // 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); } $feed->set_feed_url($urls); $feed->set_cache_location($cache_location); $feed->set_autodiscovery_cache_duration(0); $feed->set_cache_duration(0); $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); $feed->set_timeout(10); $feed->init(); $feed->handle_content_type(); if (SPNRBOX_FILTERON) { $feed->set_filter(SPNRBOX_FILTERWORDS, SPNRBOX_FILTERMODE); } header("Content-type: text/plain; charset=UTF-8"); foreach ($urls as $feeds) { $feeds = trim($feeds); if (empty($feeds)) { continue; } $feed->set_feed_url($feeds); $feed->init(); $items = $feed->get_items(); if (SPNRBOX_FILTERON) { $items = $feed->filter($items); } echo $feed->get_title() . "\n"; if (!count($items)) { echo "\tKeine Feeds gefunden.\n"; } else { $i = 0; foreach ($items as $item) { if ($i >= SPNRBOX_NUMOFFEEDS) { break; } SPNRBOX_FILTERON ? $this->highlight(SPNRBOX_FILTERWORDS, $item->get_content(), SPNRBOX_FILTERCLASS) : $item->get_content(); echo "\t\"" . $item->get_title() . "\" -> wurde geladen.\n"; $i++; } } } } }
/** * 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); }
function fof_parse($url) { $p =& FoF_Prefs::instance(); $admin_prefs = $p->admin_prefs; $pie = new SimplePie(); $pie->set_cache_duration($admin_prefs["manualtimeout"] * 60); $pie->set_favicon_handler("favicon.php"); $pie->set_feed_url($url); $pie->set_javascript(false); $pie->remove_div(false); $pie->init(); return $pie; }
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++; } } }
/** * Load and process a feed using SimplePie * * @param string $feed Feed detail array, as returned by Feeds::get() * @return SimplePie */ public static function &load_feed($feed) { // This loads the useragent class_exists('HTTPRequest'); global $lilina; $sp = new SimplePie(); $sp->set_useragent(LILINA_USERAGENT . ' SimplePie/' . SIMPLEPIE_BUILD); $sp->set_stupidly_fast(true); $sp->set_cache_location(get_option('cachedir')); //$sp->set_cache_duration(0); $sp->set_favicon_handler(get_option('baseurl') . 'lilina-favicon.php'); $sp = apply_filters('simplepie-config', $sp); $sp->set_feed_url($feed['feed']); $sp->init(); /** We need this so we have something to work with. */ $sp->get_items(); if (!isset($sp->data['ordered_items'])) { $sp->data['ordered_items'] = $sp->data['items']; } /** Let's force sorting */ usort($sp->data['ordered_items'], array(&$sp, 'sort_items')); usort($sp->data['items'], array(&$sp, 'sort_items')); do_action_ref_array('iu-load-feed', array(&$sp, $feed)); return $sp; }