Exemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            int width = Convert.ToInt32(context.Request.Params["width"]);
            int height = Convert.ToInt32(context.Request.Params["height"]);

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

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

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

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

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

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

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

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

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

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

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

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

                Photo photo = new Photo();

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

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

                photo.Save(true);

                photo.Image.Dispose();

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

                    Event newEvent = new Event(photo.Username);

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

                    newEvent.Save();

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

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

                    #endregion
                }
            }
        }
Exemplo n.º 2
0
        protected void lnkSave_Click(object sender, EventArgs e)
        {
            var photo = (Photo)Global.GetSessionState()["temp_photo"];

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

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

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

            bool isNewPhoto = photo.Id == 0;

            photo.Save(true);

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

                Event newEvent = new Event(CurrentUserSession.Username);

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

                newEvent.Save();

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

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

                #endregion
            }

            photo.Image.Dispose();

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

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

            Response.Redirect("~/ManageProfile.aspx?sel=photos");
        }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
0
        public void ProcessRequest(HttpContext context)
        {
            // Example of using a passed in value in the query string to set a categoryId
            // Now you can do anything you need to witht the file.
            //int categoryId = 0;
            //if (!string.IsNullOrEmpty(context.Request.QueryString["CategoryID"]))
            //{
            //    int.TryParse(context.Request.QueryString["CategoryID"],out categoryId);
            //}
            //if (categoryId > 0)
            //{
            //}

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

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

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

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

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

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

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

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

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

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

                                Photo photo = new Photo();

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

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

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

                                    photo.Save(true);
                                }

                                
                                photo.Image.Dispose();

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

                                    Event newEvent = new Event(photo.Username);

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

                                    newEvent.Save();

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

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

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

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

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

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

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

                                    Event newEvent = new Event(videoUpload.Username);

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

                                    newEvent.Save();

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

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

                                    #endregion
                                }

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

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

                                ThreadPool.QueueUserWorkItem(AsyncProcessVideo, videoUpload);

//                            ((PageBase)Page).StatusPageMessage = Lang.Trans("Your video has been queued for processing!");
                            }
                        }
                    }
                }
            }
            // Used as a fix for a bugnq in mac flash player that makes the 
            // onComplete event not fire
            HttpContext.Current.Response.Write(" ");
        }
Exemplo n.º 5
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 = Classes.User.Load(Username);
                }
                catch (NotFoundException)
                {
                    return;
                }

                BillingPlanOptions billingPlanOptions = null;

                Subscription subscription = Subscription.FetchActiveSubscription(Username);

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

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

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

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

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

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

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

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

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

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

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

                            newEvent.Save();

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

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

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

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

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

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

                            Event newEvent = new Event(videoUpload.Username);

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

                            newEvent.Save();

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

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

                            #endregion
                        }

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

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

                        ThreadPool.QueueUserWorkItem(AsyncProcessVideo, videoUpload);
                    }
                }
            }
        }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
0
        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);
                }
            }
        }