function privatemsg_filter_create_tags in Privatemsg 6.2
Same name and namespace in other branches
- 6 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_create_tags()
- 7.2 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_create_tags()
- 7 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_create_tags()
Function to create a tag
Parameters
$tags: A single tag or an array of tags.
3 calls to privatemsg_filter_create_tags()
- privatemsg_filter_add_tag_submit in privatemsg_filter/
privatemsg_filter.module - Form callback for adding a tag to threads.
- privatemsg_filter_form_submit in privatemsg_filter/
privatemsg_filter.module - privatemsg_rules_load_tag in privatemsg_rules/
privatemsg_rules.rules.inc - Loads a tag.
File
- privatemsg_filter/
privatemsg_filter.module, line 176 - Allows users to tag private messages and to filter based upon those tags.
Code
function privatemsg_filter_create_tags($tags) {
if (!is_array($tags)) {
$tags = array(
$tags,
);
}
$tag_ids = array();
foreach ($tags as $tag) {
$tag = trim($tag);
if (empty($tag)) {
// Do not save a blank tag.
continue;
}
// Check if the tag already exists and only create the tag if it does not.
$tag_id = db_result(db_query("SELECT tag_id FROM {pm_tags} WHERE tag = '%s'", $tag));
if (empty($tag_id) && privatemsg_user_access('create private message tags')) {
db_query("INSERT INTO {pm_tags} (tag) VALUES ('%s')", $tag);
$tag_id = db_last_insert_id('pm_tags', 'tag_id');
}
elseif (empty($tag_id)) {
// The user does not have permission to create new tags - disregard this tag and move onto the next.
drupal_set_message(t('Tag %tag was ignored because you do not have permission to create new tags.', array(
'%tag' => $tag,
)));
continue;
}
$tag_ids[] = $tag_id;
}
return $tag_ids;
}