diff options
-rw-r--r-- | class.portage.category.php | 62 |
1 files changed, 37 insertions, 25 deletions
diff --git a/class.portage.category.php b/class.portage.category.php index b4f8a96..5f53c04 100644 --- a/class.portage.category.php +++ b/class.portage.category.php @@ -7,14 +7,15 @@ protected $cache_dir; private $metadata; private $description; - - function __construct($str = null) { + + private $arr_packages; + + function __construct($category) { global $hits; $hits['category']++; - if($str) - $this->setCategory($str); + $this->setCategory($category, $tree = "/usr/portage"); } @@ -26,19 +27,42 @@ return $this->name; } - protected function setCategory($str) { + protected function setCategory($category, $tree) { - $tree =& PortageTree::singleton(); - - $str = basename($str); - $dir = $tree->getTree()."/".$str; - $this->cache_dir = $tree->getTree()."/metadata/cache/".$str; - $this->metadata = $dir."/metadata.xml"; + $category = basename($category); + $dir = "$tree/$category"; if(is_dir($dir)) { - $this->name = $str; + $this->name = $category; $this->dir = $dir; - + $this->cache_dir = "$tree/metadata/cache/$category"; + $this->metadata = "$dir/metadata.xml"; + } + + } + + public function getDescriptions() { + + if(!$this->description) { + // Get metadata + $xml = simplexml_load_file($this->metadata); + foreach($xml->longdescription as $obj) { + $str = trim(preg_replace('/\s+/', ' ', (string)$obj)); + $lang = (string)$obj['lang']; + $this->description[$lang] = $str; + } + } + + return $this->description; + } + + public function getLanguages() { + return array_keys($this->description); + } + + public function getPackages() { + + if(!$this->arr_packages) { $scandir = scandir($this->dir); $scandir = preg_grep('/^\.{1,2}$/', $scandir, PREG_GREP_INVERT); @@ -49,20 +73,8 @@ sort($arr); $this->arr_packages = $arr; - - // Get metadata - $xml = simplexml_load_file($this->metadata); - foreach($xml->longdescription as $obj) { - $str = trim(preg_replace('/\s+/', ' ', (string)$obj)); - $lang = (string)$obj['lang']; - $this->description[$lang] = $str; - } - } - } - - public function getPackages() { return $this->arr_packages; } |