/// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            var sb = new StringBuilder(text);

            Match m = this._regExSearch.Match(text);

            while (m.Success)
            {
                string replaceString = this._regExReplace.Replace("${inner}", this.GetInnerValue(m.Groups["inner"].Value));

                // pulls the htmls into the replacement collection before it's inserted back into the main text
                replacement.ReplaceHtmlFromText(ref replaceString);

                // remove old bbcode...
                sb.Remove(m.Groups[0].Index, m.Groups[0].Length);

                // insert replaced value(s)
                sb.Insert(m.Groups[0].Index, replaceString);

                // text = text.Substring( 0, m.Groups [0].Index ) + tStr + text.Substring( m.Groups [0].Index + m.Groups [0].Length );
                m = this._regExSearch.Match(sb.ToString());
            }

            text = sb.ToString();
        }
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            var sb = new StringBuilder(text);

            Match m = this._regExSearch.Match(text);

            while (m.Success)
            {
                var innerReplace = new StringBuilder(this._regExReplace);
                int i            = 0;

                foreach (string tVar in this._variables)
                {
                    string varName       = tVar;
                    string handlingValue = String.Empty;

                    if (varName.Contains(":"))
                    {
                        // has handling section
                        string[] tmpSplit = varName.Split(':');
                        varName       = tmpSplit[0];
                        handlingValue = tmpSplit[1];
                    }

                    string tValue = m.Groups[varName].Value;

                    if (this._variableDefaults != null && tValue.Length == 0)
                    {
                        // use default instead
                        tValue = this._variableDefaults[i];
                    }

                    innerReplace.Replace("${" + varName + "}", this.ManageVariableValue(varName, tValue, handlingValue));
                    i++;
                }

                innerReplace.Replace("${inner}", m.Groups["inner"].Value);

                if (this._truncateLength > 0)
                {
                    // special handling to truncate urls
                    innerReplace.Replace(
                        "${innertrunc}", m.Groups["inner"].Value.TruncateMiddle(this._truncateLength));
                }

                // pulls the htmls into the replacement collection before it's inserted back into the main text
                replacement.ReplaceHtmlFromText(ref innerReplace);

                // remove old bbcode...
                sb.Remove(m.Groups[0].Index, m.Groups[0].Length);

                // insert replaced value(s)
                sb.Insert(m.Groups[0].Index, innerReplace.ToString());

                // text = text.Substring( 0, m.Groups [0].Index ) + tStr + text.Substring( m.Groups [0].Index + m.Groups [0].Length );
                m = this._regExSearch.Match(sb.ToString());
            }

            text = sb.ToString();
        }
        /// <summary>
        /// Pull replacement blocks from the text
        /// </summary>
        /// <param name="replaceBlocks">
        /// The replace Blocks.
        /// </param>
        /// <param name="strText">
        /// The str Text.
        /// </param>
        public static void ReplaceHtmlFromText(this IReplaceBlocks replaceBlocks, ref string strText)
        {
            var sb = new StringBuilder(strText);

            ReplaceHtmlFromText(replaceBlocks, ref sb);

            strText = sb.ToString();
        }
Exemplo n.º 4
0
    /// <summary>
    /// The replace.
    /// </summary>
    /// <param name="text">
    /// The text.
    /// </param>
    /// <param name="replacement">
    /// The replacement.
    /// </param>
    public override void Replace(ref string text, IReplaceBlocks replacement)
    {
      Match m = this._regExSearch.Match(text);
      while (m.Success)
      {
        string replaceItem = this._regExReplace.Replace("${inner}", this.GetInnerValue(m.Groups["inner"].Value));

        int replaceIndex = replacement.Add(replaceItem);
        text = text.Substring(0, m.Groups[0].Index) + replacement.Get(replaceIndex) +
               text.Substring(m.Groups[0].Index + m.Groups[0].Length);

        m = this._regExSearch.Match(text);
      }
    }
