summaryrefslogtreecommitdiff
blob: 7b3ced6049ae292c41d6dab2fa50117bc10d01a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?

	class PortageCategory extends PortageTree {
	
		private $name;
		protected $dir;
		protected $cache_dir;
		private $metadata;
		private $description;
	
		function __construct($str = null) {
		
			parent::__construct();
		
			if($str)
				$this->setCategory($str);
		
		}
		
		public function __get($var) {
			return $this->$var;
		}
		
		public function __toString() {
			return $this->name;
		}
		
		protected function setCategory($str) {
		
			$str = basename($str);
			$dir = $this->getTree()."/".$str;
			$this->cache_dir = $this->getTree()."/metadata/cache/".$str;
			$this->metadata = $dir."/metadata.xml";
		
			if(is_dir($dir)) {
				$this->name = $str;
				$this->dir = $dir;
				
				$scandir = scandir($this->dir);
 				$scandir = preg_grep('/^\.{1,2}$/', $scandir, PREG_GREP_INVERT);
 				
 				foreach($scandir as $name)
 					if(is_dir($this->dir."/".$name))
 						$arr[] = $name;
 				
 				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;
		}
		
	}
?>