Example #1
0
        public Task <string> RenderViewAsync(PageEarModule module, PageEarModuleController.Model model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            if (Manager.EditMode)
            {
                hb.Append($@"
<div class='{Globals.CssDivWarning}'>
    {HE(this.__ResStr("changeMod", "Change \"Module Settings\" to configure the page ear displayed"))}
</div>");
            }

            if (module.AdImage_Data.Length > 0 && module.CoverImage_Data.Length > 0 && !string.IsNullOrWhiteSpace(module.ClickUrl))
            {
                Manager.ScriptManager.AddLast($@"
$('body').peelback({{
    adImage: '{JE(ImageHTML.FormatUrl(YetaWF.Core.Modules.ModuleImageSupport.ImageType, null, module.AdImage))}',
    peelImage: '{JE(ImageHTML.FormatUrl(YetaWF.Core.Modules.ModuleImageSupport.ImageType, null, module.CoverImage))}',
    clickURL: '{JE(module.ClickUrl)}',
    smallSize: {module.SmallSize},
    bigSize: {module.LargeSize},
    autoAnimate: {(module.Animate ? "true" : "false")},
    //gaTrack: true, //RFFU
    //gaLabel: '#1 Stegosaurus',
    debug: false
}});

// Listen for events that the page is changing
$YetaWF.registerPageChange(true, function () {{
    // when the page is removed, we need to clean up
    $('#peelback').remove();
}});");
            }
            return(Task.FromResult(hb.ToString()));
        }
Example #2
0
        private string GetImage(PageDefinition pageDef)
        {
            string image;
            string type;

            if (pageDef.FavIcon != null)
            {
                type  = PageDefinition.ImageType;
                image = pageDef.FavIcon;
            }
            else if (Module.DefaultImage != null)
            {
                type  = ModuleImageSupport.ImageType;
                image = Module.DefaultImage;
            }
            else
            {
                type  = PageDefinition.ImageType;
                image = Guid.Empty.ToString();
            }
            int size;

            switch (Module.Style)
            {
            default:
            case PageBarModule.PanelStyleEnum.Vertical:
                size = 32;
                break;

            case PageBarModule.PanelStyleEnum.Horizontal:
                size = 32;
                break;
            }
            return(ImageHTML.FormatUrl(type, null, image, size, size, Stretch: true));
        }
Example #3
0
        /// <summary>
        /// Renders an image &lt;img&gt; tag with specified attributes and returns HTML.
        /// </summary>
        /// <param name="imageType">The image type which must match a registered image handler. The YetaWF.Core.Image.ImageSupport.AddHandler method is used to register an image handler.</param>
        /// <param name="width">The width of the image. Both <paramref name="width"/> and <paramref name="height"/> may be 0, in which case no size attributes are rendered.</param>
        /// <param name="height">The height of the image. Both <paramref name="width"/> and <paramref name="height"/> may be 0, in which case no size attributes are rendered.</param>
        /// <param name="model">The model representing the image.</param>
        /// <param name="CacheBuster">A value that becomes part of the image URL, which can be used to defeat client-side caching. May be null.</param>
        /// <param name="Alt">The text that is rendered as part of the &lt;img&gt; tag's Alt attribute. May be null in which case the text "Image" is used.</param>
        /// <param name="ExternalUrl">Defines whether a full URL including domain is rendered (true) or whether just the path is used (false).</param>
        /// <param name="SecurityType">The security type of the rendered image URL.</param>
        /// <returns></returns>
        public static string RenderImage(string imageType, int width, int height, string model,
                                         string CacheBuster = null, string Alt = null, bool ExternalUrl = false, PageDefinition.PageSecurityType SecurityType = PageDefinition.PageSecurityType.Any)
        {
            string      url = ImageHTML.FormatUrl(imageType, null, model, width, height, CacheBuster: CacheBuster, ExternalUrl: ExternalUrl, SecurityType: SecurityType);
            YTagBuilder img = new YTagBuilder("img");

            img.AddCssClass("t_preview");
            img.Attributes.Add("src", url);
            img.Attributes.Add("alt", Alt ?? __ResStr("altImg", "Image"));
            return(img.ToString(YTagRenderMode.StartTag));
        }
Example #4
0
        public async Task <ActionResult> RssFeed(Guid moduleGuid)
        {
            TextModule mod = (TextModule)await ModuleDefinition.LoadAsync(moduleGuid, AllowNone : true);

            if (mod == null || !mod.Feed)
            {
                throw new Error(this.__ResStr("noFeed", "The feed is no longer available"));
            }

            ModuleAction action = await mod.GetAction_RssFeedAwait(mod.ModuleGuid);

            string url = action.GetCompleteUrl();

            SyndicationFeed        feed;
            List <SyndicationItem> items = new List <SyndicationItem>();

            feed = new SyndicationFeed(mod.FeedTitle, mod.FeedSummary,
                                       string.IsNullOrWhiteSpace(mod.FeedMainUrl) ? new Uri(url) : new Uri(Manager.CurrentSite.MakeUrl(mod.FeedMainUrl)),
                                       items);

            action = await mod.GetAction_RssDetailAsync(mod.FeedDetailUrl, mod.ModuleGuid, mod.AnchorId);

            url = action.GetCompleteUrl();
            SyndicationItem sItem = new SyndicationItem(mod.Title, mod.Contents, new Uri(url));

            sItem.PublishDate = mod.FeedPublishDate ?? DateTime.MinValue;
            items.Add(sItem);

            if (mod.FeedImage != null)
            {
                feed.ImageUrl = new Uri(Manager.CurrentSite.MakeUrl(ImageHTML.FormatUrl(YetaWF.Core.Modules.ModuleImageSupport.ImageType, null, mod.FeedImage, CacheBuster: mod.DateUpdated.Ticks.ToString())));
            }
            feed.LastUpdatedTime = mod.FeedUpdateDate ?? DateTime.MinValue;

            return(new RssResult(feed));
        }
Example #5
0
        /// <summary>
        /// Called by the framework when the component needs to be rendered as HTML.
        /// </summary>
        /// <param name="model">The model being rendered by the component.</param>
        /// <returns>The component rendered as HTML.</returns>
        public Task <string> RenderAsync(string model)
        {
            HtmlBuilder hb = new HtmlBuilder();

            hb.Append("<div class='yt_image t_display'>");

            string imageType = PropData.GetAdditionalAttributeValue <string>("ImageType", null);
            int    width     = PropData.GetAdditionalAttributeValue("Width", 0);
            int    height    = PropData.GetAdditionalAttributeValue("Height", 0);

            if (string.IsNullOrWhiteSpace(imageType) && model != null && (model.IsAbsoluteUrl() || model.StartsWith("/") || model.StartsWith("data:")))
            {
                if (width != 0 || height != 0)
                {
                    throw new InternalError("Can't use Width or Height with external Urls");
                }

                YTagBuilder img = new YTagBuilder("img");
                img.Attributes.Add("src", model);
                if (!img.Attributes.ContainsKey("alt"))
                {
                    img.Attributes.Add("alt", __ResStr("altImage", "Image"));
                }
                hb.Append(img.ToString(YTagRenderMode.Normal));
            }
            else
            {
                if (string.IsNullOrWhiteSpace(imageType))
                {
                    throw new InternalError("No ImageType specified");
                }

                bool showMissing = PropData.GetAdditionalAttributeValue("ShowMissing", true);
                if (string.IsNullOrWhiteSpace(model) && !showMissing)
                {
                    return(Task.FromResult <string>(null));
                }

                string alt = null;
                if (HtmlAttributes.ContainsKey("alt"))
                {
                    alt = (string)HtmlAttributes["alt"];
                }
                string imgTag = ImageComponentBase.RenderImage(imageType, width, height, model, Alt: alt);

                bool linkToImage = PropData.GetAdditionalAttributeValue("LinkToImage", false);
                if (linkToImage)
                {
                    YTagBuilder link   = new YTagBuilder("a");
                    string      imgUrl = ImageHTML.FormatUrl(imageType, null, model);
                    link.MergeAttribute("href", imgUrl);
                    link.MergeAttribute("target", "_blank");
                    link.MergeAttribute("rel", "noopener noreferrer");
                    link.InnerHtml = imgTag;
                    hb.Append(link.ToString(YTagRenderMode.Normal));
                }
                else
                {
                    hb.Append(imgTag);
                }
            }

            hb.Append("</div>");
            return(Task.FromResult(hb.ToString()));
        }
Example #6
0
        // Windows RSS Publisher's Guide http://blogs.msdn.com/b/rssteam/archive/2005/08/02/publishersguide.aspx

        public async Task <ActionResult> RssFeed(int?blogCategory)
        {
            BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync();

            if (!config.Feed)
            {
                throw new Error(this.__ResStr("noFeed", "The feed is no longer available"));
            }

            int          categoryIdentity = blogCategory ?? 0;
            BlogCategory category         = null;

            if (categoryIdentity != 0)
            {
                using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) {
                    category = await categoryDP.GetItemAsync(categoryIdentity);

                    if (!category.Syndicated)
                    {
                        throw new Error(this.__ResStr("noFeed", "The feed is no longer available"));
                    }
                }
            }

            using (BlogEntryDataProvider dataProvider = new BlogEntryDataProvider()) {
                List <DataProviderSortInfo> sort = new List <DataProviderSortInfo> {
                    new DataProviderSortInfo {
                        Field = nameof(BlogEntry.DatePublished), Order = DataProviderSortInfo.SortDirection.Descending
                    },
                };
                List <DataProviderFilterInfo> filters = new List <DataProviderFilterInfo> {
                    new DataProviderFilterInfo {
                        Field = nameof(BlogEntry.Published), Operator = "==", Value = true
                    },
                };
                if (categoryIdentity != 0)
                {
                    filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo {
                        Field = nameof(BlogEntry.CategoryIdentity), Operator = "==", Value = categoryIdentity
                    });
                }
                DataProviderGetRecords <BlogEntry> data = await dataProvider.GetItemsAsync(0, 0, sort, filters);

                string url = string.IsNullOrWhiteSpace(config.FeedMainUrl) ? Manager.CurrentSite.HomePageUrl : config.FeedMainUrl;

                List <SyndicationItem> items   = new List <SyndicationItem>();
                EntryDisplayModule     dispMod = new EntryDisplayModule();

                DateTime lastUpdated = DateTime.MinValue;
                foreach (BlogEntry blogEntry in data.Data)
                {
                    if (categoryIdentity == 0)
                    {
                        using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) {
                            category = await categoryDP.GetItemAsync(blogEntry.CategoryIdentity);

                            if (!category.Syndicated)
                            {
                                continue;
                            }
                        }
                    }
                    ModuleAction viewAction = await dispMod.GetAction_DisplayAsync(blogEntry.Identity);

                    if (viewAction == null)
                    {
                        continue;
                    }
                    SyndicationItem sItem   = new SyndicationItem(blogEntry.Title.ToString(), blogEntry.Text, new Uri(viewAction.GetCompleteUrl()));
                    DateTime        updDate = blogEntry.DateUpdated ?? blogEntry.DateCreated;
                    sItem.LastUpdatedTime = updDate;
                    if (!string.IsNullOrEmpty(category.SyndicationEmail))
                    {
                        sItem.Authors.Add(new SyndicationPerson(category.SyndicationEmail));
                    }
                    sItem.Categories.Add(new SyndicationCategory(category.Category.ToString()));
                    if (!string.IsNullOrEmpty(category.SyndicationCopyright.ToString()))
                    {
                        sItem.Copyright = new TextSyndicationContent(category.SyndicationCopyright.ToString());
                    }
                    sItem.PublishDate = blogEntry.DatePublished;
                    if (!string.IsNullOrEmpty(blogEntry.DisplayableSummary))
                    {
                        sItem.Summary = new TextSyndicationContent(blogEntry.DisplayableSummary);
                    }
                    lastUpdated = updDate > lastUpdated ? updDate : lastUpdated;

                    items.Add(sItem);
                }

                SyndicationFeed feed;
                if (categoryIdentity != 0)
                {
                    feed = new SyndicationFeed(category.Category.ToString(), category.Description.ToString(), new Uri(Manager.CurrentSite.MakeUrl(url)), items);
                }
                else
                {
                    feed = new SyndicationFeed(config.FeedTitle, config.FeedSummary, new Uri(Manager.CurrentSite.MakeUrl(url)), items);
                }
                if (config.FeedImage != null)
                {
                    feed.ImageUrl = new Uri(Manager.CurrentSite.MakeUrl(ImageHTML.FormatUrl(BlogConfigData.ImageType, null, config.FeedImage))); //$$$ caching issue
                }
                if (lastUpdated != DateTime.MinValue)
                {
                    feed.LastUpdatedTime = lastUpdated;
                }
                return(new RssResult(feed));
            }
        }
Example #7
0
 public string MakeFlashUrl(string filename, int width = 0, int height = 0)
 {
     // always defeat browser caching for image selection
     return(ImageHTML.FormatUrl(ImageSupport.ImageType, string.Format("{0},{1},{2}", FolderGuid.ToString(), SubFolder, FileType), filename, width, height, CacheBuster: DateTime.UtcNow.Ticks.ToString()));
 }