Exemplo n.º 5
0
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            var m = this.RegExSearch.Match(text);

            while (m.Success)
            {
                var replaceItem = this.RegExReplace.Replace("${inner}", this.GetInnerValue(m.Groups["inner"].Value));

                var replaceIndex = replacement.Add(replaceItem);
                text =
                    $"{text.Substring(0, m.Groups[0].Index)}{replacement.Get(replaceIndex)}{text.Substring(m.Groups[0].Index + m.Groups[0].Length)}";

                m = this.RegExSearch.Match(text);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            Match m = this._regExSearch.Match(text);

            while (m.Success)
            {
                string replaceItem = this._regExReplace.Replace("${inner}", this.GetInnerValue(m.Groups["inner"].Value));

                int replaceIndex = replacement.Add(replaceItem);
                text = text.Substring(0, m.Groups[0].Index) + replacement.Get(replaceIndex) +
                       text.Substring(m.Groups[0].Index + m.Groups[0].Length);

                m = this._regExSearch.Match(text);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            int index = -1;

            do
            {
                index = text.FastIndexOf(this._find);

                if (index >= 0)
                {
                    // replace it...
                    int replaceIndex = replacement.Add(this._replace);
                    text = text.Substring(0, index) + replacement.Get(replaceIndex) +
                           text.Substring(index + this._find.Length);
                }
            }while (index >= 0);
        }
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            Match m = this._regExSearch.Match(text);
            while (m.Success)
            {
                string inner = this._syntaxHighlighter.ColorText(
                    this.GetInnerValue(m.Groups["inner"].Value), m.Groups["language"].Value);

                string replaceItem = this._regExReplace.Replace("${inner}", inner);

                // pulls the htmls into the replacement collection before it's inserted back into the main text
                int replaceIndex = replacement.Add(replaceItem);

                text = text.Substring(0, m.Groups[0].Index) + replacement.Get(replaceIndex)
                       + text.Substring(m.Groups[0].Index + m.Groups[0].Length);

                m = this._regExSearch.Match(text);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            int index;

            do
            {
                index = text.FastIndexOf(this.find);

                if (index < 0)
                {
                    continue;
                }

                // replace it...
                var replaceIndex = replacement.Add(this.replace);
                text = text.Substring(0, index) + replacement.Get(replaceIndex) +
                       text.Substring(index + this.find.Length);
            }while (index >= 0);
        }
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            Match m = this._regExSearch.Match(text);

            while (m.Success)
            {
                string inner = this._syntaxHighlighter.ColorText(
                    this.GetInnerValue(m.Groups["inner"].Value), m.Groups["language"].Value);

                string replaceItem = this._regExReplace.Replace("${inner}", inner);

                // pulls the htmls into the replacement collection before it's inserted back into the main text
                int replaceIndex = replacement.Add(replaceItem);

                text = text.Substring(0, m.Groups[0].Index) + replacement.Get(replaceIndex)
                       + text.Substring(m.Groups[0].Index + m.Groups[0].Length);

                m = this._regExSearch.Match(text);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            var m = this.RegExSearch.Match(text);

            while (m.Success)
            {
                var inner = this.syntaxHighlighter.ColorText(
                    this.GetInnerValue(m.Groups["inner"].Value), m.Groups["language"].Value, this.IsEditMode);

                var replaceItem = this.RegExReplace.Replace("${inner}", inner);

                // pulls the html's into the replacement collection before it's inserted back into the main text
                var replaceIndex = replacement.Add(replaceItem);

                text =
                    $"{text.Substring(0, m.Groups[0].Index)}{replacement.Get(replaceIndex)}{text.Substring(m.Groups[0].Index + m.Groups[0].Length)}";

                m = this.RegExSearch.Match(text);
            }
        }
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            var sb = new StringBuilder(text);

              Match m = this._regExSearch.Match(text);
              while (m.Success)
              {
            // just replaces with no "inner"
            int replaceIndex = replacement.Add(this._regExReplace);

            // remove old bbcode...
            sb.Remove(m.Groups[0].Index, m.Groups[0].Length);

            // insert replaced value(s)
            sb.Insert(m.Groups[0].Index, replacement.Get(replaceIndex));

            // text = text.Substring( 0, m.Groups [0].Index ) + replacement.GetReplaceValue( replaceIndex ) + text.Substring( m.Groups [0].Index + m.Groups [0].Length );
            m = this._regExSearch.Match(sb.ToString());
              }

              text = sb.ToString();
        }
        /// <summary>
        /// The get replacements from text.
        /// </summary>
        /// <param name="replaceBlocks">
        /// The replace Blocks.
        /// </param>
        /// <param name="sb">
        /// The sb.
        /// </param>
        public static void ReplaceHtmlFromText(this IReplaceBlocks replaceBlocks, ref StringBuilder sb)
        {
            Match m = _regExHtml.Match(sb.ToString());

            while (m.Success)
            {
                // add it to the list...
                int index = replaceBlocks.Add(m.Groups[0].Value);

                // replacement lookup code
                string replace = replaceBlocks.Get(index);

                // remove the replaced item...
                sb.Remove(m.Groups[0].Index, m.Groups[0].Length);

                // insert the replaced value back in...
                sb.Insert(m.Groups[0].Index, replace);

                // text = text.Substring( 0, m.Groups [0].Index ) + replace + text.Substring( m.Groups [0].Index + m.Groups [0].Length );
                m = _regExHtml.Match(sb.ToString());
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            var sb = new StringBuilder(text);

            var m = this._regExSearch.Match(text);

            while (m.Success)
            {
                // just replaces with no "inner"
                var replaceIndex = replacement.Add(this._regExReplace);

                // remove old bbcode...
                sb.Remove(m.Groups[0].Index, m.Groups[0].Length);

                // insert replaced value(s)
                sb.Insert(m.Groups[0].Index, replacement.Get(replaceIndex));

                // text = text.Substring( 0, m.Groups [0].Index ) + replacement.GetReplaceValue( replaceIndex ) + text.Substring( m.Groups [0].Index + m.Groups [0].Length );
                m = this._regExSearch.Match(sb.ToString());
            }

            text = sb.ToString();
        }
Exemplo n.º 15
0
    /// <summary>
    /// The replace.
    /// </summary>
    /// <param name="text">
    /// The text.
    /// </param>
    /// <param name="replacement">
    /// The replacement.
    /// </param>
    public override void Replace(ref string text, IReplaceBlocks replacement)
    {
      int index = -1;

      do
      {
        
        index = text.FastIndexOf(this._find);

        if (index >= 0)
        {
          // replace it...
          int replaceIndex = replacement.Add(this._replace);
          text = text.Substring(0, index) + replacement.Get(replaceIndex) +
                 text.Substring(index + this._find.Length);
        }
      }
      while (index >= 0);
    }
Exemplo n.º 16
0
 /// <summary>
 /// The replace.
 /// </summary>
 /// <param name="text">
 /// The text.
 /// </param>
 /// <param name="replacement">
 /// The replacement.
 /// </param>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public abstract void Replace(ref string text, IReplaceBlocks replacement);
Exemplo n.º 17
0
    /// <summary>
    /// The replace.
    /// </summary>
    /// <param name="text">
    /// The text.
    /// </param>
    /// <param name="replacement">
    /// The replacement.
    /// </param>
    public override void Replace(ref string text, IReplaceBlocks replacement)
    {
      var sb = new StringBuilder(text);

      Match m = this._regExSearch.Match(text);
      while (m.Success)
      {
        string replaceString = this._regExReplace.Replace("${inner}", this.GetInnerValue(m.Groups["inner"].Value));

        // pulls the htmls into the replacement collection before it's inserted back into the main text
        replacement.ReplaceHtmlFromText(ref replaceString);

        // remove old bbcode...
        sb.Remove(m.Groups[0].Index, m.Groups[0].Length);

        // insert replaced value(s)
        sb.Insert(m.Groups[0].Index, replaceString);

        // text = text.Substring( 0, m.Groups [0].Index ) + tStr + text.Substring( m.Groups [0].Index + m.Groups [0].Length );
        m = this._regExSearch.Match(sb.ToString());
      }

      text = sb.ToString();
    }
Exemplo n.º 18
0
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            var sb = new StringBuilder(text);

            var match = this._regExSearch.Match(text);

            while (match.Success)
            {
                var innerReplace = new StringBuilder(this._regExReplace);
                int i = 0;

                if (this._truncateLength > 0)
                {
                    // special handling to truncate urls
                    innerReplace.Replace(
                      "${innertrunc}", match.Groups["inner"].Value.TruncateMiddle(this._truncateLength));
                }

                var quote = match.Groups["quote"].Value;

                var localQuoteWrote = YafContext.Current.Get<ILocalization>().GetText("COMMON", "BBCODE_QUOTEWROTE");
                var localQuotePosted = YafContext.Current.Get<ILocalization>()
                                                    .GetText("COMMON", "BBCODE_QUOTEPOSTED");

                // extract post id if exists
                if (quote.Contains(";"))
                {
                    string postId;

                    string userName;

                    try
                    {
                        postId = quote.Substring(quote.IndexOf(";") + 1);
                        userName = quote = quote.Remove(quote.IndexOf(";"));
                    }
                    catch (Exception)
                    {
                        // if post id is missing
                        postId = string.Empty;
                        userName = quote;
                    }

                    if (postId.IsSet())
                    {
                        quote =
                            @"{0} <a href=""{1}""><img src=""{2}"" title=""{3}"" alt=""{3}"" /></a>".FormatWith(
                                localQuotePosted.Replace("{0}", userName),
                                YafBuildLink.GetLink(ForumPages.posts, "m={0}#post{0}", postId),
                                YafContext.Current.Get<ITheme>().GetItem("ICONS", "ICON_LATEST"),
                                YafContext.Current.Get<ILocalization>().GetText("COMMON", "BBCODE_QUOTEPOSTED_TT"));
                    }
                    else
                    {
                        quote = localQuoteWrote.Replace("{0}", quote);
                    }
                }
                else
                {
                    quote = localQuoteWrote.Replace("{0}", quote);
                }

                innerReplace.Replace("${quote}", quote);

                foreach (string tVar in this._variables)
                {
                    string varName = tVar;
                    string handlingValue = string.Empty;

                    if (varName.Contains(":"))
                    {
                        // has handling section
                        string[] tmpSplit = varName.Split(':');
                        varName = tmpSplit[0];
                        handlingValue = tmpSplit[1];
                    }

                    string tValue = match.Groups[varName].Value;

                    if (this._variableDefaults != null && tValue.Length == 0)
                    {
                        // use default instead
                        tValue = this._variableDefaults[i];
                    }

                    innerReplace.Replace("${" + varName + "}", this.ManageVariableValue(varName, tValue, handlingValue));
                    i++;
                }

                innerReplace.Replace("${inner}", match.Groups["inner"].Value);

                // pulls the htmls into the replacement collection before it's inserted back into the main text
                replacement.ReplaceHtmlFromText(ref innerReplace);

                // remove old bbcode...
                sb.Remove(match.Groups[0].Index, match.Groups[0].Length);

                // insert replaced value(s)
                sb.Insert(match.Groups[0].Index, innerReplace.ToString());

                // text = text.Substring( 0, m.Groups [0].Index ) + tStr + text.Substring( m.Groups [0].Index + m.Groups [0].Length );
                match = this._regExSearch.Match(sb.ToString());
            }

            text = sb.ToString();
        }
