| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class HC3_Ui_Announce |
| 3 |
{ |
| 4 |
public $ui; |
| 5 |
|
| 6 |
public function __construct( HC3_Ui $ui ) |
| 7 |
{ |
| 8 |
$this->ui = $ui; |
| 9 |
} |
| 10 |
|
| 11 |
public function session() |
| 12 |
{ |
| 13 |
return HC3_Session::instance(); |
| 14 |
} |
| 15 |
|
| 16 |
public function render( $out ) |
| 17 |
{ |
| 18 |
$session = $this->session(); |
| 19 |
|
| 20 |
$message = $session->getFlashdata('message'); |
| 21 |
$error = $session->getFlashdata('error'); |
| 22 |
$debug = $session->getFlashdata('debug'); |
| 23 |
|
| 24 |
if( ! ( ($message OR strlen($message)) OR ($debug OR strlen($debug)) OR ($error OR strlen($error)) ) ){ |
| 25 |
return $out; |
| 26 |
} |
| 27 |
|
| 28 |
if( strlen($debug) ){ |
| 29 |
$debug = $this->ui->makeBlock( $debug ) |
| 30 |
->tag('padding', 2) |
| 31 |
->tag('margin', 'y2') |
| 32 |
->tag('border') |
| 33 |
// ->tag('auto-dismiss') |
| 34 |
->tag('rounded') |
| 35 |
->tag('border-color', 'orange') |
| 36 |
; |
| 37 |
$out = $this->ui->makeList( array($debug, $out) ); |
| 38 |
} |
| 39 |
|
| 40 |
if( $message OR strlen($message) OR strlen($debug) OR $error OR strlen($error) ){ |
| 41 |
if( is_array($message) ){ |
| 42 |
$message = $this->ui->makeList($message)->gutter(0); |
| 43 |
} |
| 44 |
if( $message ){ |
| 45 |
$message = $this->ui->makeBlock( $message ) |
| 46 |
->tag('padding', 2) |
| 47 |
->tag('margin', 'y2') |
| 48 |
->tag('auto-dismiss') |
| 49 |
->tag('rounded') |
| 50 |
|
| 51 |
->tag('bgcolor', 'lightgreen') |
| 52 |
->tag('muted', 1) |
| 53 |
|
| 54 |
->tag('border', 'olive') |
| 55 |
->tag('border-color', 'olive') |
| 56 |
->tag('color', 'black') |
| 57 |
; |
| 58 |
} |
| 59 |
|
| 60 |
if( is_array($error) ){ |
| 61 |
$error = $this->ui->makeList($error)->gutter(0); |
| 62 |
} |
| 63 |
if( $error ){ |
| 64 |
$error = $this->ui->makeBlock( $error ) |
| 65 |
->tag('padding', 2) |
| 66 |
->tag('margin', 'y2') |
| 67 |
->tag('auto-dismiss') |
| 68 |
->tag('rounded') |
| 69 |
|
| 70 |
->tag('bgcolor', 'lightred') |
| 71 |
->tag('muted', 1) |
| 72 |
|
| 73 |
->tag('border', 'maroon') |
| 74 |
->tag('border-color', 'maroon') |
| 75 |
->tag('color', 'black') |
| 76 |
; |
| 77 |
|
| 78 |
if( $message ){ |
| 79 |
$message = $this->ui->makeCollection( array($error, $message) ); |
| 80 |
$message = $this->ui->makeBlock( $message ); |
| 81 |
} |
| 82 |
else { |
| 83 |
$message = $error; |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
$message |
| 88 |
->addAttr('style', 'position: absolute; left: .5em; top: .5em; right: .5em; z-index: 1000;') |
| 89 |
; |
| 90 |
|
| 91 |
$out = $this->ui->makeList( array($message, $out) ); |
| 92 |
} |
| 93 |
|
| 94 |
return $out; |
| 95 |
} |
| 96 |
} |