diff options
-rw-r--r-- | boot.php | 278 |
1 files changed, 116 insertions, 162 deletions
@@ -36,6 +36,9 @@ use Zotlabs\Daemon\Master; use Zotlabs\Lib\DB_Upgrade; use Zotlabs\Lib\Libzot; use Zotlabs\Lib\Config; +use Zotlabs\Render\SmartyTemplate; +use Zotlabs\Render\Theme; +use Zotlabs\Web\HttpMeta; require_once('vendor/autoload.php'); @@ -661,7 +664,6 @@ function sys_boot(): bool { App::$timezone = ((App::$config['system']['timezone']) ? App::$config['system']['timezone'] : 'UTC'); date_default_timezone_set(App::$timezone); - if (!defined('DEFAULT_PLATFORM_ICON')) { define('DEFAULT_PLATFORM_ICON', '/images/hz-32.png'); } @@ -903,28 +905,33 @@ class App { set_include_path( 'include' . PATH_SEPARATOR . 'library' . PATH_SEPARATOR - . 'library/langdet' . PATH_SEPARATOR . '.'); self::$scheme = 'http'; - if (x($_SERVER, 'HTTPS') && $_SERVER['HTTPS']) + + if (!empty($_SERVER['HTTPS'])) { self::$scheme = 'https'; - elseif (x($_SERVER, 'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) + } + elseif (!empty($_SERVER['SERVER_PORT']) && intval($_SERVER['SERVER_PORT']) == 443) { self::$scheme = 'https'; + } - if (x($_SERVER, 'SERVER_NAME')) { + if (!empty($_SERVER['SERVER_NAME'])) { self::$hostname = punify($_SERVER['SERVER_NAME']); - if (x($_SERVER, 'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) + if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) { self::$hostname .= ':' . $_SERVER['SERVER_PORT']; + } /* * Figure out if we are running at the top of a domain * or in a sub-directory and adjust accordingly */ $path = trim(dirname($_SERVER['SCRIPT_NAME']), '/\\'); - if (isset($path) && strlen($path) && ($path != self::$path)) + + if (isset($path) && strlen($path) && ($path != self::$path)) { self::$path = $path; + } } if (!empty($_SERVER['REQUEST_URI'])) { @@ -984,8 +991,9 @@ class App { // unix style "homedir" - if ((substr(self::$cmd, 0, 1) === '~') || (substr(self::$cmd, 0, 1) === '@')) + if (substr(self::$cmd, 0, 1) === '~' || substr(self::$cmd, 0, 1) === '@') { self::$cmd = 'channel/' . substr(self::$cmd, 1); + } /* * Break the URL path into C style argc/argv style arguments for our @@ -1005,7 +1013,7 @@ class App { self::$argv = explode('/', self::$cmd); self::$argc = count(self::$argv); - if ((array_key_exists('0', self::$argv)) && strlen(self::$argv[0])) { + if (array_key_exists('0', self::$argv) && strlen(self::$argv[0])) { if (strpos(self::$argv[0], '.')) { $_REQUEST['module_format'] = substr(self::$argv[0], strpos(self::$argv[0], '.') + 1); self::$argv[0] = substr(self::$argv[0], 0, strpos(self::$argv[0], '.')); @@ -1013,8 +1021,9 @@ class App { self::$module = str_replace(".", "_", self::$argv[0]); self::$module = str_replace("-", "_", self::$module); - if (strpos(self::$module, '_') === 0) + if (strpos(self::$module, '_') === 0) { self::$module = substr(self::$module, 1); + } } else { self::$argc = 1; @@ -1028,22 +1037,26 @@ class App { * pagination */ - self::$pager['page'] = ((x($_GET, 'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1); + self::$pager['page'] = ((!empty($_GET['page']) && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1); self::$pager['itemspage'] = 60; self::$pager['start'] = (self::$pager['page'] * self::$pager['itemspage']) - self::$pager['itemspage']; - if (self::$pager['start'] < 0) + + if (self::$pager['start'] < 0) { self::$pager['start'] = 0; + } + self::$pager['total'] = 0; /* * register template engines */ - self::$meta = new Zotlabs\Web\HttpMeta(); + self::$meta = new HttpMeta(); // create an instance of the smarty template engine so we can register it. - $smarty = new Zotlabs\Render\SmartyTemplate(); + $smarty = new SmartyTemplate(); + /// @todo validate if this is still the desired behavior self::register_template_engine(get_class($smarty)); @@ -1088,10 +1101,12 @@ class App { self::$scheme = $parsed['scheme']; self::$hostname = punify($parsed['host']); - if (x($parsed, 'port')) + if (!empty($parsed['port'])) { self::$hostname .= ':' . $parsed['port']; - if (x($parsed, 'path')) + } + if (!empty($parsed['path'])) { self::$path = trim($parsed['path'], '\\/'); + } } } @@ -1196,28 +1211,24 @@ class App { public static function build_pagehead() { - $user_scalable = ((local_channel()) ? get_pconfig(local_channel(), 'system', 'user_scalable') : 0); - if ($user_scalable === false) - $user_scalable = 0; + $user_scalable = ((local_channel()) ? get_pconfig(local_channel(), 'system', 'user_scalable', 0) : 0); - $preload_images = ((local_channel()) ? get_pconfig(local_channel(), 'system', 'preload_images') : 0); - if ($preload_images === false) - $preload_images = 0; + $preload_images = ((local_channel()) ? get_pconfig(local_channel(), 'system', 'preload_images', 0) : 0); $interval = ((local_channel()) ? get_pconfig(local_channel(), 'system', 'update_interval') : 80000); - if ($interval < 10000) + if ($interval < 10000) { $interval = 80000; - - $theme_color = ((local_channel()) ? get_pconfig(local_channel(), 'redbasic', 'nav_bg') : App::$theme_info['theme_color']); - if (!$theme_color) { - $theme_color = App::$theme_info['theme_color']; } - if (!isset(self::$page['title']) && isset(self::$config['system']['sitename'])) + $theme_color = ((local_channel()) ? get_pconfig(local_channel(), 'redbasic', 'nav_bg', App::$theme_info['theme_color']) : App::$theme_info['theme_color']); + + if (empty(self::$page['title']) && !empty(self::$config['system']['sitename'])) { self::$page['title'] = self::$config['system']['sitename']; + } - if (isset(self::$page['title'])) + if (!empty(self::$page['title'])) { $pagemeta = ['og:title' => self::$page['title']]; + } call_hooks('page_meta', $pagemeta); @@ -1376,11 +1387,11 @@ class App { public static function head_get_icon() { $icon = self::$data['pageicon']; - if (strpos($icon, '://') === false) { - $icon = z_root() . $icon; + if (str_contains($icon, '://')) { + return $icon; } - return $icon; + return z_root() . $icon; } } // End App class @@ -1433,21 +1444,6 @@ function system_unavailable() { } -function clean_urls() { - - // if(App::$config['system']['clean_urls']) - return true; - // return false; -} - -function z_path() { - $base = z_root(); - if (!clean_urls()) - $base .= '/?q='; - - return $base; -} - /** * @brief Returns the baseurl. * @@ -1459,19 +1455,6 @@ function z_root() { return App::get_baseurl(); } -/** - * @brief Return absolute URL for given $path. - * - * @param string $path - * - * @return string - */ -function absurl($path) { - if (strpos($path, '/') === 0) - return z_path() . $path; - - return $path; -} function os_mkdir($path, $mode = 0777, $recursive = false) { $oldumask = @umask(0); @@ -1524,10 +1507,11 @@ function is_ajax() { function check_config() { $saved = Config::Get('system', 'urlverify'); - if (!$saved) + if (!$saved) { Config::Set('system', 'urlverify', bin2hex(z_root())); + } - if (($saved) && ($saved != bin2hex(z_root()))) { + if ($saved && $saved !== bin2hex(z_root())) { // our URL changed. Do something. $oldurl = hex2bin($saved); @@ -1539,12 +1523,13 @@ function check_config() { $is_ip_addr = ((preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $host)) ? true : false); $was_ip_addr = ((preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $oldhost)) ? true : false); // only change the url to an ip address if it was already an ip and not a dns name - if ((!$is_ip_addr) || ($is_ip_addr && $was_ip_addr)) { + if (!$is_ip_addr || ($is_ip_addr && $was_ip_addr)) { fix_system_urls($oldurl, z_root()); Config::Set('system', 'urlverify', bin2hex(z_root())); } - else + else { logger('Attempt to change baseurl from a DNS name to an IP address was refused.'); + } } // This will actually set the url to the one stored in .htconfig, and ignore what @@ -1791,7 +1776,6 @@ function login($register = false, $form_id = 'main_login', $hiddens = false, $lo * @brief Used to end the current process, after saving session state. */ function killme() { - register_shutdown_function('shutdown'); exit; } @@ -1817,12 +1801,13 @@ function shutdown() { * @return int|bool account_id or false */ function get_account_id() { - - if (isset($_SESSION['account_id'])) + if (isset($_SESSION['account_id'])) { return intval($_SESSION['account_id']); + } - if (App::$account) + if (App::$account) { return intval(App::$account['account_id']); + } return false; } @@ -1841,8 +1826,9 @@ function get_account_id() { function local_channel() { if (session_id() && array_key_exists('authenticated', $_SESSION) && $_SESSION['authenticated'] - && array_key_exists('uid', $_SESSION) && intval($_SESSION['uid'])) + && array_key_exists('uid', $_SESSION) && intval($_SESSION['uid'])) { return intval($_SESSION['uid']); + } return false; } @@ -1862,8 +1848,9 @@ function local_channel() { function remote_channel() { if (session_id() && array_key_exists('authenticated', $_SESSION) && $_SESSION['authenticated'] - && array_key_exists('visitor_id', $_SESSION) && $_SESSION['visitor_id']) + && array_key_exists('visitor_id', $_SESSION) && $_SESSION['visitor_id']) { return $_SESSION['visitor_id']; + } return false; } @@ -1904,27 +1891,6 @@ function can_view_public_stream() { */ function notice($s) { -/* - - if (!session_id()) { - return; - } - - if (!isset($_SESSION['sysmsg'])) { - $_SESSION['sysmsg'] = []; - } - - // ignore duplicated error messages which haven't yet been displayed - - if (in_array($s, $_SESSION['sysmsg'])) { - return; - } - - if (App::$interactive) { - $_SESSION['sysmsg'][] = $s; - } -*/ - $hash = get_observer_hash(); $sse_id = false; @@ -1973,25 +1939,6 @@ function notice($s) { * @param string $s Text to display */ function info($s) { -/* - if (!session_id()) { - return; - } - - if (!isset($_SESSION['sysmsg_info'])) { - $_SESSION['sysmsg_info'] = []; - } - - // ignore duplicated error messages which haven't yet been displayed - - if (in_array($s, $_SESSION['sysmsg_info'])) { - return; - } - - if (App::$interactive) { - $_SESSION['sysmsg_info'][] = $s; - } -*/ $hash = get_observer_hash(); $sse_id = false; @@ -2078,7 +2025,7 @@ function proc_run() { return; if (count($args) && $args[0] === 'php') { - $args[0] = ((x(App::$config, 'system')) && (x(App::$config['system'], 'php_path')) && (strlen(App::$config['system']['php_path'])) ? App::$config['system']['php_path'] : 'php'); + $args[0] = ((!empty(App::$config['system']['php_path'])) ? App::$config['system']['php_path'] : 'php'); } $args = array_map('escapeshellarg', $args); @@ -2090,10 +2037,12 @@ function proc_run() { proc_close(proc_open($cmd, [], $foo)); } else { - if (Config::Get('system', 'use_proc_open')) + if (Config::Get('system', 'use_proc_open')) { proc_close(proc_open($cmdline . " &", [], $foo)); - else + } + else { exec($cmdline . ' > /dev/null &'); + } } } @@ -2118,15 +2067,17 @@ function is_windows() { * @return bool true if user is an admin */ function is_site_admin() { - - if (!session_id()) + if (!session_id()) { return false; + } - if (isset($_SESSION['delegate'])) + if (isset($_SESSION['delegate'])) { return false; + } - if (isset($_SESSION['authenticated']) && is_array(App::$account) && (App::$account['account_roles'] & ACCOUNT_ROLE_ADMIN)) + if (isset($_SESSION['authenticated']) && is_array(App::$account) && (App::$account['account_roles'] & ACCOUNT_ROLE_ADMIN)) { return true; + } return false; } @@ -2140,13 +2091,15 @@ function is_site_admin() { */ function is_developer() { - if (!session_id()) + if (!session_id()) { return false; + } - if ((intval($_SESSION['authenticated'])) - && (is_array(App::$account)) - && (App::$account['account_roles'] & ACCOUNT_ROLE_DEVELOPER)) + if (intval($_SESSION['authenticated']) + && is_array(App::$account) + && (App::$account['account_roles'] & ACCOUNT_ROLE_DEVELOPER)) { return true; + } return false; } @@ -2156,8 +2109,9 @@ function load_contact_links($uid) { $ret = []; - if (!$uid || x(App::$contacts, 'empty')) + if (!$uid || !empty(App::$contacts['empty'])) { return; + } // logger('load_contact_links'); @@ -2169,8 +2123,9 @@ function load_contact_links($uid) { $ret[$rv['xchan_hash']] = $rv; } } - else + else { $ret['empty'] = true; + } App::$contacts = $ret; } @@ -2218,8 +2173,9 @@ function argc() { } function argv($x) { - if (array_key_exists($x, App::$argv)) + if (array_key_exists($x, App::$argv)) { return App::$argv[$x]; + } return ''; } @@ -2237,8 +2193,9 @@ function dba_timer() { */ function get_observer_hash() { $observer = App::get_observer(); - if (is_array($observer)) + if (is_array($observer)) { return $observer['xchan_hash']; + } return ''; } @@ -2266,22 +2223,6 @@ function curPageURL() { return $pageURL; } -/** - * @brief Returns a custom navigation by name??? - * - * If no $navname provided load default page['nav'] - * - * @param string $navname - * - * @return mixed - * @todo not fully implemented yet - * - */ -function get_custom_nav($navname) { - if (!$navname) - return App::$page['nav']; - // load custom nav menu by name here -} /** * @brief Loads a page definition file for a module. @@ -2385,26 +2326,32 @@ function construct_page() { // logger('current_theme: ' . print_r($current_theme,true)); // Zotlabs\Render\Theme::debug(); - if (($p = theme_include($current_theme[0] . '.js')) != '') + if (($p = theme_include($current_theme[0] . '.js')) != '') { head_add_js('/' . $p); + } - if (($p = theme_include('mod_' . App::$module . '.php')) != '') + if (($p = theme_include('mod_' . App::$module . '.php')) != '') { require_once($p); + } require_once('include/js_strings.php'); - if (x(App::$page, 'template_style')) + if (!empty(App::$page['template_style'])) { head_add_css(App::$page['template_style'] . '.css'); - else - head_add_css(((x(App::$page, 'template')) ? App::$page['template'] : 'default') . '.css'); + } + else { + head_add_css(((!empty(App::$page['template'])) ? App::$page['template'] : 'default') . '.css'); + } - if (($p = theme_include('mod_' . App::$module . '.css')) != '') + if (($p = theme_include('mod_' . App::$module . '.css')) != '') { head_add_css('mod_' . App::$module . '.css'); + } - head_add_css(Zotlabs\Render\Theme::url()); + head_add_css(Theme::url()); - if (($p = theme_include('mod_' . App::$module . '.js')) != '') + if (($p = theme_include('mod_' . App::$module . '.js')) != '') { head_add_js('mod_' . App::$module . '.js'); + } App::build_pagehead(); @@ -2436,7 +2383,6 @@ function construct_page() { call_hooks('construct_page', $arr); App::$layout = $arr['layout']; - foreach (App::$layout as $k => $v) { if ((strpos($k, 'region_') === 0) && strlen($v)) { if (strpos($v, '$region_') !== false) { @@ -2471,8 +2417,9 @@ function construct_page() { // security headers - see https://securityheaders.io - if (App::get_scheme() === 'https' && isset(App::$config['system']['transport_security_header']) && intval(App::$config['system']['transport_security_header']) == 1) + if (App::get_scheme() === 'https' && isset(App::$config['system']['transport_security_header']) && intval(App::$config['system']['transport_security_header']) == 1) { header("Strict-Transport-Security: max-age=31536000"); + } if (isset(App::$config['system']['content_security_policy']) && intval(App::$config['system']['content_security_policy']) == 1) { $cspsettings = [ @@ -2524,7 +2471,7 @@ function construct_page() { } require_once(theme_include( - ((x(App::$page, 'template')) ? App::$page['template'] : 'default') . '.php') + ((!empty(App::$page['template'])) ? App::$page['template'] : 'default') . '.php') ); } @@ -2543,9 +2490,7 @@ function appdirpath() { * @param string $icon */ function head_set_icon($icon) { - App::$data['pageicon'] = $icon; - } /** @@ -2554,8 +2499,9 @@ function head_set_icon($icon) { * @return string */ function get_directory_realm() { - if ($x = Config::Get('system', 'directory_realm')) + if ($x = Config::Get('system', 'directory_realm')) { return $x; + } return DIRECTORY_REALM; } @@ -2573,8 +2519,9 @@ function get_directory_primary() { return z_root(); } - if ($x = Config::Get('system', 'directory_primary')) + if ($x = Config::Get('system', 'directory_primary')) { return $x; + } return DIRECTORY_FALLBACK_MASTER; } @@ -2593,18 +2540,22 @@ function get_poller_runtime() { function z_get_upload_dir() { $upload_dir = Config::Get('system', 'uploaddir'); - if (!$upload_dir) + if (!$upload_dir) { $upload_dir = ini_get('upload_tmp_dir'); - if (!$upload_dir) + } + + if (!$upload_dir) { $upload_dir = sys_get_temp_dir(); + } return $upload_dir; } function z_get_temp_dir() { $temp_dir = Config::Get('system', 'tempdir'); - if (!$temp_dir) + if (!$temp_dir) { $temp_dir = sys_get_temp_dir(); + } return $temp_dir; } @@ -2621,8 +2572,9 @@ function z_check_cert() { if (!$x['success']) { $recurse = 0; $y = z_fetch_url(z_root() . '/siteinfo.json', false, $recurse, ['novalidate' => true]); - if ($y['success']) + if ($y['success']) { cert_bad_email(); + } } } } @@ -2655,8 +2607,9 @@ function check_for_new_perms() { // Do not execute if we are in the middle of a git update and the relevant versions don't match - if (Permissions::version() != PermissionRoles::version()) + if (Permissions::version() != PermissionRoles::version()) { return; + } $pregistered = Config::Get('system', 'perms'); @@ -2719,8 +2672,9 @@ function check_for_new_perms() { } // We should probably call perms_refresh here, but this should get pushed in 24 hours and there is no urgency - if ($found_new_perm) + if ($found_new_perm) { Config::Set('system', 'perms', $pcurrent); + } } |