Exemplo n.º 19
0
    /// <summary>
    /// The replace.
    /// </summary>
    /// <param name="text">
    /// The text.
    /// </param>
    /// <param name="replacement">
    /// The replacement.
    /// </param>
    public override void Replace(ref string text, IReplaceBlocks replacement)
    {
      var sb = new StringBuilder(text);

      Match m = this._regExSearch.Match(text);
      while (m.Success)
      {
        var innerReplace = new StringBuilder(this._regExReplace);
        int i = 0;

        foreach (string tVar in this._variables)
        {
          string varName = tVar;
          string handlingValue = String.Empty;

          if (varName.Contains(":"))
          {
            // has handling section
            string[] tmpSplit = varName.Split(':');
            varName = tmpSplit[0];
            handlingValue = tmpSplit[1];
          }

          string tValue = m.Groups[varName].Value;

          if (this._variableDefaults != null && tValue.Length == 0)
          {
            // use default instead
            tValue = this._variableDefaults[i];
          }

          innerReplace.Replace("${" + varName + "}", this.ManageVariableValue(varName, tValue, handlingValue));
          i++;
        }

        innerReplace.Replace("${inner}", m.Groups["inner"].Value);

        if (this._truncateLength > 0)
        {
          // special handling to truncate urls
          innerReplace.Replace(
            "${innertrunc}", m.Groups["inner"].Value.TruncateMiddle(this._truncateLength));
        }

        // pulls the htmls into the replacement collection before it's inserted back into the main text
        replacement.ReplaceHtmlFromText(ref innerReplace);

        // remove old bbcode...
        sb.Remove(m.Groups[0].Index, m.Groups[0].Length);

        // insert replaced value(s)
        sb.Insert(m.Groups[0].Index, innerReplace.ToString());

        // text = text.Substring( 0, m.Groups [0].Index ) + tStr + text.Substring( m.Groups [0].Index + m.Groups [0].Length );
        m = this._regExSearch.Match(sb.ToString());
      }

      text = sb.ToString();
    }
