/// <summary> /// Creates a new blog category / tag. /// </summary> /// <param name="blogid">The blogid.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <param name="category">The category.</param> /// <returns></returns> public string newCategory( string blogid, string username, string password, wpCategory category) { if (User.validateCredentials(username, password, false)) { Channel userChannel = new Channel(username); if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "") { // Find the propertytype via the document type ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias); PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias); interfaces.IUseTags tags = UseTags(categoryType); if (tags != null) { tags.AddTag(category.name); } else { PreValue pv = new PreValue(); pv.DataTypeId = categoryType.DataTypeDefinition.Id; pv.Value = category.name; pv.Save(); } } } return(""); }
private void updateCategories(Document doc, Post post, Channel userChannel) { if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "") { ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias); PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias); String[] categories = post.categories; string categoryValue = ""; interfaces.IUseTags tags = UseTags(categoryType); if (tags != null) { tags.RemoveTagsFromNode(doc.Id); for (int i = 0; i < categories.Length; i++) { tags.AddTagToNode(doc.Id, categories[i]); } } else { for (int i = 0; i < categories.Length; i++) { PreValue pv = new PreValue(categoryType.DataTypeDefinition.Id, categories[i]); categoryValue += pv.Id + ","; } } if (categoryValue.Length > 0) { categoryValue = categoryValue.Substring(0, categoryValue.Length - 1); } doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryValue; } }
public CategoryInfo[] getCategories( string blogid, string username, string password) { if (validateUser(username, password)) { Channel userChannel = new Channel(username); if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "") { // Find the propertytype via the document type ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias); PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias); // check if the datatype uses tags or prevalues CategoryInfo[] returnedCategories = null; interfaces.IUseTags tags = UseTags(categoryType); if (tags != null) { List <interfaces.ITag> alltags = tags.GetAllTags(); returnedCategories = new CategoryInfo[alltags.Count]; int counter = 0; foreach (interfaces.ITag t in alltags) { CategoryInfo ci = new CategoryInfo(); ci.title = t.TagCaption; ci.categoryid = t.Id.ToString(); ci.description = ""; ci.rssUrl = ""; ci.htmlUrl = ""; returnedCategories[counter] = ci; counter++; } } else { SortedList categories = PreValues.GetPreValues(categoryType.DataTypeDefinition.Id); returnedCategories = new CategoryInfo[categories.Count]; IDictionaryEnumerator ide = categories.GetEnumerator(); int counter = 0; while (ide.MoveNext()) { PreValue category = (PreValue)ide.Value; CategoryInfo ci = new CategoryInfo(); ci.title = category.Value; ci.categoryid = category.Id.ToString(); ci.description = ""; ci.rssUrl = ""; ci.htmlUrl = ""; returnedCategories[counter] = ci; counter++; } } return(returnedCategories); } } throw new ArgumentException("Categories doesn't work for this channel, they might not have been activated. Contact your umbraco administrator."); }
public static interfaces.IUseTags UseTags(PropertyType categoryType) { if (typeof(interfaces.IUseTags).IsAssignableFrom(categoryType.DataTypeDefinition.DataType.DataEditor.GetType())) { interfaces.IUseTags tags = (interfaces.IUseTags)categoryType.DataTypeDefinition.DataType.DataEditor as interfaces.IUseTags; return(tags); } return(null); }
private static void UpdateCategories(Document doc, Post post, Channel userChannel) { if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "") { ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias); PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias); String[] categories = post.categories; string categoryValue = ""; interfaces.IUseTags tags = UseTags(categoryType); if (tags != null) { tags.RemoveTagsFromNode(doc.Id); for (int i = 0; i < categories.Length; i++) { tags.AddTagToNode(doc.Id, categories[i]); } //If the IUseTags provider manually set the property value to something on the IData interface then we should persist this //code commented as for some reason, even though the IUseTags control is setting IData.Value it is null here //could be a cache issue, or maybe it's a different instance of the IData or something, rather odd //doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryType.DataTypeDefinition.DataType.Data.Value; //Instead, set the document property to CSV of the tags - this WILL break custom editors for tags which don't adhere to the //pseudo standard that the .Value of the property contains CSV tags. doc.getProperty(userChannel.FieldCategoriesAlias).Value = string.Join(",", categories); } else { for (int i = 0; i < categories.Length; i++) { PreValue pv = new PreValue(categoryType.DataTypeDefinition.Id, categories[i]); categoryValue += pv.Id + ","; } if (categoryValue.Length > 0) { categoryValue = categoryValue.Substring(0, categoryValue.Length - 1); } doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryValue; } } }