Skip to content

Commit

Permalink
add pubsubhubfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
chregu committed May 11, 2010
1 parent 0c49b41 commit e20addb
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
46 changes: 46 additions & 0 deletions callback.php
@@ -0,0 +1,46 @@
<?php




$_SERVER['HTTP_HOST'] = 'v1.chregu.tv';


define("R2T_PROJECT_DIR",dirname(__FILE__));
ini_set("include_path",R2T_PROJECT_DIR."/inc/:/var/www/zf-trunk/:".ini_get("include_path"));



require_once( "Zend/Feed/Pubsubhubbub/Storage/Filesystem.php");

$storage = new Zend_Feed_Pubsubhubbub_Storage_Filesystem;
$storage->setDirectory(R2T_PROJECT_DIR."/tmp");

require_once( "Zend/Feed/Pubsubhubbub/Subscriber/Callback.php");

$callback = new Zend_Feed_Pubsubhubbub_Subscriber_Callback;
$callback->setStorage($storage);

$token = substr($_SERVER['PATH_INFO'],1);


$callback->setSubscriptionKey($token);

$callback->handle();

if ($callback->hasFeedUpdate() || isset($_GET['doit']) ) {
$data = $callback->getFeedUpdate();

$key = md5($data);
file_put_contents(R2T_PROJECT_DIR . '/tmp/updates/' . $key, $data);
$command = "/usr/bin/php /home/chregu/rss2twi.php/rss2twitter.php";
$pcommand = $command . ' > /dev/null &';
pclose(popen($pcommand, 'r'));
/* $this->_helper->getHelper('Spawn')
->setScriptPath(APPLICATION_ROOT . '/scripts/zfrun.php');
$this->_helper->spawn(
array('--key'=>$key), 'process', 'callback'
);*/
}

$callback->sendResponse();
54 changes: 54 additions & 0 deletions subscribe.php
@@ -0,0 +1,54 @@
<?php
$_SERVER['HTTP_HOST'] = 'v1.chregu.tv';


define("R2T_PROJECT_DIR",dirname(__FILE__));
ini_set("include_path",R2T_PROJECT_DIR."/inc/:/var/www/zf-trunk/:".ini_get("include_path"));

require_once 'Zend/Feed/Reader.php';


//$topic = 'http://chregu.tv/blog/atom.xml';
$topic = 'http://www.planet-php.net/atom/';
$feed = Zend_Feed_Reader::import($topic);

$feedTopicUri = $feed->getFeedLink();

/**
* The feed may advertise one or more Hub Endpoints we can use.
* We may subscribe to the Topic using one or more of the Hub
* Endpoints advertised (good idea in case a Hub goes down).
*/
$feedHubs = $feed->getHubs();

/**
* Carry out subscription operation...
*/

require_once( "Zend/Feed/Pubsubhubbub/Storage/Filesystem.php");
$storage = new Zend_Feed_Pubsubhubbub_Storage_Filesystem;
$storage->setDirectory(R2T_PROJECT_DIR."/tmp");
$options = array(
'topicUrl' => $feedTopicUri,
'hubUrls' => $feedHubs,
'storage' => $storage,
'callbackUrl' => 'http://'.$_SERVER['HTTP_HOST'].'/rss2twi/callback.php',
'usePathParameter' => true,
'authentications' => array(
)
);
require_once( "Zend/Feed/Pubsubhubbub/Subscriber.php");

$subscriber = new Zend_Feed_Pubsubhubbub_Subscriber($options);
$subscriber->subscribeAll();
/**
* Do some checking for errors...
*/
if (!$subscriber->isSuccess()) {
var_dump($subscriber->getErrors()); exit;
print "<br/>ERROR";
} else {

error_log("SEEMS TO BE OK");
}

0 comments on commit e20addb

Please sign in to comment.