Created
June 14, 2012 06:43
-
-
Save hpbuniat/2928453 to your computer and use it in GitHub Desktop.
Read the latest modification date of a number of tracs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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