get_item() 공개 메소드

This is better suited for {@link http://php.net/for for()} loops, whereas {@see \get_items()} is better suited for {@link http://php.net/foreach foreach()} loops.
또한 보기: get_item_quantity()
public get_item ( integer $key ) : SimplePie_Item | null
$key integer The item that you want to return. Remember that arrays begin with 0, not 1
리턴 SimplePie_Item | null
예제 #1
0
 public function respond()
 {
     $url = trim($this->matches[1]);
     $index = 0;
     if (isset($this->matches[2])) {
         $index = intval(trim($this->matches[2]));
         $index = $index - 1;
         $index = max(0, $index);
     }
     $error_level = error_reporting();
     error_reporting($error_level ^ E_USER_NOTICE);
     $feed = new \SimplePie();
     if ($this->cacheEnabled()) {
         $feed->set_cache_location($this->config['cache_directory']);
         $feed->set_cache_duration(600);
     }
     $feed->set_feed_url($url);
     $feed->init();
     $feed->handle_content_type();
     if ($index > $feed->get_item_quantity() - 1) {
         $index = $feed->get_item_quantity() - 1;
     }
     $item = $feed->get_item($index);
     $result = null;
     if ($item) {
         $title = html_entity_decode($item->get_title());
         $link = $item->get_permalink();
         $date = $item->get_date();
         $i = $index + 1;
         $result = "[{$i}] {$date} - {$title} - {$link}";
     }
     error_reporting($error_level);
     return $result;
 }
예제 #2
0
파일: cpanel.php 프로젝트: 01J/bealtine
 function getFeeds()
 {
     $app = JFactory::getApplication();
     $params = JComponentHelper::getParams('com_jce');
     $limit = $params->get('feed_limit', 2);
     $feeds = array();
     $options = array('rssUrl' => 'http://www.joomlacontenteditor.net/news/feed/rss/latest-news?format=feed', 'cache_time' => $params->get('feed_cachetime', 86400));
     // use this directly instead of JFactory::getXMLParserto avoid the feed data error
     jimport('simplepie.simplepie');
     if (!is_writable(JPATH_BASE . '/cache')) {
         $options['cache_time'] = 0;
     }
     $rss = new SimplePie($options['rssUrl'], JPATH_BASE . '/cache', isset($options['cache_time']) ? $options['cache_time'] : 0);
     $rss->force_feed(true);
     $rss->handle_content_type();
     if ($rss->init()) {
         $count = $rss->get_item_quantity();
         if ($count) {
             $count = $count > $limit ? $limit : $count;
             for ($i = 0; $i < $count; $i++) {
                 $feed = new StdClass();
                 $item = $rss->get_item($i);
                 $feed->link = $item->get_link();
                 $feed->title = $item->get_title();
                 $feed->description = $item->get_description();
                 $feeds[] = $feed;
             }
         }
     }
     return $feeds;
 }
예제 #3
0
 /**
  * @param $rssURL
  * @param $max
  * @return array|bool
  */
 public static function getRssFeed($rssURL, $max, $cache_time)
 {
     //if (JVM_VERSION < 3){
     $erRep = tsmConfig::setErrorReporting(false, true);
     jimport('simplepie.simplepie');
     $rssFeed = new SimplePie($rssURL);
     $feeds = array();
     $count = $rssFeed->get_item_quantity();
     $limit = min($max, $count);
     for ($i = 0; $i < $limit; $i++) {
         $feed = new StdClass();
         $item = $rssFeed->get_item($i);
         $feed->link = $item->get_link();
         $feed->title = $item->get_title();
         $feed->description = $item->get_description();
         $feeds[] = $feed;
     }
     if ($erRep[0]) {
         ini_set('display_errors', $erRep[0]);
     }
     if ($erRep[1]) {
         error_reporting($erRep[1]);
     }
     return $feeds;
     /*} else {
     			jimport('joomla.feed.factory');
     			$feed = new JFeedFactory;
     			$rssFeed = $feed->getFeed($rssURL,$cache_time);
     
     			if (empty($rssFeed) or !is_object($rssFeed)) return false;
     
     			for ($i = 0; $i < $max; $i++) {
     				if (!$rssFeed->offsetExists($i)) {
     					break;
     				}
     				$feed = new StdClass();
     				$uri = (!empty($rssFeed[$i]->uri) || !is_null($rssFeed[$i]->uri)) ? $rssFeed[$i]->uri : $rssFeed[$i]->guid;
     				$text = !empty($rssFeed[$i]->content) || !is_null($rssFeed[$i]->content) ? $rssFeed[$i]->content : $rssFeed[$i]->description;
     				$feed->link = $uri;
     				$feed->title = $rssFeed[$i]->title;
     				$feed->description = $text;
     				$feeds[] = $feed;
     			}
     			return $feeds;
     		}*/
 }
예제 #4
0
 /**
  * Method description
  *
  * @param  $service_id id of the service, we're about to use
  * @param  $service_type_id of the service, we're about to use
  * @param  $feed_url the url of the feed
  * @param  $items_per_feed maximum number of items that are fetched from the feed
  * @param  $items_max_age maximum age of any item that is fetched from feed, in days
  * @return
  * @access
  */
 function feed2array($username, $service_id, $service_type_id, $feed_url, $items_per_feed = 5, $items_max_age = '-21 days')
 {
     if (!$feed_url) {
         return false;
     }
     # get info about service type
     $max_age = $items_max_age ? date('Y-m-d H:i:s', strtotime($items_max_age)) : null;
     $items = array();
     $feed = new SimplePie();
     $feed->set_cache_location(CACHE . 'simplepie');
     $feed->set_feed_url($feed_url);
     $feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
     $feed->init();
     if ($feed->error() || $feed->feed_url != $feed_url) {
         return false;
     }
     for ($i = 0; $i < $feed->get_item_quantity($items_per_feed); $i++) {
         $feeditem = $feed->get_item($i);
         # create a NoseRub item out of the feed item
         $item = array();
         $item['datetime'] = $feeditem->get_date('Y-m-d H:i:s');
         if ($max_age && $item['datetime'] < $max_age) {
             # we can stop here, as we do not expect any newer items
             break;
         }
         $item['title'] = $feeditem->get_title();
         $item['url'] = $feeditem->get_link();
         $item['intro'] = @$intro;
         $item['type'] = @$token;
         $item['username'] = $username;
         $service = $this->getService($service_id);
         if ($service) {
             $item['content'] = $service->getContent($feeditem);
             if ($service instanceof TwitterService) {
                 $item['title'] = $item['content'];
             }
         } else {
             $item['content'] = $feeditem->get_content();
         }
         $items[] = $item;
     }
     unset($feed);
     return $items;
 }
예제 #5
0
	/**
	 * @param $rssURL
	 * @param $max
	 * @return array|bool
	 */
	static public function getRssFeed($rssURL, $max) {

		if (JVM_VERSION < 3){
			jimport('simplepie.simplepie');
			$rssFeed = new SimplePie($rssURL);

			$feeds = array();
			$count = $rssFeed->get_item_quantity();
			$limit=min($max,$count);
			for ($i = 0; $i < $limit; $i++) {
				$feed = new StdClass();
				$item = $rssFeed->get_item($i);
				$feed->link = $item->get_link();
				$feed->title = $item->get_title();
				$feed->description = $item->get_description();
				$feeds[] = $feed;
			}
			return $feeds;

		} else {
			jimport('joomla.feed.factory');
			$feed = new JFeedFactory;
			$rssFeed = $feed->getFeed($rssURL);

			if (empty($rssFeed) or !is_object($rssFeed)) return false;

			for ($i = 0; $i < $max; $i++) {
				if (!$rssFeed->offsetExists($i)) {
					break;
				}
				$feed = new StdClass();
				$uri = (!empty($rssFeed[$i]->uri) || !is_null($rssFeed[$i]->uri)) ? $rssFeed[$i]->uri : $rssFeed[$i]->guid;
				$text = !empty($rssFeed[$i]->content) || !is_null($rssFeed[$i]->content) ? $rssFeed[$i]->content : $rssFeed[$i]->description;
				$feed->link = $uri;
				$feed->title = $rssFeed[$i]->title;
				$feed->description = $text;
				$feeds[] = $feed;
			}
			return $feeds;
		}

	}
예제 #6
0
파일: simplepie.php 프로젝트: vad/taolin
 function feed_paginate($feed_url, $start = 0, $limit = 5)
 {
     //make the cache dir if it doesn't exist
     if (!file_exists($this->cache)) {
         $folder = new Folder($this->cache, true);
     }
     //include the vendor class
     App::import('Vendor', 'simplepie/simplepie');
     //setup SimplePie
     $feed = new SimplePie();
     $feed->set_feed_url($feed_url);
     $feed->set_cache_location($this->cache);
     //retrieve the feed
     $feed->init();
     //limits
     $max = $start + $limit;
     $items['title'] = $feed->get_title();
     $items['image_url'] = $feed->get_image_url();
     $items['image_height'] = $feed->get_image_height();
     $items['image_width'] = $feed->get_image_width();
     //$items['title'] = $feed->get_title();
     //get the feed items
     $items['quantity'] = $feed->get_item_quantity();
     if ($items['quantity'] < $start) {
         $items['items'] = false;
         return $items;
     } elseif ($items['quantity'] < $max) {
         $max = $items['quantity'];
     }
     for ($i = $start; $i < $max; $i++) {
         $items['items'][] = $feed->get_item($i);
     }
     //return
     if ($items) {
         return $items;
     } else {
         return false;
     }
 }
예제 #7
0
 function RssFeed($link)
 {
     //process rss
     $feed_url = $link;
     $items_per_feed = 10;
     $items_max_age = '-60 days';
     $max_age = $items_max_age ? date('Y-m-d H:i:s', strtotime($items_max_age)) : null;
     $items = array();
     App::import('vendor', 'simplepie/simplepie');
     $feed = new SimplePie();
     $feed->set_cache_location(CACHE . 'simplepie');
     $feed->set_feed_url($feed_url);
     $feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
     $feed->init();
     if ($feed->error() || $feed->feed_url != $feed_url) {
         return false;
     }
     for ($i = 0; $i < $feed->get_item_quantity($items_per_feed); $i++) {
         $feeditem = $feed->get_item($i);
         # create a NoseRub item out of the feed item
         $item = array();
         $item['datetime'] = $feeditem->get_date('Y-m-d H:i:s');
         if ($max_age && $item['datetime'] < $max_age) {
             # we can stop here, as we do not expect any newer items
             break;
         }
         $item['title'] = $feeditem->get_title();
         $item['url'] = $feeditem->get_link();
         //$item['intro']    = @$intro;
         //$item['type']     = @$token;
         //$item['username'] = $username;
         $items[] = $item;
     }
     unset($feed);
     $items;
     foreach ($items as $_item) {
         echo '<a href="' . $_item['url'] . '">' . $_item['title'] . '</a><br/>';
     }
     //end process rss
 }
예제 #8
0
function kingRssOutput($data)
{
    $feed = new SimplePie();
    $feed->feed_url($data['rss_url']);
    $path = explode($_SERVER["SERVER_NAME"], get_bloginfo('wpurl'));
    $feed->cache_location($_SERVER['DOCUMENT_ROOT'] . $path[1] . "/wp-content/cache");
    if (!empty($data['cache_time'])) {
        $feed->max_minutes = $data['cache_time'];
    }
    if (!empty($data['nosort'])) {
        $feed->order_by_date = false;
    }
    if (!empty($data['stripads'])) {
        $feed->strip_ads(1);
    }
    $feed->bypass_image_hotlink();
    $feed->bypass_image_hotlink_page($path[1] . "/index.php");
    #if images in feed are protected
    $success = $feed->init();
    if ($success && $feed->data) {
        $output = '';
        $replace_title_vars[0] = $feed->get_feed_link();
        $replace_title_vars[1] = $feed->get_feed_title();
        $replace_title_vars[2] = $feed->get_feed_description();
        $replace_title_vars[3] = $data['rss_url'];
        $replace_title_vars[4] = get_settings('siteurl') . '/wp-content/plugins/king-framework/images/rss.png';
        if ($feed->get_image_exist() == true) {
            $replace_title_vars[5] = $feed->get_image_url();
        }
        $search_title_vars = array('%link%', '%title%', '%descr%', '%rssurl%', '%rssicon%', '%feedimg%');
        #parse template placeholders
        $output .= str_replace($search_title_vars, $replace_title_vars, $data['titlehtml']);
        $max = $feed->get_item_quantity();
        if (!empty($data['max_items'])) {
            $max = min($data['max_items'], $feed->get_item_quantity());
        }
        for ($x = 0; $x < $max; $x++) {
            $item = $feed->get_item($x);
            $replace_vars[0] = stupifyEntities($item->get_title());
            $replace_vars[1] = $item->get_permalink();
            $replace_vars[2] = $item->get_date($data['showdate']);
            $replace_vars[3] = stupifyEntities($item->get_description());
            if ($item->get_categories() != false) {
                $categories = $item->get_categories();
                $replace_vars[4] = implode(" | ", $categories);
            }
            if ($item->get_author(0) != false) {
                $author = $item->get_author(0);
                $replace_vars[5] = $author->get_name();
            }
            # cut article text to length ... do the butcher
            if (!empty($data['shortdesc'])) {
                $suffix = '...';
                $short_desc = trim(str_replace("\n", ' ', str_replace("\r", ' ', strip_tags(stupifyEntities($item->get_description())))));
                $desc = substr($short_desc, 0, $data['shortdesc']);
                $lastchar = substr($desc, -1, 1);
                if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') {
                    $suffix = '';
                }
                $desc .= $suffix;
                $replace_vars[3] = $desc;
            }
            $search_vars = array('%title%', '%link%', '%date%', '%text%', '%category%', '%author%');
            #parse template placeholders
            $output .= str_replace($search_vars, $replace_vars, $data['rsshtml']);
        }
    } else {
        if (!empty($data['error'])) {
            $output = $data['error'];
        } else {
            if (isset($feed->error)) {
                $output = $feed->error;
            }
        }
    }
    return $output;
}
예제 #9
0
 function cron($verbose = false)
 {
     if ($verbose) {
         echo '<p>Starting cron...</p>';
     }
     global $wpdb;
     $options = get_option('proximusmoblog');
     if (!is_numeric($options['id'])) {
         $options['id'] = 1;
     }
     // Si l'id du prochain article est invalide, initialisé à 1
     if (is_numeric($options['blogid'])) {
         // Identifiant valide
         // Récupération du flux RSS
         require_once ABSPATH . WPINC . '/class-feed.php';
         $rss = new SimplePie();
         $rss->set_feed_url('http://payandgogeneration.proximus.be/moblogs/rss.cfm?id=' . $options['blogid']);
         // Désactiver le cache
         $rss->enable_cache(false);
         // Désactivation du tri par défaut
         $rss->enable_order_by_date(false);
         $rss->init();
         $rss->handle_content_type();
         $maxitems = $rss->get_item_quantity();
         // Nombre d'éléments du flux RSS
         $rss_items = $rss->get_items(0, $maxitems);
         // Tableau des articles récupérés
         $hackmin = 0;
         // Hack de décalage d'article pour ne pas avoir plusieurs articles publiés en même temps.
         for ($i = $maxitems - 1; $i >= 0; --$i) {
             $item = $rss->get_item($i);
             $guid = $item->get_id();
             $guid = substr($guid, strpos($guid, '=') + 1);
             $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->postmeta} WHERE meta_key = 'proximusMoblog_guid' AND meta_value = '{$guid}'"));
             if ($count == 0) {
                 if ($verbose) {
                     echo '<li>' . $guid . '</li>';
                 }
                 $enclosure = $item->get_enclosure();
                 $image = $enclosure->get_link();
                 $image = $this->downloadImage($image, $options['blogid'], $options['id']);
                 $title = str_replace('[id]', $options['id'], $options['titre']);
                 $contenu = str_replace('[image]', $image, $options['article']);
                 $date = date('Y-m-d H:i:s', time() + $hackmin);
                 // Create post object
                 $my_post = array();
                 $my_post['post_title'] = $title;
                 $my_post['post_content'] = $contenu;
                 $my_post['post_status'] = 'publish';
                 $my_post['post_date'] = $date;
                 if (!empty($options['user'])) {
                     $my_post['post_author'] = $options['user'];
                 }
                 if (!empty($options['categorie'])) {
                     $my_post['post_category'] = array($options['categorie']);
                 }
                 // Insert the post into the database
                 $postid = wp_insert_post($my_post);
                 add_post_meta($postid, 'proximusMoblog_guid', $guid);
                 $options['id']++;
                 $hackmin += 5;
             }
         }
         update_option('proximusmoblog', $options);
     }
     // Fin identifiant valide
 }
