/// <summary> /// Delete item /// </summary> /// <param name="type">Type (theme, post etc)</param> /// <param name="id">Id, for example "standard" for a theme</param> /// <param name="key">Key in the key/value for a field</param> /// <returns>True on success</returns> public bool Remove(string type, string id, string key) { if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.AccessAdminPages)) { throw new System.UnauthorizedAccessException(); } try { var item = new CustomField { CustomType = type, BlogId = Blog.CurrentInstance.BlogId, ObjectId = id, Key = key }; BlogEngine.Core.Providers.BlogService.DeleteCustomField(item); CustomFieldsParser.ClearCache(); return(true); } catch (Exception ex) { Utils.Log("Error updaging custom field", ex); return(false); } }
/// <summary> /// Write stream to the client before closing. /// </summary> public override void Close() { if (HtmlOut.Contains("webresource.axd", StringComparison.OrdinalIgnoreCase) && BlogSettings.Instance.CompressWebResource) { Regex reg = new Regex("<script\\s*src=\"((?=[^\"]*webresource.axd)[^\"]*)\"\\s*type=\"text/javascript\"[^>]*>[^<]*(?:</script>)?", RegexOptions.IgnoreCase); bool found = false; int idx = 0; var resKey = ""; var resources = new List <string>(); foreach (Match m in reg.Matches(HtmlOut)) { if (!found) // save where we found first resource file { idx = HtmlOut.IndexOf(m.Value); } var resUrl = GetScriptPathFromJsTag(m.Value); resKey += resUrl; resources.Add(resUrl); HtmlOut = HtmlOut.Replace(m.Value, ""); found = true; } if (found) { var hashKey = resKey.GetHashCode().ToString(); if (Blog.CurrentInstance.Cache[hashKey] == null) { // add resource file to the cache var resValue = ""; foreach (var r in resources) { resValue += RetrieveRemoteFile(r); } Blog.CurrentInstance.Cache.Insert(hashKey, resValue); } if (HtmlOut.Contains("</head>", StringComparison.OrdinalIgnoreCase)) { HtmlOut = HtmlOut.Insert(idx, string.Format("\n<script src=\"{0}res-{1}.js.axd\" type=\"text/javascript\"></script>", Utils.RelativeWebRoot, resKey.GetHashCode())); } } } // parse custom fields HtmlOut = CustomFieldsParser.GetPageHtml(HtmlOut); var outdata = Encoding.UTF8.GetBytes(HtmlOut); sink.Write(outdata, 0, outdata.GetLength(0)); sink.Close(); }
/// <summary> /// Crear fields for object type (post, theme etc) /// </summary> /// <param name="type">Custom type</param> /// <param name="id">Object id</param> public void ClearCustomFields(string type, string id) { if (!Security.IsAuthorizedTo(Rights.AccessAdminPages)) { throw new UnauthorizedAccessException(); } try { Providers.BlogService.ClearCustomFields(Blog.CurrentInstance.BlogId.ToString(), type, id); CustomFieldsParser.ClearCache(); } catch (Exception ex) { Utils.Log("Error updaging custom field", ex); } }
/// <summary> /// Install package /// </summary> /// <param name="pkgId"></param> public static bool InstallPackage(string pkgId) { try { // if package already installed - uninstall it if (BlogService.InstalledFromGalleryPackages() != null) { if (BlogService.InstalledFromGalleryPackages().Find(p => p.PackageId == pkgId) != null) { UninstallPackage(pkgId); } } var packageManager = new PackageManager(_repository, new DefaultPackagePathResolver(BlogConfig.GalleryFeedUrl), new PhysicalFileSystem(HttpContext.Current.Server.MapPath(Utils.ApplicationRelativeWebRoot + "App_Data/packages")) ); var package = _repository.FindPackage(pkgId); packageManager.InstallPackage(package, false, true); var iPkg = new InstalledPackage { PackageId = package.Id, Version = package.Version.ToString() }; BlogService.InsertPackage(iPkg); var packageFiles = FileSystem.InstallPackage(package); BlogService.InsertPackageFiles(packageFiles); Blog.CurrentInstance.Cache.Remove(Constants.CacheKey); CustomFieldsParser.ClearCache(); Utils.Log($"Installed package {pkgId} by {Security.CurrentUser.Identity.Name}"); } catch (Exception ex) { Utils.Log("BlogEngine.Core.Packaging.Installer.InstallPackage(" + pkgId + ")", ex); UninstallPackage(pkgId); throw; } return(true); }
/// <summary> /// Install package /// </summary> /// <param name="pkgId"></param> public static JsonResponse InstallPackage(string pkgId) { try { if (BlogService.InstalledFromGalleryPackages() != null && BlogService.InstalledFromGalleryPackages().Find(p => p.PackageId == pkgId) != null) { UninstallPackage(pkgId); } var packageManager = new PackageManager( _repository, new DefaultPackagePathResolver(BlogSettings.Instance.GalleryFeedUrl), new PhysicalFileSystem(HttpContext.Current.Server.MapPath(Utils.ApplicationRelativeWebRoot + "App_Data/packages")) ); var package = _repository.FindPackage(pkgId); packageManager.InstallPackage(package, false, true); var iPkg = new InstalledPackage { PackageId = package.Id, Version = package.Version.ToString() }; BlogService.InsertPackage(iPkg); var packageFiles = FileSystem.InstallPackage(package.Id, package.Version.ToString()); BlogService.InsertPackageFiles(packageFiles); Blog.CurrentInstance.Cache.Remove(Constants.CacheKey); CustomFieldsParser.ClearCache(); Utils.Log(string.Format("Installed package {0} by {1}", pkgId, Security.CurrentUser.Identity.Name)); } catch (Exception ex) { Utils.Log("BlogEngine.Core.Packaging.Installer.InstallPackage(" + pkgId + ")", ex); UninstallPackage(pkgId); throw; } return(new JsonResponse { Success = true, Message = "Package successfully installed" }); }
static void DeleteThemeCustomFields(string theme) { var p = CachedPackages.FirstOrDefault(pkg => pkg.Id == theme); if (p != null && p.PackageType != null && p.PackageType.ToLower() == "theme") { var fields = BlogEngine.Core.Providers.BlogService.FillCustomFields(); foreach (var f in fields) { if (f.BlogId == Blog.CurrentInstance.Id && f.CustomType.ToLower() == "theme" && f.ObjectId == theme) { BlogEngine.Core.Providers.BlogService.DeleteCustomField(f); } } CustomFieldsParser.ClearCache(); } }
/// <summary> /// Update item /// </summary> /// <param name="item">Custom field</param> /// <returns>True on success</returns> public bool Update(CustomField item) { if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.AccessAdminPages)) { throw new System.UnauthorizedAccessException(); } try { BlogEngine.Core.Providers.BlogService.SaveCustomField(item); CustomFieldsParser.ClearCache(); return(true); } catch (Exception ex) { Utils.Log("Error updaging custom field", ex); return(false); } }
/// <summary> /// Update item /// </summary> /// <param name="item">Custom field</param> /// <returns>True on success</returns> public bool Update(CustomField item) { if (!Security.IsAuthorizedTo(Rights.AccessAdminPages)) { throw new UnauthorizedAccessException(); } try { item.BlogId = Blog.CurrentInstance.Id; Providers.BlogService.SaveCustomField(item); CustomFieldsParser.ClearCache(); return(true); } catch (Exception ex) { Utils.Log("Error updaging custom field", ex); return(false); } }
/// <summary> /// Add new item /// </summary> /// <param name="item">Custom field</param> /// <returns>Added field</returns> public CustomField Add(CustomField item) { if (!Security.IsAuthorizedTo(Rights.AccessAdminPages)) { throw new UnauthorizedAccessException(); } try { //if (AlreadyExists(item)) // throw new ApplicationException("Custom field already exists"); Providers.BlogService.SaveCustomField(item); CustomFieldsParser.ClearCache(); return(item); } catch (Exception ex) { Utils.Log("Error adding custom field", ex); throw; } }
/// <summary> /// Writes the RSS channel item element information to the specified <see cref="XmlWriter"/> using the supplied <see cref="Page"/>. /// </summary> /// <param name="writer"> /// The <see cref="XmlWriter"/> to write channel item element information to. /// </param> /// <param name="publishable"> /// The <see cref="IPublishable"/> used to generate channel item content. /// </param> private static void WriteRssItem(XmlWriter writer, IPublishable publishable) { // ------------------------------------------------------------ // Cast IPublishable as Post to support comments/trackback // ------------------------------------------------------------ var post = publishable as Post; var comment = publishable as Comment; // ------------------------------------------------------------ // Raise serving event // ------------------------------------------------------------ var arg = new ServingEventArgs(publishable.Content, ServingLocation.Feed); publishable.OnServing(arg); if (arg.Cancel) { return; } // ------------------------------------------------------------ // Modify post content to make references absolute // ------------------------------------------------------------ var content = Utils.ConvertPublishablePathsToAbsolute(arg.Body, publishable); // handle custom fields in the posts content = CustomFieldsParser.GetPageHtml(content); if (comment != null) { content = content.Replace(Environment.NewLine, "<br />"); } writer.WriteStartElement("item"); // ------------------------------------------------------------ // Write required channel item elements // ------------------------------------------------------------ if (comment != null) { writer.WriteElementString("title", publishable.Author + " on " + comment.Parent.Title); } else { writer.WriteElementString("title", publishable.Title); } writer.WriteElementString("description", content); writer.WriteElementString("link", publishable.AbsoluteLink.ToString()); // ------------------------------------------------------------ // Write enclosure tag for podcasting support // ------------------------------------------------------------ if (BlogSettings.Instance.EnableEnclosures) { var encloser = GetEnclosure(content, publishable); if (!string.IsNullOrEmpty(encloser)) { writer.WriteRaw(encloser); } } // ------------------------------------------------------------ // Write optional channel item elements // ------------------------------------------------------------ if (!string.IsNullOrEmpty(BlogSettings.Instance.FeedAuthor)) { writer.WriteElementString("author", BlogSettings.Instance.FeedAuthor); } if (post != null) { writer.WriteElementString( "comments", String.Concat(publishable.AbsoluteLink.ToString(), "#comment")); } writer.WriteElementString("guid", GetPermaLink(publishable).ToString()); writer.WriteElementString("pubDate", RssDateString(publishable.DateCreated)); // ------------------------------------------------------------ // Write channel item category elements // ------------------------------------------------------------ if (publishable.Categories != null) { foreach (var category in publishable.Categories) { writer.WriteElementString("category", category.Title); } } // ------------------------------------------------------------ // Write channel item tag elements // ------------------------------------------------------------ if (BlogSettings.Instance.EnableTagExport && publishable.Categories != null) { foreach (var tag in publishable.Tags) { writer.WriteElementString("betag", "tag", "http://dotnetblogengine.net/schemas/tags", tag); } } // ------------------------------------------------------------ // Write Dublin Core syndication extension elements // ------------------------------------------------------------ if (!String.IsNullOrEmpty(publishable.Author)) { writer.WriteElementString("dc", "publisher", "http://purl.org/dc/elements/1.1/", publishable.Author); } // if (!String.IsNullOrEmpty(publishable.Description)) // { // writer.WriteElementString("dc", "description", "http://purl.org/dc/elements/1.1/", publishable.Description); // } // ------------------------------------------------------------ // Write pingback syndication extension elements // ------------------------------------------------------------ Uri pingbackServer; if (Uri.TryCreate( String.Concat(publishable.Blog.AbsoluteWebRoot.ToString().TrimEnd('/'), "/pingback.axd"), UriKind.RelativeOrAbsolute, out pingbackServer)) { writer.WriteElementString( "pingback", "server", "http://madskills.com/public/xml/rss/module/pingback/", pingbackServer.ToString()); writer.WriteElementString( "pingback", "target", "http://madskills.com/public/xml/rss/module/pingback/", GetPermaLink(publishable).ToString()); } // ------------------------------------------------------------ // Write slash syndication extension elements // ------------------------------------------------------------ if (post != null && post.Comments != null) { writer.WriteElementString( "slash", "comments", "http://purl.org/rss/1.0/modules/slash/", post.Comments.Count.ToString(CultureInfo.InvariantCulture)); } // ------------------------------------------------------------ // Write trackback syndication extension elements // ------------------------------------------------------------ if (post != null && post.TrackbackLink != null) { writer.WriteElementString( "trackback", "ping", "http://madskills.com/public/xml/rss/module/trackback/", post.TrackbackLink.ToString()); } // ------------------------------------------------------------ // Write well-formed web syndication extension elements // ------------------------------------------------------------ writer.WriteElementString( "wfw", "comment", "http://wellformedweb.org/CommentAPI/", String.Concat(publishable.AbsoluteLink.ToString(), "#comment")); writer.WriteElementString( "wfw", "commentRss", "http://wellformedweb.org/CommentAPI/", string.Format("{0}/syndication.axd?post={1}", publishable.Blog.AbsoluteWebRoot.ToString().TrimEnd('/'), publishable.Id)); // ------------------------------------------------------------ // Write </item> element // ------------------------------------------------------------ writer.WriteEndElement(); }