public static Comment Post(Core core) { long itemId = core.Functions.FormLong("item_id", 0); long itemTypeId = core.Functions.FormLong("item_type_id", 0); string comment = core.Http.Form["comment"]; ItemKey itemKey = new ItemKey(itemId, itemTypeId); ItemType itemType = new ItemType(core, itemTypeId); NumberedItem item = null; ICommentableItem thisItem = null; item = NumberedItem.Reflect(core, new ItemKey(itemId, itemTypeId)); if (item is ICommentableItem) { thisItem = (ICommentableItem)item; IPermissibleItem pItem = null; if (item is IPermissibleItem) { pItem = (IPermissibleItem)item; } else if (item is IPermissibleSubItem) { pItem = ((IPermissibleSubItem)item).PermissiveParent; } else { pItem = thisItem.Owner; } if (!pItem.Access.Can("COMMENT")) { throw new PermissionDeniedException("UNAUTHORISED_TO_COMMENT"); } } else { throw new InvalidItemException(); } Comment commentObject = null; commentObject = Comment.Create(core, itemKey, comment); if (item != null) { if (item is IActionableItem || item is IActionableSubItem) { // Touch Feed } else { ApplicationEntry ae = core.GetApplication(itemType.ApplicationId); ae.PublishToFeed(core, core.Session.LoggedInMember, commentObject, item, Functions.SingleLine(core.Bbcode.Flatten(commentObject.Body))); } ICommentableItem citem = (ICommentableItem)item; citem.CommentPosted(new CommentPostedEventArgs(commentObject, core.Session.LoggedInMember, new ItemKey(itemId, itemTypeId))); try { Subscription.SubscribeToItem(core, itemKey); } catch (AlreadySubscribedException) { // not a problem } return commentObject; } return null; }
protected void Page_Load(object sender, EventArgs e) { bool isAjax = false; if (Request["ajax"] == "true") { isAjax = true; } if (!core.Session.SignedIn) { core.Response.ShowMessage("notSignedIn", "Subscription Error", "You must be logged in to subscribe."); } string mode = core.Http["mode"]; long itemId = core.Functions.RequestLong("item", 0); long itemTypeId = core.Functions.RequestLong("type", 0); ItemKey itemKey = null; try { itemKey = new ItemKey(itemId, itemTypeId); } catch { core.Response.ShowMessage("invalidItem", "Invalid Item", "The item you have attempted to subscribe to is invalid."); return; } try { // This isn't the most elegant fix, but it works ApplicationEntry ae = null; if (core.IsPrimitiveType(itemTypeId)) { ae = core.GetApplication("GuestBook"); } else { ItemType itemType = new ItemType(core, itemTypeId); if (itemType.ApplicationId == 0) { ae = core.GetApplication("GuestBook"); } else { ae = new ApplicationEntry(core, itemType.ApplicationId); } } BoxSocial.Internals.Application.LoadApplication(core, AppPrimitives.Any, ae); } catch (InvalidItemTypeException) { core.Response.ShowMessage("invalidItem", "Invalid Item", "The item you have attempted to subscribe to is invalid."); return; } catch (InvalidApplicationException) { core.Response.ShowMessage("invalidItem", "Invalid Item", "The item you have attempted to rate is invalid."); return; } bool success = false; try { switch (mode) { case "subscribe": success = Subscription.SubscribeToItem(core, itemKey); Core.ItemSubscribed(itemKey, loggedInMember); if (success) { if (isAjax) { core.Response.SendStatus("subscriptionAccepted"); } else { core.Display.ShowMessage("Subscribed", "You have successfully subscribed."); } } else { core.Response.ShowMessage("error", "Error", "Subscription unsuccessful."); } break; case "unsubscribe": success = Subscription.UnsubscribeFromItem(core, itemKey); Core.ItemUnsubscribed(itemKey, loggedInMember); if (success) { if (isAjax) { core.Response.SendStatus("unsubscriptionAccepted"); } else { core.Display.ShowMessage("Unsubscribed", "You have successfully unsubscribed."); } } else { core.Response.ShowMessage("error", "Error", "Unsubscription unsuccessful."); } break; } } catch (InvalidItemException) { core.Response.ShowMessage("invalidItem", "Invalid Item", "The item you have attempted to subscribe to is invalid."); } catch (InvalidSubscriptionException) { core.Response.ShowMessage("invalidSubscription", "Invalid Subscription", "The subscription is not valid."); } catch (AlreadySubscribedException) { core.Response.ShowMessage("alreadySubscribed", "Already Subscribed", "You have already subscribe to this item, you cannot subscribe to it again"); } }
protected void Page_Load(object sender, EventArgs e) { string comment; long itemId; long itemTypeId; ItemKey itemKey = null; ICommentableItem thisItem = null; long commentId = -1; bool isAjax = false; ApplicationEntry ae = null; if (Request["ajax"] == "true") { isAjax = true; } string mode = Request.QueryString["mode"]; if (mode == "quote") { template.SetTemplate("posting.comment.html"); try { itemId = long.Parse((string)Request.QueryString["item"]); } catch { core.Response.SendRawText("errorFetchingComment", ""); return; } DataTable commentsTable = db.Query(string.Format("SELECT ui.user_name, c.comment_text FROM comments c LEFT JOIN user_info ui ON c.user_id = ui.user_id WHERE comment_id = {0}", itemId)); if (commentsTable.Rows.Count == 1) { string quotedComment = string.Format("\n\n[quote=\"{0}\"]{1}[/quote]", (string)commentsTable.Rows[0]["user_name"], (string)commentsTable.Rows[0]["comment_text"]); template.Parse("COMMENT_TEXT", quotedComment); } else { core.Response.SendRawText("errorFetchingComment", ""); } return; } if (mode == "fetch") { try { itemId = long.Parse((string)Request.QueryString["item"]); } catch { core.Response.SendRawText("errorFetchingComment", ""); return; } DataTable commentsTable = db.Query(string.Format("SELECT ui.user_name, c.comment_text FROM comments c LEFT JOIN user_info ui ON c.user_id = ui.user_id WHERE comment_id = {0}", itemId)); if (commentsTable.Rows.Count == 1) { core.Response.SendRawText("commentFetched", (string.Format("\n\n[quote=\"{0}\"]{1}[/quote]", (string)commentsTable.Rows[0]["user_name"], (string)commentsTable.Rows[0]["comment_text"]))); } else { core.Response.SendRawText("errorFetchingComment", ""); } return; } if (mode == "load") { try { itemId = long.Parse((string)core.Http.Query["item"]); itemTypeId = long.Parse((string)core.Http.Query["type"]); } catch { core.Response.SendRawText("errorFetchingComment", ""); return; } try { // This isn't the most elegant fix, but it works if (core.IsPrimitiveType(itemTypeId)) { ae = core.GetApplication("GuestBook"); } else { ItemType itemType = new ItemType(core, itemTypeId); if (itemType.ApplicationId == 0) { ae = core.GetApplication("GuestBook"); } else { ae = new ApplicationEntry(core, itemType.ApplicationId); } } BoxSocial.Internals.Application.LoadApplication(core, AppPrimitives.Any, ae); } catch (InvalidApplicationException) { core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comments you have attempted to fetch are invalid. (0x01)"); return; } try { thisItem = (ICommentableItem)NumberedItem.Reflect(core, new ItemKey(itemId, itemTypeId)); } catch (Exception ex) { // Only catch genuine InvalidItemException throws if ((ex.GetType() == typeof(TargetInvocationException) && ex.InnerException.GetType().IsSubclassOf(typeof(InvalidItemException))) || ex.GetType().IsSubclassOf(typeof(InvalidItemException))) { core.Response.ShowMessage("invalidItem", "Item no longer exists", "Cannot load the comments as the item no longer exists."); } throw ex; } Template template = new Template("pane.comments.html"); template.Medium = core.Template.Medium; template.SetProse(core.Prose); template.Parse("U_SIGNIN", Core.Hyperlink.BuildLoginUri()); if (thisItem is IPermissibleItem) { if (!((IPermissibleItem)thisItem).Access.Can("VIEW")) { core.Response.ShowMessage("accessDenied", "Access Denied", "The you do not have access to these comments"); return; } if (((IPermissibleItem)thisItem).Access.Can("COMMENT")) { template.Parse("CAN_COMMENT", "TRUE"); } } if (thisItem is IPermissibleSubItem) { if (!((IPermissibleSubItem)thisItem).PermissiveParent.Access.Can("VIEW")) { core.Response.ShowMessage("accessDenied", "Access Denied", "The you do not have access to these comments"); return; } if (((IPermissibleSubItem)thisItem).PermissiveParent.Access.Can("COMMENT")) { template.Parse("CAN_COMMENT", "TRUE"); } } if (thisItem is ICommentableItem) { core.Display.DisplayComments(template, ((ICommentableItem)thisItem).Owner, 1, (ICommentableItem)thisItem); //List<Comment> comments = Comment.GetComments(core, new ItemKey(itemId, itemTypeId), SortOrder.Ascending, 1, 10, null); core.Response.SendRawText("fetchSuccess", template.ToString()); } else { core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comments you have attempted to fetch are invalid. (0x07)"); } return; } if (mode == "report") { try { itemId = long.Parse((string)Request.QueryString["item"]); } catch { core.Response.ShowMessage("errorReportingComment", "Error", "The comment you have reported is invalid."); return; } // only logged in members can report comment spam if (session.IsLoggedIn) { // has the user reported the comment before? DataTable reportsTable = db.Query(string.Format("SELECT report_id FROM spam_reports WHERE comment_id = {0} AND user_id = {1};", itemId, loggedInMember.UserId)); if (reportsTable.Rows.Count == 0) { db.BeginTransaction(); db.UpdateQuery(string.Format("UPDATE comments SET comment_spam_score = comment_spam_score + 2 WHERE comment_id = {0}", itemId)); // add a log entry that the user reported this comment db.UpdateQuery(string.Format("INSERT INTO spam_reports (comment_id, user_id, report_time_ut) VALUES ({0}, {1}, UNIX_TIMESTAMP());", itemId, loggedInMember.UserId)); } else { core.Response.ShowMessage("alreadyReported", "Already Reported", "You have already reported this comment as SPAM."); } } core.Response.ShowMessage("commentReported", "Reported Comment", "You have successfully reported a comment."); return; } if (mode == "delete") { // select the comment try { Comment.Delete(core); } catch (InvalidCommentException) { core.Response.ShowMessage("errorDeletingComment", "Error", "An error was encountered while deleting the comment, the comment has not been deleted."); } catch (PermissionDeniedException) { core.Response.ShowMessage("permissionDenied", "Permission Denied", "You do not have the permissions to delete this comment."); } if (core.ResponseFormat == ResponseFormats.Xml) { core.Response.SendRawText("commentDeleted", "You have successfully deleted the comment."); } else { core.Response.ShowMessage("commentDeleted", "Comment Deleted", "You have successfully deleted the comment"); } return; } // else we post a comment { try { comment = (string)Request.Form["comment"]; itemId = core.Functions.RequestLong("item_id", 0); itemTypeId = core.Functions.RequestLong("item_type_id", 0); itemKey = new ItemKey(itemId, itemTypeId); } catch { core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comment you have attempted to post is invalid. (0x02)"); return; } if (itemId == 0 || itemTypeId == 0) { core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comment you have attempted to post is invalid. (0x08)"); return; } try { // This isn't the most elegant fix, but it works if (core.IsPrimitiveType(itemTypeId)) { ae = core.GetApplication("GuestBook"); } else { ItemType itemType = new ItemType(core, itemTypeId); if (itemType.ApplicationId == 0) { ae = core.GetApplication("GuestBook"); } else { ae = new ApplicationEntry(core, itemType.ApplicationId); } } BoxSocial.Internals.Application.LoadApplication(core, AppPrimitives.Any, ae); } catch (InvalidApplicationException) { core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comment you have attempted to post is invalid. (0x03)"); return; } /* save comment in the database */ NumberedItem item = null; try { item = NumberedItem.Reflect(core, new ItemKey(itemId, itemTypeId)); if (item is ICommentableItem) { thisItem = (ICommentableItem)item; IPermissibleItem pItem = null; if (item is IPermissibleItem) { pItem = (IPermissibleItem)item; } else if (item is IPermissibleSubItem) { pItem = ((IPermissibleSubItem)item).PermissiveParent; } else { pItem = thisItem.Owner; } if (!pItem.Access.Can("COMMENT")) { core.Response.ShowMessage("notLoggedIn", "Permission Denied", "You do not have the permissions to post a comment to this item."); } } else { core.Response.ShowMessage("invalidComment", "Invalid Item", "The comment you have attempted to post is invalid. (0x07)"); } } catch (InvalidItemException) { core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comment you have attempted to post is invalid. (0x04)"); } Comment commentObject = null; try { commentObject = Comment.Create(Core, itemKey, comment); commentId = commentObject.CommentId; if (item != null) { if (item is IActionableItem || item is IActionableSubItem) { //ae.TouchFeed(core.Session.LoggedInMember, item); } else { ae.PublishToFeed(core, core.Session.LoggedInMember, commentObject, item, Functions.SingleLine(core.Bbcode.Flatten(commentObject.Body))); } ICommentableItem citem = (ICommentableItem)item; citem.CommentPosted(new CommentPostedEventArgs(commentObject, core.Session.LoggedInMember, new ItemKey(itemId, itemTypeId))); } Comment.Commented(core, itemKey); // Notify everyone who comments on the item by default, track this so people can unsubscribe later //NotificationSubscription.Create(core, loggedInMember, itemKey); try { Subscription.SubscribeToItem(core, itemKey); } catch (AlreadySubscribedException) { // not a problem } } catch (NotLoggedInException) { core.Response.ShowMessage("notLoggedIn", "Not Logged In", "You must be logged in to post a comment."); } catch (CommentFloodException) { core.Response.ShowMessage("rejectedByFloodControl", "Posting Too Fast", "You are posting too fast. Please wait a minute and try again."); } catch (CommentTooLongException) { core.Response.ShowMessage("commentTooLong", "Comment Too Long", "The comment you have attempted to post is too long, maximum size is 511 characters."); } catch (CommentTooShortException) { core.Response.ShowMessage("commentTooShort", "Comment Too Short", "The comment you have attempted to post is too short, must be longer than two characters."); } catch (InvalidCommentException) { core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comment you have attempted to post is invalid. (0x05)"); } catch (Exception ex) { core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comment you have attempted to post is invalid. (0x06) " + ex.ToString()); } if (core.ResponseFormat == ResponseFormats.Xml) { Template ct = new Template(Server.MapPath("./templates"), "pane.comment.html"); template.Medium = core.Template.Medium; ct.SetProse(core.Prose); if (core.Session.IsLoggedIn && loggedInMember != null) { ct.Parse("LOGGED_IN", "TRUE"); ct.Parse("USER_DISPLAY_NAME", core.Session.LoggedInMember.DisplayName); ct.Parse("USER_TILE", core.Session.LoggedInMember.Tile); ct.Parse("USER_ICON", core.Session.LoggedInMember.Icon); } if (item != null) { template.Parse("ITEM_ID", item.Id.ToString()); template.Parse("ITEM_TYPE", item.ItemKey.TypeId.ToString()); } VariableCollection commentsVariableCollection = ct.CreateChild("comment-list"); //commentsVariableCollection.ParseRaw("COMMENT", Bbcode.Parse(HttpUtility.HtmlEncode(comment), core.session.LoggedInMember)); core.Display.ParseBbcode(commentsVariableCollection, "COMMENT", comment); // TODO: finish comments this commentsVariableCollection.Parse("ID", commentId.ToString()); commentsVariableCollection.Parse("TYPE_ID", ItemKey.GetTypeId(core, typeof(Comment))); commentsVariableCollection.Parse("USERNAME", loggedInMember.DisplayName); commentsVariableCollection.Parse("USER_ID", loggedInMember.Id.ToString()); commentsVariableCollection.Parse("U_PROFILE", loggedInMember.ProfileUri); commentsVariableCollection.Parse("U_QUOTE", core.Hyperlink.BuildCommentQuoteUri(commentId)); commentsVariableCollection.Parse("U_REPORT", core.Hyperlink.BuildCommentReportUri(commentId)); commentsVariableCollection.Parse("U_DELETE", core.Hyperlink.BuildCommentDeleteUri(commentId)); commentsVariableCollection.Parse("TIME", tz.DateTimeToString(tz.Now)); commentsVariableCollection.Parse("USER_TILE", loggedInMember.Tile); commentsVariableCollection.Parse("USER_ICON", loggedInMember.Icon); try { if (core.Session.IsLoggedIn) { if (thisItem.Owner.CanModerateComments(loggedInMember)) { commentsVariableCollection.Parse("MODERATE", "TRUE"); } if (thisItem.Owner.IsItemOwner(loggedInMember)) { commentsVariableCollection.Parse("OWNER", "TRUE"); commentsVariableCollection.Parse("NORMAL", "FALSE"); } else { commentsVariableCollection.Parse("OWNER", "FALSE"); commentsVariableCollection.Parse("NORMAL", "TRUE"); } } else { commentsVariableCollection.Parse("OWNER", "FALSE"); commentsVariableCollection.Parse("NORMAL", "TRUE"); } } catch (Exception ex) { commentsVariableCollection.Parse("NORMAL", "FALSE"); } core.Response.SendRawText("comment", ct.ToString()); if (db != null) { db.CloseConnection(); } Response.End(); return; } else { string redirect = Request["redirect"]; if (!string.IsNullOrEmpty(redirect)) { template.Parse("REDIRECT_URI", redirect); } core.Display.ShowMessage("Comment Posted", "Your comment has been successfully posted."); } } }
protected void Page_Load(object sender, EventArgs e) { bool isAjax = false; if (Request["ajax"] == "true") { isAjax = true; } int rating = core.Functions.RequestInt("rating", 0); long itemId = core.Functions.RequestLong("item", 0); long itemTypeId = core.Functions.RequestLong("type", 0); ItemKey itemKey = null; try { itemKey = new ItemKey(itemId, itemTypeId); } catch { core.Response.ShowMessage("invalidItem", "Invalid Item", "The item you have attempted to rate is invalid."); return; } try { // This isn't the most elegant fix, but it works ApplicationEntry ae = null; if (core.IsPrimitiveType(itemTypeId)) { ae = core.GetApplication("GuestBook"); } else { ItemType itemType = new ItemType(core, itemTypeId); if (itemType.ApplicationId == 0) { ae = core.GetApplication("GuestBook"); } else { ae = new ApplicationEntry(core, itemType.ApplicationId); } } BoxSocial.Internals.Application.LoadApplication(core, AppPrimitives.Any, ae); } catch (InvalidItemTypeException) { core.Response.ShowMessage("invalidItem", "Invalid Item", "The item you have attempted to rate is invalid."); return; } catch (InvalidApplicationException) { core.Response.ShowMessage("invalidItem", "Invalid Item", "The item you have attempted to rate is invalid."); return; } try { Rating.Vote(core, itemKey, rating); core.Response.SendStatus("voteAccepted"); } catch (InvalidItemException ex) { core.Response.ShowMessage("invalidItem", "Invalid Item", "The item you have attempted to rate is invalid."); } catch (InvalidRatingException) { core.Response.ShowMessage("invalidRating", "Invalid Rating", "The rating you have attempted to give for this item is invalid."); } catch (AlreadyRatedException) { core.Response.ShowMessage("alreadyVoted", "Already Voted", "You have already rated this item, you cannot rate it again"); } //else //{ // /* TODO permissions */ // /* after 7 days release the IP for dynamics ip fairness */ // DataTable ratingsTable = db.Query(string.Format("SELECT user_id FROM ratings WHERE rate_item_id = {0} AND rate_item_type = '{1}' AND (user_id = {2} OR (rate_ip = '{3}' AND rate_time_ut > UNIX_TIMESTAMP() - (60 * 60 * 24 * 7)))", // itemId, Mysql.Escape(itemType), loggedInMember.UserId, session.IPAddress.ToString())); // if (ratingsTable.Rows.Count > 0) // { // //Response.Write("alreadyVoted"); // Ajax.ShowMessage(true, "alreadyVoted", "Already Voted", "You have already rated this item, you cannot rate it again"); // return; // } // else // { // /* Register a vote */ // /* start transaction */ // InsertQuery iQuery = new InsertQuery("ratings"); // iQuery.AddField("rate_item_id", itemId); // iQuery.AddField("rate_item_type", itemType); // iQuery.AddField("user_id", loggedInMember.UserId); // iQuery.AddField("rate_time_ut", UnixTime.UnixTimeStamp()); // iQuery.AddField("rate_rating", rating); // iQuery.AddField("rate_ip", session.IPAddress.ToString()); // db.UpdateQuery(iQuery, true); // switch (itemType) // { // case "PHOTO": // db.UpdateQuery(string.Format("UPDATE gallery_items SET gallery_item_rating = (gallery_item_rating * gallery_item_ratings + {0}) / (gallery_item_ratings + 1), gallery_item_ratings = gallery_item_ratings + 1 WHERE gallery_item_id = {1}", // rating, itemId), false); // break; // } // Ajax.SendStatus("voteAccepted"); // return; // } //} }
public static AccessControlPermission Create(Core core, ItemType type, string permissionName, string permissionDescription, PermissionTypes permissionType) { return Create(core, type.TypeId, permissionName, permissionDescription, permissionType); }
private static ItemType updateItemTypeCache(Core core, long typeId) { ItemType typeItem = null; SelectQuery query = ItemType.GetSelectQueryStub(core, typeof(ItemType)); query.AddCondition("type_id", typeId); System.Data.Common.DbDataReader typesReader = core.Db.ReaderQuery(query); if (typesReader.HasRows) { typesReader.Read(); typeItem = new ItemType(core, typesReader); HibernateItem typeItemHibernate = new HibernateItem(typesReader); core.Cache.SetCached(string.Format("itemTypes[{0}]", typeItem.Id), typeItemHibernate, new TimeSpan(4, 0, 0), CacheItemPriority.NotRemovable); core.Cache.SetCached(string.Format("itemTypeIds[{0}]", typeItem.TypeNamespace), typeItem.Id, new TimeSpan(4, 0, 0), CacheItemPriority.NotRemovable); core.Cache.SetCached(string.Format("itemApplicationIds[{0}]", typeItem.Id), typeItem.ApplicationId, new TimeSpan(4, 0, 0), CacheItemPriority.NotRemovable); } typesReader.Close(); typesReader.Dispose(); return typeItem; }
public static Dictionary<long, string> populateItemTypeCache(Core core) { if (core == null) { throw new NullCoreException(); } Dictionary<long, string> primitiveTypes = new Dictionary<long, string>(); object o = core.Cache.GetCached("itemPrimitiveTypes"); if (o == null) { if (core.Cache != null) { SelectQuery query = ItemType.GetSelectQueryStub(core, typeof(ItemType)); System.Data.Common.DbDataReader typesReader = null; try { typesReader = core.Db.ReaderQuery(query); } catch { if (typesReader != null) { typesReader.Close(); typesReader.Dispose(); } return primitiveTypes; } while (typesReader.Read()) { ItemType typeItem = new ItemType(core, typesReader); HibernateItem typeItemHibernate = new HibernateItem(typesReader); core.Cache.SetCached(string.Format("itemTypes[{0}]", typeItem.Id), typeItemHibernate, new TimeSpan(4, 0, 0), CacheItemPriority.NotRemovable); core.Cache.SetCached(string.Format("itemTypeIds[{0}]", typeItem.TypeNamespace), typeItem.Id, new TimeSpan(4, 0, 0), CacheItemPriority.NotRemovable); core.Cache.SetCached(string.Format("itemApplicationIds[{0}]", typeItem.Id), typeItem.ApplicationId, new TimeSpan(4, 0, 0), CacheItemPriority.NotRemovable); if (typeItem.IsPrimitive) { primitiveTypes.Add(typeItem.Id, typeItem.TypeNamespace); } } core.Cache.SetCached("itemPrimitiveTypes", primitiveTypes, new TimeSpan(4, 0, 0), CacheItemPriority.High); typesReader.Close(); typesReader.Dispose(); } } return primitiveTypes; }
protected void Page_Load(object sender, EventArgs e) { Server.ScriptTimeout = 1000; string assemblyName = core.Http.Query["app"]; string mode = core.Http.Query["mode"]; System.Web.Caching.Cache cache = Cache; cache.Remove("itemFields"); if (mode == "update") { if (core.LoggedInMemberId > 2 || core.LoggedInMemberId == 0) { core.Functions.Generate403(); return; } //List<Primitive> members = new List<Primitive>(); SelectQuery query = new SelectQuery("primitive_apps"); query.AddFields(ApplicationEntry.GetFieldsPrefixed(core, typeof(ApplicationEntry))); query.AddFields(PrimitiveApplicationInfo.GetFieldsPrefixed(core, typeof(PrimitiveApplicationInfo))); query.AddJoin(JoinTypes.Inner, new DataField("primitive_apps", "application_id"), new DataField("applications", "application_id")); query.AddCondition("applications.application_assembly_name", assemblyName); /*SelectQuery query = new SelectQuery("primitive_apps pa"); query.AddFields(ApplicationEntry.APPLICATION_FIELDS); query.AddFields(ApplicationEntry.USER_APPLICATION_FIELDS); query.AddFields(UserInfo.GetFieldsPrefixed(typeof(UserInfo))); query.AddJoin(JoinTypes.Inner, "applications ap", "ap.application_id", "pa.application_id"); query.AddJoin(JoinTypes.Inner, "user_info ui", "pa.item_id", "ui.user_id"); query.AddCondition("pa.item_type", "USER");*/ DataTable userInfoTable = db.Query(query); foreach (DataRow dr in userInfoTable.Rows) { dr["user_id"] = dr["item_id"]; ItemKey itemKey = new ItemKey((long)dr["item_id"], (long)dr["item_type_id"]); core.PrimitiveCache.LoadPrimitiveProfile(itemKey); } foreach (DataRow dr in userInfoTable.Rows) { ItemKey itemKey = new ItemKey((long)dr["item_id"], (long)dr["item_type_id"]); Primitive member = core.PrimitiveCache[itemKey]; //members.Add(member); ApplicationEntry ae = new ApplicationEntry(core, dr); ae.UpdateInstall(core, member); } core.Display.ShowMessage("Application Updated", "The application has been updated for all users."); } else { string assemblyPath = ""; bool isPrimitive = false; bool isInternals = false; switch (assemblyName) { case "Internals": assemblyPath = "BoxSocial.Internals.dll"; isInternals = true; isPrimitive = false; break; case "Groups": case "Networks": assemblyPath = string.Format("{0}.dll", assemblyName); isInternals = false; isPrimitive = true; break; default: assemblyPath = string.Format("applications/{0}.dll", assemblyName); isInternals = false; isPrimitive = false; break; } Assembly loadApplication = Assembly.LoadFrom(Path.Combine(core.Http.AssemblyPath, assemblyPath)); if (isInternals) { BoxSocial.Internals.Application.InstallTables(core, loadApplication); BoxSocial.Internals.Application.InstallTypes(core, loadApplication, 0); Type[] types = loadApplication.GetTypes(); foreach (Type t in types) { //if (t.GetInterfaces(). List<PermissionInfo> permissions = AccessControlLists.GetPermissionInfo(t); foreach (PermissionInfo pi in permissions) { try { ItemType it = new ItemType(core, t.FullName); try { AccessControlPermission acp = new AccessControlPermission(core, it.Id, pi.Key); } catch (InvalidAccessControlPermissionException) { AccessControlPermission.Create(core, it.Id, pi.Key, pi.Description, pi.PermissionType); } } catch (InvalidItemTypeException) { } } } core.Display.ShowMessage("Internals Updated", "Internals have been updated."); } else { Type[] types = loadApplication.GetTypes(); foreach (Type type in types) { if (type.IsSubclassOf(typeof(Application))) { BoxSocial.Internals.Application newApplication = System.Activator.CreateInstance(type, new object[] { core }) as Application; if (newApplication != null) { long updatedRaw = UnixTime.UnixTimeStamp(); long applicationId = 0; SelectQuery query1 = Item.GetSelectQueryStub(core, typeof(ApplicationEntry)); query1.AddCondition("application_assembly_name", assemblyName); /*DataTable applicationTable = db.Query(string.Format(@"SELECT {0} FROM applications ap WHERE application_assembly_name = '{1}'", ApplicationEntry.APPLICATION_FIELDS, Mysql.Escape(assemblyName)));*/ DataTable applicationTable = db.Query(query1); if (applicationTable.Rows.Count == 1) { ApplicationEntry updateApplication = new ApplicationEntry(core, applicationTable.Rows[0]); applicationId = updateApplication.ApplicationId; string updateKey = updateApplication.Key; if (updateApplication.CreatorId == core.LoggedInMemberId) { // // Save Icon // if (newApplication.Icon != null) { if (!Directory.Exists(Server.MapPath(string.Format(@".\images\{0}\", updateKey)))) { Directory.CreateDirectory(Server.MapPath(string.Format(@".\images\{0}\", updateKey))); } newApplication.Icon.Save(Server.MapPath(string.Format(@".\images\{0}\icon.png", updateKey)), System.Drawing.Imaging.ImageFormat.Png); } // // Save StyleSheet // if (!string.IsNullOrEmpty(newApplication.StyleSheet)) { if (!Directory.Exists(Server.MapPath(@".\styles\applications\"))) { Directory.CreateDirectory(Server.MapPath(@".\styles\applications\")); } SaveTextFile(newApplication.StyleSheet, Server.MapPath(string.Format(@".\styles\applications\{0}.css", updateKey))); } // // Save JavaScript // if (!string.IsNullOrEmpty(newApplication.JavaScript)) { SaveTextFile(newApplication.JavaScript, Server.MapPath(string.Format(@".\scripts\{0}.js", updateKey))); } UpdateQuery query = new UpdateQuery("applications"); query.AddField("application_title", newApplication.Title); query.AddField("application_description", newApplication.Description); query.AddField("application_primitive", isPrimitive); query.AddField("application_primitives", (byte)newApplication.GetAppPrimitiveSupport()); query.AddField("application_comment", newApplication.UsesComments); query.AddField("application_rating", newApplication.UsesRatings); query.AddField("application_style", !string.IsNullOrEmpty(newApplication.StyleSheet)); query.AddField("application_script", !string.IsNullOrEmpty(newApplication.JavaScript)); query.AddField("application_icon", string.Format(@"/images/{0}/icon.png", updateKey)); query.AddCondition("application_assembly_name", assemblyName); db.BeginTransaction(); db.Query(query); } else { core.Functions.Generate403(); return; } } else { applicationId = db.UpdateQuery(string.Format(@"INSERT INTO applications (application_assembly_name, user_id, application_date_ut, application_title, application_description, application_primitive, application_primitives, application_comment, application_rating) VALUES ('{0}', {1}, {2}, '{3}', '{4}', {5}, {6}, {7}, {8});", Mysql.Escape(assemblyName), core.LoggedInMemberId, tz.GetUnixTimeStamp(tz.Now), Mysql.Escape(newApplication.Title), Mysql.Escape(newApplication.Description), isPrimitive, (byte)newApplication.GetAppPrimitiveSupport(), newApplication.UsesComments, newApplication.UsesRatings)); try { ApplicationEntry profileAe = new ApplicationEntry(core, "Profile"); db.UpdateQuery(string.Format(@"INSERT INTO primitive_apps (application_id, item_id, item_type_id) VALUES ({0}, {1}, '{2}');", profileAe.ApplicationId, applicationId, ItemKey.GetTypeId(core, typeof(ApplicationEntry)))); } catch { } try { ApplicationEntry guestbookAe = new ApplicationEntry(core, "GuestBook"); db.UpdateQuery(string.Format(@"INSERT INTO primitive_apps (application_id, item_id, item_type_id) VALUES ({0}, {1}, '{2}');", guestbookAe.ApplicationId, applicationId, ItemKey.GetTypeId(core, typeof(ApplicationEntry)))); } catch { } } if (applicationId > 0) { ApplicationInstallationInfo aii = newApplication.Install(); if (aii.ApplicationSlugs != null) { foreach (ApplicationSlugInfo slug in aii.ApplicationSlugs) { if (db.UpdateQuery(string.Format(@"UPDATE application_slugs SET slug_primitives = {0}, slug_updated_ut = {1} WHERE slug_stub = '{2}' AND slug_slug_ex = '{3}' AND application_id = {4}", (byte)slug.Primitives, updatedRaw, Mysql.Escape(slug.Stub), Mysql.Escape(slug.SlugEx), applicationId)) != 1) { /*db.UpdateQuery(string.Format(@"INSERT INTO application_slugs (slug_stub, slug_slug_ex, application_id, slug_primitives, slug_updated_ut) VALUES ('{0}', '{1}', {2}, {3}, {4});", Mysql.Escape(slug.Stub), Mysql.Escape(slug.SlugEx), applicationId, (byte)slug.Primitives, updatedRaw));*/ ApplicationSlug.Create(core, applicationId, slug); } } } if (aii.ApplicationModules != null) { foreach (ApplicationModule module in aii.ApplicationModules) { if (db.UpdateQuery(string.Format(@"UPDATE account_modules SET module_updated_ut = {0} WHERE module_module = '{1}' AND application_id = {2};", updatedRaw, Mysql.Escape(module.Slug), applicationId)) != 1) { db.UpdateQuery(string.Format(@"INSERT INTO account_modules (module_module, application_id, module_updated_ut) VALUES ('{0}', {1}, {2});", Mysql.Escape(module.Slug), applicationId, updatedRaw)); } } } if (aii.ApplicationCommentTypes != null) { foreach (ApplicationCommentType ct in aii.ApplicationCommentTypes) { if (db.UpdateQuery(string.Format(@"UPDATE comment_types SET type_updated_ut = {0} WHERE type_type = '{1}' AND application_id = {2};", updatedRaw, Mysql.Escape(ct.Type), applicationId)) != 1) { db.UpdateQuery(string.Format(@"INSERT INTO comment_types (type_type, application_id, type_updated_ut) VALUES ('{0}', {1}, {2});", Mysql.Escape(ct.Type), applicationId, updatedRaw)); } } } /*if (aii.ApplicationItemAccessPermissions != null) { foreach (ApplicationItemAccessPermissions iap in aii.ApplicationItemAccessPermissions) { try { AccessControlPermission acp = new AccessControlPermission(core, iap.TypeId, iap.PermissionName); } catch (InvalidAccessControlPermissionException) { AccessControlPermission.Create(core, iap.TypeId, iap.PermissionName); } } }*/ db.UpdateQuery(string.Format(@"DELETE FROM application_slugs WHERE application_id = {0} AND slug_updated_ut <> {1};", applicationId, updatedRaw)); db.UpdateQuery(string.Format(@"DELETE FROM account_modules WHERE application_id = {0} AND module_updated_ut <> {1};", applicationId, updatedRaw)); db.UpdateQuery(string.Format(@"DELETE FROM comment_types WHERE application_id = {0} AND type_updated_ut <> {1};", applicationId, updatedRaw)); BoxSocial.Internals.Application.InstallTypes(core, loadApplication, applicationId); BoxSocial.Internals.Application.InstallTables(core, loadApplication); //List<Type> types; foreach (Type t in types) { //if (t.FindInterfaces(TypeFilter.Equals, typeof(IPermissibleItem))) List<PermissionInfo> permissions = AccessControlLists.GetPermissionInfo(t); foreach (PermissionInfo pi in permissions) { try { ItemType it = new ItemType(core, t.FullName); try { AccessControlPermission acp = new AccessControlPermission(core, it.Id, pi.Key); } catch (InvalidAccessControlPermissionException) { AccessControlPermission.Create(core, it.Id, pi.Key, pi.Description, pi.PermissionType); } } catch (InvalidItemTypeException) { } } } } else { core.Display.ShowMessage("Error", "Error installing application"); EndResponse(); } } } } core.Display.ShowMessage("Application Installed", "The application has been installed."); } } EndResponse(); }