예제 #10
0
 /**
  * Test creating a very sparse post
  *
  * Only has the defaults, and nothing more
  * @dataProvider examplePostProvider
  * @param string $post Path to post template
  */
 public function testPostFromTemplate($post)
 {
     // Grab the correct collection
     $available = self::getCollectionsFromDocument($this->document);
     $proper = null;
     foreach ($available as $name => $collection) {
         if (in_array(AtomPubHelper::AtomEntryMediaType, $collection['accepted'])) {
             $proper = $collection;
             break;
         }
     }
     $this->assertNotNull($proper);
     $collection = $proper;
     Gorilla::$runner->report(Gorilla_Runner::REPORT_INFO, 'Creating from ' . str_replace(Gorilla::$path, 'Gorilla', $post));
     // Get the template data
     $data = file_get_contents($post);
     // Load it up
     $entry = AtomPubHelper_Entry::from_template($data);
     // Give it a random ID
     $entry->set_element('id', 'tag:ryanmccue.info,2012:' . sprintf("%06d%06d", rand(0, 100000), rand(0, 100000)));
     $entry->set_element('updated', date('c'));
     $headers = array('Content-Type' => AtomPubHelper::AtomEntryMediaType);
     // Generate a random slug (we'll check this later)
     $slug_num = sprintf("%06d", rand(0, 100000));
     $slug = 'ape-' . $slug_num;
     $slug_re = '#ape.?' . $slug_num . '#i';
     $headers['Slug'] = $slug;
     // Convert to XML
     $data = $entry->serialize_xml();
     Gorilla::$runner->report(Gorilla_Runner::REPORT_DEBUG, "Submitting entry:\n" . $data);
     // And then POST it to create it
     $poster = Requests::post($collection['href'], $headers, $data, self::requestsOptions());
     $this->assertEquals(201, $poster->status_code, 'Could not create new post: ' . $poster->body);
     $this->assertNotEmpty($poster->headers['location']);
     Gorilla::$runner->report(Gorilla_Runner::REPORT_INFO, 'Posting of new entry reported success, location: ' . $poster->headers['location']);
     // Check the data we got from the POST request
     Gorilla::$runner->report(Gorilla_Runner::REPORT_INFO, 'Examining the new entry as returned in the POST response');
     $wrapped = AtomPubHelper::wrap_entry($poster->body);
     $sp = new SimplePie();
     $sp->set_raw_data($wrapped);
     $sp->set_stupidly_fast();
     $sp->init();
     $this->assertNull($sp->error(), 'New entry is not well-formed: ' . $sp->error());
     $remote_entry = $sp->get_item(0);
     $this->checkEntry($entry, $remote_entry);
     $found = false;
     foreach ($remote_entry->get_links() as $link) {
         if (preg_match($slug_re, $link) > 0) {
             $found = true;
             break;
         }
     }
     if ($found) {
         Gorilla::$runner->report(Gorilla_Runner::REPORT_INFO, 'Slug was used in server-generated URI');
     } else {
         Gorilla::$runner->report(Gorilla_Runner::REPORT_WARNING, 'Slug not used in server-generated URI');
     }
     // And now check at the new location!
     Gorilla::$runner->report(Gorilla_Runner::REPORT_INFO, 'Checking at the new location');
     $new = Requests::get($poster->headers['location'], array(), array(), self::requestsOptions());
     $this->assertEquals(200, $new->status_code, 'New post not found at location');
     $wrapped = AtomPubHelper::wrap_entry($new->body);
     $sp = new SimplePie();
     $sp->set_raw_data($wrapped);
     $sp->set_stupidly_fast();
     $sp->init();
     $this->assertNull($sp->error(), 'New entry is not well-formed: ' . $sp->error());
     $remote_entry = $sp->get_item(0);
     $this->checkEntry($entry, $remote_entry);
 }
