--- /Users/neyoung/Desktop/autotag/autotag.module +++ autotag.module @@ -20,6 +20,16 @@ * may not be known on submit (if the node is new). */ function autotag_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){ + + // Not sure if this should be here. Module owner should verify this. + $node_types_to_ignore = variable_get("autotag_borked_content_types", variable_get('autotag_broken_node_types', array('webform', 'biblio'))); + + // Get content types to ignore from the settings page + $node_types_to_ignore = array_merge($node_types_to_ignore, explode(', ', trim(variable_get('autotag_content_types', '')))); + + // Don't autotag a node if it's specified on the settings page that the content type should be ignored. + if(in_array($node->type, $node_types_to_ignore)){return;} + switch($op){ case 'update': case 'insert': @@ -89,6 +99,40 @@ } } + +/** + * Implementation of hook_admin() + * + * Used to create the settings page + */ +function autotag_admin() { + + // Additional fields that autotag should ignore + $form['autotag_fields'] = array( + '#type' => 'textfield', + '#title' => t('Fields to ignore'), + '#default_value' => variable_get('autotag_fields', ''), + '#size' => 80, + '#maxlength' => 256, + '#description' => t("Comma separated list of fields to ignore."), + '#required' => FALSE, + ); + + // Content types that should not use autotag + $form['autotag_content_types'] = array( + '#type' => 'textfield', + '#title' => t('Content types to ignore'), + '#default_value' => variable_get('autotag_content_types', ''), + '#size' => 80, + '#maxlength' => 256, + '#description' => t("Comma separated list of content types that autotag won't be applied to."), + '#required' => FALSE, + ); + + return system_settings_form($form); +} + + /** * Implementation of hook_menu * @@ -102,9 +146,31 @@ 'access arguments' => array('create node content'), 'type' => MENU_CALLBACK ); + + // Displays the settings page link on the /admin page + $items['admin/autotag/autocomplete'] = array( + 'title' => 'Autotag Configuration', + 'description' => 'Allows you to configure the autotag module', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('autotag_admin'), + 'access arguments' => array('administer autotag'), + 'type' => MENU_NORMAL_ITEM, + ); + return $items; } + +/** + * Implementation of hook_perm(). + * + * Adds permissions to the modules settings page + */ +function autotag_perm() { + return array('administer autotag'); +} + + /** * hook_form_alter is further down (in a section of its own due to its size) */ @@ -180,6 +246,10 @@ // Autotag doesn't work with the following content types, return if this node // is one of these. $node_types_to_ignore = variable_get("autotag_borked_content_types", variable_get('autotag_broken_node_types', array('webform', 'biblio'))); + + // Get content types to ignore from the settings page + $node_types_to_ignore = array_merge($node_types_to_ignore, explode(', ', trim(variable_get('autotag_content_types', '')))); + if(in_array($form['type']['#value'], $node_types_to_ignore)){return;} // We're here, the form needs some changes, so lets get to it. @@ -650,6 +720,10 @@ $ignore_fields = array( 'op','attach-url','nid','vid','status','type','created','comment','changed','promote','sticky','revision_timestamp','log','format','uid','name','picture','data','path','last_comment_timestamp','last_comment_name','comment_count','files','iid','taxonomy','readmore','content','links','additionaltags' ); + + // Get fields to ignore from the settings page + $ignore_fields = array_merge($ignore_fields, explode(', ', trim(variable_get('autotag_fields', '')))); + foreach($node as $key=>$value){ if(!in_array($key, $ignore_fields)){ $fields[] = $key; @@ -662,6 +736,10 @@ $ignore_fields = array( 'op','attach-url','nid','vid','status','type','created','comment','changed','promote','sticky','revision_timestamp','log','format','uid','name','picture','data','path','last_comment_timestamp','last_comment_name','comment_count','files','iid','taxonomy','readmore','content','links','additionaltags' ); + + // Get fields to ignore from the settings page + $ignore_fields = array_merge($ignore_fields, explode(', ', trim(variable_get('autotag_fields', '')))); + if(is_object($post_form) || is_array($post_form)){ foreach($post_form as $key=>$value){ if(!in_array($key, $ignore_fields)){