ramir
Forum Replies Created
-
Forum: Plugins
In reply to: [Plugin: Twitter for WordPress] Error in hyperlink discoveryRather 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 https://
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 https:// $text = preg_replace("/(?<!:\/\/)(www\.([a-z][a-z0-9\-]*[a-z0-9]\.)*[a-z]+(\/[a-zA-Z0-9\#\%\_\=\*\-\?\&\.]*[a-zA-Z0-9\#\%\_\=\*\-\?\&])*)/i","https://$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);
Forum: Plugins
In reply to: [Plugin: Twitter for WordPress] Error in hyperlink discoveryThe regexps that are applied to the text to generate a-elements are not mutually exclusive.
When the text contains an url of the form https://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.