]> git.mxchange.org Git - friendica.git/blobdiff - boot.php
Some more improvements
[friendica.git] / boot.php
index b69fd91c45905d3d51ba6cf57e60491ddbf9140b..35c37d715ea07909bb5f8f0623ec3dd3571d0fc2 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -21,6 +21,7 @@
 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
 
 use Friendica\App;
+use Friendica\Core\System;
 use Friendica\Core\Config;
 use Friendica\Util\Lock;
 
@@ -40,9 +41,9 @@ require_once 'include/poller.php';
 
 define ( 'FRIENDICA_PLATFORM',     'Friendica');
 define ( 'FRIENDICA_CODENAME',     'Asparagus');
-define ( 'FRIENDICA_VERSION',      '3.5.3-dev' );
+define ( 'FRIENDICA_VERSION',      '3.6-dev' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1232      );
+define ( 'DB_UPDATE_VERSION',      1235      );
 
 /**
  * @brief Constant with a HTML line break.
@@ -228,8 +229,9 @@ define('PROTOCOL_UNKNOWN',         0);
 define('PROTOCOL_DFRN',            1);
 define('PROTOCOL_DIASPORA',        2);
 define('PROTOCOL_OSTATUS_SALMON',  3);
-define('PROTOCOL_OSTATUS_FEED',    4);
-define('PROTOCOL_GS_CONVERSATION', 5);
+define('PROTOCOL_OSTATUS_FEED',    4); // Deprecated
+define('PROTOCOL_GS_CONVERSATION', 5); // Deprecated
+define('PROTOCOL_SPLITTED_CONV',   6);
 /** @}*/
 
 /**
@@ -319,6 +321,8 @@ define ( 'NOTIFY_TAGSHARE', 0x0100 );
 define ( 'NOTIFY_POKE',     0x0200 );
 define ( 'NOTIFY_SHARE',    0x0400 );
 
+define ( 'SYSTEM_EMAIL',    0x4000 );
+
 define ( 'NOTIFY_SYSTEM',   0x8000 );
 /* @}*/
 
@@ -390,6 +394,7 @@ define ( 'ACTIVITY_POST',        NAMESPACE_ACTIVITY_SCHEMA . 'post' );
 define ( 'ACTIVITY_UPDATE',      NAMESPACE_ACTIVITY_SCHEMA . 'update' );
 define ( 'ACTIVITY_TAG',         NAMESPACE_ACTIVITY_SCHEMA . 'tag' );
 define ( 'ACTIVITY_FAVORITE',    NAMESPACE_ACTIVITY_SCHEMA . 'favorite' );
+define ( 'ACTIVITY_UNFAVORITE',  NAMESPACE_ACTIVITY_SCHEMA . 'unfavorite' );
 define ( 'ACTIVITY_SHARE',       NAMESPACE_ACTIVITY_SCHEMA . 'share' );
 define ( 'ACTIVITY_DELETE',      NAMESPACE_ACTIVITY_SCHEMA . 'delete' );
 
