Exemple #1
0
        /// <summary>
        /// Gets a summary of all the pages from the blog with the spefied blogId.
        /// </summary>
        /// <param name="blogid">The blogid.</param>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        public wpPageSummary[] getPageList(string blogid, string username, string password)
        {
            if (User.validateCredentials(username, password, false))
            {
                ArrayList blogPosts = new ArrayList();
                ArrayList blogPostsObjects = new ArrayList();

                User u = new User(username);
                Channel userChannel = new Channel(u.Id);


                Document rootDoc;
                if (userChannel.StartNode > 0)
                    rootDoc = new Document(userChannel.StartNode);
                else
                    rootDoc = new Document(u.StartNodeId);

                //store children array here because iterating over an Array object is very inneficient.
                var c = rootDoc.Children;
                foreach (Document d in c)
                {
                    int count = 0;
                    blogPosts.AddRange(
                        findBlogPosts(userChannel, d, u.Name, ref count, 999, userChannel.FullTree));
                }

                blogPosts.Sort(new DocumentSortOrderComparer());

                foreach (Object o in blogPosts)
                {
                    Document d = (Document)o;
                    wpPageSummary p = new wpPageSummary();
                    p.dateCreated = d.CreateDateTime;
                    p.page_title = d.Text;
                    p.page_id = d.Id;
                    p.page_parent_id = d.Parent.Id;

                    blogPostsObjects.Add(p);
                }


                return (wpPageSummary[])blogPostsObjects.ToArray(typeof(wpPageSummary));
            }
            else
            {
                return null;
            }
        }
 public bool deletePost(
     string appKey,
     string postid,
     string username,
     string password,
     [XmlRpcParameter(
         Description = "Where applicable, this specifies whether the blog "
                       + "should be republished after the post has been deleted.")] bool publish)
 {
     if (validateUser(username, password))
     {
         Channel userChannel = new Channel(username);
         new Document(int.Parse(postid))
             .delete();
         return true;
     }
     return false;
 }
        public object editPost(
            string postid,
            string username,
            string password,
            Post post,
            bool publish)
        {
            if (validateUser(username, password))
            {
                Channel userChannel = new Channel(username);
                Document doc = new Document(Convert.ToInt32(postid));


                doc.Text = HttpContext.Current.Server.HtmlDecode(post.title);

                // Excerpt
                if (userChannel.FieldExcerptAlias != null && userChannel.FieldExcerptAlias != "")
                    doc.getProperty(userChannel.FieldExcerptAlias).Value = removeLeftUrl(post.mt_excerpt);

                if (UmbracoSettings.TidyEditorContent)
                    doc.getProperty(userChannel.FieldDescriptionAlias).Value = library.Tidy(removeLeftUrl(post.description), false);
                else
                    doc.getProperty(userChannel.FieldDescriptionAlias).Value = removeLeftUrl(post.description);

                updateCategories(doc, post, userChannel);


                if (publish)
                {
                    doc.Publish(new User(username));
                    library.UpdateDocumentCache(doc.Id);
                }
                return true;
            }
            else
            {
                return false;
            }
        }
        public string newPost(
            string blogid,
            string username,
            string password,
            Post post,
            bool publish)
        {
            if (validateUser(username, password))
            {
                Channel userChannel = new Channel(username);
                User u = new User(username);
                Document doc =
                    Document.MakeNew(HttpContext.Current.Server.HtmlDecode(post.title),
                                     DocumentType.GetByAlias(userChannel.DocumentTypeAlias), u,
                                     userChannel.StartNode);


                // Excerpt
                if (userChannel.FieldExcerptAlias != null && userChannel.FieldExcerptAlias != "")
                    doc.getProperty(userChannel.FieldExcerptAlias).Value = removeLeftUrl(post.mt_excerpt);


                // Description
                if (UmbracoSettings.TidyEditorContent)
                    doc.getProperty(userChannel.FieldDescriptionAlias).Value = library.Tidy(removeLeftUrl(post.description), false);
                else
                    doc.getProperty(userChannel.FieldDescriptionAlias).Value = removeLeftUrl(post.description);

                // Categories
                updateCategories(doc, post, userChannel);

                // check release date
                if (post.dateCreated.Year > 0001)
                {
                    publish = false;
                    doc.ReleaseDate = post.dateCreated;
                }

                if (publish)
                {
                    doc.SaveAndPublish(new User(username));
                }
                return doc.Id.ToString();
            }
            else
                throw new ArgumentException("Error creating post");
        }