Exemplo n.º 20
0
 /// <summary>
 /// The replace.
 /// </summary>
 /// <param name="text">
 /// The text.
 /// </param>
 /// <param name="replacement">
 /// The replacement.
 /// </param>
 /// <exception cref="NotImplementedException">
 /// </exception>
 public abstract void Replace(ref string text, IReplaceBlocks replacement);
Exemplo n.º 21
0
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            var sb = new StringBuilder(text);

            var match = this.RegExSearch.Match(text);

            while (match.Success)
            {
                var innerReplace = new StringBuilder(this.RegExReplace);
                var i            = 0;

                if (this.TruncateLength > 0)
                {
                    // special handling to truncate urls
                    innerReplace.Replace(
                        "${innertrunc}",
                        match.Groups["inner"].Value.TruncateMiddle(this.TruncateLength));
                }

                var quote = match.Groups["quote"].Value;

                var localQuoteWrote  = BoardContext.Current.Get <ILocalization>().GetText("COMMON", "BBCODE_QUOTEWROTE");
                var localQuotePosted = BoardContext.Current.Get <ILocalization>().GetText("COMMON", "BBCODE_QUOTEPOSTED");

                // extract post id if exists
                if (quote.Contains(";"))
                {
                    string postId;

                    string userName;

                    try
                    {
                        postId   = quote.Substring(quote.LastIndexOf(";", StringComparison.Ordinal) + 1);
                        userName = quote = quote.Remove(quote.LastIndexOf(";", StringComparison.Ordinal));
                    }
                    catch (Exception)
                    {
                        // if post id is missing
                        postId   = string.Empty;
                        userName = quote;
                    }

                    quote = postId.IsSet()
                                ? $@"<footer class=""blockquote-footer pt-1 mt-3"">
                                         <cite>{localQuotePosted.Replace("{0}", userName)}&nbsp;<a href=""{BuildLink.GetLink(ForumPages.Posts, "m={0}#post{0}", postId)}""><i class=""fas fa-external-link-alt""></i></a></cite></footer>
                                         <p class=""mb-0 mt-2"">"
                                : $@"<footer class=""blockquote-footer pt-1 mt-3"">
                                         <cite>{localQuoteWrote.Replace("{0}", quote)}</cite></footer><p class=""mb-0 mt-2"">";
                }
                else
                {
                    quote =
                        $@"<footer class=""blockquote-footer pt-1 mt-3"">
                               <cite>{localQuoteWrote.Replace("{0}", quote)}</cite></footer><p class=""mb-0 mt-2"">";
                }

                innerReplace.Replace("${quote}", quote);

                this.Variables.ForEach(
                    variable =>
                {
                    var varName       = variable;
                    var handlingValue = string.Empty;

                    if (varName.Contains(":"))
                    {
                        // has handling section
                        var tmpSplit  = varName.Split(':');
                        varName       = tmpSplit[0];
                        handlingValue = tmpSplit[1];
                    }

                    var value = match.Groups[varName].Value;

                    if (this.VariableDefaults != null && value.Length == 0)
                    {
                        // use default instead
                        value = this.VariableDefaults[i];
                    }

                    innerReplace.Replace(
                        $"${{{varName}}}",
                        this.ManageVariableValue(varName, value, handlingValue));
                    i++;
                });

                innerReplace.Replace("${inner}", match.Groups["inner"].Value);

                // pulls the html's into the replacement collection before it's inserted back into the main text
                replacement.ReplaceHtmlFromText(ref innerReplace);

                // remove old BBCode...
                sb.Remove(match.Groups[0].Index, match.Groups[0].Length);

                // insert replaced value(s)
                sb.Insert(match.Groups[0].Index, innerReplace.ToString());

                // text = text.Substring( 0, m.Groups [0].Index ) + tStr + text.Substring( m.Groups [0].Index + m.Groups [0].Length );
                match = this.RegExSearch.Match(sb.ToString());
            }

            text = sb.ToString();
        }
