Dotclear


Ignore:
Timestamp:
11/08/18 12:48:36 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Move backend notices/messages system to a special admin class and try to address the old stacked notices bug (see #2237)

Location:
inc/admin
Files:
1 added
2 edited

Legend:

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

    r3919 r3920  
    1717    private static $loaded_css    = []; 
    1818    private static $xframe_loaded = false; 
    19     private static $N_TYPES       = [ 
    20         "success" => "success", 
    21         "warning" => "warning-msg", 
    22         "error"   => "error", 
    23         "message" => "message", 
    24         "static"  => "static-msg"]; 
    2519 
    2620    private static function getCore() 
     
    260254 
    261255        // Display notices and errors 
    262         echo self::notices(); 
     256        echo $core->notices->getNotices(); 
    263257    } 
    264258 
     
    266260    { 
    267261        $core = self::getCore(); 
    268         static $error_displayed = false; 
    269  
    270         $res = ''; 
    271  
    272         // return error messages if any 
    273         if ($core->error->flag() && !$error_displayed) { 
    274  
    275             # --BEHAVIOR-- adminPageNotificationError 
    276             $notice_error = $core->callBehavior('adminPageNotificationError', $core, $core->error); 
    277  
    278             if (isset($notice_error) && !empty($notice_error)) { 
    279                 $res .= $notice_error; 
    280             } else { 
    281                 $res .= '<div class="error"><p>' . 
    282                 '<strong>' . (count($core->error->getErrors()) > 1 ? __('Errors:') : __('Error:')) . '</strong>' . 
    283                 '</p>' . $core->error->toHTML() . '</div>'; 
    284             } 
    285             $error_displayed = true; 
    286         } 
    287  
    288         // return notices if any 
    289         if (isset($_SESSION['notifications'])) { 
    290             foreach ($_SESSION['notifications'] as $notification) { 
    291  
    292                 # --BEHAVIOR-- adminPageNotification 
    293                 $notice = $core->callBehavior('adminPageNotification', $core, $notification); 
    294  
    295                 $res .= (isset($notice) && !empty($notice) ? $notice : self::getNotification($notification)); 
    296             } 
    297             unset($_SESSION['notifications']); 
    298         } 
    299         return $res; 
     262        return $core->notices->getNotices(); 
    300263    } 
    301264 
    302265    public static function addNotice($type, $message, $options = []) 
    303266    { 
    304         if (isset(self::$N_TYPES[$type])) { 
    305             $class = self::$N_TYPES[$type]; 
    306         } else { 
    307             $class = $type; 
    308         } 
    309         if (isset($_SESSION['notifications']) && is_array($_SESSION['notifications'])) { 
    310             $notifications = $_SESSION['notifications']; 
    311         } else { 
    312             $notifications = []; 
    313         } 
    314  
    315         $n = array_merge($options, ['class' => $class, 'ts' => time(), 'text' => $message]); 
    316         if ($type != "static") { 
    317             $notifications[] = $n; 
    318         } else { 
    319             array_unshift($notifications, $n); 
    320         } 
    321         $_SESSION['notifications'] = $notifications; 
     267        $core = self::getCore(); 
     268        $core->notices->addNotice($type, $message, $options); 
    322269    } 
    323270 
     
    335282    { 
    336283        self::addNotice("error", $message, $options); 
    337     } 
    338  
    339     protected static function getNotification($n) 
    340     { 
    341         $core = self::getCore(); 
    342  
    343         $tag = (isset($n['divtag']) && $n['divtag']) ? 'div' : 'p'; 
    344         $ts  = ''; 
    345         if (!isset($n['with_ts']) || ($n['with_ts'] == true)) { 
    346             $ts = dt::str(__('[%H:%M:%S]'), $n['ts'], $core->auth->getInfo('user_tz')) . ' '; 
    347         } 
    348         $res = '<' . $tag . ' class="' . $n['class'] . '" role="alert">' . $ts . $n['text'] . '</' . $tag . '>'; 
    349         return $res; 
    350284    } 
    351285 
     
    495429 
    496430        // Display notices and errors 
    497         echo self::notices(); 
     431        echo $core->notices->getNotices(); 
    498432    } 
    499433 
     
    541475    { 
    542476        $core = self::getCore(); 
    543  
    544         $res = ''; 
    545         if ($msg != '') { 
    546             $res = ($div ? '<div class="' . $class . '">' : '') . '<p' . ($div ? '' : ' class="' . $class . '"') . '>' . 
    547                 ($timestamp ? dt::str(__('[%H:%M:%S]'), null, $core->auth->getInfo('user_tz')) . ' ' : '') . $msg . 
    548                 '</p>' . ($div ? '</div>' : ''); 
    549             if ($echo) { 
    550                 echo $res; 
    551             } 
    552         } 
    553         return $res; 
     477        return $core->notices->message($msg, $timestamp, $div, $echo, $class); 
    554478    } 
    555479 
  • inc/admin/prepend.php

    r3874 r3920  
    223223 
    224224    $core->favs = new dcFavorites($core); 
     225    $core->notices = new dcNotices($core); 
    225226 
    226227    # [] : Title, URL, small icon, large icon, permissions, id, class 
Note: See TracChangeset for help on using the changeset viewer.

Sites map