Esempio n. 1
0
 function testData_XML_RSS_RSSReader()
 {
     $http = new HTTPClient();
     // rss 2.0
     $url = 'http://aggressiva.livejournal.com/data/rss';
     $http->SetTimeouts(30, 15);
     $xml = $http->Fetch($url);
     $Reader = new RSSReader();
     $Reader->Parse($xml);
     $data = $Reader->GetData();
     $this->assertTrue($data['channel'], "No channel found");
     $this->assertTrue($data['item']['pubdate'], "No items found");
 }
Esempio n. 2
0
<?php

require 'inc.config.php';
header('Content-type: text/plain; charset=utf-8');
user::check('admin feeds');
// delete blogs
$db->delete('blogs', '1');
// delete subscriptions
$db->delete('subscriptions', '1');
// delete blog posts
$db->delete('blog_posts', '1');
// insert from hard coded feeds
foreach (require 'inc.rss-feeds.php' as $feedName => $feedUrl) {
    var_dump($feedName);
    $feed = RSSReader::parse($feedUrl);
    $data = array('name' => $feedName, 'title' => $feed['title'], 'url' => $feed['url'], 'feed' => $feed['feed']);
    var_dump($db->insert('blogs', $data));
}
Esempio n. 3
0
		/**
		 * Get blog entries from myspace account
		 * 
		 * @var int friend account number (if not default)
		 */
		function GetBlogEntries($accountid = 0)
		{
			if (!$accountid) $accountid = $this->AccountID;
			
			$blog_page = sprintf(self::BLOG_ATOM_URL, $accountid);

			$http = new HTTPClient();
			$http->SetTimeouts(60, 30);
			$http->Fetch($blog_page);
			$blog_xml = $http->Result;

			$Reader = new RSSReader();
			$Reader->Parse($blog_xml);
			$data = $Reader->GetData();

			if (!$data) 
				return false;
			
			$blogs = array();
			
			foreach($data['item']['title'] as $key => $subject)
			{
				$timestamp = strtotime($data['item']['published'][$key]);
				
				array_push($blogs, array(
					'date'		=> date("Y-m-d", $timestamp),
					'subject'	=> $subject,
					'category'	=> "",
					'content'	=> $data['item']['content'][$key],
					'time'		=> date("H:i", $timestamp),
					'comments'	=> "",
					'timestamp' => $timestamp
				));
				
			} 
			
			return $blogs;
			
		}
Esempio n. 4
0
<?php

