From 873662fe815c678f35ec1518d9fc013c993ae710 Mon Sep 17 00:00:00 2001 From: "Johan \"Papa\" Cwiklinski" Date: Sun, 30 May 2010 11:26:48 +0200 Subject: Use of smarty to render rpm page ; apply coding standards, add license ; refs #46,48,47 --- rpm.php | 490 ++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 262 insertions(+), 228 deletions(-) (limited to 'rpm.php') diff --git a/rpm.php b/rpm.php index edad029..6627b04 100644 --- a/rpm.php +++ b/rpm.php @@ -1,256 +1,290 @@ . + * + * @category Main + * @package RPMPHP + * + * @author Remi Collet + * @author Johan Cwiklinski + * @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 "
"; print_r($repos);echo "
"; - foreach($repos as $repomain) { - foreach ($repomain as $repo) { - /*printf ("%s", $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 "
"; print_r($repos);echo "
"; + 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 = "summary) . "\">$rpmname"; - } 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'] = '' . + $rpmname . ''; + } 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 .= "
"; - $dispowner .= sprintf ("%s", $_SERVER["PHP_SELF"], $owner, $owner); - } - printf ("\n\t%s
%s\n\t%s\n\t%s%s\n", - ($i%2 ? "odd" : "even"), $dispname, - ($upstream->channel != $upstream->type ? "channel: " . $upstream->channel : ""), - $dispowner, - ($upstream->stable ? "".$upstream->stable."
" : " "), - ($upstream->unstable && (!$upstream->stable || $upstream->stable!=$upstream->unstable) ? $upstream->unstable." (".$upstream->state.")" : " ")); + $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 . + ' (' . $upstream->state . ')'; + } - $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
", $rpm->ver, $rpm->rel); - } else { - $display .= sprintf("%s-%s
", $rpm->ver, $rpm->rel); - } - if ($verup==$verpm) $class="check"; - break; - case "": - $display .= sprintf("%s-%s
", $rpm->ver, $rpm->rel); - if ($verup==$verpm) $class="check"; - break; - case "updates": - $display .= sprintf("%s-%s (updates)
", $rpm->ver, $rpm->rel); - if ($verup==$verpm) $class="check"; - break; - case "testing": - $display .= sprintf("%s-%s (testing)
", $rpm->ver, $rpm->rel); - if ($verup==$verpm) $class="info"; - break; - } - } // RPM exists - } // sub repo - if ($display && empty($class)) $class="attn"; - if ($display) { - printf("\t%s\n", $class, $display); - } else { - echo "\t \n"; - } - } // mainrepo + switch ($repo->sub) { + case "base": + if ( isset($rpms[$repo->main."-updates"]) ) { + $display .= sprintf( + "%s-%s
", + $rpm->ver, + $rpm->rel + ); + } else { + $display .= sprintf( + "%s-%s
", + $rpm->ver, + $rpm->rel + ); + } + if ( $verup==$verpm ) { + $class="check"; + } + break; + case "": + $display .= sprintf( + "%s-%s
", + $rpm->ver, + $rpm->rel + ); + if ( $verup==$verpm ) { + $class="check"; + } + break; + case "updates": + $display .= sprintf( + "%s-%s (updates)
", + $rpm->ver, + $rpm->rel + ); + if ( $verup==$verpm ) { + $class="check"; + } + break; + case "testing": + $display .= sprintf( + "%s-%s (testing)
", + $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 "\n"; - $i++; - } - } // each $unstable - echo "$i packages found\n"; + $i++; + $packages[] = $package; + } + } // each $unstable + } + return $packages; } -?> - - - - <?php echo $type; ?> extensions in Fedora - - - - - - - -
- - -
-
-

You are here:

- -
- -
-
-
- Filter packages - - - - -
-
-
-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("

Repositories last updated %s.

", 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)); + } -?> -

- - - - - - - - - - - - -assign('packages', report($db, $type)); } catch(PDOException $e) { -?> - - - -assign( + 'error', + sprintf("%s ERREUR : %s\n", date("r"), $e->getMessage()) + ); } -?> - -
PackageOwner(s)Upstream
-getMessage()); -?> -
-
    -
  • Legend:
  • -
  • Upstream: bold if stable.
  • -
  • Repo: bold for latest release.
  • -
  • Lastest released (stable if exists)
  • -
  • Lastest in testing
  • -
  • Lastest not available
  • -
-
- - -
- - +$page_content = $smarty->fetch('rpm.tpl'); +$smarty->assign('page_content', $page_content); +$smarty->display('main.tpl'); +?> \ No newline at end of file -- cgit From c232552a41bf22f05db4ab1f56d55f8692a1b2ca Mon Sep 17 00:00:00 2001 From: "Johan \"Papa\" Cwiklinski" Date: Sun, 30 May 2010 11:29:36 +0200 Subject: Remove not relevant version ; refs #46 --- rpm.php | 1 - 1 file changed, 1 deletion(-) (limited to 'rpm.php') diff --git a/rpm.php b/rpm.php index 6627b04..11b30c2 100644 --- a/rpm.php +++ b/rpm.php @@ -31,7 +31,6 @@ * @author Johan Cwiklinski * @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. */ -- cgit From b2ae578c977b5920dd387cb6bc6b731c09259c49 Mon Sep 17 00:00:00 2001 From: "Johan \"Papa\" Cwiklinski" Date: Sun, 30 May 2010 18:18:46 +0200 Subject: Smarty variable assigned twice, export reposlist function so it could be used --- rpm.php | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'rpm.php') diff --git a/rpm.php b/rpm.php index 11b30c2..5073f9f 100644 --- a/rpm.php +++ b/rpm.php @@ -36,8 +36,6 @@ */ require 'main.inc.php'; -$smarty->assign('ariane', $ariane); - $what=(isset($_GET["what"]) ? $_GET["what"] : "%fedora"); $type=(isset($_GET["type"]) ? $_GET["type"] : "pecl"); @@ -51,32 +49,6 @@ $smarty->assign('type', $type); $smarty->assign('what', $what); $smarty->assign('page_title', strtoupper($type). ' extensions in Fedora'); -/** -* 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 "
"; print_r($repos);echo "
"; - foreach ( $repos as $repomain ) { - foreach ($repomain as $repo) { - $repos[$repo->main][$repo->sub] = $repo; - break; - } - } - return $repos; -} - /** * Retrieve packages informations * -- cgit