Index: README.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/modr8/README.txt,v retrieving revision 1.5 diff -u -r1.5 README.txt --- README.txt 16 Aug 2007 02:54:53 -0000 1.5 +++ README.txt 9 Dec 2007 19:35:02 -0000 @@ -1,6 +1,6 @@ -$Id: README.txt,v 1.5 2007/08/16 02:54:53 pwolanin Exp $ +$Id: README.txt,v 1.3.2.2 2007/08/16 02:58:04 pwolanin Exp $ -Modr8 module for Drupal 5.x. +Modr8 module for Drupal 6.x. The moderation of content was removed from core in 5.x. This module adds back that capability and also prevents posts that are in moderation from showing @@ -46,4 +46,4 @@ This module was originally written for Drupal 4.7.x by Jeff Robbins (jjeff@drupal). Upgrade to 5.x and 5.x maintenance by Peter Wolanin (pwolanin@drupal) with help from Angela Byron (webchick@drupal). - +Upgrade to 6.x by Croitor Alexander (Placinta@drupal) Index: modr8.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/modr8/modr8.info,v retrieving revision 1.1 diff -u -r1.1 modr8.info --- modr8.info 31 Oct 2006 03:31:14 -0000 1.1 +++ modr8.info 8 Dec 2007 17:58:35 -0000 @@ -1,3 +1,4 @@ ; $Id: modr8.info,v 1.1 2006/10/31 03:31:14 pwolanin Exp $ name = Modr8 description = Easy, dedicated moderation of content +core = 6.x \ No newline at end of file Index: modr8.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/modr8/modr8.install,v retrieving revision 1.2 diff -u -r1.2 modr8.install --- modr8.install 20 Jan 2007 15:26:38 -0000 1.2 +++ modr8.install 11 Dec 2007 15:36:04 -0000 @@ -1,95 +1,72 @@ array( + 'modid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'author_uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'action' => array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''), + 'title' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'message' => array('type' => 'text', 'size' => 'big', 'not null' => TRUE), + 'teaser' => array('type' => 'text', 'size' => 'big', 'not null' => TRUE), + 'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'indexes' => array( + 'nid_time' => array('nid', 'modid'), + 'action' => array('action') + ), + 'primary key' => array('modid'), + ); + + return $schema; +} /** * Implementation of hook_install(). */ function modr8_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {modr8_log} ( - modid int NOT NULL auto_increment, - nid int unsigned NOT NULL default '0', - uid int NOT NULL default '0', - author_uid int NOT NULL default '0', - action varchar(16) NOT NULL default '', - title varchar(128) NOT NULL default '', - message longtext NOT NULL, - teaser longtext NOT NULL, - timestamp int NOT NULL default '0', - PRIMARY KEY (modid), - KEY nid_time (nid, modid), - KEY action (action) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - case 'pgsql': - db_query("CREATE TABLE {modr8_log} ( - modid serial, - nid int_unsigned NOT NULL default '0', - uid int NOT NULL default '0', - author_uid int NOT NULL default '0', - action varchar(16) NOT NULL default '', - title varchar(128) NOT NULL default '', - message text NOT NULL, - teaser text NOT NULL, - timestamp int NOT NULL default '0', - PRIMARY KEY (modid) - )"); - db_query("CREATE INDEX {modr8_log}_nid_time ON {modr8_log} (nid, modid)"); - db_query("CREATE INDEX {modr8_log}_act_idx ON {modr8_log} (action)"); - break; - } + // Create tables. + drupal_install_schema('modr8'); } /** * Implementation of hook_uninstall(). */ function modr8_uninstall() { - db_query('DROP TABLE {modr8_log}'); + // Remove tables. + drupal_uninstall_schema('modr8'); } - /** * Update table definitions. */ function modr8_update_1000() { $ret = array(); - - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $ret[] = update_sql("CREATE TABLE {modr8_log} ( - modid int NOT NULL auto_increment, - nid int unsigned NOT NULL default '0', - uid int NOT NULL default '0', - author_uid int NOT NULL default '0', - action varchar(16) NOT NULL default '', - title varchar(128) NOT NULL default '', - message longtext NOT NULL, - teaser longtext NOT NULL, - timestamp int NOT NULL default '0', - PRIMARY KEY (modid), - KEY nid_time (nid, modid), - KEY action (action) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; - case 'pgsql': - $ret[] = update_sql("CREATE TABLE {modr8_log} ( - modid serial, - nid int_unsigned NOT NULL default '0', - uid int NOT NULL default '0', - author_uid int NOT NULL default '0', - action varchar(16) NOT NULL default '', - title varchar(128) NOT NULL default '', - message text NOT NULL, - teaser text NOT NULL, - timestamp int NOT NULL default '0', - PRIMARY KEY (modid) - )"); - $ret[] = update_sql("CREATE INDEX {modr8_log}_nid_time ON {modr8_log} (nid, modid)"); - $ret[] = update_sql("CREATE INDEX {modr8_log}_act_idx ON {modr8_log} (action)"); - break; - } + $name = 'modr8_log'; + $table = array( + 'fields' => array( + 'modid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'author_uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'action' => array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''), + 'title' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), + 'message' => array('type' => 'text', 'size' => 'big', 'not null' => TRUE), + 'teaser' => array('type' => 'text', 'size' => 'big', 'not null' => TRUE), + 'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0) + ), + 'indexes' => array( + 'nid_time' => array('nid', 'modid'), + 'action' => array('action') + ), + 'primary key' => array('modid'), + ); + db_create_table(&$ret, $name, $table); return $ret; } Index: modr8.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/modr8/modr8.module,v retrieving revision 1.17 diff -u -r1.17 modr8.module --- modr8.module 16 Aug 2007 02:54:53 -0000 1.17 +++ modr8.module 13 Dec 2007 14:52:45 -0000 @@ -1,5 +1,5 @@ '. t("Easy, dedicated moderation of content. Assign the 'moderate content' permission to one or mode user roles. Set up the default moderation option for each node type."). '

