function AMP_add_tags($tag_ids = false, $tag_names = false, $item_id, $item_type) { if ($tag_names) { require_once 'AMP/Content/Tag/Tag.php'; $new_tag_set = AMP_Content_Tag::create_many($tag_names); $new_tag_results = AMP_add_tags($new_tag_set, false, $item_id, $item_type); if (!$tag_ids) { return $new_tag_results; } } if (!$tag_ids) { return false; } if (!is_array($tag_ids)) { $tag_id_set = array($tag_ids); } else { $tag_id_set = $tag_ids; } $related_tags = AMPSystem_Lookup::instance('tagsBy' . ucfirst($item_type), $item_id); if ($related_tags) { $new_tags = array_diff($tag_id_set, array_keys($related_tags)); } else { $new_tags = $tag_id_set; } if (!$new_tags || empty($new_tags)) { return false; } require_once 'AMP/Content/Tag/Item/Item.php'; $action_item = new AMP_Content_Tag_Item(AMP_Registry::getDbcon()); $create_values = array('item_type' => $item_type, 'item_id' => $item_id, 'user_id' => AMP_SYSTEM_USER_ID); $results = 0; foreach ($new_tags as $new_tag_id) { $create_values['tag_id'] = $new_tag_id; $action_item->dropID(); $action_item->setData($create_values); $results += $action_item->save(); } return $results; }
function tag($tag_id = false, $tag_names = false) { if ($tag_names) { require_once 'AMP/Content/Tag/Tag.php'; $new_tag_set = AMP_Content_Tag::create_many($tag_names); $new_tag_results = true; foreach ($new_tag_set as $new_tag_id) { $new_tag_results = $new_tag_results && $this->tag($new_tag_id); } if (!$tag_id) { return $new_tag_results; } } if (!$tag_id) { return false; } $related_tags = AMPSystem_Lookup::instance('tagsByArticle', $this->id); if (isset($related_tags[$tag_id])) { return false; } require_once 'AMP/Content/Tag/Item/Item.php'; $action_item = new AMP_Content_Tag_Item(AMP_Registry::getDbcon()); $create_values = array('item_type' => 'article', 'item_id' => $this->id, 'user_id' => AMP_SYSTEM_USER_ID, 'tag_id' => $tag_id); $action_item->setData($create_values); return $action_item->save(); }
function _checkNewTags($data, $fieldname) { if (!(isset($data['new_tags']) && $data['new_tags'])) { return array(); } require_once 'AMP/Content/Tag/Tag.php'; return AMP_Content_Tag::create_many($data['new_tags']); /* $tags_set = preg_split( '/\s?,\s?/', $data['new_tags']); $tag_names = AMPSystem_Lookup::instance( 'tags' ); $simple_tag_names = array( ); $new_tags_verified = array( ); foreach( $tag_names as $tag_id => $tag_name ) { $simple_tag_names[$tag_id] = strtolower( $tag_name ); } foreach( $tags_set as $raw_new_tag ) { $new_tag = trim( $raw_new_tag ); if ( !$new_tag ) continue; //see if an existing tag matches the new one $new_tag_id = array_search( strtolower( $new_tag ), $simple_tag_names ); //create new tag if ( !$new_tag_id ) { $new_tag_id = $this->_createTag( $new_tag ); } if ( !$new_tag_id ) continue; //add the id to the results list $new_tags_verified[] = $new_tag_id; } return $new_tags_verified; */ }