if (!$a->error && function_exists($a->module . '_content')) { $arr = array('content' => $a->page['content']); call_hooks($a->module . '_mod_content', $arr); $a->page['content'] = $arr['content']; $func = $a->module . '_content'; $arr = array('content' => $func($a)); call_hooks($a->module . '_mod_aftercontent', $arr); $a->page['content'] .= $arr['content']; } } // If you're just visiting, let javascript take you home if (x($_SESSION, 'visitor_home')) { $homebase = $_SESSION['visitor_home']; } elseif (local_channel()) { $homebase = $a->get_baseurl() . '/channel/' . $a->channel['channel_address']; } if (isset($homebase)) { $a->page['content'] .= '<script>var homebase = "' . $homebase . '";</script>'; } // now that we've been through the module content, see if the page reported // a permission problem and if so, a 403 response would seem to be in order. if (stristr(implode("", $_SESSION['sysmsg']), t('Permission denied'))) { header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.')); } call_hooks('page_end', $a->page['content']); if (!$a->install) { check_cron_broken(); } construct_page($a); session_write_close(); exit;
function check_config(&$a) { $build = get_config('system', 'db_version'); if (!intval($build)) { $build = set_config('system', 'db_version', DB_UPDATE_VERSION); } $saved = get_config('system', 'urlverify'); if (!$saved) { set_config('system', 'urlverify', bin2hex(z_root())); } if ($saved && $saved != bin2hex(z_root())) { // our URL changed. Do something. $oldurl = hex2bin($saved); logger('Baseurl changed!'); $oldhost = substr($oldurl, strpos($oldurl, '//') + 2); $host = substr(z_root(), strpos(z_root(), '//') + 2); $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) { fix_system_urls($oldurl, z_root()); set_config('system', 'urlverify', bin2hex(z_root())); } 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 // we're passing - unless we are installing and it has never been set. App::set_baseurl(z_root()); // Make sure each site has a system channel. This is now created on install // so we just need to keep this around a couple of weeks until the hubs that // already exist have one $syschan_exists = get_sys_channel(); if (!$syschan_exists) { create_sys_channel(); } if ($build != DB_UPDATE_VERSION) { $stored = intval($build); if (!$stored) { logger('Critical: check_config unable to determine database schema version'); return; } $current = intval(DB_UPDATE_VERSION); if ($stored < $current && file_exists('install/update.php')) { load_config('database'); // We're reporting a different version than what is currently installed. // Run any existing update scripts to bring the database up to current. require_once 'install/update.php'; // make sure that boot.php and update.php are the same release, we might be // updating right this very second and the correct version of the update.php // file may not be here yet. This can happen on a very busy site. if (DB_UPDATE_VERSION == UPDATE_VERSION) { for ($x = $stored; $x < $current; $x++) { if (function_exists('update_r' . $x)) { // There could be a lot of processes running or about to run. // We want exactly one process to run the update command. // So store the fact that we're taking responsibility // after first checking to see if somebody else already has. // If the update fails or times-out completely you may need to // delete the config entry to try again. if (get_config('database', 'update_r' . $x)) { break; } set_config('database', 'update_r' . $x, '1'); // call the specific update $func = 'update_r' . $x; $retval = $func(); if ($retval) { // Prevent sending hundreds of thousands of emails by creating // a lockfile. $lockfile = 'store/[data]/mailsent'; if (file_exists($lockfile) && filemtime($lockfile) > time() - 86400) { return; } @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('$sitename' => App::$config['system']['sitename'], '$siteurl' => z_root(), '$update' => $x, '$error' => sprintf(t('Update %s failed. See error logs.'), $x))); $subject = email_header_encode(sprintf(t('Update Error at %s'), z_root())); mail(App::$config['system']['admin_email'], $subject, $email_msg, 'From: Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-transfer-encoding: 8bit'); //try the logger logger('CRITICAL: Update Failed: ' . $x); pop_lang(); } else { set_config('database', 'update_r' . $x, 'success'); } } } set_config('system', 'db_version', DB_UPDATE_VERSION); } } } /** * * Synchronise plugins: * * App::$config['system']['addon'] contains a comma-separated list of names * of plugins/addons which are used on this system. * Go through the database list of already installed addons, and if we have * an entry, but it isn't in the config list, call the unload procedure * and mark it uninstalled in the database (for now we'll remove it). * Then go through the config list and if we have a plugin that isn't installed, * call the install procedure and add it to the database. * */ $r = q("SELECT * FROM addon WHERE installed = 1"); if ($r) { $installed = $r; } else { $installed = array(); } $plugins = get_config('system', 'addon'); $plugins_arr = array(); if ($plugins) { $plugins_arr = explode(',', str_replace(' ', '', $plugins)); } App::$plugins = $plugins_arr; $installed_arr = array(); if (count($installed)) { foreach ($installed as $i) { if (!in_array($i['aname'], $plugins_arr)) { unload_plugin($i['aname']); } else { $installed_arr[] = $i['aname']; } } } if (count($plugins_arr)) { foreach ($plugins_arr as $p) { if (!in_array($p, $installed_arr)) { load_plugin($p); } } } load_hooks(); check_cron_broken(); }