Ejemplo n.º 1
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;
            }
        }
Ejemplo n.º 2
0
        private void AddNewFriendFriendEvent(string username, string favoriteUsername)
        {
            Event newEvent = new Event(username);

            newEvent.Type = Event.eType.NewFriendFriend;
            NewFriendFriend newFriendFriend = new NewFriendFriend();
            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} and {1} are now 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));
                }
            }
        }
Ejemplo n.º 3
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");
        }
Ejemplo n.º 4
0
        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 = 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 = 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);
                                    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);
                    }
                }
            }
        }
Ejemplo n.º 5
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());
            }
        }
Ejemplo n.º 6
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");
        }
Ejemplo n.º 7
0
        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.CreateMobileShowUserUrl(CurrentUserSession.Username)
                        };
                        RealtimeNotification.SendNotification(notification);
                    }
                }

                #endregion
            }
            else
            {
                lblStatusText.Text = "Not set".Translate();
                CurrentUserSession.StatusText = null;
                CurrentUserSession.Update();
            }

            pnlEditStatusText.Visible = false;
            pnlViewStatusText.Visible = true;
        }
Ejemplo n.º 8
0
        private void dgPendingApproval_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            if (!HasWriteAccess)
                return;

            if (e.CommandName == "Approve")
            {
                string[] parameters = ((string) e.CommandArgument).Split(':');
                if (parameters.Length == 2)
                {
                    ProfileAnswer answer = ProfileAnswer.Fetch(parameters[0], Convert.ToInt32(parameters[1]));
                    answer.Approved = true;
                    answer.Save();

                    #region Add FriendUpdatedProfile Event

                    Event newEvent = new Event(parameters[0]);

                    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(parameters[0]);

                    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>" + parameters[0] + "</b>", answer.Question.Name);
                            int imageID = 0;
                            try
                            {
                                imageID = Photo.GetPrimary(parameters[0]).Id;
                            }
                            catch (NotFoundException)
                            {
                                User user = null;
                                try
                                {
                                    user = Classes.User.Load(parameters[0]);
                                    imageID = ImageHandler.GetPhotoIdByGender(user.Gender);
                                }
                                catch (NotFoundException)
                                {
                                    continue;
                                }
                            }
                            string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                            Classes.User.SendOnlineEventNotification(parameters[0], friendUsername, text, thumbnailUrl,
                                                                     UrlRewrite.CreateShowUserUrl(parameters[0]));
                        }
                    }

                    #endregion

                    PopulateDataGrid();
                }
            }
            else if (e.CommandName == "Reject")
            {
                string[] parameters = ((string) e.CommandArgument).Split(':');
                if (parameters.Length == 2)
                {
                    ProfileAnswer.Delete(parameters[0], Convert.ToInt32(parameters[1]));
                    PopulateDataGrid();
                }
            }
        }
Ejemplo n.º 9
0
        protected void lnkSave_Click(object sender, EventArgs e)
        {
            var photo = (Photo)Session["temp_photo"];

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

            // ReSharper disable AssignNullToNotNullAttribute
            photo.Image = Image.FromFile(Session["temp_photo_fileName"] as string);
            // ReSharper restore AssignNullToNotNullAttribute

            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 (Session["temp_photo_fileName"] != null)
                    File.Delete((string)Session["temp_photo_fileName"]);
            }
            catch (IOException)
            {
            }

            Session["temp_photo"] = null;
            Session["temp_photo_fileName"] = null;

            Response.Redirect("~/Profile.aspx?sel=photos");
        }
Ejemplo n.º 10
0
        protected void btnSubmitNewComment_Click(object sender, EventArgs e)
        {
            if (txtNewComment.Text.Trim() == "")
            {
                return;
            }

            if (CurrentUserSession != null)
            {
                string commentText = Config.Misc.EnableBadWordsFilterComments
                    ? Parsers.ProcessBadWords(txtNewComment.Text) : txtNewComment.Text;
                Comment comment = Comment.Create(CurrentUserSession.Username,
                                                 User.Username, commentText);
                comment.Save();

                #region Add NewProfileComment Event

                var newEvent = new Event(User.Username) { Type = Event.eType.NewProfileComment };

                var newProfileComment = new NewProfileComment();
                newProfileComment.CommentID = comment.Id;
                newEvent.DetailsXML = Misc.ToXml(newProfileComment);

                newEvent.Save();

                if (Config.Users.NewEventNotification)
                {
                    string text = String.Format("User {0} has left a new comment on your profile".Translate(),
                                              "<b>" + CurrentUserSession.Username + "</b>");
                    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, User.Username, text, thumbnailUrl,
                                                     "Comments.aspx");
                }

                #endregion

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

            loadComments = true;
        }
