示例#1
0
        public static void AddEditableToPage(ParsePage page, ParseContext context, NameValueCollection attributes, string innerHtml)
        {
            var elementId = StringUtils.GetElementId();
            var editable  = new Editable
            {
                ElementId   = elementId,
                ElementName = context.ElementName,
                Attributes  = TranslateUtils.ToDictionary(attributes),
                InnerHtml   = innerHtml,
                StlElement  = StringUtils.Base64Encode(context.OuterHtml),
                IncludeFile = string.IsNullOrEmpty(page.IncludeFile)
                ? string.Empty
                : StringUtils.Base64Encode(page.IncludeFile),
                StartIndex = context.StartIndex,
                IsChanged  = false
            };

            page.Editables.Add(editable);

            attributes["data-element"]      = "true";
            attributes["data-element-id"]   = elementId;
            attributes["data-element-name"] = context.ElementName;
            if (StringUtils.EqualsIgnoreCase(context.ElementName, StlEditable.ElementName))
            {
                attributes["id"] = elementId;
                attributes["contenteditable"] = "true";
            }
        }
示例#2
0
文件: ParseManager.cs 项目: lzz42/cms
        public async Task InitAsync(EditMode editMode, Site site, int pageChannelId, int pageContentId, Template template)
        {
            var config = await DatabaseManager.ConfigRepository.GetAsync();

            PageInfo    = new ParsePage(PathManager, editMode, config, pageChannelId, pageContentId, site, template, new Dictionary <string, object>());
            ContextInfo = new ParseContext(PageInfo);
        }
示例#3
0
        public static void AddEditableToPage(ParsePage page, string elementId, ParseContext context, string parsedContent)
        {
            var editable = new Editable
            {
                Id            = elementId,
                ElementName   = context.ElementName,
                StlElement    = StringUtils.Base64Encode(context.OuterHtml),
                EditedContent = parsedContent,
                ParsedContent = parsedContent,
                File          = string.IsNullOrEmpty(page.IncludeFile)
                ? string.Empty
                : StringUtils.Base64Encode(page.IncludeFile),
                Index = context.StartIndex,
            };

            page.Editables.Add(editable);
        }
示例#4
0
        public static Editable GetEditable(ParsePage page, ParseContext context)
        {
            var editable = new Editable
            {
                Id          = StringUtils.GetElementId(),
                ElementName = context.ElementName,
                StlElement  = StringUtils.Base64Encode(context.OuterHtml),

                File = string.IsNullOrEmpty(page.IncludeFile)
                ? string.Empty
                : StringUtils.Base64Encode(page.IncludeFile),
                Index = context.StartIndex,
            };

            page.Editables.Add(editable);
            return(editable);
        }
示例#5
0
        public static async Task <string> ParseAsync(ParsePage pageInfo, string parsedContent)
        {
            if (parsedContent.Contains(" data-vue="))
            {
                await pageInfo.AddPageHeadCodeIfNotExistsAsync(ParsePage.Const.Jquery);

                await pageInfo.AddPageHeadCodeIfNotExistsAsync(ParsePage.Const.Vue);

                await pageInfo.AddPageHeadCodeIfNotExistsAsync(ParsePage.Const.VueElement);

                var elementId = StringUtils.GetElementId();
                parsedContent = parsedContent.Replace("<p>", "<div>");
                parsedContent = parsedContent.Replace("<p ", "<div ");
                parsedContent = parsedContent.Replace("</p>", "</div>");
                parsedContent = $@"
<div id=""vue_{elementId}""></div>
<script type=""text/javascript"">
var templates_{elementId} = '{parsedContent}';
var container_{elementId} = $(templates_{elementId});
var elements_{elementId} = container_{elementId}.find('[data-vue]');
for(var i = 0; i < elements_{elementId}.length; i++) {{
  var element = $(elements_{elementId}[i]);
  var vueHtml = decodeURIComponent(element.data('vue'));
  templates_{elementId} = templates_{elementId}.replace(elements_{elementId}[i].outerHTML, vueHtml);
}}
$('#vue_{elementId}').html(templates_{elementId});

var $vue_{elementId} = new Vue({{
  el: ""#vue_{elementId}"",
  data: {{
    show: false
  }},
  mounted: function () {{
    this.show = true;
  }}
}});
</script>
";
            }

            return(parsedContent);
        }
