Closed (fixed)
Project:
Alinks
Version:
5.x-1.2
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
3 May 2007 at 20:11 UTC
Updated:
7 Nov 2007 at 17:27 UTC
Jump to comment: Most recent
When displaying nodes configured to show alinks the following appears:
# warning: preg_replace() [function.preg-replace]: Unknown modifier 'M' in /home/public_html/modules/alinks/alinks.module on line 145.
# warning: preg_replace() [function.preg-replace]: Unknown modifier 'F' in /home/public_html/modules/alinks/alinks.module on line 145.On the logs:
preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Unknown modifier 'M' in /home/public_html/modules/alinks/alinks.module on line 145.
preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Unknown modifier 'F' in /home/public_html/modules/alinks/alinks.module on line 145.The above errors happen on 2 sites with PHP Version 5.1.4 and PHP Version 5.2.1
Comments
Comment #1
Anonymous (not verified) commentedI dont see the issue when running on PHP 5.2.0 MySQL 5.0.27 if that helps with diagnosis
Comment #2
tic2000 commentedUnfortunately I have no way to test the module on a php 5 environment. But it might help if you tell me what string did you want to replace. Cause that errors tells me that you have some non alpha numeric characters. I think you use "/" somewhere in the string, but I might be wrong.
Comment #3
Anonymous (not verified) commentedI tried this one out of curiosity
string1/string2
or
srting1 / string2
result
preg_replace() [function.preg-replace]: Unknown modifier 's'
string1/rope2
or
string1 / rope2
preg_replace() [function.preg-replace]: Unknown modifier 'r'
it seems to be looking at the /s or /r taking the character as the modifier, a space after / makes no difference.
In neither case was a link provided
Comment #4
Anonymous (not verified) commentedI forgot to say
'string1 / string2'
etc. is the complete match I tested
Comment #5
capmex commentedAfter reading your post I did a few tests. I have about 500 product strings:
I had a few products with the / character, I removed them and the error disappeared.
I think the problem was that the form for adding alinks accepted the input without any warning, so I supposed it will be properly escaped, for example all the following strings can be added:
This works:
This doesn't work (no link replacement):
This doesn't work and shows the errors:
On / OffComment #6
capmex commentedTo avoid the error to show on my sites I did a small change in the alinks.module to escape the '/' character and other meaningful regular expression characters on line 114.
Original
$alink_text[] = '/\b'. $word['alink_text'] .'\b/';Changed
$alink_text[] = '/\b'. preg_quote($word['alink_text'], '/') .'\b/';The error ceased to appear even adding alinks with the '/' and other characters, but still there's no link replacement for them as stated on my previous post. Not sure where to look for a solution to that.
Just a correction to my previous post alinks with the '!' character like 'Alert!' work.
Comment #7
Anonymous (not verified) commentedI may be wrong but these characters may have been restricted by the changes in alinks version 5.x-1.0 that took out the bug that allowed Alinks to link to words in code like hyperlinks (have '/' in the path) etc, effectively breaking the site
Comment #8
tic2000 commentedAlinks was at first designed to work with single words. I think it's impossible to make it work on any string. I can do that, but the option to limit the instances replaced will be lost (but if I use str_replace instead of preg_replace then the "plural problem" will appear again).
@capmex
I'm actually amazed that "Alert!" works. "Better Homes & Gardens" doesn't work cause "&" it's replaced with "&" when submitting the article.
I made some test and until now, if I add an option to alinks so you can choose if the string is a "word" or not you can make some of your example work. I couldn't make $25 Coupon and Alert! to work even with this enabled. If instead of "$25 Coupon" I use "A $25 Coupon" it works (with the changes I've made).
The fact is that now alinks doesn't work on strings that start or end with anything else than a letter, number or underscore character or with strings that have "/" (the character I used as delimiter).
@midkemia
The changes made from version 1.0 can be problematic if you have text like this "". Cause anything inside "<" and ">" will be stripped out if you don't use "<" and ">" respectively to write those characters.
Comment #9
tic2000 commentedI've made some more testing.
For those familiar to regular expressions. As is now, alinks looks both at start and at the end of the string for a "word boundary" (a alphanumeric or underscore character).
The solution, as I see it now, is to add two check boxes (one for the start of the string and one for the end of the string) so that the administrator can "tell" if those are "word boundary" (so if the check box is enabled is not a word boundary).
Now I want your opinions on that, if it's clear enough and easy to use for a regular site webmaster, and not for experts. I will make the required changes and submit a patch so you can test it and maybe share your experience with it.
Comment #10
tic2000 commentedDownload the latest version and let me know what you think about this.
Comment #11
Anonymous (not verified) commentedI must admit, v1.2 works fine for me. In my case i do not encounter the need for other options of word boundary, though i can see the possiblility.
What i would say is that different sites have different needs.
I create Alinks for stings i know will be acceptable to provide links for automatically and if in doubt i do not create unless i can check all location, which after a few pages becomes impractical.
As content grows. creating large numbers of Alinks, without considering the possible implications of each if applied in the wrong cases is a dangerous thing.
As soon as you let others create content all rules go out the window :)
Comment #12
capmex commentedWith the new version errors disappear and many previously unmatched links are now working, with the new option the problematic ones starting or ending with special characters can be made to work, so for me your solution is quite good. But I think many other people will find difficult to use the new extra feature. I think the best solution will be to create a regular expression that match any text entered when adding alinks, not sure how difficult that could be I have a very basic idea about regular expressions.
Just something that I noted from an alink that had two spaces between two words it didn't worked until I removed the extra space.
Thanks for the fixes on the new version.
Comment #13
tic2000 commentedIn post #8 what I meant was that
&is replaced with&I must agree with midkemia, the purpose of this module is to automatically replace strings inserted by users. It's not to replace strings like
The World Is Flat [Updated and Expanded]. What's the probability that a user writes this string exactly like that? It seems to me that is used for a site design problem (to replace that string in a limited number of pages designed by the site webmaster). But non the less I will let this option enabled. I think that I'll add an option for advanced alinks, so if you enable that you see the boundary option, if not you don't.I also think I have to add the restrictions to the module description cause as I see people expects from this module more that is designed to do.
Comment #14
Anonymous (not verified) commentedOne young grashopper you will understand :) If something is good they always want better! :)
You have done a fantastic job with this module. To me it is appears as such a simple mod but so useful, Not only does it provide for a complex linking structure across the site, it provides consistency of hyperlinks and associates tags too. From a user point of view this is what they like
Thee idea of the advanced options for the boundaries is a very good one, could that be done in access control or would it be better to keep away from that area if it means adding too much complexity that is unnecesary
Were do we vote for this to be in core :)
Comment #15
tic2000 commentedComment #16
wsams commentedI don't know if this is still active, but that preg_replace() Unknown identifier error can be solved with preg_quote(). What ever string is being matched, say preg_replace("/" . $match . "/","whatever",$string), the $match variable may have regular expression special characters, so you can escape them with preg_quote(). If you're delimiter is / like in the example, just use preg_replace("/" . preg_quote($match,"/") . "/","whatever",$string).
That should do it, let me know if you have questions.