149 lines
3.4 KiB
PHP
149 lines
3.4 KiB
PHP
|
<?php
|
||
|
// $Id$
|
||
|
|
||
|
/**
|
||
|
* @file
|
||
|
* Hooks provided by the Taxonomy module.
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @addtogroup hooks
|
||
|
* @{
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* Act on taxonomy vocabularies when loaded.
|
||
|
*
|
||
|
* Modules implementing this hook can act on the vocabulary object returned by
|
||
|
* taxonomy_vocabulary_load().
|
||
|
*
|
||
|
* @param $vocabulary
|
||
|
* A taxonomy vocabulary object.
|
||
|
*/
|
||
|
function hook_taxonomy_vocabulary_load($vocabulary) {
|
||
|
$vocabulary->synonyms = variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Act on taxonomy vocabularies when inserted.
|
||
|
*
|
||
|
* Modules implementing this hook can act on the vocabulary object when saved
|
||
|
* to the database.
|
||
|
*
|
||
|
* @param $vocabulary
|
||
|
* A taxonomy vocabulary object.
|
||
|
*/
|
||
|
function hook_taxonomy_vocabulary_insert($vocabulary) {
|
||
|
if ($vocabulary->synonyms) {
|
||
|
variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', TRUE);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Act on taxonomy vocabularies when updated.
|
||
|
*
|
||
|
* Modules implementing this hook can act on the term object when updated.
|
||
|
*
|
||
|
* @param $term
|
||
|
* A taxonomy term object, passed by reference.
|
||
|
*/
|
||
|
function hook_taxonomy_vocabulary_update($term) {
|
||
|
$status = $vocabulary->synonyms ? TRUE : FALSE;
|
||
|
if ($vocabulary->synonyms) {
|
||
|
variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', $status);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Respond to the deletion of taxonomy vocabularies.
|
||
|
*
|
||
|
* Modules implementing this hook can respond to the deletion of taxonomy
|
||
|
* vocabularies from the database.
|
||
|
*
|
||
|
* @param $vocabulary
|
||
|
* A taxonomy vocabulary object.
|
||
|
*/
|
||
|
function hook_taxonomy_vocabulary_delete($vocabulary) {
|
||
|
if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) {
|
||
|
variable_del('taxonomy_' . $vocabulary->vid . '_synonyms');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Act on taxonomy terms when loaded.
|
||
|
*
|
||
|
* Modules implementing this hook can act on the term object returned by
|
||
|
* taxonomy_term_load().
|
||
|
*
|
||
|
* @param $term
|
||
|
* A taxonomy term object.
|
||
|
*/
|
||
|
function hook_taxonomy_term_load($term) {
|
||
|
$term->synonyms = taxonomy_get_synonyms($term->tid);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Act on taxonomy terms when inserted.
|
||
|
*
|
||
|
* Modules implementing this hook can act on the term object when saved to
|
||
|
* the database.
|
||
|
*
|
||
|
* @param $term
|
||
|
* A taxonomy term object.
|
||
|
*/
|
||
|
function hook_taxonomy_term_insert($term) {
|
||
|
if (!empty($term->synonyms)) {
|
||
|
foreach (explode ("\n", str_replace("\r", '', $term->synonyms)) as $synonym) {
|
||
|
if ($synonym) {
|
||
|
db_insert('term_synonym')
|
||
|
->fields(array(
|
||
|
'tid' => $term->tid,
|
||
|
'name' => rtrim($synonym),
|
||
|
))
|
||
|
->execute();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Act on taxonomy terms when updated.
|
||
|
*
|
||
|
* Modules implementing this hook can act on the term object when updated.
|
||
|
*
|
||
|
* @param $term
|
||
|
* A taxonomy term object.
|
||
|
*/
|
||
|
function hook_taxonomy_term_update($term) {
|
||
|
hook_taxonomy_term_delete($term);
|
||
|
if (!empty($term->synonyms)) {
|
||
|
foreach (explode ("\n", str_replace("\r", '', $term->synonyms)) as $synonym) {
|
||
|
if ($synonym) {
|
||
|
db_insert('term_synonym')
|
||
|
->fields(array(
|
||
|
'tid' => $term->tid,
|
||
|
'name' => rtrim($synonym),
|
||
|
))
|
||
|
->execute();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Respond to the deletion of taxonomy terms.
|
||
|
*
|
||
|
* Modules implementing this hook can respond to the deletion of taxonomy
|
||
|
* terms from the database.
|
||
|
*
|
||
|
* @param $term
|
||
|
* A taxonomy term object.
|
||
|
*/
|
||
|
function hook_taxonomy_term_delete($term) {
|
||
|
db_delete('term_synoynm')->condition('tid', $term->tid)->execute();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @} End of "addtogroup hooks".
|
||
|
*/
|