Exemplo n.º 1
0
 public function executeRefresh()
 {
     $post = PostPeer::retrieveByPK($this->getRequestParameter('id'));
     $blog = $post->getBlog();
     $this->forward404Unless($blog->getId() == $this->getUser()->getId());
     if ($post) {
         try {
             $items = FeedParser::parse($blog->getFeed());
             foreach ($items as $item) {
                 if ($item->link == $post->getLink()) {
                     $post->removeTags();
                     foreach ($item->tags as $name) {
                         $tag = TagPeer::retriveByName($name, true);
                         $post->addTag($tag);
                     }
                     if ($post->hasTags()) {
                         $shortened = $post->setFullContent($item->content);
                         $post->setLink($item->link);
                         $post->setTitle($item->title);
                         $post->setCreatedAt($item->pubdate);
                         $post->setShortened($shortened);
                         $post->save();
                     }
                     break;
                 }
             }
             $this->setFlash('updated', 'Wpis został odświeżony.');
         } catch (Exception $e) {
             $this->setFlash('updated', 'Odswieżanie wpisu nie powiodło się.');
         }
     }
     $this->redirect('ucp/index');
 }
Exemplo n.º 2
0
 function execute(&$controller, &$request, &$user)
 {
     $member = $user->getAttribute('member', GLU_NS);
     // my feeds
     $source = DB_DataObject::factory('source');
     $source->whereAdd('member_id = ' . $source->escape($member->id));
     if ($request->hasParameter('id')) {
         $source->whereAdd('id = ' . $source->escape($request->getParameter('id')));
     }
     $source->find();
     $feeds = array();
     while ($source->fetch()) {
         $rss = new FeedParser($source->uri);
         $rss->parse();
         foreach ($rss->getItems() as $item) {
             $feed['id'] = $source->id;
             $feed['title'] = $item['title'];
             $feed['link'] = $item['link'];
             $feed['description'] = isset($item['description']) ? $item['description'] : '';
             $feed['date'] = isset($item['dc:date']) ? $item['dc:date'] : (isset($item['date']) ? $item['date'] : '');
             $feeds[] = $feed;
         }
     }
     $haj = new HTML_AJAX_JSON();
     $output = $haj->encode($feeds);
     header('Content-Type: application/x-javascript; charset=utf-8');
     echo $output;
     return VIEW_NONE;
 }
Exemplo n.º 3
0
 function testAtom03()
 {
     $uri = 'http://plnet.jp/test_feed/blogger-atom03.xml';
     $feed = new FeedParser($uri);
     $feed->parse();
     $this->assertEquals('p0t blogger', $feed->getTitle());
     $this->assertEquals('http://komagata.blogspot.com', $feed->getLink());
     $this->assertEquals('http://komagata.blogspot.com/favicon.ico', $feed->getFavicon());
     //print_r($feed->data);
 }
Exemplo n.º 4
0
 function parse()
 {
     $feed = DB_DataObject::factory('feed');
     $feed->uri = $this->uri;
     // was cached
     if ($feed->count() > 0) {
         $this->struct = $this->_getCache($this->uri);
         // no cache
     } else {
         $f = new FeedParser($this->uri);
         $f->parse();
         $this->struct = $f->toArray();
     }
 }
Exemplo n.º 5
0
 /**
  * Displays a static page.
  */
 function display()
 {
     $path = func_get_args();
     $count = count($path);
     if (!$count) {
         $this->redirect('/');
     }
     $page = $subpage = $title_for_layout = null;
     if (!empty($path[0])) {
         $page = $path[0];
     }
     if (!empty($path[1])) {
         $subpage = $path[1];
     }
     if (!empty($path[$count - 1])) {
         $this->title_for_layout = Inflector::humanize($path[$count - 1]);
         if ($this->title_for_layout == 'Home') {
             $this->title_for_layout = '';
         }
     }
     App::import('Vendor', 'feedparser/feedparser');
     $Parser = new FeedParser();
     $Parser->parse('http://blog.simpleve.com/feed/');
     $items = $Parser->getItems();
     $this->set('blogrss', $items);
     $Parser = new FeedParser();
     $Parser->parse('http://www.eveonline.com/feed/rdfdevblog.asp');
     $items = $Parser->getItems();
     $this->set('evedevblogrss', $items);
     $motd = file_get_contents('http://www.eveonline.com/motd.asp?s=xml');
     $motd = trim(str_replace('MOTD', '', $motd));
     $motd = trim(str_replace('shellexec:', '', $motd));
     $motd = trim(str_replace('<center>', '', $motd));
     $motd = trim(str_replace('</center>', '', $motd));
     $this->set('evemotd', $motd);
     $this->set(compact('page', 'subpage', 'title_for_layout'));
     $this->render(implode('/', $path));
 }
