Index: default_filter.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/default_filter/default_filter.info,v retrieving revision 1.1 diff -u -p -r1.1 default_filter.info --- default_filter.info 3 Aug 2007 17:19:18 -0000 1.1 +++ default_filter.info 29 Aug 2008 21:29:23 -0000 @@ -1,3 +1,4 @@ name = Default Filter description = "Allows administrators to set default input format per role." package = Administration +core=6.x \ No newline at end of file Index: default_filter.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/default_filter/default_filter.install,v retrieving revision 1.4 diff -u -p -r1.4 default_filter.install --- default_filter.install 31 Aug 2007 20:01:01 -0000 1.4 +++ default_filter.install 29 Aug 2008 21:29:23 -0000 @@ -1,36 +1,53 @@ array( + 'id' => array( + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'role_id' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'format_id' => array( + 'type' => 'int', + 'size' => 'medium', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'node_type' => array( + 'type' => 'varchar', + 'length' => 30, + 'not null' => TRUE, + ), + 'weight' => array( + 'type' => 'int', + 'size' => 'medium', + 'default' => 0, + 'unsigned' => FALSE, + 'not null' => TRUE, + ), + ), + 'primary key' => array('id'), + ); + + return $schema; } -function default_filter_uninstall(){ - db_query('DROP TABLE {default_filters}'); + + +function default_filter_install() { + drupal_install_schema('default_filter'); } -?> +function default_filter_uninstall() { + drupal_uninstall_schema('default_filter'); +} \ No newline at end of file Index: default_filter.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/default_filter/default_filter.module,v retrieving revision 1.10 diff -u -p -r1.10 default_filter.module --- default_filter.module 15 Jul 2008 20:19:27 -0000 1.10 +++ default_filter.module 29 Aug 2008 21:29:23 -0000 @@ -4,16 +4,16 @@ /** * Implementation of hook_help(). */ -function default_filter_help($section='') { +function default_filter_help($path, $arg) { $output = ''; - switch ($section) { + switch ($path) { case "admin/help/default_filter": case "admin/settings/default_filter": $output = '

' . t('This module allows you to set default filter formats per node type per role, preventing users from having to tick a checkbox every time they add a new node. This is useful for sites that set the global default to a less rich format to prevent anonymous users from using (for example) full HTML.') . '

'; $output .= '

' . t('To add a new default, select a role, an existing filter format, and a node type from the controls below. You may also wish to specify a weight in order to give some formats preference over others. For example, a user might belong to two roles that you have specified different defaults for. In this case, you would give a lighter weight to the more privileged role, so that its default is returned for that user, while other users who belong only to the less-privileged role would get the heavier default filter.') . '

'; $output .= '

' . t('This module honors filter format privileges. That is, if a given role has not been given permission to use a format in the filter administration section, this module does not override that permission. At present, this happens behind the scenes, and the user interface section does not enforce the prohibition yet. So be sure you have allowed a role to use a given filter prior to adding defaults here.') . '

'; - break; + break; case "admin/help#default_filter": case "admin/modules/#description": $output = '

' . t('This module allows you to specify default filter formats by role.') . '

'; @@ -24,14 +24,14 @@ function default_filter_help($section='' /** * Implementation of hook_perm(). */ -function default_filter_perm(){ +function default_filter_perm() { return array('administer default filters'); } /** * Settings submit code. */ -function default_filter_admin_submit(){ +function default_filter_admin_submit($form_values) { db_query("INSERT INTO {default_filters} (role_id, format_id, node_type, weight) VALUES(%d, %d, '%s', %d)", $_POST['role_id'], $_POST['format_id'], $_POST['node_type'], $_POST['weight']); drupal_set_message(t('Default filter settings saved.')); } @@ -39,21 +39,21 @@ function default_filter_admin_submit(){ /** * Settings form. */ -function default_filter_admin(){ +function default_filter_admin() { global $base_url; $form = array(); $roles = user_roles(); $formats = array(); - foreach(filter_formats() as $key => $format){ + foreach (filter_formats() as $key => $format) { $formats[$format->format] = $format->name; } $types = array(); - foreach(node_get_types() as $type){ + foreach (node_get_types() as $type) { $types[$type->type] = $type->name; } $types['default_filter_block'] = 'Block Filter'; - + $form['new'] = array( '#type' => 'fieldset', '#title' => t('New Filter Association'), @@ -86,13 +86,15 @@ function default_filter_admin(){ '#default_value' => 0, '#description' => t('Because people can belong to multiple roles, you may need to set a weight to assure that a given format for a given role for a given node type is set as the default before others are evaluated. The topmost grouping will be used. Negative weights rise to the top.'), ); + + $form['#submit'] = array('default_filter_admin_submit'); $output = system_settings_form($form); $headers = array(t('Role'), t('Format'), t('Node Type'), t('Weight'), t('Delete')); $rows = array(); $result = db_query('SELECT d.id, r.name AS role, f.name AS format, d.node_type, d.weight FROM {default_filters} d, {filter_formats} f, {role} r WHERE d.role_id = r.rid AND d.format_id = f.format ORDER BY d.role_id, d.weight ASC, d.format_id'); - while($row = db_fetch_object($result)){ + while ($row = db_fetch_object($result)) { $data[] = array( $row->role, $row->format, @@ -101,8 +103,9 @@ function default_filter_admin(){ '' . t('Delete') . '', ); } - - if(sizeof($data) > 0){ + + + if (!empty($data)) { $output['existing'] = array( '#type' => 'fieldset', '#title' => t('Existing Format Associations'), @@ -118,38 +121,45 @@ function default_filter_admin(){ /** * Implementation of hook_menu(). */ -function default_filter_menu($may_cache){ - $items[] = array( - 'path' => 'admin/settings/default_filter', - 'title' => t('Default Filter Settings'), - 'callback' => 'drupal_get_form', - 'callback arguments' => 'default_filter_admin', - 'access' => user_access('administer default filters'), - 'description' => t('Specify default filter formats by role.'), +function default_filter_menu() { + $items['admin/settings/default_filter'] = array( + 'title' => 'Default Filter Settings', + 'description' => 'Specify default filter formats by role.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('default_filter_admin'), + 'access arguments' => array('administer default filters'), 'type' => MENU_NORMAL_ITEM, ); - if(arg(4)){ - $items[] = array( - 'path' => 'admin/settings/default_filter/delete/' . arg(4), - 'title' => t('Delete Default Filter Association'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('default_filter_delete', intval(arg(4))), - 'access' => user_access('administer default filters'), - 'type' => MENU_NORMAL_ITEM, - ); - } + $items['admin/settings/default_filter/delete/%default_filter'] = array( + 'title' => 'Delete Default Filter Association', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('default_filter_delete', 4), + 'access arguments' => array('administer default filters'), + 'type' => MENU_NORMAL_ITEM, + ); + return $items; } +function default_filter_load($id) { + if (!is_numeric($id)) { + return FALSE; + } + else { + return db_fetch_object(db_query('SELECT * FROM {default_filters} WHERE id = %d', $id)); + } +} + + /** * Delete submit */ -function default_filter_delete_submit(){ - if($_POST['id'] && $id = intval($_POST['id'])){ +function default_filter_delete_submit() { + if ($_POST['id'] && $id = intval($_POST['id'])) { db_query('DELETE FROM {default_filters} WHERE id = %d', $id); drupal_set_message(t('Filter association deleted.')); } - else{ + else { drupal_set_message(t('Error deleting association.')); } drupal_goto('admin/settings/default_filter'); @@ -158,12 +168,13 @@ function default_filter_delete_submit(){ /** * Delete form. */ -function default_filter_delete($id){ +function default_filter_delete($form_state, $filter) { global $base_url; + $form = array(); $form['id'] = array( '#type' => 'hidden', - '#value' => $id, + '#value' => $filter->id, ); $form['warning'] = array( '#type' => 'item', @@ -188,8 +199,8 @@ function default_filter_delete($id){ * is equal to #return_value, so we set #value to the format value * to make the two line up. */ -function default_filter_form_alter($form_id, &$form) { - if($form['#id'] == 'node-form' && array_key_exists('body_filter', $form)) { +function default_filter_form_alter(&$form, &$form_state, $form_id) { + if ($form['#id'] == 'node-form' && array_key_exists('format', $form['body_field'])) { $form['default_filter_passed_form'] = array( '#type' => 'value', '#value' => 1, @@ -202,37 +213,37 @@ function default_filter_form_alter($form //formats, but others' installs used "format". This block looks for each. I've //also added below an if statement to confirm that whichever one gets set exists. $format_key = 'this is not a valid key'; - if(array_key_exists('filter', $form['body_filter'])){ + if (array_key_exists('filter', $form['body_field'])) { $format_key = 'filter'; } - if(array_key_exists('format', $form['body_filter'])){ + if (array_key_exists('format', $form['body_field'])) { $format_key = 'format'; } - if(array_key_exists($format_key, $form['body_filter']) && $format && !isset($form['nid']['#value'])){ + if (array_key_exists($format_key, $form['body_field']) && $format && !isset($form['nid']['#value'])) { //Unset any pre-selected filter. If multiples are checked, Gecko //browsers seem to take the last selected but IE takes the first selected. - foreach($form['body_filter'][$format_key] as $key => $val){ + foreach ($form['body_field'][$format_key] as $key => $val) { if (is_numeric($key)) { - if (isset($form['body_filter'][$format_key][$key]['#value'])) { - unset($form['body_filter'][$format_key][$key]['#value']); + if (isset($form['body_field'][$format_key][$key]['#value'])) { + unset($form['body_field'][$format_key][$key]['#value']); } - if (isset($form['body_filter'][$format_key][$key]['#default_value'])) { - unset($form['body_filter'][$format_key][$key]['#default_value']); + if (isset($form['body_field'][$format_key][$key]['#default_value'])) { + unset($form['body_field'][$format_key][$key]['#default_value']); } } } - if(isset($form['body_filter'][$format_key][$format])){ - $form['body_filter'][$format_key][$format]['#default_value'] = $format; + if (isset($form['body_field'][$format_key][$format])) { + $form['body_field'][$format_key][$format]['#default_value'] = $format; } } } else if ('block_box_form' == $form_id && array_key_exists('body_filter', $form)) { - $form['default_filter_passed_form'] = array( + $form['default_filter_passed_form'] = array( '#type' => 'value', '#value' => 1, ); - + $format = default_filter_retrieve('default_filter_block'); //The following two if statements are the result of an anomaly I never figured @@ -240,17 +251,17 @@ function default_filter_form_alter($form //formats, but others' installs used "format". This block looks for each. I've //also added below an if statement to confirm that whichever one gets set exists. $format_key = 'this is not a valid key'; - if(array_key_exists('filter', $form['body_filter'])){ + if (array_key_exists('filter', $form['body_filter'])) { $format_key = 'filter'; } - if(array_key_exists('format', $form['body_filter'])){ + if (array_key_exists('format', $form['body_filter'])) { $format_key = 'format'; } - if(array_key_exists($format_key, $form['body_filter']) && $format && !isset($form['nid']['#value'])){ + if (array_key_exists($format_key, $form['body_filter']) && $format && !isset($form['nid']['#value'])) { //Unset any pre-selected filter. If multiples are checked, Gecko //browsers seem to take the last selected but IE takes the first selected. - foreach($form['body_filter'][$format_key] as $key => $val){ + foreach ($form['body_filter'][$format_key] as $key => $val) { if (is_numeric($key)) { if (isset($form['body_filter'][$format_key][$key]['#value'])) { unset($form['body_filter'][$format_key][$key]['#value']); @@ -260,7 +271,7 @@ function default_filter_form_alter($form } } } - if(isset($form['body_filter'][$format_key][$format])){ + if (isset($form['body_filter'][$format_key][$format])) { $form['body_filter'][$format_key][$format]['#default_value'] = $format; } } @@ -272,10 +283,10 @@ function default_filter_form_alter($form * roles and set the node's format to that value. This handles cases in which * the user bypasses the node form (e.g. by using a blog editing client). */ -function default_filter_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){ - if($op == 'insert'){ +function default_filter_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { + if ($op == 'insert') { $format = default_filter_retrieve($node->type); - if($format && !isset($node->default_filter_passed_form)){ + if ($format && !isset($node->default_filter_passed_form)) { db_query('UPDATE {node_revisions} SET format = %d WHERE nid = %d', $format, $node->nid); } } @@ -285,26 +296,26 @@ function default_filter_nodeapi(&$node, * Get the lightest-weighted default filter associated with one of the * current user's roles. */ -function default_filter_retrieve($type){ +function default_filter_retrieve($type) { global $user; $roles = array_keys($user->roles); $eligible = array(); $eligible_formats = filter_formats(); //For each format available to this user... - foreach($eligible_formats as $f){ + foreach ($eligible_formats as $f) { //Get the roles... $eligible_roles = array_unique(split(',', $f->roles)); - //Append to the $eligible array a string that groups the format with + //Append to the $eligible array a string that groups the format with //a role that has access to that format. This is basically a flat list //of filters and the roles that can use them. - foreach($eligible_roles as $r){ + foreach ($eligible_roles as $r) { $eligible[] = $f->format . '.' . $r; } } - //Note the CONCAT function. This assures that we don't let users who + //Note the CONCAT function. This assures that we don't let users who //belong to some role access filters that belong to some other role. //$format = db_result(db_query('SELECT format_id FROM {default_filters} WHERE CONCAT(format_id, ".", role_id) IN ("' . join('","', $eligible) . '") AND role_id IN ("' . join('","', $roles) . '") AND node_type = "%s" ORDER BY weight ASC LIMIT 1', $type)); $format = db_result(db_query('SELECT format_id FROM {default_filters} WHERE CONCAT(format_id, ".", role_id) IN ("' . join('","', $eligible) . '") AND node_type = "%s" ORDER BY weight ASC LIMIT 1', $type));