- $default = array_pop($args);
-
- if (call_user_func_array('x', $args)) {
- if (count($args) === 1) {
- $return = $args[0];
- } else {
- $return = $args[0][$args[1]];
- }
- } else {
- $return = $default;
- }
-
- return $return;
-}
-
-/**
- * @brief Function to check if request was an AJAX (xmlhttprequest) request.
- *
- * @param boolean $via_worker boolean Is the check run via the worker?
- */
-function check_db($via_worker)
-{
- $build = Config::get('system', 'build');
-
- if (empty($build)) {
- Config::set('system', 'build', DB_UPDATE_VERSION - 1);
- $build = DB_UPDATE_VERSION - 1;
- }
-
- // We don't support upgrading from very old versions anymore
- if ($build < NEW_UPDATE_ROUTINE_VERSION) {
- die('You try to update from a version prior to database version 1170. The direct upgrade path is not supported. Please update to version 3.5.4 before updating to this version.');
- }
-
- if ($build < DB_UPDATE_VERSION) {
- // When we cannot execute the database update via the worker, we will do it directly
- if (!Worker::add(PRIORITY_CRITICAL, 'DBUpdate') && $via_worker) {
- update_db();
- }
- }
-}
-
-/**
- * Sets the base url for use in cmdline programs which don't have
- * $_SERVER variables
- *
- * @param object $a App
- */
-function check_url(App $a)
-{
- $url = Config::get('system', 'url');
-
- // if the url isn't set or the stored url is radically different
- // than the currently visited url, store the current value accordingly.
- // "Radically different" ignores common variations such as http vs https
- // and www.example.com vs example.com.
- // We will only change the url to an ip address if there is no existing setting
-
- if (empty($url) || (!link_compare($url, System::baseUrl())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $a->getHostName()))) {
- Config::set('system', 'url', System::baseUrl());
- }
-
- return;
-}
-
-/**
- * @brief Automatic database updates
- * @param object $a App
- */
-function update_db()
-{
- $build = Config::get('system', 'build');