Page 1 of 1

Check if a Page is New (or Freshly updated)

Posted: Thu Mar 04, 2010 6:35 am
by hexdj
I have created a UDT that can be used to check if a Content Page is new or has fresh contents (solely based on the last modification made) and will output anything that you like, it can be something basic like the word NEW next to a menu item, or an image inside the contents of the page that's being viewed, etc.

Update:
I have converted this into a plugin, which you can download here.

If you'd rather use it as a UDT, this is the code, which I have named FreshContent

Code: Select all

global $gCms;
$db =& $gCms->GetDb();

// The alias of the page to check
$the_alias = isset($params['alias']) ? $params['alias'] : ""; 

// Max number of days for a page to be considered "fresh"
$the_days = isset($params['days']) ? $params['days'] : "";

// HTML that will be output if page is at least x days "fresh"
$the_output = isset($params['output']) ? $params['output'] : "";

$query = "SELECT modified_date FROM ".cms_db_prefix()."content WHERE content_alias=?";
$row = $db->GetRow($query, array($the_alias));
if($row)
{
   $last_mod = strtotime($row['modified_date']);

   $today = time();

   $date_diff = floor(($today - $last_mod)/86400);
  
   if ($date_diff < $the_days)
   {
      return $the_output;
   }
}

else
{
  return "Content page not found, check the page <em>alias</em>.";
}
Parameters:
alias = the alias of the page in question
days = max number of days for a page to be considered "New"
output = the html to be output if a page is "New"

Usage:

Code: Select all

{FreshContent alias='home' days='14' output='<img src="new.gif" />'}
The example above checks if the page with 'home' alias has been modified in the last 14 days and if so, an image new.gif is displayed (html)

The output can be any HTML, another example would be:

Code: Select all

<li {FreshContent alias='home' days='14' output='class="new_item"'}>
   <a href="index.php/home">Home Page</a>
</li>
Yet another example, for use with Menu Manager:

Code: Select all

{FreshContent alias=$node->alias days='5' output='<img src="star.gif" />'}
Place it in the appropriate place in your Menu template and will output an image next to menu items that are at least 5 days old or more recent.

One more example:

Code: Select all

</__body>
{FreshContent alias=$page_alias days='8' output='<div class="notice">This page is new!</div>'}
...
If you use the above in your page's template it will output the above div if the page that's being viewed is at the most 8 days old.

As you can see, there's many possibilities with this simple UDT. I am making this UDT into a Plugin and will soon bee posted on the forge.

Re: Check if a Page is New (or Freshly updated)

Posted: Mon Mar 18, 2013 11:40 am
by DerWald
Can U help with this udt modify? I want to get last FEU login date to check if page was modified since last visit.