These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * @title Misc (Miscellaneous Functions) File |
||
4 | * |
||
5 | * @author Pierre-Henry Soria <[email protected]> |
||
6 | * @copyright (c) 2015-2017, Pierre-Henry Soria. All Rights Reserved. |
||
7 | * @license GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory. |
||
8 | * @package PH7 / App / Include / Helpers |
||
9 | */ |
||
10 | |||
11 | namespace PH7; |
||
12 | |||
13 | defined('PH7') or exit('Restricted access'); |
||
14 | |||
15 | use PH7\Framework\Registry\Registry; |
||
16 | |||
17 | /** |
||
18 | * Display a basic HTML body page. |
||
19 | * Since it will display a dynamic page, |
||
20 | * it will also send headers to not cache the page |
||
21 | * |
||
22 | * @param string $sTitle Title of the page. |
||
23 | * @param string $sMsg Message to display to the page. |
||
24 | * @return string The HTML body. |
||
25 | */ |
||
26 | function html_body($sTitle, $sMsg) |
||
27 | { |
||
28 | // Send headers to not cache the page |
||
29 | header('Cache-Control: no-store, no-cache, must-revalidate'); |
||
30 | header('Expires: Thu, 01 Jan 1970 00:00:00 GMT'); |
||
31 | |||
32 | return '<!DOCTYPE html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><title>' . $sTitle . '</title><meta name="author" content="pH7CMS, Pierre-Henry Soria"><meta name="copyright" content="(c) 2012-2017, Pierre-Henry Soria. All Rights Reserved"><meta name="creator" content="pH7CMS, Pierre-Henry Soria"><meta name="designer" content="pH7CMS, Pierre-Henry Soria"><meta name="generator" content="pH7CMS"><style>body{background:#EFEFEF;color:#555;font:normal 12px Arial,Helvetica,sans-serif;margin:0;padding:0}.center{margin-left:auto;margin-right:auto;text-align:center;width:80%}.error,.warning{font-weight:bold;font-size:13px;color:red}.warning{text-transform:uppercase}.italic{font-style:italic}.underline{text-decoration:underline}a{color:#08c;outline-style:none;cursor:pointer}a:link,a:visited{text-decoration:none}a:hover,a:active{color:#F24C9E;text-decoration:underline}</style></head><body><div class="center">' . $sMsg . '</div></body></html>'; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Check Internet Connection. |
||
37 | * |
||
38 | * @return boolean Returns TRUE if the Internet connection is enabled, FALSE otherwise. |
||
39 | */ |
||
40 | function is_internet() |
||
41 | { |
||
42 | // Sometimes, hosts ban a domain name, so check with several random domain name in case this happened |
||
43 | $aRandomHosts = ['www.google.com', 'www.bing.com', 'www.yahoo.com', 'www.facebook.com', 'twitter.com']; |
||
44 | |||
45 | if (false === Registry::getInstance()->is_internet_needed) |
||
46 | return true; |
||
47 | |||
48 | // Use random domain from the array to avoid a loop (it's fine for this usage. At worst the user will have to reload twice the page) |
||
49 | return (bool) @fsockopen($aRandomHosts[mt_rand(0,4)], 80, $iErrno, $sErrStr, 5); |
||
50 | } |
||
51 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.