Ejemplo n.º 11
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 = 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(" ");
        }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
        protected void btnEnterContest_Click(object sender, EventArgs e)
        {
            int photoId = 0;
            for (int i = 0; i < dlPhotos.Items.Count; i++)
            {
                RadioButton rb = (RadioButton)dlPhotos.Items[i].FindControl("rbPhoto");
                if (rb == null) continue;
                if (rb.Checked)
                {
                    HiddenField hid = (HiddenField)dlPhotos.Items[i].FindControl("hidPhotoId");
                    int.TryParse(hid.Value, out photoId);
                    break;
                }
            }
            if (photoId == 0)
            {
                lblError.Text = Lang.Trans("Please select a photo!");
                return;
            }

            PhotoContestEntry prevEntry = PhotoContestEntry.Load(contestId, CurrentUserSession.Username);
            if (prevEntry != null)
            {
                lblError.Text = Lang.Trans("You already participate in this contest!");
                return;
            }

            PhotoContestEntry entry = new PhotoContestEntry(contestId, CurrentUserSession.Username, photoId);
            entry.Save();

            #region Add Event

            Event newEvent = new Event(CurrentUserSession.Username);

            newEvent.Type = Event.eType.FriendEntersContest;
            FriendEntersContest friendEntersContest = new FriendEntersContest();
            friendEntersContest.PhotoContestEntriesID = entry.Id;
            newEvent.DetailsXML = Misc.ToXml(friendEntersContest);

            newEvent.Save();

            PhotoContest contest = PhotoContest.Load(entry.ContestId);
            string[] usernames = Classes.User.FetchMutuallyFriends(CurrentUserSession.Username);

            foreach (string friendUsername in usernames)
            {
                if (Config.Users.NewEventNotification)
                {
                    if (contest != null)
                    {
                        string text =
                                    String.Format("Your friend {0} has entered the {1} contest".Translate(),
                                                  "<b>" + CurrentUserSession.Username + "</b>", contest.Name);
                        string thumbnailUrl = ImageHandler.CreateImageUrl(photoId, 50, 50, false, true, false);
                        Classes.User.SendOnlineEventNotification(CurrentUserSession.Username, friendUsername, text,
                                                                 thumbnailUrl, "PhotoContest.aspx?cid" + contest.Id);
                    }
                }
            }

            #endregion

            StatusPageMessage = Lang.Trans("Your contest entry has been saved!");
            StatusPageLinkText = Lang.Trans("Back to contest");
            StatusPageLinkURL = "PhotoContest.aspx?cid=" + contestId;
            Response.Redirect("ShowStatus.aspx");
        }
Ejemplo n.º 14
0
        /// <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()));
            }
        }
Ejemplo n.º 15
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();
        }
Ejemplo n.º 16
0
        protected void lnkLeaveGroup_Click(object sender, EventArgs e)
        {
            if (CurrentUserSession != null)
            {
                if (Group.Owner == CurrentUserSession.Username)
                {
                    EditGroup1.ShowMessage(Misc.MessageType.Error, Lang.Trans("You are the owner of this group. Please transfer ownership of this group first."));
                    mvGroup.SetActiveView(viewManageGroup);
                    enableMenuLinks();
                    lnkManageGroup.Enabled = false;
                }
                else
                {
                    GroupMember.Delete(GroupID, CurrentUserSession.Username);

                    #region Add FriendLeftGroup Event

                    Event newEvent = new Event(CurrentUserSession.Username);

                    newEvent.Type = Event.eType.FriendLeftGroup;
                    FriendLeftGroup friendLeftGroup = new FriendLeftGroup();
                    friendLeftGroup.GroupID = GroupID;
                    newEvent.DetailsXML = Misc.ToXml(friendLeftGroup);

                    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 left 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

                    if (CurrentGroupMember != null && CurrentGroupMember.Active)
                    {
                        Group.ActiveMembers--;
                        Group.Save();
                    }

                    Response.Redirect("~/Groups.aspx?show=mg");
                }    
            }
        }
Ejemplo n.º 17
0
        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();
                }
            }
        }
Ejemplo n.º 18
0
        private static void AsyncProcessMailerQueue(object data)
        {
            if (mailerLock)
            {
                return;
            }

            try
            {
                mailerLock = true;

                BirthdaySearch search = new BirthdaySearch();

                UserSearchResults results = search.GetResults();

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

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

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

                        foreach (string recipient in usernames)
                        {
                            User u = null;
                            try
                            {
                                u = 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);
                                User.SendOnlineEventNotification(user.Username, recipient, text, thumbnailUrl,
                                                                         UrlRewrite.CreateShowUserUrl(user.Username));
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                Global.Logger.LogError("FriendBirthdayEmails", err);
            }
            finally
            {
                mailerLock = false;
            }
        }
Ejemplo n.º 19
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");
        }
