/[drupal]/contributions/modules/recent_changes/recent_changes.module
ViewVC logotype

Diff of /contributions/modules/recent_changes/recent_changes.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.5, Wed Feb 20 23:45:22 2008 UTC revision 1.1.2.6, Fri Feb 22 15:11:13 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: recent_changes.module,v 1.1.2.3 2007/03/07 03:20:50 roetzi Exp $  // $Id: recent_changes.module,v 1.1.2.5 2008/02/20 23:45:22 roetzi Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 43  function recent_changes_menu($may_cache) Line 43  function recent_changes_menu($may_cache)
43    return $items;    return $items;
44  }  }
45    
   
46  /**  /**
47   * Settings form   * Settings form
48   */   */
# Line 51  function recent_changes_admin_settings() Line 50  function recent_changes_admin_settings()
50    $form = array();    $form = array();
51    
52    $form['general_settings'] = array(    $form['general_settings'] = array(
53          '#type' => 'fieldset',      '#type' => 'fieldset',
54          '#title' => t('Recent changes general settings'),      '#title' => t('Recent changes general settings'),
55          '#collapsible' => TRUE,      '#collapsible' => TRUE,
56          '#collapsed' => FALSE,      '#collapsed' => FALSE,
57          '#weight' => -3      '#weight' => -3
58        );    );
   
59    $form['general_settings']['recent_changes_allowed_node_types'] = array(    $form['general_settings']['recent_changes_allowed_node_types'] = array(
60          '#type' => 'select',      '#type' => 'select',
61          '#title' => t('Allowed content types'),      '#title' => t('Allowed content types'),
62          '#default_value' => variable_get('recent_changes_allowed_node_types', array()),      '#default_value' => variable_get('recent_changes_allowed_node_types', array()),
63          '#options' => node_get_types('names'),      '#options' => node_get_types('names'),
64          '#multiple' => TRUE,      '#multiple' => TRUE,
65          '#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.'),      '#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.'),
66        );    );
   
67    $form['general_settings']['recent_changes_show_comments']= array(    $form['general_settings']['recent_changes_show_comments']= array(
68          '#type' => 'checkbox',      '#type' => 'checkbox',
69          '#title' => t('Show comments'),      '#title' => t('Show comments'),
70          '#return_value' => 2,      '#return_value' => 2,
71          '#default_value' => variable_get('recent_changes_show_comments', TRUE),      '#default_value' => variable_get('recent_changes_show_comments', TRUE),
72          '#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.'),      '#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.'),
73        );    );
   
74    $form['page_settings'] = array(    $form['page_settings'] = array(
75          '#type' => 'fieldset',      '#type' => 'fieldset',
76          '#title' => t('Recent changes page settings'),      '#title' => t('Recent changes page settings'),
77          '#collapsible' => TRUE,      '#collapsible' => TRUE,
78          '#collapsed' => FALSE,      '#collapsed' => FALSE,
79          '#weight' => -2      '#weight' => -2
80        );    );
   
81    $form['page_settings']['recent_changes_entries_per_page']= array(    $form['page_settings']['recent_changes_entries_per_page']= array(
82          '#type' => 'textfield',      '#type' => 'textfield',
83          '#title' => t('Entries per page'),      '#title' => t('Entries per page'),
84          '#size' => 5,      '#size' => 5,
85          '#maxlength' => 4,      '#maxlength' => 4,
86          '#default_value' => variable_get('recent_changes_entries_per_page', 50),      '#default_value' => variable_get('recent_changes_entries_per_page', 50),
87          '#description' => t('The number of entries per page'),      '#description' => t('The number of entries per page'),
88        );    );
   
89    $form['page_settings']['recent_changes_show_filter']= array(    $form['page_settings']['recent_changes_show_filter']= array(
90          '#type' => 'checkbox',      '#type' => 'checkbox',
91          '#title' => t('Show content type filter'),      '#title' => t('Show content type filter'),
92          '#return_value' => 1,      '#return_value' => 1,
93          '#default_value' => variable_get('recent_changes_show_filter', TRUE),      '#default_value' => variable_get('recent_changes_show_filter', TRUE),
94          '#description' => t('Enable to show the content type filter on top of the recent changes page'),      '#description' => t('Enable to show the content type filter on top of the recent changes page'),
95        );    );
   