Exemple #5
0
        /// <summary>
        /// Gets a specified number of pages from the blog with the spefied blogId 
        /// </summary>
        /// <param name="blogid">The blogid.</param>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="numberOfItems">The number of pages.</param>
        /// <returns></returns>
        public wpPage[] getPages(string blogid, string username, string password, int numberOfItems)
        {
            if (User.validateCredentials(username, password, false))
            {
                ArrayList blogPosts = new ArrayList();
                ArrayList blogPostsObjects = new ArrayList();

                User u = new User(username);
                Channel userChannel = new Channel(u.Id);


                Document rootDoc;
                if (userChannel.StartNode > 0)
                    rootDoc = new Document(userChannel.StartNode);
                else
                    rootDoc = new Document(u.StartNodeId);

                //store children array here because iterating over an Array object is very inneficient.
                var c = rootDoc.Children;
                foreach (Document d in c)
                {
                    int count = 0;
                    blogPosts.AddRange(
                        findBlogPosts(userChannel, d, u.Name, ref count, numberOfItems, userChannel.FullTree));
                }

                blogPosts.Sort(new DocumentSortOrderComparer());

                foreach (Object o in blogPosts)
                {
                    Document d = (Document)o;
                    wpPage p = new wpPage();
                    p.dateCreated = d.CreateDateTime;
                    p.title = d.Text;
                    p.page_id = d.Id;
                    p.wp_page_parent_id = d.Parent.Id;
                    p.wp_page_parent_title = d.Parent.Text;
                    p.permalink = library.NiceUrl(d.Id);
                    p.description = d.getProperty(userChannel.FieldDescriptionAlias).Value.ToString();
                    p.link = library.NiceUrl(d.Id);

                    if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "" &&
                        d.getProperty(userChannel.FieldCategoriesAlias) != null &&
                        ((string)d.getProperty(userChannel.FieldCategoriesAlias).Value) != "")
                    {
                        String categories = d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString();
                        char[] splitter = { ',' };
                        String[] categoryIds = categories.Split(splitter);
                        p.categories = categoryIds;
                    }


                    blogPostsObjects.Add(p);
                }


                return (wpPage[])blogPostsObjects.ToArray(typeof(wpPage));
            }
            else
            {
                return null;
            }
        }
Exemple #6
0
 /// <summary>
 /// Creates a new blog category / tag.
 /// </summary>
 /// <param name="blogid">The blogid.</param>
 /// <param name="username">The username.</param>
 /// <param name="password">The password.</param>
 /// <param name="category">The category.</param>
 /// <returns></returns>
 public string newCategory(
     string blogid,
     string username,
     string password,
     wpCategory category)
 {
     if (User.validateCredentials(username, password, false))
     {
         Channel userChannel = new Channel(username);
         if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "")
         {
             // Find the propertytype via the document type
             ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias);
             PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias);
             interfaces.IUseTags tags = UseTags(categoryType);
             if (tags != null)
             {
                 tags.AddTag(category.name);
             }
             else
             {
                 PreValue pv = new PreValue();
                 pv.DataTypeId = categoryType.DataTypeDefinition.Id;
                 pv.Value = category.name;
                 pv.Save();
             }
         }
     }
     return "";
 }
