diff -urp search_restrict/search_restrict.info search_restrict_6/search_restrict.info --- search_restrict/search_restrict.info 2008-09-26 03:10:18.000000000 +0200 +++ search_restrict_6/search_restrict.info 2008-10-02 17:53:24.000000000 +0200 @@ -1,7 +1,7 @@ ; $Id: search_restrict.info,v 1.1.2.1 2008/08/21 09:08:29 MegaGrunt Exp $ name = Search Restrict description = "Exclude specific content from search results if user doesn't have privileges." - +core = 6.x diff -urp search_restrict/search_restrict.install search_restrict_6/search_restrict.install --- search_restrict/search_restrict.install 2008-08-21 11:08:29.000000000 +0200 +++ search_restrict_6/search_restrict.install 2008-10-03 11:16:27.000000000 +0200 @@ -7,4 +7,28 @@ function search_restrict_install() { // Set a low weight so the module is called before node module. db_query("UPDATE {system} SET weight = -10 WHERE name = 'search_restrict'"); + + $types = node_get_types('names', NULL, FALSE); + + $var_types = array(); + foreach ($types as $key => $type) { + $var_types[$key] = array(); + } + + variable_set('search_restrict_content_type', $var_types); + foreach ($types as $key => $type) { + variable_set('search_restrict_roles_'.$key, array()); + } +} + +/** + * Implementation of hook_uninstall(). + */ +function search_restrict_uninstall() { + variable_del('search_restrict_content_type'); + + $types = node_get_types('names', NULL, FALSE); + foreach ($types as $key => $type) { + variable_del('search_restrict_roles_'.$key); + } } \ No newline at end of file diff -urp search_restrict/search_restrict.module search_restrict_6/search_restrict.module --- search_restrict/search_restrict.module 2008-09-26 02:50:29.000000000 +0200 +++ search_restrict_6/search_restrict.module 2008-10-03 10:02:18.000000000 +0200 @@ -5,13 +5,13 @@ * Implementation of hook_perm(). */ function search_restrict_perm() { - return array('administer search_restrict'); + return array('administer search_restrict'); } - + /** * Implementation of hook_form_alter(). */ -function search_restrict_form_alter($form_id, &$form) { +function search_restrict_form_alter(&$form, &$form_state, $form_id) { switch ($form_id) { case 'node_type_form': search_restrict_content_type_form($form); @@ -44,19 +44,21 @@ function search_restrict_content_type_fo '#default_value' => $content_type_restrictions[$form['#node_type']->type], ); // use custom submit function to avoid a query at time of search to get the list of content types - $form['#submit']['search_restrict_content_type_form_submit'] = array(); + $form['#submit'][] = 'search_restrict_content_type_form_submit'; } /** * use custom submit function to avoid a query at time of search to get the list of content types */ -function search_restrict_content_type_form_submit($form_id, $form_values) { +function search_restrict_content_type_form_submit($form, &$form_state) { $content_type_restrictions = variable_get('search_restrict_content_type', array()); - $content_type_restrictions[$form_values['type']] = $form_values['search_restrict_roles']; + $content_type_restrictions[$form_state['values']['type']] = $form_state['values']['search_restrict_roles']; variable_set('search_restrict_content_type', $content_type_restrictions); } - +/** + * Implementation of hook_db_rewrite_sql(). + */ function search_restrict_db_rewrite_sql($query, $primary_table, $primary_field, $args) { global $user; if ($user->uid == 1) return; @@ -67,21 +69,21 @@ function search_restrict_db_rewrite_sql( if ($query == '' && $primary_table == 'n' && $primary_field = 'nid' && empty($args)) { $content_type_restrictions = variable_get('search_restrict_content_type', array()); - + foreach ($content_type_restrictions as $type => $roles) { - + $access = FALSE; $access_false = array(); $access_true = array(); - + // list included and excluded roles foreach ($roles as $role_id => $selected) { - if (empty($selected)) { + if (empty($selected)) { $access_false[] = $role_id; } else { - $access_true[] = $role_id; - } + $access_true[] = $role_id; + } } // if no roles or all roles have been selected then everyone has access skip this content type @@ -89,10 +91,10 @@ function search_restrict_db_rewrite_sql( // if user has role in include list skip this content type foreach ($access_true as $role_selected) { if (!empty($user_roles[$role_selected])) $access = TRUE; - } - + } + // user doesn't have any roles that are allowed to search this content type - if (empty($access)) $excluded_types[] = $type; + if (empty($access)) $excluded_types[] = $type; } }