예제 #11
0
    function thefrosty_network_feed($attr, $count)
    {
        global $wpdb;
        include_once ABSPATH . WPINC . '/class-simplepie.php';
        $feed = new SimplePie();
        $feed->set_feed_url($attr);
        $feed->enable_cache(true);
        $feed->set_cache_duration(60 * 60 * 24 * 7);
        $cache_folder = plugin_dir_path(__FILE__) . 'cache';
        if (!is_writable($cache_folder)) {
            chmod($cache_folder, 0666);
        }
        $feed->set_cache_location($cache_folder);
        $feed->init();
        $feed->handle_content_type();
        $items = $feed->get_item();
        echo '<div class="t' . esc_attr($count) . ' tab-content postbox open feed">';
        echo '<ul>';
        if (empty($items)) {
            echo '<li>No items</li>';
        } else {
            foreach ($feed->get_items(0, 3) as $item) {
                ?>
		
				<li>		
					<a href='<?php 
                echo esc_url($item->get_permalink());
                ?>
' title='<?php 
                esc_attr_e($item->get_description());
                ?>
'><?php 
                esc_attr_e($item->get_title());
                ?>
</a><br /> 		
					<span style="font-size:10px; color:#aaa;"><?php 
                esc_attr_e($item->get_date('F, jS Y | g:i a'));
                ?>
</span>		
				</li>		
			<?php 
            }
        }
        echo '</ul>';
        echo '</div>';
    }
 /**
  * @param string $title
  * @return bool
  */
 function generate_content(&$title)
 {
     global $serendipity;
     $socialbookmarksID = $this->get_config('socialbookmarksID');
     if (empty($socialbookmarksID)) {
         return false;
     }
     $socialbookmarksService = $this->get_config('socialbookmarksService');
     if (($title = $this->get_config('sidebarTitle')) == '') {
         $title = $socialbookmarksService;
     }
     $moreLink = $this->get_config('moreLink');
     $md5_socialbookmarksID = md5($socialbookmarksID);
     $md5_socialbookmarksService = md5($socialbookmarksService);
     if ($this->get_config('displayNumber') < 31 && $this->get_config('displayNumber') >= 1) {
         $displayNumber = $this->get_config('displayNumber');
     } else {
         $displayNumber = 30;
     }
     if ($this->get_config('cacheTime') > 0) {
         $cacheTime = $this->get_config('cacheTime') * 3600;
     } else {
         $cacheTime = 3600 + 1;
     }
     $gsocialbookmarksURL = $this->feed_types[$socialbookmarksService]['usr_bookmarks_page'];
     $gsocialbookmarksFeedURL = $this->feed_types[$socialbookmarksService][$this->get_config('specialFeatures')];
     $gsocialbookmarksCacheLoc = $serendipity['serendipityPath'] . '/templates_c/socialbookmarks_';
     $parsedCache = $gsocialbookmarksCacheLoc . $md5_socialbookmarksService . '_' . $md5_socialbookmarksID . '.cache';
     if (!is_file($parsedCache) || mktime() - filectime($parsedCache) > $cacheTime) {
         if (!is_dir($gsocialbookmarksCacheLoc) && !mkdir($gsocialbookmarksCacheLoc, 0775)) {
             print 'Try to chmod go+rwx - permissions are wrong.';
         }
         if ($this->get_config('specialFeatures') != 'usr_js_tagcloud') {
             if (file_exists(S9Y_PEAR_PATH . '/simplepie/simplepie.inc')) {
                 require_once S9Y_PEAR_PATH . '/simplepie/simplepie.inc';
             } else {
                 require_once dirname(__FILE__) . '/simplepie/simplepie.inc';
             }
             $socialbookmarksFeed = new SimplePie();
             $socialbookmarksFeed->set_feed_url(str_replace('%username%', urlencode(utf8_decode(stripslashes($socialbookmarksID))), $gsocialbookmarksFeedURL));
             $socialbookmarksFeed->set_cache_location($serendipity['serendipityPath'] . '/templates_c/');
             $socialbookmarksFeed->enable_cache(false);
             $socialbookmarksFeed->init();
             $socialbookmarksFeed->handle_content_type();
             if ($socialbookmarksFeed->data) {
                 $fileHandle = @fopen($parsedCache, 'w');
                 if ($fileHandle) {
                     $socialbookmarksContent = '<ul class="serendipity_socialbookmarks_list" style="padding:0.1em;list-style-type:none;font-size:1em;">' . "\r\n";
                     $max = $socialbookmarksFeed->get_item_quantity($displayNumber);
                     for ($x = 0; $x < $max; $x++) {
                         /** @var SimplePie_Item $item */
                         $item = $socialbookmarksFeed->get_item($x);
                         $socialbookmarksContent .= '<li class="serendipity_socialbookmarks_item xfolkentry" style="list-style-type:' . ($this->get_config('displayThumbnails') ? 'none' : 'square') . ';list-style-position:inside;">';
                         $socialbookmarksContent .= '<a href="' . $this->decode($item->get_permalink()) . ' " class="taggedlink" title="' . trim(substr($this->decode(function_exists('serendipity_specialchars') ? serendipity_specialchars(strip_tags($item->get_description())) : htmlspecialchars(strip_tags($item->get_description()), ENT_COMPAT, LANG_CHARSET)), 0, 100)) . '" rel="external">';
                         if ($this->get_config('displayThumbnails')) {
                             $socialbookmarksContent .= $this->socialbookmarks_get_thumbnail($item->get_description());
                         } else {
                             $socialbookmarksContent .= html_entity_decode($this->decode($item->get_title()), ENT_COMPAT, LANG_CHARSET);
                         }
                         $socialbookmarksContent .= '</a>';
                         if ($this->get_config('displayTags') && class_exists('serendipity_event_freetag')) {
                             // display tags for each bookmark
                             $socialbookmarksContent .= $this->socialbookmarks_get_tags($item);
                         }
                         $socialbookmarksContent .= '</li>' . "\r\n";
                     }
                     $socialbookmarksContent .= '</ul>';
                     fwrite($fileHandle, $socialbookmarksContent);
                     fclose($fileHandle);
                     print $socialbookmarksContent;
                 } else {
                     print 'A ' . $this->get_config('socialbookmarksService') . ' error occured! <br />' . 'Error Message: unable to make a socialbookmarks cache file: ' . $parsedCache . '!';
                 }
             } elseif (is_file($parsedCache)) {
                 print file_get_contents($parsedCache);
             } else {
                 print 'A ' . $this->get_config('socialbookmarksService') . ' error occured! <br />' . 'Error Message: rss failed';
             }
         } else {
             $gsocialbookmarksFeedURL = str_replace('%username%', urlencode(utf8_decode(stripslashes($socialbookmarksID))), $gsocialbookmarksFeedURL);
             echo '<script type="text/javascript" src="' . $gsocialbookmarksFeedURL . $this->get_config('additionalParams') . '"></scipt>';
         }
     } else {
         print file_get_contents($parsedCache);
     }
     if (serendipity_db_bool($moreLink)) {
         print '<a href="' . str_replace('%username%', urlencode(utf8_decode(stripslashes($socialbookmarksID))), $gsocialbookmarksURL) . '/">(' . PLUGIN_SOCIALBOOKMARKS_MORELINK . ')</a>';
     }
 }