@@ -505,6 +510,11 @@ function startup() {
  */
 function get_app() {
        global $a;
+
+       if (empty($a)) {
+               $a = new App(dirname(__DIR__));
+       }
+
        return $a;
 }
 
@@ -551,31 +561,16 @@ function system_unavailable() {
        killme();
 }
 
-function clean_urls() {
-       $a = get_app();
-       return true;
-}
-
-function z_path() {
-       $base = App::get_baseurl();
-
-       if (!clean_urls()) {
-               $base .= '/?q=';
-       }
-
-       return $base;
-}
-
 /**
  * @brief Returns the baseurl.
  *
- * @see App::get_baseurl()
+ * @see System::baseUrl()
  *
  * @return string
- * @TODO Maybe super-flous and deprecated? Seems to only wrap App::get_baseurl()
+ * @TODO Function is deprecated and only used in some addons
  */
 function z_root() {
-       return App::get_baseurl();
+       return System::baseUrl();
 }
 
 /**
@@ -601,7 +596,12 @@ function is_ajax() {
        return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
 }
 
-function check_db() {
+/**
+ * @brief Function to check if request was an AJAX (xmlhttprequest) request.
+ *
+ * @param $via_worker boolean Is the check run via the poller?
+ */
+function check_db($via_worker) {
 
        $build = get_config('system', 'build');
        if (!x($build)) {
@@ -609,7 +609,10 @@ function check_db() {
                $build = DB_UPDATE_VERSION;
        }
        if ($build != DB_UPDATE_VERSION) {
-               proc_run(PRIORITY_CRITICAL, 'include/dbupdate.php');
+               // 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(get_app());
+               }
        }
 }
 
@@ -628,10 +631,10 @@ function check_url(App $a) {
        // We will only change the url to an ip address if there is no existing setting
 
        if (!x($url)) {
-               $url = set_config('system', 'url', App::get_baseurl());
+               $url = set_config('system', 'url', System::baseUrl());
        }
-       if ((!link_compare($url, App::get_baseurl())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $a->get_hostname))) {
-               $url = set_config('system', 'url', App::get_baseurl());
+       if ((!link_compare($url, System::baseUrl())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $a->get_hostname))) {
+               $url = set_config('system', 'url', System::baseUrl());
        }
 
        return;
@@ -901,8 +904,14 @@ function login($register = false, $hiddens = false) {
  * @brief Used to end the current process, after saving session state.
  */
 function killme() {
+       global $session_exists;
+
        if (!get_app()->is_backend()) {
-               session_write_close();
+               if (!$session_exists) {
+                       session_abort();
+               } else {
+                       session_write_close();
+               }
        }
 
        exit();
@@ -913,7 +922,7 @@ function killme() {
  */
 function goaway($s) {
        if (!strstr(normalise_link($s), "http://")) {
-               $s = App::get_baseurl() . "/" . $s;
+               $s = System::baseUrl() . "/" . $s;
        }
 
        header("Location: $s");
@@ -961,6 +970,10 @@ function public_contact() {
  * @return int|bool visitor_id or false
  */
 function remote_user() {
+       // You cannot be both local and remote
+       if (local_user()) {
+               return false;
+       }
        if ((x($_SESSION, 'authenticated')) && (x($_SESSION, 'visitor_id'))) {
                return intval($_SESSION['visitor_id']);
        }
@@ -1017,107 +1030,15 @@ function get_max_import_size() {
 }
 
 /**
- * @brief Wrap calls to proc_close(proc_open()) and call hook
- *     so plugins can take part in process :)
+ * @brief compatibilty wrapper for Worker::add function
  *
  * @param (integer|array) priority or parameter array, $cmd atrings are deprecated and are ignored
  *
- * next args are passed as $cmd command line
- * or: proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
- * or: proc_run(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "include/create_shadowentry.php", $post_id);
- *
- * @note $cmd and string args are surrounded with ""
- *
- * @hooks 'proc_run'
- *     array $arr
+ * @return boolean "false" if proc_run couldn't be executed
  */
-function proc_run($cmd) {
-
-       $a = get_app();
-
+function proc_run() {
        $proc_args = func_get_args();
-
-       $args = array();
-       if (!count($proc_args)) {
-               return;
-       }
-
-       // Preserve the first parameter
-       // It could contain a command, the priority or an parameter array
-       // If we use the parameter array we have to protect it from the following function
-       $run_parameter = array_shift($proc_args);
-
-       // expand any arrays
-       foreach ($proc_args as $arg) {
-               if (is_array($arg)) {
-                       foreach ($arg as $n) {
-                               $args[] = $n;
-                       }
-               } else {
-                       $args[] = $arg;
-               }
-       }
-
-       // Now we add the run parameters back to the array
-       array_unshift($args, $run_parameter);
-
-       $arr = array('args' => $args, 'run_cmd' => true);
-
-       call_hooks("proc_run", $arr);
-       if (!$arr['run_cmd'] || ! count($args)) {
-               return;
-       }
-
-       $priority = PRIORITY_MEDIUM;
-       $dont_fork = get_config("system", "worker_dont_fork");
-       $created = datetime_convert();
-
-       if (is_int($run_parameter)) {
-               $priority = $run_parameter;
-       } elseif (is_array($run_parameter)) {
-               if (isset($run_parameter['priority'])) {
-                       $priority = $run_parameter['priority'];
-               }
-               if (isset($run_parameter['created'])) {
-                       $created = $run_parameter['created'];
-               }
-               if (isset($run_parameter['dont_fork'])) {
-                       $dont_fork = $run_parameter['dont_fork'];
-               }
-       }
-
-       $argv = $args;
-       array_shift($argv);
-
-       $parameters = json_encode($argv);
-       $found = dba::select('workerqueue', array('id'), array('parameter' => $parameters, 'done' => false), array('limit' => 1));
-
-       if (!dbm::is_result($found)) {
-               dba::insert('workerqueue', array('parameter' => $parameters, 'created' => $created, 'priority' => $priority));
-       }
-
-       // Should we quit and wait for the poller to be called as a cronjob?
-       if ($dont_fork) {
-               return;
-       }
-
-       // If there is a lock then we don't have to check for too much worker
-       if (!Lock::set('poller_worker', 0)) {
-               return;
-       }
-
-       // If there are already enough workers running, don't fork another one
-       $quit = poller_too_much_workers();
-       Lock::remove('poller_worker');
-
-       if ($quit) {
-               return;
-       }
-
-       // Now call the poller to execute the jobs that we just added to the queue
-       $args = array("include/poller.php", "no_cron");
-
-       $a->proc_run($args);
+       call_user_func_array('Friendica\Core\Worker::add', $proc_args);
 }
 
 function current_theme() {
@@ -1399,7 +1320,7 @@ function get_temppath() {
 
        if (($temppath != "") && App::directory_usable($temppath)) {
                // We have a temp path and it is usable
-               return $temppath;
+               return App::realpath($temppath);
        }
 
        // We don't have a working preconfigured temp path, so we take the system path.
@@ -1407,6 +1328,9 @@ function get_temppath() {
 
        // Check if it is usable
        if (($temppath != "") && App::directory_usable($temppath)) {
+               // Always store the real path, not the path through symlinks
+               $temppath = App::realpath($temppath);
+
                // To avoid any interferences with other systems we create our own directory
                $new_temppath = $temppath . "/" . $a->get_hostname();
                if (!is_dir($new_temppath)) {
@@ -1495,7 +1419,7 @@ function get_itemcachepath() {
 
        $itemcache = get_config('system', 'itemcache');
        if (($itemcache != "") && App::directory_usable($itemcache)) {
-               return $itemcache;
+               return App::realpath($itemcache);
        }
 
        $temppath = get_temppath();