diff --git a/boot.php b/boot.php
index 45029fecd..5815b8db1 100644
--- a/boot.php
+++ b/boot.php
@@ -1,4 +1,5 @@
\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
-
/**
* @brief Image storage quality.
*
@@ -61,8 +62,8 @@ define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
* below about 50
*
*/
-
define ( 'JPEG_QUALITY', 100 );
+
/**
* $a->config['system']['png_quality'] from 0 (uncompressed) to 9
*/
@@ -86,12 +87,10 @@ define ( 'PNG_QUALITY', 8 );
*/
define ( 'MAX_IMAGE_LENGTH', -1 );
-
/**
* Not yet used
*/
-
-define ( 'DEFAULT_DB_ENGINE', 'MyISAM' );
+define ( 'DEFAULT_DB_ENGINE', 'InnoDB' );
/**
* @name SSL Policy
@@ -165,7 +164,6 @@ define ( 'UPDATE_SUCCESS', 0);
define ( 'UPDATE_FAILED', 1);
/** @}*/
-
/**
* @name page/profile types
*
@@ -291,20 +289,16 @@ $netgroup_ids = array(
NETWORK_PHANTOM => (-127),
);
-
/**
* Maximum number of "people who like (or don't like) this" that we will list by name
*/
-
define ( 'MAX_LIKERS', 75);
/**
* Communication timeout
*/
-
define ( 'ZCURL_TIMEOUT' , (-1));
-
/**
* @name Notify
*
@@ -345,8 +339,6 @@ define ( 'TERM_CONVERSATION', 7 );
define ( 'TERM_OBJ_POST', 1 );
define ( 'TERM_OBJ_PHOTO', 2 );
-
-
/**
* @name Namespaces
*
@@ -458,14 +450,13 @@ define('SR_SCOPE_TAGS', 'tags');
/**
* Lowest possible date time value
*/
-
define ('NULL_DATE', '0001-01-01 00:00:00');
-
// Normally this constant is defined - but not if "pcntl" isn't installed
if (!defined("SIGTERM")) {
define("SIGTERM", 15);
}
+
/**
*
* Reverse the effect of magic_quotes_gpc if it is enabled.
@@ -473,9 +464,7 @@ if (!defined("SIGTERM")) {
* See http://php.net/manual/en/security.magicquotes.disabling.php
*
*/
-
function startup() {
-
error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_time_limit(0);
@@ -483,7 +472,6 @@ function startup() {
// This has to be quite large to deal with embedded private photos
ini_set('pcre.backtrack_limit', 500000);
-
if (get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
while (list($key, $val) = each($process)) {
@@ -499,989 +487,6 @@ function startup() {
}
unset($process);
}
-
-}
-
-/**
- *
- * 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
- * and anything else that might need to be passed around
- * before we spit the page out.
- *
- */
-class App {
-
- /// @TODO decide indending as a colorful mixure is ahead ...
- public $module_loaded = false;
- public $query_string;
- public $config;
- public $page;
- public $profile;
- public $profile_uid;
- public $user;
- public $cid;
- public $contact;
- public $contacts;
- public $page_contact;
- public $content;
- public $data = array();
- public $error = false;
- public $cmd;
- public $argv;
- public $argc;
- public $module;
- public $pager;
- public $strings;
- public $path;
- public $hooks;
- public $timezone;
- public $interactive = true;
- public $plugins;
- public $apps = array();
- public $identities;
- public $is_mobile = false;
- public $is_tablet = false;
- public $is_friendica_app;
- public $performance = array();
- public $callstack = array();
- public $theme_info = array();
- public $backend = true;
-
- public $nav_sel;
-
- public $category;
-
-
- // Allow themes to control internal parameters
- // by changing App values in theme.php
-
- public $sourcename = '';
- public $videowidth = 425;
- public $videoheight = 350;
- public $force_max_items = 0;
- public $theme_thread_allow = true;
- public $theme_events_in_profile = true;
-
- /**
- * @brief An array for all theme-controllable parameters
- *
- * Mostly unimplemented yet. Only options 'template_engine' and
- * beyond are used.
- */
- public $theme = array(
- 'sourcename' => '',
- 'videowidth' => 425,
- 'videoheight' => 350,
- 'force_max_items' => 0,
- 'thread_allow' => true,
- 'stylesheet' => '',
- 'template_engine' => 'smarty3',
- );
-
- /**
- * @brief An array of registered template engines ('name'=>'class name')
- */
- public $template_engines = array();
- /**
- * @brief An array of instanced template engines ('name'=>'instance')
- */
- public $template_engine_instance = array();
-
- public $process_id;
-
- private $ldelim = array(
- 'internal' => '',
- 'smarty3' => '{{'
- );
- private $rdelim = array(
- 'internal' => '',
- 'smarty3' => '}}'
- );
-
- private $scheme;
- private $hostname;
- private $db;
-
- private $curl_code;
- private $curl_content_type;
- private $curl_headers;
-
- private $cached_profile_image;
- private $cached_profile_picdate;
-
- private static $a;
-
- /**
- * @brief App constructor.
- */
- function __construct() {
-
- global $default_timezone;
-
- $hostname = "";
-
- if (file_exists(".htpreconfig.php")) {
- include ".htpreconfig.php";
- }
-
- $this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
-
- date_default_timezone_set($this->timezone);
-
- $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["parser"] = 0;
- $this->performance["marktime"] = 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();
- $this->callstack["parser"] = array();
-
- $this->config = array();
- $this->page = array();
- $this->pager= array();
-
- $this->query_string = '';
-
- $this->process_id = uniqid("log", true);
-
- startup();
-
- set_include_path(
- get_include_path() . PATH_SEPARATOR
- . 'include' . PATH_SEPARATOR
- . 'library' . PATH_SEPARATOR
- . 'library/langdet' . PATH_SEPARATOR
- . '.' );
-
- $this->scheme = 'http';
-
- if ((x($_SERVER, 'HTTPS') && $_SERVER['HTTPS']) ||
- (x($_SERVER, 'HTTP_FORWARDED') && preg_match("/proto=https/", $_SERVER['HTTP_FORWARDED'])) ||
- (x($_SERVER, 'HTTP_X_FORWARDED_PROTO') && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') ||
- (x($_SERVER, 'HTTP_X_FORWARDED_SSL') && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') ||
- (x($_SERVER, 'FRONT_END_HTTPS') && $_SERVER['FRONT_END_HTTPS'] == 'on') ||
- (x($_SERVER, 'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) // XXX: reasonable assumption, but isn't this hardcoding too much?
- ) {
- $this->scheme = 'https';
- }
-
- if (x($_SERVER, 'SERVER_NAME')) {
- $this->hostname = $_SERVER['SERVER_NAME'];
-
- if (x($_SERVER, 'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
- $this->hostname .= ':' . $_SERVER['SERVER_PORT'];
- }
- /*
- * Figure out if we are running at the top of a domain
- * or in a sub-directory and adjust accordingly
- */
-
- /// @TODO This kind of escaping breaks syntax-highlightning on CoolEdit (Midnight Commander)
- $path = trim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
- if (isset($path) && strlen($path) && ($path != $this->path)) {
- $this->path = $path;
- }
- }
-
- if ($hostname != "") {
- $this->hostname = $hostname;
- }
-
- if (is_array($_SERVER["argv"]) && $_SERVER["argc"] > 1 && substr(end($_SERVER["argv"]), 0, 4) == "http" ) {
- $this->set_baseurl(array_pop($_SERVER["argv"]));
- $_SERVER["argc"] --;
- }
-
- 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
- $this->query_string = ltrim($this->query_string, '/');
- } 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
- $this->query_string = ltrim($this->query_string, '/');
- }
-
- if (x($_GET, 'pagename')) {
- $this->cmd = trim($_GET['pagename'], '/\\');
- } elseif (x($_GET, 'q')) {
- $this->cmd = trim($_GET['q'], '/\\');
- }
-
-
- // fix query_string
- $this->query_string = str_replace($this->cmd . "&", $this->cmd . "?", $this->query_string);
-
- // unix style "homedir"
- if (substr($this->cmd, 0, 1) === '~') {
- $this->cmd = 'profile/' . substr($this->cmd, 1);
- }
-
- // Diaspora style profile url
- if (substr($this->cmd, 0, 2) === 'u/') {
- $this->cmd = 'profile/' . substr($this->cmd, 2);
- }
-
-
- /*
- * Break the URL path into C style argc/argv style arguments for our
- * modules. Given "http://example.com/module/arg1/arg2", $this->argc
- * will be 3 (integer) and $this->argv will contain:
- * [0] => 'module'
- * [1] => 'arg1'
- * [2] => 'arg2'
- *
- *
- * There will always be one argument. If provided a naked domain
- * URL, $this->argv[0] is set to "home".
- */
-
- $this->argv = explode('/', $this->cmd);
- $this->argc = count($this->argv);
- if ((array_key_exists('0', $this->argv)) && strlen($this->argv[0])) {
- $this->module = str_replace(".", "_", $this->argv[0]);
- $this->module = str_replace("-", "_", $this->module);
- } else {
- $this->argc = 1;
- $this->argv = array('home');
- $this->module = 'home';
- }
-
- /*
- * See if there is any page number information, and initialise
- * pagination
- */
-
- $this->pager['page'] = ((x($_GET, 'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1);
- $this->pager['itemspage'] = 50;
- $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
-
- if ($this->pager['start'] < 0) {
- $this->pager['start'] = 0;
- }
- $this->pager['total'] = 0;
-
- /*
- * Detect mobile devices
- */
-
- $mobile_detect = new Mobile_Detect();
- $this->is_mobile = $mobile_detect->isMobile();
- $this->is_tablet = $mobile_detect->isTablet();
-
- // Friendica-Client
- $this->is_friendica_app = ($_SERVER['HTTP_USER_AGENT'] == "Apache-HttpClient/UNAVAILABLE (java 1.4)");
-
- /*
- * register template engines
- */
- $dc = get_declared_classes();
- foreach ($dc as $k) {
- if (in_array("ITemplateEngine", class_implements($k))){
- $this->register_template_engine($k);
- }
- }
-
- self::$a = $this;
-
- }
-
- public static function get_basepath() {
-
- $basepath = get_config("system", "basepath");
-
- if ($basepath == "") {
- $basepath = dirname(__FILE__);
- }
-
- if ($basepath == "") {
- $basepath = $_SERVER["DOCUMENT_ROOT"];
- }
-
- if ($basepath == "") {
- $basepath = $_SERVER["PWD"];
- }
-
- return $basepath;
- }
-
- function get_scheme() {
- 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 (!(isset($this) && get_class($this) == __CLASS__)) {
- return self::$a->get_baseurl($ssl);
- }
-
- $scheme = $this->scheme;
-
- 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.
-
- if (Config::get('system', 'ssl_policy') == SSL_POLICY_SELFSIGN) {
- if ($ssl) {
- $scheme = 'https';
- } else {
- $scheme = 'http';
- }
- }
-
- if (Config::get('config', 'hostname') != '') {
- $this->hostname = Config::get('config', 'hostname');
- }
-
- 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);
-
- if ($parsed) {
- $this->scheme = $parsed['scheme'];
-
- $hostname = $parsed['host'];
- if (x($parsed, 'port')) {
- $hostname .= ':' . $parsed['port'];
- }
- if (x($parsed, 'path')) {
- $this->path = trim($parsed['path'], '\\/');
- }
-
- if (file_exists(".htpreconfig.php")) {
- include ".htpreconfig.php";
- }
-
- if (get_config('config', 'hostname') != '') {
- $this->hostname = get_config('config', 'hostname');
- }
-
- if (!isset($this->hostname) OR ($this->hostname == '')) {
- $this->hostname = $hostname;
- }
- }
- }
-
- function get_hostname() {
- if (get_config('config', 'hostname') != "") {
- $this->hostname = get_config('config', 'hostname');
- }
-
- return $this->hostname;
- }
-
- function set_hostname($h) {
- $this->hostname = $h;
- }
-
- function set_path($p) {
- $this->path = trim(trim($p), '/');
- }
-
- function get_path() {
- return $this->path;
- }
-
- function set_pager_total($n) {
- $this->pager['total'] = intval($n);
- }
-
- function set_pager_itemspage($n) {
- $this->pager['itemspage'] = ((intval($n) > 0) ? intval($n) : 0);
- $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
- }
-
- function set_pager_page($n) {
- $this->pager['page'] = $n;
- $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
- }
-
- function init_pagehead() {
- $interval = ((local_user()) ? get_pconfig(local_user(),'system','update_interval') : 40000);
-
- // If the update is "deactivated" set it to the highest integer number (~24 days)
- if ($interval < 0) {
- $interval = 2147483647;
- }
-
- if ($interval < 10000) {
- $interval = 40000;
- }
-
- // compose the page title from the sitename and the
- // current module called
- if (!$this->module == '') {
- $this->page['title'] = $this->config['sitename'] . ' (' . $this->module . ')';
- } else {
- $this->page['title'] = $this->config['sitename'];
- }
-
- /* put the head template at the beginning of page['htmlhead']
- * since the code added by the modules frequently depends on it
- * being first
- */
- if (!isset($this->page['htmlhead'])) {
- $this->page['htmlhead'] = '';
- }
-
- // If we're using Smarty, then doing replace_macros() will replace
- // any unrecognized variables with a blank string. Since we delay
- // replacing $stylesheet until later, we need to replace it now
- // with another variable name
- if ($this->theme['template_engine'] === 'smarty3') {
- $stylesheet = $this->get_template_ldelim('smarty3') . '$stylesheet' . $this->get_template_rdelim('smarty3');
- } else {
- $stylesheet = '$stylesheet';
- }
-
- $shortcut_icon = get_config("system", "shortcut_icon");
- if ($shortcut_icon == "") {
- $shortcut_icon = "images/friendica-32.png";
- }
-
- $touch_icon = get_config("system", "touch_icon");
- if ($touch_icon == "") {
- $touch_icon = "images/friendica-128.png";
- }
-
- // get data wich is needed for infinite scroll on the network page
- $invinite_scroll = infinite_scroll_data($this->module);
-
- $tpl = get_markup_template('head.tpl');
- $this->page['htmlhead'] = replace_macros($tpl,array(
- '$baseurl' => $this->get_baseurl(), // FIXME for z_path!!!!
- '$local_user' => local_user(),
- '$generator' => 'Friendica' . ' ' . FRIENDICA_VERSION,
- '$delitem' => t('Delete this item?'),
- '$showmore' => t('show more'),
- '$showfewer' => t('show fewer'),
- '$update_interval' => $interval,
- '$shortcut_icon' => $shortcut_icon,
- '$touch_icon' => $touch_icon,
- '$stylesheet' => $stylesheet,
- '$infinite_scroll' => $invinite_scroll,
- )) . $this->page['htmlhead'];
- }
-
- function init_page_end() {
- if (!isset($this->page['end'])) {
- $this->page['end'] = '';
- }
- $tpl = get_markup_template('end.tpl');
- $this->page['end'] = replace_macros($tpl,array(
- '$baseurl' => $this->get_baseurl() // FIXME for z_path!!!!
- )) . $this->page['end'];
- }
-
- function set_curl_code($code) {
- $this->curl_code = $code;
- }
-
- function get_curl_code() {
- return $this->curl_code;
- }
-
- function set_curl_content_type($content_type) {
- $this->curl_content_type = $content_type;
- }
-
- function get_curl_content_type() {
- return $this->curl_content_type;
- }
-
- function set_curl_headers($headers) {
- $this->curl_headers = $headers;
- }
-
- function get_curl_headers() {
- return $this->curl_headers;
- }
-
- function get_cached_avatar_image($avatar_image){
- return $avatar_image;
- }
-
-
- /**
- * @brief Removes the baseurl from an url. This avoids some mixed content problems.
- *
- * @param string $orig_url
- *
- * @return string The cleaned url
- */
- function remove_baseurl($orig_url){
-
- // Is the function called statically?
- if (!(isset($this) && get_class($this) == __CLASS__)) {
- return self::$a->remove_baseurl($orig_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."/", "", $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
- */
- function register_template_engine($class, $name = '') {
- /// @TODO Really === and not just == ?
- if ($name === "") {
- $v = get_class_vars( $class );
- if (x($v,"name")) $name = $v['name'];
- }
- if ($name === "") {
- echo "template engine $class cannot be registered without a name.\n";
- killme();
- }
- $this->template_engines[$name] = $class;
- }
-
- /**
- * @brief Return template engine instance.
- *
- * If $name is not defined, return engine defined by theme,
- * or default
- *
- * @param strin $name Template engine name
- * @return object Template Engine instance
- */
- function template_engine($name = '') {
- /// @TODO really type-check included?
- if ($name !== "") {
- $template_engine = $name;
- } else {
- $template_engine = 'smarty3';
- if (x($this->theme, 'template_engine')) {
- $template_engine = $this->theme['template_engine'];
- }
- }
-
- if (isset($this->template_engines[$template_engine])){
- if (isset($this->template_engine_instance[$template_engine])){
- return $this->template_engine_instance[$template_engine];
- } else {
- $class = $this->template_engines[$template_engine];
- $obj = new $class;
- $this->template_engine_instance[$template_engine] = $obj;
- return $obj;
- }
- }
-
- echo "template engine $template_engine is not registered!\n"; killme();
- }
-
- /**
- * @brief Returns the active template engine.
- *
- * @return string
- */
- function get_template_engine() {
- return $this->theme['template_engine'];
- }
-
- function set_template_engine($engine = 'smarty3') {
- $this->theme['template_engine'] = $engine;
- }
-
- function get_template_ldelim($engine = 'smarty3') {
- return $this->ldelim[$engine];
- }
-
- function get_template_rdelim($engine = 'smarty3') {
- return $this->rdelim[$engine];
- }
-
- 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])) {
- // Prevent ugly E_NOTICE
- $this->performance[$value] = 0;
- }
-
- $this->performance[$value] += (float)$duration;
- $this->performance["marktime"] += (float)$duration;
-
- $callstack = $this->callstack();
-
- if (!isset($this->callstack[$value][$callstack])) {
- // Prevent ugly E_NOTICE
- $this->callstack[$value][$callstack] = 0;
- }
-
- $this->callstack[$value][$callstack] += (float)$duration;
-
- }
-
- /**
- * @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 string
- */
- function callstack() {
- $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6);
-
- // We remove the first two items from the list since they contain data that we don't need.
- array_shift($trace);
- array_shift($trace);
-
- $callstack = array();
- foreach ($trace AS $func) {
- $callstack[] = $func["function"];
- }
-
- return implode(", ", $callstack);
- }
-
- function get_useragent() {
- return
- FRIENDICA_PLATFORM . " '" .
- FRIENDICA_CODENAME . "' " .
- FRIENDICA_VERSION . "-" .
- DB_UPDATE_VERSION . "; " .
- $this->get_baseurl();
- }
-
- function is_friendica_app() {
- return $this->is_friendica_app;
- }
-
- /**
- * @brief Checks if the site is called via a backend process
- *
- * This isn't a perfect solution. But we need this check very early.
- * So we cannot wait until the modules are loaded.
- *
- * @return bool Is it a known backend?
- */
- function is_backend() {
- static $backends = array();
- $backends[] = "_well_known";
- $backends[] = "api";
- $backends[] = "dfrn_notify";
- $backends[] = "fetch";
- $backends[] = "hcard";
- $backends[] = "hostxrd";
- $backends[] = "nodeinfo";
- $backends[] = "noscrape";
- $backends[] = "p";
- $backends[] = "poco";
- $backends[] = "post";
- $backends[] = "proxy";
- $backends[] = "pubsub";
- $backends[] = "pubsubhubbub";
- $backends[] = "receive";
- $backends[] = "rsd_xml";
- $backends[] = "salmon";
- $backends[] = "statistics_json";
- $backends[] = "xrd";
-
- // Check if current module is in backend or backend flag is set
- return (in_array($this->module, $backends) || $this->backend);
- }
-
- /**
- * @brief Checks if the maximum number of database processes is reached
- *
- * @return bool Is the limit reached?
- */
- function max_processes_reached() {
-
- if ($this->is_backend()) {
- $process = "backend";
- $max_processes = get_config('system', 'max_processes_backend');
- if (intval($max_processes) == 0) {
- $max_processes = 5;
- }
- } else {
- $process = "frontend";
- $max_processes = get_config('system', 'max_processes_frontend');
- if (intval($max_processes) == 0) {
- $max_processes = 20;
- }
- }
-
- $processlist = dbm::processlist();
- if ($processlist["list"] != "") {
- logger("Processcheck: Processes: ".$processlist["amount"]." - Processlist: ".$processlist["list"], LOGGER_DEBUG);
-
- if ($processlist["amount"] > $max_processes) {
- logger("Processcheck: Maximum number of processes for ".$process." tasks (".$max_processes.") reached.", LOGGER_DEBUG);
- return true;
- }
- }
- return false;
- }
-
- /**
- * @brief Checks if the minimal memory is reached
- *
- * @return bool Is the memory limit reached?
- */
- public function min_memory_reached() {
- $min_memory = Config::get('system', 'min_memory', 0);
- if ($min_memory == 0) {
- return false;
- }
-
- if (!is_readable("/proc/meminfo")) {
- return false;
- }
-
- $memdata = explode("\n", file_get_contents('/proc/meminfo'));
-
- $meminfo = array();
- foreach ($memdata as $line) {
- list($key, $val) = explode(":", $line);
- $meminfo[$key] = (int)trim(str_replace("kB", "", $val));
- $meminfo[$key] = (int)($meminfo[$key] / 1024);
- }
-
- if (!isset($meminfo['MemAvailable']) OR !isset($meminfo['MemFree'])) {
- return false;
- }
-
- $free = $meminfo['MemAvailable'] + $meminfo['MemFree'];
-
- $reached = ($free < $min_memory);
-
- if ($reached) {
- logger('Minimal memory reached: '.$free.'/'.$meminfo['MemTotal'].' - limit '.$min_memory, LOGGER_DEBUG);
- }
-
- return $reached;
- }
-
- /**
- * @brief Checks if the maximum load is reached
- *
- * @return bool Is the load reached?
- */
- function maxload_reached() {
-
- if ($this->is_backend()) {
- $process = "backend";
- $maxsysload = intval(get_config('system', 'maxloadavg'));
- if ($maxsysload < 1) {
- $maxsysload = 50;
- }
- } else {
- $process = "frontend";
- $maxsysload = intval(get_config('system','maxloadavg_frontend'));
- if ($maxsysload < 1) {
- $maxsysload = 50;
- }
- }
-
- $load = current_load();
- if ($load) {
- if (intval($load) > $maxsysload) {
- logger('system: load '.$load.' for '.$process.' tasks ('.$maxsysload.') too high.');
- return true;
- }
- }
- return false;
- }
-
- function proc_run($args) {
-
- if (!function_exists("proc_open")) {
- return;
- }
-
- // 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.
- $cachekey = "app:proc_run:started";
- $result = Cache::get($cachekey);
-
- if (!is_null($result) AND (time() - $result) < 10) {
- return;
- }
-
- // Set the timestamp of the last proc_run
- Cache::set($cachekey, time(), CACHE_MINUTE);
-
- array_unshift($args, ((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();
-
- for ($x = 0; $x < count($args); $x ++) {
- $args[$x] = escapeshellarg($args[$x]);
- }
-
- $cmdline = implode($args, " ");
-
- if ($this->min_memory_reached()) {
- return;
- }
-
- if (get_config('system', 'proc_windows')) {
- $resource = proc_open('cmd /c start /b ' . $cmdline, array(), $foo, dirname(__FILE__));
- } else {
- $resource = proc_open($cmdline . " &", array(), $foo, dirname(__FILE__));
- }
- if (!is_resource($resource)) {
- logger('We got no resource for command '.$cmdline, LOGGER_DEBUG);
- return;
- }
- proc_close($resource);
- }
-
- /**
- * @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;
- }
}
/**
@@ -1494,7 +499,6 @@ function get_app() {
return $a;
}
-
/**
* @brief Multi-purpose function to check variable state.
*
@@ -1509,7 +513,7 @@ function get_app() {
*
* @return bool|int
*/
-function x($s,$k = NULL) {
+function x($s, $k = NULL) {
if ($k != NULL) {
if ((is_array($s)) && (array_key_exists($k, $s))) {
if ($s[$k]) {
@@ -1529,7 +533,6 @@ function x($s,$k = NULL) {
}
}
-
/**
* @brief Called from db initialisation if db is dead.
*/
@@ -1539,7 +542,6 @@ function system_unavailable() {
killme();
}
-
function clean_urls() {
$a = get_app();
return true;
@@ -1548,7 +550,7 @@ function clean_urls() {
function z_path() {
$base = App::get_baseurl();
- if (! clean_urls()) {
+ if (!clean_urls()) {
$base .= '/?q=';
}
@@ -1575,7 +577,7 @@ function z_root() {
* @return string
*/
function absurl($path) {
- if (strpos($path,'/') === 0) {
+ if (strpos($path, '/') === 0) {
return z_path() . $path;
}
return $path;
@@ -1592,25 +594,23 @@ function is_ajax() {
function check_db() {
- $build = get_config('system','build');
- if (! x($build)) {
- set_config('system','build',DB_UPDATE_VERSION);
+ $build = get_config('system', 'build');
+ if (!x($build)) {
+ set_config('system', 'build', DB_UPDATE_VERSION);
$build = DB_UPDATE_VERSION;
}
if ($build != DB_UPDATE_VERSION) {
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(App $a) {
- $url = get_config('system','url');
+ $url = get_config('system', 'url');
// if the url isn't set or the stored url is radically different
// than the currently visited url, store the current value accordingly.
@@ -1618,24 +618,23 @@ function check_url(App $a) {
// and www.example.com vs example.com.
// We will only change the url to an ip address if there is no existing setting
- if (! x($url)) {
- $url = set_config('system','url',App::get_baseurl());
+ if (!x($url)) {
+ $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());
+ 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(App $a) {
- $build = get_config('system','build');
- if (! x($build)) {
- $build = set_config('system','build',DB_UPDATE_VERSION);
+ $build = get_config('system', 'build');
+ if (!x($build)) {
+ $build = set_config('system', 'build', DB_UPDATE_VERSION);
}
if ($build != DB_UPDATE_VERSION) {
@@ -1646,7 +645,6 @@ function update_db(App $a) {
// We're reporting a different version than what is currently installed.
// Run any existing update scripts to bring the database up to current.
-
// make sure that boot.php and update.php are the same release, we might be
// updating right this very second and the correct version of the update.php
// file may not be here yet. This can happen on a very busy site.
@@ -1654,12 +652,12 @@ function update_db(App $a) {
if (DB_UPDATE_VERSION == UPDATE_VERSION) {
// Compare the current structure with the defined structure
- $t = get_config('database','dbupdate_'.DB_UPDATE_VERSION);
+ $t = get_config('database', 'dbupdate_' . DB_UPDATE_VERSION);
if ($t !== false) {
return;
}
- set_config('database','dbupdate_'.DB_UPDATE_VERSION, time());
+ set_config('database', 'dbupdate_' . DB_UPDATE_VERSION, time());
// run old update routine (wich could modify the schema and
// conflits with new routine)
@@ -1683,7 +681,7 @@ function update_db(App $a) {
);
return;
} else {
- set_config('database','dbupdate_'.DB_UPDATE_VERSION, 'success');
+ set_config('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success');
}
// run any left update_nnnn functions in update.php
@@ -1707,15 +705,14 @@ function run_update_function($x) {
// We want exactly one process to run the update command.
// So store the fact that we're taking responsibility
// after first checking to see if somebody else already has.
-
// If the update fails or times-out completely you may need to
// delete the config entry to try again.
- $t = get_config('database','update_' . $x);
+ $t = get_config('database', 'update_' . $x);
if ($t !== false) {
return false;
}
- set_config('database','update_' . $x, time());
+ set_config('database', 'update_' . $x, time());
// call the specific update
@@ -1730,13 +727,13 @@ function run_update_function($x) {
);
return false;
} else {
- set_config('database','update_' . $x, 'success');
- set_config('system','build', $x + 1);
+ set_config('database', 'update_' . $x, 'success');
+ set_config('system', 'build', $x + 1);
return true;
}
} else {
- set_config('database','update_' . $x, 'success');
- set_config('system','build', $x + 1);
+ set_config('database', 'update_' . $x, 'success');
+ set_config('system', 'build', $x + 1);
return true;
}
return true;
@@ -1765,11 +762,11 @@ function check_plugins(App $a) {
$installed = array();
}
- $plugins = get_config('system','addon');
+ $plugins = get_config('system', 'addon');
$plugins_arr = array();
if ($plugins) {
- $plugins_arr = explode(',',str_replace(' ', '',$plugins));
+ $plugins_arr = explode(',', str_replace(' ', '', $plugins));
}
$a->plugins = $plugins_arr;
@@ -1778,7 +775,7 @@ function check_plugins(App $a) {
if (count($installed)) {
foreach ($installed as $i) {
- if (! in_array($i['name'],$plugins_arr)) {
+ if (!in_array($i['name'], $plugins_arr)) {
uninstall_plugin($i['name']);
} else {
$installed_arr[] = $i['name'];
@@ -1788,20 +785,18 @@ function check_plugins(App $a) {
if (count($plugins_arr)) {
foreach ($plugins_arr as $p) {
- if (! in_array($p,$installed_arr)) {
+ if (!in_array($p, $installed_arr)) {
install_plugin($p);
}
}
}
-
load_hooks();
return;
}
-function get_guid($size=16, $prefix = "") {
-
+function get_guid($size = 16, $prefix = "") {
if ($prefix == "") {
$a = get_app();
$prefix = hash("crc32", $a->get_hostname());
@@ -1834,7 +829,7 @@ function get_guid($size=16, $prefix = "") {
* @hooks 'login_hook'
* string $o
*/
-function login($register = false, $hiddens=false) {
+function login($register = false, $hiddens = false) {
$a = get_app();
$o = "";
$reg = false;
@@ -1845,14 +840,14 @@ function login($register = false, $hiddens=false) {
);
}
- $noid = get_config('system','no_openid');
+ $noid = get_config('system', 'no_openid');
$dest_url = $a->query_string;
if (local_user()) {
$tpl = get_markup_template("logout.tpl");
} else {
- $a->page['htmlhead'] .= replace_macros(get_markup_template("login_head.tpl"),array(
+ $a->page['htmlhead'] .= replace_macros(get_markup_template("login_head.tpl"), array(
'$baseurl' => $a->get_baseurl(true)
));
@@ -1886,10 +881,9 @@ function login($register = false, $hiddens=false) {
'$privacytitle' => t('Website Privacy Policy'),
'$privacylink' => t('privacy policy'),
-
));
- call_hooks('login_hook',$o);
+ call_hooks('login_hook', $o);
return $o;
}
@@ -1898,7 +892,6 @@ function login($register = false, $hiddens=false) {
* @brief Used to end the current process, after saving session state.
*/
function killme() {
-
if (!get_app()->is_backend()) {
session_write_close();
}
@@ -1911,14 +904,13 @@ function killme() {
*/
function goaway($s) {
if (!strstr(normalise_link($s), "http://")) {
- $s = App::get_baseurl()."/".$s;
+ $s = App::get_baseurl() . "/" . $s;
}
header("Location: $s");
killme();
}
-
/**
* @brief Returns the user id of locally logged in user or false.
*
@@ -1960,7 +952,7 @@ function public_contact() {
* @return int|bool visitor_id or false
*/
function remote_user() {
- if ((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id'))) {
+ if ((x($_SESSION, 'authenticated')) && (x($_SESSION, 'visitor_id'))) {
return intval($_SESSION['visitor_id']);
}
return false;
@@ -1975,7 +967,7 @@ function remote_user() {
*/
function notice($s) {
$a = get_app();
- if (! x($_SESSION,'sysmsg')) {
+ if (!x($_SESSION, 'sysmsg')) {
$_SESSION['sysmsg'] = array();
}
if ($a->interactive) {
@@ -1993,11 +985,11 @@ function notice($s) {
function info($s) {
$a = get_app();
- if (local_user() AND get_pconfig(local_user(),'system','ignore_info')) {
+ if (local_user() AND get_pconfig(local_user(), 'system', 'ignore_info')) {
return;
}
- if (! x($_SESSION,'sysmsg_info')) {
+ if (!x($_SESSION, 'sysmsg_info')) {
$_SESSION['sysmsg_info'] = array();
}
if ($a->interactive) {
@@ -2005,7 +997,6 @@ function info($s) {
}
}
-
/**
* @brief Wrapper around config to limit the text length of an incoming message
*
@@ -2013,12 +1004,12 @@ function info($s) {
*/
function get_max_import_size() {
$a = get_app();
- return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 );
+ 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 :)
+ * so plugins can take part in process :)
*
* @param (integer|array) priority or parameter array, $cmd atrings are deprecated and are ignored
*
@@ -2029,9 +1020,9 @@ function get_max_import_size() {
* @note $cmd and string args are surrounded with ""
*
* @hooks 'proc_run'
- * array $arr
+ * array $arr
*/
-function proc_run($cmd){
+function proc_run($cmd) {
$a = get_app();
@@ -2064,7 +1055,7 @@ function proc_run($cmd){
$arr = array('args' => $args, 'run_cmd' => true);
call_hooks("proc_run", $arr);
- if (!$arr['run_cmd'] OR !count($args)) {
+ if (!$arr['run_cmd'] OR ! count($args)) {
return;
}
@@ -2086,8 +1077,7 @@ function proc_run($cmd){
array_shift($argv);
$parameters = json_encode($argv);
- $found = q("SELECT `id` FROM `workerqueue` WHERE `parameter` = '%s'",
- dbesc($parameters));
+ $found = q("SELECT `id` FROM `workerqueue` WHERE `parameter` = '%s'", dbesc($parameters));
if (!dbm::is_result($found)) {
q("INSERT INTO `workerqueue` (`parameter`, `created`, `priority`)
@@ -2123,7 +1113,7 @@ function proc_run($cmd){
$a->proc_run($args);
}
-function current_theme(){
+function current_theme() {
$app_base_themes = array('duepuntozero', 'dispy', 'quattro');
$a = get_app();
@@ -2145,7 +1135,7 @@ function current_theme(){
// This works only if the user is on the same server
if ($page_theme && local_user() && (local_user() != $a->profile_uid)) {
- if (get_pconfig(local_user(),'system','always_my_theme')) {
+ if (get_pconfig(local_user(), 'system', 'always_my_theme')) {
$page_theme = null;
}
}
@@ -2155,7 +1145,7 @@ function current_theme(){
$is_mobile = $a->is_mobile || $a->is_tablet;
$standard_system_theme = Config::get('system', 'theme', '');
- $standard_theme_name = ((isset($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $standard_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']) {
@@ -2166,7 +1156,7 @@ function current_theme(){
if ($system_theme == '') {
$system_theme = $standard_system_theme;
}
- $theme_name = ((isset($_SESSION) && x($_SESSION,'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme);
+ $theme_name = ((isset($_SESSION) && x($_SESSION, 'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme);
if ($theme_name === '---') {
// user has selected to have the mobile theme be the same as the normal one
@@ -2188,21 +1178,21 @@ function current_theme(){
}
if ($theme_name &&
- (file_exists('view/theme/' . $theme_name . '/style.css') ||
- file_exists('view/theme/' . $theme_name . '/style.php'))) {
+ (file_exists('view/theme/' . $theme_name . '/style.css') ||
+ file_exists('view/theme/' . $theme_name . '/style.php'))) {
return($theme_name);
}
foreach ($app_base_themes as $t) {
if (file_exists('view/theme/' . $t . '/style.css') ||
- file_exists('view/theme/' . $t . '/style.php')) {
+ file_exists('view/theme/' . $t . '/style.php')) {
return($t);
}
}
- $fallback = array_merge(glob('view/theme/*/style.css'),glob('view/theme/*/style.php'));
+ $fallback = array_merge(glob('view/theme/*/style.css'), glob('view/theme/*/style.php'));
if (count($fallback)) {
- return (str_replace('view/theme/','', substr($fallback[0],0,-10)));
+ return (str_replace('view/theme/', '', substr($fallback[0], 0, -10)));
}
/// @TODO No final return statement?
@@ -2222,13 +1212,13 @@ function current_theme_url() {
$opts = (($a->profile_uid) ? '?f=&puid=' . $a->profile_uid : '');
if (file_exists('view/theme/' . $t . '/style.php')) {
- return('view/theme/'.$t.'/style.pcss'.$opts);
+ return('view/theme/' . $t . '/style.pcss' . $opts);
}
- return('view/theme/'.$t.'/style.css');
+ return('view/theme/' . $t . '/style.css');
}
-function feed_birthday($uid,$tz) {
+function feed_birthday($uid, $tz) {
/**
*
@@ -2248,11 +1238,9 @@ function feed_birthday($uid,$tz) {
* 6:00PM the day before, but that will correspond to midnight to the birthday person.
*
*/
-
-
$birthday = '';
- if (! strlen($tz)) {
+ if (!strlen($tz)) {
$tz = 'UTC';
}
@@ -2261,16 +1249,16 @@ function feed_birthday($uid,$tz) {
);
if (dbm::is_result($p)) {
- $tmp_dob = substr($p[0]['dob'],5);
+ $tmp_dob = substr($p[0]['dob'], 5);
if (intval($tmp_dob)) {
- $y = datetime_convert($tz,$tz,'now','Y');
+ $y = datetime_convert($tz, $tz, 'now', 'Y');
$bd = $y . '-' . $tmp_dob . ' 00:00';
$t_dob = strtotime($bd);
- $now = strtotime(datetime_convert($tz,$tz,'now'));
+ $now = strtotime(datetime_convert($tz, $tz, 'now'));
if ($t_dob < $now) {
$bd = $y + 1 . '-' . $tmp_dob . ' 00:00';
}
- $birthday = datetime_convert($tz,'UTC',$bd,ATOM_TIME);
+ $birthday = datetime_convert($tz, 'UTC', $bd, ATOM_TIME);
}
}
@@ -2288,7 +1276,7 @@ function is_site_admin() {
$adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
//if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email']))
- if (local_user() && x($a->user,'email') && x($a->config,'admin_email') && in_array($a->user['email'], $adminlist)) {
+ if (local_user() && x($a->user, 'email') && x($a->config, 'admin_email') && in_array($a->user['email'], $adminlist)) {
return true;
}
return false;
@@ -2310,7 +1298,7 @@ function build_querystring($params, $name = null) {
if ($name == null) {
$ret .= build_querystring($val, $key);
} else {
- $ret .= build_querystring($val, $name."[$key]");
+ $ret .= build_querystring($val, $name . "[$key]");
}
} else {
$val = urlencode($val);
@@ -2358,10 +1346,10 @@ function explode_querystring($query) {
}
/**
-* Returns the complete URL of the current page, e.g.: http(s)://something.com/network
-*
-* Taken from http://webcheatsheet.com/php/get_current_page_url.php
-*/
+ * Returns the complete URL of the current page, e.g.: http(s)://something.com/network
+ *
+ * Taken from http://webcheatsheet.com/php/get_current_page_url.php
+ */
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
@@ -2371,9 +1359,9 @@ function curPageURL() {
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") {
- $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
+ $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
} else {
- $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
+ $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
@@ -2382,7 +1370,7 @@ function random_digits($digits) {
$rn = '';
for ($i = 0; $i < $digits; $i++) {
/// @TODO rand() is different to mt_rand() and maybe lesser "random"
- $rn .= rand(0,9);
+ $rn .= rand(0, 9);
}
return $rn;
}
@@ -2400,7 +1388,7 @@ function get_server() {
function get_cachefile($file, $writemode = true) {
$cache = get_itemcachepath();
- if ((! $cache) || (! is_dir($cache))) {
+ if ((!$cache) || (!is_dir($cache))) {
return("");
}
@@ -2433,15 +1421,15 @@ function clear_cache($basepath = "", $path = "") {
return;
}
- $cachetime = (int)get_config('system','itemcache_duration');
+ $cachetime = (int) get_config('system', 'itemcache_duration');
if ($cachetime == 0) {
$cachetime = 86400;
}
- if (is_writable($path)){
+ if (is_writable($path)) {
if ($dh = opendir($path)) {
while (($file = readdir($dh)) !== false) {
- $fullpath = $path."/".$file;
+ $fullpath = $path . "/" . $file;
if ((filetype($fullpath) == "dir") and ($file != ".") and ($file != "..")) {
clear_cache($basepath, $fullpath);
}
@@ -2456,12 +1444,12 @@ function clear_cache($basepath = "", $path = "") {
function get_itemcachepath() {
// Checking, if the cache is deactivated
- $cachetime = (int)get_config('system','itemcache_duration');
+ $cachetime = (int) get_config('system', 'itemcache_duration');
if ($cachetime < 0) {
return "";
}
- $itemcache = get_config('system','itemcache');
+ $itemcache = get_config('system', 'itemcache');
if (($itemcache != "") AND App::directory_usable($itemcache)) {
return $itemcache;
}
@@ -2469,7 +1457,7 @@ function get_itemcachepath() {
$temppath = get_temppath();
if ($temppath != "") {
- $itemcache = $temppath."/itemcache";
+ $itemcache = $temppath . "/itemcache";
if (!file_exists($itemcache) && !is_dir($itemcache)) {
mkdir($itemcache);
}
@@ -2488,7 +1476,7 @@ function get_itemcachepath() {
* @return string Spool path
*/
function get_spoolpath() {
- $spoolpath = get_config('system','spoolpath');
+ $spoolpath = get_config('system', 'spoolpath');
if (($spoolpath != "") AND App::directory_usable($spoolpath)) {
// We have a spool path and it is usable
return $spoolpath;
@@ -2499,7 +1487,7 @@ function get_spoolpath() {
if ($temppath != "") {
// To avoid any interferences with other systems we create our own directory
- $spoolpath = $temppath."/spool";
+ $spoolpath = $temppath . "/spool";
if (!is_dir($spoolpath)) {
mkdir($spoolpath);
}
@@ -2535,7 +1523,7 @@ function get_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 = $temppath."/".$a->get_hostname();
+ $new_temppath = $temppath . "/" . $a->get_hostname();
if (!is_dir($new_temppath)) {
/// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method?
mkdir($new_temppath);
@@ -2581,7 +1569,7 @@ function validate_include(&$file) {
return false;
}
- $file = str_replace(getcwd()."/", "", $file, $count);
+ $file = str_replace(getcwd() . "/", "", $file, $count);
if ($count != 1) {
return false;
}
@@ -2633,7 +1621,7 @@ function argc() {
* @return string Value of the argv key
*/
function argv($x) {
- if (array_key_exists($x,get_app()->argv)) {
+ if (array_key_exists($x, get_app()->argv)) {
return get_app()->argv[$x];
}
@@ -2650,12 +1638,12 @@ function argv($x) {
*
* @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
- * 'reload_uri' => $reload_uri The URI of the content we have to load
+ * 'pageno' => $pageno The number of the actual page
+ * 'reload_uri' => $reload_uri The URI of the content we have to load
*/
function infinite_scroll_data($module) {
- if (get_pconfig(local_user(),'system','infinite_scroll')
+ if (get_pconfig(local_user(), 'system', 'infinite_scroll')
AND ($module == "network") AND ($_GET["mode"] != "minimal")) {
// get the page number
@@ -2674,7 +1662,7 @@ function infinite_scroll_data($module) {
}
}
- if (($a->page_offset != "") AND !strstr($reload_uri, "&offset=")) {
+ if (($a->page_offset != "") AND ! strstr($reload_uri, "&offset=")) {
$reload_uri .= "&offset=" . urlencode($a->page_offset);
}
diff --git a/composer.lock b/composer.lock
index b46614f6e..f057d0cec 100644
--- a/composer.lock
+++ b/composer.lock
@@ -226,10 +226,10 @@
},
{
"name": "pear-pear.php.net/PEAR",
- "version": "1.10.3",
+ "version": "1.10.4",
"dist": {
"type": "file",
- "url": "https://pear.php.net/get/PEAR-1.10.3.tgz",
+ "url": "https://pear.php.net/get/PEAR-1.10.4.tgz",
"reference": null,
"shasum": null
},
@@ -247,7 +247,7 @@
"pear-pear.php.net/pear_frontend_web": "<=0.4.0.0"
},
"replace": {
- "pear-pear/pear": "== 1.10.3.0"
+ "pear-pear/pear": "== 1.10.4.0"
},
"type": "pear-library",
"autoload": {
diff --git a/doc/Composer.md b/doc/Composer.md
index 8310baf3f..02ce61639 100644
--- a/doc/Composer.md
+++ b/doc/Composer.md
@@ -113,3 +113,8 @@ For Composer, this would be:
````
$> COMPOSER_HOME=/var/tmp/composer sudo -u [web user] util/composer.phar [mode]
````
+
+## Related
+
+* [Class autoloading](help/autoloader)
+* [How To Move Classes to `src`](help/Developer-How-To-Move-Classes-to-src)
diff --git a/doc/Developer-How-To-Move-Classes-to-src.md b/doc/Developer-How-To-Move-Classes-to-src.md
new file mode 100644
index 000000000..25eb39372
--- /dev/null
+++ b/doc/Developer-How-To-Move-Classes-to-src.md
@@ -0,0 +1,108 @@
+How To Move Classes to `src`
+==============
+
+* [Home](help)
+ * [Developer Intro](help/Developers-Intro)
+
+Friendica uses [Composer](help/Composer) to manage autoloading.
+This means that all the PHP class files moved to the `src` folder will be [automatically included](help/autoloader) when the class it defines is first used in the flow.
+This is an improvement over the current `require` usage since files will be included on an actual usage basis instead of the presence of a `require` call.
+
+However, there are a significant number of items to check when moving a class file from the `include` folder to the `src` folder, and this page is there to list them.
+
+## Decide the namespace
+
+This isn't the most technical decision of them all, but it has long lasting consequences as it will be the name that will be used to refer to this class from now on.
+There is [a shared Ethercalc sheet](https://ethercalc.org/friendica_classes) to suggest namespace/class names that lists all the already moved class files for inspiration.
+
+A few pointers though:
+* `Friendica` is the base namespace for all classes in the `src` folder
+* Namespaces match the directory structure, with `Friendica` namespace being the base `src` directory. The `Config` class set in the `Friendica\Core` namespace is expected to be found at `src/Core/Config.php`.
+* Namespaces can help group classes with a similar purpose or relevant to a particular feature
+
+When you're done deciding the namespace, it's time to use it.
+Let's say we choose `Friendica\Core` for the `Config` class.
+
+## Use the namespace
+
+To declare the namespace, the file `src/Core/Config.php` must start with the following statement:
+
+````php
+namespace Friendica\Core;
+````
+
+From now on, the `Config` class can be referred to as `Friendica\Core\Config`, however it isn't very practical, especially when the class was previously used as `Config`.
+Thankfully, PHP provides namespace shortcuts through `use`.
+
+This language construct just provides a different naming scheme for a namespace or a class, but doesn't trigger the autoload mechanism on its own.
+Here are the different ways you can use `use`:
+
+````php
+// No use
+$config = new Friendica\Core\Config();
+````
+````php
+// Namespace shortcut
+use Friendica\Core;
+
+$config = new Core\Config();
+````
+````php
+// Class name shortcut
+use Friendica\Core\Config;
+
+$config = new Config();
+````
+````php
+// Aliasing
+use Friendica\Core\Config as Cfg;
+
+$config = new Cfg();
+````
+
+Whatever the style chosen, a repository-wide search has to be done to find all the class name usage and either use the fully-qualified class name (including the namespace) or add a `use` statement at the start of each relevant file.
+
+## Escape non-namespace classes
+
+The class file you just moved is now in the `Friendica` namespace, but it probably isn't the case for all the classes referenced in this file.
+Since we added a `namespace Friendica\Core;` to the file, all the class names still declared in `include` will be implicitly understood as `Friendica\Core\ClassName`, which is rarely what we expect.
+
+To avoid `Class Friendica\Core\ClassName not found` errors, all the `include`-declared class names have to be prepended with a `\`, it tells the autoloader not to look for the class in the namespace but in the global space where non-namespaced classes are set.
+If there are only a handful of references to a single non-namespaced class, just prepending `\` is enough. However, if there are many instance, we can use `use` again.
+
+````php
+namespace Friendica\Core;
+...
+if (\dbm::is_result($r)) {
+ ...
+}
+````
+````php
+namespace Friendica\Core;
+
+use \dbm;
+
+if (dbm::is_result($r)) {
+ ...
+}
+````
+
+## Remove any useless `require`
+
+Now that you successfully moved your class to the autoloaded `src` folder, there's no need to include this file anywhere in the app ever again.
+Please remove all the `require_once` mentions of the former file, as they will provoke a Fatal Error even if the class isn't used.
+
+## Miscellaneous tips
+
+When you are done with moving the class, please run `php util/typo.php` from the Friendica base directory to check for obvious mistakes.
+Howevever, this tool isn't bullet-proof, and a staging install of Friendica is recommended to test your class move without impairing your production server if you host one.
+
+Most of Friendica processes are run in the background, so make sure to turn on your debug log to check for errors that wouldn't show up while simply browsing Friendica.
+
+Check the class file for any magic constant `__FILE__` or `__DIR__`, as their value changed since you moved the class in the file tree.
+Most of the time it's used for debugging purposes but there can be instances where it's used to create cache folders for example.
+
+## Related
+
+* [Class autoloading](help/autoloader)
+* [Using Composer](help/Composer)
\ No newline at end of file
diff --git a/doc/Developers-Intro.md b/doc/Developers-Intro.md
index 5568afeb5..3cda8ab46 100644
--- a/doc/Developers-Intro.md
+++ b/doc/Developers-Intro.md
@@ -52,7 +52,9 @@ Friendica uses [Composer](https://getcomposer.org) to manage dependencies librar
It's a command-line tool that downloads required libraries into the `vendor` folder and makes any namespaced class in `src` available through the whole application through `boot.php`.
+* [Class autoloading](help/autoloader)
* [Using Composer](help/Composer)
+* [How To Move Classes to `src`](help/Developer-How-To-Move-Classes-to-src)
###Coding standards
diff --git a/doc/Home.md b/doc/Home.md
index 5490d171f..4cecec44e 100644
--- a/doc/Home.md
+++ b/doc/Home.md
@@ -36,21 +36,25 @@ Friendica Documentation and Resources
**Developer Manual**
-* [Where to get started?](help/Developers-Intro)
-* [Help on Github](help/Github)
-* [Help on Vagrant](help/Vagrant)
-* [How to translate Friendica](help/translations)
-* [Bugs and Issues](help/Bugs-and-Issues)
-* [Plugin Development](help/Plugins)
-* [Theme Development](help/themes)
-* [Smarty 3 Templates](help/smarty3-templates)
-* [Protocol Documentation](help/Protocol)
-* [Database schema documantation](help/database)
-* [Class Autoloading](help/autoloader)
-* [Using Composer](help/Composer)
-* [Code - Reference(Doxygen generated - sets cookies)](doc/html/)
-* [Twitter/GNU Social API Functions](help/api)
-
+* [Get started](help/Developers-Intro)
+* Set up development environment
+ * [Help on Github](help/Github)
+ * [Help on Vagrant](help/Vagrant)
+ * [Bugs and Issues](help/Bugs-and-Issues)
+* Code structure
+ * [Plugin Development](help/Plugins)
+ * [Theme Development](help/themes)
+ * [Smarty 3 Templates](help/smarty3-templates)
+* How To
+ * [Translate Friendica](help/translations)
+ * [Use Composer](help/Composer)
+ * [Move classes to `src`](help/Developer-How-To-Move-Classes-to-src)
+* Reference
+ * [Twitter/GNU Social API Functions](help/api)
+ * [Code (Doxygen generated - sets cookies)](doc/html/)
+ * [Protocol Documentation](help/Protocol)
+ * [Database schema documantation](help/database)
+ * [Class Autoloading](help/autoloader)
**External Resources**
diff --git a/doc/autoloader.md b/doc/autoloader.md
index 83f101044..af76cf329 100644
--- a/doc/autoloader.md
+++ b/doc/autoloader.md
@@ -24,14 +24,14 @@ For more info about PHP autoloading, please refer to the [official PHP documenta
Let's say you have a PHP file in `src/` that define a very useful class:
```php
- // src/ItemsManager.php
- getAll();
+function network_content(App $a) {
+ $itemsmanager = new Friendica\ItemsManager();
+ $items = $itemsmanager->getAll();
- // pass $items to template
- // return result
- }
+ // pass $items to template
+ // return result
+}
```
That's a quite simple example, but look: no `require()`!
@@ -61,132 +61,137 @@ If you need to use a class, you can simply use it and you don't need to do anyth
Going further: now we have a bunch of `*Manager` classes that cause some code duplication, let's define a `BaseManager` class, where we move all common code between all managers:
```php
- // src/BaseManager.php
-
diff --git a/include/Emailer.php b/include/Emailer.php
index b0cdc3fe6..9df6ac36c 100644
--- a/include/Emailer.php
+++ b/include/Emailer.php
@@ -81,4 +81,3 @@ class Emailer {
return $res;
}
}
-?>
diff --git a/include/ForumManager.php b/include/ForumManager.php
index c2a20df29..8f38ed3a3 100644
--- a/include/ForumManager.php
+++ b/include/ForumManager.php
@@ -1,5 +1,7 @@
Notification identifier
* int 'total' => Total number of available network notifications
@@ -436,7 +435,7 @@ class NotificationsManager {
}
/**
- * @brief Total number of system notifications
+ * @brief Total number of system notifications
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
@@ -460,13 +459,13 @@ class NotificationsManager {
/**
* @brief Get system notifications
- *
+ *
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
* @param int $start Start the query at this point
* @param int $limit Maximum number of query results
- *
+ *
* @return array with
* string 'ident' => Notification identifier
* int 'total' => Total number of available system notifications
@@ -502,7 +501,7 @@ class NotificationsManager {
/**
* @brief Addional SQL query string for the personal notifications
- *
+ *
* @return string The additional sql query
*/
private function _personal_sql_extra() {
@@ -520,7 +519,7 @@ class NotificationsManager {
}
/**
- * @brief Total number of personal notifications
+ * @brief Total number of personal notifications
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
@@ -550,13 +549,13 @@ class NotificationsManager {
/**
* @brief Get personal notifications
- *
+ *
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
* @param int $start Start the query at this point
* @param int $limit Maximum number of query results
- *
+ *
* @return array with
* string 'ident' => Notification identifier
* int 'total' => Total number of available personal notifications
@@ -573,13 +572,13 @@ class NotificationsManager {
$sql_seen = " AND `item`.`unseen` = 1 ";
$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
- `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
- `pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
+ `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
+ `pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
WHERE `item`.`visible` = 1
$sql_extra
$sql_seen
- AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
+ AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
ORDER BY `item`.`created` DESC LIMIT %d, %d " ,
intval(local_user()),
intval($start),
@@ -588,7 +587,7 @@ class NotificationsManager {
if (dbm::is_result($r))
$notifs = $this->formatNotifs($r, $ident);
-
+
$arr = array (
'notifications' => $notifs,
'ident' => $ident,
@@ -599,7 +598,7 @@ class NotificationsManager {
}
/**
- * @brief Total number of home notifications
+ * @brief Total number of home notifications
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
@@ -626,13 +625,13 @@ class NotificationsManager {
/**
* @brief Get home notifications
- *
+ *
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
* @param int $start Start the query at this point
* @param int $limit Maximum number of query results
- *
+ *
* @return array with
* string 'ident' => Notification identifier
* int 'total' => Total number of available home notifications
@@ -673,7 +672,7 @@ class NotificationsManager {
}
/**
- * @brief Total number of introductions
+ * @brief Total number of introductions
* @param bool $all
* If false only include introductions into the query
* which aren't marked as ignored
@@ -698,13 +697,13 @@ class NotificationsManager {
/**
* @brief Get introductions
- *
+ *
* @param bool $all
* If false only include introductions into the query
* which aren't marked as ignored
* @param int $start Start the query at this point
* @param int $limit Maximum number of query results
- *
+ *
* @return array with
* string 'ident' => Notification identifier
* int 'total' => Total number of available introductions
@@ -749,7 +748,7 @@ class NotificationsManager {
/**
* @brief Format the notification query in an usable array
- *
+ *
* @param array $intros The array from the db query
* @return array with the introductions
*/
diff --git a/include/Photo.php b/include/Photo.php
index 828dce82d..504f7e942 100644
--- a/include/Photo.php
+++ b/include/Photo.php
@@ -4,6 +4,8 @@
* @brief This file contains the Photo class for image processing
*/
+use Friendica\App;
+
require_once("include/photos.php");
class Photo {
diff --git a/include/Probe.php b/include/Probe.php
index bed13fdf3..85f64d29b 100644
--- a/include/Probe.php
+++ b/include/Probe.php
@@ -5,8 +5,9 @@
*
*/
-use \Friendica\Core\Config;
-use \Friendica\Core\PConfig;
+use Friendica\App;
+use Friendica\Core\Config;
+use Friendica\Core\PConfig;
require_once("include/feed.php");
require_once('include/email.php');
@@ -1261,4 +1262,3 @@ class Probe {
}
}
-?>
diff --git a/include/Smilies.php b/include/Smilies.php
index d67b92d8b..f4de32f8f 100644
--- a/include/Smilies.php
+++ b/include/Smilies.php
@@ -5,6 +5,8 @@
* @brief This file contains the Smilies class which contains functions to handle smiles
*/
+use Friendica\App;
+
/**
* This class contains functions to handle smiles
*/
@@ -13,13 +15,13 @@ class Smilies {
/**
* @brief Function to list all smilies
- *
+ *
* Get an array of all smilies, both internal and from addons.
- *
+ *
* @return array
* 'texts' => smilie shortcut
* 'icons' => icon in html
- *
+ *
* @hook smilie ('texts' => smilies texts array, 'icons' => smilies html array)
*/
public static function get_list() {
@@ -64,41 +66,41 @@ class Smilies {
);
$icons = array(
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '',
- '~friendica ',
- 'redmatrix',
- 'redmatrix'
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '',
+ '~friendica ',
+ 'redmatrix',
+ 'redmatrix'
);
$params = array('texts' => $texts, 'icons' => $icons);
@@ -121,7 +123,7 @@ class Smilies {
*
* @param string $s
* @param boolean $sample
- *
+ *
* @return string HML Output of the Smilie
*/
public static function replace($s, $sample = false) {
@@ -166,7 +168,7 @@ class Smilies {
*
* @param string $x
* @return string HTML Output
- *
+ *
* @todo: Rework because it doesn't work correctly
*/
private function preg_heart($x) {
@@ -174,7 +176,7 @@ class Smilies {
return $x[0];
$t = '';
for($cnt = 0; $cnt < strlen($x[1]); $cnt ++)
- $t .= '';
+ $t .= '';
$r = str_replace($x[0],$t,$x[0]);
return $r;
}
diff --git a/include/acl_selectors.php b/include/acl_selectors.php
index fbe5d1e69..c7c6bb206 100644
--- a/include/acl_selectors.php
+++ b/include/acl_selectors.php
@@ -4,6 +4,8 @@
* @file include/acl_selectors.php
*/
+use Friendica\App;
+
require_once "include/contact_selectors.php";
require_once "include/contact_widgets.php";
require_once "include/DirSearch.php";
diff --git a/include/api.php b/include/api.php
index f68c1bb9e..fc38f1bc8 100644
--- a/include/api.php
+++ b/include/api.php
@@ -6,7 +6,8 @@
* @todo Automatically detect if incoming data is HTML or BBCode
*/
-use \Friendica\Core\Config;
+use Friendica\App;
+use Friendica\Core\Config;
require_once 'include/HTTPExceptions.php';
require_once 'include/bbcode.php';
diff --git a/include/auth.php b/include/auth.php
index c1a6120db..5dfe9d3e0 100644
--- a/include/auth.php
+++ b/include/auth.php
@@ -1,6 +1,7 @@
rLogFile);
}
}
-?>
diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php
index a07a58353..1dc775887 100644
--- a/include/bb2diaspora.php
+++ b/include/bb2diaspora.php
@@ -1,5 +1,7 @@
diff --git a/include/cron.php b/include/cron.php
index c4299dd4c..bac9c8a3d 100644
--- a/include/cron.php
+++ b/include/cron.php
@@ -1,5 +1,6 @@
diff --git a/include/dbm.php b/include/dbm.php
index 3430577da..db50dae89 100644
--- a/include/dbm.php
+++ b/include/dbm.php
@@ -110,4 +110,3 @@ class dbm {
return date('Y-m-d H:i:s', $timestamp);
}
}
-?>
diff --git a/include/dbstructure.php b/include/dbstructure.php
index 993ddad40..6a14220c2 100644
--- a/include/dbstructure.php
+++ b/include/dbstructure.php
@@ -1,6 +1,7 @@
setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
- xml::add_element($doc, $root, "id", app::get_baseurl()."/profile/".$owner["nick"]);
+ xml::add_element($doc, $root, "id", App::get_baseurl()."/profile/".$owner["nick"]);
xml::add_element($doc, $root, "title", $owner["name"]);
$attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
@@ -448,13 +450,13 @@ class dfrn {
// DFRN itself doesn't uses this. But maybe someone else wants to subscribe to the public feed.
ostatus::hublinks($doc, $root);
- $attributes = array("rel" => "salmon", "href" => app::get_baseurl()."/salmon/".$owner["nick"]);
+ $attributes = array("rel" => "salmon", "href" => App::get_baseurl()."/salmon/".$owner["nick"]);
xml::add_element($doc, $root, "link", "", $attributes);
- $attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-replies", "href" => app::get_baseurl()."/salmon/".$owner["nick"]);
+ $attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-replies", "href" => App::get_baseurl()."/salmon/".$owner["nick"]);
xml::add_element($doc, $root, "link", "", $attributes);
- $attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-mention", "href" => app::get_baseurl()."/salmon/".$owner["nick"]);
+ $attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-mention", "href" => App::get_baseurl()."/salmon/".$owner["nick"]);
xml::add_element($doc, $root, "link", "", $attributes);
}
@@ -511,7 +513,7 @@ class dfrn {
}
xml::add_element($doc, $author, "name", $owner["name"], $attributes);
- xml::add_element($doc, $author, "uri", app::get_baseurl().'/profile/'.$owner["nickname"], $attributes);
+ xml::add_element($doc, $author, "uri", App::get_baseurl().'/profile/'.$owner["nickname"], $attributes);
xml::add_element($doc, $author, "dfrn:handle", $owner["addr"], $attributes);
$attributes = array("rel" => "photo", "type" => "image/jpeg",
@@ -812,7 +814,7 @@ class dfrn {
$parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"]));
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
$attributes = array("ref" => $parent_item, "type" => "text/html",
- "href" => app::get_baseurl().'/display/'.$parent[0]['guid'],
+ "href" => App::get_baseurl().'/display/'.$parent[0]['guid'],
"dfrn:diaspora_guid" => $parent[0]['guid']);
xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
}
@@ -854,7 +856,7 @@ class dfrn {
// We save this value in "plink". Maybe we should read it from there as well?
xml::add_element($doc, $entry, "link", "", array("rel" => "alternate", "type" => "text/html",
- "href" => app::get_baseurl()."/display/".$item["guid"]));
+ "href" => App::get_baseurl()."/display/".$item["guid"]));
// "comment-allow" is some old fashioned stuff for old Friendica versions.
// It is included in the rewritten code for completeness
diff --git a/include/diaspora.php b/include/diaspora.php
index 0c3ff68da..51b496f86 100644
--- a/include/diaspora.php
+++ b/include/diaspora.php
@@ -8,7 +8,8 @@
* This will change in the future.
*/
-use \Friendica\Core\Config;
+use Friendica\App;
+use Friendica\Core\Config;
require_once 'include/items.php';
require_once 'include/bb2diaspora.php';
@@ -3819,4 +3820,3 @@ class Diaspora {
return true;
}
}
-?>
diff --git a/include/directory.php b/include/directory.php
index 41a3dd784..e507a939f 100644
--- a/include/directory.php
+++ b/include/directory.php
@@ -1,9 +1,9 @@
$author, "items" => $items);
}
}
-?>
diff --git a/include/files.php b/include/files.php
index c20a6d832..0ac0078c8 100644
--- a/include/files.php
+++ b/include/files.php
@@ -47,4 +47,3 @@ function update_files_for_items() {
create_files_from_item($message["id"]);
}
}
-?>
diff --git a/include/follow.php b/include/follow.php
index 57520abe6..161e669e9 100644
--- a/include/follow.php
+++ b/include/follow.php
@@ -1,4 +1,7 @@
diff --git a/include/html2plain.php b/include/html2plain.php
index dc2cb137c..ed338ce71 100644
--- a/include/html2plain.php
+++ b/include/html2plain.php
@@ -233,4 +233,3 @@ function html2plain($html, $wraplength = 75, $compact = false)
return(trim($message));
}
-?>
diff --git a/include/identity.php b/include/identity.php
index 1fea5b25d..dea044b48 100644
--- a/include/identity.php
+++ b/include/identity.php
@@ -3,6 +3,8 @@
* @file include/identity.php
*/
+use Friendica\App;
+
require_once('include/ForumManager.php');
require_once('include/bbcode.php');
require_once("mod/proxy.php");
diff --git a/include/items.php b/include/items.php
index 5eac12d89..3c5e88a38 100644
--- a/include/items.php
+++ b/include/items.php
@@ -4,7 +4,8 @@
* @file include/items.php
*/
-use \Friendica\ParseUrl;
+use Friendica\App;
+use Friendica\ParseUrl;
require_once 'include/bbcode.php';
require_once 'include/oembed.php';
@@ -339,7 +340,7 @@ function add_page_info_to_body($body, $texturl = false, $no_photos = false) {
* Adds a "lang" specification in a "postopts" element of given $arr,
* if possible and not already present.
* Expects "body" element to exist in $arr.
- *
+ *
* @todo Add a parameter to request forcing override
*/
function item_add_language_opt(&$arr) {
diff --git a/include/like.php b/include/like.php
index a53b90c03..4f2600271 100644
--- a/include/like.php
+++ b/include/like.php
@@ -1,4 +1,7 @@
diff --git a/include/nav.php b/include/nav.php
index fe4c50818..e2633be0a 100644
--- a/include/nav.php
+++ b/include/nav.php
@@ -1,5 +1,7 @@
gen_token();
$sec = $this->gen_token();
-
+
if ($consumer->key){
$k = $consumer->key;
} else {
$k = $consumer;
}
-
+
$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP()+%d)",
dbesc($key),
dbesc($sec),
@@ -80,19 +82,19 @@ class FKOAuthDataStore extends OAuthDataStore {
function new_access_token($token, $consumer, $verifier = null) {
logger(__function__.":".$token.", ". $consumer.", ". $verifier);
-
+
// return a new access token attached to this consumer
// for the user associated with this token if the request token
// is authorized
// should also invalidate the request token
-
+
$ret=Null;
-
+
// get user for this verifier
$uverifier = get_config("oauth", $verifier);
logger(__function__.":".$verifier.",".$uverifier);
if (is_null($verifier) || ($uverifier!==false)){
-
+
$key = $this->gen_token();
$sec = $this->gen_token();
$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires, uid) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP()+%d, %d)",
@@ -103,13 +105,13 @@ class FKOAuthDataStore extends OAuthDataStore {
intval(ACCESS_TOKEN_DURATION),
intval($uverifier));
if ($r)
- $ret = new OAuthToken($key,$sec);
+ $ret = new OAuthToken($key,$sec);
}
-
-
+
+
q("DELETE FROM tokens WHERE id='%s'", $token->key);
-
-
+
+
if (!is_null($ret) && $uverifier!==false){
del_config("oauth", $verifier);
/* $apps = get_pconfig($uverifier, "oauth", "apps");
@@ -117,9 +119,9 @@ class FKOAuthDataStore extends OAuthDataStore {
$apps[] = $consumer->key;
set_pconfig($uverifier, "oauth", "apps", $apps);*/
}
-
+
return $ret;
-
+
}
}
@@ -172,9 +174,9 @@ class FKOAuth1 extends OAuthServer {
intval($_SESSION['uid'])
);
- call_hooks('logged_in', $a->user);
+ call_hooks('logged_in', $a->user);
}
-
+
}
/*
class FKOAuth2 extends OAuth2 {
@@ -190,13 +192,13 @@ class FKOAuth2 extends OAuth2 {
dbesc($client_secret),
dbesc($redirect_uri)
);
-
+
return $r;
}
protected function checkClientCredentials($client_id, $client_secret = NULL) {
$client_secret = $this->db_secret($client_secret);
-
+
$r = q("SELECT pw FROM clients WHERE client_id = '%s'",
dbesc($client_id));
@@ -218,21 +220,21 @@ class FKOAuth2 extends OAuth2 {
protected function getAccessToken($oauth_token) {
$r = q("SELECT client_id, expires, scope FROM tokens WHERE id = '%s'",
dbesc($oauth_token));
-
+
if (dbm::is_result($r))
return $r[0];
return null;
}
-
+
protected function setAccessToken($oauth_token, $client_id, $expires, $scope = NULL) {
$r = q("INSERT INTO tokens (id, client_id, expires, scope) VALUES ('%s', '%s', %d, '%s')",
dbesc($oauth_token),
dbesc($client_id),
intval($expires),
dbesc($scope));
-
+
return $r;
}
@@ -246,23 +248,23 @@ class FKOAuth2 extends OAuth2 {
protected function getAuthCode($code) {
$r = q("SELECT id, client_id, redirect_uri, expires, scope FROM auth_codes WHERE id = '%s'",
dbesc($code));
-
+
if (dbm::is_result($r))
return $r[0];
return null;
}
protected function setAuthCode($code, $client_id, $redirect_uri, $expires, $scope = NULL) {
- $r = q("INSERT INTO auth_codes
- (id, client_id, redirect_uri, expires, scope) VALUES
+ $r = q("INSERT INTO auth_codes
+ (id, client_id, redirect_uri, expires, scope) VALUES
('%s', '%s', '%s', %d, '%s')",
dbesc($code),
dbesc($client_id),
dbesc($redirect_uri),
intval($expires),
dbesc($scope));
- return $r;
- }
-
+ return $r;
+ }
+
}
*/
diff --git a/include/oembed.php b/include/oembed.php
index 0b8b71366..80b49fbf0 100755
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -4,8 +4,9 @@
* @file include/oembed.php
*/
-use \Friendica\ParseUrl;
-use \Friendica\Core\Config;
+use Friendica\App;
+use Friendica\ParseUrl;
+use Friendica\Core\Config;
function oembed_replacecb($matches){
$embedurl=$matches[1];
diff --git a/include/onepoll.php b/include/onepoll.php
index 5227b61a1..3483d2493 100644
--- a/include/onepoll.php
+++ b/include/onepoll.php
@@ -1,6 +1,6 @@
saveXML()));
}
}
-?>
diff --git a/include/pgettext.php b/include/pgettext.php
index b42dcec11..9b541e8e3 100644
--- a/include/pgettext.php
+++ b/include/pgettext.php
@@ -10,7 +10,7 @@
*
*/
-use \Friendica\Core\Config;
+use Friendica\Core\Config;
require_once("include/dba.php");
diff --git a/include/photos.php b/include/photos.php
index e872532a4..38cda3f2b 100644
--- a/include/photos.php
+++ b/include/photos.php
@@ -4,8 +4,8 @@
* @brief Functions related to photo handling.
*/
-use \Friendica\Core\Config;
-use \Friendica\Core\PConfig;
+use Friendica\Core\Config;
+use Friendica\Core\PConfig;
function getGps($exifCoord, $hemi) {
$degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;
diff --git a/include/pidfile.php b/include/pidfile.php
index 3093e149a..dda6b3e9c 100644
--- a/include/pidfile.php
+++ b/include/pidfile.php
@@ -38,4 +38,3 @@ class pidfile {
return(posix_kill(file_get_contents($this->_file), SIGTERM));
}
}
-?>
diff --git a/include/plaintext.php b/include/plaintext.php
index 6ab4ec77d..215d9f3db 100644
--- a/include/plaintext.php
+++ b/include/plaintext.php
@@ -4,7 +4,8 @@
* @file include/plaintext.php
*/
-use \Friendica\ParseUrl;
+use Friendica\App;
+use Friendica\ParseUrl;
require_once("include/Photo.php");
require_once("include/bbcode.php");
@@ -431,4 +432,3 @@ function plaintext(App $a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2
return($post);
}
-?>
diff --git a/include/plugin.php b/include/plugin.php
index 83f6f1ab9..336b213aa 100644
--- a/include/plugin.php
+++ b/include/plugin.php
@@ -1,10 +1,11 @@
($starttime + 3600))
return;
}
-
}
/**
@@ -687,4 +688,3 @@ if (array_search(__file__,get_included_files())===0){
killme();
}
-?>
diff --git a/include/post_update.php b/include/post_update.php
index f9649961d..9d18b27b4 100644
--- a/include/post_update.php
+++ b/include/post_update.php
@@ -258,5 +258,3 @@ function post_update_1206() {
logger("Done", LOGGER_DEBUG);
return true;
}
-
-?>
diff --git a/include/pubsubpublish.php b/include/pubsubpublish.php
index 1e47c3085..24d7b6963 100644
--- a/include/pubsubpublish.php
+++ b/include/pubsubpublish.php
@@ -1,5 +1,7 @@
diff --git a/include/redir.php b/include/redir.php
index 76e30a6ea..36f982b12 100644
--- a/include/redir.php
+++ b/include/redir.php
@@ -1,5 +1,7 @@
$id));
}
-?>
diff --git a/include/security.php b/include/security.php
index 05371f71c..09ac03c35 100644
--- a/include/security.php
+++ b/include/security.php
@@ -1,5 +1,7 @@
diff --git a/include/spool_post.php b/include/spool_post.php
index f64b39e4b..2b21e4196 100644
--- a/include/spool_post.php
+++ b/include/spool_post.php
@@ -4,7 +4,7 @@
* @brief Posts items that wer spooled because they couldn't be posted.
*/
-use \Friendica\Core\Config;
+use Friendica\Core\Config;
require_once("include/items.php");
@@ -55,4 +55,3 @@ function spool_post_run($argv, $argc) {
}
}
}
-?>
diff --git a/include/tags.php b/include/tags.php
index d809da2bf..6067f3f4b 100644
--- a/include/tags.php
+++ b/include/tags.php
@@ -1,4 +1,7 @@
diff --git a/include/text.php b/include/text.php
index 01873bff2..c9babba94 100644
--- a/include/text.php
+++ b/include/text.php
@@ -1,12 +1,13 @@
diff --git a/include/uimport.php b/include/uimport.php
index 4cc5b6c04..0ee15952a 100644
--- a/include/uimport.php
+++ b/include/uimport.php
@@ -1,11 +1,7 @@
t('No'),
));
- //echo "
"; var_dump($app); killme();
-
return $o;
}
diff --git a/mod/apps.php b/mod/apps.php
index 199ce0f91..0c0df7654 100644
--- a/mod/apps.php
+++ b/mod/apps.php
@@ -1,25 +1,25 @@
apps)==0)
- notice( t('No installed applications.') . EOL);
+ if (count($a->apps) == 0) {
+ notice(t('No installed applications.') . EOL);
+ }
-
- $tpl = get_markup_template("apps.tpl");
+ $tpl = get_markup_template('apps.tpl');
return replace_macros($tpl, array(
'$title' => $title,
'$apps' => $a->apps,
));
-
-
-
}
diff --git a/mod/attach.php b/mod/attach.php
index dd7154dfe..6155a3f99 100644
--- a/mod/attach.php
+++ b/mod/attach.php
@@ -1,5 +1,7 @@
t('Credits'),
- '$thanks' => t('Friendica is a community project, that would not be possible without the help of many people. Here is a list of those who have contributed to the code or the translation of Friendica. Thank you all!'),
- '$names' => $arr,
- ));
+use Friendica\App;
+
+function credits_content(App $a) {
+ /* fill the page with credits */
+ $f = fopen('util/credits.txt', 'r');
+ $names = fread($f, filesize('util/credits.txt'));
+ $arr = explode("\n", htmlspecialchars($names));
+ fclose($f);
+ $tpl = get_markup_template('credits.tpl');
+ return replace_macros($tpl, array(
+ '$title' => t('Credits'),
+ '$thanks' => t('Friendica is a community project, that would not be possible without the help of many people. Here is a list of those who have contributed to the code or the translation of Friendica. Thank you all!'),
+ '$names' => $arr,
+ ));
}
diff --git a/mod/crepair.php b/mod/crepair.php
index 902a12930..59ac620a3 100644
--- a/mod/crepair.php
+++ b/mod/crepair.php
@@ -1,4 +1,7 @@
set_pager_itemspage(60);
@@ -9,24 +11,18 @@ function directory_init(App $a) {
$a->page['aside'] .= findpeople_widget();
$a->page['aside'] .= follow_widget();
-
}
else {
unset($_SESSION['theme']);
unset($_SESSION['mobile-theme']);
}
-
-
}
-
function directory_post(App $a) {
if(x($_POST,'search'))
$a->data['search'] = $_POST['search'];
}
-
-
function directory_content(App $a) {
global $db;
diff --git a/mod/dirfind.php b/mod/dirfind.php
index c5844d13d..c24ab9dbd 100644
--- a/mod/dirfind.php
+++ b/mod/dirfind.php
@@ -1,4 +1,7 @@
page['aside'] .= follow_widget();
}
-
-
function dirfind_content(App $a, $prefix = "") {
$community = false;
diff --git a/mod/display.php b/mod/display.php
index 1f1fd1120..ca6809eba 100644
--- a/mod/display.php
+++ b/mod/display.php
@@ -1,5 +1,7 @@
*/
+use Friendica\App;
+
require_once('include/Photo.php');
/**
diff --git a/mod/fetch.php b/mod/fetch.php
index b87fc0e8e..0afd7af10 100644
--- a/mod/fetch.php
+++ b/mod/fetch.php
@@ -2,6 +2,9 @@
/*
This file is part of the Diaspora protocol. It is used for fetching single public posts.
*/
+
+use Friendica\App;
+
require_once("include/crypto.php");
require_once("include/diaspora.php");
require_once("include/xml.php");
diff --git a/mod/filer.php b/mod/filer.php
index 47c4aa5e4..6259879de 100644
--- a/mod/filer.php
+++ b/mod/filer.php
@@ -1,10 +1,11 @@
argv[1] == "json"){
diff --git a/mod/fsuggest.php b/mod/fsuggest.php
index b3d543971..32ed63b4c 100644
--- a/mod/fsuggest.php
+++ b/mod/fsuggest.php
@@ -1,5 +1,6 @@
";
$html = implode("\n",$lines);
- $a->page['aside'] = $toc.$a->page['aside'];
+ $a->page['aside'] = '' . $toc . $a->page['aside'] . '';
}
$html = "
diff --git a/mod/home.php b/mod/home.php
index b1708d80a..bd77a840d 100644
--- a/mod/home.php
+++ b/mod/home.php
@@ -1,5 +1,7 @@
config['register_policy'] == REGISTER_CLOSED) ? false : true);
-
}
diff --git a/mod/lostpass.php b/mod/lostpass.php
index 455a9b1e2..37ef3e2f8 100644
--- a/mod/lostpass.php
+++ b/mod/lostpass.php
@@ -1,5 +1,7 @@
App::get_baseurl(),
- '$touch_icon' => $touch_icon,
- '$title' => Config::get('config', 'sitename', 'Friendica'),
- ));
-
- echo $o;
-
- killme();
+ header('Content-type: application/manifest+json');
+ $touch_icon = Config::get('system', 'touch_icon', 'images/friendica-128.png');
+ if ($touch_icon == '') {
+ $touch_icon = 'images/friendica-128.png';
}
-?>
+
+ $o = replace_macros($tpl, array(
+ '$baseurl' => App::get_baseurl(),
+ '$touch_icon' => $touch_icon,
+ '$title' => Config::get('config', 'sitename', 'Friendica'),
+ ));
+
+ echo $o;
+
+ killme();
+}
diff --git a/mod/match.php b/mod/match.php
index 44f5141ad..4119bf8e8 100644
--- a/mod/match.php
+++ b/mod/match.php
@@ -1,5 +1,8 @@
' . t('Welcome to Friendica') . '';
-
$o .= '
' . t('New Member Checklist') . '
';
-
$o .= '
';
-
$o .= t('We would like to offer some tips and links to help make your experience enjoyable. Click any item to visit the relevant page. A link to this page will be visible from your home page for two weeks after your initial registration and then will quietly disappear.');
-
$o .= '
' . t('Getting Started') . '
';
-
$o .= '
';
-
$o .= '
' . '' . t('Friendica Walk-Through') . ' ' . t('On your Quick Start page - find a brief introduction to your profile and network tabs, make some new connections, and find some groups to join.') . '
' . EOL;
-
$o .= '
';
-
$o .= '
' . t('Settings') . '
';
-
$o .= '
';
-
$o .= '
' . '' . t('Go to Your Settings') . ' ' . t('On your Settings page - change your initial password. Also make a note of your Identity Address. This looks just like an email address - and will be useful in making friends on the free social web.') . '
' . EOL;
-
$o .= '
' . t('Review the other settings, particularly the privacy settings. An unpublished directory listing is like having an unlisted phone number. In general, you should probably publish your listing - unless all of your friends and potential friends know exactly how to find you.') . '
' . EOL;
-
$o .= '
';
-
$o .= '
' . t('Profile') . '
';
-
$o .= '
';
-
$o .= '
' . '' . t('Upload Profile Photo') . ' ' . t('Upload a profile photo if you have not done so already. Studies have shown that people with real photos of themselves are ten times more likely to make friends than people who do not.') . '
' . EOL;
-
$o .= '
' . '' . t('Edit Your Profile') . ' ' . t('Edit your default profile to your liking. Review the settings for hiding your list of friends and hiding the profile from unknown visitors.') . '
' . EOL;
-
$o .= '
' . '' . t('Profile Keywords') . ' ' . t('Set some public keywords for your default profile which describe your interests. We may be able to find other people with similar interests and suggest friendships.') . '
' . '' . t('Importing Emails') . ' ' . t('Enter your email access information on your Connector Settings page if you wish to import and interact with friends or mailing lists from your email INBOX') . '
' . EOL;
+ }
$o .= '
' . '' . t('Go to Your Contacts Page') . ' ' . t('Your Contacts page is your gateway to managing friendships and connecting with friends on other networks. Typically you enter their address or site URL in the Add New Contact dialog.') . '
' . EOL;
-
$o .= '
' . '' . t("Go to Your Site's Directory") . ' ' . t('The Directory page lets you find other people in this network or other federated sites. Look for a Connect or Follow link on their profile page. Provide your own Identity Address if requested.') . '
' . EOL;
-
$o .= '
' . '' . t('Finding New People') . ' ' . t("On the side panel of the Contacts page are several tools to find new friends. We can match people by interest, look up people by name or interest, and provide suggestions based on network relationships. On a brand new site, friend suggestions will usually begin to be populated within 24 hours.") . '
' . EOL;
-
$o .= '
';
-
$o .= '
' . t('Groups') . '
';
-
$o .= '
';
-
$o .= '
' . '' . t('Group Your Contacts') . ' ' . t('Once you have made some friends, organize them into private conversation groups from the sidebar of your Contacts page and then you can interact with each group privately on your Network page.') . '
' . '' . t("Why Aren't My Posts Public?") . ' ' . t("Friendica respects your privacy. By default, your posts will only show up to people you've added as friends. For more information, see the help section from the link above.") . '