96    $form['page_settings']['recent_changes_type_select_size'] = array(    $form['page_settings']['recent_changes_type_select_size'] = array(
97          '#type' => 'select',      '#type' => 'select',
98          '#title' => t('Number of visible content types in content type filter'),      '#title' => t('Number of visible content types in content type filter'),
99          '#default_value' => variable_get('recent_changes_type_select_size', 5),      '#default_value' => variable_get('recent_changes_type_select_size', 5),
100          '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),      '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
101          '#description' => t('The number of rows that will be displayed in the content type filter. Hint: select 1 in case multiple selection is disabled!'),      '#description' => t('The number of rows that will be displayed in the content type filter. Hint: select 1 in case multiple selection is disabled!'),
102        );    );
   
103    $form['page_settings']['recent_changes_allow_multiple_filter']= array(    $form['page_settings']['recent_changes_allow_multiple_filter']= array(
104          '#type' => 'checkbox',      '#type' => 'checkbox',
105          '#title' => t('Allow multiple content type selection'),      '#title' => t('Allow multiple content type selection'),
106          '#return_value' => 1,      '#return_value' => 1,
107          '#default_value' => variable_get('recent_changes_allow_multiple_filter', TRUE),      '#default_value' => variable_get('recent_changes_allow_multiple_filter', TRUE),
108          '#description' => t('Allow multiple selection in the content type filter.'),      '#description' => t('Allow multiple selection in the content type filter.'),
109        );    );
   
110    $form['feed_settings'] = array(    $form['feed_settings'] = array(
111          '#type' => 'fieldset',      '#type' => 'fieldset',
112          '#title' => t('Recent changes feed settings'),      '#title' => t('Recent changes feed settings'),
113          '#collapsible' => TRUE,      '#collapsible' => TRUE,
114          '#collapsed' => FALSE,      '#collapsed' => FALSE,
115          '#weight' => -1,      '#weight' => -1,
116          '#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.'),      '#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.'),
117        );    );
   
118    $form['feed_settings']['recent_changes_list_inacces_revisions_in_feeds']= array(    $form['feed_settings']['recent_changes_list_inacces_revisions_in_feeds']= array(
119          '#type' => 'checkbox',      '#type' => 'checkbox',
120          '#title' => t('List inaccessible revisions'),      '#title' => t('List inaccessible revisions'),
121          '#return_value' => 1,      '#return_value' => 1,
122          '#default_value' => variable_get('recent_changes_list_inacces_revisions_in_feeds', TRUE),      '#default_value' => variable_get('recent_changes_list_inacces_revisions_in_feeds', TRUE),
123          '#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.'),      '#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.'),
124        );    );
   
125    $form['feed_settings']['recent_changes_list_inacces_nodes_in_feeds']= array(    $form['feed_settings']['recent_changes_list_inacces_nodes_in_feeds']= array(
126          '#type' => 'checkbox',      '#type' => 'checkbox',
127          '#title' => t('List inaccessible nodes'),      '#title' => t('List inaccessible nodes'),
128          '#return_value' => 1,      '#return_value' => 1,
129          '#default_value' => variable_get('recent_changes_list_inacces_nodes_in_feeds', TRUE),      '#default_value' => variable_get('recent_changes_list_inacces_nodes_in_feeds', TRUE),
130          '#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.'),      '#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.'),
131        );    );
   
132    $form['feed_settings']['recent_changes_show_access_denied_titles']= array(    $form['feed_settings']['recent_changes_show_access_denied_titles']= array(
133          '#type' => 'checkbox',      '#type' => 'checkbox',
134          '#title' => t('Show titles of inaccessible content'),      '#title' => t('Show titles of inaccessible content'),
135          '#return_value' => 1,      '#return_value' => 1,
136          '#default_value' => variable_get('recent_changes_show_access_denied_titles', TRUE),      '#default_value' => variable_get('recent_changes_show_access_denied_titles', TRUE),
137          '#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.'),      '#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.'),
138        );    );
   
139    $form['feed_settings']['recent_changes_show_diff']= array(    $form['feed_settings']['recent_changes_show_diff']= array(
140          '#type' => 'checkbox',      '#type' => 'checkbox',
141          '#title' => t('Show diffs in feeds'),      '#title' => t('Show diffs in feeds'),
142          '#return_value' => 1,      '#return_value' => 1,
143          '#default_value' => variable_get('recent_changes_show_diffs', TRUE),      '#default_value' => variable_get('recent_changes_show_diff', TRUE),
144          '#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.'),      '#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.'),
145        );    );
   
