[28379] trunk/www
source_changes at macosforge.org
source_changes at macosforge.org
Wed Aug 29 18:36:17 PDT 2007
Revision: 28379
http://trac.macosforge.org/projects/macports/changeset/28379
Author: jmpp at macports.org
Date: 2007-08-29 18:36:17 -0700 (Wed, 29 Aug 2007)
Log Message:
-----------
Separate ports and news into their own databases and abstract calls to them through appropriate variables in the code.
Modified Paths:
--------------
trunk/www/includes/common.inc
trunk/www/includes/news.inc
trunk/www/ports.php
Modified: trunk/www/includes/common.inc
===================================================================
--- trunk/www/includes/common.inc 2007-08-29 22:06:12 UTC (rev 28378)
+++ trunk/www/includes/common.inc 2007-08-30 01:36:17 UTC (rev 28379)
@@ -7,10 +7,11 @@
######################################################################
# Ports database connection parameters:
-$host = 'localhost';
-$user = 'www';
-$pass = '';
-$connect = mysql_pconnect($host, $user, $pass) or die("Can't connect to db!");
+$portsdb = 'macports_ports';
+$portsdb_host = 'localhost';
+$portsdb_user = 'www';
+$portsdb_passwd = '';
+$portsdb_connect = mysql_connect($portsdb_host, $portsdb_user, $portsdb_passwd) or die("Can't connect to the ports database!");
######################################################################
@@ -66,7 +67,9 @@
# Print a total count of currently available ports:
function ports_count() {
- $result = mysql_query("SELECT count(*) FROM macports.portfiles");
+ global $portsdb;
+
+ $result = mysql_query("SELECT count(*) FROM $portsdb.portfiles") or die("Error: " . mysql_error());
if ($result) {
$row = mysql_fetch_array($result);
$count = $row[0];
Modified: trunk/www/includes/news.inc
===================================================================
--- trunk/www/includes/news.inc 2007-08-29 22:06:12 UTC (rev 28378)
+++ trunk/www/includes/news.inc 2007-08-30 01:36:17 UTC (rev 28379)
@@ -9,19 +9,21 @@
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$PHP_SELF = $_SERVER['PHP_SELF'];
/* include_once("$DOCUMENT_ROOT/macports/includes/db.inc"); */
-/* $connect = mysql_pconnect($host, $user, $pass) or die("Can't connect to db!"); */
-/* mysql_select_db($db); */
+$newsdb = 'macports_news';
+$newsdb_host = 'localhost';
+$newsdb_user = 'www';
+$newsdb_passwd = '';
+$newsdb_connect = mysql_pconnect($newsdb_host, $newsdb_user, $newsdb_pass) or die("Can't connect to the MacPorts news database!");
-
######################################################################
# create an RSS feed of the project news
function create_rss() {
- global $DOCUMENT_ROOT, $connect;
+ global $DOCUMENT_ROOT, $newsdb, $newsdb_connect;
- $query = "SELECT id, title, news FROM headlines ORDER BY id DESC LIMIT 10";
- $result = mysql_query($query) or die("Error: $query.");
+ $query = "SELECT id, title, news FROM $newsdb.headlines ORDER BY id DESC LIMIT 10";
+ $result = mysql_query($query) or die("Error: $query (" . mysql_error() . ")");
if(!$result) {
die("Error: $result.");
}
@@ -53,7 +55,7 @@
$rss .= " <title>$row->title</title>\n";
$rss .= " <link>http://www.macports.org/archives.php?id=$row->id</link>\n";
- $desc_query = "SELECT SUBSTRING_INDEX(news, ' ', 26) FROM headlines WHERE id=$row->id";
+ $desc_query = "SELECT SUBSTRING_INDEX(news, ' ', 26) FROM $newsdb.headlines WHERE id=$row->id";
$desc_result = mysql_query($desc_query);
$desc_row = mysql_fetch_row($desc_result);
@@ -76,10 +78,10 @@
# print the project news
function print_headlines() {
- global $connect;
+ global $newsdb, $newsdb_connect;
- $query = "SELECT id, DATE_FORMAT(timestamp, '%e %b %Y, %l:%i %p') AS f_timestamp, title, news FROM headlines ORDER BY id DESC LIMIT 5";
- $result = mysql_query($query) or die("Error: $query.");
+ $query = "SELECT id, DATE_FORMAT(timestamp, '%e %b %Y, %l:%i %p') AS f_timestamp, title, news FROM $newsdb.headlines ORDER BY id DESC LIMIT 5";
+ $result = mysql_query($query) or die("Error: $query (" . mysql_error() . ")");
if(!$result) {
die("Error: $result.");
}
@@ -100,11 +102,11 @@
# display a single headline
function print_headline() {
- global $connect;
+ global $newsdb, $newsdb_connect;
$id = $_GET['id'];
- $query = "SELECT id, DATE_FORMAT(timestamp, '%e %b %Y, %l:%i %p') AS f_timestamp, title, news FROM headlines WHERE id='$id'";
- $result = mysql_query($query) or die("Error: $query.");
+ $query = "SELECT id, DATE_FORMAT(timestamp, '%e %b %Y, %l:%i %p') AS f_timestamp, title, news FROM $newsdb.headlines WHERE id='$id'";
+ $result = mysql_query($query) or die("Error: $query (" . mysql_error() . ")");
if(!$result) {
die("Error: $result.");
}
@@ -125,7 +127,7 @@
# print the form used to add project news
function print_add_headline() {
- global $PHP_SELF, $connect;
+ global $PHP_SELF, $newsdb, $newsdb_connect;
if(!$_POST['submit']) {
echo "<p>Use the form below to add project news.</p>\n\n";
@@ -151,7 +153,7 @@
}
if(sizeof($errorList) == 0) {
$query = "INSERT INTO headlines (timestamp, title, news) VALUES (NOW(), '$title', '$news')";
- $result = mysql_query($query) or die("Error: $query.");
+ $result = mysql_query($query) or die("Error: $query (" . mysql_error() . ")");
if(!$result) {
die("Error: $result.");
}
@@ -174,12 +176,12 @@
# print the form used to edit project news
function print_edit_headline($id) {
- global $PHP_SELF, $connect;
+ global $PHP_SELF, $newsdb, $newsdb_connect;
if(!$_POST['submit']) {
$id = $_GET['id'];
- $query = "SELECT title, news FROM headlines WHERE id='$id'";
- $result = mysql_query($query) or die("Error: $query.");
+ $query = "SELECT title, news FROM $newsdb.headlines WHERE id='$id'";
+ $result = mysql_query($query) or die("Error: $query (" . mysql_error() . ")");
if(!$result) {
die("Error: $result.");
}
@@ -214,7 +216,7 @@
}
if(sizeof($errorList) == 0) {
$query = "UPDATE headlines SET title='$title', news='$news' WHERE id='$id'";
- $result = mysql_query($query) or die("Error: $query.");
+ $result = mysql_query($query) or die("Error: $query (" . mysql_error() . ")");
if(!$result) {
die("Error: $result.");
@@ -238,13 +240,13 @@
# print a list of all existing headlines
function print_all_headlines() {
- global $connect;
+ global $newsdb, $newsdb_connect;
echo "<p>Below is a list of all existing news headlines. They can be viewed, edited, or deleted from this interface.
Alternatively, you can also <a href=\"/macports/admin/add.php\">add news</a>.</p>\n\n";
- $query = "SELECT id, title, DATE_FORMAT(timestamp, '%e %b %Y, %l:%i %p') AS f_timestamp FROM headlines ORDER BY id DESC";
- $result = mysql_query($query) or die("Error: $query.");
+ $query = "SELECT id, title, DATE_FORMAT(timestamp, '%e %b %Y, %l:%i %p') AS f_timestamp FROM $newsdb.headlines ORDER BY id DESC";
+ $result = mysql_query($query) or die("Error: $query (" . mysql_error() . ")");
if(!$result) {
die("Error: $result.");
}
@@ -264,10 +266,10 @@
# print a list of all existing headlines without the admin foobage
# (this is cheap and could be better)
function print_all_headlines_nonadmin() {
- global $connect;
+ global $newsdb, $newsdb_connect;
- $query = "SELECT id, title, DATE_FORMAT(timestamp, '%e %b %Y, %l:%i %p') AS f_timestamp FROM headlines ORDER BY id DESC";
- $result = mysql_query($query) or die("Error: $query.");
+ $query = "SELECT id, title, DATE_FORMAT(timestamp, '%e %b %Y, %l:%i %p') AS f_timestamp FROM $newsdb.headlines ORDER BY id DESC";
+ $result = mysql_query($query) or die("Error: $query (" . mysql_error() . ")");
if(!$result) {
die("Error: $result.");
}
Modified: trunk/www/ports.php
===================================================================
--- trunk/www/ports.php 2007-08-29 22:06:12 UTC (rev 28378)
+++ trunk/www/ports.php 2007-08-30 01:36:17 UTC (rev 28379)
@@ -15,7 +15,7 @@
This form allows you to search the current index of MacPorts software. <br />
<i>Index last updated: </i>
<?php
- $sql = "SELECT UNIX_TIMESTAMP(activity_time) FROM macports.log ORDER BY UNIX_TIMESTAMP(activity_time) DESC";
+ $sql = "SELECT UNIX_TIMESTAMP(activity_time) FROM $portsdb.log ORDER BY UNIX_TIMESTAMP(activity_time) DESC";
$result = mysql_query($sql);
if($result && $row = mysql_fetch_row($result)) {
echo date("d-M-Y H:i:s", $row[0]);
@@ -41,7 +41,7 @@
<tr><td colspan="4"><hr size="1" noshade="noshade" /></td></tr>
<tr>
<?php
- $result = mysql_query("SELECT count(*) from macports.portfiles");
+ $result = mysql_query("SELECT count(*) from $portsdb.portfiles");
if ($result) {
$row = mysql_fetch_array($result);
$count = $row[0];
@@ -57,7 +57,7 @@
<tr><td colspan="4"><hr size="1" noshade="noshade" /></td></tr>
<tr><th colspan="4" align="left">View By Category:</th></tr>
<?php
- $query = "SELECT DISTINCT category FROM macports.categories ORDER BY category";
+ $query = "SELECT DISTINCT category FROM $portsdb.categories ORDER BY category";
$result = mysql_query($query);
if($result) {
while( $row = mysql_fetch_assoc($result) ) {
@@ -75,7 +75,7 @@
if ($by && ($substr || $by == "all")) {
$fields = "name, path, version, description";
$query = "1";
- $tables = "macports.portfiles p";
+ $tables = "$portsdb.portfiles p";
if ($by == "name") {
$query .= " AND p.name LIKE '%" . mysql_real_escape_string($substr) . "%'";
}
@@ -86,19 +86,19 @@
$query .= " AND p.description LIKE '%" . mysql_real_escape_string($substr) . "%'";
}
if ($by == "cat") {
- $tables .= ", macports.categories c";
+ $tables .= ", $portsdb.categories c";
$query .= " AND c.portfile=p.name AND c.category='" . mysql_real_escape_string($substr) . "'";
}
if ($by == "variant") {
- $tables .= ", macports.variants v";
+ $tables .= ", $portsdb.variants v";
$query .= " AND v.portfile=p.name AND v.variant='" . mysql_real_escape_string($substr) . "'";
}
if ($by == "platform") {
- $tables .= ", macports.platforms pl";
+ $tables .= ", $portsdb.platforms pl";
$query .= " AND pl.portfile=p.name AND pl.platform ='" . mysql_real_escape_string($substr) . "'";
}
if ($by == "maintainer") {
- $tables .= ", macports.maintainers m";
+ $tables .= ", $portsdb.maintainers m";
$query .= " AND m.portfile=p.name AND m.maintainer LIKE '%" . mysql_real_escape_string($substr) . "%'";
}
$query = "SELECT DISTINCT $fields FROM $tables WHERE $query ORDER BY name";
@@ -117,7 +117,7 @@
<?php echo htmlspecialchars($row['description']); ?><br />
<?php
// MAINTAINERS
- $nquery = "SELECT maintainer FROM macports.maintainers WHERE portfile='" . mysql_real_escape_string($row['name']) . "' ORDER BY is_primary DESC, maintainer";
+ $nquery = "SELECT maintainer FROM $portsdb.maintainers WHERE portfile='" . mysql_real_escape_string($row['name']) . "' ORDER BY is_primary DESC, maintainer";
$nresult = mysql_query($nquery);
if ($nresult) {
?>
@@ -134,7 +134,7 @@
}
// CATEGORIES
- $nquery = "SELECT category FROM macports.categories WHERE portfile='" . mysql_real_escape_string($row['name']) . "' ORDER BY is_primary DESC, category";
+ $nquery = "SELECT category FROM $portsdb.categories WHERE portfile='" . mysql_real_escape_string($row['name']) . "' ORDER BY is_primary DESC, category";
$nresult = mysql_query($nquery);
if ($nresult) {
?>
@@ -153,7 +153,7 @@
}
// PLATFORMS
- $nquery = "SELECT platform FROM macports.platforms WHERE portfile='" . mysql_real_escape_string($row['name']) . "' ORDER BY platform";
+ $nquery = "SELECT platform FROM $portsdb.platforms WHERE portfile='" . mysql_real_escape_string($row['name']) . "' ORDER BY platform";
$nresult = mysql_query($nquery);
if ($nresult && mysql_num_rows($nresult) > 0) {
?>
@@ -169,7 +169,7 @@
}
// DEPENDENCIES
- $nquery = "SELECT library FROM macports.dependencies WHERE portfile='" . mysql_real_escape_string($row['name']) . "' ORDER BY library";
+ $nquery = "SELECT library FROM $portsdb.dependencies WHERE portfile='" . mysql_real_escape_string($row['name']) . "' ORDER BY library";
$nresult = mysql_query($nquery);
if ($nresult && mysql_num_rows($nresult) > 0) {
?>
@@ -186,7 +186,7 @@
}
/*
// VARIANTS
- $nquery = "SELECT variant FROM macports.variants WHERE portfile='" . mysql_real_escape_string($row['name']) . "' ORDER BY variant";
+ $nquery = "SELECT variant FROM $portsdb.variants WHERE portfile='" . mysql_real_escape_string($row['name']) . "' ORDER BY variant";
$nresult = mysql_query($nquery);
if ($nresult && mysql_num_rows($nresult) > 0) {
?>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070829/409fa121/attachment.html
More information about the macports-changes
mailing list