Changeset 3920:c0b5cb32a713 for inc/admin
- Timestamp:
- 11/08/18 12:48:36 (7 years ago)
- Branch:
- default
- Location:
- inc/admin
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/lib.dc.page.php
r3919 r3920 17 17 private static $loaded_css = []; 18 18 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"];25 19 26 20 private static function getCore() … … 260 254 261 255 // Display notices and errors 262 echo self::notices();256 echo $core->notices->getNotices(); 263 257 } 264 258 … … 266 260 { 267 261 $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(); 300 263 } 301 264 302 265 public static function addNotice($type, $message, $options = []) 303 266 { 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); 322 269 } 323 270 … … 335 282 { 336 283 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;350 284 } 351 285 … … 495 429 496 430 // Display notices and errors 497 echo self::notices();431 echo $core->notices->getNotices(); 498 432 } 499 433 … … 541 475 { 542 476 $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); 554 478 } 555 479 -
inc/admin/prepend.php
r3874 r3920 223 223 224 224 $core->favs = new dcFavorites($core); 225 $core->notices = new dcNotices($core); 225 226 226 227 # [] : Title, URL, small icon, large icon, permissions, id, class
Note: See TracChangeset
for help on using the changeset viewer.