mirror of
https://github.com/friendica/friendica
synced 2025-04-27 09:50:12 +00:00
Merge pull request #5905 from nupplaphil/move_global_functions
Move global functions
This commit is contained in:
commit
07da170bcf
8 changed files with 66 additions and 90 deletions
37
src/App.php
37
src/App.php
|
@ -110,6 +110,11 @@ class App
|
|||
*/
|
||||
private $currentTheme;
|
||||
|
||||
/**
|
||||
* @var bool check if request was an AJAX (xmlhttprequest) request
|
||||
*/
|
||||
private $isAjax;
|
||||
|
||||
/**
|
||||
* Register a stylesheet file path to be included in the <head> tag of every page.
|
||||
* Inclusion is done in App->initHead().
|
||||
|
@ -322,6 +327,8 @@ class App
|
|||
$this->is_mobile = $mobile_detect->isMobile();
|
||||
$this->is_tablet = $mobile_detect->isTablet();
|
||||
|
||||
$this->isAjax = strtolower(defaults($_SERVER, 'HTTP_X_REQUESTED_WITH', '')) == 'xmlhttprequest';
|
||||
|
||||
// Register template engines
|
||||
$this->registerTemplateEngine('Friendica\Render\FriendicaSmartyEngine');
|
||||
}
|
||||
|
@ -1221,7 +1228,7 @@ class App
|
|||
}
|
||||
}
|
||||
|
||||
$load = current_load();
|
||||
$load = System::currentLoad();
|
||||
if ($load) {
|
||||
if (intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' for ' . $process . ' tasks (' . $maxsysload . ') too high.');
|
||||
|
@ -1572,4 +1579,32 @@ class App
|
|||
{
|
||||
return Core\Theme::getStylesheetPath($this->getCurrentTheme());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if request was an AJAX (xmlhttprequest) request.
|
||||
*
|
||||
* @return boolean true if it was an AJAX request
|
||||
*/
|
||||
public function isAjax()
|
||||
{
|
||||
return $this->isAjax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a argv key
|
||||
* TODO there are a lot of $a->argv usages in combination with defaults() which can be replaced with this method
|
||||
*
|
||||
* @param int $position the position of the argument
|
||||
* @param mixed $default the default value if not found
|
||||
*
|
||||
* @return mixed returns the value of the argument
|
||||
*/
|
||||
public function getArgumentValue($position, $default = '')
|
||||
{
|
||||
if (array_key_exists($position, $this->argv)) {
|
||||
return $this->argv[$position];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -216,6 +216,26 @@ class System extends BaseObject
|
|||
return substr($trailer . uniqid('') . mt_rand(), 0, 26);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current Load of the System
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function currentLoad()
|
||||
{
|
||||
if (!function_exists('sys_getloadavg')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$load_arr = sys_getloadavg();
|
||||
|
||||
if (!is_array($load_arr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return max($load_arr[0], $load_arr[1]);
|
||||
}
|
||||
|
||||
/// @todo Move the following functions from boot.php
|
||||
/*
|
||||
function killme()
|
||||
|
@ -232,6 +252,5 @@ class System extends BaseObject
|
|||
function get_cachefile($file, $writemode = true)
|
||||
function get_itemcachepath()
|
||||
function get_spoolpath()
|
||||
function current_load()
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -618,7 +618,7 @@ class Worker
|
|||
$active = self::activeWorkers();
|
||||
|
||||
// Decrease the number of workers at higher load
|
||||
$load = current_load();
|
||||
$load = System::currentLoad();
|
||||
if ($load) {
|
||||
$maxsysload = intval(Config::get("system", "maxloadavg", 50));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue