<?php
#CMS - CMS Made Simple
#(c)2010 by Michael Kat. (http://www.MKRD.info/)
#This project's homepage is: http://dev.cmsmadesimple.org
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY.

function smarty_cms_function_last_created_pages($params, &$smarty) {

	global $gCms;
	$db = $gCms->db;

	if(empty($params['number']))
		$number = 20;
	else
		$number = $params['number'];
		
	if(empty($params['format']))
		$format = "d. M Y";
	else
		$format = $params['format'];

	
	$query = "SELECT * FROM ".cms_db_prefix()."content WHERE active=1 ORDER BY create_date DESC LIMIT 0,".$number;
	$dbresult = $db->Execute($query);

	$ret = "";
	while ($dbresult && $row = $dbresult->FetchRow())
	{
		$ret .= date($format,$db->UnixTimeStamp($row['create_date']));
		$ret .= "&nbsp;<a href=\"index.php/".$row['content_alias']."\" target=\"_self\">".$row['content_name']."</a><br />";
	}

	return $ret;
}

function smarty_cms_help_function_last_created_pages() {
	?>
        <h3>What does this do?</h3>
        <p>Prints the most recently created pages. If no format is given, it will default to a format similar to '01. Jan 2006'. If no number is given, 20 pages are displayed.</p>
        <h3>How do I use it?</h3>
        <p>Just insert the tag into your template/page like: <code>{last_created_pages format='d. M Y' number='20'}</code></p>
        <h3>What parameters does it take?</h3>
        <ul>
			<li><em>(optional)</em> format - Date/Time format using parameters from php's date (not strftime!) function. See <a href="http://php.net/date" target="_blank">here</a> for a parameter list and information.</li>
			<li><em>(optional)</em> number - Max number of pages to show.</li>
        </ul>
        </p>

	<?php
}

function smarty_cms_about_function_last_created_pages() {
	?>
        <p>Author: Michael Kat. &lt;www.MKRD.info&gt;</p>
        <p>Version: 1.0</p>
        <p>
        Change History:<br />
        1.0 - Initial release based on function.last_modified_pages by Thomas Gubisch
		      Compatible with CMSMS version 1.8.2

        </p>
	<?php
}
?>
