Example #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            lblError.Text = String.Empty;
            litAlert.Text = String.Empty;
            IsNext = true;
            try
            {
                var toSave = new List<ProfileAnswer>();
                var toDelete = new List<ProfileAnswer>();
                var modifiedQuestionIDs = new List<int>();
                var parentControls = new List<Control>();
                GetParentControls(topicsPanels[CurrentTopicName], parentControls);
                GetAnswers(topicsPanels[CurrentTopicName], parentControls, toSave, toDelete, modifiedQuestionIDs);

                if (modifiedQuestionIDs.Count > 0)
                {
                    var newEvent = new Event(CurrentUserSession.Username) { Type = Event.eType.FriendUpdatedProfile };
                    var friendUpdatedProfile = new UpdatedProfile { QuestionIDs = modifiedQuestionIDs };
                    newEvent.DetailsXML = Misc.ToXml(friendUpdatedProfile);
                    newEvent.Save();
                }

                foreach (ProfileAnswer answer in toSave)
                    answer.Save();

                foreach (ProfileAnswer answer in toDelete)
                    answer.Delete();

                if (CurrentUserSession != null)
                {
                    CurrentUserSession.HasProfile = true;
                    CurrentUserSession.HasApprovedProfile =
                        User.HasProfile(CurrentUserSession.Username, true);
                }

                string message = "<br><b>" +
                                Lang.Trans("Your profile has been updated successfully!") +
                                "</b><br><br>";

                message = message +
                          Lang.Trans("Profiles with photos get 20 times more Response!");

                ((PageBase)Page).StatusPageMessage = message;

                ((PageBase)Page).StatusPageLinkSkindId = "UploadPhotos";
                ((PageBase)Page).StatusPageLinkText = Lang.Trans("Upload photos now!");
                ((PageBase)Page).StatusPageLinkURL = "~/ManageProfile.aspx?sel=photos";
            }
            catch (AnswerRequiredException)
            {
            }
        }
        private void AddRemovedFriendFriendEvent(string username, string favoriteUsername)
        {
            Event newEvent = new Event(username);

            newEvent.Type = Event.eType.RemovedFriendFriend;
            RemovedFriendFriend newFriendFriend = new RemovedFriendFriend();
            newFriendFriend.Username = favoriteUsername;
            newEvent.DetailsXML = Misc.ToXml(newFriendFriend);

            newEvent.Save();

            if (Config.Users.NewEventNotification)
            {
                string[] usernames = Classes.User.FetchMutuallyFriends(username);

                string text = String.Format("{0} {1} are no longer friends".Translate(),
                                              "<b>" + username + "</b>", favoriteUsername);
                int imageID = 0;
                try
                {
                    imageID = Photo.GetPrimary(username).Id;
                }
                catch (NotFoundException)
                {
                    User user = null;
                    try
                    {
                        user = Classes.User.Load(username);
                        imageID = ImageHandler.GetPhotoIdByGender(user.Gender);
                    }
                    catch (NotFoundException) { return; }
                }
                string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);

                foreach (string friendUsername in usernames)
                {
                    if (favoriteUsername == friendUsername) continue;

                    Classes.User.SendOnlineEventNotification(username, friendUsername, text, thumbnailUrl,
                                                         UrlRewrite.CreateShowUserUrl(favoriteUsername));
                }
            }
        }
Example #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var toSave = new List<ProfileAnswer>();
                var toDelete = new List<ProfileAnswer>();
                List<int> modifiedQuestionIDs = new List<int>();
                List<Control> parentControls = new List<Control>();
                GetParentControls(plhProfile, parentControls);
                GetAnswers(plhProfile, parentControls, toSave, toDelete, modifiedQuestionIDs);

                if (modifiedQuestionIDs.Count > 0)
                {
                    var newEvent = new Event(CurrentUserSession.Username);

                    newEvent.Type = Event.eType.FriendUpdatedProfile;
                    var friendUpdatedProfile = new UpdatedProfile();
                    friendUpdatedProfile.QuestionIDs = modifiedQuestionIDs;
                    newEvent.DetailsXML = Misc.ToXml(friendUpdatedProfile);

                    newEvent.Save();
                }

                foreach (ProfileAnswer answer in toSave)
                {
                    answer.Save();
                }
                foreach (ProfileAnswer answer in toDelete)
                {
                    answer.Delete();
                }

                if (CurrentUserSession != null)
                {
                    CurrentUserSession.HasProfile = true;
                    CurrentUserSession.HasApprovedProfile =
                        User.HasProfile(CurrentUserSession.Username, true);
                }

                string message = Lang.Trans
                    ("<br><b>Your profile has been updated successfully!</b><br><br>");

                message = message +
                          Lang.Trans("Profiles with photos get 20 times more Response!");

                ((PageBase) Page).StatusPageMessage = message;

                ((PageBase) Page).StatusPageLinkSkindId = "UploadPhotos";
                ((PageBase) Page).StatusPageLinkText = Lang.Trans("Upload photos now!");
                ((PageBase) Page).StatusPageLinkURL = "~/ManageProfile.aspx?sel=photos";
                
                completedPctPanel.Width = new Unit(GetProfileCompletePercentage());

                Response.Redirect("ShowStatus.aspx");
            }
            catch (AnswerRequiredException)
            {
            }
        }
Example #4
0
        private void JoinGroup(string answer)
        {
            if (CurrentUserSession != null)
            {
                if (CurrentGroup != null)
                {
                    if (CurrentGroup.AccessLevel == Group.eAccessLevel.Private && !CurrentUserSession.IsAdmin())
                    {
                        ((PageBase) Page).StatusPageMessage =
                            Lang.Trans(
                                "This is a private group and only invited users are allowed to join. Please use 'Pending Invitations' link in the Group section to join.");

                        Response.Redirect("~/ShowStatus.aspx");
                        return;
                    }

                    string username = CurrentUserSession.Username;

                    if (GroupMember.IsBanned(username, GroupID))
                    {
                        ShowMessage(Misc.MessageType.Success, Lang.Trans("You are banned!"));
                        return;
                    }

                    int memberOf = GroupMember.Fetch(username).Length;
                    int maxGroupsPermitted = 0;// Config.Groups.MaxGroupsPerMember;
                    if (CurrentUserSession.BillingPlanOptions.MaxGroupsPerMember.Value > maxGroupsPermitted)
                        maxGroupsPermitted = CurrentUserSession.BillingPlanOptions.MaxGroupsPerMember.Value;
                    if (CurrentUserSession.Level != null && CurrentUserSession.Level.Restrictions.MaxGroupsPerMember > maxGroupsPermitted)
                        maxGroupsPermitted = CurrentUserSession.Level.Restrictions.MaxGroupsPerMember;

                    if (memberOf >= maxGroupsPermitted)
                    {
                        ShowMessage(Misc.MessageType.Error,
                                    String.Format(
                                        Lang.Trans(
                                            "You are already a member of {0} groups. Please leave one of them first."),
                                        maxGroupsPermitted));
                        return;
                    }

                    GroupMember groupMember = new GroupMember(CurrentGroup.ID, username);

                    groupMember.Active = CurrentGroup.AccessLevel == Group.eAccessLevel.Public
                                         || CurrentUserSession.IsAdmin()
                                             ? true
                                             : false;
                    groupMember.Type = CurrentUserSession.IsAdmin()
                                           ? GroupMember.eType.Admin
                                           : GroupMember.eType.Member;
                    groupMember.JoinAnswer = answer;
                    groupMember.Save();

                    if (groupMember.Active)
                    {
                        #region Add Event

                        Event newEvent = new Event(CurrentUserSession.Username);

                        newEvent.Type = Event.eType.FriendJoinedGroup;
                        FriendJoinedGroup friendJoinedGroup = new FriendJoinedGroup();
                        friendJoinedGroup.GroupID = CurrentGroup.ID;
                        newEvent.DetailsXML = Misc.ToXml(friendJoinedGroup);

                        newEvent.Save();

                        string[] usernames = User.FetchMutuallyFriends(CurrentUserSession.Username);

                        foreach (string friendUsername in usernames)
                        {
                            if (Config.Users.NewEventNotification)
                            {
                                string text =
                                    String.Format("Your friend {0} has joined the {1} group".Translate(),
                                                  "<b>" + CurrentUserSession.Username + "</b>",
                                                  Server.HtmlEncode(CurrentGroup.Name));
                                int imageID = 0;
                                try
                                {
                                    imageID = Photo.GetPrimary(CurrentUserSession.Username).Id;
                                }
                                catch (NotFoundException)
                                {
                                    imageID = ImageHandler.GetPhotoIdByGender(CurrentUserSession.Gender);
                                }
                                string thumbnailUrl =
                                    ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                                Classes.User.SendOnlineEventNotification(CurrentUserSession.Username, friendUsername,
                                                                         text, thumbnailUrl,
                                                                         UrlRewrite.CreateShowGroupUrl(
                                                                             CurrentGroup.ID.ToString()));
                            }
                        }

                        #endregion
                    }

                    CurrentGroupMember = groupMember;

                    if (groupMember.Active)
                    {
                        CurrentGroup.ActiveMembers++;
                        CurrentGroup.Save();
                    }

                    if (CurrentGroup.AccessLevel == Group.eAccessLevel.Moderated && !CurrentUserSession.IsAdmin())
                    {
                        ((PageBase) Page).StatusPageMessage = Lang.Trans("Your join request has been sent.");

                        Response.Redirect("~/ShowStatus.aspx");
                    }
                }

                mvViewGroup.SetActiveView(vGroupInfo);
                OnJoinPanelClose(new EventArgs());
            }
        }
        protected void lnkSave_Click(object sender, EventArgs e)
        {
            var photo = (Photo)Global.GetSessionState()["temp_photo"];

            if (photo == null)
            {
                if (ufPhoto.HasFile)
                {
                    btnUpload_Click(null, null);
                    photo = (Photo)Global.GetSessionState()["temp_photo"];
                }
                else
                {
                    lblError.Text = Lang.Trans("Please upload image first!");
                    return;
                }
            }

            if (Global.GetSessionState().ContainsKey("temp_photo_fileName"))
            {
                string filename = Global.GetSessionState()["temp_photo_fileName"] as string;
                photo.Image = Image.FromFile(filename);
            }
            
            if (photo.Id > 0)
            {
                try
                {
                    string cacheFileDir = Config.Directories.ImagesCacheDirectory + "/" + photo.Id % 10;
                    string cacheFileMask = String.Format("photo_{0}_*.jpg", photo.Id);
                    foreach (string file in Directory.GetFiles(cacheFileDir, cacheFileMask))
                    {
                        File.Delete(file);
                    }
                    cacheFileMask = String.Format("photoface_{0}_*.jpg", photo.Id);
                    foreach (string file in Directory.GetFiles(cacheFileDir, cacheFileMask))
                    {
                        File.Delete(file);
                    }
                }
                catch (Exception err)
                {
                    Global.Logger.LogError(err);
                }
            }

            photo.User = CurrentUserSession;
            photo.Name = Config.Misc.EnableBadWordsFilterProfile ? Parsers.ProcessBadWords(txtName.Text) : txtName.Text;
            photo.Description = Config.Misc.EnableBadWordsFilterProfile
                                    ? Parsers.ProcessBadWords(txtDescription.Text)
                                    : txtDescription.Text;
            photo.PrivatePhoto = chkPrivatePhoto.Checked;
            photo.Salute = true;

            bool isNewPhoto = photo.Id == 0;

            photo.Save(true);

            if (photo.Approved && !photo.PrivatePhoto && isNewPhoto)
            {
                #region Add NewFriendPhoto Event

                Event newEvent = new Event(CurrentUserSession.Username);

                newEvent.Type = Event.eType.NewFriendPhoto;
                NewFriendPhoto newFriendPhoto = new NewFriendPhoto();
                newFriendPhoto.PhotoID = photo.Id;
                newEvent.DetailsXML = Misc.ToXml(newFriendPhoto);

                newEvent.Save();

                string[] usernames = Classes.User.FetchMutuallyFriends(CurrentUserSession.Username);

                foreach (string friendUsername in usernames)
                {
                    if (Config.Users.NewEventNotification)
                    {
                        string text = String.Format("Your friend {0} has uploaded a new photo".Translate(),
                                                  "<b>" + photo.Username + "</b>");
                        string thumbnailUrl = ImageHandler.CreateImageUrl(photo.Id, 50, 50, false, true, true);
                        Classes.User.SendOnlineEventNotification(photo.Username, friendUsername,
                                                                 text, thumbnailUrl,
                                                                 UrlRewrite.CreateShowUserPhotosUrl(photo.Username));
                    }
                }

                #endregion
            }

            photo.Image.Dispose();

            try
            {
                if (Global.GetSessionState()["temp_photo_fileName"] != null)
                    File.Delete((string)Global.GetSessionState()["temp_photo_fileName"]);
            }
            catch (IOException)
            {
            }

            Global.GetSessionState()["temp_photo"] = null;
            Global.GetSessionState()["temp_photo_fileName"] = null;

            Response.Redirect("~/ManageProfile.aspx?sel=photos");
        }
        private void dgPendingVideos_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            if (!HasWriteAccess)
                return;

            VideoUpload videoUpload = VideoUpload.Load(Convert.ToInt32(e.CommandArgument));

            if (e.CommandName == "approve")
            {
                if (videoUpload != null)
                {
                    videoUpload.Approved = true;
                    videoUpload.Save();

                    if (!videoUpload.IsPrivate)
                    {
                        #region Add NewFriendVideoUpload Event

                        Event newEvent = new Event(videoUpload.Username);

                        newEvent.Type = Event.eType.NewFriendVideoUpload;
                        NewFriendVideoUpload newFriendVideoUpload = new NewFriendVideoUpload();
                        newFriendVideoUpload.VideoUploadID = videoUpload.Id;
                        newEvent.DetailsXML = Misc.ToXml(newFriendVideoUpload);

                        newEvent.Save();

                        string[] usernames = Classes.User.FetchMutuallyFriends(videoUpload.Username);

                        foreach (string friendUsername in usernames)
                        {
                            if (Config.Users.NewEventNotification)
                            {
                                string text = String.Format("Your friend {0} has uploaded a new video".TranslateA(),
                                                      "<b>" + videoUpload.Username + "</b>");
                                int imageID = 0;
                                try
                                {
                                    imageID = Photo.GetPrimary(videoUpload.Username).Id;
                                }
                                catch (NotFoundException)
                                {
                                    Classes.User user = null;
                                    try
                                    {
                                        user = Classes.User.Load(videoUpload.Username);
                                        imageID = ImageHandler.GetPhotoIdByGender(user.Gender);
                                    }
                                    catch (NotFoundException)
                                    {
                                        continue;
                                    }
                                }
                                string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                                Classes.User.SendOnlineEventNotification(videoUpload.Username, friendUsername,
                                                                         text, thumbnailUrl,
                                                                         UrlRewrite.CreateShowUserUrl(videoUpload.Username));
                            }
                        }

                        #endregion
                    }

                    Classes.User.AddScore(videoUpload.Username, Config.UserScores.ApprovedVideo, 
                        "ApprovedVideo");

                    #region e-mail notification

                    try
                    {
                        Classes.User user = Classes.User.Load(videoUpload.Username);

                        MiscTemplates.ApproveVideoMessage approveVideoMessageTemplate =
                            new MiscTemplates.ApproveVideoMessage(user.LanguageId);
                        Message.Send(Config.Users.SystemUsername, user.Username, approveVideoMessageTemplate.Message, 0);
                    }
                    catch (NotFoundException ex)
                    {
                        Log(ex);
                    }

                    #endregion

                    PopulateDataGrid();
                }
            }
            else if (e.CommandName == "reject")
            {
                if (videoUpload != null)
                {
                    VideoUpload.Delete(Convert.ToInt32(e.CommandArgument));

                    Classes.User.AddScore(videoUpload.Username, Config.UserScores.RejectedVideo,
                        "RejectedVideo");

                    #region e-mail notification

                    try
                    {
                        Classes.User user = Classes.User.Load(videoUpload.Username);

                        MiscTemplates.RejectVideoMessage rejectVideoMessageTemplate =
                            new MiscTemplates.RejectVideoMessage(user.LanguageId);
                        Message.Send(Config.Users.SystemUsername, user.Username, rejectVideoMessageTemplate.Message, 0);
                    }
                    catch (NotFoundException ex)
                    {
                        Log(ex);
                    }

                    #endregion

                    PopulateDataGrid();
                }
            }
        }
