/// <summary> /// Creates a new blog entry /// </summary> /// <param name="core">Core token</param> /// <param name="blog"></param> /// <param name="title">Title for the new blog entry</param> /// <param name="body">Body for the new blog entry</param> /// <param name="license">License ID for the new blog entry</param> /// <param name="status">Publish status for the new blog entry</param> /// <param name="category">Category ID for the new blog entry</param> /// <param name="postTime">Post time for the new blog entry</param> /// <returns>The new blog entry retrieved from the DB</returns> /// <exception cref="NullCoreException">Throws exception when core token is null</exception> /// <exception cref="InvalidBlogException">Throws exception when blog token is null</exception> /// <exception cref="UnauthorisedToCreateItemException">Throws exception when unauthorised to create a new BlogEntry</exception> public static BlogEntry Create(Core core, AccessControlToken token, Blog blog, string title, string body, byte license, PublishStatuses status, short category, long postTime) { if (core == null) { throw new NullCoreException(); } if (blog == null) { throw new InvalidBlogException(); } if (blog.UserId != core.LoggedInMemberId) { throw new UnauthorisedToCreateItemException(); } /*if (!blog.Access.Can("POST_ITEMS")) { }*/ string bodyCache = string.Empty; if (!body.Contains("[user") && !body.Contains("sid=true]")) { bodyCache = core.Bbcode.Parse(HttpUtility.HtmlEncode(body), null, blog.Owner, true, string.Empty, string.Empty); } long now = UnixTime.UnixTimeStamp(); BlogEntry blogEntry = (BlogEntry)Item.Create(core, typeof(BlogEntry), new FieldValuePair("user_id", blog.UserId), new FieldValuePair("post_time_ut", now), new FieldValuePair("post_title", title), new FieldValuePair("post_published_ut", postTime), new FieldValuePair("post_modified_ut", now), new FieldValuePair("post_ip", core.Session.IPAddress.ToString()), new FieldValuePair("post_text", body), new FieldValuePair("post_text_cache", bodyCache), new FieldValuePair("post_license", license), new FieldValuePair("post_status", (byte)status), new FieldValuePair("post_category", category), new FieldValuePair("post_simple_permissions", true)); AccessControlLists acl = new AccessControlLists(core, blogEntry); acl.SaveNewItemPermissions(token); return blogEntry; }
private string saveImage(NumberedItem post, string imageType, byte[] imageData) { BlogEntry myBlogEntry = null; if (post is BlogEntry) { myBlogEntry = (BlogEntry)myBlogEntry; } string imagePath = string.Empty; Gallery.Gallery parent = null; Gallery.Gallery grandParent = null; string grandParentSlug = "photos-from-posts"; try { grandParent = new Gallery.Gallery(core, Owner, grandParentSlug); } catch (InvalidGalleryException) { Gallery.Gallery root = new Gallery.Gallery(core, Owner); grandParent = Gallery.Gallery.Create(core, Owner, root, "Photos From Posts", ref grandParentSlug, "All my unsorted uploads"); } string gallerySlug = "blog-" + post.Id.ToString(); try { parent = new Gallery.Gallery(core, Owner, gallerySlug); parent.GalleryTitle = myBlogEntry.Title; parent.Update(); } catch (InvalidGalleryException) { parent = Gallery.Gallery.Create(core, Owner, grandParent, myBlogEntry.Title, ref gallerySlug, string.Empty); } AccessControlLists acl = new AccessControlLists(core, parent); acl.SaveNewItemPermissions(); MemoryStream stream = new MemoryStream(); stream.Write(imageData, 0, imageData.Length); string slug = "image-" + parent.Items.ToString(); GalleryItem newGalleryItem = GalleryItem.Create(core, Owner, parent, string.Empty, ref slug, slug, imageType, (ulong)imageData.Length, string.Empty, core.Functions.GetLicenseId(), core.Functions.GetClassification(), stream, true /*, width, height*/); imagePath = newGalleryItem.FullPath; return imagePath; }
void AccountGalleriesUpload_Save(object sender, EventArgs e) { ControlPanelSubModule.AuthoriseRequestSid(core); long galleryId = core.Functions.FormLong("gallery-id", 0); string title = core.Http.Form["title"]; string galleryTitle = core.Http.Form["gallery-title"]; string description = core.Http.Form["description"]; bool publishToFeed = (core.Http.Form["publish-feed"] != null); bool highQualitySave = (core.Http.Form["high-quality"] != null); bool submittedTitle = true; if (string.IsNullOrEmpty(galleryTitle)) { submittedTitle = false; galleryTitle = "Uploaded " + core.Tz.Now.ToString("MMMM dd, yyyy"); } bool newGallery = core.Http.Form["album"] == "create"; int filesUploaded = 0; for (int i = 0; i < core.Http.Files.Count; i++) { if (core.Http.Files.GetKey(i).StartsWith("photo-file", StringComparison.Ordinal)) { filesUploaded++; if (core.Http.Files[i] == null || core.Http.Files[i].ContentLength == 0) { core.Response.ShowMessage("error", "No files selected", "You need to select some files to upload"); } } } if (filesUploaded == 0) { core.Response.ShowMessage("error", "No files selected", "You need to select some files to upload"); return; } try { Gallery parent = null; if (newGallery) { Gallery grandParent = null; if (!submittedTitle) { string grandParentSlug = "photos-from-posts"; try { grandParent = new Gallery(core, Owner, grandParentSlug); } catch (InvalidGalleryException) { Gallery root = new Gallery(core, Owner); grandParent = Gallery.Create(core, Owner, root, "Photos From Posts", ref grandParentSlug, "All my unsorted uploads"); } } else { grandParent = new Gallery(core, Owner); } string gallerySlug = string.Empty; if (!submittedTitle) { gallerySlug = "photos-" + UnixTime.UnixTimeStamp().ToString(); } else { gallerySlug = Gallery.GetSlugFromTitle(galleryTitle, ""); } try { parent = Gallery.Create(core, LoggedInMember, grandParent, galleryTitle, ref gallerySlug, string.Empty); } catch (GallerySlugNotUniqueException) { core.Response.ShowMessage("error", "Gallery not unique", "Please give a different name to the gallery"); } AccessControlLists acl = new AccessControlLists(core, parent); acl.SaveNewItemPermissions(); } else { parent = new Gallery(core, Owner, galleryId); } string slug = string.Empty; try { for (int i = 0; i < core.Http.Files.Count; i++) { if (!core.Http.Files.GetKey(i).StartsWith("photo-file", StringComparison.Ordinal)) { continue; } slug = core.Http.Files[i].FileName; MemoryStream stream = new MemoryStream(); core.Http.Files[i].InputStream.CopyTo(stream); db.BeginTransaction(); GalleryItem newGalleryItem = GalleryItem.Create(core, Owner, parent, title, ref slug, core.Http.Files[i].FileName, core.Http.Files[i].ContentType, (ulong)core.Http.Files[i].ContentLength, description, core.Functions.GetLicenseId(), core.Functions.GetClassification(), stream, highQualitySave /*, width, height*/); stream.Close(); if (publishToFeed && i < 3) { core.CallingApplication.PublishToFeed(core, LoggedInMember, parent, newGalleryItem, Functions.SingleLine(core.Bbcode.Flatten(newGalleryItem.ItemAbstract))); } } //db.CommitTransaction(); if (core.ResponseFormat == ResponseFormats.Xml) { long newestId = core.Functions.FormLong("newest-id", 0); long newerId = 0; List<BoxSocial.Internals.Action> feedActions = Feed.GetNewerItems(core, LoggedInMember, newestId); Template template = new Template("pane.feeditem.html"); template.Medium = core.Template.Medium; template.SetProse(core.Prose); foreach (BoxSocial.Internals.Action feedAction in feedActions) { VariableCollection feedItemVariableCollection = template.CreateChild("feed_days_list.feed_item"); if (feedAction.Id > newerId) { newerId = feedAction.Id; } core.Display.ParseBbcode(feedItemVariableCollection, "TITLE", feedAction.FormattedTitle); core.Display.ParseBbcode(feedItemVariableCollection, "TEXT", feedAction.Body, core.PrimitiveCache[feedAction.OwnerId], true, string.Empty, string.Empty); feedItemVariableCollection.Parse("USER_DISPLAY_NAME", feedAction.Owner.DisplayName); feedItemVariableCollection.Parse("ID", feedAction.ActionItemKey.Id); feedItemVariableCollection.Parse("TYPE_ID", feedAction.ActionItemKey.TypeId); if (feedAction.ActionItemKey.GetType(core).Likeable) { feedItemVariableCollection.Parse("LIKEABLE", "TRUE"); if (feedAction.Info.Likes > 0) { feedItemVariableCollection.Parse("LIKES", string.Format(" {0:d}", feedAction.Info.Likes)); feedItemVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", feedAction.Info.Dislikes)); } } if (feedAction.ActionItemKey.GetType(core).Commentable) { feedItemVariableCollection.Parse("COMMENTABLE", "TRUE"); if (feedAction.Info.Comments > 0) { feedItemVariableCollection.Parse("COMMENTS", string.Format(" ({0:d})", feedAction.Info.Comments)); } } //Access access = new Access(core, feedAction.ActionItemKey, true); if (feedAction.PermissiveParent.Access.IsPublic()) { feedItemVariableCollection.Parse("IS_PUBLIC", "TRUE"); if (feedAction.ActionItemKey.GetType(core).Shareable) { feedItemVariableCollection.Parse("SHAREABLE", "TRUE"); //feedItemVariableCollection.Parse("U_SHARE", feedAction.ShareUri); if (feedAction.Info.SharedTimes > 0) { feedItemVariableCollection.Parse("SHARES", string.Format(" {0:d}", feedAction.Info.SharedTimes)); } } } if (feedAction.Owner is User) { feedItemVariableCollection.Parse("USER_TILE", ((User)feedAction.Owner).Tile); feedItemVariableCollection.Parse("USER_ICON", ((User)feedAction.Owner).Icon); } } // Check for new messages and upload Dictionary<string, string> returnValues = new Dictionary<string, string>(); returnValues.Add("update", "true"); returnValues.Add("message", description); returnValues.Add("template", template.ToString()); returnValues.Add("newest-id", newerId.ToString()); core.Response.SendDictionary("statusPosted", returnValues); } else { if (filesUploaded == 1) { template.Parse("REDIRECT_URI", Gallery.BuildPhotoUri(core, Owner, parent.FullPath, slug)); } else { template.Parse("REDIRECT_URI", parent.Uri); } core.Display.ShowMessage("Photo Uploaded", "You have successfully uploaded a photo."); } return; } catch (GalleryItemTooLargeException) { db.RollBackTransaction(); core.Response.ShowMessage("error", "Photo too big", "The photo you have attempted to upload is too big, you can upload photos up to " + Functions.BytesToString(core.Settings.MaxFileSize) + " in size."); return; } catch (GalleryQuotaExceededException) { db.RollBackTransaction(); core.Response.ShowMessage("error", "Not Enough Quota", "You do not have enough quota to upload this photo. Try resizing the image before uploading or deleting images you no-longer need. Smaller images use less quota."); return; } catch (InvalidGalleryItemTypeException) { db.RollBackTransaction(); core.Response.ShowMessage("error", "Invalid image uploaded", "You have tried to upload a file type that is not a picture. You are allowed to upload PNG and JPEG images."); return; } catch (InvalidGalleryFileNameException) { db.RollBackTransaction(); core.Response.ShowMessage("error", "Submission failed", "Submission failed, try uploading with a different file name."); return; } } catch (InvalidGalleryException) { db.RollBackTransaction(); core.Response.ShowMessage("error", "Submission failed", "Submission failed, Invalid Gallery."); return; } }
public static StatusMessage SaveMessage(Core core, string message) { if (core == null) { throw new NullCoreException(); } StatusMessage statusMessage = StatusMessage.Create(core, core.Session.LoggedInMember, message, core.Session.ApplicationId); AccessControlLists acl = new AccessControlLists(core, statusMessage); acl.SaveNewItemPermissions(); core.Search.Index(statusMessage); ApplicationEntry ae = core.GetApplication("Profile"); ae.PublishToFeed(core, core.Session.LoggedInMember, statusMessage, Functions.SingleLine(core.Bbcode.Flatten(statusMessage.Message))); return statusMessage; }
protected void Page_Load(object sender, EventArgs e) { bool isAjax = false; long itemId; long itemTypeId; ItemKey itemKey = null; IShareableItem item = null; if (Request["ajax"] == "true") { isAjax = true; } if (!core.Session.IsLoggedIn) { core.Response.ShowMessage("notLoggedIn", "Not Logged In", "Sign in to share this item."); } string mode = Request.QueryString["mode"]; if (mode == "post") { template.SetTemplate("pane.share.post.html"); try { itemId = long.Parse((string)core.Http.Query["item"]); itemTypeId = long.Parse((string)core.Http.Query["type"]); itemKey = new ItemKey(itemId, itemTypeId); item = (IShareableItem)NumberedItem.Reflect(core, itemKey); TextBox messageTextBox = new TextBox("share-message"); PermissionGroupSelectBox permissionSelectBox = new PermissionGroupSelectBox(core, "share-permissions", core.Session.LoggedInMember.ItemKey); template.Parse("S_SHARE_MESSAGE", messageTextBox); template.Parse("S_SHARE_PERMISSIONS", permissionSelectBox); template.Parse("S_SHARED_URI", item.Info.ShareUri); core.Display.ParseBbcode(template, "S_SHARED_STRING", core.Functions.Tldr("[share=\"[iurl=\"" + item.Uri + "\"]" + item.Owner.DisplayName + "[/iurl]\"]" + item.ShareString + "[/share]"), item.Owner); } catch { core.Response.SendRawText("errorFetchingItem", ""); return; } core.Response.SendRawText("sharingForm", template.ToString()); return; } // Save the Share try { itemId = long.Parse((string)core.Http.Form["item"]); itemTypeId = long.Parse((string)core.Http.Form["type"]); } catch { core.Response.SendRawText("errorFetchingItem", ""); return; } itemKey = new ItemKey(itemId, itemTypeId); item = (IShareableItem)NumberedItem.Reflect(core, itemKey); if (item is IPermissibleItem) { IPermissibleItem pitem = (IPermissibleItem)item; if (!pitem.Access.IsPublic()) { core.Response.ShowMessage("cannotShare", "Cannot Share", "You can only share public items."); return; } } string message = (string)core.Http.Form["share-message"] + "\n\n" + core.Functions.Tldr("[share=\"[iurl=\"" + item.Uri + "\"]" + item.Owner.DisplayName + "[/iurl]\"]" + item.ShareString + "[/share]"); StatusMessage newStatus = StatusMessage.Create(core, core.Session.LoggedInMember, message); AccessControlLists acl = new AccessControlLists(core, newStatus); acl.SaveNewItemPermissions("share-permissions"); core.Search.Index(newStatus); ApplicationEntry ae = core.GetApplication("Profile"); ae.PublishToFeed(core, core.Session.LoggedInMember, newStatus, Functions.SingleLine(core.Bbcode.Flatten(newStatus.Message))); Share.ShareItem(core, itemKey); if (Request.Form["ajax"] == "true") { Template template = new Template("pane.statusmessage.html"); template.Medium = core.Template.Medium; template.SetProse(core.Prose); VariableCollection statusMessageVariableCollection = template.CreateChild("status_messages"); core.Display.ParseBbcode(statusMessageVariableCollection, "STATUS_MESSAGE", core.Bbcode.FromStatusCode(newStatus.Message), core.Session.LoggedInMember, true, string.Empty, string.Empty); statusMessageVariableCollection.Parse("STATUS_UPDATED", core.Tz.DateTimeToString(newStatus.GetTime(core.Tz))); statusMessageVariableCollection.Parse("ID", newStatus.Id.ToString()); statusMessageVariableCollection.Parse("TYPE_ID", newStatus.ItemKey.TypeId.ToString()); statusMessageVariableCollection.Parse("USERNAME", newStatus.Poster.DisplayName); statusMessageVariableCollection.Parse("U_PROFILE", newStatus.Poster.ProfileUri); statusMessageVariableCollection.Parse("U_QUOTE", string.Empty /*core.Hyperlink.BuildCommentQuoteUri(newStatus.Id)*/); statusMessageVariableCollection.Parse("U_REPORT", string.Empty /*core.Hyperlink.BuildCommentReportUri(newStatus.Id)*/); statusMessageVariableCollection.Parse("U_DELETE", string.Empty /*core.Hyperlink.BuildCommentDeleteUri(newStatus.Id)*/); statusMessageVariableCollection.Parse("U_PERMISSIONS", newStatus.Access.AclUri); statusMessageVariableCollection.Parse("USER_TILE", newStatus.Poster.Tile); statusMessageVariableCollection.Parse("USER_ICON", newStatus.Poster.Icon); statusMessageVariableCollection.Parse("URI", newStatus.Uri); statusMessageVariableCollection.Parse("IS_OWNER", "TRUE"); if (newStatus.Access.IsPublic()) { statusMessageVariableCollection.Parse("IS_PUBLIC", "TRUE"); statusMessageVariableCollection.Parse("SHAREABLE", "TRUE"); statusMessageVariableCollection.Parse("U_SHARE", newStatus.ShareUri); } Dictionary<string, string> returnValues = new Dictionary<string, string>(StringComparer.Ordinal); returnValues.Add("update", item.OwnerKey.Equals(newStatus.Owner.ItemKey) ? "true" : "false"); returnValues.Add("message", message); returnValues.Add("template", template.ToString()); core.Response.SendDictionary("statusPosted", returnValues); return; } else { string redirect = Request["redirect"]; if (!string.IsNullOrEmpty(redirect)) { template.Parse("REDIRECT_URI", redirect); } core.Display.ShowMessage("Shared", "You have shared this item to your status feed."); } }
/// <summary> /// /// </summary> /// <param name="core"></param> public static void Upload(Core core) { Primitive owner = core.Session.LoggedInMember; long galleryId = core.Functions.FormLong("gallery-id", 0); string title = core.Http.Form["title"]; string galleryTitle = core.Http.Form["gallery-title"]; string description = core.Http.Form["description"]; bool publishToFeed = (core.Http.Form["publish-feed"] != null); bool highQualitySave = (core.Http.Form["high-quality"] != null); bool submittedTitle = true; if (string.IsNullOrEmpty(galleryTitle)) { submittedTitle = false; galleryTitle = "Uploaded " + core.Tz.Now.ToString("MMMM dd, yyyy"); } bool newGallery = core.Http.Form["album"] == "create"; int filesUploaded = 0; for (int i = 0; i < core.Http.Files.Count; i++) { if (core.Http.Files.GetKey(i).StartsWith("photo-file", StringComparison.Ordinal)) { if (core.Http.Files[i] == null || core.Http.Files[i].ContentLength == 0) { // Ignore error, continue continue; } filesUploaded++; } } if (filesUploaded == 0) { //core.Ajax.ShowMessage(core.IsAjax, "error", "No files selected", "You need to select some files to upload"); return; } try { Gallery parent = null; if (newGallery) { Gallery grandParent = null; if (!submittedTitle) { string grandParentSlug = "photos-from-posts"; try { grandParent = new Gallery(core, owner, grandParentSlug); } catch (InvalidGalleryException) { Gallery root = new Gallery(core, owner); grandParent = Gallery.Create(core, owner, root, "Photos From Posts", ref grandParentSlug, "All my unsorted uploads"); } } else { grandParent = new Gallery(core, owner); } string gallerySlug = string.Empty; if (!submittedTitle) { gallerySlug = "photos-" + UnixTime.UnixTimeStamp().ToString(); } else { gallerySlug = Gallery.GetSlugFromTitle(galleryTitle, ""); } try { parent = Gallery.Create(core, owner, grandParent, galleryTitle, ref gallerySlug, string.Empty); } catch (GallerySlugNotUniqueException) { core.Response.ShowMessage("error", "Gallery not unique", "Please give a different name to the gallery"); } AccessControlLists acl = new AccessControlLists(core, parent); acl.SaveNewItemPermissions(); } else { parent = new Gallery(core, owner, galleryId); } string slug = string.Empty; try { for (int i = 0; i < core.Http.Files.Count; i++) { if (!core.Http.Files.GetKey(i).StartsWith("photo-file", StringComparison.Ordinal)) { continue; } slug = core.Http.Files[i].FileName; MemoryStream stream = new MemoryStream(); core.Http.Files[i].InputStream.CopyTo(stream); core.Db.BeginTransaction(); GalleryItem newGalleryItem = GalleryItem.Create(core, owner, parent, title, ref slug, core.Http.Files[i].FileName, core.Http.Files[i].ContentType, (ulong)core.Http.Files[i].ContentLength, description, core.Functions.GetLicenseId(), core.Functions.GetClassification(), stream, highQualitySave, core.Session.ApplicationId /*, width, height*/); stream.Close(); if (publishToFeed && i < 3) { core.CallingApplication.PublishToFeed(core, core.Session.LoggedInMember, parent, newGalleryItem, Functions.SingleLine(core.Bbcode.Flatten(newGalleryItem.ItemAbstract))); } } } catch (GalleryItemTooLargeException) { core.Db.RollBackTransaction(); core.Response.ShowMessage("error", "Photo too big", "The photo you have attempted to upload is too big, you can upload photos up to " + Functions.BytesToString(core.Settings.MaxFileSize) + " in size."); return; } catch (GalleryQuotaExceededException) { core.Db.RollBackTransaction(); core.Response.ShowMessage("error", "Not Enough Quota", "You do not have enough quota to upload this photo. Try resizing the image before uploading or deleting images you no-longer need. Smaller images use less quota."); return; } catch (InvalidGalleryItemTypeException) { core.Db.RollBackTransaction(); core.Response.ShowMessage("error", "Invalid image uploaded", "You have tried to upload a file type that is not a picture. You are allowed to upload PNG and JPEG images."); return; } catch (InvalidGalleryFileNameException) { core.Db.RollBackTransaction(); core.Response.ShowMessage("error", "Submission failed", "Submission failed, try uploading with a different file name."); return; } } catch (InvalidGalleryException) { } }