示例#6
0
        public async Task ParseTest()
        {
            var siteInfo     = new Site();
            var templateInfo = new Template();
            var pluginItems  = new Dictionary <string, object>();
            var pageInfo     = await ParsePage.GetPageInfoAsync(0, 0, siteInfo, templateInfo, pluginItems);

            var contextInfo = new ParseContext(pageInfo);

            var template = $@"<stl:a href=""https://www.siteserver.cn"">test</stl:a>";
            var builder  = new StringBuilder(template);

            await StlParserManager.ParseTemplateContentAsync(builder, pageInfo, contextInfo);

            var parsedContent = builder.ToString();

            _output.WriteLine(parsedContent);

            Assert.True(true);
        }
示例#7
0
            public async Task LoadAsync(IAuthManager auth, IPathManager pathManager, IConfigRepository configRepository, ISiteRepository siteRepository, GetRequest request)
            {
                //Request = new AuthenticatedRequest();
                //IsApiAuthorized = Request.IsApiAuthenticated && AccessTokenManager.IsScope(Request.ApiToken, AccessTokenManager.ScopeStl);

                Auth = auth;

                if (request.SiteId > 0)
                {
                    Site = await siteRepository.GetAsync(request.SiteId);
                }
                else if (!string.IsNullOrEmpty(request.SiteDir))
                {
                    Site = await siteRepository.GetSiteByDirectoryAsync(request.SiteDir);
                }
                else
                {
                    Site = await siteRepository.GetSiteByIsRootAsync();

                    if (Site == null)
                    {
                        var siteList = await siteRepository.GetSitesAsync();

                        if (siteList != null && siteList.Count > 0)
                        {
                            Site = siteList[0];
                        }
                    }
                }

                if (Site == null)
                {
                    return;
                }

                if (request.ChannelId == 0)
                {
                    request.ChannelId = Site.Id;
                }

                var templateInfo = new Template
                {
                    Id                  = 0,
                    SiteId              = Site.Id,
                    TemplateName        = string.Empty,
                    TemplateType        = TemplateType.IndexPageTemplate,
                    RelatedFileName     = string.Empty,
                    CreatedFileFullName = string.Empty,
                    CreatedFileExtName  = string.Empty,
                    DefaultTemplate     = true
                };

                var config = await configRepository.GetAsync();

                PageInfo = new ParsePage(pathManager, config, request.ChannelId, request.ContentId, Site, templateInfo,
                                         new Dictionary <string, object>())
                {
                    User = await Auth.GetUserAsync()
                };

                var attributes = TranslateUtils.NewIgnoreCaseNameValueCollection();

                foreach (var key in request.Keys)
                {
                    attributes[key] = request[key];
                }

                ContextInfo = new ParseContext(PageInfo)
                {
                    IsStlEntity = true,
                    Attributes  = attributes,
                    InnerHtml   = string.Empty
                };
            }
