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
93
94
95
96
97
98
99
100
|
<?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, $trim=null) {
$r=array();
foreach (explode("\n", $this->data) as $line) {
if (!strlen($line)) continue;
list($name, $val)=explode(': ', $line, 2);
$name=strtolower($name);
if (!$skip_masked && $name == 'keywords')
$r['masked']=$this->is_masked($val);
if (!isset($trim) || in_array($name, $trim))
$r[$name]=$val;
}
return $r;
}
function is_masked($keywords=null) {
if ($keywords === null) {
$array=$this->to_array(true);
$keywords=$array['keywords'];
}
$heads=$this->get_profile()->get_headers();
return !count(array_intersect(explode(' ', $keywords), explode(' ', $heads['accept_keywords'])));
}
public static function from_atom($atom, &$profile=null, $nomasked=true) {
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='';
$name=$atom;
}
$c=array();
if ($profile) $c[]='`profile`='.$profile->id;
if ($bcat) {
$c[]='`bcat`="'.$bcat.'"';
$c[]='`lcat`="'.$lcat.'"';
}
if ($name != '*') $c[]='`name`="'.$name.'"';
$c=implode(' AND ', $c);
$r=query('SELECT * FROM `gentoo_packages` WHERE '.$c);
while ($pkg=$r->fetch(PDO::FETCH_ASSOC)) {
$pkg=new sql_gentoo_package($pkg);
if (!$pkg->is_masked())
return $pkg;
}
return null;
}
}
?>
|