Completed
Pull Request — develop (#17)
by Patrick
09:45
created

FlipPage::getSites()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Http\Html;
3
4
define('JS_JQUERY', 0);
5
define('JS_JQUERY_UI', 1);
6
define('JS_BOOTSTRAP', 2);
7
define('JQUERY_VALIDATE', 3);
8
define('JQUERY_TOUCH', 4);
9
define('JS_TINYNAV', 5);
10
define('JS_BOOTSTRAP_FH', 6);
11
define('JS_BOOTSTRAP_SW', 7);
12
define('JS_DATATABLE', 8);
13
define('JS_CHART', 9);
14
define('JS_METISMENU', 10);
15
define('JS_BOOTBOX', 11);
16
define('JS_DATATABLE_ODATA', 12);
17
define('JS_CRYPTO_MD5_JS', 13);
18
define('JS_JCROP', 14);
19
define('JS_TYPEAHEAD', 15);
20
define('JS_CHEET', 16);
21
define('JS_FLIPSIDE', 20);
22
define('JS_LOGIN', 21);
23
define('CSS_JQUERY_UI', 0);
24
define('CSS_BOOTSTRAP', 1);
25
define('CSS_BOOTSTRAP_FH', 2);
26
define('CSS_BOOTSTRAP_SW', 3);
27
define('CSS_DATATABLE', 4);
28
define('CSS_JCROP', 5);
29
define('CSS_FONTAWESOME', 6);
30
global $jsArray;
31
$jsArray = array(
32
        JS_JQUERY => array(
33
            'no' => array(
34
                'no'  => '/js/common/jquery.js',
35
                'min' => '/js/common/jquery.min.js'
36
            ),
37
            'cdn' => array(
38
                'no'  => '//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.js',
39
                'min' => '//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'
40
            )
41
        ),
42
        JS_JQUERY_UI => array(
43
            'no' => array(
44
                'no'  => '/js/common/jquery-ui.js',
45
                'min' => '/js/common/jquery-ui.min.js'
46
            ),
47
            'cdn' => array(
48
                'no'  => '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js',
49
                'min' => '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js'
50
            )
51
        ),
52
        JS_BOOTSTRAP => array(
53
            'no' => array(
54
                'no'  => '/js/common/bootstrap.js',
55
                'min' => '/js/common/bootstrap.min.js'
56
            ),
57
            'cdn' => array(
58
                'no'  => '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.js',
59
                'min' => '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js'
60
            )
61
        ),
62
        JQUERY_VALIDATE => array(
63
            'no' => array(
64
                'no'  => '/js/common/jquery.validate.js',
65
                'min' => '/js/common/jquery.validate.min.js'
66
            ),
67
            'cdn' => array(
68
                'no'  => '//ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.js',
69
                'min' => '//ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js'
70
            )
71
        ),
72
        JQUERY_TOUCH => array(
73
            'no' => array(
74
                'no'  => '/js/common/jquery.ui.touch-punch.min.js',
75
                'min' => '/js/common/jquery.ui.touch-punch.min.js'
76
            ),
77
            'cdn' => array(
78
                'no'  => '//cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js',
79
                'min' => '//cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js'
80
            )
81
        ),
82
        JS_TINYNAV => array(
83
            'no' => array(
84
                'no'  => '/js/common/tinynav.js',
85
                'min' => '/js/common/tinynav.min.js'
86
            ),
87
            'cdn' => array(
88
                'no'  => '//cdnjs.cloudflare.com/ajax/libs/TinyNav.js/1.2.0/tinynav.js',
89
                'min' => '//cdnjs.cloudflare.com/ajax/libs/TinyNav.js/1.2.0/tinynav.min.js'
90
            )
91
        ),
92
        JS_BOOTSTRAP_FH => array(
93
            'no' => array(
94
                'no'  => '/js/common/bootstrap-formhelpers.js',
95
                'min' => '/js/common/bootstrap-formhelpers.min.js'
96
            ),
97
            'cdn' => array(
98
                'no'  => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-formhelpers/2.3.0/js/bootstrap-formhelpers.js',
99
                'min' => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-formhelpers/2.3.0/js/bootstrap-formhelpers.min.js'
100
            )
101
        ),
102
        JS_BOOTSTRAP_SW => array(
103
            'no' => array(
104
                'no'  => '/js/common/bootstrap-switch.js',
105
                'min' => '/js/common/bootstrap-switch.min.js'
106
            ),
107
            'cdn' => array(
108
                'no'  => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/js/bootstrap-switch.js',
109
                'min' => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/js/bootstrap-switch.min.js'
110
            )
111
        ),
112
        JS_DATATABLE => array(
113
            'no' => array(
114
                'no'  => '/js/common/jquery.dataTables.js',
115
                'min' => '/js/common/jquery.dataTables.min.js'
116
            ),
117
            'cdn' => array(
118
                'no'  => '//cdn.datatables.net/1.10.7/js/jquery.dataTables.js',
119
                'min' => '//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js'
120
            )
121
        ),
122
        JS_CHART => array(
123
            'no' => array(
124
                'no'  => '/js/common/Chart.js',
125
                'min' => '/js/common/Chart.min.js'
126
            ),
127
            'cdn' => array(
128
                'no'  => '//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.js',
129
                'min' => '//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js'
130
            )
131
        ),
132
        JS_METISMENU => array(
133
            'no' => array(
134
                'no'  => '/js/common/metisMenu.js',
135
                'min' => '/js/common/metisMenu.min.js'
136
            ),
137
            'cdn' => array(
138
                'no'  => '//cdnjs.cloudflare.com/ajax/libs/metisMenu/2.0.2/metisMenu.js',
139
                'min' => '//cdnjs.cloudflare.com/ajax/libs/metisMenu/2.0.2/metisMenu.min.js'
140
            )
141
        ),
142
        JS_BOOTBOX => array(
143
            'no' => array(
144
                'no'  => '/js/common/bootbox.js',
145
                'min' => '/js/common/bootbox.min.js'
146
            ),
147
            'cdn' => array(
148
                'no'  => '//cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.3.0/bootbox.js',
149
                'min' => '//cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.3.0/bootbox.min.js'
150
            )
151
        ),
152
        JS_DATATABLE_ODATA => array(
153
            'no' => array(
154
                'no'  => '/js/common/jquery.dataTables.odata.js',
155
                'min' => '/js/common/jquery.dataTables.odata.js',
156
            ),
157
            'cdn' => array(
158
                'no'  => '/js/common/jquery.dataTables.odata.js',
159
                'min' => '/js/common/jquery.dataTables.odata.js',
160
            )
161
        ),
162
        JS_CRYPTO_MD5_JS => array(
163
            'no' => array(
164
                'no'  => '/js/common/md5.js',
165
                'min' => '/js/common/md5.js',
166
            ),
167
            'cdn' => array(
168
                'no'  => '//cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/md5.js',
169
                'min' => '//cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/md5.js',
170
            )
171
        ),
172
        JS_JCROP => array(
173
            'no' => array(
174
                'no'  => '/js/common/jquery.Jcrop.js',
175
                'min' => '/js/common/jquery.Jcrop.min.js'
176
            ),
177
            'cdn' => array(
178
                'no'  => '//cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.js',
179
                'min' => '//cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js'
180
            )
181
        ),
182
        JS_TYPEAHEAD => array(
183
            'no' => array(
184
                'no'  => '/js/common/typeahead.bundle.js',
185
                'min' => '/js/common/typeahead.bundle.min.js'
186
            ),
187
            'cdn' => array(
188
                'no'  => '//cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.bundle.js',
189
                'min' => '//cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.bundle.min.js'
190
            )
191
        ),
192
        JS_CHEET => array(
193
            'no' => array(
194
                'no'  => '/js/common/cheet.js',
195
                'min' => '/js/common/cheer.min.js'
196
            ),
197
            'cdn' => array(
198
                'no'  => '//cdn.rawgit.com/namuol/cheet.js/master/cheet.min.js',
199
                'min' => '//cdn.rawgit.com/namuol/cheet.js/master/cheet.min.js'
200
            )
201
        ),
202
        JS_FLIPSIDE => array(
203
            'no' => array(
204
                'no'  => '/js/common/flipside.js',
205
                'min' => '/js/common/flipside.min.js'
206
            ),
207
            'cdn' => array(
208
                'no'  => '/js/common/flipside.js',
209
                'min' => '/js/common/flipside.min.js'
210
            )
211
        ),
212
        JS_LOGIN => array(
213
            'no' => array(
214
                'no'  => '/js/common/login.js',
215
                'min' => '/js/common/login.min.js'
216
            ),
217
            'cdn' => array(
218
                'no'  => '/js/common/login.js',
219
                'min' => '/js/common/login.min.js'
220
            )
221
        )
222
);
223
global $cssArray;
224
$cssArray = array(
225
    CSS_JQUERY_UI => array(
226
        'no' => array(
227
                'no'  => '/css/common/jquery-ui.css',
228
                'min' => '/css/common/jquery-ui.min.css'
229
            ),
230
            'cdn' => array(
231
                'no'  => '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css',
232
                'min' => '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.min.css'
233
            )
234
    ),
235
    CSS_BOOTSTRAP => array(
236
            'no' => array(
237
                'no'  => '/css/common/bootstrap.css',
238
                'min' => '/css/common/bootstrap.min.css'
239
            ),
240
            'cdn' => array(
241
                'no'  => '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css',
242
                'min' => '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'
243
            )
244
    ),
245
    CSS_BOOTSTRAP_FH => array(
246
        'no' => array(
247
                'no'  => '/css/common/bootstrap-formhelpers.css',
248
                'min' => '/css/common/bootstrap-formhelpers.min.css'
249
            ),
250
            'cdn' => array(
251
                'no'  => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-formhelpers/2.3.0/css/bootstrap-formhelpers.css',
252
                'min' => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-formhelpers/2.3.0/css/bootstrap-formhelpers.min.css'
253
            )
254
    ),
255
    CSS_BOOTSTRAP_SW => array(
256
            'no' => array(
257
                'no'  => '/css/common/bootstrap-switch.css',
258
                'min' => '/css/common/bootstrap-switch.min.css'
259
            ),
260
            'cdn' => array(
261
                'no'  => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/css/bootstrap3/bootstrap-switch.css',
262
                'min' => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/css/bootstrap3/bootstrap-switch.min.css'
263
            )
264
    ),
265
    CSS_DATATABLE => array(
266
        'no' => array(
267
                'no'  => '/css/common/jquery.dataTables.css',
268
                'min' => '/css/common/jquery.dataTables.min.css'
269
            ),
270
            'cdn' => array(
271
                'no'  => '//cdn.datatables.net/1.10.7/css/jquery.dataTables.css',
272
                'min' => '//cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css'
273
            )
274
    ),
275
    CSS_JCROP => array(
276
        'no'  => array(
277
            'no'  => '/css/common/jquery.Jcrop.css',
278
            'min' => '/css/common/jquery.Jcrop.min.css'
279
        ),
280
        'cdn' => array(
281
            'no'  => '//cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/jquery.Jcrop.css',
282
            'min' => '//cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css'
283
        )
284
    ),
285
    CSS_FONTAWESOME => array(
286
        'no'  => array(
287
            'no'  => '/css/common/font-awesome.css',
288
            'min' => '/css/common/font-awesome.min.css'
289
        ),
290
        'cdn' => array(
291
            'no'  => '//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.css',
292
            'min' => '//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css'
293
        )
294
    )
295
);
296
297
/**
298
 * A framework specific webpage abstraction layer
299
 *
300
 * This class abstracts out some basic webpage creation with JQuery, Bootstrap, and other helpers
301
 */
302
class FlipPage extends WebPage
303
{
304
    /** The currently logged in user or null if no user is logged in */
305
    public $user;
306
    /** An array of links to put in the header */
307
    public $links;
308
    /** An array of notifications to draw on the page */
309
    public $notifications;
310
    /** Should we draw the header? */
311
    public $header;
312
    /** The login page URL */
313
    public $loginUrl;
314
    /** The logout page URL */
315
    public $logoutUrl;
316
    /** Should we use minified JS/CSS? */
317
    protected $minified = null;
318
    /** Should we use local JS/CSS or Content Delivery Networks? */
319
    protected $cdn = null;
320
    /** Draw the analytics scripts */
321
    protected $analytics = true;
322
    /** An instance of the Settings class */
323
    protected $settings;
324
325
    public $wwwUrl;
326
    public $wikiUrl;
327
    public $profilesUrl;
328
    public $secureUrl;
329
330
    /**
331
     * Create a webpage with JQuery, Bootstrap, etc
332
     *
333
     * @param string $title The webpage title
334
     *
335
     * @SuppressWarnings("StaticAccess")
336
     */
337 View Code Duplication
    public function __construct($title = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
338
    {
339
        $this->settings = \Settings::getInstance();
340
        parent::__construct($title);
341
        $this->setupVars();
342
        $this->addWellKnownJS(JS_JQUERY, false);
343
        $this->addWellKnownJS(JS_FLIPSIDE, false);
344
        $this->addBootstrap();
345
        $this->links = array();
346
        $this->notifications = array();
347
        $this->wwwUrl = $this->settings->getGlobalSetting('www_url', 'https://www.burningflipside.com');
348
        $this->wikiUrl = $this->settings->getGlobalSetting('wiki_url', 'https://wiki.burningflipside.com');
349
        $this->aboutUrl = $this->settings->getGlobalSetting('about_url', $this->wwwUrl.'/about');
0 ignored issues
show
Bug introduced by
The property aboutUrl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
350
        $this->aboutMenu = $this->settings->getGlobalSetting('about_menu', array(
0 ignored issues
show
Bug introduced by
The property aboutMenu does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
351
            'Burning Flipside' => $this->wwwUrl.'/about/event',
352
            'AAR, LLC' => $this->wwwUrl.'/organization/aar',
353
            'Privacy Policy' => $this->wwwUrl.'/about/privacy'
354
        ));
355
        $this->profilesUrl = $this->settings->getGlobalSetting('profiles_url', 'https://profiles.burningflipside.com/');
356
        $this->loginUrl = $this->settings->getGlobalSetting('login_url', $this->profilesUrl.'/login.php');
357
        $this->logoutUrl = $this->settings->getGlobalSetting('logout_url', $this->profilesUrl.'/logout.php');
358
        $this->registerUrl = $this->settings->getGlobalSetting('register_url', $this->profilesUrl.'/register.php');
0 ignored issues
show
Bug introduced by
The property registerUrl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
359
        $this->resetUrl = $this->settings->getGlobalSetting('reset_url', $this->profilesUrl.'/reset.php');
0 ignored issues
show
Bug introduced by
The property resetUrl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
360
        $this->secureUrl = $this->settings->getGlobalSetting('secure_url', 'https://secure.burningflipside.com/');
361
        $this->user = \FlipSession::getUser();
362
        $this->addAllLinks();
363
    }
364
365
    /**
366
     * Draw the page
367
     *
368
     * @param boolean $header Draw the header
0 ignored issues
show
Bug introduced by
There is no parameter named $header. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
369
     */
370
    public function printPage($response)
371
    {
372
        $this->renderNotifications();
373
        $this->addNoScript();
374
        $this->addAnalyticsBlock();
375
        $this->addJSGlobals();
376
        $this->addHeader();
377
        return parent::printPage($response);
378
    }
379
380
    /**
381
     * Get the external site links for this page
382
     *
383
     */
384
    protected function getSites()
385
    {
386
        return $this->settings->getSiteLinks();
387
    }
388
389
    /**
390
     * Add the links to be used in the header
391
     */
392 View Code Duplication
    protected function addAllLinks()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
393
    {
394
        if($this->user === false || $this->user === null)
395
        {
396
            if(isset($_SERVER['REQUEST_URI']) && strstr($_SERVER['REQUEST_URI'], 'logout.php') === false)
397
            {
398
                $this->addLink('Login', $this->loginUrl);
399
            }
400
        }
401
        else
402
        {
403
            $this->add_links();
404
            $this->addLink('Logout', $this->logoutUrl);
405
        }
406
        if($this->aboutUrl !== false)
407
        {
408
            if(!empty($this->aboutMenu))
409
            {
410
                $this->addLink('About', $this->aboutUrl, $this->aboutMenu);
411
            }
412
            else
413
            {
414
                $this->addLink('About', $this->aboutUrl);
415
            }
416
        }
417
    }
418
419
    /**
420
     * Setup minified and cdn class varibles from defaults or the settings file
421
     */
422 View Code Duplication
    private function setupVars()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
423
    {
424
        if($this->minified !== null && $this->cdn !== null)
425
        {
426
            return;
427
        }
428
        $this->minified = 'min';
429
        $this->cdn      = 'cdn';
430
        if($this->settings->getGlobalSetting('use_minified', true) == false)
431
        {
432
            $this->minified = 'no';
433
        }
434
        if($this->settings->getGlobalSetting('use_cdn', true) == false)
435
        {
436
            $this->cdn = 'no';
437
        }
438
    }
439
    /**
440
     * Add a JavaScript file from its src URI
441
     *
442
     * @param string $uri The webpath to the JavaScript file
443
     * @param boolean $async Can the JavaScript be loaded asynchronously?
444
     */
445 View Code Duplication
    public function addJSByURI($uri, $async = true)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
446
    {
447
        $attributes = array('src'=>$uri, 'type'=>'text/javascript');
448
        if($async === true)
449
        {
450
            $attributes['async'] = true;
451
        }
452
        $jsTag = $this->createOpenTag('script', $attributes);
453
        $closeTag = $this->createCloseTag('script');
454
        $this->addHeadTag($jsTag);
455
        $this->addHeadTag($closeTag);
456
    }
457
458
    /**
459
     * Add a Cascading Style Sheet file from its src URI
460
     *
461
     * @param string $uri The webpath to the Cascading Style Sheet file
462
     * @param boolean $async Can the CSS be loaded asynchronously?
463
     */
464 View Code Duplication
    public function addCSSByURI($uri, $async = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
465
    {
466
        $attributes = array('rel'=>'stylesheet', 'href'=>$uri, 'type'=>'text/css');
467
        if($async === true && $this->importSupport === true)
0 ignored issues
show
Bug introduced by
The property importSupport does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
468
        {
469
            $attributes['rel'] = 'import';
470
        }
471
        $cssTag = $this->createOpenTag('link', $attributes, true);
472
        $this->addHeadTag($cssTag);
473
    }
474
    /**
475
     * Add a JavaScript file from a set of files known to the framework
476
     *
477
     * @param string $jsFileID the ID of the JS file
478
     * @param boolean $async Can the JS file be loaded asynchronously?
479
     */
480 View Code Duplication
    public function addWellKnownJS($jsFileID, $async = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
481
    {
482
        global $jsArray;
483
        $this->setupVars();
484
        $src = $jsArray[$jsFileID][$this->cdn][$this->minified];
485
        $this->addJSByURI($src, $async);
486
    }
487
    /**
488
     * Add a CSS file from a set of files known to the framework
489
     *
490
     * @param string $cssFileID the ID of the CSS file
491
     * @param boolean $async Can the CSS file be loaded asynchronously?
492
     */
493 View Code Duplication
    public function addWellKnownCSS($cssFileID, $async = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
494
    {
495
        global $cssArray;
496
        $this->setupVars();
497
        $src = $cssArray[$cssFileID][$this->cdn][$this->minified];
498
        $this->addCSSByURI($src, $async);
499
    }
500
501
    /**
502
     * Add files needed by the Bootstrap framework
503
     */
504
    private function addBootstrap()
505
    {
506
        $this->addWellKnownJS(JS_BOOTSTRAP);
507
        $this->addWellKnownCSS(CSS_BOOTSTRAP);
508
        $this->addWellKnownCSS(CSS_FONTAWESOME);
509
    }
510 View Code Duplication
    protected function getSiteLinksForHeader()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
511
    {
512
        $sites = $this->getSites();
513
        $names = array_keys($sites);
514
        $ret = '';
515
        foreach($names as $name)
516
        {
517
            $ret .= '<li>'.$this->createLink($name, $sites[$name]).'</li>';
518
        }
519
        return $ret;
520
    }
521
    /**
522
     * Get the link for the HREF
523
     *
524
     * @return string The HREF for the dropdown
525
     */
526 View Code Duplication
    protected function getHrefForDropdown(&$link)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
527
    {
528
        if(isset($link['_']))
529
        {
530
            $ret = $link['_'];
531
            unset($link['_']);
532
            return $ret;
533
        }
534
        return '#';
535
    }
536
537 View Code Duplication
    protected function getDropdown($link, $name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
538
    {
539
        $ret = '<li class="dropdown">';
540
        $href = $this->getHrefForDropdown($link);
541
        $ret .= '<a href="'.$href.'" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">'.$name.' <span class="caret"></span></a>';
542
        $ret .= '<ul class="dropdown-menu">';
543
        $subNames = array_keys($link);
544
        foreach($subNames as $subName)
545
        {
546
            $ret .= $this->getLinkByName($subName, $link);
547
        }
548
        $ret .= '</ul></li>';
549
        return $ret;
550
    }
551 View Code Duplication
    protected function getLinkByName($name, $links)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
552
    {
553
        if(is_array($links[$name]))
554
        {
555
            return $this->getDropdown($links[$name], $name);
556
        }
557
        if($links[$name] === false)
558
        {
559
            return '<li>'.$name.'</li>';
560
        }
561
        return '<li>'.$this->createLink($name, $links[$name]).'</li>';
562
    }
563 View Code Duplication
    protected function getLinksMenus()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
564
    {
565
        $names = array_keys($this->links);
566
        $ret = '';
567
        foreach($names as $name)
568
        {
569
            $ret .= $this->getLinkByName($name, $this->links);
570
        }
571
        return $ret;
572
    }
573
574
    /**
575
     * Draw the header for the page
576
     */
577 View Code Duplication
    protected function addHeader()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
578
    {
579
        $sites = $this->getSiteLinksForHeader();
580
        $links = $this->getLinksMenus();
581
        $header = '<nav class="navbar navbar-default navbar-fixed-top">
582
                      <div class="container-fluid">
583
                          <!-- Brand and toggle get grouped for better mobile display -->
584
                          <div class="navbar-header">
585
                          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse" aria-expanded="false">
586
                              <span class="sr-only">Toggle navigation</span>
587
                              <span class="icon-bar"></span>
588
                              <span class="icon-bar"></span>
589
                              <span class="icon-bar"></span>
590
                          </button>
591
                          <a class="navbar-brand" href="#">
592
                              <picture>
593
                                  <source srcset="/img/common/logo.svg" style="width: 30px; height:30px"/>
594
                                  <img alt="Burning Flipside" src="/img/common/logo.png" style="width: 30px; height:30px"/>
595
                              </picture>
596
                          </a>
597
                          </div>
598
                          <!-- Collect the nav links, forms, and other content for toggling -->
599
                          <div class="collapse navbar-collapse" id="navbar-collapse">
600
                              <ul id="site_nav" class="nav navbar-nav">
601
                              '.$sites.'
602
                              </ul>
603
                              <ul class="nav navbar-nav navbar-right">
604
                              '.$links.'
605
                              </ul>
606
                          </div>
607
                      </div>
608
                  </nav>';
609
        $this->body = $header.$this->body;
610
        $this->body_tags .= 'style="padding-top: 60px;"';
611
    }
612
613
    /** Notification that is green for success */
614
    const NOTIFICATION_SUCCESS = 'alert-success';
615
    /** Notification that is blue for infomrational messages */
616
    const NOTIFICATION_INFO    = 'alert-info';
617
    /** Notification that is yellow for warning */
618
    const NOTIFICATION_WARNING = 'alert-warning';
619
    /** Notification that is red for error */
620
    const NOTIFICATION_FAILED  = 'alert-danger';
621
    /**
622
     * Add a notification to the page
623
     *
624
     * @param string $message The message to show in the notifcation
625
     * @param string $severity The severity of the notifcation
626
     * @param boolean $dismissible Can the user dismiss the notificaton?
627
     */
628
    public function addNotification($message, $severity = self::NOTIFICATION_INFO, $dismissible = true)
629
    {
630
        array_push($this->notifications, array('msg'=>$message, 'sev'=>$severity, 'dismissible'=>$dismissible));
631
    }
632
633
    /**
634
     * Draw all notifications to the page
635
     */
636 View Code Duplication
    private function renderNotifications()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
637
    {
638
        $count = count($this->notifications);
639
        if($count === 0)
640
        {
641
            return;
642
        }
643
        for($i = 0; $i < $count; $i++)
644
        {
645
            $class = 'alert '.$this->notifications[$i]['sev'];
646
            $button = '';
647
            if($this->notifications[$i]['dismissible'])
648
            {
649
                $class .= ' alert-dismissible';
650
                $button = '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
651
            }
652
            $prefix = '';
653
            switch($this->notifications[$i]['sev'])
654
            {
655
                case self::NOTIFICATION_INFO:
656
                    $prefix = '<strong>Notice:</strong> ';
657
                    break;
658
                case self::NOTIFICATION_WARNING:
659
                    $prefix = '<strong>Warning!</strong> ';
660
                    break;
661
                case self::NOTIFICATION_FAILED:
662
                    $prefix = '<strong>Warning!</strong> ';
663
                    break;
664
            }
665
            $style = '';
666
            if(($i + 1) < count($this->notifications))
667
            {
668
                //Not the last notification, remove the end margin
669
                $style = 'style="margin: 0px;"';
670
            }
671
            $this->body = '
672
                <div class="'.$class.'" role="alert" '.$style.'>
673
                    '.$button.$prefix.$this->notifications[$i]['msg'].'
674
                </div>
675
            '.$this->body;
676
        }
677
    }
678
679
    /**
680
     * Add the no script block
681
     */
682
    private function addNoScript()
683
    {
684
        $this->body = '<noscript>
685
                <div class="alert alert-danger alert-dismissible" role="alert">
686
                    <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
687
                    <strong>Error!</strong> This site makes extensive use of JavaScript. Please enable JavaScript or this site will not function.
688
                </div>
689
            </noscript>'.$this->body;
690
    }
691
692
    /**
693
     * Add the analytics script block
694
     */
695
    private function addAnalyticsBlock()
696
    {
697
        if($this->analytics === false)
698
        {
699
            return;
700
        }
701
        $this->body = $this->body.'<script>
702
  (function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){
703
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
704
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
705
  })(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\');
706
  ga(\'create\', \'UA-64901342-1\', \'auto\');
707
  ga(\'send\', \'pageview\');
708
</script>';
709
    }
710
    /**
711
     * Add some global js vars
712
     */
713 View Code Duplication
    private function addJSGlobals()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
714
    {
715
      $this->body = $this->body.'<script>
716
var profilesUrl = \''.$this->profilesUrl.'\'
717
var loginUrl = \''.$this->loginUrl.'\'
718
var logoutUrl = \''.$this->logoutUrl.'\'
719
</script>';
720
    }
721
722
    /**
723
     * Add a link to the header
724
     *
725
     * @param string $name The name of the link
726
     * @param boolean|string $url The URL to link to
727
     * @param boolean|array $submenu Any submenu items for the dropdown
728
     */
729 View Code Duplication
    public function addLink($name, $url = false, $submenu = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
730
    {
731
        if(is_array($submenu))
732
        {
733
            $submenu['_'] = $url;
734
            $this->links[$name] = $submenu;
735
            return;
736
        }
737
        $this->links[$name] = $url;
738
    }
739
740
    /**
741
     * Add the login form to the page
742
     *
743
     * @SuppressWarnings("StaticAccess")
744
     */
745 View Code Duplication
    public function add_login_form()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
746
    {
747
        $auth = \AuthProvider::getInstance();
748
        $authLinks = $auth->getSupplementaryLinks();
749
        $authLinksStr = '';
750
        $count = count($authLinks);
751
        for($i = 0; $i < $count; $i++)
752
        {
753
            $authLinksStr .= $authLinks[$i];
754
        }
755
        if($count > 0)
756
        {
757
            $authLinksStr = 'Sign in with '.$authLinksStr;
758
        }
759
        $this->body .= '<div class="modal fade" role="dialog" id="login-dialog" title="Login" aria-hidden="true">
760
                            <div class="modal-dialog">
761
                                <div class="modal-content">
762
                                    <div class="modal-header">
763
                                        <button type="button" class="close" data-dismiss="modal">
764
                                            <span aria-hidden="true">&times;</span>
765
                                            <span class="sr-only">Close</span>
766
                                        </button>
767
                                        <h4 class="modal-title">Login</h4>
768
                                    </div>
769
                                    <div class="modal-body">
770
                                        <form id="login_dialog_form" role="form">
771
                                            <input class="form-control" type="text" name="username" placeholder="Username or Email" required autofocus/>
772
                                            <input class="form-control" type="password" name="password" placeholder="Password" required/>
773
                                            <input type="hidden" name="return" value="'.$this->currentUrl().'"/>
0 ignored issues
show
Bug introduced by
The method currentUrl() does not exist on Http\Html\FlipPage. Did you maybe mean getCurrentUrl()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
774
                                            <button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
775
                                        </form>
776
                                        '.$authLinksStr.'
777
                                    </div>
778
                                </div>
779
                            </div>
780
                        </div>';
781
    }
782
    /**
783
     * Add additional links
784
     */
785
    public function add_links()
786
    {
787
    }
788
}
789