Created
August 16, 2012 00:39
-
-
Save a2life/3365056 to your computer and use it in GitHub Desktop.
ModX snippet to examine resource creation/modification date and attache "new" and/or "update" image if newer than 30 days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is a MODX snippet to add "new" or "Updated" images to menu, | |
* pages and such. | |
* You need to provide your own new.gif and updated.gif file. change the | |
* file path to the images files accordingly. | |
* if called without input parameter then it will look at the page resource and | |
* determine if the page is newly published or updated. | |
* if called with input=`resourceID` then it will look into that resource ID. | |
* This snippet can be also used with getResoruces or Wayfinder. | |
* To indicate if the page is new or updated, then simply call | |
* [[!newOrUpdate]] in the page | |
* To use with Wayfinder, | |
* Wayfinder template should include [[!newOrUpdate? &input=`[[+wf.docit]]`]] | |
* therefore, rowTpl can be defined like this | |
* <li [[+wf.id]] [[+wf.classes]] > | |
* <a href="[[+wf.link]]" title="[[+wf.title]]" [[+wf.attributes]]> | |
* [[+wf.linktext]][[!newOrUpdate? input=`[[+wf.docid]]`]]</a> [[+wf.wrapper]] | |
* </li> | |
* and wayfinder snippet will be called like this | |
* [[!Wayfinder? &rowTpl=`rowTpl`]] | |
* To use with getResources.. | |
* getResources template should include [[!newOrUpdate? &input=`[[+id]]`]] | |
* therefore, the template can be defined like so.. | |
* <dt> | |
* <a href="[[~[[+id]]]]">[[+pagetitle]]</a>[[!NewOrUpdate? input=`[[+id]]`]] | |
* <dd> | |
* [[+longtitle]]</br> | |
* [[+introtext]] | |
* </dd> | |
* </dt> | |
*/ | |
if (isset($input)){ | |
$resource=$modx->getObject('modResource',$input); | |
} | |
else $resource=& $modx->resource; | |
$published=$resource->get('publishedon'); | |
$edited=$resource->get('editedon'); | |
$output=""; | |
if ((time()-strtotime($published))<30*24*60*60) | |
$output.='<img src="images/new.gif" />'; | |
if ((time()-strtotime($edited))<30*24*60*60 and (substr($published,0,9))!=(substr($edited,0,9))) | |
$output.='<img src="images/updated.gif" />'; | |
return $output; |
Above should read [[!newOrUpdate]] etc.,
and git perser ate backticks surrunding [[~##]]
Logic flaw corrected. it now shows both new and update if both dates are less than 30 days from today.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a ModX Snippet that inserts "new.gif" or "update.gif" depending on publishe date and modifiecation date relative to today. if they are less than 30 days difference, it will show relevant gif file. There is a logic flaw (if published and then modified in a short period, it will show New and not modified. Usage in modx is
[[!newOrOld]] for current resource,
or
[[!newOrOld? input=
[[~##]]
]] where ## is a resource ID that the snippet will look into. (can be used in getResource or wayfinder template)