Get last modified date ona published object in PHP

Author Message

Alex Jones

Wednesday 19 November 2003 10:28:50 am

I need to find out when a content object was last modified with a PHP script (kernel/content view.php to be specific). I have tried a couple of methods but have not been able to generate the proper date. I have a feelign any "solution" that I come up with will be ugly and probably much more complicated than the right way.

I am trying to set the Last-Modified header for each document to the date and time that the content object was modified.

I would truly appreciate any help!

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Hans Melis

Wednesday 19 November 2003 10:49:52 am

Hi Alex,

To get the modified timestamp, just do the following in PHP:

$object->attribute( 'modified' );

This will return a unix timestamp. To format it, just use PHP's date function (and see PHP's manual for all formatting options, it's quite similar to the 'date' command in unix).

--
Hans

Hans
http://blog.hansmelis.be

Hans Melis

Wednesday 19 November 2003 10:58:58 am

In fact, you can copy the header being sent in index.php. That would format the timestamp as a GMT date/time.

header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $object->attribute('modified') ) . 'GMT' );

This will send a Last-Modified header in the format: Wed, 18 Nov 2003 18:54:19 GMT (but then with your timestamp converted to the GMT timezone).

--
Hans

Hans
http://blog.hansmelis.be

Alex Jones

Wednesday 19 November 2003 11:49:10 am

Hans, I really appreciate your help. But this doesn't seem to work. When I insert the code you furnished, eZ publish generates an error and cannot finish processing. I tried echoing the statement, but what resulted was:

'Last-Modified: ' . gmdate(modifed)

Instead of
'Last-Modified: ' . Monday, November 10, 2003 4:04:24 PM

It doesn't seem to grab the date to process... Any thoughts?

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Hans Melis

Wednesday 19 November 2003 1:33:25 pm

That's weird. I tested the code on my local install and it works fine.

Of course, $object means the name of the variable that holds your content object.

Just did another test (just printing it in kernel/content/view.php) with the code:
gmdate( 'D, d M Y H:i:s', $object->attribute('modified') )

The result of that code (on my content object) is:
Mon, 29 Sep 2003 18:43:36

EDIT: I just noticed there's a typo in my post above. It said 'modifed' instead of 'modified'. I should learn to always use copy/paste instead of typing it again ;) Sorry for that.

--
Hans

Hans
http://blog.hansmelis.be

Alex Jones

Wednesday 19 November 2003 2:09:38 pm

That did it! I understand the mistake; I've made many like that myself. In fact, I should have caught the typo as well considering how much time I spent studying that one line.

Thanks for your help!

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 03:28:33
Script start
Timing: Jan 19 2025 03:28:33
Module start 'layout'
Timing: Jan 19 2025 03:28:33
Module start 'content'
Timing: Jan 19 2025 03:28:35
Module end 'content'
Timing: Jan 19 2025 03:28:35
Script end

Main resources:

Total runtime1.5647 sec
Peak memory usage4,096.0000 KB
Database Queries66

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0047 589.2891152.6406
Module start 'layout' 0.00470.0029 741.929739.4922
Module start 'content' 0.00761.5554 781.4219581.7344
Module end 'content' 1.56310.0016 1,363.156316.1250
Script end 1.5646  1,379.2813 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.2080160.0002
Check MTime0.00150.0943160.0001
Mysql Total
Database connection0.00090.056010.0009
Mysqli_queries1.497795.7184660.0227
Looping result0.00060.0400640.0000
Template Total1.532197.920.7661
Template load0.00230.149620.0012
Template processing1.529797.768120.7649
Template load and register function0.00010.005610.0001
states
state_id_array0.00110.069410.0011
state_identifier_array0.00390.247220.0019
Override
Cache load0.00200.1303470.0000
Sytem overhead
Fetch class attribute can translate value0.00100.064720.0005
Fetch class attribute name0.00160.102980.0002
XML
Image XML parsing0.00110.069520.0005
class_abstraction
Instantiating content class attribute0.00000.0017120.0000
General
dbfile0.00100.0644210.0000
String conversion0.00000.000240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
6content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
12content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 32
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs