public static IEnumerable LoadTags(int page) { WebUtils.CheckRightsForAdminPostPages(false); var tags = new List <JsonTag>(); foreach (var p in Post.Posts) { foreach (var t in p.Tags) { var tg = tags.FirstOrDefault(tag => tag.TagName == t); if (tg == null) { tags.Add(new JsonTag { TagName = t, TagCount = 1 }); } else { tg.TagCount++; } } } return(from t in tags orderby t.TagName select t); }
public static string LoadPostPager(int page, int pageSize, string type) { if (!WebUtils.CheckRightsForAdminPostPages(false)) { return(null); } return(JsonPosts.GetPager(page, pageSize)); }
public static IEnumerable LoadPosts(int page, string type, string filter, string title, int pageSize) { if (!WebUtils.CheckRightsForAdminPostPages(false)) { return(null); } return(JsonPosts.GetPosts(page, pageSize, type, filter, title)); }
public static IEnumerable LoadBlogs(int page, int pageSize) { if (!WebUtils.CheckRightsForAdminPostPages(false)) { return(null); } if (!WebUtils.CheckIfPrimaryBlog(false)) { return(null); } return(JsonBlogs.GetBlogs(page, pageSize)); }
public static JsonResponse <IEnumerable <KeyValuePair <string, string> > > GetCopyFromBlogs() { if (!WebUtils.CheckRightsForAdminPostPages(false)) { return(null); } if (!WebUtils.CheckIfPrimaryBlog(false)) { return(null); } return(new JsonResponse <IEnumerable <KeyValuePair <string, string> > >() { Success = true, Data = Blog.Blogs.Select(b => new KeyValuePair <string, string>(b.Id.ToString(), b.Name)) }); }
public static IEnumerable LoadGetttyImagesClient(string custId) { if (!WebUtils.CheckRightsForAdminPostPages(false)) { return(null); } if (!WebUtils.CheckIfPrimaryBlog(false)) { return(null); } var gettyImages = new GettyImages(); var userId = gettyImages.GetUserIdByEmail(Security.CurrentMembershipUser.Email); var imageResults = gettyImages.LoadGetttyImagesClient(userId); return(imageResults); }
/// <summary> /// Handles the Load event of the Page 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 Page_Load(object sender, EventArgs e) { WebUtils.CheckRightsForAdminPostPages(false); if (!Page.IsPostBack) { BindGrid(); LoadParentDropDown(ddlNewParent, null); } grid.RowEditing += new GridViewEditEventHandler(grid_RowEditing); grid.RowUpdating += new GridViewUpdateEventHandler(grid_RowUpdating); grid.RowCancelingEdit += delegate { Response.Redirect(Request.RawUrl); }; grid.RowDeleting += new GridViewDeleteEventHandler(grid_RowDeleting); grid.RowDataBound += new GridViewRowEventHandler(grid_RowDataBound); btnAdd.Click += new EventHandler(btnAdd_Click); btnAdd.Text = Resources.labels.add + " " + Resources.labels.category.ToLowerInvariant(); valExist.ServerValidate += new ServerValidateEventHandler(valExist_ServerValidate); Page.Title = Resources.labels.categories; }
public static IEnumerable LoadGetttyImages(string key) { var gettyImages = new GettyImages(); if (string.IsNullOrEmpty(key)) { return(new List <GettyImage>()); } if (!WebUtils.CheckRightsForAdminPostPages(false)) { return(null); } if (!WebUtils.CheckIfPrimaryBlog(false)) { return(null); } //Get 50 images from getty images by API var imageResults = gettyImages.GetGettyImages(key); return(imageResults); }
public static JsonResponse <JsonBlog> GetBlog(string blogId) { if (!WebUtils.CheckRightsForAdminPostPages(false)) { return(null); } if (!WebUtils.CheckIfPrimaryBlog(false)) { return(null); } if (string.IsNullOrWhiteSpace(blogId) || blogId.Length != 36) { return(new JsonResponse <JsonBlog>() { Success = false, Message = "Blog not found." }); } Blog blog = Blog.GetBlog(new Guid(blogId)); if (blog == null) { return(new JsonResponse <JsonBlog>() { Success = false, Message = "Blog not found." }); } return(new JsonResponse <JsonBlog>() { Success = true, Data = JsonBlogs.CreateJsonBlog(blog) }); }
protected void Page_Load(object sender, EventArgs e) { WebUtils.CheckRightsForAdminPostPages(false); }
public static JsonResponse SavePost( string id, string content, string title, string desc, string slug, string tags, string author, bool isPublished, bool hasCommentsEnabled, string cats, string date, string time) { WebUtils.CheckRightsForAdminPostPages(false); var response = new JsonResponse { Success = false }; var settings = BlogSettings.Instance; if (string.IsNullOrEmpty(id) && !Security.IsAuthorizedTo(Rights.CreateNewPosts)) { response.Message = "Not authorized to create new Posts."; return(response); } try { var post = string.IsNullOrEmpty(id) ? new BlogEngine.Core.Post() : BlogEngine.Core.Post.GetPost(new Guid(id)); if (post == null) { response.Message = "Post to Edit was not found."; return(response); } else if (!string.IsNullOrEmpty(id) && !post.CanUserEdit) { response.Message = "Not authorized to edit this Post."; return(response); } bool isSwitchingToPublished = isPublished && (post.New || !post.IsPublished); if (isSwitchingToPublished) { if (!post.CanPublish(author)) { response.Message = "Not authorized to publish this Post."; return(response); } } if (string.IsNullOrEmpty(content)) { content = "[No text]"; } post.Author = author; post.Title = title; post.Content = content; post.Description = desc; if (!string.IsNullOrEmpty(slug)) { post.Slug = Utils.RemoveIllegalCharacters(slug.Trim()); } post.DateCreated = DateTime.ParseExact(date + " " + time, "yyyy-MM-dd HH\\:mm", null).AddHours( -BlogSettings.Instance.Timezone); post.IsPublished = isPublished; post.HasCommentsEnabled = hasCommentsEnabled; post.Tags.Clear(); if (tags.Trim().Length > 0) { var vtags = tags.Trim().Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (var tag in vtags.Where(tag => string.IsNullOrEmpty(post.Tags.Find(t => t.Equals(tag.Trim(), StringComparison.OrdinalIgnoreCase))))) { post.Tags.Add(tag.Trim()); } } post.Categories.Clear(); if (cats.Trim().Length > 0) { var vcats = cats.Trim().Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); foreach (var cat in vcats) { post.Categories.Add(Category.GetCategory(new Guid(cat))); } } post.Save(); // If this is an unpublished post and the user does not have rights to // view unpublished posts, then redirect to the Posts list. if (post.IsVisible) { response.Data = post.RelativeLink; } else { response.Data = string.Format("{0}admin/Posts/Posts.aspx", Utils.RelativeWebRoot); } HttpContext.Current.Session.Remove("content"); HttpContext.Current.Session.Remove("title"); HttpContext.Current.Session.Remove("description"); HttpContext.Current.Session.Remove("slug"); HttpContext.Current.Session.Remove("tags"); } catch (Exception ex) { Utils.Log(string.Format("Admin.AjaxHelper.SavePost(): {0}", ex.Message)); response.Message = string.Format("Could not save post: {0}", ex.Message); return(response); } response.Success = true; response.Message = "Post saved"; return(response); }
public static IEnumerable LoadPosts(int page, string type, string filter, string title) { WebUtils.CheckRightsForAdminPostPages(false); return(JsonPosts.GetPosts(page, type, filter, title)); }
public static string LoadPostPager(int page) { WebUtils.CheckRightsForAdminPostPages(false); return(JsonPosts.GetPager(page)); }
public HttpResponseMessage Post(string action, string dirPath = "") { WebUtils.CheckRightsForAdminPostPages(false); HttpPostedFile file = HttpContext.Current.Request.Files[0]; action = action.ToLowerInvariant(); if (file != null && file.ContentLength > 0) { var dirName = string.Format("/{0}/{1}", DateTime.Now.ToString("yyyy"), DateTime.Now.ToString("MM")); var fileName = new FileInfo(file.FileName).Name; // to work in IE and others // iOS sends all images as "image.jpg" or "image.png" fileName = fileName.Replace("image.jpg", DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg"); fileName = fileName.Replace("image.png", DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".png"); var root = Blog.CurrentInstance.StorageLocation + Utils.FilesFolder; dirPath = dirPath.SanitizePath(root); if (!string.IsNullOrEmpty(dirPath)) { dirName = dirPath; } if (action == "filemgr" || action == "file") { string[] ImageExtensnios = { ".jpg", ".png", ".jpeg", ".tiff", ".gif", ".bmp" }; if (ImageExtensnios.Any(x => fileName.ToLower().Contains(x.ToLower()))) { action = "image"; } else { action = "file"; } } var dir = new BlogEngine.Core.FileSystem.Directory(); var retUrl = ""; if (action == "import") { if (Security.IsAdministrator) { return(ImportBlogML()); } } if (action == "profile") { if (Security.IsAuthorizedTo(Rights.EditOwnUser)) { // upload profile image dir = BlogService.GetDirectory("/avatars"); var dot = fileName.LastIndexOf("."); var ext = dot > 0 ? fileName.Substring(dot) : ""; var profileFileName = User.Identity.Name + ext; var imgPath = HttpContext.Current.Server.MapPath(dir.FullPath + "/" + profileFileName); var image = Image.FromStream(file.InputStream); Image thumb = image.GetThumbnailImage(80, 80, () => false, IntPtr.Zero); thumb.Save(imgPath); return(Request.CreateResponse(HttpStatusCode.Created, profileFileName)); } } if (action == "image") { if (Security.IsAuthorizedTo(Rights.EditOwnPosts)) { dir = BlogService.GetDirectory(dirName); var uploaded = BlogService.UploadFile(file.InputStream, fileName, dir, true); return(Request.CreateResponse(HttpStatusCode.Created, uploaded.AsImage.ImageUrl)); } } if (action == "file") { if (Security.IsAuthorizedTo(Rights.EditOwnPosts)) { dir = BlogService.GetDirectory(dirName); var uploaded = BlogService.UploadFile(file.InputStream, fileName, dir, true); retUrl = uploaded.FileDownloadPath + "|" + fileName + " (" + BytesToString(uploaded.FileSize) + ")"; return(Request.CreateResponse(HttpStatusCode.Created, retUrl)); } } if (action == "video") { if (Security.IsAuthorizedTo(Rights.EditOwnPosts)) { // default media folder var mediaFolder = "Custom/Media"; // get the mediaplayer extension and use it's folder var mediaPlayerExtension = BlogEngine.Core.Web.Extensions.ExtensionManager.GetExtension("MediaElementPlayer"); mediaFolder = mediaPlayerExtension.Settings[0].GetSingleValue("folder"); var folder = Utils.ApplicationRelativeWebRoot + mediaFolder + "/"; //var fileName = file.FileName; UploadVideo(folder, file, fileName); return(Request.CreateResponse(HttpStatusCode.Created, fileName)); } } } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event to initialize the page. /// </summary> /// <param name="e"> /// An <see cref="T:System.EventArgs"/> that contains the event data. /// </param> protected override void OnInit(EventArgs e) { WebUtils.CheckRightsForAdminPostPages(false); MaintainScrollPositionOnPostBack = true; BindTags(); BindUsers(); Page.Title = labels.add_Entry; Page.ClientScript.GetCallbackEventReference(this, "title", "ApplyCallback", "slug"); if (!String.IsNullOrEmpty(Request.QueryString["id"]) && Request.QueryString["id"].Length == 36) { var id = new Guid(Request.QueryString["id"]); Page.Title = string.Format("{0} {1}", labels.edit, labels.post); BindPost(id); BindCategories(id); } else { BindCategories(Guid.Empty); PreSelectAuthor(Page.User.Identity.Name); txtDate.Text = DateTime.Now.AddHours(BlogSettings.Instance.Timezone).ToString("yyyy-MM-dd"); txtTime.Text = DateTime.Now.AddHours(BlogSettings.Instance.Timezone).ToString("HH\\:mm"); cbEnableComments.Checked = BlogSettings.Instance.IsCommentsEnabled; cbPublish.Checked = Security.IsAuthorizedTo(Rights.PublishOwnPosts); if (Session["content"] != null) { txtContent.Text = Session["content"].ToString(); txtRawContent.Text = txtContent.Text; txtTitle.Text = Session["title"].ToString(); txtDescription.Text = Session["description"].ToString(); txtSlug.Text = Session["slug"].ToString(); txtTags.Text = Session["tags"].ToString(); } BindBookmarklet(); } if (!Security.IsAuthorizedTo(Rights.EditOtherUsersPosts)) { ddlAuthor.Enabled = false; } cbEnableComments.Enabled = BlogSettings.Instance.IsCommentsEnabled; if (Request.Cookies[RawEditorCookie] != null) { txtRawContent.Visible = true; txtContent.Visible = false; cbUseRaw.Checked = true; } btnCategory.Click += BtnCategoryClick; btnUploadFile.Click += BtnUploadFileClick; btnUploadImage.Click += BtnUploadImageClick; btnUploadVideo.Click += BtnUploadVideoClick; valExist.ServerValidate += ValExistServerValidate; cbUseRaw.CheckedChanged += CbUseRawCheckedChanged; base.OnInit(e); }
public HttpResponseMessage Post(string action) { WebUtils.CheckRightsForAdminPostPages(false); HttpPostedFile file = HttpContext.Current.Request.Files[0]; action = action.ToLower(); if (file != null && file.ContentLength > 0) { var dirName = string.Format("/{0}/{1}", DateTime.Now.ToString("yyyy"), DateTime.Now.ToString("MM")); var dir = BlogService.GetDirectory(dirName); var retUrl = ""; if (action == "import") { if (Security.IsAdministrator) { return(ImportBlogML()); } } if (action == "profile") { if (Security.IsAuthorizedTo(Rights.EditOwnUser)) { // upload profile image dir = BlogService.GetDirectory("/avatars"); var dot = file.FileName.IndexOf("."); var ext = dot > 0 ? file.FileName.Substring(dot) : ""; var fileName = User.Identity.Name + ext; var imgPath = HttpContext.Current.Server.MapPath(dir.FullPath + "/" + fileName); var image = Image.FromStream(file.InputStream); Image thumb = image.GetThumbnailImage(80, 80, () => false, IntPtr.Zero); thumb.Save(imgPath); return(Request.CreateResponse(HttpStatusCode.Created, fileName)); } } if (action == "image") { if (Security.IsAuthorizedTo(Rights.EditOwnPosts)) { var uploaded = BlogService.UploadFile(file.InputStream, file.FileName, dir, true); return(Request.CreateResponse(HttpStatusCode.Created, uploaded.FileDownloadPath)); } } if (action == "file") { if (Security.IsAuthorizedTo(Rights.EditOwnPosts)) { var uploaded = BlogService.UploadFile(file.InputStream, file.FileName, dir, true); retUrl = uploaded.FileDownloadPath + "|" + file.FileName + " (" + BytesToString(uploaded.FileSize) + ")"; return(Request.CreateResponse(HttpStatusCode.Created, retUrl)); } } if (action == "video") { if (Security.IsAuthorizedTo(Rights.EditOwnPosts)) { // default media folder var mediaFolder = "media"; // get the mediaplayer extension and use it's folder var mediaPlayerExtension = BlogEngine.Core.Web.Extensions.ExtensionManager.GetExtension("MediaElementPlayer"); mediaFolder = mediaPlayerExtension.Settings[0].GetSingleValue("folder"); var folder = Utils.ApplicationRelativeWebRoot + mediaFolder + "/"; var fileName = file.FileName; UploadVideo(folder, file, fileName); return(Request.CreateResponse(HttpStatusCode.Created, fileName)); } } } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }