--- recent_changes.module.old 2008-02-28 16:00:30.859375000 +0100
+++ recent_changes.module 2008-02-28 16:03:15.218750000 +0100
@@ -1,21 +1,24 @@
'.t('The recent changes module offers a page which shows all recent changes on nodes. The page can be viewed by anyone with the access content permission, but no content is shown for node types the user has no permissions for. If you have the diff module installed, a link to the diff-view will be offered in the table. A feed of all recent changes, or per content type is also available. Headers of inaccessible content can be shown in feeds, depending on the settings in the recent changes administrative page.').'
';
+ $output = ''.t('The recent changes module offers a page which shows all recent changes on nodes and comments. The page can be viewed by anyone with the access recent changes permission, but no content is shown for node types the user has no permissions for. If you have the diff module installed, a link to the diff-view will be offered in the table. A feed of all recent changes, or per content type is also available. You can use the Secure Site module to provide a login mechanism for the RSS feed at ' . $base_url . '/recent_changes/feed.').'
';
return $output;
- break;
- }
+ }
}
/**
@@ -28,7 +31,7 @@ function recent_changes_menu($may_cache)
'title' => t('Recent changes'),
'path' => 'recent_changes',
'callback' => 'recent_changes_view',
- 'access' => user_access('access content'),
+ 'access' => user_access('access recent changes'),
'type' => MENU_NORMAL_ITEM
);
$items[] = array(
@@ -43,6 +46,9 @@ function recent_changes_menu($may_cache)
return $items;
}
+function recent_changes_perm() {
+ return array('access recent changes');
+}
/**
* Settings form
@@ -51,147 +57,112 @@ function recent_changes_admin_settings()
$form = array();
$form['general_settings'] = array(
- '#type' => 'fieldset',
- '#title' => t('Recent changes general settings'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- '#weight' => -3
- );
-
+ '#type' => 'fieldset',
+ '#title' => t('Recent changes general settings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ '#weight' => -3,
+ '#description' => t('The settings in this block apply to both the recent changes page and the recent changes feed.'),
+ );
$form['general_settings']['recent_changes_allowed_node_types'] = array(
- '#type' => 'select',
- '#title' => t('Allowed content types'),
- '#default_value' => variable_get('recent_changes_allowed_node_types', array()),
- '#options' => node_get_types('names'),
- '#multiple' => TRUE,
- '#description' => t('Select the content types that will be shown on the recent changes page and in recent changes feeds. Select none to list all content types. Note that nodes or comments that are inaccessible to a user will not be listed on his or her recent changes page, but headers of inaccessible nodes and comments might show up in recent changes feeds, depending on the settings below.'),
- );
-
+ '#type' => 'select',
+ '#title' => t('Allowed content types'),
+ '#default_value' => variable_get('recent_changes_allowed_node_types', array()),
+ '#options' => node_get_types('names'),
+ '#multiple' => TRUE,
+ '#description' => t('Select the content types that will be shown on the recent changes page and in recent changes feeds. Select none to list all content types. Note that nodes or comments that are inaccessible to a user will not be listed on his or her recent changes page or in recent changes feeds.'),
+ );
$form['general_settings']['recent_changes_show_comments']= array(
- '#type' => 'checkbox',
- '#title' => t('Show comments'),
- '#return_value' => 2,
- '#default_value' => variable_get('recent_changes_show_comments', TRUE),
- '#description' => t('Add a comments option to the content type filter on the recent changes page. To enable the selection of comments for a certain content type in the content type filter, you should enable multiple filter selection below.'),
- );
-
+ '#type' => 'checkbox',
+ '#title' => t('Show comments'),
+ '#return_value' => 2,
+ '#default_value' => variable_get('recent_changes_show_comments', TRUE),
+ '#description' => t('Add a comments option to the content type filter on the recent changes page. To enable the selection of comments for a certain content type in the content type filter, you should enable multiple filter selection below.'),
+ );
$form['page_settings'] = array(
- '#type' => 'fieldset',
- '#title' => t('Recent changes page settings'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- '#weight' => -2
- );
-
+ '#type' => 'fieldset',
+ '#title' => t('Recent changes page settings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ '#weight' => -2,
+ '#description' => t('Settings for the recent changes page.'),
+ );
$form['page_settings']['recent_changes_entries_per_page']= array(
- '#type' => 'textfield',
- '#title' => t('Entries per page'),
- '#size' => 5,
- '#maxlength' => 4,
- '#default_value' => variable_get('recent_changes_entries_per_page', 50),
- '#description' => t('The number of entries per page'),
- );
-
+ '#type' => 'textfield',
+ '#title' => t('Entries per page'),
+ '#size' => 5,
+ '#maxlength' => 4,
+ '#default_value' => variable_get('recent_changes_entries_per_page', 50),
+ '#description' => t('The number of entries per page'),
+ );
$form['page_settings']['recent_changes_show_filter']= array(
- '#type' => 'checkbox',
- '#title' => t('Show content type filter'),
- '#return_value' => 1,
- '#default_value' => variable_get('recent_changes_show_filter', TRUE),
- '#description' => t('Enable to show the content type filter on top of the recent changes page'),
- );
-
+ '#type' => 'checkbox',
+ '#title' => t('Show content type filter'),
+ '#return_value' => 1,
+ '#default_value' => variable_get('recent_changes_show_filter', TRUE),
+ '#description' => t('Enable to show the content type filter on top of the recent changes page'),
+ );
$form['page_settings']['recent_changes_type_select_size'] = array(
- '#type' => 'select',
- '#title' => t('Number of visible content types in content type filter'),
- '#default_value' => variable_get('recent_changes_type_select_size', 5),
- '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
- '#description' => t('The number of rows that will be displayed in the content type filter. Hint: select 1 in case multiple selection is disabled!'),
- );
-
+ '#type' => 'select',
+ '#title' => t('Number of visible content types in content type filter'),
+ '#default_value' => variable_get('recent_changes_type_select_size', 5),
+ '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
+ '#description' => t('The number of rows that will be displayed in the content type filter. Hint: select 1 in case multiple selection is disabled!'),
+ );
$form['page_settings']['recent_changes_allow_multiple_filter']= array(
- '#type' => 'checkbox',
- '#title' => t('Allow multiple content type selection'),
- '#return_value' => 1,
- '#default_value' => variable_get('recent_changes_allow_multiple_filter', TRUE),
- '#description' => t('Allow multiple selection in the content type filter.'),
- );
-
+ '#type' => 'checkbox',
+ '#title' => t('Allow multiple content type selection'),
+ '#return_value' => 1,
+ '#default_value' => variable_get('recent_changes_allow_multiple_filter', TRUE),
+ '#description' => t('Allow multiple selection in the content type filter.'),
+ );
$form['feed_settings'] = array(
- '#type' => 'fieldset',
- '#title' => t('Recent changes feed settings'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- '#weight' => -1,
- '#description' => t('A feed is available for the recent items page. Links to feeds per content type are also available when a single content type is selected in the content type filter.'),
- );
-
- $form['feed_settings']['recent_changes_list_inacces_revisions_in_feeds']= array(
- '#type' => 'checkbox',
- '#title' => t('List inaccessible revisions'),
- '#return_value' => 1,
- '#default_value' => variable_get('recent_changes_list_inacces_revisions_in_feeds', TRUE),
- '#description' => t('Usually no login takes place when the recent changes feed is accessed, which means that older revisions might not be accessible. Enable this option to list revisions in feeds even if the \'view revisions\' permission is disabled for anonymous users. Note that titles of inaccessible content can be replaced by \'access denied\' messages by disabling the checkbox below.'),
- );
-
- $form['feed_settings']['recent_changes_list_inacces_nodes_in_feeds']= array(
- '#type' => 'checkbox',
- '#title' => t('List inaccessible nodes'),
- '#return_value' => 1,
- '#default_value' => variable_get('recent_changes_list_inacces_nodes_in_feeds', TRUE),
- '#description' => t('Usually no login takes place when the recent changes feed is accessed, which means certain content types might be inaccessible. Enable this option to list inaccessible nodes in feeds. Note that titles of inaccessible content can be replaced by \'access denied\' messages by disabling the checkbox below.'),
- );
-
- $form['feed_settings']['recent_changes_show_access_denied_titles']= array(
- '#type' => 'checkbox',
- '#title' => t('Show titles of inaccessible content'),
- '#return_value' => 1,
- '#default_value' => variable_get('recent_changes_show_access_denied_titles', TRUE),
- '#description' => t('Usually no login takes place when the recent changes feed is accessed, which means certain nodes, comments or revisions migth be inaccessible. Enable this option to show the titles of inaccessible nodes. Note that the content of inaccessible nodes will never be displayed in feeds.'),
- );
-
+ '#type' => 'fieldset',
+ '#title' => t('Recent changes feed settings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ '#weight' => -1,
+ '#description' => t('A feed is available for the recent items page. Links to feeds per content type are also available when a single content type is selected in the content type filter.'),
+ );
$form['feed_settings']['recent_changes_show_diff']= array(
- '#type' => 'checkbox',
- '#title' => t('Show diffs in feeds'),
- '#return_value' => 1,
- '#default_value' => variable_get('recent_changes_show_diffs', TRUE),
- '#description' => t('When the diff module is installed and the length of XML items (see below) is set to \'Full text\', the difference between a revision of a node and its predecessor can be shown. Check this box to enable this feature.'),
- );
-
+ '#type' => 'checkbox',
+ '#title' => t('Show diffs in feeds'),
+ '#return_value' => 1,
+ '#default_value' => variable_get('recent_changes_show_diff', TRUE),
+ '#description' => t('When the diff module is installed and the length of XML items (see below) is set to \'Full text\', the difference between a revision of a node and its predecessor can be shown. Check this box to enable this feature.'),
+ );
$form['feed_settings']['recent_changes_feed_default_items'] = array(
- '#type' => 'select',
- '#title' => t('Number of items per feed'),
- '#default_value' => variable_get('recent_changes_feed_default_items', 10),
- '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
- '#description' => t('The default number of items to include in the recent changes feed.'),
- );
-
+ '#type' => 'select',
+ '#title' => t('Number of items per feed'),
+ '#default_value' => variable_get('recent_changes_feed_default_items', 10),
+ '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
+ '#description' => t('The default number of items to include in the recent changes feed.'),
+ );
$form['feed_settings']['recent_changes_feed_item_type']= array(
- '#type' => 'select',
- '#title' => t('Display of XML feed items'),
- '#default_value' => variable_get('recent_changes_feed_item_type', 'teaser'),
- '#options' => array('title' => 'Titles only', 'teaser' => 'Titles plus teaser', 'fulltext' => 'Full text'),
- '#multiple' => FALSE,
- '#description' => t('The length of XML items in the recent changes feed.'),
- );
+ '#type' => 'select',
+ '#title' => t('Display of XML feed items'),
+ '#default_value' => variable_get('recent_changes_feed_item_type', 'teaser'),
+ '#options' => array('title' => 'Titles only', 'teaser' => 'Titles plus teaser', 'fulltext' => 'Full text'),
+ '#multiple' => FALSE,
+ '#description' => t('The length of XML items in the recent changes feed.'),
+ );
return system_settings_form($form);
}
-
/**
* Menu callback.
*/
function recent_changes_view() {
// Print feed if requested or display normal page otherwise
if (arg(1) === 'feed') {
- return recent_changes_feed(arg(2));
+ return recent_changes_feed(arg(2));
}
else {
return recent_changes_page();
}
}
-
/**
* Page display of recent changes.
*/
@@ -202,7 +173,7 @@ function recent_changes_page() {
if ($_POST['op'] === t('Filter')) {
unset($_GET['page']);
}
-
+
// Initialize
$output = '';
$day = -1;
@@ -219,7 +190,7 @@ function recent_changes_page() {
else {
drupal_add_feed(url('recent_changes/feed', NULL, NULL, TRUE), t('Recent changes of !site', array('!site' => variable_get('site_name', 'drupal'))));
}
-
+
// Show filter if enabled
$output .= (variable_get('recent_changes_show_filter', TRUE)) ? drupal_get_form('recent_changes_filter_form') : '';
@@ -227,65 +198,62 @@ function recent_changes_page() {
$header = array('', '', t('Type'), t('Title'), t('User'), t('Log'));
// SQL results provided by pager implementation
- list($sql, $count_sql) = _recent_changes_query($node_types, user_access('view revisions'));
+ list($sql, $count_sql) = _recent_changes_query($node_types);
$sql_results = pager_query($sql, variable_get('recent_changes_entries_per_page', 50), 0, $count_sql);
-
+
// put database results in $results
$results = array();
while ($db_item = db_fetch_object($sql_results)) {
$results[] = $db_item;
}
-
+
// parse results into items
$items = _recent_changes_parse_results($results);
-
+
foreach ($items as $item) {
// Check if day of week changed and if yes output the new day.
$current_day = format_date($item->timestamp, 'custom', 'z');
if ($day != $current_day) {
$day = $current_day;
$rows[] = array(
- array(
+ array(
'data' => format_date($item->timestamp, 'custom', 'D, j F Y'),
'colspan' => '6',
'class' => 'date'
- )
- );
+ )
+ );
}
// Add the items
$rows[] = array(
- $item->op_link,
- format_date($item->timestamp, 'custom', 'H:i'),
- $item->node_type_name,
- '' . $item->flag . ' ' . call_user_func_array('l', array_merge(array($item->item_title), $item->link_array)) . (($item->item_title_add) ? '
'. $item->item_title_add : ''),
- $item->user_link,
- $item->log_text,
+ $item->op_link,
+ format_date($item->timestamp, 'custom', 'H:i'),
+ $item->node_type_name,
+ '' . $item->flag . ' ' . call_user_func_array('l', array_merge(array($item->item_title), $item->link_array)) . (($item->item_title_add) ? '
'. $item->item_title_add : ''),
+ $item->user_link,
+ $item->log_text,
);
}
// Print table and pager
- $output .= theme('table', $header, $rows, array('class' => 'recent-changes'));
+ $output .= theme('table', $header, $rows, array('class' => 'recent-changes'));
$output .= theme('pager', NULL, variable_get('recent_changes_entries_per_page', 50), 0);
return($output);
}
-
/**
* RSS feed of recent changes.
*/
function recent_changes_feed($node_types = NULL) {
global $base_url;
- $list_inaccess_content = variable_get('recent_changes_list_inacces_nodes_in_feeds', TRUE);
- $node_types = ($list_inaccess_content) ? _recent_changes_array_node_types($node_types) : _recent_changes_parse_node_types($node_types);
- $show_access_denied_titles = variable_get('recent_changes_show_access_denied_titles', TRUE);
+ $node_types = _recent_changes_parse_node_types($node_types);
$item_type = variable_get('recent_changes_feed_item_type', 'teaser');
+ $access_revisions = user_access('view revisions');
$teaser = ($item_type == 'teaser');
- $load_revisions = user_access('view revisions') || variable_get('recent_changes_list_inacces_revisions_in_feeds', TRUE);
// perform sql query
- list($sql, $count_sql) = _recent_changes_query($node_types, $load_revisions);
+ list($sql, $count_sql) = _recent_changes_query($node_types);
$sql_results = db_query($sql . " LIMIT %d", variable_get('recent_changes_feed_default_items', 10));
// put database results in $results
@@ -311,10 +279,10 @@ function recent_changes_feed($node_types
// load node to check node access, and check access if the loaded node is an older revision
$node = node_load($item->nid, $item->vid);
- $node_access = node_access('view', $node) && ($item->is_current_revision || user_access('view revisions'));
+ $node_access = node_access('view', $node) && ($item->is_current_revision || $access_revisions);
$prev_revision = ($item->prev_revision) ? node_load($item->nid, $item->prev_revision->vid) : NULL;
- $prev_revision_access = ($prev_revision) ? (node_access('view', $prev_revision) && user_access('view revisions')) : FALSE;
+ $prev_revision_access = ($prev_revision) ? (node_access('view', $prev_revision) && $access_revisions) : FALSE;
$load_diff = module_exists('diff') && variable_get('recent_changes_show_diff', TRUE) && !$is_comment && $prev_revision_access && ($item_type == 'fulltext');
$load_node_text = $node_access && ($item_type != 'title') && !$load_diff;
@@ -322,8 +290,8 @@ function recent_changes_feed($node_types
// load node or comment body text
if ($load_node_text) {
if ($is_comment) {
- $body_text = $item->comment_text;
- $teaser_text = node_teaser($body_text, $node->format);
+ $body_text = $item->comment_text;
+ $teaser_text = node_teaser($body_text, $node->format);
$node->body = check_markup($body_text, $node->format, FALSE);
$node->teaser = check_markup($teaser_text, $node->format, FALSE);
$node->readmore = ($teaser && (strlen($teaser_text) < strlen($body_text)));
@@ -334,9 +302,7 @@ function recent_changes_feed($node_types
$extra = node_invoke_nodeapi($node, 'rss item');
}
}
-
- // load diff
- if($load_diff) {
+ elseif($load_diff) { // load diff as body text
$node->body = _recent_changes_get_diff($node, $prev_revision);
}
@@ -344,11 +310,11 @@ function recent_changes_feed($node_types
if (!$node_access) {
$node->body = t('You are not authorized to access this item.');
$node->teaser = t('You are not authorized to access this item.');
- $title = ($show_access_denied_titles) ? $title : t('Access denied');
+ $title = t('Access denied');
}
// add additional info at the first line of the body text
- if (($item->item_title_add) && ($node_access || $show_access_denied_titles)) {
+ if (($item->item_title_add) && $node_access) {
$text = '' . (($is_comment) ? t('Comment') . ' ' . $item->item_title_add : ucfirst($item->item_title_add)) . '
';
}
@@ -371,8 +337,8 @@ function recent_changes_feed($node_types
// put in normal extra information
$extra = array_merge($extra,
array(
- array('key' => 'pubDate', 'value' => date('r', $item->timestamp)),
- array('key' => 'dc:creator', 'value' => $item->user_name),
+ array('key' => 'pubDate', 'value' => date('r', $item->timestamp)),
+ array('key' => 'dc:creator', 'value' => $item->user_name),
array('key' => 'guid', 'value' => $item->nid .' at '. $base_url . (($is_comment) ? ' comment '.$item->cid : ' revision '.$item->vid), 'attributes' => array('isPermaLink' => 'false')),
)
);
@@ -386,7 +352,7 @@ function recent_changes_feed($node_types
}
}
}
-
+
// RSS channel information
$single_node_type = count($node_types) == 1;
$filter_text = ($single_node_type) ? ' filtered by '. _recent_changes_node_type_name($node_types[0]) : '';
@@ -405,13 +371,12 @@ function recent_changes_feed($node_types
$output .= "\n";
// Set MIME type in HTML header
- drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
+ drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
// Print feed text
print $output;
}
-
/**
* Parsing of recent changes results
*/
@@ -430,9 +395,9 @@ function _recent_changes_parse_results($
// get previous revisions
$all_node_nid = implode(", ", array_keys($nids, TRUE));
- $where_nid = ($all_node_nid) ? "WHERE n.nid IN ($all_node_nid)" : "WHERE FALSE";
+ $where_nid = ($all_node_nid) ? "WHERE n.nid IN ($all_node_nid)" : "WHERE FALSE";
$revisions_result = db_query("SELECT n.nid, n.vid AS curr_vid, p.vid, p.title FROM {node_revisions} n LEFT JOIN {node_revisions} p ON ((n.nid = p.nid) AND (n.vid > p.vid)) $where_nid ORDER BY p.vid DESC");
-
+
while ($revision = db_fetch_object($revisions_result)) {
$curr_vid = $revision->curr_vid;
if(is_null($revision->vid)) {
@@ -441,7 +406,7 @@ function _recent_changes_parse_results($
$has_revisions[$revision->nid] = TRUE;
$prev_revisions[$curr_vid] = (!isset($prev_revisions[$curr_vid])) ? $revision : $prev_revisions[$curr_vid];
}
-
+
// parse results
foreach ($results as $result) {
$is_comment = ($result->cid != 0);
@@ -450,15 +415,15 @@ function _recent_changes_parse_results($
// the owner is the user specified in the {node} table (also called "author" in drupal terminology)
$owner_user->uid = $result->uid;
$owner_user->name = $result->name;
-
+
// the active user is the user that performed the update, or posted the revision or comment
$active_user->uid = $result->auid;
$active_user->name = $result->aname;
-
+
$is_current_revision = $result->vid == $result->cvid;
$show_revisions = $access_revisions && $has_revisions[$result->nid];
$show_diff_link = $prev_revision->vid && $exists_diff && $access_revisions;
- $moved = !$is_comment && $prev_revision->vid && ($prev_revision->title !== $result->title);
+ $moved = !$is_comment && $prev_revision->vid && ($prev_revision->title !== $result->title);
$flags = array(
'comment' => $is_comment,
@@ -475,7 +440,7 @@ function _recent_changes_parse_results($
$result_title = ($is_comment) ? $result->subject : $result->title;
$result_link = array("node/$result->nid" . (($is_comment || $is_current_revision) ? '' : "/revisions/$result->vid/view"), NULL, NULL, ($is_comment) ? "comment-$result->cid" : NULL);
$result_url = array("node/$result->nid" . (($is_comment || $is_current_revision) ? '' : "/revisions/$result->vid/view"), NULL, ($is_comment) ? "comment-$result->cid" : NULL);
-
+
$owner_intro_text = ($moved && $access_revisions) ? ', ' . t('from') . ' ' : t('author') . ': ';
$result_title_add = ($moved && $access_revisions) ? t('source: ') . l($prev_revision->title, "node/$result->nid/revisions/$prev_revision->vid/view") : '';
$result_title_add .= (!$is_comment && ($result->uid != $result->auid)) ? $owner_intro_text . theme('username', $owner_user) : '';
@@ -505,47 +470,45 @@ function _recent_changes_parse_results($
return($items);
}
-
/**
* Build SQL query depending on node type filter and comments filter.
- * Inaccessible node types should already have been filtered out by this stage.
- * If the load_revisions is false, only the recent changes from the {node} table are used, otherwise older revisions might also show up if they were recently changed.
-*/
-function _recent_changes_query($node_types, $load_revisions) {
- // show comments
+ * Inaccessible and unallowed node_types should already have been filtered out by this stage.
+ */
+function _recent_changes_query($node_types) {
+ // determins whether comments and revisions should be loaded
$comment_index = array_search('comment', $node_types);
- $show_comments = (!is_bool($comment_index) && !is_null($comment_index));
-
- // if only comments is selected, show comments for all allowed node types
+ $load_comments = (!is_bool($comment_index) && !is_null($comment_index));
+ $load_revisions = user_access('view revisions');
+
+ // if only comments is selected, show comments for all allowed node types
$comments_only = (count($node_types) == 1 && $node_types[0] === 'comment');
- $node_types = $comments_only ? _recent_changes_parse_node_types() : $node_types;
-
+ $node_types = ($comments_only) ? _recent_changes_parse_node_types() : $node_types;
+
// construct node type query (note that leading and trailing single quotes (') need to be added later)
$where_type = implode("', '", $node_types);
// construct where queries depending on whether the revision, node, or comment should be displayed
$node_where = ($where_type && !$comments_only && !$load_revisions) ? "WHERE n.type IN ('$where_type')" : "WHERE FALSE";
$revision_where = ($where_type && !$comments_only && $load_revisions) ? "WHERE n.type IN ('$where_type')" : "WHERE FALSE";
- $comment_where = ($where_type && $show_comments) ? "WHERE n.type IN ('$where_type')" : "WHERE FALSE";
-
+ $comment_where = ($where_type && $load_comments) ? "WHERE n.type IN ('$where_type')" : "WHERE FALSE";
+
// queries to get the selected nodes, comments and revisions for the selected node types
- $nodes_query = "SELECT n.nid, n.vid, n.vid AS cvid, n.uid, u.name, r.title, '' AS log, n.created, r.timestamp, n.type, 0 AS cid, '' AS subject, '' AS comment, r.uid AS auid, a.name AS aname FROM {node} n LEFT JOIN {node_revisions} r ON n.vid = r.vid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {users} a ON r.uid = a.uid $node_where AND n.status >= 1";
- $revisions_query = "SELECT r.nid, r.vid, n.vid AS cvid, n.uid, u.name, r.title, r.log, n.created, r.timestamp, n.type, 0 AS cid, '' AS subject, '' AS comment, r.uid AS auid, a.name AS aname FROM {node_revisions} r LEFT JOIN {node} n ON r.nid = n.nid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {users} a ON r.uid = a.uid $revision_where AND n.status >= 1";
- $comments_query = "SELECT c.nid, n.vid, n.vid AS cvid, n.uid, u.name, n.title, '' AS log, c.timestamp AS created, c.timestamp, n.type, c.cid, c.subject, c.comment, c.uid AS auid, c.name AS aname FROM {comments} c LEFT JOIN {node} n ON c.nid = n.nid LEFT JOIN {users} u ON n.uid = u.uid $comment_where AND n.status >= 1";
+ $nodes_query = db_rewrite_sql("SELECT n.nid, n.vid, n.vid AS cvid, n.uid, u.name, r.title, '' AS log, n.created, r.timestamp, n.type, 0 AS cid, '' AS subject, '' AS comment, r.uid AS auid, a.name AS aname FROM {node} n LEFT JOIN {node_revisions} r ON n.vid = r.vid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {users} a ON r.uid = a.uid $node_where AND n.status >= 1");
+ $revisions_query = db_rewrite_sql("SELECT r.nid, r.vid, n.vid AS cvid, n.uid, u.name, r.title, r.log, n.created, r.timestamp, n.type, 0 AS cid, '' AS subject, '' AS comment, r.uid AS auid, a.name AS aname FROM {node_revisions} r LEFT JOIN {node} n ON r.nid = n.nid LEFT JOIN {users} u ON n.uid = u.uid LEFT JOIN {users} a ON r.uid = a.uid $revision_where AND n.status >= 1");
+ $comments_query = db_rewrite_sql("SELECT c.nid, n.vid, n.vid AS cvid, n.uid, u.name, n.title, '' AS log, c.timestamp AS created, c.timestamp, n.type, c.cid, c.subject, c.comment, c.uid AS auid, c.name AS aname FROM {comments} c LEFT JOIN {node} n ON c.nid = n.nid LEFT JOIN {users} u ON n.uid = u.uid $comment_where AND n.status >= 1");
// counter queries
- $node_count = "SELECT COUNT(*) FROM {node} n $node_where AND n.status >= 1";
- $revision_count = "SELECT COUNT(*) FROM {node_revisions} r JOIN {node} n ON r.nid = n.nid $revision_where AND n.status >= 1";
- $comment_count = "SELECT COUNT(*) FROM {comments} c LEFT JOIN {node} n ON c.nid = n.nid $comment_where AND n.status >= 1";
-
+ $node_count = db_rewrite_sql("SELECT COUNT(*) FROM {node} n $node_where AND n.status >= 1");
+ $revision_count = db_rewrite_sql("SELECT COUNT(*) FROM {node_revisions} r JOIN {node} n ON r.nid = n.nid $revision_where AND n.status >= 1");
+ $comment_count = db_rewrite_sql("SELECT COUNT(*) FROM {comments} c LEFT JOIN {node} n ON c.nid = n.nid $comment_where AND n.status >= 1");
+
// unify queries
$sql = "($nodes_query) UNION ALL ($revisions_query) UNION ALL ($comments_query) ORDER BY timestamp DESC";
$sql_count = "SELECT ($node_count) + ($revision_count) + ($comment_count)";
-
+
return(array($sql, $sql_count));
}
-
/**
* Form for input filter.
*/
@@ -559,16 +522,16 @@ function recent_changes_filter_form() {
foreach ($node_types AS $type) {
$node_names[$type] = _recent_changes_node_type_name($type);
}
-
+
// content types have no weights, so we can safely sort them here
asort($node_names);
-
+
// add "All content types" if only single selection is allowed
$node_names = ($allow_multiple) ? $node_names : array_merge(array(FALSE => t('All content types')), $node_names);
$form = array();
$form['#attributes'] = array('class' => 'inline');
-
+
$form['recent_changes_filter_node_types'] = array(
'#type' => 'select',
'#title' => t('Filter content type'),
@@ -582,22 +545,34 @@ function recent_changes_filter_form() {
'#type' => 'button',
'#value' => t('Filter')
);
-
+
return $form;
}
-
-/*
-* Interface with the diff module. Returns a table with the differences between $node and $prev_revision
-*/
+/**
+ * Interface with the diff module. Returns a table with the differences between $node and $prev_revision
+ * We already checked whether diff module exists, so we should not do that here
+ */
function _recent_changes_get_diff($node, $prev_revision) {
- $item_text = '';
- $item_text .= ' | Revision of '. format_date($prev_revision->revision_timestamp) .' | | Revision of '. format_date($node->revision_timestamp) .' |
';
- $item_text .= _diff_table_body($prev_revision, $node);
- $item_text .= '
';
+ // Create diff
+ // Probably a newer (older??) version of diff module??
+ if (function_exists('_diff_body_rows')) {
+ $rows = _diff_body_rows($prev_revision, $node);
+ $cols = _diff_default_cols();
+ $header = _diff_default_headers();
+ $item_text = theme('diff_table', $header, $rows, array('class' => 'diff'), NULL, $cols);
+ }
+ else {
+ $item_text = '';
+ $item_text .= _diff_table_body($prev_revision, $node);
+ $item_text .= '
';
+ }
+
// Replace css classes from diff with actual style elements since we cannot reference a css file from the rss feed.
$patterns = array(
+ '/class=["\']diff-marker["\']/',
+ '/class=["\']diff-content["\']/',
'/class=["\']diff-section-title["\']/',
'/class=["\']diff-deletedline["\']/',
'/class=["\']diff-addedline["\']/',
@@ -606,6 +581,8 @@ function _recent_changes_get_diff($node,
);
$replacements = array(
+ 'style="width:1.4em;"',
+ 'style="width:50%;"',
'style="background-color: #f0f0ff;"',
'style="background-color: #ffa;width: 50%"',
'style="background-color: #afa;width: 50%"',
@@ -616,16 +593,22 @@ function _recent_changes_get_diff($node,
$item_text = preg_replace($patterns, $replacements, $item_text);
$item_text .= "
\n";
- return($item_text);
+ return $item_text;
}
-
-/*
-* Removes the node types to which the user has no access
-*/
+/**
+ * Removes the node types to which the user has no access
+ */
function _recent_changes_access_check($node_types) {
- // Check for each node type (and comments) whether current user has 'view' access to it
+ // Check with db_rewrite_sql which node types are not allowed (i.e. WHERE n.type NOT IN ('module_node_type_name'))
+ $tsql = db_rewrite_sql('SELECT * FROM node n');
+ $tpattern = '/n\.type\s*NOT\s*IN\s*(\(+)([\s*\'\w\'\,\s*]+)(\)+)/';
+ $tmatches = array();
+ preg_match_all($tpattern, $tsql, $tmatches);
+ $dbrw_node_types = preg_split("/[\s*\,\s*]+/", implode(',', $tmatches[2]));
+
+ // Check for each node type (and comments) whether current user has 'view' access to it
foreach ($node_types as $key=>$type) {
$access = FALSE;
if ($type == 'comment') {
@@ -637,11 +620,13 @@ function _recent_changes_access_check($n
$access = user_access('access content');
}
else {
- // this would be the right way to implement access checks, but unfortunately most modules don't implement it
+ // This would be the right way to implement access checks, but unfortunately most modules don't implement it
$access = module_invoke($module, 'access', 'view', NULL);
// If $access is empty, we try it another way:
- // First we request all possible permissions, then we check the first one with the word 'access' in it with the user_access command. If there is no permission with the word access in it, user_access('access content') is used. This works most of the time.
+ // First we request all possible permissions, then we check the first one with the word 'access' in it with
+ // the user_access command. If there is no permission with the word access in it, user_access('access content')
+ // is used. This works most of the time.
if (is_null($access)) {
$perms = module_invoke($module, 'perm');
$pattern = "/(?m)^access.*$/";
@@ -652,50 +637,51 @@ function _recent_changes_access_check($n
}
}
+ // Check if the node type is in db_rewrite_sql disallowed node types
+ $access &= !(in_array("'$type'", $dbrw_node_types));
+
// If the user has no access, remove the content type from the list
if (!$access) {
unset($node_types[$key]);
}
}
-
+
return($node_types);
}
-
/**
* Return allowed node types, including a 'comments' option
*/
function _recent_changes_get_allowed_node_types() {
$allowed_node_types = variable_get('recent_changes_allowed_node_types', array());
$allowed_node_types = ($allowed_node_types) ? $allowed_node_types : array_keys(node_get_types('names'));
-
+
// add comments option
$allowed_node_types = (variable_get('recent_changes_show_comments', TRUE)) ? array_merge(array('comment'), $allowed_node_types) : $allowed_node_types;
-
+
return $allowed_node_types;
}
-
/**
* Parse (and cache) node types, and perform access check
*/
function _recent_changes_parse_node_types($node_types = NULL) {
// do some caching in case node_types is NULL
static $all_parsed_node_types;
-
- $parse_all_node_types = is_null($node_types);
+
+ $parse_all_node_types = is_null($node_types);
// return cached version if available
if ($parse_all_node_types && isset($all_parsed_node_types)) {
return $all_parsed_node_types;
}
-
+
// put content types in an array, and use allowed_content_types if node_types was empty
$node_types = _recent_changes_array_node_types($node_types);
-
+
// perform access check
$node_types = _recent_changes_access_check($node_types);
-
+
// cache all parsed node types if all node types were requested
if ($parse_all_node_types) {
$all_parsed_node_types = $node_types;
@@ -704,11 +690,10 @@ function _recent_changes_parse_node_type
return($node_types);
}
-
/**
* Given an array or of node types or a single node type, this function returns the node types that are also in allowed node types
* If the input argument $node_types is NULL, all allowed node types are returned
- * Note that no access checking is performed here!
+ * Note that no access checking is performed here!
*/
function _recent_changes_array_node_types($node_types = NULL) {
$allowed_node_types = _recent_changes_get_allowed_node_types();