[geeklog-cvs] geeklog: Implement partial pseudo plugin API for draft stories s...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sun Feb 21 14:53:35 EST 2010
changeset 7747:7a8ca5e52c23
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/7a8ca5e52c23
user: Dirk Haun <dirk at haun-online.de>
date: Sun Feb 21 10:19:08 2010 +0100
description:
Implement partial pseudo plugin API for draft stories so we can get rid of most of the special handling for draft story "submissions" in moderation.php
diffstat:
public_html/admin/moderation.php | 132 +++++++++++--------------------------------
system/lib-story.php | 90 ++++++++++++++++++++++++++++++
2 files changed, 125 insertions(+), 97 deletions(-)
diffs (truncated from 324 to 300 lines):
diff -r 0517ca14a59a -r 7a8ca5e52c23 public_html/admin/moderation.php
--- a/public_html/admin/moderation.php Sat Feb 20 22:59:16 2010 +0100
+++ b/public_html/admin/moderation.php Sun Feb 21 10:19:08 2010 +0100
@@ -227,7 +227,7 @@
if ($_CONF['listdraftstories'] == 1) {
if (SEC_hasRights('story.edit')) {
- $retval .= draftlist ($token);
+ $retval .= itemlist('story_draft', $token);
}
}
@@ -265,7 +265,6 @@
require_once $_CONF['path_system'] . 'lib-admin.php';
$retval = '';
- $isplugin = false;
if (empty($type)) {
// something is terribly wrong, bail
@@ -273,6 +272,8 @@
return $retval;
}
+ $isplugin = false;
+
if ($type == 'comment') {
$sql = "SELECT cid AS id,title,comment,date,uid,type,sid "
. "FROM {$_TABLES['commentsubmissions']} "
@@ -292,7 +293,7 @@
$H = $plugin->submissionheading;
$section_title = $plugin->submissionlabel;
$section_help = $helpfile;
- if ($type <> 'story') {
+ if (($type != 'story') && ($type != 'story_draft')) {
$isplugin = true;
}
}
@@ -314,13 +315,19 @@
$data_arr = array();
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray($result);
+ /**
+ * @todo There should be an API for these URLs ...
+ */
if ($isplugin) {
$A['edit'] = $_CONF['site_admin_url'] . '/plugins/' . $type
. '/index.php?mode=editsubmission&id=' . $A[0];
} elseif ($type == 'comment') {
$A['edit'] = $_CONF['site_url'] . '/comment.php'
. '?mode=editsubmission&cid=' . $A[0];
- } else {
+ } elseif ($type == 'story_draft') {
+ $A['edit'] = $_CONF['site_admin_url'] . '/story.php'
+ . '?mode=edit&sid=' . $A[0];
+ } else { // this pretty much only leaves $type == 'story'
$A['edit'] = $_CONF['site_admin_url'] . '/' . $type
. '.php?mode=editsubmission&id=' . $A[0];
}
@@ -335,7 +342,8 @@
array('text' => $H[1], 'field' => 2),
array('text' => $H[2], 'field' => 3),
array('text' => $LANG29[2], 'field' => 'delete'),
- array('text' => $LANG29[1], 'field' => 'approve'));
+ array('text' => $LANG29[1], 'field' => 'approve')
+ );
if ($type == 'comment') {
// data for comment submission headers
$header_arr[6]['text'] = $LANG29[42];
@@ -350,7 +358,7 @@
'no_data' => $LANG29[39],
'form_url' => "{$_CONF['site_admin_url']}/moderation.php"
);
- $form_arr = array("bottom" => '', "top" => '');
+ $form_arr = array('bottom' => '', 'top' => '');
if ($nrows > 0) {
$form_arr['bottom'] = '<input type="hidden" name="type" value="' . $type . '"' . XHTML . '>' . LB
. '<input type="hidden" name="' . CSRF_TOKEN . '" value="' . $token . '"'. XHTML . '>' . LB
@@ -435,70 +443,6 @@
}
/**
-* Displays a list of all the stories that have the 'draft' flag set.
-*
-* When enabled, this will list all the stories that have been marked as
-* 'draft'. Approving a story from this list will clear the draft flag and
-* thus publish the story.
-*
-* @param string $token CSRF token
-* @return string HTML for the list of draft stories
-*
-*/
-function draftlist($token)
-{
- global $_CONF, $_TABLES, $LANG24, $LANG29, $LANG_ADMIN;
-
- require_once $_CONF['path_system'] . 'lib-admin.php';
-
- $retval = '';
-
- $result = DB_query ("SELECT sid AS id,title,UNIX_TIMESTAMP(date) AS day,tid FROM {$_TABLES['stories']} WHERE (draft_flag = 1)" . COM_getTopicSQL ('AND') . COM_getPermSQL ('AND', 0, 3) . " ORDER BY date ASC");
- $nrows = DB_numRows($result);
- $data_arr = array();
-
- for ($i = 0; $i < $nrows; $i++) {
- $A = DB_fetchArray($result);
- $A['edit'] = $_CONF['site_admin_url'] . '/story.php?mode=edit&sid='
- . $A['id'];
- $A['row'] = $i;
- $A['title'] = stripslashes($A['title']);
- $A['tid'] = stripslashes($A['tid']);
- $data_arr[$i] = $A;
- }
-
- $header_arr = array(
- array('text' => $LANG_ADMIN['edit'], 'field' => 0),
- array('text' => $LANG29[10], 'field' => 'title'),
- array('text' => $LANG29[14], 'field' => 'day'),
- array('text' => $LANG29[15], 'field' => 'tid'),
- array('text' => $LANG29[2], 'field' => 'delete'),
- array('text' => $LANG29[1], 'field' => 'approve'));
-
- $text_arr = array('has_menu' => false,
- 'title' => $LANG29[35] . ' (' . $LANG24[34] . ')',
- 'help_url' => 'ccdraftsubmission.html',
- 'no_data' => $LANG29[39],
- 'form_url' => "{$_CONF['site_admin_url']}/moderation.php");
-
- $form_arr = array("bottom" => '', "top" => '');
- if ($nrows > 0) {
- $form_arr['bottom'] = '<input type="hidden" name="type" value="draft"' . XHTML . '>' . LB
- . '<input type="hidden" name="' . CSRF_TOKEN . '" value="' . $token . '"'. XHTML . '>' . LB
- . '<input type="hidden" name="mode" value="moderation"' . XHTML . '>' . LB
- . '<input type="hidden" name="count" value="' . $nrows . '"' . XHTML . '>'
- . '<p align="center"><input type="submit" value="'
- . $LANG_ADMIN['submit'] . '"' . XHTML . '></p>' . LB;
- }
-
- $listoptions = array('chkdelete' => true, 'chkfield' => 'id');
- $table = ADMIN_simpleList('ADMIN_getListField_moderation', $header_arr,
- $text_arr, $data_arr, $listoptions, $form_arr);
- $retval .= $table;
- return $retval;
-}
-
-/**
* Moderates an item
*
* This will actually perform moderation (approve or delete) one or more items
@@ -548,15 +492,11 @@
return $retval;
}
- if ($type == 'draft') {
- STORY_deleteStory($mid[$i]);
- } else {
- // There may be some plugin specific processing that needs to
- // happen first.
- $retval .= PLG_deleteSubmission($type, $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]);
- }
+ DB_delete($submissiontable, $id, $mid[$i]);
break;
case 'approve':
@@ -584,21 +524,23 @@
PLG_itemSaved($A['sid'], 'article');
COM_rdfUpToDateCheck ();
COM_olderStuff ();
- } else if ($type == 'draft') {
- DB_query ("UPDATE {$_TABLES['stories']} SET draft_flag = 0 WHERE sid = '{$mid[$i]}'");
-
- COM_rdfUpToDateCheck ();
- COM_olderStuff ();
- } else if ($type == 'comment') {
+ } elseif ($type == 'comment') {
$sid = CMT_approveModeration($mid[$i]);
- if ( !in_array($sid, $sidArray) ) {
+ if (! in_array($sid, $sidArray)) {
$sidArray[$i] = $sid;
}
} else {
- // This is called in case this is a plugin. There may be some
- // plugin specific processing that needs to happen.
- DB_copy($table,$fields,$fields,$submissiontable,$id,$mid[$i]);
- $retval .= PLG_approveSubmission($type,$mid[$i]);
+ /**
+ * This is called in case this is a plugin. There may be some
+ * plugin specific processing that needs to happen.
+ */
+
+ // avoid unnecessary copy, e.g. for draft stories
+ if ($table != $submissiontable) {
+ DB_copy($table, $fields, $fields,
+ $submissiontable, $id, $mid[$i]);
+ }
+ $retval .= PLG_approveSubmission($type, $mid[$i]);
}
break;
}
@@ -630,15 +572,11 @@
foreach ($_POST['delitem'] as $delitem) {
$delitem = COM_applyFilter($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);
+ // There may be some plugin specific processing that needs
+ // to happen first.
+ $retval .= PLG_deleteSubmission($type, $delitem);
- DB_delete($submissiontable, $id, $delitem);
- }
+ DB_delete($submissiontable, $id, $delitem);
}
}
}
diff -r 0517ca14a59a -r 7a8ca5e52c23 system/lib-story.php
--- a/system/lib-story.php Sat Feb 20 22:59:16 2010 +0100
+++ b/system/lib-story.php Sun Feb 21 10:19:08 2010 +0100
@@ -991,6 +991,96 @@
/*
+ * Another pseudo plugin API for draft stories
+ */
+
+/**
+* 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_draft()
+{
+ global $_TABLES;
+
+ return array(
+ 'sid',
+ $_TABLES['stories'],
+ 'sid,uid,tid,title,introtext,date,postmode',
+ $_TABLES['stories']
+ );
+}
+
+/**
+* Performs draft 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_draft($sid)
+{
+ global $_TABLES;
+
+ STORY_deleteStory($sid);
+
+ return '';
+}
+
+/**
+* Returns SQL & Language texts to moderation.php
+*
+* @return mixed Plugin object or void if not allowed
+*
+*/
+function plugin_itemlist_story_draft()
+{
+ global $_TABLES, $LANG24, $LANG29;
+
+ if (SEC_hasRights('story.edit')) {
+ $plugin = new Plugin();
+ $plugin->submissionlabel = $LANG29[35] . ' (' . $LANG24[34] . ')';
+ $plugin->submissionhelpfile = 'ccdraftsubmission.html';
+ $plugin->getsubmissionssql = "SELECT sid AS id,title,date,tid FROM {$_TABLES['stories']} WHERE (draft_flag = 1)" . COM_getTopicSQL ('AND') . COM_getPermSQL ('AND', 0, 3) . " ORDER BY date ASC";
+ $plugin->addSubmissionHeading($LANG29[10]);
+ $plugin->addSubmissionHeading($LANG29[14]);
+ $plugin->addSubmissionHeading($LANG29[15]);
+
+ return $plugin;
+ }
+}
+
+/**
+* "Approve" a draft story
+*
More information about the geeklog-cvs
mailing list