Created
October 28, 2011 19:05
-
-
Save mariuswilms/1323139 to your computer and use it in GitHub Desktop.
Reusable Copyright Element for Lithium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Reusable Copyright Element for Lithium. | |
* | |
* Works without passing any options at all (except the `holder`), will make | |
* "smart" guesses. Allows customization by passing strings for `holder`, `object` | |
* or years for `begin` and `end`. | |
* | |
* Example Usage: | |
* ``` | |
* <?=$this->view()->render( | |
* array('element' => 'copyright'), | |
* array('holder' => 'James Brown') | |
* ); ?> | |
* ``` | |
* | |
* Example Output: | |
* ``` | |
* © 2011 James Brown. All rights reserved. | |
* ``` | |
* | |
* @copyright 2011 David Persson <[email protected]> | |
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | |
* @link https://gist.github.com/1323139 | |
*/ | |
extract(array( | |
'holder' => null, // i.e. `'James Brown'`; required. | |
'object' => null, // Additional copyright property to prepend; optional. | |
'begin' => null, // The beginning year i.e. 2009; optional. | |
'end' => null // The ending year i.e. 2011; optional. | |
), EXTR_SKIP); | |
$end = date('Y'); | |
if (!isset($begin) || $begin == $end) { | |
$years = $end; | |
} elseif ($end - $begin == 1) { | |
$years = "{$begin}, {$end}"; | |
} else { | |
$years = "{$begin} – {$end}"; | |
} | |
?> | |
<div class="copyright"> | |
<?php if (isset($object)): ?> | |
<?php echo sprintf('%1$s © %2$s %3$s.', ucfirst($object), $years, $holder) ?> | |
<?php else: ?> | |
<?php echo sprintf('© %1$s %2$s.', $years, $holder) ?> | |
<?php endif ?> | |
<?php echo 'All rights reserved.' ?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment