Hi there,
Ran into a problem, an incompatibility between the Print module and Quiz module.
When you start a Quiz, on the first page, everything's fine. Once you move to the next page, the url for the quiz looks something like this:
node/6/quiz/start/eb7a5f1ad74b2dfd1d2786d05aa58a6c
...and then the print/email links stop showing up.
Digging into the code, I found that at this point, print_insert_link doesn't seem to have access to the $node object or $path variable, so it attempts to get a path from the url, and fails, because of all the cruft on the end from the quiz module.
The original code looks like this...
if ($path === NULL) {
$nid = preg_replace('!^node/!', '', $_GET['q']);
$path = $_GET['q'];
}
The $_GET['q'] is useless 'cuz you just end up with quiz path (ie. /node/6/quiz/start/eb7a5f1ad74b2dfd1d2786d05aa58a6c) and the regular expression doesn't return a proper node id either (ie. 6/quiz/start/eb7a5f1ad74b2dfd1d2786d05aa58a6c)
Not sure, but there might be other modules out there that alter the URL in the same way.
Suggestion: instead of using preg_replace, use preg_match and make the regex a little more targetted...
if ($path === NULL) {
preg_match('!^node/([0-9]+)!', $_GET['q'],$matches);
$nid = $matches[1];
$path = $matches[0];
}
This should work exactly the same as it's working now, returning the same results, but will also prevent the module from getting paths that have had additional elements added to the end of them like the Quiz module does.
Sorry, I don't know how to roll a patch yet, otherwise I'd upload one. :P
Thoughts?
Note - I'm running Print v1.4, but the same incompatibility exists in v1.6 from what I can tell, since those functions are still using preg_replace.
Comments
Comment #1
jcnventuraHi,
It's nice that you bothered looking into the code, but you should have looked a bit deeper.
The lines you looked at basically determine whether a page is a Drupal node or not. In the case of the quiz page, they correctly determine that it is not a node by the fact that the path is not node/number. If you want to have a print link in those pages you have to configure the appropriate path in the non-node textarea that you can find in the settings pages.
João
Comment #2
Stephen Scholtz commentedYou're right João, I didn't quite go far enough.
In the settings pages for Print (yoursite.com/admin/settings/print), I looked under "Advanced Link Options" and found the "Show link in system (non-content) pages" option. Setting it to "Show on every page" fixed my problem, no need to change to module code.
Sorry about that!
Cheers,
Stephen