예제 #13
0
파일: network.php 프로젝트: bashrc/hubzilla
function discover_by_url($url, $arr = null)
{
    require_once 'library/HTML5/Parser.php';
    $x = scrape_feed($url);
    if (!$x) {
        if (!$arr) {
            return false;
        }
        $network = $arr['network'] ? $arr['network'] : 'unknown';
        $name = $arr['name'] ? $arr['name'] : 'unknown';
        $photo = $arr['photo'] ? $arr['photo'] : '';
        $addr = $arr['addr'] ? $arr['addr'] : '';
        $guid = $url;
    }
    $profile = $url;
    logger('scrape_feed results: ' . print_r($x, true));
    if ($x['feed_atom']) {
        $guid = $x['feed_atom'];
    }
    if ($x['feed_rss']) {
        $guid = $x['feed_rss'];
    }
    if (!$guid) {
        return false;
    }
    // try and discover stuff from the feeed
    require_once 'library/simplepie/simplepie.inc';
    $feed = new SimplePie();
    $level = 0;
    $x = z_fetch_url($guid, false, $level, array('novalidate' => true));
    if (!$x['success']) {
        logger('probe_url: feed fetch failed for ' . $poll);
        return false;
    }
    $xml = $x['body'];
    logger('probe_url: fetch feed: ' . $guid . ' returns: ' . $xml, LOGGER_DATA);
    logger('probe_url: scrape_feed: headers: ' . $x['header'], LOGGER_DATA);
    // Don't try and parse an empty string
    $feed->set_raw_data($xml ? $xml : '<?xml version="1.0" encoding="utf-8" ?><xml></xml>');
    $feed->init();
    if ($feed->error()) {
        logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error());
    }
    $name = unxmlify(trim($feed->get_title()));
    $photo = $feed->get_image_url();
    $author = $feed->get_author();
    if ($author) {
        if (!$name) {
            $name = unxmlify(trim($author->get_name()));
        }
        if (!$name) {
            $name = trim(unxmlify($author->get_email()));
            if (strpos($name, '@') !== false) {
                $name = substr($name, 0, strpos($name, '@'));
            }
        }
        if (!$profile && $author->get_link()) {
            $profile = trim(unxmlify($author->get_link()));
        }
        if (!$photo) {
            $rawtags = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
            if ($rawtags) {
                $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
                if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') {
                    $photo = $elems['link'][0]['attribs']['']['href'];
                }
            }
        }
    } else {
        $item = $feed->get_item(0);
        if ($item) {
            $author = $item->get_author();
            if ($author) {
                if (!$name) {
                    $name = trim(unxmlify($author->get_name()));
                    if (!$name) {
                        $name = trim(unxmlify($author->get_email()));
                    }
                    if (strpos($name, '@') !== false) {
                        $name = substr($name, 0, strpos($name, '@'));
                    }
                }
                if (!$profile && $author->get_link()) {
                    $profile = trim(unxmlify($author->get_link()));
                }
            }
            if (!$photo) {
                $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/', 'thumbnail');
                if ($rawmedia && $rawmedia[0]['attribs']['']['url']) {
                    $photo = unxmlify($rawmedia[0]['attribs']['']['url']);
                }
            }
            if (!$photo) {
                $rawtags = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
                if ($rawtags) {
                    $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
                    if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') {
                        $photo = $elems['link'][0]['attribs']['']['href'];
                    }
                }
            }
        }
    }
    if ($poll === $profile) {
        $lnk = $feed->get_permalink();
    }
    if (isset($lnk) && strlen($lnk)) {
        $profile = $lnk;
    }
    if (!$network) {
        $network = 'rss';
    }
    if (!$name) {
        $name = notags($feed->get_description());
    }
    if (!$guid) {
        return false;
    }
    $r = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($guid));
    if ($r) {
        return true;
    }
    if (!$photo) {
        $photo = z_root() . '/images/rss_icon.png';
    }
    $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_pubkey, xchan_addr, xchan_url, xchan_name, xchan_network, xchan_instance_url, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ", dbesc($guid), dbesc($guid), dbesc($pubkey), dbesc($addr), dbesc($profile), dbesc($name), dbesc($network), dbesc(z_root()), dbesc(datetime_convert()));
    $photos = import_xchan_photo($photo, $guid);
    $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'", dbesc(datetime_convert()), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), dbesc($photos[3]), dbesc($guid));
    return true;
}
예제 #14
0
function probe_url($url, $mode = PROBE_NORMAL)
{
    require_once 'include/email.php';
    $result = array();
    if (!$url) {
        return $result;
    }
    $network = null;
    $diaspora = false;
    $diaspora_base = '';
    $diaspora_guid = '';
    $diaspora_key = '';
    $has_lrdd = false;
    $email_conversant = false;
    $twitter = strpos($url, 'twitter.com') !== false ? true : false;
    $at_addr = strpos($url, '@') !== false ? true : false;
    if (!$twitter) {
        if (strpos($url, 'mailto:') !== false && $at_addr) {
            $url = str_replace('mailto:', '', $url);
            $links = array();
        } else {
            $links = lrdd($url);
        }
        if (count($links)) {
            $has_lrdd = true;
            logger('probe_url: found lrdd links: ' . print_r($links, true), LOGGER_DATA);
            foreach ($links as $link) {
                if ($link['@attributes']['rel'] === NAMESPACE_ZOT) {
                    $zot = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === NAMESPACE_DFRN) {
                    $dfrn = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === 'salmon') {
                    $notify = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === NAMESPACE_FEED) {
                    $poll = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') {
                    $hcard = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
                    $profile = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0') {
                    $poco = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') {
                    $diaspora_base = unamp($link['@attributes']['href']);
                    $diaspora = true;
                }
                if ($link['@attributes']['rel'] === 'http://joindiaspora.com/guid') {
                    $diaspora_guid = unamp($link['@attributes']['href']);
                    $diaspora = true;
                }
                if ($link['@attributes']['rel'] === 'diaspora-public-key') {
                    $diaspora_key = base64_decode(unamp($link['@attributes']['href']));
                    $pubkey = rsatopem($diaspora_key);
                    $diaspora = true;
                }
            }
            // Status.Net can have more than one profile URL. We need to match the profile URL
            // to a contact on incoming messages to prevent spam, and we won't know which one
            // to match. So in case of two, one of them is stored as an alias. Only store URL's
            // and not webfinger user@host aliases. If they've got more than two non-email style
            // aliases, let's hope we're lucky and get one that matches the feed author-uri because
            // otherwise we're screwed.
            foreach ($links as $link) {
                if ($link['@attributes']['rel'] === 'alias') {
                    if (strpos($link['@attributes']['href'], '@') === false) {
                        if (isset($profile)) {
                            if ($link['@attributes']['href'] !== $profile) {
                                $alias = unamp($link['@attributes']['href']);
                            }
                        } else {
                            $profile = unamp($link['@attributes']['href']);
                        }
                    }
                }
            }
        } elseif ($mode == PROBE_NORMAL) {
            // Check email
            $orig_url = $url;
            if (strpos($orig_url, '@') && validate_email($orig_url)) {
                $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user()));
                $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user()));
                if (count($x) && count($r)) {
                    $mailbox = construct_mailbox_name($r[0]);
                    $password = '';
                    openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);
                    $mbox = email_connect($mailbox, $r[0]['user'], $password);
                    if (!$mbox) {
                        logger('probe_url: email_connect failed.');
                    }
                    unset($password);
                }
                if ($mbox) {
                    $msgs = email_poll($mbox, $orig_url);
                    logger('probe_url: searching ' . $orig_url . ', ' . count($msgs) . ' messages found.', LOGGER_DEBUG);
                    if (count($msgs)) {
                        $addr = $orig_url;
                        $network = NETWORK_MAIL;
                        $name = substr($url, 0, strpos($url, '@'));
                        $phost = substr($url, strpos($url, '@') + 1);
                        $profile = 'http://' . $phost;
                        // fix nick character range
                        $vcard = array('fn' => $name, 'nick' => $name, 'photo' => avatar_img($url));
                        $notify = 'smtp ' . random_string();
                        $poll = 'email ' . random_string();
                        $priority = 0;
                        $x = email_msg_meta($mbox, $msgs[0]);
                        if (stristr($x->from, $orig_url)) {
                            $adr = imap_rfc822_parse_adrlist($x->from, '');
                        } elseif (stristr($x->to, $orig_url)) {
                            $adr = imap_rfc822_parse_adrlist($x->to, '');
                        }
                        if (isset($adr)) {
                            foreach ($adr as $feadr) {
                                if (strcasecmp($feadr->mailbox, $name) == 0 && strcasecmp($feadr->host, $phost) == 0 && strlen($feadr->personal)) {
                                    $personal = imap_mime_header_decode($feadr->personal);
                                    $vcard['fn'] = "";
                                    foreach ($personal as $perspart) {
                                        if ($perspart->charset != "default") {
                                            $vcard['fn'] .= iconv($perspart->charset, 'UTF-8//IGNORE', $perspart->text);
                                        } else {
                                            $vcard['fn'] .= $perspart->text;
                                        }
                                    }
                                    $vcard['fn'] = notags($vcard['fn']);
                                }
                            }
                        }
                    }
                    imap_close($mbox);
                }
            }
        }
    }
    if ($mode == PROBE_NORMAL) {
        if (strlen($zot)) {
            $s = fetch_url($zot);
            if ($s) {
                $j = json_decode($s);
                if ($j) {
                    $network = NETWORK_ZOT;
                    $vcard = array('fn' => $j->fullname, 'nick' => $j->nickname, 'photo' => $j->photo);
                    $profile = $j->url;
                    $notify = $j->post;
                    $pubkey = $j->pubkey;
                    $poll = 'N/A';
                }
            }
        }
        if (strlen($dfrn)) {
            $ret = scrape_dfrn($hcard ? $hcard : $dfrn);
            if (is_array($ret) && x($ret, 'dfrn-request')) {
                $network = NETWORK_DFRN;
                $request = $ret['dfrn-request'];
                $confirm = $ret['dfrn-confirm'];
                $notify = $ret['dfrn-notify'];
                $poll = $ret['dfrn-poll'];
                $vcard = array();
                $vcard['fn'] = $ret['fn'];
                $vcard['nick'] = $ret['nick'];
                $vcard['photo'] = $ret['photo'];
            }
        }
    }
    if ($diaspora && $diaspora_base && $diaspora_guid) {
        if ($mode == PROBE_DIASPORA || !$notify) {
            $notify = $diaspora_base . 'receive/users/' . $diaspora_guid;
            $batch = $diaspora_base . 'receive/public';
        }
        if (strpos($url, '@')) {
            $addr = str_replace('acct:', '', $url);
        }
    }
    if ($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) {
        if ($diaspora) {
            $network = NETWORK_DIASPORA;
        } elseif ($has_lrdd) {
            $network = NETWORK_OSTATUS;
        }
        $priority = 0;
        if ($hcard && !$vcard) {
            $vcard = scrape_vcard($hcard);
            // Google doesn't use absolute url in profile photos
            if (x($vcard, 'photo') && substr($vcard['photo'], 0, 1) == '/') {
                $h = @parse_url($hcard);
                if ($h) {
                    $vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo'];
                }
            }
            logger('probe_url: scrape_vcard: ' . print_r($vcard, true), LOGGER_DATA);
        }
        if ($twitter) {
            logger('twitter: setup');
            $tid = basename($url);
            $tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss';
            if (intval($tid)) {
                $poll = $tapi . '?user_id=' . $tid;
            } else {
                $poll = $tapi . '?screen_name=' . $tid;
            }
            $profile = 'http://twitter.com/#!/' . $tid;
            $vcard['photo'] = 'https://api.twitter.com/1/users/profile_image/' . $tid;
            $vcard['nick'] = $tid;
            $vcard['fn'] = $tid . '@twitter';
        }
        if (!x($vcard, 'fn')) {
            if (x($vcard, 'nick')) {
                $vcard['fn'] = $vcard['nick'];
            }
        }
        $check_feed = false;
        if ($twitter || !$poll) {
            $check_feed = true;
        }
        if (!isset($vcard) || !x($vcard, 'fn') || !$profile) {
            $check_feed = true;
        }
        if ($at_addr && !count($links)) {
            $check_feed = false;
        }
        if ($check_feed) {
            $feedret = scrape_feed($poll ? $poll : $url);
            logger('probe_url: scrape_feed ' . ($poll ? $poll : $url) . ' returns: ' . print_r($feedret, true), LOGGER_DATA);
            if (count($feedret) && ($feedret['feed_atom'] || $feedret['feed_rss'])) {
                $poll = x($feedret, 'feed_atom') ? unamp($feedret['feed_atom']) : unamp($feedret['feed_rss']);
                if (!x($vcard)) {
                    $vcard = array();
                }
            }
            if (x($feedret, 'photo') && !x($vcard, 'photo')) {
                $vcard['photo'] = $feedret['photo'];
            }
            require_once 'library/simplepie/simplepie.inc';
            $feed = new SimplePie();
            $xml = fetch_url($poll);
            logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA);
            $a = get_app();
            logger('probe_url: scrape_feed: headers: ' . $a->get_curl_headers(), LOGGER_DATA);
            $feed->set_raw_data($xml);
            $feed->init();
            if ($feed->error()) {
                logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error());
            }
            if (!x($vcard, 'photo')) {
                $vcard['photo'] = $feed->get_image_url();
            }
            $author = $feed->get_author();
            if ($author) {
                $vcard['fn'] = unxmlify(trim($author->get_name()));
                if (!$vcard['fn']) {
                    $vcard['fn'] = trim(unxmlify($author->get_email()));
                }
                if (strpos($vcard['fn'], '@') !== false) {
                    $vcard['fn'] = substr($vcard['fn'], 0, strpos($vcard['fn'], '@'));
                }
                $email = unxmlify($author->get_email());
                if (!$profile && $author->get_link()) {
                    $profile = trim(unxmlify($author->get_link()));
                }
                if (!$vcard['photo']) {
                    $rawtags = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
                    if ($rawtags) {
                        $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
                        if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') {
                            $vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
                        }
                    }
                }
            } else {
                $item = $feed->get_item(0);
                if ($item) {
                    $author = $item->get_author();
                    if ($author) {
                        $vcard['fn'] = trim(unxmlify($author->get_name()));
                        if (!$vcard['fn']) {
                            $vcard['fn'] = trim(unxmlify($author->get_email()));
                        }
                        if (strpos($vcard['fn'], '@') !== false) {
                            $vcard['fn'] = substr($vcard['fn'], 0, strpos($vcard['fn'], '@'));
                        }
                        $email = unxmlify($author->get_email());
                        if (!$profile && $author->get_link()) {
                            $profile = trim(unxmlify($author->get_link()));
                        }
                    }
                    if (!$vcard['photo']) {
                        $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/', 'thumbnail');
                        if ($rawmedia && $rawmedia[0]['attribs']['']['url']) {
                            $vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']);
                        }
                    }
                    if (!$vcard['photo']) {
                        $rawtags = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
                        if ($rawtags) {
                            $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
                            if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') {
                                $vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
                            }
                        }
                    }
                }
            }
            if (!$vcard['photo'] && strlen($email)) {
                $vcard['photo'] = avatar_img($email);
            }
            if ($poll === $profile) {
                $lnk = $feed->get_permalink();
            }
            if (isset($lnk) && strlen($lnk)) {
                $profile = $lnk;
            }
            if (!x($vcard, 'fn')) {
                $vcard['fn'] = notags($feed->get_title());
            }
            if (!x($vcard, 'fn')) {
                $vcard['fn'] = notags($feed->get_description());
            }
            if (strpos($vcard['fn'], 'Twitter / ') !== false) {
                $vcard['fn'] = substr($vcard['fn'], strpos($vcard['fn'], '/') + 1);
                $vcard['fn'] = trim($vcard['fn']);
            }
            if (!x($vcard, 'nick')) {
                $vcard['nick'] = strtolower(notags(unxmlify($vcard['fn'])));
                if (strpos($vcard['nick'], ' ')) {
                    $vcard['nick'] = trim(substr($vcard['nick'], 0, strpos($vcard['nick'], ' ')));
                }
            }
            if (!$network) {
                $network = NETWORK_FEED;
            }
            if (!$priority) {
                $priority = 2;
            }
        }
    }
    if (!x($vcard, 'photo')) {
        $a = get_app();
        $vcard['photo'] = $a->get_baseurl() . '/images/person-175.jpg';
    }
    if (!$profile) {
        $profile = $url;
    }
    // No human could be associated with this link, use the URL as the contact name
    if ($network === NETWORK_FEED && $poll && !x($vcard, 'fn')) {
        $vcard['fn'] = $url;
    }
    $vcard['fn'] = notags($vcard['fn']);
    $vcard['nick'] = str_replace(' ', '', notags($vcard['nick']));
    $result['name'] = $vcard['fn'];
    $result['nick'] = $vcard['nick'];
    $result['url'] = $profile;
    $result['addr'] = $addr;
    $result['batch'] = $batch;
    $result['notify'] = $notify;
    $result['poll'] = $poll;
    $result['request'] = $request;
    $result['confirm'] = $confirm;
    $result['poco'] = $poco;
    $result['photo'] = $vcard['photo'];
    $result['priority'] = $priority;
    $result['network'] = $network;
    $result['alias'] = $alias;
    $result['pubkey'] = $pubkey;
    logger('probe_url: ' . print_r($result, true), LOGGER_DEBUG);
    return $result;
}
예제 #15
0
파일: index.php 프로젝트: caomw/OpenCOLLADA
						<div class="nav_head">
							<h3>Project Status</h3>
						</div>
						<div class="nav_main">
							<ul>
								<!-- <li>Status: 93%</li> -->
								<li>Last release:<br/>
								 
								<?php 
