X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=boot.php;h=b8e92670708836c6d5b9c376185120031e914161;hb=564bc2290064c81adc43dda5c3e30d1f7038223d;hp=348b786e4dfadec12a129da2ebb0bee7d162e2f9;hpb=43df08f8604f24d4fe6cdb928132edd0255e6275;p=friendica.git diff --git a/boot.php b/boot.php index 348b786e4d..b8e9267070 100644 --- a/boot.php +++ b/boot.php @@ -19,6 +19,8 @@ require_once('include/autoloader.php'); +use \Friendica\Core\Config; + require_once('include/config.php'); require_once('include/network.php'); require_once('include/plugin.php'); @@ -38,7 +40,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', 1205 ); +define ( 'DB_UPDATE_VERSION', 1214 ); /** * @brief Constant with a HTML line break. @@ -127,6 +129,10 @@ define ( 'CACHE_MONTH', 0 ); define ( 'CACHE_WEEK', 1 ); define ( 'CACHE_DAY', 2 ); define ( 'CACHE_HOUR', 3 ); +define ( 'CACHE_HALF_HOUR', 4 ); +define ( 'CACHE_QUARTER_HOUR', 5 ); +define ( 'CACHE_FIVE_MINUTES', 6 ); +define ( 'CACHE_MINUTE', 7 ); /* @}*/ /** @@ -239,6 +245,7 @@ define ( 'NETWORK_STATUSNET', 'stac'); // Statusnet connector define ( 'NETWORK_APPNET', 'apdn'); // app.net define ( 'NETWORK_NEWS', 'nntp'); // Network News Transfer Protocol define ( 'NETWORK_ICALENDAR', 'ical'); // iCalendar +define ( 'NETWORK_PNUT', 'pnut'); // pnut.io define ( 'NETWORK_PHANTOM', 'unkn'); // Place holder /** @}*/ @@ -268,6 +275,7 @@ $netgroup_ids = array( NETWORK_APPNET => (-17), NETWORK_NEWS => (-18), NETWORK_ICALENDAR => (-19), + NETWORK_PNUT => (-20), NETWORK_PHANTOM => (-127), ); @@ -422,6 +430,17 @@ define('PRIORITY_LOW', 40); define('PRIORITY_NEGLIGIBLE',50); /* @}*/ +/** + * @name Social Relay settings + * + * See here: https://github.com/jaywink/social-relay + * and here: https://wiki.diasporafoundation.org/Relay_servers_for_public_posts + * @{ + */ +define('SR_SCOPE_NONE', ''); +define('SR_SCOPE_ALL', 'all'); +define('SR_SCOPE_TAGS', 'tags'); +/* @}*/ // Normally this constant is defined - but not if "pcntl" isn't installed if (!defined("SIGTERM")) @@ -566,7 +585,6 @@ class App { private $scheme; private $hostname; - private $baseurl; private $db; private $curl_code; @@ -605,6 +623,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(); @@ -664,22 +683,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 @@ -688,13 +708,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); + } /* @@ -761,7 +783,7 @@ class App { } - function get_basepath() { + public static function get_basepath() { $basepath = get_config("system", "basepath"); @@ -781,60 +803,84 @@ class App { return($this->scheme); } + /** + * @brief Retrieves the Friendica instance base URL + * + * This function assembles the base URL from multiple parts: + * - Protocol is determined either by the request or a combination of + * system.ssl_policy and the $ssl parameter. + * - Host name is determined either by system.hostname or inferred from request + * - Path is inferred from SCRIPT_NAME + * + * Note: $ssl parameter value doesn't directly correlate with the resulting protocol + * + * @param bool $ssl Whether to append http or https under SSL_POLICY_SELFSIGN + * @return string Friendica server base URL + */ function get_baseurl($ssl = false) { // Is the function called statically? - if (!is_object($this)) - return(self::$a->get_baseurl($ssl)); + if (!(isset($this) && get_class($this) == __CLASS__)) { + return self::$a->get_baseurl($ssl); + } $scheme = $this->scheme; - if((x($this->config,'system')) && (x($this->config['system'],'ssl_policy'))) { - if(intval($this->config['system']['ssl_policy']) === intval(SSL_POLICY_FULL)) - $scheme = 'https'; + if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) { + $scheme = 'https'; + } - // Basically, we have $ssl = true on any links which can only be seen by a logged in user - // (and also the login link). Anything seen by an outsider will have it turned off. + // Basically, we have $ssl = true on any links which can only be seen by a logged in user + // (and also the login link). Anything seen by an outsider will have it turned off. - if($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) { - if($ssl) - $scheme = 'https'; - else - $scheme = 'http'; + if (Config::get('system', 'ssl_policy') == SSL_POLICY_SELFSIGN) { + if ($ssl) { + $scheme = 'https'; + } else { + $scheme = 'http'; } } - if (get_config('config','hostname') != "") - $this->hostname = get_config('config','hostname'); + if (Config::get('config', 'hostname') != '') { + $this->hostname = Config::get('config', 'hostname'); + } - $this->baseurl = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' ); - return $this->baseurl; + return $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' ); } + /** + * @brief Initializes the baseurl components + * + * Clears the baseurl cache to prevent inconstistencies + * + * @param string $url + */ function set_baseurl($url) { $parsed = @parse_url($url); - $this->baseurl = $url; - if($parsed) { $this->scheme = $parsed['scheme']; $hostname = $parsed['host']; - if(x($parsed,'port')) + if (x($parsed, 'port')) { $hostname .= ':' . $parsed['port']; - if(x($parsed,'path')) - $this->path = trim($parsed['path'],'\\/'); + } + if (x($parsed, 'path')) { + $this->path = trim($parsed['path'], '\\/'); + } - if (file_exists(".htpreconfig.php")) + if (file_exists(".htpreconfig.php")) { @include(".htpreconfig.php"); + } - if (get_config('config','hostname') != "") - $this->hostname = get_config('config','hostname'); + if (get_config('config', 'hostname') != '') { + $this->hostname = get_config('config', 'hostname'); + } - if (!isset($this->hostname) OR ($this->hostname == "")) + if (!isset($this->hostname) OR ($this->hostname == '')) { $this->hostname = $hostname; + } } - } function get_hostname() { @@ -922,7 +968,6 @@ class App { '$local_user' => local_user(), '$generator' => 'Friendica' . ' ' . FRIENDICA_VERSION, '$delitem' => t('Delete this item?'), - '$comment' => t('Comment'), '$showmore' => t('show more'), '$showfewer' => t('show fewer'), '$update_interval' => $interval, @@ -982,7 +1027,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']); @@ -997,20 +1042,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; + } } /** @@ -1100,6 +1153,9 @@ class App { } function save_timestamp($stamp, $value) { + if (!isset($this->config['system']['profiler']) || !$this->config['system']['profiler']) + return; + $duration = (float)(microtime(true)-$stamp); if (!isset($this->performance[$value])) { @@ -1131,23 +1187,33 @@ class App { $this->remove_inactive_processes(); + 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), dbesc(datetime_convert())); + } + q("COMMIT"); } /** * @brief Remove inactive processes */ function remove_inactive_processes() { + q("START TRANSACTION"); + $r = q("SELECT `pid` FROM `process`"); - if(dbm::is_result($r)) - foreach ($r AS $process) - if (!posix_kill($process["pid"], 0)) + 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"])); + } + } + } + q("COMMIT"); } /** @@ -1176,11 +1242,6 @@ class App { return implode(", ", $callstack); } - function mark_timestamp($mark) { - //$this->performance["markstart"] -= microtime(true) - $this->performance["marktime"]; - $this->performance["markstart"] = microtime(true) - $this->performance["markstart"] - $this->performance["marktime"]; - } - function get_useragent() { return(FRIENDICA_PLATFORM." '".FRIENDICA_CODENAME."' ".FRIENDICA_VERSION."-".DB_UPDATE_VERSION."; ".$this->get_baseurl()); } @@ -1232,10 +1293,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'); @@ -1267,10 +1324,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')); @@ -1324,17 +1377,25 @@ 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_int($args[0]))) { + if (count($args) && ($args[0] === 'php' OR !is_string($args[0]))) { // If the last worker fork was less than 10 seconds before then don't fork another one. // This should prevent the forking of masses of workers. if (get_config("system", "worker")) { - if ((time() - get_config("system", "proc_run_started")) < 10) - return; - + $cachekey = "app:proc_run:started"; + $result = Cache::get($cachekey); + if (!is_null($result)) { + if ((time() - $result) < 10) { + return; + } + } // Set the timestamp of the last proc_run - set_config("system", "proc_run_started", time()); + Cache::set($cachekey, time(), CACHE_MINUTE); } $args[0] = ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'); @@ -1354,6 +1415,53 @@ class App { proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__))); } + + /** + * @brief Returns the system user that is executing the script + * + * This mostly returns something like "www-data". + * + * @return string system username + */ + static function systemuser() { + if (!function_exists('posix_getpwuid') OR !function_exists('posix_geteuid')) { + return ''; + } + + $processUser = posix_getpwuid(posix_geteuid()); + return $processUser['name']; + } + + /** + * @brief Checks if a given directory is usable for the system + * + * @return boolean the directory is usable + */ + static function directory_usable($directory) { + + if ($directory == '') { + logger("Directory is empty. This shouldn't happen.", LOGGER_DEBUG); + return false; + } + + if (!file_exists($directory)) { + logger('Path "'.$directory.'" does not exist for user '.self::systemuser(), LOGGER_DEBUG); + return false; + } + if (is_file($directory)) { + logger('Path "'.$directory.'" is a file for user '.self::systemuser(), LOGGER_DEBUG); + return false; + } + if (!is_dir($directory)) { + logger('Path "'.$directory.'" is not a directory for user '.self::systemuser(), LOGGER_DEBUG); + return false; + } + if (!is_writable($directory)) { + logger('Path "'.$directory.'" is not writable for user '.self::systemuser(), LOGGER_DEBUG); + return false; + } + return true; + } } /** @@ -1413,17 +1521,16 @@ function system_unavailable() { function clean_urls() { - global $a; - // if($a->config['system']['clean_urls']) + $a = get_app(); return true; - // return false; } function z_path() { - global $a; - $base = $a->get_baseurl(); + $base = App::get_baseurl(); + if(! clean_urls()) $base .= '/?q='; + return $base; } @@ -1433,10 +1540,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(); } /** @@ -1478,7 +1585,7 @@ function check_db() { * Sets the base url for use in cmdline programs which don't have * $_SERVER variables */ -function check_url(&$a) { +function check_url(App $a) { $url = get_config('system','url'); @@ -1489,9 +1596,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; } @@ -1500,7 +1607,7 @@ function check_url(&$a) { /** * @brief Automatic database updates */ -function update_db(&$a) { +function update_db(App $a) { $build = get_config('system','build'); if(! x($build)) $build = set_config('system','build',DB_UPDATE_VERSION); @@ -1509,7 +1616,7 @@ function update_db(&$a) { $stored = intval($build); $current = intval(DB_UPDATE_VERSION); if($stored < $current) { - load_config('database'); + Config::load('database'); // We're reporting a different version than what is currently installed. // Run any existing update scripts to bring the database up to current. @@ -1616,10 +1723,10 @@ function run_update_function($x) { * @param App $a * */ -function check_plugins(&$a) { +function check_plugins(App $a) { $r = q("SELECT * FROM `addon` WHERE `installed` = 1"); - if(dbm::is_result($r)) + if (dbm::is_result($r)) $installed = $r; else $installed = array(); @@ -1837,7 +1944,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 ); } @@ -1845,11 +1952,12 @@ function get_max_import_size() { * @brief Wrap calls to proc_close(proc_open()) and call hook * so plugins can take part in process :) * - * @param (string|integer) $cmd program to run or priority + * @param (string|integer|array) $cmd program to run, priority or parameter array * * next args are passed as $cmd command line * e.g.: proc_run("ls","-la","/tmp"); * 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 "" * @@ -1860,24 +1968,31 @@ function proc_run($cmd){ $a = get_app(); - $args = func_get_args(); + $proc_args = func_get_args(); - $newargs = array(); - if (!count($args)) + $args = array(); + if (!count($proc_args)) { return; + } - // expand any arrays + // 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); - foreach($args as $arg) { - if(is_array($arg)) { - foreach($arg as $n) { - $newargs[] = $n; + // expand any arrays + foreach ($proc_args as $arg) { + if (is_array($arg)) { + foreach ($arg as $n) { + $args[] = $n; } - } else - $newargs[] = $arg; + } else { + $args[] = $arg; + } } - $args = $newargs; + // Now we add the run parameters back to the array + array_unshift($args, $run_parameter); $arr = array('args' => $args, 'run_cmd' => true); @@ -1885,16 +2000,24 @@ function proc_run($cmd){ if (!$arr['run_cmd'] OR !count($args)) return; - if (!get_config("system", "worker") OR - (($args[0] != 'php') AND !is_int($args[0]))) { + if (!get_config("system", "worker") OR (is_string($run_parameter) AND ($run_parameter != 'php'))) { $a->proc_run($args); return; } - if (is_int($args[0])) - $priority = $args[0]; - else - $priority = PRIORITY_MEDIUM; + $priority = PRIORITY_MEDIUM; + $dont_fork = get_config("system", "worker_dont_fork"); + + 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['dont_fork'])) { + $dont_fork = $run_parameter['dont_fork']; + } + } $argv = $args; array_shift($argv); @@ -1911,8 +2034,9 @@ function proc_run($cmd){ intval($priority)); // Should we quit and wait for the poller to be called as a cronjob? - if (get_config("system", "worker_dont_fork")) + if ($dont_fork) { return; + } // Checking number of workers $workers = q("SELECT COUNT(*) AS `workers` FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'"); @@ -1946,7 +2070,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']; } @@ -1962,16 +2086,18 @@ function current_theme(){ // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet(); $is_mobile = $a->is_mobile || $a->is_tablet; - $standard_system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : ''); + $standard_system_theme = Config::get('system', 'theme', ''); $standard_theme_name = ((isset($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $standard_system_theme); - if($is_mobile) { - if(isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) { + if ($is_mobile) { + if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) { $system_theme = $standard_system_theme; $theme_name = $standard_theme_name; - } - else { - $system_theme = ((isset($a->config['system']['mobile-theme'])) ? $a->config['system']['mobile-theme'] : $standard_system_theme); + } else { + $system_theme = Config::get('system', 'mobile-theme', ''); + if ($system_theme == '') { + $system_theme = $standard_system_theme; + } $theme_name = ((isset($_SESSION) && x($_SESSION,'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme); if($theme_name === '---') { @@ -2017,7 +2143,7 @@ function current_theme(){ * @return string */ function current_theme_url() { - global $a; + $a = get_app(); $t = current_theme(); @@ -2059,7 +2185,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'); @@ -2240,8 +2366,9 @@ function get_itemcachepath() { return ""; $itemcache = get_config('system','itemcache'); - if (($itemcache != "") AND is_dir($itemcache) AND is_writable($itemcache)) - return($itemcache); + if (($itemcache != "") AND App::directory_usable($itemcache)) { + return $itemcache; + } $temppath = get_temppath(); @@ -2251,9 +2378,9 @@ function get_itemcachepath() { mkdir($itemcache); } - if (is_dir($itemcache) AND is_writable($itemcache)) { + if (App::directory_usable($itemcache)) { set_config("system", "itemcache", $itemcache); - return($itemcache); + return $itemcache; } } return ""; @@ -2261,50 +2388,110 @@ function get_itemcachepath() { function get_lockpath() { $lockpath = get_config('system','lockpath'); - if (($lockpath != "") AND is_dir($lockpath) AND is_writable($lockpath)) - return($lockpath); + if (($lockpath != "") AND App::directory_usable($lockpath)) { + // We have a lock path and it is usable + return $lockpath; + } + // We don't have a working preconfigured lock path, so we take the temp path. $temppath = get_temppath(); if ($temppath != "") { + // To avoid any interferences with other systems we create our own directory $lockpath = $temppath."/lock"; - - if (!is_dir($lockpath)) + if (!is_dir($lockpath)) { mkdir($lockpath); - elseif (!is_writable($lockpath)) - $lockpath = $temppath; + } - if (is_dir($lockpath) AND is_writable($lockpath)) { + if (App::directory_usable($lockpath)) { + // The new path is usable, we are happy set_config("system", "lockpath", $lockpath); - return($lockpath); + return $lockpath; + } else { + // We can't create a subdirectory, strange. + // But the directory seems to work, so we use it but don't store it. + return $temppath; + } + } + + // Reaching this point means that the operating system is configured badly. + 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 App::directory_usable($spoolpath)) { + // We have a spool path and it is usable + return $spoolpath; + } + + // We don't have a working preconfigured spool path, so we take the temp path. + $temppath = get_temppath(); + + if ($temppath != "") { + // To avoid any interferences with other systems we create our own directory + $spoolpath = $temppath."/spool"; + if (!is_dir($spoolpath)) { + mkdir($spoolpath); + } + + if (App::directory_usable($spoolpath)) { + // The new path is usable, we are happy + set_config("system", "spoolpath", $spoolpath); + return $spoolpath; + } else { + // We can't create a subdirectory, strange. + // But the directory seems to work, so we use it but don't store it. + return $temppath; } } + + // Reaching this point means that the operating system is configured badly. return ""; } function get_temppath() { $a = get_app(); - $temppath = get_config("system","temppath"); - if (($temppath != "") AND is_dir($temppath) AND is_writable($temppath)) - return($temppath); + $temppath = get_config("system", "temppath"); + + if (($temppath != "") AND App::directory_usable($temppath)) { + // We have a temp path and it is usable + return $temppath; + } + // We don't have a working preconfigured temp path, so we take the system path. $temppath = sys_get_temp_dir(); - if (($temppath != "") AND is_dir($temppath) AND is_writable($temppath)) { - $temppath .= "/".$a->get_hostname(); - if (!is_dir($temppath)) - mkdir($temppath); - - if (is_dir($temppath) AND is_writable($temppath)) { - set_config("system", "temppath", $temppath); - return($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)) + mkdir($new_temppath); + + if (App::directory_usable($new_temppath)) { + // The new path is usable, we are happy + set_config("system", "temppath", $new_temppath); + return $new_temppath; + } else { + // We can't create a subdirectory, strange. + // But the directory seems to work, so we use it but don't store it. + return $temppath; } } - return(""); + // Reaching this point means that the operating system is configured badly. + return ''; } -function set_template_engine(&$a, $engine = 'internal') { +/// @deprecated +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