Date issue in php-enabled custom filter
| Project: | Custom filter |
| Version: | 5.x-1.2 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
I created a custom filter under Drupal 5.7 using PHP code and it is not querying date information correctly. In case it's important, I'm using a customized zen theme (from starterkit) and am on PHP 5.2.4 / MySQL 5.0.45.
Interestingly, the exact same code works fine when added to node.tpl.php instead, although the formatting of the code is a little different:
Code in node.tpl.php:
<div align="right" class="caption"><?php print t('(node.tpl) Last Revision: ') . format_date($node->changed, 'custom', "F jS, Y"); ?></div>
Code in custom filter:
return
'<div align="right" class="caption">'
. t('Last Revision: ') . format_date($node->changed, 'custom', "F jS, Y")
.'</div>';The settings for this filter are:
Name: Revision Notation
Description: Prints "Last revised on" notation.
Pattern: /\[revision\]/i
Replacement text: (See php code above)
PHP checkbox: checked
I'm sure it isn't the fault of the module, but it appears that when code like this is used in this way, the date and time is: "December 31st, 1969" (beginning of Unix epoch?). When the code I posted above is used in node.tpl.php instead, it actually grabs the date the node is saved, so I think it's just a difference in how the the query is being executed. What does MySQL see in this case? Let me know if you need me to create a new issue for this one.
I've used it in both Filtered HTML and PHP code input formats with the same result. My Filtered HTML filter ranking is:
URL fiter - 0
HTML flter - 1
Linebreak converter - 2
Hide email addresses - 3 (SpamSpan module)
Headngs to Anchors - 4 (Table of Contents module)
Table of Contents - 5 (Table of Contents module)
Term and Year - 6 (note: this is another custom filter)
Tablemanager fiter - 7 (Table Manager module)
Revision Notation - 8(similar to PHP code filter ranking)
In another issue, arhip said about this:
I've tried the replacement rule and the date shown is January 1st, 1970. I've checked $GLOBALS, seems that during filter process $node hadn't been loaded yet. But when the code used in node.tpl.php, $node had been loaded, so it worked.
Now I'm trying using node_load hook.
Ok, I think I need you to create a new issue.
Thanks.

#1
Thought I'd check in again. Do you think you will be able to take a look at this issue?
#2
Sorry, I have a lot of work to be done. This issue is a difficult thing to solve, since all filter processing was done before all information about a node loaded.
This is my temporary solution, by setting variable
$vars->nodebefore the filter get processed. Then the replacement code should be like this:return'<div align="right" class="caption">'
. t('Last Revision: ') . format_date($vars->node->changed, 'custom', "F jS, Y")
.'</div>';
Still looking for a better solution, to integrate nicely with this module.
#3
And since this is normal due to node load order, I change the category as feature request.
#4
Drupal filters don't get any reference to the node they are used in.
If you would be working with Drupal 6, you could get the node object with a call to
menu_get_object(). In the case of Drupal 5, you must manually load the node object usingarg()to retrieve the node ID.#5
As the report has gotten an answer, I am setting it as fixed.
#6
Automatically closed -- issue fixed for 2 weeks with no activity.