Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kelsee Ishmael 71 posts 158 karma points
    Jun 24, 2011 @ 00:03
    Kelsee Ishmael
    0

    Inserting html into TinyMCE with a macro not working.

    I recently created a macro that allows users to pull the value of a query key into the TinyMCE content. There are two properties on the macro.

    • "queryString" defines the query key the user is trying to pull. 
    • "htmlCode" defines the HTML the user would like to output. Users use a token in place of the query string value.

    Code:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:ControlData="urn:ControlData" xmlns:TokenDates="urn:TokenDates"
      exclude-result-prefixes="msxml
    umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes
    Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings
    Exslt.ExsltSets ControlData TokenDates "
    >


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
    <xsl:variable name="queryString" select="/macro/queryString"/>
    <xsl:variable name="stringValue" select="umbraco.library:RequestQueryString($queryString)"/>
    <xsl:variable name="htmlCode" select="/macro/htmlCode"/>
    <xsl:variable name="formattedCode" select="Exslt.ExsltStrings:replace($htmlCode, '[%%stringvalue%%]', $stringValue)"/>
        
    <xsl:template match="/">
    <xsl:if test="$stringValue != ''">
    <xsl:choose>
    <xsl:when test="$htmlCode != ''">
    <xsl:value-of select="$formattedCode" disable-output-escaping="yes"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$stringValue"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:if> 
    </xsl:template>
    </xsl:stylesheet>

    This macro works perfectly on a template, however, whenever I try to insert "html" into the textstring property of the macro, I receive an error when saving the page node. This isn't the first time I've had issues inserting html into a macro in TinyMCE and received an error. The html I was inserting was a very simple <a href>

    Error 1:

    All my content disappears and it is replace with: [tidy error]

    Error 2:



    Server Error in '/' Application.



    Length cannot be less than zero.
    Parameter name: length





    Description: An unhandled exception occurred during
    the execution of the current web request. Please review the stack trace
    for more information about the error and where it originated in the
    code.





    Exception Details: System.ArgumentOutOfRangeException: Length cannot be less than zero.
    Parameter name: length



    Source Error:



    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.





    Stack Trace:



    [ArgumentOutOfRangeException: Length cannot be less than zero.
    Parameter name: length]
    System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +9389195
    umbraco.editorControls.tinyMCE3.TinyMCE.generateMacroTag(String macroContent) +50
    umbraco.editorControls.tinyMCE3.TinyMCE.replaceMacroTags(String text) +93
    umbraco.editorControls.tinyMCE3.TinyMCE.Save() +62
    umbraco.controls.ContentControl.saveClick(Object Sender, ImageClickEventArgs e) +158
    umbraco.controls.ContentControl.savePublish(Object Sender, ImageClickEventArgs e) +20
    System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +115
    System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +120
    System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563








    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1



    Has anybody else had troubles with this? It doesn't seem to matter if I use ascii codes for the html and/or if I use single quotes vs. double quotes.

    Any thoughts?

    Thanks!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jun 25, 2011 @ 23:40
    Jan Skovgaard
    0

    Hi Kaifish

    I've been doing the same trick several times without encoutering this issue...not that I think this matters but out of curiosity what version of Umbraco do you experience this on?

    /Jan

  • Kelsee Ishmael 71 posts 158 karma points
    Jun 28, 2011 @ 22:09
    Kelsee Ishmael
    0

    I've experienced it on multiple installations. It seems to be an issue on all 4.5+ versions.

  • Zac 239 posts 541 karma points
    Sep 29, 2011 @ 02:51
    Zac
    0

    Did you ever find a solution for this issue?  I'm experiencing the same issue on a 4.7 install.

  • Rodion Novoselov 694 posts 859 karma points
    Sep 29, 2011 @ 10:25
    Rodion Novoselov
    0

    I tried this and found that the problem seems to happen when htmlCode contains reserved html characters (e.g. htmlCode is '[%%stringvalue%%]'). As a workaround you can try to enter this directly into the html code of your TinyMCI code in such format:

    umb_htmlcode="&amp;lt;span&amp;gt;[%%stringvalue%%]&amp;lt;/span&amp;gt;"

    And add decoding to your xslt, e.g.:

    <msxml:script language="C#" implements-prefix="scripts">
      <msxml:assembly name="System.Web" />
      public static string HtmlDecode(string html) {
        return System.Web.HttpUtility.HtmlDecode(html);
      }
    msxml:script>

    ...

    <xsl:value-of select="scripts:HtmlDecode($formattedCode)" disable-output-escaping="yes"/>

    The solution looks quite ugly, but I still couldn't find any other one.

  • Rodion Novoselov 694 posts 859 karma points
    Sep 29, 2011 @ 10:30
    Rodion Novoselov
    0

    Also, note, that it's important that special characters should be encoded twice, so that e.g. '<' becomes not '&lt;' but '&amp;lt;' and like that.

  • Zac 239 posts 541 karma points
    Sep 29, 2011 @ 17:22
    Zac
    0

    Thanks for the suggestion. I found the same to be true, however, I can't trust my end users to correctly encode the html.

  • Wojciech Tengler 95 posts 198 karma points
    Nov 28, 2011 @ 12:19
    Wojciech Tengler
    0

    You can find issue and solution here:

    http://umbraco.codeplex.com/workitem/30620

  • Chris Knowles 141 posts 222 karma points
    Dec 07, 2011 @ 11:20
    Chris Knowles
    0

    How do i apply this fix? I'm not sure which file i need to modify?

    Can someone help?

    Thanks

    Chris

  • Zac 239 posts 541 karma points
    Dec 08, 2011 @ 18:19
    Zac
    1

    I fixed this by making some changes to the /umbraco_client/tiny_mce3/tiny_mce_src.js file.  I posted the updated file on my website and you can download it here: http://www.tadasolutions.com/downloads/tiny_mce_src.js.

    Let me know if this solves your issue -- it worked wonderfully for me.

Please Sign in or register to post replies

Write your reply to:

Draft