require_once('include/autoloader.php');
+use \Friendica\Core\Config;
+
require_once('include/config.php');
require_once('include/network.php');
require_once('include/plugin.php');
define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Asparagus');
-define ( 'FRIENDICA_VERSION', '3.5-dev' );
+define ( 'FRIENDICA_VERSION', '3.5.1-dev' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
-define ( 'DB_UPDATE_VERSION', 1199 );
+define ( 'DB_UPDATE_VERSION', 1214 );
/**
* @brief Constant with a HTML line break.
/**
* @brief Image storage quality.
- *
+ *
* Lower numbers save space at cost of image detail.
* For ease of upgrade, please do not change here. Change jpeg quality with
* $a->config['system']['jpeg_quality'] = n;
/**
* @name SSL Policy
- *
+ *
* SSL redirection policies
* @{
*/
/**
* @name Logger
- *
+ *
* log levels
* @{
*/
/**
* @name Cache
- *
+ *
* Cache levels
* @{
*/
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 );
/* @}*/
/**
* @name Register
- *
+ *
* Registration policies
* @{
*/
/**
* @name Contact_is
- *
+ *
* Relationship types
* @{
*/
/**
* @name Update
- *
+ *
* DB update return values
* @{
*/
define ( 'PAGE_PRVGROUP', 5 );
/** @}*/
+/**
+ * @name account types
+ *
+ * ACCOUNT_TYPE_PERSON - the account belongs to a person
+ * Associated page types: PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE
+ *
+ * ACCOUNT_TYPE_ORGANISATION - the account belongs to an organisation
+ * Associated page type: PAGE_SOAPBOX
+ *
+ * ACCOUNT_TYPE_NEWS - the account is a news reflector
+ * Associated page type: PAGE_SOAPBOX
+ *
+ * ACCOUNT_TYPE_COMMUNITY - the account is community forum
+ * Associated page types: PAGE_COMMUNITY, PAGE_PRVGROUP
+ * @{
+ */
+define ( 'ACCOUNT_TYPE_PERSON', 0 );
+define ( 'ACCOUNT_TYPE_ORGANISATION',1 );
+define ( 'ACCOUNT_TYPE_NEWS', 2 );
+define ( 'ACCOUNT_TYPE_COMMUNITY', 3 );
+/** @}*/
+
/**
* @name CP
- *
+ *
* Type of the community page
* @{
*/
/**
* @name Network
- *
+ *
* Network and protocol family types
* @{
*/
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
/** @}*/
NETWORK_APPNET => (-17),
NETWORK_NEWS => (-18),
NETWORK_ICALENDAR => (-19),
+ NETWORK_PNUT => (-20),
NETWORK_PHANTOM => (-127),
);
/**
* @name Notify
- *
+ *
* Email notification options
* @{
*/
/**
* @name Term
- *
+ *
* Tag/term types
* @{
*/
/**
* @name Namespaces
- *
+ *
* Various namespaces we may need to parse
* @{
*/
/**
* @name Activity
- *
+ *
* Activity stream defines
* @{
*/
/**
* @name Gravity
- *
+ *
* Item weight for query ordering
* @{
*/
* Process priority for the worker
* @{
*/
-define('PRIORITY_HIGH', 1);
-define('PRIORITY_MEDIUM', 2);
-define('PRIORITY_LOW', 3);
+define('PRIORITY_UNDEFINED', 0);
+define('PRIORITY_CRITICAL', 10);
+define('PRIORITY_HIGH', 20);
+define('PRIORITY_MEDIUM', 30);
+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"))
/**
*
* class: App
- *
+ *
* @brief Our main application structure for the life of this page.
- *
+ *
* Primarily deals with the URL that got us here
* and tries to make some sense of it, and
* stores our page contents and config storage
private $scheme;
private $hostname;
- private $baseurl;
private $db;
private $curl_code;
$this->performance["start"] = microtime(true);
$this->performance["database"] = 0;
+ $this->performance["database_write"] = 0;
$this->performance["network"] = 0;
$this->performance["file"] = 0;
$this->performance["rendering"] = 0;
$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();
#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
// 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);
+ }
/*
}
- function get_basepath() {
+ public static function get_basepath() {
$basepath = get_config("system", "basepath");
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() {
'$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,
} 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']);
/**
* @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;
+ }
}
/**
* @brief Register template engine class
- *
+ *
* If $name is "", is used class static property $class::$name
- *
+ *
* @param string $class
* @param string $name
*/
/**
* @brief Return template engine instance.
- *
+ *
* If $name is not defined, return engine defined by theme,
* or default
*
}
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])) {
}
+ /**
+ * @brief Log active processes into the "process" table
+ */
+ function start_process() {
+ $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
+
+ $command = basename($trace[0]["file"]);
+
+ $this->remove_inactive_processes();
+
+ q("START 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()));
+ }
+ 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)) {
+ q("DELETE FROM `process` WHERE `pid` = %d", intval($process["pid"]));
+ }
+ }
+ }
+ q("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 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());
}
*/
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');
*/
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'));
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')
+ 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")) {
+ $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
+ Cache::set($cachekey, time(), CACHE_MINUTE);
+ }
+
$args[0] = ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php');
+ }
// add baseurl to args. cli scripts can't construct it
$args[] = $this->get_baseurl();
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;
+ }
}
/**
* @brief Retrieve the App structure
- *
+ *
* Useful in functions which require it but don't get it passed to them
*/
function get_app() {
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;
}
* @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();
}
/**
$build = DB_UPDATE_VERSION;
}
if($build != DB_UPDATE_VERSION)
- proc_run(PRIORITY_HIGH, 'include/dbupdate.php');
+ proc_run(PRIORITY_CRITICAL, 'include/dbupdate.php');
}
* 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');
// 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;
}
/**
* @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);
$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.
* and mark it uninstalled in the database (for now we'll remove it).
* Then go through the config list and if we have a plugin that isn't installed,
* call the install procedure and add it to the database.
- *
+ *
* @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();
}
}
-/**
+/**
* @brief Wrapper for adding a login box.
- *
+ *
* @param bool $register
* If $register == true provide a registration link.
* This will most always depend on the value of $a->config['register_policy'].
* @param bool $hiddens
- *
+ *
* @return string
* Returns the complete html for inserting into the page
- *
+ *
* @hooks 'login_hook'
* string $o
*/
* @brief Used to end the current process, after saving session state.
*/
function killme() {
- session_write_close();
+
+ if (!get_app()->is_backend())
+ session_write_close();
+
exit;
}
/**
* @brief Returns the user id of locally logged in user or false.
- *
+ *
* @return int|bool user id or false
*/
function local_user() {
/**
* @brief Returns contact id of authenticated site visitor or false
- *
+ *
* @return int|bool visitor_id or false
*/
function remote_user() {
* @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 );
}
* @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 ""
- *
+ *
* @hooks 'proc_run'
* array $arr
*/
$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);
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);
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'");
$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'];
}
// $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 === '---') {
/**
* @brief Return full URL to theme which is currently in effect.
- *
+ *
* Provide a sane default if nothing is chosen or the specified theme does not exist.
- *
+ *
* @return string
*/
function current_theme_url() {
- global $a;
+ $a = get_app();
$t = current_theme();
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');
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();
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 "";
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
if (!is_array($load_arr))
return false;
- return max($load_arr);
+ return max($load_arr[0], $load_arr[1]);
}
/**
* @brief get c-style args
- *
+ *
* @return int
*/
function argc() {
/**
* @brief Returns the value of a argv key
- *
+ *
* @param int $x argv key
* @return string Value of the argv key
*/
/**
* @brief Get the data which is needed for infinite scroll
- *
+ *
* For invinite scroll we need the page number of the actual page
* and the the URI where the content of the next page comes from.
* This data is needed for the js part in main.js.
* Note: infinite scroll does only work for the network page (module)
- *
+ *
* @param string $module The name of the module (e.g. "network")
* @return array Of infinite scroll data
* 'pageno' => $pageno The number of the actual page