Ejemplo n.º 20
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");
        }
Ejemplo n.º 21
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)
                {
                    Session["BillingPlanOption"] = CurrentUserSession.BillingPlanOptions.CanCreateBlogs;
                    Response.Redirect("~/Profile.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)
                        {
                            Session["BillingPlanOption"] = CurrentUserSession.BillingPlanOptions.CanCreateBlogs;
                            Response.Redirect("~/Profile.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.");
                }
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Handles the ItemCommand event of the dgPendingApproval control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void dgPendingApproval_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            if (!HasWriteAccess)
                return;

            int groupID = Int32.Parse(GroupIDs[e.Item.ItemIndex]);
            Group group = Group.Fetch(groupID/*Convert.ToInt32(e.CommandArgument)*/);

            if (group != null)
            {
                if (e.CommandName == "Approve")
                {
                    try
                    {
                        User owner = Classes.User.Load(group.Owner);
                        MiscTemplates.ApproveGroupMessage approveGroupTemplate =
                            new MiscTemplates.ApproveGroupMessage(owner.LanguageId);

                        #region Add NewFriendGroup Event

                        Event newEvent = new Event(group.Owner);

                        newEvent.Type = Event.eType.NewFriendGroup;
                        NewFriendGroup newFriendGroup = new NewFriendGroup();
                        newFriendGroup.GroupID = group.ID;
                        newEvent.DetailsXML = Misc.ToXml(newFriendGroup);

                        newEvent.Save();

                        int imageID = 0;
                        try
                        {
                            imageID = Photo.GetPrimary(group.Owner).Id;
                        }
                        catch (NotFoundException)
                        {
                            imageID = ImageHandler.GetPhotoIdByGender(owner.Gender);
                        }

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

                        #endregion

                        Message msg = new Message(Config.Users.SystemUsername, group.Owner);
                        msg.Body = approveGroupTemplate.Message.Replace("%%GROUP%%", group.Name);
                        msg.Send();
                    }
                    catch (NotFoundException ex)
                    {
                        Log(ex);
                    }

                    group.Approved = true;
                    group.Save();
                }
                else if (e.CommandName == "Reject")
                {
                    string reason = String.Empty;
                    TextBox txtReason = (TextBox) e.Item.FindControl("txtReason");

                    try
                    {
                        User user = Classes.User.Load(group.Owner);
                        MiscTemplates.RejectGroupMessage rejectGroupTemplate =
                            new MiscTemplates.RejectGroupMessage(user.LanguageId);
                        Message msg = new Message(Config.Users.SystemUsername, group.Owner);

                        reason = rejectGroupTemplate.WithReasonMessage;

                        if (txtReason.Text.Trim() != String.Empty)
                        {
                            reason =
                                reason.Replace("%%REASON%%", txtReason.Text.Trim()).Replace("%%GROUP%%", group.Name);
                            msg.Body = reason;
                        }
                        else
                        {
                            msg.Body = rejectGroupTemplate.WithNoReasonMessage.Replace("%%GROUP%%", group.Name);
                        }
                        msg.Send();
                    }
                    catch (NotFoundException ex)
                    {
                        Log(ex);
                    }

                    Group.Delete(groupID/*Convert.ToInt32(e.CommandArgument)*/);
                }

                Results = null;
            }
        }
Ejemplo n.º 23
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()));
            }
        }
Ejemplo n.º 24
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()));
        }
Ejemplo n.º 25
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 = 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
                }
            }
        }
Ejemplo n.º 26
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 =
                        Classes.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!");

                StatusPageMessage = message;

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

//                Response.Redirect("ShowStatus.aspx");
            }
            catch (AnswerRequiredException)
            {
            }
        }
Ejemplo n.º 27
0
        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;
            }
        }
Ejemplo n.º 28
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)
            {
            }
        }
Ejemplo n.º 29
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));
                }
            }
        }
Ejemplo n.º 30
0
        private static void AsyncProcessMailerQueue(object data)
        {
            if (mailerLock)
            {
                return;
            }

            try
            {
                mailerLock = true;

                if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
                {
                    using (var db = new AspNetDatingDataContext())
                    {
                        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 = 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 = User.Load(username);
                        }
                        catch (NotFoundException) { continue; }

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

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

                        foreach (string recipient in usernames)
                        {
                            User u = null;
                            try
                            {
                                u = 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);
                                User.SendOnlineEventNotification(user.Username, recipient, text, thumbnailUrl,
                                                                         UrlRewrite.CreateShowUserUrl(user.Username));
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                Global.Logger.LogError("FriendBirthdayEmails", err);
            }
            finally
            {
                mailerLock = false;
            }
        }