From 36ee5561035af335bc3c900ded7aa89066421226 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Tue, 24 Jun 2008 02:53:16 -0400 Subject: Move code out of index.php Move database queries to functions and html to templates. Signed-off-by: Loui Chang --- web/lib/stats.inc | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 web/lib/stats.inc (limited to 'web/lib') diff --git a/web/lib/stats.inc b/web/lib/stats.inc new file mode 100644 index 0000000..e659210 --- /dev/null +++ b/web/lib/stats.inc @@ -0,0 +1,72 @@ += $targstamp OR Packages.ModifiedTS >= $targstamp)"; + $result = db_query($q, $dbh); + $row = mysql_fetch_row($result); + $update_count = $row[0]; + + include('stats/general_stats_table.php'); +} + -- cgit v1.2.3-70-g09d2 From 2feee92a75d4fe7042be52d1eef4e6e466af4967 Mon Sep 17 00:00:00 2001 From: Andrea Scarpino Date: Tue, 8 Jul 2008 18:56:42 +0200 Subject: Remember user between sessions. Signed-off-by: Loui Chang --- web/lang/en/index_po.inc | 2 ++ web/lang/it/index_po.inc | 2 ++ web/lib/acctfuncs.inc | 7 ++++++- web/template/login_form.php | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) (limited to 'web/lib') diff --git a/web/lang/en/index_po.inc b/web/lang/en/index_po.inc index bdeb87f..eb626eb 100644 --- a/web/lang/en/index_po.inc +++ b/web/lang/en/index_po.inc @@ -25,6 +25,8 @@ $_t["en"]["Password:"] = "Password:"; $_t["en"]["Username:"] = "Username:"; +$_t["en"]["Remember me"] = "Remember me"; + $_t["en"]["Welcome to the AUR! If you're a newcomer, you may want to read the %hGuidelines%h."] = "Welcome to the AUR! If you're a newcomer, you may want to read the %hGuidelines%h."; $_t["en"]["This is where the intro text will go."] = "This is where the intro text will go."; diff --git a/web/lang/it/index_po.inc b/web/lang/it/index_po.inc index f1e54eb..12b6e56 100644 --- a/web/lang/it/index_po.inc +++ b/web/lang/it/index_po.inc @@ -19,6 +19,8 @@ $_t["it"]["Password:"] = "Password:"; $_t["it"]["Username:"] = "Nome utente:"; +$_t["it"]["Remember me"] = "Ricordami" ; + $_t["it"]["Welcome to the AUR! If you're a newcomer, you may want to read the %hGuidelines%h."] = "Benvenuto in AUR! Se sei un nuovo utente, dovresti leggere le %hGuidelines%h."; $_t["it"]["This is where the intro text will go."] = "Qui ci andrà il testo di introduzione."; diff --git a/web/lib/acctfuncs.inc b/web/lib/acctfuncs.inc index bbd6b74..73db270 100644 --- a/web/lib/acctfuncs.inc +++ b/web/lib/acctfuncs.inc @@ -644,7 +644,12 @@ function try_login() { if ($logged_in) { # set our SID cookie - setcookie("AURSID", $new_sid, 0, "/"); + if ($_POST['remember_me'] == "on") + # Set cookies for 30 days. + $cookie_time = time() + (60 * 60 * 24 * 30); + else + $cookie_time = 0; + setcookie("AURSID", $new_sid, $cookie_time, "/"); # header("Location: /index.php"); header("Location: " . $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']); $login_error = ""; diff --git a/web/template/login_form.php b/web/template/login_form.php index b2ed066..4bfc579 100644 --- a/web/template/login_form.php +++ b/web/template/login_form.php @@ -16,6 +16,7 @@ } ?>" /> + " /> -- cgit v1.2.3-70-g09d2 From 1deb924674d1a42fc9b127a18bdc012c84ec6f93 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Wed, 9 Jul 2008 00:30:05 -0400 Subject: Make JSON search return more information. Signed-off-by: Loui Chang --- web/lib/aurjson.class.php | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'web/lib') diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php index 953f5ab..6ff9b0f 100644 --- a/web/lib/aurjson.class.php +++ b/web/lib/aurjson.class.php @@ -22,6 +22,8 @@ if (!extension_loaded('json')) class AurJSON { private $dbh = false; private $exposed_methods = array('search','info'); + private $fields = array('ID','Name','Version','Description', + 'URL','URLPath','License','NumVotes','OutOfDate'); /** * Handles post data, and routes the request. @@ -42,7 +44,9 @@ class AurJSON { // do the routing if ( in_array($http_data['type'], $this->exposed_methods) ) { // ugh. this works. I hate you php. - $json = call_user_func_array(array(&$this,$http_data['type']),$http_data['arg']); + $json = call_user_func_array(array(&$this,$http_data['type']), + $http_data['arg']); + // allow rpc callback for XDomainAjax if ( isset($http_data['callback']) ) { return $http_data['callback'] . "({$json})"; @@ -87,22 +91,22 @@ class AurJSON { } $keyword_string = mysql_real_escape_string($keyword_string, $this->dbh); - $query = sprintf( - "SELECT Name,ID FROM Packages WHERE ( Name LIKE '%%%s%%' OR Description LIKE '%%%s%%' ) AND DummyPkg=0", - $keyword_string, $keyword_string ); + + $query = "SELECT " . implode(',', $this->fields) . + " FROM Packages WHERE DummyPkg=0 AND "; + $query .= sprintf("( Name LIKE '%%%s%%' OR Description LIKE '%%%s%%' )", + $keyword_string, $keyword_string); $result = db_query($query, $this->dbh); if ( $result && (mysql_num_rows($result) > 0) ) { $search_data = array(); while ( $row = mysql_fetch_assoc($result) ) { - $elem = array( - 'Name' => $row['Name'], - 'ID' => $row['ID'] ); - array_push($search_data,$elem); - } + array_push($search_data, $row); + } + mysql_free_result($result); - return $this->json_results('search',$search_data); + return $this->json_results('search', $search_data); } else { return $this->json_error('No results found'); @@ -115,7 +119,8 @@ class AurJSON { * @return mixed Returns an array of value data containing the package data **/ private function info($pqdata) { - $base_query = "SELECT ID,Name,Version,Description,URL,URLPath,License,NumVotes,OutOfDate FROM Packages WHERE DummyPkg=0 AND "; + $base_query = "SELECT " . implode(',', $this->fields) . + " FROM Packages WHERE DummyPkg=0 AND "; if ( is_numeric($pqdata) ) { // just using sprintf to coerce the pqd to an int @@ -127,7 +132,8 @@ class AurJSON { if(get_magic_quotes_gpc()) { $pqdata = stripslashes($pqdata); } - $query_stub = sprintf("Name=\"%s\"",mysql_real_escape_string($pqdata)); + $query_stub = sprintf("Name=\"%s\"", + mysql_real_escape_string($pqdata)); } $result = db_query($base_query.$query_stub, $this->dbh); @@ -135,11 +141,11 @@ class AurJSON { if ( $result && (mysql_num_rows($result) > 0) ) { $row = mysql_fetch_assoc($result); mysql_free_result($result); - return $this->json_results('info',$row); + return $this->json_results('info', $row); } else { return $this->json_error('No result found'); } } } -?> + -- cgit v1.2.3-70-g09d2 From 1a1a6eb36e17315f08eee0e44a83fe4bdf0887f5 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Wed, 9 Jul 2008 14:38:08 -0400 Subject: Add a new DEFAULT_LANG constant. DEFAULT_LANG will essentially be used to specify what language strings are initially written in. This will eliminate the need for English translation arrays in AUR and make adding or changing the English strings a lot easier. DEFAULT_LANG may be required for strings to display properly. Also change the output when a translation isn't found. Eliminate the which can cause validation errors depending on where the string is placed. Signed-off-by: Loui Chang --- web/lib/aur.inc | 8 +++----- web/lib/config.inc.proto | 11 ++++++++--- web/lib/translator.inc | 9 ++++++--- 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'web/lib') diff --git a/web/lib/aur.inc b/web/lib/aur.inc index 81ffde2..ade5b82 100644 --- a/web/lib/aur.inc +++ b/web/lib/aur.inc @@ -311,12 +311,11 @@ function set_lang() { $LANG = $row[0]; } $update_cookie = 1; - } else { - $LANG = "en"; } + # Set $LANG to default if nothing is valid. if (!array_key_exists($LANG, $SUPPORTED_LANGS)) { - $LANG = "en"; # default to English + $LANG = DEFAULT_LANG; } if ($update_cookie) { @@ -336,7 +335,7 @@ function html_header($title="") { global $SUPPORTED_LANGS; $login = try_login(); - $login_error = $login['error']; + $login_error = $login['error']; $title = htmlspecialchars($title, ENT_QUOTES); @@ -410,4 +409,3 @@ function uid_from_username($username="") return $row[0]; } -?> diff --git a/web/lib/config.inc.proto b/web/lib/config.inc.proto index 7a0a155..505fa7c 100644 --- a/web/lib/config.inc.proto +++ b/web/lib/config.inc.proto @@ -16,9 +16,12 @@ define( "USERNAME_MAX_LEN", 16 ); define( "PASSWD_MIN_LEN", 4 ); define( "PASSWD_MAX_LEN", 128 ); -$LOGIN_TIMEOUT = 7200; # number of idle seconds before timeout +# Language that messages are initially written in. +# This should never change. +define("DEFAULT_LANG", "en"); -$SUPPORTED_LANGS = array( # what languages we have translations for +# Languages we have translations for +$SUPPORTED_LANGS = array( "en" => "English", "pl" => "Polski", "it" => "Italiano", @@ -30,4 +33,6 @@ $SUPPORTED_LANGS = array( # what languages we have translations for "fr" => "Français" ); -?> +# Idle seconds before timeout +$LOGIN_TIMEOUT = 7200; + diff --git a/web/lib/translator.inc b/web/lib/translator.inc index 41ece89..f16bd11 100644 --- a/web/lib/translator.inc +++ b/web/lib/translator.inc @@ -37,12 +37,16 @@ function __() { # First argument is always string to be translated $tag = $args[0]; - $translated = $_t[$LANG][$tag]; + if (empty($LANG) || $LANG == DEFAULT_LANG) + $translated = $tag; + else + $translated = $_t[$LANG][$tag]; + if (empty($translated)) { # if it's a supported language, but there isn't a translation, # alert the visitor to the missing translation. # - $translated = "_${tag}_"; + $translated = "_${tag}_"; } # This condition is to reorganise the arguments in case of @@ -63,4 +67,3 @@ function __() { return $translated; } -?> -- cgit v1.2.3-70-g09d2 From 2c6bae2e63c69f87599e5ef081eeba0a8d08bf00 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Wed, 23 Jul 2008 10:36:41 -0400 Subject: Convert special chars in translations to html entities. This closes FS#10809 - bug in french translation of AUR web interface Signed-off-by: Loui Chang --- web/lib/translator.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'web/lib') diff --git a/web/lib/translator.inc b/web/lib/translator.inc index f16bd11..fb9ed63 100644 --- a/web/lib/translator.inc +++ b/web/lib/translator.inc @@ -25,7 +25,6 @@ include_once("common_po.inc"); - function __() { global $_t; global $LANG; @@ -49,6 +48,8 @@ function __() { $translated = "_${tag}_"; } + $translated = htmlspecialchars($translated, ENT_QUOTES); + # This condition is to reorganise the arguments in case of # deprecated usage. __("string", array("string","string")) if (!empty($args[1]) && is_array($args[1])) { @@ -64,6 +65,7 @@ function __() { $translated = preg_replace("/\%[sh]/", $args[$i], $translated, 1); } } + return $translated; } -- cgit v1.2.3-70-g09d2 From 1d416d6891d2945af6bfcc67ebfeb89e83195c60 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Tue, 19 Aug 2008 15:35:58 -0400 Subject: Add Turkish to SUPPORTED_LANGS in config.inc.proto. Signed-off-by: Loui Chang --- web/lib/config.inc.proto | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'web/lib') diff --git a/web/lib/config.inc.proto b/web/lib/config.inc.proto index 505fa7c..7248b93 100644 --- a/web/lib/config.inc.proto +++ b/web/lib/config.inc.proto @@ -22,15 +22,16 @@ define("DEFAULT_LANG", "en"); # Languages we have translations for $SUPPORTED_LANGS = array( + "ca" => "Català", + "de" => "Deutsch", "en" => "English", - "pl" => "Polski", + "es" => "Español", + "fr" => "Français", "it" => "Italiano", - "ca" => "Català", + "pl" => "Polski", "pt" => "Português", - "es" => "Español", - "de" => "Deutsch", "ru" => "Русский", - "fr" => "Français" + "tr" => "Türkçe" ); # Idle seconds before timeout -- cgit v1.2.3-70-g09d2 From 52fb8550a21aeac6a6c75700c78be36de8983e15 Mon Sep 17 00:00:00 2001 From: Andrea Scarpino Date: Tue, 26 Aug 2008 17:49:26 +0200 Subject: doesn't show disown package when already disowned Signed-off-by: Callan Barrett --- web/lib/pkgfuncs.inc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'web/lib') diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index 77b0ab1..484e5a6 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -512,14 +512,12 @@ function package_details($id=0, $SID="") { if ($row["MaintainerUID"] == 0) { echo "\n"; - } - - if ($row["MaintainerUID"] == uid_from_sid($SID) || - account_from_sid($SID) == "Trusted User" || - account_from_sid($SID) == "Developer") { + } else if ($row["MaintainerUID"] == uid_from_sid($SID) || + account_from_sid($SID) == "Trusted User" || + account_from_sid($SID) == "Developer") { echo "\n"; - } + } if (account_from_sid($SID) == "Trusted User" || account_from_sid($SID) == "Developer") { -- cgit v1.2.3-70-g09d2 From 5c3f01909301f641f57b2ffe8b59609de6be2256 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Fri, 12 Sep 2008 20:19:42 -0400 Subject: Use system rm in rm_rf function. PHP can't properly handle symlinks which causes problems when self-referencing symlinks appear. This closes FS#11187. Signed-off-by: Loui Chang --- web/lib/aur.inc | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'web/lib') diff --git a/web/lib/aur.inc b/web/lib/aur.inc index ade5b82..a126bb9 100644 --- a/web/lib/aur.inc +++ b/web/lib/aur.inc @@ -374,19 +374,10 @@ function can_submit_pkg($name="", $sid="") { # recursive delete directory # function rm_rf($dirname="") { - $d = dir($dirname); - while ($f = $d->read()) { - if ($f != "." && $f != "..") { - if (is_dir($dirname."/".$f)) { - rm_rf($dirname."/".$f); - } - if (is_file($dirname."/".$f) || is_link($dirname."/".$f)) { - unlink($dirname."/".$f); - } - } + if ($dirname != "") { + exec('rm -rf ' . escapeshellcmd($dirname)); } - $d->close(); - rmdir($dirname); + return; } -- cgit v1.2.3-70-g09d2 From df39cded09cb2a1ed9ee2f11207b28ccbb24fd51 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Mon, 29 Sep 2008 00:07:33 +0800 Subject: Sort required by list in package details page. This closes FS#11420. Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/lib/pkgfuncs.inc | 1 + 1 file changed, 1 insertion(+) (limited to 'web/lib') diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index 484e5a6..5ba56da 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -128,6 +128,7 @@ function package_required($pkgid=0) { $q.= "WHERE PackageDepends.PackageID = Packages.ID "; $q.= "AND PackageDepends.DepPkgID = "; $q.= mysql_real_escape_string($pkgid); + $q.= " ORDER BY Name"; $result = db_query($q, $dbh); if (!$result) {return array();} while ($row = mysql_fetch_row($result)) { -- cgit v1.2.3-70-g09d2 From c7bfd9528473da0886afd328f0fa68e26c97ca3d Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Thu, 18 Sep 2008 22:16:40 -0400 Subject: Take formatting out of version number in web/lib/version.inc Signed-off-by: Loui Chang Signed-off-by: Callan Barrett --- web/lib/version.inc | 2 +- web/template/footer.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'web/lib') diff --git a/web/lib/version.inc b/web/lib/version.inc index dcc2f3c..9ef059f 100644 --- a/web/lib/version.inc +++ b/web/lib/version.inc @@ -1,3 +1,3 @@ v1.5.2" ); +define( "AUR_VERSION", "v1.5.2" ); diff --git a/web/template/footer.php b/web/template/footer.php index 9d85c7d..fe8f89c 100644 --- a/web/template/footer.php +++ b/web/template/footer.php @@ -3,7 +3,7 @@
$ver

\n"; + print "

$ver

\n"; } ?> -- cgit v1.2.3-70-g09d2 From 78ace0914eb6a8c6cc39306ab586ab741aa25187 Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Sun, 5 Oct 2008 20:24:57 -0400 Subject: Show developer-TUs their total community packages. This closes: FS#11561 - Devs in AUR can't see their packages in Community Thanks to Hugo Doria for the original patch. Signed-off-by: Loui Chang Signed-off-by: Callan Barrett --- web/lib/stats.inc | 2 +- web/template/stats/user_table.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'web/lib') diff --git a/web/lib/stats.inc b/web/lib/stats.inc index e659210..6fbc033 100644 --- a/web/lib/stats.inc +++ b/web/lib/stats.inc @@ -29,7 +29,7 @@ function user_table($user, $dbh) # If the user is a TU calculate the number of the packages $atype = account_from_sid($_COOKIE["AURSID"]); - if ($atype == 'Trusted User') { + if (($atype == 'Trusted User') || ($atype == 'Developer')) { $result = db_query(sprintf($base_q, 'community'), $dbh); $row = mysql_fetch_row($result); $maintainer_community_count = $row[0]; diff --git a/web/template/stats/user_table.php b/web/template/stats/user_table.php index b844662..ec71999 100644 --- a/web/template/stats/user_table.php +++ b/web/template/stats/user_table.php @@ -13,7 +13,7 @@ - + -- cgit v1.2.3-70-g09d2 From 8f5882e68deec6a8780653ae537aea7aa02283c3 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sun, 5 Oct 2008 01:46:31 +0800 Subject: Convert package flagging to a function Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/html/packages.php | 101 +++----------------------------------------------- web/lib/pkgfuncs.inc | 74 +++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 96 deletions(-) (limited to 'web/lib') diff --git a/web/html/packages.php b/web/html/packages.php index 4cfe9c4..317583f 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -37,106 +37,17 @@ if (isset($_COOKIE["AURSID"])) { # grab the list of Package IDs to be operated on # isset($_POST["IDs"]) ? $ids = $_POST["IDs"] : $ids = array(); -#isset($_REQUEST["All_IDs"]) ? -# $all_ids = explode(":", $_REQUEST["All_IDs"]) : -# $all_ids = array(); - # determine what button the visitor clicked # if ($_POST['action'] == "do_Flag" || isset($_POST['do_Flag'])) { - if (!$atype) { - print __("You must be logged in before you can flag packages."); - print "
\n"; - - } else { - - if (!empty($ids)) { - $dbh = db_connect(); - - # Flag the packages in $ids array - # - $first = 1; - while (list($pid, $v) = each($ids)) { - if ($first) { - $first = 0; - $flag = $pid; - } else { - $flag .= ", ".$pid; - } - } - $q = "UPDATE Packages SET OutOfDate = 1 "; - $q.= "WHERE ID IN (" . $flag . ")"; - db_query($q, $dbh); - - print "

\n"; - print __("The selected packages have been flagged out-of-date."); - print "

\n"; - - # notification by tardo. - $f_name = username_from_sid($_COOKIE['AURSID']); - $f_email = email_from_sid($_COOKIE['AURSID']); - $f_uid = uid_from_sid($_COOKIE['AURSID']); - $q = "SELECT Packages.Name, Users.Email, Packages.ID "; - $q.= "FROM Packages, Users "; - $q.= "WHERE Packages.ID IN (" . $flag .") "; - $q.= "AND Users.ID = Packages.MaintainerUID "; - $q.= "AND Users.ID != " . $f_uid; - $result = db_query($q, $dbh); - if (mysql_num_rows($result)) { - while ($row = mysql_fetch_assoc($result)) { - # construct email - $body = "Your package " . $row['Name'] . " has been flagged out of date by " . $f_name . ". You may view your package at:\nhttp://aur.archlinux.org/packages.php?do_Details=1&ID=" . $row['ID']; - $body = wordwrap($body, 70); - $headers = "To: ".$row['Email']."\nReply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n"; - @mail(' ', "AUR Out-of-date Notification for ".$row['Name'], $body, $headers); - } - } - - } else { - print "

\n"; - print __("You did not select any packages to flag."); - print "

\n"; - } - } - + print "

"; + print pkg_flag($atype, $ids, True); + print "

"; } elseif ($_POST['action'] == "do_UnFlag" || isset($_POST['do_UnFlag'])) { - if (!$atype) { - print __("You must be logged in before you can unflag packages."); - print "
\n"; - - } else { - - if (!empty($ids)) { - $dbh = db_connect(); - - # Un-Flag the packages in $ids array - # - $first = 1; - while (list($pid, $v) = each($ids)) { - if ($first) { - $first = 0; - $unflag = $pid; - } else { - $unflag .= ", ".$pid; - } - } - $q = "UPDATE Packages SET OutOfDate = 0 "; - $q.= "WHERE ID IN (" . $unflag . ")"; - db_query($q, $dbh); - - print "

\n"; - print __("The selected packages have been unflagged."); - print "

\n"; - } else { - print "

\n"; - print __("You did not select any packages to unflag."); - print "

\n"; - } - - - } - + print "

"; + print pkg_flag($atype, $ids, False); + print "

"; } elseif ($_POST['action'] == "do_Disown" || isset($_POST['do_Disown'])) { if (!$atype) { print __("You must be logged in before you can disown packages."); diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index 5ba56da..a508a0b 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -985,4 +985,76 @@ function pkg_search_page($SID="") { return; } -?> +function pkg_flag ($atype, $ids, $action = True) { + if (!$atype) { + if ($action) { + return __("You must be logged in before you can flag packages."); + } else { + return __("You must be logged in before you can unflag packages."); + } + } + + if (empty($ids)) { + if ($action) { + return __("You did not select any packages to flag."); + } else { + return __("You did not select any packages to unflag."); + } + } + + foreach ($ids as $pid => $v) { + if (!is_numeric($pid)) { + if ($action) { + return __("You did not select any packages to flag."); + } else { + return __("You did not select any packages to unflag."); + } + } + } + + $dbh = db_connect(); + + $first = 1; + foreach ($ids as $pid => $v) { + if ($first) { + $first = 0; + $flag = $pid; + } else { + $flag .= ", " . $pid; + } + } + + $ood = $action ? 1 : 0; + $q = "UPDATE Packages SET OutOfDate = " . $ood; + $q.= " WHERE ID IN (" . $flag . ")"; + + db_query($q, $dbh); + + if ($action) { + # Notify of flagging by email + $f_name = username_from_sid($_COOKIE['AURSID']); + $f_email = email_from_sid($_COOKIE['AURSID']); + $f_uid = uid_from_sid($_COOKIE['AURSID']); + $q = "SELECT Packages.Name, Users.Email, Packages.ID "; + $q.= "FROM Packages, Users "; + $q.= "WHERE Packages.ID IN (" . $flag .") "; + $q.= "AND Users.ID = Packages.MaintainerUID "; + $q.= "AND Users.ID != " . $f_uid; + $result = db_query($q, $dbh); + if (mysql_num_rows($result)) { + while ($row = mysql_fetch_assoc($result)) { + # construct email + $body = "Your package " . $row['Name'] . " has been flagged out of date by " . $f_name . ". You may view your package at:\nhttp://aur.archlinux.org/packages.php?ID=" . $row['ID']; + $body = wordwrap($body, 70); + $headers = "To: ".$row['Email']."\nReply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n"; + @mail(' ', "AUR Out-of-date Notification for ".$row['Name'], $body, $headers); + } + } + } + + if ($action) { + return __("The selected packages have been flagged out-of-date."); + } else { + return __("The selected packages have been unflagged."); + } +} -- cgit v1.2.3-70-g09d2 From a447281d4f5ce2071ebc81b375c70ae44231b046 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sat, 4 Oct 2008 03:42:34 +0800 Subject: Convert package deletion to a function Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/html/packages.php | 90 +++------------------------------------------------ web/lib/pkgfuncs.inc | 73 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 86 deletions(-) (limited to 'web/lib') diff --git a/web/html/packages.php b/web/html/packages.php index 317583f..bc3ed18 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -22,7 +22,7 @@ if (isset($_GET['ID'])) { $title = __("Packages"); } -html_header($title); # print out the HTML header +html_header($title); # get login privileges # @@ -95,91 +95,9 @@ if ($_POST['action'] == "do_Flag" || isset($_POST['do_Flag'])) { } elseif ($_POST['action'] == "do_Delete" || isset($_POST['do_Delete'])) { - if (!$atype) { - print __("You must be logged in before you can disown packages."); - print "
\n"; - } else { - # Delete the packages in $ids array (but only if they are Unsupported) - # - if (!empty($ids)) { - $dbh = db_connect(); - - # Delete the packages in $ids array - # - $first = 1; - while (list($pid, $v) = each($ids)) { - if ($first) { - $first = 0; - $delete = $pid; - } else { - $delete .= ", ".$pid; - } - } - - $field = "MaintainerUID"; - - # Only grab Unsupported packages that "we" own or are not owned at all - # - $ids_to_delete = array(); - $q = "SELECT Packages.ID FROM Packages, PackageLocations "; - $q.= "WHERE Packages.ID IN (" . $delete . ") "; - $q.= "AND Packages.LocationID = PackageLocations.ID "; - $q.= "AND PackageLocations.Location = 'unsupported' "; - # If they're a TU or dev, can always delete, otherwise check ownership - # - if ($atype == "Trusted User" || $atype == "Developer") { - $result = db_query($q, $dbh); - } - if ($result != Null && mysql_num_rows($result) > 0) { - while ($row = mysql_fetch_assoc($result)) { - $ids_to_delete[] = $row['ID']; - } - } - if (!empty($ids_to_delete)) { - # These are the packages that are safe to delete - # - foreach ($ids_to_delete as $id) { - # delete from PackageVotes - $q = "DELETE FROM PackageVotes WHERE PackageID = " . $id; - $result = db_query($q, $dbh); - - # delete from PackageDepends - $q = "DELETE FROM PackageDepends WHERE PackageID = " . $id; - $result = db_query($q, $dbh); - - # delete from PackageSources - $q = "DELETE FROM PackageSources WHERE PackageID = " . $id; - $result = db_query($q, $dbh); - - # delete from PackageComments - $q = "DELETE FROM PackageComments WHERE PackageID = " . $id; - $result = db_query($q, $dbh); - - # delete from Packages - $q = "DELETE FROM Packages WHERE ID = " . $id; - $result = db_query($q, $dbh); - - # delete from CommentNotify - $q = "DELETE FROM CommentNotify WHERE PkgID = " . $id; - $result = db_query($q, $dbh); - - # Print the success message - print "

\n"; - print __("The selected packages have been deleted."); - print "

\n"; - } - } else { - print "

\n"; - print __("None of the selected packages could be deleted."); - print "

\n"; - } # end if (!empty($ids_to_delete)) - } else { - print "

\n"; - print __("You did not select any packages to delete."); - print "

\n"; - } # end if (!empty($ids)) - } # end if (!atype) - + print "

"; + print pkg_delete($atype, $ids, False); + print "

"; } elseif ($_POST['action'] == "do_Adopt" || isset($_POST['do_Adopt'])) { if (!$atype) { print __("You must be logged in before you can adopt packages."); diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index a508a0b..c952b85 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -1058,3 +1058,76 @@ function pkg_flag ($atype, $ids, $action = True) { return __("The selected packages have been unflagged."); } } + +function pkg_delete ($atype, $ids) { + if (!$atype) { + return __("You must be logged in before you can disown packages."); + } + + if (empty($ids)) { + return __("You did not select any packages to delete."); + } + + # Delete the packages in $ids array (but only if they are Unsupported) + # + $dbh = db_connect(); + + # Delete the packages in $ids array + # + $first = 1; + foreach ($ids as $pid => $v) { + if ($first) { + $first = 0; + $delete = $pid; + } else { + $delete .= ", ".$pid; + } + } + + $field = "MaintainerUID"; + + # Only grab Unsupported packages that "we" own or are not owned at all + $ids_to_delete = array(); + $q = "SELECT Packages.ID FROM Packages, PackageLocations "; + $q.= "WHERE Packages.ID IN (" . $delete . ") "; + $q.= "AND Packages.LocationID = PackageLocations.ID "; + $q.= "AND PackageLocations.Location = 'unsupported' "; + + # If they're a TU or dev, can delete + if ($atype == "Trusted User" || $atype == "Developer") { + $result = db_query($q, $dbh); + } + + if ($result != Null && mysql_num_rows($result) > 0) { + while ($row = mysql_fetch_assoc($result)) { + $ids_to_delete[] = $row['ID']; + } + } + + if (empty($ids_to_delete)) { + return __("None of the selected packages could be deleted."); + } + + # These are the packages that are safe to delete + foreach ($ids_to_delete as $id) { + $q = "DELETE FROM PackageVotes WHERE PackageID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM PackageDepends WHERE PackageID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM PackageSources WHERE PackageID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM PackageComments WHERE PackageID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM Packages WHERE ID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM CommentNotify WHERE PkgID = " . $id; + $result = db_query($q, $dbh); + } + + return __("The selected packages have been deleted."); +} -- cgit v1.2.3-70-g09d2 From 5d4303d0b6afacb2b3a8731bdb9fdbd6c40f5c0e Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sun, 5 Oct 2008 02:13:35 +0800 Subject: Convert package adoption/disowning to a function Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/html/packages.php | 100 +++----------------------------------------------- web/lib/pkgfuncs.inc | 58 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 94 deletions(-) (limited to 'web/lib') diff --git a/web/html/packages.php b/web/html/packages.php index bc3ed18..5935ebd 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -49,105 +49,17 @@ if ($_POST['action'] == "do_Flag" || isset($_POST['do_Flag'])) { print pkg_flag($atype, $ids, False); print "

"; } elseif ($_POST['action'] == "do_Disown" || isset($_POST['do_Disown'])) { - if (!$atype) { - print __("You must be logged in before you can disown packages."); - print "
\n"; - - } else { - # Disown the packages in $ids array - # - if (!empty($ids)) { - $dbh = db_connect(); - - # Disown the packages in $ids array - # - $first = 1; - while (list($pid, $v) = each($ids)) { - if ($first) { - $first = 0; - $disown = $pid; - } else { - $disown .= ", ".$pid; - } - } - - $field = "MaintainerUID"; - $q = "UPDATE Packages "; - $q.= "SET ".$field." = 0 "; - $q.= "WHERE ID IN (" . $disown . ") "; - # If a user is a TU or dev they can disown any package - if ($atype == "User") { - $q.= "AND ".$field." = ".uid_from_sid($_COOKIE["AURSID"]); - } - db_query($q, $dbh); - - print "

\n"; - print __("The selected packages have been disowned."); - print "

\n"; - } else { - print "

\n"; - print __("You did not select any packages to disown."); - print "

\n"; - } - - - } - - + print "

"; + print pkg_adopt($atype, $ids, False); + print "

"; } elseif ($_POST['action'] == "do_Delete" || isset($_POST['do_Delete'])) { print "

"; print pkg_delete($atype, $ids, False); print "

"; } elseif ($_POST['action'] == "do_Adopt" || isset($_POST['do_Adopt'])) { - if (!$atype) { - print __("You must be logged in before you can adopt packages."); - print "
\n"; - - } else { - # Adopt the packages in $ids array - # - if (!empty($ids)) { - $dbh = db_connect(); - - # Adopt the packages in $ids array - # - $first = 1; - while (list($pid, $v) = each($ids)) { - if ($first) { - $first = 0; - $adopt = $pid; - } else { - $adopt .= ", ".$pid; - } - } - - $field = "MaintainerUID"; - # NOTE: Only "orphaned" packages can be adopted at a particular - # user class (TU/Dev or User). - # - $q = "UPDATE Packages "; - $q.= "SET ".$field." = ".uid_from_sid($_COOKIE["AURSID"])." "; - $q.= "WHERE ID IN (" . $adopt . ") "; - if ($atype == "User") - { - # Regular users may only adopt orphan packages from unsupported - # FIXME: We assume that LocationID for unsupported is "2" - $q.= "AND ".$field." = 0"; - $q.= " AND LocationID = 2"; - } - db_query($q, $dbh); - - print "

\n"; - print __("The selected packages have been adopted."); - print "

\n"; - } else { - print "

\n"; - print __("You did not select any packages to adopt."); - print "

\n"; - } - } - - + print "

"; + print pkg_adopt($atype, $ids, True); + print "

"; } elseif ($_POST['action'] == "do_Vote" || isset($_POST['do_Vote'])) { if (!$atype) { print __("You must be logged in before you can vote for packages."); diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index c952b85..415f3e7 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -1131,3 +1131,61 @@ function pkg_delete ($atype, $ids) { return __("The selected packages have been deleted."); } + +function pkg_adopt ($atype, $ids, $action = True) { + if (!$atype) { + if ($action) { + return __("You must be logged in before you can adopt packages."); + } else { + return __("You must be logged in before you can disown packages."); + } + } + + if (empty($ids)) { + if ($action) { + return __("You did not select any packages to adopt."); + } else { + return __("You did not select any packages to disown."); + } + } + + $dbh = db_connect(); + + $first = 1; + foreach ($ids as $pid => $v) { + if ($first) { + $first = 0; + $pkg = $pid; + } else { + $pkg .= ", ".$pid; + } + } + + $field = "MaintainerUID"; + $q = "UPDATE Packages "; + + if ($action) { + $user = uid_from_sid($_COOKIE["AURSID"]); + } else { + $user = 0; + } + + $q.= "SET $field = $user "; + $q.= "WHERE ID IN ($pkg) "; + + if ($action && $atype == "User") { + # Regular users may only adopt orphan packages from unsupported + $q.= "AND $field = 0 "; + $q.= "AND LocationID = 2 "; + } else if ($atype == "User") { + $q.= "AND $field = " . uid_from_sid($_COOKIE["AURSID"]); + } + + db_query($q, $dbh); + + if ($action) { + return __("The selected packages have been adopted."); + } else { + return __("The selected packages have been disowned."); + } +} -- cgit v1.2.3-70-g09d2 From 132fd7cfc791a76f084140b2901018a046160b84 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sun, 5 Oct 2008 02:54:13 +0800 Subject: Convert package voting to a function Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/html/packages.php | 112 +++----------------------------------------------- web/lib/pkgfuncs.inc | 77 ++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 106 deletions(-) (limited to 'web/lib') diff --git a/web/html/packages.php b/web/html/packages.php index 5935ebd..91b0e6e 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -61,113 +61,13 @@ if ($_POST['action'] == "do_Flag" || isset($_POST['do_Flag'])) { print pkg_adopt($atype, $ids, True); print "

"; } elseif ($_POST['action'] == "do_Vote" || isset($_POST['do_Vote'])) { - if (!$atype) { - print __("You must be logged in before you can vote for packages."); - print "
\n"; - - } else { - # vote on the packages in $ids array. - # - if (!empty($ids)) { - $dbh = db_connect(); - $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]); - $uid = uid_from_sid($_COOKIE["AURSID"]); - # $vote_ids will contain the string of Package.IDs that - # the visitor hasn't voted for already - # - $first = 1; - while (list($pid, $v) = each($ids)) { - if (!isset($my_votes[$pid])) { - # cast a vote for this package - # - if ($first) { - $first = 0; - $vote_ids = $pid; - $vote_clauses = "(".$uid.", ".$pid.")"; - } else { - $vote_ids .= ", ".$pid; - $vote_clauses .= ", (".$uid.", ".$pid.")"; - } - } - } - # only vote for packages the user hasn't already voted for - # - $q = "UPDATE Packages SET NumVotes = NumVotes + 1 "; - $q.= "WHERE ID IN (".$vote_ids.")"; - db_query($q, $dbh); - - $q = "INSERT INTO PackageVotes (UsersID, PackageID) VALUES "; - $q.= $vote_clauses; - db_query($q, $dbh); - - # Update the LastVoted field for this user - # - $q = "UPDATE Users SET LastVoted = UNIX_TIMESTAMP() "; - $q.= "WHERE ID = ".$uid; - db_query($q, $dbh); - - print "

\n"; - print __("Your votes have been cast for the selected packages."); - print "

\n"; - - } else { - print "

\n"; - print __("You did not select any packages to vote for."); - print "

\n"; - } - } - - + print "

"; + print pkg_vote($atype, $ids, True); + print "

"; } elseif ($_POST['action'] == "do_UnVote" || isset($_POST['do_UnVote'])) { - if (!$atype) { - print __("You must be logged in before you can un-vote for packages."); - print "
\n"; - - } else { - # un-vote on the packages in $ids array. - # - if (!empty($ids)) { - $dbh = db_connect(); - $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]); - $uid = uid_from_sid($_COOKIE["AURSID"]); - # $unvote_ids will contain the string of Package.IDs that - # the visitor has voted for and wants to unvote. - # - $first = 1; - while (list($pid, $v) = each($ids)) { - if (isset($my_votes[$pid])) { - # cast a un-vote for this package - # - if ($first) { - $first = 0; - $unvote_ids = $pid; - } else { - $unvote_ids .= ", ".$pid; - } - } - } - # only un-vote for packages the user has already voted for - # - $q = "UPDATE Packages SET NumVotes = NumVotes - 1 "; - $q.= "WHERE ID IN (".$unvote_ids.")"; - db_query($q, $dbh); - - $q = "DELETE FROM PackageVotes WHERE UsersID = ".$uid." "; - $q.= "AND PackageID IN (".$unvote_ids.")"; - db_query($q, $dbh); - - print "

\n"; - print __("Your votes have been removed from the selected packages."); - print "

\n"; - - } else { - print "

\n"; - print __("You did not select any packages to un-vote for."); - print "

\n"; - } - } - - + print "

"; + print pkg_vote($atype, $ids, False); + print "

"; } elseif (isset($_GET["ID"])) { if (!intval($_GET["ID"])) { diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index 415f3e7..7fe3f31 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -1189,3 +1189,80 @@ function pkg_adopt ($atype, $ids, $action = True) { return __("The selected packages have been disowned."); } } + +function pkg_vote ($atype, $ids, $action = True) { + if (!$atype) { + if ($action) { + return __("You must be logged in before you can vote for packages."); + } else { + return __("You must be logged in before you can un-vote for packages."); + } + } + + if (empty($ids)) { + if ($action) { + return __("You did not select any packages to vote for."); + } else { + return __("Your votes have been removed from the selected packages."); + } + } + + $dbh = db_connect(); + $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]); + $uid = uid_from_sid($_COOKIE["AURSID"]); + + $first = 1; + foreach ($ids as $pid => $v) { + if ($action) { + $check = !isset($my_votes[$pid]); + } else { + $check = isset($my_votes[$pid]); + } + + if ($check) { + if ($first) { + $first = 0; + $vote_ids = $pid; + if ($action) { + $vote_clauses = "($uid, $pid)"; + } + } else { + $vote_ids .= ", $pid"; + if ($action) { + $vote_clauses .= ", ($uid, $pid)"; + } + } + } + } + + # only vote for packages the user hasn't already voted for + # + $op = $action ? "+" : "-"; + $q = "UPDATE Packages SET NumVotes = NumVotes $op 1 "; + $q.= "WHERE ID IN ($vote_ids)"; + + db_query($q, $dbh); + + if ($action) { + $q = "INSERT INTO PackageVotes (UsersID, PackageID) VALUES "; + $q.= $vote_clauses; + } else { + $q = "DELETE FROM PackageVotes WHERE UsersID = $uid "; + $q.= "AND PackageID IN ($vote_ids)"; + } + + db_query($q, $dbh); + + if ($action) { + $q = "UPDATE Users SET LastVoted = UNIX_TIMESTAMP() "; + $q.= "WHERE ID = $uid"; + + db_query($q, $dbh); + } + + if ($action) { + return __("Your votes have been cast for the selected packages."); + } else { + return __("Your votes have been removed from the selected packages."); + } +} -- cgit v1.2.3-70-g09d2