]> git.mxchange.org Git - friendica.git/blobdiff - boot.php
Merge branch 'develop' into utf8mb4
[friendica.git] / boot.php
index 8fdccef4a5cee57de7cbed121705c4569cf9f298..becb9bd570e895172d7a6e0465517eaccf4169c3 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -17,7 +17,7 @@
  * easily as email does today.
  */
 
-require_once('include/autoloader.php');
+require_once(__DIR__ . DIRECTORY_SEPARATOR. 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
 
 use \Friendica\Core\Config;
 
@@ -29,7 +29,6 @@ require_once('include/datetime.php');
 require_once('include/pgettext.php');
 require_once('include/nav.php');
 require_once('include/cache.php');
-require_once('library/Mobile_Detect/Mobile_Detect.php');
 require_once('include/features.php');
 require_once('include/identity.php');
 require_once('update.php');
@@ -39,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM',     'Friendica');
 define ( 'FRIENDICA_CODENAME',     'Asparagus');
 define ( 'FRIENDICA_VERSION',      '3.5.2-dev' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1216      );
+define ( 'DB_UPDATE_VERSION',      1219      );
 
 /**
  * @brief Constant with a HTML line break.
@@ -253,7 +252,6 @@ define ( 'NETWORK_PHANTOM',          'unkn');    // Place holder
  * and existing allocations MUST NEVER BE CHANGED
  * OR RE-ASSIGNED! You may only add to them.
  */
-
 $netgroup_ids = array(
        NETWORK_DFRN     => (-1),
        NETWORK_ZOT      => (-2),
@@ -384,6 +382,7 @@ define ( 'ACTIVITY_UPDATE',      NAMESPACE_ACTIVITY_SCHEMA . 'update' );
 define ( 'ACTIVITY_TAG',         NAMESPACE_ACTIVITY_SCHEMA . 'tag' );
 define ( 'ACTIVITY_FAVORITE',    NAMESPACE_ACTIVITY_SCHEMA . 'favorite' );
 define ( 'ACTIVITY_SHARE',       NAMESPACE_ACTIVITY_SCHEMA . 'share' );
+define ( 'ACTIVITY_DELETE',      NAMESPACE_ACTIVITY_SCHEMA . 'delete' );
 
 define ( 'ACTIVITY_POKE',        NAMESPACE_ZOT . '/activity/poke' );
 define ( 'ACTIVITY_MOOD',        NAMESPACE_ZOT . '/activity/mood' );
@@ -503,6 +502,7 @@ function startup() {
  */
 class App {
 
+       /// @TODO decide indending as a colorful mixure is ahead ...
        public  $module_loaded = false;
        public  $query_string;
        public  $config;
@@ -611,8 +611,9 @@ class App {
 
                $hostname = "";
 
-               if (file_exists(".htpreconfig.php"))
-                       @include(".htpreconfig.php");
+               if (file_exists(".htpreconfig.php")) {
+                       include ".htpreconfig.php";
+               }
 
                $this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
 
@@ -646,86 +647,85 @@ class App {
                startup();
 
                set_include_path(
-                               'include' . PATH_SEPARATOR
+                               get_include_path() . PATH_SEPARATOR
+                               . 'include' . PATH_SEPARATOR
                                . 'library' . PATH_SEPARATOR
-                               . 'library/phpsec' . PATH_SEPARATOR
                                . 'library/langdet' . PATH_SEPARATOR
                                . '.' );
 
-
                $this->scheme = 'http';
-               if ((x($_SERVER,'HTTPS') && $_SERVER['HTTPS']) ||
-                  (x($_SERVER['HTTP_FORWARDED']) && preg_match("/proto=https/", $_SERVER['HTTP_FORWARDED'])) ||
-                  (x($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ||
-                  (x($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') ||
-                  (x($_SERVER['FRONT_END_HTTPS']) && $_SERVER['FRONT_END_HTTPS'] == 'on') ||
-                  (x($_SERVER,'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) // XXX: reasonable assumption, but isn't this hardcoding too much?
-                  ) {
+
+               if ((x($_SERVER, 'HTTPS') && $_SERVER['HTTPS']) ||
+                               (x($_SERVER, 'HTTP_FORWARDED') && preg_match("/proto=https/", $_SERVER['HTTP_FORWARDED'])) ||
+                               (x($_SERVER, 'HTTP_X_FORWARDED_PROTO') && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ||
+                               (x($_SERVER, 'HTTP_X_FORWARDED_SSL') && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') ||
+                               (x($_SERVER, 'FRONT_END_HTTPS') && $_SERVER['FRONT_END_HTTPS'] == 'on') ||
+                               (x($_SERVER, 'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) // XXX: reasonable assumption, but isn't this hardcoding too much?
+                               ) {
                        $this->scheme = 'https';
                }
 
-               if (x($_SERVER,'SERVER_NAME')) {
+               if (x($_SERVER, 'SERVER_NAME')) {
                        $this->hostname = $_SERVER['SERVER_NAME'];
 
-                       if (x($_SERVER,'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443)
+                       if (x($_SERVER, 'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
                                $this->hostname .= ':' . $_SERVER['SERVER_PORT'];
+                       }
                        /*
                         * Figure out if we are running at the top of a domain
                         * or in a sub-directory and adjust accordingly
                         */
 
-                       $path = trim(dirname($_SERVER['SCRIPT_NAME']),'/\\');
-                       if (isset($path) && strlen($path) && ($path != $this->path))
+                       /// @TODO This kind of escaping breaks syntax-highlightning on CoolEdit (Midnight Commander)
+                       $path = trim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
+                       if (isset($path) && strlen($path) && ($path != $this->path)) {
                                $this->path = $path;
+                       }
                }
 
-               if ($hostname != "")
+               if ($hostname != "") {
                        $this->hostname = $hostname;
+               }
 
-               if (is_array($_SERVER["argv"]) && $_SERVER["argc"]>1 && substr(end($_SERVER["argv"]), 0, 4)=="http" ) {
-                       $this->set_baseurl(array_pop($_SERVER["argv"]) );
+               if (is_array($_SERVER["argv"]) && $_SERVER["argc"] > 1 && substr(end($_SERVER["argv"]), 0, 4) == "http" ) {
+                       $this->set_baseurl(array_pop($_SERVER["argv"]));
                        $_SERVER["argc"] --;
                }
 
-               #set_include_path("include/$this->hostname" . PATH_SEPARATOR . get_include_path());
+               if ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 9) === "pagename=") {
+                       $this->query_string = substr($_SERVER['QUERY_STRING'], 9);
 
-               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=") {
-                       $this->query_string = substr($_SERVER['QUERY_STRING'],2);
+                       $this->query_string = ltrim($this->query_string, '/');
+               } 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);
+                       $this->query_string = ltrim($this->query_string, '/');
                }
 
-               if (x($_GET,'pagename')) {
-                       $this->cmd = trim($_GET['pagename'],'/\\');
-               } elseif (x($_GET,'q')) {
-                       $this->cmd = trim($_GET['q'],'/\\');
+               if (x($_GET, 'pagename')) {
+                       $this->cmd = trim($_GET['pagename'], '/\\');
+               } elseif (x($_GET, 'q')) {
+                       $this->cmd = trim($_GET['q'], '/\\');
                }
 
 
                // fix query_string
-               $this->query_string = str_replace($this->cmd."&",$this->cmd."?", $this->query_string);
+               $this->query_string = str_replace($this->cmd . "&", $this->cmd . "?", $this->query_string);
 
                // unix style "homedir"
-
-               if (substr($this->cmd,0,1) === '~') {
-                       $this->cmd = 'profile/' . substr($this->cmd,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/') {
-                       $this->cmd = 'profile/' . substr($this->cmd,2);
+               if (substr($this->cmd, 0, 2) === 'u/') {
+                       $this->cmd = 'profile/' . substr($this->cmd, 2);
                }
 
 
                /*
-                *
                 * Break the URL path into C style argc/argv style arguments for our
                 * modules. Given "http://example.com/module/arg1/arg2", $this->argc
                 * will be 3 (integer) and $this->argv will contain:
@@ -736,12 +736,11 @@ class App {
                 *
                 * There will always be one argument. If provided a naked domain
                 * URL, $this->argv[0] is set to "home".
-                *
                 */
 
-               $this->argv = explode('/',$this->cmd);
+               $this->argv = explode('/', $this->cmd);
                $this->argc = count($this->argv);
-               if ((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) {
+               if ((array_key_exists('0', $this->argv)) && strlen($this->argv[0])) {
                        $this->module = str_replace(".", "_", $this->argv[0]);
                        $this->module = str_replace("-", "_", $this->module);
                } else {
@@ -755,9 +754,10 @@ class App {
                 * pagination
                 */
 
-               $this->pager['page'] = ((x($_GET,'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1);
+               $this->pager['page'] = ((x($_GET, 'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1);
                $this->pager['itemspage'] = 50;
                $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
+
                if ($this->pager['start'] < 0) {
                        $this->pager['start'] = 0;
                }
@@ -804,11 +804,11 @@ class App {
                        $basepath = $_SERVER["PWD"];
                }
 
-               return($basepath);
+               return $basepath;
        }
 
        function get_scheme() {
-               return($this->scheme);
+               return $this->scheme;
        }
 
        /**
@@ -878,7 +878,7 @@ class App {
                        }
 
                        if (file_exists(".htpreconfig.php")) {
-                               include(".htpreconfig.php");
+                               include ".htpreconfig.php";
                        }
 
                        if (get_config('config', 'hostname') != '') {
@@ -892,8 +892,8 @@ class App {
        }
 
        function get_hostname() {
-               if (get_config('config','hostname') != "") {
-                       $this->hostname = get_config('config','hostname');
+               if (get_config('config', 'hostname') != "") {
+                       $this->hostname = get_config('config', 'hostname');
                }
 
                return $this->hostname;
@@ -904,7 +904,7 @@ class App {
        }
 
        function set_path($p) {
-               $this->path = trim(trim($p),'/');
+               $this->path = trim(trim($p), '/');
        }
 
        function get_path() {
@@ -939,8 +939,8 @@ class App {
 
                // compose the page title from the sitename and the
                // current module called
-               if (!$this->module=='') {
-                       $this->page['title'] = $this->config['sitename'].' ('.$this->module.')';
+               if (!$this->module == '') {
+                   $this->page['title'] = $this->config['sitename'] . ' (' . $this->module . ')';
                } else {
                        $this->page['title'] = $this->config['sitename'];
                }
@@ -1028,29 +1028,6 @@ class App {
 
        function get_cached_avatar_image($avatar_image){
                return $avatar_image;
-
-               // The following code is deactivated. It doesn't seem to make any sense and it slows down the system.
-               /*
-               if ($this->cached_profile_image[$avatar_image])
-                       return $this->cached_profile_image[$avatar_image];
-
-               $path_parts = explode("/",$avatar_image);
-               $common_filename = $path_parts[count($path_parts)-1];
-
-               if ($this->cached_profile_picdate[$common_filename]){
-                       $this->cached_profile_image[$avatar_image] = $avatar_image . $this->cached_profile_picdate[$common_filename];
-               } else {
-                       $r = q("SELECT `contact`.`avatar-date` AS picdate FROM `contact` WHERE `contact`.`thumb` like '%%/%s'",
-                               $common_filename);
-                       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']);
-                               $this->cached_profile_image[$avatar_image] = $avatar_image.$this->cached_profile_picdate[$common_filename];
-                       }
-               }
-               return $this->cached_profile_image[$avatar_image];
-               */
        }
 
 
@@ -1065,7 +1042,7 @@ class App {
 
                // Is the function called statically?
                if (!(isset($this) && get_class($this) == __CLASS__)) {
-                       return(self::$a->remove_baseurl($orig_url));
+                       return self::$a->remove_baseurl($orig_url);
                }
 
                // Remove the hostname from the url if it is an internal link
@@ -1090,11 +1067,12 @@ class App {
         * @param string $name
         */
        function register_template_engine($class, $name = '') {
-               if ($name===""){
+               /// @TODO Really === and not just == ?
+               if ($name === "") {
                        $v = get_class_vars( $class );
                        if (x($v,"name")) $name = $v['name'];
                }
-               if ($name===""){
+               if ($name === "") {
                        echo "template engine <tt>$class</tt> cannot be registered without a name.\n";
                        killme();
                }
@@ -1110,8 +1088,9 @@ class App {
         * @param strin $name Template engine name
         * @return object Template Engine instance
         */
-       function template_engine($name = ''){
-               if ($name!=="") {
+       function template_engine($name = '') {
+               /// @TODO really type-check included?
+               if ($name !== "") {
                        $template_engine = $name;
                } else {
                        $template_engine = 'smarty3';
@@ -1145,18 +1124,6 @@ class App {
 
        function set_template_engine($engine = 'smarty3') {
                $this->theme['template_engine'] = $engine;
-               /*
-               $this->theme['template_engine'] = 'smarty3';
-
-               switch($engine) {
-                       case 'smarty3':
-                               if (is_writable('view/smarty3/'))
-                                       $this->theme['template_engine'] = 'smarty3';
-                               break;
-                       default:
-                               break;
-               }
-               */
        }
 
        function get_template_ldelim($engine = 'smarty3') {
@@ -1260,11 +1227,16 @@ class App {
        }
 
        function get_useragent() {
-               return(FRIENDICA_PLATFORM." '".FRIENDICA_CODENAME."' ".FRIENDICA_VERSION."-".DB_UPDATE_VERSION."; ".$this->get_baseurl());
+               return
+                       FRIENDICA_PLATFORM . " '" .
+                       FRIENDICA_CODENAME . "' " .
+                       FRIENDICA_VERSION . "-" .
+                       DB_UPDATE_VERSION . "; " .
+                       $this->get_baseurl();
        }
 
        function is_friendica_app() {
-               return($this->is_friendica_app);
+               return $this->is_friendica_app;
        }
 
        /**
@@ -1276,33 +1248,29 @@ class App {
         * @return bool Is it a known backend?
         */
        function is_backend() {
-               static $backend = array(
-                       "_well_known",
-                       "api",
-                       "dfrn_notify",
-                       "fetch",
-                       "hcard",
-                       "hostxrd",
-                       "nodeinfo",
-                       "noscrape",
-                       "p",
-                       "poco",
-                       "post",
-                       "proxy",
-                       "pubsub",
-                       "pubsubhubbub",
-                       "receive",
-                       "rsd_xml",
-                       "salmon",
-                       "statistics_json",
-                       "xrd",
-               );
-
-               if (in_array($this->module, $backend)) {
-                       return(true);
-               } else {
-                       return($this->backend);
-               }
+               static $backends = array();
+               $backends[] = "_well_known";
+               $backends[] = "api";
+               $backends[] = "dfrn_notify";
+               $backends[] = "fetch";
+               $backends[] = "hcard";
+               $backends[] = "hostxrd";
+               $backends[] = "nodeinfo";
+               $backends[] = "noscrape";
+               $backends[] = "p";
+               $backends[] = "poco";
+               $backends[] = "post";
+               $backends[] = "proxy";
+               $backends[] = "pubsub";
+               $backends[] = "pubsubhubbub";
+               $backends[] = "receive";
+               $backends[] = "rsd_xml";
+               $backends[] = "salmon";
+               $backends[] = "statistics_json";
+               $backends[] = "xrd";
+
+               // Check if current module is in backend or backend flag is set
+               return (in_array($this->module, $backends) || $this->backend);
        }
 
        /**
@@ -1379,11 +1347,11 @@ class App {
                // This should prevent the forking of masses of workers.
                $cachekey = "app:proc_run:started";
                $result = Cache::get($cachekey);
-               if (!is_null($result)) {
-                       if ((time() - $result) < 10) {
-                               return;
-                       }
+
+               if (!is_null($result) AND (time() - $result) < 10) {
+                       return;
                }
+
                // Set the timestamp of the last proc_run
                Cache::set($cachekey, time(), CACHE_MINUTE);
 
@@ -1396,13 +1364,14 @@ class App {
                        $args[$x] = escapeshellarg($args[$x]);
                }
 
-               $cmdline = implode($args," ");
+               $cmdline = implode($args, " ");
 
-               if (get_config('system','proc_windows')) {
-                       proc_close(proc_open('cmd /c start /b ' . $cmdline,array(),$foo,dirname(__FILE__)));
+               if (get_config('system', 'proc_windows')) {
+                       proc_close(proc_open('cmd /c start /b ' . $cmdline, array(), $foo, dirname(__FILE__)));
                } else {
-                       proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__)));
+                       proc_close(proc_open($cmdline . " &", array(), $foo, dirname(__FILE__)));
                }
+
        }
 
        /**
@@ -1480,7 +1449,7 @@ function get_app() {
  */
 function x($s,$k = NULL) {
        if ($k != NULL) {
-               if ((is_array($s)) && (array_key_exists($k,$s))) {
+               if ((is_array($s)) && (array_key_exists($k, $s))) {
                        if ($s[$k]) {
                                return (int) 1;
                        }
@@ -1776,8 +1745,9 @@ function get_guid($size=16, $prefix = "") {
                $prefix = hash("crc32", $a->get_hostname());
        }
 
-       while (strlen($prefix) < ($size - 13))
+       while (strlen($prefix) < ($size - 13)) {
                $prefix .= mt_rand();
+       }
 
        if ($size >= 24) {
                $prefix = substr($prefix, 0, $size - 22);
@@ -1821,7 +1791,7 @@ function login($register = false, $hiddens=false) {
                $tpl = get_markup_template("logout.tpl");
        } else {
                $a->page['htmlhead'] .= replace_macros(get_markup_template("login_head.tpl"),array(
-                       '$baseurl'              => $a->get_baseurl(true)
+                       '$baseurl' => $a->get_baseurl(true)
                ));
 
                $tpl = get_markup_template("login.tpl");
@@ -1871,7 +1841,7 @@ function killme() {
                session_write_close();
        }
 
-       exit;
+       exit();
 }
 
 /**
@@ -1911,11 +1881,11 @@ function public_contact() {
                if (x($_SESSION, 'my_address')) {
                        // Local user
                        $public_contact_id = intval(get_contact($_SESSION['my_address'], 0));
-               } else if (x($_SESSION, 'visitor_home')) {
+               } elseif (x($_SESSION, 'visitor_home')) {
                        // Remote user
                        $public_contact_id = intval(get_contact($_SESSION['visitor_home'], 0));
                }
-       } else if (!x($_SESSION, 'authenticated')) {
+       } elseif (!x($_SESSION, 'authenticated')) {
                $public_contact_id = false;
        }
 
@@ -2174,7 +2144,6 @@ function current_theme(){
        }
 
        /// @TODO No final return statement?
-
 }
 
 /**
@@ -2256,9 +2225,10 @@ function is_site_admin() {
 
        $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
 
-       //if (local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email']))
-       if (local_user() && x($a->user,'email') && x($a->config,'admin_email') && in_array($a->user['email'], $adminlist))
+       //if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email']))
+       if (local_user() && x($a->user,'email') && x($a->config,'admin_email') && in_array($a->user['email'], $adminlist)) {
                return true;
+       }
        return false;
 }
 
@@ -2270,21 +2240,24 @@ function is_site_admin() {
  *
  * @return string
  */
-function build_querystring($params, $name=null) {
+function build_querystring($params, $name = null) {
        $ret = "";
-       foreach ($params as $key=>$val) {
+       foreach ($params as $key => $val) {
                if (is_array($val)) {
-                       if ($name==null) {
+                       /// @TODO maybe not compare against null, use is_null()
+                       if ($name == null) {
                                $ret .= build_querystring($val, $key);
                        } else {
                                $ret .= build_querystring($val, $name."[$key]");
                        }
                } else {
                        $val = urlencode($val);
-                       if ($name!=null) {
-                               $ret.=$name."[$key]"."=$val&";
+                       /// @TODO maybe not compare against null, use is_null()
+                       if ($name != null) {
+                               /// @TODO two string concated, can be merged to one
+                               $ret .= $name . "[$key]" . "=$val&";
                        } else {
-                               $ret.= "$key=$val&";
+                               $ret .= "$key=$val&";
                        }
                }
        }
@@ -2302,7 +2275,8 @@ function explode_querystring($query) {
        }
 
        $args = explode('&', substr($query, $arg_st));
-       foreach ($args as $k=>$arg) {
+       foreach ($args as $k => $arg) {
+               /// @TODO really compare type-safe here?
                if ($arg === '') {
                        unset($args[$k]);
                }
@@ -2331,7 +2305,9 @@ function curPageURL() {
        if ($_SERVER["HTTPS"] == "on") {
                $pageURL .= "s";
        }
+
        $pageURL .= "://";
+
        if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") {
                $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
        } else {
@@ -2343,6 +2319,7 @@ function curPageURL() {
 function random_digits($digits) {
        $rn = '';
        for ($i = 0; $i < $digits; $i++) {
+               /// @TODO rand() is different to mt_rand() and maybe lesser "random"
                $rn .= rand(0,9);
        }
        return $rn;
@@ -2365,9 +2342,9 @@ function get_cachefile($file, $writemode = true) {
                return("");
        }
 
-       $subfolder = $cache."/".substr($file, 0, 2);
+       $subfolder = $cache . "/" . substr($file, 0, 2);
 
-       $cachepath = $subfolder."/".$file;
+       $cachepath = $subfolder . "/" . $file;
 
        if ($writemode) {
                if (!is_dir($subfolder)) {
@@ -2376,7 +2353,8 @@ function get_cachefile($file, $writemode = true) {
                }
        }
 
-       return($cachepath);
+       /// @TODO no need to put braces here
+       return $cachepath;
 }
 
 function clear_cache($basepath = "", $path = "") {
@@ -2495,9 +2473,11 @@ function get_temppath() {
        // Check if it is usable
        if (($temppath != "") AND App::directory_usable($temppath)) {
                // To avoid any interferences with other systems we create our own directory
-               $new_temppath .= "/".$a->get_hostname();
-               if (!is_dir($new_temppath))
+               $new_temppath = $temppath."/".$a->get_hostname();
+               if (!is_dir($new_temppath)) {
+                       /// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method?
                        mkdir($new_temppath);
+               }
 
                if (App::directory_usable($new_temppath)) {
                        // The new path is usable, we are happy
@@ -2518,6 +2498,7 @@ function get_temppath() {
 function set_template_engine(App $a, $engine = 'internal') {
 /// @note This function is no longer necessary, but keep it as a wrapper to the class method
 /// to avoid breaking themes again unnecessarily
+/// @TODO maybe output a warning here so the theme developer can see it? PHP won't show such warnings like Java does.
 
        $a->set_template_engine($engine);
 }
@@ -2525,7 +2506,7 @@ function set_template_engine(App $a, $engine = 'internal') {
 if (!function_exists('exif_imagetype')) {
        function exif_imagetype($file) {
                $size = getimagesize($file);
-               return($size[2]);
+               return $size[2];
        }
 }
 
@@ -2616,20 +2597,24 @@ function infinite_scroll_data($module) {
                AND ($module == "network") AND ($_GET["mode"] != "minimal")) {
 
                // get the page number
-               if (is_string($_GET["page"]))
+               if (is_string($_GET["page"])) {
                        $pageno = $_GET["page"];
-               else
+               } else {
                        $pageno = 1;
+               }
 
                $reload_uri = "";
 
                // try to get the uri from which we load the content
-               foreach ($_GET AS $param => $value)
-                       if (($param != "page") AND ($param != "q"))
-                               $reload_uri .= "&".$param."=".urlencode($value);
+               foreach ($_GET AS $param => $value) {
+                       if (($param != "page") AND ($param != "q")) {
+                               $reload_uri .= "&" . $param . "=" . urlencode($value);
+                       }
+               }
 
-               if (($a->page_offset != "") AND !strstr($reload_uri, "&offset="))
-                       $reload_uri .= "&offset=".urlencode($a->page_offset);
+               if (($a->page_offset != "") AND !strstr($reload_uri, "&offset=")) {
+                       $reload_uri .= "&offset=" . urlencode($a->page_offset);
+               }
 
                $arr = array("pageno" => $pageno, "reload_uri" => $reload_uri);