protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = Translate.Text("Album");
            Label2.Text = Translate.Text("Upload");
            SelectNUpload.Text = Translate.Text("Upload");

            currPageItem = Sitecore.Context.Item;

            if (!Page.IsPostBack)
            {
                // If query string variable CurrentAlbum is set then copy it to session
                if (Request.QueryString["CurrentAlbum"] != null)
                {
                    System.Web.HttpContext.Current.Session["CurrentAlbum"] = PhotoAlbumObject.RestoreItemFromQueryString(Request.QueryString["CurrentAlbum"]);
                }
                _albumInst = new PhotoAlbumObject(null);
                if (_albumInst.CurrentPhotoAlbumFolder != null)
                {
                    ChildList albums = _albumInst.CurrentPhotoAlbumFolder.Children;
                    var lstUserAlbums = new List<UserAlbum>();
                    foreach (Item alb in albums.InnerChildren)
                    {
                        if (alb.Name != "AlbumsListFeed")
                            lstUserAlbums.Add(new UserAlbum { Id = alb.ID, Name = alb.Name });
                    }
                    if (albums != null)
                    {
                        AlbumsList.DataSource = lstUserAlbums;
                        AlbumsList.DataTextField = "Name";
                        AlbumsList.DataValueField = "ID";
                        AlbumsList.DataBind();
                        if (Request.QueryString["CurrentAlbum"] != null)
                        {
                            AlbumsList.SelectedValue = Request.QueryString["CurrentAlbum"];
                        }
                        if (_albumInst.CurrentAlbumItem != null)
                        {
                            AlbumsList.SelectedValue = _albumInst.CurrentAlbumItem.Name;
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Determines whether [is current user owner].
 /// </summary>
 /// <param name="albumInst">The album inst.</param>
 /// <param name="owner">The owner.</param>
 /// <returns>
 /// <c>true</c> if [is current user owner]; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsCurrentUserOwner(PhotoAlbumObject albumInst, object owner)
 {
     try
     {
         bool   result     = false;
         string currUser   = PhotoAlbumObject.ParseUserName(Sitecore.Context.User.Profile.UserName);
         string albumOwner = (string)HttpContext.Current.Session["CurrentUser"];
         if (currUser == albumOwner)
         {
             result = true;
         }
         return(result);
     }
     catch (Exception ex)
     {
         Log.Error("Cannot compare current user and current photo album creator", ex, owner);
         return(false);
     }
 }
 /// <summary>
 /// Determines whether [is current user owner].
 /// </summary>
 /// <param name="albumInst">The album inst.</param>
 /// <param name="owner">The owner.</param>
 /// <returns>
 /// <c>true</c> if [is current user owner]; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsCurrentUserOwner(PhotoAlbumObject albumInst, object owner)
 {
     try
     {
         bool result = false;
         string currUser = PhotoAlbumObject.ParseUserName(Sitecore.Context.User.Profile.UserName);
         string albumOwner = (string)HttpContext.Current.Session["CurrentUser"];
         if (currUser == albumOwner)
         {
             result = true;
         }
         return result;
     }
     catch (Exception ex)
     {
         Log.Error("Cannot compare current user and current photo album creator", ex, owner);
         return false;
     }
 }
        private Item CreateItemSimple(string itemName, Item parentItem, Item itemTemplate)
        {
            Item result;

            try
            {
                using (new SecurityDisabler())
                {
                    Item item = parentItem.Add(itemName, new TemplateID(itemTemplate.ID));
                    PhotoAlbumObject.PublishOneItem(item);
                    result = item;
                }
            }
            catch (Exception exception)
            {
                Log.Error("Cannot create item", exception, this);
                result = null;
            }
            return(result);
        }
        /// <summary>
        /// Handles the Select N upload_ click event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void SelectNUpload_Click(object sender, EventArgs e)
        {
            // base.Request.Files
            _albumInst = new PhotoAlbumObject(AlbumsList.SelectedItem.Text);
            ErrorMsg.Visible = false;

            if (!_albumInst.UploadNCreate(FileUpload1, Request.Files, AlbumsList.SelectedValue) && !string.IsNullOrEmpty(_albumInst.PageErrorMsg))
            {
                ErrorMsg.Text = _albumInst.PageErrorMsg;
                ErrorMsg.Visible = true;
            }
            else
            {
                /*  var albumUrl = @"/Photo_album/Custom/View_Album.aspx?CurrentAlbum=" + _albumInst.CurrentAlbumItem.ID;
                  var uriString = string.Format(CultureInfo.InvariantCulture, @"http://{0}/{1}", Request.Url.Host, albumUrl);
                  var shortener = new UrlShortener.BusinessLayer.GoogleUrlShortener();
                  var shortUri = shortener.ShortenUrl(new Uri(uriString));
                  var sharableEvent = new SharableEvent(Sitecore.Context.User, SharableEventType.PhotoUploaded, SharingTarget.All, shortUri, Request.Files[0].FileName);
                  EventsDispatcher.ProcessEvent(sharableEvent);*/

                // Tracking Goal Upload photos
                // AnalyticsTrackerHelper.TriggerEvent("Upload photos", "User has uploaded photos", string.Empty, string.Empty, "CurrentPage");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            CurrentUser = Request.QueryString["CurrentUser"];
              CurrentPhotoId = Request.QueryString["photo_id"];
              if (string.IsNullOrEmpty(CurrentUser) || string.IsNullOrEmpty(CurrentPhotoId))
              {
            photoalbum.Visible = false;
            Response.Write("<p width='100%' align='center'>\"This page requires specific parameters and can only be reached from a Album Detail page\"</p>");
            return;
              }

              this.currPageItem = Sitecore.Context.Item;
              XslFile1.Parameters = String.Format(CultureInfo.CurrentCulture, "username={0}", CurrentUser);
              this.currPhoto = PhotoAlbumObject.RestoreItemFromQueryString(CurrentPhotoId);

              this.ImagesContent.InnerHtml = this.BuildImagesHtml(this.currPhoto);
              this.albumInst = new PhotoAlbumObject(null)
                         {
                           CurrentAlbumItem = (Item) HttpContext.Current.Session["CurrentAlbum"]
                         };
              // Generate album view link
              this.ReturnToAlbumLink.HRef = PhotoAlbumObject.GetItemPath(Sitecore.Configuration.Settings.GetSetting("detailAlbumPageID")) + "?CurrentAlbum=" + this.albumInst.CurrentAlbumItem.ID.ToString() + "&CurrentUser=" + CurrentUser;
              this.ShowReviews();

              this.HideReviewFormForOwner();

              if (PhotoRateClicked())
              {
            this.PostReview();
            Response.Redirect(Request.RawUrl);
              }
              EditZoomPicture();
        }
Esempio n. 7
0
 public string ReturnToAlbum()
 {
     return(PhotoAlbumObject.GetItemPath(Sitecore.Configuration.Settings.GetSetting("detailAlbumPageID")) + "?CurrentAlbum=" + GetAlbumItemId() + "&CurrentUser="******"CurrentUser"]);
 }
        public bool UploadNCreate(FileUpload fileUpload, HttpFileCollection files, string albumID)
        {
            bool flag = true;
            bool result;

            try
            {
                if (fileUpload.PostedFile != null && fileUpload.PostedFile.ContentLength != 0)
                {
                    if (string.IsNullOrEmpty(albumID))
                    {
                        this.PageErrorMsg = "You should choose album for uploading";
                        result            = false;
                        return(result);
                    }
                    if (!this.IsMimeTypeAllowed(fileUpload.PostedFile.ContentType, PhotoAlbumConstants.allowedMimeTypes))
                    {
                        this.PageErrorMsg = "You should upload only jpeg, jpg images or zip archives";
                        result            = false;
                        return(result);
                    }
                    using (new SecurityDisabler())
                    {
                        Item       item       = this.CurrentMediaFolder;
                        UploadArgs uploadArgs = new UploadArgs();
                        uploadArgs.Files       = files;
                        uploadArgs.Folder      = item.Paths.Path;
                        uploadArgs.Overwrite   = false;
                        uploadArgs.Unpack      = true;
                        uploadArgs.Versioned   = false;
                        uploadArgs.Language    = Context.Language;
                        uploadArgs.Destination = UploadDestination.Database;
                        Context.SetActiveSite("shell");

                        try
                        {
                            if (PipelineFactory.GetPipeline("uiUpload") != null && PipelineFactory.GetPipeline("uiUpload").Processors != null)
                            {
                                foreach (Processor p in from Processor p in PipelineFactory.GetPipeline("uiUpload").Processors where p.Name.Equals("Sitecore.Pipelines.Upload.Done,Sitecore.Kernel,Process") select p)
                                {
                                    PipelineFactory.GetPipeline("uiUpload").Processors.Remove(p);
                                }
                            }
                        }
                        catch (Exception exception) { Log.Error("Delete from Pipelines ", exception, this); }

                        PipelineFactory.GetPipeline("uiUpload").Start(uploadArgs);

                        if (uploadArgs.UploadedItems.Count == 1)
                        {
                            PhotoAlbumObject.PublishOneItem(uploadArgs.UploadedItems[0]);
                        }
                        else
                        {
                            if (uploadArgs.UploadedItems.Count > 1)
                            {
                                PhotoAlbumObject.PublishOneItem(uploadArgs.UploadedItems[0].Parent);
                            }
                        }
                        foreach (Item current in uploadArgs.UploadedItems)
                        {
                            current.Editing.BeginEdit();
                            if (current.Fields["alt"] != null)
                            {
                                current.Fields["alt"].Value = current.Name;
                            }
                            current.Editing.EndEdit();
                        }
                        Context.SetActiveSite("website");
                        Item item2        = Factory.GetDatabase(this.DbName).Items[albumID];
                        Item itemTemplate = Factory.GetDatabase(this.DbName).Items[PhotoAlbumConstants.photoTemplateID];
                        foreach (Item current2 in uploadArgs.UploadedItems)
                        {
                            string itemName2 = this.CheckExistingItemName(item2, current2.Name, false);
                            this.CreateAndFillItem(itemName2, new Hashtable
                            {
                                {
                                    "Title",
                                    current2.Name
                                },

                                {
                                    "image",
                                    current2
                                }
                            }, item2, itemTemplate, false);
                        }
                        this.CurrentAlbumItem = item2;
                        result = flag;
                        return(result);
                    }
                }
                this.PageErrorMsg = "You should choose zip archive or image";
                result            = false;
            }
            catch (Exception exception)
            {
                Log.Error("Cannot upload image(s)", exception, this);
                result = false;
            }
            return(result);
        }
        private Item CreateAndFillItem(string itemName, Hashtable itemFieldsData, Item destionationItem, Item itemTemplate, bool nameExact)
        {
            Item result;

            using (new SecurityDisabler())
            {
                try
                {
                    string text = this.CheckExistingItemName(destionationItem, itemName, nameExact);
                    if (nameExact && text == string.Empty)
                    {
                        if (itemName == string.Empty)
                        {
                            this.PageErrorMsg = "Enter album name, please";
                            result            = null;
                        }
                        else
                        {
                            this.PageErrorMsg = "The album with name \"" + itemName + "\" already exists";
                            result            = null;
                        }
                    }
                    else
                    {
                        Item       item      = destionationItem.Add(text, new TemplateID(itemTemplate.ID));
                        Language[] languages = item.Languages;
                        for (int i = 0; i < languages.Length; i++)
                        {
                            Language language = languages[i];
                            Item     item2    = item.Database.GetItem(item.ID, language);
                            if (item2.Versions.Count == 0)
                            {
                                item2 = item2.Versions.AddVersion();
                            }
                            item2.Editing.BeginEdit();
                            foreach (string text2 in itemFieldsData.Keys)
                            {
                                string type;
                                if ((type = item2.Fields[text2].Type) != null && type == "Image")
                                {
                                    if (itemFieldsData[text2] is Item)
                                    {
                                        Item       item3      = (Item)itemFieldsData[text2];
                                        MediaItem  mediaItem  = item3;
                                        ImageField imageField = item2.Fields[text2];
                                        imageField.Src       = "~/media" + mediaItem.MediaPath + ".ashx";
                                        imageField.MediaPath = mediaItem.MediaPath;
                                        imageField.MediaID   = mediaItem.ID;
                                        imageField.Alt       = "photo image";
                                    }
                                }
                                else
                                {
                                    item2[text2] = (string)itemFieldsData[text2];
                                }
                            }
                            item2.Editing.EndEdit();
                        }
                        PhotoAlbumObject.PublishOneItem(item);
                        result = item;
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Cannot create or edit the item. Possible there are invalid fieds collection", exception, this);
                    result = null;
                }
            }
            return(result);
        }