12.include.cache.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * DESCRIPTION:
  4. * This snippet returns the current year
  5. * It is then styled with a chunk to output a copyright notice which you can adapt to fit your needs.
  6. * You can call this snippet with a startyear for your website.
  7. * If you use a start year it automatically changes when the year passes.
  8. * i.e. 2012 turns into 2012-2013
  9. *
  10. * PARAMETERS:
  11. * @ &startYear (string) optional. Default: Current Year
  12. * @ &separator (string) optional. Default: '-'
  13. * @ &static (bool) optional. Default: 0
  14. * @ &tpl (string) optional. Default: 'sc_chunk'
  15. *
  16. * PLACEHOLDERS:
  17. * @ [[+output]]
  18. *
  19. * The usage defines '2012' as the 'current' year purely for illustration purpose only.
  20. * This is obviously wrong in 2013 or up...
  21. *
  22. * USAGE:
  23. * // Outputs: "&copy; 2012 by [[+site_name]]"
  24. * [[SimpleCopyright]]
  25. *
  26. * // Outputs: "&copy; 2007-2012 by [[+site_name]]"
  27. * // After newyears eve it turns into 2012-2013 automatically
  28. * [[SimpleCopyright? &startYear=`2007`]]
  29. *
  30. * // Outputs: "&copy; 2004 by [[+site_name]]".
  31. * // Always use 'static' in conjunction with 'startYear'.
  32. * // If you use 'static' only it will ignore it's setting and resolve to the current year.
  33. * [[SimpleCopyright? &startYear=`2004` &static=`1`]]
  34. *
  35. * You can also set the separator just for fun...
  36. * It defaults to "-"
  37. *
  38. * This outputs "&copy; 2007/2012"
  39. * [[SimpleCopyright? &startYear=`2007` &separator=`/`]]
  40. *
  41. */
  42. // Get the current year
  43. $currentYear = date('Y');
  44. // Check for a starting year, separator, static & chunk
  45. $startYear = (string) $modx->getOption('startYear', $scriptProperties);
  46. $separator = (string) $modx->getOption('separator', $scriptProperties, '-');
  47. $static = (bool) $modx->getOption('static', $scriptProperties, 0);
  48. $tpl = (string) $modx->getOption('tpl', $scriptProperties, 'sc_chunk');
  49. if($static&&!empty($startYear)){
  50. // is static : can be the future too
  51. $construct = $startYear;
  52. } elseif(!empty($startYear)) {
  53. // is semi dynamic : set with a starting year that never exceeds the future
  54. $construct = ($startYear>=$currentYear ? $currentYear : $startYear.$separator.$currentYear);
  55. } else {
  56. // is dynamic : changes with each year
  57. $construct = $currentYear;
  58. }
  59. // Get a chunk to style the output & check if it exists...
  60. $chunk = $modx->getObject('modChunk',array(
  61. 'name' => $tpl
  62. ));
  63. if (!$chunk){
  64. // If no chunk is found return error & write to log
  65. $modx->log(xPDO::LOG_LEVEL_ERROR, 'No chunk found!');
  66. return 'No chunk found!';
  67. } else {
  68. $outputString = $modx->getChunk($tpl,array(
  69. 'output' => $construct
  70. ));
  71. }
  72. return $outputString;
  73. return;