146    $form['feed_settings']['recent_changes_feed_default_items'] = array(    $form['feed_settings']['recent_changes_feed_default_items'] = array(
147          '#type' => 'select',      '#type' => 'select',
148          '#title' => t('Number of items per feed'),      '#title' => t('Number of items per feed'),
149          '#default_value' => variable_get('recent_changes_feed_default_items', 10),      '#default_value' => variable_get('recent_changes_feed_default_items', 10),
150          '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),      '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
151          '#description' => t('The default number of items to include in the recent changes feed.'),      '#description' => t('The default number of items to include in the recent changes feed.'),
152        );    );
   
153    $form['feed_settings']['recent_changes_feed_item_type']= array(    $form['feed_settings']['recent_changes_feed_item_type']= array(
154          '#type' => 'select',      '#type' => 'select',
155          '#title' => t('Display of XML feed items'),      '#title' => t('Display of XML feed items'),
156          '#default_value' => variable_get('recent_changes_feed_item_type', 'teaser'),      '#default_value' => variable_get('recent_changes_feed_item_type', 'teaser'),
157          '#options' => array('title' => 'Titles only', 'teaser' => 'Titles plus teaser', 'fulltext' => 'Full text'),      '#options' => array('title' => 'Titles only', 'teaser' => 'Titles plus teaser', 'fulltext' => 'Full text'),
158          '#multiple' => FALSE,      '#multiple' => FALSE,
159          '#description' => t('The length of XML items in the recent changes feed.'),      '#description' => t('The length of XML items in the recent changes feed.'),
160        );    );
161    
162    return system_settings_form($form);    return system_settings_form($form);
163  }  }
164    
   
165  /**  /**
166   * Menu callback.   * Menu callback.
167   */   */
# Line 191  function recent_changes_view() { Line 175  function recent_changes_view() {
175    }    }
176  }  }
177    
   
178  /**  /**
179   * Page display of recent changes.   * Page display of recent changes.
180   */   */
# Line 202  function recent_changes_page() { Line 185  function recent_changes_page() {
185    if ($_POST['op'] === t('Filter')) {    if ($_POST['op'] === t('Filter')) {
186      unset($_GET['page']);      unset($_GET['page']);
187    }    }
188    
189    // Initialize    // Initialize
190    $output = '';    $output = '';
191    $day = -1;    $day = -1;
# Line 219  function recent_changes_page() { Line 202  function recent_changes_page() {
202    else {    else {
203      drupal_add_feed(url('recent_changes/feed', NULL, NULL, TRUE), t('Recent changes of !site', array('!site' => variable_get('site_name', 'drupal'))));      drupal_add_feed(url('recent_changes/feed', NULL, NULL, TRUE), t('Recent changes of !site', array('!site' => variable_get('site_name', 'drupal'))));
204    }    }
205    
206    // Show filter if enabled    // Show filter if enabled
207    $output .= (variable_get('recent_changes_show_filter', TRUE)) ? drupal_get_form('recent_changes_filter_form') : '';    $output .= (variable_get('recent_changes_show_filter', TRUE)) ? drupal_get_form('recent_changes_filter_form') : '';
208    
# Line 229  function recent_changes_page() { Line 212  function recent_changes_page() {
212    // SQL results provided by pager implementation    // SQL results provided by pager implementation
213    list($sql, $count_sql) = _recent_changes_query($node_types, user_access('view revisions'));    list($sql, $count_sql) = _recent_changes_query($node_types, user_access('view revisions'));
214    $sql_results = pager_query($sql, variable_get('recent_changes_entries_per_page', 50), 0, $count_sql);    $sql_results = pager_query($sql, variable_get('recent_changes_entries_per_page', 50), 0, $count_sql);
215    
216    // put database results in $results    // put database results in $results
217    $results = array();    $results = array();
218    while ($db_item = db_fetch_object($sql_results)) {    while ($db_item = db_fetch_object($sql_results)) {
219      $results[] = $db_item;      $results[] = $db_item;
220    }    }
221    
222    // parse results into items    // parse results into items
223    $items = _recent_changes_parse_results($results);    $items = _recent_changes_parse_results($results);
224    
225    foreach ($items as $item) {    foreach ($items as $item) {
226      // Check if day of week changed and if yes output the new day.      // Check if day of week changed and if yes output the new day.
227      $current_day = format_date($item->timestamp, 'custom', 'z');      $current_day = format_date($item->timestamp, 'custom', 'z');
# Line 256  function recent_changes_page() { Line 239  function recent_changes_page() {
239      // Add the items      // Add the items
240      $rows[] = array(      $rows[] = array(
241        $item->op_link,        $item->op_link,
242        format_date($item->timestamp, 'custom', 'H:i'),        format_date($item->timestamp, 'custom', 'H:i'),
243        $item->node_type_name,        $item->node_type_name,
244        '<span class="change-flag">' . $item->flag . '</span> ' . call_user_func_array('l', array_merge(array($item->item_title), $item->link_array)) . (($item->item_title_add) ? '<br>'. $item->item_title_add : ''),        '<span class="change-flag">' . $item->flag . '</span> ' . call_user_func_array('l', array_merge(array($item->item_title), $item->link_array)) . (($item->item_title_add) ? '<br>'. $item->item_title_add : ''),
245        $item->user_link,        $item->user_link,
# Line 265  function recent_changes_page() { Line 248  function recent_changes_page() {
248    }    }
249    
250    // Print table and pager    // Print table and pager
251    $output .= theme('table', $header, $rows, array('class' => 'recent-changes'));    $output .= theme('table', $header, $rows, array('class' => 'recent-changes'));
252    $output .= theme('pager', NULL, variable_get('recent_changes_entries_per_page', 50), 0);    $output .= theme('pager', NULL, variable_get('recent_changes_entries_per_page', 50), 0);
253    return($output);    return($output);
254  }  }
255    
   
