Help!
I've been playing around with the filter hooks trying to get one of my modules to work with them and I've hit a wall which I just can't seem to get around? Currently users have to enter this to display content:
<?php print tablemanager_display(1, 35); ?>
Now this works fine, if a table needs to be paginated then it is (at 35 lines as per the example above) and the pager links do as they should and display each page just fine. If a column is set to be sortable then yes, it can be sorted in either direction by clicking on the appropriate column header - this all works fine...
...but... as I've said, I'm trying to implement the call as a filter as it's not ideal having to give php input filter rights to users who you want to be able to post tables. So, currently I've made it so that:
[tablemanager:1, 35]
Works nicely as well... It displays table 1 and paginates to 35 lines as before, it shows the pager links and the headers marked as sortable jussssst fine... but... None of the links do anything? If you click 'next page' the page reloads with the same view, likewise the header reloads with the same view - nothing works and I just can't fathom out why not? I'm wondering whether it's a Drupal restriction on how filters work or something? Maybe they're run in a sandbox kind of way and so $_GET['q'] kind of things won't work with them? I honestly haven't a clue and it's very frustrating.
If anyone can give me any advice on things to try then PLEASE let me know.
Thank you
Pobster
PS. The filter code is pretty short - so here it is:
/**
* Implementation of hook_filter
*/
function tablemanager_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return (array(0 => t('Tablemanager filter')));
break;
case 'name':
return t('tablemanager filter');
break;
case 'description':
return t('Substitutes [tablemanager: ...] tags with the corresponding table');
break;
case 'no cache':
return TRUE;
break;
case 'prepare':
return $text;
break;
case 'process':
return _tablemanager_process_text($text);
break;
} // end switch
} // tablemanager_filter
function _tablemanager_process_text($text) {
$pattern = "/\[tablemanager:(\d+,?\w*,?\w*,?\w*=?\d*\|?\w*=?\w*\|?\w*=?\w*,?.*?)\]/i";
if (preg_match_all($pattern, $text, $matches)) {
$date = array();
$attrib = array();
foreach ($matches[1] as $no => $args) {
$arg = explode(',', $args);
if ($arg[3]) {
$params = explode('|', $arg[3]);
foreach ($params as $param) {
$temp = explode('=', $param);
$date[$temp[0]] = $temp[1];
}
}
if ($arg[4]) {
$params = explode('|', $arg[4]);
foreach ($params as $param) {
$temp = explode('=', $param);
$attrib[$temp[0]] = $temp[1];
}
}
$text = str_replace($matches[0][$no], tablemanager_display($arg[0], $arg[1], $arg[2], $date, $attrib), $text);
}
}
return $text;
} // _tablemanager_process_text
Comments
Okay... It seems the cache
Okay... It seems the cache is the problem? If I empty it then the links work... Once... And then I have to empty the cache again. SURELY as I've specified:
I shouldn't be getting this problem? What's going on?
Pobster
Same problem
Drupal does not calls my filter every time it loads page :(
My 'problem' was resolved by
My 'problem' was resolved by disabling the filter and re-enabling it. Drupal doesn't use it's filters on the fly (so to speak) - seems wasteful to me, but there you go...
Pobster