cvs: pearweb /include pear-database.php pear-format-html.php /public_html packages.php

From: Date: Sun, 02 Sep 2001 04:27:03 +0000
Subject: cvs: pearweb /include pear-database.php pear-format-html.php /public_html packages.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-748@lists.php.net to get a copy of this message
ssb Sun Sep 2 00:27:03 2001 EDT Modified files: /pearweb/include pear-database.php pear-format-html.php /pearweb/public_html packages.php Log: * fixed categories so it tracks _packages_ with visitation instead of sub-categories * updated package browser

Index: pearweb/include/pear-database.php diff -u pearweb/include/pear-database.php:1.11 pearweb/include/pear-database.php:1.12 --- pearweb/include/pear-database.php:1.11 Sat Sep 1 19:06:18 2001 +++ pearweb/include/pear-database.php Sun Sep 2 00:27:03 2001 @@ -1,5 +1,7 @@ <?php +require_once "DB/storage.php"; + // {{{ validate() function validate($entity, $field, $value /* , $oldvalue, $object */) { @@ -52,18 +54,28 @@ SELECT * FROM table WHERE right-1 = left; */ -function visit_node(&$tree, $node) { +function visit_node(&$tree, $node, &$cnt, $debug) { static $visitno; if (empty($visitno) || empty($node)) { $visitno = 1; } - $tree[$node]['leftvisit'] = $visitno++; + $tree[$node]['leftvisit'] = $visitno; + $inc = 1; + if (isset($cnt[$node])) { + $inc += $cnt[$node] * 2; + } + if ($debug) { + var_dump($cnt[$node]); + print "inc=$inc<br />\n"; + } + $visitno += $inc; if (isset($tree[$node]['children'])) { foreach ($tree[$node]['children'] as $cnode) { - visit_node($tree, $cnode); + visit_node($tree, $cnode, $cnt, $debug); } } - $tree[$node]['rightvisit'] = $visitno++; + $tree[$node]['rightvisit'] = $visitno; + $visitno += $inc; } // }}} @@ -72,24 +84,41 @@ function renumber_visitations($debug = false) { global $dbh; + $sth = $dbh->query("SELECT category FROM packages"); + if (DB::isError($sth)) { + return $sth; + } + $pkg_count = array(); + while ($sth->fetchInto($row, DB_FETCHMODE_ORDERED) === DB_OK) { + if (isset($pkg_count[$row[0]])) { + $pkg_count[$row[0]]++; + } else { + $pkg_count[$row[0]] = 1; + } + } + $sth->free(); $sth = $dbh->query("SELECT * FROM categories ORDER BY name"); if (DB::isError($sth)) { return $sth; } - $tree = array('' => array("children" => array())); + $tree = array(0 => array("children" => array())); $oldleft = array(); $oldright = array(); + $new_count = array(); while ($sth->fetchInto($row, DB_FETCHMODE_ASSOC) === DB_OK) { extract($row); - if ($name == '') { - continue; - } - $tree[$parent]["children"][] = $name; - $tree[$name]["parent"] = $parent; - $oldleft[$name] = (int)$leftvisit; - $oldright[$name] = (int)$rightvisit; + settype($parent, 'integer'); + $tree[$parent]["children"][] = $id; + $tree[$id]["parent"] = $parent; + $oldleft[$id] = (int)$leftvisit; + $oldright[$id] = (int)$rightvisit; + if (!isset($pkg_count[$id])) { + $new_count[$id] = 0; + } elseif ($npackages != $pkg_count[$id]) { + $new_count[$id] = $pkg_count[$id]; + } } - visit_node($tree, ''); + visit_node($tree, 0, $pkg_count, $debug); foreach ($tree as $node => $data) { if (!isset($oldleft[$node])) { continue; @@ -98,15 +127,18 @@ $r = $data["rightvisit"]; if ($oldleft[$node] == $l && $oldright[$node] == $r) { if ($debug) { - print "keeping $node\n"; + print "keeping $node<br />\n"; } continue; } if ($debug) { - print "updating $node\n"; + print "updating $node<br />\n"; } - $query = "UPDATE categories SET leftvisit = $l, rightvisit = $r ". - "WHERE name = '$node'"; + $query = "UPDATE categories SET leftvisit = $l, rightvisit = $r"; + if (isset($new_count[$node])) { + $query .= ", npackages = {$new_count[$node]}"; + } + $query .= " WHERE id = $node"; $dbh->query($query); } return DB_OK; @@ -146,37 +178,56 @@ // {{{ add_package() -/*function add_package($data) +// add a package, return new package id or PEAR error +function add_package($data) { global $dbh; - $defaults = array( - "virtual" => false, - "parent" => null, - "license" => "PHP License" - ); - foreach ($defaults as $property => $default_value) { - if (!isset($data[$property])) { - $data[$property] = $default_value; - } - } + // name, category + // license, summary, description extract($data); - - $query = "INSERT INTO packages (id,name,virtual,parent,license,summary,". - "description) VALUES(?,?,?,?,?,?,?)"; + if (empty($license)) { + $license = "PEAR License"; + } + if (empty($category)) { + return PEAR::raiseError("no `category' field"); + } + if (empty($name)) { + return PEAR::raiseError("no `name' field"); + } + $query = "INSERT INTO packages (id,name,category,license,summary,". + "description) VALUES(?,?,?,?,?,?)"; $id = $dbh->nextId("packages"); $sth = $dbh->prepare($query); if (DB::isError($sth)) { return $sth; } - $err = $dbh->execute($sth, array($id, $name, $virtual, $parent, $license, - $summary, $desc)); + $err = $dbh->execute($sth, array($id, $name, $category, $license, + $summary, $description)); if (DB::isError($err)) { return $err; } - return renumber_visitations(); -}*/ + if (DB::isError($err = renumber_visitations())) { + return $err; + } + return $id; +} // }}} + +function add_maintainer($package, $user, $role) +{ + global $dbh; + $query = "INSERT INTO maintains VALUES(?,?,?)"; + $sth = $dbh->prepare($query); + if (DB::isError($sth)) { + return $sth; + } + $err = $dbh->execute($sth, array($user, $package, $role)); + if (DB::isError($err)) { + return $err; + } + return DB_OK; +} // {{{ get_recent_releases() Index: pearweb/include/pear-format-html.php diff -u pearweb/include/pear-format-html.php:1.8 pearweb/include/pear-format-html.php:1.9 --- pearweb/include/pear-format-html.php:1.8 Sat Sep 1 19:06:41 2001 +++ pearweb/include/pear-format-html.php Sun Sep 2 00:27:03 2001 @@ -46,8 +46,8 @@ global $main_menu, $PHP_SELF; $SIDEBAR_DATA .= "<br /><br />\n"; $me = basename($PHP_SELF); - foreach ($main_menu as $url => $title) { - $tt = str_replace(" ", "&nbsp;", $title); + foreach ($main_menu as $url => $tit) { + $tt = str_replace(" ", "&nbsp;", $tit); if ($url == $me) { $SIDEBAR_DATA .= "<b>&gt;&gt;$tt&lt;&lt;</b><br />\n"; } else { @@ -97,7 +97,7 @@ print "<FONT COLOR=\"#990000\"><B>$error</B></FONT><BR>\n"; } -function error_handler($errobj) +function error_handler($errobj, $title = "Error") { if (PEAR::isError($errobj)) { $msg = $errobj->getMessage(); @@ -106,7 +106,7 @@ $msg = $errobj; $info = ''; } - response_header("Error"); + response_header($title); $report = "Error: $msg"; if ($info) { $report .= ": $info"; @@ -179,6 +179,14 @@ print "$indent </td>\n"; print "$indent </tr>\n"; print "$indent</table>\n"; +} + +function html_table_border(&$tableobj, $width = "100%") +{ + $border = new HTML_Table('border="0" cellpadding="0" cellspacing="1" '. + "width=\"{$width}\""); + $border->addRow(array($tableobj->toHtml()), 'bgcolor="#000000"'); + print $border->toHtml(); } ?> Index: pearweb/public_html/packages.php diff -u pearweb/public_html/packages.php:1.8 pearweb/public_html/packages.php:1.9 --- pearweb/public_html/packages.php:1.8 Sat Sep 1 13:07:53 2001 +++ pearweb/public_html/packages.php Sun Sep 2 00:27:03 2001 @@ -10,7 +10,7 @@ $category_where = "categories.parent IS NULL"; $category_title = "Package Browser: Top Level Categories"; } else { - $category_where = "categories.parent = $catpid"; + $category_where = "categories.parent = " . $dbh->quote($catpid); $category_title = "Package Browser: " . urldecode($catname); } @@ -18,44 +18,42 @@ $dbh->setFetchmode(DB_FETCHMODE_ASSOC); // 1) Show categories of this level -echo '<table border="0" width="100%"><tr><td>'; $sth = $dbh->query("SELECT * from categories WHERE $category_where"); -$table = new HTML_Table('border="1" cellpadding="1" cellspacing="1" width="90%" align="center"'); +$table = new HTML_Table('border="0" cellpadding="2" cellspacing="1" width="100%"'); $nrow = 0; while ($sth->fetchInto($row)) { extract($row); - if (!$npackages) { + $npackages = ($rightvisit - $leftvisit - 1) / 2; + if ($npackages == 0) { //continue; // XXXX Uncomment me to only show categories with packages } // XXXX change me with elseif + settype($npackages, "string"); if ($nrow == 0) { - $table->addRow(array("Categories", "Sub.<br>categories", "Num.<br>Packages", "Summary"), - null, 'TH'); + $table->addRow(array("Category", "#&nbsp;Packages", "Summary"), + 'bgcolor="#ffffff"', 'TH'); } $bg = ($nrow++ % 2) ? '#f0f0f0' : '#e0e0e0'; - $childs = ($rightvisit - $leftvisit - 1) / 2; - if (!$childs) { - $childs = '0'; - } $name = "<a href=\"$PHP_SELF?catpid=$id&catname=".urlencode($name)."\">$name</a>"; - $table->addRow(array($name, $childs, $npackages, $summary)); + $table->addRow(array($name, $npackages, $summary)); $table->setCellAttributes($nrow, 0, "width=\"20%\" bgcolor=\"$bg\""); $table->setCellAttributes($nrow, 1, "width=\"10%\" bgcolor=\"$bg\" align=\"center\""); - $table->setCellAttributes($nrow, 2, "width=\"10%\" bgcolor=\"$bg\" align=\"center\""); - $table->setCellAttributes($nrow, 3, "width=\"60%\" bgcolor=\"$bg\""); + $table->setCellAttributes($nrow, 2, "width=\"70%\" bgcolor=\"$bg\""); } if ($nrow == 0) { - echo "<center><p>No sub-categories in this level yet</p></center>"; + print "<center><p>No sub-categories in this level yet</p></center>"; } -echo $table->toHTML(); -echo '</td></tr></table><br><hr width="60%">'; +html_table_border($table); + +print '<br /><hr width="60%" />'; // 2) Show packages of this level -echo '<table border="0" width="100%"><tr><td>'; -echo "<center><p>No packages in this level yet</p></center>"; -echo '</td></tr></table>'; +print '<table border="0" width="100%"><tr><td>'; +print "<center><p>No packages in this level yet</p></center>"; +print '</td></tr></table>'; response_footer(); + ?>
« previous php.pear.cvs (#748) next »