summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--class.portage.package.changelog.php105
1 files changed, 99 insertions, 6 deletions
diff --git a/class.portage.package.changelog.php b/class.portage.package.changelog.php
index a013c64..bad7dd9 100644
--- a/class.portage.package.changelog.php
+++ b/class.portage.package.changelog.php
@@ -3,18 +3,111 @@
class PackageChangelog {
private $recent_changes;
- public $recent_date;
+ private $recent_date;
- function __construct($str, $date = null) {
+ private $package;
+ private $category;
+ private $tree;
+ private $dir;
+ private $filename;
+ private $mtime;
+
+ private $changelog;
+ private $hash;
+ private $filesize;
+
+ public function __construct($category = null, $package = null, $tree = "/usr/portage") {
global $hits;
$hits['changelog']++;
+
+ if($category && $package && $tree)
+ $this->setPackage($category, $package, $tree);
+
+ }
+
+ public function __toString() {
+ return $this->getChangelog();
+ }
+
+ public function __get($var) {
+
+ switch($var) {
+
+ case 'package':
+ case 'category':
+ case 'tree':
+ case 'dir':
+ case 'filename':
+ case 'recent_date':
+ return $this->$var;
+ break;
+
+ case 'mtime':
+ return $this->getMtime();
+ break;
+
+ case 'changelog':
+ return $this->getChangelog();
+ break;
+
+ case 'hash':
+ return $this->getHash();
+ break;
+
+ case 'filesize':
+ return $this->getFilesize();
+ break;
+
+ case 'recent_changes':
+ return $this->getRecentChanges();
+ break;
+
+ }
+
+ }
+
+ private function setPackage($category, $package, $tree) {
+
+ $category = basename($category);
+ $package = basename($package);
+
+ $this->dir = "$tree/$category/$package";
+
+ if(is_dir($this->dir)) {
+ $this->package = $package;
+ $this->category = $category;
+ $this->tree = $tree;
+ }
+
+ if(file_exists($this->dir."/ChangeLog")) {
+ $this->filename = $this->dir."/ChangeLog";
+ }
- $this->changelog = $str;
+ }
+
+ public function getChangelog() {
+ if(!$this->changelog && $this->filename)
+ $this->changelog = file_get_contents($this->filename);
+ return $this->changelog;
+ }
- if(!is_null($date))
- $this->date = $date;
+ public function getFilesize() {
+ if(is_null($this->filesize) && $this->filename)
+ $this->filesize = filesize($this->filename);
+ return $this->filesize;
+ }
+
+ public function getHash() {
+ if(!$this->hash && $this->filename)
+ $this->hash = sha1($this->getChangelog());
+ return $this->hash;
+ }
+ public function getMtime() {
+ if(!$this->mtime && $this->filename)
+ $this->mtime = filemtime($this->filename);
+ return $this->mtime;
}
@@ -23,7 +116,7 @@
$pattern_date = "/^\d{1,2}\s\w{3}\s\d{4}/";
// $pattern_dev = "/<\w+@gentoo\.org>/";
- $arr = explode("\n", $this->changelog);
+ $arr = explode("\n", $this->getChangelog());
// print_r($arr);
// Cut off the header