Пример #1
0
        private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, int totalStar, int initStar, string successMessage, string failureMessage, string theme, bool isTextOnly)
        {
            var tableName  = NodeManager.GetTableName(pageInfo.PublishmentSystemInfo, contextInfo.ChannelId);
            var tableStyle = NodeManager.GetTableStyle(pageInfo.PublishmentSystemInfo, contextInfo.ChannelId);
            var contentId  = ContentUtility.GetRealContentId(tableStyle, tableName, contextInfo.ContentId);
            var channelId  = BaiRongDataProvider.ContentDao.GetNodeId(tableName, contextInfo.ContentId);

            if (isTextOnly)
            {
                var counts     = DataProvider.StarDao.GetCount(pageInfo.PublishmentSystemId, channelId, contentId);
                var totalCount = counts[0];
                var totalPoint = counts[1];

                var totalCountAndPointAverage = DataProvider.StarSettingDao.GetTotalCountAndPointAverage(pageInfo.PublishmentSystemId, contentId);
                var settingTotalCount         = (int)totalCountAndPointAverage[0];
                var settingPointAverage       = (decimal)totalCountAndPointAverage[1];
                if (settingTotalCount > 0 || settingPointAverage > 0)
                {
                    totalCount += settingTotalCount;
                    totalPoint += Convert.ToInt32(settingPointAverage * settingTotalCount);
                }

                decimal num;
                if (totalCount > 0)
                {
                    num = Convert.ToDecimal(totalPoint) / Convert.ToDecimal(totalCount);
                }
                else
                {
                    num = initStar;
                }

                if (num > totalStar)
                {
                    num = totalStar;
                }

                var numString = num.ToString(CultureInfo.InvariantCulture);
                if (numString.IndexOf('.') == -1)
                {
                    return(numString + ".0");
                }
                var first  = numString.Substring(0, numString.IndexOf('.'));
                var second = numString.Substring(numString.IndexOf('.') + 1, 1);
                return(first + "." + second);
            }
            else
            {
                var updaterId = pageInfo.UniqueId;
                var ajaxDivId = StlParserUtility.GetAjaxDivId(updaterId);

                pageInfo.AddPageScriptsIfNotExists(ElementName,
                                                   $@"<script language=""javascript"" src=""{SiteFilesAssets.Star.GetScriptUrl(pageInfo.ApiUrl)}""></script>");

                var builder = new StringBuilder();
                builder.Append(
                    $@"<link rel=""stylesheet"" href=""{SiteFilesAssets.Star.GetStyleUrl(pageInfo.ApiUrl, theme)}"" type=""text/css"" />");
                builder.Append($@"<div id=""{ajaxDivId}"">");

                var innerPageUrl           = Star.GetUrl(pageInfo.ApiUrl, pageInfo.PublishmentSystemId, channelId, contentId, updaterId, totalStar, initStar, theme, false);
                var innerPageUrlWithAction = Star.GetUrl(pageInfo.ApiUrl, pageInfo.PublishmentSystemId, channelId, contentId, updaterId, totalStar, initStar, theme, true);

                string loadingHtml =
                    $@"<img src=""{SiteFilesAssets.GetUrl(pageInfo.ApiUrl, SiteFilesAssets.FileLoading)}"" />";

                builder.Append(loadingHtml);

                builder.Append("</div>");

                var successAlert = string.Empty;
                if (!string.IsNullOrEmpty(successMessage))
                {
                    successAlert = $"stlSuccessAlert('{successMessage}');";
                }

                builder.Append($@"
<script type=""text/javascript"" language=""javascript"">
function stlStar_{updaterId}(url)
{{
    try
    {{
        var cnum=Math.ceil(Math.random()*1000);
        url = url + '&r=' + cnum;

        jQuery.get(url, '', function(data, textStatus){{
            jQuery('#{ajaxDivId}').html(data);
        }});

    }}catch(e){{}}
}}

stlStar_{updaterId}('{innerPageUrl}');

function stlStarPoint_{updaterId}(point)
{{
    if (stlStarCheck({pageInfo.PublishmentSystemId}, {channelId}, {contentId}, '{failureMessage}')){{
        jQuery('#{ajaxDivId}').innerHTML = '{loadingHtml}';
        stlStar_{updaterId}('{innerPageUrlWithAction}' + point);
        {successAlert}
    }}
}}
</script>
");

                return(builder.ToString());
            }
        }