/[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.5.2.1, Thu Feb 21 00:27:54 2008 UTC revision 1.5.2.2, Fri Feb 22 15:11:05 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: recent_changes.module,v 1.1.2.5 2008/02/20 23:45:22 roetzi Exp $  // $Id: recent_changes.module,v 1.5.2.1 2008/02/21 00:27:54 roetzi Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 41  function recent_changes_menu() { Line 41  function recent_changes_menu() {
41    return $items;    return $items;
42  }  }
43    
   
44  /**  /**
45   * Settings form   * Settings form
46   */   */
# Line 139  function recent_changes_admin_settings() Line 138  function recent_changes_admin_settings()
138      '#type' => 'checkbox',      '#type' => 'checkbox',
139      '#title' => t('Show diffs in feeds'),      '#title' => t('Show diffs in feeds'),
140      '#return_value' => 1,      '#return_value' => 1,
141      '#default_value' => variable_get('recent_changes_show_diffs', TRUE),      '#default_value' => variable_get('recent_changes_show_diff', TRUE),
142      '#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.'),
143    );    );
144    $form['feed_settings']['recent_changes_feed_default_items'] = array(    $form['feed_settings']['recent_changes_feed_default_items'] = array(
# Line 161  function recent_changes_admin_settings() Line 160  function recent_changes_admin_settings()
160    return system_settings_form($form);    return system_settings_form($form);
161  }  }
162    
   
163  /**  /**
164   * Menu callback.   * Menu callback.
165   */   */
# Line 175  function recent_changes_view() { Line 173  function recent_changes_view() {
173    }    }
174  }  }
175    
   
176  /**  /**
177   * Page display of recent changes.   * Page display of recent changes.
178   */   */
# Line 186  function recent_changes_page() { Line 183  function recent_changes_page() {
183    if ($_POST['op'] === t('Filter')) {    if ($_POST['op'] === t('Filter')) {
184      unset($_GET['page']);      unset($_GET['page']);
185    }    }
186    
187    // Initialize    // Initialize
188    $output = '';    $output = '';
189    $day = -1;    $day = -1;
# Line 203  function recent_changes_page() { Line 200  function recent_changes_page() {
200    else {    else {
201      drupal_add_feed(url('recent_changes/feed', array('absolute' => TRUE)), t('Recent changes of !site', array('!site' => variable_get('site_name', 'drupal'))));      drupal_add_feed(url('recent_changes/feed', array('absolute' => TRUE)), t('Recent changes of !site', array('!site' => variable_get('site_name', 'drupal'))));
202    }    }
203    
204    // Show filter if enabled    // Show filter if enabled
205    $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') : '';
206    
# Line 213  function recent_changes_page() { Line 210  function recent_changes_page() {
210    // SQL results provided by pager implementation    // SQL results provided by pager implementation
211    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'));
212    $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);
213    
214    // put database results in $results    // put database results in $results
215    $results = array();    $results = array();
216    while ($db_item = db_fetch_object($sql_results)) {    while ($db_item = db_fetch_object($sql_results)) {
217      $results[] = $db_item;      $results[] = $db_item;
218    }    }
219    
220    // parse results into items    // parse results into items
221    $items = _recent_changes_parse_results($results);    $items = _recent_changes_parse_results($results);
222    
223    foreach ($items as $item) {    foreach ($items as $item) {
224      // 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.
225      $current_day = format_date($item->timestamp, 'custom', 'z');      $current_day = format_date($item->timestamp, 'custom', 'z');
# Line 240  function recent_changes_page() { Line 237  function recent_changes_page() {
237      // Add the items      // Add the items
238      $rows[] = array(      $rows[] = array(
239        $item->op_link,        $item->op_link,
240        format_date($item->timestamp, 'custom', 'H:i'),        format_date($item->timestamp, 'custom', 'H:i'),
241        $item->node_type_name,        $item->node_type_name,
242        '<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 : ''),
243        $item->user_link,        $item->user_link,
# Line 249  function recent_changes_page() { Line 246  function recent_changes_page() {
246    }    }
247    
248    // Print table and pager    // Print table and pager
249    $output .= theme('table', $header, $rows, array('class' => 'recent-changes'));    $output .= theme('table', $header, $rows, array('class' => 'recent-changes'));
250    $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);
251    return($output);    return($output);
252  }  }
253    
   