'; + return '

'. t("Easy, dedicated moderation of content. Assign the 'moderate content' permission to one or mode user roles. Set up the default moderation option for each node type.") .'

'; // OPTIONAL: Add additional cases for other paths that should display help text. } } +/** + * An access function for Moderation Menu Tab + */ +function modr8_moderation_access($nid) { + return user_access('moderate content') && db_result(db_query("SELECT COUNT(*) FROM {modr8_log} ml WHERE ml.nid = %d", $nid)); +} /** * Implementation of hook_menu(). */ -function modr8_menu($may_cache) { +function modr8_menu() { $items = array(); - if ($may_cache) { - $items[] = array( - 'path' => 'admin/content/modr8', - 'title' => t('Moderated content'), - 'description' => t('Approve or delete moderated content.'), - 'access' => user_access('moderate content'), - 'callback' => 'modr8_page', + $items['admin/content/modr8'] = array( + 'title' => 'Moderated content', + 'description' => 'Approve or delete moderated content.', + 'access callback' => 'user_access', + 'access arguments' => array('moderate content'), + 'page callback' => 'modr8_page', + 'file' => 'modr8_admin.inc', + 'file path' => drupal_get_path('module', 'modr8') , ); - $items[] = array( - 'path' => 'admin/logs/modr8', - 'title' => t('Content moderation log'), - 'description' => t('Show log of all actions on moderated content.'), - 'access' => user_access('moderate content'), - 'callback' => 'modr8_log_view', + $items['admin/reports/modr8'] = array( + 'title' => 'Content moderation log', + 'description' => 'Show log of all actions on moderated content.', + 'access callback' => 'user_access', + 'access arguments' => array('moderate content'), + 'page callback' => 'modr8_log_view', + 'file' => 'modr8_admin.inc', + 'file path' => drupal_get_path('module', 'modr8') , ); - $items[] = array( - 'path' => 'admin/settings/modr8', - 'title' => t('Modr8 settings'), - 'description' => t('Configure content moderation.'), - 'callback' => 'modr8_settings', - 'access' => user_access('administer site configuration'), + $items['admin/settings/modr8'] = array( + 'title' => 'Modr8 settings', + 'description' => 'Configure content moderation.', + 'page callback' => 'modr8_settings', + 'access callback' => 'user_access', + 'access arguments' => array('administer site configuration'), + 'file' => 'modr8_admin.inc', + 'file path' => drupal_get_path('module', 'modr8') , ); - } - elseif (arg(0) == 'node' && is_numeric($nid = arg(1))) { - $items[] = array( - 'path' => 'node/'. $nid .'/modr8', - 'title' => t('Moderation'), - 'callback' => 'modr8_log_view', - 'callback arguments' => array('node', $nid), - 'access' => user_access('moderate content') && db_result(db_query("SELECT COUNT(*) FROM {modr8_log} ml WHERE ml.nid = %d", $nid)), + + $items['node/%/modr8'] = array( + 'title' => 'Moderation', + 'page callback' => 'modr8_log_view', + 'page arguments' => array('node', 1), + 'access callback' => 'modr8_moderation_access', + 'access arguments' => array(1), + 'file' => 'modr8_admin.inc', + 'file path' => drupal_get_path('module', 'modr8') , 'weight' => 10, 'type' => MENU_LOCAL_TASK ); - } return $items; } @@ -74,8 +85,6 @@ */ function modr8_log_view($op = '', $id = 0) { - require_once drupal_get_path('module', 'modr8'). '/modr8_admin.inc'; - switch ($op) { case '': return modr8_log_overview(); @@ -83,15 +92,16 @@ if (is_numeric($id)) { drupal_set_title(t('Moderation log event')); return modr8_log_event($id); + } break; case 'node': if (is_numeric($id)) { $node = node_load($id); - if ($node->nid) { - drupal_set_title(check_plain($node->title)); - } - return modr8_log_overview($id); + if ($node->nid) { + drupal_set_title(check_plain($node->title)); + } + return modr8_log_overview($id); } break; } @@ -104,8 +114,6 @@ */ function modr8_settings() { - require_once drupal_get_path('module', 'modr8'). '/modr8_admin.inc'; - return drupal_get_form('modr8_settings_form'); } @@ -149,7 +157,7 @@ } } -function modr8_form_alter($form_id, &$form){ +function modr8_form_alter(&$form, $form_state, $form_id) { if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) { @@ -188,7 +196,6 @@ * Menu callback; displays the content moderation form. */ function modr8_page() { - require_once drupal_get_path('module', 'modr8'). '/modr8_admin.inc'; $is_published = ''; if (!user_access('administer nodes')) { @@ -197,15 +204,18 @@ } $count_sql = db_rewrite_sql('SELECT COUNT(*) FROM {node} n WHERE '. $is_published .' n.moderate = 1'); $page_sql = db_rewrite_sql('SELECT n.nid FROM {node} n WHERE '. $is_published .' n.moderate = 1 ORDER BY n.changed DESC'); - $result = pager_query($page_sql, variable_get('modr8_nodes_per_page', 10), 0, $count_sql); - - $output = '

