Skip to content

Instantly share code, notes, and snippets.

@hpbuniat
Created June 14, 2012 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hpbuniat/2928453 to your computer and use it in GitHub Desktop.
Save hpbuniat/2928453 to your computer and use it in GitHub Desktop.
Read the latest modification date of a number of tracs
<?php
/**
* Read the latest modification date of a number of tracs
*/
class tracTest {
/**
* The http-client to use (w/ auth)
*
* @var Zend_Http_Client
*/
protected $_oHttp = null;
/**
* The list of tracs
*
* @var array
*/
protected $_aTracs = array();
/**
* The result
*
* @var array
*/
protected $_aResult = array();
/**
* The max age
*
* @var int
*/
const DAYS = 120;
/**
* Create the object
*
* @param Zend_Http_Client $oHttp
*/
public function __construct(Zend_Http_Client $oHttp) {
$this->_oHttp = $oHttp;
Zend_Feed::setHttpClient($oHttp);
}
/**
* Get the list of tracs
*
* @param string $sUrl
*
* @return tracTest
*/
public function getTracs($sUrl) {
$oResponse = $this->_oHttp->setUri($sUrl)->request('GET');
$sBody = $oResponse->getBody();
$oRead = new Zend_Dom_Query($sBody);
$this->_aTracs = array();
foreach ($oRead->query('a.large') as $oResult) {
$this->_aTracs[] = trim($sUrl, '/') . $oResult->getAttribute('href');
}
return $this;
}
/**
* Read the timelines
*
* @return tracTest
*/
public function getTimelines() {
foreach ($this->_aTracs as $sTrac) {
$sUrl = sprintf('%s/timeline?wiki=on&max=10&authors=&daysback=%d&format=rss', $sTrac, self::DAYS);
$sResult = self::DAYS + 1;
try {
$oRss = new Zend_Feed_Rss($sUrl);
foreach ($oRss as $oEntry) {
$sResult = floor((time() - strtotime($oEntry->pubDate())) / 86400);
}
}
catch (Exception $e) {
$sResult = $e->getMessage();
}
$this->_aResult[$sTrac] = $sResult;
}
return $this;
}
/**
* Get the result
*
* @return array
*/
public function get() {
arsort($this->_aResult);
return $this->_aResult;
}
}
$aOpts = getopt('u:l:p:');
if (empty($aOpts['u']) === true or empty($aOpts['l']) === true or empty($aOpts['p']) === true) {
print_r('usage: ' . $argv[0] . ' -u url -l login -p password' . PHP_EOL);
exit;
}
$oHttp = new Zend_Http_Client();
$oHttp->setAuth($aOpts['l'], $aOpts['p']);
$o = new tracTest($oHttp);
$aResult = $o->getTracs($aOpts['u'])->getTimelines()->get();
print_r($aResult);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment