Ejemplo n.º 1
0
        public static string Parse(string stlElement, XmlNode node, PageInfo pageInfo, ContextInfo contextInfo)
        {
            string parsedContent;

            try
            {
                var isAllSites       = false;
                var siteName         = string.Empty;
                var siteDir          = string.Empty;
                var siteIds          = string.Empty;
                var channelIndex     = string.Empty;
                var channelName      = string.Empty;
                var channelIds       = string.Empty;
                var type             = ContentAttribute.Title;
                var word             = string.Empty;
                var dateAttribute    = ContentAttribute.AddDate;
                var dateFrom         = string.Empty;
                var dateTo           = string.Empty;
                var since            = string.Empty;
                var pageNum          = 0;
                var isHighlight      = false;
                var isDefaultDisplay = false;

                var ie = node.Attributes?.GetEnumerator();
                if (ie != null)
                {
                    while (ie.MoveNext())
                    {
                        var attr = (XmlAttribute)ie.Current;

                        if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeIsAllSites))
                        {
                            isAllSites = TranslateUtils.ToBool(attr.Value);
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeSiteName))
                        {
                            siteName = attr.Value;
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeSiteDir))
                        {
                            siteDir = attr.Value;
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeSiteIds))
                        {
                            siteIds = attr.Value;
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeChannelIndex))
                        {
                            channelIndex = attr.Value;
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeChannelName))
                        {
                            channelName = attr.Value;
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeChannelIds))
                        {
                            channelIds = attr.Value;
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeType))
                        {
                            type = attr.Value;
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeWord))
                        {
                            word = attr.Value;
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeDateAttribute))
                        {
                            dateAttribute = attr.Value;
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeDateFrom))
                        {
                            dateFrom = attr.Value;
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeDateTo))
                        {
                            dateTo = attr.Value;
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeSince))
                        {
                            since = attr.Value;
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributePageNum))
                        {
                            pageNum = TranslateUtils.ToInt(attr.Value, 0);
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeIsHighlight))
                        {
                            isHighlight = TranslateUtils.ToBool(attr.Value);
                        }
                        else if (StringUtils.EqualsIgnoreCase(attr.Name, AttributeIsDefaultDisplay))
                        {
                            isDefaultDisplay = TranslateUtils.ToBool(attr.Value);
                        }
                    }
                }

                string loading;
                string yes;
                string no;
                StlInnerUtility.GetLoadingYesNo(node, pageInfo, out loading, out yes, out no);

                if (string.IsNullOrEmpty(loading))
                {
                    loading = StlCacheManager.FileContent.GetContentByFilePath(SiteFilesAssets.Search.LoadingTemplatePath);
                }
                if (string.IsNullOrEmpty(yes))
                {
                    yes = StlCacheManager.FileContent.GetContentByFilePath(SiteFilesAssets.Search.YesTemplatePath);
                }
                if (string.IsNullOrEmpty(no))
                {
                    no = StlCacheManager.FileContent.GetContentByFilePath(SiteFilesAssets.Search.NoTemplatePath);
                }

                pageInfo.AddPageScriptsIfNotExists(PageInfo.Components.Jquery);

                var ajaxDivId     = StlParserUtility.GetAjaxDivId(pageInfo.UniqueId);
                var apiUrl        = ActionsSearch.GetUrl(pageInfo.PublishmentSystemInfo.Additional.ApiUrl);
                var apiParameters = ActionsSearch.GetParameters(isAllSites, siteName, siteDir, siteIds, channelIndex, channelName, channelIds, type, word, dateAttribute, dateFrom, dateTo, since, pageNum, isHighlight, isDefaultDisplay, pageInfo.PublishmentSystemId, ajaxDivId, yes);

                var builder = new StringBuilder();
                builder.Append($@"
<div id=""{ajaxDivId}"">
    <div class=""stl_loading"">{loading}</div>
    <div class=""stl_yes"" style=""display:none""></div>
    <div class=""stl_no"" style=""display:none"">{no}</div>
</div>
");

                builder.Append($@"
<script type=""text/javascript"" language=""javascript"">
jQuery(document).ready(function(){{
    var url = '{apiUrl}';
    var parameters = {apiParameters};

    var queryString = document.location.search;
    if (queryString && queryString.length > 1) {{
        queryString = queryString.substring(1);
        var arr = queryString.split('&');
        for(var i=0; i < arr.length; i++) {{
            var item = arr[i];
            var arr2 = item.split('=');
            if (arr2 && arr2.length == 2) {{
                var key = (arr2[0] || '').toLowerCase();
                if (key) {{
                    parameters[key] = decodeURIComponent(arr2[1]);
                }}
            }}
        }}
        if (!parameters['page']) {{
            parameters['page'] = 1;
        }}

        jQuery.support.cors = true;
        jQuery.ajax({{
            url: url,
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(parameters),
            dataType: 'json',
            success: function(res) {{
                jQuery(""#{ajaxDivId} .stl_loading"").hide();
                jQuery(""#{ajaxDivId} .stl_yes"").show();
                jQuery(""#{ajaxDivId} .stl_no"").hide();
                jQuery(""#{ajaxDivId} .stl_yes"").html(res);
            }},
            error: function(e) {{
                jQuery(""#{ajaxDivId} .stl_loading"").hide();
                jQuery(""#{ajaxDivId} .stl_yes"").hide();
                jQuery(""#{ajaxDivId} .stl_no"").show();
            }}
        }});
    }} else {{
        jQuery(""#{ajaxDivId} .stl_loading"").hide();
        jQuery(""#{ajaxDivId} .stl_yes"").hide();
        jQuery(""#{ajaxDivId} .stl_no"").show();
    }}
}});

function stlRedirect{ajaxDivId}(page)
{{
    var queryString = document.location.search;
    if (queryString && queryString.length > 1) {{
        queryString = queryString.substring(1);
        var parameters = '';
        var arr = queryString.split('&');
        for(var i=0; i < arr.length; i++) {{
            var item = arr[i];
            var arr2 = item.split('=');
            if (arr2 && arr2.length == 2) {{
                if (arr2[0] !== 'page') {{
                    parameters += item + '&';
                }}
            }}
        }}
        parameters += 'page=' + page;
        location.href = location.protocol + '//' + location.host + location.pathname + location.hash + '?' + parameters;
    }}
}}

function stlJump{ajaxDivId}(selObj)
{{
    stlRedirect{ajaxDivId}(selObj.options[selObj.selectedIndex].value);
}}
</script>
");

                parsedContent = builder.ToString();
            }
            catch (Exception ex)
            {
                parsedContent = StlParserUtility.GetStlErrorMessage(ElementName, ex);
            }

            return(parsedContent);
        }
Ejemplo n.º 2
0
        public static string Parse(string stlElement, XmlNode node, PageInfo pageInfo, ContextInfo contextInfo)
        {
            string parsedContent;

            try
            {
                var pageNum          = 0;
                var width            = string.Empty;
                var isHighlight      = false;
                var isRedirectSingle = false;
                var isDefaultDisplay = false;
                var dateAttribute    = ContentAttribute.AddDate;

                var ie = node.Attributes?.GetEnumerator();
                if (ie != null)
                {
                    while (ie.MoveNext())
                    {
                        var attr          = (XmlAttribute)ie.Current;
                        var attributeName = attr.Name.ToLower();
                        if (attributeName.Equals(AttributePageNum))
                        {
                            pageNum = TranslateUtils.ToInt(attr.Value, 0);
                        }
                        else if (attributeName.Equals(AttributeWidth))
                        {
                            width = attr.Value;
                        }
                        else if (attributeName.Equals(AttributeIsHighlight))
                        {
                            isHighlight = TranslateUtils.ToBool(attr.Value);
                        }
                        else if (attributeName.Equals(AttributeIsRedirectSingle))
                        {
                            isRedirectSingle = TranslateUtils.ToBool(attr.Value);
                        }
                        else if (attributeName.Equals(AttributeIsDefaultDisplay))
                        {
                            isDefaultDisplay = TranslateUtils.ToBool(attr.Value);
                        }
                        else if (attributeName.Equals(AttributeDateAttribute))
                        {
                            dateAttribute = attr.Value;
                        }
                    }
                }

                string loading;
                string yes;
                string no;
                StlParserUtility.GetSearchOutputTemplateString(node, out loading, out yes, out no, pageInfo, contextInfo);

                if (string.IsNullOrEmpty(loading))
                {
                    loading = @"<div style=""margin: 0 auto;
    padding: 40px 0;
    font-size: 14px;
    font-family: 'Microsoft YaHei';
    text-align: center;
    font-weight: 400;"">
        搜索中,请稍后...
</div>";
                }

                if (string.IsNullOrEmpty(yes))
                {
                    yes = @"<stl:pageContents cellpadding=""2"" width=""95%"" layout=""Table"" cellspacing=""2"" pageNum=""22"">
	<stl:a target=""_blank""></stl:a>
</stl:pageContents>
<br />
<stl:pageitems>
<table cellpadding=""0"" width=""90%"" cellspacing=""0"" height=""40"" align=""center"">
  <tr>
    <td align=""left""><stl:pageItem type=""FirstPage"" text=""首页""></stl:pageItem>&nbsp;|&nbsp;<stl:pageItem type=""PreviousPage"" text=""上一页""></stl:pageItem>&nbsp;|&nbsp;<stl:pageItem type=""NextPage"" text=""下一页""></stl:pageItem>&nbsp;|&nbsp;<stl:pageItem type=""LastPage"" text=""末页""></stl:pageItem></td>
    <td align=""right""><stl:pageItem type=""CurrentPageIndex"" text=""当前页:""></stl:pageItem>/<stl:pageItem type=""TotalPageNum""></stl:pageItem>&nbsp;&nbsp;<stl:pageItem type=""PageNavigation""></stl:pageItem></td>
  </tr>
</table>
</stl:pageitems>";
                }

                if (string.IsNullOrEmpty(no))
                {
                    no = @"<div style=""margin: 0 auto;
    padding: 40px 0;
    font-size: 14px;
    font-family: 'Microsoft YaHei';
    text-align: center;
    font-weight: 400;
    display: none;"">
        抱歉,找不到和您的查询相符的网页。
    </div>";
                }

                pageInfo.AddPageScriptsIfNotExists(PageInfo.Components.Jquery);

                var ajaxDivId     = StlParserUtility.GetAjaxDivId(pageInfo.UniqueId);
                var apiUrl        = ActionsSearch.GetUrl(pageInfo.PublishmentSystemInfo.Additional.ApiUrl);
                var apiParameters = ActionsSearch.GetParameters(pageInfo.PublishmentSystemId, ajaxDivId, pageNum, isHighlight, isRedirectSingle, isDefaultDisplay, dateAttribute, pageInfo.TemplateInfo.Charset, yes);

                var builder = new StringBuilder();
                builder.Append(string.IsNullOrEmpty(width)
                    ? $@"<div id=""{ajaxDivId}"">"
                    : $@"<div id=""{ajaxDivId}"" style=""width:{width}"">");
                builder.Append($@"<div class=""loading"">{loading}</div>");
                builder.Append($@"<div class=""yes"">{string.Empty}</div>");
                builder.Append($@"<div class=""no"">{no}</div>");
                builder.Append("</div>");

                builder.Append($@"
<script type=""text/javascript"" language=""javascript"">
jQuery(document).ready(function(){{
    jQuery(""#{ajaxDivId} .loading"").show();
    jQuery(""#{ajaxDivId} .yes"").hide();
    jQuery(""#{ajaxDivId} .no"").hide();

    var url = '{apiUrl}';
    var parameters = {apiParameters};

    var queryString = document.location.search;
    if (queryString && queryString.length > 1) {{
        queryString = queryString.substring(1);
        var arr = queryString.split('&');
        for(var i=0; i < arr.length; i++) {{
            var item = arr[i];
            var arr2 = item.split('=');
            if (arr2 && arr2.length == 2) {{
                parameters[arr2[0]] = decodeURIComponent(arr2[1]);
            }}
        }}
        if (!parameters['page']) {{
            parameters['page'] = 1;
        }}

        jQuery.support.cors = true;
        jQuery.ajax({{
            url: url,
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(parameters),
            dataType: 'json',
            success: function(res) {{
                jQuery(""#{ajaxDivId} .loading"").hide();
                jQuery(""#{ajaxDivId} .yes"").show();
                jQuery(""#{ajaxDivId} .no"").hide();
                jQuery(""#{ajaxDivId} .yes"").html(res);
            }},
            error: function(e) {{
                jQuery(""#{ajaxDivId} .loading"").hide();
                jQuery(""#{ajaxDivId} .yes"").hide();
                jQuery(""#{ajaxDivId} .no"").show();
            }}
        }});
    }} else {{
        jQuery(""#{ajaxDivId} .loading"").hide();
        jQuery(""#{ajaxDivId} .yes"").hide();
        jQuery(""#{ajaxDivId} .no"").show();
    }}
}});

function stlRedirect{ajaxDivId}(page)
{{
    var queryString = document.location.search;
    if (queryString && queryString.length > 1) {{
        queryString = queryString.substring(1);
        var parameters = '';
        var arr = queryString.split('&');
        for(var i=0; i < arr.length; i++) {{
            var item = arr[i];
            var arr2 = item.split('=');
            if (arr2 && arr2.length == 2) {{
                if (arr2[0] !== 'page') {{
                    parameters += item + '&';
                }}
            }}
        }}
        parameters += 'page=' + page;
        location.href = location.protocol + '//' + location.host + location.pathname + location.hash + '?' + parameters;
    }}
}}

function stlJump{ajaxDivId}(selObj)
{{
    stlRedirect{ajaxDivId}(selObj.options[selObj.selectedIndex].value);
}}
</script>
");

                parsedContent = builder.ToString();
            }
            catch (Exception ex)
            {
                parsedContent = StlParserUtility.GetStlErrorMessage(ElementName, ex);
            }

            return(parsedContent);
        }