[geeklog-cvs] geeklog: A first attempt to reduce the amount of special handlin...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sun Feb 21 14:53:32 EST 2010


changeset 7743:ab9277207ba9
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/ab9277207ba9
user: Dirk Haun <dirk at haun-online.de>
date: Sat Feb 20 21:49:42 2010 +0100
description:
A first attempt to reduce the amount of special handling in moderation.php

diffstat:

 public_html/admin/moderation.php |  75 +++++++++++++++++--------------------
 system/lib-story.php             |  57 ++++++++++++++++++++++++++--
 2 files changed, 88 insertions(+), 44 deletions(-)

diffs (205 lines):

diff -r 63f9bc6089ca -r ab9277207ba9 public_html/admin/moderation.php
--- a/public_html/admin/moderation.php	Sat Feb 20 16:33:27 2010 +0100
+++ b/public_html/admin/moderation.php	Sat Feb 20 21:49:42 2010 +0100
@@ -508,34 +508,28 @@
 * @return   string              HTML for "command and control" page
 *
 */
-function moderation ($mid, $action, $type, $count)
+function moderation($mid, $action, $type, $count)
 {
     global $_CONF, $_TABLES;
 
     $retval = '';
 
-    switch ($type) {
-    case 'story':
-        $id = 'sid';
-        $table = $_TABLES['stories'];
-        $submissiontable = $_TABLES['storysubmission'];
-        $fields = 'sid,uid,tid,title,introtext,date,postmode';
-        break;
-    case 'comment':
+    if (empty($type)) {
+        // something is terribly wrong, bail
+        $retval .= COM_errorLog("Submission type not set in moderation.php");
+        return $retval;
+    }
+
+    if ($type == 'comment') {
         $id = 'cid';
+        $table = $_TABLES['comments'];
         $submissiontable = $_TABLES['commentsubmissions'];
         $sidArray[] = '';
-        break;
-    default:
-        if (strlen($type) <= 0) {
-            // something is terribly wrong, bail
-            $retval .= COM_errorLog("Unable to find type of $type in moderation() in moderation.php");
-            return $retval;
-        }
+    } else {
         list($id, $table, $fields, $submissiontable) = PLG_getModerationValues($type);
     }
 
-    // Set true if an valid action other than delete_all is selected
+    // Set true if a valid action other than delete_all is selected
     $formaction = false;
 
     for ($i = 0; $i < $count; $i++) {
@@ -547,19 +541,19 @@
 
         switch ($action[$i]) {
         case 'delete':
-            if (!empty ($type) && ($type <> 'story') && ($type <> 'draft')) {
-                // There may be some plugin specific processing that needs to
-                // happen first.
-                $retval .= PLG_deleteSubmission($type, $mid[$i]);
-            }
             if (empty($mid[$i])) {
                 $retval .= COM_errorLog("moderation.php just tried deleting everything in table $submissiontable because it got an empty id.  Please report this immediately to your site administrator");
                 return $retval;
             }
+
             if ($type == 'draft') {
                 STORY_deleteStory($mid[$i]);
             } else {
-                DB_delete($submissiontable,"$id",$mid[$i]);
+                // There may be some plugin specific processing that needs to
+                // happen first.
+                $retval .= PLG_deleteSubmission($type, $mid[$i]);
+
+                DB_delete($submissiontable, $id, $mid[$i]);
             }
             break;
 
@@ -607,22 +601,22 @@
             break;
         }
     }
-    
+
     // after loop update comment tree and count for each story
     if (isset($sidArray)) {
-        foreach($sidArray as $sid) {
+        foreach ($sidArray as $sid) {
             CMT_rebuildTree($sid);
-            //update comment count of stories;
-            $comments = DB_count ($_TABLES['comments'], 'sid', $sid);
-            DB_change ($_TABLES['stories'], 'comments', $comments, 'sid', $sid);
+            // update comment count of stories;
+            $comments = DB_count($_TABLES['comments'], 'sid', $sid);
+            DB_change($_TABLES['stories'], 'comments', $comments, 'sid', $sid);
         }
     }
-    
-    //Add new comment users to group comment.submit group
+
+    // Add new comment users to group comment.submit group
     if (isset($_POST['publishfuture']) ) {
         for ($i = 0; $i < count($_POST['publishfuture']); $i++ ) {
             $uid =  COM_applyFilter($_POST['publishfuture'][$i], true);
-            if ($uid > 1 && !SEC_inGroup('Comment Submitters', $uid) ) {
+            if ($uid > 1 && !SEC_inGroup('Comment Submitters', $uid)) {
                 SEC_addUserToGroup($uid, 'Comment Submitters');
             }
         }
@@ -633,15 +627,16 @@
     if (!$formaction AND isset($_POST['delitem'])) {
         foreach ($_POST['delitem'] as $delitem) {
             $delitem = COM_applyFilter($delitem);
-            if (!empty ($type) && ($type <> 'story') && ($type <> 'draft')) {
-                // There may be some plugin specific processing that needs to
-                // happen first.
-                $retval .= PLG_deleteSubmission($type, $delitem);
-            }
-            if ($type == 'draft') {
-                STORY_deleteStory($delitem);
-            } else {
-                DB_delete($submissiontable,"$id",$delitem);
+            if (! empty($delitem)) {
+                if ($type == 'draft') {
+                    STORY_deleteStory($delitem);
+                } else {
+                    // There may be some plugin specific processing that needs
+                    // to happen first.
+                    $retval .= PLG_deleteSubmission($type, $delitem);
+
+                    DB_delete($submissiontable, $id, $delitem);
+                }
             }
         }
     }
diff -r 63f9bc6089ca -r ab9277207ba9 system/lib-story.php
--- a/system/lib-story.php	Sat Feb 20 16:33:27 2010 +0100
+++ b/system/lib-story.php	Sat Feb 20 21:49:42 2010 +0100
@@ -896,16 +896,65 @@
     CMT_updateCommentcodes();
 }
 
+
+/*
+ * Implement *some* of the Plugin API functions for stories. While stories
+ * aren't a plugin (and likely never will be), implementing some of the API
+ * functions here will save us from doing special handling elsewhere.
+ */
+
 /**
- * Return true since this component supports webservices
- *
- * @return  bool	True, if webservices are supported
- */
+* Return true since this component supports webservices
+*
+* @return   bool        True, if webservices are supported
+*
+*/
 function plugin_wsEnabled_story()
 {
     return true;
 }
 
+/**
+* Returns list of moderation values
+*
+* The array returned contains (in order): the row 'id' label, main table,
+* moderation fields (comma separated), and submission table
+*
+* @return   array       Returns array of useful moderation values
+*
+*/
+function plugin_moderationvalues_story()
+{
+    global $_TABLES;
+
+    return array(
+        'sid',
+        $_TABLES['stories'],
+        'sid,uid,tid,title,introtext,date,postmode',
+        $_TABLES['storysubmission']
+    );
+}
+
+/**
+* Performs story exclusive work for items deleted by moderation
+*
+* While moderation.php handles the actual removal from the submission
+* table, within this function we handle all other deletion related tasks
+*
+* @param    string  $sid    Identifying string, i.e. the story id
+* @return   string          Any wanted HTML output
+*
+*/
+function plugin_moderationdelete_story($sid)
+{
+    global $_TABLES;
+
+    DB_delete($_TABLES['storysubmission'], 'sid', $sid);
+
+    return '';
+}
+
+
 /*
  * START SERVICES SECTION
  * This section implements the various services offered by the story module



More information about the geeklog-cvs mailing list