diff --git a/boot.php b/boot.php index 32e0c0e14..d17e984b1 100644 --- a/boot.php +++ b/boot.php @@ -32,7 +32,6 @@ require_once('include/cache.php'); require_once('library/Mobile_Detect/Mobile_Detect.php'); require_once('include/features.php'); require_once('include/identity.php'); -require_once('include/pidfile.php'); require_once('update.php'); require_once('include/dbstructure.php'); @@ -1354,60 +1353,25 @@ class App { return false; } - /** - * @brief Checks if the process is already running - * - * @param string $taskname The name of the task that will be used for the name of the lockfile - * @param string $task The path and name of the php script - * @param int $timeout The timeout after which a task should be killed - * - * @return bool Is the process running? - */ - function is_already_running($taskname, $task = "", $timeout = 540) { - - $lockpath = get_lockpath(); - if ($lockpath != '') { - $pidfile = new pidfile($lockpath, $taskname); - if ($pidfile->is_already_running()) { - logger("Already running"); - if ($pidfile->running_time() > $timeout) { - $pidfile->kill(); - logger("killed stale process"); - // Calling a new instance - if ($task != "") - proc_run(PRIORITY_MEDIUM, $task); - } - return true; - } - } - return false; - } - function proc_run($args) { if (!function_exists("proc_open")) { return; } - // Add the php path if it is a php call - if (count($args) && ($args[0] === 'php' OR !is_string($args[0]))) { - - // If the last worker fork was less than 10 seconds before then don't fork another one. - // This should prevent the forking of masses of workers. - if (get_config("system", "worker")) { - $cachekey = "app:proc_run:started"; - $result = Cache::get($cachekey); - if (!is_null($result)) { - if ((time() - $result) < 10) { - return; - } - } - // Set the timestamp of the last proc_run - Cache::set($cachekey, time(), CACHE_MINUTE); + // 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)) { + if ((time() - $result) < 10) { + return; } - - $args[0] = ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'); } + // 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(); @@ -1897,11 +1861,35 @@ function goaway($s) { * @return int|bool user id or false */ function local_user() { - if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid'))) + if (x($_SESSION, 'authenticated') && x($_SESSION, 'uid')) { return intval($_SESSION['uid']); + } return false; } +/** + * @brief Returns the public contact id of logged in user or false. + * + * @return int|bool public contact id or false + */ +function public_contact() { + static $public_contact_id = false; + + if (!$public_contact_id && x($_SESSION, 'authenticated')) { + if (x($_SESSION, 'my_address')) { + // Local user + $public_contact_id = intval(get_contact($_SESSION['my_address'], 0)); + } else if (x($_SESSION, 'visitor_home')) { + // Remote user + $public_contact_id = intval(get_contact($_SESSION['visitor_home'], 0)); + } + } else if (!x($_SESSION, 'authenticated')) { + $public_contact_id = false; + } + + return $public_contact_id; +} + /** * @brief Returns contact id of authenticated site visitor or false * @@ -1960,10 +1948,9 @@ function get_max_import_size() { * @brief Wrap calls to proc_close(proc_open()) and call hook * so plugins can take part in process :) * - * @param (string|integer|array) $cmd program to run, priority or parameter array + * @param (integer|array) priority or parameter array, $cmd atrings are deprecated and are ignored * * next args are passed as $cmd command line - * e.g.: proc_run("ls","-la","/tmp"); * or: proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id); * or: proc_run(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "include/create_shadowentry.php", $post_id); * @@ -2008,11 +1995,6 @@ function proc_run($cmd){ if (!$arr['run_cmd'] OR !count($args)) return; - if (!get_config("system", "worker") OR (is_string($run_parameter) AND ($run_parameter != 'php'))) { - $a->proc_run($args); - return; - } - $priority = PRIORITY_MEDIUM; $dont_fork = get_config("system", "worker_dont_fork"); @@ -2060,7 +2042,7 @@ function proc_run($cmd){ return; // Now call the poller to execute the jobs that we just added to the queue - $args = array("php", "include/poller.php", "no_cron"); + $args = array("include/poller.php", "no_cron"); $a->proc_run($args); } @@ -2394,38 +2376,6 @@ function get_itemcachepath() { return ""; } -function get_lockpath() { - $lockpath = get_config('system','lockpath'); - if (($lockpath != "") AND App::directory_usable($lockpath)) { - // We have a lock path and it is usable - return $lockpath; - } - - // We don't have a working preconfigured lock path, so we take the temp path. - $temppath = get_temppath(); - - if ($temppath != "") { - // To avoid any interferences with other systems we create our own directory - $lockpath = $temppath."/lock"; - if (!is_dir($lockpath)) { - mkdir($lockpath); - } - - if (App::directory_usable($lockpath)) { - // The new path is usable, we are happy - set_config("system", "lockpath", $lockpath); - return $lockpath; - } else { - // We can't create a subdirectory, strange. - // But the directory seems to work, so we use it but don't store it. - return $temppath; - } - } - - // Reaching this point means that the operating system is configured badly. - return ""; -} - /** * @brief Returns the path where spool files are stored * diff --git a/database.sql b/database.sql index b133489e4..c7ab893d7 100644 --- a/database.sql +++ b/database.sql @@ -1,5 +1,5 @@ -- ------------------------------------------ --- Friendica 3.5.1-rc (Asparagus) +-- Friendica 3.5.2-dev (Asparagus) -- DB_UPDATE_VERSION 1215 -- ------------------------------------------ @@ -204,18 +204,6 @@ CREATE TABLE IF NOT EXISTS `conv` ( INDEX `uid` (`uid`) ) DEFAULT CHARSET=utf8mb4; --- --- TABLE deliverq --- -CREATE TABLE IF NOT EXISTS `deliverq` ( - `id` int(10) unsigned NOT NULL auto_increment, - `cmd` varbinary(32) NOT NULL DEFAULT '', - `item` int(11) NOT NULL DEFAULT 0, - `contact` int(11) NOT NULL DEFAULT 0, - PRIMARY KEY(`id`), - UNIQUE INDEX `cmd_item_contact` (`cmd`,`item`,`contact`) -) DEFAULT CHARSET=utf8mb4; - -- -- TABLE event -- diff --git a/include/Contact.php b/include/Contact.php index e3fa6ea89..3d4040317 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -702,15 +702,6 @@ function posts_from_gcontact(App $a, $gcontact_id) { else $sql = "`item`.`uid` = %d"; - if(get_config('system', 'old_pager')) { - $r = q("SELECT COUNT(*) AS `total` FROM `item` - WHERE `gcontact-id` = %d and $sql", - intval($gcontact_id), - intval(local_user())); - - $a->set_pager_total($r[0]['total']); - } - $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`, `author-name` AS `name`, `owner-avatar` AS `photo`, `owner-link` AS `url`, `owner-avatar` AS `thumb` @@ -724,13 +715,9 @@ function posts_from_gcontact(App $a, $gcontact_id) { intval($a->pager['itemspage']) ); - $o = conversation($a,$r,'community',false); + $o = conversation($a, $r, 'community', false); - if(!get_config('system', 'old_pager')) { - $o .= alt_pager($a,count($r)); - } else { - $o .= paginate($a); - } + $o .= alt_pager($a, count($r)); return $o; } @@ -763,15 +750,6 @@ function posts_from_contact_url(App $a, $contact_url) { $author_id = intval($r[0]["author-id"]); - if (get_config('system', 'old_pager')) { - $r = q("SELECT COUNT(*) AS `total` FROM `item` - WHERE `author-id` = %d and $sql", - intval($author_id), - intval(local_user())); - - $a->set_pager_total($r[0]['total']); - } - $r = q(item_query()." AND `item`.`author-id` = %d AND ".$sql. " ORDER BY `item`.`created` DESC LIMIT %d, %d", intval($author_id), @@ -780,13 +758,9 @@ function posts_from_contact_url(App $a, $contact_url) { intval($a->pager['itemspage']) ); - $o = conversation($a,$r,'community',false); + $o = conversation($a, $r, 'community', false); - if (!get_config('system', 'old_pager')) { - $o .= alt_pager($a,count($r)); - } else { - $o .= paginate($a); - } + $o .= alt_pager($a, count($r)); return $o; } diff --git a/include/api.php b/include/api.php index d7fa1d587..701e527cc 100644 --- a/include/api.php +++ b/include/api.php @@ -1686,20 +1686,16 @@ use \Friendica\Core\Config; ); if ($r[0]['body'] != "") { - if (!intval(get_config('system','old_share'))) { - if (strpos($r[0]['body'], "[/share]") !== false) { - $pos = strpos($r[0]['body'], "[share"); - $post = substr($r[0]['body'], $pos); - } else { - $post = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']); - - $post .= $r[0]['body']; - $post .= "[/share]"; - } - $_REQUEST['body'] = $post; - } else - $_REQUEST['body'] = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8')."[url=".$r[0]['reply_url']."]".$r[0]['reply_author']."[/url] \n".$r[0]['body']; + if (strpos($r[0]['body'], "[/share]") !== false) { + $pos = strpos($r[0]['body'], "[share"); + $post = substr($r[0]['body'], $pos); + } else { + $post = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']); + $post .= $r[0]['body']; + $post .= "[/share]"; + } + $_REQUEST['body'] = $post; $_REQUEST['profile_uid'] = api_user(); $_REQUEST['type'] = 'wall'; $_REQUEST['api_source'] = true; diff --git a/include/auth.php b/include/auth.php index e3c8d92ee..57e9d9bf6 100644 --- a/include/auth.php +++ b/include/auth.php @@ -125,6 +125,7 @@ if (isset($_SESSION) && x($_SESSION,'authenticated') && (!x($_POST,'auth-params' $openid = new LightOpenID; $openid->identity = $openid_url; $_SESSION['openid'] = $openid_url; + $_SESSION['remember'] = $_POST['remember']; $openid->returnUrl = App::get_baseurl(true).'/openid'; goaway($openid->authUrl()); } catch (Exception $e) { @@ -178,17 +179,12 @@ if (isset($_SESSION) && x($_SESSION,'authenticated') && (!x($_POST,'auth-params' goaway(z_root()); } - // If the user specified to remember the authentication, then set a cookie - // that expires after one week (the default is when the browser is closed). - // The cookie will be renewed automatically. - // The week ensures that sessions will expire after some inactivity. - if ($_POST['remember']) - new_cookie(604800, $r[0]); - else + if (! $_POST['remember']) { new_cookie(0); // 0 means delete on browser exit + } // if we haven't failed up this point, log them in. - + $_SESSION['remember'] = $_POST['remember']; $_SESSION['last_login_date'] = datetime_convert('UTC','UTC'); authenticate_success($record, true, true); } @@ -203,39 +199,3 @@ function nuke_session() { session_unset(); session_destroy(); } - -/** - * @brief Calculate the hash that is needed for the "Friendica" cookie - * - * @param array $user Record from "user" table - * - * @return string Hashed data - */ -function cookie_hash($user) { - return(hash("sha256", get_config("system", "site_prvkey"). - $user["uprvkey"]. - $user["password"])); -} - -/** - * @brief Set the "Friendica" cookie - * - * @param int $time - * @param array $user Record from "user" table - */ -function new_cookie($time, $user = array()) { - - if ($time != 0) - $time = $time + time(); - - if ($user) - $value = json_encode(array("uid" => $user["uid"], - "hash" => cookie_hash($user), - "ip" => $_SERVER['REMOTE_ADDR'])); - else - $value = ""; - - setcookie("Friendica", $value, $time, "/", "", - (get_config('system', 'ssl_policy') == SSL_POLICY_FULL), true); - -} diff --git a/include/conversation.php b/include/conversation.php index a1d086cb9..93c42cd7b 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -416,8 +416,8 @@ These Fields are not added below (yet). They are here to for bug search. `item`.`shadow`, */ - return "`item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`, - `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`, + return "`item`.`author-id`, `item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`, + `item`.`owner-id`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`, `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`, `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`, `item`.`commented`, `item`.`created`, `item`.`edited`, @@ -1066,8 +1066,9 @@ function builtin_activity_puller($item, &$conv_responses) { else $conv_responses[$mode][$item['thr-parent']] ++; - if((local_user()) && (local_user() == $item['uid']) && ($item['self'])) + if (public_contact() == $item['author-id']) { $conv_responses[$mode][$item['thr-parent'] . '-self'] = 1; + } $conv_responses[$mode][$item['thr-parent'] . '-l'][] = $url; diff --git a/include/create_shadowentry.php b/include/create_shadowentry.php index 005295c97..98db23f9e 100644 --- a/include/create_shadowentry.php +++ b/include/create_shadowentry.php @@ -6,26 +6,9 @@ * This script is started from mod/item.php to save some time when doing a post. */ -use \Friendica\Core\Config; - -require_once("boot.php"); require_once("include/threads.php"); function create_shadowentry_run($argv, $argc) { - global $a, $db; - - if (is_null($a)) - $a = new App; - - if (is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - } - - Config::load(); - if ($argc != 2) { return; } @@ -34,9 +17,4 @@ function create_shadowentry_run($argv, $argc) { add_shadow_entry($message_id); } - -if (array_search(__file__,get_included_files())===0){ - create_shadowentry_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} ?> diff --git a/include/cron.php b/include/cron.php index 26ff728f4..7b261aabf 100644 --- a/include/cron.php +++ b/include/cron.php @@ -1,35 +1,11 @@ maxload_reached()) - return; - if (App::is_already_running('cron', 'include/cron.php', 540)) - return; - } - $last = get_config('system','last_cron'); $poll_interval = intval(get_config('system','cron_interval')); @@ -64,10 +30,6 @@ function cron_run(&$argv, &$argc){ } } - $a->set_baseurl(get_config('system','url')); - - load_hooks(); - logger('cron: start'); // run queue delivery process in the background @@ -85,34 +47,17 @@ function cron_run(&$argv, &$argc){ // Expire and remove user entries cron_expire_and_remove_users(); - // If the worker is active, split the jobs in several sub processes - if (get_config("system", "worker")) { - // Check OStatus conversations - proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_mentions"); + // Check OStatus conversations + proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_mentions"); - // Check every conversation - proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_conversations"); + // Check every conversation + proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_conversations"); - // Call possible post update functions - proc_run(PRIORITY_LOW, "include/cronjobs.php", "post_update"); + // Call possible post update functions + proc_run(PRIORITY_LOW, "include/cronjobs.php", "post_update"); - // update nodeinfo data - proc_run(PRIORITY_LOW, "include/cronjobs.php", "nodeinfo"); - } else { - // Check OStatus conversations - // Check only conversations with mentions (for a longer time) - ostatus::check_conversations(true); - - // Check every conversation - ostatus::check_conversations(false); - - // Call possible post update functions - // see include/post_update.php for more details - post_update(); - - // update nodeinfo data - nodeinfo_cron(); - } + // update nodeinfo data + proc_run(PRIORITY_LOW, "include/cronjobs.php", "nodeinfo"); // once daily run birthday_updates and then expire in background @@ -123,6 +68,8 @@ function cron_run(&$argv, &$argc){ update_contact_birthdays(); + proc_run(PRIORITY_LOW, "include/discover_poco.php", "update_server"); + proc_run(PRIORITY_LOW, "include/discover_poco.php", "suggestions"); set_config('system','last_expire_day',$d2); @@ -213,14 +160,6 @@ function cron_poll_contacts($argc, $argv) { $force = true; } - $interval = intval(get_config('system','poll_interval')); - if (!$interval) - $interval = ((get_config('system','delivery_interval') === false) ? 3 : intval(get_config('system','delivery_interval'))); - - // If we are using the worker we don't need a delivery interval - if (get_config("system", "worker")) - $interval = false; - $sql_extra = (($manual_id) ? " AND `id` = $manual_id " : ""); reload_plugins(); @@ -335,9 +274,6 @@ function cron_poll_contacts($argc, $argv) { } else { proc_run(PRIORITY_LOW, 'include/onepoll.php', $contact['id']); } - - if($interval) - @time_sleep_until(microtime(true) + (float) $interval); } } } @@ -488,8 +424,3 @@ function cron_repair_database() { /// - remove children when parent got lost /// - set contact-id in item when not present } - -if (array_search(__file__,get_included_files())===0){ - cron_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} diff --git a/include/cronhooks.php b/include/cronhooks.php index 72b86be42..bea0f6a19 100644 --- a/include/cronhooks.php +++ b/include/cronhooks.php @@ -2,37 +2,11 @@ use \Friendica\Core\Config; -require_once("boot.php"); - function cronhooks_run(&$argv, &$argc){ - global $a, $db; + global $a; - if(is_null($a)) { - $a = new App; - } - - if(is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - }; - - require_once('include/session.php'); require_once('include/datetime.php'); - Config::load(); - - // Don't check this stuff if the function is called by the poller - if (App::callstack() != "poller_run") { - if ($a->maxload_reached()) - return; - if (App::is_already_running('cronhooks', 'include/cronhooks.php', 1140)) - return; - } - - load_hooks(); - if (($argc == 2) AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) { foreach ($a->hooks["cron"] as $hook) if ($hook[1] == $argv[1]) { @@ -42,7 +16,7 @@ function cronhooks_run(&$argv, &$argc){ return; } - $last = get_config('system','last_cronhook'); + $last = get_config('system', 'last_cronhook'); $poll_interval = intval(get_config('system','cronhook_interval')); if(! $poll_interval) @@ -62,22 +36,16 @@ function cronhooks_run(&$argv, &$argc){ $d = datetime_convert(); - if (get_config("system", "worker") AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) { + if (is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) { foreach ($a->hooks["cron"] as $hook) { logger("Calling cronhooks for '".$hook[1]."'", LOGGER_DEBUG); proc_run(PRIORITY_MEDIUM, "include/cronhooks.php", $hook[1]); } - } else - call_hooks('cron', $d); + } logger('cronhooks: end'); - set_config('system','last_cronhook', time()); + set_config('system', 'last_cronhook', time()); return; } - -if (array_search(__file__,get_included_files())===0){ - cronhooks_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} diff --git a/include/cronjobs.php b/include/cronjobs.php index f0a56370b..5cc2bf132 100644 --- a/include/cronjobs.php +++ b/include/cronjobs.php @@ -1,44 +1,14 @@ set_baseurl(get_config('system','url')); - // No parameter set? So return if ($argc <= 1) return; @@ -71,8 +41,3 @@ function cronjobs_run(&$argv, &$argc){ return; } - -if (array_search(__file__,get_included_files())===0){ - cronjobs_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} diff --git a/include/dba.php b/include/dba.php index 8e2d18db6..62728acae 100644 --- a/include/dba.php +++ b/include/dba.php @@ -1,17 +1,5 @@ error = sprintf( t('Cannot locate DNS info for database server \'%s\''), $server); + $this->error = sprintf(t('Cannot locate DNS info for database server \'%s\''), $server); $this->connected = false; $this->db = null; return; @@ -61,37 +48,52 @@ class dba { } } - if (class_exists('mysqli')) { - $this->db = @new mysqli($server,$user,$pass,$db); - if (! mysqli_connect_errno()) { + if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) { + $this->driver = 'pdo'; + $connect = "mysql:host=".$server.";dbname=".$db; + if (isset($a->config["system"]["db_charset"])) { + $connect .= ";charset=".$a->config["system"]["db_charset"]; + } + $this->db = @new PDO($connect, $user, $pass); + if (!$this->db->errorCode()) { $this->connected = true; } - if (isset($a->config["system"]["db_charset"])) { - $this->db->set_charset($a->config["system"]["db_charset"]); + } elseif (class_exists('mysqli')) { + $this->driver = 'mysqli'; + $this->db = @new mysqli($server,$user,$pass,$db); + if (!mysqli_connect_errno()) { + $this->connected = true; + + if (isset($a->config["system"]["db_charset"])) { + $this->db->set_charset($a->config["system"]["db_charset"]); + } } - } else { - $this->mysqli = false; + } elseif (function_exists('mysql_connect')) { + $this->driver = 'mysql'; $this->db = mysql_connect($server,$user,$pass); if ($this->db && mysql_select_db($db,$this->db)) { $this->connected = true; + + if (isset($a->config["system"]["db_charset"])) { + mysql_set_charset($a->config["system"]["db_charset"], $this->db); + } + } + } else { + // No suitable SQL driver was found. + if (!$install) { + system_unavailable(); } - if (isset($a->config["system"]["db_charset"])) - mysql_set_charset($a->config["system"]["db_charset"], $this->db); } + if (!$this->connected) { $this->db = null; if (!$install) { system_unavailable(); } } - $a->save_timestamp($stamp1, "network"); } - public function getdb() { - return $this->db; - } - /** * @brief Returns the MySQL server version string * @@ -101,12 +103,18 @@ class dba { * @return string */ public function server_info() { - if ($this->mysqli) { - $return = $this->db->server_info; - } else { - $return = mysql_get_server_info($this->db); + switch ($this->driver) { + case 'pdo': + $version = $this->db->getAttribute(PDO::ATTR_SERVER_VERSION); + break; + case 'mysqli': + $version = $this->db->server_info; + break; + case 'mysql': + $version = mysql_get_server_info($this->db); + break; } - return $return; + return $version; } /** @@ -130,12 +138,18 @@ class dba { return 0; } - if ($this->mysqli) { - $return = $this->result->num_rows; - } else { - $return = mysql_num_rows($this->result); + switch ($this->driver) { + case 'pdo': + $rows = $this->result->rowCount(); + break; + case 'mysqli': + $rows = $this->result->num_rows; + break; + case 'mysql': + $rows = mysql_num_rows($this->result); + break; } - return $return; + return $rows; } /** @@ -172,8 +186,9 @@ class dba { if ((intval($a->config["system"]["db_loglimit_index"]) > 0)) { $log = (in_array($row['key'], $watchlist) AND ($row['rows'] >= intval($a->config["system"]["db_loglimit_index"]))); - } else + } else { $log = false; + } if ((intval($a->config["system"]["db_loglimit_index_high"]) > 0) AND ($row['rows'] >= intval($a->config["system"]["db_loglimit_index_high"]))) { $log = true; @@ -203,13 +218,7 @@ class dba { $this->error = ''; - // Check the connection (This can reconnect the connection - if configured) - if ($this->mysqli) { - $connected = $this->db->ping(); - } else { - $connected = mysql_ping($this->db); - } - $connstr = ($connected ? "Connected" : "Disonnected"); + $connstr = ($this->connected() ? "Connected" : "Disonnected"); $stamp1 = microtime(true); @@ -219,10 +228,22 @@ class dba { $sql = "/*".$a->callstack()." */ ".$sql; } - if ($this->mysqli) { - $result = @$this->db->query($sql); - } else { - $result = @mysql_query($sql,$this->db); + $columns = 0; + + switch ($this->driver) { + case 'pdo': + $result = @$this->db->query($sql); + // Is used to separate between queries that returning data - or not + if (!is_bool($result)) { + $columns = $result->columnCount(); + } + break; + case 'mysqli': + $result = @$this->db->query($sql); + break; + case 'mysql': + $result = @mysql_query($sql,$this->db); + break; } $stamp2 = microtime(true); $duration = (float)($stamp2-$stamp1); @@ -243,16 +264,27 @@ class dba { } } - if ($this->mysqli) { - if ($this->db->errno) { - $this->error = $this->db->error; - $this->errorno = $this->db->errno; - } - } elseif (mysql_errno($this->db)) { - $this->error = mysql_error($this->db); - $this->errorno = mysql_errno($this->db); + switch ($this->driver) { + case 'pdo': + $errorInfo = $this->db->errorInfo(); + if ($errorInfo) { + $this->error = $errorInfo[2]; + $this->errorno = $errorInfo[1]; + } + break; + case 'mysqli': + if ($this->db->errno) { + $this->error = $this->db->error; + $this->errorno = $this->db->errno; + } + break; + case 'mysql': + if (mysql_errno($this->db)) { + $this->error = mysql_error($this->db); + $this->errorno = mysql_errno($this->db); + } + break; } - if (strlen($this->error)) { logger('DB Error ('.$connstr.') '.$this->errorno.': '.$this->error); } @@ -266,10 +298,16 @@ class dba { } elseif ($result === true) { $mesg = 'true'; } else { - if ($this->mysqli) { - $mesg = $result->num_rows . ' results' . EOL; - } else { - $mesg = mysql_num_rows($result) . ' results' . EOL; + switch ($this->driver) { + case 'pdo': + $mesg = $result->rowCount().' results'.EOL; + break; + case 'mysqli': + $mesg = $result->num_rows.' results'.EOL; + break; + case 'mysql': + $mesg = mysql_num_rows($result).' results'.EOL; + break; } } @@ -293,7 +331,7 @@ class dba { } } - if (($result === true) || ($result === false)) { + if (is_bool($result)) { return $result; } if ($onlyquery) { @@ -302,18 +340,32 @@ class dba { } $r = array(); - if ($this->mysqli) { - if ($result->num_rows) { - while($x = $result->fetch_array(MYSQLI_ASSOC)) + switch ($this->driver) { + case 'pdo': + while ($x = $result->fetch(PDO::FETCH_ASSOC)) { $r[] = $x; + } + $result->closeCursor(); + break; + case 'mysqli': + while ($x = $result->fetch_array(MYSQLI_ASSOC)) { + $r[] = $x; + } $result->free_result(); - } - } else { - if (mysql_num_rows($result)) { - while($x = mysql_fetch_array($result, MYSQL_ASSOC)) + break; + case 'mysql': + while ($x = mysql_fetch_array($result, MYSQL_ASSOC)) { $r[] = $x; + } mysql_free_result($result); - } + break; + } + + // PDO doesn't return "true" on successful operations - like mysqli does + // Emulate this behaviour by checking if the query returned data and had columns + // This should be reliable enough + if (($this->driver == 'pdo') AND (count($r) == 0) AND ($columns == 0)) { + return true; } //$a->save_timestamp($stamp1, "database"); @@ -328,12 +380,16 @@ class dba { $x = false; if ($this->result) { - if ($this->mysqli) { - if ($this->result->num_rows) + switch ($this->driver) { + case 'pdo': + $x = $this->result->fetch(PDO::FETCH_ASSOC); + break; + case 'mysqli': $x = $this->result->fetch_array(MYSQLI_ASSOC); - } else { - if (mysql_num_rows($this->result)) + break; + case 'mysql': $x = mysql_fetch_array($this->result, MYSQL_ASSOC); + break; } } return($x); @@ -341,10 +397,16 @@ class dba { public function qclose() { if ($this->result) { - if ($this->mysqli) { - $this->result->free_result(); - } else { - mysql_free_result($this->result); + switch ($this->driver) { + case 'pdo': + $this->result->closeCursor(); + break; + case 'mysqli': + $this->result->free_result(); + break; + case 'mysql': + mysql_free_result($this->result); + break; } } } @@ -355,35 +417,65 @@ class dba { public function escape($str) { if ($this->db && $this->connected) { - if ($this->mysqli) { - return @$this->db->real_escape_string($str); - } else { - return @mysql_real_escape_string($str,$this->db); + switch ($this->driver) { + case 'pdo': + return substr(@$this->db->quote($str, PDO::PARAM_STR), 1, -1); + case 'mysqli': + return @$this->db->real_escape_string($str); + case 'mysql': + return @mysql_real_escape_string($str,$this->db); } } } function connected() { - if ($this->mysqli) { - $connected = $this->db->ping(); - } else { - $connected = mysql_ping($this->db); + switch ($this->driver) { + case 'pdo': + // Not sure if this really is working like expected + $connected = ($this->db->getAttribute(PDO::ATTR_CONNECTION_STATUS) != ""); + break; + case 'mysqli': + $connected = $this->db->ping(); + break; + case 'mysql': + $connected = mysql_ping($this->db); + break; } return $connected; } + function insert_id() { + switch ($this->driver) { + case 'pdo': + $id = $this->db->lastInsertId(); + break; + case 'mysqli': + $id = $this->db->insert_id; + break; + case 'mysql': + $id = mysql_insert_id($this->db); + break; + } + return $id; + } + function __destruct() { if ($this->db) { - if ($this->mysqli) { - $this->db->close(); - } else { - mysql_close($this->db); + switch ($this->driver) { + case 'pdo': + $this->db = null; + break; + case 'mysqli': + $this->db->close(); + break; + case 'mysql': + mysql_close($this->db); + break; } } } -}} +} -if (! function_exists('printable')) { function printable($s) { $s = preg_replace("~([\x01-\x08\x0E-\x0F\x10-\x1F\x7F-\xFF])~",".", $s); $s = str_replace("\x00",'.',$s); @@ -391,37 +483,32 @@ function printable($s) { $s = escape_tags($s); } return $s; -}} +} // Procedural functions -if (! function_exists('dbg')) { function dbg($state) { global $db; + if ($db) { $db->dbg($state); } -}} +} -if (! function_exists('dbesc')) { function dbesc($str) { global $db; + if ($db && $db->connected) { return($db->escape($str)); } else { return(str_replace("'","\\'",$str)); } -}} - - +} // Function: q($sql,$args); // Description: execute SQL query with printf style args. // Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d", // 'user', 1); - -if (! function_exists('q')) { function q($sql) { - global $db; $args = func_get_args(); unset($args[0]); @@ -445,8 +532,7 @@ function q($sql) { */ logger('dba: no database: ' . print_r($args,true)); return false; - -}} +} /** * @brief Performs a query with "dirty reads" @@ -458,8 +544,8 @@ function q($sql) { * @return array Query array */ function qu($sql) { - global $db; + $args = func_get_args(); unset($args[0]); @@ -484,7 +570,6 @@ function qu($sql) { */ logger('dba: no database: ' . print_r($args,true)); return false; - } /** @@ -492,40 +577,31 @@ function qu($sql) { * Raw db query, no arguments * */ - -if (! function_exists('dbq')) { function dbq($sql) { - global $db; + if ($db && $db->connected) { $ret = $db->q($sql); } else { $ret = false; } return $ret; -}} - +} // Caller is responsible for ensuring that any integer arguments to // dbesc_array are actually integers and not malformed strings containing // SQL injection vectors. All integer array elements should be specifically // cast to int to avoid trouble. - - -if (! function_exists('dbesc_array_cb')) { function dbesc_array_cb(&$item, $key) { if (is_string($item)) $item = dbesc($item); -}} +} - -if (! function_exists('dbesc_array')) { function dbesc_array(&$arr) { if (is_array($arr) && count($arr)) { array_walk($arr,'dbesc_array_cb'); } -}} - +} function dba_timer() { return microtime(true); diff --git a/include/dbclean.php b/include/dbclean.php index 8408ad188..bff4ff2a2 100644 --- a/include/dbclean.php +++ b/include/dbclean.php @@ -5,26 +5,8 @@ */ use \Friendica\Core\Config; -use \Friendica\Core\PConfig; - -require_once("boot.php"); function dbclean_run(&$argv, &$argc) { - global $a, $db; - - if (is_null($a)) { - $a = new App; - } - - if (is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - } - - Config::load(); - if (!Config::get('system', 'dbclean', false)) { return; } @@ -35,7 +17,7 @@ function dbclean_run(&$argv, &$argc) { $stage = 0; } - if (Config::get("system", "worker") AND ($stage == 0)) { + if ($stage == 0) { proc_run(PRIORITY_LOW, 'include/dbclean.php', 1); proc_run(PRIORITY_LOW, 'include/dbclean.php', 2); proc_run(PRIORITY_LOW, 'include/dbclean.php', 3); @@ -56,12 +38,8 @@ function remove_orphans($stage = 0) { $count = 0; - // With activated worker we split the deletion in many small tasks - if (Config::get("system", "worker")) { - $limit = 1000; - } else { - $limit = 10000; - } + // We split the deletion in many small tasks + $limit = 1000; if (($stage == 1) OR ($stage == 0)) { logger("Deleting old global item entries from item table without user copy"); @@ -159,14 +137,9 @@ function remove_orphans($stage = 0) { } // Call it again if not all entries were purged - if (($stage != 0) AND ($count > 0) AND Config::get("system", "worker")) { + if (($stage != 0) AND ($count > 0)) { proc_run(PRIORITY_MEDIUM, 'include/dbclean.php'); } } - -if (array_search(__file__,get_included_files())===0){ - dbclean_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} ?> diff --git a/include/dbstructure.php b/include/dbstructure.php index 85afc4bbd..7bf403cd6 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -712,18 +712,6 @@ function db_definition($charset) { "uid" => array("uid"), ) ); - $database["deliverq"] = array( - "fields" => array( - "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), - "cmd" => array("type" => "varbinary(32)", "not null" => "1", "default" => ""), - "item" => array("type" => "int(11)", "not null" => "1", "default" => "0"), - "contact" => array("type" => "int(11)", "not null" => "1", "default" => "0"), - ), - "indexes" => array( - "PRIMARY" => array("id"), - "cmd_item_contact" => array("UNIQUE", "cmd", "item", "contact"), - ) - ); $database["event"] = array( "fields" => array( "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), diff --git a/include/dbupdate.php b/include/dbupdate.php index 14709208f..725eca737 100644 --- a/include/dbupdate.php +++ b/include/dbupdate.php @@ -2,32 +2,12 @@ use \Friendica\Core\Config; -require_once("boot.php"); - function dbupdate_run(&$argv, &$argc) { - global $a, $db; - - if(is_null($a)){ - $a = new App; - } - - if(is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - } - - Config::load(); + global $a; // We are deleting the latest dbupdate entry. // This is done to avoid endless loops because the update was interupted. - Config::delete('database','dbupdate_'.DB_UPDATE_VERSION); + Config::delete('database', 'dbupdate_'.DB_UPDATE_VERSION); update_db($a); } - -if (array_search(__file__,get_included_files())===0){ - dbupdate_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} diff --git a/include/delivery.php b/include/delivery.php index 8ccb19ced..faa1cad67 100644 --- a/include/delivery.php +++ b/include/delivery.php @@ -2,44 +2,25 @@ use \Friendica\Core\Config; -require_once("boot.php"); require_once('include/queue_fn.php'); require_once('include/html2plain.php'); -require_once("include/Scrape.php"); +require_once('include/Scrape.php'); require_once('include/diaspora.php'); -require_once("include/ostatus.php"); -require_once("include/dfrn.php"); +require_once('include/ostatus.php'); +require_once('include/dfrn.php'); function delivery_run(&$argv, &$argc){ - global $a, $db; + global $a; - if (is_null($a)) { - $a = new App; - } - - if (is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - } - - require_once("include/session.php"); - require_once("include/datetime.php"); + require_once('include/datetime.php'); require_once('include/items.php'); require_once('include/bbcode.php'); require_once('include/email.php'); - Config::load(); - - load_hooks(); - if ($argc < 3) { return; } - $a->set_baseurl(get_config('system','url')); - logger('delivery: invoked: '. print_r($argv,true), LOGGER_DEBUG); $cmd = $argv[1]; @@ -49,30 +30,6 @@ function delivery_run(&$argv, &$argc){ $contact_id = intval($argv[$x]); - /// @todo When switching completely to the worker we won't need this anymore - // Some other process may have delivered this item already. - - $r = q("SELECT * FROM `deliverq` WHERE `cmd` = '%s' AND `item` = %d AND `contact` = %d LIMIT 1", - dbesc($cmd), - dbesc($item_id), - dbesc($contact_id) - ); - if (!dbm::is_result($r)) { - continue; - } - - if ($a->maxload_reached()) { - return; - } - - // It's ours to deliver. Remove it from the queue. - - q("DELETE FROM `deliverq` WHERE `cmd` = '%s' AND `item` = %d AND `contact` = %d", - dbesc($cmd), - dbesc($item_id), - dbesc($contact_id) - ); - if (!$item_id || !$contact_id) { continue; } @@ -577,8 +534,3 @@ function delivery_run(&$argv, &$argc){ return; } - -if (array_search(__file__,get_included_files())===0){ - delivery_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} diff --git a/include/directory.php b/include/directory.php index 2ca367d36..088adbe78 100644 --- a/include/directory.php +++ b/include/directory.php @@ -1,36 +1,16 @@ set_baseurl(get_config('system','url')); - - $dir = get_config('system','directory'); - - if(! strlen($dir)) + if (!strlen($dir)) { return; + } $dir .= "/submit"; @@ -39,13 +19,8 @@ function directory_run(&$argv, &$argc){ call_hooks('globaldir_update', $arr); logger('Updating directory: ' . $arr['url'], LOGGER_DEBUG); - if(strlen($arr['url'])) + if (strlen($arr['url'])) { fetch_url($dir . '?url=' . bin2hex($arr['url'])); - + } return; } - -if (array_search(__file__,get_included_files())===0){ - directory_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} diff --git a/include/discover_poco.php b/include/discover_poco.php index 10c741ae5..f0bfb646b 100644 --- a/include/discover_poco.php +++ b/include/discover_poco.php @@ -2,62 +2,64 @@ use \Friendica\Core\Config; -require_once("boot.php"); -require_once("include/socgraph.php"); +require_once('include/socgraph.php'); +require_once('include/datetime.php'); -function discover_poco_run(&$argv, &$argc){ - global $a, $db; +function discover_poco_run(&$argv, &$argc) { - if(is_null($a)) { - $a = new App; - } + /* + This function can be called in these ways: + - dirsearch : Searches for "search pattern" in the directory. "search pattern" is url encoded. + - checkcontact: Updates gcontact entries + - suggestions: Discover other servers for their contacts. + - server : Searches for the poco server list. "poco url" is base64 encoded. + - update_server: Frequently check the first 250 servers for vitality. + */ - if(is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - }; - - require_once('include/session.php'); - require_once('include/datetime.php'); - - Config::load(); - - // Don't check this stuff if the function is called by the poller - if (App::callstack() != "poller_run") - if ($a->maxload_reached()) - return; - - if(($argc > 2) && ($argv[1] == "dirsearch")) { + if (($argc > 2) && ($argv[1] == "dirsearch")) { $search = urldecode($argv[2]); $mode = 1; - } elseif(($argc == 2) && ($argv[1] == "checkcontact")) { + } elseif (($argc == 2) && ($argv[1] == "checkcontact")) { $mode = 2; - } elseif(($argc == 2) && ($argv[1] == "suggestions")) { + } elseif (($argc == 2) && ($argv[1] == "suggestions")) { $mode = 3; + } elseif (($argc == 3) && ($argv[1] == "server")) { + $mode = 4; + } elseif (($argc == 2) && ($argv[1] == "update_server")) { + $mode = 5; } elseif ($argc == 1) { $search = ""; $mode = 0; - } else + } else { die("Unknown or missing parameter ".$argv[1]."\n"); - - // Don't check this stuff if the function is called by the poller - if (App::callstack() != "poller_run") - if (App::is_already_running('discover_poco'.$mode.urlencode($search), 'include/discover_poco.php', 1140)) - return; - - $a->set_baseurl(get_config('system','url')); - - load_hooks(); + } logger('start '.$search); - if ($mode==3) + if ($mode == 5) { + update_server(); + } elseif ($mode == 4) { + $server_url = base64_decode($argv[2]); + if ($server_url == "") { + return; + } + $server_url = filter_var($server_url, FILTER_SANITIZE_URL); + if (substr(normalise_link($server_url), 0, 7) != "http://") { + return; + } + $result = "Checking server ".$server_url." - "; + $ret = poco_check_server($server_url); + if ($ret) { + $result .= "success"; + } else { + $result .= "failed"; + } + logger($result, LOGGER_DEBUG); + } elseif ($mode == 3) { update_suggestions(); - elseif (($mode == 2) AND get_config('system','poco_completion')) + } elseif (($mode == 2) AND get_config('system','poco_completion')) { discover_users(); - elseif (($mode == 1) AND ($search != "") and get_config('system','poco_local_search')) { + } elseif (($mode == 1) AND ($search != "") and get_config('system','poco_local_search')) { discover_directory($search); gs_search_user($search); } elseif (($mode == 0) AND ($search == "") and (get_config('system','poco_discovery') > 0)) { @@ -74,6 +76,33 @@ function discover_poco_run(&$argv, &$argc){ return; } +/** + * @brief Updates the first 250 servers + * + */ +function update_server() { + $r = q("SELECT `url`, `created`, `last_failure`, `last_contact` FROM `gserver` ORDER BY rand()"); + + if (!dbm::is_result($r)) { + return; + } + + $updated = 0; + + foreach ($r AS $server) { + if (!poco_do_update($server["created"], "", $server["last_failure"], $server["last_contact"])) { + continue; + } + logger('Update server status for server '.$server["url"], LOGGER_DEBUG); + + proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", base64_encode($server["url"])); + + if (++$updated > 250) { + return; + } + } +} + function discover_users() { logger("Discover users", LOGGER_DEBUG); @@ -84,9 +113,9 @@ function discover_users() { dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_FEED)); - if (!$users) + if (!$users) { return; - + } $checked = 0; foreach ($users AS $user) { @@ -111,27 +140,29 @@ function discover_users() { continue; } - if ($user["server_url"] != "") + if ($user["server_url"] != "") { $server_url = $user["server_url"]; - else + } else { $server_url = poco_detect_server($user["url"]); - + } if (($server_url == "") OR poco_check_server($server_url, $gcontacts[0]["network"])) { logger('Check user '.$user["url"]); poco_last_updated($user["url"], true); - if (++$checked > 100) + if (++$checked > 100) { return; - } else + } + } else { q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc(normalise_link($user["url"]))); + } } } function discover_directory($search) { $data = Cache::get("dirsearch:".$search); - if (!is_null($data)){ + if (!is_null($data)) { // Only search for the same item every 24 hours if (time() < $data + (60 * 60 * 24)) { logger("Already searched for ".$search." in the last 24 hours", LOGGER_DEBUG); @@ -142,7 +173,7 @@ function discover_directory($search) { $x = fetch_url(get_server()."/lsearch?p=1&n=500&search=".urlencode($search)); $j = json_decode($x); - if(count($j->results)) + if (count($j->results)) { foreach($j->results as $jj) { // Check if the contact already exists $exists = q("SELECT `id`, `last_contact`, `last_failure`, `updated` FROM `gcontact` WHERE `nurl` = '%s'", normalise_link($jj->url)); @@ -150,32 +181,33 @@ function discover_directory($search) { logger("Profile ".$jj->url." already exists (".$search.")", LOGGER_DEBUG); if (($exists[0]["last_contact"] < $exists[0]["last_failure"]) AND - ($exists[0]["updated"] < $exists[0]["last_failure"])) + ($exists[0]["updated"] < $exists[0]["last_failure"])) { continue; - + } // Update the contact poco_last_updated($jj->url); continue; } - // Harcoded paths aren't so good. But in this case it is okay. - // First: We only will get Friendica contacts (which always are using this url schema) - // Second: There will be no further problems if we are doing a mistake - $server_url = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$1$2", $jj->url); - if ($server_url != $jj->url) + $server_url = poco_detect_server($jj->url); + if ($server_url != '') { if (!poco_check_server($server_url)) { logger("Friendica server ".$server_url." doesn't answer.", LOGGER_DEBUG); continue; } - logger("Friendica server ".$server_url." seems to be okay.", LOGGER_DEBUG); + logger("Friendica server ".$server_url." seems to be okay.", LOGGER_DEBUG); + } - logger("Check if profile ".$jj->url." is reachable (".$search.")", LOGGER_DEBUG); $data = probe_url($jj->url); if ($data["network"] == NETWORK_DFRN) { + logger("Profile ".$jj->url." is reachable (".$search.")", LOGGER_DEBUG); logger("Add profile ".$jj->url." to local directory (".$search.")", LOGGER_DEBUG); poco_check($data["url"], $data["name"], $data["network"], $data["photo"], "", "", "", $jj->tags, $data["addr"], "", 0); + } else { + logger("Profile ".$jj->url." is not responding or no Friendica contact - but network ".$data["network"], LOGGER_DEBUG); } } + } Cache::set("dirsearch:".$search, time(), CACHE_DAY); } @@ -195,14 +227,14 @@ function gs_search_user($search) { $url = "http://gstools.org/api/users_search/".urlencode($search); $result = z_fetch_url($url); - if (!$result["success"]) + if (!$result["success"]) { return false; - + } $contacts = json_decode($result["body"]); - if ($contacts->status == 'ERROR') + if ($contacts->status == 'ERROR') { return false; - + } foreach($contacts->data AS $user) { $contact = probe_url($user->site_address."/".$user->name); if ($contact["network"] != NETWORK_PHANTOM) { @@ -211,9 +243,3 @@ function gs_search_user($search) { } } } - - -if (array_search(__file__,get_included_files())===0){ - discover_poco_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} diff --git a/include/expire.php b/include/expire.php index 855d7fb5e..35b109a50 100644 --- a/include/expire.php +++ b/include/expire.php @@ -2,32 +2,13 @@ use \Friendica\Core\Config; -require_once("boot.php"); - function expire_run(&$argv, &$argc){ - global $a, $db; + global $a; - if(is_null($a)) { - $a = new App; - } - - if(is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - }; - - require_once('include/session.php'); require_once('include/datetime.php'); require_once('include/items.php'); require_once('include/Contact.php'); - Config::load(); - - $a->set_baseurl(get_config('system','url')); - - // physically remove anything that has been deleted for more than two months $r = q("delete from item where deleted = 1 and changed < UTC_TIMESTAMP() - INTERVAL 60 DAY"); @@ -53,8 +34,3 @@ function expire_run(&$argv, &$argc){ return; } - -if (array_search(__file__,get_included_files())===0){ - expire_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} diff --git a/include/feed.php b/include/feed.php index e0fef50db..295993370 100644 --- a/include/feed.php +++ b/include/feed.php @@ -17,11 +17,11 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { $a = get_app(); - if (!$simulate) + if (!$simulate) { logger("Import Atom/RSS feed '".$contact["name"]."' (Contact ".$contact["id"].") for user ".$importer["uid"], LOGGER_DEBUG); - else + } else { logger("Test Atom/RSS feed", LOGGER_DEBUG); - + } if ($xml == "") { logger('XML is empty.', LOGGER_DEBUG); return; @@ -45,63 +45,69 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { $author["author-link"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:link/text()')->item(0)->nodeValue; $author["author-name"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:title/text()')->item(0)->nodeValue; - if ($author["author-name"] == "") + if ($author["author-name"] == "") { $author["author-name"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:description/text()')->item(0)->nodeValue; - + } $entries = $xpath->query('/rdf:RDF/rss:item'); } // Is it Atom? if ($xpath->query('/atom:feed')->length > 0) { $alternate = $xpath->query("atom:link[@rel='alternate']")->item(0)->attributes; - if (is_object($alternate)) - foreach($alternate AS $attributes) - if ($attributes->name == "href") + if (is_object($alternate)) { + foreach($alternate AS $attributes) { + if ($attributes->name == "href") { $author["author-link"] = $attributes->textContent; - - if ($author["author-link"] == "") - $author["author-link"] = $author["author-id"]; - - if ($author["author-link"] == "") { - $self = $xpath->query("atom:link[@rel='self']")->item(0)->attributes; - if (is_object($self)) - foreach($self AS $attributes) - if ($attributes->name == "href") - $author["author-link"] = $attributes->textContent; + } + } } - if ($author["author-link"] == "") - $author["author-link"] = $xpath->evaluate('/atom:feed/atom:id/text()')->item(0)->nodeValue; + if ($author["author-link"] == "") { + $author["author-link"] = $author["author-id"]; + } + if ($author["author-link"] == "") { + $self = $xpath->query("atom:link[@rel='self']")->item(0)->attributes; + if (is_object($self)) { + foreach($self AS $attributes) { + if ($attributes->name == "href") { + $author["author-link"] = $attributes->textContent; + } + } + } + } + if ($author["author-link"] == "") { + $author["author-link"] = $xpath->evaluate('/atom:feed/atom:id/text()')->item(0)->nodeValue; + } $author["author-avatar"] = $xpath->evaluate('/atom:feed/atom:logo/text()')->item(0)->nodeValue; $author["author-name"] = $xpath->evaluate('/atom:feed/atom:title/text()')->item(0)->nodeValue; - if ($author["author-name"] == "") + if ($author["author-name"] == "") { $author["author-name"] = $xpath->evaluate('/atom:feed/atom:subtitle/text()')->item(0)->nodeValue; - - if ($author["author-name"] == "") + } + if ($author["author-name"] == "") { $author["author-name"] = $xpath->evaluate('/atom:feed/atom:author/atom:name/text()')->item(0)->nodeValue; - + } $value = $xpath->evaluate('atom:author/poco:displayName/text()')->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $author["author-name"] = $value; - + } if ($simulate) { $author["author-id"] = $xpath->evaluate('/atom:feed/atom:author/atom:uri/text()')->item(0)->nodeValue; $value = $xpath->evaluate('atom:author/poco:preferredUsername/text()')->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $author["author-nick"] = $value; - + } $value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $author["author-location"] = $value; - + } $value = $xpath->evaluate('atom:author/poco:note/text()')->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $author["author-about"] = $value; - + } } $author["edited"] = $author["created"] = $xpath->query('/atom:feed/atom:updated/text()')->item(0)->nodeValue; @@ -118,12 +124,12 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { $author["author-name"] = $xpath->evaluate('/rss/channel/title/text()')->item(0)->nodeValue; $author["author-avatar"] = $xpath->evaluate('/rss/channel/image/url/text()')->item(0)->nodeValue; - if ($author["author-name"] == "") + if ($author["author-name"] == "") { $author["author-name"] = $xpath->evaluate('/rss/channel/copyright/text()')->item(0)->nodeValue; - - if ($author["author-name"] == "") + } + if ($author["author-name"] == "") { $author["author-name"] = $xpath->evaluate('/rss/channel/description/text()')->item(0)->nodeValue; - + } $author["edited"] = $author["created"] = $xpath->query('/rss/channel/pubDate/text()')->item(0)->nodeValue; $author["app"] = $xpath->evaluate('/rss/channel/generator/text()')->item(0)->nodeValue; @@ -134,9 +140,9 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { if (!$simulate) { $author["author-link"] = $contact["url"]; - if ($author["author-name"] == "") + if ($author["author-name"] == "") { $author["author-name"] = $contact["name"]; - + } $author["author-avatar"] = $contact["thumb"]; $author["owner-link"] = $contact["url"]; @@ -171,33 +177,39 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { $entrylist = array(); - foreach ($entries AS $entry) + foreach ($entries AS $entry) { $entrylist[] = $entry; - + } foreach (array_reverse($entrylist) AS $entry) { $item = array_merge($header, $author); - if (is_object($alternate)) - foreach($alternate AS $attributes) - if ($attributes->name == "href") + $alternate = $xpath->query("atom:link[@rel='alternate']", $entry)->item(0)->attributes; + if (!is_object($alternate)) { + $alternate = $xpath->query("atom:link", $entry)->item(0)->attributes; + } + if (is_object($alternate)) { + foreach($alternate AS $attributes) { + if ($attributes->name == "href") { $item["plink"] = $attributes->textContent; - - if ($item["plink"] == "") + } + } + } + if ($item["plink"] == "") { $item["plink"] = $xpath->evaluate('link/text()', $entry)->item(0)->nodeValue; - - if ($item["plink"] == "") + } + if ($item["plink"] == "") { $item["plink"] = $xpath->evaluate('rss:link/text()', $entry)->item(0)->nodeValue; - + } $item["plink"] = original_url($item["plink"]); $item["uri"] = $xpath->evaluate('atom:id/text()', $entry)->item(0)->nodeValue; - if ($item["uri"] == "") + if ($item["uri"] == "") { $item["uri"] = $xpath->evaluate('guid/text()', $entry)->item(0)->nodeValue; - - if ($item["uri"] == "") + } + if ($item["uri"] == "") { $item["uri"] = $item["plink"]; - + } $item["parent-uri"] = $item["uri"]; if (!$simulate) { @@ -211,54 +223,50 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { $item["title"] = $xpath->evaluate('atom:title/text()', $entry)->item(0)->nodeValue; - if ($item["title"] == "") + if ($item["title"] == "") { $item["title"] = $xpath->evaluate('title/text()', $entry)->item(0)->nodeValue; - - if ($item["title"] == "") + } + if ($item["title"] == "") { $item["title"] = $xpath->evaluate('rss:title/text()', $entry)->item(0)->nodeValue; - - $alternate = $xpath->query("atom:link[@rel='alternate']", $entry)->item(0)->attributes; - if (!is_object($alternate)) - $alternate = $xpath->query("atom:link", $entry)->item(0)->attributes; - + } $published = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue; - if ($published == "") + if ($published == "") { $published = $xpath->query('pubDate/text()', $entry)->item(0)->nodeValue; - - if ($published == "") + } + if ($published == "") { $published = $xpath->query('dc:date/text()', $entry)->item(0)->nodeValue; - + } $updated = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue; - if ($updated == "") + if ($updated == "") { $updated = $published; - - if ($published != "") + } + if ($published != "") { $item["created"] = $published; - - if ($updated != "") + } + if ($updated != "") { $item["edited"] = $updated; - + } $creator = $xpath->query('author/text()', $entry)->item(0)->nodeValue; - if ($creator == "") + if ($creator == "") { $creator = $xpath->query('atom:author/atom:name/text()', $entry)->item(0)->nodeValue; - - if ($creator == "") + } + if ($creator == "") { $creator = $xpath->query('dc:creator/text()', $entry)->item(0)->nodeValue; - - if ($creator != "") + } + if ($creator != "") { $item["author-name"] = $creator; - - if ($pubDate != "") + } + if ($pubDate != "") { $item["edited"] = $item["created"] = $pubDate; - + } $creator = $xpath->query('dc:creator/text()', $entry)->item(0)->nodeValue; - if ($creator != "") + if ($creator != "") { $item["author-name"] = $creator; - + } /// @TODO ? // Ausland // @@ -273,12 +281,13 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { $title = ""; foreach($enclosure->attributes AS $attributes) { - if ($attributes->name == "url") + if ($attributes->name == "url") { $href = $attributes->textContent; - elseif ($attributes->name == "length") + } elseif ($attributes->name == "length") { $length = $attributes->textContent; - elseif ($attributes->name == "type") + } elseif ($attributes->name == "type") { $type = $attributes->textContent; + } } if(strlen($item["attach"])) $item["attach"] .= ','; @@ -292,9 +301,11 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { $preview = ""; // Handle enclosures and treat them as preview picture - foreach ($attachments AS $attachment) - if ($attachment["type"] == "image/jpeg") + foreach ($attachments AS $attachment) { + if ($attachment["type"] == "image/jpeg") { $preview = $attachment["link"]; + } + } $item["body"] = $item["title"].add_page_info($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]); $item["tag"] = add_page_keywords($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]); @@ -304,20 +315,20 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { } else { $body = trim($xpath->evaluate('atom:content/text()', $entry)->item(0)->nodeValue); - if ($body == "") + if ($body == "") { $body = trim($xpath->evaluate('content:encoded/text()', $entry)->item(0)->nodeValue); - - if ($body == "") + } + if ($body == "") { $body = trim($xpath->evaluate('description/text()', $entry)->item(0)->nodeValue); - - if ($body == "") + } + if ($body == "") { $body = trim($xpath->evaluate('atom:summary/text()', $entry)->item(0)->nodeValue); - + } // remove the content of the title if it is identically to the body // This helps with auto generated titles e.g. from tumblr - if (title_is_body($item["title"], $body)) + if (title_is_body($item["title"], $body)) { $item["title"] = ""; - + } $item["body"] = html2bbcode($body); } @@ -336,14 +347,16 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { $id = item_store($item, false, $notify); logger("Feed for contact ".$contact["url"]." stored under id ".$id); - } else + } else { $items[] = $item; - - if ($simulate) + } + if ($simulate) { break; + } } - if ($simulate) + if ($simulate) { return array("header" => $author, "items" => $items); + } } ?> diff --git a/include/gprobe.php b/include/gprobe.php index 4407fa6d6..719cfce48 100644 --- a/include/gprobe.php +++ b/include/gprobe.php @@ -2,36 +2,14 @@ use \Friendica\Core\Config; -require_once("boot.php"); require_once('include/Scrape.php'); require_once('include/socgraph.php'); +require_once('include/datetime.php'); function gprobe_run(&$argv, &$argc){ - global $a, $db; - - if(is_null($a)) { - $a = new App; - } - - if(is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - }; - - require_once('include/session.php'); - require_once('include/datetime.php'); - - Config::load(); - - $a->set_baseurl(get_config('system','url')); - - load_hooks(); - - if($argc != 2) + if ($argc != 2) { return; - + } $url = hex2bin($argv[1]); $r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1", @@ -74,8 +52,3 @@ function gprobe_run(&$argv, &$argc){ logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG); return; } - -if (array_search(__file__,get_included_files())===0){ - gprobe_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} diff --git a/include/like.php b/include/like.php index 210bde690..a53b90c03 100644 --- a/include/like.php +++ b/include/like.php @@ -18,155 +18,169 @@ require_once("include/diaspora.php"); function do_like($item_id, $verb) { $a = get_app(); - if(! local_user() && ! remote_user()) { + if (! local_user() && ! remote_user()) { return false; } - switch($verb) { + switch ($verb) { case 'like': + $bodyverb = t('%1$s likes %2$s\'s %3$s'); + $activity = ACTIVITY_LIKE; + break; case 'unlike': + $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s'); $activity = ACTIVITY_LIKE; break; case 'dislike': case 'undislike': + $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s'); $activity = ACTIVITY_DISLIKE; break; case 'attendyes': case 'unattendyes': + $bodyverb = t('%1$s is attending %2$s\'s %3$s'); $activity = ACTIVITY_ATTEND; break; case 'attendno': case 'unattendno': + $bodyverb = t('%1$s is not attending %2$s\'s %3$s'); $activity = ACTIVITY_ATTENDNO; break; case 'attendmaybe': case 'unattendmaybe': + $bodyverb = t('%1$s may attend %2$s\'s %3$s'); $activity = ACTIVITY_ATTENDMAYBE; break; default: + logger('like: unknown verb ' . $verb . ' for item ' . $item_id); return false; - break; } + // Enable activity toggling instead of on/off + $event_verb_flag = $activity === ACTIVITY_ATTEND || $activity === ACTIVITY_ATTENDNO || $activity === ACTIVITY_ATTENDMAYBE; + logger('like: verb ' . $verb . ' item ' . $item_id); - $r = q("SELECT * FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1", + // Retrieve item + $items = q("SELECT * FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1", dbesc($item_id), dbesc($item_id) ); - if(! $item_id || (! dbm::is_result($r))) { - logger('like: no item ' . $item_id); + if (! $item_id || ! dbm::is_result($items)) { + logger('like: unknown item ' . $item_id); return false; } - $item = $r[0]; + $item = $items[0]; - $owner_uid = $item['uid']; - - if (! can_write_wall($a,$owner_uid)) { + if (! can_write_wall($a, $item['uid'])) { + logger('like: unable to write on wall ' . $item['uid']); return false; } - $remote_owner = null; + // Retrieves the local post owner + $owners = q("SELECT `contact`.* FROM `contact` + WHERE `contact`.`self` = 1 + AND `contact`.`uid` = %d", + intval($item['uid']) + ); + if (dbm::is_result($owners)) { + $owner_self_contact = $owners[0]; + } else { + logger('like: unknown owner ' . $item['uid']); + return false; + } - if(! $item['wall']) { - // The top level post may have been written by somebody on another system - $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($item['contact-id']), - intval($item['uid']) + // Retrieve the current logged in user's public contact + $author_id = public_contact(); + + $contacts = q("SELECT * FROM `contact` WHERE `id` = %d", + intval($author_id) + ); + if (dbm::is_result($contacts)) { + $author_contact = $contacts[0]; + } else { + logger('like: unknown author ' . $author_id); + return false; + } + + // Contact-id is the uid-dependant author contact + if (local_user() == $item['uid']) { + $item_contact_id = $owner_self_contact['id']; + $item_contact = $owner_self_contact; + } else { + $item_contact_id = get_contact($author_contact['url'], $item['uid']); + + $contacts = q("SELECT * FROM `contact` WHERE `id` = %d", + intval($item_contact_id) ); - if (! dbm::is_result($r)) { + if (dbm::is_result($contacts)) { + $item_contact = $contacts[0]; + } else { + logger('like: unknown item contact ' . $item_contact_id); return false; } - if (! $r[0]['self']) { - $remote_owner = $r[0]; - } } - // this represents the post owner on this system. - - $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` - WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1", - intval($owner_uid) - ); - if (dbm::is_result($r)) { - $owner = $r[0]; - } - - if (! $owner) { - logger('like: no owner'); - return false; - } - - if (! $remote_owner) { - $remote_owner = $owner; - } - - // This represents the person posting - - if ((local_user()) && (local_user() == $owner_uid)) { - $contact = $owner; - } else { - $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($_SESSION['visitor_id']), - intval($owner_uid) - ); - if (dbm::is_result($r)) { - $contact = $r[0]; - } - } - if (! $contact) { - return false; - } - - - $verbs = " '".dbesc($activity)."' "; - + // Look for an existing verb row // event participation are essentially radio toggles. If you make a subsequent choice, // we need to eradicate your first choice. - if ($activity === ACTIVITY_ATTEND || $activity === ACTIVITY_ATTENDNO || $activity === ACTIVITY_ATTENDMAYBE) { - $verbs = " '" . dbesc(ACTIVITY_ATTEND) . "','" . dbesc(ACTIVITY_ATTENDNO) . "','" . dbesc(ACTIVITY_ATTENDMAYBE) . "' "; + if ($event_verb_flag) { + $verbs = "'" . dbesc(ACTIVITY_ATTEND) . "', '" . dbesc(ACTIVITY_ATTENDNO) . "', '" . dbesc(ACTIVITY_ATTENDMAYBE) . "'"; + } else { + $verbs = "'".dbesc($activity)."'"; } - $r = q("SELECT `id`, `guid` FROM `item` WHERE `verb` IN ( $verbs ) AND `deleted` = 0 - AND `contact-id` = %d AND `uid` = %d - AND (`parent` = '%s' OR `parent-uri` = '%s' OR `thr-parent` = '%s') LIMIT 1", - intval($contact['id']), intval($owner_uid), + $existing_like = q("SELECT `id`, `guid`, `verb` FROM `item` + WHERE `verb` IN ($verbs) + AND `deleted` = 0 + AND `author-id` = %d + AND `uid` = %d + AND (`parent` = '%s' OR `parent-uri` = '%s' OR `thr-parent` = '%s') + LIMIT 1", + intval($author_contact['id']), + intval($item['uid']), dbesc($item_id), dbesc($item_id), dbesc($item['uri']) ); - if (dbm::is_result($r)) { - $like_item = $r[0]; + // If it exists, mark it as deleted + if (dbm::is_result($existing_like)) { + $like_item = $existing_like[0]; // Already voted, undo it - $r = q("UPDATE `item` SET `deleted` = 1, `unseen` = 1, `changed` = '%s' WHERE `id` = %d", + q("UPDATE `item` SET `deleted` = 1, `unseen` = 1, `changed` = '%s' WHERE `id` = %d", dbesc(datetime_convert()), intval($like_item['id']) ); - // Clean up the Diaspora signatures for this like // Go ahead and do it even if Diaspora support is disabled. We still want to clean up // if it had been enabled in the past - $r = q("DELETE FROM `sign` WHERE `iid` = %d", + q("DELETE FROM `sign` WHERE `iid` = %d", intval($like_item['id']) ); $like_item_id = $like_item['id']; proc_run(PRIORITY_HIGH, "include/notifier.php", "like", $like_item_id); + if (!$event_verb_flag || $like_item['verb'] == $activity) { + return true; + } + } + + // Verb is "un-something", just trying to delete existing entries + if (strpos($verb, 'un') === 0) { return true; } - $uri = item_new_uri($a->get_hostname(),$owner_uid); - + // Else or if event verb different from existing row, create a new item row $post_type = (($item['resource-id']) ? t('photo') : t('status')); if ($item['object-type'] === ACTIVITY_OBJ_EVENT) { $post_type = t('event'); } - $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ); - $link = xmlify('' . "\n") ; + $objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ; + $link = xmlify('' . "\n") ; $body = $item['body']; $obj = <<< EOT @@ -180,80 +194,62 @@ function do_like($item_id, $verb) { $body EOT; - if ($verb === 'like') { - $bodyverb = t('%1$s likes %2$s\'s %3$s'); - } - if ($verb === 'dislike') { - $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s'); - } - if ($verb === 'attendyes') { - $bodyverb = t('%1$s is attending %2$s\'s %3$s'); - } - if ($verb === 'attendno') { - $bodyverb = t('%1$s is not attending %2$s\'s %3$s'); - } - if ($verb === 'attendmaybe') { - $bodyverb = t('%1$s may attend %2$s\'s %3$s'); - } - if (! isset($bodyverb)) { - return false; - } - - $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]'; + $ulink = '[url=' . $author_contact['url'] . ']' . $author_contact['name'] . '[/url]'; $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]'; - $plink = '[url=' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]'; + $plink = '[url=' . App::get_baseurl() . '/display/' . $owner_self_contact['nick'] . '/' . $item['id'] . ']' . $post_type . '[/url]'; - /// @TODO Or rewrite this to multi-line initialization of the array? - $arr = array(); + $new_item = array( + 'guid' => get_guid(32), + 'uri' => item_new_uri($a->get_hostname(), $item['uid']), + 'uid' => $item['uid'], + 'contact-id' => $item_contact_id, + 'type' => 'activity', + 'wall' => $item['wall'], + 'origin' => 1, + 'gravity' => GRAVITY_LIKE, + 'parent' => $item['id'], + 'parent-uri' => $item['uri'], + 'thr-parent' => $item['uri'], + 'owner-id' => $item['owner-id'], + 'owner-name' => $item['owner-name'], + 'owner-link' => $item['owner-link'], + 'owner-avatar' => $item['owner-avatar'], + 'author-id' => $author_contact['id'], + 'author-name' => $author_contact['name'], + 'author-link' => $author_contact['url'], + 'author-avatar' => $author_contact['thumb'], + 'body' => sprintf($bodyverb, $ulink, $alink, $plink), + 'verb' => $activity, + 'object-type' => $objtype, + 'object' => $obj, + 'allow_cid' => $item['allow_cid'], + 'allow_gid' => $item['allow_gid'], + 'deny_cid' => $item['deny_cid'], + 'deny_gid' => $item['deny_gid'], + 'visible' => 1, + 'unseen' => 1, + 'last-child' => 0 + ); - $arr['guid'] = get_guid(32); - $arr['uri'] = $uri; - $arr['uid'] = $owner_uid; - $arr['contact-id'] = $contact['id']; - $arr['type'] = 'activity'; - $arr['wall'] = $item['wall']; - $arr['origin'] = 1; - $arr['gravity'] = GRAVITY_LIKE; - $arr['parent'] = $item['id']; - $arr['parent-uri'] = $item['uri']; - $arr['thr-parent'] = $item['uri']; - $arr['owner-name'] = $remote_owner['name']; - $arr['owner-link'] = $remote_owner['url']; - $arr['owner-avatar'] = $remote_owner['thumb']; - $arr['author-name'] = $contact['name']; - $arr['author-link'] = $contact['url']; - $arr['author-avatar'] = $contact['thumb']; - $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink ); - $arr['verb'] = $activity; - $arr['object-type'] = $objtype; - $arr['object'] = $obj; - $arr['allow_cid'] = $item['allow_cid']; - $arr['allow_gid'] = $item['allow_gid']; - $arr['deny_cid'] = $item['deny_cid']; - $arr['deny_gid'] = $item['deny_gid']; - $arr['visible'] = 1; - $arr['unseen'] = 1; - $arr['last-child'] = 0; - - $post_id = item_store($arr); + $new_item_id = item_store($new_item); + // @todo: Explain this block if (! $item['visible']) { - $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d", + q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d", intval($item['id']), - intval($owner_uid) + intval($item['uid']) ); } - // Save the author information for the like in case we need to relay to Diaspora - Diaspora::store_like_signature($contact, $post_id); + Diaspora::store_like_signature($item_contact, $new_item_id); - $arr['id'] = $post_id; + $new_item['id'] = $new_item_id; - call_hooks('post_local_end', $arr); + call_hooks('post_local_end', $new_item); - proc_run(PRIORITY_HIGH, "include/notifier.php", "like", $post_id); + proc_run(PRIORITY_HIGH, "include/notifier.php", "like", $new_item_id); return true; } diff --git a/include/network.php b/include/network.php index b0e71fab7..f9d35c52c 100644 --- a/include/network.php +++ b/include/network.php @@ -72,8 +72,9 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { $a = get_app(); $ch = @curl_init($url); - if(($redirects > 8) || (! $ch)) - return false; + if(($redirects > 8) || (! $ch)) { + return $ret; + } @curl_setopt($ch, CURLOPT_HEADER, true); diff --git a/include/notifier.php b/include/notifier.php index 24830a11a..e3d7d10d6 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -2,12 +2,11 @@ use \Friendica\Core\Config; -require_once("boot.php"); require_once('include/queue_fn.php'); require_once('include/html2plain.php'); -require_once("include/Scrape.php"); +require_once('include/Scrape.php'); require_once('include/diaspora.php'); -require_once("include/ostatus.php"); +require_once('include/ostatus.php'); require_once('include/salmon.php'); /* @@ -44,35 +43,17 @@ require_once('include/salmon.php'); function notifier_run(&$argv, &$argc){ - global $a, $db; + global $a; - if (is_null($a)) { - $a = new App; - } - - if (is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - } - - require_once("include/session.php"); - require_once("include/datetime.php"); + require_once('include/datetime.php'); require_once('include/items.php'); require_once('include/bbcode.php'); require_once('include/email.php'); - Config::load(); - - load_hooks(); - if ($argc < 3) { return; } - $a->set_baseurl(get_config('system','url')); - logger('notifier: invoked: ' . print_r($argv,true), LOGGER_DEBUG); $cmd = $argv[1]; @@ -490,79 +471,22 @@ function notifier_run(&$argv, &$argc){ if ($relocate) { $r = $recipients_relocate; } else { - $r = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND NOT `blocked` AND NOT `pending` AND NOT `archive`".$sql_extra, + $r = q("SELECT `id`, `url`, `network`, `self` FROM `contact` + WHERE `id` IN (%s) AND NOT `blocked` AND NOT `pending` AND NOT `archive`".$sql_extra, dbesc($recip_str) ); } - $interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval'))); - - // If we are using the worker we don't need a delivery interval - if (get_config("system", "worker")) { - $interval = false; - } // delivery loop if (dbm::is_result($r)) { foreach ($r as $contact) { - if (!$contact['self']) { - if (($contact['network'] === NETWORK_DIASPORA) && ($public_message)) { - continue; - } - q("INSERT INTO `deliverq` (`cmd`,`item`,`contact`) VALUES ('%s', %d, %d)", - dbesc($cmd), - intval($item_id), - intval($contact['id']) - ); - } - } - - - // This controls the number of deliveries to execute with each separate delivery process. - // By default we'll perform one delivery per process. Assuming a hostile shared hosting - // provider, this provides the greatest chance of deliveries if processes start getting - // killed. We can also space them out with the delivery_interval to also help avoid them - // getting whacked. - - // If $deliveries_per_process > 1, we will chain this number of multiple deliveries - // together into a single process. This will reduce the overall number of processes - // spawned for each delivery, but they will run longer. - - // When using the workerqueue, we don't need this functionality. - - $deliveries_per_process = intval(get_config('system','delivery_batch_count')); - if (($deliveries_per_process <= 0) OR get_config("system", "worker")) { - $deliveries_per_process = 1; - } - - $this_batch = array(); - - for ($x = 0; $x < count($r); $x ++) { - $contact = $r[$x]; - if ($contact['self']) { continue; } logger("Deliver ".$target_item["guid"]." to ".$contact['url']." via network ".$contact['network'], LOGGER_DEBUG); - // potentially more than one recipient. Start a new process and space them out a bit. - // we will deliver single recipient types of message and email recipients here. - - $this_batch[] = $contact['id']; - - if (count($this_batch) >= $deliveries_per_process) { - proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$this_batch); - $this_batch = array(); - if ($interval) { - @time_sleep_until(microtime(true) + (float) $interval); - } - } - continue; - } - - // be sure to pick up any stragglers - if (count($this_batch)) { - proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$this_batch); + proc_run(PRIORITY_HIGH,'include/delivery.php', $cmd, $item_id, $contact['id']); } } @@ -614,18 +538,6 @@ function notifier_run(&$argv, &$argc){ if (dbm::is_result($r)) { logger('pubdeliver '.$target_item["guid"].': '.print_r($r,true), LOGGER_DEBUG); - // throw everything into the queue in case we get killed - - foreach ($r as $rr) { - if ((! $mail) && (! $fsuggest) && (! $followup)) { - q("INSERT INTO `deliverq` (`cmd`,`item`,`contact`) VALUES ('%s', %d, %d) - ON DUPLICATE KEY UPDATE `cmd` = '%s', `item` = %d, `contact` = %d", - dbesc($cmd), intval($item_id), intval($rr['id']), - dbesc($cmd), intval($item_id), intval($rr['id']) - ); - } - } - foreach ($r as $rr) { // except for Diaspora batch jobs @@ -639,9 +551,6 @@ function notifier_run(&$argv, &$argc){ if ((! $mail) && (! $fsuggest) && (! $followup)) { logger('notifier: delivery agent: '.$rr['name'].' '.$rr['id'].' '.$rr['network'].' '.$target_item["guid"]); proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$rr['id']); - if ($interval) { - @time_sleep_until(microtime(true) + (float) $interval); - } } } } @@ -694,9 +603,3 @@ function notifier_run(&$argv, &$argc){ return; } - - -if (array_search(__file__,get_included_files())===0){ - notifier_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} diff --git a/include/onepoll.php b/include/onepoll.php index bfb904fb6..5227b61a1 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -2,8 +2,7 @@ use \Friendica\Core\Config; -require_once("boot.php"); -require_once("include/follow.php"); +require_once('include/follow.php'); function RemoveReply($subject) { while (in_array(strtolower(substr($subject, 0, 3)), array("re:", "aw:"))) @@ -13,20 +12,8 @@ function RemoveReply($subject) { } function onepoll_run(&$argv, &$argc){ - global $a, $db; + global $a; - if (is_null($a)) { - $a = new App; - } - - if (is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - }; - - require_once('include/session.php'); require_once('include/datetime.php'); require_once('include/items.php'); require_once('include/Contact.php'); @@ -34,12 +21,6 @@ function onepoll_run(&$argv, &$argc){ require_once('include/socgraph.php'); require_once('include/queue_fn.php'); - Config::load(); - - $a->set_baseurl(get_config('system','url')); - - load_hooks(); - logger('onepoll: start'); $manual_id = 0; @@ -61,13 +42,6 @@ function onepoll_run(&$argv, &$argc){ return; } - // Don't check this stuff if the function is called by the poller - if (App::callstack() != "poller_run") { - if (App::is_already_running('onepoll'.$contact_id, '', 540)) { - return; - } - } - $d = datetime_convert(); // Only poll from those with suitable relationships, @@ -697,8 +671,3 @@ function onepoll_run(&$argv, &$argc){ return; } - -if (array_search(__file__,get_included_files())===0) { - onepoll_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} diff --git a/include/poller.php b/include/poller.php index 6eb4aef06..487c86ab3 100644 --- a/include/poller.php +++ b/include/poller.php @@ -35,6 +35,10 @@ function poller_run($argv, $argc){ return; } + $a->set_baseurl(Config::get('system', 'url')); + + load_hooks(); + $a->start_process(); if (poller_max_connections_reached()) { @@ -465,7 +469,7 @@ function poller_too_much_workers() { // Are there fewer workers running as possible? Then fork a new one. if (!Config::get("system", "worker_dont_fork") AND ($queues > ($active + 1)) AND ($entries > 1)) { logger("Active workers: ".$active."/".$queues." Fork a new worker.", LOGGER_DEBUG); - $args = array("php", "include/poller.php", "no_cron"); + $args = array("include/poller.php", "no_cron"); $a = get_app(); $a->proc_run($args); } @@ -576,7 +580,7 @@ function poller_worker_process() { * @brief Call the front end worker */ function call_worker() { - if (!Config::get("system", "frontend_worker") OR !Config::get("system", "worker")) { + if (!Config::get("system", "frontend_worker")) { return; } @@ -588,7 +592,7 @@ function call_worker() { * @brief Call the front end worker if there aren't any active */ function call_worker_if_idle() { - if (!Config::get("system", "frontend_worker") OR !Config::get("system", "worker")) { + if (!Config::get("system", "frontend_worker")) { return; } @@ -615,7 +619,7 @@ function call_worker_if_idle() { logger('Call poller', LOGGER_DEBUG); - $args = array("php", "include/poller.php", "no_cron"); + $args = array("include/poller.php", "no_cron"); $a = get_app(); $a->proc_run($args); return; diff --git a/include/pubsubpublish.php b/include/pubsubpublish.php index 428103a97..3641bbcf7 100644 --- a/include/pubsubpublish.php +++ b/include/pubsubpublish.php @@ -1,12 +1,31 @@ 1) { + $pubsubpublish_id = intval($argv[1]); + } else { + // We'll push to each subscriber that has push > 0, + // i.e. there has been an update (set in notifier.php). + $r = q("SELECT `id`, `callback_url` FROM `push_subscriber` WHERE `push` > 0"); + + foreach ($r as $rr) { + logger("Publish feed to ".$rr["callback_url"], LOGGER_DEBUG); + proc_run(PRIORITY_HIGH, 'include/pubsubpublish.php', $rr["id"]); + } + } + + handle_pubsubhubbub($pubsubpublish_id); + + return; +} function handle_pubsubhubbub($id) { - global $a, $db; + global $a; $r = q("SELECT * FROM `push_subscriber` WHERE `id` = %d", intval($id)); if (!$r) @@ -54,70 +73,3 @@ function handle_pubsubhubbub($id) { intval($rr['id'])); } } - - -function pubsubpublish_run(&$argv, &$argc){ - global $a, $db; - - if(is_null($a)){ - $a = new App; - } - - if(is_null($db)){ - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - }; - - require_once('include/items.php'); - - Config::load(); - - // Don't check this stuff if the function is called by the poller - if (App::callstack() != "poller_run") { - if (App::is_already_running("pubsubpublish", "include/pubsubpublish.php", 540)) { - return; - } - } - - $a->set_baseurl(get_config('system','url')); - - load_hooks(); - - if ($argc > 1) { - $pubsubpublish_id = intval($argv[1]); - } - else { - // We'll push to each subscriber that has push > 0, - // i.e. there has been an update (set in notifier.php). - $r = q("SELECT `id`, `callback_url` FROM `push_subscriber` WHERE `push` > 0"); - - // Use the delivery interval that is also used for the notifier - $interval = Config::get("system", "delivery_interval", 2); - - // If we are using the worker we don't need a delivery interval - if (get_config("system", "worker")) { - $interval = false; - } - - foreach ($r as $rr) { - logger("Publish feed to ".$rr["callback_url"], LOGGER_DEBUG); - proc_run(PRIORITY_HIGH, 'include/pubsubpublish.php', $rr["id"]); - - if($interval) - @time_sleep_until(microtime(true) + (float) $interval); - } - } - - handle_pubsubhubbub($pubsubpublish_id); - - return; - -} - -if (array_search(__file__,get_included_files())===0){ - pubsubpublish_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} - diff --git a/include/queue.php b/include/queue.php index 7e2657fa5..c0c73cda6 100644 --- a/include/queue.php +++ b/include/queue.php @@ -2,41 +2,16 @@ use \Friendica\Core\Config; -require_once("boot.php"); require_once('include/queue_fn.php'); require_once('include/dfrn.php'); +require_once("include/datetime.php"); +require_once('include/items.php'); +require_once('include/bbcode.php'); +require_once('include/socgraph.php'); require_once('include/cache.php'); function queue_run(&$argv, &$argc){ - global $a, $db; - - if (is_null($a)){ - $a = new App; - } - - if (is_null($db)){ - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - }; - - require_once("include/session.php"); - require_once("include/datetime.php"); - require_once('include/items.php'); - require_once('include/bbcode.php'); - require_once('include/socgraph.php'); - - Config::load(); - - // Don't check this stuff if the function is called by the poller - if (App::callstack() != "poller_run") - if (App::is_already_running('queue', 'include/queue.php', 540)) - return; - - $a->set_baseurl(get_config('system','url')); - - load_hooks(); + global $a; if ($argc > 1) { $queue_id = intval($argv[1]); @@ -54,30 +29,13 @@ function queue_run(&$argv, &$argc){ // Handling the pubsubhubbub requests proc_run(PRIORITY_HIGH,'include/pubsubpublish.php'); - $interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval'))); - - // If we are using the worker we don't need a delivery interval - if (get_config("system", "worker")) - $interval = false; - - $r = q("select * from deliverq where 1"); - if ($r) { - foreach ($r as $rr) { - logger('queue: deliverq'); - proc_run(PRIORITY_HIGH,'include/delivery.php',$rr['cmd'],$rr['item'],$rr['contact']); - if ($interval) { - time_sleep_until(microtime(true) + (float) $interval); - } - } - } - $r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue` INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id` WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY"); if ($r) { foreach ($r as $rr) { logger('Removing expired queue item for ' . $rr['name'] . ', uid=' . $rr['uid']); - logger('Expired queue data :' . $rr['content'], LOGGER_DATA); + logger('Expired queue data: ' . $rr['content'], LOGGER_DATA); } q("DELETE FROM `queue` WHERE `created` < UTC_TIMESTAMP() - INTERVAL 3 DAY"); } @@ -86,158 +44,137 @@ function queue_run(&$argv, &$argc){ // After that, we'll only attempt delivery once per hour. $r = q("SELECT `id` FROM `queue` WHERE ((`created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR && `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE) OR (`last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR)) ORDER BY `cid`, `created`"); - } else { - logger('queue: start for id '.$queue_id); - $r = q("SELECT `id` FROM `queue` WHERE `id` = %d LIMIT 1", - intval($queue_id) - ); - } + call_hooks('queue_predeliver', $a, $r); - if (!$r){ + if (dbm::is_result($r)) { + foreach ($r as $q_item) { + logger('Call queue for id '.$q_item['id']); + proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']); + } + } return; } - if (!$queue_id) - call_hooks('queue_predeliver', $a, $r); - - // delivery loop + // delivering require_once('include/salmon.php'); require_once('include/diaspora.php'); - foreach($r as $q_item) { + $r = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1", + intval($queue_id)); - // queue_predeliver hooks may have changed the queue db details, - // so check again if this entry still needs processing + if (!dbm::is_result($r)) { + return; + } - if ($queue_id) { - $qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1", - intval($queue_id)); - } elseif (get_config("system", "worker")) { - logger('Call queue for id '.$q_item['id']); - proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']); - continue; - } else - $qi = q("SELECT * FROM `queue` WHERE `id` = %d AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ", - intval($q_item['id'])); + $q_item = $r[0]; - if (!dbm::is_result($qi)) { - continue; + $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", + intval($q_item['cid']) + ); + + if (!dbm::is_result($c)) { + remove_queue_item($q_item['id']); + return; + } + + $dead = Cache::get($cachekey_deadguy.$c[0]['notify']); + + if (!is_null($dead) AND $dead) { + logger('queue: skipping known dead url: '.$c[0]['notify']); + update_queue_time($q_item['id']); + return; + } + + $server = poco_detect_server($c[0]['url']); + + if ($server != "") { + $vital = Cache::get($cachekey_server.$server); + + if (is_null($vital)) { + logger("Check server ".$server." (".$c[0]["network"].")"); + + $vital = poco_check_server($server, $c[0]["network"], true); + Cache::set($cachekey_server.$server, $vital, CACHE_QUARTER_HOUR); } - - $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", - intval($qi[0]['cid']) - ); - if (! dbm::is_result($c)) { - remove_queue_item($q_item['id']); - continue; - } - - $dead = Cache::get($cachekey_deadguy.$c[0]['notify']); - - if (!is_null($dead) AND $dead) { - logger('queue: skipping known dead url: '.$c[0]['notify']); + if (!is_null($vital) AND !$vital) { + logger('queue: skipping dead server: '.$server); update_queue_time($q_item['id']); - continue; + return; } + } - $server = poco_detect_server($c[0]['url']); + $u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey` + FROM `user` WHERE `uid` = %d LIMIT 1", + intval($c[0]['uid']) + ); + if (!dbm::is_result($u)) { + remove_queue_item($q_item['id']); + return; + } - if ($server != "") { - $vital = Cache::get($cachekey_server.$server); + $data = $q_item['content']; + $public = $q_item['batch']; + $contact = $c[0]; + $owner = $u[0]; - if (is_null($vital)) { - logger("Check server ".$server." (".$c[0]["network"].")"); + $deliver_status = 0; - $vital = poco_check_server($server, $c[0]["network"], true); - Cache::set($cachekey_server.$server, $vital, CACHE_QUARTER_HOUR); - } + switch ($contact['network']) { + case NETWORK_DFRN: + logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>'); + $deliver_status = dfrn::deliver($owner, $contact, $data); - if (!is_null($vital) AND !$vital) { - logger('queue: skipping dead server: '.$server); + if ($deliver_status == (-1)) { update_queue_time($q_item['id']); - continue; + Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR); + } else { + remove_queue_item($q_item['id']); } - } + break; + case NETWORK_OSTATUS: + if ($contact['notify']) { + logger('queue: slapdelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>'); + $deliver_status = slapper($owner, $contact['notify'], $data); - $u = q("SELECT `user`.*, `user`.`pubkey` AS `upubkey`, `user`.`prvkey` AS `uprvkey` - FROM `user` WHERE `uid` = %d LIMIT 1", - intval($c[0]['uid']) - ); - if (! dbm::is_result($u)) { - remove_queue_item($q_item['id']); - continue; - } - - $data = $qi[0]['content']; - $public = $qi[0]['batch']; - $contact = $c[0]; - $owner = $u[0]; - - $deliver_status = 0; - - switch($contact['network']) { - case NETWORK_DFRN: - logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>'); - $deliver_status = dfrn::deliver($owner,$contact,$data); - - if ($deliver_status < 0) { + if ($deliver_status == (-1)) { update_queue_time($q_item['id']); Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR); } else { remove_queue_item($q_item['id']); } - break; - case NETWORK_OSTATUS: - if ($contact['notify']) { - logger('queue: slapdelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>'); - $deliver_status = slapper($owner,$contact['notify'],$data); + } + break; + case NETWORK_DIASPORA: + if ($contact['notify']) { + logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>'); + $deliver_status = Diaspora::transmit($owner, $contact, $data, $public, true); - if ($deliver_status == (-1)) { - update_queue_time($q_item['id']); - Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR); - } else { - remove_queue_item($q_item['id']); - } - } - break; - case NETWORK_DIASPORA: - if ($contact['notify']) { - logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>'); - $deliver_status = Diaspora::transmit($owner,$contact,$data,$public,true); - - if ($deliver_status == (-1)) { - update_queue_time($q_item['id']); - Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR); - } else { - remove_queue_item($q_item['id']); - } - } - break; - - default: - $params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false); - call_hooks('queue_deliver', $a, $params); - - if ($params['result']) { - remove_queue_item($q_item['id']); - } else { + if ($deliver_status == (-1)) { update_queue_time($q_item['id']); + Cache::set($cachekey_deadguy.$contact['notify'], true, CACHE_QUARTER_HOUR); + } else { + remove_queue_item($q_item['id']); } - break; + } + break; + + default: + $params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false); + call_hooks('queue_deliver', $a, $params); + + if ($params['result']) { + remove_queue_item($q_item['id']); + } else { + update_queue_time($q_item['id']); + } + break; - } - logger('Deliver status '.(int)$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>'); } + logger('Deliver status '.(int)$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>'); return; - -} - -if (array_search(__file__,get_included_files())===0){ - queue_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); } diff --git a/include/remove_contact.php b/include/remove_contact.php index aa2062111..68bf2adfe 100644 --- a/include/remove_contact.php +++ b/include/remove_contact.php @@ -6,24 +6,7 @@ use \Friendica\Core\Config; -require_once("boot.php"); - function remove_contact_run($argv, $argc) { - global $a, $db; - - if (is_null($a)) { - $a = new App; - } - - if (is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - } - - Config::load(); - if ($argc != 2) { return; } @@ -46,9 +29,4 @@ function remove_contact_run($argv, $argc) { q("DELETE FROM `queue` WHERE `cid` = %d", intval($id)); } - -if (array_search(__file__, get_included_files()) === 0) { - remove_contact_run($_SERVER["argv"], $_SERVER["argc"]); - killme(); -} ?> diff --git a/include/security.php b/include/security.php index 11a2955b4..a9d2f83de 100644 --- a/include/security.php +++ b/include/security.php @@ -1,5 +1,44 @@ $user["uid"], + "hash" => cookie_hash($user), + "ip" => $_SERVER['REMOTE_ADDR'])); + } + else { + $value = ""; + } + + setcookie("Friendica", $value, $time, "/", "", + (get_config('system', 'ssl_policy') == SSL_POLICY_FULL), true); + +} + function authenticate_success($user_record, $login_initial = false, $interactive = false, $login_refresh = false) { $a = get_app(); @@ -94,6 +133,21 @@ function authenticate_success($user_record, $login_initial = false, $interactive } + + if ($login_initial) { + // If the user specified to remember the authentication, then set a cookie + // that expires after one week (the default is when the browser is closed). + // The cookie will be renewed automatically. + // The week ensures that sessions will expire after some inactivity. + if ($_SESSION['remember']) { + logger('Injecting cookie for remembered user '. $_SESSION['remember_user']['nickname']); + new_cookie(604800, $user_record); + unset($_SESSION['remember']); + } + } + + + if ($login_initial) { call_hooks('logged_in', $a->user); diff --git a/include/shadowupdate.php b/include/shadowupdate.php index 83a785fe1..5b0a1b94b 100644 --- a/include/shadowupdate.php +++ b/include/shadowupdate.php @@ -5,20 +5,26 @@ use \Friendica\Core\Config; require_once("boot.php"); require_once("include/threads.php"); -global $a, $db; +function shadowupdate_run(&$argv, &$argc){ + global $a, $db; -if(is_null($a)) - $a = new App; + if (is_null($a)) { + $a = new App; + } -if(is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); + if (is_null($db)) { + @include(".htconfig.php"); + require_once("include/dba.php"); + $db = new dba($db_host, $db_user, $db_pass, $db_data); + unset($db_host, $db_user, $db_pass, $db_data); + } + + Config::load(); + + update_shadow_copy(); } -Config::load(); - -update_shadow_copy(); -killme(); -?> +if (array_search(__file__,get_included_files())===0){ + shadowupdate_run($_SERVER["argv"],$_SERVER["argc"]); + killme(); +} diff --git a/include/socgraph.php b/include/socgraph.php index 152f713c1..e0d6b156a 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -309,7 +309,18 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca logger("profile-check generation: ".$generation." Network: ".$network." URL: ".$profile_url." name: ".$name." avatar: ".$profile_photo, LOGGER_DEBUG); - poco_check_server($server_url, $network); + // We check the server url to be sure that it is a real one + $server_url2 = poco_detect_server($profile_url); + + // We are no sure that it is a correct URL. So we use it in the future + if ($server_url2 != "") { + $server_url = $server_url2; + } + + // The server URL doesn't seem to be valid, so we don't store it. + if (!poco_check_server($server_url, $network)) { + $server_url = ""; + } $gcontact = array("url" => $profile_url, "addr" => $addr, @@ -401,13 +412,47 @@ function poco_detect_server($profile) { // Mastodon if ($server_url == "") { - $red = preg_replace("=(https?://)(.*)/users/(.*)=ism", "$1$2", $profile); - if ($red != $profile) { - $server_url = $red; + $mastodon = preg_replace("=(https?://)(.*)/users/(.*)=ism", "$1$2", $profile); + if ($mastodon != $profile) { + $server_url = $mastodon; $network = NETWORK_OSTATUS; } } + // Numeric OStatus variant + if ($server_url == "") { + $ostatus = preg_replace("=(https?://)(.*)/user/(.*)=ism", "$1$2", $profile); + if ($ostatus != $profile) { + $server_url = $ostatus; + $network = NETWORK_OSTATUS; + } + } + + // Wild guess + if ($server_url == "") { + $base = preg_replace("=(https?://)(.*?)/(.*)=ism", "$1$2", $profile); + if ($base != $profile) { + $server_url = $base; + $network = NETWORK_PHANTOM; + } + } + + if ($server_url == "") { + return ""; + } + + $r = q("SELECT `id` FROM `gserver` WHERE `nurl` = '%s' AND `last_contact` > `last_failure`", + dbesc(normalise_link($server_url))); + if (dbm::is_result($r)) { + return $server_url; + } + + // Fetch the host-meta to check if this really is a server + $serverret = z_fetch_url($server_url."/.well-known/host-meta"); + if (!$serverret["success"]) { + return ""; + } + return $server_url; } @@ -424,10 +469,12 @@ function poco_last_updated($profile, $force = false) { q("UPDATE `gcontact` SET `created` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc(normalise_link($profile))); - if ($gcontacts[0]["server_url"] != "") + if ($gcontacts[0]["server_url"] != "") { $server_url = $gcontacts[0]["server_url"]; - else + } + if (($server_url == '') OR ($gcontacts[0]["server_url"] == $gcontacts[0]["nurl"])) { $server_url = poco_detect_server($profile); + } if (!in_array($gcontacts[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_FEED, NETWORK_OSTATUS, ""))) { logger("Profile ".$profile.": Network type ".$gcontacts[0]["network"]." can't be checked", LOGGER_DEBUG); @@ -680,6 +727,213 @@ function poco_to_boolean($val) { return ($val); } +/** + * @brief Detect server type (Hubzilla or Friendica) via the poco data + * + * @param object $data POCO data + * @return array Server data + */ +function poco_detect_poco_data($data) { + $server = false; + + if (!isset($data->entry)) { + return false; + } + + if (count($data->entry) == 0) { + return false; + } + + if (!isset($data->entry[0]->urls)) { + return false; + } + + if (count($data->entry[0]->urls) == 0) { + return false; + } + + foreach ($data->entry[0]->urls AS $url) { + if ($url->type == 'zot') { + $server = array(); + $server["platform"] = 'Hubzilla'; + $server["network"] = NETWORK_DIASPORA; + return $server; + } + } + return false; +} + +/** + * @brief Detect server type by using the nodeinfo data + * + * @param string $server_url address of the server + * @return array Server data + */ +function poco_fetch_nodeinfo($server_url) { + $serverret = z_fetch_url($server_url."/.well-known/nodeinfo"); + if (!$serverret["success"]) { + return false; + } + + $nodeinfo = json_decode($serverret['body']); + + if (!is_object($nodeinfo)) { + return false; + } + + if (!is_array($nodeinfo->links)) { + return false; + } + + $nodeinfo_url = ''; + + foreach ($nodeinfo->links AS $link) { + if ($link->rel == 'http://nodeinfo.diaspora.software/ns/schema/1.0') { + $nodeinfo_url = $link->href; + } + } + + if ($nodeinfo_url == '') { + return false; + } + + $serverret = z_fetch_url($nodeinfo_url); + if (!$serverret["success"]) { + return false; + } + + $nodeinfo = json_decode($serverret['body']); + + if (!is_object($nodeinfo)) { + return false; + } + + $server = array(); + + $server['register_policy'] = REGISTER_CLOSED; + + if (is_bool($nodeinfo->openRegistrations) AND $nodeinfo->openRegistrations) { + $server['register_policy'] = REGISTER_OPEN; + } + + if (is_object($nodeinfo->software)) { + if (isset($nodeinfo->software->name)) { + $server['platform'] = $nodeinfo->software->name; + } + + if (isset($nodeinfo->software->version)) { + $server['version'] = $nodeinfo->software->version; + // Version numbers on Nodeinfo are presented with additional info, e.g.: + // 0.6.3.0-p1702cc1c, 0.6.99.0-p1b9ab160 or 3.4.3-2-1191. + $server['version'] = preg_replace("=(.+)-(.{4,})=ism", "$1", $server['version']); + } + } + + if (is_object($nodeinfo->metadata)) { + if (isset($nodeinfo->metadata->nodeName)) { + $server['site_name'] = $nodeinfo->metadata->nodeName; + } + } + + $diaspora = false; + $friendica = false; + $gnusocial = false; + + if (is_array($nodeinfo->protocols->inbound)) { + foreach ($nodeinfo->protocols->inbound AS $inbound) { + if ($inbound == 'diaspora') { + $diaspora = true; + } + if ($inbound == 'friendica') { + $friendica = true; + } + if ($inbound == 'gnusocial') { + $gnusocial = true; + } + } + } + + if ($gnusocial) { + $server['network'] = NETWORK_OSTATUS; + } + if ($diaspora) { + $server['network'] = NETWORK_DIASPORA; + } + if ($friendica) { + $server['network'] = NETWORK_DFRN; + } + + if (!$server) { + return false; + } + + return $server; +} + +/** + * @brief Detect server type (Hubzilla or Friendica) via the front page body + * + * @param string $body Front page of the server + * @return array Server data + */ +function poco_detect_server_type($body) { + $server = false; + + $doc = new \DOMDocument(); + @$doc->loadHTML($body); + $xpath = new \DomXPath($doc); + + $list = $xpath->query("//meta[@name]"); + + foreach ($list as $node) { + $attr = array(); + if ($node->attributes->length) { + foreach ($node->attributes as $attribute) { + $attr[$attribute->name] = $attribute->value; + } + } + if ($attr['name'] == 'generator') { + $version_part = explode(" ", $attr['content']); + if (count($version_part) == 2) { + if (in_array($version_part[0], array("Friendika", "Friendica"))) { + $server = array(); + $server["platform"] = $version_part[0]; + $server["version"] = $version_part[1]; + $server["network"] = NETWORK_DFRN; + } + } + } + } + + if (!$server) { + $list = $xpath->query("//meta[@property]"); + + foreach ($list as $node) { + $attr = array(); + if ($node->attributes->length) { + foreach ($node->attributes as $attribute) { + $attr[$attribute->name] = $attribute->value; + } + } + if ($attr['property'] == 'generator') { + if (in_array($attr['content'], array("hubzilla", "BlaBlaNet"))) { + $server = array(); + $server["platform"] = $attr['content']; + $server["version"] = ""; + $server["network"] = NETWORK_DIASPORA; + } + } + } + } + + if (!$server) { + return false; + } + + $server["site_name"] = $xpath->evaluate($element."//head/title/text()", $context)->item(0)->nodeValue; + return $server; +} + function poco_check_server($server_url, $network = "", $force = false) { // Unify the server address @@ -729,7 +983,9 @@ function poco_check_server($server_url, $network = "", $force = false) { logger("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$servers[0]["created"]." Failure: ".$last_failure." Contact: ".$last_contact, LOGGER_DEBUG); $failure = false; + $possible_failure = false; $orig_last_failure = $last_failure; + $orig_last_contact = $last_contact; // Check if the page is accessible via SSL. $orig_server_url = $server_url; @@ -769,18 +1025,58 @@ function poco_check_server($server_url, $network = "", $force = false) { $last_failure = datetime_convert(); $failure = true; } + $possible_failure = true; } elseif ($network == NETWORK_DIASPORA) $last_contact = datetime_convert(); + // If the server has no possible failure we reset the cached data + if (!$possible_failure) { + $version = ""; + $platform = ""; + $site_name = ""; + $info = ""; + $register_policy = -1; + } + + // Look for poco if (!$failure) { - // Test for Diaspora + $serverret = z_fetch_url($server_url."/poco"); + if ($serverret["success"]) { + $data = json_decode($serverret["body"]); + if (isset($data->totalResults)) { + $poco = $server_url."/poco"; + $last_contact = datetime_convert(); + + $server = poco_detect_poco_data($data); + if ($server) { + $platform = $server['platform']; + $network = $server['network']; + $version = ''; + $site_name = ''; + } + } + } + } + + if (!$failure) { + // Test for Diaspora, Hubzilla, Mastodon or older Friendica servers $serverret = z_fetch_url($server_url); - if (!$serverret["success"] OR ($serverret["body"] == "")) + if (!$serverret["success"] OR ($serverret["body"] == "")) { + $last_failure = datetime_convert(); $failure = true; - else { + } else { + $server = poco_detect_server_type($serverret["body"]); + if ($server) { + $platform = $server['platform']; + $network = $server['network']; + $version = $server['version']; + $site_name = $server['site_name']; + $last_contact = datetime_convert(); + } + $lines = explode("\n",$serverret["header"]); - if(count($lines)) + if(count($lines)) { foreach($lines as $line) { $line = trim($line); if(stristr($line,'X-Diaspora-Version:')) { @@ -790,6 +1086,7 @@ function poco_check_server($server_url, $network = "", $force = false) { $network = NETWORK_DIASPORA; $versionparts = explode("-", $version); $version = $versionparts[0]; + $last_contact = datetime_convert(); } if(stristr($line,'Server: Mastodon')) { @@ -797,12 +1094,14 @@ function poco_check_server($server_url, $network = "", $force = false) { $network = NETWORK_OSTATUS; // Mastodon doesn't reveal version numbers $version = ""; + $last_contact = datetime_convert(); } } + } } } - if (!$failure) { + if (!$failure AND ($poco == "")) { // Test for Statusnet // Will also return data for Friendica and GNU Social - but it will be overwritten later // The "not implemented" is a special treatment for really, really old Friendica versions @@ -810,8 +1109,11 @@ function poco_check_server($server_url, $network = "", $force = false) { if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND ($serverret["body"] != '') AND (strlen($serverret["body"]) < 30)) { $platform = "StatusNet"; - $version = trim($serverret["body"], '"'); + // Remove junk that some GNU Social servers return + $version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]); + $version = trim($version, '"'); $network = NETWORK_OSTATUS; + $last_contact = datetime_convert(); } // Test for GNU Social @@ -819,17 +1121,32 @@ function poco_check_server($server_url, $network = "", $force = false) { if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND ($serverret["body"] != '') AND (strlen($serverret["body"]) < 30)) { $platform = "GNU Social"; - $version = trim($serverret["body"], '"'); + // Remove junk that some GNU Social servers return + $version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]); + $version = trim($version, '"'); $network = NETWORK_OSTATUS; + $last_contact = datetime_convert(); } + } + if (!$failure) { + // Test for Hubzilla, Redmatrix or Friendica $serverret = z_fetch_url($server_url."/api/statusnet/config.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); - if (isset($data->site->server)) { $last_contact = datetime_convert(); + if (isset($data->site->platform)) { + $platform = $data->site->platform->PLATFORM_NAME; + $version = $data->site->platform->STD_VERSION; + $network = NETWORK_DIASPORA; + } + if (isset($data->site->BlaBlaNet)) { + $platform = $data->site->BlaBlaNet->PLATFORM_NAME; + $version = $data->site->BlaBlaNet->STD_VERSION; + $network = NETWORK_DIASPORA; + } if (isset($data->site->hubzilla)) { $platform = $data->site->hubzilla->PLATFORM_NAME; $version = $data->site->hubzilla->RED_VERSION; @@ -866,32 +1183,66 @@ function poco_check_server($server_url, $network = "", $force = false) { } } + // Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix if (!$failure) { $serverret = z_fetch_url($server_url."/statistics.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); - if ($version == "") + if (isset($data->version)) { $version = $data->version; + // Version numbers on statistics.json are presented with additional info, e.g.: + // 0.6.3.0-p1702cc1c, 0.6.99.0-p1b9ab160 or 3.4.3-2-1191. + $version = preg_replace("=(.+)-(.{4,})=ism", "$1", $version); + } $site_name = $data->name; - if (isset($data->network) AND ($platform == "")) + if (isset($data->network)) { $platform = $data->network; + } - if ($platform == "Diaspora") + if ($platform == "Diaspora") { $network = NETWORK_DIASPORA; + } - if ($data->registrations_open) + if ($data->registrations_open) { $register_policy = REGISTER_OPEN; - else + } else { $register_policy = REGISTER_CLOSED; + } if (isset($data->version)) $last_contact = datetime_convert(); } } + // Query nodeinfo. Working for (at least) Diaspora and Friendica. + if (!$failure) { + $server = poco_fetch_nodeinfo($server_url); + if ($server) { + $register_policy = $server['register_policy']; + + if (isset($server['platform'])) { + $platform = $server['platform']; + } + + if (isset($server['network'])) { + $network = $server['network']; + } + + if (isset($server['version'])) { + $version = $server['version']; + } + + if (isset($server['site_name'])) { + $site_name = $server['site_name']; + } + + $last_contact = datetime_convert(); + } + } + // Check for noscrape // Friendica servers could be detected as OStatus servers if (!$failure AND in_array($network, array(NETWORK_DFRN, NETWORK_OSTATUS))) { @@ -929,16 +1280,21 @@ function poco_check_server($server_url, $network = "", $force = false) { } } - // Look for poco - if (!$failure) { - $serverret = z_fetch_url($server_url."/poco"); - if ($serverret["success"]) { - $data = json_decode($serverret["body"]); - if (isset($data->totalResults)) { - $poco = $server_url."/poco"; - $last_contact = datetime_convert(); - } - } + if ($possible_failure AND !$failure) { + $last_failure = datetime_convert(); + $failure = true; + } + + if ($failure) { + $last_contact = $orig_last_contact; + } else { + $last_failure = $orig_last_failure; + } + + if (($last_contact <= $last_failure) AND !$failure) { + logger("Server ".$server_url." seems to be alive, but last contact wasn't set - could be a bug", LOGGER_DEBUG); + } else if (($last_contact >= $last_failure) AND $failure) { + logger("Server ".$server_url." seems to be dead, but last failure wasn't set - could be a bug", LOGGER_DEBUG); } // Check again if the server exists @@ -949,7 +1305,7 @@ function poco_check_server($server_url, $network = "", $force = false) { $info = strip_tags($info); $platform = strip_tags($platform); - if ($servers) + if ($servers) { q("UPDATE `gserver` SET `url` = '%s', `version` = '%s', `site_name` = '%s', `info` = '%s', `register_policy` = %d, `poco` = '%s', `noscrape` = '%s', `network` = '%s', `platform` = '%s', `last_contact` = '%s', `last_failure` = '%s' WHERE `nurl` = '%s'", dbesc($server_url), @@ -965,7 +1321,7 @@ function poco_check_server($server_url, $network = "", $force = false) { dbesc($last_failure), dbesc(normalise_link($server_url)) ); - else + } elseif (!$failure) { q("INSERT INTO `gserver` (`url`, `nurl`, `version`, `site_name`, `info`, `register_policy`, `poco`, `noscrape`, `network`, `platform`, `created`, `last_contact`, `last_failure`) VALUES ('%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", dbesc($server_url), @@ -983,7 +1339,7 @@ function poco_check_server($server_url, $network = "", $force = false) { dbesc($last_failure), dbesc(datetime_convert()) ); - + } logger("End discovery for server ".$server_url, LOGGER_DEBUG); return !$failure; @@ -1246,6 +1602,33 @@ function update_suggestions() { } } +/** + * @brief Fetch server list from remote servers and adds them when they are new. + * + * @param string $poco URL to the POCO endpoint + */ +function poco_fetch_serverlist($poco) { + $serverret = z_fetch_url($poco."/@server"); + if (!$serverret["success"]) { + return; + } + $serverlist = json_decode($serverret['body']); + + if (!is_array($serverlist)) { + return; + } + + foreach ($serverlist AS $server) { + $server_url = str_replace("/index.php", "", $server->url); + + $r = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", dbesc(normalise_link($server_url))); + if (!dbm::is_result($r)) { + logger("Call server check for server ".$server_url, LOGGER_DEBUG); + proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", base64_encode($server_url)); + } + } +} + function poco_discover_federation() { $last = get_config('poco','last_federation_discovery'); @@ -1261,8 +1644,9 @@ function poco_discover_federation() { if ($serverdata) { $servers = json_decode($serverdata); - foreach($servers->pods AS $server) - poco_check_server("https://".$server->host); + foreach ($servers->pods AS $server) { + proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", base64_encode("https://".$server->host)); + } } // Currently disabled, since the service isn't available anymore. @@ -1307,6 +1691,9 @@ function poco_discover($complete = false) { continue; } + // Discover new servers out there + poco_fetch_serverlist($server["poco"]); + // Fetch all users from the other server $url = $server["poco"]."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; @@ -1881,4 +2268,20 @@ function gs_discover() { q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"])); } } + +/** + * @brief Returns a list of all known servers + * @return array List of server urls + */ +function poco_serverlist() { + $r = q("SELECT `url`, `site_name` AS `displayName`, `network`, `platform`, `version` FROM `gserver` + WHERE `network` IN ('%s', '%s', '%s') AND `last_contact` > `last_failure` + ORDER BY `last_contact` + LIMIT 1000", + dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS)); + if (!dbm::is_result($r)) { + return false; + } + return $r; +} ?> diff --git a/include/spool_post.php b/include/spool_post.php index b4cce46b5..f64b39e4b 100644 --- a/include/spool_post.php +++ b/include/spool_post.php @@ -6,24 +6,10 @@ use \Friendica\Core\Config; -require_once("boot.php"); require_once("include/items.php"); function spool_post_run($argv, $argc) { - global $a, $db; - - if (is_null($a)) { - $a = new App; - } - - if (is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - } - - Config::load(); + global $a; $path = get_spoolpath(); @@ -69,9 +55,4 @@ function spool_post_run($argv, $argc) { } } } - -if (array_search(__file__, get_included_files()) === 0) { - spool_post_run($_SERVER["argv"], $_SERVER["argc"]); - killme(); -} ?> diff --git a/include/tagupdate.php b/include/tagupdate.php index b4de121e9..1e97135c5 100644 --- a/include/tagupdate.php +++ b/include/tagupdate.php @@ -1,24 +1,6 @@ diff --git a/include/text.php b/include/text.php index 11248902b..6619dec93 100644 --- a/include/text.php +++ b/include/text.php @@ -268,90 +268,90 @@ function hex2bin($s) { }} -if(! function_exists('paginate_data')) { /** - * Automatica pagination data. + * @brief Paginator function. Pushes relevant links in a pager array structure. + * + * Links are generated depending on the current page and the total number of items. + * Inactive links (like "first" and "prev" on page 1) are given the "disabled" class. + * Current page link is given the "active" CSS class * * @param App $a App instance - * @param int $count [optional] item count (used with alt pager) + * @param int $count [optional] item count (used with minimal pager) * @return Array data for pagination template */ -function paginate_data(App $a, $count=null) { - $stripped = preg_replace('/([&?]page=[0-9]*)/','',$a->query_string); +function paginate_data(App $a, $count = null) { + $stripped = preg_replace('/([&?]page=[0-9]*)/', '', $a->query_string); - $stripped = str_replace('q=','',$stripped); - $stripped = trim($stripped,'/'); + $stripped = str_replace('q=', '', $stripped); + $stripped = trim($stripped, '/'); $pagenum = $a->pager['page']; - if (($a->page_offset != "") AND !preg_match('/[?&].offset=/', $stripped)) - $stripped .= "&offset=".urlencode($a->page_offset); - - $url = $stripped; - - $data = array(); - function _l(&$d, $name, $url, $text, $class="") { - if (!strpos($url, "?")) { - if ($pos = strpos($url, "&")) - $url = substr($url, 0, $pos)."?".substr($url, $pos + 1); - } - - $d[$name] = array('url'=>$url, 'text'=>$text, 'class'=>$class); + if (($a->page_offset != '') AND !preg_match('/[?&].offset=/', $stripped)) { + $stripped .= '&offset=' . urlencode($a->page_offset); } - if (!is_null($count)){ - // alt pager - if($a->pager['page']>1) - _l($data, "prev", $url.'&page='.($a->pager['page'] - 1), t('newer')); - if($count>0) - _l($data, "next", $url.'&page='.($a->pager['page'] + 1), t('older')); + $url = $stripped; + $data = array(); + + function _l(&$d, $name, $url, $text, $class = '') { + if (strpos($url, '?') === false && ($pos = strpos($url, '&')) !== false) { + $url = substr($url, 0, $pos) . '?' . substr($url, $pos + 1); + } + + $d[$name] = array('url' => $url, 'text' => $text, 'class' => $class); + } + + if (!is_null($count)) { + // minimal pager (newer / older) + $data['class'] = 'pager'; + _l($data, 'prev', $url . '&page=' . ($a->pager['page'] - 1), t('newer'), 'previous' . ($a->pager['page'] == 1 ? ' disabled' : '')); + _l($data, 'next', $url . '&page=' . ($a->pager['page'] + 1), t('older'), 'next' . ($count <= 0 ? ' disabled' : '')); } else { - // full pager - if($a->pager['total'] > $a->pager['itemspage']) { - if($a->pager['page'] != 1) - _l($data, "prev", $url.'&page='.($a->pager['page'] - 1), t('prev')); - - _l($data, "first", $url."&page=1", t('first')); - + // full pager (first / prev / 1 / 2 / ... / 14 / 15 / next / last) + $data['class'] = 'pagination'; + if ($a->pager['total'] > $a->pager['itemspage']) { + _l($data, 'first', $url . '&page=1', t('first'), $a->pager['page'] == 1 ? 'disabled' : ''); + _l($data, 'prev', $url . '&page=' . ($a->pager['page'] - 1), t('prev'), $a->pager['page'] == 1 ? 'disabled' : ''); $numpages = $a->pager['total'] / $a->pager['itemspage']; $numstart = 1; $numstop = $numpages; - if($numpages > 14) { - $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1); - $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14)); + // Limit the number of displayed page number buttons. + if ($numpages > 8) { + $numstart = (($pagenum > 4) ? ($pagenum - 4) : 1); + $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 8)); } $pages = array(); - for($i = $numstart; $i <= $numstop; $i++){ - if($i == $a->pager['page']) - _l($pages, $i, "#", $i, "current"); - else - _l($pages, $i, $url."&page=$i", $i, "n"); + for ($i = $numstart; $i <= $numstop; $i++) { + if ($i == $a->pager['page']) { + _l($pages, $i, '#', $i, 'current active'); + } else { + _l($pages, $i, $url . '&page='. $i, $i, 'n'); + } } - if(($a->pager['total'] % $a->pager['itemspage']) != 0) { - if($i == $a->pager['page']) - _l($pages, $i, "#", $i, "current"); - else - _l($pages, $i, $url."&page=$i", $i, "n"); + if (($a->pager['total'] % $a->pager['itemspage']) != 0) { + if ($i == $a->pager['page']) { + _l($pages, $i, '#', $i, 'current active'); + } else { + _l($pages, $i, $url . '&page=' . $i, $i, 'n'); + } } $data['pages'] = $pages; $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages); - _l($data, "last", $url."&page=$lastpage", t('last')); - - if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0) - _l($data, "next", $url."&page=".($a->pager['page'] + 1), t('next')); - + _l($data, 'next', $url . '&page=' . ($a->pager['page'] + 1), t('next'), $a->pager['page'] == $lastpage ? 'disabled' : ''); + _l($data, 'last', $url . '&page=' . $lastpage, t('last'), $a->pager['page'] == $lastpage ? 'disabled' : ''); } } - return $data; -}} + return $data; +} if(! function_exists('paginate')) { /** diff --git a/include/threadupdate.php b/include/threadupdate.php index dc528c6b8..3a4028603 100644 --- a/include/threadupdate.php +++ b/include/threadupdate.php @@ -1,25 +1,7 @@ diff --git a/include/uimport.php b/include/uimport.php index c6eeb6fc7..4cc5b6c04 100644 --- a/include/uimport.php +++ b/include/uimport.php @@ -11,14 +11,11 @@ define("IMPORT_DEBUG", False); function last_insert_id() { global $db; + if (IMPORT_DEBUG) return 1; - if ($db->mysqli) { - $thedb = $db->getdb(); - return $thedb->insert_id; - } else { - return mysql_insert_id(); - } + + return $db->insert_id(); } function last_error() { diff --git a/include/update_gcontact.php b/include/update_gcontact.php index 6aa8bcac2..08d4149a7 100644 --- a/include/update_gcontact.php +++ b/include/update_gcontact.php @@ -2,46 +2,23 @@ use \Friendica\Core\Config; -require_once("boot.php"); - function update_gcontact_run(&$argv, &$argc){ - global $a, $db; - - if(is_null($a)) { - $a = new App; - } - - if(is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); - }; + global $a; require_once('include/Scrape.php'); - require_once("include/socgraph.php"); - - Config::load(); - - $a->set_baseurl(get_config('system','url')); - - load_hooks(); + require_once('include/socgraph.php'); logger('update_gcontact: start'); - if(($argc > 1) && (intval($argv[1]))) + if (($argc > 1) && (intval($argv[1]))) { $contact_id = intval($argv[1]); + } - if(!$contact_id) { + if (!$contact_id) { logger('update_gcontact: no contact'); return; } - // Don't check this stuff if the function is called by the poller - if (App::callstack() != "poller_run") - if (App::is_already_running('update_gcontact'.$contact_id, '', 540)) - return; - $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id)); if (!$r) @@ -98,8 +75,3 @@ function update_gcontact_run(&$argv, &$argc){ dbesc(normalise_link($data["url"])) ); } - -if (array_search(__file__,get_included_files())===0){ - update_gcontact_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -} diff --git a/mod/admin.php b/mod/admin.php index 147513083..b1bc8de5f 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -27,7 +27,7 @@ require_once("include/text.php"); function admin_post(App $a) { - if(!is_site_admin()) { + if (!is_site_admin()) { return; } @@ -39,7 +39,7 @@ function admin_post(App $a) { // urls if ($a->argc > 1) { - switch ($a->argv[1]){ + switch ($a->argv[1]) { case 'site': admin_page_site_post($a); break; @@ -47,10 +47,10 @@ function admin_post(App $a) { admin_page_users_post($a); break; case 'plugins': - if($a->argc > 2 && + if ($a->argc > 2 && is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")) { @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php"); - if(function_exists($a->argv[2].'_plugin_admin_post')) { + if (function_exists($a->argv[2].'_plugin_admin_post')) { $func = $a->argv[2].'_plugin_admin_post'; $func($a); } @@ -59,14 +59,16 @@ function admin_post(App $a) { return; // NOTREACHED break; case 'themes': - if($a->argc < 2) { - if(is_ajax()) return; + if ($a->argc < 2) { + if (is_ajax()) { + return; + } goaway('admin/'); return; } $theme = $a->argv[2]; - if(is_file("view/theme/$theme/config.php")){ + if (is_file("view/theme/$theme/config.php")) { function __call_theme_admin_post(App $a, $theme) { $orig_theme = $a->theme; $orig_page = $a->page; @@ -77,8 +79,10 @@ function admin_post(App $a) { $init = $theme."_init"; - if(function_exists($init)) $init($a); - if(function_exists("theme_admin_post")) { + if (function_exists($init)) { + $init($a); + } + if (function_exists("theme_admin_post")) { $admin_form = theme_admin_post($a); } @@ -90,8 +94,9 @@ function admin_post(App $a) { __call_theme_admin_post($a, $theme); } info(t('Theme settings updated.')); - if(is_ajax()) return; - + if (is_ajax()) { + return; + } goaway('admin/themes/'.$theme); return; break; @@ -130,7 +135,7 @@ function admin_post(App $a) { */ function admin_content(App $a) { - if(!is_site_admin()) { + if (!is_site_admin()) { return login(false); } @@ -168,7 +173,7 @@ function admin_content(App $a) { $r = q("SELECT `name` FROM `addon` WHERE `plugin_admin` = 1 ORDER BY `name`"); $aside_tools['plugins_admin']=array(); - foreach ($r as $h){ + foreach ($r as $h) { $plugin =$h['name']; $aside_tools['plugins_admin'][] = array("admin/plugins/".$plugin, $plugin, "plugin"); // temp plugins with admin @@ -199,8 +204,8 @@ function admin_content(App $a) { */ $o = ''; // urls - if($a->argc > 1) { - switch ($a->argv[1]){ + if ($a->argc > 1) { + switch ($a->argv[1]) { case 'site': $o = admin_page_site($a); break; @@ -238,7 +243,7 @@ function admin_content(App $a) { $o = admin_page_summary($a); } - if(is_ajax()) { + if (is_ajax()) { echo $o; killme(); return ''; @@ -270,8 +275,8 @@ function admin_page_federation(App $a) { // off one % two of them are needed in the query // Add more platforms if you like, when one returns 0 known nodes it is not // displayed on the stats page. - $platforms = array('Friendica', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon'); - $colors = array('Friendica' => '#ffc018', // orange from the logo + $platforms = array('Friendi%%a', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon'); + $colors = array('Friendi%%a' => '#ffc018', // orange from the logo 'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray '%%red%%' => '#c50001', // fire red from the logo 'Hubzilla' => '#43488a', // blue from the logo @@ -310,19 +315,21 @@ function admin_page_federation(App $a) { // in the DB the Diaspora versions have the format x.x.x.x-xx the last // part (-xx) should be removed to clean up the versions from the "head // commit" information and combined into a single entry for x.x.x.x - if($p=='Diaspora') { + if ($p == 'Diaspora') { $newV = array(); $newVv = array(); - foreach($v as $vv) { + foreach ($v as $vv) { $newVC = $vv['total']; $newVV = $vv['version']; $posDash = strpos($newVV, '-'); - if($posDash) + if ($posDash) { $newVV = substr($newVV, 0, $posDash); - if(isset($newV[$newVV])) + } + if (isset($newV[$newVV])) { $newV[$newVV] += $newVC; - else + } else { $newV[$newVV] = $newVC; + } } foreach ($newV as $key => $value) { array_push($newVv, array('total'=>$value, 'version'=>$key)); @@ -333,7 +340,7 @@ function admin_page_federation(App $a) { // early friendica versions have the format x.x.xxxx where xxxx is the // DB version stamp; those should be operated out and versions be // conbined - if($p=='Friendica') { + if ($p == 'Friendi%%a') { $newV = array(); $newVv = array(); foreach ($v as $vv) { @@ -341,12 +348,14 @@ function admin_page_federation(App $a) { $newVV = $vv['version']; $lastDot = strrpos($newVV,'.'); $len = strlen($newVV)-1; - if(($lastDot == $len-4) && (!strrpos($newVV,'-rc')==$len-3)) + if (($lastDot == $len-4) && (!strrpos($newVV,'-rc') == $len-3)) { $newVV = substr($newVV, 0, $lastDot); - if(isset($newV[$newVV])) + } + if (isset($newV[$newVV])) { $newV[$newVV] += $newVC; - else + } else { $newV[$newVV] = $newVC; + } } foreach ($newV as $key => $value) { array_push($newVv, array('total'=>$value, 'version'=>$key)); @@ -455,7 +464,10 @@ function admin_page_summary(App $a) { ); $users=0; - foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+= $u['count']; } + foreach ($r as $u) { + $accounts[$u['page-flags']][1] = $u['count']; + $users+= $u['count']; + } logger('accounts: '.print_r($accounts,true),LOGGER_DATA); @@ -468,12 +480,8 @@ function admin_page_summary(App $a) { $r = qu("SELECT COUNT(*) AS `total` FROM `queue` WHERE 1"); $queue = (($r) ? $r[0]['total'] : 0); - if (get_config('system','worker')) { - $r = qu("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE 1"); - $workerqueue = (($r) ? $r[0]['total'] : 0); - } else { - $workerqueue = 0; - } + $r = qu("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE 1"); + $workerqueue = (($r) ? $r[0]['total'] : 0); // We can do better, but this is a quick queue status @@ -485,7 +493,6 @@ function admin_page_summary(App $a) { '$title' => t('Administration'), '$page' => t('Summary'), '$queues' => $queues, - '$workeractive' => get_config('system','worker'), '$users' => array(t('Registered users'), $users), '$accounts' => $accounts, '$pending' => array(t('Pending registrations'), $pending), @@ -506,19 +513,19 @@ function admin_page_summary(App $a) { * @param App $a */ function admin_page_site_post(App $a) { - if(!x($_POST,"page_site")) { + if (!x($_POST,"page_site")) { return; } check_form_security_token_redirectOnErr('/admin/site', 'admin_site'); // relocate - if(x($_POST,'relocate') && x($_POST,'relocate_url') && $_POST['relocate_url']!="") { + if (x($_POST,'relocate') && x($_POST,'relocate_url') && $_POST['relocate_url'] != "") { $new_url = $_POST['relocate_url']; $new_url = rtrim($new_url,"/"); $parsed = @parse_url($new_url); - if(!$parsed || (!x($parsed,'host') || !x($parsed,'scheme'))) { + if (!$parsed || (!x($parsed,'host') || !x($parsed,'scheme'))) { notice(t("Can not parse base url. Must have at least ://")); goaway('admin/site'); } @@ -551,7 +558,7 @@ function admin_page_site_post(App $a) { $q = sprintf("UPDATE %s SET %s;", $table_name, $upds); $r = q($q); - if(!$r) { + if (!$r) { notice("Failed updating '$table_name': ".$db->error); goaway('admin/site'); } @@ -630,8 +637,6 @@ function admin_page_site_post(App $a) { $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : ''); $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : ''); $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60); - $delivery_interval = ((x($_POST,'delivery_interval')) ? intval(trim($_POST['delivery_interval'])) : 0); - $poll_interval = ((x($_POST,'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0); $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50); $maxloadavg_frontend = ((x($_POST,'maxloadavg_frontend')) ? intval(trim($_POST['maxloadavg_frontend'])) : 50); $optimize_max_tablesize = ((x($_POST,'optimize_max_tablesize')) ? intval(trim($_POST['optimize_max_tablesize'])): 100); @@ -649,37 +654,32 @@ function admin_page_site_post(App $a) { $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False); $ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0); $force_ssl = ((x($_POST,'force_ssl')) ? True : False); - $old_share = ((x($_POST,'old_share')) ? True : False); $hide_help = ((x($_POST,'hide_help')) ? True : False); - $suppress_language = ((x($_POST,'suppress_language')) ? True : False); $suppress_tags = ((x($_POST,'suppress_tags')) ? True : False); $use_fulltext_engine = ((x($_POST,'use_fulltext_engine')) ? True : False); $itemcache = ((x($_POST,'itemcache')) ? notags(trim($_POST['itemcache'])) : ''); $itemcache_duration = ((x($_POST,'itemcache_duration')) ? intval($_POST['itemcache_duration']) : 0); $max_comments = ((x($_POST,'max_comments')) ? intval($_POST['max_comments']) : 0); - $lockpath = ((x($_POST,'lockpath')) ? notags(trim($_POST['lockpath'])) : ''); $temppath = ((x($_POST,'temppath')) ? notags(trim($_POST['temppath'])) : ''); $basepath = ((x($_POST,'basepath')) ? notags(trim($_POST['basepath'])) : ''); $singleuser = ((x($_POST,'singleuser')) ? notags(trim($_POST['singleuser'])) : ''); $proxy_disabled = ((x($_POST,'proxy_disabled')) ? True : False); - $old_pager = ((x($_POST,'old_pager')) ? True : False); $only_tag_search = ((x($_POST,'only_tag_search')) ? True : False); $rino = ((x($_POST,'rino')) ? intval($_POST['rino']) : 0); $embedly = ((x($_POST,'embedly')) ? notags(trim($_POST['embedly'])) : ''); - $worker = ((x($_POST,'worker')) ? True : False); $worker_queues = ((x($_POST,'worker_queues')) ? intval($_POST['worker_queues']) : 4); $worker_dont_fork = ((x($_POST,'worker_dont_fork')) ? True : False); $worker_fastlane = ((x($_POST,'worker_fastlane')) ? True : False); $worker_frontend = ((x($_POST,'worker_frontend')) ? True : False); - if($a->get_path() != "") + if ($a->get_path() != "") { $diaspora_enabled = false; - - if(!$thread_allow) + } + if (!$thread_allow) { $ostatus_disabled = true; - - if($ssl_policy != intval(get_config('system','ssl_policy'))) { - if($ssl_policy == SSL_POLICY_FULL) { + } + if ($ssl_policy != intval(get_config('system','ssl_policy'))) { + if ($ssl_policy == SSL_POLICY_FULL) { q("UPDATE `contact` SET `url` = REPLACE(`url` , 'http:' , 'https:'), `photo` = REPLACE(`photo` , 'http:' , 'https:'), @@ -697,8 +697,7 @@ function admin_page_site_post(App $a) { `thumb` = REPLACE(`thumb` , 'http:' , 'https:') WHERE 1 " ); - } - elseif($ssl_policy == SSL_POLICY_SELFSIGN) { + } elseif ($ssl_policy == SSL_POLICY_SELFSIGN) { q("UPDATE `contact` SET `url` = REPLACE(`url` , 'https:' , 'http:'), `photo` = REPLACE(`photo` , 'https:' , 'http:'), @@ -719,8 +718,6 @@ function admin_page_site_post(App $a) { } } set_config('system','ssl_policy',$ssl_policy); - set_config('system','delivery_interval',$delivery_interval); - set_config('system','poll_interval',$poll_interval); set_config('system','maxloadavg',$maxloadavg); set_config('system','maxloadavg_frontend',$maxloadavg_frontend); set_config('system','optimize_max_tablesize',$optimize_max_tablesize); @@ -734,12 +731,11 @@ function admin_page_site_post(App $a) { set_config('config','sitename',$sitename); set_config('config','hostname',$hostname); set_config('config','sender_email', $sender_email); - set_config('system','suppress_language',$suppress_language); set_config('system','suppress_tags',$suppress_tags); set_config('system','shortcut_icon',$shortcut_icon); set_config('system','touch_icon',$touch_icon); - if($banner=="") { + if ($banner == "") { // don't know why, but del_config doesn't work... q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1", dbesc("system"), @@ -749,7 +745,7 @@ function admin_page_site_post(App $a) { set_config('system','banner', $banner); } - if($info=="") { + if ($info == "") { del_config('config','info'); } else { set_config('config','info',$info); @@ -757,12 +753,12 @@ function admin_page_site_post(App $a) { set_config('system','language', $language); set_config('system','theme', $theme); - if($theme_mobile === '---') { + if ($theme_mobile === '---') { del_config('system','mobile-theme'); } else { set_config('system','mobile-theme', $theme_mobile); } - if($singleuser === '---') { + if ($singleuser === '---') { del_config('system','singleuser'); } else { set_config('system','singleuser', $singleuser); @@ -805,25 +801,21 @@ function admin_page_site_post(App $a) { set_config('config','private_addons', $private_addons); set_config('system','force_ssl', $force_ssl); - set_config('system','old_share', $old_share); set_config('system','hide_help', $hide_help); set_config('system','use_fulltext_engine', $use_fulltext_engine); set_config('system','itemcache', $itemcache); set_config('system','itemcache_duration', $itemcache_duration); set_config('system','max_comments', $max_comments); - set_config('system','lockpath', $lockpath); set_config('system','temppath', $temppath); set_config('system','basepath', $basepath); set_config('system','proxy_disabled', $proxy_disabled); - set_config('system','old_pager', $old_pager); set_config('system','only_tag_search', $only_tag_search); - set_config('system','worker', $worker); set_config('system','worker_queues', $worker_queues); set_config('system','worker_dont_fork', $worker_dont_fork); set_config('system','worker_fastlane', $worker_fastlane); set_config('system','frontend_worker', $worker_frontend); - if($rino==2 and !function_exists('mcrypt_create_iv')) { + if (($rino == 2) and !function_exists('mcrypt_create_iv')) { notice(t("RINO2 needs mcrypt php extension to work.")); } else { set_config('system','rino_encrypt', $rino); @@ -851,7 +843,7 @@ function admin_page_site(App $a) { /* Installed langs */ $lang_choices = get_available_languages(); - if(strlen(get_config('system','directory_submit_url')) AND + if (strlen(get_config('system','directory_submit_url')) AND !strlen(get_config('system','directory'))) { set_config('system','directory', dirname(get_config('system','directory_submit_url'))); del_config('system','directory_submit_url'); @@ -862,12 +854,12 @@ function admin_page_site(App $a) { $theme_choices_mobile = array(); $theme_choices_mobile["---"] = t("No special theme for mobile devices"); $files = glob('view/theme/*'); - if($files) { + if ($files) { $allowed_theme_list = Config::get('system', 'allowed_themes'); - foreach($files as $file) { - if(intval(file_exists($file.'/unsupported'))) + foreach ($files as $file) { + if (intval(file_exists($file.'/unsupported'))) continue; $f = basename($file); @@ -879,7 +871,7 @@ function admin_page_site(App $a) { $theme_name = ((file_exists($file.'/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f); - if(file_exists($file.'/mobile')) { + if (file_exists($file.'/mobile')) { $theme_choices_mobile[$f] = $theme_name; } else { $theme_choices[$f] = $theme_name; @@ -928,15 +920,15 @@ function admin_page_site(App $a) { /* Banner */ $banner = get_config('system','banner'); - if($banner == false) + if ($banner == false) { $banner = 'logoFriendica'; + } $banner = htmlspecialchars($banner); $info = get_config('config','info'); $info = htmlspecialchars($info); // Automatically create temporary paths get_temppath(); - get_lockpath(); get_itemcachepath(); //echo "
"; var_dump($lang_choices); die("
"); @@ -954,9 +946,9 @@ function admin_page_site(App $a) { SSL_POLICY_SELFSIGN => t("Self-signed certificate, use SSL for local links only (discouraged)") ); - if($a->config['hostname'] == "") + if ($a->config['hostname'] == "") { $a->config['hostname'] = $a->get_hostname(); - + } $diaspora_able = ($a->get_path() == ""); $optimize_max_tablesize = Config::get('system','optimize_max_tablesize', 100); @@ -996,7 +988,6 @@ function admin_page_site(App $a) { '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), get_config('system','mobile-theme'), t("Theme for mobile devices"), $theme_choices_mobile), '$ssl_policy' => array('ssl_policy', t("SSL link policy"), (string) intval(get_config('system','ssl_policy')), t("Determines whether generated links should be forced to use SSL"), $ssl_choices), '$force_ssl' => array('force_ssl', t("Force SSL"), get_config('system','force_ssl'), t("Force all Non-SSL requests to SSL - Attention: on some systems it could lead to endless loops.")), - '$old_share' => array('old_share', t("Old style 'Share'"), get_config('system','old_share'), t("Deactivates the bbcode element 'share' for repeating items.")), '$hide_help' => array('hide_help', t("Hide help entry from navigation menu"), get_config('system','hide_help'), t("Hides the menu entry for the Help pages from the navigation menu. You can still access it calling /help directly.")), '$singleuser' => array('singleuser', t("Single user instance"), get_config('system','singleuser'), t("Make this instance multi-user or single-user for the named user"), $user_names), '$maximagesize' => array('maximagesize', t("Maximum image size"), get_config('system','maximagesize'), t("Maximum size in bytes of uploaded images. Default is 0, which means no limits.")), @@ -1036,8 +1027,6 @@ function admin_page_site(App $a) { '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""), '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""), '$timeout' => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), t("Value is in seconds. Set to 0 for unlimited (not recommended).")), - '$delivery_interval' => array('delivery_interval', t("Delivery interval"), (x(get_config('system','delivery_interval'))?get_config('system','delivery_interval'):2), t("Delay background delivery processes by this many seconds to reduce system load. Recommend: 4-5 for shared hosts, 2-3 for virtual private servers. 0-1 for large dedicated servers.")), - '$poll_interval' => array('poll_interval', t("Poll interval"), (x(get_config('system','poll_interval'))?get_config('system','poll_interval'):2), t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")), '$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")), '$maxloadavg_frontend' => array('maxloadavg_frontend', t("Maximum Load Average (Frontend)"), ((intval(get_config('system','maxloadavg_frontend')) > 0)?get_config('system','maxloadavg_frontend'):50), t("Maximum system load before the frontend quits service - default 50.")), '$optimize_max_tablesize'=> array('optimize_max_tablesize', t("Maximum table size for optimization"), $optimize_max_tablesize, t("Maximum table size (in MB) for the automatic optimization - default 100 MB. Enter -1 to disable it.")), @@ -1052,16 +1041,13 @@ function admin_page_site(App $a) { '$nodeinfo' => array('nodeinfo', t("Publish server information"), get_config('system','nodeinfo'), t("If enabled, general server and usage data will be published. The data contains the name and version of the server, number of users with public profiles, number of posts and the activated protocols and connectors. See the-federation.info for details.")), '$use_fulltext_engine' => array('use_fulltext_engine', t("Use MySQL full text engine"), get_config('system','use_fulltext_engine'), t("Activates the full text engine. Speeds up search - but can only search for four and more characters.")), - '$suppress_language' => array('suppress_language', t("Suppress Language"), get_config('system','suppress_language'), t("Suppress language information in meta information about a posting.")), '$suppress_tags' => array('suppress_tags', t("Suppress Tags"), get_config('system','suppress_tags'), t("Suppress showing a list of hashtags at the end of the posting.")), '$itemcache' => array('itemcache', t("Path to item cache"), get_config('system','itemcache'), t("The item caches buffers generated bbcode and external images.")), '$itemcache_duration' => array('itemcache_duration', t("Cache duration in seconds"), get_config('system','itemcache_duration'), t("How long should the cache files be hold? Default value is 86400 seconds (One day). To disable the item cache, set the value to -1.")), '$max_comments' => array('max_comments', t("Maximum numbers of comments per post"), get_config('system','max_comments'), t("How much comments should be shown for each post? Default value is 100.")), - '$lockpath' => array('lockpath', t("Path for lock file"), get_config('system','lockpath'), t("The lock file is used to avoid multiple pollers at one time. Only define a folder here.")), '$temppath' => array('temppath', t("Temp path"), get_config('system','temppath'), t("If you have a restricted system where the webserver can't access the system temp path, enter another path here.")), '$basepath' => array('basepath', t("Base path to installation"), get_config('system','basepath'), t("If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot.")), '$proxy_disabled' => array('proxy_disabled', t("Disable picture proxy"), get_config('system','proxy_disabled'), t("The picture proxy increases performance and privacy. It shouldn't be used on systems with very low bandwith.")), - '$old_pager' => array('old_pager', t("Enable old style pager"), get_config('system','old_pager'), t("The old style pager has page numbers but slows down massively the page speed.")), '$only_tag_search' => array('only_tag_search', t("Only search in tags"), get_config('system','only_tag_search'), t("On large systems the text search can slow down the system extremely.")), '$relocate_url' => array('relocate_url', t("New base url"), App::get_baseurl(), t("Change base url for this server. Sends relocate message to all DFRN contacts of all users.")), @@ -1069,7 +1055,6 @@ function admin_page_site(App $a) { '$rino' => array('rino', t("RINO Encryption"), intval(get_config('system','rino_encrypt')), t("Encryption layer between nodes."), array("Disabled", "RINO1 (deprecated)", "RINO2")), '$embedly' => array('embedly', t("Embedly API key"), get_config('system','embedly'), t("Embedly is used to fetch additional data for web pages. This is an optional parameter.")), - '$worker' => array('worker', t("Enable 'worker' background processing"), get_config('system','worker'), t("The worker background processing limits the number of parallel background jobs to a maximum number and respects the system load.")), '$worker_queues' => array('worker_queues', t("Maximum number of parallel workers"), get_config('system','worker_queues'), t("On shared hosters set this to 2. On larger systems, values of 10 are great. Default value is 4.")), '$worker_dont_fork' => array('worker_dont_fork', t("Don't use 'proc_open' with the worker"), get_config('system','worker_dont_fork'), t("Enable this if your system doesn't allow the use of 'proc_open'. This can happen on shared hosters. If this is enabled you should increase the frequency of poller calls in your crontab.")), '$worker_fastlane' => array('worker_fastlane', t("Enable fastlane"), get_config('system','worker_fastlane'), t("When enabed, the fastlane mechanism starts an additional worker if processes with higher priority are blocked by processes of lower priority.")), @@ -1097,42 +1082,45 @@ function admin_page_dbsync(App $a) { $o = ''; - if($a->argc > 3 && intval($a->argv[3]) && $a->argv[2] === 'mark') { + if ($a->argc > 3 && intval($a->argv[3]) && $a->argv[2] === 'mark') { set_config('database', 'update_'.intval($a->argv[3]), 'success'); $curr = get_config('system','build'); - if(intval($curr) == intval($a->argv[3])) + if (intval($curr) == intval($a->argv[3])) { set_config('system','build',intval($curr) + 1); + } info(t('Update has been marked successful').EOL); goaway('admin/dbsync'); } - if(($a->argc > 2) AND (intval($a->argv[2]) OR ($a->argv[2] === 'check'))) { + if (($a->argc > 2) AND (intval($a->argv[2]) OR ($a->argv[2] === 'check'))) { require_once("include/dbstructure.php"); $retval = update_structure(false, true); - if(!$retval) { + if (!$retval) { $o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION)."
"; set_config('database', 'dbupdate_'.DB_UPDATE_VERSION, 'success'); - } else + } else { $o .= sprintf(t("Executing of database structure update %s failed with error: %s"), DB_UPDATE_VERSION, $retval)."
"; - if($a->argv[2] === 'check') + } + if ($a->argv[2] === 'check') { return $o; + } } - if($a->argc > 2 && intval($a->argv[2])) { + if ($a->argc > 2 && intval($a->argv[2])) { require_once('update.php'); $func = 'update_'.intval($a->argv[2]); - if(function_exists($func)) { + if (function_exists($func)) { $retval = $func(); - if($retval === UPDATE_FAILED) { + if ($retval === UPDATE_FAILED) { $o .= sprintf(t("Executing %s failed with error: %s"), $func, $retval); } - elseif($retval === UPDATE_SUCCESS) { + elseif ($retval === UPDATE_SUCCESS) { $o .= sprintf(t('Update %s was successfully applied.', $func)); set_config('database',$func, 'success'); - } - else + } else { $o .= sprintf(t('Update %s did not return a status. Unknown if it succeeded.'), $func); + } } else { $o .= sprintf(t('There was no additional update function %s that needed to be called.'), $func)."
"; set_config('database',$func, 'success'); @@ -1145,8 +1133,9 @@ function admin_page_dbsync(App $a) { if (dbm::is_result($r)) { foreach ($r as $rr) { $upd = intval(substr($rr['k'],7)); - if($upd < 1139 || $rr['v'] === 'success') + if ($upd < 1139 || $rr['v'] === 'success') { continue; + } $failed[] = $upd; } } @@ -1186,7 +1175,7 @@ function admin_page_users_post(App $a) { check_form_security_token_redirectOnErr('/admin/users', 'admin_users'); - if (!($nu_name==="") && !($nu_email==="") && !($nu_nickname==="")) { + if (!($nu_name === "") && !($nu_email === "") && !($nu_nickname === "")) { require_once('include/user.php'); $result = create_user(array('username'=>$nu_name, 'email'=>$nu_email, @@ -1237,31 +1226,31 @@ function admin_page_users_post(App $a) { } - if(x($_POST,'page_users_block')) { - foreach($users as $uid){ + if (x($_POST,'page_users_block')) { + foreach ($users as $uid) { q("UPDATE `user` SET `blocked` = 1-`blocked` WHERE `uid` = %s", intval($uid) ); } notice(sprintf(tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users))); } - if(x($_POST,'page_users_delete')) { + if (x($_POST,'page_users_delete')) { require_once("include/Contact.php"); - foreach($users as $uid){ + foreach ($users as $uid) { user_remove($uid); } notice(sprintf(tt("%s user deleted", "%s users deleted", count($users)), count($users))); } - if(x($_POST,'page_users_approve')) { + if (x($_POST,'page_users_approve')) { require_once("mod/regmod.php"); - foreach($pending as $hash){ + foreach ($pending as $hash) { user_allow($hash); } } - if(x($_POST,'page_users_deny')) { + if (x($_POST,'page_users_deny')) { require_once("mod/regmod.php"); - foreach($pending as $hash){ + foreach ($pending as $hash) { user_deny($hash); } } @@ -1282,31 +1271,31 @@ function admin_page_users_post(App $a) { * @return string */ function admin_page_users(App $a) { - if($a->argc>2) { + if ($a->argc>2) { $uid = $a->argv[3]; $user = q("SELECT `username`, `blocked` FROM `user` WHERE `uid` = %d", intval($uid)); - if(count($user)==0) { + if (count($user) == 0) { notice('User not found'.EOL); goaway('admin/users'); return ''; // NOTREACHED } - switch($a->argv[2]){ - case "delete":{ + switch($a->argv[2]) { + case "delete": check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't'); // delete user require_once("include/Contact.php"); user_remove($uid); notice(sprintf(t("User '%s' deleted"), $user[0]['username']).EOL); - }; break; - case "block":{ + break; + case "block": check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't'); q("UPDATE `user` SET `blocked` = %d WHERE `uid` = %s", intval(1-$user[0]['blocked']), intval($uid) ); notice(sprintf(($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']).EOL); - }; break; + break; } goaway('admin/users'); return ''; // NOTREACHED @@ -1322,7 +1311,7 @@ function admin_page_users(App $a) { /* get users */ $total = qu("SELECT COUNT(*) AS `total` FROM `user` WHERE 1"); - if(count($total)) { + if (count($total)) { $a->set_pager_total($total[0]['total']); $a->set_pager_itemspage(100); } @@ -1339,22 +1328,22 @@ function admin_page_users(App $a) { $order = "contact.name"; $order_direction = "+"; - if (x($_GET,'o')){ + if (x($_GET,'o')) { $new_order = $_GET['o']; - if ($new_order[0]==="-") { + if ($new_order[0] === "-") { $order_direction = "-"; $new_order = substr($new_order,1); } - if (in_array($new_order, $valid_orders)){ + if (in_array($new_order, $valid_orders)) { $order = $new_order; } - if (x($_GET,'d')){ + if (x($_GET,'d')) { $new_direction = $_GET['d']; } } $sql_order = "`".str_replace('.','`.`',$order)."`"; - $sql_order_direction = ($order_direction==="+")?"ASC":"DESC"; + $sql_order_direction = ($order_direction === "+")?"ASC":"DESC"; $users = qu("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date` FROM `user` @@ -1368,7 +1357,7 @@ function admin_page_users(App $a) { //echo "
$users"; killme();
 
 	$adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
-	$_setup_users = function ($e) use ($adminlist){
+	$_setup_users = function ($e) use ($adminlist) {
 		$accounts = array(
 			t('Normal Account'),
 			t('Soapbox Account'),
@@ -1394,22 +1383,21 @@ function admin_page_users(App $a) {
 	$tmp_users = array();
 	$deleted = array();
 
-	while(count($users)) {
+	while (count($users)) {
 		$new_user = array();
-		foreach(array_pop($users) as $k => $v) {
+		foreach (array_pop($users) as $k => $v) {
 			$k = str_replace('-','_',$k);
 			$new_user[$k] = $v;
 		}
-		if($new_user['deleted']) {
+		if ($new_user['deleted']) {
 			array_push($deleted, $new_user);
-		}
-		else {
+		} else {
 			array_push($tmp_users, $new_user);
 		}
 	}
 	//Reversing the two array, and moving $tmp_users to $users
 	array_reverse($deleted);
-	while(count($tmp_users)) {
+	while (count($tmp_users)) {
 		array_push($users, array_pop($tmp_users));
 	}
 
@@ -1486,19 +1474,19 @@ function admin_page_plugins(App $a) {
 	/*
 	 * Single plugin
 	 */
-	if($a->argc == 3) {
+	if ($a->argc == 3) {
 		$plugin = $a->argv[2];
-		if(!is_file("addon/$plugin/$plugin.php")) {
+		if (!is_file("addon/$plugin/$plugin.php")) {
 			notice(t("Item not found."));
 			return '';
 		}
 
-		if(x($_GET,"a") && $_GET['a']=="t") {
+		if (x($_GET,"a") && $_GET['a']=="t") {
 			check_form_security_token_redirectOnErr('/admin/plugins', 'admin_themes', 't');
 
 			// Toggle plugin status
 			$idx = array_search($plugin, $a->plugins);
-			if($idx !== false) {
+			if ($idx !== false) {
 				unset($a->plugins[$idx]);
 				uninstall_plugin($plugin);
 				info(sprintf(t("Plugin %s disabled."), $plugin));
@@ -1515,22 +1503,22 @@ function admin_page_plugins(App $a) {
 		// display plugin details
 		require_once('library/markdown.php');
 
-		if(in_array($plugin, $a->plugins)) {
+		if (in_array($plugin, $a->plugins)) {
 			$status="on"; $action= t("Disable");
 		} else {
 			$status="off"; $action= t("Enable");
 		}
 
 		$readme=Null;
-		if(is_file("addon/$plugin/README.md")) {
+		if (is_file("addon/$plugin/README.md")) {
 			$readme = file_get_contents("addon/$plugin/README.md");
 			$readme = Markdown($readme);
-		} elseif(is_file("addon/$plugin/README")) {
+		} elseif (is_file("addon/$plugin/README")) {
 			$readme = "
". file_get_contents("addon/$plugin/README") ."
"; } $admin_form=""; - if(is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)) { + if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)) { @require_once("addon/$plugin/$plugin.php"); $func = $plugin.'_plugin_admin'; $func($a, $admin_form); @@ -1622,8 +1610,8 @@ function admin_page_plugins(App $a) { */ function toggle_theme(&$themes,$th,&$result) { for($x = 0; $x < count($themes); $x ++) { - if($themes[$x]['name'] === $th) { - if($themes[$x]['allowed']) { + if ($themes[$x]['name'] === $th) { + if ($themes[$x]['allowed']) { $themes[$x]['allowed'] = 0; $result = 0; } @@ -1642,8 +1630,8 @@ function toggle_theme(&$themes,$th,&$result) { */ function theme_status($themes,$th) { for($x = 0; $x < count($themes); $x ++) { - if($themes[$x]['name'] === $th) { - if($themes[$x]['allowed']) { + if ($themes[$x]['name'] === $th) { + if ($themes[$x]['allowed']) { return 1; } else { @@ -1661,11 +1649,12 @@ function theme_status($themes,$th) { */ function rebuild_theme_table($themes) { $o = ''; - if(count($themes)) { - foreach($themes as $th) { - if($th['allowed']) { - if(strlen($o)) + if (count($themes)) { + foreach ($themes as $th) { + if ($th['allowed']) { + if (strlen($o)) { $o .= ','; + } $o .= $th['name']; } } @@ -1695,15 +1684,18 @@ function admin_page_themes(App $a) { $allowed_themes_str = get_config('system','allowed_themes'); $allowed_themes_raw = explode(',',$allowed_themes_str); $allowed_themes = array(); - if(count($allowed_themes_raw)) - foreach($allowed_themes_raw as $x) - if(strlen(trim($x))) + if (count($allowed_themes_raw)) { + foreach ($allowed_themes_raw as $x) { + if (strlen(trim($x))) { $allowed_themes[] = trim($x); + } + } + } $themes = array(); $files = glob('view/theme/*'); - if($files) { - foreach($files as $file) { + if ($files) { + foreach ($files as $file) { $f = basename($file); // Is there a style file? @@ -1718,12 +1710,13 @@ function admin_page_themes(App $a) { $is_supported = 1-(intval(file_exists($file.'/unsupported'))); $is_allowed = intval(in_array($f,$allowed_themes)); - if($is_allowed OR $is_supported OR get_config("system", "show_unsupported_themes")) + if ($is_allowed OR $is_supported OR get_config("system", "show_unsupported_themes")) { $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed); + } } } - if(! count($themes)) { + if (! count($themes)) { notice(t('No themes found.')); return ''; } @@ -1732,25 +1725,24 @@ function admin_page_themes(App $a) { * Single theme */ - if($a->argc == 3) { + if ($a->argc == 3) { $theme = $a->argv[2]; - if(! is_dir("view/theme/$theme")) { + if (! is_dir("view/theme/$theme")) { notice(t("Item not found.")); return ''; } - if(x($_GET,"a") && $_GET['a']=="t") { + if (x($_GET,"a") && $_GET['a']=="t") { check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't'); // Toggle theme status toggle_theme($themes,$theme,$result); $s = rebuild_theme_table($themes); - if($result) { + if ($result) { install_theme($theme); info(sprintf('Theme %s enabled.',$theme)); - } - else { + } else { uninstall_theme($theme); info(sprintf('Theme %s disabled.',$theme)); } @@ -1763,22 +1755,22 @@ function admin_page_themes(App $a) { // display theme details require_once('library/markdown.php'); - if(theme_status($themes,$theme)) { + if (theme_status($themes,$theme)) { $status="on"; $action= t("Disable"); } else { $status="off"; $action= t("Enable"); } - $readme=Null; - if(is_file("view/theme/$theme/README.md")) { + $readme = Null; + if (is_file("view/theme/$theme/README.md")) { $readme = file_get_contents("view/theme/$theme/README.md"); $readme = Markdown($readme); - } elseif(is_file("view/theme/$theme/README")) { + } elseif (is_file("view/theme/$theme/README")) { $readme = "
". file_get_contents("view/theme/$theme/README") ."
"; } - $admin_form=""; - if(is_file("view/theme/$theme/config.php")) { + $admin_form = ""; + if (is_file("view/theme/$theme/config.php")) { function __get_theme_admin_form(App $a, $theme) { $orig_theme = $a->theme; $orig_page = $a->page; @@ -1789,8 +1781,10 @@ function admin_page_themes(App $a) { $init = $theme."_init"; - if(function_exists($init)) $init($a); - if(function_exists("theme_admin")) { + if (function_exists($init)) { + $init($a); + } + if (function_exists("theme_admin")) { $admin_form = theme_admin($a); } @@ -1803,9 +1797,9 @@ function admin_page_themes(App $a) { } $screenshot = array(get_theme_screenshot($theme), t('Screenshot')); - if(! stristr($screenshot[0],$theme)) + if (! stristr($screenshot[0],$theme)) { $screenshot = null; - + } $t = get_markup_template("admin_plugins_details.tpl"); return replace_macros($t, array( @@ -1851,7 +1845,7 @@ function admin_page_themes(App $a) { $xthemes = array(); if ($themes) { - foreach($themes as $th) { + foreach ($themes as $th) { $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name'])); } } @@ -1976,25 +1970,25 @@ function admin_page_viewlogs(App $a) { $f = get_config('system','logfile'); $data = ''; - if(!file_exists($f)) { + if (!file_exists($f)) { $data = t("Error trying to open $f log file.\r\n
Check to see if file $f exist and is readable."); - } - else { + } else { $fp = fopen($f, 'r'); - if(!$fp) { + if (!$fp) { $data = t("Couldn't open $f log file.\r\n
Check to see if file $f is readable."); - } - else { + } else { $fstat = fstat($fp); $size = $fstat['size']; - if($size != 0) { - if($size > 5000000 || $size < 0) + if ($size != 0) { + if ($size > 5000000 || $size < 0) { $size = 5000000; + } $seek = fseek($fp,0-$size,SEEK_END); - if($seek === 0) { + if ($seek === 0) { $data = escape_tags(fread($fp,$size)); - while(! feof($fp)) + while (! feof($fp)) { $data .= escape_tags(fread($fp,4096)); + } } } fclose($fp); @@ -2022,22 +2016,24 @@ function admin_page_features_post(App $a) { $arr = array(); $features = get_features(false); - foreach($features as $fname => $fdata) { - foreach(array_slice($fdata,1) as $f) { + foreach ($features as $fname => $fdata) { + foreach (array_slice($fdata,1) as $f) { $feature = $f[0]; $feature_state = 'feature_'.$feature; $featurelock = 'featurelock_'.$feature; - if(x($_POST[$feature_state])) + if (x($_POST[$feature_state])) { $val = intval($_POST['feature_'.$feature]); - else + } else { $val = 0; + } set_config('feature',$feature,$val); - if(x($_POST[$featurelock])) + if (x($_POST[$featurelock])) { set_config('feature_lock',$feature,$val); - else + } else { del_config('feature_lock',$feature); + } } } @@ -2061,18 +2057,19 @@ function admin_page_features_post(App $a) { */ function admin_page_features(App $a) { - if((argc() > 1) && (argv(1) === 'features')) { + if ((argc() > 1) && (argv(1) === 'features')) { $arr = array(); $features = get_features(false); - foreach($features as $fname => $fdata) { + foreach ($features as $fname => $fdata) { $arr[$fname] = array(); $arr[$fname][0] = $fdata[0]; - foreach(array_slice($fdata,1) as $f) { + foreach (array_slice($fdata,1) as $f) { $set = get_config('feature',$f[0]); - if($set === false) + if ($set === false) { $set = $f[3]; + } $arr[$fname][1][] = array( array('feature_' .$f[0],$f[1],$set,$f[2],array(t('Off'),t('On'))), array('featurelock_' .$f[0],sprintf(t('Lock feature %s'),$f[1]),(($f[4] !== false) ? "1" : ''),'',array(t('Off'),t('On'))) diff --git a/mod/community.php b/mod/community.php index 7c92ff462..174330401 100644 --- a/mod/community.php +++ b/mod/community.php @@ -48,27 +48,6 @@ function community_content(App $a, $update = 0) { // Only public posts can be shown // OR your own posts if you are a logged in member - if(get_config('system', 'old_pager')) { - $r = qu("SELECT COUNT(distinct(`item`.`uri`)) AS `total` - FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - INNER JOIN `user` ON `user`.`uid` = `item`.`uid` AND `user`.`hidewall` = 0 - WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 - AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' - AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' - AND `item`.`private` = 0 AND `item`.`wall` = 1" - ); - - if (dbm::is_result($r)) - $a->set_pager_total($r[0]['total']); - - if(! $r[0]['total']) { - info( t('No results.') . EOL); - return $o; - } - - } - $r = community_getitems($a->pager['start'], $a->pager['itemspage']); if (! dbm::is_result($r)) { @@ -105,13 +84,9 @@ function community_content(App $a, $update = 0) { // we behave the same in message lists as the search module - $o .= conversation($a,$s,'community',$update); + $o .= conversation($a, $s, 'community', $update); - if(!get_config('system', 'old_pager')) { - $o .= alt_pager($a,count($r)); - } else { - $o .= paginate($a); - } + $o .= alt_pager($a, count($r)); return $o; } diff --git a/mod/network.php b/mod/network.php index 23cf098b6..a1181a74c 100644 --- a/mod/network.php +++ b/mod/network.php @@ -599,21 +599,6 @@ function network_content(App $a, $update = 0) { $pager_sql = ''; } else { - if(get_config('system', 'old_pager')) { - $r = qu("SELECT COUNT(*) AS `total` - FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = $sql_table.`contact-id` - AND (NOT `contact`.`blocked` OR `contact`.`pending`) - WHERE $sql_table.`uid` = %d AND $sql_table.`visible` AND NOT $sql_table.`deleted` - $sql_extra2 $sql_extra3 - $sql_extra $sql_nets ", - intval($_SESSION['uid']) - ); - - if (dbm::is_result($r)) { - $a->set_pager_total($r[0]['total']); - } - } - // check if we serve a mobile device and get the user settings // accordingly if ($a->is_mobile) { @@ -788,15 +773,13 @@ function network_content(App $a, $update = 0) { $mode = (($nouveau) ? 'network-new' : 'network'); - $o .= conversation($a,$items,$mode,$update); + $o .= conversation($a, $items, $mode, $update); if (!$update) { - if (get_pconfig(local_user(),'system','infinite_scroll')) { + if (get_pconfig(local_user(), 'system', 'infinite_scroll')) { $o .= scroll_loader(); - } elseif (!get_config('system', 'old_pager')) { - $o .= alt_pager($a,count($items)); } else { - $o .= paginate($a); + $o .= alt_pager($a, count($items)); } } diff --git a/mod/openid.php b/mod/openid.php index 59a753014..b45cd9797 100644 --- a/mod/openid.php +++ b/mod/openid.php @@ -30,7 +30,7 @@ function openid_content(App $a) { // mod/settings.php in 8367cad so it might have left mixed // records in the user table // - $r = q("SELECT * FROM `user` + $r = q("SELECT *, `user`.`pubkey` as `upubkey`, `user`.`prvkey` as `uprvkey` FROM `user` WHERE ( `openid` = '%s' OR `openid` = '%s' ) AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 diff --git a/mod/poco.php b/mod/poco.php index 4ce075301..30648acab 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -7,14 +7,14 @@ function poco_init(App $a) { $system_mode = false; - if(intval(get_config('system','block_public')) || (get_config('system','block_local_dir'))) + if (intval(get_config('system','block_public')) || (get_config('system','block_local_dir'))) { http_status_exit(401); + } - - if($a->argc > 1) { + if ($a->argc > 1) { $user = notags(trim($a->argv[1])); } - if(! x($user)) { + if (! x($user)) { $c = q("SELECT * FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1"); if (! dbm::is_result($c)) { http_status_exit(401); @@ -27,42 +27,55 @@ function poco_init(App $a) { $justme = false; $global = false; - if($a->argc > 1 && $a->argv[1] === '@global') { + if ($a->argc > 1 && $a->argv[1] === '@server') { + // List of all servers that this server knows + $ret = poco_serverlist(); + header('Content-type: application/json'); + echo json_encode($ret); + killme(); + } + if ($a->argc > 1 && $a->argv[1] === '@global') { + // List of all profiles that this server recently had data from $global = true; $update_limit = date("Y-m-d H:i:s", time() - 30 * 86400); } - if($a->argc > 2 && $a->argv[2] === '@me') + if ($a->argc > 2 && $a->argv[2] === '@me') { $justme = true; - if($a->argc > 3 && $a->argv[3] === '@all') + } + if ($a->argc > 3 && $a->argv[3] === '@all') { $justme = false; - if($a->argc > 3 && $a->argv[3] === '@self') + } + if ($a->argc > 3 && $a->argv[3] === '@self') { $justme = true; - if($a->argc > 4 && intval($a->argv[4]) && $justme == false) + } + if ($a->argc > 4 && intval($a->argv[4]) && $justme == false) { $cid = intval($a->argv[4]); + } - - if(!$system_mode AND !$global) { + if (!$system_mode AND !$global) { $r = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid` where `user`.`nickname` = '%s' and `profile`.`is-default` = 1 limit 1", dbesc($user) ); - if(! dbm::is_result($r) || $r[0]['hidewall'] || $r[0]['hide-friends']) + if (! dbm::is_result($r) || $r[0]['hidewall'] || $r[0]['hide-friends']) { http_status_exit(404); + } $user = $r[0]; } - if($justme) + if ($justme) { $sql_extra = " AND `contact`.`self` = 1 "; + } // else // $sql_extra = " AND `contact`.`self` = 0 "; - if($cid) + if ($cid) { $sql_extra = sprintf(" AND `contact`.`id` = %d ",intval($cid)); - - if(x($_GET,'updatedSince')) + } + if (x($_GET,'updatedSince')) { $update_limit = date("Y-m-d H:i:s",strtotime($_GET['updatedSince'])); - + } if ($global) { $r = q("SELECT count(*) AS `total` FROM `gcontact` WHERE `updated` >= '%s' AND `updated` >= `last_failure` AND NOT `hide` AND `network` IN ('%s', '%s', '%s')", dbesc($update_limit), @@ -70,7 +83,7 @@ function poco_init(App $a) { dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS) ); - } elseif($system_mode) { + } elseif ($system_mode) { $r = q("SELECT count(*) AS `total` FROM `contact` WHERE `self` = 1 AND `uid` IN (SELECT `uid` FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1) "); } else { @@ -84,14 +97,15 @@ function poco_init(App $a) { dbesc(NETWORK_STATUSNET) ); } - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $totalResults = intval($r[0]['total']); - else + } else { $totalResults = 0; - + } $startIndex = intval($_GET['startIndex']); - if(! $startIndex) + if (! $startIndex) { $startIndex = 0; + } $itemsPerPage = ((x($_GET,'count') && intval($_GET['count'])) ? intval($_GET['count']) : $totalResults); if ($global) { @@ -105,7 +119,7 @@ function poco_init(App $a) { intval($startIndex), intval($itemsPerPage) ); - } elseif($system_mode) { + } elseif ($system_mode) { logger("Start system mode query", LOGGER_DEBUG); $r = q("SELECT `contact`.*, `profile`.`about` AS `pabout`, `profile`.`locality` AS `plocation`, `profile`.`pub_keywords`, `profile`.`gender` AS `pgender`, `profile`.`address` AS `paddress`, `profile`.`region` AS `pregion`, @@ -134,13 +148,15 @@ function poco_init(App $a) { logger("Query done", LOGGER_DEBUG); $ret = array(); - if(x($_GET,'sorted')) + if (x($_GET,'sorted')) { $ret['sorted'] = false; - if(x($_GET,'filtered')) + } + if (x($_GET,'filtered')) { $ret['filtered'] = false; - if(x($_GET,'updatedSince') AND !$global) + } + if (x($_GET,'updatedSince') AND !$global) { $ret['updatedSince'] = false; - + } $ret['startIndex'] = (int) $startIndex; $ret['itemsPerPage'] = (int) $itemsPerPage; $ret['totalResults'] = (int) $totalResults; @@ -164,58 +180,61 @@ function poco_init(App $a) { 'generation' => false ); - if((! x($_GET,'fields')) || ($_GET['fields'] === '@all')) - foreach($fields_ret as $k => $v) + if ((! x($_GET,'fields')) || ($_GET['fields'] === '@all')) { + foreach ($fields_ret as $k => $v) { $fields_ret[$k] = true; - else { + } + } else { $fields_req = explode(',',$_GET['fields']); - foreach($fields_req as $f) + foreach ($fields_req as $f) { $fields_ret[trim($f)] = true; + } } - if(is_array($r)) { + if (is_array($r)) { if (dbm::is_result($r)) { foreach ($r as $rr) { if (!isset($rr['generation'])) { - if ($global) + if ($global) { $rr['generation'] = 3; - elseif ($system_mode) + } elseif ($system_mode) { $rr['generation'] = 1; - else + } else { $rr['generation'] = 2; + } } - if (($rr['about'] == "") AND isset($rr['pabout'])) + if (($rr['about'] == "") AND isset($rr['pabout'])) { $rr['about'] = $rr['pabout']; - + } if ($rr['location'] == "") { - if (isset($rr['plocation'])) + if (isset($rr['plocation'])) { $rr['location'] = $rr['plocation']; - + } if (isset($rr['pregion']) AND ($rr['pregion'] != "")) { - if ($rr['location'] != "") + if ($rr['location'] != "") { $rr['location'] .= ", "; - + } $rr['location'] .= $rr['pregion']; } if (isset($rr['pcountry']) AND ($rr['pcountry'] != "")) { - if ($rr['location'] != "") + if ($rr['location'] != "") { $rr['location'] .= ", "; - + } $rr['location'] .= $rr['pcountry']; } } - if (($rr['gender'] == "") AND isset($rr['pgender'])) + if (($rr['gender'] == "") AND isset($rr['pgender'])) { $rr['gender'] = $rr['pgender']; - - if (($rr['keywords'] == "") AND isset($rr['pub_keywords'])) + } + if (($rr['keywords'] == "") AND isset($rr['pub_keywords'])) { $rr['keywords'] = $rr['pub_keywords']; - - if (isset($rr['account-type'])) + } + if (isset($rr['account-type'])) { $rr['contact-type'] = $rr['account-type']; - + } $about = Cache::get("about:".$rr['updated'].":".$rr['nurl']); if (is_null($about)) { $about = bbcode($rr['about'], false, false); @@ -230,111 +249,122 @@ function poco_init(App $a) { } $entry = array(); - if($fields_ret['id']) + if ($fields_ret['id']) { $entry['id'] = (int)$rr['id']; - if($fields_ret['displayName']) - $entry['displayName'] = $rr['name']; - if($fields_ret['aboutMe']) - $entry['aboutMe'] = $about; - if($fields_ret['currentLocation']) - $entry['currentLocation'] = $rr['location']; - if($fields_ret['gender']) - $entry['gender'] = $rr['gender']; - if($fields_ret['generation']) - $entry['generation'] = (int)$rr['generation']; - if($fields_ret['urls']) { - $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile')); - if($rr['addr'] && ($rr['network'] !== NETWORK_MAIL)) - $entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger'); } - if($fields_ret['preferredUsername']) + if ($fields_ret['displayName']) { + $entry['displayName'] = $rr['name']; + } + if ($fields_ret['aboutMe']) { + $entry['aboutMe'] = $about; + } + if ($fields_ret['currentLocation']) { + $entry['currentLocation'] = $rr['location']; + } + if ($fields_ret['gender']) { + $entry['gender'] = $rr['gender']; + } + if ($fields_ret['generation']) { + $entry['generation'] = (int)$rr['generation']; + } + if ($fields_ret['urls']) { + $entry['urls'] = array(array('value' => $rr['url'], 'type' => 'profile')); + if ($rr['addr'] && ($rr['network'] !== NETWORK_MAIL)) { + $entry['urls'][] = array('value' => 'acct:' . $rr['addr'], 'type' => 'webfinger'); + } + } + if ($fields_ret['preferredUsername']) { $entry['preferredUsername'] = $rr['nick']; - if($fields_ret['updated']) { + } + if ($fields_ret['updated']) { if (!$global) { $entry['updated'] = $rr['success_update']; - if ($rr['name-date'] > $entry['updated']) + if ($rr['name-date'] > $entry['updated']) { $entry['updated'] = $rr['name-date']; - - if ($rr['uri-date'] > $entry['updated']) + } + if ($rr['uri-date'] > $entry['updated']) { $entry['updated'] = $rr['uri-date']; - - if ($rr['avatar-date'] > $entry['updated']) + } + if ($rr['avatar-date'] > $entry['updated']) { $entry['updated'] = $rr['avatar-date']; - } else + } + } else { $entry['updated'] = $rr['updated']; - + } $entry['updated'] = date("c", strtotime($entry['updated'])); } - if($fields_ret['photos']) + if ($fields_ret['photos']) { $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile')); - if($fields_ret['network']) { - $entry['network'] = $rr['network']; - if ($entry['network'] == NETWORK_STATUSNET) - $entry['network'] = NETWORK_OSTATUS; - if (($entry['network'] == "") AND ($rr['self'])) - $entry['network'] = NETWORK_DFRN; } - if($fields_ret['tags']) { + if ($fields_ret['network']) { + $entry['network'] = $rr['network']; + if ($entry['network'] == NETWORK_STATUSNET) { + $entry['network'] = NETWORK_OSTATUS; + } + if (($entry['network'] == "") AND ($rr['self'])) { + $entry['network'] = NETWORK_DFRN; + } + } + if ($fields_ret['tags']) { $tags = str_replace(","," ",$rr['keywords']); $tags = explode(" ", $tags); $cleaned = array(); foreach ($tags as $tag) { $tag = trim(strtolower($tag)); - if ($tag != "") + if ($tag != "") { $cleaned[] = $tag; + } } $entry['tags'] = array($cleaned); } - if($fields_ret['address']) { + if ($fields_ret['address']) { $entry['address'] = array(); // Deactivated. It just reveals too much data. (Although its from the default profile) //if (isset($rr['paddress'])) // $entry['address']['streetAddress'] = $rr['paddress']; - if (isset($rr['plocation'])) + if (isset($rr['plocation'])) { $entry['address']['locality'] = $rr['plocation']; - - if (isset($rr['pregion'])) + } + if (isset($rr['pregion'])) { $entry['address']['region'] = $rr['pregion']; - + } // See above //if (isset($rr['ppostalcode'])) // $entry['address']['postalCode'] = $rr['ppostalcode']; - if (isset($rr['pcountry'])) + if (isset($rr['pcountry'])) { $entry['address']['country'] = $rr['pcountry']; + } } - if($fields_ret['contactType']) + if ($fields_ret['contactType']) { $entry['contactType'] = intval($rr['contact-type']); - + } $ret['entry'][] = $entry; } - } - else + } else { $ret['entry'][] = array(); - } - else + } + } else { http_status_exit(500); - + } logger("End of poco", LOGGER_DEBUG); - if($format === 'xml') { + if ($format === 'xml') { header('Content-type: text/xml'); echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify(array('$response' => $ret))); killme(); } - if($format === 'json') { + if ($format === 'json') { header('Content-type: application/json'); echo json_encode($ret); killme(); - } - else + } else { http_status_exit(500); - - + } } diff --git a/mod/profile.php b/mod/profile.php index d2864d838..fbce509d2 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -251,23 +251,6 @@ function profile_content(App $a, $update = 0) { $sql_extra3 = sprintf(" AND `thread`.`contact-id` = %d ", intval(intval($a->profile['contact_id']))); } - if(get_config('system', 'old_pager')) { - $r = q("SELECT COUNT(*) AS `total` - FROM `thread` INNER JOIN `item` ON `item`.`id` = `thread`.`iid` - $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - WHERE `thread`.`uid` = %d AND `thread`.`visible` = 1 AND `thread`.`deleted` = 0 - and `thread`.`moderated` = 0 - AND `thread`.`wall` = 1 - $sql_extra3 $sql_extra $sql_extra2 ", - intval($a->profile['profile_uid']) - ); - - if (dbm::is_result($r)) { - $a->set_pager_total($r[0]['total']); - } - } - // check if we serve a mobile device and get the user settings // accordingly if ($a->is_mobile) { @@ -335,14 +318,10 @@ function profile_content(App $a, $update = 0) { ); } - $o .= conversation($a,$items,'profile',$update); + $o .= conversation($a, $items, 'profile', $update); - if(! $update) { - if(!get_config('system', 'old_pager')) { - $o .= alt_pager($a,count($items)); - } else { - $o .= paginate($a); - } + if (!$update) { + $o .= alt_pager($a, count($items)); } return $o; diff --git a/mod/share.php b/mod/share.php index 928ccdef2..36a4d5945 100644 --- a/mod/share.php +++ b/mod/share.php @@ -15,28 +15,18 @@ function share_init(App $a) { if(! dbm::is_result($r) || ($r[0]['private'] == 1)) killme(); - if (!intval(get_config('system','old_share'))) { - if (strpos($r[0]['body'], "[/share]") !== false) { - $pos = strpos($r[0]['body'], "[share"); - $o = substr($r[0]['body'], $pos); - } else { - $o = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']); - - if($r[0]['title']) - $o .= '[b]'.$r[0]['title'].'[/b]'."\n"; - $o .= $r[0]['body']; - $o.= "[/share]"; - } + if (strpos($r[0]['body'], "[/share]") !== false) { + $pos = strpos($r[0]['body'], "[share"); + $o = substr($r[0]['body'], $pos); } else { - $o = ''; + $o = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']); - $o .= "\xE2\x99\xb2" . ' [url=' . $r[0]['author-link'] . ']' . $r[0]['author-name'] . '[/url]' . "\n"; if($r[0]['title']) - $o .= '[b]' . $r[0]['title'] . '[/b]' . "\n"; - $o .= $r[0]['body'] . "\n" ; - - $o .= (($r[0]['plink']) ? '[url=' . $r[0]['plink'] . ']' . t('link') . '[/url]' . "\n" : ''); + $o .= '[b]'.$r[0]['title'].'[/b]'."\n"; + $o .= $r[0]['body']; + $o.= "[/share]"; } + echo $o; killme(); } diff --git a/mod/worker.php b/mod/worker.php index c202a28d6..4949b830f 100644 --- a/mod/worker.php +++ b/mod/worker.php @@ -10,7 +10,7 @@ use \Friendica\Core\PConfig; function worker_init($a){ - if (!Config::get("system", "frontend_worker") OR !Config::get("system", "worker")) { + if (!Config::get("system", "frontend_worker")) { return; } diff --git a/object/Item.php b/object/Item.php index d95af3419..b693520b9 100644 --- a/object/Item.php +++ b/object/Item.php @@ -287,32 +287,6 @@ class Item extends BaseObject { localize_item($item); - if ($item["postopts"] and !get_config("system", "suppress_language")) { - //$langdata = explode(";", $item["postopts"]); - //$langstr = substr($langdata[0], 5)." (".round($langdata[1]*100, 1)."%)"; - $langstr = ""; - if (substr($item["postopts"], 0, 5) == "lang=") { - $postopts = substr($item["postopts"], 5); - - $languages = explode(":", $postopts); - - if (sizeof($languages) == 1) { - $languages = array(); - $languages[] = $postopts; - } - - foreach ($languages as $language) { - $langdata = explode(";", $language); - if ($langstr != "") { - $langstr .= ", "; - } - - //$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)"; - $langstr .= round($langdata[1]*100, 1)."% ".$langdata[0]; - } - } - } - $body = prepare_body($item,true); list($categories, $folders) = get_cats_and_terms($item); @@ -420,7 +394,6 @@ class Item extends BaseObject { 'previewing' => ($conv->is_preview() ? ' preview ' : ''), 'wait' => t('Please wait'), 'thread_level' => $thread_level, - 'postopts' => $langstr, 'edited' => $edited, 'network' => $item["item_network"], 'network_name' => network_to_name($item['item_network'], $profile_link), diff --git a/view/templates/admin_site.tpl b/view/templates/admin_site.tpl index 2edfddb88..fdba195f1 100644 --- a/view/templates/admin_site.tpl +++ b/view/templates/admin_site.tpl @@ -56,7 +56,6 @@ {{include file="field_select.tpl" field=$theme_mobile}} {{include file="field_select.tpl" field=$ssl_policy}} {{if $ssl_policy.2 == 1}}{{include file="field_checkbox.tpl" field=$force_ssl}}{{/if}} - {{include file="field_checkbox.tpl" field=$old_share}} {{include file="field_checkbox.tpl" field=$hide_help}} {{include file="field_select.tpl" field=$singleuser}}
@@ -120,19 +119,13 @@ {{include file="field_input.tpl" field=$proxy}} {{include file="field_input.tpl" field=$proxyuser}} {{include file="field_input.tpl" field=$timeout}} - {{if NOT $worker.2}} - {{include file="field_input.tpl" field=$delivery_interval}} - {{include file="field_input.tpl" field=$poll_interval}} - {{/if}} {{include file="field_input.tpl" field=$maxloadavg}} {{include file="field_input.tpl" field=$maxloadavg_frontend}} {{include file="field_input.tpl" field=$optimize_max_tablesize}} {{include file="field_input.tpl" field=$optimize_fragmentation}} {{include file="field_input.tpl" field=$abandon_days}} - {{include file="field_input.tpl" field=$lockpath}} {{include file="field_input.tpl" field=$temppath}} {{include file="field_input.tpl" field=$basepath}} - {{include file="field_checkbox.tpl" field=$suppress_language}} {{include file="field_checkbox.tpl" field=$suppress_tags}} {{include file="field_checkbox.tpl" field=$nodeinfo}} {{include file="field_input.tpl" field=$embedly}} @@ -153,17 +146,13 @@ {{include file="field_input.tpl" field=$itemcache_duration}} {{include file="field_input.tpl" field=$max_comments}} {{include file="field_checkbox.tpl" field=$proxy_disabled}} - {{include file="field_checkbox.tpl" field=$old_pager}}

{{$worker_title}}

- {{include file="field_checkbox.tpl" field=$worker}} - {{if $worker.2}} - {{include file="field_input.tpl" field=$worker_queues}} - {{include file="field_checkbox.tpl" field=$worker_dont_fork}} - {{include file="field_checkbox.tpl" field=$worker_fastlane}} - {{include file="field_checkbox.tpl" field=$worker_frontend}} - {{/if}} + {{include file="field_input.tpl" field=$worker_queues}} + {{include file="field_checkbox.tpl" field=$worker_dont_fork}} + {{include file="field_checkbox.tpl" field=$worker_fastlane}} + {{include file="field_checkbox.tpl" field=$worker_frontend}}
diff --git a/view/templates/admin_summary.tpl b/view/templates/admin_summary.tpl index c8e8af229..a8243b614 100644 --- a/view/templates/admin_summary.tpl +++ b/view/templates/admin_summary.tpl @@ -11,7 +11,7 @@
{{$queues.label}}
-
{{$queues.deliverq}} - {{$queues.queue}}{{if $workeractive}} - {{$queues.workerq}}{{/if}}
+
{{$queues.deliverq}} - {{$queues.queue}} - {{$queues.workerq}}
{{$pending.0}}
diff --git a/view/templates/paginate.tpl b/view/templates/paginate.tpl index 21d56509a..fcd580b07 100644 --- a/view/templates/paginate.tpl +++ b/view/templates/paginate.tpl @@ -2,7 +2,7 @@ {{if $pager}} {{if $pager.prev}}{{$pager.prev.text}}{{/if}} - {{if $pager.first}}{{$pager.first.text}}{{/if}} + {{if $pager.first}}{{$pager.first.text}}{{/if}} {{foreach $pager.pages as $p}}{{$p.text}}{{/foreach}} diff --git a/view/theme/duepuntozero/style.css b/view/theme/duepuntozero/style.css index c1e806744..8e2c5d447 100644 --- a/view/theme/duepuntozero/style.css +++ b/view/theme/duepuntozero/style.css @@ -1552,6 +1552,9 @@ blockquote.shared_content { clear:left; } +.pager .disabled { + display: none; +} .pager_first, .pager_last, diff --git a/view/theme/frio/css/style.css b/view/theme/frio/css/style.css index df9585d07..8d7a5f769 100644 --- a/view/theme/frio/css/style.css +++ b/view/theme/frio/css/style.css @@ -2508,6 +2508,56 @@ body .tread-wrapper .hovercard:hover .hover-card-content a { color: $link_color !important; } +/* Pagination improvements */ +.pagination { + text-align: center; + display: block; +} +.pagination > li > a, +.pagination > li > span { + color: $link_color; + float: none; +} +.pagination>li>a:hover, +.pagination>li>span:hover { + color: $link_hover_color; +} +.pagination > .active > a, +.pagination > .active > a:focus, +.pagination > .active > a:hover, +.pagination > .active > span, +.pagination > .active > span:focus, +.pagination > .active > span:hover { + background-color: $link_color; + border-color: $link_color; + border-radius: 3px; +} +.pagination li.pager_n a { + margin-left: 3px; + border-radius: 3px; +} +.pagination .pager_prev a { + margin-left: -5px; + margin-right: 4px; + border-top-right-radius: 3px; + border-bottom-right-radius: 3px; +} +.pagination .pager_next a { + margin-left: 4px; + margin-right: -5px; + border-top-left-radius: 3px; + border-bottom-left-radius: 3px; +} +.pager .next > a, +.pager .previous > a { + float: none; + border-radius: 3px; +} +.pagination .disabled > a, +.pager .disabled > a { + display: none; +} + /* * some temporary workarounds until this will solved * elsewhere (e.g. new templates) diff --git a/view/theme/frio/js/textedit.js b/view/theme/frio/js/textedit.js index 9226646b7..d212ee003 100644 --- a/view/theme/frio/js/textedit.js +++ b/view/theme/frio/js/textedit.js @@ -162,21 +162,29 @@ function qCommentInsert(obj,id) { function confirmDelete() { return confirm(aStr.delitem); } -function dropItem(url, object) { +/** + * Hide and removes an item element from the DOM after the deletion url is + * successful, restore it else. + * + * @param {string} url The item removal URL + * @param {string} elementId The DOM id of the item element + * @returns {undefined} + */ +function dropItem(url, elementId) { var confirm = confirmDelete(); - //if the first character of the object is #, remove it because - // we use getElementById which don't need the # - // getElementByID selects elements even if there are special characters - // in the ID (like %) which won't work with jQuery - /// @todo ceck if we can solve this in the template - object = object.indexOf('#') == 0 ? object.substring(1) : object; - - if(confirm) { + if (confirm) { $('body').css('cursor', 'wait'); - $(document.getElementById(object)).fadeTo('fast', 0.33, function () { - $.get(url).done(function() { - $(document.getElementById(object)).remove(); + + var $el = $(document.getElementById(elementId)); + + $el.fadeTo('fast', 0.33, function () { + $.get(url).then(function() { + $el.remove(); + }).fail(function() { + // @todo Show related error message + $el.show(); + }).always(function() { $('body').css('cursor', 'auto'); }); }); diff --git a/view/theme/frio/js/theme.js b/view/theme/frio/js/theme.js index b4ba2fd35..62cd85df9 100644 --- a/view/theme/frio/js/theme.js +++ b/view/theme/frio/js/theme.js @@ -573,31 +573,38 @@ String.prototype.rtrim = function() { return trimmed; }; -// Scroll to a specific item and highlight it -// Note: jquery.color.js is needed -function scrollToItem(itemID) { - if( typeof itemID === "undefined") +/** + * Scroll the screen to the item element whose id is provided, then highlights it + * + * Note: jquery.color.js is required + * + * @param {string} elementId The item element id + * @returns {undefined} + */ +function scrollToItem(elementId) { + if (typeof elementId === "undefined") { return; + } - var elm = $('#'+itemID); + var $el = $(document.getElementById(elementId)); // Test if the Item exists - if(!elm.length) + if (!$el.length) { return; + } // Define the colors which are used for highlighting var colWhite = {backgroundColor:'#F5F5F5'}; var colShiny = {backgroundColor:'#FFF176'}; - // Get the Item Position (we need to substract 100 to match - // correct position - var itemPos = $(elm).offset().top - 100; + // Get the Item Position (we need to substract 100 to match correct position + var itemPos = $el.offset().top - 100; // Scroll to the DIV with the ID (GUID) $('html, body').animate({ scrollTop: itemPos }, 400, function() { // Highlight post/commenent with ID (GUID) - $(elm).animate(colWhite, 1000).animate(colShiny).animate(colWhite, 600); + $el.animate(colWhite, 1000).animate(colShiny).animate(colWhite, 600); }); } diff --git a/view/theme/frio/php/Colors.php b/view/theme/frio/php/Colors.php deleted file mode 100644 index d6ba15fbc..000000000 --- a/view/theme/frio/php/Colors.php +++ /dev/null @@ -1,292 +0,0 @@ - 1) - $opacity = 1.0; - $output = 'rgba('.implode(",",$rgb).','.$opacity.')'; - } else { - $output = 'rgb('.implode(",",$rgb).')'; - } - - //Return rgb(a) color string - return $output; - } - - function hex2rgb( $colour ) { - if ( $colour[0] == '#' ) { - $colour = substr( $colour, 1 ); - } - if ( strlen( $colour ) == 6 ) { - list( $r, $g, $b ) = array( $colour[0] . $colour[1], $colour[2] . $colour[3], $colour[4] . $colour[5] ); - } elseif ( strlen( $colour ) == 3 ) { - list( $r, $g, $b ) = array( $colour[0] . $colour[0], $colour[1] . $colour[1], $colour[2] . $colour[2] ); - } else { - return false; - } - $r = hexdec( $r ); - $g = hexdec( $g ); - $b = hexdec( $b ); - return array( 'red' => $r, 'green' => $g, 'blue' => $b ); - } - - - function rgbToHsl( $r, $g, $b ) { - $oldR = $r; - $oldG = $g; - $oldB = $b; - $r /= 255; - $g /= 255; - $b /= 255; - $max = max( $r, $g, $b ); - $min = min( $r, $g, $b ); - $h; - $s; - $l = ( $max + $min ) / 2; - $d = $max - $min; - - if( $d == 0 ){ - $h = $s = 0; // achromatic - } else { - $s = $d / ( 1 - abs( 2 * $l - 1 ) ); - switch( $max ){ - case $r: - $h = 60 * fmod( ( ( $g - $b ) / $d ), 6 ); - if ($b > $g) { - $h += 360; - } - break; - case $g: - $h = 60 * ( ( $b - $r ) / $d + 2 ); - break; - case $b: - $h = 60 * ( ( $r - $g ) / $d + 4 ); - break; - } - } - - return array( round( $h, 2 ), round( $s, 2 ), round( $l, 2 ) ); - } - function hslToRgb( $h, $s, $l ){ - $r = ""; - $g = ""; - $b = ""; - - $c = ( 1 - abs( 2 * $l - 1 ) ) * $s; - $x = $c * ( 1 - abs( fmod( ( $h / 60 ), 2 ) - 1 ) ); - $m = $l - ( $c / 2 ); - if ( $h < 60 ) { - $r = $c; - $g = $x; - $b = 0; - } else if ( $h < 120 ) { - $r = $x; - $g = $c; - $b = 0; - } else if ( $h < 180 ) { - $r = 0; - $g = $c; - $b = $x; - } else if ( $h < 240 ) { - $r = 0; - $g = $x; - $b = $c; - } else if ( $h < 300 ) { - $r = $x; - $g = 0; - $b = $c; - } else { - $r = $c; - $g = 0; - $b = $x; - } - - $r = ( $r + $m ) * 255; - $g = ( $g + $m ) * 255; - $b = ( $b + $m ) * 255; - - return array( floor( $r ), floor( $g ), floor( $b ) ); - } - - /* - * Som more example code - this needs to be deletet if we don't need it in - * the future - */ - - function HTMLToRGB($htmlCode) - { - if($htmlCode[0] == '#') - $htmlCode = substr($htmlCode, 1); - - if (strlen($htmlCode) == 3) - { - $htmlCode = $htmlCode[0] . $htmlCode[0] . $htmlCode[1] . $htmlCode[1] . $htmlCode[2] . $htmlCode[2]; - } - - $r = hexdec($htmlCode[0] . $htmlCode[1]); - $g = hexdec($htmlCode[2] . $htmlCode[3]); - $b = hexdec($htmlCode[4] . $htmlCode[5]); - - return $b + ($g << 0x8) + ($r << 0x10); - } - - function RGBToHTML($RGB) - { - $r = 0xFF & ($RGB >> 0x10); - $g = 0xFF & ($RGB >> 0x8); - $b = 0xFF & $RGB; - - $r = dechex($r); - $g = dechex($g); - $b = dechex($b); - - return "#" . str_pad($r, 2, "0", STR_PAD_LEFT) . str_pad($g, 2, "0", STR_PAD_LEFT) . str_pad($b, 2, "0", STR_PAD_LEFT); - } - - function ChangeLuminosity($RGB, $LuminosityPercent) - { - $HSL = RGBToHSL($RGB); - $NewHSL = (int)(((float)$LuminosityPercent / 100) * 255) + (0xFFFF00 & $HSL); - return HSLToRGB($NewHSL); - } - - function RGBToHSL($RGB) - { - $r = 0xFF & ($RGB >> 0x10); - $g = 0xFF & ($RGB >> 0x8); - $b = 0xFF & $RGB; - - $r = ((float)$r) / 255.0; - $g = ((float)$g) / 255.0; - $b = ((float)$b) / 255.0; - - $maxC = max($r, $g, $b); - $minC = min($r, $g, $b); - - $l = ($maxC + $minC) / 2.0; - - if($maxC == $minC) - { - $s = 0; - $h = 0; - } - else - { - if($l < .5) - { - $s = ($maxC - $minC) / ($maxC + $minC); - } - else - { - $s = ($maxC - $minC) / (2.0 - $maxC - $minC); - } - if($r == $maxC) - $h = ($g - $b) / ($maxC - $minC); - if($g == $maxC) - $h = 2.0 + ($b - $r) / ($maxC - $minC); - if($b == $maxC) - $h = 4.0 + ($r - $g) / ($maxC - $minC); - - $h = $h / 6.0; - } - - $h = (int)round(255.0 * $h); - $s = (int)round(255.0 * $s); - $l = (int)round(255.0 * $l); - - $HSL = $l + ($s << 0x8) + ($h << 0x10); - return $HSL; - } - - function HSLToRGB($HSL) - { - $h = 0xFF & ($HSL >> 0x10); - $s = 0xFF & ($HSL >> 0x8); - $l = 0xFF & $HSL; - - $h = ((float)$h) / 255.0; - $s = ((float)$s) / 255.0; - $l = ((float)$l) / 255.0; - - if($s == 0) - { - $r = $l; - $g = $l; - $b = $l; - } - else - { - if($l < .5) - { - $t2 = $l * (1.0 + $s); - } - else - { - $t2 = ($l + $s) - ($l * $s); - } - $t1 = 2.0 * $l - $t2; - - $rt3 = $h + 1.0/3.0; - $gt3 = $h; - $bt3 = $h - 1.0/3.0; - - if($rt3 < 0) $rt3 += 1.0; - if($rt3 > 1) $rt3 -= 1.0; - if($gt3 < 0) $gt3 += 1.0; - if($gt3 > 1) $gt3 -= 1.0; - if($bt3 < 0) $bt3 += 1.0; - if($bt3 > 1) $bt3 -= 1.0; - - if(6.0 * $rt3 < 1) $r = $t1 + ($t2 - $t1) * 6.0 * $rt3; - elseif(2.0 * $rt3 < 1) $r = $t2; - elseif(3.0 * $rt3 < 2) $r = $t1 + ($t2 - $t1) * ((2.0/3.0) - $rt3) * 6.0; - else $r = $t1; - - if(6.0 * $gt3 < 1) $g = $t1 + ($t2 - $t1) * 6.0 * $gt3; - elseif(2.0 * $gt3 < 1) $g = $t2; - elseif(3.0 * $gt3 < 2) $g = $t1 + ($t2 - $t1) * ((2.0/3.0) - $gt3) * 6.0; - else $g = $t1; - - if(6.0 * $bt3 < 1) $b = $t1 + ($t2 - $t1) * 6.0 * $bt3; - elseif(2.0 * $bt3 < 1) $b = $t2; - elseif(3.0 * $bt3 < 2) $b = $t1 + ($t2 - $t1) * ((2.0/3.0) - $bt3) * 6.0; - else $b = $t1; - } - - $r = (int)round(255.0 * $r); - $g = (int)round(255.0 * $g); - $b = (int)round(255.0 * $b); - - $RGB = $b + ($g << 0x8) + ($r << 0x10); - return $RGB; - } -} \ No newline at end of file diff --git a/view/theme/frio/templates/paginate.tpl b/view/theme/frio/templates/paginate.tpl new file mode 100644 index 000000000..252dd7e5b --- /dev/null +++ b/view/theme/frio/templates/paginate.tpl @@ -0,0 +1,16 @@ + +{{* Pager template, uses output of paginate_data() in include/text.php *}} + +{{if $pager}} +
    + {{if $pager.first}}
  • ∣<
  • {{/if}} + + {{if $pager.prev}}
  • <
  • {{/if}} + + {{foreach $pager.pages as $p}}{{/foreach}} + + {{if $pager.next}}
  • >
  • {{/if}} + + {{if $pager.last}}
  • >∣
  • {{/if}} +
+{{/if}} diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index 90fbe03bb..0a6eca0c2 100644 --- a/view/theme/frio/templates/search_item.tpl +++ b/view/theme/frio/templates/search_item.tpl @@ -7,7 +7,7 @@ -
+
{{* Put additional actions in a top-right dropdown menu *}} @@ -54,7 +54,7 @@ {{if $item.drop.dropping}}
  • - {{$item.drop.delete}} + {{$item.drop.delete}}
  • {{/if}} diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index 1977f541c..85091cf1c 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -68,9 +68,9 @@ as the value of $top_child_total (this is done at the end of this file) {{* Use a different div container in dependence max thread-level = 7 *}} {{if $item.thread_level<7}} -
    +
    {{else}} -
    +
    {{/if}}
    {{* Put addional actions in a top-right dropdown menu *}} @@ -129,7 +129,7 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.drop.dropping}}
  • - {{$item.drop.delete}} + {{$item.drop.delete}}
  • {{/if}} diff --git a/view/theme/frost-mobile/style.css b/view/theme/frost-mobile/style.css index c005e838f..7c5d2c760 100644 --- a/view/theme/frost-mobile/style.css +++ b/view/theme/frost-mobile/style.css @@ -1909,6 +1909,9 @@ input#profile-jot-email { -webkit-border-radius: 10px; } +.pager .disabled { + display: none; +} .pager_first, .pager_last, diff --git a/view/theme/frost/style.css b/view/theme/frost/style.css index 46eb650ec..9b65da9c8 100644 --- a/view/theme/frost/style.css +++ b/view/theme/frost/style.css @@ -1866,6 +1866,9 @@ input#dfrn-url { -webkit-border-radius: 10px; } +.pager .disabled { + display: none; +} .pager_first, .pager_last, diff --git a/view/theme/quattro/green/style.css b/view/theme/quattro/green/style.css index 8eba0e4cf..af5cfcedf 100644 --- a/view/theme/quattro/green/style.css +++ b/view/theme/quattro/green/style.css @@ -2481,6 +2481,9 @@ footer { margin-top: 25px; clear: both; } +.pager .disabled { + display: none; +} /** * ADMIN */ diff --git a/view/theme/quattro/lilac/style.css b/view/theme/quattro/lilac/style.css index b42453420..0c17b0033 100644 --- a/view/theme/quattro/lilac/style.css +++ b/view/theme/quattro/lilac/style.css @@ -2481,6 +2481,9 @@ footer { margin-top: 25px; clear: both; } +.pager .disabled { + display: none; +} /** * ADMIN */ diff --git a/view/theme/quattro/quattro.less b/view/theme/quattro/quattro.less index 6c0198688..53bb7e38a 100644 --- a/view/theme/quattro/quattro.less +++ b/view/theme/quattro/quattro.less @@ -1675,6 +1675,9 @@ footer { height: 100px; display: table-row; } margin-top: 25px; clear: both; } +.pager .disabled { + display: none; +} /** * ADMIN diff --git a/view/theme/smoothly/style.css b/view/theme/smoothly/style.css index e91eccfe1..ec52277bd 100644 --- a/view/theme/smoothly/style.css +++ b/view/theme/smoothly/style.css @@ -396,6 +396,10 @@ ul.menu-popup li a:hover { margin: 4px; } +.pager .disabled { + display: none; +} + .pager_current { background-color: #1873a2; color: #ffffff; diff --git a/view/theme/vier/style.css b/view/theme/vier/style.css index 8454c7e0a..32617867c 100644 --- a/view/theme/vier/style.css +++ b/view/theme/vier/style.css @@ -247,6 +247,10 @@ div.pager { float: left; } +.pager .disabled { + display: none; +} + .hide-comments-outer { margin-left: 80px; margin-bottom: 5px;