X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FApp.php;h=3e34d3c5a9e76c824e91f329d1c4afc69bd755a4;hb=0373056448aec398ee765065adc998aa0da02ac0;hp=aaaf6b24512ad721c10839f271c63a2d402cde87;hpb=fd5d058156185c6c02c1285a794139d07f4d13ce;p=friendica.git diff --git a/src/App.php b/src/App.php index aaaf6b2451..3e34d3c5a9 100644 --- a/src/App.php +++ b/src/App.php @@ -2,11 +2,13 @@ namespace Friendica; +use Friendica\Core\System; +use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Core\PConfig; +use Friendica\Database\DBM; -use Cache; -use dbm; +use dba; use Detection\MobileDetect; @@ -71,7 +73,6 @@ class App { public $videowidth = 425; public $videoheight = 350; public $force_max_items = 0; - public $theme_thread_allow = true; public $theme_events_in_profile = true; /** @@ -85,7 +86,6 @@ class App { 'videowidth' => 425, 'videoheight' => 350, 'force_max_items' => 0, - 'thread_allow' => true, 'stylesheet' => '', 'template_engine' => 'smarty3', ); @@ -100,6 +100,7 @@ class App { */ public $template_engine_instance = array(); public $process_id; + public $queue; private $ldelim = array( 'internal' => '', 'smarty3' => '{{' @@ -129,8 +130,14 @@ class App { $hostname = ''; - if (file_exists('.htpreconfig.php')) { - include '.htpreconfig.php'; + if (! static::directory_usable($basepath, false)) { + throw new Exception('Basepath ' . $basepath . ' isn\'t usable.'); + } + + $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR); + + if (file_exists($this->basepath.DIRECTORY_SEPARATOR.'.htpreconfig.php')) { + include $this->basepath.DIRECTORY_SEPARATOR.'.htpreconfig.php'; } $this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC'); @@ -198,17 +205,10 @@ class App { $this->hostname = $hostname; } - if (! static::directory_usable($basepath, false)) { - throw new Exception('Basepath ' . $basepath . ' isn\'t usable.'); - } - - $this->basepath = rtrim($basepath, DIRECTORY_SEPARATOR); - set_include_path( get_include_path() . PATH_SEPARATOR . $this->basepath . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR . $this->basepath . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR - . $this->basepath . DIRECTORY_SEPARATOR . 'library/langdet' . PATH_SEPARATOR . $this->basepath); @@ -293,7 +293,7 @@ class App { // Register template engines $dc = get_declared_classes(); foreach ($dc as $k) { - if (in_array('ITemplateEngine', class_implements($k))) { + if (in_array('Friendica\Render\ITemplateEngine', class_implements($k))) { $this->register_template_engine($k); } } @@ -326,7 +326,27 @@ class App { $basepath = $_SERVER['PWD']; } - return $basepath; + return self::realpath($basepath); + } + + /** + * @brief Returns a normalized file path + * + * This is a wrapper for the "realpath" function. + * That function cannot detect the real path when some folders aren't readable. + * Since this could happen with some hosters we need to handle this. + * + * @param string $path The path that is about to be normalized + * @return string normalized path - when possible + */ + public static function realpath($path) { + $normalized = realpath($path); + + if (!is_bool($normalized)) { + return $normalized; + } else { + return $path; + } } function get_scheme() { @@ -348,11 +368,6 @@ class App { * @return string Friendica server base URL */ function get_baseurl($ssl = false) { - // Is the function called statically? - if (!(isset($this) && get_class($this) == __CLASS__)) { - return self::$a->get_baseurl($ssl); - } - $scheme = $this->scheme; if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) { @@ -398,15 +413,15 @@ class App { $this->path = trim($parsed['path'], '\\/'); } - if (file_exists('.htpreconfig.php')) { - include '.htpreconfig.php'; + if (file_exists($this->basepath.DIRECTORY_SEPARATOR.'.htpreconfig.php')) { + include $this->basepath.DIRECTORY_SEPARATOR.'.htpreconfig.php'; } if (Config::get('config', 'hostname') != '') { $this->hostname = Config::get('config', 'hostname'); } - if (!isset($this->hostname) OR ( $this->hostname == '')) { + if (!isset($this->hostname) || ( $this->hostname == '')) { $this->hostname = $hostname; } } @@ -499,7 +514,7 @@ class App { $tpl = get_markup_template('head.tpl'); $this->page['htmlhead'] = replace_macros($tpl, array( - '$baseurl' => $this->get_baseurl(), // FIXME for z_path!!!! + '$baseurl' => $this->get_baseurl(), '$local_user' => local_user(), '$generator' => 'Friendica' . ' ' . FRIENDICA_VERSION, '$delitem' => t('Delete this item?'), @@ -519,7 +534,7 @@ class App { } $tpl = get_markup_template('end.tpl'); $this->page['end'] = replace_macros($tpl, array( - '$baseurl' => $this->get_baseurl() // FIXME for z_path!!!! + '$baseurl' => $this->get_baseurl() )) . $this->page['end']; } @@ -560,11 +575,6 @@ class App { */ function remove_baseurl($orig_url) { - // Is the function called statically? - if (!(isset($this) && get_class($this) == __CLASS__)) { - return self::$a->remove_baseurl($orig_url); - } - // Remove the hostname from the url if it is an internal link $nurl = normalise_link($orig_url); $base = normalise_link($this->get_baseurl()); @@ -671,7 +681,7 @@ class App { $this->performance[$value] += (float) $duration; $this->performance['marktime'] += (float) $duration; - $callstack = $this->callstack(); + $callstack = System::callstack(); if (!isset($this->callstack[$value][$callstack])) { // Prevent ugly E_NOTICE @@ -691,57 +701,37 @@ class App { $this->remove_inactive_processes(); - q('START TRANSACTION'); + dba::transaction(); $r = q('SELECT `pid` FROM `process` WHERE `pid` = %d', intval(getmypid())); - if (!dbm::is_result($r)) { - q("INSERT INTO `process` (`pid`,`command`,`created`) VALUES (%d, '%s', '%s')", intval(getmypid()), dbesc($command), dbesc(datetime_convert())); + if (!DBM::is_result($r)) { + dba::insert('process', array('pid' => getmypid(), 'command' => $command, 'created' => datetime_convert())); } - q('COMMIT'); + dba::commit(); } /** * @brief Remove inactive processes */ function remove_inactive_processes() { - q('START TRANSACTION'); + dba::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'])); + dba::delete('process', array('pid' => $process['pid'])); } } } - q('COMMIT'); + dba::commit(); } /** * @brief Remove the active process from the "process" table */ function end_process() { - q('DELETE FROM `process` WHERE `pid` = %d', intval(getmypid())); - } - - /** - * @brief Returns a string with a callstack. Can be used for logging. - * - * @return string - */ - function callstack($depth = 4) { - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $depth + 2); - - // We remove the first two items from the list since they contain data that we don't need. - array_shift($trace); - array_shift($trace); - - $callstack = array(); - foreach ($trace AS $func) { - $callstack[] = $func['function']; - } - - return implode(', ', $callstack); + dba::delete('process', array('pid' => getmypid())); } function get_useragent() { @@ -797,6 +787,8 @@ class App { * @return bool Is the limit reached? */ function max_processes_reached() { + // Deactivated, needs more investigating if this check really makes sense + return false; if ($this->is_backend()) { $process = 'backend'; @@ -812,7 +804,7 @@ class App { } } - $processlist = dbm::processlist(); + $processlist = DBM::processlist(); if ($processlist['list'] != '') { logger('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list'], LOGGER_DEBUG); @@ -848,7 +840,7 @@ class App { $meminfo[$key] = (int) ($meminfo[$key] / 1024); } - if (!isset($meminfo['MemAvailable']) OR ! isset($meminfo['MemFree'])) { + if (!isset($meminfo['MemAvailable']) || ! isset($meminfo['MemFree'])) { return false; } @@ -900,12 +892,12 @@ class App { return; } - // If the last worker fork was less than 10 seconds before then don't fork another one. + // If the last worker fork was less than 2 seconds before then don't fork another one. // This should prevent the forking of masses of workers. $cachekey = 'app:proc_run:started'; $result = Cache::get($cachekey); - if (!is_null($result) AND ( time() - $result) < 10) { + if (!is_null($result) && ( time() - $result) < 2) { return; } @@ -947,7 +939,7 @@ class App { * @return string system username */ static function systemuser() { - if (!function_exists('posix_getpwuid') OR ! function_exists('posix_geteuid')) { + if (!function_exists('posix_getpwuid') || ! function_exists('posix_geteuid')) { return ''; } @@ -978,7 +970,7 @@ class App { logger('Path "' . $directory . '" is not a directory for user ' . self::systemuser(), LOGGER_DEBUG); return false; } - if ($check_writable AND !is_writable($directory)) { + if ($check_writable && !is_writable($directory)) { logger('Path "' . $directory . '" is not writable for user ' . self::systemuser(), LOGGER_DEBUG); return false; }