254  /**  /**
255   * RSS feed of recent changes.   * RSS feed of recent changes.
256   */   */
# Line 306  function recent_changes_feed($node_types Line 302  function recent_changes_feed($node_types
302      // load node or comment body text      // load node or comment body text
303      if ($load_node_text) {      if ($load_node_text) {
304        if ($is_comment) {        if ($is_comment) {
305          $body_text = $item->comment_text;          $body_text = $item->comment_text;
306          $teaser_text = node_teaser($body_text, $node->format);          $teaser_text = node_teaser($body_text, $node->format);
307          $node->body = check_markup($body_text, $node->format, FALSE);          $node->body = check_markup($body_text, $node->format, FALSE);
308          $node->teaser = check_markup($teaser_text, $node->format, FALSE);          $node->teaser = check_markup($teaser_text, $node->format, FALSE);
309          $node->readmore = ($teaser && (strlen($teaser_text) < strlen($body_text)));          $node->readmore = ($teaser && (strlen($teaser_text) < strlen($body_text)));
# Line 355  function recent_changes_feed($node_types Line 351  function recent_changes_feed($node_types
351      // put in normal extra information      // put in normal extra information
352      $extra = array_merge($extra,      $extra = array_merge($extra,
353        array(        array(
354          array('key' => 'pubDate', 'value' =>  date('r', $item->timestamp)),          array('key' => 'pubDate', 'value' =>  date('r', $item->timestamp)),
355          array('key' => 'dc:creator', 'value' => $item->user_name),          array('key' => 'dc:creator', 'value' => $item->user_name),
356          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')),
357        )        )
358      );      );
# Line 370  function recent_changes_feed($node_types Line 366  function recent_changes_feed($node_types
366        }        }
367      }      }
368    }    }
369    
370    // RSS channel information    // RSS channel information
371    $single_node_type = count($node_types) == 1;    $single_node_type = count($node_types) == 1;
372    $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 389  function recent_changes_feed($node_types Line 385  function recent_changes_feed($node_types
385    $output .= "</rss>\n";    $output .= "</rss>\n";
386    
387    // Set MIME type in HTML header    // Set MIME type in HTML header
388    drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');    drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
389    
390    // Print feed text    // Print feed text
391    print $output;    print $output;
392  }  }
393    
   
394  /**  /**
395   * Parsing of recent changes results   * Parsing of recent changes results
396   */   */
# Line 414  function _recent_changes_parse_results($ Line 409  function _recent_changes_parse_results($
409    
410    // get previous revisions    // get previous revisions
411    $all_node_nid = implode(", ", array_keys($nids, TRUE));    $all_node_nid = implode(", ", array_keys($nids, TRUE));
412    $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";
413    $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");
414    
415    while ($revision = db_fetch_object($revisions_result)) {    while ($revision = db_fetch_object($revisions_result)) {
416      $curr_vid = $revision->curr_vid;      $curr_vid = $revision->curr_vid;
417      if(is_null($revision->vid)) {      if(is_null($revision->vid)) {
# Line 425  function _recent_changes_parse_results($ Line 420  function _recent_changes_parse_results($
420      $has_revisions[$revision->nid] = TRUE;      $has_revisions[$revision->nid] = TRUE;
421      $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];
422    }    }
423    
424    // parse results    // parse results
425    foreach ($results as $result) {    foreach ($results as $result) {
426      $is_comment = ($result->cid != 0);      $is_comment = ($result->cid != 0);
427      $prev_revision = $prev_revisions[$result->vid];      if (isset($prev_revisions[$result->vid])) {
428          $prev_revision = $prev_revisions[$result->vid];
429        }
430        else {
431          $prev_revision = new stdClass();
432          $prev_revision->vid = 0;
433          $prev_revision->title = '';
434        }
435    
436      // 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)
437      $owner_user->uid = $result->uid;      $owner_user->uid = $result->uid;
438      $owner_user->name = $result->name;      $owner_user->name = $result->name;
439    
440      // 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
441      $active_user->uid = $result->auid;      $active_user->uid = $result->auid;
442      $active_user->name = $result->aname;      $active_user->name = $result->aname;
443    
444      $is_current_revision = $result->vid == $result->cvid;      $is_current_revision = $result->vid == $result->cvid;
445      $show_revisions = $access_revisions && $has_revisions[$result->nid];      $show_revisions = $access_revisions && isset($has_revisions[$result->nid]) && $has_revisions[$result->nid];
446      $show_diff_link = $prev_revision->vid && $exists_diff && $access_revisions;      $show_diff_link = $prev_revision->vid && $exists_diff && $access_revisions;
447      $moved = !$is_comment && $prev_revision->vid && ($prev_revision->title !== $result->title);      $moved = !$is_comment && $prev_revision->vid && ($prev_revision->title !== $result->title);
448    
449      $flags = array(      $flags = array(
450        'comment' => $is_comment,        'comment' => $is_comment,
# Line 459  function _recent_changes_parse_results($ Line 461  function _recent_changes_parse_results($
461      $result_title = ($is_comment) ? $result->subject : $result->title;      $result_title = ($is_comment) ? $result->subject : $result->title;
462      $result_link = array("node/$result->nid" . (($is_comment || $is_current_revision) ? '' : "/revisions/$result->vid/view"), array('fragment' => ($is_comment) ? "comment-$result->cid" : NULL));      $result_link = array("node/$result->nid" . (($is_comment || $is_current_revision) ? '' : "/revisions/$result->vid/view"), array('fragment' => ($is_comment) ? "comment-$result->cid" : NULL));
463      $result_url =  array("node/$result->nid" . (($is_comment || $is_current_revision) ? '' : "/revisions/$result->vid/view"), array('fragment' => ($is_comment) ? "comment-$result->cid" : NULL ));      $result_url =  array("node/$result->nid" . (($is_comment || $is_current_revision) ? '' : "/revisions/$result->vid/view"), array('fragment' => ($is_comment) ? "comment-$result->cid" : NULL ));
464    
465      $owner_intro_text = ($moved && $access_revisions) ? ', ' . t('from') . ' ' : t('author') . ': ';      $owner_intro_text = ($moved && $access_revisions) ? ', ' . t('from') . ' ' : t('author') . ': ';
466      $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") : '';
467      $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 489  function _recent_changes_parse_results($ Line 491  function _recent_changes_parse_results($
491    return($items);    return($items);
492  }  }
493    
   
494  /**  /**
495   * Build SQL query depending on node type filter and comments filter.   * Build SQL query depending on node type filter and comments filter.
496   * Inaccessible node types should already have been filtered out by this stage.   * Inaccessible node types should already have been filtered out by this stage.
497   * 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.
498  */  */
499  function _recent_changes_query($node_types, $load_revisions) {  function _recent_changes_query($node_types, $load_revisions) {
500    // show comments    // show comments
501    $comment_index = array_search('comment', $node_types);    $comment_index = array_search('comment', $node_types);
502    $show_comments = (!is_bool($comment_index) && !is_null($comment_index));    $show_comments = (!is_bool($comment_index) && !is_null($comment_index));
503    
504    // if only comments is selected, show comments for all allowed node types    // if only comments is selected, show comments for all allowed node types
505    $comments_only = (count($node_types) == 1 && $node_types[0] === 'comment');    $comments_only = (count($node_types) == 1 && $node_types[0] === 'comment');
506    $node_types = $comments_only ? _recent_changes_parse_node_types() : $node_types;    $node_types = $comments_only ? _recent_changes_parse_node_types() : $node_types;
507    
508    // 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)
509    $where_type = implode("', '", $node_types);    $where_type = implode("', '", $node_types);
510    
# Line 511  function _recent_changes_query($node_typ Line 512  function _recent_changes_query($node_typ
512    $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";
513    $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";
514    $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";
515    
516    // 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
517    $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";
518    $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 521  function _recent_changes_query($node_typ Line 522  function _recent_changes_query($node_typ
522    $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";
523    $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";
524    $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";
525    
526    // unify queries    // unify queries
527    $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";
528    $sql_count = "SELECT ($node_count) + ($revision_count) + ($comment_count)";    $sql_count = "SELECT ($node_count) + ($revision_count) + ($comment_count)";
529    
530    return(array($sql, $sql_count));    return(array($sql, $sql_count));
531  }  }
532    
   
533  /**  /**
534   * Form for input filter.   * Form for input filter.
535   */   */
# Line 543  function recent_changes_filter_form() { Line 543  function recent_changes_filter_form() {
543    foreach ($node_types AS $type) {    foreach ($node_types AS $type) {
544      $node_names[$type] = _recent_changes_node_type_name($type);      $node_names[$type] = _recent_changes_node_type_name($type);
545    }    }
546    
547    // content types have no weights, so we can safely sort them here    // content types have no weights, so we can safely sort them here
548    asort($node_names);    asort($node_names);
549    
550    // add "All content types" if only single selection is allowed    // add "All content types" if only single selection is allowed
551    $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);
552    
553    $form = array();    $form = array();
554    $form['#attributes'] = array('class' => 'inline');    $form['#attributes'] = array('class' => 'inline');
555    
556    $form['recent_changes_filter_node_types'] = array(    $form['recent_changes_filter_node_types'] = array(
557      '#type' => 'select',      '#type' => 'select',
558      '#title' => t('Filter content type'),      '#title' => t('Filter content type'),
# Line 566  function recent_changes_filter_form() { Line 566  function recent_changes_filter_form() {
566      '#type' => 'button',      '#type' => 'button',
567      '#value' => t('Filter')      '#value' => t('Filter')
568    );    );
569    
570    return $form;    return $form;
571  }  }
572    
573    /**
574  /*   * Interface with the diff module. Returns a table with the differences between $node and $prev_revision
575  * Interface with the diff module. Returns a table with the differences between $node and $prev_revision   */
 */  
576  function _recent_changes_get_diff($node, $prev_revision) {  function _recent_changes_get_diff($node, $prev_revision) {
577    $item_text  = '<table style="width:100%">';    // Check for diff module
578    $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')) {
579    $item_text .= _diff_table_body($prev_revision, $node);      return '';
580    $item_text .= '</table>';    }
581    
582      // Crete diff
583      $rows = _diff_body_rows($prev_revision, $node);
584      $cols = _diff_default_cols();
585      $header = array();
586      $item_text = theme('diff_table', $header, $rows, array('class' => 'diff'), NULL, $cols);
587    
588    // 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.
589    $patterns = array(    $patterns = array(
590        '/class=["\']diff-marker["\']/',
591        '/class=["\']diff-content["\']/',
592      '/class=["\']diff-section-title["\']/',      '/class=["\']diff-section-title["\']/',
593      '/class=["\']diff-deletedline["\']/',      '/class=["\']diff-deletedline["\']/',
594      '/class=["\']diff-addedline["\']/',      '/class=["\']diff-addedline["\']/',
# Line 590  function _recent_changes_get_diff($node, Line 597  function _recent_changes_get_diff($node,
597    );    );
598    
599    $replacements = array(    $replacements = array(
600        'style="width:1.4em;"',
601        'style="width:50%;"',
602      'style="background-color: #f0f0ff;"',      'style="background-color: #f0f0ff;"',
603      'style="background-color: #ffa;width: 50%"',      'style="background-color: #ffa;width: 50%"',
604      'style="background-color: #afa;width: 50%"',      'style="background-color: #afa;width: 50%"',
# Line 600  function _recent_changes_get_diff($node, Line 609  function _recent_changes_get_diff($node,
609    $item_text = preg_replace($patterns, $replacements, $item_text);    $item_text = preg_replace($patterns, $replacements, $item_text);
610    $item_text .= "<hr/>\n";    $item_text .= "<hr/>\n";
611    
612    return($item_text);    return $item_text;
613  }  }
614    
615    /**
616  /*   * Removes the node types to which the user has no access
617  * Removes the node types to which the user has no access   */
 */  
618  function _recent_changes_access_check($node_types) {  function _recent_changes_access_check($node_types) {
619    
620    // 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
621    foreach ($node_types as $key=>$type) {    foreach ($node_types as $key=>$type) {
622      $access = FALSE;      $access = FALSE;
623      if ($type == 'comment') {      if ($type == 'comment') {
# Line 622  function _recent_changes_access_check($n Line 630  function _recent_changes_access_check($n
630        }        }
631        else {        else {
632          // 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
633  // This is not correct as the 'view' parameter also needs that a node object is passed.          // This is not correct as the 'view' parameter also needs that a node object is passed.
634  // Only for 'create' parameters it is sufficent to pass a node type          // Only for 'create' parameters it is sufficent to pass a node type
635  //        $access = module_invoke($module, 'access', 'view', NULL);  //        $access = module_invoke($module, 'access', 'view', NULL);
636          $access = NULL;          $access = NULL;
637    
638          // If $access is empty, we try it another way:          // If $access is empty, we try it another way:
639          // 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
640            // the user_access command. If there is no permission with the word access in it, user_access('access content')
641            // is used. This works most of the time.
642          if (is_null($access)) {          if (is_null($access)) {
643            $perms = module_invoke($module, 'perm');            $perms = module_invoke($module, 'perm');
644            $pattern = "/(?m)^access.*$/";            $pattern = "/(?m)^access.*$/";
# Line 644  function _recent_changes_access_check($n Line 654  function _recent_changes_access_check($n
654        unset($node_types[$key]);        unset($node_types[$key]);
655      }      }
656    }    }
657    
658    return($node_types);    return($node_types);
659  }  }
660    
   
661  /**  /**
662   * Return allowed node types, including a 'comments' option   * Return allowed node types, including a 'comments' option
663   */   */
664  function _recent_changes_get_allowed_node_types() {  function _recent_changes_get_allowed_node_types() {
665    $allowed_node_types = variable_get('recent_changes_allowed_node_types', array());    $allowed_node_types = variable_get('recent_changes_allowed_node_types', array());
666    $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'));
667    
668    // add comments option    // add comments option
669    $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;
670    
671    return $allowed_node_types;    return $allowed_node_types;
672  }  }
673    
   
674  /**  /**
675   * Parse (and cache) node types, and perform access check   * Parse (and cache) node types, and perform access check
676   */   */
677  function _recent_changes_parse_node_types($node_types = NULL) {  function _recent_changes_parse_node_types($node_types = NULL) {
678    // do some caching in case node_types is NULL    // do some caching in case node_types is NULL
679    static $all_parsed_node_types;    static $all_parsed_node_types;
680    
681    $parse_all_node_types = is_null($node_types);    $parse_all_node_types = is_null($node_types);
682    
683    // return cached version if available    // return cached version if available
684    if ($parse_all_node_types && isset($all_parsed_node_types)) {    if ($parse_all_node_types && isset($all_parsed_node_types)) {
685      return $all_parsed_node_types;      return $all_parsed_node_types;
686    }    }
687    
688    // 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
689    $node_types = _recent_changes_array_node_types($node_types);    $node_types = _recent_changes_array_node_types($node_types);
690    
691    // perform access check    // perform access check
692    $node_types = _recent_changes_access_check($node_types);    $node_types = _recent_changes_access_check($node_types);
693    
694    // cache all parsed node types if all node types were requested    // cache all parsed node types if all node types were requested
695    if ($parse_all_node_types) {    if ($parse_all_node_types) {
696      $all_parsed_node_types = $node_types;      $all_parsed_node_types = $node_types;
# Line 691  function _recent_changes_parse_node_type Line 699  function _recent_changes_parse_node_type
699    return($node_types);    return($node_types);
700  }  }
701    
   
702  /**  /**
703   * 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
704   * 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
705   * Note that no access checking is performed here!   * Note that no access checking is performed here!
706   */   */
707  function _recent_changes_array_node_types($node_types = NULL) {  function _recent_changes_array_node_types($node_types = NULL) {
708    $allowed_node_types = _recent_changes_get_allowed_node_types();    $allowed_node_types = _recent_changes_get_allowed_node_types();

Legend:
Removed from v.1.5.2.1  
changed lines
  Added in v.1.5.2.2

  ViewVC Help
Powered by ViewVC 1.1.2