本文整理汇总了PHP中SimplePie::set_input_encoding方法的典型用法代码示例。如果您正苦于以下问题:PHP SimplePie::set_input_encoding方法的具体用法?PHP SimplePie::set_input_encoding怎么用?PHP SimplePie::set_input_encoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimplePie
的用法示例。
在下文中一共展示了SimplePie::set_input_encoding方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _createSimplePie
/**
* _createSimplePie
*
* @param string &$feed Params
*
* @return object
*/
private function _createSimplePie(&$feed)
{
include_once JPATH_AUTOTWEET . '/libs/SimplePie_autoloader.php';
// Process the feed with SimplePie
$simplePie = new SimplePie();
$simplePie->set_feed_url($feed->xtform->get('url'));
$simplePie->set_stupidly_fast(true);
$simplePie->enable_order_by_date(true);
if ($feed->xtform->get('encoding', 'utf-8')) {
$simplePie->set_input_encoding($feed->xtform->get('encoding'));
}
if ($feed->xtform->get('force_fsockopen')) {
$simplePie->force_fsockopen(true);
}
$use_sp_cache = EParameter::getComponentParam(CAUTOTWEETNG, 'use_sp_cache', true);
if ($use_sp_cache && is_writable(JPATH_CACHE)) {
$simplePie->set_cache_location(JPATH_CACHE);
$simplePie->enable_cache(true);
} else {
$simplePie->enable_cache(false);
}
$set_sp_timeout = EParameter::getComponentParam(CAUTOTWEETNG, 'set_sp_timeout', 10);
if ($set_sp_timeout) {
$simplePie->set_timeout((int) $set_sp_timeout);
}
$simplePie->init();
return $simplePie;
}
示例2: getFeedByUrl
private function getFeedByUrl($url)
{
// Create a new instance of the SimplePie object
$feed = new \SimplePie();
// Set feed
$feed->set_feed_url($url);
// 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);
}
// Trigger force-feed
if (!empty($_GET['force']) && $_GET['force'] == 'true') {
$feed->force_feed(true);
}
$feed->set_cache_location(dirname(__FILE__) . '/../cache/');
$feed->init();
return $feed->get_items(0, 10);
}
示例3: SimplePie
include_once '../idn/idna_convert.class.php';
// Create a new instance of the SimplePie object
$feed = new SimplePie();
//$feed->force_fsockopen(true);
// Make sure that page is getting passed a URL
if (isset($_GET['feed']) && $_GET['feed'] !== '') {
// Strip slashes if magic quotes is enabled (which automatically escapes certain characters)
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
$_GET['feed'] = stripslashes($_GET['feed']);
}
// Use the URL that was passed to the page in SimplePie
$feed->set_feed_url($_GET['feed']);
}
// 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);
}
// Trigger force-feed
if (!empty($_GET['force']) && $_GET['force'] == 'true') {
$feed->force_feed(true);
}
// 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.
示例4: getFeedData
public static function getFeedData($params)
{
$rssurl = str_replace("\n", ",", JString::trim($params->get('rssurl', '')));
$feedTimeout = (int) $params->get('feedTimeout', 10);
$rssdateorder = (int) $params->get('rssdateorder', 1);
$dformat = $params->get('dformat', '%d %b %Y %H:%M %P');
$rssperfeed = (int) $params->get('rssperfeed', 3);
$textfilter = JString::trim($params->get('textfilter', ''));
$pagination = (int) $params->get('pagination', 0);
$totalfeeds = (int) $params->get('rssitems', 5);
$filtermode = (int) $params->get('filtermode', 0);
$showfeedinfo = (int) $params->get('showfeedinfo', 1);
$input_encoding = JString::trim($params->get('inputencoding', ''));
$showimage = (int) $params->get('rssimage', 1);
$cacheTime = (int) $params->get('feedcache', 15) * 60;
//minutes
$orderBy = $params->get('orderby', 'date');
$tmzone = (int) $params->get('tmzone', 0) ? true : false;
$cachePath = JPATH_SITE . DS . 'cache' . DS . 'mod_we_ufeed_display';
$start = $end = 0;
if ($pagination) {
$pagination_items = (int) $params->get('paginationitems', 5);
$current_limit = modFeedShowHelper::getPage($params->get('mid', 0));
$start = ($current_limit - 1) * $pagination_items;
$end = $current_limit * $pagination_items;
}
#Get clean array
$rss_urls = @array_filter(explode(",", $rssurl));
#If only 1 link, use totalfeeds for total limit
if (count($rss_urls) == 1) {
$rssperfeed = $totalfeeds;
}
# Intilize RSS Doc
if (!class_exists('SimplePie')) {
jimport('simplepie.simplepie');
}
//Parser Code
$simplepie = new SimplePie();
$simplepie->set_cache_location($cachePath);
$simplepie->set_cache_duration($cacheTime);
$simplepie->set_stupidly_fast(true);
$simplepie->force_feed(true);
//$simplepie->force_fsockopen(false); //gives priority to CURL if is installed
$simplepie->set_timeout($feedTimeout);
$simplepie->set_item_limit($rssperfeed);
$simplepie->enable_order_by_date(false);
if ($input_encoding) {
$simplepie->set_input_encoding($input_encoding);
$simplepie->set_output_encoding('UTF-8');
}
$simplepie->set_feed_url($rss_urls);
$simplepie->init();
$rssTotalItems = (int) $simplepie->get_item_quantity($totalfeeds);
if ((int) $params->get('debug', 0)) {
echo "<h3>Total RSS Items:" . $rssTotalItems . "</h3>";
echo print_r($simplepie, true);
#debug
}
if (get_class($simplepie) != 'SimplePie' || !$rssTotalItems) {
return array("rsstotalitems" => 0, 'items' => false);
}
$feedItems = array();
#store all feeds items
$counter = 1;
foreach ($simplepie->get_items($start, $end) as $key => $feed) {
#Word Filter
if (!empty($textfilter) && $filtermode != 0) {
$filter = modFeedShowHelper::filterItems($feed, $textfilter);
#Include #Exclude
if ($filtermode == 1 && !$filter || $filtermode == 2 && $filter) {
$rssTotalItems--;
continue;
#Include
}
}
$FeedValues[$key] = new stdClass();
# channel header and link
$channel = $feed->get_feed();
$FeedValues[$key]->FeedTitle = $channel->get_title();
$FeedValues[$key]->FeedLink = $channel->get_link();
if ($showfeedinfo) {
$FeedValues[$key]->FeedFavicon = 'http://g.etfv.co/' . urlencode($FeedValues[$key]->FeedLink);
}
$FeedValues[$key]->FeedDescription = $channel->get_description();
$FeedValues[$key]->FeedLogo = $channel->get_image_url();
#Item
$FeedValues[$key]->ItemTitle = $feed->get_title();
$feeDateUNIX = $feed->get_date('U');
if ($feeDateUNIX < 1) {
$feeDateUNIX = strtotime(trim(str_replace(",", "", $feed->get_date(''))));
}
$FeedValues[$key]->ItemDate = WEJM16 ? JHTML::_('date', $feeDateUNIX, $dformat, $tmzone) : JHtml::date($feeDateUNIX, $dformat, $tmzone);
$FeedValues[$key]->ItemLink = $feed->get_link();
//$feed->get_permalink();
$FeedValues[$key]->ItemText = $feed->get_description();
$FeedValues[$key]->ItemFulltext = $feed->get_content();
$FeedValues[$key]->ItemEnclosure = $feed->get_enclosure();
$FeedValues[$key]->ItemEnclosures = $feed->get_enclosures();
if ($showimage) {
$FeedValues[$key]->ItemImage = "";
//.........这里部分代码省略.........
示例5: SimplePie
}
// Get Template
$rss['template_ITEM'] = get_tmpl_section('ITEM', $rssfeed['template']);
$rss['template_DIVIDER'] = get_tmpl_section('DIVIDER', $rssfeed['template']);
$rss['template_FEEDINFO'] = get_tmpl_section('FEEDINFO', $rssfeed['template']);
$rss['template_RSSFEED'] = get_tmpl_section('RSSFEED', $rssfeed['template']);
// Load SimplePie
require_once PHPWCMS_ROOT . '/include/inc_ext/simplepie.inc.php';
$rss_obj = new SimplePie();
// Feed URL
$rss_obj->set_feed_url($rssfeed['rssurl']);
// Output Encoding Charset
$rss_obj->set_output_encoding(PHPWCMS_CHARSET);
// Input Encoding Charset
if (!empty($rssfeed['content_type'])) {
$rss_obj->set_input_encoding($rssfeed['content_type']);
}
// Feed Cache Timeout
if (!$rssfeed["timeout"]) {
// set to default value = 3600 seconds = 1 hour
$rssfeed["timeout"] = 3600;
}
if ($rssfeed["cacheoff"]) {
// check if cache enabled or not
$rssfeed["timeout"] = 0;
}
if ($rssfeed["timeout"]) {
$rss_obj->enable_cache(true);
$rss_obj->set_cache_duration($rssfeed["timeout"]);
$rss_obj->set_cache_location(PHPWCMS_RSS);
} else {
示例6: _setSimplePieModxPlaceholders
/**
* 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();
//.........这里部分代码省略.........
示例7: fetchDataFromArXiv
function fetchDataFromArXiv($itemArray, $sourceFormat = "arXiv XML")
{
global $errors;
// NOTE: ATM, error checking is done in function 'arxivToRefbase()'
$sourceURLArray = array();
if (!empty($itemArray)) {
// Remove any duplicate IDs:
$itemArray = array_unique($itemArray);
// NOTE:
// When querying arXiv.org for multiple arXiv IDs *at once*, errors are not
// returned inline on a per-record basis. If one or more of the given
// arXiv IDs are invalid, arXiv.org returns a *single* error message, and
// any other requested records seem to get omitted from the arXiv response.
// To work around this, we'll query arXiv.org for each given arXiv ID
// *individually*, and we then perform the record validation (i.e. error
// checking) in function 'arxivToRefbase()'.
foreach ($itemArray as $item) {
// if (preg_match("#(arXiv:|http://arxiv\.org/abs/)?([\w.-]+/\d{7}|\d{4}\.\d{4,})(v\d+)?#i", $item)) // '$item' is an arXiv ID
// {
// Build query URL:
$sourceURLArray[] = "http://export.arxiv.org/api/query" . "?id_list=" . rawurlencode($item);
// }
}
// Perform query:
$feed = new SimplePie();
// setup new SimplePie constructor
$feed->set_feed_url($sourceURLArray);
// setup multi-feed request
$feed->set_input_encoding('UTF-8');
// force UTF-8 as input encoding
$feed->enable_cache(false);
// disable caching
$feed->enable_order_by_date(false);
// disable automatic sorting of entries by date
$feed->init();
// process options, fetch feeds, cache, parse, merge, etc
}
return array($errors, $feed);
}