return $return;
}
-/**
- * @brief Returns the baseurl.
- *
- * @see System::baseUrl()
- *
- * @return string
- * @TODO Function is deprecated and only used in some addons
- */
-function z_root()
-{
- return System::baseUrl();
-}
-
-/**
- * @brief Return absolut URL for given $path.
- *
- * @param string $path given path
- *
- * @return string
- */
-function absurl($path)
-{
- if (strpos($path, '/') === 0) {
- return z_path() . $path;
- }
- return $path;
-}
-
-/**
- * @brief Function to check if request was an AJAX (xmlhttprequest) request.
- *
- * @return boolean
- */
-function is_ajax()
-{
- return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
-}
-
/**
* @brief Function to check if request was an AJAX (xmlhttprequest) request.
*
return $valid;
}
-function current_load()
-{
- 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]);
-}
-
-/**
- * @brief get c-style args
- *
- * @return int
- */
-function argc()
-{
- return get_app()->argc;
-}
-
-/**
- * @brief Returns the value of a argv key
- *
- * @param int $x argv key
- * @return string Value of the argv key
- */
-function argv($x)
-{
- if (array_key_exists($x, get_app()->argv)) {
- return get_app()->argv[$x];
- }
-
- return '';
-}
-
/**
* @brief Get the data which is needed for infinite scroll
*
break;
case 'themes':
if ($a->argc < 2) {
- if (is_ajax()) {
+ if ($a->isAjax()) {
return;
}
goaway('admin/');
}
info(L10n::t('Theme settings updated.'));
- if (is_ajax()) {
+ if ($a->isAjax()) {
return;
}
$return_path = 'admin/themes/' . $theme;
$o = admin_page_summary($a);
}
- if (is_ajax()) {
+ if ($a->isAjax()) {
echo $o;
killme();
return '';
*/
function admin_page_features(App $a)
{
- if ((argc() > 1) && (argv(1) === 'features')) {
+ if (($a->argc > 1) && ($a->argv[1] === 'features')) {
$arr = [];
$features = Feature::get(false);
$path = '';
// looping through the argv keys bigger than 0 to build
// a path relative to /help
- for ($x = 1; $x < argc(); $x ++) {
+ for ($x = 1; $x < $a->argc; $x ++) {
if (strlen($path)) {
$path .= '/';
}
- $path .= argv($x);
+ $path .= $a->getArgumentValue($x);
}
$title = basename($path);
$filename = $path;
$o = '';
if (($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
- if (is_ajax()) {
+ if ($a->isAjax()) {
$o = Item::deleteForUser(['id' => $a->argv[2]], local_user());
} else {
$o = drop_item($a->argv[2]);
}
- if (is_ajax()) {
+ if ($a->isAjax()) {
// ajax return: [<item id>, 0 (no perm) | <owner id>]
echo json_encode([intval($a->argv[2]), intval($o)]);
killme();
$item = Item::selectFirst(['body'], ['uid' => local_user(), 'id' => $item_id]);
if (DBA::isResult($item)) {
- if (is_ajax()) {
+ if ($a->isAjax()) {
echo str_replace("\n", '<br />', $item['body']);
killme();
} else {
*/
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().
$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');
}
}
}
- $load = current_load();
+ $load = System::currentLoad();
if ($load) {
if (intval($load) > $maxsysload) {
logger('system: load ' . $load . ' for ' . $process . ' tasks (' . $maxsysload . ') too high.');
{
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;
+ }
}
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()
function get_cachefile($file, $writemode = true)
function get_itemcachepath()
function get_spoolpath()
- function current_load()
*/
}
$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));