Skip to content

Instantly share code, notes, and snippets.

@a2life
Created August 16, 2012 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save a2life/3365056 to your computer and use it in GitHub Desktop.
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
<?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;
@a2life
Copy link
Author

a2life commented Aug 16, 2012

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)

@a2life
Copy link
Author

a2life commented Aug 16, 2012

Above should read [[!newOrUpdate]] etc.,

@a2life
Copy link
Author

a2life commented Aug 16, 2012

and git perser ate backticks surrunding [[~##]]

@a2life
Copy link
Author

a2life commented Aug 17, 2012

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