summaryrefslogtreecommitdiffstats
path: root/rpm.php
diff options
context:
space:
mode:
authorJohan "Papa" Cwiklinski <trasher@odysseus.(none)>2010-05-30 11:26:48 +0200
committerJohan "Papa" Cwiklinski <trasher@odysseus.(none)>2010-05-30 11:26:48 +0200
commit873662fe815c678f35ec1518d9fc013c993ae710 (patch)
tree337e5cd7aec92d841575b5d755393cd0aba85584 /rpm.php
parentc44eb057150670df61268a4c686eae274beb7352 (diff)
Use of smarty to render rpm page ; apply coding standards, add license ; refs #46,48,47
Diffstat (limited to 'rpm.php')
-rw-r--r--rpm.php490
1 files changed, 262 insertions, 228 deletions
diff --git a/rpm.php b/rpm.php
index edad029..6627b04 100644
--- a/rpm.php
+++ b/rpm.php
@@ -1,256 +1,290 @@
<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * RPMs listing
+ *
+ * PHP version 5
+ *
+ * Copyright © 2010 Remi Collet
+ *
+ * This file is part of rpmphp.
+ *
+ * rpmphp is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * rpmphp is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with rpmphp. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Main
+ * @package RPMPHP
+ *
+ * @author Remi Collet <unknown@unknwown.com>
+ * @author Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2010 Remi Collet
+ * @license http://www.gnu.org/licenses/agpl-3.0-standalone.html AGPL License 3.0 or (at your option) any later version
+ * @version SVN: $Id: ajouter_adherent.php 836 2010-02-27 08:11:44Z trashy $
+ * @link http://github.com/remicollet/rpmphp/
+ * @since The begining of times.
+*/
+require 'main.inc.php';
+
+$smarty->assign('ariane', $ariane);
+
$what=(isset($_GET["what"]) ? $_GET["what"] : "%fedora");
$type=(isset($_GET["type"]) ? $_GET["type"] : "pecl");
-require "config.inc.php";
+$ariane[] = array(
+ 'url' => '#',
+ 'text' => strtoupper($type). ' extensions in Fedora'
+);
+$smarty->assign('ariane', $ariane);
+
+$smarty->assign('type', $type);
+$smarty->assign('what', $what);
+$smarty->assign('page_title', strtoupper($type). ' extensions in Fedora');
-function listRepos($db){
- $repos = array();
- $res=$db->query("SELECT * FROM repo WHERE active=1 ORDER BY ID");
- if ($res) while ($repo = $res->fetchObject()) {
- $repos[$repo->main][$repo->sub]=$repo;
- }
- // echo "<pre>"; print_r($repos);echo "</pre>";
- foreach($repos as $repomain) {
- foreach ($repomain as $repo) {
- /*printf ("<th align='left'>%s</th>", $repo->main);*/
- $repos[$repo->main][$repo->sub] = $repo;
- break;
- }
- }
- return $repos;
+/**
+* Get repositories list
+*
+* @param object $db a reference to the database
+*
+* @return array
+*/
+function listRepos($db)
+{
+ $repos = array();
+ $res=$db->query("SELECT * FROM repo WHERE active=1 ORDER BY ID");
+ if ( $res ) {
+ while ($repo = $res->fetchObject()) {
+ $repos[$repo->main][$repo->sub]=$repo;
+ }
+ }
+ // echo "<pre>"; print_r($repos);echo "</pre>";
+ foreach ( $repos as $repomain ) {
+ foreach ($repomain as $repo) {
+ $repos[$repo->main][$repo->sub] = $repo;
+ break;
+ }
+ }
+ return $repos;
}
-function Report ($db, $type, $repos) {
- global $what;
+/**
+* Retrieve packages informations
+*
+* @param Object $db A reference to the database
+* @param string $type The current type
+*
+* @return array
+*/
+function report($db, $type)
+{
+ global $what, $smarty;
+ $packages = null;
+ $repos = listRepos($db);
+ $smarty->assign('repos', $repos);
- $i=0;
- $resup=$db->query("SELECT * FROM upstream WHERE type='$type' ORDER BY name");
- if ($resup) while ($upstream = $resup->fetchObject()) {
- $rpmname = $upstream->name;
+ $i=0;
+ $resup=$db->query("SELECT * FROM upstream WHERE type='$type' ORDER BY name");
+ if ($resup) {
+ while ($upstream = $resup->fetchObject()) {
+ $package = null;
+ $rpmname = $upstream->name;
- $sql2="SELECT DISTINCT owner FROM acls WHERE name = '$rpmname'";
- $res2=$db->query($sql2);
- $owners=array();
- if ($res2) while ($owner= $res2->fetchObject()) $owners[] = $owner->owner;
+ $sql2="SELECT DISTINCT owner FROM acls WHERE name = '$rpmname'";
+ $res2=$db->query($sql2);
+ $owners=array();
+ if ( $res2 ) {
+ while ($owner= $res2->fetchObject()) {
+ $owners[] = $owner->owner;
+ }
+ }
- $sql = "SELECT * FROM rpm WHERE name = '$rpmname'";
+ $sql = "SELECT * FROM rpm WHERE name = '$rpmname'";
- $res=$db->query($sql);
- $rpm = ($res ? $res->fetchObject() : false);
+ $res=$db->query($sql);
+ $rpm = ($res ? $res->fetchObject() : false);
- switch ($what) {
- case '%fedora':
- $display = ($rpm !== false);
- break;
- case '%stable':
- $display = !empty($upstream->stable);
- break;
- case '%all':
- $display = true;
- break;
- default: // owner
- $display = (array_search($what, $owners) !== false);
- break;
- }
+ switch ($what) {
+ case '%fedora':
+ $display = ($rpm !== false);
+ break;
+ case '%stable':
+ $display = !empty($upstream->stable);
+ break;
+ case '%all':
+ $display = true;
+ break;
+ default: // owner
+ $display = (array_search($what, $owners) !== false);
+ break;
+ }
- if ($display) {
- if ($rpm) {
- $dispname = "<a href=\"zoom.php?rpm=" . $rpmname . "\" title=\"" . htmlentities($rpm->summary) . "\">$rpmname</a>";
- } else {
- $dispname = $rpmname;
- }
- $rpms=array();
- if ($rpm) do {
- $rpms[$rpm->repo_main."-".$rpm->repo_sub]=$rpm;
- } while ($rpm = $res->fetchObject());
+ if ($display) {
+ if ($rpm) {
+ $package['name'] = '<a href="zoom.php?rpm=' . $rpmname .
+ '" title="' . htmlentities($rpm->summary) . '">' .
+ $rpmname . '</a>';
+ } else {
+ $package['name'] = $rpmname;
+ }
+ if ( $upstream->channel != $upstream->type ) {
+ $package['channel'] = $upstream->channel;
+ }
+ $rpms=array();
+ if ( $rpm ) {
+ do {
+ $rpms[$rpm->repo_main."-".$rpm->repo_sub]=$rpm;
+ } while ($rpm = $res->fetchObject());
+ }
- $dispowner="";
- foreach ($owners as $owner) {
- if ($dispowner) $dispowner .= "<br/>";
- $dispowner .= sprintf ("<a href=\"%s?type=$type&amp;what=%s\">%s</a>", $_SERVER["PHP_SELF"], $owner, $owner);
- }
- printf ("<tr class=\"%s\">\n\t<td>%s<br/><small>%s</small></td>\n\t<td>%s</td>\n\t<td>%s%s</td>\n",
- ($i%2 ? "odd" : "even"), $dispname,
- ($upstream->channel != $upstream->type ? "channel: " . $upstream->channel : ""),
- $dispowner,
- ($upstream->stable ? "<strong>".$upstream->stable."</strong><br />" : "&nbsp;"),
- ($upstream->unstable && (!$upstream->stable || $upstream->stable!=$upstream->unstable) ? $upstream->unstable." <small>(".$upstream->state.")</small>" : "&nbsp;"));
+ $dispowner="";
+ $package['owners'] = $owners;
+ if ( $upstream->stable ) {
+ $package['upstream_stable'] = $upstream->stable;
+ }
+ if ( $upstream->unstable
+ && (!$upstream->stable
+ || $upstream->stable!=$upstream->unstable)
+ ) {
+ $package['upstream_unstable'] = $upstream->unstable .
+ ' <small>(' . $upstream->state . ')</small>';
+ }
- $verup = strtolower($upstream->stable ? $upstream->stable : $upstream->unstable);
+ $verup = strtolower($upstream->stable ? $upstream->stable : $upstream->unstable);
- foreach($repos as $repomain) {
- $display="";
- $class="";
- foreach ($repomain as $repo) {
- if (isset($rpms[$repo->main."-".$repo->sub])) {
- $rpm=$rpms[$repo->main."-".$repo->sub];
+ $versions = null;
+ foreach ( $repos as $repomain ) {
+ $display="";
+ $class="";
+ foreach ( $repomain as $k=>$repo ) {
+ if ( isset($rpms[$repo->main."-".$repo->sub]) ) {
+ $rpm=$rpms[$repo->main."-".$repo->sub];
- $verpm=$rpm->ver;
- if (preg_match("/\.((beta|RC)\d*)\./i", $rpm->rel, $res)) {
- $verpm .= strtolower($res[1]);
- }
+ $verpm=$rpm->ver;
+ if (preg_match("/\.((beta|RC)\d*)\./i", $rpm->rel, $res)) {
+ $verpm .= strtolower($res[1]);
+ }
- switch ($repo->sub) {
- case "base":
- if (isset($rpms[$repo->main."-updates"])) {
- $display .= sprintf("%s-%s<br/>", $rpm->ver, $rpm->rel);
- } else {
- $display .= sprintf("<strong>%s</strong>-%s<br/>", $rpm->ver, $rpm->rel);
- }
- if ($verup==$verpm) $class="check";
- break;
- case "":
- $display .= sprintf("<strong>%s</strong>-%s<br/>", $rpm->ver, $rpm->rel);
- if ($verup==$verpm) $class="check";
- break;
- case "updates":
- $display .= sprintf("<strong>%s</strong>-%s <small>(updates)</small><br/>", $rpm->ver, $rpm->rel);
- if ($verup==$verpm) $class="check";
- break;
- case "testing":
- $display .= sprintf("%s-%s <small>(testing)</small><br/>", $rpm->ver, $rpm->rel);
- if ($verup==$verpm) $class="info";
- break;
- }
- } // RPM exists
- } // sub repo
- if ($display && empty($class)) $class="attn";
- if ($display) {
- printf("\t<td class=\"%s\">%s</td>\n", $class, $display);
- } else {
- echo "\t<td>&nbsp;</td>\n";
- }
- } // mainrepo
+ switch ($repo->sub) {
+ case "base":
+ if ( isset($rpms[$repo->main."-updates"]) ) {
+ $display .= sprintf(
+ "%s-%s<br/>",
+ $rpm->ver,
+ $rpm->rel
+ );
+ } else {
+ $display .= sprintf(
+ "<strong>%s</strong>-%s<br/>",
+ $rpm->ver,
+ $rpm->rel
+ );
+ }
+ if ( $verup==$verpm ) {
+ $class="check";
+ }
+ break;
+ case "":
+ $display .= sprintf(
+ "<strong>%s</strong>-%s<br/>",
+ $rpm->ver,
+ $rpm->rel
+ );
+ if ( $verup==$verpm ) {
+ $class="check";
+ }
+ break;
+ case "updates":
+ $display .= sprintf(
+ "<strong>%s</strong>-%s <small>(updates)</small><br/>",
+ $rpm->ver,
+ $rpm->rel
+ );
+ if ( $verup==$verpm ) {
+ $class="check";
+ }
+ break;
+ case "testing":
+ $display .= sprintf(
+ "%s-%s <small>(testing)</small><br/>",
+ $rpm->ver,
+ $rpm->rel
+ );
+ if ( $verup==$verpm ) {
+ $class="info";
+ }
+ break;
+ }
+ } // RPM exists
+ } // sub repo
+ if ( $display && empty($class) ) {
+ $class="attn";
+ }
+ $versions[] = array(
+ 'class' => $class,
+ 'display' => $display
+ );
+ $package['versions'] = $versions;
+ } // mainrepo
- echo "</tr>\n";
- $i++;
- }
- } // each $unstable
- echo "<tr id=\"count_found\"><td colspan=\"" . (count(array_keys($repos)) + 3) . "\">$i packages found</td></tr>\n";
+ $i++;
+ $packages[] = $package;
+ }
+ } // each $unstable
+ }
+ return $packages;
}
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
- <head>
- <title><?php echo $type; ?> extensions in Fedora</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <link rel="stylesheet" type="text/css" media="screen" href="css/rpmphp.css"/>
- <!--<link rel="stylesheet" type="text/css" media="print" href="css/rpmphp-print.css">-->
- <link rel="shortcut icon" href="images/favicon.ico"/>
- <link rel="icon" href="images/favicon.ico"/>
- </head>
- <body>
- <div id="wrapper">
-<?php
-include '_header.php';
-?>
- <!-- content BEGIN -->
- <div id="fedora-content">
- <div id="ariane">
- <p>You are here: </p>
- <ul>
- <li><a href="./">Reports home</a></li>
- <li><a href="#"><?php echo strtoupper($type) . ' extensions'; ?></a></li>
- </ul>
- </div>
-
- <div id="filter">
- <form action="rpm.php" method="get">
- <fieldset>
- <legend>Filter <?php echo strtoupper($type); ?> packages</legend>
- <input type="hidden" name='type' value="<?php echo $type; ?>" />
- <label for="what">Criteria: </label>
- <select name="what" id="what">
- <optgroup label="Pakages">
- <option value="%fedora"<?php if ($what=='%fedora') echo " selected=\"selected\""; ?>>In fedora</option>
- <option value="%stable"<?php if ($what=='%stable') echo " selected=\"selected\""; ?>>All stable</option>
- <option value="%all"<?php if ($what=='%all') echo " selected=\"selected\""; ?>>All</option>
- </optgroup>
- <optgroup label="Owner">
-<?php
try {
- switch ($type) {
- case "pecl": $filter = "WHERE name LIKE 'php-pecl-%' "; break;
- case "pear": $filter = "WHERE name LIKE 'php-%' "; break;
- case "R": $filter = "WHERE name LIKE 'R-%' "; break;
- default: $filter = "";
- }
+ switch ($type) {
+ case "pecl":
+ $filter = "WHERE name LIKE 'php-pecl-%' ";
+ break;
+ case "pear":
+ $filter = "WHERE name LIKE 'php-%' ";
+ break;
+ case "R":
+ $filter = "WHERE name LIKE 'R-%' ";
+ break;
+ default:
+ $filter = "";
+ }
- $db = new PDO ("mysql:dbname=" . MYBASE . ";host=" . MYHOST, MYUSER, MYPASS);
- $sql="SELECT DISTINCT owner FROM acls $filter ORDER BY owner";
- $res=$db->query($sql);
- if ($res)while ($owner = $res->fetchObject()) {
- printf("\t\t\t\t\t\t\t\t\t<option value=\"%s\" %s>%s</option>\n", $owner->owner, ($what==$owner->owner ? " selected=\"selected\"" : ""), $owner->owner);
- } else {
- echo "\t\t\t\t\t\t\t\t\t<option value=\"remi\">remi</option>\n";
- }
-?>
- </optgroup>
- </select>
- <input type="submit" value="Filter" />
- </fieldset>
- </form>
- </div>
-<?php
+ $db = new PDO ("mysql:dbname=" . MYBASE . ";host=" . MYHOST, MYUSER, MYPASS);
+ $sql="SELECT DISTINCT owner FROM acls $filter ORDER BY owner";
+ $res=$db->query($sql);
+ if ( $res ) {
+ while ( $owner = $res->fetchObject() ) {
+ $owners[] = $owner;
+ }
+ $smarty->assign('owners', $owners);
+ }
- $sql='SELECT MAX(stamp) AS stamp FROM repo';
- $res=$db->query($sql);
- if ($res && $row=$res->fetchObject()) {
- printf("<p>Repositories last updated %s.</p>", date("r", $row->stamp));
- }
+ $sql='SELECT MAX(stamp) AS stamp FROM repo';
+ $res=$db->query($sql);
+ if ($res && $row=$res->fetchObject()) {
+ $smarty->assign('repositories_update', date("r", $row->stamp));
+ }
-?>
- <h1><?php echo strtoupper($type). ' extensions in Fedora'; ?></h1>
- <table id="list-packages">
- <thead>
- <tr>
- <th>Package</th>
- <th>Owner(s)</th>
- <th>Upstream</th>
-<?php
-$repos = listRepos($db);
-$repos_k = array_keys($repos);
-foreach ( $repos_k as $r ) {
-?>
- <th><?php echo $r; ?></th>
-<?php
-}
-?>
- </tr>
- </thead>
- <tbody>
-<?php
- Report($db, $type, $repos);
+ $smarty->assign('packages', report($db, $type));
} catch(PDOException $e) {
-?>
- <tr>
- <td colspan="<?php echo count($repos_k) + 3; ?>">
-<?php
- printf("%s ERREUR : %s\n", date("r"), $e->getMessage());
-?>
- </td>
- </tr>
-<?php
+ $smarty->assign(
+ 'error',
+ sprintf("%s ERREUR : %s\n", date("r"), $e->getMessage())
+ );
}
-?>
- </tbody>
- </table>
- <ul id="legend">
- <li>Legend: </li>
- <li><strong>Upstream</strong>: bold if stable. </li>
- <li><strong>Repo</strong>: bold for latest release.</li>
- <li class='check'>Lastest released (stable if exists)</li>
- <li class='info'>Lastest in testing</li>
- <li class='attn'>Lastest not available</li>
- </ul>
- </div><!-- /fedora-content -->
-
-<?php
-include '_footer.php';
-?>
- </div>
- </body>
-</html>
+$page_content = $smarty->fetch('rpm.tpl');
+$smarty->assign('page_content', $page_content);
+$smarty->display('main.tpl');
+?> \ No newline at end of file