]> git.mxchange.org Git - friendica.git/blobdiff - boot.php
Events are now shared with Diaspora.
[friendica.git] / boot.php
index 88f7ad7829fff1e30d40290b2794d2834fd089a1..aad8813766002d0cd265b0eeabb6f5f580ae43c3 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM',     'Friendica');
 define ( 'FRIENDICA_CODENAME',     'Asparagus');
 define ( 'FRIENDICA_VERSION',      '3.5.1-dev' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1208      );
+define ( 'DB_UPDATE_VERSION',      1211      );
 
 /**
  * @brief Constant with a HTML line break.
@@ -530,6 +530,7 @@ class App {
        public  $videoheight = 350;
        public  $force_max_items = 0;
        public  $theme_thread_allow = true;
+       public  $theme_richtext_editor = true;
        public  $theme_events_in_profile = true;
 
        /**
@@ -609,6 +610,7 @@ class App {
                $this->performance["markstart"] = microtime(true);
 
                $this->callstack["database"] = array();
+               $this->callstack["database_write"] = array();
                $this->callstack["network"] = array();
                $this->callstack["file"] = array();
                $this->callstack["rendering"] = array();
@@ -668,22 +670,23 @@ class App {
 
                #set_include_path("include/$this->hostname" . PATH_SEPARATOR . get_include_path());
 
-               if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,9) === "pagename=") {
+               if ((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,9) === "pagename=") {
                        $this->query_string = substr($_SERVER['QUERY_STRING'],9);
                        // removing trailing / - maybe a nginx problem
                        if (substr($this->query_string, 0, 1) == "/")
                                $this->query_string = substr($this->query_string, 1);
-               } elseif((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") {
+               } elseif ((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") {
                        $this->query_string = substr($_SERVER['QUERY_STRING'],2);
                        // removing trailing / - maybe a nginx problem
                        if (substr($this->query_string, 0, 1) == "/")
                                $this->query_string = substr($this->query_string, 1);
                }
 
-               if (x($_GET,'pagename'))
+               if (x($_GET,'pagename')) {
                        $this->cmd = trim($_GET['pagename'],'/\\');
-               elseif (x($_GET,'q'))
+               } elseif (x($_GET,'q')) {
                        $this->cmd = trim($_GET['q'],'/\\');
+               }
 
 
                // fix query_string
@@ -692,13 +695,15 @@ class App {
 
                // unix style "homedir"
 
-               if(substr($this->cmd,0,1) === '~')
+               if (substr($this->cmd,0,1) === '~') {
                        $this->cmd = 'profile/' . substr($this->cmd,1);
+               }
 
                // Diaspora style profile url
 
-               if(substr($this->cmd,0,2) === 'u/')
+               if (substr($this->cmd,0,2) === 'u/') {
                        $this->cmd = 'profile/' . substr($this->cmd,2);
+               }
 
 
                /*
@@ -765,7 +770,7 @@ class App {
 
        }
 
-       function get_basepath() {
+       public static function get_basepath() {
 
                $basepath = get_config("system", "basepath");
 
@@ -804,7 +809,7 @@ class App {
        function get_baseurl($ssl = false) {
 
                // Is the function called statically?
-               if (!is_object($this)) {
+               if (!(isset($this) && get_class($this) == __CLASS__)) {
                        return self::$a->get_baseurl($ssl);
                }
 
@@ -1026,7 +1031,7 @@ class App {
                } else {
                        $r = q("SELECT `contact`.`avatar-date` AS picdate FROM `contact` WHERE `contact`.`thumb` like '%%/%s'",
                                $common_filename);
-                       if(! dbm::is_result($r)){
+                       if (! dbm::is_result($r)) {
                                $this->cached_profile_image[$avatar_image] = $avatar_image;
                        } else {
                                $this->cached_profile_picdate[$common_filename] = "?rev=".urlencode($r[0]['picdate']);
@@ -1041,20 +1046,28 @@ class App {
        /**
         * @brief Removes the baseurl from an url. This avoids some mixed content problems.
         *
-        * @param string $url
+        * @param string $orig_url
         *
         * @return string The cleaned url
         */
