[geeklog-cvs] geeklog: Added delete and cancel buttons to all comment edit forms.

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Thu Aug 19 09:11:02 EDT 2010


changeset 7965:04a766c90c75
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/04a766c90c75
user: Tom <websitemaster at cogeco.net>
date: Thu Aug 19 09:10:00 2010 -0400
description:
Added delete and cancel buttons to all comment edit forms.

diffstat:

 public_html/comment.php                                            |  121 +++++++--
 public_html/docs/history                                           |    2 +
 public_html/layout/professional/comment/commentform.thtml          |    6 +-
 public_html/layout/professional/comment/commentform_advanced.thtml |    6 +-
 system/lib-comment.php                                             |   21 +-
 5 files changed, 118 insertions(+), 38 deletions(-)

diffs (250 lines):

diff -r db06e8ad9f7b -r 04a766c90c75 public_html/comment.php
--- a/public_html/comment.php	Wed Aug 18 20:08:19 2010 -0400
+++ b/public_html/comment.php	Thu Aug 19 09:10:00 2010 -0400
@@ -60,6 +60,42 @@
 // the data being passed in a POST operation
 // echo COM_debug($_POST);
 
+
+/**
+ * Handles a comment submission
+ *
+ * @copyright Vincent Furia 2005
+ * @author Vincent Furia, vinny01 AT users DOT sourceforge DOT net
+ * @return string HTML (possibly a refresh)
+ */
+function handleCancel()
+{
+    global $_CONF;
+    
+    $display = '';
+
+    $type = COM_applyFilter ($_POST['type']);
+    $sid = COM_applyFilter ($_POST['sid']);
+    switch ( $type ) {
+        case 'article':
+            $display = COM_refresh (COM_buildUrl ($_CONF['site_url']
+                . "/article.php?story=$sid"));
+
+            break;
+        default: // assume plugin
+            // Need a way to go back to initial page for plugins.
+            $url = PLG_getItemInfo($type, $sid, 'url');
+            if ($url == '') { // Then plugin doesn't support PLG_getItemInfo
+                $url = $_CONF['site_url'] . '/index.php';
+            }
+            $display = COM_refresh ($url);
+
+            break;
+    }
+
+    return $display;
+}
+
 /**
  * Handles a comment submission
  *
@@ -127,45 +163,51 @@
  * @author Vincent Furia, vinny01 AT users DOT sourceforge DOT net
  * @return string HTML (possibly a refresh)
  */