256  /**  /**
257   * RSS feed of recent changes.   * RSS feed of recent changes.
258   */   */
# Line 371  function recent_changes_feed($node_types Line 353  function recent_changes_feed($node_types
353      // put in normal extra information      // put in normal extra information
354      $extra = array_merge($extra,      $extra = array_merge($extra,
355        array(        array(
356          array('key' => 'pubDate', 'value' =>  date('r', $item->timestamp)),          array('key' => 'pubDate', 'value' =>  date('r', $item->timestamp)),
357          array('key' => 'dc:creator', 'value' => $item->user_name),          array('key' => 'dc:creator', 'value' => $item->user_name),
358          array('key' => 'guid', 'value' => $item->nid .' at '. $base_url . (($is_comment) ? ' comment '.$item->cid : ' revision '.$item->vid), 'attributes' => array('isPermaLink' => 'false')),          array('key' => 'guid', 'value' => $item->nid .' at '. $base_url . (($is_comment) ? ' comment '.$item->cid : ' revision '.$item->vid), 'attributes' => array('isPermaLink' => 'false')),
359        )        )
360      );      );
# Line 386  function recent_changes_feed($node_types Line 368  function recent_changes_feed($node_types
368        }        }
369      }      }
370    }    }
371    
372    // RSS channel information    // RSS channel information
373    $single_node_type = count($node_types) == 1;    $single_node_type = count($node_types) == 1;
374    $filter_text = ($single_node_type) ? ' filtered by '. _recent_changes_node_type_name($node_types[0]) : '';    $filter_text = ($single_node_type) ? ' filtered by '. _recent_changes_node_type_name($node_types[0]) : '';
# Line 405  function recent_changes_feed($node_types Line 387  function recent_changes_feed($node_types
387    $output .= "</rss>\n";    $output .= "</rss>\n";
388    
389    // Set MIME type in HTML header    // Set MIME type in HTML header
390    drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');    drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
391    
392    // Print feed text    // Print feed text
393    print $output;    print $output;
394  }  }
395    
   
