• Hi.

    Your plugin has issues with discovering hyperlinks from twitter.

    This update:
    http://twitter.com/karla_porter/statuses/2652060959

    Is translated into HTML code as follows:

    <p class="twitter-message">
    The recruitersphere's Renegade of Funk <a href="http://twitter.com/sgordon70" class="twitter-user">@sgordon70</a> 12:00pm EST on
    <a href="http://twitter.com/animal" class="twitter-user">@animal</a> Recruiting Animal Show 
    
    <a href="http://<a href="http://www.recruitingshow.com" class="twitter-link">www.recruitingshow.com</a>" class="twitter-link">http://<a href="http://www.recruitingshow.com" class="twitter-link">www.recruitingshow.com</a></a>
    
    / <a href="http://twitter.com/karla_porter/statuses/2652060959" class="twitter-link">#</a> <span class="twitter-timestamp"><abbr title="2009/07/15 09:58:02">15 mins ago</abbr></span></p>

    As you can see the hyperlink for “recruitingshow.com” has become broken.

    http://wordpress.org/extend/plugins/twitter-for-wordpress/

Viewing 8 replies - 1 through 8 (of 8 total)
  • The regexps that are applied to the text to generate a-elements are not mutually exclusive.

    When the text contains an url of the form http://www.some.where, the first regexp (which matches a full url starting with a protocol) generates an a-element, and the second regexp (which matches a url without a protocol but starting with www.) generates a-elements inside both the href-attribute and the contained text of the first a-element.

    The second regexp should not match anything that has already been matched by the first, or in general, anything that is inside an a-element.

    Rather than generating a-elements with two different regexps, which causes the problems mentioned above, it would probably be better to use only one regexp to generate a-elements from complete urls. Before this any incomplete urls can be first turned into complete urls e.g. by adding http://

    I’m also not very happy with the url syntax in the regexps, which among other problems does not seem to allow any hash signs, or periods in the path part.

    My suggestion:

    // turn an incomplete url beginning with www. into a complete url beginning with http://
    $text = preg_replace("/(?<!:\/\/)(www\.([a-z][a-z0-9\-]*[a-z0-9]\.)*[a-z]+(\/[a-zA-Z0-9\#\%\_\=\*\-\?\&\.]*[a-zA-Z0-9\#\%\_\=\*\-\?\&])*)/i","http://$1", $text);
    
    // turn complete url beginning with protocol:// into a-elements
    $text = preg_replace("/([a-zA-Z]+:\/\/([a-z][a-z0-9\-]*[a-z0-9]\.)*[a-z]+(\/[a-zA-Z0-9\#\%\_\=\*\-\?\&\.]*[a-zA-Z0-9\#\%\_\=\*\-\?\&])*)/i","<a href=\"$1\" class=\"twitter-link\">$1</a>", $text);

    just noting that ramir’s suggested change above worked great.

    thanks ramir, your suggestion works much better for me also. The only (slight) problem is if the url ends with a ‘/’, it doesn’t get included in the link. Not a huge issue for me though, I’ll try to figure it out.

    Thanks for the fix. It works great.

    For any beginners finding this thread and wondering how to use ramir’s fix for version 1.9.6 of Twitter for WordPress, open the twitter.php file and replace the following lines (115-119):

    // Props to Allen Shaw
    // match protocol://address/path/file.extension?some=variable&another=asf%
    $text = preg_replace("/\b([a-zA-Z]+:\/\/[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)\b/i","<a href=\"$1\" class=\"twitter-link\">$1</a>", $text);
    // match www.something.domain/path/file.extension?some=variable&another=asf%
    $text = preg_replace("/\b(www\.[a-z][a-z0-9\_\.\-]*[a-z]{2,6}[a-zA-Z0-9\/\*\-\?\&\%]*)\b/i","<a href=\"http://$1\" class=\"twitter-link\">$1</a>", $text);

    with ramir’s code:

    // Props to ramir
    // turn an incomplete url beginning with www. into a complete url beginning with http://
    $text = preg_replace("/(?<!:\/\/)(www\.([a-z][a-z0-9\-]*[a-z0-9]\.)*[a-z]+(\/[a-zA-Z0-9\#\%\_\=\*\-\?\&\.]*[a-zA-Z0-9\#\%\_\=\*\-\?\&])*)/i","http://$1", $text);
    // turn complete url beginning with protocol:// into a-elements
    $text = preg_replace("/([a-zA-Z]+:\/\/([a-z][a-z0-9\-]*[a-z0-9]\.)*[a-z]+(\/[a-zA-Z0-9\#\%\_\=\*\-\?\&\.]*[a-zA-Z0-9\#\%\_\=\*\-\?\&])*)/i","<a href=\"$1\" class=\"twitter-link\">$1</a>", $text);
    // Props to Allen Shaw

    just an FYI for people using Ramir’s code above, the new “j.mp” shortened links no longer work with it. Expect to see these links a lot more since the bit.ly team is behind it and are beginning to roll out this week.

    I modified the regexp to work with the plugin:

    // turn complete url beginning with protocol:// into a-elements
    	$text = preg_replace("/([a-zA-Z]+:\/\/([a-z0-9\-]*[a-z0-9]\.)*[a-z]+(\/[a-zA-Z0-9\#\%\_\=\*\-\?\&\.]*[a-zA-Z0-9\#\%\_\=\*\-\?\&])*)/i","<a href=\"$1\" class=\"twitter-link\">$1</a>", $text);

    do you know how we can display more than 1 tweet ?
    I searched all codes but could not find or make sure..
    I want to display last 5 tweets on my site

    i do not mean widget. because I have bilingual site, i want to set two different twitter account in different languages. I’m able to do twitter account part, meaning in english different account, in secondary language different twitter account.
    just i could not set the number of links in code.
    how can i make it default it in code ?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Twitter for WordPress] Error in hyperlink discovery’ is closed to new replies.