Exemple #7
0
        private void setupChannel()
        {
            Channel userChannel;
            try
            {
                userChannel =
                    new Channel(u.Id);
            }
            catch
            {
                userChannel = new Channel();
            }

            // Populate dropdowns
            foreach (DocumentType dt in DocumentType.GetAllAsList())
                cDocumentType.Items.Add(
                    new ListItem(dt.Text, dt.Alias)
                    );

            // populate fields
            ArrayList fields = new ArrayList();
            cDescription.ID = "cDescription";
            cCategories.ID = "cCategories";
            cExcerpt.ID = "cExcerpt";
            cDescription.Items.Add(new ListItem(ui.Text("choose"), ""));
            cCategories.Items.Add(new ListItem(ui.Text("choose"), ""));
            cExcerpt.Items.Add(new ListItem(ui.Text("choose"), ""));

            foreach (PropertyType pt in PropertyType.GetAll())
            {
                if (!fields.Contains(pt.Alias))
                {
                    cDescription.Items.Add(new ListItem(string.Format("{0} ({1})", pt.Name, pt.Alias), pt.Alias));
                    cCategories.Items.Add(new ListItem(string.Format("{0} ({1})", pt.Name, pt.Alias), pt.Alias));
                    cExcerpt.Items.Add(new ListItem(string.Format("{0} ({1})", pt.Name, pt.Alias), pt.Alias));
                    fields.Add(pt.Alias);
                }
            }

            // Handle content and media pickers

            PlaceHolder medias = new PlaceHolder();
            cMediaPicker.AppAlias = "media";
            cMediaPicker.TreeAlias = "media";

            if (userChannel.MediaFolder > 0)
                cMediaPicker.Value = userChannel.MediaFolder.ToString();
            else
                cMediaPicker.Value = "-1";

            medias.Controls.Add(cMediaPicker);

            PlaceHolder content = new PlaceHolder();
            cContentPicker.AppAlias = "content";
            cContentPicker.TreeAlias = "content";

            if (userChannel.StartNode > 0)
                cContentPicker.Value = userChannel.StartNode.ToString();
            else
                cContentPicker.Value = "-1";

            content.Controls.Add(cContentPicker);


            // Setup the panes
            Pane ppInfo = new Pane();
            ppInfo.addProperty(ui.Text("name", base.getUser()), cName);
            ppInfo.addProperty(ui.Text("user", "startnode", base.getUser()), content);
            ppInfo.addProperty(ui.Text("user", "searchAllChildren", base.getUser()), cFulltree);
            ppInfo.addProperty(ui.Text("user", "mediastartnode", base.getUser()), medias);

            Pane ppFields = new Pane();
            ppFields.addProperty(ui.Text("user", "documentType", base.getUser()), cDocumentType);
            ppFields.addProperty(ui.Text("user", "descriptionField", base.getUser()), cDescription);
            ppFields.addProperty(ui.Text("user", "categoryField", base.getUser()), cCategories);
            ppFields.addProperty(ui.Text("user", "excerptField", base.getUser()), cExcerpt);


            TabPage channelInfo = UserTabs.NewTabPage(ui.Text("user", "contentChannel", base.getUser()));

            channelInfo.Controls.Add(ppInfo);
            channelInfo.Controls.Add(ppFields);

            channelInfo.HasMenu = true;
            ImageButton save = channelInfo.Menu.NewImageButton();
            save.ImageUrl = SystemDirectories.Umbraco + "/images/editor/save.gif";
            save.Click += new ImageClickEventHandler(saveUser_Click);
            save.ID = "save";
            if (!IsPostBack)
            {
                cName.Text = userChannel.Name;
                cDescription.SelectedValue = userChannel.FieldDescriptionAlias;
                cCategories.SelectedValue = userChannel.FieldCategoriesAlias;
                cExcerpt.SelectedValue = userChannel.FieldExcerptAlias;
                cDocumentType.SelectedValue = userChannel.DocumentTypeAlias;
                cFulltree.Checked = userChannel.FullTree;
            }
        }
