rendered paste body<?phpfunction nospam($mail) { $mail = preg_replace("/\@/", " at ", $mail); $mail = preg_replace("/\./", " dot ", $mail); return htmlspecialchars($mail);}class PortDb{ private $db; protected $last_result; function __construct($dbhandle) { try { $this->db = new SQLiteDatabase($dbhandle); } catch (Exception $exception) { die($exception->getMessage()); } } private function lazy_programmer() { die("LAZY PROGRAMMER ERROR"); } protected function getQuery($query) { $res = $this->db->query($query, SQLITE_ASSOC, $query_error); if ($query_error) { die("ERROR: $query_error"); } $this->last_result = $res->fetchAll(SQLITE_ASSOC); return $this->last_result; } public function doQuery() { $this->lazy_programmer(); } protected function htmlHeader() { return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>CRUX port browser</title> <link rel="stylesheet" type="text/css" href="portdb.css"/> </head> <body> <div class="cruxheader"> <a href="/" title="">Home</a> :: <a href="/Main/Documentation">Documentation</a> :: <a href="/Main/Download">Download</a> :: <a href="/Main/Development">Development</a> :: <a href="/Main/Community">Community</a> :: <a href="/Public/HomePage">Public</a> :: <a href="/portdb">Ports</a> :: <a href="/Main/Bugs" title="">Bugs</a> :: <a href="/Main/Links" title="">Links</a> :: <a href="/Main/About" title="">About</a> </div> <div class="content"> <b>Sections: </b><a href="?a=index">Repositories</a> :: <a href="?a=search">Search</a> :: <a href="?a=register">Register</a> :: <a href="?a=dups">Duplicates</a>'; } protected function htmlFooter() { return '</div><div class="footer"><b>DISCLAIMER</b>: the ports not belonging to the core and opt collections are provided by contributors; there is no guarantee or support by the CRUX team.</div></body></html>'; } protected function toHTML() { die($this->lazy_programmer()); } public function toXML() { header("Content-type: text/xml"); echo '<?xml version="1.0" encoding="UTF-8"?>'; }}class RepoList extends PortDb { public function doQuery() { $sql = 'select collname,maintainer,colltype,url,count(*) as tot from collections join ports on collection=collname group by collname order by collections.collid'; return $this->getQuery($sql); } public function toXML($res) { PortDb::toXML($res); $xml = "\n<result>\n"; foreach ($res as $repo) { $xml .= "\t<repo>\n"; $xml .= "\t\t<name>" . $repo["collname"] . "</name>\n"; $xml .= "\t\t<maintainer>" . nospam($repo["maintainer"]) . "</maintainer>\n"; $xml .= "\t\t<type>" . $repo["colltype"] . "</type>\n"; $xml .= "\t\t<url>" . $repo["url"] . "</url>\n"; $xml .= "\t\t<ports>" . $repo["tot"] . "</ports>\n"; $xml .= "\t</repo>\n"; } $xml .= "</result>"; return $xml; } public function toHTML($res) { $html = PortDb::htmlHeader(); $html .= "<h2>Overview of available repositories</h2>\n"; $html .= "<table class=\"listing\">\n"; $html .= "<thead><tr><th>Repo Name</th><th># ports</th><th>Type</th><th>Maintainer</th><th>Repo URL</th></tr></thead>\n"; $i = 0; foreach ($res as $repo) { if ($repo["colltype"] == "httpup") { $url = '<a href="' . $repo["url"] . '">' . $repo["url"] . '</a>'; } else { $url = $repo["url"]; } $html .= '<tr class="row' . $i%2 . '">'; $html .= '<td><a href="?a=repo&q=' . $repo["collname"] . '">' . $repo["collname"] . "</a></td>"; $html .= "<td>" . $repo["tot"] . "</td>"; $html .= '<td><a href="?a=getup&q=' . $repo["collname"] . '">' . $repo["colltype"] . '</a>' . "</td>"; $html .= "<td>" . nospam($repo["maintainer"]) . "</td><td>" . $url . "</td></tr>\n"; $i++; } $html .= "</table>\n"; $html .= PortDb::htmlFooter(); return $html; }}class PortsList extends PortDb{ public function doQuery($repo) { $sql = "select * from ports join collections on collection=collname where collection = ? order by portname"; return $this->getQuery($sql$dsn = "/home/lucas/dev/portdb/portdb.db";$portdb = new RepoList($dsn);$res = $portdb->doQuery();//print_r($res[0]);echo $portdb->toHTML($res);?>