396  /**  /**
397   * Parsing of recent changes results   * Parsing of recent changes results
398   */   */
# Line 430  function _recent_changes_parse_results($ Line 411  function _recent_changes_parse_results($
411    
412    // get previous revisions    // get previous revisions
413    $all_node_nid = implode(", ", array_keys($nids, TRUE));    $all_node_nid = implode(", ", array_keys($nids, TRUE));
414    $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";
415    $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");    $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");
416    
417    while ($revision = db_fetch_object($revisions_result)) {    while ($revision = db_fetch_object($revisions_result)) {
418      $curr_vid = $revision->curr_vid;      $curr_vid = $revision->curr_vid;
419      if(is_null($revision->vid)) {      if(is_null($revision->vid)) {
# Line 441  function _recent_changes_parse_results($ Line 422  function _recent_changes_parse_results($
422      $has_revisions[$revision->nid] = TRUE;      $has_revisions[$revision->nid] = TRUE;
423      $prev_revisions[$curr_vid] = (!isset($prev_revisions[$curr_vid])) ? $revision : $prev_revisions[$curr_vid];      $prev_revisions[$curr_vid] = (!isset($prev_revisions[$curr_vid])) ? $revision : $prev_revisions[$curr_vid];
424    }    }
425    
426    // parse results    // parse results
427    foreach ($results as $result) {    foreach ($results as $result) {
428      $is_comment = ($result->cid != 0);      $is_comment = ($result->cid != 0);
# Line 450  function _recent_changes_parse_results($ Line 431  function _recent_changes_parse_results($
431      // the owner is the user specified in the {node} table (also called "author" in drupal terminology)      // the owner is the user specified in the {node} table (also called "author" in drupal terminology)
432      $owner_user->uid = $result->uid;      $owner_user->uid = $result->uid;
433      $owner_user->name = $result->name;      $owner_user->name = $result->name;
434    
435      // the active user is the user that performed the update, or posted the revision or comment      // the active user is the user that performed the update, or posted the revision or comment
436      $active_user->uid = $result->auid;      $active_user->uid = $result->auid;
437      $active_user->name = $result->aname;      $active_user->name = $result->aname;
438    
439      $is_current_revision = $result->vid == $result->cvid;      $is_current_revision = $result->vid == $result->cvid;
440      $show_revisions = $access_revisions && $has_revisions[$result->nid];      $show_revisions = $access_revisions && $has_revisions[$result->nid];
441      $show_diff_link = $prev_revision->vid && $exists_diff && $access_revisions;      $show_diff_link = $prev_revision->vid && $exists_diff && $access_revisions;
442      $moved = !$is_comment && $prev_revision->vid && ($prev_revision->title !== $result->title);      $moved = !$is_comment && $prev_revision->vid && ($prev_revision->title !== $result->title);
443    
444      $flags = array(      $flags = array(
445        'comment' => $is_comment,        'comment' => $is_comment,
# Line 475  function _recent_changes_parse_results($ Line 456  function _recent_changes_parse_results($
456      $result_title = ($is_comment) ? $result->subject : $result->title;      $result_title = ($is_comment) ? $result->subject : $result->title;
457      $result_link = array("node/$result->nid" . (($is_comment || $is_current_revision) ? '' : "/revisions/$result->vid/view"), NULL, NULL, ($is_comment) ? "comment-$result->cid" : NULL);      $result_link = array("node/$result->nid" . (($is_comment || $is_current_revision) ? '' : "/revisions/$result->vid/view"), NULL, NULL, ($is_comment) ? "comment-$result->cid" : NULL);
458      $result_url =  array("node/$result->nid" . (($is_comment || $is_current_revision) ? '' : "/revisions/$result->vid/view"), 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);
459    
460      $owner_intro_text = ($moved && $access_revisions) ? ', ' . t('from') . ' ' : t('author') . ': ';      $owner_intro_text = ($moved && $access_revisions) ? ', ' . t('from') . ' ' : t('author') . ': ';
461      $result_title_add = ($moved && $access_revisions) ? t('source: ') . l($prev_revision->title, "node/$result->nid/revisions/$prev_revision->vid/view") : '';      $result_title_add = ($moved && $access_revisions) ? t('source: ') . l($prev_revision->title, "node/$result->nid/revisions/$prev_revision->vid/view") : '';
462      $result_title_add .= (!$is_comment && ($result->uid != $result->auid)) ? $owner_intro_text . theme('username', $owner_user) : '';      $result_title_add .= (!$is_comment && ($result->uid != $result->auid)) ? $owner_intro_text . theme('username', $owner_user) : '';
# Line 505  function _recent_changes_parse_results($ Line 486  function _recent_changes_parse_results($
486    return($items);    return($items);
487  }  }
488    
   
489  /**  /**
490   * Build SQL query depending on node type filter and comments filter.   * Build SQL query depending on node type filter and comments filter.
491   * Inaccessible node types should already have been filtered out by this stage.   * Inaccessible node types should already have been filtered out by this stage.
492   * 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.   * 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.
493  */  */
494  function _recent_changes_query($node_types, $load_revisions) {  function _recent_changes_query($node_types, $load_revisions) {
495    // show comments    // show comments
496    $comment_index = array_search('comment', $node_types);    $comment_index = array_search('comment', $node_types);
497    $show_comments = (!is_bool($comment_index) && !is_null($comment_index));    $show_comments = (!is_bool($comment_index) && !is_null($comment_index));
498    
499    // if only comments is selected, show comments for all allowed node types    // if only comments is selected, show comments for all allowed node types
500    $comments_only = (count($node_types) == 1 && $node_types[0] === 'comment');    $comments_only = (count($node_types) == 1 && $node_types[0] === 'comment');
501    $node_types = $comments_only ? _recent_changes_parse_node_types() : $node_types;    $node_types = $comments_only ? _recent_changes_parse_node_types() : $node_types;
502    
503    // construct node type query (note that leading and trailing single quotes (') need to be added later)    // construct node type query (note that leading and trailing single quotes (') need to be added later)
504    $where_type = implode("', '", $node_types);    $where_type = implode("', '", $node_types);
505    
# Line 527  function _recent_changes_query($node_typ Line 507  function _recent_changes_query($node_typ
507    $node_where = ($where_type && !$comments_only && !$load_revisions) ? "WHERE n.type IN ('$where_type')" : "WHERE FALSE";    $node_where = ($where_type && !$comments_only && !$load_revisions) ? "WHERE n.type IN ('$where_type')" : "WHERE FALSE";
508    $revision_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";
509    $comment_where = ($where_type && $show_comments) ? "WHERE n.type IN ('$where_type')" : "WHERE FALSE";    $comment_where = ($where_type && $show_comments) ? "WHERE n.type IN ('$where_type')" : "WHERE FALSE";
510    
511    // queries to get the selected nodes, comments and revisions for the selected node types    // queries to get the selected nodes, comments and revisions for the selected node types
512    $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";    $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";
513    $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";    $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";
# Line 537  function _recent_changes_query($node_typ Line 517  function _recent_changes_query($node_typ
517    $node_count = "SELECT COUNT(*) FROM {node} n $node_where AND n.status >= 1";    $node_count = "SELECT COUNT(*) FROM {node} n $node_where AND n.status >= 1";
518    $revision_count = "SELECT COUNT(*) FROM {node_revisions} r JOIN {node} n ON r.nid = n.nid $revision_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";
519    $comment_count = "SELECT COUNT(*) FROM {comments} c LEFT JOIN {node} n ON c.nid = n.nid $comment_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";
520    
521    // unify queries    // unify queries
522    $sql = "($nodes_query) UNION ALL ($revisions_query) UNION ALL ($comments_query) ORDER BY timestamp DESC";    $sql = "($nodes_query) UNION ALL ($revisions_query) UNION ALL ($comments_query) ORDER BY timestamp DESC";
523    $sql_count = "SELECT ($node_count) + ($revision_count) + ($comment_count)";    $sql_count = "SELECT ($node_count) + ($revision_count) + ($comment_count)";
524    
525    return(array($sql, $sql_count));    return(array($sql, $sql_count));
526  }  }
527    
   
528  /**  /**
529   * Form for input filter.   * Form for input filter.
530   */   */
# Line 559  function recent_changes_filter_form() { Line 538  function recent_changes_filter_form() {
538    foreach ($node_types AS $type) {    foreach ($node_types AS $type) {
539      $node_names[$type] = _recent_changes_node_type_name($type);      $node_names[$type] = _recent_changes_node_type_name($type);
540    }    }
541    
542    // content types have no weights, so we can safely sort them here    // content types have no weights, so we can safely sort them here
543    asort($node_names);    asort($node_names);
544    
545    // add "All content types" if only single selection is allowed    // add "All content types" if only single selection is allowed
546    $node_names = ($allow_multiple) ? $node_names : array_merge(array(FALSE => t('All content types')), $node_names);    $node_names = ($allow_multiple) ? $node_names : array_merge(array(FALSE => t('All content types')), $node_names);
547    
548    $form = array();    $form = array();
549    $form['#attributes'] = array('class' => 'inline');    $form['#attributes'] = array('class' => 'inline');
550    
551    $form['recent_changes_filter_node_types'] = array(    $form['recent_changes_filter_node_types'] = array(
552      '#type' => 'select',      '#type' => 'select',
553      '#title' => t('Filter content type'),      '#title' => t('Filter content type'),
# Line 582  function recent_changes_filter_form() { Line 561  function recent_changes_filter_form() {
561      '#type' => 'button',      '#type' => 'button',
562      '#value' => t('Filter')      '#value' => t('Filter')
563    );    );
564    
565    return $form;    return $form;
566  }  }
567    
568    /**
569  /*   * Interface with the diff module. Returns a table with the differences between $node and $prev_revision
570  * Interface with the diff module. Returns a table with the differences between $node and $prev_revision   */
 */  
571  function _recent_changes_get_diff($node, $prev_revision) {  function _recent_changes_get_diff($node, $prev_revision) {
572    $item_text  = '<table style="width:100%">';    // Check for diff module
573    $item_text .= '<thead><tr><th></th><th>Revision of '. format_date($prev_revision->revision_timestamp) .'</th><th></th><th>Revision of '. format_date($node->revision_timestamp) .'</th></tr></thead>';    if (!module_exists('diff')) {
574    $item_text .= _diff_table_body($prev_revision, $node);      return '';
575    $item_text .= '</table>';    }
576    
577      // Crete diff
578      $rows = _diff_body_rows($prev_revision, $node);
579      $cols = _diff_default_cols();
580      $header = _diff_default_headers();
581      $item_text = theme('diff_table', $header, $rows, array('class' => 'diff'), NULL, $cols);
582    
583    // Replace css classes from diff with actual style elements since we cannot reference a css file from the rss feed.    // Replace css classes from diff with actual style elements since we cannot reference a css file from the rss feed.
584    $patterns = array(    $patterns = array(
585        '/class=["\']diff-marker["\']/',
586        '/class=["\']diff-content["\']/',
587      '/class=["\']diff-section-title["\']/',      '/class=["\']diff-section-title["\']/',
588      '/class=["\']diff-deletedline["\']/',      '/class=["\']diff-deletedline["\']/',
589      '/class=["\']diff-addedline["\']/',      '/class=["\']diff-addedline["\']/',
# Line 606  function _recent_changes_get_diff($node, Line 592  function _recent_changes_get_diff($node,
592    );    );
593    
594    $replacements = array(    $replacements = array(
595        'style="width:1.4em;"',
596        'style="width:50%;"',
597      'style="background-color: #f0f0ff;"',      'style="background-color: #f0f0ff;"',
598      'style="background-color: #ffa;width: 50%"',      'style="background-color: #ffa;width: 50%"',
599      'style="background-color: #afa;width: 50%"',      'style="background-color: #afa;width: 50%"',
# Line 616  function _recent_changes_get_diff($node, Line 604  function _recent_changes_get_diff($node,
604    $item_text = preg_replace($patterns, $replacements, $item_text);    $item_text = preg_replace($patterns, $replacements, $item_text);
605    $item_text .= "<hr/>\n";    $item_text .= "<hr/>\n";
606    
607    return($item_text);    return $item_text;
608  }  }
609    
610    /**
611  /*   * Removes the node types to which the user has no access
612  * Removes the node types to which the user has no access   */
 */  
613  function _recent_changes_access_check($node_types) {  function _recent_changes_access_check($node_types) {
614    
615    // Check for each node type (and comments) whether current user has 'view' access to it    // Check for each node type (and comments) whether current user has 'view' access to it
616    foreach ($node_types as $key=>$type) {    foreach ($node_types as $key=>$type) {
617      $access = FALSE;      $access = FALSE;
618      if ($type == 'comment') {      if ($type == 'comment') {
# Line 641  function _recent_changes_access_check($n Line 628  function _recent_changes_access_check($n
628          $access = module_invoke($module, 'access', 'view', NULL);          $access = module_invoke($module, 'access', 'view', NULL);
629    
630          // If $access is empty, we try it another way:          // If $access is empty, we try it another way:
631          // 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
632            // the user_access command. If there is no permission with the word access in it, user_access('access content')
633            // is used. This works most of the time.
634          if (is_null($access)) {          if (is_null($access)) {
635            $perms = module_invoke($module, 'perm');            $perms = module_invoke($module, 'perm');
636            $pattern = "/(?m)^access.*$/";            $pattern = "/(?m)^access.*$/";
# Line 657  function _recent_changes_access_check($n Line 646  function _recent_changes_access_check($n
646        unset($node_types[$key]);        unset($node_types[$key]);
647      }      }
648    }    }
649    
650    return($node_types);    return($node_types);
651  }  }
652    
   
653  /**  /**
654   * Return allowed node types, including a 'comments' option   * Return allowed node types, including a 'comments' option
655   */   */
656  function _recent_changes_get_allowed_node_types() {  function _recent_changes_get_allowed_node_types() {
657    $allowed_node_types = variable_get('recent_changes_allowed_node_types', array());    $allowed_node_types = variable_get('recent_changes_allowed_node_types', array());
658    $allowed_node_types = ($allowed_node_types) ? $allowed_node_types : array_keys(node_get_types('names'));    $allowed_node_types = ($allowed_node_types) ? $allowed_node_types : array_keys(node_get_types('names'));
659    
660    // add comments option    // add comments option
661    $allowed_node_types = (variable_get('recent_changes_show_comments', TRUE)) ? array_merge(array('comment'), $allowed_node_types) : $allowed_node_types;    $allowed_node_types = (variable_get('recent_changes_show_comments', TRUE)) ? array_merge(array('comment'), $allowed_node_types) : $allowed_node_types;
662    
663    return $allowed_node_types;    return $allowed_node_types;
664  }  }
665    
   
666  /**  /**
667   * Parse (and cache) node types, and perform access check   * Parse (and cache) node types, and perform access check
668   */   */
669  function _recent_changes_parse_node_types($node_types = NULL) {  function _recent_changes_parse_node_types($node_types = NULL) {
670    // do some caching in case node_types is NULL    // do some caching in case node_types is NULL
671    static $all_parsed_node_types;    static $all_parsed_node_types;
672    
673    $parse_all_node_types = is_null($node_types);    $parse_all_node_types = is_null($node_types);
674    
675    // return cached version if available    // return cached version if available
676    if ($parse_all_node_types && isset($all_parsed_node_types)) {    if ($parse_all_node_types && isset($all_parsed_node_types)) {
677      return $all_parsed_node_types;      return $all_parsed_node_types;
678    }    }
679    
680    // put content types in an array, and use allowed_content_types if node_types was empty    // put content types in an array, and use allowed_content_types if node_types was empty
681    $node_types = _recent_changes_array_node_types($node_types);    $node_types = _recent_changes_array_node_types($node_types);
682    
683    // perform access check    // perform access check
684    $node_types = _recent_changes_access_check($node_types);    $node_types = _recent_changes_access_check($node_types);
685    
686    // cache all parsed node types if all node types were requested    // cache all parsed node types if all node types were requested
687    if ($parse_all_node_types) {    if ($parse_all_node_types) {
688      $all_parsed_node_types = $node_types;      $all_parsed_node_types = $node_types;
# Line 704  function _recent_changes_parse_node_type Line 691  function _recent_changes_parse_node_type
691    return($node_types);    return($node_types);
692  }  }
693    
   
694  /**  /**
695   * 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   * 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
696   * If the input argument $node_types is NULL, all allowed node types are returned   * If the input argument $node_types is NULL, all allowed node types are returned
697   * Note that no access checking is performed here!   * Note that no access checking is performed here!
698   */   */
699  function _recent_changes_array_node_types($node_types = NULL) {  function _recent_changes_array_node_types($node_types = NULL) {
700    $allowed_node_types = _recent_changes_get_allowed_node_types();    $allowed_node_types = _recent_changes_get_allowed_node_types();
# Line 738  function _recent_changes_node_type_name( Line 724  function _recent_changes_node_type_name(
724  //while ($has_revision_nid = db_fetch_object($revisions_result)) {  //while ($has_revision_nid = db_fetch_object($revisions_result)) {
725  //  $has_revisions[$has_revision_nid->nid] = TRUE;  //  $has_revisions[$has_revision_nid->nid] = TRUE;
726  //}  //}
   
 ?>  

Legend:
Removed from v.1.1.2.5  
changed lines
  Added in v.1.1.2.6

  ViewVC Help
Powered by ViewVC 1.1.2