summaryrefslogtreecommitdiff
blob: 41fec018e524e5c6df3371f48c79601e829bd3a8 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
class sql_gentoo_package extends sql_row_obj {
	protected $table='gentoo_packages', $primary_key=array('id'), $columns=array(
		'id' => array (
			'type' => 'INT',
			'length' => 10,
			'unsigned' => true,
			'not_null' => true,
			'auto_increment' => true
		),
		'profile' => array (
			'type' => 'TINYINT',
			'length' => 3,
			'unsigned' => true,
			'not_null' => true,
			'default' => 0,
			'refers_to' => 'gentoo_profiles.id'
		),
		'bcat' => array (
			'type' => 'VARCHAR',
			'length' => 255,
			'not_null' => true,
			'default' => ''
		),
		'lcat' => array (
			'type' => 'VARCHAR',
			'length' => 255,
			'not_null' => true,
			'default' => ''
		),
		'name' => array (
			'type' => 'VARCHAR',
			'length' => 255,
			'not_null' => true,
			'default' => ''
		),
		'version' => array (
			'type' => 'VARCHAR',
			'length' => 255,
			'not_null' => true,
			'default' => ''
		),
		'data' => array (
			'type' => 'TEXT',
			'not_null' => true
		)

	);
	function &to_array($skip_masked=false) {
		$r=array();
		foreach (explode("\n", $this->data) as $line) {
			if (!strlen($line)) continue;
			list($name, $val)=explode(': ', $line, 2);
			$name=strtolower($name);
			$r[$name]=$val;
		}
		if (!$skip_masked) {
			$r['masked']=$this->is_masked($r);
		}
		return $r;
	}
	function is_masked(&$array=null) {
		if ($array === null) {
			$array=$this->to_array(true);
		}
		$heads=$this->get_profile()->get_headers();
		return !count(array_intersect(explode(' ', $array['keywords']), explode(' ', $heads['accept_keywords'])));
	}
	public static function from_atom($atom, &$profile=null) {
		global $S;
		if (strlen($atom) == 0) return null;
		if (strpos($atom, '/')) {
			list($bcat, $name)=explode('/', $atom);
			if ($i=strpos($bcat, '-')) {
				$lcat=substr($bcat, $i);
				$bcat=substr($bcat, 0, strlen($bcat)-strlen($lcat));
			}
		} else {
			$bcat=$lcat=null;
			$name=$atom;
		}
		$c=array();
		if ($profile) $c[]='`profile`='.$profile->id;
		if ($bcat) $c[]='`bcat`="'.$bcat.'"';
		if ($lcat) $c[]='`lcat`="'.$lcat.'"';
		if ($name) $c[]='`name`="'.$name.'"';
		$c=implode(' AND ', $c);
		$r=$S['pdo']->query('SELECT * FROM `gentoo_packages` WHERE '.$c.' LIMIT 1');
		return $r->rowCount()?new sql_gentoo_package($r->fetch(PDO::FETCH_ASSOC)):null;
	}
}
?>