require_once 'WeatherForecast.php';
require_once 'WeatherDayInfo.php';
$url = "http://jornaldotempo.uol.com.br/rss/cidades/rss_prev_Lavras-MG.xml";
$reader = new RSSReader(simplexml_load_file($url));
$rssItem = $reader->getRssWeahter();
$wheaterForecast = new WeatherForecast($rssItem->title(), $rssItem->description());
$daysInfo = $wheaterForecast->daysInfo();
?>
<div id="weatherforecast">
    <label for="weather-city" style="color: #921b1b; font-weight: bold;">
        Para trocar a cidade clique na caixa abaixo
    </label><br />
    <h2>
        <!--<span><?echo $wheaterForecast->city()?></span>-->
        <?include "cities.html"?>
    </h2>
    <div class="painel-weather">
        <table class="weather-table" border="0">
            <tbody>
            <?$i = 0;?>
            <?while($daysInfo->valid() && $i < 4):?>
              <?$dayInfo = $daysInfo->current();?>
              <?if($i % 2 == 0):?>
              <tr>
              <?endif?>
                  <td>
                      <div class="td-weather">
                        <?echo $dayInfo->day()?> <!--(<?//echo $dayInfo->situation()?>)--> <br/>
                        <div class="weather-info">
Esempio n. 5
0
<?
require_once 'NewsController.php';
require_once 'NewsDao.php';
require_once 'NewRSS.php';
?>
<?php 
$controller = new NewsController(new NewsDao($connect));
try {
    $allRSS = $controller->listAll();
} catch (Exception $err) {
    echo $err->getMessage();
}
$reader = new RSSReader(simplexml_load_file($allRSS->offsetGet(0)->link()));
//$reader = new RSSReader(simplexml_load_file("http://www.revistacafeicultura.com.br/rss/rss.xml"));
$iterator = $reader->getRss();
// echo "<br />";
?>
<div>
    <!--<label class="label-font">Selecione a fonte: </label>-->
    <label for="weather-city" style="color: #921b1b; font-weight: bold;">
        Para trocar a fonte clique na caixa abaixo
    </label><br />    
    <h2 id="h2-rss">
        <select id="change-rss">
            <!--<option value=""></option>-->
            <?$i = 0;?>
            <?foreach($allRSS as $rss):?>
            <option value="<?echo $rss->id()?>" <?if($i++ == 0) echo "selected='selected'"?>>
                    <?echo ($rss->title())?>
            </option>
            <?endforeach;?>
Esempio n. 6
0
<?
require_once 'NewsController.php';
require_once 'NewsDao.php';
require_once 'NewRSS.php';
?>
<?php 
$controller = new NewsController(new NewsDao(Connection::connect()));
$id = $_GET['id'];
$newRss = $controller->get($id);
if ($newRss != null) {
    $reader = new RSSReader(simplexml_load_file($newRss->link()));
    $iterator = $reader->getRss();
    //$html = "<h6>".$reader->rssFont()." - <span style='font-size: 11px; font-weight: normal;'>".$reader->rssfontDescription()."</span></h6>";
    $html = "";
    $html .= "<ul>";
    $i = 7;
    while ($iterator->valid() && $i-- > 0) {
        $html .= "<li>";
        $html .= "<a class='news-rss' href='" . $iterator->current()->link() . "'>";
        $html .= "<span class='pubdate' style='font-size: 11px'>[" . $iterator->current()->pubDate() . "]</span> - ";
        $html .= "<span class='title-rss'>" . $iterator->current()->title() . "</span>";
        $html .= "<br />";
        //$html .=    "<span class='description-rss'>".$iterator->current()->description()."</span>";
        $html .= "</a>";
        $html .= "</li>";
        $iterator->next();
    }
    $html .= "</ul>";
    echo $html;
} else {
    print_r("Selecione uma fonte!");
Esempio n. 7
0
		/**
		 * Get blog entries from myspace account
		 * 
		 * @var int friend account number (if not default)
		 */
		function GetBlogEntries($accountid)
		{
			if (!$accountid) $accountid = $this->AccountID;
			
			$blog_page = sprintf(self::BLOG_URL, $accountid);
			
			$http = new HTTPClient();
			$http->SetTimeouts(60, 30);
			$http->Fetch($blog_page);
			
			if (preg_match("/<title>[^<]*302 Found[^<]*<\/title>/msi", $http->Result))
			{
				$blog_page = sprintf(self::BLOG_URL_SIMPLE, $accountid);
				
				$http = new HTTPClient();
				$http->SetTimeouts(60, 30);
				$http->Fetch($blog_page);
			}
			
			$blog_xml = $http->Result;
			
			$Reader = new RSSReader();
			$Reader->Parse($blog_xml);
			$data = $Reader->GetData();

			if (!$data) 
				return false;
			
			$blogs = array();
			
			foreach((array)$data['item']['title'] as $key => $subject)
			{
				$timestamp = strtotime($data['item']['pubdate'][$key]);
				
				array_push($blogs, array(
					'date'		=> date("Y-m-d", $timestamp),
					'subject'	=> $subject,
					'category'	=> "",
					'content'	=> $data['item']['description'][$key],
					'time'		=> date("H:i", $timestamp),
					'comments'	=> "",
					'timestamp' => $timestamp
				));
				
			} 
			
			return $blogs;
			
		}
Esempio n. 8
0
<?php

require 'inc.config.php';
user::check('add feed');
$feedUrl = '';
$feedExists = false;
if (isset($_POST['url'])) {
    $feedUrl = $_POST['url'];
    // Parse feed
    $feed = RSSReader::parse($feedUrl, $error);
    // Show feed to user
    if (empty($_POST['confirm'])) {
        echo '<p>This is what I got:</p>';
        if ($feed) {
            echo '<pre>' . h(print_r($feed, 1)) . '</pre>';
        } else {
            var_dump($feed, $error);
        }
    }
    // May exist already
    $blog = $db->select('blogs', array('feed' => $feedUrl), null, array('first' => true, 'class' => 'Blog'));
    if (!$blog) {
        if (!empty($_POST['confirm'])) {
            // save into db
            $data = array('name' => '', 'title' => $feed['title'], 'url' => $feed['url'], 'updated' => 0, 'checked' => 0, 'feed' => $feed['feed'], 'added_by_user_id' => USER_ID, 'private' => (int) (!empty($_POST['private'])));
            $db->insert('blogs', $data);
            $id = $db->insert_id();
            user::success('Blog added: ' . h($data['title']));
            redirect('index.php?blog=' . $id);
        }
        echo '<h1>Looks good? Resubmit!</h1>';
 /** 
  * This function will take a single rss <item> array and according to the
  * other attributes will wrap an HTML <div> around the cdata of the rss
  * element specified by 'element_no'.  Some elements have special case
  * issues, these are elements 0(title), 1(link), 2(description), and 
  * 6(enclosure).  The special issues are:
  *	0 - according to parameter $href_title this may or may not be linked
  *		via an HTML <a href> to the rss <link> location.
  *	1 - this is wrapped in both a <div> and <a href> linking to its own
  *		location.
  *	2 - the description may be shortened to	the number of characters 
  *		specified by $summary_length.
  *	6 - this rss element only has attributes which are currently not
  *		dealt with and thus it returns nothing.
  *
  * Other than these special cases a simple <div> wrapper will be 
  * produced and returned.
  *
  * @author Daniel Fowler (www.alephcipher.com)
  *
  * @param array &$rss_item_array an array containing the rss elements of a 
  *		single rss <item> such that the elements can be referenced
  *		in the array by name (e.g. $rss_item_array['description'])
  * @param int $element_no a number between (and including) 0(zero) and 10 
  *		that specifies the element to wrap in a div.  The number
  *		refers to an element as specified by get_element_name_from_no().
  * @param int $summary_length the length as specified by get_safe_summary() that
  *		the description should be shortened too, this is only used if
  *		$element_no refers to the description element.
  * @param bool $href_title true will add an HTML <a href> to the title element
  *		linking to the location given by the <link> element.  False
  *		will not (default).
  * @return string returns the HTML formatted content of rss element.
  * 
  */
 private static function get_element_div_wrapper(&$rss_item_array, $element_no, $summary_length, $href_title = false)
 {
     $element_name = RSSReader::get_element_name_from_no($element_no);
     //echo "PARSING element: " . $element_name . "<br />"; // DEBUG
     // elements with attr's: 9 7 4 6
     // elements with special issues: 0 1 2 6
     $str_to_ret = "";
     switch ($element_no) {
         case 0:
             // title
             if ($href_title) {
                 $str_to_ret = "\t<div class=\"rss_" . $element_name . "\"><a href=\"" . $rss_item_array[RSSReader::get_element_name_from_no(1)] . "\">" . $rss_item_array[$element_name] . "</a></div>\n";
             } else {
                 $str_to_ret = "\t<div class=\"rss_" . $element_name . "\">" . $rss_item_array[$element_name] . "</div>\n";
             }
             break;
         case 1:
             // link
             $str_to_ret = "\t<div class=\"rss_" . $element_name . "\"><a href=\"" . $rss_item_array[$element_name] . "\">" . $rss_item_array[$element_name] . "</a></div>\n";
             break;
         case 2:
             // description
             $str_to_ret .= "\t<div class=\"rss_description\">" . RSSReader::get_safe_summary($rss_item_array[$element_name], $summary_length) . "</div>\n";
             break;
         case 6:
             // enclosure
             // TODO: figure out how to deal with this element
             //$element_list .= "\t<div class=\"rss_enclosure\">" . $rss_item_array[""] . "</div>\n";
             break;
         default:
             // the rest
             $str_to_ret = "\t<div class=\"rss_" . $element_name . "\">" . $rss_item_array[$element_name] . "</div>\n";
             break;
     }
     return $str_to_ret;
 }
Esempio n. 10
0
 /**
  * Get FeedReader object for the feed.
  *
  * @return FeedReader
  */
 private function getReader()
 {
     if (!$this->reader) {
         $xml = $this->getXML();
         if (RSSReader::canRead($xml)) {
             $this->reader = new RSSReader($xml);
         } else {
             if (AtomReader::canRead($xml)) {
                 $this->reader = new AtomReader($xml);
             } else {
                 $this->reader = new NullReader($xml);
             }
         }
     }
     return $this->reader;
 }
Esempio n. 11
0
		div.rss_title
		{
			border-bottom: #000077 dashed 1px;
		}

		div.rss_pubdate
		{
			border-bottom: #000077 dashed 1px;
			font-size:10px;
		}


	</style> 
</head>
<body onload="" onunload="">
<?php 
// PHP execution for the rss_reader
include_once "rss_reader.php";
$rss_reader = new RSSReader();
//$rss_reader->set_file_to_parse("sample-rss-2.xml");
$rss_reader->set_file_to_parse("http://codingnotes.alephcipher.com/feed/");
$rss_data = $rss_reader->parse_file();
//var_dump($rss_data);
//echo RSSReader::rss_array_to_html($rss_data); // smallest possible function call
echo RSSReader::rss_array_to_html($rss_data, 3, 0, "082", true);
?>

</body>
</html>
Esempio n. 12
0
<?php

include "../../wp-load.php";
include "rss.class.php";
$sql = "select * from " . $table_prefix . "newstracker";
$result = $wpdb->get_results($sql);
if (is_array($result) && count($result) >= 1) {
    foreach ($result as $tracker) {
        $rss = new RSSReader($tracker->url);
        while ($rss->hasNext()) {
            $rssdata = $rss->next();
            $url = $rssdata["link"];
            $title = $rssdata["title"];
            $desc = $rssdata["description"];
            $pub = $rssdata["pubDate"];
            $hash = sha1($url . $title . $pub);
            $data = array("hash" => $hash);
            $sql = "select * from " . $table_prefix . "news_verify WHERE hash ='" . $hash . "'";
            $result = $wpdb->get_row($sql);
            if (!is_array($result) && count($result) <= 0) {
                $res = $wpdb->insert($table_prefix . "news_verify", $data);
                $returndata = addToDB($rssdata);
                /*echo $returndata;*/
            } else {
                /*print_r("0");*/
            }
            unset($hash);
        }
    }
}
Esempio n. 13
0
function get_daily_horoscope($dob)
{
    $sign = get_zodiac_sign($dob);
    $rss = new RSSReader('http://findyourfate.com/rss/dailyhoroscope-feed.asp?sign=' . $sign);
    $nn = $rss->getNumberOfNews();
    $output = '';
    $output .= '<table width="40%"  border="0" cellspacing="0" cellpadding="5" class="box">';
    $output .= '<tr><td>' . $rss->getImage() . '</td></tr>';
    $output .= '<tr><td>' . $rss->getChannelTitle('rsstitle') . '</td></tr>';
    for ($i = 0; $i < $nn; ++$i) {
        $output .= '<tr><td>' . $rss->getItemTitle('rsslink', $i) . '</td></tr>';
        $output .= '<tr><td>' . $rss->getItemDescription('rsstext', $i) . '</td></tr>';
        $output .= '<tr><td>' . $rss->getItemPubdate('rssdate', $i) . '</td></tr>';
        $output .= '<tr><td height="10"></td></tr>';
    }
    $output .= '</table>';
    return $output;
}