diff --git a/smileys.module b/smileys.module index d938d99..11d49b5 100644 --- a/smileys.module +++ b/smileys.module @@ -11,6 +11,15 @@ function smileys_help($path, $arg) { } } +/* According to 'Drupal common practice' the image URL output in node text should + * be a relative one. (This a.o. keeps image links consistent over both http and https). + * However, this can break image links in RSS feeds in Drupal 6. A solution for this is + * to make this module output absolute image URLs. + * (Another solution, if you want to make both https and RSS feeds work well, + * is to keep the below variable at FALSE and install the pathologic module.) + */ +define(SMILEYS_ABSOLUTE_URLS, TRUE); + /** * Implementation of hook_perm(). */ @@ -204,10 +213,11 @@ function smileys_table() { $header = array(t('Smiley'), t('Acronyms')); $rows = array(); $list = _smileys_list(1, " ORDER BY weight"); + $base = (SMILEYS_ABSOLUTE_URLS ? $GLOBALS['base_url'] : '') . base_path(); foreach ($list as $smiley) { $acronyms = explode(' ', $smiley->acronyms); $rows[] = array( - ''. $acronyms[0] .'', + theme("image", $smiley->image , $acronyms[0], $smiley->description, array("class"=>"smiley-class")), check_plain($smiley->acronyms) ); } @@ -274,14 +284,20 @@ function smileys_filter_process($text) { } } else if (!$ignore) { + $base = (SMILEYS_ABSOLUTE_URLS ? $GLOBALS['base_url'] : '') . base_path(); foreach ($list as $smiley) { $acronyms = explode(" ", $smiley->acronyms); $alt = str_replace('\\', '\\\\', check_plain($smiley->description)); foreach ($acronyms as $a) { - if ($smiley->standalone) - $chunk = eregi_replace("([ ,\.\?!:\(\)\r\n\<\>])". preg_quote($a) ."([ ,\.\?!:\(\)\r\n\<\>])", "\\1image) ."\" title=\"". check_plain($alt) ."\" alt=\"". check_plain($alt) ."\" class=\"smiley-content\"/>\\2", $chunk); - else - $chunk = eregi_replace(preg_quote($a), ''. check_plain($alt) .'', $chunk); + if ($smiley->standalone) { + // For a discussion on additional unicode white space as smiley + // boundaries see http://drupal.org/node/567290#comment-2047730. + // Conclusion: If Drupal requires >=PHP-5.1.0 reconsider using + // unicode PCRE like "\p{Zs}". + $chunk = preg_replace("/(?<= |\xC2\xA0|[ ,\.\?!:\(\)\r\n\<\>])". preg_quote($a) ."(?= |\xC2\xA0|[ ,\.\?!:\(\)\r\n\<\>])/i", theme('image', $smiley->image, $alt, $alt, array('class' => 'smiley-content')) . '\\2', $chunk); + } else { + $chunk = preg_replace('/'. preg_quote($a) .'/i', theme('image', $smiley->image, $alt, $alt, array('class' => 'smiley-content')), $chunk); + } } } }