Dotclear


Ignore:
Timestamp:
10/10/13 14:11:56 (12 years ago)
Author:
Dsls
Branch:
default
Message:

Display notifications chronologically, add options to methods (timestamp or not, div or p)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/lib.dc.page.php

    r2306 r2328  
    1717{ 
    1818     private static $loaded_js=array(); 
     19     private static $N_TYPES = array( 
     20          "success" => "success",  
     21          "warning" => "warning-msg",  
     22          "error" => "error",  
     23          "message" => "message",  
     24          "static" => "static-msg"); 
    1925 
    2026     # Auth check 
     
    186192          $res = ''; 
    187193          if (isset($_SESSION['notifications'])) { 
    188                $types = array("success" => "success", "warning" => "warning-msg", "error" => "error"); 
    189194               $notifications = $_SESSION['notifications']; 
    190                foreach ($types as $type => $class) { 
    191                     if (isset($notifications[$type])) { 
    192                          foreach ($notifications[$type] as $n) { 
    193                               $res .= self::getNotification($n,$class); 
    194                          } 
    195                     } 
     195               foreach ($_SESSION['notifications'] as $notification) { 
     196                    $res .= self::getNotification($notification); 
    196197               } 
    197198               unset($_SESSION['notifications']); 
     
    200201     } 
    201202 
    202      public static function addNotice($type,$message) 
    203      { 
    204           $notification = isset($_SESSION['notifications']) ? $_SESSION['notifications'] : array(); 
    205           $notification[$type][] = array('ts' => time(), 'text' => $message); 
    206           $_SESSION['notifications'] = $notification; 
    207      } 
    208  
    209      public static function addSuccessNotice($message) 
    210      { 
    211           self::addNotice("success",$message); 
    212      } 
    213  
    214      public static function addWarningNotice($message) 
    215      { 
    216           self::addNotice("warning",$message); 
    217      } 
    218  
    219      public static function addErrorNotice($message) 
    220      { 
    221           self::addNotice("error",$message); 
    222      } 
    223  
    224      protected static function getNotification($msg,$class) 
     203     public static function addNotice($type,$message,$options=array()) 
     204     { 
     205          if (isset(self::$N_TYPES[$type])){ 
     206               $class = self::$N_TYPES[$type]; 
     207          } else { 
     208               $class=$type; 
     209          } 
     210          if (isset($_SESSION['notifications']) && is_array($_SESSION['notifications'])) { 
     211               $notifications = $_SESSION['notifications']; 
     212          } else { 
     213               $notifications = array(); 
     214          } 
     215           
     216          $n = array_merge($options,array('class' => $class,'ts' => time(), 'text' => $message)); 
     217          if ($type != "static") { 
     218               $notifications[] = $n; 
     219          } else { 
     220               array_unshift($notifications, $n); 
     221          } 
     222          $_SESSION['notifications'] = $notifications; 
     223     } 
     224 
     225     public static function addSuccessNotice($message,$options=array()) 
     226     { 
     227          self::addNotice("success",$message,$options); 
     228     } 
     229 
     230     public static function addWarningNotice($message,$options=array()) 
     231     { 
     232          self::addNotice("warning",$message,$options); 
     233     } 
     234 
     235     public static function addErrorNotice($message,$options=array()) 
     236     { 
     237          self::addNotice("error",$message,$options); 
     238     } 
     239 
     240     protected static function getNotification($n) 
    225241     { 
    226242          global $core; 
    227  
    228           $res = '<p class="'.$class.'">'.dt::str(__('[%H:%M:%S]'),$msg['ts'],$core->auth->getInfo('user_tz')).' '.$msg['text'].'</p>'; 
     243          $tag = (isset($n['divtag'])&& $n['divtag'])?'div':'p'; 
     244          $ts = ''; 
     245          if (!isset($n['with_ts']) || ($n['with_ts'] == true)) { 
     246               $ts = dt::str(__('[%H:%M:%S]'),$n['ts'],$core->auth->getInfo('user_tz')).' '; 
     247          } 
     248          $res = '<'.$tag.' class="'.$n['class'].'">'.$ts.$n['text'].'</'.$tag.'>'; 
    229249          return $res; 
    230250     } 
Note: See TracChangeset for help on using the changeset viewer.

Sites map