define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Asparagus');
-define ( 'FRIENDICA_VERSION', '3.5' );
+define ( 'FRIENDICA_VERSION', '3.5.1-dev' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
-define ( 'DB_UPDATE_VERSION', 1202 );
+define ( 'DB_UPDATE_VERSION', 1208 );
/**
* @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
* @{
*/
/**
* @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
* @{
*/
/**
*
* 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
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
+ *
+ * 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) {
// Is the function called statically?
- if (!is_object($this))
- return(self::$a->get_baseurl($ssl));
+ if (!is_object($this)) {
+ return self::$a->get_baseurl($ssl);
+ }
+
+ // Arbitrary values, the resulting url protocol can be different
+ $cache_index = $ssl ? 'https' : 'http';
+
+ // Cached value found, nothing to process
+ if (isset($this->baseurl[$cache_index])) {
+ return $this->baseurl[$cache_index];
+ }
$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))
+ if ((x($this->config, 'system')) && (x($this->config['system'], 'ssl_policy'))) {
+ if (intval($this->config['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.
- if($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) {
- if($ssl)
+ if ($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) {
+ if ($ssl) {
$scheme = 'https';
- else
+ } else {
$scheme = 'http';
+ }
}
}
- if (get_config('config','hostname') != "")
- $this->hostname = get_config('config','hostname');
+ if (get_config('config', 'hostname') != '') {
+ $this->hostname = get_config('config', 'hostname');
+ }
- $this->baseurl = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' );
- return $this->baseurl;
+ $this->baseurl[$cache_index] = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' );
+
+ return $this->baseurl[$cache_index];
}
+ /**
+ * @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;
+ $this->baseurl = [];
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() {
/**
* @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])) {
$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");
}
/**
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());
}
/**
* @brief Retrieve the App structure
- *
+ *
* Useful in functions which require it but don't get it passed to them
*/
function get_app() {
* 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
*
*/
}
}
-/**
+/**
* @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 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() {
* so plugins can take part in process :)
*
* @param (string|integer) $cmd program to run or priority
- *
+ *
* 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);
*
* @note $cmd and string args are surrounded with ""
- *
+ *
* @hooks 'proc_run'
* array $arr
*/
/**
* @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() {
/**
* @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