Exemplo n.º 22
0
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            var sb = new StringBuilder(text);

            var match = this._regExSearch.Match(text);

            while (match.Success)
            {
                var innerReplace = new StringBuilder(this._regExReplace);
                int i            = 0;

                if (this._truncateLength > 0)
                {
                    // special handling to truncate urls
                    innerReplace.Replace(
                        "${innertrunc}", match.Groups["inner"].Value.TruncateMiddle(this._truncateLength));
                }

                var quote = match.Groups["quote"].Value;

                var localQuoteWrote  = YafContext.Current.Get <ILocalization>().GetText("COMMON", "BBCODE_QUOTEWROTE");
                var localQuotePosted = YafContext.Current.Get <ILocalization>()
                                       .GetText("COMMON", "BBCODE_QUOTEPOSTED");

                // extract post id if exists
                if (quote.Contains(";"))
                {
                    string postId;

                    string userName;

                    try
                    {
                        postId   = quote.Substring(quote.IndexOf(";") + 1);
                        userName = quote = quote.Remove(quote.IndexOf(";"));
                    }
                    catch (Exception)
                    {
                        // if post id is missing
                        postId   = string.Empty;
                        userName = quote;
                    }

                    if (postId.IsSet())
                    {
                        quote =
                            @"{0} <a href=""{1}""><img src=""{2}"" title=""{3}"" alt=""{3}"" /></a>".FormatWith(
                                localQuotePosted.Replace("{0}", userName),
                                YafBuildLink.GetLink(ForumPages.posts, "m={0}#post{0}", postId),
                                YafContext.Current.Get <ITheme>().GetItem("ICONS", "ICON_LATEST"),
                                YafContext.Current.Get <ILocalization>().GetText("COMMON", "BBCODE_QUOTEPOSTED_TT"));
                    }
                    else
                    {
                        quote = localQuoteWrote.Replace("{0}", quote);
                    }
                }
                else
                {
                    quote = localQuoteWrote.Replace("{0}", quote);
                }

                innerReplace.Replace("${quote}", quote);

                foreach (string tVar in this._variables)
                {
                    string varName       = tVar;
                    string handlingValue = string.Empty;

                    if (varName.Contains(":"))
                    {
                        // has handling section
                        string[] tmpSplit = varName.Split(':');
                        varName       = tmpSplit[0];
                        handlingValue = tmpSplit[1];
                    }

                    string tValue = match.Groups[varName].Value;

                    if (this._variableDefaults != null && tValue.Length == 0)
                    {
                        // use default instead
                        tValue = this._variableDefaults[i];
                    }

                    innerReplace.Replace("${" + varName + "}", this.ManageVariableValue(varName, tValue, handlingValue));
                    i++;
                }

                innerReplace.Replace("${inner}", match.Groups["inner"].Value);

                // pulls the htmls into the replacement collection before it's inserted back into the main text
                replacement.ReplaceHtmlFromText(ref innerReplace);

                // remove old bbcode...
                sb.Remove(match.Groups[0].Index, match.Groups[0].Length);

                // insert replaced value(s)
                sb.Insert(match.Groups[0].Index, innerReplace.ToString());

                // text = text.Substring( 0, m.Groups [0].Index ) + tStr + text.Substring( m.Groups [0].Index + m.Groups [0].Length );
                match = this._regExSearch.Match(sb.ToString());
            }

            text = sb.ToString();
        }
