From 448afde0d8c049b93f6f4e87dc9392a6bfdde409 Mon Sep 17 00:00:00 2001 From: Marcin Juszkiewicz Date: Thu, 24 Aug 2006 10:00:33 +0000 Subject: feed-browser: starting version of web browser for feeds (GPLv2 license) - show packages list - show sections list - show package information - allow to download package --- contrib/feed-browser/index.php | 540 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 540 insertions(+) create mode 100644 contrib/feed-browser/index.php (limited to 'contrib/feed-browser/index.php') diff --git a/contrib/feed-browser/index.php b/contrib/feed-browser/index.php new file mode 100644 index 0000000000..7921a42260 --- /dev/null +++ b/contrib/feed-browser/index.php @@ -0,0 +1,540 @@ + + + +Feed browser + + + + + +
+ + +
+ + +"; + $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 ); + } + } + + $ipkgoutput .= " z"; + + if(isset($searchletter)) + { + $ipkgoutput .= searchpkg("$searchletter%"); + } + + return $ipkgoutput; +} + +function searchpkg ($searchword) +{ + $result = db_query("SELECT DISTINCT p_name,p_desc,p_section FROM packages WHERE p_name LIKE '$searchword' ORDER BY p_name ASC;"); + + $ipkgoutput = "\n"; + $ipkgoutput .="\n"; + + foreach($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 + ("\n", + urlencode($package['p_name']), $package['p_name'], $package['p_section'], $package['p_section'], $package['p_desc']); + } + + } + + $ipkgoutput .= '
PackageSectionDescription
%s%s %s
'; + + return $ipkgoutput; +} + +function searchsection($section) +{ + $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;"); + + $ipkgoutput = "\n"; + $ipkgoutput .="\n"; + + foreach($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 ("", + urlencode($package['p_name']), + $package['p_name'], + $package['p_section'], $package['p_section'], + $package['p_desc']); + }//if strstr + } + + $ipkgoutput .= "
PackageSectionDescription
%s%s%s
\n"; + + return $ipkgoutput; +} + +function pkgdetails ($package) +{ + $result = db_query("SELECT * FROM packages,feeds WHERE packages.p_name='$package' AND feeds.f_name = packages.p_feed"); + + // 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

", $package['packages.p_desc']); + $details .= ""; + + $details .= sprintf ("\n", htmlentities(str_replace('@', ' at ', $package['packages.p_maintainer']))); + + if($package['packages.p_homepage']) + { + $details .= sprintf ("\n", $package['packages.p_homepage']); + } + + if($package['packages.p_section']) + { + $details .= sprintf ("\n", $package['packages.p_section'],$package['packages.p_section']); + } + + if($package['packages.p_depends']) + { + $details .= sprintf ("\n", addlinks ($package['packages.p_depends'])); + } + + if($package['packages.p_recommends']) + { + $details .= sprintf ("\n", addlinks ($package['packages.p_recommends'])); + } + + if($package['packages.p_replaces']) + { + $details .= sprintf ("\n", addlinks ($package['packages.p_replaces'])); + } + + if($package['packages.p_provides']) + { + $details .= sprintf ("\n", addlinks ($package['packages.p_provides'])); + } + + if($package['packages.p_conflicts']) + { + $details .= sprintf ("\n", 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
Maintainer:%s
Homepage:%s
Section:%s
Depends:%s
Recommends:%s
Replaces:%s
Provides:%s
Conflicts:%s
Size:%s
", $size); + + if($package['packages.p_source']) + { + $sourcearray = explode (" ", $package['packages.p_source']); + + $details .= "\n

Source:

'; + + } + + $details .= "\n

Available versions and architectures:

\n"; + } + else + { + $details = "

Sorry, package not found\n

return\n"; + } + + return $details; +} + +function addlinks ($input) +{ + // split input elements up + $elements = preg_split ('/[\s,]+/', $input); + + $offset = 0; + + foreach ($elements as $element) + { + // skip version information and empty elements (shouldn't happend) + if (!eregi('^([0-9a-z\-]*)$', $element) OR empty($element)) + { + continue; + } + + // do we have this package in the db? + $result = db_query ("SELECT DISTINCT p_name FROM packages WHERE p_name='{$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"; + } + + return $ipkgoutput; +} + +?> -- cgit v1.2.3