-function handleDelete()
+function handleDelete($formtype)
 {
     global $_CONF, $_TABLES;
 
     $display = '';
+    
+    if ($formtype == 'editsubmission') {
+        DB_delete($_TABLES['commentsubmissions'], 'cid', COM_applyFilter($_REQUEST['cid'], true));
 
-    $type = COM_applyFilter($_REQUEST['type']);
-    $sid = COM_applyFilter($_REQUEST['sid']);
-
-    switch ($type) {
-    case 'article':
-        $has_editPermissions = SEC_hasRights('story.edit');
-        $result = DB_query("SELECT owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['stories']} WHERE sid = '$sid'");
-        $A = DB_fetchArray($result);
-
-        if ($has_editPermissions && SEC_hasAccess($A['owner_id'],
-                $A['group_id'], $A['perm_owner'], $A['perm_group'],
-                $A['perm_members'], $A['perm_anon']) == 3) {
-            CMT_deleteComment(COM_applyFilter($_REQUEST['cid'], true), $sid,
-                              'article');
-            $comments = DB_count($_TABLES['comments'], 'sid', $sid);
-            DB_change($_TABLES['stories'], 'comments', $comments,
-                      'sid', $sid);
-            $display .= COM_refresh(COM_buildUrl ($_CONF['site_url']
-                                    . "/article.php?story=$sid") . '#comments');
-        } else {
-            COM_errorLog("User {$_USER['username']} (IP: {$_SERVER['REMOTE_ADDR']}) tried to illegally delete comment $cid from $type $sid");
-            $display .= COM_refresh($_CONF['site_url'] . '/index.php');
+        $display = COM_refresh ( $_CONF['site_admin_url'] . '/moderation.php');      
+    } else {
+        $type = COM_applyFilter($_REQUEST['type']);
+        $sid = COM_applyFilter($_REQUEST['sid']);    
+        
+        switch ($type) {
+        case 'article':
+            $has_editPermissions = SEC_hasRights('story.edit');
+            $result = DB_query("SELECT owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['stories']} WHERE sid = '$sid'");
+            $A = DB_fetchArray($result);
+    
+            if ($has_editPermissions && SEC_hasAccess($A['owner_id'],
+                    $A['group_id'], $A['perm_owner'], $A['perm_group'],
+                    $A['perm_members'], $A['perm_anon']) == 3) {
+                CMT_deleteComment(COM_applyFilter($_REQUEST['cid'], true), $sid,
+                                  'article');
+                $comments = DB_count($_TABLES['comments'], 'sid', $sid);
+                DB_change($_TABLES['stories'], 'comments', $comments,
+                          'sid', $sid);
+                $display .= COM_refresh(COM_buildUrl ($_CONF['site_url']
+                                        . "/article.php?story=$sid") . '#comments');
+            } else {
+                COM_errorLog("User {$_USER['username']} (IP: {$_SERVER['REMOTE_ADDR']}) tried to illegally delete comment $cid from $type $sid");
+                $display .= COM_refresh($_CONF['site_url'] . '/index.php');
+            }
+            break;
+    
+        default: // assume plugin
+            if (!($display = PLG_commentDelete($type, 
+                                COM_applyFilter($_REQUEST['cid'], true), $sid))) {
+                $display = COM_refresh($_CONF['site_url'] . '/index.php');
+            }
+            break;
         }
-        break;
-
-    default: // assume plugin
-        if (!($display = PLG_commentDelete($type, 
-                            COM_applyFilter($_REQUEST['cid'], true), $sid))) {
-            $display = COM_refresh($_CONF['site_url'] . '/index.php');
-        }
-        break;
     }
-
+    
     return $display;
 }
 
@@ -344,6 +386,10 @@
 if (!empty ($_REQUEST['mode'])) {
     $mode = COM_applyFilter ($_REQUEST['mode']);
 }
+$formtype = '';
+if (!empty ($_REQUEST['formtype'])) {
+    $formtype = COM_applyFilter ($_REQUEST['formtype']);
+}
 switch ($mode) {
 case $LANG03[28]: // Preview Changes (for edit)
 case $LANG03[34]: // Preview Submission changes (for edit)
@@ -370,9 +416,10 @@
     $display .= handleSubmit();  // moved to function for readibility
     break;
 
+case $LANG_ADMIN['delete']:    
 case 'delete':
     if (SEC_checkToken()) {
-        $display .= handleDelete();  // moved to function for readibility
+        $display .= handleDelete($formtype);  // moved to function for readibility
     } else {
         $display .= COM_refresh($_CONF['site_url'] . '/index.php');
     }
@@ -430,7 +477,13 @@
     }
     $display = COM_refresh($_CONF['site_url'] . '/index.php');
     break;
-
+case $LANG_ADMIN['cancel']:
+    if ($formtype == 'editsubmission') {
+        $display = COM_refresh ( $_CONF['site_admin_url'] . '/moderation.php');        
+    } else {
+        $display .= handleCancel();  // moved to function for readibility
+    }
+    break;
 default:  // New Comment
     $abort = false;
     $sid = '';
diff -r db06e8ad9f7b -r 04a766c90c75 public_html/docs/history
--- a/public_html/docs/history	Wed Aug 18 20:08:19 2010 -0400
+++ b/public_html/docs/history	Thu Aug 19 09:10:00 2010 -0400
@@ -3,6 +3,8 @@
 ??? ?, 2010 (1.7.1)
 -----------
 
+- Added cancel and delete buttons to comment edit and submission forms when needed.
+  (Feature #0000981) [Tom]
 - Reverted parts of the changes for bug #0001057: Do _not_ escape curly braces
   when displaying a block's content (bug #0001156). If you run into the problem
   that words in curly braces inside blocks are interpreted as template
diff -r db06e8ad9f7b -r 04a766c90c75 public_html/layout/professional/comment/commentform.thtml
--- a/public_html/layout/professional/comment/commentform.thtml	Wed Aug 18 20:08:19 2010 -0400
+++ b/public_html/layout/professional/comment/commentform.thtml	Thu Aug 19 09:10:00 2010 -0400
@@ -41,7 +41,11 @@
                                                             <li>{lang_instr_line4}</li>
                                                             <li>{lang_instr_line5}</li></ul>
                                                             <input type="submit" name="mode" value="{lang_preview}"{xhtml}>
-                                                            {save_option} {notification}
+                                                            <input type="hidden" name="formtype" value="{formtype}"{xhtml}>
+                                                            {save_option} 
+                                                            <input type="submit" value="{lang_cancel}" name="mode"{xhtml}> 
+                                                            {delete_option} 
+                                                            {notification}
                                                         </td>
                                                     </tr>
                                                 </table>
diff -r db06e8ad9f7b -r 04a766c90c75 public_html/layout/professional/comment/commentform_advanced.thtml
--- a/public_html/layout/professional/comment/commentform_advanced.thtml	Wed Aug 18 20:08:19 2010 -0400
+++ b/public_html/layout/professional/comment/commentform_advanced.thtml	Thu Aug 19 09:10:00 2010 -0400
@@ -55,7 +55,11 @@
                                                             <li>{lang_instr_line4}</li>
                                                             <li>{lang_instr_line5}</li></ul>
                                                             <input type="submit" name="mode" value="{lang_preview}"{xhtml}>
-                                                            {save_option} {notification}
+                                                            <input type="hidden" name="formtype" value="{formtype}"{xhtml}>
+                                                            {save_option} 
+                                                            <input type="submit" value="{lang_cancel}" name="mode"{xhtml}> 
+                                                            {delete_option} 
+                                                            {notification}
                                                         </td>
                                                     </tr>
                                                 </table>
diff -r db06e8ad9f7b -r 04a766c90c75 system/lib-comment.php
--- a/system/lib-comment.php	Wed Aug 18 20:08:19 2010 -0400
+++ b/system/lib-comment.php	Thu Aug 19 09:10:00 2010 -0400
@@ -744,8 +744,7 @@
 */
 function CMT_commentForm($title,$comment,$sid,$pid='0',$type,$mode,$postmode)
 {
-    global $_CONF, $_TABLES, $_USER, $LANG03, $LANG12;
-           $LANG_ACCESS;
+    global $_CONF, $_TABLES, $_USER, $LANG03, $LANG12, $LANG_ADMIN, $LANG_ACCESS, $MESSAGE;
 
     $retval = '';
 
@@ -959,6 +958,24 @@
                 $comment_template->set_var('lang_logoutorcreateaccount',
                     $LANG03[03]);
             }
+            
+            $comment_template->set_var('lang_cancel', $LANG_ADMIN['cancel']); 
+
+            if ($mode == 'editsubmission' OR $mode == 'edit' OR $mode == $LANG03[34] OR $mode == $LANG03[28]) {
+                $delbutton = '<input type="submit" value="' . $LANG_ADMIN['delete']
+                           . '" name="mode"%s' . XHTML . '>';            
+                $jsconfirm = ' onclick="return confirm(\'' . $MESSAGE[76] . '\');"';
+                $comment_template->set_var ('delete_option',
+                                          sprintf ($delbutton, $jsconfirm));            
+            }
+            if ($mode == 'editsubmission' OR $mode == $LANG03[34]) { // Preview Submission changes (for edit)
+                $comment_template->set_var('formtype', 'editsubmission');
+            } elseif ($mode == 'edit' OR $mode == $LANG03[28]) { // Preview changes (for edit)
+                $comment_template->set_var('formtype', 'edit');
+            } else {
+                $comment_template->set_var('formtype', 'new');
+            }    
+            
 
             if ($postmode == 'html') {
                 $comment_template->set_var ('show_texteditor', 'none');



More information about the geeklog-cvs mailing list