Completed
Push — master ( 12d1e3...236763 )
by Patrick
03:09
created

class.FlipPage.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * A WebPage class specific to this framework
4
 *
5
 * This file describes an abstraction for creating a webpage with JQuery, Bootstrap,
6
 * and other framework specific abilities
7
 *
8
 * PHP version 5 and 7
9
 *
10
 * @author Patrick Boyd / [email protected]
11
 * @copyright Copyright (c) 2015, Austin Artistic Reconstruction
12
 * @license http://www.apache.org/licenses/ Apache 2.0 License
13
 */
14
15
/**
16
 * We use the FlipsideSettings class for a list of sites and settings
17
 * about CDNs and minified JS/CSS
18
 */
19
if(isset($GLOBALS['FLIPSIDE_SETTINGS_LOC']))
20
{
21
    require_once($GLOBALS['FLIPSIDE_SETTINGS_LOC'].'/class.FlipsideSettings.php');
22
}
23
else
24
{
25
    require_once('/var/www/secure_settings/class.FlipsideSettings.php');
26
}
27
28
/**
29
 * We need the parent class
30
 */
31
require_once('class.WebPage.php');
32
33
define('JS_JQUERY',       0);
34
define('JS_JQUERY_UI',    1);
35
define('JS_BOOTSTRAP',    2);
36
define('JQUERY_VALIDATE', 3);
37
define('JQUERY_TOUCH',    4);
38
define('JS_TINYNAV',      5);
39
define('JS_BOOTSTRAP_FH', 6);
40
define('JS_BOOTSTRAP_SW', 7);
41
define('JS_DATATABLE',    8);
42
define('JS_CHART',        9);
43
define('JS_METISMENU',    10);
44
define('JS_BOOTBOX',         11);
45
define('JS_DATATABLE_ODATA', 12);
46
define('JS_CRYPTO_MD5_JS',   13);
47
define('JS_JCROP',           14);
48
define('JS_TYPEAHEAD',       15);
49
define('JS_FLIPSIDE',     20);
50
define('JS_LOGIN',        21);
51
52
define('CSS_JQUERY_UI',    0);
53
define('CSS_BOOTSTRAP',    1);
54
define('CSS_BOOTSTRAP_FH', 2);
55
define('CSS_BOOTSTRAP_SW', 3);
56
define('CSS_DATATABLE',    4);
57
define('CSS_JCROP',        5);
58
define('CSS_FONTAWESOME',  6);
59
60
global $jsArray;
61
$jsArray = array(
62
     JS_JQUERY => array(
63
         'no' => array(
64
             'no'  => '/js/common/jquery.js',
65
             'min' => '/js/common/jquery.min.js'
66
         ),
67
         'cdn' => array(
68
             'no'  => '//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.js',
69
             'min' => '//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'
70
         )
71
     ),
72
     JS_JQUERY_UI => array(
73
         'no' => array(
74
             'no'  => '/js/common/jquery-ui.js',
75
             'min' => '/js/common/jquery-ui.min.js'
76
         ),
77
         'cdn' => array(
78
             'no'  => '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js',
79
             'min' => '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js'
80
         )
81
     ),
82
     JS_BOOTSTRAP => array(
83
         'no' => array(
84
             'no'  => '/js/common/bootstrap.js',
85
             'min' => '/js/common/bootstrap.min.js'
86
         ),
87
         'cdn' => array(
88
             'no'  => '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.js',
89
             'min' => '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js'
90
         )
91
     ),
92
     JQUERY_VALIDATE => array(
93
         'no' => array(
94
             'no'  => '/js/common/jquery.validate.js',
95
             'min' => '/js/common/jquery.validate.min.js'
96
         ),
97
         'cdn' => array(
98
             'no'  => '//ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.js',
99
             'min' => '//ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js'
100
         )
101
     ),
102
     JQUERY_TOUCH => array(
103
         'no' => array(
104
             'no'  => '/js/common/jquery.ui.touch-punch.min.js',
105
             'min' => '/js/common/jquery.ui.touch-punch.min.js'
106
         ),
107
         'cdn' => array(
108
             'no'  => '//cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js',
109
             'min' => '//cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js'
110
         )
111
     ),
112
     JS_TINYNAV => array(
113
         'no' => array(
114
             'no'  => '/js/common/tinynav.js',
115
             'min' => '/js/common/tinynav.min.js'
116
         ),
117
         'cdn' => array(
118
             'no'  => '//cdnjs.cloudflare.com/ajax/libs/TinyNav.js/1.2.0/tinynav.js',
119
             'min' => '//cdnjs.cloudflare.com/ajax/libs/TinyNav.js/1.2.0/tinynav.min.js'
120
         )
121
     ),
122
     JS_BOOTSTRAP_FH => array(
123
         'no' => array(
124
             'no'  => '/js/common/bootstrap-formhelpers.js',
125
             'min' => '/js/common/bootstrap-formhelpers.min.js'
126
         ),
127
         'cdn' => array(
128
             'no'  => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-formhelpers/2.3.0/js/bootstrap-formhelpers.js',
129
             'min' => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-formhelpers/2.3.0/js/bootstrap-formhelpers.min.js'
130
         )
131
     ),
132
     JS_BOOTSTRAP_SW => array(
133
         'no' => array(
134
             'no'  => '/js/common/bootstrap-switch.js',
135
             'min' => '/js/common/bootstrap-switch.min.js'
136
         ),
137
         'cdn' => array(
138
             'no'  => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/js/bootstrap-switch.js',
139
             'min' => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/js/bootstrap-switch.min.js'
140
         )
141
     ),
142
     JS_DATATABLE => array(
143
         'no' => array(
144
             'no'  => '/js/common/jquery.dataTables.js',
145
             'min' => '/js/common/jquery.dataTables.min.js'
146
         ),
147
         'cdn' => array(
148
             'no'  => '//cdn.datatables.net/1.10.7/js/jquery.dataTables.js',
149
             'min' => '//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js'
150
         )
151
     ),
152
     JS_CHART => array(
153
         'no' => array(
154
             'no'  => '/js/common/Chart.js',
155
             'min' => '/js/common/Chart.min.js'
156
         ),
157
         'cdn' => array(
158
             'no'  => '//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.js',
159
             'min' => '//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js'
160
         )
161
     ),
162
     JS_METISMENU => array(
163
         'no' => array(
164
             'no'  => '/js/common/metisMenu.js',
165
             'min' => '/js/common/metisMenu.min.js'
166
         ),
167
         'cdn' => array(
168
             'no'  => '//cdnjs.cloudflare.com/ajax/libs/metisMenu/2.0.2/metisMenu.js',
169
             'min' => '//cdnjs.cloudflare.com/ajax/libs/metisMenu/2.0.2/metisMenu.min.js'
170
         )
171
     ),
172
     JS_BOOTBOX => array(
173
         'no' => array(
174
             'no'  => '/js/common/bootbox.js',
175
             'min' => '/js/common/bootbox.min.js'
176
         ),
177
         'cdn' => array(
178
             'no'  => '//cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.3.0/bootbox.js',
179
             'min' => '//cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.3.0/bootbox.min.js'
180
         )
181
     ),
182
     JS_DATATABLE_ODATA => array(
183
         'no' => array(
184
             'no'  => '/js/common/jquery.dataTables.odata.js',
185
             'min' => '/js/common/jquery.dataTables.odata.js',
186
         ),
187
         'cdn' => array(
188
             'no'  => '/js/common/jquery.dataTables.odata.js',
189
             'min' => '/js/common/jquery.dataTables.odata.js',
190
         )
191
     ),
192
     JS_CRYPTO_MD5_JS => array(
193
         'no' => array(
194
             'no'  => '/js/common/md5.js',
195
             'min' => '/js/common/md5.js',
196
         ),
197
         'cdn' => array(
198
             'no'  => '//cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/md5.js',
199
             'min' => '//cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/md5.js',
200
         )
201
     ),
202
     JS_JCROP => array(
203
         'no' => array(
204
             'no'  => '/js/common/jquery.Jcrop.min.js',
205
             'min' => '/js/common/jquery.Jcrop.min.js'
206
         ),
207
         'cdn' => array(
208
             'no'  => '//cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js',
209
             'min' => '//cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js'
210
         )
211
     ),
212
     JS_TYPEAHEAD => array(
213
         'no' => array(
214
             'no'  => '/js/common/typeahead.bundle.js',
215
             'min' => '/js/common/typeahead.bundle.min.js'
216
         ),
217
         'cdn' => array(
218
             'no'  => '//cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.bundle.js',
219
             'min' => '//cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.bundle.min.js'
220
         )
221
     ),
222
     JS_FLIPSIDE => array(
223
         'no' => array(
224
             'no'  => '/js/common/flipside.js',
225
             'min' => '/js/common/flipside.min.js'
226
         ),
227
         'cdn' => array(
228
             'no'  => '/js/common/flipside.js',
229
             'min' => '/js/common/flipside.min.js'
230
         )
231
     ),
232
     JS_LOGIN => array(
233
         'no' => array(
234
             'no'  => '/js/common/login.js',
235
             'min' => '/js/common/login.min.js'
236
         ),
237
         'cdn' => array(
238
             'no'  => '/js/common/login.js',
239
             'min' => '/js/common/login.min.js'
240
         )
241
     )
242
);
243
244
global $cssArray;
245
$cssArray = array(
246
    CSS_JQUERY_UI => array(
247
        'no' => array(
248
             'no'  => '/css/common/jquery-ui.css',
249
             'min' => '/css/common/jquery-ui.min.css'
250
         ),
251
         'cdn' => array(
252
             'no'  => '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css',
253
             'min' => '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.min.css'
254
         )
255
    ),
256
    CSS_BOOTSTRAP => array(
257
         'no' => array(
258
             'no'  => '/css/common/bootstrap.css',
259
             'min' => '/css/common/bootstrap.min.css'
260
         ),
261
         'cdn' => array(
262
             'no'  => '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css',
263
             'min' => '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'
264
         )
265
    ),
266
    CSS_BOOTSTRAP_FH => array(
267
        'no' => array(
268
             'no'  => '/css/common/bootstrap-formhelpers.css',
269
             'min' => '/css/common/bootstrap-formhelpers.min.css'
270
         ),
271
         'cdn' => array(
272
             'no'  => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-formhelpers/2.3.0/css/bootstrap-formhelpers.css',
273
             'min' => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-formhelpers/2.3.0/css/bootstrap-formhelpers.min.css'
274
         )
275
    ),
276
    CSS_BOOTSTRAP_SW => array(
277
         'no' => array(
278
             'no'  => '/css/common/bootstrap-switch.css',
279
             'min' => '/css/common/bootstrap-switch.min.css'
280
         ),
281
         'cdn' => array(
282
             'no'  => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/css/bootstrap3/bootstrap-switch.css',
283
             'min' => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/css/bootstrap3/bootstrap-switch.min.css'
284
         )
285
    ),
286
    CSS_DATATABLE => array(
287
        'no' => array(
288
             'no'  => '/css/common/jquery.dataTables.css',
289
             'min' => '/css/common/jquery.dataTables.min.css'
290
         ),
291
         'cdn' => array(
292
             'no'  => '//cdn.datatables.net/1.10.7/css/jquery.dataTables.css',
293
             'min' => '//cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css'
294
         )
295
    ),
296
    CSS_JCROP => array(
297
        'no'  => array(
298
            'no'  => '/css/common/jquery.Jcrop.min.css',
299
            'min' => '/css/common/jquery.Jcrop.min.css'
300
        ),
301
        'cdn' => array(
302
            'no'  => '//cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css',
303
            'min' => '//cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css'
304
        ) 
305
    ),
306
    CSS_FONTAWESOME => array(
307
        'no'  => array(
308
            'no'  => '/css/common/font-awesome.min.css',
309
            'min' => '/css/common/font-awesome.min.css'
310
        ),
311
        'cdn' => array(
312
            'no'  => '//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css',
313
            'min' => '//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css'
314
        )
315
    )
316
);
317
318
/**
319
 * A framework specific webpage abstraction layer
320
 *
321
 * This class abstracts out some basic webpage creation with JQuery, Bootstrap, and other helpers
322
 */
