diff options
author | redmatrix <git@macgirvin.com> | 2016-06-19 19:12:33 -0700 |
---|---|---|
committer | redmatrix <git@macgirvin.com> | 2016-06-19 19:12:33 -0700 |
commit | fb61c4fb3497d3751bb43f12cadee9e9c7776be9 (patch) | |
tree | 604989e10424456783fccff1fccc5b14da26db7f /boot.php | |
parent | bfaabfb7b5ff639992a01b0e1fc374cd43d536e9 (diff) | |
parent | 4578649f758e65f1d87ebb98da7cd891d0b90d0d (diff) | |
download | volse-hubzilla-fb61c4fb3497d3751bb43f12cadee9e9c7776be9.tar.gz volse-hubzilla-fb61c4fb3497d3751bb43f12cadee9e9c7776be9.tar.bz2 volse-hubzilla-fb61c4fb3497d3751bb43f12cadee9e9c7776be9.zip |
Merge branch '1.8RC'
Diffstat (limited to 'boot.php')
-rwxr-xr-x | boot.php | 361 |
1 files changed, 191 insertions, 170 deletions
@@ -37,19 +37,18 @@ require_once('include/nav.php'); require_once('include/cache.php'); require_once('include/permissions.php'); require_once('library/Mobile_Detect/Mobile_Detect.php'); -require_once('include/BaseObject.php'); require_once('include/features.php'); require_once('include/taxonomy.php'); -require_once('include/identity.php'); -require_once('include/Contact.php'); +require_once('include/channel.php'); +require_once('include/connections.php'); require_once('include/account.php'); define ( 'PLATFORM_NAME', 'hubzilla' ); -define ( 'STD_VERSION', '1.6.6' ); -define ( 'ZOT_REVISION', 1 ); +define ( 'STD_VERSION', '1.8' ); +define ( 'ZOT_REVISION', 1.1 ); -define ( 'DB_UPDATE_VERSION', 1168 ); +define ( 'DB_UPDATE_VERSION', 1176 ); /** @@ -474,6 +473,7 @@ define ( 'NAMESPACE_YMEDIA', 'http://search.yahoo.com/mrss/' ); * activity stream defines */ +define ( 'ACTIVITY_REACT', NAMESPACE_ZOT . '/activity/react' ); define ( 'ACTIVITY_LIKE', NAMESPACE_ACTIVITY_SCHEMA . 'like' ); define ( 'ACTIVITY_DISLIKE', NAMESPACE_ZOT . '/activity/dislike' ); define ( 'ACTIVITY_AGREE', NAMESPACE_ZOT . '/activity/agree' ); @@ -514,6 +514,7 @@ define ( 'ACTIVITY_OBJ_ALBUM', NAMESPACE_ACTIVITY_SCHEMA . 'photo-album' ); define ( 'ACTIVITY_OBJ_EVENT', NAMESPACE_ACTIVITY_SCHEMA . 'event' ); define ( 'ACTIVITY_OBJ_GROUP', NAMESPACE_ACTIVITY_SCHEMA . 'group' ); define ( 'ACTIVITY_OBJ_GAME', NAMESPACE_ACTIVITY_SCHEMA . 'game' ); +define ( 'ACTIVITY_OBJ_WIKI', NAMESPACE_ACTIVITY_SCHEMA . 'wiki' ); define ( 'ACTIVITY_OBJ_TAGTERM', NAMESPACE_ZOT . '/activity/tagterm' ); define ( 'ACTIVITY_OBJ_PROFILE', NAMESPACE_ZOT . '/activity/profile' ); define ( 'ACTIVITY_OBJ_THING', NAMESPACE_ZOT . '/activity/thing' ); @@ -580,6 +581,72 @@ define ( 'ITEM_IS_STICKY', 1000 ); define ( 'DBTYPE_MYSQL', 0 ); define ( 'DBTYPE_POSTGRES', 1 ); + +function sys_boot() { + + // our central App object + + App::init(); + + /* + * Load the configuration file which contains our DB credentials. + * Ignore errors. If the file doesn't exist or is empty, we are running in + * installation mode. + */ + + // miniApp is a conversion object from old style .htconfig.php files + + $a = new miniApp; + + + App::$install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true); + + @include('.htconfig.php'); + + if(! defined('UNO')) + define('UNO', 0); + + if(array_key_exists('default_timezone',get_defined_vars())) { + App::$config['system']['timezone'] = $default_timezone; + } + + $a->convert(); + + App::$timezone = ((App::$config['system']['timezone']) ? App::$config['system']['timezone'] : 'UTC'); + date_default_timezone_set(App::$timezone); + + + /* + * Try to open the database; + */ + + require_once('include/dba/dba_driver.php'); + + if(! App::$install) { + DBA::dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type, App::$install); + if(! DBA::$dba->connected) { + system_unavailable(); + } + + unset($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type); + + /** + * Load configs from db. Overwrite configs from .htconfig.php + */ + + load_config('config'); + load_config('system'); + load_config('feature'); + + App::$session = new Zotlabs\Web\Session(); + App::$session->init(); + load_hooks(); + call_hooks('init_1'); + } + +} + + /** * * Reverse the effect of magic_quotes_gpc if it is enabled. @@ -626,12 +693,25 @@ function startup() { class ZotlabsAutoloader { static public function loader($className) { $filename = str_replace('\\', '/', $className) . ".php"; - if (file_exists($filename)) { + if(file_exists($filename)) { include($filename); if (class_exists($className)) { return TRUE; } } + $arr = explode('\\',$className); + if($arr && count($arr) > 1) { + if(! $arr[0]) + $arr = array_shift($arr); + $filename = 'addon/' . lcfirst($arr[0]) . '/' . $arr[1] . ((count($arr) === 2) ? '.php' : '/' . $arr[2] . ".php"); + if(file_exists($filename)) { + include($filename); + if (class_exists($className)) { + return TRUE; + } + } + } + return FALSE; } } @@ -687,6 +767,7 @@ class App { private static $perms = null; // observer permissions private static $widgets = array(); // widgets for this page + public static $session = null; public static $groups; public static $language; public static $langsave; @@ -703,6 +784,7 @@ class App { public static $content; public static $data = array(); public static $error = false; + public static $emojitab = false; public static $cmd; public static $argv; public static $argc; @@ -889,21 +971,27 @@ class App { self::head_set_icon('/images/hz-32.png'); - BaseObject::set_app($this); - /* * register template engines */ + + spl_autoload_register('ZotlabsAutoloader::loader'); + + self::$meta= new Zotlabs\Web\HttpMeta(); + + // create an instance of the smarty template engine so we can register it. + + $smarty = new Zotlabs\Render\SmartyTemplate(); + $dc = get_declared_classes(); + foreach ($dc as $k) { - if (in_array("ITemplateEngine", class_implements($k))){ + if(in_array('Zotlabs\\Render\\TemplateEngine', class_implements($k))) { self::register_template_engine($k); } } - spl_autoload_register('ZotlabsAutoloader::loader'); - self::$meta= new Zotlabs\Web\HttpMeta(); } @@ -1057,7 +1145,7 @@ class App { if(! self::$meta->get_field('og:title')) self::$meta->set('og:title',self::$page['title']); - self::$meta->set('generator', Zotlabs\Project\System::get_platform_name()); + self::$meta->set('generator', Zotlabs\Lib\System::get_platform_name()); /* put the head template at the beginning of page['htmlhead'] * since the code added by the modules frequently depends on it @@ -1072,7 +1160,7 @@ class App { '$local_channel' => local_channel(), '$metas' => self::$meta->get(), '$update_interval' => $interval, - 'osearch' => sprintf( t('Search %1$s (%2$s)','opensearch'), Zotlabs\Project\System::get_site_name(), t('$Projectname','opensearch')), + 'osearch' => sprintf( t('Search %1$s (%2$s)','opensearch'), Zotlabs\Lib\System::get_site_name(), t('$Projectname','opensearch')), '$icon' => head_get_icon(), '$head_css' => head_get_css(), '$head_js' => head_get_js(), @@ -1178,7 +1266,6 @@ class App { * @return App */ function get_app() { - global $a; return $a; } @@ -1228,7 +1315,6 @@ function system_unavailable() { function clean_urls() { - global $a; // if(App::$config['system']['clean_urls']) return true; @@ -1236,8 +1322,6 @@ function clean_urls() { } function z_path() { - global $a; - $base = z_root(); if(! clean_urls()) $base .= '/?q='; @@ -1253,7 +1337,6 @@ function z_path() { * @return string */ function z_root() { - global $a; return App::get_baseurl(); } @@ -1383,6 +1466,12 @@ function check_config(&$a) { @unlink($lockfile); //send the administrator an e-mail file_put_contents($lockfile, $x); + + $r = q("select account_language from account where account_email = '%s' limit 1", + dbesc(App::$config['system']['admin_email']) + ); + push_lang(($r) ? $r[0]['account_language'] : 'en'); + $email_tpl = get_intltext_template("update_fail_eml.tpl"); $email_msg = replace_macros($email_tpl, array( @@ -1400,6 +1489,7 @@ function check_config(&$a) { . 'Content-transfer-encoding: 8bit' ); //try the logger logger('CRITICAL: Update Failed: ' . $x); + pop_lang(); } else set_config('database','update_r' . $x, 'success'); @@ -1442,11 +1532,11 @@ function check_config(&$a) { if(count($installed)) { foreach($installed as $i) { - if(! in_array($i['name'], $plugins_arr)) { - unload_plugin($i['name']); + if(! in_array($i['aname'], $plugins_arr)) { + unload_plugin($i['aname']); } else { - $installed_arr[] = $i['name']; + $installed_arr[] = $i['aname']; } } } @@ -1556,7 +1646,7 @@ function fix_system_urls($oldurl, $newurl) { } } - proc_run('php', 'include/notifier.php', 'refresh_all', $c[0]['channel_id']); + Zotlabs\Daemon\Master::Summon(array('Notifier', 'refresh_all', $c[0]['channel_id'])); } } @@ -1585,7 +1675,6 @@ function fix_system_urls($oldurl, $newurl) { // returns the complete html for inserting into the page function login($register = false, $form_id = 'main-login', $hiddens=false) { - $a = get_app(); $o = ''; $reg = false; $reglink = get_config('system', 'register_link'); @@ -1655,9 +1744,13 @@ function goaway($s) { } function shutdown() { +<<<<<<< HEAD global $db; if(is_object($db) && $db->connected) $db->close(); +======= + +>>>>>>> 1.8RC } /** @@ -1691,7 +1784,9 @@ function get_account_id() { * @return int|bool channel_id or false */ function local_channel() { - if((x($_SESSION, 'authenticated')) && (x($_SESSION, 'uid'))) + if(session_id() + && array_key_exists('authenticated',$_SESSION) && $_SESSION['authenticated'] + && array_key_exists('uid',$_SESSION) && intval($_SESSION['uid'])) return intval($_SESSION['uid']); return false; @@ -1722,7 +1817,9 @@ function local_user() { * @return string|bool visitor_id or false */ function remote_channel() { - if((x($_SESSION, 'authenticated')) && (x($_SESSION, 'visitor_id'))) + if(session_id() + && array_key_exists('authenticated',$_SESSION) && $_SESSION['authenticated'] + && array_key_exists('visitor_id',$_SESSION) && $_SESSION['visitor_id']) return $_SESSION['visitor_id']; return false; @@ -1747,7 +1844,9 @@ function remote_user() { * @param string $s Text to display */ function notice($s) { - $a = get_app(); + if(! session_id()) + return; + if(! x($_SESSION, 'sysmsg')) $_SESSION['sysmsg'] = array(); // ignore duplicated error messages which haven't yet been displayed @@ -1771,8 +1870,10 @@ function notice($s) { * @param string $s Text to display */ function info($s) { - $a = get_app(); - if(! x($_SESSION, 'sysmsg_info')) $_SESSION['sysmsg_info'] = array(); + if(! session_id()) + return; + if(! x($_SESSION, 'sysmsg_info')) + $_SESSION['sysmsg_info'] = array(); if(App::$interactive) $_SESSION['sysmsg_info'][] = $s; } @@ -1800,42 +1901,45 @@ function get_max_import_size() { * * $cmd and string args are surrounded with "" */ -function proc_run($cmd){ - - $a = get_app(); +function proc_run(){ $args = func_get_args(); $newargs = array(); + if(! count($args)) return; - // expand any arrays - - foreach($args as $arg) { - if(is_array($arg)) { - foreach($arg as $n) { - $newargs[] = $n; - } - } - else - $newargs[] = $arg; - } - - $args = $newargs; + $args = flatten_array_recursive($args); $arr = array('args' => $args, 'run_cmd' => true); call_hooks('proc_run', $arr); + if(! $arr['run_cmd']) 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'); - for($x = 0; $x < count($args); $x++) - $args[$x] = escapeshellarg($args[$x]); + // redirect proc_run statements of legacy daemon processes to the newer Daemon Master object class + // We will keep this interface until everybody has transitioned. (2016-05-20) + + if(strstr($args[1],'include/')) { + // convert 'include/foo.php' to 'Foo' + $orig = substr(ucfirst(substr($args[1],8)),0,-4); + logger('proc_run_redirect: ' . $orig); + if(file_exists('Zotlabs/Daemon/' . $orig . '.php')) { + array_shift($args); // daemons are all run by php, pop it off the top of the array + $args[0] = $orig; // replace with the new daemon name + logger('Redirecting old proc_run interface: ' . print_r($args,true), LOGGER_DEBUG, LOG_DEBUG); + \Zotlabs\Daemon\Master::Summon($args); // summon the daemon + return; + } + } + + $args = array_map('escapeshellarg',$args); $cmdline = implode($args," "); if(is_windows()) { @@ -1855,110 +1959,15 @@ function proc_run($cmd){ * @brief Checks if we are running on M$ Windows. * * @return bool true if we run on M$ Windows + * + * It's possible you might be able to run on WAMP or XAMPP, and this + * has been accomplished, but is not officially supported. Good luck. + * */ function is_windows() { return ((strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false); } - -function current_theme(){ - $app_base_themes = array('redbasic'); - - $a = get_app(); - $page_theme = null; - - // Find the theme that belongs to the channel whose stuff we are looking at - - if(App::$profile_uid && App::$profile_uid != local_channel()) { - $r = q("select channel_theme from channel where channel_id = %d limit 1", - intval(App::$profile_uid) - ); - if($r) - $page_theme = $r[0]['channel_theme']; - } - - if(array_key_exists('theme', App::$layout) && App::$layout['theme']) - $page_theme = App::$layout['theme']; - - // Allow folks to over-rule channel themes and always use their own on their own site. - // The default is for channel themes to take precedence over your own on pages belonging - // to that channel. - - if($page_theme && local_channel() && App::$profile_uid && local_channel() != App::$profile_uid) { - if(get_pconfig(local_channel(),'system','always_my_theme')) - $page_theme = null; - } - - $is_mobile = App::$is_mobile || App::$is_tablet; - - $standard_system_theme = ((isset(App::$config['system']['theme'])) ? App::$config['system']['theme'] : ''); - $standard_theme_name = ((isset($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $standard_system_theme); - - if($is_mobile) { - if(isset($_SESSION['show_mobile']) && !$_SESSION['show_mobile']) { - $system_theme = $standard_system_theme; - $theme_name = $standard_theme_name; - } - else { - $system_theme = ((isset(App::$config['system']['mobile_theme'])) ? App::$config['system']['mobile_theme'] : ''); - $theme_name = ((isset($_SESSION) && x($_SESSION,'mobile_theme')) ? $_SESSION['mobile_theme'] : $system_theme); - - if($theme_name === '' || $theme_name === '---' ) { - // user has selected to have the mobile theme be the same as the normal one - $system_theme = $standard_system_theme; - $theme_name = $standard_theme_name; - } - } - } - else { - $system_theme = $standard_system_theme; - $theme_name = $standard_theme_name; - - if($page_theme) - $theme_name = $page_theme; - } - - if($theme_name && - (file_exists('view/theme/' . $theme_name . '/css/style.css') || - file_exists('view/theme/' . $theme_name . '/php/style.php'))) - return($theme_name); - - foreach($app_base_themes as $t) { - if(file_exists('view/theme/' . $t . '/css/style.css') || - file_exists('view/theme/' . $t . '/php/style.php')) - return($t); - } - - $fallback = array_merge(glob('view/theme/*/css/style.css'),glob('view/theme/*/php/style.php')); - if(count($fallback)) - return (str_replace('view/theme/','', substr($fallback[0],0,-10))); - -} - - -/** - * @brief Return full URL to theme which is currently in effect. - * - * Provide a sane default if nothing is chosen or the specified theme does not exist. - * - * @param bool $installing default false - * - * @return string - */ -function current_theme_url($installing = false) { - global $a; - - $t = current_theme(); - - $opts = ''; - $opts = ((App::$profile_uid) ? '?f=&puid=' . App::$profile_uid : ''); - $opts .= ((x(App::$layout,'schema')) ? '&schema=' . App::$layout['schema'] : ''); - if(file_exists('view/theme/' . $t . '/php/style.php')) - return('view/theme/' . $t . '/php/style.pcss' . $opts); - - return('view/theme/' . $t . '/css/style.css'); -} - /** * @brief Check if current user has admin role. * @@ -1966,8 +1975,11 @@ function current_theme_url($installing = false) { * * @return bool true if user is an admin */ + function is_site_admin() { - $a = get_app(); + + if(! session_id()) + return false; if($_SESSION['delegate']) return false; @@ -1988,7 +2000,10 @@ function is_site_admin() { * @return bool true if user is a developer */ function is_developer() { - $a = get_app(); + + if(! session_id()) + return false; + if((intval($_SESSION['authenticated'])) && (is_array(App::$account)) && (App::$account['account_roles'] & ACCOUNT_ROLE_DEVELOPER)) @@ -1999,7 +2014,6 @@ function is_developer() { function load_contact_links($uid) { - $a = get_app(); $ret = array(); @@ -2008,7 +2022,7 @@ function load_contact_links($uid) { // logger('load_contact_links'); - $r = q("SELECT abook_id, abook_flags, abook_my_perms, abook_their_perms, xchan_hash, xchan_photo_m, xchan_name, xchan_url from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d ", + $r = q("SELECT abook_id, abook_flags, abook_my_perms, abook_their_perms, xchan_hash, xchan_photo_m, xchan_name, xchan_url, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d ", intval($uid) ); if($r) { @@ -2031,6 +2045,7 @@ function load_contact_links($uid) { * * @return string */ + function build_querystring($params, $name = null) { $ret = ''; foreach($params as $key => $val) { @@ -2073,8 +2088,9 @@ function dba_timer() { /** * @brief Returns xchan_hash from the observer. * - * @return string Empty if no observer, otherwise xchan_hash from observer + * @return empty string if no observer, otherwise xchan_hash from observer */ + function get_observer_hash() { $observer = App::get_observer(); if(is_array($observer)) @@ -2131,8 +2147,6 @@ function load_pdl(&$a) { App::$comanche = new Zotlabs\Render\Comanche(); - // require_once('include/comanche.php'); - if (! count(App::$layout)) { $arr = array('module' => App::$module, 'layout' => ''); @@ -2153,13 +2167,10 @@ function load_pdl(&$a) { App::$pdl = $s; } } - } function exec_pdl(&$a) { -// require_once('include/comanche.php'); - if(App::$pdl) { App::$comanche->parse(App::$pdl,1); } @@ -2195,7 +2206,9 @@ function construct_page(&$a) { } } - if (($p = theme_include(current_theme() . '.js')) != '') + $current_theme = Zotlabs\Render\Theme::current(); + + if (($p = theme_include($current_theme[0] . '.js')) != '') head_add_js($p); if (($p = theme_include('mod_' . App::$module . '.php')) != '') @@ -2209,7 +2222,7 @@ function construct_page(&$a) { head_add_css(((x(App::$page, 'template')) ? App::$page['template'] : 'default' ) . '.css'); head_add_css('mod_' . App::$module . '.css'); - head_add_css(current_theme_url($installing)); + head_add_css(Zotlabs\Render\Theme::url($installing)); head_add_js('mod_' . App::$module . '.js'); @@ -2315,7 +2328,6 @@ function appdirpath() { * @param string $icon */ function head_set_icon($icon) { - global $a; App::$data['pageicon'] = $icon; // logger('head_set_icon: ' . $icon); @@ -2327,7 +2339,6 @@ function head_set_icon($icon) { * @return string absolut path to pageicon */ function head_get_icon() { - global $a; $icon = App::$data['pageicon']; if(! strpos($icon, '://')) @@ -2393,7 +2404,7 @@ function z_get_temp_dir() { } function z_check_cert() { - $a = get_app(); + if(strpos(z_root(),'https://') !== false) { $x = z_fetch_url(z_root() . '/siteinfo/json'); if(! $x['success']) { @@ -2414,8 +2425,6 @@ function z_check_cert() { */ function cert_bad_email() { - $a = get_app(); - $email_tpl = get_intltext_template("cert_bad_eml.tpl"); $email_msg = replace_macros($email_tpl, array( '$sitename' => App::$config['system']['sitename'], @@ -2436,26 +2445,30 @@ function cert_bad_email() { */ function check_cron_broken() { - $t = get_config('system','lastpollcheck'); + $d = get_config('system','lastcron'); + + if((! $d) || ($d < datetime_convert('UTC','UTC','now - 4 hours'))) { + Zotlabs\Daemon\Master::Summon(array('Cron')); + } + + $t = get_config('system','lastcroncheck'); if(! $t) { // never checked before. Start the timer. - set_config('system','lastpollcheck',datetime_convert()); + set_config('system','lastcroncheck',datetime_convert()); return; } + if($t > datetime_convert('UTC','UTC','now - 3 days')) { // Wait for 3 days before we do anything so as not to swamp the admin with messages return; } - $d = get_config('system','lastpoll'); if(($d) && ($d > datetime_convert('UTC','UTC','now - 3 days'))) { // Scheduled tasks have run successfully in the last 3 days. - set_config('system','lastpollcheck',datetime_convert()); + set_config('system','lastcroncheck',datetime_convert()); return; } - $a = get_app(); - $email_tpl = get_intltext_template("cron_bad_eml.tpl"); $email_msg = replace_macros($email_tpl, array( '$sitename' => App::$config['system']['sitename'], @@ -2469,8 +2482,16 @@ function check_cron_broken() { 'From: Administrator' . '@' . App::get_hostname() . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-transfer-encoding: 8bit' ); - set_config('system','lastpollcheck',datetime_convert()); return; } + +function observer_prohibited($allow_account = false) { + + if($allow_account) + return (((get_config('system','block_public')) && (! get_account_id()) && (! remote_channel())) ? true : false ); + return (((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) ? true : false ); + +} + |