diff --git export_ui/wordfilter.inc export_ui/wordfilter.inc new file mode 100644 index 0000000..3bbd90d --- /dev/null +++ export_ui/wordfilter.inc @@ -0,0 +1,105 @@ + 'wordfilter', + + // The access permission to use. If not provided it will default to + // 'administer site configuration' + 'access' => 'administer words filtered', + + // You can actually define large chunks of the menu system here. Nothing + // is required here. If you leave out the values, the prefix will default + // to admin/structure and the item will default to the plugin name. + 'menu' => array( + 'menu prefix' => 'admin/config/content', + 'menu item' => 'wordfilter', + // Title of the top level menu. Note this should not be translated, + // as the menu system will translate it. + 'menu title' => 'Word Filter', + // Description of the top level menu, which is usually needed for + // menu items in an administration list. Will be translated + // by the menu system. + 'menu description' => 'Replaces words or phrases inside posts with filtered versions.', + ), + + // These are required to provide proper strings for referring to the + // actual type of exportable. "proper" means it will appear at the + // beginning of a sentence. + 'title singular' => t('word'), + 'title singular proper' => t('Words'), + 'title plural' => t('words'), + 'title plural proper' => t('Words'), + + // This will provide you with a form for editing the properties on your + // exportable, with validate and submit handler. + // + // The item being edited will be in $form_state['item']. + // + // The submit handler is only responsible for moving data from + // $form_state['values'] to $form_state['item']. + // + // All callbacks will accept &$form and &$form_state as arguments. + 'form' => array( + 'settings' => 'wordfilter_admin_edit_form', + 'submit' => 'wordfilter_admin_edit_form_submit', + ), +); + + + +/** + * Edit word filter form. + */ +function wordfilter_admin_edit_form(&$form, &$form_state) { + $word = $form_state['item']; + // CTools tries to be nice by already giving us this field, but no thanks. + unset($form['info']['words']); + + $form['id'] = array( + '#type' => 'hidden', + '#value' => isset($word->id) ? $word->id : '', + ); + + $form['words'] = array( + '#type' => 'textfield', + '#title' => t('Word or phrase to filter'), + '#default_value' => !empty($word->words) ? $word->words : '', + '#description' => t('Enter the word or phrase you want to filter.'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + ); + $form['replacement'] = array( + '#type' => 'textfield', + '#title' => t('Replacement text'), + '#description' => t('Enter the filtered version of the word or phrase to replace the original word or phrase.'), + '#default_value' => !empty($word->replacement) ? $word->replacement : variable_get('wordfilter_default_replacement', '[filtered word]'), + '#size' => 50, + '#maxlength' => 255, + ); + $form['standalone'] = array( + '#type' => 'checkbox', + '#title' => t('Stand-alone'), + '#default_value' => isset($word->standalone) ? $word->standalone : 0, + '#description' => t('When checked, the word or phrase will only be filtered when found as a separate word or phrase (i.e. prefixed and suffixed by spaces or "whitespace"). A period one character after a word or phrase will exclude the words or phrases from replacement in stand-alone mode. This is useful for preventing accidental word or phrase filtering with short or common words or phrases.'), + ); + + return $form; +} + +/** + * Edit word filter form submit handler. + */ +function wordfilter_admin_edit_form_submit($form, &$form_state) { + $word = (object) $form_state['values']; + wordfilter_word_save($word); + watchdog('wordfilter', 'Updated filter for: %word', array('%word' => $form_state['values']['words'])); + drupal_set_message(t('Updated filter for: %word', array('%word' => $form_state['values']['words']))); +} diff --git wordfilter.crud.inc wordfilter.crud.inc new file mode 100644 index 0000000..5a1f84c --- /dev/null +++ wordfilter.crud.inc @@ -0,0 +1,69 @@ +id) && is_numeric($word->id)) ? array('id') : array(); + + $result = drupal_write_record('wordfilter', $word, $update); + + if ($result && $clear_cache) { + _wordfilter_cache_clear(); + } + + return $result; +} + +/** + * Clear static and Drupal caches. + */ +function _wordfilter_cache_clear() { + drupal_static_reset('wordfilter_word_load_all'); + cache_clear_all('*', 'cache_filter', TRUE); + cache_clear_all('wordfilter', 'cache'); +} diff --git wordfilter.info wordfilter.info index a109b81..00e929a 100644 --- wordfilter.info +++ wordfilter.info @@ -1,8 +1,6 @@ name = Word Filter description = Replaces words inside posts with filtered versions. core = 7.x -files[] = wordfilter.module -files[] = workfilter.install ; Information added by drupal.org packaging script on 2011-02-25 version = "7.x-1.x-dev" core = "7.x" diff --git wordfilter.install wordfilter.install index 25b3488..ea01322 100755 --- wordfilter.install +++ wordfilter.install @@ -11,6 +11,20 @@ function wordfilter_schema() { $schema['wordfilter'] = array( 'description' => 'The {wordfilter} table stores user ids of users and other users that they have chosen to ignore.', + 'export' => array( + 'key' => 'words', + 'key name' => 'Word', + 'primary key' => 'id', + 'identifier' => 'word', // Exports will be as $word + 'default hook' => 'wordfilter_default_words', // Function hook name. + 'load all callback' => 'wordfilter_word_load_all', + 'api' => array( + 'owner' => 'wordfilter', + 'api' => 'wordfilter_words', // Base name for api include files. + 'minimum_version' => 1, + 'current_version' => 1, + ), + ), 'fields' => array( 'id' => array( 'description' => 'The ID of the wordfilter word pair.', diff --git wordfilter.module wordfilter.module index c00eae6..ab21101 100644 --- wordfilter.module +++ wordfilter.module @@ -5,6 +5,8 @@ * Replaces words inside posts with filtered versions. */ +require_once 'wordfilter.crud.inc'; + /** * Implements hook_help(). * @@ -50,29 +52,13 @@ function wordfilter_permission() { function wordfilter_menu() { $items = array(); - $items['admin/config/content/wordfilter'] = array( - 'title' => 'Word filter', - 'description' => 'Replaces words or phrases inside posts with filtered versions.', - 'page callback' => 'wordfilter_admin_list', - 'access callback' => 'user_access', - 'access arguments' => array('administer words filtered'), - ); - - $items['admin/config/content/wordfilter/list'] = array( - 'title' => 'List', - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'access callback' => 'user_access', - 'access arguments' => array('administer words filtered'), - 'weight' => -10, - ); - - $items['admin/config/content/wordfilter/add'] = array( - 'title' => 'Add', + $items['admin/config/content/wordfilter/bulk-add'] = array( + 'title' => 'Bulk Add', 'page callback' => 'drupal_get_form', 'page arguments' => array('wordfilter_admin_add_form'), 'access callback' => 'user_access', 'access arguments' => array('administer words filtered'), - 'type' => MENU_LOCAL_TASK, + 'type' => MENU_LOCAL_ACTION, ); $items['admin/config/content/wordfilter/test'] = array( @@ -84,24 +70,6 @@ function wordfilter_menu() { 'type' => MENU_LOCAL_TASK, ); - $items['admin/config/content/wordfilter/edit/%'] = array( - 'title' => 'Edit', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('wordfilter_admin_edit_form', 5), - 'access callback' => 'user_access', - 'access arguments' => array('administer words filtered'), - 'type' => MENU_CALLBACK, - ); - - $items['admin/config/content/wordfilter/delete/%'] = array( - 'title' => 'Delete', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('wordfilter_admin_form_delete_confirm', 5), - 'access callback' => 'user_access', - 'access arguments' => array('administer words filtered'), - 'type' => MENU_CALLBACK, - ); - return $items; } @@ -153,6 +121,15 @@ function wordfilter_settings_form() { } /** + * Implements hook_ctools_plugin_directory(). + */ +function wordfilter_ctools_plugin_directory($module, $plugin) { + if ($module == 'ctools' && $plugin == 'export_ui') { + return 'export_ui'; + } +} + +/** * Delete a word from the word filter list delete * confirmation callback */ @@ -231,7 +208,7 @@ function wordfilter_block_view($delta = '') { function _wordfilter_table() { $content .= '
' . check_plain($filtered_word->replacement) . ' | ' . $alt . ' |