323
class FlipPage extends WebPage
324
{
325
    /** The currently logged in user or null if no user is logged in */
326
    public $user;
327
    /** An array of links to put in the header */
328
    public $links;
329
    /** An array of notifications to draw on the page */
330
    public $notifications;
331
    /** Should we draw the header? */
332
    public $header;
333
    /** The login page URL */
334
    public $loginUrl;
335
    /** The logout page URL */
336
    public $logoutUrl;
337
    /** Should we use minified JS/CSS? */
338
    protected $minified = null;
339
    /** Should we use local JS/CSS or Content Delivery Networks? */
340
    protected $cdn = null;
341
    /** Draw the analytics scripts */
342
    protected $analytics = true;
343
344
    /**
345
     * Create a webpage with JQuery, Bootstrap, etc
346
     *
347
     * @param string $title The webpage title
348
     * @param boolean $header Draw the header bar?
349
     *
350
     * @SuppressWarnings("StaticAccess")
351
     */
352
    function __construct($title, $header=true)
353
    {
354
        parent::__construct($title);
355
        $this->setupVars();
356
        $this->add_js(JS_JQUERY, false);
357
        $this->add_js(JS_FLIPSIDE, false);
358
        $this->addBootstrap();
359
        $this->header = $header;
360
        $this->links = array();
361
        $this->notifications = array();
362
        $this->loginUrl = 'login.php';
363
        $this->logoutUrl = 'logout.php';
364
        if(isset(FlipsideSettings::$global))
365
        {
366
            if(isset(FlipsideSettings::$global['login_url']))
367
            {
368
                $this->loginUrl = FlipsideSettings::$global['login_url'];
369
            }
370
            if(isset(FlipsideSettings::$global['logout_url']))
371
            {
372
                $this->logoutUrl = FlipsideSettings::$global['logout_url'];
373
            }
374
        }
375
        $this->user = FlipSession::getUser();
376
        $this->addAllLinks();
377
    }
378
379
    /**
380
     * Get the external site links for this page 
381
     *
382
     */
383
    protected function getSites()
384
    {
385
        if(isset(FlipsideSettings::$sites))
386
        {
387
            return FlipsideSettings::$sites;
388
        }
389
        return array();
390
    }
391
392
    /**
393
     * Add the links to be used in the header
394
     *
395
     * @SuppressWarnings("Superglobals")
396
     *
397
     * @todo Consider pulling the about menu from the settings file or a DB
398
     */
399
    protected function addAllLinks()
400
    {
401
        if($this->user === false || $this->user === null)
402
        {
403
            if(isset($_SERVER['REQUEST_URI']) && strstr($_SERVER['REQUEST_URI'], 'logout.php') === false)
404
            {
405
                $this->addLink('Login', $this->loginUrl);
406
            }
407
        }
408
        else
409
        {
410
            $this->add_links();
411
            $this->addLink('Logout', $this->logoutUrl);
412
        }
413
        $about_menu = array(
414
            'Burning Flipside'=>'https://www.burningflipside.com/about/event',
415
            'AAR, LLC'=>'https://www.burningflipside.com/organization/aar',
416
            'Privacy Policy'=>'https://www.burningflipside.com/about/privacy'
417
        );
418
        $this->addLink('About', 'http://www.burningflipside.com/about', $about_menu);
419
    }
420
421
    /**
422
     * Setup minified and cdn class varibles from defaults or the settings file
423
     */
424
    private function setupVars()
425
    {
426
        if($this->minified !== null && $this->cdn !== null) return;
427
        $this->minified = 'min';
428
        $this->cdn      = 'cdn';
429
        if(isset(FlipsideSettings::$global))
430
        {
431
            if(isset(FlipsideSettings::$global['use_minified']) && !FlipsideSettings::$global['use_minified'])
432
            {
433
                $this->minified = 'no';
434
            }
435
            if(isset(FlipsideSettings::$global['use_cdn']) && !FlipsideSettings::$global['use_cdn'])
436
            {
437
                $this->cdn = 'no';
438
            }
439
        }
440
    }
441
442
    /**
443
     * Add a JavaScript file from its src URI
444
     *
445
     * @param string $src The webpath to the JavaScript file
446
     * @param boolean $async Can the JavaScript be loaded asynchronously?
447
     *
448
     * @deprecated 2.0.0 Please use addJSByURI() instead
449
     */
450
    function add_js_from_src($src, $async=true)
451
    {
452
        $this->addJSByURI($src, $async);
453
    }
454
455
    /**
456
     * Add a JavaScript file from its src URI
457
     *
458
     * @param string $uri The webpath to the JavaScript file
459
     * @param boolean $async Can the JavaScript be loaded asynchronously?
460
     */
461
    public function addJSByURI($uri, $async=true)
462
    {
463
        $attributes = array('src'=>$uri, 'type'=>'text/javascript');
464
        if($async === true)
465
        {
466
            $attributes['async'] = true;
467
        }
468
        $jsTag = $this->createOpenTag('script', $attributes);
469
        $closeTag = $this->createCloseTag('script');
470
        $this->addHeadTag($jsTag);
471
        $this->addHeadTag($closeTag);
472
    }
473
474
    /**
475
     * Add a Cascading Style Sheet file from its src URI
476
     *
477
     * @param string $src The webpath to the Cascading Style Sheet file
478
     * @param boolean $import Can the CSS be loaded asynchronously?
479
     *
480
     * @deprecated 2.0.0 Please use addCSSByURI() instead
481
     */
482
    function add_css_from_src($src, $import=false)
483
    {
484
        $this->addCSSByURI($src, $import);
485
    }
486
487
    /**
488
     * Add a Cascading Style Sheet file from its src URI
489
     *
490
     * @param string $src The webpath to the Cascading Style Sheet file
491
     * @param boolean $async Can the CSS be loaded asynchronously?
492
     */
493
    public function addCSSByURI($uri, $async=false)
494
    {
495
        $attributes = array('rel'=>'stylesheet', 'href'=>$uri, 'type'=>'text/css');
496
        if($async === true && $this->importSupport === true)
497
        {
498
            $attributes['rel'] = 'import';
499
        }
500
        $cssTag = $this->createOpenTag('link', $attributes, true);
501
        $this->addHeadTag($cssTag);
502
    }
503
504
    /**
505
     * Add a JavaScript file from a set of files known to the framework
506
     *
507
     * @param string $type the ID of the JS file
508
     * @param boolean $async Can the JS file be loaded asynchronously?
509
     *
510
     * @deprecated 2.0.0 Please use addWellKnownJS() instead
511
     */
512
    function addJS($type, $async=true)
513
    {
514
        $this->addWellKnownJS($type, $async);
515
    }
516
517
    function add_js($type, $async=true)
518
    {
519
        $this->addWellKnownJS($type, $async);
520
    }
521
522
    /**
523
     * Add a JavaScript file from a set of files known to the framework
524
     *
525
     * @param string $jsFileID the ID of the JS file
526
     * @param boolean $async Can the JS file be loaded asynchronously?
527
     */
528
    public function addWellKnownJS($jsFileID, $async=true)
529
    {
530
        global $jsArray;
531
        $this->setupVars();
532
        $src = $jsArray[$jsFileID][$this->cdn][$this->minified];
533
        $this->addJSByURI($src, $async);
534
    }
535
536
    /**
537
     * Add a CSS file from a set of files known to the framework
538
     *
539
     * @param string $type the ID of the CSS file
540
     * @param boolean $import Can the CSS file be loaded asynchronously?
541
     *
542
     * @deprecated 2.0.0 Please use addWellKnownCSS() instead
543
     */
544
    function add_css($type, $import=false)
545
    {
546
        $this->addWellKnownCSS($type, $import);
547
    }
548
549
    /**
550
     * Add a CSS file from a set of files known to the framework
551
     *
552
     * @param string $cssFileID the ID of the CSS file
553
     * @param boolean $async Can the CSS file be loaded asynchronously?
554
     */
555
    public function addWellKnownCSS($cssFileID, $async=true)
556
    {
557
        global $cssArray;
558
        $this->setupVars();
559
        $src = $cssArray[$cssFileID][$this->cdn][$this->minified];
560
        $this->addCSSByURI($src, $async);
561
    }
562
563
    /**
564
     * Add files needed by the Bootstrap framework
565
     */
566
    private function addBootstrap()
567
    {
568
        $this->add_js(JS_BOOTSTRAP, false);
569
        $this->addWellKnownCSS(CSS_BOOTSTRAP);
570
        $this->addWellKnownCSS(CSS_FONTAWESOME);
571
    }
572
573
    protected function getSiteLinksForHeader()
574
    {
575
        $sites = $this->getSites();
576
        $names = array_keys($sites);
577
        $ret = '';
578
        foreach($names as $name)
579
        {
580
            $ret.='<li>'.$this->createLink($name, $sites[$name]).'</li>';
581
        }
582
        return $ret;
583
    }
584
585
    protected function getHrefForDropdown(&$link)
586
    {
587
        if(isset($link['_']))
588
        {
589
            $ret = $link['_'];
590
            unset($link['_']);
591
            return $ret;
592
        }
593
        return '#';
594
    }
595
596
    protected function getDropdown($link, $name)
597
    {
598
        $ret = '<li class="dropdown">';
599
        $href = $this->getHrefForDropdown($link);
600
        $ret.= '<a href="'.$href.'" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">'.$name.' <span class="caret"></span></a>';
601
        $ret.='<ul class="dropdown-menu">';
602
        $subNames = array_keys($link);
603
        foreach($subNames as $subName)
604
        {
605
            $ret.=$this->getLinkByName($subName, $link);
606
        }
607
        $ret.='</ul></li>';
608
        return $ret;
609
    }
610
611
    protected function getLinkByName($name, $links)
612
    {
613
        if(is_array($links[$name]))
614
        {
615
            return $this->getDropdown($links[$name], $name);
616
        }
617
        if($links[$name] === false)
618
        {
619
            return '<li>'.$name.'</li>';
620
        }
621
        return '<li>'.$this->createLink($name, $links[$name]).'</li>';
622
    }
623
624
    protected function getLinksMenus()
625
    {
626
        $names = array_keys($this->links);
627
        $ret = '';
628
        foreach($names as $name)
629
        {
630
            $ret.=$this->getLinkByName($name, $this->links);
631
        }
632
        return $ret;
633
    }
634
635
    /**
636
     * Draw the header for the page
637
     */
638
    protected function addHeader()
639
    {
640
        $sites = $this->getSiteLinksForHeader();
641
        $links = $this->getLinksMenus();
642
        $header ='<nav class="navbar navbar-default navbar-fixed-top">
643
                      <div class="container-fluid">
644
                          <!-- Brand and toggle get grouped for better mobile display -->
645
                          <div class="navbar-header">
646
                          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse" aria-expanded="false">
647
                              <span class="sr-only">Toggle navigation</span>
648
                              <span class="icon-bar"></span>
649
                              <span class="icon-bar"></span>
650
                              <span class="icon-bar"></span>
651
                          </button>
652
                          <a class="navbar-brand" href="#">
653
                              <picture>
654
                                  <source srcset="/img/common/logo.svg" style="width: 30px; height:30px"/>
655
                                  <img alt="Burning Flipside" src="/img/common/logo.png" style="width: 30px; height:30px"/>
656
                              </picture>
657
                          </a>
658
                          </div>
659
                          <!-- Collect the nav links, forms, and other content for toggling -->
660
                          <div class="collapse navbar-collapse" id="navbar-collapse">
661
                              <ul id="site_nav" class="nav navbar-nav">
662
                              '.$sites.'
663
                              </ul>
664
                              <ul class="nav navbar-nav navbar-right">
665
                              '.$links.'
666
                              </ul>
667
                          </div>
668
                      </div>
669
                  </nav>';
670
        $this->body = $header.$this->body;
671
        $this->body_tags.='style="padding-top: 60px;"';
672
    }
673
674
    /** Notification that is green for success */
675
    const NOTIFICATION_SUCCESS = 'alert-success';
676
    /** Notification that is blue for infomrational messages */
677
    const NOTIFICATION_INFO    = 'alert-info';
678
    /** Notification that is yellow for warning */
679
    const NOTIFICATION_WARNING = 'alert-warning';
680
    /** Notification that is red for error */
681
    const NOTIFICATION_FAILED  = 'alert-danger';
682
683
    /**
684
     * Add a notification to the page
685
     *
686
     * @param string $msg The message to show in the notifcation
687
     * @param string $sev The severity of the notifcation
688
     * @param boolean $dismissible Can the user dismiss the notificaton?
689
     *
690
     * @deprecated 2.0.0 Use the addNotification function instead 
691
     */
692
    function add_notification($msg, $sev=self::NOTIFICATION_INFO, $dismissible=1)
693
    {
694
        $notice = array('msg'=>$msg, 'sev'=>$sev, 'dismissible'=>$dismissible);
695
        array_push($this->notifications, $notice);
696
    }
697
698
    /**
699
     * Add a notification to the page
700
     *
701
     * @param string $message The message to show in the notifcation
702
     * @param string $sevity The severity of the notifcation
703
     * @param boolean $dismissible Can the user dismiss the notificaton?
704
     *
705
     * @deprecated 2.0.0 Use the addNotification function instead
706
     */
707
    public function addNotification($message, $severity=self::NOTIFICATION_INFO, $dismissible=true)
708
    {
709
        array_push($this->notificatons, array('msg'=>$message, 'sev'=>$severity, 'dismissible'=>$dismissible)); 
0 ignored issues
show
The property notificatons does not seem to exist. Did you mean notifications?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
710
    }
711
712
    /**
713
     * Draw all notifications to the page
714
     */
715
    private function renderNotifications()
716
    {
717
        $count = count($this->notifications);
718
        if($count === 0)
719
        {
720
            return;
721
        }
722
        for($i = 0; $i < $count; $i++)
723
        {
724
            $class = 'alert '.$this->notifications[$i]['sev'];
725
            $button = '';
726
            if($this->notifications[$i]['dismissible'])
727
            {
728
                $class .= ' alert-dismissible';
729
                $button = '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
730
            }
731
            $prefix = '';
732
            switch($this->notifications[$i]['sev'])
733
            {
734
                case self::NOTIFICATION_INFO:
735
                    $prefix = '<strong>Notice:</strong> '; 
736
                    break;
737
                case self::NOTIFICATION_WARNING:
738
                    $prefix = '<strong>Warning!</strong> ';
739
                    break;
740
                case self::NOTIFICATION_FAILED:
741
                    $prefix = '<strong>Warning!</strong> ';
742
                    break;
743
            }
744
            $style = '';
745
            if($i+1 < count($this->notifications))
746
            {
747
                //Not the last notification, remove the end margin
748
                $style='style="margin: 0px;"';
749
            }
750
            $this->body = '
751
                <div class="'.$class.'" role="alert" '.$style.'>
752
                    '.$button.$prefix.$this->notifications[$i]['msg'].'
753
                </div>
754
            '.$this->body;
755
        }
756
    }
757
758
    /**
759
     * Add the no script block
760
     */
761
    private function addNoScript()
762
    {
763
        $this->body = '<noscript>
764
                <div class="alert alert-danger alert-dismissible" role="alert">
765
                    <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
766
                    <strong>Error!</strong> This site makes extensive use of JavaScript. Please enable JavaScript or this site will not function.
767
                </div>
768
            </noscript>'.$this->body;
769
    }
770
771
    /**
772
     * Add the analytics script block
773
     */
774
    private function addAnalyticsBlock()
775
    {
776
        if($this->analytics === false)
777
        {
778
            return;
779
        }
780
        $this->body = $this->body.'<script>
781
  (function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){
782
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
783
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
784
  })(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\');
785
786
  ga(\'create\', \'UA-64901342-1\', \'auto\');
787
  ga(\'send\', \'pageview\');
788
789
</script>';
790
    }
791
792
    /**
793
     * Draw the page
794
     *
795
     * @param boolean $header Draw the header
796
     * @param boolean $analytics Include analytics on the page
797
     */
798
    public function printPage($header=true)
799
    {
800
        $this->renderNotifications();
801
        $this->addNoScript();
802
        $this->addAnalyticsBlock();
803
        if($this->header || $header)
804
        {
805
            $this->addHeader();
806
        }
807
        parent::printPage();
808
    }
809
810
    /**
811
     * Add a link to the header
812
     *
813
     * @param string $name The name of the link
814
     * @param false|string $url The URL to link to
815
     * @param false|array $subment Any submenu items for the dropdown
816
     *
817
     * @deprecated 1.0.0 Use addLink instead
818
     */
819
    function add_link($name, $url=false, $submenu=false)
820
    {
821
        $this->addLink($name, $url, $submenu);
822
    }
823
824
    /**
825
     * Add a link to the header
826
     *
827
     * @param string $name The name of the link
828
     * @param false|string $url The URL to link to
829
     * @param false|array $subment Any submenu items for the dropdown
830
     */
831
    public function addLink($name, $url=false, $submenu=false)
832
    {
833
        if(is_array($submenu))
834
        {
835
            $submenu['_'] = $url;
836
            $this->links[$name] = $submenu;
837
        }
838
        else
839
        {
840
            $this->links[$name] = $url;
841
        }
842
    }
843
844
    /**
845
     * Add the login form to the page
846
     *
847
     * @SuppressWarnings("StaticAccess")
848
     */
849
    function add_login_form()
850
    {
851
        $auth = \AuthProvider::getInstance();
852
        $authLinks = $auth->getSupplementaryLinks();
853
        $authLinksStr = '';
854
        $count = count($authLinks);
855
        for($i = 0; $i < $count; $i++)
856
        {
857
            $authLinksStr .= $authLinks[$i];
858
        }
859
        if($count > 0)
860
        {
861
            $authLinksStr = 'Sign in with '.$authLinksStr;
862
        }
863
        $this->body .= '<div class="modal fade" role="dialog" id="login-dialog" title="Login" aria-hidden="true">
864
                            <div class="modal-dialog">
865
                                <div class="modal-content">
866
                                    <div class="modal-header">
867
                                        <button type="button" class="close" data-dismiss="modal">
868
                                            <span aria-hidden="true">&times;</span>
869
                                            <span class="sr-only">Close</span>
870
                                        </button>
871
                                        <h4 class="modal-title">Login</h4>
872
                                    </div>
873
                                    <div class="modal-body">
874
                                        <form id="login_dialog_form" role="form">
875
                                            <input class="form-control" type="text" name="username" placeholder="Username or Email" required autofocus/>
876
                                            <input class="form-control" type="password" name="password" placeholder="Password" required/>
877
                                            <input type="hidden" name="return" value="'.$this->currentUrl().'"/>
878
                                            <button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
879
                                        </form>
880
                                        '.$authLinksStr.'
881
                                    </div>
882
                                </div>
883
                            </div>
884
                        </div>';
885
    }
886
887
    /**
888
     * Add additional links
889
     */
890
    function add_links()
891
    {
892
    }
893
}
894
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
895
?>
896