[phpmix-cvs] drupal/modules/akismet akismet.module,1.17,1.18
Status: Pre-Alpha
Brought to you by:
markus_petrux
From: <php...@li...> - 2006-06-10 19:01:19
|
Update of /cvsroot/phpmix/drupal/modules/akismet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7310 Modified Files: akismet.module Log Message: Reviewed module settings regarding e-mail notifications. Implementation of hook_user to let users decide whether they wish to get e-mail notifications for all content, just content in need of approval or nothing at all. Index: akismet.module =================================================================== RCS file: /cvsroot/phpmix/drupal/modules/akismet/akismet.module,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** akismet.module 10 Jun 2006 13:36:35 -0000 1.17 --- akismet.module 10 Jun 2006 19:01:04 -0000 1.18 *************** *** 60,68 **** break; case 'admin/akismet/nodes': ! $output = t("Below is the list of nodes awaiting for moderation. Click on the titles to see the content, the author's name to view the author's user information. You may also wish to click on the headers to order the nodes upon your needs."); $output .= '<br />'. t('<strong>Note:</strong> To interact fully with the <a href="%akismet">Akismet Service</a> you really should try putting data back into the system as well as just taking it out. If it is at all possible, please use the submit <em>ham</em> operation rather than simply publishing content that was identified as spam (false positives). This is necessary in order to let Akismet learn from its mistakes. Thank you.', array('%akismet' => 'http://akismet.com')); break; case 'admin/akismet/comments': ! $output = t("Below is the list of comments awaiting for moderation. Click on the subjects to see the comments, the author's name to view the author's user information. You may also wish to click on the headers to order the comments upon your needs."); $output .= '<br />'. t('<strong>Note:</strong> To interact fully with the <a href="%akismet">Akismet Service</a> you really should try putting data back into the system as well as just taking it out. If it is at all possible, please use the submit <em>ham</em> operation rather than simply publishing content that was identified as spam (false positives). This is necessary in order to let Akismet learn from its mistakes. Thank you.', array('%akismet' => 'http://akismet.com')); break; --- 60,68 ---- break; case 'admin/akismet/nodes': ! $output = t('Below is the list of nodes awaiting for moderation. Click on the titles to see the content, the author\'s name to view the author\'s user information. You may also wish to click on the headers to order the nodes upon your needs.'); $output .= '<br />'. t('<strong>Note:</strong> To interact fully with the <a href="%akismet">Akismet Service</a> you really should try putting data back into the system as well as just taking it out. If it is at all possible, please use the submit <em>ham</em> operation rather than simply publishing content that was identified as spam (false positives). This is necessary in order to let Akismet learn from its mistakes. Thank you.', array('%akismet' => 'http://akismet.com')); break; case 'admin/akismet/comments': ! $output = t('Below is the list of comments awaiting for moderation. Click on the subjects to see the comments, the author\'s name to view the author\'s user information. You may also wish to click on the headers to order the comments upon your needs.'); $output .= '<br />'. t('<strong>Note:</strong> To interact fully with the <a href="%akismet">Akismet Service</a> you really should try putting data back into the system as well as just taking it out. If it is at all possible, please use the submit <em>ham</em> operation rather than simply publishing content that was identified as spam (false positives). This is necessary in order to let Akismet learn from its mistakes. Thank you.', array('%akismet' => 'http://akismet.com')); break; *************** *** 137,141 **** // This is why this cron task is being more complex that it could really be. Anyway, these // queries shouldn't be too heavy. ! $result = db_query("SELECT s.content_id FROM {akismet_spam_marks} s LEFT JOIN {node} n ON s.content_id = n.nid WHERE s.content_type = 'node' AND n.nid IS NULL"); if (db_num_rows($result)) { while ($s = db_fetch_object($result)) { --- 137,141 ---- // This is why this cron task is being more complex that it could really be. Anyway, these // queries shouldn't be too heavy. ! $result = db_query('SELECT s.content_id FROM {akismet_spam_marks} s LEFT JOIN {node} n ON s.content_id = n.nid WHERE s.content_type = \'node\' AND n.nid IS NULL'); if (db_num_rows($result)) { while ($s = db_fetch_object($result)) { *************** *** 145,149 **** } } ! $result = db_query("SELECT s.content_id FROM {akismet_spam_marks} s LEFT JOIN {comments} c ON s.content_id = c.cid WHERE s.content_type = 'comment' AND c.cid IS NULL"); if (db_num_rows($result)) { while ($s = db_fetch_object($result)) { --- 145,149 ---- } } ! $result = db_query('SELECT s.content_id FROM {akismet_spam_marks} s LEFT JOIN {comments} c ON s.content_id = c.cid WHERE s.content_type = \'comment\' AND c.cid IS NULL'); if (db_num_rows($result)) { while ($s = db_fetch_object($result)) { *************** *** 200,208 **** if ($spam_nids_removed > 0) { $spam_nids_list = implode(',', $obsolete_spam_marks['nids']); ! db_query("DELETE FROM {akismet_spam_marks} WHERE content_type = 'node' AND content_id IN (%s)", $spam_nids_list); } if ($spam_cids_removed > 0) { $spam_cids_list = implode(',', $obsolete_spam_marks['cids']); ! db_query("DELETE FROM {akismet_spam_marks} WHERE content_type = 'comment' AND content_id IN (%s)", $spam_cids_list); } if ($spam_marks_removed > 0) { --- 200,208 ---- if ($spam_nids_removed > 0) { $spam_nids_list = implode(',', $obsolete_spam_marks['nids']); ! db_query('DELETE FROM {akismet_spam_marks} WHERE content_type = \'node\' AND content_id IN (%s)', $spam_nids_list); } if ($spam_cids_removed > 0) { $spam_cids_list = implode(',', $obsolete_spam_marks['cids']); ! db_query('DELETE FROM {akismet_spam_marks} WHERE content_type = \'comment\' AND content_id IN (%s)', $spam_cids_list); } if ($spam_marks_removed > 0) { *************** *** 261,265 **** ); if (!empty($akismet_wpapikey) && !$is_valid) { ! $form['service']['akismet_wpapikey']['#description'] .= '<div class="marker">'. t("<strong>WARNING: Your API Key doesn't seem to be valid!</strong>") .'</div>'; } $form['service']['akismet_connection_enabled'] = array( --- 261,265 ---- ); if (!empty($akismet_wpapikey) && !$is_valid) { ! $form['service']['akismet_wpapikey']['#description'] .= '<div class="marker">'. t('<strong>WARNING: Your API Key doesn\'t seem to be valid!</strong>') .'</div>'; } $form['service']['akismet_connection_enabled'] = array( *************** *** 326,329 **** --- 326,335 ---- )) ); + $form['general']['akismet_email_enabled'] = array( + '#type' => 'radios', '#title' => t('E-mail notifications'), + '#options' => $enable_options, + '#default_value' => variable_get('akismet_email_enabled', 1), + '#description' => t('Use this option to <em>enable</em> or <em>disable</em> e-mail notifications to content moderators. If enabled, users with proper permissions are allowed to set, from their user profiles, whether they wish to receive e-mail notications for all new (or updated) posts, just for content needing approval or no notifications at all. Users are notified about content types they are allowed to moderate only.') + ); $form['node_options'] = array( *************** *** 443,481 **** ); ! $email_to_options = array( ! 'site_email' => t('Main Site Address'), ! 'site_admin' => t('Main Site Administrator'), ! 'content_admins' => t('Content Administrators'), ! 'content_moderators' => t('Content Moderators') ! ); ! $email_when_options = array( ! 'all' => t('Content is posted'), 'approval' => t('Only content needing approval'), 'never' => t('Never') ); ! $form['email_options'] = array( ! '#type' => 'fieldset', '#title' => t('E-mail Options'), ! '#collapsible' => TRUE, '#collapsed' => TRUE ! ); ! $form['email_options']['akismet_email_to'] = array( ! '#type' => 'checkboxes', '#title' => t('Send e-mails to'), ! '#options' => $email_to_options, ! '#default_value' => variable_get('akismet_email_to', 0), ! '#description' => t('Use this option to select groups of users to whom e-mail notifications will be sent, when content is posted, based on the criteria specified below. It worths to mention that content administrators and moderators will only be notified about posts they have proper access to.') ! ); ! $form['email_options']['akismet_email_exclude_self'] = array( ! '#type' => 'radios', '#title' => t('Exclude notifications to self poster'), ! '#options' => $enable_options, ! '#default_value' => variable_get('akismet_email_exclude_self', 1), ! '#description' => t('Use this option to exclude self poster from receiving e-mail notifications.') ! ); ! $form['email_options']['akismet_email_when'] = array( ! '#type' => 'radios', '#title' => t('Send e-mails when'), ! '#options' => $email_when_options, ! '#default_value' => variable_get('akismet_email_when', 'approval'), ! '#description' => t('Use this option to specify the critica for which the user groups specified above should receive e-mail notifications.') ! ); ! return $form; } --- 449,522 ---- ); ! return $form; ! } ! ! /** ! * Implementation of hook_user(). ! */ ! function akismet_user($op, &$edit, &$account, $category = NULL) { ! $moderator_email_for_options = array( ! 'all' => t('All new (or updated) content'), 'approval' => t('Only content needing approval'), 'never' => t('Never') ); ! switch ($op) { ! case 'form': ! if ($category == 'account' && variable_get('akismet_email_enabled', 1)) { ! $moderator_types = akismet_get_moderator_types($account); ! $moderator_types_count = count($moderator_types); ! if ($moderator_types_count > 0) { ! $form = array(); ! $form['akismet_moderator'] = array( ! '#type' => 'fieldset', '#title' => t('Akismet moderator settings'), ! '#weight' => 5, ! '#collapsible' => TRUE, '#collapsed' => FALSE, ! '#description' => t('You are currently moderator for the following content types: %types.', array('%types' => implode(', ', $moderator_types))) ! ); ! $form['akismet_moderator']['akismet_moderator_email_for'] = array( ! '#type' => 'radios', '#title' => t('Send me e-mails for'), ! '#options' => $moderator_email_for_options, ! '#default_value' => (isset($moderator_email_for_options[$edit['akismet_moderator_email_for']]) ? $edit['akismet_moderator_email_for'] : 'approval') ! ); ! return $form; ! } ! } ! break; ! case 'load': ! $moderator_types = akismet_get_moderator_types($account); ! $moderator_types_count = count($moderator_types); ! if ($moderator_types_count > 0) { ! $moderator_data = db_fetch_object(db_query('SELECT * FROM {akismet_moderator} WHERE uid = %d', $account->uid)); ! $account->akismet_moderator_email_for = (isset($moderator_data->email_for) && isset($moderator_types[$moderator_data->email_for]) ? $moderator_data->email_for : 'approval'); ! } ! break; ! case 'insert': ! case 'update': ! $moderator_types = akismet_get_moderator_types($account); ! $moderator_types_count = count($moderator_types); ! if ($moderator_types_count > 0 && isset($edit['akismet_moderator_email_for'])) { ! if (!isset($moderator_email_for_options[$edit['akismet_moderator_email_for']])) { ! $edit['akismet_moderator_email_for'] = 'approval'; ! } ! db_query('UPDATE {akismet_moderator} SET email_for = \'%s\' WHERE uid = %d', $edit['akismet_moderator_email_for'], $account->uid); ! if (!db_affected_rows()) { ! db_query('INSERT INTO {akismet_moderator} (uid, email_for) VALUES (%d, \'%s\')', $account->uid, $edit['akismet_moderator_email_for']); ! } ! $edit['akismet_moderator_email_for'] = NULL; ! break; ! } ! // Fall through, to remove possible garbage. ! case 'delete': ! db_query('DELETE FROM {akismet_moderator} WHERE uid = %d', $account->uid); ! break; ! } ! } ! function akismet_notify_users() { ! // Proceed only if e-mail notifications are enabled. ! if (!variable_get('akismet_email_enabled', 0)) { ! return; ! } ! // @TODO: } *************** *** 716,731 **** if (variable_get('akismet_node_publish_links', 0)) { if ($content->status) { ! $links[] = l(t('unpublish'), "akismet/node/$content->nid/unpublish"); } else { ! $links[] = l(t('publish'), "akismet/node/$content->nid/publish"); } } if (variable_get('akismet_node_spam_links', 0)) { if (akismet_content_is_spam('node', $content->nid)) { ! $links[] = l((variable_get('akismet_connection_enabled', 1) ? t('submit ham') : t('mark as ham')), "akismet/node/$content->nid/submit-ham"); } else { ! $links[] = l((variable_get('akismet_connection_enabled', 1) ? t('submit spam') : t('mark as spam')), "akismet/node/$content->nid/submit-spam"); } } --- 757,772 ---- if (variable_get('akismet_node_publish_links', 0)) { if ($content->status) { ! $links[] = l(t('unpublish'), 'akismet/node/'. $content->nid .'/unpublish'); } else { ! $links[] = l(t('publish'), 'akismet/node/'. $content->nid .'/publish'); } } if (variable_get('akismet_node_spam_links', 0)) { if (akismet_content_is_spam('node', $content->nid)) { ! $links[] = l((variable_get('akismet_connection_enabled', 1) ? t('submit ham') : t('mark as ham')), 'akismet/node/'. $content->nid .'/submit-ham'); } else { ! $links[] = l((variable_get('akismet_connection_enabled', 1) ? t('submit spam') : t('mark as spam')), 'akismet/node/'. $content->nid .'/submit-spam'); } } *************** *** 734,749 **** if (variable_get('akismet_comment_publish_links', 1)) { if ($content->status == COMMENT_PUBLISHED) { ! $links[] = l(t('unpublish'), "akismet/comment/$content->cid/unpublish"); } else if ($content->status == COMMENT_NOT_PUBLISHED) { ! $links[] = l(t('publish'), "akismet/comment/$content->cid/publish"); } } if (variable_get('akismet_comment_spam_links', 1)) { if (akismet_content_is_spam('comment', $content->cid)) { ! $links[] = l((variable_get('akismet_connection_enabled', 1) ? t('submit ham') : t('mark as ham')), "akismet/comment/$content->cid/submit-ham"); } else { ! $links[] = l((variable_get('akismet_connection_enabled', 1) ? t('submit spam') : t('mark as spam')), "akismet/comment/$content->cid/submit-spam"); } } --- 775,790 ---- if (variable_get('akismet_comment_publish_links', 1)) { if ($content->status == COMMENT_PUBLISHED) { ! $links[] = l(t('unpublish'), 'akismet/comment/'. $content->cid .'/unpublish'); } else if ($content->status == COMMENT_NOT_PUBLISHED) { ! $links[] = l(t('publish'), 'akismet/comment/'. $content->cid .'/publish'); } } if (variable_get('akismet_comment_spam_links', 1)) { if (akismet_content_is_spam('comment', $content->cid)) { ! $links[] = l((variable_get('akismet_connection_enabled', 1) ? t('submit ham') : t('mark as ham')), 'akismet/comment/'. $content->cid .'/submit-ham'); } else { ! $links[] = l((variable_get('akismet_connection_enabled', 1) ? t('submit spam') : t('mark as spam')), 'akismet/comment/'. $content->cid .'/submit-spam'); } } *************** *** 778,785 **** if ($content_type == 'node') { ! drupal_goto("node/$content->nid"); } else { // comment ! drupal_goto("node/$content->nid", NULL, "comment-$content->cid"); } } --- 819,826 ---- if ($content_type == 'node') { ! drupal_goto('node/'. $content->nid); } else { // comment ! drupal_goto('node/'. $content->nid, NULL, 'comment-'. $content->cid); } } *************** *** 826,833 **** if ($content_type == 'node') { ! drupal_goto("node/$content->nid"); } else { // comment ! drupal_goto("node/$content->nid", NULL, "comment-$content->cid"); } } --- 867,874 ---- if ($content_type == 'node') { ! drupal_goto('node/'. $content->nid); } else { // comment ! drupal_goto('node/'. $content->nid, NULL, 'comment-'. $content->cid); } } *************** *** 877,889 **** // Record the event to watchdog. if ($akismet_api_result == AKISMET_API_RESULT_ERROR) { ! watchdog('content', t('Akismet service seems to be down, %content-type-name queued for manual approval: %title', array('%content-type-name' => $content_type_name, '%title' => theme('placeholder', $node->title))), WATCHDOG_WARNING, l(t('view'), "node/$node->nid")); } else { ! watchdog('content', t('Spam detected by Akismet in %content-type-name: %title', array('%content-type-name' => $content_type_name, '%title' => theme('placeholder', $node->title))), WATCHDOG_WARNING, l(t('view'), "node/$node->nid")); } } break; case 'delete': ! db_query("DELETE FROM {akismet_spam_marks} WHERE content_type = 'node' AND content_id = %d", $node->nid); break; } --- 918,930 ---- // Record the event to watchdog. if ($akismet_api_result == AKISMET_API_RESULT_ERROR) { ! watchdog('content', t('Akismet service seems to be down, %content-type-name queued for manual approval: %title', array('%content-type-name' => $content_type_name, '%title' => theme('placeholder', $node->title))), WATCHDOG_WARNING, l(t('view'), 'node/'. $node->nid)); } else { ! watchdog('content', t('Spam detected by Akismet in %content-type-name: %title', array('%content-type-name' => $content_type_name, '%title' => theme('placeholder', $node->title))), WATCHDOG_WARNING, l(t('view'), 'node/'. $node->nid)); } } break; case 'delete': ! db_query('DELETE FROM {akismet_spam_marks} WHERE content_type = \'node\' AND content_id = %d', $node->nid); break; } *************** *** 895,899 **** function akismet_comment(&$comment, $op) { if ($op == 'delete') { ! db_query("DELETE FROM {akismet_spam_marks} WHERE content_type = 'comment' AND content_id = %d", $comment->cid); } } --- 936,940 ---- function akismet_comment(&$comment, $op) { if ($op == 'delete') { ! db_query('DELETE FROM {akismet_spam_marks} WHERE content_type = \'comment\' AND content_id = %d', $comment->cid); } } *************** *** 984,991 **** // Record the event to watchdog. if ($akismet_api_result == AKISMET_API_RESULT_ERROR) { ! watchdog('content', t('Akismet service seems to be down, comment queued for manual approval: %subject', array('%subject' => theme('placeholder', $comment->subject))), WATCHDOG_WARNING, l(t('view'), "node/$comment->nid", NULL, NULL, "comment-$comment->cid")); } else { ! watchdog('content', t('Spam detected by Akismet in comment: %subject', array('%subject' => theme('placeholder', $comment->subject))), WATCHDOG_WARNING, l(t('view'), "node/$comment->nid", NULL, NULL, "comment-$comment->cid")); } } --- 1025,1032 ---- // Record the event to watchdog. if ($akismet_api_result == AKISMET_API_RESULT_ERROR) { ! watchdog('content', t('Akismet service seems to be down, comment queued for manual approval: %subject', array('%subject' => theme('placeholder', $comment->subject))), WATCHDOG_WARNING, l(t('view'), 'node/'. $comment->nid, NULL, NULL, 'comment-'. $comment->cid)); } else { ! watchdog('content', t('Spam detected by Akismet in comment: %subject', array('%subject' => theme('placeholder', $comment->subject))), WATCHDOG_WARNING, l(t('view'), 'node/'. $comment->nid, NULL, NULL, 'comment-'. $comment->cid)); } } *************** *** 1016,1028 **** $sql_nodetypes = array(); foreach ($allowed_nodes as $type => $name) { ! $sql_nodetypes[] = "'". $type ."'"; } $sql_nodetypes = implode(', ', $sql_nodetypes); ! $sql_nodes = "SELECT n.*, s.spam_created FROM {akismet_spam_marks} s INNER JOIN {node} n ON s.content_id = n.nid WHERE s.content_type = 'node' AND (n.type IN (". $sql_nodetypes .") OR n.status = 0)"; ! $sql_nodes_cnt = "SELECT COUNT(*) AS cnt FROM {akismet_spam_marks} s INNER JOIN {node} n ON s.content_id = n.nid WHERE s.content_type = 'node' AND (n.type IN (". $sql_nodetypes .") OR n.status = 0)"; } if ($allowed_comments) { ! $sql_comments = "SELECT c.*, s.spam_created FROM {akismet_spam_marks} s INNER JOIN {comments} c ON s.content_id = c.cid WHERE s.content_type = 'comment' OR c.status = ". COMMENT_NOT_PUBLISHED; ! $sql_comments_cnt = "SELECT COUNT(*) AS cnt FROM {akismet_spam_marks} s INNER JOIN {comments} c ON s.content_id = c.cid WHERE s.content_type = 'comment' OR c.status = ". COMMENT_NOT_PUBLISHED; } --- 1057,1069 ---- $sql_nodetypes = array(); foreach ($allowed_nodes as $type => $name) { ! $sql_nodetypes[] = '\''. $type .'\''; } $sql_nodetypes = implode(', ', $sql_nodetypes); ! $sql_nodes = 'SELECT n.*, s.spam_created FROM {akismet_spam_marks} s INNER JOIN {node} n ON s.content_id = n.nid WHERE s.content_type = \'node\' AND (n.type IN ('. $sql_nodetypes .') OR n.status = 0)'; ! $sql_nodes_cnt = 'SELECT COUNT(*) AS cnt FROM {akismet_spam_marks} s INNER JOIN {node} n ON s.content_id = n.nid WHERE s.content_type = \'node\' AND (n.type IN ('. $sql_nodetypes .') OR n.status = 0)'; } if ($allowed_comments) { ! $sql_comments = 'SELECT c.*, s.spam_created FROM {akismet_spam_marks} s INNER JOIN {comments} c ON s.content_id = c.cid WHERE s.content_type = \'comment\' OR c.status = '. COMMENT_NOT_PUBLISHED; ! $sql_comments_cnt = 'SELECT COUNT(*) AS cnt FROM {akismet_spam_marks} s INNER JOIN {comments} c ON s.content_id = c.cid WHERE s.content_type = \'comment\' OR c.status = '. COMMENT_NOT_PUBLISHED; } *************** *** 1070,1074 **** if ($op == 'nodes') { $rows[] = array( ! l($content->title, "node/$content->nid", array('title' => truncate_utf8($content->body, 128))) .' '. theme('mark', node_mark($content->nid, $content->changed)), node_get_name($content), theme('username', $content), --- 1111,1115 ---- if ($op == 'nodes') { $rows[] = array( ! l($content->title, 'node/'. $content->nid, array('title' => truncate_utf8($content->body, 128))) .' '. theme('mark', node_mark($content->nid, $content->changed)), node_get_name($content), theme('username', $content), *************** *** 1080,1084 **** $content->name = $content->uid ? $content->registered_name : $content->name; $rows[] = array( ! l($content->subject, "node/$content->nid", array('title' => truncate_utf8($content->comment, 128)), NULL, "comment-$content->cid") .' '. theme('mark', node_mark($content->nid, $content->timestamp)), theme('username', $content), ($content->status == COMMENT_PUBLISHED ? t('published') : t('not published')), --- 1121,1125 ---- $content->name = $content->uid ? $content->registered_name : $content->name; $rows[] = array( ! l($content->subject, 'node/'. $content->nid, array('title' => truncate_utf8($content->comment, 128)), NULL, 'comment-'. $content->cid) .' '. theme('mark', node_mark($content->nid, $content->timestamp)), theme('username', $content), ($content->status == COMMENT_PUBLISHED ? t('published') : t('not published')), *************** *** 1109,1113 **** */ function akismet_content_is_spam($content_type, $content_id) { ! return db_result(db_query("SELECT 1 FROM {akismet_spam_marks} WHERE content_type = '%s' AND content_id = %d", $content_type, $content_id)); } --- 1150,1154 ---- */ function akismet_content_is_spam($content_type, $content_id) { ! return db_result(db_query('SELECT 1 FROM {akismet_spam_marks} WHERE content_type = \'%s\' AND content_id = %d', $content_type, $content_id)); } *************** *** 1138,1169 **** * Get the types the current user is allowed to moderate. * * @return array Moderator Types. */ ! function akismet_get_moderator_types() { ! static $moderator_types = FALSE; ! if ($moderator_types === FALSE) { ! $moderator_types = array(); $node_types = node_get_types(); ! if (user_access('administer nodes')) { foreach ($node_types as $type => $name) { ! $moderator_types[$type] = $name; } } else { foreach ($node_types as $type => $name) { ! if (user_access('moderate spam in nodes of type '. $node_types[$type])) { ! $moderator_types[$type] = $name; } } } ! if (user_access('administer comments') || user_access('moderate spam in comments')) { ! $moderator_types['comments'] = t('comments'); } } ! return $moderator_types; } --- 1179,1218 ---- * Get the types the current user is allowed to moderate. * + * @param object The account to check; use current user if not given. * @return array Moderator Types. */ ! function akismet_get_moderator_types($account = NULL) { ! global $user; ! static $node_types = FALSE; ! static $moderator_types = array(); ! if (is_null($account)) { ! $account = $user; ! } ! ! if ($node_types === FALSE) { $node_types = node_get_types(); + } ! if (!isset($moderator_types[$account->uid])) { ! if (user_access('administer nodes', $account)) { foreach ($node_types as $type => $name) { ! $moderator_types[$account->uid][$type] = $name; } } else { foreach ($node_types as $type => $name) { ! if (user_access('moderate spam in nodes of type '. $node_types[$type], $account)) { ! $moderator_types[$account->uid][$type] = $name; } } } ! if (user_access('administer comments', $account) || user_access('moderate spam in comments', $account)) { ! $moderator_types[$account->uid]['comments'] = t('comments'); } } ! return $moderator_types[$account->uid]; } *************** *** 1171,1179 **** * Is current user spam moderator? * ! * @param string Moderator Type ('comments' or node type). * @return boolean TRUE if current user is moderator of specified type; FALSE otherwise. */ ! function akismet_is_spam_moderator($moderator_type) { ! $moderator_types = akismet_get_moderator_types(); return isset($moderator_types[$moderator_type]); } --- 1220,1236 ---- * Is current user spam moderator? * ! * @param string Moderator Type (comments, node type or NULL). ! * @param object The account to check; use current user if not given. * @return boolean TRUE if current user is moderator of specified type; FALSE otherwise. */ ! function akismet_is_spam_moderator($moderator_type = NULL, $account = NULL) { ! global $user; ! if (is_null($account)) { ! $account = $user; ! } ! $moderator_types = akismet_get_moderator_types($account); ! if (is_null($moderator_type)) { ! return (count($moderator_types) > 0 ? TRUE : FALSE); ! } return isset($moderator_types[$moderator_type]); } *************** *** 1280,1293 **** $content_id = $content->nid; $content_title = $content->title; ! $content_link = l(t('view'), "node/$content->nid"); } else { // comment $content_id = $content->cid; $content_title = $content->subject; ! $content_link = l(t('view'), "node/$content->nid", NULL, NULL, "comment-$content->cid"); } if ($op == 'submit-spam') { ! db_query("INSERT INTO {akismet_spam_marks} (content_type, content_id, spam_created) VALUES ('%s', %d, %d)", $content_type, $content_id, time()); if (variable_get('akismet_connection_enabled', 1)) { --- 1337,1350 ---- $content_id = $content->nid; $content_title = $content->title; ! $content_link = l(t('view'), 'node/'. $content->nid); } else { // comment $content_id = $content->cid; $content_title = $content->subject; ! $content_link = l(t('view'), 'node/'. $content->nid, NULL, NULL, 'comment-'. $content->cid); } if ($op == 'submit-spam') { ! db_query('INSERT INTO {akismet_spam_marks} (content_type, content_id, spam_created) VALUES (\'%s\', %d, %d)', $content_type, $content_id, time()); if (variable_get('akismet_connection_enabled', 1)) { *************** *** 1300,1304 **** } else { // submit-ham ! db_query("DELETE FROM {akismet_spam_marks} WHERE content_type = '%s' AND content_id = %d", $content_type, $content_id); if (variable_get('akismet_connection_enabled', 1)) { --- 1357,1361 ---- } else { // submit-ham ! db_query('DELETE FROM {akismet_spam_marks} WHERE content_type = \'%s\' AND content_id = %d', $content_type, $content_id); if (variable_get('akismet_connection_enabled', 1)) { *************** *** 1335,1339 **** if ($log_action) { $action = ($op == 'publish' ? t('Content published') : t('Content unpublished')); ! watchdog('content', t('%action: %title', array('%action' => $action, '%title' => theme('placeholder', $content->title))), WATCHDOG_NOTICE, l(t('view'), "node/$content->nid")); } } --- 1392,1396 ---- if ($log_action) { $action = ($op == 'publish' ? t('Content published') : t('Content unpublished')); ! watchdog('content', t('%action: %title', array('%action' => $action, '%title' => theme('placeholder', $content->title))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $content->nid)); } } *************** *** 1359,1363 **** if ($log_action) { $action = ($op == 'publish' ? t('Comment published') : t('Comment unpublished')); ! watchdog('content', t('%action: %subject', array('%action' => $action, '%subject' => theme('placeholder', $content->subject))), WATCHDOG_NOTICE, l(t('view'), "node/$content->nid", NULL, NULL, "comment-$content->cid")); } } --- 1416,1420 ---- if ($log_action) { $action = ($op == 'publish' ? t('Comment published') : t('Comment unpublished')); ! watchdog('content', t('%action: %subject', array('%action' => $action, '%subject' => theme('placeholder', $content->subject))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $content->nid, NULL, NULL, 'comment-'. $content->cid)); } } *************** *** 1390,1394 **** // Prepare data that varies depending on type of content. if ($content_type == 'comment') { ! $comment_data['permalink'] = url("node/$content->nid", NULL, "comment-$content->cid", TRUE); $comment_data['comment_author_email'] = $content->mail; $comment_data['comment_author_url'] = $content->homepage; --- 1447,1451 ---- // Prepare data that varies depending on type of content. if ($content_type == 'comment') { ! $comment_data['permalink'] = url('node/'. $content->nid, NULL, 'comment-'. $content->cid, TRUE); $comment_data['comment_author_email'] = $content->mail; $comment_data['comment_author_url'] = $content->homepage; *************** *** 1397,1401 **** else { global $user; ! $comment_data['permalink'] = url("node/$content->nid"); $comment_data['comment_author_email'] = $user->mail; $comment_data['comment_author_url'] = ''; --- 1454,1458 ---- else { global $user; ! $comment_data['permalink'] = url('node/'. $content->nid); $comment_data['comment_author_email'] = $user->mail; $comment_data['comment_author_url'] = ''; *************** *** 1461,1470 **** */ function _akismet_get_version_message($url) { - global $user; - if ($user->uid != 1) { - return ''; - } $new_version = _akismet_check_version(isset($_GET['vchk']) ? TRUE : FALSE); - $output = ''; if (empty($new_version)) { drupal_set_message(t('Sorry, could not connect to remote server to check for new version information. Please, consult the <a href="%admin-logs">log</a> for details.', array('%admin-logs' => url('admin/logs'))), 'error'); --- 1518,1522 ---- *************** *** 1478,1489 **** } } - $output = '<p>'; - $output .= t('You are running version <strong>%your-version</strong>.', array('%your-version' => AKISMET_MODULE_VERSION)); $timestamp_last = variable_get('akismet_version_check_timestamp', 0); ! if ($timestamp_last) { ! $output .= '<br />'. t('Last time checked: %last. The time is now %time.', array('%last' => format_date($timestamp_last), '%time' => format_date(time()))); ! } ! $output .= '<br />'. t('<a href="%check">Check for newest version</a>.', array('%check' => url($url, 'vchk=1'))); ! $output .= '</p>'; return $output; } --- 1530,1539 ---- } } $timestamp_last = variable_get('akismet_version_check_timestamp', 0); ! $output = '<p>' ! .t('You are running version <strong>%your-version</strong>', array('%your-version' => AKISMET_MODULE_VERSION)) ! .($timestamp_last > 0 ? ', '. t('version checked %time ago', array('%time' => format_interval(time() - $timestamp_last))) : '') ! .'. '. t('<a href="%check">Check for newest version</a>.', array('%check' => url($url, 'vchk=1'))) ! .'</p>'; return $output; } *************** *** 1502,1506 **** global $base_url; if (!empty($key)) { ! $request = "key=$key&blog=$base_url". base_path(); $response = _akismet_api_http_post($request, AKISMET_API_HOST, '/'. AKISMET_API_VERSION .'/verify-key'); } --- 1552,1556 ---- global $base_url; if (!empty($key)) { ! $request = 'key='. $key .'&blog='. $base_url . base_path(); $response = _akismet_api_http_post($request, AKISMET_API_HOST, '/'. AKISMET_API_VERSION .'/verify-key'); } *************** *** 1641,1646 **** ."Host: $host\r\n" ."Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n" ! ."Content-Length: ". strlen($request) ."\r\n" ! ."User-Agent: ". AKISMET_API_USERAGENT ."\r\n" ."\r\n" .$request; --- 1691,1696 ---- ."Host: $host\r\n" ."Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n" ! .'Content-Length: '. strlen($request) ."\r\n" ! .'User-Agent: '. AKISMET_API_USERAGENT ."\r\n" ."\r\n" .$request; |