WordPress.org

Ready to get started?Download WordPress

Forums

Crayon Syntax Highlighter
[resolved] Multiple crayons per page - only the first one is processed (18 posts)

  1. sjlevy
    Member
    Posted 1 year ago #

    I have pages with multiple code blocks on them

    Only the first code block is processed, the rest come out like:
    [crayon-5195034c37078/]

    I am not using any custom themes, just the standard with latest WP running on IIS 7.5

    I did not have this problem on a Linux server, but now that I am on IIS it has cropped up

    My wp-content has full permissions for both IUSR and IIS_USRS, so I do not think it is a permissions issue

    Any ideas?

    Thanks

    http://wordpress.org/extend/plugins/crayon-syntax-highlighter/

  2. sjlevy
    Member
    Posted 1 year ago #

    P.S.

    I have tried 'Resetting' the Crayon settings, as well as completely uninstalling and reinstalling the plugin

  3. tomfaltesek
    Member
    Posted 1 year ago #

    I have the same issue. I reinstalled and disabled all other plugins, but that didn't help. I played around with a bunch of setting combinations and that didn't help.

    The Crayon that does show up looks pretty good, though!

  4. sjlevy
    Member
    Posted 1 year ago #

    Tom, are you on IIS as well?

  5. tomfaltesek
    Member
    Posted 1 year ago #

    Yes. 7.5. Did you figure it out?

  6. sjlevy
    Member
    Posted 1 year ago #

    I did some testing

    On Server 2008 (non R2) IIS 7.0 it works

    On Server 2008 R2 IIS 7.5 it does not, I was able to reproduce the problem on a fresh installation

    Still tinkering to see if I can figure it out

    No reply from the developer yet

  7. tomfaltesek
    Member
    Posted 1 year ago #

    That's strange that it works in 7.... I'm pretty clueless about PHP and WordPress. Sorry that I can't be of more help.

    Are you using the WinCache extension for IIS? Do you think that has anything to do with it?

  8. msrosyidi
    Member
    Posted 1 year ago #

    have the same issue but only on my local computer using UniServer ...

  9. tomfaltesek
    Member
    Posted 1 year ago #

    FYI- 2.2.1 did not resolve this issue for me.

  10. sjlevy
    Member
    Posted 1 year ago #

    I don't have WinCache extension

    Still digging around for an answer

  11. sjlevy
    Member
    Posted 1 year ago #

    The Crayon processing isn't working more than once per instance

    Perhaps this is an issue with the latest version of PHP and not necessarily IIS?

    What exact version of PHP are you running? I am running 5.4.15

  12. tomfaltesek
    Member
    Posted 1 year ago #

    I'm running 5.3.24

  13. tomfaltesek
    Member
    Posted 1 year ago #

    I installed PHP 5.4.3 and now it works perfectly fine! Thanks for giving me the idea. Perhaps you should update.

    Here's 64 phpbit version:
    http://www.anindya.com/php-5-4-3-and-php-5-3-13-x64-64-bit-for-windows/

    Some of the php extensions have to be replaced and are provided separately.

    This could have all been avoided if the Web Platform Installer had the latest version of PHP...

  14. sjlevy
    Member
    Posted 1 year ago #

    Hmm, not sure I would trust that

    The latest official release is 5.4.15

    The version on that website was probably compiled on some beta code and is a year old (the article was posted in May 2012)

  15. msrosyidi
    Member
    Posted 1 year ago #

    PHP Version 5.4.15
    Server version: 5.5.31 - MySQL Community Server (GPL)
    WordPress 3.5.1 and WordPress 3.6 beta 3

  16. sjlevy
    Member
    Posted 1 year ago #

    I think it has something to do with both blocks being given the same crayon ID

    After numerous tests I have the following two log entries

    This first log entry is from an instance where both blocks were converted correctly. I was only able to get it to work a few times, and generally on refreshes after long periods of inactivity (perhaps an IIS caching issue?). Notice how each block is given a unique ID.

    [DEBUG] 'init'
     [DEBUG] 'the_posts'
     [DEBUG] 'capture for id 4 len 2828'
     [DEBUG] 'capture adding id 4 , now has len 2842'
     [DEBUG] 'add_crayon_id [crayon-51a0552761ebe'
     [DEBUG] 'add_crayon_id [crayon-51a055276228e'
     [DEBUG] 'capture added id 4 : 2870'
     [DEBUG] 'capture ignore for id 4 : 2828 vs 2870'
     [WP UPLOAD FUNCTION] array (
      'path' => 'C:\\inetpub\\wwwroot\\wordpress/wp-content/uploads/2013/05',
      'url' => 'http://dev4/wordpress/wp-content/uploads/2013/05',
      'subdir' => '/2013/05',
      'basedir' => 'C:\\inetpub\\wwwroot\\wordpress/wp-content/uploads',
      'baseurl' => 'http://dev4/wordpress/wp-content/uploads',
      'error' => false,
    )
     [UPLOAD PATH] 'C:/inetpub/wwwroot/wordpress/wp-content/uploads/crayon-syntax-highlighter/'
     [DEBUG] 'Setting theme directories'
     [DEBUG] '/themes/'
     [DEBUG] 'C:/inetpub/wwwroot/wordpress/wp-content/uploads/crayon-syntax-highlighter/themes/'
     [DEBUG] 'CAPTURED FOR ID 4'
     [DEBUG] 'Setting font directories'
     [DEBUG] '/fonts/'
     [DEBUG] 'C:/inetpub/wwwroot/wordpress/wp-content/uploads/crayon-syntax-highlighter/fonts/'
     [DEBUG] 'capture finished for post id 4 crayon-id 51a0552761ebe atts: 3 code: 1422'
     [DEBUG] 'capture finished for post id 4 crayon-id 51a055276228e atts: 3 code: 997'
     [DEBUG] 'head'
     [DEBUG] 'head: missed enqueue'
     [DEBUG] 'head: force enqueue'
     [DEBUG] 'enqueue'
     [DEBUG] 'the_content'
     [DEBUG] 'shortcode'
     [DEBUG] 'instance'
     [DEBUG] 'the_content: id 4 has UID 51a0552761ebe : 1'
     [DEBUG] 'the_content: REPLACED for id 4 from len 436 to 23791'
     [DEBUG] 'shortcode'
     [DEBUG] 'instance'
     [DEBUG] 'the_content: id 4 has UID 51a055276228e : 1'
     [DEBUG] 'the_content: REPLACED for id 4 from len 436 to 40341'
     [DEBUG] 'the_content'
     [DEBUG] 'the_posts'

    Compare that to this second log entry, which is an example where only one code block is being processed and the other fails to process. Notice how the crayon ID is now duplicated:

    [DEBUG] 'init'
     [DEBUG] 'the_posts'
     [DEBUG] 'capture for id 4 len 2828'
     [DEBUG] 'capture adding id 4 , now has len 2842'
     [DEBUG] 'add_crayon_id [crayon-51a055337be8b'
     [DEBUG] 'add_crayon_id [crayon-51a055337be8b'
     [DEBUG] 'capture added id 4 : 2870'
     [DEBUG] 'capture ignore for id 4 : 2828 vs 2870'
     [WP UPLOAD FUNCTION] array (
      'path' => 'C:\\inetpub\\wwwroot\\wordpress/wp-content/uploads/2013/05',
      'url' => 'http://dev4/wordpress/wp-content/uploads/2013/05',
      'subdir' => '/2013/05',
      'basedir' => 'C:\\inetpub\\wwwroot\\wordpress/wp-content/uploads',
      'baseurl' => 'http://dev4/wordpress/wp-content/uploads',
      'error' => false,
    )
     [UPLOAD PATH] 'C:/inetpub/wwwroot/wordpress/wp-content/uploads/crayon-syntax-highlighter/'
     [DEBUG] 'Setting theme directories'
     [DEBUG] '/themes/'
     [DEBUG] 'C:/inetpub/wwwroot/wordpress/wp-content/uploads/crayon-syntax-highlighter/themes/'
     [DEBUG] 'CAPTURED FOR ID 4'
     [DEBUG] 'Setting font directories'
     [DEBUG] '/fonts/'
     [DEBUG] 'C:/inetpub/wwwroot/wordpress/wp-content/uploads/crayon-syntax-highlighter/fonts/'
     [DEBUG] 'capture finished for post id 4 crayon-id 51a055337be8b atts: 3 code: 1422'
     [DEBUG] 'capture finished for post id 4 crayon-id 51a055337be8b atts: 3 code: 997'
     [DEBUG] 'head'
     [DEBUG] 'head: missed enqueue'
     [DEBUG] 'head: force enqueue'
     [DEBUG] 'enqueue'
     [DEBUG] 'the_content'
     [DEBUG] 'shortcode'
     [DEBUG] 'instance'
     [DEBUG] 'the_content: id 4 has UID 51a055337be8b : 1'
     [DEBUG] 'the_content: REPLACED for id 4 from len 436 to 17000'
     [DEBUG] 'the_content'
     [DEBUG] 'the_posts'
  17. sjlevy
    Member
    Posted 1 year ago #

    I have the answer

    Crayon was assigning multiple blocks the same ID and therefore only the first was being processed

    The problem is with uniqid() on line 505 of crayon_wp.class.php

    In IIS 7.5 + PHP NTS-- uniqid() is apparently more often NOT unique than IS unique

    You can verify this with a simple test, try the following code on your site:

    $i = 1;
    foreach(range(1,1000) as $e) {
    	echo uniqid()." - $i<br />";
    	$i++;
    }

    Sometimes the first hundred or more uniqid() calls return the same value

    The fix: add more entropy to uniqid by changing it to uniqid('',true)

    In this case we also need to replace the . since it clashes with Crayon's RegEx

    So the final answer:

    Change line 505 from:
    $uid = $content[0] . '-' . uniqid();

    To:
    $uid = $content[0] . '-' . str_replace('.','',uniqid('',true));

  18. akarmenia
    Member
    Plugin Author

    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags