Skip to content

Instantly share code, notes, and snippets.

@exside
Forked from a2life/NeworUpdate
Created March 3, 2013 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exside/5073854 to your computer and use it in GitHub Desktop.
Save exside/5073854 to your computer and use it in GitHub Desktop.
<?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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment