protected function _subscribe($topic) { try { $feed = Zend_Feed_Reader::import($topic); } catch (Zend_Exception $e) { return false; } /** * Must use the URI of the feed contained in the feed itself in * case the original is no longer valid (e.g. feed moved and we just * followed a redirect to the new URI) */ $feedTopicUri = $feed->getFeedLink(); if (empty($feedTopicUri)) { $feedTopicUri = $topic; } /** * 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(); if (is_null($feedHubs) || empty($feedHubs)) { return false; } /** * Carry out subscription operation... */ $storage = new Zend_Feed_Pubsubhubbub_Storage_Filesystem(); $storage->setDirectory(APPLICATION_ROOT . '/store/subscriptions'); $options = array('topicUrl' => $feedTopicUri, 'hubUrls' => $feedHubs, 'storage' => $storage, 'callbackUrl' => 'http://hub.survivethedeepend.com/callback', 'usePathParameter' => true, 'authentications' => array('http://superfeedr.com/hubbub' => array('padraicb', 'password'))); $subscriber = new Zend_Feed_Pubsubhubbub_Subscriber($options); $subscriber->subscribeAll(); /** * Do some checking for errors... */ if (!$subscriber->isSuccess()) { var_dump($subscriber->getErrors()); exit; } return true; }
public function indexAction() { $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $storage = new Zend_Feed_Pubsubhubbub_Storage_Filesystem(); $storage->setDirectory(APPLICATION_ROOT . '/store/subscriptions'); $callback = new Zend_Feed_Pubsubhubbub_Subscriber_Callback(); $callback->setStorage($storage); /** * At time of writing, no fully PuSH 0.2 compatible Hubs exist * so we must detect the expected verify token (if used) and set * it explicitly. This is used by all callback requests and is set * when subscribing. */ $callback->setVerifyToken($this->_getParam('subkey')); $callback->handle(); /** * Check if a feed update was received and process it * asynchronously. Note: Asynchronous processing should be * utilised since a Hub might timeout very quickly if the * processing time exceeds its timeout setting (including * network latency). */ if ($callback->hasFeedUpdate()) { $data = $callback->getFeedUpdate(); $key = md5($data); file_put_contents(APPLICATION_ROOT . '/store/updates/' . $key, $data); $this->_helper->getHelper('Spawn')->setScriptPath(APPLICATION_ROOT . '/scripts/zfrun.php'); $this->_helper->spawn(array('--key' => $key), 'process', 'callback'); } file_put_contents(APPLICATION_ROOT . '/log/' . microtime(true), print_r($callback->getHttpResponse(), true)); /** * Send final response to Client */ $callback->sendResponse(); }
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"); }
<?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();