Posts tagged with “year”

September 20

Copyright Year Smarty Plugin

I've been seeing a lot of people handling the copyright year quite wrong, even though it is a very simple matter, one that should always be automated since it requires an yearly maintenance otherwise. The copyright year should be handled as it follows:

  • display the current year only if the website/blog was created this year
  • display the creation year and the current year if the website/blog was created one or more years ago

Pretty simple and a lot easier to automatize than to always remember to change the year when it actually needs changing. And since it is somewhere between the back-end and the front-end I think Smarty (or you templating engine of choice) is the way to go for this one and that is why I built a tiny but quite useful Smarty plugin to do this for you.

You just have to provide the "company name" (or your name, or your projects name, you got the point) and the year that the project was created and it handles the rest. Pretty straight-forward.

Example 1:
{copyright company="George Maicovschi" created="2009"}
will output
All content copyright © 2009 George Maicovschi

Example 2:
{copyright company="George Maicovschi" created="2006"}
will output
All content copyright © 2006-2009 George Maicovschi

In order to use the code just copy and paste it in a file name function.copyright.php that is located in Smarty's plugins directory.

<?php
function smarty_function_copyright($params,&$smarty)
	{
	//The `company` parameter cannot be empty. Check for it;
	if (empty($params['company']))
		{
		$smarty->_trigger_fatal_error("[copyright] param `company` missing");
		return;
		}
	//The `created` parameter cannot be empty. Check for it;
	if (empty($params['created']))
		{
		$smarty->_trigger_fatal_error("[copyright] param `created` missing");
		return;
		}
	$current_year=date('Y',time());
	return "All content copyright © ".($current_year>$params['created']?$params['created'].'-'.$current_year:$current_year)." {$params['company']}";
	}
?>

Enjoy!

03:32 PM | 2 Comments | Tags: , , , , ,