private static void LoadSettings() { ExtensionSettings settings = ExtensionManager.GetSettings("DotNetShoutout"); _borderColor = settings.GetSingleValue("borderColor"); _textBackColor = settings.GetSingleValue("textBackColor"); _textForeColor = settings.GetSingleValue("textForeColor"); _countBackColor = settings.GetSingleValue("countBackColor"); _countForeColor = settings.GetSingleValue("countForeColor"); }
void Post_Serving(object sender, ServingEventArgs e) { DateTime lastUpload = DateTime.Parse(_settings.GetSingleValue("LastUpload")); int interval = Int32.Parse(_settings.GetSingleValue("Interval")); if (DateTime.Now > lastUpload + TimeSpan.FromMinutes((double)interval)) { try { _settings.UpdateScalarValue("LastUpload", DateTime.Now.ToUniversalTime().ToString("u")); Import(); } catch (Exception ex) { Log(string.Format("FATAL: Uncaught exception: {0}", ex.ToString()), LogLevel.Critical); } if (_logStream != null) { _logStream.Close(); _logStream = null; _logLock = null; } } if (e.Location == ServingLocation.SinglePost) { AddOpenGraphTags(); } }
private void Post_Serving(object sender, ServingEventArgs e) { if (e.Location != ServingLocation.PostList && e.Location != ServingLocation.SinglePost) { return; } string regex__1 = @"\[youtube:.*?\]"; MatchCollection matches = Regex.Matches(e.Body, regex__1); if (matches.Count == 0) { return; } Int32 width = default(Int32); Int32 height = default(Int32); Int32 border = default(Int32); String color1 = default(String); String color2 = default(String); String BaseURL = default(String); try { width = Int32.Parse(settings.GetSingleValue("width")); height = Int32.Parse(settings.GetSingleValue("height")); border = Int32.Parse(settings.GetSingleValue("border")); color1 = settings.GetSingleValue("color1"); color2 = settings.GetSingleValue("color2"); BaseURL = "http://www.youtube.com/v/"; } catch { return; } for (int i = 0; i < matches.Count; i++) { Int32 length = "[youtube:".Length; string mediaFile = matches[i].Value.Substring(length, matches[i].Value.Length - length - 1); string player = @"<div id=""YouTubePlayer_{0}"" style=""width:{2}px; height:{3}px;""> <object width=""{2}"" height=""{3}""> <param name=""movie"" value=""{7}{1}&fs=1&border={4}&color1=0x{5}&color2=0x{6}""></param> <param name=""allowFullScreen"" value=""true""></param> <embed src=""{7}{1}&fs=1&border={4}&color1=0x{5}&color2=0x{6}"" type = ""application/x-shockwave-flash"" width=""{2}"" height=""{3}"" allowfullscreen=""true""></embed> </object> </div>"; e.Body = e.Body.Replace(matches[i].Value, String.Format(player, i, mediaFile, width, height, border, color1, color2, BaseURL)); } }
/// <summary> /// Initializes anti-spam service /// </summary> /// <returns> /// True if service online and credentials validated /// </returns> public bool Initialize() { if (!ExtensionManager.ExtensionEnabled("TypePadFilter")) { return(false); } site = settings.GetSingleValue("SiteURL"); key = settings.GetSingleValue("ApiKey"); api = new Akismet(key, site, "BlogEngine.net 1.5", "api.antispam.typepad.com"); return(api.VerifyKey()); }
private void AddJavaScriptToPage(Page page) { if (page != null) { string innerFadeScript = "InnerFadeScript"; ClientScriptManager clientScriptManager = Page.ClientScript; Type csType = page.GetType(); StringBuilder scripts = new StringBuilder(); // register innerfade script plugin if (!clientScriptManager.IsClientScriptBlockRegistered(csType, innerFadeScript)) { if (bool.Parse(_rotatorSettings.GetSingleValue("UseExtensionJQuery"))) { scripts.AppendLine("<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js\"></script>"); } scripts.AppendFormat("<script type=\"text/javascript\" src=\"{0}Custom/Controls/FeaturedPostsRotator/js/jquery.innerfade.js\"></script>", Utils.AbsoluteWebRoot); scripts.AppendLine("<script type=\"text/javascript\">"); scripts.AppendLine("$(document).ready(function () {"); scripts.AppendLine("$('#show').innerFade({ indexContainer: '#index', currentItemContainer: '.current', totalItemsContainer: '.total', animationtype: 'fade', speed: 3000, timeout: 5000, type: 'sequence', prevLink: '.prev', nextLink: '.next', containerheight: 260 });"); scripts.AppendLine("});"); scripts.AppendLine("</script>"); page.ClientScript.RegisterStartupScript(csType, innerFadeScript, scripts.ToString()); } } }
public bool Initialize() { if (!ExtensionManager.ExtensionEnabled("AkismetFilter")) { return(false); } if (_settings == null) { InitSettings(); } _site = _settings.GetSingleValue("SiteURL"); _key = _settings.GetSingleValue("ApiKey"); _api = new Akismet(_key, _site, "BlogEngine.net 1.6"); return(_api.VerifyKey()); }
static string GetOption(string opt) { if (_options != null) { string pattern = "\tSyntaxHighlighter.defaults['{0}'] = {1};"; string val = _options.GetSingleValue(opt).ToLowerInvariant(); return(string.Format(pattern, opt, val)); } return(""); }
/// <summary> /// An event that handles ServingEventArgs /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Post_Serving(object sender, ServingEventArgs e) { if (!string.IsNullOrEmpty(e.Body)) { // only process the posts if (e.Location == ServingLocation.PostList || e.Location == ServingLocation.SinglePost || e.Location == ServingLocation.SinglePage) { string regex = @"\[donate:.*]"; MatchCollection matches = Regex.Matches(e.Body, regex); if (matches.Count > 0) { foreach (Match match in matches) { string item_name = match.Value.Replace("[donate:", "").Replace("]", ""); string literal_donate = ""; literal_donate = GetDonateButton(item_name, double.Parse(settings.GetSingleValue("taxRate")), double.Parse(settings.GetSingleValue("shipping")), settings.GetSingleValue("username")); e.Body = e.Body.Replace(match.Value, literal_donate); } } } } }
protected override void OnInit(EventArgs e) { base.OnInit(e); ExtensionSettings Settings = ExtensionManager.GetSettings("Recaptcha"); publicKey = Settings.GetSingleValue("PublicKey"); privateKey = Settings.GetSingleValue("PrivateKey"); if (String.IsNullOrEmpty(Theme)) { Theme = Settings.GetSingleValue("Theme"); } if (RecaptchaEnabled && RecaptchaNecessary) { skipRecaptcha = false; } if (String.IsNullOrEmpty(publicKey) || String.IsNullOrEmpty(privateKey)) { throw new ApplicationException("reCAPTCHA needs to be configured with a public & private key."); } }
private void OnPostServing(object sender, ServingEventArgs e) { Post post = (Post)sender; if (bool.Parse(_settings.GetSingleValue("ExcludeAuthenticatedViews")) && HttpContext.Current.Request.IsAuthenticated) { return; } string pattern = _settings.GetSingleValue("ExcludeViewsFromIPs"); string ip = HttpContext.Current.Request.UserHostAddress; bool matchedIp = (!string.IsNullOrEmpty(pattern) && Regex.IsMatch(ip, pattern)); // Do not count view of authenticated users and users who have IPs match the pattern if (matchedIp) { return; } if (e.Location.Equals(ServingLocation.SinglePost)) { post.View(); } }
private static void AddCssStyles(Page page) { AddStylesheet("shCore.css", page); if (_themes != null) { switch (_themes.GetSingleValue("SelectedTheme")) { case "Django": AddStylesheet("shThemeDjango.css", page); break; case "Eclipse": AddStylesheet("shThemeEclipse.css", page); break; case "Emacs": AddStylesheet("shThemeEmacs.css", page); break; case "FadeToGrey": AddStylesheet("shThemeFadeToGrey.css", page); break; case "MDUltra": AddStylesheet("shThemeMDUltra.css", page); break; case "Midnight": AddStylesheet("shThemeMidnight.css", page); break; case "Dark": AddStylesheet("shThemeRDark.css", page); break; default: AddStylesheet("shThemeDefault.css", page); break; } } }
private static void AddJavaScripts(Page page) { AddJavaScript("shCore.js", page); if (_brushes != null) { if (_brushes.GetSingleValue("shBrushBash").ToLowerInvariant() == "true") { AddJavaScript("shBrushBash.js", page); } if (_brushes.GetSingleValue("shBrushCpp").ToLowerInvariant() == "true") { AddJavaScript("shBrushCpp.js", page); } if (_brushes.GetSingleValue("shBrushCSharp").ToLowerInvariant() == "true") { AddJavaScript("shBrushCSharp.js", page); } if (_brushes.GetSingleValue("shBrushCss").ToLowerInvariant() == "true") { AddJavaScript("shBrushCss.js", page); } if (_brushes.GetSingleValue("shBrushDelphi").ToLowerInvariant() == "true") { AddJavaScript("shBrushDelphi.js", page); } if (_brushes.GetSingleValue("shBrushDiff").ToLowerInvariant() == "true") { AddJavaScript("shBrushDiff.js", page); } if (_brushes.GetSingleValue("shBrushGroovy").ToLowerInvariant() == "true") { AddJavaScript("shBrushGroovy.js", page); } if (_brushes.GetSingleValue("shBrushJava").ToLowerInvariant() == "true") { AddJavaScript("shBrushJava.js", page); } if (_brushes.GetSingleValue("shBrushJScript").ToLowerInvariant() == "true") { AddJavaScript("shBrushJScript.js", page); } if (_brushes.GetSingleValue("shBrushPhp").ToLowerInvariant() == "true") { AddJavaScript("shBrushPhp.js", page); } if (_brushes.GetSingleValue("shBrushPlain").ToLowerInvariant() == "true") { AddJavaScript("shBrushPlain.js", page); } if (_brushes.GetSingleValue("shBrushPython").ToLowerInvariant() == "true") { AddJavaScript("shBrushPython.js", page); } if (_brushes.GetSingleValue("shBrushRuby").ToLowerInvariant() == "true") { AddJavaScript("shBrushRuby.js", page); } if (_brushes.GetSingleValue("shBrushScala").ToLowerInvariant() == "true") { AddJavaScript("shBrushScala.js", page); } if (_brushes.GetSingleValue("shBrushSql").ToLowerInvariant() == "true") { AddJavaScript("shBrushSql.js", page); } if (_brushes.GetSingleValue("shBrushVb").ToLowerInvariant() == "true") { AddJavaScript("shBrushVb.js", page); } if (_brushes.GetSingleValue("shBrushXml").ToLowerInvariant() == "true") { AddJavaScript("shBrushXml.js", page); } if (_brushes.GetSingleValue("shBrushColdFusion").ToLowerInvariant() == "true") { AddJavaScript("shBrushColdFusion.js", page); } if (_brushes.GetSingleValue("shBrushErlang").ToLowerInvariant() == "true") { AddJavaScript("shBrushErlang.js", page); } if (_brushes.GetSingleValue("shBrushJavaFX").ToLowerInvariant() == "true") { AddJavaScript("shBrushJavaFX.js", page); } if (_brushes.GetSingleValue("shBrushPerl").ToLowerInvariant() == "true") { AddJavaScript("shBrushPerl.js", page); } if (_brushes.GetSingleValue("shBrushPowerShell").ToLowerInvariant() == "true") { AddJavaScript("shBrushPowerShell.js", page); } if (_brushes.GetSingleValue("shBrushFSharp").ToLowerInvariant() == "true") { AddJavaScript("shBrushFSharp.js", page); } } }
void ImageGuarding(object sender, EventArgs e) { HttpContext context = HttpContext.Current; if (context.Request.UrlReferrer != null) { if (string.Compare(context.Request.Url.Host.Replace("www.", ""), context.Request.UrlReferrer.Host.Replace("www.", ""), true, CultureInfo.InvariantCulture) != 0) { string guardingType = settings.GetSingleValue("guardingType"); if (guardingType.Equals("Reject")) { context.Response.StatusCode = 403; context.Response.End(); } else if (guardingType.Equals("Block")) { string blockImagePath = settings.GetSingleValue("blockImagePath"); var fi = new FileInfo(context.Server.MapPath(blockImagePath)); if (fi.Exists) { //context.Response.Cache.SetCacheability(HttpCacheability.Public); //context.Response.Cache.SetExpires(DateTime.Now.AddYears(1)); string extension = Path.GetExtension(fi.Name); context.Response.ContentType = string.Compare(extension.ToUpper(), "JPG") == 0 ? "image/jpeg" : string.Format("image/{0}", extension); context.Response.TransmitFile(fi.FullName); context.Response.End(); } } else if (guardingType.Equals("Watermark")) { FileInfo originImageFileInfo = GetOriginalImage(); if (originImageFileInfo != null) { TextWatermarker txtWatermarker = null; ImageWatermarker imgWatermarker = null; Image originImage = Bitmap.FromFile(originImageFileInfo.FullName); string watermarkText = settings.GetSingleValue("watermarkText"); if (!string.IsNullOrWhiteSpace(watermarkText)) { txtWatermarker = new TextWatermarker(originImage, watermarkText); txtWatermarker.AddWatermark(); originImage = txtWatermarker.WatermarkedImage; } string watermarkImagePath = settings.GetSingleValue("watermarkImagePath"); if (!string.IsNullOrWhiteSpace(watermarkImagePath)) { FileInfo fi = new FileInfo(context.Server.MapPath(watermarkImagePath)); if (fi.Exists) { Image watermarkImage = Bitmap.FromFile(fi.FullName); imgWatermarker = new ImageWatermarker(originImage, watermarkImage); imgWatermarker.Position = WatermarkPostion.BottomLeft; imgWatermarker.AddWatermark(); originImage = imgWatermarker.WatermarkedImage; } } // Serving the watermarked image //context.Response.Cache.SetCacheability(HttpCacheability.Public); //context.Response.Cache.SetExpires(DateTime.Now.AddYears(1)); string extension = Path.GetExtension(originImageFileInfo.Name); context.Response.ContentType = string.Compare(extension.ToUpper(), "JPG") == 0 ? "image/jpeg" : string.Format("image/{0}", extension); //originImage.Save(context.Response.OutputStream, ImageHelper.GetImageFormatByExtension(extension)); MemoryStream mem = new MemoryStream(); originImage.Save(mem, ImageHelper.GetImageFormatByExtension(extension)); mem.WriteTo(context.Response.OutputStream); mem.Dispose(); originImage.Dispose(); if (txtWatermarker != null) { txtWatermarker.Dispose(); } if (imgWatermarker != null) { imgWatermarker.Dispose(); } context.Response.End(); } else { context.Response.StatusCode = 404; context.Response.End(); } } else { } } else { // string.Compare(context.Request.Url.Host, context.Request.UrlReferrer.Host, true, CultureInfo.InvariantCulture) == 0 // The request host and the referrer host are the same, serve the image normally //FileInfo originImageFileInfo = GetOriginalImage(); //if (originImageFileInfo != null) //{ // TextWatermarker txtWatermarker = null; // Image originImage = Bitmap.FromFile(originImageFileInfo.FullName); // string watermarkText = context.Request.Url.Host; // if (!string.IsNullOrWhiteSpace(watermarkText)) // { // txtWatermarker = new TextWatermarker(originImage, watermarkText); // txtWatermarker.Position = WatermarkPostion.TopLeft; // txtWatermarker.AddWatermark(); // originImage = txtWatermarker.WatermarkedImage; // } // watermarkText = context.Request.UrlReferrer.Host; // if (!string.IsNullOrWhiteSpace(watermarkText)) // { // txtWatermarker = new TextWatermarker(originImage, watermarkText); // txtWatermarker.AddWatermark(); // originImage = txtWatermarker.WatermarkedImage; // } // string extension = Path.GetExtension(originImageFileInfo.Name); // context.Response.ContentType = string.Compare(extension.ToUpper(), "JPG") == 0 ? "image/jpeg" : string.Format("image/{0}", extension); // //originImage.Save(context.Response.OutputStream, ImageHelper.GetImageFormatByExtension(extension)); // MemoryStream mem = new MemoryStream(); // originImage.Save(mem, ImageHelper.GetImageFormatByExtension(extension)); // mem.WriteTo(context.Response.OutputStream); // mem.Dispose(); // originImage.Dispose(); // if (txtWatermarker != null) // txtWatermarker.Dispose(); // context.Response.End(); //} //else //{ // context.Response.StatusCode = 404; // context.Response.End(); //} } } }
protected string GetAlbumsTable() { if (string.IsNullOrEmpty(Settings.GetSingleValue("Account"))) { return(string.Empty); } var service = new PicasaService("exampleCo-exampleApp-1"); string usr = Settings.GetSingleValue("Account") + "@gmail.com"; string pwd = Settings.GetSingleValue("Password"); service.setUserCredentials(usr, pwd); var sb = new StringBuilder("<table class=\"beTable\">"); var query = new AlbumQuery(PicasaQuery.CreatePicasaUri(usr)); PicasaFeed feed = service.Query(query); sb.Append(GetHeader()); var cnt = 0; foreach (PicasaEntry entry in feed.Entries) { var ac = new AlbumAccessor(entry); const string cell = "<td>{0}</td>"; sb.Append(cnt % 2 == 0 ? "<tr>" : "<tr class=\"alt\">"); // thumbnail string albumUri = ((Google.GData.Client.AtomEntry)(entry)).AlternateUri.ToString(); string firstThumbUrl = entry.Media.Thumbnails[0].Attributes["url"] as string; string thumbAncr = string.Format("<a href=\"{2}\"><img src=\"{0}\" alt=\"{1}\" width=\"40\" /></a>", firstThumbUrl, entry.Title.Text, albumUri); sb.Append(string.Format(cell, thumbAncr)); // title sb.Append(string.Format(cell, ac.AlbumTitle)); // description sb.Append(string.Format(cell, ac.AlbumSummary + " ")); // number of photos sb.Append(string.Format(cell, ac.NumPhotos)); // access sb.Append(string.Format(cell, ac.Access)); // extension tag string feedUri = entry.FeedUri; const string showTag = "[PicasaShow:{0}]"; const string albmTag = "[PicasaAlbum:{0}]"; if (ac.Access.ToLower() == "protected") { sb.Append(string.Format(cell, " ")); sb.Append(string.Format(cell, " ")); } else { sb.Append(string.Format(cell, string.Format(showTag, ac.AlbumTitle))); sb.Append(string.Format(cell, string.Format(albmTag, ac.AlbumTitle))); } sb.Append("</tr>"); cnt++; } return(sb + "</table>"); }
private static string GetSlideShow(string albumId) { string s; try { var service = new PicasaService("exampleCo-exampleApp-1"); string usr = Settings.GetSingleValue("Account") + "@gmail.com"; string pwd = Settings.GetSingleValue("Password"); service.setUserCredentials(usr, pwd); var query = new AlbumQuery(PicasaQuery.CreatePicasaUri(usr)); PicasaFeed feed = service.Query(query); string id = ""; string key = ""; foreach (PicasaEntry entry in feed.Entries) { var ac = new AlbumAccessor(entry); if (ac.Name == albumId) { id = ac.Id; string feedUri = entry.FeedUri; if (feedUri.Contains("authkey=")) { string authKey = feedUri.Substring(feedUri.IndexOf("authkey=")).Substring(8); key = authKey; } } } if (key.Length > 0) { key = "authkey%3D" + key; } string user = Settings.GetSingleValue("Account"); string auto = ""; if (bool.Parse(Settings.GetSingleValue("AutoPlay")) == false) { auto = "&noautoplay=1"; } string width = Settings.GetSingleValue("ShowWidth"); string height = "96"; if (int.Parse(width) > 0) { height = (int.Parse(width) * 0.74).ToString(); } s = string.Format(Tag, id, key, user, auto, width, height); } catch (Exception exp) { s = exp.Message; } return(s); }
/// <summary> /// Build object tag /// </summary> /// <param name="soundFile">Name of the mp3 file ("my song.mp3")</param> /// <returns>Flash object markup</returns> public static string PlayerObject(string soundFile) { string sFile = string.Empty; string[] sFiles = soundFile.Split(",".ToCharArray()); var mp3Root = string.Format("{0}Custom/Media/mp3/", Utils.AbsoluteWebRoot); foreach (string file in sFiles) { if (file.Substring(0, 7) == "http://") { sFile += file; } else { sFile += mp3Root + file; } sFile += ","; } sFile = sFile.Substring(0, sFile.Length - 1); sFile = HttpUtility.UrlEncode(sFile); var playerRoot = string.Format("{0}Custom/Controls/Mp3Player/", Utils.AbsoluteWebRoot); const string s = "<p>" + "<object type='application/x-shockwave-flash' data='{0}player.swf' id='audioplayer{1}' height='{18}' width='{17}'>" + "<param name='movie' value='{0}player.swf'>" + "<param name='FlashVars' value='playerID={1}&bg=0x{5}&leftbg=0x{6}&lefticon=0x{7}&rightbg=0x{8}&rightbghover=0x{9}&righticon=0x{10}&righticonhover=0x{11}&text=0x{12}&slider=0x{13}&track=0x{14}&border=0x{15}&loader=0x{16}&soundFile={2}'>" + "<param name='quality' value='high'>" + "<param name='menu' value='{3}'>" + "<param name='bgcolor' value='{4}'>" + "</object>" + "</p>"; cnt++; return(String.Format(s, playerRoot, cnt, sFile, "No", Settings.GetSingleValue(BgColor), Settings.GetSingleValue(Bg), Settings.GetSingleValue(Leftbg), Settings.GetSingleValue(Lefticon), Settings.GetSingleValue(Rightbg), Settings.GetSingleValue(Rightbghover), Settings.GetSingleValue(Righticon), Settings.GetSingleValue(Righticonhover), Settings.GetSingleValue(Text), Settings.GetSingleValue(Slider), Settings.GetSingleValue(Track), Settings.GetSingleValue(Border), Settings.GetSingleValue(Loader), Settings.GetSingleValue(Width), Settings.GetSingleValue(Height))); }