'. l(t('Show log of all actions on moderated content.'), 'admin/logs/modr8') .'

'; - if (db_num_rows($result)) { + $result = pager_query($page_sql, 10, 0, $count_sql); + $result_count = pager_query($page_sql, 10, 0, $count_sql); + $output = '

'. l(t('Show log of all actions on moderated content.'), 'admin/reports/modr8') .'

'; + + + if (db_fetch_object($result_count)) { $output .= drupal_get_form('modr8_form', $result); $output .= theme('pager'); + } else { - $output .= '

'. t('@items in moderation', array('@items' => format_plural(0, '1 post', '@count posts'))). '

'; + $output .= '

'. t('@items in moderation', array('@items' => format_plural(0, '1 post', '@count posts'))) .'

'; } return $output; } @@ -240,7 +250,7 @@ /** * Implementation of hook_cron() * - *.Remove expired moderation log events. + * Remove expired moderation log events. */ function modr8_cron() { if ($log_clear = variable_get('modr8_log_clear', 0)) { @@ -257,7 +267,7 @@ return $blocks; } elseif ($op == 'view') { - if (user_access('moderate content')){ + if (user_access('moderate content')) { $block['subject'] = t('Moderation queue'); $is_published = ''; if (!user_access('administer nodes')) { @@ -265,10 +275,10 @@ $is_published = 'n.status = 1 AND '; } $count = db_result(db_query(db_rewrite_sql('SELECT COUNT(*) FROM {node} n WHERE '. $is_published .' n.moderate = 1'))); - $content = '

'. l(t('@items in moderation',array('@items' => format_plural($count, '1 post', '@count posts'))),'admin/content/modr8'). '

'; + $content = '

'. l(t('@items in moderation', array('@items' => format_plural($count, '1 post', '@count posts'))), 'admin/content/modr8') .'

'; if ($count) { $sql = db_rewrite_sql('SELECT n.nid, n.title FROM {node} n WHERE '. $is_published .' n.moderate = 1 ORDER BY n.changed DESC'); - $result = db_query_range($sql,0,6); + $result = db_query_range($sql, 0, 6); $content .= node_title_list($result, t('Recent additions:')); } $block['content'] = $content; @@ -276,7 +286,21 @@ } } } - +/** + * Implementation of hook_theme(). + */ +function modr8_theme() { + return array( + 'modr8_message' => array('arguments' => array('teaser', 'nodetype', 'op')), + 'modr8_form' => array('arguments' => array('form')), + 'moderation_event' => array('arguments' => array('event')), + 'modr8_note' => array('arguments' => array('note')), + + ); +} +/** + * Theming function for messages. + */ function theme_modr8_message($teaser = FALSE, $nodetype = 'page', $op = 'view') { if ($teaser) { return '
'. t('Pending moderation') .'
'; Index: modr8_admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/modr8/modr8_admin.inc,v retrieving revision 1.13 diff -u -r1.13 modr8_admin.inc --- modr8_admin.inc 13 Dec 2007 00:58:19 -0000 1.13 +++ modr8_admin.inc 12 Dec 2007 21:20:05 -0000 @@ -1,7 +1,7 @@ 'radios', @@ -61,7 +61,7 @@ '#type' => 'textarea', '#title' => t('Acceptance e-mail'), '#default_value' => variable_get('modr8_accepted_text', $accept_default), - '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), + '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), ); $form['text']['modr8_send_deny'] = array( @@ -82,7 +82,7 @@ '#type' => 'textarea', '#title' => t('Denial e-mail'), '#default_value' => variable_get('modr8_denial_text', $denial_default), - '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), + '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), ); $form['text']['modr8_send_noact'] = array( @@ -103,32 +103,35 @@ '#type' => 'textarea', '#title' => t('No action e-mail note'), '#default_value' => variable_get('modr8_noact_text', $noact_default), - '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), + '#description' => t('Replacement strings are: %macros', array('%macros' => $macros)), ); - $form['#validate'] = array('modr8_settings_validate' => array()); + $form['#validate'] = array('modr8_settings_validate'); return system_settings_form($form); } -function modr8_settings_validate($form_id, $form_values) { - if ($form_values['modr8_email_from'] && !valid_email_address($form_values['modr8_email_from'])) { +function modr8_settings_validate($form, &$form_state) { + if ($form_state['values']['modr8_email_from'] && !valid_email_address($form_state['values']['modr8_email_from'])) { form_set_error('modr8_email_from', t('You must either enter a valid e-mail address, or leave the moderator e-mail field empty.')); } } -function modr8_form($result = NULL) { - +function modr8_form($form_state, $result = NULL) { + + $form = array( '#theme' => 'modr8_form', '#tree' => TRUE, ); while ($r = db_fetch_object($result)) { + $node = node_load($r->nid); // This flag can be used by modr8, or other modules to change the teaser specifically // for when it's being shown in the moderation list. $node->modr8_form_teaser = TRUE; $teaser = node_view($node, TRUE, FALSE, FALSE); + $form[$node->nid] = array( '#tree' => TRUE, ); @@ -155,10 +158,10 @@ $log_link = ''; $events = db_query("SELECT modid FROM {modr8_log} WHERE nid = %d", $node->nid); - $count = db_num_rows($events); + $count = db_result(db_query("SELECT COUNT(modid) FROM {modr8_log} WHERE nid = %d", $node->nid)); if ($count) { if ($count == 1) { - $url = 'admin/logs/modr8/event/'. db_result($events); + $url = 'admin/reports/modr8/event/'. db_result($events); } else { $url = 'node/'. $node->nid .'/modr8/'; @@ -185,7 +188,7 @@ } $form['submit'] = array( '#type' => 'submit', - '#value' => t('Submit'), + '#value' => t('Save'), ); return $form; @@ -231,12 +234,12 @@ /** * Form submit handler, which approves or deletes the node. */ -function modr8_form_submit($form_id, $form_values) { - foreach ($form_values as $nid => $values) { +function modr8_form_submit($form, &$form_state) { + foreach ($form_state['values'] as $nid => $values) { $message = ''; switch ($values['ops']) { case 'approve': - if (variable_get('modr8_send_approve', FALSE)){ + if (variable_get('modr8_send_approve', FALSE)) { $message = modr8_usermail('approve', $nid, $values); } $publish = ''; @@ -249,7 +252,7 @@ modr8_log_action('approve', $nid, $values, $message); break; case 'delete': - if (variable_get('modr8_send_deny', FALSE)){ + if (variable_get('modr8_send_deny', FALSE)) { $message = modr8_usermail('deny', $nid, $values); } node_delete($nid); @@ -257,7 +260,7 @@ modr8_log_action('delete', $nid, $values, $message); break; case 'nada': - if (variable_get('modr8_send_noact', FALSE) && !empty($values['note'])){ + if (variable_get('modr8_send_noact', FALSE) && !empty($values['note'])) { $message = modr8_usermail('nada', $nid, $values); modr8_log_action('nada', $nid, $values, $message); } @@ -267,14 +270,12 @@ function modr8_log_action($op, $nid, $values, $message) { global $user; - $actions = array('approve' => 'Approve','delete' => 'Delete','nada' => 'No action'); + $actions = array('approve' => 'Approve', 'delete' => 'Delete', 'nada' => 'No action'); db_query("INSERT INTO {modr8_log} (nid, uid, author_uid, action, title, message, teaser, timestamp) VALUES (%d, %d, %d, '%s', '%s', '%s', '%s', %d)", $nid, $user->uid, $values['author_uid'], $actions[$op], $values['title'], $message, $values['preview'], time()); - - module_invoke_all("modr8_action", $op, $nid); } -function modr8_usermail($op, $nid, $values){ +function modr8_usermail($op, $nid, $values) { $node = node_load($nid); if (is_object($node)) { @@ -302,16 +303,7 @@ $note = theme('modr8_note', $values['note']); - // eval the replacements - $replacements_raw = modr8_replacements(); - foreach ($replacements_raw as $key => $val) { - eval('$replacements["$key"] = '. $val .';'); - } - - // replace the macros - $subject = strtr($subject, $replacements); - $message = strtr($message, $replacements); - + $sendmail_from = ''; $site_mail = variable_get('modr8_email_from', ''); if (!$site_mail) { $sendmail_from = ini_get('sendmail_from'); @@ -321,7 +313,13 @@ drupal_set_message(t('You should create an administrator mail address for your site! Do it here.', array('@url' => url('admin/settings/site-information'))), 'error'); } // send the email - if (drupal_mail('modr8_usermail',$account->mail, $subject, $message, $site_mail)) { + $language = user_preferred_language($account); + $params = array('account' => $account, 'node' => $node, 'subject' => $subject, 'message' => $message, 'note' => $note); + + if ($account->uid == 0) { + $message = t('No %type message was sent.', array('%type' => $optype)); + } + elseif ($account->uid>0 && drupal_mail('modr8', 'notify', $account->mail, user_preferred_language($account), $params)) { drupal_set_message(t('%type message was sent to %username', array('%type' => $optype, '%username' => $account->name))); $message = filter_xss(nl2br($message), array('br', 'a')); // Return sanitized e-mail with HTML breaks added. } @@ -337,15 +335,37 @@ return $message; } -function theme_modr8_note($note){ - if ($note){ +/** + * Implementation of hook_mail() + */ +function modr8_mail($key, &$message, $params) { + $language = $message['language']; + $node = $params['node']; + $account = $params['account']; + $note = $params['note']; + switch ($key) { + case 'notify': + // eval the replacements + $replacements_raw = modr8_replacements(); + foreach ($replacements_raw as $key => $val) + eval('$replacements["$key"] = '. $val .';'); + $params['subject'] = strtr($params['subject'], $replacements); + $params['message'] = strtr($params['message'], $replacements); + $message['subject'] = $params['subject']; + $message['body'] = $params['message']; + break; + } +} + +function theme_modr8_note($note) { + if ($note) { $note = t("Note: @note", array('@note' => $note)); } return $note; } -function modr8_replacements(){ +function modr8_replacements() { return array( '%title' => '$node->title', '%teaser' => '$node->teaser', @@ -354,10 +374,10 @@ '%medium_date' => 'format_date($node->created, "medium")', '%long_date' => 'format_date($node->created, "long")', '%type' => 'node_get_types("name", $node)', - '%node_url' => 'url("node/". $node->nid, NULL, NULL, TRUE)', + '%node_url' => 'url("node/". $node->nid, array("absolute" => TRUE))', '%author_name' => '$account->name', '%author_mail' => '$account->mail', - '%author_url' => 'url("user/". $account->uid, NULL, NULL, TRUE)', + '%author_url' => 'url("user/". $account->uid, array("absolute" => TRUE))', '%site' => 'variable_get("site_name", "Drupal")', '%note' => '$note', ); @@ -404,7 +424,7 @@ array('data' => t('Action'), ), array('data' => t('Moderator'), 'field' => 'u.name'), array('data' => t('Date'), 'field' => 'ml.modid', 'sort' => 'desc'), - array('data' => t('Title (view event)'),), + array('data' => t('Title (view event)')), ); $tablesort = tablesort_sql($header); @@ -422,14 +442,14 @@ while ($event = db_fetch_object($result)) { $rows[] = array(t($event->action), theme('username', $event), format_date($event->timestamp, 'small'), - l(truncate_utf8($event->title, 50, TRUE, TRUE), 'admin/logs/modr8/event/'. $event->modid, array(), NULL, NULL, FALSE, TRUE) + l(truncate_utf8($event->title, 50, TRUE, TRUE), 'admin/reports/modr8/event/'. $event->modid, array(), NULL, NULL, FALSE, TRUE) ); } if (!$rows) { $rows[] = array(array('data' => t('No log messages available.'), 'colspan' => 4)); } - + $output = ''; $output .= theme('table', $header, $rows); $output .= theme('pager', NULL, 50, 0);