Exemplo n.º 23
0
        /// <summary>
        /// The replace.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="replacement">
        /// The replacement.
        /// </param>
        public override void Replace(ref string text, IReplaceBlocks replacement)
        {
            var sb = new StringBuilder(text);

            var match = this._regExSearch.Match(text);

            while (match.Success)
            {
                var innerReplace = new StringBuilder(this._regExReplace);
                var i            = 0;

                if (this._truncateLength > 0)
                {
                    // special handling to truncate urls
                    innerReplace.Replace(
                        "${innertrunc}", match.Groups["inner"].Value.TruncateMiddle(this._truncateLength));
                }

                var quote = match.Groups["quote"].Value;

                var localQuoteWrote  = YafContext.Current.Get <ILocalization>().GetText("COMMON", "BBCODE_QUOTEWROTE");
                var localQuotePosted = YafContext.Current.Get <ILocalization>()
                                       .GetText("COMMON", "BBCODE_QUOTEPOSTED");

                // extract post id if exists
                if (quote.Contains(";"))
                {
                    string postId;

                    string userName;

                    try
                    {
                        postId   = quote.Substring(quote.LastIndexOf(";", StringComparison.Ordinal) + 1);
                        userName = quote = quote.Remove(quote.LastIndexOf(";", StringComparison.Ordinal));
                    }
                    catch (Exception)
                    {
                        // if post id is missing
                        postId   = string.Empty;
                        userName = quote;
                    }

                    if (postId.IsSet())
                    {
                        quote =
                            @"<div class=""card-header text-muted"">{0} <a href=""{1}"">{2}</a></div><div class=""card-body""><p class=""card-text"">".FormatWith(
                                localQuotePosted.Replace("{0}", userName),
                                YafBuildLink.GetLink(ForumPages.posts, "m={0}#post{0}", postId),
                                @"<i class=""fas fa-external-link-alt""></i>",
                                YafContext.Current.Get <ILocalization>().GetText("COMMON", "BBCODE_QUOTEPOSTED_TT"));
                    }
                    else
                    {
                        quote =
                            @"<div class=""card-header text-muted"">{0}</div><div class=""card-body""><p class=""card-text"">"
                            .FormatWith(localQuoteWrote.Replace("{0}", quote));
                    }
                }
                else
                {
                    quote =
                        @"<div class=""card-header text-muted"">{0}</div><div class=""card-body""><p class=""card-text"">"
                        .FormatWith(localQuoteWrote.Replace("{0}", quote));
                }

                innerReplace.Replace("${quote}", quote);

                foreach (var variable in this._variables)
                {
                    var varName       = variable;
                    var handlingValue = string.Empty;

                    if (varName.Contains(":"))
                    {
                        // has handling section
                        var tmpSplit = varName.Split(':');
                        varName       = tmpSplit[0];
                        handlingValue = tmpSplit[1];
                    }

                    var value = match.Groups[varName].Value;

                    if (this._variableDefaults != null && value.Length == 0)
                    {
                        // use default instead
                        value = this._variableDefaults[i];
                    }

                    innerReplace.Replace("${" + varName + "}", this.ManageVariableValue(varName, value, handlingValue));
                    i++;
                }

                innerReplace.Replace("${inner}", match.Groups["inner"].Value);

                // pulls the html's into the replacement collection before it's inserted back into the main text
                replacement.ReplaceHtmlFromText(ref innerReplace);

                // remove old BBCode...
                sb.Remove(match.Groups[0].Index, match.Groups[0].Length);

                // insert replaced value(s)
                sb.Insert(match.Groups[0].Index, innerReplace.ToString());

                // text = text.Substring( 0, m.Groups [0].Index ) + tStr + text.Substring( m.Groups [0].Index + m.Groups [0].Length );
                match = this._regExSearch.Match(sb.ToString());
            }

            text = sb.ToString();
        }