Example #1
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");
        }
        protected void btnApproveAll_Click(object sender, EventArgs e)
        {
            if (!HasWriteAccess)
                return;
            
            foreach (DataListItem item in listPendingApproval.Items)
            {
                int photoId = Convert.ToInt32(((LinkButton) item.Controls[1]).CommandArgument);

                Photo photo = Photo.Fetch(photoId);

                photo.ApprovePhoto(CurrentAdminSession.Username);

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

                    Event newEvent = new Event(photo.Username);

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

                    newEvent.Save();

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

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

                    #endregion 
                }

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

            PopulateDataGrid();
        }
Example #3
0
        public ApproveRejectPhotosResponse ApproveRejectPhotos(string username, string password,
                                                               ApproveRejectPhotosRequest req)
        {
            var resp = new ApproveRejectPhotosResponse();

            try
            {
                Classes.Admin admin = Classes.Admin.Authorize(username, password);

                if (Config.AdminSettings.ReadOnly
                    || (username != Config.Users.SystemUsername && Config.AdminSettings.AdminPermissionsEnabled
                        && (admin.Privileges.photoApproval & Classes.Admin.eAccess.Write) == 0))
                {
                    resp.Error = Lang.Trans("Access denied!");
                    return resp;
                }
            }
            catch (Exception err)
            {
                resp.Error = err.Message;
                return resp;
            }

            if (req.ApprovedPhotos != null)
            {
                foreach (ApprovedPhotoInfo photoInfo in req.ApprovedPhotos)
                {
                    Photo photo = Photo.Fetch(photoInfo.Id);
                    if (Config.Photos.EnableExplicitPhotos)
                    {
                        photo.ExplicitPhoto = photoInfo.Explicit;
                        if (photo.ExplicitPhoto && Config.Photos.MakeExplicitPhotosPrivate)
                        {
                            photo.PrivatePhoto = true;
                        }
                    }
                    photo.ApprovePhoto(username);
                    Classes.User.AddScore(photo.Username, Config.UserScores.ApprovedPhoto, "ApprovedPhoto");
                    try
                    {
                        var approvePhotoMessageTemplate =
                            new MiscTemplates.ApprovePhotoMessage(photo.User.LanguageId);
                        Message.Send(Config.Users.SystemUsername, photo.User.Username,
                                     approvePhotoMessageTemplate.Message, 0);
                    }
                    catch (NotFoundException ex)
                    {
                        Global.Logger.LogError(ex);
                    }
                }
            }

            if (req.RejectedPhotos != null)
            {
                foreach (RejectedPhotoInfo photoInfo in req.RejectedPhotos)
                {
                    Photo photo = Photo.Fetch(photoInfo.Id);
                    var rejectPhotoMessageTemplate =
                        new MiscTemplates.RejectPhotoMessage(photo.User.LanguageId);
                    string reasonMessage = rejectPhotoMessageTemplate.WithReasonMessage;

                    if (photoInfo.Reason != null && photoInfo.Reason.Trim().Length > 0)
                    {
                        reasonMessage = reasonMessage.Replace("%%REASON%%", photoInfo.Reason);
                        Message.Send(Config.Users.SystemUsername, photo.User.Username, reasonMessage, 0);
                    }
                    else
                        Message.Send(Config.Users.SystemUsername, photo.User.Username,
                                     rejectPhotoMessageTemplate.WithNoReasonMessage, 0);

                    Photo.Delete(photoInfo.Id);
                    Classes.User.AddScore(photo.Username, Config.UserScores.RejectedPhoto, "RejectedPhoto");

                    if (photoInfo.DeleteUser)
                    {
                        Classes.User.Delete(photo.Username, photoInfo.Reason);
                    }
                }
            }

            return resp;
        }
        private void determinePhotoState()
        {
            CommunityPhotoApproval[] approvals = CommunityPhotoApproval.FetchByPhotoID(CurrentPhotoID);
            int votes = approvals.Length;

            if (votes == Config.CommunityModeratedSystem.RequiredNumberOfVotesToDetermine)
            {
                Photo photo = null;
                int approved = 0;
                int rejected = 0;

                foreach (CommunityPhotoApproval approval in approvals)
                {
                    if (approval.Approved) approved++;
                    else rejected++;
                }

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

                if ((approved * 100) / Config.CommunityModeratedSystem.RequiredNumberOfVotesToDetermine >= Config.CommunityModeratedSystem.RequiredPercentageToApprovePhoto)
                {
                    photo.Approved = true;
                    photo.ApprovedDate = DateTime.Now;
                    photo.Save(false);

                    Classes.User.SetPhotoModerationApprovalScore(CurrentPhotoID, true,
                                                                 Config.CommunityModeratedSystem.ScoresForCorrectOpinion,
                                                                 Config.CommunityModeratedSystem.PenaltyForIncorrectOpinion);

                    CommunityPhotoApproval.DeleteByPhotoID(CurrentPhotoID);

                    MiscTemplates.ApprovePhotoMessage approvePhotoMessageTemplate =
                    new MiscTemplates.ApprovePhotoMessage(photo.User.LanguageId);
                    Message.Send(Config.Users.SystemUsername, photo.User.Username, approvePhotoMessageTemplate.Message, 0);

                    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".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 ((rejected * 100) / Config.CommunityModeratedSystem.RequiredNumberOfVotesToDetermine >= Config.CommunityModeratedSystem.RequiredPercentageToRejectPhoto)
                {
                    Classes.User.SetPhotoModerationApprovalScore(CurrentPhotoID, false,
                                                                 Config.CommunityModeratedSystem.ScoresForCorrectOpinion,
                                                                 Config.CommunityModeratedSystem.PenaltyForIncorrectOpinion);

                    Photo.Delete(CurrentPhotoID);

                    MiscTemplates.RejectPhotoMessage rejectPhotoMessageTemplate =
                        new MiscTemplates.RejectPhotoMessage(photo.User.LanguageId);
                    Message.Send(Config.Users.SystemUsername, photo.User.Username,
                                 rejectPhotoMessageTemplate.WithNoReasonMessage, 0);
                }
                else
                {
                    photo.ManualApproval = true;
                    photo.Save(false);
                }
            }
        }