Example #1
0
        public static string ParseTextEditor(IAttributes attributes, string attributeName, SiteInfo siteInfo, NameValueCollection pageScripts, StringBuilder extraBuilder)
        {
            var value = attributes.GetString(attributeName);

            value = ContentUtility.TextEditorContentDecode(siteInfo, value, true);
            value = UEditorUtils.TranslateToHtml(value);
            value = StringUtils.HtmlEncode(value);

            var controllerUrl = ApiRouteUEditor.GetUrl(ApiManager.InnerApiUrl, siteInfo.Id);
            var editorUrl     = SiteServerAssets.GetUrl("ueditor");

            if (pageScripts["uEditor"] == null)
            {
                extraBuilder.Append(
                    $@"<script type=""text/javascript"">window.UEDITOR_HOME_URL = ""{editorUrl}/"";window.UEDITOR_CONTROLLER_URL = ""{controllerUrl}"";</script><script type=""text/javascript"" src=""{editorUrl}/editor_config.js""></script><script type=""text/javascript"" src=""{editorUrl}/ueditor_all_min.js""></script>");
            }
            pageScripts["uEditor"] = string.Empty;

            extraBuilder.Append($@"
<script type=""text/javascript"">
$(function(){{
  UE.getEditor('{attributeName}', {UEditorUtils.ConfigValues});
  $('#{attributeName}').show();
}});
</script>");

            return($@"<textarea id=""{attributeName}"" name=""{attributeName}"" style=""display:none"">{value}</textarea>");
        }
Example #2
0
        public async Task <Content> DecodeContentAsync(Site site, Channel channel, Content content)
        {
            content = content.Clone <Content>();

            var tableStyles = await _tableStyleRepository.GetContentStylesAsync(site, channel);

            foreach (var style in tableStyles)
            {
                if (style.InputType == InputType.Image || style.InputType == InputType.Video || style.InputType == InputType.File)
                {
                    var countName = ColumnsManager.GetCountName(style.AttributeName);
                    var count     = content.Get <int>(countName);
                    for (var i = 0; i <= count; i++)
                    {
                        var extendName = ColumnsManager.GetExtendName(style.AttributeName, i);
                        var value      = content.Get <string>(extendName);
                        value = await ParseSiteUrlAsync(site, value, false);

                        content.Set(extendName, value);
                    }
                }
                else if (style.InputType == InputType.TextEditor)
                {
                    var value = content.Get <string>(style.AttributeName);
                    value = await DecodeTextEditorAsync(site, value, true);

                    value = UEditorUtils.TranslateToHtml(value);

                    content.Set(style.AttributeName, value);
                }
            }

            return(content);
        }
        public async Task <ActionResult <ChannelResult> > Get(int siteId, int channelId)
        {
            if (!await _authManager.HasSitePermissionsAsync(siteId,
                                                            MenuUtils.SitePermissions.Channels))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(siteId);

            if (site == null)
            {
                return(NotFound());
            }

            var channel = await _channelRepository.GetAsync(channelId);

            var styles = await GetStylesAsync(channel);

            var entity = new Entity(channel.ToDictionary());

            foreach (var style in styles)
            {
                if (style.InputType == InputType.Image ||
                    style.InputType == InputType.Video ||
                    style.InputType == InputType.File)
                {
                    var count = channel.Get(ColumnsManager.GetCountName(style.AttributeName), 0);
                    entity.Set(ColumnsManager.GetCountName(style.AttributeName), count);
                    for (var n = 0; n <= count; n++)
                    {
                        var extendName = ColumnsManager.GetExtendName(style.AttributeName, n);
                        entity.Set(extendName, channel.Get(extendName));
                    }
                }
                else if (style.InputType == InputType.CheckBox ||
                         style.InputType == InputType.SelectMultiple)
                {
                    var list = ListUtils.GetStringList(channel.Get(style.AttributeName,
                                                                   string.Empty));
                    entity.Set(style.AttributeName, list);
                }
                else if (style.InputType == InputType.TextEditor)
                {
                    var value = channel.Get(style.AttributeName, string.Empty);
                    value = await _pathManager.DecodeTextEditorAsync(site, value, true);

                    value = UEditorUtils.TranslateToHtml(value);

                    entity.Set(style.AttributeName, value);
                }
                else
                {
                    entity.Set(style.AttributeName, channel.Get(style.AttributeName));
                }
            }

            var filePath            = channel.FilePath;
            var channelFilePathRule = channel.ChannelFilePathRule;
            var contentFilePathRule = channel.ContentFilePathRule;

            return(new ChannelResult
            {
                Entity = entity,
                Styles = styles,
                FilePath = filePath,
                ChannelFilePathRule = channelFilePathRule,
                ContentFilePathRule = contentFilePathRule
            });
        }