1<?php 2/** 3 * Date/time Command: Formats a date/time to a pre-configured format. 4 * 5 * For a full description of this Command Plugin command, see: 6 * http://www.splitbrain.org/plugin:date-time 7 * 8 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 9 * @author Joe Lapp <http://www.spiderjoe.com> 10 */ 11 12class CommandPluginExtension_dt extends CommandPluginExtension 13{ 14 function getCachedData($embedding, $params, $paramHash, $content, 15 &$errorMessage) // STATIC 16 { 17 global $conf; 18 19 // Determine the name of the configuration variable. 20 21 $configName = 'dtformat'; 22 if(sizeof($params) == 1 && is_string($params[0])) 23 $configName .= '_'.$params[0]; 24 else if(sizeof($params) != 0) 25 { 26 $errorMessage = "_INVALID_DT_PARAMETERS_"; 27 return null; // return value doesn't matter in this case 28 } 29 30 // Load the css class and the date format from the variable. 31 32 $cssClass = null; 33 $format = null; 34 35 $configVal = null; 36 $configVal = @$conf[$configName]; 37 38 if($configVal != null) 39 { 40 $barPos = strpos($configVal, '|'); 41 if($barPos === false) 42 $format = $configVal; 43 else 44 { 45 $cssClass = substr($configVal, 0, $barPos); 46 // next line works even if there is no format 47 $format = substr($configVal, $barPos + 1); 48 } 49 } 50 51 // Format the date/time. 52 53 if(!empty($format)) 54 { 55 if(trim($content) == '') 56 $newDT = date($format); 57 else 58 $newDT = date($format, strtotime($content)); 59 } 60 else 61 $newDT = $content; 62 63 $newDT = htmlspecialchars($newDT); 64 65 // Return the newly formatted date/time. 66 67 if($embedding == 'block') 68 { 69 if($cssClass) 70 return '<div class=\''.$cssClass.'\'>'.$newDT.'</div>'; 71 return '<div>'.$newDT.'</div>'; 72 } 73 else if($cssClass) 74 return '<span class=\''.$cssClass.'\'>'.$newDT.'</span>'; 75 return $newDT; 76 } 77} 78?>