Example #7
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (mvVideo.GetActiveView() == vUploadVideo)
            {
                List<VideoUpload> videos = VideoUpload.Load(null, CurrentUserSession.Username, null, null, null, null);

                if (videos.Count >= CurrentUserSession.BillingPlanOptions.MaxVideoUploads.Value
                    && (CurrentUserSession.Level != null && videos.Count >= CurrentUserSession.Level.Restrictions.MaxVideoUploads))
                {
                    ((PageBase)Page).StatusPageMessage = Lang.Trans("You cannot upload more videos!");
                    Response.Redirect("ShowStatus.aspx");
                    return;
                }
            }

            if (!fileVideo.HasFile)
            {
                lblError.Text = Lang.Trans("Please select video file!");
                return;
            }

            string tempfile;

            if (!Misc.GetTempFileName(out tempfile))
                tempfile = Path.GetTempFileName();

            fileVideo.SaveAs(tempfile);

            var videoUpload = new VideoUpload(((PageBase)Page).CurrentUserSession.Username);
            if (CurrentUserSession != null)
            {
                if (CurrentUserSession.BillingPlanOptions.AutoApproveVideos.Value
                    || CurrentUserSession.Level != null && CurrentUserSession.Level.Restrictions.AutoApproveVideos)
                {
                    videoUpload.Approved = true;
                }
            }
            videoUpload.IsPrivate = cbPrivateVideo.Checked;
            videoUpload.Save(); // Save to get new ID

            if (videoUpload.Approved && !videoUpload.IsPrivate)
            {
                #region Add NewFriendVideoUpload Event

                Event newEvent = new Event(videoUpload.Username);

                newEvent.Type = Event.eType.NewFriendVideoUpload;
                NewFriendVideoUpload newFriendVideoUpload = new NewFriendVideoUpload();
                newFriendVideoUpload.VideoUploadID = videoUpload.Id;
                newEvent.DetailsXML = Misc.ToXml(newFriendVideoUpload);

                newEvent.Save();

                string[] usernames = Classes.User.FetchMutuallyFriends(videoUpload.Username);

                foreach (string friendUsername in usernames)
                {
                    if (Config.Users.NewEventNotification)
                    {
                        if (CurrentUserSession != null)
                        {
                            string text = String.Format("Your friend {0} has uploaded a new video".Translate(),
                                                          "<b>" + CurrentUserSession.Username + "</b>");
                            int imageID = 0;
                            try
                            {
                                imageID = Photo.GetPrimary(CurrentUserSession.Username).Id;
                            }
                            catch (NotFoundException)
                            {
                                imageID = ImageHandler.GetPhotoIdByGender(CurrentUserSession.Gender);
                            }
                            string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                            Classes.User.SendOnlineEventNotification(videoUpload.Username, friendUsername,
                                                                     text, thumbnailUrl,
                                                                     UrlRewrite.CreateShowUserUrl(videoUpload.Username));
                        }
                    }
                }

                #endregion
            }

            string userFilesPath = "~/UserFiles/" + ((PageBase)Page).CurrentUserSession.Username;
            string userFilesDir = Server.MapPath(userFilesPath);
            if (!Directory.Exists(userFilesDir))
            {
                Directory.CreateDirectory(userFilesDir);
            }

            File.Move(tempfile, userFilesDir + @"\video_" + videoUpload.Id + ".original");

            ThreadPool.QueueUserWorkItem(AsyncProcessVideo, videoUpload);

            ((PageBase)Page).StatusPageMessage = Lang.Trans("Your video has been queued for processing!");
            Response.Redirect("ShowStatus.aspx");
        }
