本文整理汇总了PHP中SimplePie::get_favicon方法的典型用法代码示例。如果您正苦于以下问题:PHP SimplePie::get_favicon方法的具体用法?PHP SimplePie::get_favicon怎么用?PHP SimplePie::get_favicon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimplePie
的用法示例。
在下文中一共展示了SimplePie::get_favicon方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: data
/**
* 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 »"</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 »';
$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);
}
示例2: addSubscription
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();
}
}
}
示例3: upgrade_single
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;
}
示例4: foreach
?>
">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>';
示例5: fetchFeeds
//.........这里部分代码省略.........
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);
示例6: array
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();
}
示例7: edit_feed
/**
* 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;
}
}
示例8: getFaviconURL
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;
}
示例9: SimplePieWP
//.........这里部分代码省略.........
}
} 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 {
示例10: _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();
//.........这里部分代码省略.........
示例11: SimplePie
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());
}
示例12: import_articles
/**
* 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();
//.........这里部分代码省略.........
示例13: get
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
}
}
}
示例14: __construct
//.........这里部分代码省略.........
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++;
}
}
}