All pastes #1080600 Raw Edit

Mine

public php v1 · immutable
#1080600 ·published 2008-07-23 10:19 UTC
rendered paste body
<?php$dbhandle = "sqlite:/home/lucas/Projects/crux/portdb/portdb-new.db";function 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 PDO($dbhandle);    }    catch (Exception $exception) {      die($exception->getMessage());    }  }  private function lazy_programmer() {    die("LAZY PROGRAMMER ERROR");  }  protected function getQuery($query) {    try {      $res = $this->db->query($query);    }    catch (Exception $exception) {      die($exception->getMessage());    }    $this->last_result = $res->fetchAll();    return $this->last_result;  }  public function doQuery() {    $this->lazy_programmer();  }  protected function htmlHeader() {    return file_get_contents("header.html");  }  protected function htmlFooter() {    return file_get_contents("footer.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) {      $name =& $repo["collname"];      $count =& $repo["tot"];      $type =& $repo["colltype"];      $maintainer =& nospam($repo["maintainer"]);      if ($type == "httpup") {	$url = '<a href="' . $repo["url"] . '">' . $repo["url"] . '</a>';      }      else {	$url =& $repo["url"];      }      $row = $i%2;      $html .= "<tr class=\"row$row\">                  <td><a href=\"?a=repo&q=$name\">$name</a></td>                  <td>$count</td>                  <td><a href=\"?a=getup&q=$name\">$type</a></td>                  <td>$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);  }}$portdb = new RepoList($dbhandle);$res = $portdb->doQuery();//print_r($res[0]);echo $portdb->toHTML($res);?>