$projfiles = new SimplePie();
$projfiles->enable_cache(false);
$projfiles->set_feed_url('http://sourceforge.net/export/rss2_projfiles.php?group_id=136478');
$projfiles->init();
$projfiles->handle_content_type();
if ($projfiles->data) {
    $item = $projfiles->get_item(0);
    list($version, $head) = split("released", $item->get_title());
    //echo $version;
    // if a part of the Version Sting overlaps the "Project Status"
    // Box, the whole site looks bad with IE.
    $token = strtok($version, " ");
    while ($token != false) {
        if (strlen($token) >= 20) {
            echo chunk_split($token, 20, "<br/>");
        } else {
            echo "{$token} ";
        }
        $token = strtok(" ");
    }
}
?>
예제 #16
0
파일: menu.php 프로젝트: joadelvia/intranet
defined('INTRANET_DIRECTORY') or exit('No direct script access allowed');
$idea = $_SESSION['ide'];
$profi = $_SESSION['profi'];
// FEED RSS
$feed = new SimplePie();
$feed->set_feed_url("http://www.juntadeandalucia.es/educacion/www/novedades.xml");
$feed->set_output_encoding('ISO-8859-1');
$feed->enable_cache(false);
$feed->set_cache_duration(600);
$feed->init();
$feed->handle_content_type();
$feed->get_title() ? $feed_title = $feed->get_title() : ($feed_title = 'Novedades - Consejería Educación');
$first_items = array();
$items_per_feed = 5;
for ($x = 0; $x < $feed->get_item_quantity($items_per_feed); $x++) {
    $first_items[] = $feed->get_item($x);
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
	<meta charset="iso-8859-1">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="description" content="Intranet del <?php 
echo $config['centro_denominacion'];
?>
">
	<meta name="author" content="IESMonterroso (https://github.com/IESMonterroso/intranet/)">
	<meta name="robots" content="noindex, nofollow">
	
예제 #17
0
/**
* Syndication import function. Imports headline data to a portal block.
*
* Rewritten December 19th 2004 by Michael Jervis (mike@*censored*ingbrit.com). Now
* utilises a Factory Pattern to open a URL and automaticaly retreive a feed
* object populated with feed data. Then import it into the portal block.
*
* @param    string  $bid            Block ID
* @param    string  $rdfurl         URL to get content from
* @param    int     $maxheadlines   Maximum number of headlines to display
* @return   void
* @see function COM_rdfCheck
*
*/
function COM_rdfImport($bid, $rdfurl, $maxheadlines = 0)
{
    global $_CONF, $_TABLES, $LANG21;
    require_once $_CONF['path'] . '/lib/simplepie/autoloader.php';
    $result = DB_query("SELECT rdf_last_modified, rdf_etag FROM {$_TABLES['blocks']} WHERE bid = " . (int) $bid);
    list($last_modified, $etag) = DB_fetchArray($result);
    // Load the actual feed handlers:
    $feed = new SimplePie();
    $feed->set_useragent('glFusion/' . GVERSION . ' ' . SIMPLEPIE_USERAGENT);
    $feed->set_feed_url($rdfurl);
    $feed->set_cache_location($_CONF['path'] . '/data/layout_cache');
    $rc = $feed->init();
    if ($rc == true) {
        $feed->handle_content_type();
        /* We have located a reader, and populated it with the information from
         * the syndication file. Now we will sort out our display, and update
         * the block.
         */
        if ($maxheadlines == 0) {
            if (!empty($_CONF['syndication_max_headlines'])) {
                $maxheadlines = $_CONF['syndication_max_headlines'];
            }
        }
        if ($maxheadlines == 0) {
            $number_of_items = $feed->get_item_quantity();
        } else {
            $number_of_items = $feed->get_item_quantity($maxheadlines);
        }
        $etag = '';
        $update = date('Y-m-d H:i:s');
        $last_modified = $update;
        $last_modified = DB_escapeString($last_modified);
        if (empty($last_modified)) {
            DB_query("UPDATE {$_TABLES['blocks']} SET rdfupdated = '{$update}', rdf_last_modified = NULL, rdf_etag = NULL WHERE bid = " . (int) $bid);
        } else {
            DB_query("UPDATE {$_TABLES['blocks']} SET rdfupdated = '{$update}', rdf_last_modified = '{$last_modified}', rdf_etag = '{$etag}' WHERE bid = " . (int) $bid);
        }
        for ($i = 0; $i < $number_of_items; $i++) {
            $item = $feed->get_item($i);
            $title = $item->get_title();
            if (empty($title)) {
                $title = $LANG21[61];
            }
            $link = $item->get_permalink();
            $enclosure = $item->get_enclosure();
            if ($link != '') {
                $content = COM_createLink($title, $link, $attr = array('target' => '_blank'));
            } elseif ($enclosure != '') {
                $content = COM_createLink($title, $enclosure, $attr = array('target' => '_blank'));
            } else {
                $content = $title;
            }
            $articles[] = $content;
        }
        // build a list
        $content = COM_makeList($articles, 'list-feed');
        $content = str_replace(array("\r", "\n"), '', $content);
        if (strlen($content) > 65000) {
            $content = $LANG21[68];
        }
        // Standard theme based function to put it in the block
        $result = DB_change($_TABLES['blocks'], 'content', DB_escapeString($content), 'bid', (int) $bid);
    } else {
        $err = $feed->error();
        COM_errorLog($err);
        $content = DB_escapeString($err);
        DB_query("UPDATE {$_TABLES['blocks']} SET content = '{$content}', rdf_last_modified = NULL, rdf_etag = NULL WHERE bid = " . (int) $bid);
    }
}
예제 #18
0
파일: main.php 프로젝트: subiet/Swiftriver
 /**
  *
  *   //get all the admin feeds in database.
  */
 private function get_new_feeds($category_id)
 {
     //get all the admin feeds in database.
     $dbfeeds = ORM::factory('feed')->select('id', 'feed_url', 'category_id')->where('category_id', $category_id)->find_all();
     if ($category_id == 0) {
         $dbfeeds = ORM::factory('feed')->select('id', 'feed_url', 'category_id')->find_all();
     }
     foreach ($dbfeeds as $dbfeed) {
         //Don't do anything about twitter categories.
         if ($dbfeed->category_id != 11) {
             $url = "";
             $feed = new SimplePie();
             $feed->enable_order_by_date(true);
             if ($dbfeed->category_id == 1) {
                 $url = "http://twitter.com/statuses/user_timeline/" . $dbfeed->feed_url . ".rss";
                 $feed->set_feed_url($url);
                 //	exit(0);
             } else {
                 $url = $dbfeed->feed_url;
                 $feed->set_feed_url($dbfeed->feed_url);
             }
             $feed->set_cache_location(APPPATH . 'cache');
             $feed->set_timeout(10);
             $feed->init();
             //		$channel = $feed->get_feed_tags('', 'channel');
             //		echo " tags=> ".$channel."<br/>";
             // echo "$url :<br/>";
             //	exit(0)
             $max_items = $feed->get_item_quantity();
             $require_new_items = 20;
             $new_item_counter = 0;
             $start = 0;
             for ($i = $start; $i < $max_items && $new_item_counter < $require_new_items; $i++) {
                 $item = $feed->get_item($i);
                 /*				//getting all the feed information.								 
                 						echo "$url:  latitude => ".$item->get_latitude();
                 						echo "   longitude => ".$item->get_longitude();
                 						echo '<a href="' . $feed->get_image_link() . '" title="' . $feed->get_image_title() . '">';
                 						echo '<img src="' . $feed->get_image_url() . '" width="' . $feed->get_image_width() . '" height="' . $feed->get_image_height() . '" />';
                 						echo '</a><br/>Title:'.$item->get_title();
                 						echo '<br/>Description:'.$item->get_description();
                 						echo '<hr/>';
                 								
                 						*/
                 $itemobj = new Feed_Item_Model();
                 $itemobj->feed_id = $dbfeed->id;
                 $itemobj->item_title = $item->get_title();
                 $itemobj->item_description = $item->get_description();
                 $itemobj->item_link = $item->get_permalink();
                 $itemobj->item_date = $item->get_date('Y-m-d h:m:s');
                 if ($author = $item->get_author()) {
                     $itemobj->item_source = $item->get_author()->get_name();
                     //temporary not working.
                 }
                 //echo "in Main Controller $dbfeed->feed_url =>  latitude =".$feed->get_latitude().", longitude =".$feed->get_longitude()."<br/>";
                 //echo "in Main Controller $dbfeed->feed_url =>   get_author() => ".$feed->get_author()."<br/>";
                 $linkCount = ORM::factory('feed_item')->where('item_link', $item->get_permalink())->count_all();
                 if ($linkCount == 0) {
                     $new_item_counter++;
                     //  echo "link:=> ".$item->get_permalink()." is new and has appear ".$linkCount." times <br/>";
                     $itemobj->save();
                 } else {
                     if ($linkCount > 0) {
                         //	echo "link:=> ".$item->get_permalink()." appears ".$linkCount." times <br/>";
                     }
                 }
             }
         }
     }
     //		exit(0);
 }
예제 #19
0
 protected function processResponse($response, $type)
 {
     wfProfileIn(__METHOD__);
     $return = '';
     switch ($type) {
         case self::RESPONSE_FORMAT_JSON:
             $return = json_decode($response, true);
             break;
         case self::RESPONSE_FORMAT_XML:
             $sp = new SimplePie();
             $sp->set_raw_data($response);
             $sp->init();
             if ($sp->error()) {
                 $return = $sp->data;
             } else {
                 $oItem = $sp->get_item();
                 if (empty($oItem)) {
                     $this->videoNotFound();
                 }
                 $return = get_object_vars($oItem->get_enclosure());
             }
             break;
         case self::RESPONSE_FORMAT_PHP:
             $return = unserialize($response);
             break;
         default:
             throw new UnsuportedTypeSpecifiedException();
     }
     wfProfileOut(__METHOD__);
     return $this->postProcess($return);
 }
예제 #20
0
 public static function getRssFeed($rssURL, $max)
 {
     jimport('simplepie.simplepie');
     $rssFeed = new SimplePie($rssURL);
     $feeds = array();
     $count = $rssFeed->get_item_quantity();
     $limit = min($max, $count);
     for ($i = 0; $i < $limit; $i++) {
         $feed = new StdClass();
         $item = $rssFeed->get_item($i);
         $feed->link = $item->get_link();
         $feed->title = $item->get_title();
         $feed->description = $item->get_description();
         $feeds[] = $feed;
     }
     return $feeds;
 }
예제 #21
0
    function thefrosty_dashboard_widget_rss($sidebar_args)
    {
        global $wpdb;
        extract(array($sidebar_args, EXTR_SKIP));
        //echo '<a href="http://frosty.me/cl"><img style="float:right; margin: 0 0 5px 5px;" src="' . plugin_dir_url( __FILE__ ) . '/Austin_Passy.jpg" alt="frosty" /></a>';
        $style = '<style type="text/css">';
        $style .= '.frosty .frosty-image { display:inline-block; height:25px; float:left; width:25px; overflow:hidden }' . "\n";
        $style .= '.frosty .frosty-image span { background:url("' . esc_url(plugin_dir_url(__FILE__)) . 'Sprite.jpg") 0 0 no-repeat; display: inline-block; height: 25px; width: 25px }' . "\n";
        $style .= '.frosty li { padding-left:30px }' . "\n";
        $style .= 'span.austinpassy { background-position: -31px 0 !important }' . "\n";
        $style .= 'span.jeanaarter { background-position: -60px 0 !important }' . "\n";
        $style .= 'span.wordcamp { background-position: -92px 0 !important }' . "\n";
        $style .= 'span.floatoholics { background-position: -124px 0 !important }' . "\n";
        $style .= 'span.thefrosty { background-position: -156px 0 !important }' . "\n";
        $style .= 'span.greatescapecabofishing { background-position: -193px 0 !important }' . "\n";
        $style .= 'span.wpworkshop { background-position: -221px 0 !important }' . "\n";
        $style .= 'span.infieldbox { background-position: -251px 0 !important }' . "\n";
        $style .= '</style>' . "\n";
        $domain = preg_replace('|https?://([^/]+)|', '$1', get_option('siteurl'));
        include_once ABSPATH . WPINC . '/class-simplepie.php';
        $feed = new SimplePie();
        $feed->set_feed_url('http://pipes.yahoo.com/pipes/pipe.run?_id=52c339c010550750e3e64d478b1c96ea&_render=rss');
        $feed->enable_cache(true);
        $cache_folder = plugin_dir_path(__FILE__) . 'cache';
        if (!is_writable($cache_folder)) {
            chmod($cache_folder, 0666);
        }
        $feed->set_cache_location($cache_folder);
        $feed->init();
        $feed->handle_content_type();
        $items = $feed->get_item();
        echo '<ul class="frosty">';
        if (empty($items)) {
            echo '<li>No items</li>';
        } else {
            echo $style;
            foreach ($feed->get_items(0, 6) as $item) {
                $title = esc_attr(strtolower(sanitize_title_with_dashes(htmlentities($item->get_title()))));
                $class = str_replace('http://', '', $item->get_permalink());
                $class = str_replace(array('2010.', '2011.', '2012.', '2014.'), '', $class);
                $class = str_replace(array('.com/', '.net/', '.org/', '.la/', 'la.'), ' ', $class);
                $class = str_replace(array('2011/', '2012/', '2013/', '2014/'), '', $class);
                $class = str_replace(array('01/', '02/', '03/', '04/', '05/', '06/', '07/', '08/', '09/', '10/', '11/', '12/'), '', $class);
                $class = str_replace($title, '', $class);
                $class = str_replace('/', '', $class);
                $class = str_replace('feedproxy.google', '', $class);
                $class = str_replace('~r', '', $class);
                $class = str_replace('~', ' ', $class);
                // Redundant, I know. Can you make a preg_replace for this?
                ?>
                    
                    <div class="frosty-image">
                    	<span class="<?php 
                echo strtolower(esc_attr($class));
                ?>
">&nbsp;</span>
                    </div>
					<li>
						<a class="rsswidget" href="<?php 
                echo esc_url($item->get_permalink());
                ?>
" title="<?php 
                esc_attr_e($item->get_description());
                ?>
"><?php 
                esc_attr_e($item->get_title());
                ?>
</a>		
						<span style="font-size:10px; color:#aaa;"><?php 
                echo esc_html($item->get_date('F, jS Y'));
                ?>
</span>			
					</li>		
				<?php 
            }
        }
        echo '</ul>';
    }
예제 #22
0
						</div>
						<div class="content_main">
							
							<?php 
$projfiles = new SimplePie();
$projfiles->enable_cache(false);
$projfiles->set_feed_url('http://sourceforge.net/export/rss2_projfiles.php?group_id=136478');
$projfiles->init();
$projfiles->handle_content_type();
if ($projfiles->data) {
    ?>
							
							<?php 
    $max = $projfiles->get_item_quantity(5);
    for ($x = 0; $x < $max; $x++) {
        $item = $projfiles->get_item($x);
        ?>
								<h3>
								    <a href="<?php 
        echo $item->get_permalink();
        ?>
">
									<?php 
        echo $item->get_title();
        ?>
								    </a>
								</h3>
								<div class="head3_menu">
									<p>
										<a href="<?php 
        echo $item->add_to_delicious();
예제 #23
0
파일: update.php 프로젝트: rmccue/Arduino
<?php

require_once 'simplepie.inc';
$settings = file_get_contents('../settings.json');
$settings = json_decode($settings);
$settings->last_update = time();
file_put_contents('../settings.json', json_encode($settings));
$sp = new SimplePie();
$sp->set_cache_location('./cache');
$sp->set_cache_duration($settings->frequency * 60);
$sp->set_feed_url('http://xml.weather.yahoo.com/forecastrss?p=' . $settings->location . '&u=c');
$sp->init();
if (stripos($sp->get_title(), 'error')) {
    die('Invalid location');
}
$item = $sp->get_item();
$weather = $item->get_item_tags('http://xml.weather.yahoo.com/ns/rss/1.0', 'forecast');
$weather = $weather[0]['attribs'][''];
$today = array();
$today[] = $weather['low'];
$today[] = $weather['high'];
// Cloudy conditions
if ($weather['code'] > 25 && $weather['code'] < 31) {
    $today[] = 'C';
} elseif ($weather['code'] > 30 && $weather['code'] < 35) {
    $today[] = 'F';
} else {
    $today[] = 'S';
}
file_put_contents('../weather.txt', implode(',', $today));
echo shell_exec('cd .. & python arduino.py 2> err.txt');
예제 #24
0
파일: Scrape.php 프로젝트: vinzv/friendica
function probe_url($url, $mode = PROBE_NORMAL, $level = 1)
{
    require_once 'include/email.php';
    $result = array();
    if (!$url) {
        return $result;
    }
    $result = Cache::get("probe_url:" . $mode . ":" . $url);
    if (!is_null($result)) {
        $result = unserialize($result);
        return $result;
    }
    $network = null;
    $diaspora = false;
    $diaspora_base = '';
    $diaspora_guid = '';
    $diaspora_key = '';
    $has_lrdd = false;
    $email_conversant = false;
    $connectornetworks = false;
    $appnet = false;
    if (strpos($url, 'twitter.com')) {
        $connectornetworks = true;
        $network = NETWORK_TWITTER;
    }
    // Twitter is deactivated since twitter closed its old API
    //$twitter = ((strpos($url,'twitter.com') !== false) ? true : false);
    $lastfm = strpos($url, 'last.fm/user') !== false ? true : false;
    $at_addr = strpos($url, '@') !== false ? true : false;
    if (!$appnet && !$lastfm && !$connectornetworks) {
        if (strpos($url, 'mailto:') !== false && $at_addr) {
            $url = str_replace('mailto:', '', $url);
            $links = array();
        } else {
            $links = lrdd($url);
        }
        if (count($links)) {
            $has_lrdd = true;
            logger('probe_url: found lrdd links: ' . print_r($links, true), LOGGER_DATA);
            foreach ($links as $link) {
                if ($link['@attributes']['rel'] === NAMESPACE_ZOT) {
                    $zot = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === NAMESPACE_DFRN) {
                    $dfrn = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === 'salmon') {
                    $notify = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === NAMESPACE_FEED) {
                    $poll = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') {
                    $hcard = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
                    $profile = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0') {
                    $poco = unamp($link['@attributes']['href']);
                }
                if ($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') {
                    $diaspora_base = unamp($link['@attributes']['href']);
                    $diaspora = true;
                }
                if ($link['@attributes']['rel'] === 'http://joindiaspora.com/guid') {
                    $diaspora_guid = unamp($link['@attributes']['href']);
                    $diaspora = true;
                }
                if ($link['@attributes']['rel'] === 'diaspora-public-key') {
                    $diaspora_key = base64_decode(unamp($link['@attributes']['href']));
                    if (strstr($diaspora_key, 'RSA ')) {
                        $pubkey = rsatopem($diaspora_key);
                    } else {
                        $pubkey = $diaspora_key;
                    }
                    $diaspora = true;
                }
                if ($link['@attributes']['rel'] === 'http://ostatus.org/schema/1.0/subscribe' and $mode == PROBE_NORMAL) {
                    $diaspora = false;
                }
            }
            // Status.Net can have more than one profile URL. We need to match the profile URL
            // to a contact on incoming messages to prevent spam, and we won't know which one
            // to match. So in case of two, one of them is stored as an alias. Only store URL's
            // and not webfinger user@host aliases. If they've got more than two non-email style
            // aliases, let's hope we're lucky and get one that matches the feed author-uri because
            // otherwise we're screwed.
            foreach ($links as $link) {
                if ($link['@attributes']['rel'] === 'alias') {
                    if (strpos($link['@attributes']['href'], '@') === false) {
                        if (isset($profile)) {
                            if ($link['@attributes']['href'] !== $profile) {
                                $alias = unamp($link['@attributes']['href']);
                            }
                        } else {
                            $profile = unamp($link['@attributes']['href']);
                        }
                    }
                }
            }
            // If the profile is different from the url then the url is abviously an alias
            if ($alias == "" and $profile != "" and !$at_addr and normalise_link($profile) != normalise_link($url)) {
                $alias = $url;
            }
        } elseif ($mode == PROBE_NORMAL) {
            // Check email
            $orig_url = $url;
            if (strpos($orig_url, '@') && validate_email($orig_url)) {
                $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval(local_user()));
                $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user()));
                if (count($x) && count($r)) {
                    $mailbox = construct_mailbox_name($r[0]);
                    $password = '';
                    openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);
                    $mbox = email_connect($mailbox, $r[0]['user'], $password);
                    if (!$mbox) {
                        logger('probe_url: email_connect failed.');
                    }
                    unset($password);
                }
                if ($mbox) {
                    $msgs = email_poll($mbox, $orig_url);
                    logger('probe_url: searching ' . $orig_url . ', ' . count($msgs) . ' messages found.', LOGGER_DEBUG);
                    if (count($msgs)) {
                        $addr = $orig_url;
                        $network = NETWORK_MAIL;
                        $name = substr($url, 0, strpos($url, '@'));
                        $phost = substr($url, strpos($url, '@') + 1);
                        $profile = 'http://' . $phost;
                        // fix nick character range
                        $vcard = array('fn' => $name, 'nick' => $name, 'photo' => avatar_img($url));
                        $notify = 'smtp ' . random_string();
                        $poll = 'email ' . random_string();
                        $priority = 0;
                        $x = email_msg_meta($mbox, $msgs[0]);
                        if (stristr($x[0]->from, $orig_url)) {
                            $adr = imap_rfc822_parse_adrlist($x[0]->from, '');
                        } elseif (stristr($x[0]->to, $orig_url)) {
                            $adr = imap_rfc822_parse_adrlist($x[0]->to, '');
                        }
                        if (isset($adr)) {
                            foreach ($adr as $feadr) {
                                if (strcasecmp($feadr->mailbox, $name) == 0 && strcasecmp($feadr->host, $phost) == 0 && strlen($feadr->personal)) {
                                    $personal = imap_mime_header_decode($feadr->personal);
                                    $vcard['fn'] = "";
                                    foreach ($personal as $perspart) {
                                        if ($perspart->charset != "default") {
                                            $vcard['fn'] .= iconv($perspart->charset, 'UTF-8//IGNORE', $perspart->text);
                                        } else {
                                            $vcard['fn'] .= $perspart->text;
                                        }
                                    }
                                    $vcard['fn'] = notags($vcard['fn']);
                                }
                            }
                        }
                    }
                    imap_close($mbox);
                }
            }
        }
    }
    if ($mode == PROBE_NORMAL) {
        if (strlen($zot)) {
            $s = fetch_url($zot);
            if ($s) {
                $j = json_decode($s);
                if ($j) {
                    $network = NETWORK_ZOT;
                    $vcard = array('fn' => $j->fullname, 'nick' => $j->nickname, 'photo' => $j->photo);
                    $profile = $j->url;
                    $notify = $j->post;
                    $pubkey = $j->pubkey;
                    $poll = 'N/A';
                }
            }
        }
        if (strlen($dfrn)) {
            $ret = scrape_dfrn($hcard ? $hcard : $dfrn, true);
            if (is_array($ret) && x($ret, 'dfrn-request')) {
                $network = NETWORK_DFRN;
                $request = $ret['dfrn-request'];
                $confirm = $ret['dfrn-confirm'];
                $notify = $ret['dfrn-notify'];
                $poll = $ret['dfrn-poll'];
                $vcard = array();
                $vcard['fn'] = $ret['fn'];
                $vcard['nick'] = $ret['nick'];
                $vcard['photo'] = $ret['photo'];
            }
        }
    }
    if ($diaspora && $diaspora_base && $diaspora_guid) {
        if ($mode == PROBE_DIASPORA || !$notify) {
            $notify = $diaspora_base . 'receive/users/' . $diaspora_guid;
            $batch = $diaspora_base . 'receive/public';
        }
        if (strpos($url, '@')) {
            $addr = str_replace('acct:', '', $url);
        }
    }
    if ($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) {
        if ($diaspora) {
            $network = NETWORK_DIASPORA;
        } elseif ($has_lrdd and $notify) {
            $network = NETWORK_OSTATUS;
        }
        if (strpos($url, '@')) {
            $addr = str_replace('acct:', '', $url);
        }
        $priority = 0;
        if ($hcard && !$vcard) {
            $vcard = scrape_vcard($hcard);
            // Google doesn't use absolute url in profile photos
            if (x($vcard, 'photo') && substr($vcard['photo'], 0, 1) == '/') {
                $h = @parse_url($hcard);
                if ($h) {
                    $vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo'];
                }
            }
            logger('probe_url: scrape_vcard: ' . print_r($vcard, true), LOGGER_DATA);
        }
        if ($diaspora && $addr) {
            // Diaspora returns the name as the nick. As the nick will never be updated,
            // let's use the Diaspora nickname (the first part of the handle) as the nick instead
            $addr_parts = explode('@', $addr);
            $vcard['nick'] = $addr_parts[0];
        }
        /* if($twitter) {
        			logger('twitter: setup');
        			$tid = basename($url);
        			$tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss';
        			if(intval($tid))
        				$poll = $tapi . '?user_id=' . $tid;
        			else
        				$poll = $tapi . '?screen_name=' . $tid;
        			$profile = 'http://twitter.com/#!/' . $tid;
        			//$vcard['photo'] = 'https://api.twitter.com/1/users/profile_image/' . $tid;
        			$vcard['photo'] = 'https://api.twitter.com/1/users/profile_image?screen_name=' . $tid . '&size=bigger';
        			$vcard['nick'] = $tid;
        			$vcard['fn'] = $tid;
        		} */
        if ($lastfm) {
            $profile = $url;
            $poll = str_replace(array('www.', 'last.fm/'), array('', 'ws.audioscrobbler.com/1.0/'), $url) . '/recenttracks.rss';
            $vcard['nick'] = basename($url);
            $vcard['fn'] = $vcard['nick'] . t(' on Last.fm');
            $network = NETWORK_FEED;
        }
        if (!x($vcard, 'fn')) {
            if (x($vcard, 'nick')) {
                $vcard['fn'] = $vcard['nick'];
            }
        }
        $check_feed = false;
        if (stristr($url, 'tumblr.com') && !stristr($url, '/rss')) {
            $poll = $url . '/rss';
            $check_feed = true;
            // Will leave it to others to figure out how to grab the avatar, which is on the $url page in the open graph meta links
        }
        if ($appnet || !$poll) {
            $check_feed = true;
        }
        if (!isset($vcard) || !x($vcard, 'fn') || !$profile) {
            $check_feed = true;
        }
        if ($at_addr && !count($links)) {
            $check_feed = false;
        }
        if ($connectornetworks) {
            $check_feed = false;
        }
        if ($check_feed) {
            $feedret = scrape_feed($poll ? $poll : $url);
            logger('probe_url: scrape_feed ' . ($poll ? $poll : $url) . ' returns: ' . print_r($feedret, true), LOGGER_DATA);
            if (count($feedret) && ($feedret['feed_atom'] || $feedret['feed_rss'])) {
                $poll = x($feedret, 'feed_atom') ? unamp($feedret['feed_atom']) : unamp($feedret['feed_rss']);
                if (!x($vcard)) {
                    $vcard = array();
                }
            }
            if (x($feedret, 'photo') && !x($vcard, 'photo')) {
                $vcard['photo'] = $feedret['photo'];
            }
            require_once 'library/simplepie/simplepie.inc';
            $feed = new SimplePie();
            $xml = fetch_url($poll);
            logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA);
            $a = get_app();
            logger('probe_url: scrape_feed: headers: ' . $a->get_curl_headers(), LOGGER_DATA);
            // Don't try and parse an empty string
            $feed->set_raw_data($xml ? $xml : '<?xml version="1.0" encoding="utf-8" ?><xml></xml>');
            $feed->init();
            if ($feed->error()) {
                logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error());
                $network = NETWORK_PHANTOM;
            }
            if (!x($vcard, 'photo')) {
                $vcard['photo'] = $feed->get_image_url();
            }
            $author = $feed->get_author();
            if ($author) {
                $vcard['fn'] = unxmlify(trim($author->get_name()));
                if (!$vcard['fn']) {
                    $vcard['fn'] = trim(unxmlify($author->get_email()));
                }
                if (strpos($vcard['fn'], '@') !== false) {
                    $vcard['fn'] = substr($vcard['fn'], 0, strpos($vcard['fn'], '@'));
                }
                $email = unxmlify($author->get_email());
                if (!$profile && $author->get_link()) {
                    $profile = trim(unxmlify($author->get_link()));
                }
                if (!$vcard['photo']) {
                    $rawtags = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
                    if ($rawtags) {
                        $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
                        if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') {
                            $vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
                        }
                    }
                }
                // Fetch fullname via poco:displayName
                $pocotags = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
                if ($pocotags) {
                    $elems = $pocotags[0]['child']['http://portablecontacts.net/spec/1.0'];
                    if (isset($elems["displayName"])) {
                        $vcard['fn'] = $elems["displayName"][0]["data"];
                    }
                    if (isset($elems["preferredUsername"])) {
                        $vcard['nick'] = $elems["preferredUsername"][0]["data"];
                    }
                }
            } else {
                $item = $feed->get_item(0);
                if ($item) {
                    $author = $item->get_author();
                    if ($author) {
                        $vcard['fn'] = trim(unxmlify($author->get_name()));
                        if (!$vcard['fn']) {
                            $vcard['fn'] = trim(unxmlify($author->get_email()));
                        }
                        if (strpos($vcard['fn'], '@') !== false) {
                            $vcard['fn'] = substr($vcard['fn'], 0, strpos($vcard['fn'], '@'));
                        }
                        $email = unxmlify($author->get_email());
                        if (!$profile && $author->get_link()) {
                            $profile = trim(unxmlify($author->get_link()));
                        }
                    }
                    if (!$vcard['photo']) {
                        $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/', 'thumbnail');
                        if ($rawmedia && $rawmedia[0]['attribs']['']['url']) {
                            $vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']);
                        }
                    }
                    if (!$vcard['photo']) {
                        $rawtags = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
                        if ($rawtags) {
                            $elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
                            if (x($elems, 'link') && $elems['link'][0]['attribs']['']['rel'] === 'photo') {
                                $vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
                            }
                        }
                    }
                }
            }
            // Workaround for misconfigured Friendica servers
            if ($network == "" and strstr($url, "/profile/")) {
                $noscrape = str_replace("/profile/", "/noscrape/", $url);
                $noscrapejson = fetch_url($noscrape);
                if ($noscrapejson) {
                    $network = NETWORK_DFRN;
                    $poco = str_replace("/profile/", "/poco/", $url);
                    $noscrapedata = json_decode($noscrapejson, true);
                    if (isset($noscrapedata["addr"])) {
                        $addr = $noscrapedata["addr"];
                    }
                    if (isset($noscrapedata["fn"])) {
                        $vcard["fn"] = $noscrapedata["fn"];
                    }
                    if (isset($noscrapedata["key"])) {
                        $pubkey = $noscrapedata["key"];
                    }
                    if (isset($noscrapedata["photo"])) {
                        $vcard["photo"] = $noscrapedata["photo"];
                    }
                    if (isset($noscrapedata["dfrn-request"])) {
                        $request = $noscrapedata["dfrn-request"];
                    }
                    if (isset($noscrapedata["dfrn-confirm"])) {
                        $confirm = $noscrapedata["dfrn-confirm"];
                    }
                    if (isset($noscrapedata["dfrn-notify"])) {
                        $notify = $noscrapedata["dfrn-notify"];
                    }
                    if (isset($noscrapedata["dfrn-poll"])) {
                        $poll = $noscrapedata["dfrn-poll"];
                    }
                }
            }
            if (!$vcard['photo'] && strlen($email)) {
                $vcard['photo'] = avatar_img($email);
            }
            if ($poll === $profile) {
                $lnk = $feed->get_permalink();
            }
            if (isset($lnk) && strlen($lnk)) {
                $profile = $lnk;
            }
            if (!$network) {
                $network = NETWORK_FEED;
                // If it is a feed, don't take the author name as feed name
                unset($vcard['fn']);
            }
            if (!x($vcard, 'fn')) {
                $vcard['fn'] = notags($feed->get_title());
            }
            if (!x($vcard, 'fn')) {
                $vcard['fn'] = notags($feed->get_description());
            }
            if (strpos($vcard['fn'], 'Twitter / ') !== false) {
                $vcard['fn'] = substr($vcard['fn'], strpos($vcard['fn'], '/') + 1);
                $vcard['fn'] = trim($vcard['fn']);
            }
            if (!x($vcard, 'nick')) {
                $vcard['nick'] = strtolower(notags(unxmlify($vcard['fn'])));
                if (strpos($vcard['nick'], ' ')) {
                    $vcard['nick'] = trim(substr($vcard['nick'], 0, strpos($vcard['nick'], ' ')));
                }
            }
            if (!$priority) {
                $priority = 2;
            }
        }
    }
    if (!x($vcard, 'photo')) {
        $a = get_app();
        $vcard['photo'] = $a->get_baseurl() . '/images/person-175.jpg';
    }
    if (!$profile) {
        $profile = $url;
    }
    // No human could be associated with this link, use the URL as the contact name
    if ($network === NETWORK_FEED && $poll && !x($vcard, 'fn')) {
        $vcard['fn'] = $url;
    }
    if ($notify != "" and $poll != "") {
        $baseurl = matching(normalise_link($notify), normalise_link($poll));
        $baseurl2 = matching($baseurl, normalise_link($profile));
        if ($baseurl2 != "") {
            $baseurl = $baseurl2;
        }
    }
    if ($baseurl == "" and $notify != "") {
        $baseurl = matching(normalise_link($profile), normalise_link($notify));
    }
    if ($baseurl == "" and $poll != "") {
        $baseurl = matching(normalise_link($profile), normalise_link($poll));
    }
    $baseurl = rtrim($baseurl, "/");
    if (strpos($url, '@') and $addr == "" and $network == NETWORK_DFRN) {
        $addr = str_replace('acct:', '', $url);
    }
    $vcard['fn'] = notags($vcard['fn']);
    $vcard['nick'] = str_replace(' ', '', notags($vcard['nick']));
    $result['name'] = $vcard['fn'];
    $result['nick'] = $vcard['nick'];
    $result['url'] = $profile;
    $result['addr'] = $addr;
    $result['batch'] = $batch;
    $result['notify'] = $notify;
    $result['poll'] = $poll;
    $result['request'] = $request;
    $result['confirm'] = $confirm;
    $result['poco'] = $poco;
    $result['photo'] = $vcard['photo'];
    $result['priority'] = $priority;
    $result['network'] = $network;
    $result['alias'] = $alias;
    $result['pubkey'] = $pubkey;
    $result['baseurl'] = $baseurl;
    logger('probe_url: ' . print_r($result, true), LOGGER_DEBUG);
    if ($level == 1) {
        // Trying if it maybe a diaspora account
        if ($result['network'] == NETWORK_FEED or $result['addr'] == "") {
            require_once 'include/bbcode.php';
            $address = GetProfileUsername($url, "", true);
            $result2 = probe_url($address, $mode, ++$level);
            if ($result2['network'] != "") {
                $result = $result2;
            }
        }
        // Maybe it's some non standard GNU Social installation (Single user, subfolder or no uri rewrite)
        if ($result['network'] == NETWORK_FEED and $result['baseurl'] != "" and $result['nick'] != "") {
            $addr = $result['nick'] . '@' . str_replace("http://", "", $result['baseurl']);
            $result2 = probe_url($addr, $mode, ++$level);
            if ($result2['network'] != "" and $result2['network'] != NETWORK_FEED) {
                $result = $result2;
            }
        }
    }
    // Only store into the cache if the value seems to be valid
    if ($result['network'] != NETWORK_PHANTOM) {
        Cache::set("probe_url:" . $mode . ":" . $url, serialize($result), CACHE_DAY);
    }
    return $result;
}
예제 #25
0
파일: news.php 프로젝트: caomw/OpenCOLLADA
						</div>
						<div class="content_main">
							
							<?php 
$newsfeed = new SimplePie();
$newsfeed->enable_cache(false);
$newsfeed->set_feed_url('http://sourceforge.net/export/rss2_projnews.php?group_id=136478&rss_fulltext=1');
$newsfeed->init();
$newsfeed->handle_content_type();
if ($newsfeed->data) {
    ?>
							
							<?php 
    $max = $newsfeed->get_item_quantity(5);
    for ($x = 0; $x < $max; $x++) {
        $item = $newsfeed->get_item($x);
        ?>
								<h3>
								    <a href="<?php 
        echo $item->get_permalink();
        ?>
">
									<?php 
        echo $item->get_title();
        ?>
								    </a>
								</h3>
								<div class="head3_menu">
									<p>
									    <a href="<?php 
        echo $item->add_to_delicious();