";
$alfabet = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y');
foreach($alfabet as $letter)
{
if($letter == $searchletter)
{
$ipkgoutput .= sprintf(" %s |", $letter );
}
else
{
$ipkgoutput .= sprintf(" %s |", $letter, $letter, $letter );
}
}
$ipkgoutput .= " z";
return $ipkgoutput;
}
function searchpkg ($searchword)
{
if($result = db_query("SELECT DISTINCT p_name,p_desc,p_section FROM packages WHERE p_name LIKE '$searchword' ORDER BY p_name ASC"))
{
return generate_list_of_packages($result);
}
}
function generate_list_of_packages($query_result)
{
$ipkgoutput = "
\n";
$ipkgoutput .="Package | Section | Description |
\n";
foreach($query_result as $package)
{
if (!strstr ($package['p_name'], 'locale'))
{
if(strlen($package['p_desc']) > 40)
{
$pos = strpos($package['p_desc'],' ', 40);
if($pos)
{
$package['p_desc'] = substr($package['p_desc'], 0, $pos) . '...';
}
}
$ipkgoutput .= sprintf
("%s | %s | %s |
\n",
urlencode($package['p_name']), $package['p_name'], $package['p_section'], $package['p_section'], htmlentities($package['p_desc']));
}
}
$ipkgoutput .= '
';
return $ipkgoutput;
}
function searchsection($section)
{
if($result = db_query("SELECT DISTINCT p_name,p_desc,p_section FROM packages WHERE p_section LIKE '$section%' ORDER BY p_section ASC, p_name ASC"))
{
return generate_list_of_packages($result);
}
}
function pkgdetails ($package)
{
$result = db_query("SELECT * FROM packages,feeds
WHERE (packages.p_name='$package' OR packages.p_provides='$package')
AND feeds.f_name = packages.p_feed
ORDER BY packages.p_version DESC, feeds.f_name ASC, packages.p_arch DESC ");
// display first result
if ($result)
{
$package = $result[0];
$details = sprintf("Package details for %s %s
", $package['packages.p_name'], $package['packages.p_version']);
$details .= sprintf ("%s
", htmlentities($package['packages.p_desc']));
$details .= "";
$details .= sprintf ("\n- Maintainer:
- %s
", str_replace(array('@',', '), array(' at ', '
'), htmlentities($package['packages.p_maintainer'])));
if($package['packages.p_homepage'])
{
$details .= sprintf ("\n- Homepage:
- %s
", $package['packages.p_homepage']);
}
if($package['packages.p_section'])
{
$details .= sprintf ("\n- Section:
- %s
", $package['packages.p_section'],$package['packages.p_section']);
}
if($package['packages.p_depends'])
{
$details .= sprintf ("\n- Depends:
- %s
", addlinks ($package['packages.p_depends']));
}
if($package['packages.p_recommends'])
{
$details .= sprintf ("\n- Recommends:
- %s
", addlinks ($package['packages.p_recommends']));
}
if($package['packages.p_replaces'])
{
$details .= sprintf ("\n- Replaces:
- %s
", addlinks ($package['packages.p_replaces']));
}
if($package['packages.p_provides'])
{
$details .= sprintf ("\n- Provides:
- %s
", addlinks ($package['packages.p_provides']));
}
if($package['packages.p_conflicts'])
{
$details .= sprintf ("\n- Conflicts:
- %s
", addlinks ($package['packages.p_conflicts']));
}
$size = $package['packages.p_size'];
if(strlen($size) > 6)
{
$size = sprintf("%02.2f Megabytes", $size / (1024 * 1024));
}
if(strlen($size) > 3 && strlen($size) < 7)
{
$size = sprintf("%02.2f Kilobytes", $size / (1024 ));
}
if(strlen($size) < 4)
{
$size = sprintf("%s Bytes", $size);
}
$details .= sprintf ("\n- Size:
- %s
", $size);
if($package['packages.p_source'])
{
$sourcearray = explode (" ", $package['packages.p_source']);
$details .= "\nSource:
";
foreach ($sourcearray as $key => $source_url)
{
if (substr ($source_url, 0, 4) == "http" || substr ($source_url, 0, 3) == "ftp")
{
$url_parts = parse_url($source_url);
$details .= sprintf ("- %s
", $source_url, array_pop(explode('/', $url_parts['path'])));
}
else
{
$details .= sprintf ("- %s
", $source_url);
}
}
$details .= '
';
}
$details .= "\nAvailable versions and architectures:
\n";
foreach($result as $packages_a)
{
$details .= sprintf("\n- %s %s for %s (%s feed)
\n",
$packages_a['feeds.f_uri']."/".$packages_a['packages.p_file'],
$packages_a['packages.p_name'],
$packages_a['packages.p_version'],
$packages_a['packages.p_arch'],
$packages_a['packages.p_name'],
$packages_a['packages.p_version'],
$packages_a['packages.p_arch'],
$packages_a['feeds.f_name']
);
}
$details .= "
\n";
}
else
{
$details = "Sorry, package not found\n
return\n";
}
return $details;
}
function addlinks ($input)
{
// split input elements up
$elements = explode (', ', $input);
$offset = 0;
foreach ($elements as $element)
{
// strip version number
$element = ereg_replace('^(.*)( \((.*)\))+$', '\\1', $element);
// do we have this package in the db?
$result = db_query ("SELECT DISTINCT p_name FROM packages WHERE p_name='{$element}' OR p_provides='{$element}'");
if(isset($result[0]['p_name']))
{
// find position of string in line
$pos = strpos ($input, $element, $offset);
$link = sprintf("$element", urlencode ($element));
// replace element with a link
$input = substr_replace ($input, $link, $pos, strlen ($element));
// update offset
$offset = ($pos + strlen ($link));
}
else
{
$offset += strlen ($element);
}
}
return $input;
}
function sectionslist()
{
$ipkgoutput = '';
if($result = db_query ("SELECT DISTINCT p_section FROM packages ORDER BY p_section"))
{
$ipkgoutput = "\n";
$section_up = $result[0]['p_section'];
$section_level = FALSE;
$opie_top = FALSE;
foreach($result as $item)
{
$section_name = $item['p_section'];
if(0 === strpos($section_name, 'opie') AND !$opie_top)
{
$opie_top = TRUE;
$section_up = 'opie';
}
elseif($opie_top AND 0 !== strpos($section_name, 'opie'))
{
$opie_top = FALSE;
}
if(
strpos($section_name, '/') // subsection
)
{
if(0 === strpos($section_name, $section_up . '/')) // console/network are not part of console/net
{
if(!$section_level)
{
$ipkgoutput .= '';
}
$section_name = str_replace($section_up . '/', '', $item['p_section']);
$section_level = TRUE;
}
}
elseif($section_level)
{
$section_up = $section_name;
$ipkgoutput .= '
';
$section_level = FALSE;
}
else
{
$section_up = $section_name;
}
$ipkgoutput .= sprintf ("- %s
",
urlencode($item['p_section']),
urlencode($item['p_section']),
$section_name);
}
if($section_level)
{
$ipkgoutput .= '
';
}
$ipkgoutput .= "\n";
}
return $ipkgoutput;
}
function check_database()
{
if($db = sqlite_open(DB_FILENAME))
{
//initialize db
if (db_table_exists ($db, 'packages') === FALSE)
{
sqlite_query ($db, "CREATE TABLE packages (
p_name varchar(50),
p_version varchar(10),
p_arch varchar(12),
p_depends varchar(50),
p_maintainer varchar(50),
p_homepage varchar(100),
p_section varchar(20),
p_replaces varchar(50),
p_provides varchar(50),
p_recommends varchar(50),
p_conflicts varchar(50),
p_size int(10),
p_md5 char(32),
p_source varchar(500),
p_feed varchar(20),
p_file varchar(100),
p_desc varchar(1000))");
}
if (db_table_exists ($db, 'feeds') === FALSE)
{
sqlite_query ($db, "CREATE TABLE feeds (
f_name varchar(20),
f_uri varchar(100),
f_comments varchar(500))");
test_insert_ipkgs ($db) ;
}
sqlite_close($db);
}
}
?>