define ( 'FRIENDICA_CODENAME', 'Asparagus');
define ( 'FRIENDICA_VERSION', '3.5.1-dev' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
-define ( 'DB_UPDATE_VERSION', 1207 );
+define ( 'DB_UPDATE_VERSION', 1208 );
/**
* @brief Constant with a HTML line break.
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 );
/* @}*/
/**
/**
* @brief Retrieves the Friendica instance base URL
*
- * Caches both SSL and non-SSL version for performance
+ * 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
*
- * @param bool $ssl
- * @return string
+ * Caches the result (depending on $ssl value) for performance.
+ *
+ * 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) {
return self::$a->get_baseurl($ssl);
}
- if (!isset($this->baseurl[$ssl ? 'https' : 'http'])) {
- $scheme = $this->scheme;
+ // Arbitrary values, the resulting url protocol can be different
+ $cache_index = $ssl ? 'https' : 'http';
- if ((x($this->config, 'system')) && (x($this->config['system'], 'ssl_policy'))) {
- if (intval($this->config['system']['ssl_policy']) === SSL_POLICY_FULL) {
- $scheme = 'https';
- }
+ // Cached value found, nothing to process
+ if (isset($this->baseurl[$cache_index])) {
+ return $this->baseurl[$cache_index];
+ }
- // 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.
+ $scheme = $this->scheme;
- if ($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) {
- if ($ssl) {
- $scheme = 'https';
- } else {
- $scheme = 'http';
- }
- }
+ if ((x($this->config, 'system')) && (x($this->config['system'], 'ssl_policy'))) {
+ if (intval($this->config['system']['ssl_policy']) === SSL_POLICY_FULL) {
+ $scheme = 'https';
}
- if (get_config('config', 'hostname') != '') {
- $this->hostname = get_config('config', 'hostname');
+ // 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';
+ }
}
+ }
- $this->baseurl[$ssl ? 'https' : 'http'] = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' );
+ if (get_config('config', 'hostname') != '') {
+ $this->hostname = get_config('config', 'hostname');
}
- return $this->baseurl[$ssl ? 'https' : 'http'];
+
+ $this->baseurl[$cache_index] = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' );
+
+ return $this->baseurl[$cache_index];
}
/**
$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");
}
/**