| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php return '/*
- * DESCRIPTION:
- * This snippet returns the current year
- * It is then styled with a chunk to output a copyright notice which you can adapt to fit your needs.
- * You can call this snippet with a startyear for your website.
- * If you use a start year it automatically changes when the year passes.
- * i.e. 2012 turns into 2012-2013
- *
- * PARAMETERS:
- * @ &startYear (string) optional. Default: Current Year
- * @ &separator (string) optional. Default: \'-\'
- * @ &static (bool) optional. Default: 0
- * @ &tpl (string) optional. Default: \'sc_chunk\'
- *
- * PLACEHOLDERS:
- * @ [[+output]]
- *
- * The usage defines \'2012\' as the \'current\' year purely for illustration purpose only.
- * This is obviously wrong in 2013 or up...
- *
- * USAGE:
- * // Outputs: "© 2012 by [[+site_name]]"
- * [[SimpleCopyright]]
- *
- * // Outputs: "© 2007-2012 by [[+site_name]]"
- * // After newyears eve it turns into 2012-2013 automatically
- * [[SimpleCopyright? &startYear=`2007`]]
- *
- * // Outputs: "© 2004 by [[+site_name]]".
- * // Always use \'static\' in conjunction with \'startYear\'.
- * // If you use \'static\' only it will ignore it\'s setting and resolve to the current year.
- * [[SimpleCopyright? &startYear=`2004` &static=`1`]]
- *
- * You can also set the separator just for fun...
- * It defaults to "-"
- *
- * This outputs "© 2007/2012"
- * [[SimpleCopyright? &startYear=`2007` &separator=`/`]]
- *
- */
- // Get the current year
- $currentYear = date(\'Y\');
- // Check for a starting year, separator, static & chunk
- $startYear = (string) $modx->getOption(\'startYear\', $scriptProperties);
- $separator = (string) $modx->getOption(\'separator\', $scriptProperties, \'-\');
- $static = (bool) $modx->getOption(\'static\', $scriptProperties, 0);
- $tpl = (string) $modx->getOption(\'tpl\', $scriptProperties, \'sc_chunk\');
- if($static&&!empty($startYear)){
- // is static : can be the future too
- $construct = $startYear;
- } elseif(!empty($startYear)) {
- // is semi dynamic : set with a starting year that never exceeds the future
- $construct = ($startYear>=$currentYear ? $currentYear : $startYear.$separator.$currentYear);
- } else {
- // is dynamic : changes with each year
- $construct = $currentYear;
- }
- // Get a chunk to style the output & check if it exists...
- $chunk = $modx->getObject(\'modChunk\',array(
- \'name\' => $tpl
- ));
- if (!$chunk){
- // If no chunk is found return error & write to log
- $modx->log(xPDO::LOG_LEVEL_ERROR, \'No chunk found!\');
- return \'No chunk found!\';
- } else {
- $outputString = $modx->getChunk($tpl,array(
- \'output\' => $construct
- ));
- }
-
- return $outputString;
- return;
- ';
|