cvs: php-master-web /manage user-notes.php

From: Date: Sat, 12 Jun 2004 17:24:09 +0000
Subject: cvs: php-master-web /manage user-notes.php
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-24938@lists.php.net to get a copy of this message
goba Sat Jun 12 13:24:09 2004 EDT Modified files: /php-master-web/manage user-notes.php Log: introduce note_get_by_id() and note_mail_on_action() to get rid of repetitive code http://cvs.php.net/diff.php/php-master-web/manage/user-notes.php?r1=1.43&r2=1.44&ty=u Index: php-master-web/manage/user-notes.php diff -u php-master-web/manage/user-notes.php:1.43 php-master-web/manage/user-notes.php:1.44 --- php-master-web/manage/user-notes.php:1.43 Thu Jun 10 05:21:10 2004 +++ php-master-web/manage/user-notes.php Sat Jun 12 13:24:09 2004 @@ -1,5 +1,5 @@ <?php -// $Id: user-notes.php,v 1.43 2004/06/10 09:21:10 goba Exp $ +// $Id: user-notes.php,v 1.44 2004/06/12 17:24:09 goba Exp $ // Force login before action can be taken include_once 'login.inc'; @@ -7,7 +7,7 @@ include_once 'email-validation.inc'; //require_once 'alert_lib.inc'; // remove comment if alerts are needed -$mailto = $mailfrom = "php-notes@lists.php.net"; +define("NOTES_MAIL", "php-notes@lists.php.net"); $reject_text = 'You are receiving this email because your note posted @@ -119,19 +119,19 @@ switch($action) { case 'approve': if ($id) { - if ($result = db_query("SELECT * FROM note WHERE id=$id")) { - if (!mysql_num_rows ($result)) { - die ("Note #$id doesn't exist. It has probably been deleted/rejected already"); - } - - $row = mysql_fetch_array ($result); + if ($row = note_get_by_id($id)) { if ($row['status'] != 'na') { die ("Note #$id has already been approved"); } if ($row['id'] && db_query("UPDATE note SET status=NULL WHERE id=$id")) { - mail ($mailto, "note $row[id] approved from $row[sect] by $user", "This note has been approved and will appear in the manual\n\n----\n\n".$row['note'], "From: $user@php.net\r\nIn-Reply-To: <note-$id@php.net>"); + note_mail_on_action( + $user, + $id, + "note {$row['id']} approved from {$row['sect']} by $user", + "This note has been approved and will appear in the manual.\n\n----\n\n{$row['note']}" + ); } print "Note #$id has been approved and will appear in the manual"; @@ -141,18 +141,20 @@ case 'reject': case 'delete': if ($id) { - if ($result = db_query("SELECT * FROM note WHERE id=$id")) { - if (!mysql_num_rows ($result)) { - die ("Note #$id doesn't exist. It has probably been deleted/rejected already"); - } + if ($row = note_get_by_id($id)) { - $row = mysql_fetch_array($result); if ($row['id'] && db_query("DELETE FROM note WHERE id=$id")) { // ** alerts ** //$mailto .= get_emails_for_sect($row["sect"]); - mail($mailto,"note $row[id] ".($action == "reject" ? "rejected" : "deleted")." from $row[sect] by $user","Note Submitter: $row[user]\n\n----\n\n".$row['note'],"From: $user@php.net\r\nIn-Reply-To: <note-$id@php.net>"); + $action_taken = ($action == "reject" ? "rejected" : "deleted"); + note_mail_on_action( + $user, + $id, + "note {$row['id'}] $action_taken from {$row['sect']} by $user", + "Note Submitter: {$row['user']}\n\n----\n\n{$row['note']}" + ); if ($action == 'reject') { - mail_user($row['user'], $mailfrom, "note $row[id] rejected and deleted from $row[sect] by notes editor $user",$reject_text."\n\n----- Copy of your note below -----\n\n".$row['note']); + note_mail_user($row['user'], "note $row[id] rejected and deleted from $row[sect] by notes editor $user",$reject_text."\n\n----- Copy of your note below -----\n\n".$row['note']); } } @@ -175,12 +177,7 @@ head(); } - if ($result = db_query("SELECT *,UNIX_TIMESTAMP(ts) AS ts FROM note WHERE id=$id")) { - if (!mysql_num_rows ($result)) { - die ("Note #$id doesn't exist. It has probably been deleted/rejected already"); - } - $row = mysql_fetch_array($result); - } + $row = note_get_by_id($id); $email = isset($email) ? $email : addslashes($row['user']); $sect = isset($sect) ? $sect : addslashes($row['sect']); @@ -190,9 +187,14 @@ // ** alerts ** //$mailto .= get_emails_for_sect($row["sect"]); - mail($mailto,"note $row[id] modified in $row[sect] by $user",stripslashes($note)."\n\n--was--\n$row[note]\n\nhttp://www.php.net/manual/en/$row[sect].php","From: $user@php.net\r\nIn-Reply-To: <note-$id@php.net>"); + note_mail_on_action( + $user, + $id, + "note {$row['id']} modified in {$row['sect']} by $user", + stripslashes($note)."\n\n--was--\n{$row['note']}\n\nhttp://php.net/manual/en/{$row['sect']}.php" + ); if (addslashes($row["sect"]) != $sect) { - mail_user($email, $mailfrom, "note $id moved from $row[sect] to $sect by notes editor $user", "----- Copy of your note below -----\n\n".stripslashes($note)); + note_mail_user($email, "note $id moved from $row[sect] to $sect by notes editor $user", "----- Copy of your note below -----\n\n".stripslashes($note)); } header('Location: user-notes.php?id=' . $id . '&was=' . $action); exit; @@ -301,7 +303,7 @@ } // Send out a mail to the note submitter, with an envelope sender ignoring bounces -function mail_user($mailto, $mailfrom, $subject, $message) +function note_mail_user($mailto, $subject, $message) { $email = clean_antispam($email); if (is_emailable_address($email)) { @@ -309,8 +311,27 @@ $mailto, $subject, $message, - "From: $mailfrom", + "From: ". NOTES_MAIL, "-fbounces-ignored@php.net" ); } +} + +// Return data about a note by its ID +function note_get_by_id($id) +{ + $id = intval($id); + if ($result = db_query("SELECT *, UNIX_TIMESTAMP(ts) AS ts FROM note WHERE id='$id'")) { + if (!mysql_num_rows($result)) { + die("Note #$id doesn't exist. It has probably been deleted/rejected already."); + } + return mysql_fetch_assoc($result); + } + return FALSE; +} + +// Sends out a notification to the mailing list when +// some action is performed on a user note. +function note_mail_on_action($user, $id, $subject, $body) { + mail(NOTES_MAIL, $subject, $body, "From: $user@php.net\r\nIn-Reply-To: <note-$id@php.net>"); }

« previous php.mirrors (#24938) next »