We have an application where a certain list of terms should never be added as tags by the autotagger.
The following code is pretty simple and implements this idea.
It is for ver 1.27 but looking at ver 2.0 I think the same idea will work there as well.
You enter terms on the Autotag admin page, then autotag checks those terms and will never add those tags if they occur in the node.
In autotag.functions.inc, in function _autotag_search_field, add these lines:
//makes it skip autotagging on certain terms that we don't want automatic tags to be added for, ever
$autotag_skip_terms=variable_get('autotag_skip_terms', "");
#$autotag_skip_terms="News,Cycling Tips and Stories,Safe Routes to School,Advocacy Alerts"; #for testing purposes
$autotag_skip_terms_array=explode (",",$autotag_skip_terms);
$autotag_skip_terms_array = array_map('trim', $autotag_skip_terms_array);
foreach ( $autotag_skip_terms_array as $key => $value)
$autotag_skip_terms_array2[$key]= "'" . strtolower($value) ."'";//$autotag_skip_terms_array = array_map('strtolower', $autotag_skip_terms_array);
$skip_terms_sql_l = "";
$skip_terms_sql_s = "";
if (count($autotag_skip_terms_array2)>0) {$skip_terms_sql_l = "AND lowername NOT IN (" . implode(",",$autotag_skip_terms_array2).") ";
$skip_terms_sql_s = "AND LOWER(s.name) NOT IN (" . implode(",",$autotag_skip_terms_array2).") ";
}$words_including_small = preg_split('/[\ `!"£$%^&*()_\-+={\[}\]:;@\'~#<,>.?\/|\\\]/', strtolower($field), -1, PREG_SPLIT_NO_EMPTY);
A little lower in the same function, add the $skip_terms_sql_l and $skip_terms_sql_s variables like this:
$results = db_query("
SELECT
t.tid, t.vid
FROM
{term_lowername} l,
{term_data} t
WHERE
t.tid = l.tid AND
lowername IN (".implode(",",$words_placeholder).") AND
(".implode(" OR ",$vids_placeholder).") $skip_terms_sql_l $tag_only_leaves_sql
UNION
SELECT
t.tid, t.vid
FROM
{term_data} t,
{term_synonym} s
WHERE
s.tid = t.tid AND
LOWER(s.name) IN (".implode(",",$words_placeholder).") AND
(".implode(" OR ",$vids_placeholder).") $skip_terms_sql_s $tag_only_leaves_sql",
array_merge($words,$vids,$words,$vids));
A little lower, add those same two variables to these lines:
$results = db_query("
SELECT
tid
FROM
{term_lowername} l
WHERE
(".implode(" OR ",$sql_array).") $tag_only_leaves_sql
UNION
SELECT
tid
FROM
{term_synonym} s
WHERE
(".implode(" OR ",$sql_array_syn).") $skip_terms_sql_l $skip_terms_sql_s $tag_only_leaves_sql",
array_merge($words_array, $words_array_syn));
In autotag.settings.inc, add the autotag_skip_terms form element like this:
$form['autotag_only_leaves'] = array(
'#type' => 'checkbox',
'#title' => t('Tag nodes with only terms at the very tip of a taxonomy (i.e. Terms which are not the parent of any other term)'),
'#default_value' => variable_get('autotag_only_leaves', false),
'#description' => t('If checked, only the leaf terms will be used by autotag')
);
$form['autotag_skip_terms'] = array(
'#type' => 'textarea',
'#title' => t('Never autotag with these terms (comma separated list)'),
'#default_value' => variable_get('autotag_skip_terms', ""),
'#cols' => 60,
'#rows' => 5,
'#description' => t("These terms will be skipped when autotagging. They must match terms in the taxonomy exactly (except, not case-sensitive). If your taxonomy has synonyms defined you'll need to enter BOTH the term and its synonym to prevent autotagging."),
);
That's it--pretty simple and seems to work.
Comments
Comment #1
flug commentedJust in case the code above didn't come through formatted right, here it is with better formatting:
#1 (all but the last line is added):
#2: Only variables $skip_terms_sql_l and $skip_terms_sql_s are added:
#3: Only variables $skip_terms_sql_l and $skip_terms_sql_s are added:
#4: The $form['autotag_skip_terms'] section is added:
Comment #2
sdrycroft commentedThis may be possible to add by adding a "don't tag field" to a vocabulary, which when selected, means that a term will not be selected by the autotag module. This is actually pretty simple, and would only require a simple change to the autotag module.