? .git ? b ? drushrc.php ? forum_node_access.patch ? logger.patch ? min.patch ? mw.patch ? tmp.patch ? includes/database/log.inc Index: includes/database/query.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/database/query.inc,v retrieving revision 1.5 diff -u -F^f -p -r1.5 query.inc --- includes/database/query.inc 6 Oct 2008 14:39:40 -0000 1.5 +++ includes/database/query.inc 13 Oct 2008 02:29:23 -0000 @@ -1032,7 +1032,7 @@ class DatabaseCondition implements Query if ($condition['field'] instanceof QueryConditionInterface) { // Compile the sub-condition recursively and add it to the list. $condition['field']->compile($connection); - $condition_fragments[] = (string)$condition['field']; + $condition_fragments[] = '('. (string)$condition['field']. ')'; $arguments += $condition['field']->arguments(); } else { Index: modules/forum/forum.module =================================================================== RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v retrieving revision 1.470 diff -u -F^f -p -r1.470 forum.module --- modules/forum/forum.module 13 Oct 2008 00:33:03 -0000 1.470 +++ modules/forum/forum.module 13 Oct 2008 02:29:23 -0000 @@ -486,9 +486,27 @@ function forum_block($op = 'list', $delt switch ($delta) { case 'active': $title = t('Active forum topics'); - $sql = db_rewrite_sql("SELECT n.nid, n.title, l.comment_count, l.last_comment_timestamp FROM {node} n INNER JOIN {term_node} tn ON tn.vid = n.vid INNER JOIN {term_data} td ON td.tid = tn.tid INNER JOIN {node_comment_statistics} l ON n.nid = l.nid WHERE n.status = 1 AND td.vid = %d ORDER BY l.last_comment_timestamp DESC"); - $result = db_query_range($sql, variable_get('forum_nav_vocabulary', ''), 0, variable_get('forum_block_num_active', '5')); - $content = node_title_list($result); + $query = db_select('node', 'n'); + $tn_alias = $query->join('term_node', 'tn', 'tn.vid = n.vid'); + $td_alias = $query->join('term_data', 'td', 'tn.tid = tn.tid'); + $l_alias = $query->join('node_comment_statistics', 'l', 'n.nid = l.nid'); + $nid_field = $query->addField('n', 'nid'); + $title_field = $query->addField('n', 'title'); + $comment_count_field = $query->addField($l_alias, 'comment_count'); + $query->addField($l_alias, 'last_comment_timestamp'); + $query->condition("n.status", 1); + $query->condition("{$td_alias}.vid", variable_get('forum_nav_vocabulary', '')); + $query->orderBy("{$l_alias}.last_comment_timestamp", 'DESC'); + $query->range(0, variable_get('forum_block_num_active', '5')); + $query->addTag('node_access'); + $result = $query->execute(); + foreach ($result as $node) { + $options = isset($node->$comment_count_field) ? array('attributes' => array('title' => format_plural($node->$comment_count_field, '1 comment', '@count comments'))) : array(); + $items[] = l($node->$title_field, 'node/' . $node->$nid_field, $options); + } + if (!empty($items)) { + $content = theme('node_list', $items); + } break; case 'new': Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.988 diff -u -F^f -p -r1.988 node.module --- modules/node/node.module 13 Oct 2008 00:33:03 -0000 1.988 +++ modules/node/node.module 13 Oct 2008 02:29:24 -0000 @@ -2267,35 +2267,34 @@ function node_db_rewrite_sql($query, $pr } } - /** * Implementation of hook_query_alter(). - * @todo This doesn't quite work yet. */ -function DISABLED_node_query_alter(Query $query) { - if ($query->hasTag('node_access')) { - if (! user_access('administer nodes')) { - $query->distinct(); - $access_alias = $query->join('node_access', 'na', 'na.nid = n.nid'); - dsm('hello'); - _node_query_alter_where($query, 'view', $access_alias); +function node_query_alter(QueryAlterableInterface $query) { + if ($query->hasTag('node_access') && !node_access_view_all_nodes()) { + $query->distinct(); + if (!$op = $query->getMetaData('op')) { + $op = 'view'; } - } -} + if (!user_access('bypass node access')) { + $access_alias = $query->join('node_access', 'na', 'na.nid = n.nid'); + $or = db_or(); + foreach (node_access_grants($op, $query->getMetaData('account')) as $realm => $gids) { + foreach ($gids as $gid) { + $or->condition(db_and() + ->condition("{$access_alias}.gid", $gid) + ->condition("{$access_alias}.realm", $realm) + ); + } + } -function _node_query_alter_where($query, $op = 'view', $node_access_alias = 'na', $account = NULL) { - $or = db_or(); - foreach (node_access_grants($op, $account) as $realm => $gids) { - foreach ($gids as $gid) { - $or->condition("{$node_access_alias}.gid = :gid AND {$node_access_alias}.realm = :realm", array(':gid' => $gid, ':realm' => $realm)); - } - } + if (count($or->conditions())) { + $query->condition($or); + } - if (count($or->conditions())) { - $query->condition($or); + $query->condition("{$access_alias}.grant_$op", 1, '>='); + } } - - $query->condition("$node_access_alias.grant_$op", '>=', 1); } /**