Exemplo n.º 6
0
set_time_limit(0);
define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/..'));
define('SF_APP', 'backend');
define('SF_ENVIRONMENT', 'prod');
define('SF_DEBUG', false);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
$databaseManager = new sfDatabaseManager();
$databaseManager->initialize();
$blogs = BlogPeer::getApproved();
logmsg('Skrypt odswiezajacy');
logmsg('Feedow do sprawdzenia: %d', count($blogs));
logmsg(str_repeat('-', 80));
foreach ($blogs as $blog) {
    logmsg('Parsowanie feedu %s', $blog->getFeed());
    try {
        $items = FeedParser::parse($blog->getFeed());
        $ts = PostPeer::getNewestTimestamp($blog);
        logmsg('Najnowszy wpis (timestamp): %d', $ts);
        foreach ($items as $item) {
            if (!parseItem($blog, $item, $ts)) {
                break;
            }
        }
    } catch (Exception $e) {
        logmsg('Blad: %s', $e->getMessage());
    }
    logmsg(str_repeat('-', 80) . "\n");
}
logmsg('Odswiezanie zakonczone.');
function parseItem($blog, $item, $ts)
{
Exemplo n.º 7
0
<?php

include 'FeedParser.php';
$Parser = new FeedParser();
$Parser->parse('http://www.sitepoint.com/rss.php');
$channels = $Parser->getChannels();
$items = $Parser->getItems();
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Testing the PHP Universal Feed Parser</title>
	<style type="text/css">
	body{
		padding: 0px;
		margin: 50px 150px;
		border: 1px solid #ddd;
		font-family: verdana, arial;
	}
	
	h1#title {
		background-color: #eee;
		border-bottom : 1px solid #ddd;
		margin: 0px 0px 15px;
		padding:10px;
		text-align: center;
	}
	h1#title a{
		font-size: 18px;
	}
	
Exemplo n.º 8
0
<?php

require_once dirname(dirname(__FILE__)) . '/webapp/config.php';
require_once 'FeedParser.php';
$uri = $_SERVER['argv'][1];
$feed = new FeedParser($uri);
$res = $feed->parse();
print_r($feed->toArray());
Exemplo n.º 9
0
 function execute(&$controller, &$request, &$user)
 {
     $uri = $request->getParameter('uri');
     $member = $user->getAttribute('member', GLU_NS);
     $redirect = $request->hasParameter('redirect') ? $request->getParameter('redirect') : null;
     $cc_id = $this->getContentCategoryIdByUri($uri) ? $this->getContentCategoryIdByUri($uri) : 8;
     // get feed
     $f = new FeedParser($uri);
     $parse_result = $f->parse();
     if ($parse_result === false) {
         trigger_error(__CLASS__ . '::' . __FUNCTION__ . '(): ' . "Failed to parse feed uri: {$uri}", E_USER_NOTICE);
         header('Content-Type: text/plain; charset=utf-8');
         echo 'false';
         return VIEW_NONE;
     }
     $name = $f->getTitle();
     $favicon = $f->getFavicon() ? $f->getFavicon() : SCRIPT_PATH . 'images/favicon.ico';
     $db =& DBUtils::connect(false);
     $db->query('BEGIN');
     // get feedId
     $feedId = $this->getFeedIdByUri($uri);
     if ($feedId === false) {
         // add feed
         $fields = array('uri' => $uri, 'link' => $f->getLink(), 'title' => $f->getTitle(), 'description' => $f->getDescription(), 'favicon' => $favicon, 'lastupdatedtime' => date("Y-m-d H:i:s"));
         $res = $db->autoExecute('feed', $fields, DB_AUTOQUERY_INSERT);
         if (DB::isError($res)) {
             $db->rollback();
             trigger_error(__CLASS__ . '::' . __FUNCTION__ . '(): ' . "Failed to insert. " . $res->toString(), E_USER_ERROR);
             header('Content-Type: text/plain; charset=utf-8');
             echo 'false';
             return VIEW_NONE;
         }
         // specific mysql
         $feedId = $db->getOne('SELECT LAST_INSERT_ID()');
     }
     // add member_to_feed
     $m2f_fields = array('member_id' => MemberUtils::get_id_by_account($member->account), 'feed_id' => $feedId);
     if (DBUtils::get('member_to_feed', $m2f_fields)) {
         echo "'already exists'";
         // already exists
         return VIEW_NONE;
     }
     $res = $db->autoExecute('member_to_feed', $m2f_fields, DB_AUTOQUERY_INSERT);
     if (DB::isError($res)) {
         $db->rollback();
         trigger_error(__CLASS__ . '::' . __FUNCTION__ . '(): ' . "Failed to insert m2f. " . $res->toString(), E_USER_WARNING);
         header('Content-Type: text/plain; charset=utf-8');
         echo 'false';
         return VIEW_NONE;
     }
     // add member_to_content_category_to_feed
     $m2cc2f_fields = array('member_id' => $member->id, 'content_category_id' => $cc_id, 'feed_id' => $feedId);
     $sql = "SELECT count(*)\n            FROM member_to_content_category_to_feed\n            WHERE member_id = ?\n            AND content_category_id = ?\n            AND feed_id = ? ";
     if ($db->getOne($sql, array_values($m2cc2f_fields)) == 0) {
         $res = $db->autoExecute('member_to_content_category_to_feed', $m2cc2f_fields, DB_AUTOQUERY_INSERT);
         if (DB::isError($res)) {
             $db->rollback();
             trigger_error(__CLASS__ . '::' . __FUNCTION__ . '(): ' . 'Failed to insert m2cc2f. ' . $res->toString(), E_USER_WARNING);
             header('Content-Type: text/plain; charset=utf-8');
             echo 'false';
             return VIEW_NONE;
         }
     }
     // try to crawl
     $crawler =& new Crawler();
     $crawl_result = $crawler->crawl($uri);
     if ($crawl_result === false) {
         $db->rollback();
         trigger_error("AddFeedAction::execute(): Failed to crawl: {$uri}", E_USER_NOTICE);
         header('Content-Type: text/plain; charset=utf-8');
         echo 'false';
         return VIEW_NONE;
     }
     $db->commit();
     if ($redirect) {
         Controller::redirect(SCRIPT_PATH . 'setting/feed');
     } else {
         header('Content-Type: text/plain; charset=utf-8');
         echo 'true';
     }
     return VIEW_NONE;
 }