Exemple #8
0
        /// <summary>
        /// Handles the Click event of the saveUser control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
        private void saveUser_Click(object sender, ImageClickEventArgs e)
        {
            if (base.IsValid)
            {
                try
                {
                    MembershipUser user = Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].GetUser(u.LoginName, true);


                    string tempPassword = ((controls.passwordChanger)passw.Controls[0]).Password;
                    if (!string.IsNullOrEmpty(tempPassword.Trim()))
                    {
                        // make sure password is not empty
                        if (string.IsNullOrEmpty(u.Password)) u.Password = "******";
                        user.ChangePassword(u.Password, tempPassword);
                    }

                    // Is it using the default membership provider
                    if (Membership.Providers[UmbracoSettings.DefaultBackofficeProvider] is UsersMembershipProvider)
                    {
                        // Save user in membership provider
                        UsersMembershipUser umbracoUser = user as UsersMembershipUser;
                        umbracoUser.FullName = uname.Text.Trim();
                        umbracoUser.Language = userLanguage.SelectedValue;
                        umbracoUser.UserType = UserType.GetUserType(int.Parse(userType.SelectedValue));
                        Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].UpdateUser(umbracoUser);

                        // Save user details
                        u.Email = email.Text.Trim();
                        u.Language = userLanguage.SelectedValue;
                    }
                    else
                    {
                        u.Name = uname.Text.Trim();
                        u.Language = userLanguage.SelectedValue;
                        u.UserType = UserType.GetUserType(int.Parse(userType.SelectedValue));
                        if (!(Membership.Providers[UmbracoSettings.DefaultBackofficeProvider] is ActiveDirectoryMembershipProvider)) Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].UpdateUser(user);
                    }


                    u.LoginName = lname.Text;
                    //u.StartNodeId = int.Parse(startNode.Value);


                    int startNode;
                    if (!int.TryParse(contentPicker.Value, out startNode))
                    {
                        //set to default if nothing is choosen
                        if (u.StartNodeId > 0)
                            startNode = u.StartNodeId;
                        else
                            startNode = -1;
                    }
                    u.StartNodeId = startNode;


                    u.Disabled = Disabled.Checked;
                    u.DefaultToLiveEditing = DefaultToLiveEditing.Checked;
                    u.NoConsole = NoConsole.Checked;
                    //u.StartMediaId = int.Parse(mediaStartNode.Value);


                    int mstartNode;
                    if (!int.TryParse(mediaPicker.Value, out mstartNode))
                    {
                        //set to default if nothing is choosen
                        if (u.StartMediaId > 0)
                            mstartNode = u.StartMediaId;
                        else
                            mstartNode = -1;
                    }
                    u.StartMediaId = mstartNode;

                    u.clearApplications();

                    foreach (ListItem li in lapps.Items)
                    {
                        if (li.Selected) u.addApplication(li.Value);
                    }

                    u.Save();

                    // save data
                    if (cName.Text != "")
                    {
                        Channel c;
                        try
                        {
                            c = new Channel(u.Id);
                        }
                        catch
                        {
                            c = new Channel();
                            c.User = u;
                        }

                        c.Name = cName.Text;
                        c.FullTree = cFulltree.Checked;
                        c.StartNode = int.Parse(cContentPicker.Value);
                        c.MediaFolder = int.Parse(cMediaPicker.Value);
                        c.FieldCategoriesAlias = cCategories.SelectedValue;
                        c.FieldDescriptionAlias = cDescription.SelectedValue;
                        c.FieldExcerptAlias = cExcerpt.SelectedValue;
                        c.DocumentTypeAlias = cDocumentType.SelectedValue;

                        //
                        c.MediaTypeAlias = "image";
                        c.MediaTypeFileProperty = "umbracoFile";
                        c.ImageSupport = true;

                        c.Save();

                    }

                    speechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "editUserSaved", base.getUser()), "");
                }
                catch (Exception ex)
                {
                    speechBubble(speechBubbleIcon.error, ui.Text("speechBubbles", "editUserError", base.getUser()), "");
                    Log.Add(LogTypes.Error, 0, ex.Message);
                }
            }
            else
            {
                speechBubble(speechBubbleIcon.error, ui.Text("speechBubbles", "editUserError", base.getUser()), "");
            }
        }
        public BlogInfo[] getUsersBlogs(
            string appKey,
            string username,
            string password)
        {
            if (validateUser(username, password))
            {
                BlogInfo[] blogs = new BlogInfo[1];
                User u = new User(username);
                Channel userChannel = new Channel(u.Id);
                Document rootDoc;
                if (userChannel.StartNode > 0)
                    rootDoc = new Document(userChannel.StartNode);
                else
                    rootDoc = new Document(u.StartNodeId);

                BlogInfo bInfo = new BlogInfo();
                bInfo.blogName = userChannel.Name;
                bInfo.blogid = rootDoc.Id.ToString();
                bInfo.url = library.NiceUrlWithDomain(rootDoc.Id, true);
                blogs[0] = bInfo;

                return blogs;
            }

            throw new ArgumentException(string.Format("No data found for user with username: '******'", username));
        }
        private void updateCategories(Document doc, Post post, Channel userChannel)
        {
            if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "")
            {
                ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias);
                PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias);

                String[] categories = post.categories;
                string categoryValue = "";
                interfaces.IUseTags tags = UseTags(categoryType);
                if (tags != null)
                {
                    tags.RemoveTagsFromNode(doc.Id);
                    for (int i = 0; i < categories.Length; i++)
                    {
                        tags.AddTagToNode(doc.Id, categories[i]);
                    }
                    //If the IUseTags provider manually set the property value to something on the IData interface then we should persist this
                    //code commented as for some reason, even though the IUseTags control is setting IData.Value it is null here
                    //could be a cache issue, or maybe it's a different instance of the IData or something, rather odd
                    //doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryType.DataTypeDefinition.DataType.Data.Value;

                    //Instead, set the document property to CSV of the tags - this WILL break custom editors for tags which don't adhere to the
                    //pseudo standard that the .Value of the property contains CSV tags. 
                    doc.getProperty(userChannel.FieldCategoriesAlias).Value = string.Join(",", categories);
                }
                else
                {
                    for (int i = 0; i < categories.Length; i++)
                    {
                        PreValue pv = new PreValue(categoryType.DataTypeDefinition.Id, categories[i]);
                        categoryValue += pv.Id + ",";
                    }
                    if (categoryValue.Length > 0)
                        categoryValue = categoryValue.Substring(0, categoryValue.Length - 1);

                    doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryValue;
                }
            }
        }
        protected UrlData newMediaObjectLogic(
            string blogid,
            string username,
            string password,
            FileData file)
        {
            if (validateUser(username, password))
            {
                User u = new User(username);
                Channel userChannel = new Channel(username);
                UrlData fileUrl = new UrlData();
                if (userChannel.ImageSupport)
                {
                    Media rootNode;
                    if (userChannel.MediaFolder > 0)
                        rootNode = new Media(userChannel.MediaFolder);
                    else
                        rootNode = new Media(u.StartMediaId);

                    // Create new media
                    Media m = Media.MakeNew(file.name, MediaType.GetByAlias(userChannel.MediaTypeAlias), u, rootNode.Id);

                    Property fileObject = m.getProperty(userChannel.MediaTypeFileProperty);
                    string _fullFilePath;
                    string filename = file.name.Replace("/", "_");
                    // Generate file
                    if (UmbracoSettings.UploadAllowDirectories)
                    {
                        // Create a new folder in the /media folder with the name /media/propertyid
                        Directory.CreateDirectory( IOHelper.MapPath( SystemDirectories.Media + "/" + fileObject.Id));

                        _fullFilePath = IOHelper.MapPath( SystemDirectories.Media + "/" + fileObject.Id + "/" + filename);
                        fileObject.Value = SystemDirectories.Media + "/" + fileObject.Id + "/" + filename;
                    }
                    else
                    {
                        filename = fileObject.Id + "-" + filename;
                        _fullFilePath = IOHelper.MapPath(SystemDirectories.Media + "/" + filename);
                        fileObject.Value = SystemDirectories.Media + "/" + filename;
                    }

                    fileUrl.url = "http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + IOHelper.ResolveUrl(fileObject.Value.ToString());

                    File.WriteAllBytes(_fullFilePath, file.bits);

                    // Try updating standard file values
                    try
                    {
                        string orgExt = "";
                        // Size
                        if (m.getProperty("umbracoBytes") != null)
                            m.getProperty("umbracoBytes").Value = file.bits.Length;
                        // Extension
                        if (m.getProperty("umbracoExtension") != null)
                        {
                            orgExt =
                                ((string)
                                 file.name.Substring(file.name.LastIndexOf(".") + 1,
                                                     file.name.Length - file.name.LastIndexOf(".") - 1));
                            m.getProperty("umbracoExtension").Value = orgExt.ToLower();
                        }
                        // Width and Height
                        // Check if image and then get sizes, make thumb and update database
                        if (m.getProperty("umbracoWidth") != null && m.getProperty("umbracoHeight") != null &&
                            ",jpeg,jpg,gif,bmp,png,tiff,tif,".IndexOf("," + orgExt.ToLower() + ",") > 0)
                        {
                            int fileWidth;
                            int fileHeight;

                            FileStream fs = new FileStream(_fullFilePath,
                                                           FileMode.Open, FileAccess.Read, FileShare.Read);

                            Image image = Image.FromStream(fs);
                            fileWidth = image.Width;
                            fileHeight = image.Height;
                            fs.Close();
                            try
                            {
                                m.getProperty("umbracoWidth").Value = fileWidth.ToString();
                                m.getProperty("umbracoHeight").Value = fileHeight.ToString();
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch
                    {
                    }

                    return fileUrl;
                }
                else
                    throw new ArgumentException(
                        "Image Support is turned off in this channel. Modify channel settings in umbraco to enable image support.");
            }
            return new UrlData();
        }
        protected UrlData newMediaObjectLogic(
            string blogid,
            string username,
            string password,
            FileData file)
        {
            if (validateUser(username, password))
            {
                User u = new User(username);
                Channel userChannel = new Channel(username);
                UrlData fileUrl = new UrlData();
                if (userChannel.ImageSupport)
                {
                    Media rootNode;
                    if (userChannel.MediaFolder > 0)
                        rootNode = new Media(userChannel.MediaFolder);
                    else
                        rootNode = new Media(u.StartMediaId);

                    // Create new media
                    Media m = Media.MakeNew(file.name, MediaType.GetByAlias(userChannel.MediaTypeAlias), u, rootNode.Id);

                    Property fileObject = m.getProperty(userChannel.MediaTypeFileProperty);
                    
                    var filename = file.name.Replace("/", "_");
                    var relativeFilePath = _fs.GetRelativePath(fileObject.Id, filename);

                    fileObject.Value = _fs.GetUrl(relativeFilePath);
                    fileUrl.url = fileObject.Value.ToString();

                    if (!fileUrl.url.StartsWith("http"))
                    {
                        var protocol = GlobalSettings.UseSSL ? "https" : "http";
                        fileUrl.url = protocol + "://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + fileUrl.url;
                    }

                    _fs.AddFile(relativeFilePath, new MemoryStream(file.bits));

                    // Try updating standard file values
                    try
                    {
                        string orgExt = "";
                        // Size
                        if (m.getProperty(Constants.Conventions.Media.Bytes) != null)
                            m.getProperty(Constants.Conventions.Media.Bytes).Value = file.bits.Length;
                        // Extension
                        if (m.getProperty(Constants.Conventions.Media.Extension) != null)
                        {
                            orgExt =
                                ((string)
                                 file.name.Substring(file.name.LastIndexOf(".") + 1,
                                                     file.name.Length - file.name.LastIndexOf(".") - 1));
                            m.getProperty(Constants.Conventions.Media.Extension).Value = orgExt.ToLower();
                        }
                        // Width and Height
                        // Check if image and then get sizes, make thumb and update database
                        if (m.getProperty(Constants.Conventions.Media.Width) != null && m.getProperty(Constants.Conventions.Media.Height) != null &&
                            ",jpeg,jpg,gif,bmp,png,tiff,tif,".IndexOf("," + orgExt.ToLower() + ",") > 0)
                        {
                            int fileWidth;
                            int fileHeight;

                            var stream = _fs.OpenFile(relativeFilePath);

                            Image image = Image.FromStream(stream);
                            fileWidth = image.Width;
                            fileHeight = image.Height;
                            stream.Close();
                            try
                            {
                                m.getProperty(Constants.Conventions.Media.Width).Value = fileWidth.ToString();
                                m.getProperty(Constants.Conventions.Media.Height).Value = fileHeight.ToString();
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch
                    {
                    }

                    return fileUrl;
                }
                else
                    throw new ArgumentException(
                        "Image Support is turned off in this channel. Modify channel settings in umbraco to enable image support.");
            }
            return new UrlData();
        }
        protected ArrayList findBlogPosts(Channel userChannel, Document d, String userName, ref int count, int max,
                                          bool fullTree)
        {
            ArrayList list = new ArrayList();

            ContentType ct = d.ContentType;

            if (ct.Alias.Equals(userChannel.DocumentTypeAlias) &
                (count < max))
            {
                list.Add(d);
                count = count + 1;
            }

            if (d.Children != null && d.Children.Length > 0 && fullTree)
            {
                //store children array here because iterating over an Array object is very inneficient.
                var c = d.Children;
                foreach (Document child in c)
                {
                    if (count < max)
                    {
                        list.AddRange(findBlogPosts(userChannel, child, userName, ref count, max, true));
                    }
                }
            }
            return list;
        }
        public BlogInfo[] getUsersBlogs(
            string appKey,
            string username,
            string password)
        {
            if (validateUser(username, password))
            {
                BlogInfo[] blogs = new BlogInfo[1];
                User u = new User(username);
                Channel userChannel = new Channel(u.Id);
                Document rootDoc;
                if (userChannel.StartNode > 0)
                    rootDoc = new Document(userChannel.StartNode);
                else
                    rootDoc = new Document(u.StartNodeId);

                BlogInfo bInfo = new BlogInfo();
                bInfo.blogName = userChannel.Name;
                bInfo.blogid = rootDoc.Id.ToString();
                bInfo.url = HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + library.NiceUrl(rootDoc.Id);
                blogs[0] = bInfo;

                return blogs;
            }

            throw new ArgumentException(string.Format("No data found for user with username: '******'", username));
        }
        public Post[] getRecentPosts(
            string blogid,
            string username,
            string password,
            int numberOfPosts)
        {
            if (validateUser(username, password))
            {
                ArrayList blogPosts = new ArrayList();
                ArrayList blogPostsObjects = new ArrayList();

                User u = new User(username);
                Channel userChannel = new Channel(u.Id);


                Document rootDoc;
                if (userChannel.StartNode > 0)
                    rootDoc = new Document(userChannel.StartNode);
                else
                {
                    if (u.StartNodeId == -1)
                    {
                        rootDoc = Document.GetRootDocuments()[0];
                    }
                    else
                    {
                        rootDoc = new Document(u.StartNodeId);
                    }
                }

                //store children array here because iterating over an Array object is very inneficient.
                var c = rootDoc.Children;
                foreach (Document d in c)
                {
                    int count = 0;
                    blogPosts.AddRange(
                        findBlogPosts(userChannel, d, u.Name, ref count, numberOfPosts, userChannel.FullTree));
                }

                blogPosts.Sort(new DocumentSortOrderComparer());

                foreach (Object o in blogPosts)
                {
                    Document d = (Document)o;
                    Post p = new Post();
                    p.dateCreated = d.CreateDateTime;
                    p.userid = username;
                    p.title = d.Text;
                    p.permalink = library.NiceUrl(d.Id);
                    p.description = d.getProperty(userChannel.FieldDescriptionAlias).Value.ToString();
                    p.link = library.NiceUrl(d.Id);
                    p.postid = d.Id.ToString();

                    if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "" &&
                        d.getProperty(userChannel.FieldCategoriesAlias) != null &&
                        d.getProperty(userChannel.FieldCategoriesAlias).Value != null &&
                        d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString() != "")
                    {
                        String categories = d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString();
                        char[] splitter = { ',' };
                        String[] categoryIds = categories.Split(splitter);
                        p.categories = categoryIds;
                    }

                    // Excerpt
                    if (userChannel.FieldExcerptAlias != null && userChannel.FieldExcerptAlias != "")
                        p.mt_excerpt = d.getProperty(userChannel.FieldExcerptAlias).Value.ToString();


                    blogPostsObjects.Add(p);
                }


                return (Post[])blogPostsObjects.ToArray(typeof(Post));
            }
            else
            {
                return null;
            }
        }
        public Post getPost(
            string postid,
            string username,
            string password)
        {
            if (validateUser(username, password))
            {
                Channel userChannel = new Channel(username);
                Document d = new Document(int.Parse(postid));
                Post p = new Post();
                p.title = d.Text;
                p.description = d.getProperty(userChannel.FieldDescriptionAlias).Value.ToString();

                // Excerpt
                if (userChannel.FieldExcerptAlias != null && userChannel.FieldExcerptAlias != "")
                    p.mt_excerpt = d.getProperty(userChannel.FieldExcerptAlias).Value.ToString();

                // Categories
                if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "" &&
                    d.getProperty(userChannel.FieldCategoriesAlias) != null &&
                    d.getProperty(userChannel.FieldCategoriesAlias).Value != null &&
                    d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString() != "")
                {
                    String categories = d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString();
                    char[] splitter = { ',' };
                    String[] categoryIds = categories.Split(splitter);
                    p.categories = categoryIds;
                }

                p.postid = postid;
                p.permalink = library.NiceUrl(d.Id);
                p.dateCreated = d.CreateDateTime;
                p.link = p.permalink;
                return p;
            }
            else
                throw new ArgumentException(string.Format("Error retriving post with id: '{0}'", postid));
        }
        public CategoryInfo[] getCategories(
            string blogid,
            string username,
            string password)
        {
            if (validateUser(username, password))
            {
                Channel userChannel = new Channel(username);
                if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "")
                {
                    // Find the propertytype via the document type
                    ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias);
                    PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias);

                    // check if the datatype uses tags or prevalues
                    CategoryInfo[] returnedCategories = null;
                    interfaces.IUseTags tags = UseTags(categoryType);
                    if (tags != null)
                    {
                        List<interfaces.ITag> alltags = tags.GetAllTags();
                        if (alltags != null)
                        {
                            returnedCategories = new CategoryInfo[alltags.Count];
                            int counter = 0;
                            foreach (interfaces.ITag t in alltags)
                            {
                                CategoryInfo ci = new CategoryInfo();
                                ci.title = t.TagCaption;
                                ci.categoryid = t.Id.ToString();
                                ci.description = "";
                                ci.rssUrl = "";
                                ci.htmlUrl = "";
                                returnedCategories[counter] = ci;
                                counter++;
                            }
                        }
                        else
                        {
                            returnedCategories = new CategoryInfo[0];
                        }
                    }
                    else
                    {
                        SortedList categories = PreValues.GetPreValues(categoryType.DataTypeDefinition.Id);
                        returnedCategories = new CategoryInfo[categories.Count];
                        IDictionaryEnumerator ide = categories.GetEnumerator();
                        int counter = 0;
                        while (ide.MoveNext())
                        {
                            PreValue category = (PreValue)ide.Value;
                            CategoryInfo ci = new CategoryInfo();
                            ci.title = category.Value;
                            ci.categoryid = category.Id.ToString();
                            ci.description = "";
                            ci.rssUrl = "";
                            ci.htmlUrl = "";
                            returnedCategories[counter] = ci;
                            counter++;
                        }
                    }

                    return returnedCategories;
                }
            }

            throw new ArgumentException("Categories doesn't work for this channel, they might not have been activated. Contact your umbraco administrator.");
        }
        /// <summary>
        /// Handles the Click event of the saveUser control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
        private void SaveUser_Click(object sender, EventArgs e)
        {
            if (base.IsValid)
            {
                try
                {
                    var membershipUser = BackOfficeProvider.GetUser(u.LoginName, true);
                    if (membershipUser == null)
                    {
                        throw new ProviderException("Could not find user in the membership provider with login name " + u.LoginName);
                    }

                    var passwordChangerControl = (passwordChanger) passw.Controls[0];
                    var passwordChangerValidator = (CustomValidator) passw.Controls[1].Controls[0].Controls[0];

                    //perform the changing password logic
                    ChangePassword(passwordChangerControl, membershipUser, passwordChangerValidator);
                    
                    // Is it using the default membership provider
                    if (BackOfficeProvider is UsersMembershipProvider)
                    {
                        // Save user in membership provider
                        UsersMembershipUser umbracoUser = membershipUser as UsersMembershipUser;
                        umbracoUser.FullName = uname.Text.Trim();
                        umbracoUser.Language = userLanguage.SelectedValue;
                        umbracoUser.UserType = UserType.GetUserType(int.Parse(userType.SelectedValue));
                        BackOfficeProvider.UpdateUser(umbracoUser);

                        // Save user details
                        u.Email = email.Text.Trim();
                        u.Language = userLanguage.SelectedValue;
                    }
                    else
                    {
                        u.Name = uname.Text.Trim();
                        u.Language = userLanguage.SelectedValue;
                        u.UserType = UserType.GetUserType(int.Parse(userType.SelectedValue));
                        //SD: This check must be here for some reason but apparently we don't want to try to 
                        // update when the AD provider is active.
                        if ((BackOfficeProvider is ActiveDirectoryMembershipProvider) == false)
                        {
                            BackOfficeProvider.UpdateUser(membershipUser);
                        }
                    }


                    u.LoginName = lname.Text;
                    //u.StartNodeId = int.Parse(startNode.Value);


                    int startNode;
                    if (!int.TryParse(contentPicker.Value, out startNode))
                    {
                        //set to default if nothing is choosen
                        if (u.StartNodeId > 0)
                            startNode = u.StartNodeId;
                        else
                            startNode = -1;
                    }
                    u.StartNodeId = startNode;


                    u.Disabled = Disabled.Checked;
                    
                    u.NoConsole = NoConsole.Checked;
                    //u.StartMediaId = int.Parse(mediaStartNode.Value);


                    int mstartNode;
                    if (!int.TryParse(mediaPicker.Value, out mstartNode))
                    {
                        //set to default if nothing is choosen
                        if (u.StartMediaId > 0)
                            mstartNode = u.StartMediaId;
                        else
                            mstartNode = -1;
                    }
                    u.StartMediaId = mstartNode;

                    u.clearApplications();

                    foreach (ListItem li in lapps.Items)
                    {
                        if (li.Selected) u.addApplication(li.Value);
                    }

                    u.Save();

                    // save data
                    if (cName.Text != "")
                    {
                        Channel c;
                        try
                        {
                            c = new Channel(u.Id);
                        }
                        catch
                        {
                            c = new Channel();
                            c.User = u;
                        }

                        c.Name = cName.Text;
                        c.FullTree = cFulltree.Checked;
                        c.StartNode = int.Parse(cContentPicker.Value);
                        c.MediaFolder = int.Parse(cMediaPicker.Value);
                        c.FieldCategoriesAlias = cCategories.SelectedValue;
                        c.FieldDescriptionAlias = cDescription.SelectedValue;
                        c.FieldExcerptAlias = cExcerpt.SelectedValue;
                        c.DocumentTypeAlias = cDocumentType.SelectedValue;

                        //
                        c.MediaTypeAlias = Constants.Conventions.MediaTypes.Image; // [LK:2013-03-22] This was previously lowercase; unsure if using const will cause an issue.
                        c.MediaTypeFileProperty = Constants.Conventions.Media.File;
                        c.ImageSupport = true;

                        c.Save();

                    }

                    ClientTools.ShowSpeechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "editUserSaved", UmbracoUser), "");
                }
                catch (Exception ex)
                {
                    ClientTools.ShowSpeechBubble(speechBubbleIcon.error, ui.Text("speechBubbles", "editUserError", UmbracoUser), "");
                    LogHelper.Error<EditUser>("Exception", ex);
                }
            }
            else
            {
                ClientTools.ShowSpeechBubble(speechBubbleIcon.error, ui.Text("speechBubbles", "editUserError", UmbracoUser), "");
            }
        }
        private void updateCategories(Document doc, Post post, Channel userChannel)
        {
            if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "")
            {
                ContentType blogPostType = ContentType.GetByAlias(userChannel.DocumentTypeAlias);
                PropertyType categoryType = blogPostType.getPropertyType(userChannel.FieldCategoriesAlias);

                String[] categories = post.categories;
                string categoryValue = "";
                interfaces.IUseTags tags = UseTags(categoryType);
                if (tags != null)
                {
                    tags.RemoveTagsFromNode(doc.Id);
                    for (int i = 0; i < categories.Length; i++)
                    {
                        tags.AddTagToNode(doc.Id, categories[i]);
                    }

                }
                else
                {
                    for (int i = 0; i < categories.Length; i++)
                    {
                        PreValue pv = new PreValue(categoryType.DataTypeDefinition.Id, categories[i]);
                        categoryValue += pv.Id + ",";
                    }
                }
                if (categoryValue.Length > 0)
                    categoryValue = categoryValue.Substring(0, categoryValue.Length - 1);

                doc.getProperty(userChannel.FieldCategoriesAlias).Value = categoryValue;
            }
        }