Dotclear

Changeset 1138:11db80678704


Ignore:
Timestamp:
03/29/13 07:07:07 (12 years ago)
Author:
JcDenis
Branch:
twig
Message:

Add timestamp to messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.context.php

    r1128 r1138  
    2525     protected $protected_globals = array(); 
    2626     protected $memory = array(); 
     27     protected $timestamp_messages = true; 
    2728      
    2829     public function __construct($core) 
     
    171172     public function addMessageStatic($message) 
    172173     { 
    173           $this->protected_globals['messages']['static'][] = $message; 
     174          $this->protected_globals['messages']['static'][] = $this->timeStamp($message); 
    174175          return $this; 
    175176     } 
     
    184185     public function addMessagesList($title,$messages) 
    185186     { 
    186           $this->protected_globals['messages']['lists'][$title] = $messages; 
     187          $this->protected_globals['messages']['lists'][$title] = $this->timeStamp($messages); 
    187188          return $this; 
    188189     } 
     
    196197     public function setAlert($message) 
    197198     { 
    198           $this->protected_globals['messages']['alert'] = $message; 
     199          $this->protected_globals['messages']['alert'] = $this->timeStamp($message); 
    199200          return $this; 
    200201     } 
     
    208209     public function addError($error) 
    209210     { 
    210           $this->protected_globals['messages']['errors'][] = $error; 
     211          $this->protected_globals['messages']['errors'][] = $this->timeStamp($error); 
    211212          return $this; 
    212213     } 
     
    220221     { 
    221222          return !empty($this->protected_globals['messages']['errors']); 
     223     } 
     224      
     225     /** 
     226      * Set use of timestamp on messages 
     227      * 
     228      * @param boolean $add Add timestamp to messages 
     229      * @return object self 
     230      */ 
     231     public function setTimestamp($add=true) 
     232     { 
     233          $this->timestamp_messages; 
     234          return $this; 
     235     } 
     236      
     237     /** 
     238      * Prepend message with a timestamp 
     239      * 
     240      * @param string|array $message Message(s) 
     241      * @return string|array Timestamp message(s) 
     242      */ 
     243     public function timeStamp($message) 
     244     { 
     245          if (!$this->timestamp_messages) { 
     246               return $message; 
     247          } 
     248           
     249          $tz = @$this->core->auth->getInfo('user_tz'); 
     250          if (!$tz) { 
     251               $tz = $this->core->blog->settings->system->blog_timezone; 
     252          } 
     253          $dt = dt::str(__('%H:%M:%S:'),null,$tz); 
     254           
     255          if (!is_array($message)) { 
     256               return $dt.' '.$message; 
     257          } else { 
     258               foreach($message as $k => $v) 
     259               { 
     260                    $message[$k] = $dt.' '.$v; 
     261               } 
     262               return $message; 
     263          } 
    222264     } 
    223265      
Note: See TracChangeset for help on using the changeset viewer.

Sites map