-       function remove_baseurl($url){
+       function remove_baseurl($orig_url){
 
                // Is the function called statically?
-               if (!is_object($this))
-                       return(self::$a->remove_baseurl($url));
+               if (!(isset($this) && get_class($this) == __CLASS__)) {
+                       return(self::$a->remove_baseurl($orig_url));
+               }
 
-               $url = normalise_link($url);
+               // Remove the hostname from the url if it is an internal link
+               $nurl = normalise_link($orig_url);
                $base = normalise_link($this->get_baseurl());
-               $url = str_replace($base."/", "", $url);
-               return $url;
+               $url = str_replace($base."/", "", $nurl);
+
+               // if it is an external link return the orignal value
+               if ($url == normalise_link($orig_url)) {
+                       return $orig_url;
+               } else {
+                       return $url;
+               }
        }
 
        /**
@@ -1181,7 +1194,7 @@ class App {
                q("START TRANSACTION");
 
                $r = q("SELECT `pid` FROM `process` WHERE `pid` = %d", intval(getmypid()));
-               if(!dbm::is_result($r)) {
+               if (!dbm::is_result($r)) {
                        q("INSERT INTO `process` (`pid`,`command`,`created`) VALUES (%d, '%s', '%s')",
                                intval(getmypid()),
                                dbesc($command),
@@ -1197,7 +1210,7 @@ class App {
                q("START TRANSACTION");
 
                $r = q("SELECT `pid` FROM `process`");
-               if(dbm::is_result($r)) {
+               if (dbm::is_result($r)) {
                        foreach ($r AS $process) {
                                if (!posix_kill($process["pid"], 0)) {
                                        q("DELETE FROM `process` WHERE `pid` = %d", intval($process["pid"]));
@@ -1284,10 +1297,6 @@ class App {
         */
        function max_processes_reached() {
 
-               // Is the function called statically?
-               if (!is_object($this))
-                       return(self::$a->max_processes_reached());
-
                if ($this->is_backend()) {
                        $process = "backend";
                        $max_processes = get_config('system', 'max_processes_backend');
@@ -1319,10 +1328,6 @@ class App {
         */
        function maxload_reached() {
 
-               // Is the function called statically?
-               if (!is_object($this))
-                       return(self::$a->maxload_reached());
-
                if ($this->is_backend()) {
                        $process = "backend";
                        $maxsysload = intval(get_config('system', 'maxloadavg'));
@@ -1376,6 +1381,10 @@ class App {
 
        function proc_run($args) {
 
+               if (!function_exists("proc_open")) {
+                       return;
+               }
+
                // Add the php path if it is a php call
                if (count($args) && ($args[0] === 'php' OR !is_string($args[0]))) {
 
@@ -1465,17 +1474,18 @@ function system_unavailable() {
 
 
 function clean_urls() {
-       global $a;
+       $a = get_app();
        //      if($a->config['system']['clean_urls'])
        return true;
        //      return false;
 }
 
 function z_path() {
-       global $a;
-       $base = $a->get_baseurl();
+       $base = App::get_baseurl();
+
        if(! clean_urls())
                $base .= '/?q=';
+
        return $base;
 }
 
@@ -1485,10 +1495,10 @@ function z_path() {
  * @see App::get_baseurl()
  *
  * @return string
+ * @TODO Maybe super-flous and deprecated? Seems to only wrap App::get_baseurl()
  */
 function z_root() {
-       global $a;
-       return $a->get_baseurl();
+       return App::get_baseurl();
 }
 
 /**
@@ -1541,9 +1551,9 @@ function check_url(&$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',$a->get_baseurl());
-       if((! link_compare($url,$a->get_baseurl())) && (! preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$a->get_hostname)))
-               $url = set_config('system','url',$a->get_baseurl());
+               $url = set_config('system','url',App::get_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());
 
        return;
 }
@@ -1671,7 +1681,7 @@ function run_update_function($x) {
 function check_plugins(&$a) {
 
        $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
-       if(dbm::is_result($r))
+       if (dbm::is_result($r))
                $installed = $r;
        else
                $installed = array();
@@ -1889,7 +1899,7 @@ function info($s) {
  * @return int
  */
 function get_max_import_size() {
-       global $a;
+       $a = get_app();
        return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 );
 }
 
@@ -2015,7 +2025,7 @@ function current_theme(){
                $r = q("select theme from user where uid = %d limit 1",
                        intval($a->profile_uid)
                );
-               if(dbm::is_result($r))
+               if (dbm::is_result($r))
                        $page_theme = $r[0]['theme'];
        }
 
@@ -2086,7 +2096,7 @@ function current_theme(){
  * @return string
  */
 function current_theme_url() {
-       global $a;
+       $a = get_app();
 
        $t = current_theme();
 
@@ -2128,7 +2138,7 @@ function feed_birthday($uid,$tz) {
                        intval($uid)
        );
 
-       if(dbm::is_result($p)) {
+       if (dbm::is_result($p)) {
                $tmp_dob = substr($p[0]['dob'],5);
                if(intval($tmp_dob)) {
                        $y = datetime_convert($tz,$tz,'now','Y');
@@ -2351,6 +2361,36 @@ function get_lockpath() {
        return "";
 }
 
+/**
+ * @brief Returns the path where spool files are stored
+ *
+ * @return string Spool path
+ */
+function get_spoolpath() {
+       $spoolpath = get_config('system','spoolpath');
+       if (($spoolpath != "") AND is_dir($spoolpath) AND is_writable($spoolpath)) {
+               return($spoolpath);
+       }
+
+       $temppath = get_temppath();
+
+       if ($temppath != "") {
+               $spoolpath = $temppath."/spool";
+
+               if (!is_dir($spoolpath)) {
+                       mkdir($spoolpath);
+               } elseif (!is_writable($spoolpath)) {
+                       $spoolpath = $temppath;
+               }
+
+               if (is_dir($spoolpath) AND is_writable($spoolpath)) {
+                       set_config("system", "spoolpath", $spoolpath);
+                       return($spoolpath);
+               }
+       }
+       return "";
+}
+
 function get_temppath() {
        $a = get_app();