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; } } ?>