示例#8
0
        private static string ParseImpl(ParsePage pageInfo, string scrollHtml, int scrollDelay, string direction, string width, string height)
        {
            string topHtml;
            string bottomHtml;
            string scripts;

            if (string.IsNullOrEmpty(height) && direction == DirectionVertical)
            {
                height = "height:120px;";
            }

            var elementId = StringUtils.GetElementId();

            if (direction.Equals(DirectionVertical))
            {
                topHtml = $@"
<div id=""uniqueID_1"" style=""overflow: hidden; {width} {height}""><div id=""uniqueID_2"" align=""left"">";

                bottomHtml = @"</div><div id=""uniqueID_3""></div></div>";

                scripts = $@"
<script language=javascript>
var uniqueID_isMar = true;
var uniqueID_1=document.getElementById(""uniqueID_1"");
var uniqueID_2=document.getElementById(""uniqueID_2"");
var uniqueID_3=document.getElementById(""uniqueID_3"");
if (uniqueID_1.style.pixelHeight){{
    uniqueID_isMar = uniqueID_2.offsetHeight > uniqueID_1.style.pixelHeight;
}}else{{
    var uniqueID_height = parseInt(uniqueID_1.style.height.replace('%', '').replace('px', ''));
    uniqueID_isMar = uniqueID_2.offsetHeight > uniqueID_height;
}}
if (uniqueID_isMar){{
    uniqueID_3.innerHTML=uniqueID_2.innerHTML;
    function uniqueID_function(){{
	     <!--if(uniqueID_3.offsetTop-uniqueID_1.scrollTop<=0)-->
        if(uniqueID_2.offsetHeight*2==uniqueID_1.scrollTop+uniqueID_1.offsetHeight)
		    uniqueID_1.scrollTop-=uniqueID_2.offsetHeight;
	    else{{
		    uniqueID_1.scrollTop++
	    }}
    }}
    var uniqueID_myMar=setInterval(uniqueID_function,{scrollDelay});
    uniqueID_1.onmouseover=function() {{clearInterval(uniqueID_myMar)}}
    uniqueID_1.onmouseout=function() {{uniqueID_myMar=setInterval(uniqueID_function,{scrollDelay})}}
}}
</script>";
            }
            else
            {
                topHtml = $@"
<div id=uniqueID_1 style=""OVERFLOW: hidden; {width} {height}""><table cellpadding=0 align=left border=0 cellspace=0><tr><td id=uniqueID_2 nowrap=""nowrap"">";

                bottomHtml = @"</td><td id=uniqueID_3 nowrap=""nowrap""></td></tr></table></div>";

                scripts = $@"
<script language=javascript>
var uniqueID_isMar = true;
var uniqueID_1=document.getElementById(""uniqueID_1"");
var uniqueID_2=document.getElementById(""uniqueID_2"");
var uniqueID_3=document.getElementById(""uniqueID_3"");
if (uniqueID_1.style.pixelWidth){{
    uniqueID_isMar = uniqueID_2.offsetWidth > uniqueID_1.style.pixelWidth;
}}else{{
    var uniqueID_width = parseInt(uniqueID_1.style.width.replace('%', '').replace('px', ''));
    uniqueID_isMar = uniqueID_2.offsetWidth > uniqueID_width;
}}
if (uniqueID_isMar){{
    function uniqueID_function(){{
	    uniqueID_3.innerHTML=uniqueID_2.innerHTML;
	    <!--if(uniqueID_3.offsetLeft-uniqueID_1.scrollLeft<=0)-->
        if(uniqueID_2.offsetWidth*2+1==uniqueID_1.scrollLeft+uniqueID_1.offsetWidth )
		    uniqueID_1.scrollLeft-=uniqueID_2.offsetWidth;
	    else{{
		    uniqueID_1.scrollLeft++
	    }}
    }}
    var uniqueID_myMar=setInterval(uniqueID_function,{scrollDelay});
    uniqueID_1.onmouseover=function() {{clearInterval(uniqueID_myMar)}}
    uniqueID_1.onmouseout=function() {{uniqueID_myMar=setInterval(uniqueID_function,{scrollDelay})}}
}}
</script>";
            }

            if (!pageInfo.FootCodes.ContainsKey(ElementName + elementId))
            {
                pageInfo.FootCodes.Add(ElementName + elementId, scripts.Replace("uniqueID", elementId));
            }

            return(topHtml.Replace("uniqueID", elementId) + scrollHtml + bottomHtml.Replace("uniqueID", elementId));
        }