/** * Creates a tag * * @param string $p_username The user's username * @param string $p_password The user's password * @param array $p_tag The tag to create * @return soap_fault|integer */ function mc_tag_add($p_username, $p_password, $p_tag) { $t_user_id = mci_check_login($p_username, $p_password); if ($t_user_id === false) { return mci_soap_fault_login_failed(); } if (!access_has_global_level(config_get('tag_create_threshold'))) { return mci_soap_fault_access_denied($t_user_id); } $t_valid_matches = array(); $t_tag_name = $p_tag['name']; $t_tag_description = array_key_exists('description', $p_tag) ? $p_tag['description'] : ''; if (!tag_name_is_valid($t_tag_name, $t_valid_matches)) { return new soap_fault('client', '', 'Invalid tag name : "' . $t_tag_name . '"'); } $t_matching_by_name = tag_get_by_name($t_tag_name); if ($t_matching_by_name != false) { return new soap_fault('client', '', 'A tag with the same name already exists , id: ' . $t_matching_by_name['id']); } return tag_create($t_tag_name, $t_user_id, $t_tag_description); }
/** * Creates a tag * * @param string $p_username The user's username * @param string $p_password The user's password * @param array $p_tag The tag to create * @return soap_fault|integer */ function mc_tag_add($p_username, $p_password, $p_tag) { $t_user_id = mci_check_login($p_username, $p_password); if ($t_user_id === false) { return mci_soap_fault_login_failed(); } if (!access_has_global_level(config_get('tag_create_threshold'))) { return mci_soap_fault_access_denied($t_user_id); } $t_valid_matches = array(); $p_tag = SoapObjectsFactory::unwrapObject($p_tag); $t_tag_name = $p_tag['name']; $t_tag_description = array_key_exists('description', $p_tag) ? $p_tag['description'] : ''; if (!tag_name_is_valid($t_tag_name, $t_valid_matches)) { return SoapObjectsFactory::newSoapFault('Client', 'Invalid tag name : "' . $t_tag_name . '"'); } $t_matching_by_name = tag_get_by_name($t_tag_name); if ($t_matching_by_name != false) { return SoapObjectsFactory::newSoapFault('Client', 'A tag with the same name already exists , id: ' . $t_matching_by_name['id']); } log_event(LOG_WEBSERVICE, "creating tag '{$t_tag_name}' for user '{$t_user_id}'"); return tag_create($t_tag_name, $t_user_id, $t_tag_description); }
/** * Parse a filter string to extract existing and new tags. * When given a string, parses for tag names separated by configured separator, * then returns an array of tag rows for each tag. Existing tags get the full * row of information returned. If the tag does not exist, a row is returned with * id = -1 and the tag name, and if the name is invalid, a row is returned with * id = -2 and the tag name. The resulting array is then sorted by tag name. * @param string Filter string to parse * @return array Rows of tags parsed from filter string */ function tag_parse_filters($p_string) { $t_tags = array(); $t_prefix = '[+-]{0,1}'; $t_strings = explode(config_get('tag_separator'), $p_string); foreach ($t_strings as $t_name) { $t_name = trim($t_name); $t_matches = array(); if (!is_blank($t_name) && tag_name_is_valid($t_name, $t_matches, $t_prefix)) { $t_tag_row = tag_get_by_name($t_matches[1]); if ($t_tag_row !== false) { $t_filter = utf8_substr($t_name, 0, 1); if ('+' == $t_filter) { $t_tag_row['filter'] = 1; } else { if ('-' == $t_filter) { $t_tag_row['filter'] = -1; } else { $t_tag_row['filter'] = 0; } } $t_tags[] = $t_tag_row; } } else { continue; } } usort($t_tags, 'tag_cmp_name'); return $t_tags; }