Index: better_formats_settings.admin.inc =================================================================== --- better_formats_settings.admin.inc (revision 1) +++ better_formats_settings.admin.inc (working copy) @@ -11,7 +11,7 @@ * * @see better_formats_menu() */ -function better_formats_settings_admin_form() { +function better_formats_settings_admin_form($form, &$form_state) { $form = array(); $form['display'] = array( Index: tests/better_formats_anonymous_user.test =================================================================== --- tests/better_formats_anonymous_user.test (revision 1) +++ tests/better_formats_anonymous_user.test (working copy) @@ -47,12 +47,12 @@ // Let anon use full html - it's crazy, but it's just simpletest $edit = array(); $edit['roles[1]'] = TRUE; - $this->drupalPost('admin/settings/filters/2', $edit, t('Save configuration')); + $this->drupalPost('admin/config/content/formats/2', $edit, t('Save configuration')); // Set full html as default for anon on comments - again, crazy, but... $edit = array(); $edit['comment-1[format]'] = 2; - $this->drupalPost('admin/settings/filters/defaults', $edit, t('Save defaults')); + $this->drupalPost('admin/config/content/formats/defaults', $edit, t('Save defaults')); $this->setPermission('anonymous user', array('show format selection for comments' => FALSE, 'create page content' => TRUE)); $this->drupalLogout(); @@ -106,7 +106,7 @@ */ function setPermission($role, $permissions) { // Get role id (rid) for specified role. - $rid = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", array('%s' => $role))); + $rid = db_query("SELECT rid FROM {role} WHERE name = :name", array(':name' => array('%s' => $role)))->fetchField(); if ($rid === FALSE) { $this->fail(t(' [permission] Role "' . $role . '" not found.')); } Index: better_formats.module =================================================================== --- better_formats.module (revision 1) +++ better_formats.module (working copy) @@ -10,7 +10,7 @@ */ /** - * Implementation of hook_help(). + * Implements hook_help(). */ function better_formats_help($path, $arg) { switch ($path) { @@ -25,27 +25,48 @@ } /** - * Implementation of hook_perm(). + * Implements hook_permission(). */ -function better_formats_perm() { +function better_formats_permission() { return array( - 'show format selection for nodes', - 'show format selection for comments', - 'show format selection for blocks', - 'show format tips', - 'show more format tips link', - 'collapse format fieldset by default', - 'collapsible format selection', + 'show format selection for nodes' => array( + 'title' => t('show format selection for nodes'), + 'description' => t('TODO Add a description for \'show format selection for nodes\''), + ), + 'show format selection for comments' => array( + 'title' => t('show format selection for comments'), + 'description' => t('TODO Add a description for \'show format selection for comments\''), + ), + 'show format selection for blocks' => array( + 'title' => t('show format selection for blocks'), + 'description' => t('TODO Add a description for \'show format selection for blocks\''), + ), + 'show format tips' => array( + 'title' => t('show format tips'), + 'description' => t('TODO Add a description for \'show format tips\''), + ), + 'show more format tips link' => array( + 'title' => t('show more format tips link'), + 'description' => t('TODO Add a description for \'show more format tips link\''), + ), + 'collapse format fieldset by default' => array( + 'title' => t('collapse format fieldset by default'), + 'description' => t('TODO Add a description for \'collapse format fieldset by default\''), + ), + 'collapsible format selection' => array( + 'title' => t('collapsible format selection'), + 'description' => t('TODO Add a description for \'collapsible format selection\''), + ), ); } /** - * Implementation of hook_menu(). + * Implements hook_menu(). */ function better_formats_menu() { $items = array(); - $items['admin/settings/filters/settings'] = array( + $items['admin/config/content/formats/settings'] = array( 'title' => 'Settings', 'description' => 'Manage input formats', 'page callback' => 'drupal_get_form', @@ -55,7 +76,7 @@ 'weight' => 3, 'file' => 'better_formats_settings.admin.inc', ); - $items['admin/settings/filters/defaults'] = array( + $items['admin/config/content/formats/defaults'] = array( 'title' => 'Defaults', 'description' => 'Manage input formats', 'page callback' => 'drupal_get_form', @@ -70,23 +91,23 @@ } /** - * Implementation of hook_theme(). + * Implements hook_theme(). */ function better_formats_theme() { return array( 'better_formats_defaults_admin_form' => array( 'template' => 'better-formats-defaults-admin-form', 'file' => 'better_formats_defaults.admin.inc', - 'arguments' => array('form' => NULL), + 'render element' => 'form', ), 'better_formats_filter_tips_more_info' => array( - 'arguments' => array(), + 'variables' => array(), ), ); } /** - * Implementation of hook_form_alter(). + * Implements hook_form_alter(). */ function better_formats_form_alter(&$form, $form_state, $form_id) { // Alter new node and comment forms. @@ -144,7 +165,8 @@ $node_type = $form['#node_type']->type; // Build array of all formats for allowed checkboxes. - $formats = filter_formats(); + global $user; + $formats = filter_formats($user); foreach ($formats as $format) { $format_boxes[$format->format] = $format->name; } @@ -209,7 +231,12 @@ // Remove current db entries. $sql = "DELETE FROM {better_formats_defaults} WHERE type='comment/%s' OR type='node/%s'"; - db_query($sql, $node_type, $node_type); + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query($sql, $node_type, $node_type) */ + db_delete('better_formats_defaults') + ->condition('type', $node_type) + ->condition('type', $node_type) + ->execute(); // Insert defualt values into DB. $sql = "INSERT INTO {better_formats_defaults} @@ -217,6 +244,7 @@ foreach ($form_state['values']['better_formats_defaults'] as $key => $values) { if (strpos($key, 'node-') === 0 || strpos($key, 'comment-') === 0) { list($type, $rid) = explode('-', $key); + // TODO Please convert this statement to the D7 database API syntax. db_query($sql, $rid, $type . '/' . $node_type, $values['format'], 2, $values['weight']); } } @@ -236,15 +264,21 @@ $sql = "SELECT rid FROM {role} ORDER BY rid DESC"; - $row = db_fetch_object(db_query_range($sql, 0, 1)); + $row = db_fetch_object(db_query_range($sql)); $rid = $row->rid; // Create stubs in per role table. $sql = "INSERT INTO {better_formats_defaults} VALUES (%d, '%s', %d, %d, %d)"; - db_query($sql, $rid, 'node', 0, 1, 25); - db_query($sql, $rid, 'comment', 0, 1, 25); - db_query($sql, $rid, 'block', 0, 1, 25); + // TODO Please convert this statement to the D7 database API syntax. + /* db_query($sql, $rid, 'node', 0, 1, 25) */ + NULL; + // TODO Please convert this statement to the D7 database API syntax. + /* db_query($sql, $rid, 'comment', 0, 1, 25) */ + NULL; + // TODO Please convert this statement to the D7 database API syntax. + /* db_query($sql, $rid, 'block', 0, 1, 25) */ + NULL; } /** @@ -256,18 +290,24 @@ // Delete role from format manager table. $sql = "DELETE FROM {better_formats_defaults} WHERE rid = %d"; - db_query($sql, $form['rid']['#value']); + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query($sql, $form['rid']['#value']) */ + db_delete('better_formats_defaults') + ->condition('rid', $form['rid']['#value']) + ->execute(); } /** - * Implementation of hook_node_type(). + * Implements hook_node_type_delete(). */ -function better_formats_node_type($op, $info) { - if ($op === 'delete') { +function better_formats_node_type_delete($info) { + if (TRUE) { // Delete per node type settings on node type delete. $sql = "DELETE FROM {better_formats_defaults} WHERE type IN ('node/%s', 'comment/%s')"; - db_query($sql, $info->type, $info->type); + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query($sql, $info->type, $info->type) */ + db_delete('better_formats_defaults')->where("type IN (' node / % s ', ' comment / % s ')")->execute(); // Delete node type variables. variable_del('better_formats_allowed_' . $info->type); @@ -275,11 +315,16 @@ } /** - * Implementation of hook_elements(). + * Implements hook_node_type(). + */ +function better_formats_node_type_OLD($op, $info) { } + +/** + * Implements hook_element_info(). * * Adds a process function to CCK's text module FAPI elements. */ -function better_formats_elements() { +function better_formats_element_info() { return array( 'text_textfield' => array( '#process' => array('better_formats_text_process'), @@ -306,7 +351,7 @@ // Get core default for new or selected format for existing. $filter_key = (count($element['#columns']) == 2) ? $element['#columns'][1] : 'format'; $format = isset($element['#value'][$filter_key]) ? $element['#value'][$filter_key] : $element['#default_value'][$filter_key]; - $parents = array_merge($element['#parents'] , array($filter_key)); + $parents = array_merge($element['#parents'], array($filter_key)); $default = better_formats_get_default_format('node', $form['type']['#value']); // Overwrite format default if new node. @@ -467,7 +512,8 @@ FROM {better_formats_defaults} WHERE rid IN (%s) AND type IN ('$types') ORDER BY type_weight DESC, weight ASC"; - $row = db_fetch_object(db_query_range($sql, $roles, 0, 1)); + // TODO Please convert this statement to the D7 database API syntax. + $row = db_fetch_object(db_query_range($sql, $roles)); $format[$type] = filter_resolve_format($row->format); } @@ -487,7 +533,8 @@ */ function better_formats_filter_form($value = FILTER_FORMAT_DEFAULT, $default_format, $mode = 'node', $node_type = '', $weight = 1, $parents = array('format')) { $value = filter_resolve_format($value); - $formats = filter_formats(); + global $user; + $formats = filter_formats($user); $show_selection = user_access('show format selection for ' . $mode . 's'); $show_tips = user_access('show format tips'); $show_tips_link = user_access('show more format tips link'); @@ -555,11 +602,11 @@ '#default_value' => $default, '#return_value' => $format->format, '#parents' => $parents, - '#id' => form_clean_id('edit-' . implode('-', $parents_for_id)), + '#id' => drupal_clean_css_identifier('edit-' . implode('-', $parents_for_id)), ); if ($show_tips) { - $form[$format->format]['#description'] = theme('filter_tips', _filter_tips($format->format, FALSE)); + $form[$format->format]['#description'] = theme('filter_tips', array('tips' => _filter_tips($format->format, FALSE))); } else { // Ensure expected filter_form() structure. @@ -591,7 +638,7 @@ $tips = _filter_tips($format->format, FALSE); $form['format']['guidelines'] = array( '#title' => t('Formatting guidelines'), - '#value' => theme('filter_tips', $tips, FALSE), + '#value' => theme('filter_tips', array('tips' => $tips, 'long' => FALSE)), ); } else { Index: better_formats.install =================================================================== --- better_formats.install (revision 1) +++ better_formats.install (working copy) @@ -11,7 +11,7 @@ /** - * Implementation of hook_schema(). + * Implements hook_schema(). */ function better_formats_schema() { $schema['better_formats_defaults'] = array( @@ -55,48 +55,50 @@ } /** - * Implementation of hook_install(). + * Implements hook_install(). */ function better_formats_install() { // Create tables. - drupal_install_schema('better_formats'); + // TODO The drupal_(un)install_schema functions are called automatically in D7. + // drupal_install_schema('better_formats') // Increase module weight to prevent compatibility issues. $sql = "UPDATE {system} SET weight = 100 WHERE name = 'better_formats'"; - db_query($sql); + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query($sql) */ + db_update('system') + ->fields(array( + 'weight' => 100, + )) + ->condition('name', 'better_formats') + ->execute(); // Insert format defaults. $roles = user_roles(); - $sql = "INSERT INTO {better_formats_defaults} - VALUES (%d, '%s', %d, %d, %d)"; foreach ($roles as $rid => $role) { - db_query($sql, $rid, 'node', 0, 1, 0); - db_query($sql, $rid, 'comment', 0, 1, 0); - db_query($sql, $rid, 'block', 0, 1, 25); + $node_sql = db_insert('better_formats_defaults')->fields(array('rid' => $rid, 'type' => 'node', 'format' => 0, 'type_weight' => 1, 'weight' => 0,))->execute(); + $comment_sql = db_insert('better_formats_defaults')->fields(array('rid' => $rid, 'type' => 'comment', 'format' => 0, 'type_weight' => 1, 'weight' => 0,))->execute(); + $block_sql = db_insert('better_formats_defaults')->fields(array('rid' => $rid, 'type' => 'block', 'format' => 0, 'type_weight' => 1, 'weight' => 25,))->execute(); } // Set default perms to be like core defaults. - $default_perms = ', show format selection for nodes, show format selection for comments, show format selection for blocks, show format tips, show more format tips link, collapsible format selection, collapse format fieldset by default'; + $default_perms = 'show format selection for nodes, show format selection for comments, show format selection for blocks, show format tips, show more format tips link, collapsible format selection, collapse format fieldset by default'; // Get current core perms. - $sql = "SELECT * - FROM {permission} - WHERE rid IN (1,2)"; - $result = db_query($sql); + $result = db_query("SELECT * FROM {role_permission} WHERE rid IN (1,2)"); $role_perms = array(); - while ($row = db_fetch_object($result)) { - $role_perms[$row->rid] = $row; + foreach($result as $record) { + $role_perms[$record->rid] = $record; } // If a role has no permissions set it will not have a row in the database. // Assume that roles do not need perms set for BF as well if none are set. if (!empty($role_perms)) { // Add perms to core roles (anonymous user, authenticated user). foreach ($role_perms as $perms) { - $sql = "UPDATE {permission} - SET perm = '%s' - WHERE pid = %d"; - db_query($sql, $perms->perm . $default_perms, $perms->pid); + $sql = "UPDATE {permission} SET permission = '%s' WHERE pid = %d"; + // TODO Please review the conversion of this statement to the D7 database API syntax. + db_update('role_permission')->fields(array('permission' => $perms->perm . $default_perms,))->condition('module', 'better_formats')->execute(); } // Clear the cache. cache_clear_all(); @@ -104,16 +106,21 @@ } /** - * Implementation of hook_uninstall(). + * Implements hook_uninstall(). */ function better_formats_uninstall() { // Remove tables. - drupal_uninstall_schema('better_formats'); + // TODO The drupal_(un)install_schema functions are called automatically in D7. + // drupal_uninstall_schema('better_formats') // Delete settings from varible table. $sql = "DELETE FROM {variable} WHERE name LIKE 'better_formats%'"; - db_query($sql); + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query($sql) */ + db_delete('variable') + ->condition('name', 'better_formats%', 'LIKE') + ->execute(); } /** @@ -127,6 +134,7 @@ $sql = "INSERT INTO {better_formats_defaults} VALUES (%d, '%s', %d, %d, %d)"; foreach ($roles as $rid => $role) { + // TODO Please convert this statement to the D7 database API syntax. $result = db_query($sql, $rid, 'block', 0, 1, 25); $ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql)); } @@ -149,12 +157,22 @@ $sql = "UPDATE {permission} SET perm = '%s' WHERE pid = %d"; - $result = db_query($sql, $perms->perm, $perms->pid); + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query($sql, $perms->perm, $perms->pid) */ + $result = db_update('permission') + ->fields(array( + 'perm' => $perms->perm, + )) + ->condition('pid', $perms->pid) + ->execute(); $ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql)); } // Clear the cache. cache_clear_all(); } - return $ret; + // hook_update_N() no longer returns a $ret array. Instead, return + // nothing or a translated string indicating the update ran successfully. + // See http://drupal.org/node/224333#update_sql. + return t('TODO Add a descriptive string here to show in the UI.') /* $ret */; } Index: better_formats_defaults.admin.inc =================================================================== --- better_formats_defaults.admin.inc (revision 1) +++ better_formats_defaults.admin.inc (working copy) @@ -16,7 +16,7 @@ * @see better_formats_defaults_admin_form_validate() * @see better_formats_defaults_admin_form_submit() */ -function better_formats_defaults_admin_form() { +function better_formats_defaults_admin_form($form, &$form_state) { $form = array( '#tree' => TRUE, ); @@ -41,7 +41,8 @@ * @see better_formats_defaults_admin_form_submit() */ function better_formats_defaults_admin_form_validate($form, &$form_state) { - $formats = filter_formats(); + global $user; + $formats = filter_formats($user); foreach ($formats as $fid => $format) { $roles[$fid] = explode(',', $format->roles); } @@ -79,6 +80,7 @@ foreach ($form_state['values'] as $key => $values) { if (strpos($key, 'node-') === 0 || strpos($key, 'comment-') === 0 || strpos($key, 'block-') === 0) { list($type, $rid) = explode('-', $key); + // TODO Please convert this statement to the D7 database API syntax. db_query($sql, $values['format'], $values['weight'], $rid, $type); } } @@ -114,6 +116,7 @@ ON bf.rid = role.rid WHERE bf.type IN ('$types') ORDER BY bf.type_weight DESC, bf.weight, role.rid"; + // TODO Please convert this statement to the D7 database API syntax. $result = db_query($sql); $roles_set = array(); @@ -159,7 +162,8 @@ * @see better_formats_get_role_default_fields() */ function better_formats_get_formats_per_role() { - $formats = filter_formats(); + global $user; + $formats = filter_formats($user); $roles = user_roles(); // Get roles that have administer filters permission. @@ -197,6 +201,7 @@ FROM {permission} WHERE perm LIKE '%$perm%' ORDER BY rid"; + // TODO Please convert this statement to the D7 database API syntax. $result = db_query($sql); $roles[$perm] = array(); while ($row = db_fetch_object($result)) { Index: better_formats.info =================================================================== --- better_formats.info (revision 1) +++ better_formats.info (working copy) @@ -1,11 +1,18 @@ ; $Id: better_formats.info,v 1.1.2.2 2009/02/25 06:44:17 dragonwize Exp $ name = Better Formats description = Enhances the core input format system by managing input format defaults and settings. -core = 6.x +core = 7.x ; Information added by drupal.org packaging script on 2010-02-05 version = "6.x-1.2" -core = "6.x" +core = 7.x project = "better_formats" datestamp = "1265402405" + +files[] = better-formats-defaults-admin-form.tpl.php +files[] = better_formats.install +files[] = better_formats.module +files[] = better_formats_defaults.admin.inc +files[] = better_formats_settings.admin.inc +files[] = tests/better_formats_anonymous_user.test