diff -up -r term_permissions.info term_permissions.info --- term_permissions.info 2011-12-14 02:51:29.000000000 +0200 +++ term_permissions.info 2012-01-17 21:56:01.278488554 +0200 @@ -5,7 +5,7 @@ dependencies[] = taxonomy ; Information added by drupal.org packaging script on 2011-12-14 version = "6.x-1.x-dev" -core = "6.x" +core = 7.x project = "term_permissions" datestamp = "1323823889" diff -up -r term_permissions.install term_permissions.install --- term_permissions.install 2011-12-13 16:04:58.000000000 +0200 +++ term_permissions.install 2012-01-17 21:56:01.346488552 +0200 @@ -1,12 +1,19 @@ array( - 'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), - 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), + 'tid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'uid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), ), 'primary key' => array( 'tid', @@ -37,8 +52,16 @@ function term_permissions_schema() { $schema['term_permissions_role'] = array( 'fields' => array( - 'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), - 'rid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), + 'tid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'rid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), ), 'primary key' => array( 'tid', @@ -50,8 +73,9 @@ function term_permissions_schema() { } /** - * Implementation of hook_uninstall(). + * Implements hook_uninstall(). */ function term_permissions_uninstall() { - drupal_uninstall_schema('term_permissions'); + // TODO The drupal_(un)install_schema functions are called automatically in D7. + // drupal_uninstall_schema('term_permissions') } diff -up -r term_permissions.module term_permissions.module --- term_permissions.module 2011-12-13 16:04:58.000000000 +0200 +++ term_permissions.module 2012-01-17 21:56:01.782488555 +0200 @@ -6,7 +6,7 @@ */ /** - * Implementation of hook_help(). + * Implements hook_help(). */ function term_permissions_help($path, $arg) { switch ($path) { @@ -18,7 +18,7 @@ function term_permissions_help($path, $a } /** - * Implementation of hook_menu(). + * Implements hook_menu(). */ function term_permissions_menu() { $items = array(); @@ -32,7 +32,7 @@ function term_permissions_menu() { } /** - * Implementation of hook_form_alter() + * Implements hook_form_alter(). * * @param $form * The form to alter. @@ -62,8 +62,11 @@ function term_permissions_form_alter(&$f // Pull in any stored users in the database. $allowed_users = array(); if (!empty($form['tid']['#value'])) { - $result = db_query("SELECT uid FROM {term_permissions_user} WHERE tid = %d", $form['#term']['tid']); - while($uid = db_result($result)) { + $result = db_query("SELECT uid FROM {term_permissions_user} WHERE tid = :tid", array(':tid' => $form['#term']['tid'])); + while ($uid = $result->fetchField()) { + // TODO Convert "user_load" to "user_load_multiple" if "$uid" is other than a uid. + // To return a single user object, wrap "user_load_multiple" with "array_shift" or equivalent. + // Example: array_shift(user_load_multiple(array(), $uid)) $u = user_load($uid); $allowed_users[] = $u->name; } @@ -84,8 +87,8 @@ function term_permissions_form_alter(&$f $allowed_roles = array(); if (!empty($form['tid']['#value'])) { - $result = db_query("SELECT rid FROM {term_permissions_role} WHERE tid = %d", array($form['tid']['#value'])); - while($rid = db_result($result)) { + $result = db_query("SELECT rid FROM {term_permissions_role} WHERE tid = :tid", array(':tid' => array($form['tid']['#value']))); + while ($rid = $result->fetchField()) { $allowed_roles[] = $rid; } } @@ -107,17 +110,17 @@ function term_permissions_form_alter(&$f // This is the node add / edit form. If a different selector is used from // another contributed module, we do nothing so as to not break the form. - if (isset($form['type']) && isset($form['#node']) && isset($form['taxonomy']) && (!variable_get('taxonomy_override_selector', FALSE)) && $form['type']['#value'] .'_node_form' == $form_id) { - foreach($form['taxonomy'] as $vid => $vocabulary) { + if (isset($form['type']) && isset($form['#node']) && isset($form['taxonomy']) && (!variable_get('taxonomy_override_selector', FALSE)) && $form['type']['#value'] . '_node_form' == $form_id) { + foreach ($form['taxonomy'] as $vid => $vocabulary) { if (!is_array($vocabulary) || !isset($vocabulary['#options'])) { continue; } $total_terms = count($vocabulary['#options']); - foreach($vocabulary['#options'] as $terms) { + foreach ($vocabulary['#options'] as $terms) { if (!isset($terms->option)) { continue; } - foreach($terms->option as $tid => $term) { + foreach ($terms->option as $tid => $term) { // Now we have the term ID, check to see if the current user has // access to the term. global $user; @@ -129,8 +132,8 @@ function term_permissions_form_alter(&$f // vocabulary, remove the form item entirely. if ($total_terms <= 0) { if ($vocabulary['#required']) { - drupal_set_message(t("Your account doesn't have permission to use any of the terms in the %vocabulary vocabulary. Your account must be given permission to use at least one term in the %vocabulary vocabulary to be able to add or edit the %content-type content type.", array('%vocabulary' => $vocabulary['#title'], '%content-type' => node_get_types('name', $form['type']['#value']))), 'warning'); - watchdog('term_permissions', '%user was blocked from accessing the %content-type form as they do not have permission to use any terms in the %vocabulary vocabulary.', array('%user' => isset($user->name) ? $user->name : variable_get('anonymous', 'Anonymous'), '%content-type' => node_get_types('name', $form['type']['#value']), '@vocabulary-url' => url('admin/content/taxonomy/' . $vid), '%vocabulary' => $vocabulary['#title']), WATCHDOG_WARNING, l(t('edit vocabulary'), 'admin/content/taxonomy/' . $vid)); + drupal_set_message(t("Your account doesn't have permission to use any of the terms in the %vocabulary vocabulary. Your account must be given permission to use at least one term in the %vocabulary vocabulary to be able to add or edit the %content-type content type.", array('%vocabulary' => $vocabulary['#title'], '%content-type' => node_type_get_name($form['type']['#value']))), 'warning'); + watchdog('term_permissions', '%user was blocked from accessing the %content-type form as they do not have permission to use any terms in the %vocabulary vocabulary.', array('%user' => isset($user->name) ? $user->name : variable_get('anonymous', 'Anonymous'), '%content-type' => node_type_get_name($form['type']['#value']), '@vocabulary-url' => url('admin/structure/taxonomy/' . $vid), '%vocabulary' => $vocabulary['#title']), WATCHDOG_WARNING, l(t('edit vocabulary'), 'admin/structure/taxonomy/' . $vid)); drupal_access_denied(); exit(); } @@ -154,7 +157,7 @@ function term_permissions_validate($form if (!empty($form_state['values']['access']['user'])) { $allowed_users = drupal_explode_tags($form_state['values']['access']['user']); foreach ($allowed_users as $name) { - if (!(user_load(array('name' => $name)))) { + if (!(array_shift(user_load_multiple(array(), array('name' => $name))))) { form_set_error('search_user', t('The user %name does not exist.', array('%user' => $name))); } } @@ -172,20 +175,42 @@ function term_permissions_validate($form */ function term_permissions_submit($form, &$form_state) { // For each user, save the term ID and the user ID. - db_query("DELETE FROM {term_permissions_user} WHERE tid = %d", $form_state['values']['tid']); + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query("DELETE FROM {term_permissions_user} WHERE tid = %d", $form_state['values']['tid']) */ + db_delete('term_permissions_user') + ->condition('tid', $form_state['values']['tid']) + ->execute(); if (!empty($form_state['values']['access']['user'])) { $allowed_users = drupal_explode_tags($form_state['values']['access']['user']); - foreach($allowed_users as $name) { - $u = user_load(array('name' => $name)); - db_query("INSERT INTO {term_permissions_user} (tid, uid) VALUES (%d, %d)", $form_state['values']['tid'], $u->uid); + foreach ($allowed_users as $name) { + $u = array_shift(user_load_multiple(array(), array('name' => $name))); + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query("INSERT INTO {term_permissions_user} (tid, uid) VALUES (%d, %d)", $form_state['values']['tid'], $u->uid) */ + $id = db_insert('term_permissions_user') + ->fields(array( + 'tid' => $form_state['values']['tid'], + 'uid' => $u->uid, + )) + ->execute(); } } // For each role, save the term ID and the role ID. - db_query("DELETE FROM {term_permissions_role} WHERE tid = %d", $form_state['values']['tid']); + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query("DELETE FROM {term_permissions_role} WHERE tid = %d", $form_state['values']['tid']) */ + db_delete('term_permissions_role') + ->condition('tid', $form_state['values']['tid']) + ->execute(); if (!empty($form_state['values']['access']['role'])) { - foreach(array_keys(array_filter($form_state['values']['access']['role'])) as $rid) { - db_query("INSERT INTO {term_permissions_role} (tid, rid) VALUES (%d, %d)", $form_state['values']['tid'], $rid); + foreach (array_keys(array_filter($form_state['values']['access']['role'])) as $rid) { + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query("INSERT INTO {term_permissions_role} (tid, rid) VALUES (%d, %d)", $form_state['values']['tid'], $rid) */ + $id = db_insert('term_permissions_role') + ->fields(array( + 'tid' => $form_state['values']['tid'], + 'rid' => $rid, + )) + ->execute(); } } } @@ -207,12 +232,13 @@ function term_permissions_allowed($tid, return TRUE; } // Are permissions enabled on this term? - if (!(db_result(db_query("SELECT COUNT(1) FROM {term_permissions_user} WHERE tid = %d", $tid)) || db_result(db_query("SELECT COUNT(1) FROM {term_permissions_role} WHERE tid = %d", $tid)))) { + if (!(db_query("SELECT COUNT(1) FROM {term_permissions_user} WHERE tid = :tid", array(':tid' => $tid))->fetchField() || db_query("SELECT COUNT(1) FROM {term_permissions_role} WHERE tid = :tid", array(':tid' => $tid))->fetchField())) { return TRUE; } // Permissions are enabled, check to see if this user or one of their roles // is allowed. - if (db_result(db_query("SELECT uid FROM {term_permissions_user} WHERE tid = %d AND uid = %d", $tid, $user->uid)) || db_result(db_query("SELECT rid FROM {term_permissions_role} WHERE tid = %d AND rid IN (" . implode(', ', array_keys($user->roles)) . ")", $tid))) { + // TODO Please convert this statement to the D7 database API syntax. + if (db_query("SELECT uid FROM {term_permissions_user} WHERE tid = :tid AND uid = :uid", array(':tid' => $tid, ':uid' => $user->uid))->fetchField() || db_query("SELECT rid FROM {term_permissions_role} WHERE tid = %d AND rid IN (" . implode(', ', array_keys($user->roles)) . ")", $tid)->fetchField()) { return TRUE; } return FALSE; @@ -230,9 +256,10 @@ function term_permissions_autocomplete_m $last_string = trim(array_pop($array)); $matches = array(); - $result = db_query_range("SELECT u.name FROM {users} u WHERE LOWER(u.name) LIKE LOWER('%s%%')", $last_string, 0, 10); + // TODO Please convert this statement to the D7 database API syntax. + $result = db_query_range("SELECT u.name FROM {users} u WHERE LOWER(u.name) LIKE LOWER('%s%%')", $last_string); - $prefix = count($array) ? implode(', ', $array) .', ' : ''; + $prefix = count($array) ? implode(', ', $array) . ', ' : ''; while ($user = db_fetch_object($result)) { $matches[$prefix . $user->name] = check_plain($user->name); @@ -240,5 +267,5 @@ function term_permissions_autocomplete_m if (module_exists('devel')) { $GLOBALS['devel_shutdown'] = FALSE; } - exit(drupal_json($matches)); + exit(drupal_json_output($matches)); }