| 1 |
<?php |
<?php |
| 2 |
// $id$ |
/** |
| 3 |
|
* @file |
| 4 |
/** |
* Author: James Blake <james at webgeer dot com> |
| 5 |
* @file |
* Enables one to view unapproved nodes or comments using an RSS reader. |
| 6 |
* Author: James Blake <james at webgeer dot com> |
* |
| 7 |
* Enables one to view unapproved nodes or comments using an RSS reader. |
* This module was made a lot easier for me by both adminblock.module and commentrss.module. |
| 8 |
* |
* Thanks to both Fredrik Jonsson and Gabor Hojtsy. |
| 9 |
* This module was made a lot easier for me by both adminblock.module and commentrss.module. |
* |
| 10 |
* Thanks to both Fredrik Jonsson and Gabor Hojtsy. |
* @version $Id$ |
| 11 |
*/ |
* @since DRUPAL-4-6 |
| 12 |
|
* @license GPL 2.0 |
| 13 |
define('ADMINRSS_KEY', variable_get('adminrss_key',NULL)); |
* @todo watchdog/logging feed |
| 14 |
|
*/ |
| 15 |
/** |
|
| 16 |
* Implementation of hook_help(). |
require_once('adminrss_data.inc'); |
| 17 |
*/ |
|
| 18 |
function adminrss_help($section) { |
/** |
| 19 |
switch ($section) { |
* Implementation of hook_help(). |
| 20 |
case 'admin/modules#description': |
* |
| 21 |
return t('Provide an RSS feed for unapproved nodes and comments'); |
* @return string |
| 22 |
} |
*/ |
| 23 |
} |
function adminrss_help($section) { |
| 24 |
|
switch ($section) { |
| 25 |
/** |
case 'admin/modules#description': |
| 26 |
* 5.0 equivalent of hook_settings(). |
return t('Provide an RSS feed for unapproved nodes and comments'); |
| 27 |
* |
} |
| 28 |
*/ |
} |
| 29 |
function adminrss_admin_settings() { |
|
| 30 |
|
/** |
| 31 |
$key = variable_get('adminrss_key', ''); |
* 5.0 equivalent of hook_settings(). |
| 32 |
if ($key == ''){ |
* |
| 33 |
$key = md5(uniqid(rand(), true)); |
* @return array |
| 34 |
variable_set('adminrss_key', $key); |
*/ |
| 35 |
} |
function adminrss_admin_settings() { |
| 36 |
|
|
| 37 |
$form = array(); |
$key = variable_get(ADMINRSS_VAR_KEY, ''); |
| 38 |
$form['adminrss_key'] = array( |
|
| 39 |
'#type' => 'textfield', |
$form = array(); |
| 40 |
'#title' => t('Admin RSS Key'), |
$form[ADMINRSS_VAR_KEY] = array( |
| 41 |
'#required' => TRUE, |
'#type' => 'textfield', |
| 42 |
'#description' => t('This is the key that will be required in order to get access to the admin RSS feeds.'), |
'#title' => t('Admin RSS Key'), |
| 43 |
'#default_value' => $key, |
'#required' => TRUE, |
| 44 |
'#weight' => -5); |
'#description' => t('This is the key that will be required in order to get access to the admin RSS feeds.'), |
| 45 |
|
'#size' => 50, |
| 46 |
if (!empty($key)) { |
'#maxlength' => 255, |
| 47 |
$form['feeds'] = array( |
'#default_value' => $key, |
| 48 |
'#type' => 'markup', |
'#weight' => -5 |
| 49 |
'#value' => t('<ul>Admin RSS Feeds locations: <li>!nodefeed</li><li>!commentfeed</li></ul>', |
); |
| 50 |
array( |
|
| 51 |
'!nodefeed' => l(t('Nodes feed'), "adminrss/node/$key"), |
if (!empty($key)) { |
| 52 |
'!commentfeed' => l(t('Comments feed'), "adminrss/comment/$key") |
$form['feeds'] = array( |
| 53 |
) |
'#type' => 'fieldset', |
| 54 |
), |
'#title' => t('Admin RSS Feeds locations'), |
| 55 |
); |
'#description' => t('Copy and paste these links to your RSS aggregator.'), |
| 56 |
} |
); |
| 57 |
return system_settings_form($form); |
$form['feeds']['links'] = array( |
| 58 |
} |
'#type' => 'markup', |
| 59 |
|
'#value' => t('<ul><li>!nodefeed</li><li>!commentfeed</li></ul>', |
| 60 |
/** |
array( |
| 61 |
* Implementation of hook_menu(). |
'!nodefeed' => l(t('Nodes feed'), ADMINRSS_PATH_HOME ."/node/$key"), |
| 62 |
* |
'!commentfeed' => l(t('Comments feed'), ADMINRSS_PATH_HOME ."/comment/$key") |
| 63 |
*/ |
) |
| 64 |
|
), |
| 65 |
function adminrss_menu($may_cache) { |
); |
| 66 |
$items = array(); |
} |
| 67 |
|
|
| 68 |
if ($may_cache) { |
$form[ADMINRSS_VAR_LINK_TYPE] = array( |
| 69 |
$items[] = array( |
'#type' => 'select', |
| 70 |
'path' => 'adminrss', |
'#title' => t('Comment feed links back to'), |
| 71 |
'title' => 'Admin RSS Feed', |
'#options' => array( |
| 72 |
'callback' => 'adminrss_handler', |
0 => t('Comment approval queue'), |
| 73 |
'access' => TRUE, |
1 => t('Individual comment edit'), |
| 74 |
'type' => MENU_CALLBACK |
), |
| 75 |
); |
'#default_value' => variable_get(ADMINRSS_VAR_LINK_TYPE, 0), |
| 76 |
$items[] = array( |
); |
| 77 |
'path' => 'adminrss/publish', |
|
| 78 |
'title' => 'Publish', |
return system_settings_form($form); |
| 79 |
'callback' => 'adminrss_publish', |
} |
| 80 |
'access' => user_access('administer nodes'), |
|
| 81 |
'type' => MENU_CALLBACK |
/** |
| 82 |
); |
* Implementation of hook_menu(). |
| 83 |
$items[] = array( |
* |
| 84 |
'path' => 'adminrss/publish_promote', |
* @param boolean $may_cache |
| 85 |
'title' => 'Publish and promote', |
* @return array |
| 86 |
'callback' => 'adminrss_publish_and_promote', |
*/ |
| 87 |
'access' => user_access('administer nodes'), |
function adminrss_menu($may_cache) { |
| 88 |
'type' => MENU_CALLBACK |
$items = array(); |
| 89 |
); |
|
| 90 |
$items[] = array( |
if ($may_cache) { |
| 91 |
'path' => 'admin/settings/adminrss', |
$items[] = array( |
| 92 |
'title' => 'Admin RSS Feed', |
'path' => ADMINRSS_PATH_HOME, |
| 93 |
'description' => t('Configure access to the Admin RSS feeds.'), |
'title' => t('Admin RSS Feed'), |
| 94 |
'callback' => 'drupal_get_form', |
'callback' => 'adminrss_handler', |
| 95 |
'callback arguments' => array('adminrss_admin_settings'), |
'access' => TRUE, |
| 96 |
'access' => user_access('administer site configuration'), |
'type' => MENU_CALLBACK |
| 97 |
'type' => MENU_NORMAL_ITEM, |
); |
| 98 |
); |
$items[] = array( |
| 99 |
} |
'path' => ADMINRSS_PATH_SETTINGS, |
| 100 |
|
'title' => t('Admin RSS Feed'), |
| 101 |
return $items; |
'description' => t('Configure access to the Admin RSS feeds.'), |
| 102 |
} |
'callback' => 'drupal_get_form', |
| 103 |
|
'callback arguments' => array('adminrss_admin_settings'), |
| 104 |
/** |
'access' => user_access('administer site configuration'), |
| 105 |
* The handler for admin RSS |
'type' => MENU_NORMAL_ITEM, |
| 106 |
* |
); |
| 107 |
* If the $type is not set to either 'node' or 'comment' or the key is not set, |
} |
| 108 |
* the function returns 401 |
|
| 109 |
*/ |
return $items; |
| 110 |
function adminrss_handler($type = NULL, $key = NULL) { |
} |
| 111 |
if (isset($type) && isset($key) && ($key == ADMINRSS_KEY)) { |
|
| 112 |
if (in_array($type, array('node', 'comment'))) { |
/** |
| 113 |
if (call_user_func('adminrss_feed_' . $type)) { |
* The handler for admin RSS |
| 114 |
return; |
* |
| 115 |
} |
* If the $type is not set to either 'node' or 'comment' or the key is not set, |
| 116 |
} |
* the function returns 401. |
| 117 |
} |
* |
| 118 |
else { |
* @param string $type |
| 119 |
//error must specify both a type and provide a key |
* @param string $key |
| 120 |
drupal_access_denied(); |
* @return void |
| 121 |
} |
*/ |
| 122 |
} |
function adminrss_handler($type = NULL, $key = NULL) { |
| 123 |
|
if (isset($type) && isset($key) && ($key == variable_get(ADMINRSS_VAR_KEY, ''))) { |
| 124 |
/** |
if (in_array($type, array('node', 'comment'))) { |
| 125 |
* Publish the comment/node and then redirect to the node. Uses Drupal auth. |
if (call_user_func('adminrss_feed_'. $type)) { |
| 126 |
*/ |
return; |
| 127 |
function adminrss_publish($type, $nid){ |
} |
| 128 |
if (isset($type) && isset($nid) && in_array($type, array('node', 'comment'))){ |
} |
| 129 |
if ($type=='node'){ |
} |
| 130 |
node_operations_publish(array($nid)); |
else { |
| 131 |
drupal_goto('node/'.$nid); |
//error must specify both a type and provide a key |
| 132 |
} else { |
drupal_set_message(t('You must specify valid type and key information to access an AdminRSS feed.'), 'error'); |
| 133 |
$comment = _comment_load($nid); |
drupal_access_denied(); |
| 134 |
db_query('UPDATE {comments} SET status=0 WHERE cid='.$nid); |
} |
| 135 |
drupal_goto("node/$comment->nid",NULL,"comment-$comment->cid"); |
} |
| 136 |
} |
|
| 137 |
} else { |
/** |
| 138 |
drupal_access_denied(); |
* Output a node feed for nodes under moderation |
| 139 |
} |
* |
| 140 |
} |
* @return string |
| 141 |
|
*/ |
| 142 |
/** |
function adminrss_feed_node() { |
| 143 |
* Publish and promote the node to the front page. |
$result = db_query_range('SELECT n.nid, n.title, n.changed, u.name, u.uid |
| 144 |
*/ |
FROM {node} n |
| 145 |
function adminrss_publish_and_promote($nid){ |
INNER JOIN {users} u ON n.uid = u.uid |
| 146 |
if (isset($nid)){ |
WHERE n.status = 0 AND n.moderate = 1 |
| 147 |
node_operations_publish(array($nid)); |
ORDER BY n.changed DESC', 0, 15); |
| 148 |
node_operations_promote(array($nid)); |
node_feed($result, array('description' => t('Unapproved Nodes for Administration'))); |
| 149 |
drupal_goto('node/'.$nid); |
} |
| 150 |
} else { |
|
| 151 |
drupal_access_denied(); |
/** |
| 152 |
} |
* Output a comment feed for comments under moderation |
| 153 |
} |
* |
| 154 |
|
* Items include a link to the comment on the node page and the node title, |
| 155 |
/** |
* to make it easier to check whether the comment is on topic. |
| 156 |
* Output a node feed for nodes under moderation |
* |
| 157 |
*/ |
* @return string |
| 158 |
function adminrss_feed_node() { |
*/ |
| 159 |
$result = db_query_range('SELECT n.nid, n.title, n.changed, u.name, u.uid |
function adminrss_feed_comment() { |
| 160 |
FROM {node} n |
$result = db_query_range('SELECT c.timestamp, c.subject, c.cid, c.nid, n.title, c.comment |
| 161 |
INNER JOIN {users} u ON n.uid = u.uid |
FROM {comments} c |
| 162 |
WHERE n.status = 0 AND n.moderate = 1 |
INNER JOIN {node} n ON c.nid = n.nid |
| 163 |
ORDER BY n.changed DESC', 0, 15); |
WHERE c.status = 1 |
| 164 |
$items = ''; |
ORDER BY c.timestamp DESC ', 0, 15); |
| 165 |
while ($results = db_fetch_object($result)) { |
$items = ''; |
| 166 |
$node = node_load($results->nid); |
$link_type = variable_get(ADMINRSS_LINK_TYPE, 0); |
| 167 |
$link = url('node/edit/'. $node->nid, NULL,NULL,TRUE); |
while ($comment = db_fetch_object($result)) { |
| 168 |
$content = '<p>'.t($node->type.': !node', array('!node' => l($node->title, "node/$node->nid", NULL, NULL, NULL))).'</p>'; |
switch ($link_type) { |
| 169 |
// Insert actions |
case 0: // approval queue |
| 170 |
$content .= '<p>'.l(t('publish'),'adminrss/publish/node/'.$node->nid, NULL, NULL, NULL).'|'.l(t('publish and promote'),'adminrss/publish_promote/'.$node->nid, NULL, NULL, NULL).'</p>'; |
$link = url('admin/content/comment/list/approval', NULL, NULL, TRUE); |
| 171 |
if (!empty($node->body)) { |
break; |
| 172 |
$content .= " : \n" . filter_xss($node->body); |
case 1: // individual edit link |
| 173 |
} |
$link = url("comment/edit/$comment->cid", NULL, NULL, TRUE); |
| 174 |
$items .= format_rss_item($comment->subject, $link, $content, array('pubDate' => date('r', $node->timestamp))); |
// Old-style links below: |
| 175 |
} |
// url("node/{$comment->nid}", NULL, "comment-{$comment->cid}", TRUE); |
| 176 |
adminrss_format_feed($items, array( |
break; |
| 177 |
'description' => t('Unapproved Nodes for Administration'), |
default: // site home |
| 178 |
'title' => variable_get('site_name', 'drupal') . ' - ' . t('Nodes'), |
$link = base_path(); |
| 179 |
)); |
} |
| 180 |
} |
$content = t('Comment on node !node', array('!node' => l($comment->title, "node/$comment->nid", NULL, NULL, "comment-$comment->cid"))); |
| 181 |
|
if (!empty($comment->comment)) { |
| 182 |
/** |
$content .= " : \n" . filter_xss($comment->comment); |
| 183 |
* Output a comment feed for comments under moderation |
} |
| 184 |
* Items include a link to the comment on the node page and the node title, |
$items .= format_rss_item($comment->subject, $link, $content, array('pubDate' => date('r', $comment->timestamp))); |
| 185 |
* to make it easier to check whether the comment is on topic. |
// $comment = db_fetch_object($result)) { |
| 186 |
*/ |
// $items[] = $comment->subject .' - '. format_date($comment->timestamp, 'medium') .'<br />['. l(t('node'), 'node/'. $comment->nid, array('title' => $comment->title)) .']|['. l(t('edit'), 'comment/edit/'. $comment->cid) .']|['. l(t('delete'), 'admin/comment/delete/'. $comment->cid) .']'; |
| 187 |
function adminrss_feed_comment() { |
} |
| 188 |
$result = db_query_range('SELECT c.timestamp, c.subject, c.cid, c.nid, n.title, c.comment |
adminrss_format_feed($items, array('description' => t('Unapproved Comments for Administration'))); |
| 189 |
FROM {comments} c |
} |
| 190 |
INNER JOIN {node} n ON c.nid = n.nid |
|
| 191 |
WHERE c.status = 1 |
/** |
| 192 |
ORDER BY c.timestamp DESC ', 0, 15); |
* Note this function was originally identical to the commentrss.module's |
| 193 |
$items = ''; |
* function commentrss_format_feed() |
| 194 |
while ($comment = db_fetch_object($result)) { |
* |
| 195 |
$link = url('comment/edit/'. $comment->cid, NULL,NULL,TRUE); // url("node/{$comment->nid}", NULL, "comment-{$comment->cid}", TRUE); |
* @param array $items |
| 196 |
$content = t('Comment on node !node', array('!node' => l($comment->title, "node/$comment->nid", NULL, NULL, "comment-$comment->cid"))); |
* @param array $channel |
| 197 |
$content .= '<p>'.l(t('publish'),'adminrss/publish/comment/'.$comment->cid, NULL, NULL, NULL).'</p>'; |
* @return void |
| 198 |
if (!empty($comment->comment)) { |
*/ |
| 199 |
$content .= "\n" . filter_xss($comment->comment); |
function adminrss_format_feed($items, $channel = array()) { |
| 200 |
} |
global $base_url; |
| 201 |
$items .= format_rss_item($comment->subject, $link, $content, array('pubDate' => date('r', $comment->timestamp))); |
|
| 202 |
} |
$languages = (function_exists('locale') |
| 203 |
adminrss_format_feed($items, array( |
? locale_supported_languages() |
| 204 |
'description' => t('Unapproved Comments for Administration'), |
: array('name' => array('en' => 'English'))); |
| 205 |
'title' => variable_get('site_name', 'drupal') . ' - ' . t('Comments'), |
$channel_defaults = array( |
| 206 |
)); |
'version' => '0.92', |
| 207 |
} |
'title' => variable_get('site_name', 'drupal') .' - '. t('Comments'), |
| 208 |
|
'link' => $base_url, |
| 209 |
/** |
'description' => t('Comments'), |
| 210 |
* Note this function was originally identical to the commentrss.module's |
'language' => (($key = reset(array_keys($languages['name']))) ? $key : 'en') |
| 211 |
* function commentrss_format_feed() |
); |
| 212 |
*/ |
$channel = array_merge($channel_defaults, $channel); |
| 213 |
function adminrss_format_feed($items, $channel = array()) { |
|
| 214 |
global $base_url; |
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" |
| 215 |
|
."<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">]>\n" |
| 216 |
$languages = (function_exists('locale') |
."<rss version=\"". $channel["version"] ."\" xml:base=\"". $base_url ."\">\n" |
| 217 |
? locale_supported_languages() |
. format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']) |
| 218 |
: array('name' => array('en' => 'English'))); |
."</rss>\n"; |
| 219 |
$channel_defaults = array( |
|
| 220 |
'version' => '0.92', |
drupal_set_header('Content-Type: text/xml; charset=utf-8'); |
| 221 |
'title' => variable_get('site_name', 'drupal') . ' - ' . t('AdminRSS'), |
print $output; |
| 222 |
'link' => $base_url, |
} |
|
'description' => t('AdminRSS'), |
|
|
'language' => (($key = reset(array_keys($languages['name']))) ? $key : 'en') |
|
|
); |
|
|
$channel = array_merge($channel_defaults, $channel); |
|
|
|
|
|
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" |
|
|
. "<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">]>\n" |
|
|
. "<rss version=\"". $channel["version"] . "\" xml:base=\"". $base_url ."\">\n" |
|
|
. format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']) |
|
|
. "</rss>\n"; |
|
|
|
|
|
drupal_set_header('Content-Type: text/xml; charset=utf-8'); |
|
|
print $output; |
|
|
} |
|