Example #8
0
        protected void dlGroups_ItemCommand(object source, DataListCommandEventArgs e)
        {
            int groupID = Convert.ToInt32(e.CommandArgument);

            switch (e.CommandName)
            {
                case "Accept" :
                    GroupMember groupMember =
                        GroupMember.Fetch(groupID, CurrentUserSession.Username);

                    if (groupMember != null)
                    {
                        groupMember.Active = true;
                        groupMember.Save();

                        Group group = Group.Fetch(groupID);

                        if (group != null)
                        {
                            group.ActiveMembers++;
                            group.Save();    
                        }

                        #region Add Event

                        Event newEvent = new Event(CurrentUserSession.Username);

                        newEvent.Type = Event.eType.FriendJoinedGroup;
                        FriendJoinedGroup friendJoinedGroup = new FriendJoinedGroup();
                        friendJoinedGroup.GroupID = groupID;
                        newEvent.DetailsXML = Misc.ToXml(friendJoinedGroup);

                        newEvent.Save();

                        string[] usernames = Classes.User.FetchMutuallyFriends(CurrentUserSession.Username);

                        foreach (string friendUsername in usernames)
                        {
                            if (Config.Users.NewEventNotification)
                            {
                                if (group != null)
                                {
                                    string text =
                                        String.Format("Your friend {0} has joined the {1} group".Translate(),
                                                      "<b>" + CurrentUserSession.Username + "</b>",
                                                      Server.HtmlEncode(group.Name));
                                    int imageID = 0;
                                    try
                                    {
                                        imageID = Photo.GetPrimary(CurrentUserSession.Username).Id;
                                    }
                                    catch (NotFoundException)
                                    {
                                        imageID = ImageHandler.GetPhotoIdByGender(CurrentUserSession.Gender);
                                    }
                                    string thumbnailUrl =
                                        ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                                    Classes.User.SendOnlineEventNotification(CurrentUserSession.Username, friendUsername,
                                                                             text,
                                                                             thumbnailUrl,
                                                                             UrlRewrite.CreateShowGroupUrl(
                                                                                 group.ID.ToString()));
                                }
                            }
                        }

                        #endregion
                    }
                    break;

                case "Reject" :
                    GroupMember.Delete(Convert.ToInt32(e.CommandArgument), CurrentUserSession.Username);
                    break;
            }

            Response.Redirect("~/Groups.aspx?show=mg");
        }
        public void ProcessRequest(HttpContext context)
        {
            string cacheKey = "silverlightUpload_" + context.Request.Headers["guid"];
            string type = context.Request.Headers["type"];
            if (context.Cache.Get(cacheKey) != null)
            {
                if (type == "photo")
                {
                    Username = ((string)context.Cache.Get(cacheKey)).Split('|')[0];
                    string photoAlbumID = ((string)context.Cache.Get(cacheKey)).Split('|')[1];
                    if (photoAlbumID == "-1") PhotoAlbumID = null;
                    else PhotoAlbumID = Convert.ToInt32(photoAlbumID);
                }
                else if (type == "video") Username = ((string)context.Cache.Get(cacheKey));
            }

            if (Username != null)
            {
                User user;
                try
                {
                    user = Classes.User.Load(Username);
                }
                catch (NotFoundException)
                {
                    return;
                }

                BillingPlanOptions billingPlanOptions = null;

                Subscription subscription = Subscription.FetchActiveSubscription(Username);

                if (subscription == null)
                    billingPlanOptions = Config.Users.GetNonPayingMembersOptions();
                else
                {
                    BillingPlan plan = BillingPlan.Fetch(subscription.PlanID);
                    billingPlanOptions = plan.Options;
                }
                //if (!Config.Users.PaymentRequired)
                //{
                //    billingPlanOptions = Config.Users.GetNonPayingMembersOptions();
                //}
                //else
                //{
                //    var isNonPaidMember = !User.IsPaidMember(Username);

                //    if (isNonPaidMember)
                //    {
                //        billingPlanOptions = Config.Users.GetNonPayingMembersOptions();
                //    }
                //    else
                //    {
                //        Subscription subscription =
                //            Subscription.FetchActiveSubscription(Username);
                //        if (subscription == null)
                //            billingPlanOptions = new BillingPlanOptions();
                //        else
                //        {
                //            BillingPlan plan = BillingPlan.Fetch(subscription.PlanID);
                //            billingPlanOptions = plan.Options;
                //        }
                //    }
                //}

                // if there was a file uploded
                if (context.Request.InputStream.Length > 0)
                {
                    if (type == "photo")
                    {
                        Image image;
                        try
                        {
                            image = Image.FromStream(context.Request.InputStream);
                        }
                        catch (Exception err)
                        {
                            Global.Logger.LogStatus("Image upload failed", err);
                            context.Cache.Insert("silverlightPhotoUploadError_" + Username,
                                                 Lang.Trans("Invalid image!"), null, DateTime.Now.AddMinutes(10),
                                                 Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
                            return;
                        }

                        if (image.Height < Config.Photos.PhotoMinHeight || image.Width < Config.Photos.PhotoMinWidth)
                        {
                            string key = "silverlightPhotoUploadError_" + Username;
                            string error = Lang.Trans("The photo is too small!") + "\\n";
                            if (context.Cache.Get(key) != null)
                            {
                                error = context.Cache.Get(key) + error;
                            }
                            context.Cache.Insert(key, error, null, DateTime.Now.AddMinutes(10),
                                                 Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
                            return;
                        }

                        var photo = new Photo
                                        {
                                            Image = image,
                                            ExplicitPhoto = false,
                                            User = user,
                                            PhotoAlbumID = PhotoAlbumID,
                                            Name = String.Empty,
                                            Description = String.Empty
                                        };

                        if (Config.Photos.AutoApprovePhotos
                            || billingPlanOptions.AutoApprovePhotos.Value
                            || user.Level != null && user.Level.Restrictions.AutoApprovePhotos)
                        {
                            photo.Approved = true;
                        }
                        else
                        {
                            photo.Approved = false;
                        }

                        lock (threadLock)
                        {
                            int allPhotos = Photo.Search(-1, Username, -1, null, null, null, null).Length;
                            int maxPhotos = billingPlanOptions.MaxPhotos.Value;
                            if (user.Level != null && maxPhotos < user.Level.Restrictions.MaxPhotos)
                                maxPhotos = user.Level.Restrictions.MaxPhotos;
                            if (allPhotos >= maxPhotos)
                            {
                                context.Cache.Insert("silverlightPhotoUploadError_" + Username,
                                                     String.Format(
                                                         Lang.Trans("You cannot have more than {0} photos!"),
                                                         maxPhotos), null, DateTime.Now.AddMinutes(30),
                                                     Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
                                return;
                            }

                            photo.Save(true);
                        }
                        
                        photo.Image.Dispose();

                        if (photo.Approved && !photo.PrivatePhoto)
                        {
                            #region Add NewFriendPhoto Event

                            var newEvent = new Event(photo.Username) { Type = Event.eType.NewFriendPhoto };

                            var newFriendPhoto = new NewFriendPhoto();
                            newFriendPhoto.PhotoID = photo.Id;
                            newEvent.DetailsXML = Misc.ToXml(newFriendPhoto);

                            newEvent.Save();

                            string[] usernames = Classes.User.FetchMutuallyFriends(photo.Username);

                            foreach (string friendUsername in usernames)
                            {
                                if (Config.Users.NewEventNotification)
                                {
                                    string text =
                                        String.Format("Your friend {0} has uploaded a new photo".Translate(),
                                                      "<b>" + photo.Username + "</b>");
                                    string thumbnailUrl = ImageHandler.CreateImageUrl(photo.Id, 50, 50, false, true,
                                                                                      true);
                                    Classes.User.SendOnlineEventNotification(photo.Username, friendUsername,
                                                                     text, thumbnailUrl,
                                                                     UrlRewrite.CreateShowUserPhotosUrl(
                                                                         photo.Username));
                                }
                            }

                            #endregion
                        }
                    }
                    else if (type == "video")
                    {
                        string tempfile;
                        
                        if (!Misc.GetTempFileName(out tempfile))
                            tempfile = Path.GetTempFileName();
                        using (FileStream fs = File.Create(tempfile))
                        {
                            int bytesRead = 0;
                            byte[] buffer = new byte[1024];
                            while ((bytesRead = context.Request.InputStream.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                fs.Write(buffer, 0, bytesRead);
                            }
                        }
                        
                        VideoUpload videoUpload = new VideoUpload(Username);
                        if (billingPlanOptions.AutoApproveVideos.Value
                            || user.Level != null && user.Level.Restrictions.AutoApproveVideos)
                        {
                            videoUpload.Approved = true;
                        }

                        lock(threadLock)
                        {
                            List<VideoUpload> videos = VideoUpload.Load(null, Username, null, null, null, null);
                            int maxVideoUploads = 0; // Config.Misc.MaxVideoUploads;
                            if (maxVideoUploads < billingPlanOptions.MaxVideoUploads.Value)
                                maxVideoUploads = billingPlanOptions.MaxVideoUploads.Value;
                            if (user.Level != null && maxVideoUploads < user.Level.Restrictions.MaxVideoUploads)
                                maxVideoUploads = user.Level.Restrictions.MaxVideoUploads;
                            if (videos.Count >= maxVideoUploads)
                            {
                                context.Cache.Insert("silverlightVideoUploadError_" + Username,
                                                     String.Format(
                                                         Lang.Trans("You cannot have more than {0} video uploads!"),
                                                         maxVideoUploads),
                                                     null, DateTime.Now.AddMinutes(30),
                                                     Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
                                return;
                            }

                            videoUpload.Save(); // Save to get new ID
                        }

                        if (videoUpload.Approved && !videoUpload.IsPrivate)
                        {
                            #region Add NewFriendVideoUpload Event

                            Event newEvent = new Event(videoUpload.Username);

                            newEvent.Type = Event.eType.NewFriendVideoUpload;
                            NewFriendVideoUpload newFriendVideoUpload = new NewFriendVideoUpload();
                            newFriendVideoUpload.VideoUploadID = videoUpload.Id;
                            newEvent.DetailsXML = Misc.ToXml(newFriendVideoUpload);

                            newEvent.Save();

                            string[] usernames = Classes.User.FetchMutuallyFriends(videoUpload.Username);

                            foreach (string friendUsername in usernames)
                            {
                                if (Config.Users.NewEventNotification)
                                {
                                    string text =
                                        String.Format("Your friend {0} has uploaded a new video".Translate(),
                                                      "<b>" + videoUpload.Username + "</b>");
                                    int imageID = 0;
                                    try
                                    {
                                        imageID = Photo.GetPrimary(videoUpload.Username).Id;
                                    }
                                    catch (NotFoundException)
                                    {
                                        imageID = ImageHandler.GetPhotoIdByGender(user.Gender);
                                    }
                                    string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true,
                                                                                      true);
                                    Classes.User.SendOnlineEventNotification(videoUpload.Username,
                                                                             friendUsername,
                                                                             text, thumbnailUrl,
                                                                             UrlRewrite.CreateShowUserUrl(
                                                                                 videoUpload.Username));
                                }
                            }

                            #endregion
                        }

                        string userFilesPath = "~/UserFiles/" + Username;
                        string userFilesDir = context.Server.MapPath(userFilesPath);
                        if (!Directory.Exists(userFilesDir))
                        {
                            Directory.CreateDirectory(userFilesDir);
                        }

                        File.Move(tempfile, userFilesDir + @"\video_" + videoUpload.Id + ".original");

                        ThreadPool.QueueUserWorkItem(AsyncProcessVideo, videoUpload);
                    }
                }
            }
        }
        protected void lnkUpdateStatusText_Click(object sender, EventArgs e)
        {
            string status = String.Empty;

            status = txtStatusText.Text.Trim();

            if (status.Length > 0)
            {
                lblStatusText.Text = Server.HtmlEncode(status);
                _currentUserSession.StatusText = status;
                _currentUserSession.Update();

                #region Add FriendUpdatedStatus Event & realtime notifications

                Event newEvent = new Event(_currentUserSession.Username) { Type = Event.eType.FriendUpdatedStatus };

                var friendUpdatedStatus = new FriendUpdatedStatus { Status = status };
                newEvent.DetailsXML = Misc.ToXml(friendUpdatedStatus);

                newEvent.Save();

                string[] usernames = Classes.User.FetchMutuallyFriends(_currentUserSession.Username);

                foreach (string friendUsername in usernames)
                {
                    if (Config.Users.NewEventNotification &&
                        (Classes.User.IsOnline(friendUsername) || Classes.User.IsUsingNotifier(friendUsername)))
                    {
                        var text = String.Format("Your friend {0} has changed their status to \"{1}\"".Translate(),
                                                 "<b>" + _currentUserSession.Username + "</b>", status);
                        var imageID = 0;
                        try
                        {
                            imageID = _currentUserSession.GetPrimaryPhoto().Id;
                        }
                        catch (NotFoundException)
                        {
                            imageID = ImageHandler.GetPhotoIdByGender(_currentUserSession.Gender);
                        }
                        var thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                        var notification = new GenericEventNotification
                        {
                            Recipient = friendUsername,
                            Sender = _currentUserSession.Username,
                            Text = text,
                            ThumbnailUrl = thumbnailUrl,
                            RedirectUrl = UrlRewrite.CreateShowUserUrl(_currentUserSession.Username)
                        };
                        RealtimeNotification.SendNotification(notification);
                    }
                }

                #endregion

                // Update Twitter status
                if (Config.Misc.EnableTwitterIntegration && Twitter.HasCredentials(_currentUserSession.Username))
                {
                    try
                    {
                        Twitter.PublishTweet(_currentUserSession.Username, status);
                    }
                    catch (Exception err)
                    {
                        Global.Logger.LogError("Twitter", err);
                    }
                }
            }
            else
            {
                lblStatusText.Text = "Not set".Translate();
                _currentUserSession.StatusText = null;
                _currentUserSession.Update();
            }

            pnlEditStatusText.Visible = false;
            pnlViewStatusText.Visible = true;
        }
Example #11
0
        private static void AsyncProcessMailerQueue(object data)
        {
            if (mailerLock)
            {
                return;
            }

            try
            {
                mailerLock = true;

                if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
                {
                    using (var db = new ezFixUpDataContext())
                    {
                        var friendsWithCommingBirthdays = CompiledQueries.FetchActiveFriendsByBirthday(db, 7);
                        var usernames = friendsWithCommingBirthdays.Select(f => f.u_username).Distinct();

                        foreach (string recipient in usernames)
                        {
                            User u = null;
                            try
                            {
                                u = Classes.User.Load(recipient);
                            }
                            catch (NotFoundException)
                            {
                                continue;
                            }

                            var hisBirthdaysFriends = friendsWithCommingBirthdays
                                                                .Where(f => f.u_username == recipient)
                                                                .Select(f => f.f_username).ToArray();

                            MiscTemplates.FriendBirthday friendBirthdayTemplate =
                                                                new MiscTemplates.FriendBirthday(u.LanguageId);

                            var frUsernames = string.Join(",\r\n", hisBirthdaysFriends);
                            Message.Send(Config.Users.SystemUsername, recipient,
                                         friendBirthdayTemplate.Message.Replace("%%USERNAMES%%", frUsernames),
                                         0);
                        }
                    }
                }

                BirthdaySearch search = new BirthdaySearch();

                UserSearchResults results = search.GetResults();

                if (results != null && results.Usernames != null)
                {
                    foreach (string username in results.Usernames)
                    {
                        User user = null;
                        try
                        {
                            user = Classes.User.Load(username);
                        }
                        catch (NotFoundException) { continue; }

                        Event evt = new Event(username);
                        evt.Type = Event.eType.FriendBirthday;
                        evt.Save();

                        string[] usernames = Classes.User.FetchMutuallyFriends(username);

                        foreach (string recipient in usernames)
                        {
                            User u = null;
                            try
                            {
                                u = Classes.User.Load(recipient);
                            }
                            catch (NotFoundException)
                            {
                                continue;
                            }
                            //MiscTemplates.FriendBirthday friendBirthdayTemplate =
                            //    new MiscTemplates.FriendBirthday(u.LanguageId);
                            //Message.Send(Config.Users.SystemUsername, recipient,
                            //             friendBirthdayTemplate.Message.Replace("%%USERNAME%%", username), 0);

                            if (Config.Users.NewEventNotification)
                            {
                                int imageID = 0;
                                try
                                {
                                    imageID = Photo.GetPrimary(user.Username).Id;
                                }
                                catch (NotFoundException)
                                {
                                    imageID = ImageHandler.GetPhotoIdByGender(user.Gender);
                                }
                                string text = String.Format("{0} has a birthday today".Translate(),
                                                      "<b>" + user.Username + "</b>");

                                string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                                Classes.User.SendOnlineEventNotification(user.Username, recipient, text, thumbnailUrl,
                                                                         UrlRewrite.CreateShowUserUrl(user.Username));
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                Global.Logger.LogError("FriendBirthdayEmails", err);
            }
            finally
            {
                mailerLock = false;
            }
        }
        protected void btnSaveAndApprove_Click(object sender, EventArgs e)
        {
            if (!HasWriteAccess)
                return;

            BlogPost blogPost = null;

            try
            {
                blogPost = BlogPost.Load(id);
            }
            catch (NotFoundException)
            {
                return;
            }

            if (txtTitle.Text.Trim().Length == 0 || txtContent.Text.Trim().Length == 0)
                btnReject_Click(null, null);
            else
            {
                blogPost.Title = txtTitle.Text.Trim();
                blogPost.Content = txtContent.Text.Trim();
            }
            blogPost.Approved = true;
            blogPost.Save();

            #region Add NewFriendBlogPost Event

            Event newEvent = new Event(username);

            newEvent.Type = Event.eType.NewFriendBlogPost;
            NewFriendBlogPost newFriendBlogPost = new NewFriendBlogPost();
            newFriendBlogPost.BlogPostID = blogPost.Id;
            newEvent.DetailsXML = Misc.ToXml(newFriendBlogPost);

            newEvent.Save();

            string[] usernames = Classes.User.FetchMutuallyFriends(username);

            foreach (string friendUsername in usernames)
            {
                if (Config.Users.NewEventNotification)
                {
                    string text = String.Format("Your friend {0} has a new blog post: {1}".TranslateA(),
                                            "<b>" + username + "</b>",
                                            Server.HtmlEncode(blogPost.Title));
                    int imageID = 0;
                    try
                    {
                        imageID = Photo.GetPrimary(username).Id;
                    }
                    catch (NotFoundException)
                    {
                        Classes.User user = null;
                        try
                        {
                            user = Classes.User.Load(username);
                            imageID = ImageHandler.GetPhotoIdByGender(user.Gender);
                        }
                        catch (NotFoundException)
                        {
                            continue;
                        }
                    }
                    string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                    Classes.User.SendOnlineEventNotification(username, friendUsername,
                                                             text, thumbnailUrl,
                                                             UrlRewrite.CreateShowUserBlogUrl(
                                                                 username, blogPost.Id));
                }
            }

            #endregion

            Response.Redirect("ApproveBlogPosts.aspx");
        }
        protected void dlPendingMembers_ItemCommand(object source, DataListCommandEventArgs e)
        {
            string currentUsername = ((PageBase) Page).CurrentUserSession.Username;
            string pendingUsername = (string) e.CommandArgument;

            GroupMember groupMember = GroupMember.Fetch(GroupID, pendingUsername);

            switch (e.CommandName)
            {
                case "Approve" :
                    if (groupMember != null)
                    {
                        groupMember.Active = true;
                        groupMember.Save();
                        CurrentGroup.ActiveMembers++;
                        CurrentGroup.Save();

                        try
                        {
                            User toUser = User.Load(pendingUsername);
                            MiscTemplates.ApproveGroupMemberMessage approveGroupMemberTemplate =
                                new MiscTemplates.ApproveGroupMemberMessage(toUser.LanguageId);
                            Message msg = new Message(currentUsername, pendingUsername);
                            msg.Body = approveGroupMemberTemplate.Message.Replace("%%GROUP%%",
                                Parsers.ProcessGroupName(CurrentGroup.Name));
                            msg.Send();

                            #region Add Event

                            Event newEvent = new Event(pendingUsername);

                            newEvent.Type = Event.eType.FriendJoinedGroup;
                            FriendJoinedGroup friendJoinedGroup = new FriendJoinedGroup();
                            friendJoinedGroup.GroupID = CurrentGroup.ID;
                            newEvent.DetailsXML = Misc.ToXml(friendJoinedGroup);

                            newEvent.Save();

                            int imageID = 0;
                            try
                            {
                                imageID = Photo.GetPrimary(pendingUsername).Id;
                            }
                            catch (NotFoundException)
                            {
                                imageID = ImageHandler.GetPhotoIdByGender(toUser.Gender);
                            }

                            string[] usernames = User.FetchMutuallyFriends(pendingUsername);
                            foreach (string friendUsername in usernames)
                            {
                                if (Config.Users.NewEventNotification)
                                {
                                    string text =
                                        String.Format("Your friend {0} has joined the {1} group".Translate(),
                                                      "<b>" + pendingUsername + "</b>",
                                                      Server.HtmlEncode(CurrentGroup.Name));
                                    string thumbnailUrl =
                                        ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                                    User.SendOnlineEventNotification(pendingUsername, friendUsername,
                                                                             text, thumbnailUrl,
                                                                             UrlRewrite.CreateShowGroupUrl(
                                                                                 CurrentGroup.ID.ToString()));
                                }
                            }

                            #endregion
                        }
                        catch (NotFoundException)
                        {
                        }
                    }
                    break;

                case "Reject" :
                    if (groupMember != null)
                    {
                        GroupMember.Delete(GroupID, pendingUsername);

                        try
                        {
                            User user = User.Load(pendingUsername);
                            MiscTemplates.RejectGroupMemberMessage rejectGroupMemberTemplate =
                                new MiscTemplates.RejectGroupMemberMessage(user.LanguageId);
                            Message msg = new Message(currentUsername, pendingUsername);
                            msg.Body = rejectGroupMemberTemplate.Message.Replace("%%GROUP%%",
                                Parsers.ProcessGroupName(CurrentGroup.Name));
                            msg.Send();
                        }
                        catch (NotFoundException)
                        {
                        }
                    }
                    break;
            }
        }
        protected void btnApproveAll_Click(object sender, EventArgs e)
        {
            if (!HasWriteAccess)
                return;
            
            foreach (DataListItem item in listPendingApproval.Items)
            {
                int photoId = Convert.ToInt32(((LinkButton) item.Controls[1]).CommandArgument);

                Photo photo = Photo.Fetch(photoId);

                photo.ApprovePhoto(CurrentAdminSession.Username);

                if (!photo.PrivatePhoto)
                {
                    #region Add Event

                    Event newEvent = new Event(photo.Username);

                    newEvent.Type = Event.eType.NewFriendPhoto;
                    NewFriendPhoto newFriendPhoto = new NewFriendPhoto();
                    newFriendPhoto.PhotoID = photo.Id;
                    newEvent.DetailsXML = Misc.ToXml(newFriendPhoto);

                    newEvent.Save();

                    string[] usernames = Classes.User.FetchMutuallyFriends(photo.Username);

                    foreach (string friendUsername in usernames)
                    {
                        if (Config.Users.NewEventNotification)
                        {
                            string text = String.Format("Your friend {0} has uploaded a new photo".TranslateA(),
                                                      "<b>" + photo.Username + "</b>");
                            string thumbnailUrl = ImageHandler.CreateImageUrl(photo.Id, 50, 50, false, true, true);
                            Classes.User.SendOnlineEventNotification(photo.Username, friendUsername,
                                                                     text, thumbnailUrl,
                                                                     UrlRewrite.CreateShowUserPhotosUrl(photo.Username));
                        }
                    }

                    #endregion 
                }

                try
                {
                    MiscTemplates.ApprovePhotoMessage approvePhotoMessageTemplate =
                        new MiscTemplates.ApprovePhotoMessage(photo.User.LanguageId);
                    Message.Send(Config.Users.SystemUsername, photo.User.Username, approvePhotoMessageTemplate.Message, 0);
                }
                catch (Exception ex)
                {
                    Log(ex);
                }
            }

            PopulateDataGrid();
        }
Example #15
0
        public void ProcessRequest(HttpContext context)
        {
            int width = Convert.ToInt32(context.Request.Params["width"]);
            int height = Convert.ToInt32(context.Request.Params["height"]);

            string cacheKey = "webcamUpload_" + context.Request.Params["guid"];
            if (context.Cache.Get(cacheKey) != null)
            {
                Username = ((string)context.Cache.Get(cacheKey)).Split('|')[0];
                string photoAlbumID = ((string)context.Cache.Get(cacheKey)).Split('|')[1];
                if (photoAlbumID == "-1") PhotoAlbumID = null;
                else PhotoAlbumID = Convert.ToInt32(photoAlbumID);
            }

            if (Username != null)
            {
                User user = null;

                try
                {
                    user = Classes.User.Load(Username);
                }
                catch (NotFoundException)
                {
                    return;
                }

                Bitmap bmp = new Bitmap(width, height);
                Graphics graphics = Graphics.FromImage(bmp);
                SolidBrush brush = new SolidBrush(Color.White);
                graphics.FillRectangle(brush, 0, 0, width, height);

                for (int rows = 0; rows < height; rows++)
                {
                    string parameters = context.Request.Params["px" + rows];

                    // convert the string into an array of n elements
                    string[] crow = (parameters).Split(',');

                    for (int cols = 0; cols < width; cols++)
                    {
                        string value = crow[cols];
                        if (value.Length > 0)
                        {
                            StringBuilder hex = new StringBuilder(value);
                            while (hex.Length < 6)
                            {
                                hex.Insert(0, "0").Append(hex.ToString());
                            }

                            int r = Int32.Parse(hex.ToString().Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
                            int g = Int32.Parse(hex.ToString().Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
                            int b = Int32.Parse(hex.ToString().Substring(4, 2), System.Globalization.NumberStyles.HexNumber);

                            Color c = Color.FromArgb(r, g, b);
                            bmp.SetPixel(cols, rows, c);
                        }
                    }
                }

                if (Config.Photos.DoWatermark
                    && bmp.Width >= Config.Photos.MinWidthToWatermark
                    && bmp.Height >= Config.Photos.MinHeightToWatermark)
                {
                    Image watermark;
                    if (context.Cache["Watermark_Image"] == null)
                    {
                        string filename = context.Server.MapPath("~/Images") + "/Watermark.png";
                        watermark = Image.FromFile(filename);
                        context.Cache.Add("Watermark_Image", watermark, new CacheDependency(filename),
                                          Cache.NoAbsoluteExpiration, TimeSpan.FromHours(24),
                                          CacheItemPriority.NotRemovable, null);
                    }
                    else
                    {
                        watermark = (Image)context.Cache["Watermark_Image"];
                    }

                    try
                    {
                        lock (watermark)
                        {
                            Photo.ApplyWatermark(bmp, watermark, Config.Photos.WatermarkTransparency,
                                                 Config.Photos.WatermarkPosition);
                        }
                    }
                    catch (Exception err)
                    {
                        Global.Logger.LogWarning("Unable to apply watermark", err);
                    }
                }

                BillingPlanOptions billingPlanOptions = null;
                Subscription subscription = Subscription.FetchActiveSubscription(Username);
                if (subscription == null)
                    billingPlanOptions = new BillingPlanOptions();
                else
                {
                    BillingPlan plan = BillingPlan.Fetch(subscription.PlanID);
                    billingPlanOptions = plan.Options;
                }

                Photo photo = new Photo();

                photo.Image = bmp;
                photo.ExplicitPhoto = false;
                photo.User = user;
                photo.PhotoAlbumID = PhotoAlbumID;
                photo.Name = String.Empty;
                photo.Description = String.Empty;

                if (Config.Photos.AutoApprovePhotos
                    || billingPlanOptions.AutoApprovePhotos.Value
                    || user.Level != null && user.Level.Restrictions.AutoApprovePhotos)
                {
                    photo.Approved = true;
                }
                else
                {
                    photo.Approved = false;
                }

                photo.Save(true);

                photo.Image.Dispose();

                if (photo.Approved && !photo.PrivatePhoto)
                {
                    #region Add NewFriendPhoto Event

                    Event newEvent = new Event(photo.Username);

                    newEvent.Type = Event.eType.NewFriendPhoto;
                    NewFriendPhoto newFriendPhoto = new NewFriendPhoto();
                    newFriendPhoto.PhotoID = photo.Id;
                    newEvent.DetailsXML = Misc.ToXml(newFriendPhoto);

                    newEvent.Save();

                    string[] usernames = Classes.User.FetchMutuallyFriends(photo.Username);

                    foreach (string friendUsername in usernames)
                    {
                        if (Config.Users.NewEventNotification)
                        {
                            string text = String.Format("Your friend {0} has uploaded a new photo".Translate(),
                                  "<b>" + photo.Username + "</b>");
                            string thumbnailUrl = ImageHandler.CreateImageUrl(photo.Id, 50, 50, false, true, true);
                            Classes.User.SendOnlineEventNotification(photo.Username, friendUsername,
                                                                     text, thumbnailUrl,
                                                                     UrlRewrite.CreateShowUserPhotosUrl(
                                                                         photo.Username));
                        }
                    }

                    #endregion
                }
            }
        }
Example #16
0
        protected void btnStartNewTopic_Click(object sender, EventArgs e)
        {
            string topicName = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtTopicName.Text.Trim()) : txtTopicName.Text.Trim();
            string post = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtPost.Text.Trim()) : txtPost.Text.Trim();

            if (topicName.Length == 0)
            {
                type = eType.AddTopic;

                lblError.Text = Lang.Trans("Please enter topic name.");
                return;
            }

            if (post.Length == 0)
            {
                type = eType.AddTopic;

                lblError.Text = Lang.Trans("Please enter post text.");
                return;
            }

            #region Find unclosed [quote] tags

            int openQuotesCount = Regex.Matches(post, @"\[quote", RegexOptions.IgnoreCase).Count;
            int closedQuotesCount = Regex.Matches(post, @"\[/quote", RegexOptions.IgnoreCase).Count;
            if (openQuotesCount != closedQuotesCount)
            {
                type = eType.AddTopic;
                this.post = post;

                lblError.Text = Lang.Trans("Please close all [quote] tags with a [/quote] tag!");
                return;
            }

            #endregion

            if (CurrentUserSession != null)
            {
                var groupTopic = new GroupTopic(GroupID, CurrentUserSession.Username)
                                     {
                                         Name = topicName,
                                         Posts = 1,
                                         Locked = cbLocked.Checked
                                     };

                if (cbCreatePoll.Checked)
                {
                    if (validatePollsChoices())
                    {
                        groupTopic.IsPoll = true;
                    }
                    else
                    {
                        lblError.Text = Lang.Trans("Please enter at least one choice!");
                        return;
                    }
                }

                if (cbSticky.Checked)
                {
                    if (!DatePicker1.ValidDateEntered)
                    {
                        lblError.Text = Lang.Trans("Please select date!");
                        return;
                    }
                    groupTopic.StickyUntil = DatePicker1.SelectedDate;
                }

                groupTopic.Save();

                User.AddScore(CurrentUserSession.Username, Config.UserScores.NewTopic, "NewTopic");

                var groupPost = new GroupPost(groupTopic.ID, CurrentUserSession.Username) {Post = post};
                groupPost.Save();

                #region Subscribe automatically for this topic

                GroupTopicSubscription groupTopicSubscription = new GroupTopicSubscription(CurrentUserSession.Username, groupTopic.ID, GroupID);
                groupTopicSubscription.DateUpdated = groupTopic.DateUpdated;
                groupTopicSubscription.Save();

                #endregion

                #region create a poll

                if (cbCreatePoll.Checked)
                {
                    foreach (RepeaterItem item in rptChoices.Items)
                    {
                        TextBox txtChoice = item.FindControl("txtChoice") as TextBox;

                        if (txtChoice != null && txtChoice.Text.Trim() != String.Empty)
                        {
                            GroupPollsChoice choice = new GroupPollsChoice(groupTopic.ID);
                            choice.Answer = txtChoice.Text.Trim();
                            choice.Save();
                        }
                    }
                }

                #endregion

                #region Add NewGroupTopic Event

                Event newEvent = new Event(CurrentUserSession.Username);

                newEvent.FromGroup = GroupID;
                newEvent.Type = Event.eType.NewGroupTopic;
                NewGroupTopic newGroupTopic = new NewGroupTopic();
                newGroupTopic.GroupTopicID = groupTopic.ID;
                newEvent.DetailsXML = Misc.ToXml(newGroupTopic);

                newEvent.Save();

                Group group = Group.Fetch(groupTopic.GroupID);

                string[] usernames = User.FetchMutuallyFriends(CurrentUserSession.Username);

                foreach (string friendUsername in usernames)
                {
                    if (Config.Users.NewEventNotification)
                    {
                        if (group != null)
                        {
                            string text =
                                String.Format("Your friend {0} has posted a new topic {1} in the {2} group".Translate(),
                                              "<b>" + CurrentUserSession.Username + "</b>",
                                              Server.HtmlEncode(groupTopic.Name), Server.HtmlEncode(group.Name));
                            int imageID = 0;
                            try
                            {
                                imageID = Photo.GetPrimary(CurrentUserSession.Username).Id;
                            }
                            catch (NotFoundException)
                            {
                                imageID = ImageHandler.GetPhotoIdByGender(CurrentUserSession.Gender);
                            }
                            string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                            User.SendOnlineEventNotification(CurrentUserSession.Username, friendUsername, text,
                                                             thumbnailUrl,
                                                             UrlRewrite.CreateShowGroupTopicsUrl(
                                                                 groupTopic.ID.ToString()));
                        }
                    }
                }

                GroupMember[] groupMembers = GroupMember.Fetch(GroupID, true);

                foreach (GroupMember groupMember in groupMembers)
                {
                    // A user should not receive events for their topics
                    if (groupMember.Username == CurrentUserSession.Username) continue;

                    if (Config.Users.NewEventNotification)
                    {
                        if (group != null)
                        {
                            string text =
                                String.Format("There is a new topic {0} in the {1} group".Translate(),
                                              "<b>" + Server.HtmlEncode(groupTopic.Name) + "</b>",
                                              Server.HtmlEncode(group.Name));
                            string thumbnailUrl = GroupIcon.CreateImageUrl(group.ID, 50, 50, true);
                            User.SendOnlineEventNotification(CurrentUserSession.Username, groupMember.Username, text,
                                                             thumbnailUrl, UrlRewrite.CreateShowGroupUrl(group.ID.ToString()));
                        }
                    }
                }

                #endregion
            }

            Response.Redirect(UrlRewrite.CreateShowGroupTopicsUrl(GroupID.ToString()));
            
        }
Example #17
0
        protected void btnSaveAndApprove_Click(object sender, EventArgs e)
        {
            if (!HasWriteAccess)
                return;
            
            ProfileAnswer answer = new ProfileAnswer(username, questionID);

            if (txtAnswer.Text.Trim() == String.Empty)
                btnReject_Click(null, null);
            else
                answer.Value = txtAnswer.Text;
            answer.Approved = true;
            answer.Save();

            #region Add FriendUpdatedProfile Event

            Event newEvent = new Event(username);

            newEvent.Type = Event.eType.FriendUpdatedProfile;
            UpdatedProfile updatedProfile = new UpdatedProfile();
            updatedProfile.QuestionIDs = new List<int>() {answer.Question.Id };
            newEvent.DetailsXML = Misc.ToXml(updatedProfile);

            newEvent.Save();

            string[] usernames = Classes.User.FetchMutuallyFriends(username);

            foreach (string friendUsername in usernames)
            {
                if (Config.Users.NewEventNotification)
                {
                    string text = String.Format("Your friend {0} has updated the \"{1}\" section in their profile".TranslateA(),
                                            "<b>" + username + "</b>", answer.Question.Name);
                    int imageID = 0;
                    try
                    {
                        imageID = Photo.GetPrimary(username).Id;
                    }
                    catch (NotFoundException)
                    {
                        User user = null;
                        try
                        {
                            user = Classes.User.Load(username);
                            imageID = ImageHandler.GetPhotoIdByGender(user.Gender);
                        }
                        catch (NotFoundException)
                        {
                            break;
                        }
                    }
                    string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                    Classes.User.SendOnlineEventNotification(username, friendUsername, text, thumbnailUrl,
                                                             UrlRewrite.CreateShowUserUrl(username));
                }
            }

            #endregion

            Response.Redirect("ApproveAnswers.aspx");
        }
Example #18
0
        public void ProcessRequest(HttpContext context)
        {
            // Example of using a passed in value in the query string to set a categoryId
            // Now you can do anything you need to witht the file.
            //int categoryId = 0;
            //if (!string.IsNullOrEmpty(context.Request.QueryString["CategoryID"]))
            //{
            //    int.TryParse(context.Request.QueryString["CategoryID"],out categoryId);
            //}
            //if (categoryId > 0)
            //{
            //}

            if (context.Request.Files.Count > 0)
            {
                // get the applications path

                //string uploadPath = context.Server.MapPath(context.Request.ApplicationPath + "/Upload");
                // loop through all the uploaded files

                string cacheKey = "flashUpload_" + context.Request.Params["guid"];
                if (context.Cache.Get(cacheKey) != null)
                {
                    if (context.Request.Params["type"] == "photo")
                    {
                        Username = ((string)context.Cache.Get(cacheKey)).Split('|')[0];
                        string photoAlbumID = ((string) context.Cache.Get(cacheKey)).Split('|')[1];
                        if (photoAlbumID == "-1") PhotoAlbumID = null;
                        else PhotoAlbumID = Convert.ToInt32(photoAlbumID);
                    }
                    else if (context.Request.Params["type"] == "video") Username = ((string)context.Cache.Get(cacheKey));
                }

                if (Username != null)
                {
                    User user = null;

                    try
                    {
                        user = Classes.User.Load(Username);
                    }
                    catch (NotFoundException)
                    {
                        return;
                    }

                    BillingPlanOptions billingPlanOptions = null;
                    if (!Config.Misc.SiteIsPaid)
                    {
                        billingPlanOptions = Config.Users.GetNonPayingMembersOptions();
                    }
                    else
                    {
                        var isNonPaidMember = !User.IsPaidMember(Username);

                        if (isNonPaidMember)
                        {
                            billingPlanOptions = Config.Users.GetNonPayingMembersOptions();
                        }
                        else
                        {
                            Subscription subscription =
                                Subscription.FetchActiveSubscription(Username);
                            if (subscription == null)
                                billingPlanOptions = Config.Users.GetNonPayingMembersOptions();//new BillingPlanOptions();
                            else
                            {
                                BillingPlan plan = BillingPlan.Fetch(subscription.PlanID);
                                billingPlanOptions = plan.Options;
                            }
                        }
                    }

                    for (int j = 0; j < context.Request.Files.Count; j++)
                    {
                        // get the current file
                        HttpPostedFile uploadFile = context.Request.Files[j];
                        // if there was a file uploded
                        if (uploadFile.ContentLength > 0)
                        {
                            // use this if using flash to upload
                            //uploadFile.SaveAs(Path.Combine(uploadPath, uploadFile.FileName));

                            if (context.Request.Params["type"] == "photo")
                            {
                                Image image;
                                try
                                {
                                    image = Image.FromStream
                                        (uploadFile.InputStream);
                                }
                                catch (Exception err)
                                {
                                    Global.Logger.LogStatus("Image upload failed", err);
                                    context.Cache.Insert("flashPhotoUploadError_" + Username,
                                        Lang.Trans("Invalid image!"), null, DateTime.Now.AddMinutes(30),
                                        Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
                                    return;
                                }

                                if (image.Height < Config.Photos.PhotoMinHeight || image.Width < Config.Photos.PhotoMinWidth)
                                {
                                    string key = "flashPhotoUploadError_" + Username;
                                    string error = uploadFile.FileName + " - " + Lang.Trans("The photo is too small!") + "\\n";
                                    if (context.Cache.Get(key) != null)
                                    {
                                        error = context.Cache.Get(key) + error;
                                    }
                                    context.Cache.Insert(key, error, null, DateTime.Now.AddMinutes(30),
                                        Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
                                    return;
                                }

                                Photo photo = new Photo();

                                photo.Image = image;
                                photo.ExplicitPhoto = false;
                                photo.User = user;
                                photo.PhotoAlbumID = PhotoAlbumID;
                                photo.Name = String.Empty;
                                photo.Description = String.Empty;

                                if (Config.Photos.AutoApprovePhotos
                                    || billingPlanOptions.AutoApprovePhotos.Value
                                    || user.Level != null && user.Level.Restrictions.AutoApprovePhotos)
                                {
                                    photo.Approved = true;
                                }
                                else
                                {
                                    photo.Approved = false;
                                }

                                lock(threadLock)
                                {
                                    int allPhotos = Photo.Search(-1, Username, -1, null, null, null, null).Length;
                                    int maxPhotos = billingPlanOptions.MaxPhotos.Value;
                                    if (user.Level != null && maxPhotos < user.Level.Restrictions.MaxPhotos)
                                        maxPhotos = user.Level.Restrictions.MaxPhotos;
                                    if (allPhotos >= maxPhotos)
                                    {
                                        context.Cache.Insert("flashPhotoUploadError_" + Username,
                                                             String.Format(
                                                                 Lang.Trans("You cannot have more than {0} photos!"),
                                                                 maxPhotos), null, DateTime.Now.AddMinutes(30),
                                                             Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
                                        return;
                                    }

                                    photo.Save(true);
                                }

                                
                                photo.Image.Dispose();

                                if (photo.Approved && !photo.PrivatePhoto)
                                {
                                    #region Add NewFriendPhoto Event

                                    Event newEvent = new Event(photo.Username);

                                    newEvent.Type = Event.eType.NewFriendPhoto;
                                    NewFriendPhoto newFriendPhoto = new NewFriendPhoto();
                                    newFriendPhoto.PhotoID = photo.Id;
                                    newEvent.DetailsXML = Misc.ToXml(newFriendPhoto);

                                    newEvent.Save();

                                    string[] usernames = Classes.User.FetchMutuallyFriends(photo.Username);

                                    foreach (string friendUsername in usernames)
                                    {
                                        if (Config.Users.NewEventNotification)
                                        {
                                            string text = String.Format("Your friend {0} has uploaded a new photo".Translate(),
                                                  "<b>" + photo.Username + "</b>");
                                            string thumbnailUrl = ImageHandler.CreateImageUrl(photo.Id, 50, 50, false, true, true);
                                            Classes.User.SendOnlineEventNotification(photo.Username, friendUsername,
                                                                                     text, thumbnailUrl,
                                                                                     UrlRewrite.CreateShowUserPhotosUrl(
                                                                                         photo.Username));
                                        }
                                    }

                                    #endregion
                                }
                            }
                            else if (context.Request.Params["type"] == "video")
                            {
                                string tempfile;
                                
                                if (!Misc.GetTempFileName(out tempfile))
                                    tempfile = Path.GetTempFileName();
                                uploadFile.SaveAs(tempfile);

                                VideoUpload videoUpload = new VideoUpload(Username);
                                if (billingPlanOptions.AutoApproveVideos.Value
                                    || user.Level != null && user.Level.Restrictions.AutoApproveVideos)
                                {
                                    videoUpload.Approved = true;
                                }

                                lock (threadLock)
                                {
                                    List<VideoUpload> videos = VideoUpload.Load(null, Username, null, null, null, null);
                                    int maxVideoUploads = 0;// Config.Misc.MaxVideoUploads;
                                    if (maxVideoUploads < billingPlanOptions.MaxVideoUploads.Value)
                                        maxVideoUploads = billingPlanOptions.MaxVideoUploads.Value;
                                    if (user.Level != null && maxVideoUploads < user.Level.Restrictions.MaxVideoUploads)
                                        maxVideoUploads = user.Level.Restrictions.MaxVideoUploads;
                                    if (videos.Count >= maxVideoUploads)
                                    {
                                        context.Cache.Insert("flashVideoUploadError_" + Username,
                                                             String.Format(
                                                                 Lang.Trans("You cannot have more than {0} video uploads!"),
                                                                 maxVideoUploads),
                                                             null, DateTime.Now.AddMinutes(30),
                                                             Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
                                        return;
                                    }

                                    videoUpload.Save(); // Save to get new ID
                                }

                                if (videoUpload.Approved && !videoUpload.IsPrivate)
                                {
                                    #region Add NewFriendVideoUpload Event

                                    Event newEvent = new Event(videoUpload.Username);

                                    newEvent.Type = Event.eType.NewFriendVideoUpload;
                                    NewFriendVideoUpload newFriendVideoUpload = new NewFriendVideoUpload();
                                    newFriendVideoUpload.VideoUploadID = videoUpload.Id;
                                    newEvent.DetailsXML = Misc.ToXml(newFriendVideoUpload);

                                    newEvent.Save();

                                    string[] usernames = Classes.User.FetchMutuallyFriends(videoUpload.Username);

                                    foreach (string friendUsername in usernames)
                                    {
                                        if (Config.Users.NewEventNotification)
                                        {
                                            string text = String.Format("Your friend {0} has uploaded a new video".Translate(),
                                                  "<b>" + videoUpload.Username + "</b>");
                                            int imageID = 0;
                                            try
                                            {
                                                imageID = Photo.GetPrimary(videoUpload.Username).Id;
                                            }
                                            catch (NotFoundException)
                                            {
                                                imageID = ImageHandler.GetPhotoIdByGender(user.Gender);
                                            }
                                            string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                                            Classes.User.SendOnlineEventNotification(videoUpload.Username,
                                                                                     friendUsername,
                                                                                     text, thumbnailUrl,
                                                                                     UrlRewrite.CreateShowUserUrl(
                                                                                         videoUpload.Username));
                                        }
                                    }

                                    #endregion
                                }

                                string userFilesPath = "~/UserFiles/" + Username;
                                string userFilesDir = context.Server.MapPath(userFilesPath);
                                if (!Directory.Exists(userFilesDir))
                                {
                                    Directory.CreateDirectory(userFilesDir);
                                }

                                File.Move(tempfile, userFilesDir + @"\video_" + videoUpload.Id + ".original");

                                ThreadPool.QueueUserWorkItem(AsyncProcessVideo, videoUpload);

//                            ((PageBase)Page).StatusPageMessage = Lang.Trans("Your video has been queued for processing!");
                            }
                        }
                    }
                }
            }
            // Used as a fix for a bugnq in mac flash player that makes the 
            // onComplete event not fire
            HttpContext.Current.Response.Write(" ");
        }
        /// <summary>
        /// Handles the Click event of the btnUpload control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (CurrentUserSession == null || (CurrentGroupMember == null && !CurrentUserSession.IsAdmin())) 
                return;

            string name = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtName.Text.Trim()) : txtName.Text.Trim();
            string description = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtDescription.Text.Trim()) : txtDescription.Text.Trim();

            if (name.Length == 0)
            {
                lblError.Text = Lang.Trans("Please enter name");
                return;
            }

            if (description.Length == 0)
            {
                lblError.Text = Lang.Trans("Please enter description");
                return;
            }

            if (fuGroupPhoto.PostedFile.FileName.Length > 0)
            {
                GroupPhoto groupPhoto = new GroupPhoto(GroupID, CurrentUserSession.Username);

                try
                {
                    groupPhoto.Image = System.Drawing.Image.FromStream(fuGroupPhoto.PostedFile.InputStream);    
                }
                catch
                {
                    lblError.Text = Lang.Trans("Invalid image!");
                    return;
                }

                groupPhoto.Name = name;
                groupPhoto.Description = description;

                groupPhoto.Save();

                string cacheFileDir = Config.Directories.ImagesCacheDirectory + "/" + groupPhoto.ID % 10;
                string cacheFileMask = String.Format("groupPhoto{0}_*.jpg", groupPhoto.ID);
                foreach (string file in Directory.GetFiles(cacheFileDir, cacheFileMask))
                {
                    File.Delete(file);
                }

                #region Add NewGroupPhoto Event

                Event newEvent = new Event(CurrentUserSession.Username);

                newEvent.FromGroup = GroupID;
                newEvent.Type = Event.eType.NewGroupPhoto;
                NewGroupPhoto newGroupPhoto = new NewGroupPhoto();
                newGroupPhoto.GroupPhotoID = groupPhoto.ID;
                newEvent.DetailsXML = Misc.ToXml(newGroupPhoto);

                newEvent.Save();

                Group group = Group.Fetch(groupPhoto.GroupID);
                string[] usernames = User.FetchMutuallyFriends(CurrentUserSession.Username);

                foreach (string friendUsername in usernames)
                {
                    if (Config.Users.NewEventNotification)
                    {
                        if (group != null)
                        {
                            string text =
                                    String.Format("Your friend {0} has uploaded a new photo in the {1} group".Translate(),
                                                  "<b>" + CurrentUserSession.Username + "</b>", Server.HtmlEncode(group.Name));
                            string thumbnailUrl = GroupImage.CreateImageUrl(groupPhoto.ID, 50, 50, true);
                            User.SendOnlineEventNotification(CurrentUserSession.Username, friendUsername, text,
                                                             thumbnailUrl,
                                                             UrlRewrite.CreateShowGroupPhotosUrl(group.ID.ToString()));
                        }
                    }
                }

                GroupMember[] groupMembers = GroupMember.Fetch(GroupID, true);

                foreach (GroupMember groupMember in groupMembers)
                {
                    if (groupMember.Username == CurrentUserSession.Username) continue;

                    if (Config.Users.NewEventNotification)
                    {
                        if (group != null)
                        {
                            string text =
                                        String.Format("There is a new photo in the {0} group".Translate(),
                                                      "<b>" + Parsers.ProcessGroupName(group.Name) + "</b>");
                            string thumbnailUrl = GroupImage.CreateImageUrl(groupPhoto.ID, 50, 50, true);
                            User.SendOnlineEventNotification(CurrentUserSession.Username, groupMember.Username, text,
                                                             thumbnailUrl,
                                                             UrlRewrite.CreateShowGroupPhotosUrl(group.ID.ToString()));
                        }
                    }
                }

                #endregion

                Response.Redirect(UrlRewrite.CreateShowGroupPhotosUrl(GroupID.ToString()));
            }
        }
Example #20
0
        private void AddRemovedFriendRelationshipEvent(string fromUsername, string toUsername, Relationship.eRelationshipStatus type)
        {
            Event newEvent = new Event(fromUsername);

            newEvent.Type = Event.eType.RemovedFriendRelationship;
            RemovedFriendRelationship removedFriendRelationship = new RemovedFriendRelationship();
            removedFriendRelationship.Username = toUsername;
            removedFriendRelationship.Type = type;
            newEvent.DetailsXML = Misc.ToXml(removedFriendRelationship);

            newEvent.Save();

            if (Config.Users.NewEventNotification)
            {
                string[] usernames = User.FetchMutuallyFriends(fromUsername);

                string text = String.Format("{0} {1} are no longer in relationship ({2})".Translate(),
                                            "<b>" + fromUsername + "</b>", toUsername,
                                            Relationship.GetRelationshipStatusString(type));
                int imageID = 0;
                try
                {
                    imageID = Photo.GetPrimary(fromUsername).Id;
                }
                catch (NotFoundException)
                {
                    User user = null;
                    try
                    {
                        user = User.Load(fromUsername);
                        imageID = ImageHandler.GetPhotoIdByGender(user.Gender);
                    }
                    catch (NotFoundException) { return; }
                }
                string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);

                foreach (string friendUsername in usernames)
                {
                    if (toUsername == friendUsername) continue;

                    User.SendOnlineEventNotification(fromUsername, friendUsername, text, thumbnailUrl,
                                                         UrlRewrite.CreateShowUserUrl(toUsername));
                }
            }
        }
Example #21
0
        protected void btnEmbedVideo_Click(object sender, EventArgs e)
        {
            string thumbUrl = (string)ViewState["UploadVideo_ThumbUrl"];
            string videoUrl = (string)ViewState["UploadVideo_VideoUrl"];
            string title = (string)ViewState["UploadVideo_Title"];

            VideoEmbed embed = new VideoEmbed(((PageBase)Page).CurrentUserSession.Username, videoUrl);
            embed.ThumbUrl = thumbUrl;
            embed.Title = title;
            embed.Save();

            #region Add NewFriendYouTubeUpload Event

            Event newEvent = new Event(embed.Username);

            newEvent.Type = Event.eType.NewFriendYouTubeUpload;
            NewFriendYouTubeUpload newFriendYouTubeUpload = new NewFriendYouTubeUpload();
            newFriendYouTubeUpload.YouTubeUploadID = embed.Id;
            newEvent.DetailsXML = Misc.ToXml(newFriendYouTubeUpload);

            newEvent.Save();

            string[] usernames = Classes.User.FetchMutuallyFriends(embed.Username);

            foreach (string friendUsername in usernames)
            {
                if (Config.Users.NewEventNotification)
                {
                    if (CurrentUserSession != null)
                    {
                        string text = String.Format("Your friend {0} has uploaded a new video".Translate(),
                                                      "<b>" + CurrentUserSession.Username + "</b>");
                        int imageID = 0;
                        try
                        {
                            imageID = Photo.GetPrimary(CurrentUserSession.Username).Id;
                        }
                        catch (NotFoundException)
                        {
                            imageID = ImageHandler.GetPhotoIdByGender(CurrentUserSession.Gender);
                        }
                        string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                        Classes.User.SendOnlineEventNotification(embed.Username, friendUsername,
                                                                 text, thumbnailUrl,
                                                                 UrlRewrite.CreateShowUserUrl(embed.Username));
                    }
                }
            }

            #endregion

            ShowEmbeddedVideos();
        }
Example #22
0
        /// <summary>
        /// Handles the Click event of the btnApprove control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void btnApprove_Click(object sender, EventArgs e)
        {
            if (!HasWriteAccess)
                return;
            
            Photo photo = Photo.Fetch(photoID);
            if (Config.Photos.EnableExplicitPhotos)
            {
                photo.ExplicitPhoto = chkExplicitPhoto.Checked;
                if (photo.ExplicitPhoto && Config.Photos.MakeExplicitPhotosPrivate)
                {
                    photo.PrivatePhoto = true;
                }
            }

            if (photo.ManualApproval)
            {
                photo.ManualApproval = false;
                photo.Save(false);
                CommunityPhotoApproval.DeleteByPhotoID(photo.Id);
                Classes.User.SetPhotoModerationApprovalScore(photo.Id, true,
                                                                 Config.CommunityModeratedSystem.ScoresForCorrectOpinion,
                                                                 Config.CommunityModeratedSystem.PenaltyForIncorrectOpinion);
            }

            photo.ApprovePhoto(CurrentAdminSession.Username);

            if (!photo.PrivatePhoto)
            {
                #region Add Event

                Event newEvent = new Event(photo.Username);

                newEvent.Type = Event.eType.NewFriendPhoto;
                NewFriendPhoto newFriendPhoto = new NewFriendPhoto();
                newFriendPhoto.PhotoID = photo.Id;
                newEvent.DetailsXML = Misc.ToXml(newFriendPhoto);

                newEvent.Save();

                string[] usernames = Classes.User.FetchMutuallyFriends(photo.Username);

                foreach (string friendUsername in usernames)
                {
                    if (Config.Users.NewEventNotification)
                    {
                        string text = String.Format("Your friend {0} has uploaded a new photo".TranslateA(),
                                                      "<b>" + photo.Username + "</b>");
                        string thumbnailUrl = ImageHandler.CreateImageUrl(photo.Id, 50, 50, false, true, true);
                        Classes.User.SendOnlineEventNotification(photo.Username, friendUsername,
                                                                 text, thumbnailUrl,
                                                                 UrlRewrite.CreateShowUserPhotosUrl(photo.Username));
                    }
                }

                #endregion
            }
            

            Classes.User.AddScore(photo.Username, Config.UserScores.ApprovedPhoto, "ApprovedPhoto");
            try
            {
                MiscTemplates.ApprovePhotoMessage approvePhotoMessageTemplate =
                    new MiscTemplates.ApprovePhotoMessage(photo.User.LanguageId);
                Message.Send(Config.Users.SystemUsername, photo.User.Username, approvePhotoMessageTemplate.Message, 0);
            }
            catch (NotFoundException ex)
            {
                Log(ex);
            }

            Response.Redirect("ApprovePhotos.aspx");
        }
Example #23
0
        protected void btnSaveChanges_Click(object sender, EventArgs e)
        {
            if (ValidateData())
            {
                Classes.Blog blog = Classes.Blog.Load(CurrentUserSession.Username);

                if (permissionCheckResult == PermissionCheckResult.Yes ||
                    (CurrentUserSession.Level != null &&
                                       CurrentUserSession.Level.Restrictions.CanCreateBlogs))
                {
                }
                else if (permissionCheckResult == PermissionCheckResult.YesButPlanUpgradeNeeded ||
                         permissionCheckResult == PermissionCheckResult.YesButMoreCreditsNeeded)
                {
                    Global.GetSessionState()["BillingPlanOption"] = CurrentUserSession.BillingPlanOptions.CanCreateBlogs;
                    Response.Redirect("~/ManageProfile.aspx?sel=payment");
                    return;
                }
                else if (permissionCheckResult == PermissionCheckResult.No)
                {
                    ((PageBase)Page).StatusPageMessage = Lang.Trans("You are not allowed to create blogs!");
                    Response.Redirect("ShowStatus.aspx");
                    return;
                }

                BlogPost blogPost = null;
                string content = htmlEditor != null ? htmlEditor.Content : ckeditor.Text;
                if (BlogPostId == -1)
                {
                    //if (Config.Credits.Required && Config.Credits.CreditsForBlogPost > 0)
                    //{
                    #region Charge credits

                        //if (!Config.Users.FreeForFemales ||
                        //    CurrentUserSession.Gender != User.eGender.Female)
                        //{
                    if (permissionCheckResult == PermissionCheckResult.YesWithCredits)
                    {
                        int creditsLeft = CurrentUserSession.Credits - CurrentUserSession.BillingPlanOptions.CanCreateBlogs.Credits;

                        if (creditsLeft < 0)
                        {
                            Global.GetSessionState()["BillingPlanOption"] = CurrentUserSession.BillingPlanOptions.CanCreateBlogs;
                            Response.Redirect("~/ManageProfile.aspx?sel=payment");
                            return;
                        }

                        var user = Classes.User.Load(CurrentUserSession.Username);
                        user.Credits -= CurrentUserSession.BillingPlanOptions.CanCreateBlogs.Credits;
                        user.Update(true);
                        CurrentUserSession.Credits = user.Credits;
                    }       
                        //}

                    #endregion
                    //}

                    if (Config.Misc.EnableBadWordsFilterBlogs)
                    {
                        blogPost = BlogPost.Create(blog.Id, Parsers.ProcessBadWords(txtName.Text.Trim()),
                                                   Parsers.ProcessBadWords(content.Trim()));
                    }
                    else
                    {
                        blogPost = BlogPost.Create(blog.Id, txtName.Text.Trim(), content.Trim());    
                    }
                }
                else
                {
                    blogPost = BlogPost.Load(BlogPostId);

                    if (Config.Misc.EnableBadWordsFilterBlogs)
                    {
                        blogPost.Title = Parsers.ProcessBadWords(txtName.Text.Trim());
                        blogPost.Content = Parsers.ProcessBadWords(content.Trim());
                    }
                    else
                    {
                        blogPost.Title = txtName.Text.Trim();
                        blogPost.Content = content.Trim();    
                    }
                }
                blogPost.Save();

                if (BlogPostId == -1 && blogPost.Approved)
                {
                    #region Add NewFriendBlogPost Event

                    Event newEvent = new Event(CurrentUserSession.Username);

                    newEvent.Type = Event.eType.NewFriendBlogPost;
                    NewFriendBlogPost newFriendBlogPost = new NewFriendBlogPost();
                    newFriendBlogPost.BlogPostID = blogPost.Id;
                    newEvent.DetailsXML = Misc.ToXml(newFriendBlogPost);

                    newEvent.Save();

                    string[] usernames = User.FetchMutuallyFriends(CurrentUserSession.Username);

                    foreach (string friendUsername in usernames)
                    {
                        if (Config.Users.NewEventNotification)
                        {
                            string text = String.Format("Your friend {0} has a new blog post: {1}".Translate(),
                                                    "<b>" + CurrentUserSession.Username + "</b>",
                                                    Server.HtmlEncode(blogPost.Title));
                            int imageID = 0;
                            try
                            {
                                imageID = Photo.GetPrimary(CurrentUserSession.Username).Id;
                            }
                            catch (NotFoundException)
                            {
                                imageID = ImageHandler.GetPhotoIdByGender(CurrentUserSession.Gender);
                            }
                            string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                            Classes.User.SendOnlineEventNotification(CurrentUserSession.Username, friendUsername,
                                                                     text, thumbnailUrl,
                                                                     UrlRewrite.CreateShowUserBlogUrl(
                                                                         CurrentUserSession.Username, blogPost.Id));
                        }
                    }

                    #endregion
                }

                txtName.Text = "";
                if (ckeditor != null)
                    ckeditor.Text = "";
                else if (htmlEditor != null)
                    htmlEditor.Content = "";
                if (BlogPostId != -1)
                {
                    BlogPostId = -1;
                    lblError.Text = Lang.Trans("Post has been edited successfully.");
                    Visible = false;
                    OnSaveChangesClick(e);
                }
                else
                {
                    lblError.Text = Lang.Trans("Post has been added successfully.");
                }
            }
        }
Example #24
0
 private static Event[] filterEvents(List<Event> events, Event e)
 {
     List<Event> result = null;
     result = events.Where(u => u.FromUsername == e.FromUsername && u.FromGroup == e.FromGroup && u.Type == e.Type && u.Date >= e.Date.AddDays(-1)).ToList();
     events.RemoveAll(result.Contains);
     //            if (e.Type == eType.NewFriendFriend)
     //            {
     //                events.RemoveAll(ev => ev.Type == eType.NewFriendFriend &&
     //                                 result.Exists(
     //                                     r => r.FromUsername == Misc.FromXml<NewFriendFriend>(ev.DetailsXML).Username
     //                                     && ev.FromUsername == Misc.FromXml<NewFriendFriend>(r.DetailsXML).Username));
     //            }
     //            else if (e.Type == eType.RemovedFriendFriend)
     //            {
     //                events.RemoveAll(ev => ev.Type == eType.RemovedFriendFriend &&
     //                                 result.Exists(
     //                                     r => r.FromUsername == Misc.FromXml<RemovedFriendFriend>(ev.DetailsXML).Username
     //                                     && ev.FromUsername == Misc.FromXml<RemovedFriendFriend>(r.DetailsXML).Username));
     //            }
     //            else if (e.Type == eType.NewFriendRelationship)
     //            {
     //                events.RemoveAll(ev => ev.Type == eType.NewFriendRelationship &&
     //                                 result.Exists(
     //                                     r => r.FromUsername == Misc.FromXml<NewFriendRelationship>(ev.DetailsXML).Username
     //                                     && ev.FromUsername == Misc.FromXml<NewFriendRelationship>(r.DetailsXML).Username));
     //            }
     //            else if (e.Type == eType.RemovedFriendRelationship)
     //            {
     //                events.RemoveAll(ev => ev.Type == eType.RemovedFriendRelationship &&
     //                                 result.Exists(
     //                                     r => r.FromUsername == Misc.FromXml<RemovedFriendRelationship>(ev.DetailsXML).Username
     //                                     && ev.FromUsername == Misc.FromXml<RemovedFriendRelationship>(r.DetailsXML).Username));
     //            }
     return result.ToArray();
 }
Example #25
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
                AudioUpload[] audioUploads = AudioUpload.Load(null, CurrentUserSession.Username, null, null);

                if (audioUploads.Length >= CurrentUserSession.BillingPlanOptions.MaxAudioUploads.Value
                    && (CurrentUserSession.Level != null && audioUploads.Length >= CurrentUserSession.Level.Restrictions.MaxAudioUploads))
                {
                    ((PageBase)Page).StatusPageMessage = Lang.Trans("You cannot upload more audio files!");
                    Response.Redirect("ShowStatus.aspx");
                    return;
                }

            if (!fileAudio.HasFile)
            {
                lblError.Text = Lang.Trans("Please select audio file!");
                return;
            }

            string title = txtTitle.Text.Length > 0 ? txtTitle.Text : Path.GetFileNameWithoutExtension(fileAudio.FileName);

            //string tempfile = Path.GetTempFileName();
            //fileAudio.SaveAs(tempfile);

            var audioUpload = new AudioUpload(CurrentUserSession.Username);
            if (CurrentUserSession != null)
            {
                if (CurrentUserSession.BillingPlanOptions.AutoApproveAudioUploads.Value
                    || CurrentUserSession.Level != null && CurrentUserSession.Level.Restrictions.AutoApproveAudioUploads)
                {
                    audioUpload.Approved = true;
                }
            }
            audioUpload.Title = title;
            audioUpload.IsPrivate = cbPrivateAudio.Checked;
            audioUpload.Save(); // Save to get new ID

            if (audioUpload.Approved && !audioUpload.IsPrivate)
            {
                #region Add NewFriendAudioUpload Event

                Event newEvent = new Event(audioUpload.Username);

                newEvent.Type = Event.eType.NewFriendAudioUpload;
                NewFriendAudioUpload newFriendAudioUpload = new NewFriendAudioUpload();
                newFriendAudioUpload.AudioUploadID = audioUpload.Id;
                newEvent.DetailsXML = Misc.ToXml(newFriendAudioUpload);

                newEvent.Save();

                string[] usernames = Classes.User.FetchMutuallyFriends(audioUpload.Username);

                foreach (string friendUsername in usernames)
                {
                    if (Config.Users.NewEventNotification)
                    {
                        string text = String.Format("Your friend {0} has uploaded a new audio".Translate(),
                                              "<b>" + audioUpload.Username + "</b>");
                        int imageID = 0;
                        try
                        {
                            imageID = Photo.GetPrimary(audioUpload.Username).Id;
                        }
                        catch (NotFoundException)
                        {
                            User user = null;
                            try
                            {
                                user = User.Load(audioUpload.Username);
                                imageID = ImageHandler.GetPhotoIdByGender(user.Gender);
                            }
                            catch (NotFoundException) { break; }
                        }
                        string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                        User.SendOnlineEventNotification(audioUpload.Username, friendUsername,
                                                                 text, thumbnailUrl,
                                                                 UrlRewrite.CreateShowUserUrl(audioUpload.Username));
                    }
                }

                #endregion
            }

            string userFilesPath = "~/UserFiles/" + CurrentUserSession.Username;
            string userFilesDir = Server.MapPath(userFilesPath);
            if (!Directory.Exists(userFilesDir))
            {
                Directory.CreateDirectory(userFilesDir);
            }

            fileAudio.SaveAs(userFilesDir + @"\audio_" + audioUpload.Id + ".mp3");

            //File.Move(tempfile, userFilesDir + @"\audio_" + audioUpload.Id + ".mp3");
        }
Example #26
0
 private static void removeDuplicateEvents(List<Event> events, Event e)
 {
     events.Remove(e);
     if (e.Type == eType.NewFriendRelationship)
     {
         events.RemoveAll(ev => ev.Type == eType.NewFriendRelationship &&
                              e.FromUsername == Misc.FromXml<NewFriendRelationship>(ev.DetailsXML).Username
                              && ev.FromUsername == Misc.FromXml<NewFriendRelationship>(e.DetailsXML).Username);
     }
     else if (e.Type == eType.RemovedFriendRelationship)
     {
         events.RemoveAll(ev => ev.Type == eType.RemovedFriendRelationship &&
                          e.FromUsername == Misc.FromXml<RemovedFriendRelationship>(ev.DetailsXML).Username
                              && ev.FromUsername == Misc.FromXml<RemovedFriendRelationship>(e.DetailsXML).Username);
     }
     else if (e.Type == eType.NewFriendFriend)
     {
         events.RemoveAll(ev => ev.Type == eType.NewFriendFriend &&
                          e.FromUsername == Misc.FromXml<NewFriendFriend>(ev.DetailsXML).Username
                              && ev.FromUsername == Misc.FromXml<NewFriendFriend>(e.DetailsXML).Username);
     }
     else if (e.Type == eType.RemovedFriendFriend)
     {
         events.RemoveAll(ev => ev.Type == eType.RemovedFriendFriend &&
                          e.FromUsername == Misc.FromXml<RemovedFriendFriend>(ev.DetailsXML).Username
                              && ev.FromUsername == Misc.FromXml<RemovedFriendFriend>(e.DetailsXML).Username);
     }
 }
Example #27
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (CurrentUserSession != null)
            {
                #region validate fields

                string title = txtTitle.Text.Trim();
                string description = txtDescription.Text.Trim();
                DateTime date = DateTime.MinValue;
                string location = txtLocation.Text.Trim();

                if (title.Length == 0)
                {
                    lblError.Text = Lang.Trans("Please enter event name.");
                    return;
                }

                if (description.Length == 0)
                {
                    lblError.Text = Lang.Trans("Please enter description.");
                    return;
                }

                if (!datePicker1.ValidDateEntered)
                {
                    lblError.Text = Lang.Trans("Please select valid date!");
                    return;
                }

                if (txtHoursMin.Text.Trim().Length > 0)
                {
                    date =
                        datePicker1.SelectedDate.AddHours(DateTime.Parse(txtHoursMin.Text.Trim()).Hour).AddMinutes(
                            DateTime.Parse(txtHoursMin.Text.Trim()).Minute);
                }

                #endregion

                GroupEvent groupEvent = new GroupEvent(GroupID, CurrentUserSession.Username);
                groupEvent.Title = Server.HtmlEncode(title);
                groupEvent.Description = Server.HtmlEncode(description);
                groupEvent.Date = date == DateTime.MinValue ? datePicker1.SelectedDate : date;
                groupEvent.Location = location;

                groupEvent.Save();

                if (fuImage.PostedFile.FileName.Length > 0)
                {
                    Image image = null;
                    try
                    {
                        image = Image.FromStream(fuImage.PostedFile.InputStream);
                    }
                    catch
                    {
                        lblError.Text = Lang.Trans("Invalid image!");
                        return;
                    }

                    GroupEvent.SaveImage(groupEvent.ID.Value, image);

                    string cacheFileDir = Config.Directories.ImagesCacheDirectory + "/" + groupEvent.ID % 10;
                    string cacheFileMask = String.Format("groupEventID{0}_*.jpg", groupEvent.ID);
                    foreach (string file in Directory.GetFiles(cacheFileDir, cacheFileMask))
                    {
                        File.Delete(file);
                    }
                }

                #region Add NewGroupEvent Event

                Event newEvent = new Event(GroupID);

                newEvent.Type = Event.eType.NewGroupEvent;
                NewGroupEvent newGroupEvent = new NewGroupEvent();
                newGroupEvent.GroupEventID = groupEvent.ID.Value;
                newEvent.DetailsXML = Misc.ToXml(newGroupEvent);

                newEvent.Save();

                Group group = Group.Fetch(GroupID);
                GroupMember[] groupMembers = GroupMember.Fetch(GroupID, true);

                foreach (GroupMember groupMember in groupMembers)
                {
                    if (groupMember.Username == CurrentUserSession.Username) continue;

                    if (Config.Users.NewEventNotification)
                    {
                        if (group != null)
                        {
                            string text = String.Format("There is a new event {0} in the {1} group".Translate(),
                                                        "<b>" + Server.HtmlEncode(groupEvent.Title) + "</b>",
                                                        Parsers.ProcessGroupName(group.Name));
                            string thumbnailUrl = GroupIcon.CreateImageUrl(group.ID, 50, 50, true);
                            User.SendOnlineEventNotification(CurrentUserSession.Username, groupMember.Username, text,
                                                             thumbnailUrl,
                                                             UrlRewrite.CreateShowGroupEventsUrl(group.ID.ToString()));
                        }
                    }
                }

                #endregion

                Response.Redirect(UrlRewrite.CreateShowGroupEventsUrl(GroupID.ToString()));
            }
        }
Example #28
0
        protected void btnSubmitNewComment_Click(object sender, EventArgs e)
        {
            if (txtNewComment.Text.Trim() == "")
            {
                return;
            }

            if (CurrentUserSession != null)
            {
                var comment = new PhotoComment(CurrentPhotoId, CurrentUserSession.Username)
                                  {
                                      Comment = (Config.Misc.EnableBadWordsFilterComments
                                                     ? Parsers.ProcessBadWords(txtNewComment.Text)
                                                     : txtNewComment.Text)
                                  };

                comment.Save();

                User.AddScore(CurrentUserSession.Username,
                              Config.UserScores.LeftComment, "LeftPhotoComment");
                User.AddScore(User.Username, Config.UserScores.ReceivedComment, "ReceivedPhotoComment");

                Photo photo = null;
                try
                {
                    photo = Photo.Fetch(CurrentPhotoId);
                }
                catch (NotFoundException) { return; }

                if (!photo.PrivatePhoto)
                {
                    #region Add NewPhotoComment Event

                    var newEvent = new Event(User.Username) { Type = Event.eType.NewPhotoComment };
                    var newPhotoComment = new NewPhotoComment();
                    newPhotoComment.PhotoCommentID = comment.ID.Value;
                    newEvent.DetailsXML = Misc.ToXml(newPhotoComment);

                    newEvent.Save();

                    if (Config.Users.NewEventNotification)
                    {
                        string text = String.Format("User {0} has left a new comment on one of your photos".Translate(),
                                                  "<b>" + CurrentUserSession.Username + "</b>");
                        int imageID = 0;
                        try
                        {
                            imageID = Photo.GetPrimary(CurrentUserSession.Username).Id;
                        }
                        catch (NotFoundException)
                        {
                            imageID = ImageHandler.GetPhotoIdByGender(CurrentUserSession.Gender);
                        }
                        string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                        User.SendOnlineEventNotification(CurrentUserSession.Username, User.Username, text, thumbnailUrl,
                                                         "Comments.aspx");
                    }

                    #endregion
                }
            }

            loadComments = true;
        }
        protected void dgPendingApproval_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            if (!HasWriteAccess)
                return;

            if (e.CommandName == "Approve")
            {
                string[] parameters = ((string)e.CommandArgument).Split(':');
                if (parameters.Length == 2)
                {
                    string username = parameters[0];
                    int id = Convert.ToInt32(parameters[1]);
                    BlogPost blogPost = null;
                    try
                    {
                        blogPost = BlogPost.Load(id);
                    }
                    catch (NotFoundException) { return; }
                    blogPost.Approved = true;
                    blogPost.Save();

                    #region Add NewFriendBlogPost Event

                    Event newEvent = new Event(username);

                    newEvent.Type = Event.eType.NewFriendBlogPost;
                    NewFriendBlogPost newFriendBlogPost = new NewFriendBlogPost();
                    newFriendBlogPost.BlogPostID = blogPost.Id;
                    newEvent.DetailsXML = Misc.ToXml(newFriendBlogPost);

                    newEvent.Save();

                    string[] usernames = Classes.User.FetchMutuallyFriends(username);

                    foreach (string friendUsername in usernames)
                    {
                        if (Config.Users.NewEventNotification)
                        {
                            string text = String.Format("Your friend {0} has a new blog post: {1}".TranslateA(),
                                                    "<b>" + username + "</b>",
                                                    Server.HtmlEncode(blogPost.Title));
                            int imageID = 0;
                            try
                            {
                                imageID = Photo.GetPrimary(username).Id;
                            }
                            catch (NotFoundException)
                            {
                                Classes.User user = null;
                                try
                                {
                                    user = Classes.User.Load(username);
                                    imageID = ImageHandler.GetPhotoIdByGender(user.Gender);
                                }
                                catch (NotFoundException)
                                {
                                    continue;
                                }
                            }
                            string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                            Classes.User.SendOnlineEventNotification(username, friendUsername,
                                                                     text, thumbnailUrl,
                                                                     UrlRewrite.CreateShowUserBlogUrl(
                                                                         username, blogPost.Id));
                        }
                    }

                    #endregion

                    PopulateDataGrid();
                }
            }
            else if (e.CommandName == "Reject")
            {
                string[] parameters = ((string)e.CommandArgument).Split(':');
                if (parameters.Length == 2)
                {
                    BlogPost.Delete(Convert.ToInt32(parameters[1]));
                    PopulateDataGrid();
                }
            }
        }
Example #30
0
        protected void btnJoinEvent_Click(object sender, EventArgs e)
        {
            if (CurrentUserSession != null)
            {
                GroupEvent.SetAttender(EventID, CurrentUserSession.Username);

                var newEvent = new Event(CurrentUserSession.Username)
                {
                    Type = Event.eType.FriendAttendingEvent
                };

                var friendAttendingEvent = new FriendAttendingEvent();
                friendAttendingEvent.EventID = EventID;
                newEvent.DetailsXML = Misc.ToXml(friendAttendingEvent);

                newEvent.Save();

                string[] usernames = User.FetchMutuallyFriends(CurrentUserSession.Username);

                foreach (string friendUsername in usernames)
                {
                    if (Config.Users.NewEventNotification)
                    {
                        if (CurrentEvent != null)
                        {
                            Group group = Group.Fetch(CurrentEvent.GroupID);
                            if (group != null)
                            {
                                string text =
                                    String.Format(
                                        "Your friend {0} is attending the {1} event from the {2} group".Translate(),
                                        "<b>" + CurrentUserSession.Username + "</b>",
                                        Server.HtmlEncode(CurrentEvent.Title),
                                        Server.HtmlEncode(group.Name));
                                int imageID;
                                try
                                {
                                    imageID = Photo.GetPrimary(CurrentUserSession.Username).Id;
                                }
                                catch (NotFoundException)
                                {
                                    imageID = ImageHandler.GetPhotoIdByGender(CurrentUserSession.Gender);
                                }
                                string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                                User.SendOnlineEventNotification(CurrentUserSession.Username, friendUsername, text,
                                                                 thumbnailUrl,
                                                                 UrlRewrite.CreateShowGroupEventsUrl(group.ID.ToString()));
                            }
                        }
                    }
                }

                loadAttenders(false);

                pnlAttenders.Visible = true;
            }
        }