From 2a8a5a6d880e087df3127b5fe36f6090a489b5a6 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Feb 2017 18:19:20 +0000 Subject: [PATCH 01/60] Improved server vitality detection --- include/socgraph.php | 80 +++++++++++++++++++++++++++++++++++++++++--- mod/admin.php | 6 ++-- 2 files changed, 79 insertions(+), 7 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index a0dd88df2d..ff9467748f 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -680,6 +680,43 @@ function poco_to_boolean($val) { return ($val); } +function poco_detect_friendica_server($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) { + 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 +766,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. $server_url = str_replace("http://", "https://", $server_url); @@ -750,6 +789,7 @@ 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(); @@ -757,11 +797,12 @@ function poco_check_server($server_url, $network = "", $force = false) { // Test for Diaspora $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 { $lines = explode("\n",$serverret["header"]); - if(count($lines)) + if(count($lines)) { foreach($lines as $line) { $line = trim($line); if(stristr($line,'X-Diaspora-Version:')) { @@ -771,6 +812,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')) { @@ -778,8 +820,19 @@ function poco_check_server($server_url, $network = "", $force = false) { $network = NETWORK_OSTATUS; // Mastodon doesn't reveal version numbers $version = ""; + $last_contact = datetime_convert(); } } + } + + $friendica_server = poco_detect_friendica_server($serverret["body"]); + if ($friendica_server) { + $platform = $friendica_server['platform']; + $network = $friendica_server['network']; + $version = $friendica_server['version']; + $site_name = $friendica_server['site_name']; + $last_contact = datetime_convert(); + } } } @@ -793,6 +846,7 @@ function poco_check_server($server_url, $network = "", $force = false) { $platform = "StatusNet"; $version = trim($serverret["body"], '"'); $network = NETWORK_OSTATUS; + $last_contact = datetime_convert(); } // Test for GNU Social @@ -802,12 +856,12 @@ function poco_check_server($server_url, $network = "", $force = false) { $platform = "GNU Social"; $version = trim($serverret["body"], '"'); $network = NETWORK_OSTATUS; + $last_contact = datetime_convert(); } $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(); @@ -847,6 +901,7 @@ 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"); @@ -922,6 +977,23 @@ function poco_check_server($server_url, $network = "", $force = false) { } } + 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 $servers = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", dbesc(normalise_link($server_url))); diff --git a/mod/admin.php b/mod/admin.php index 1475130834..fffc8bf818 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -270,8 +270,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 @@ -333,7 +333,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) { From 48209f0ecd1e61cabfbf1eb5454197974807e441 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Feb 2017 23:16:49 +0000 Subject: [PATCH 02/60] Now there is only the worker. --- include/create_shadowentry.php | 22 -------- include/cron.php | 89 +++--------------------------- include/cronhooks.php | 38 +------------ include/cronjobs.php | 37 +------------ include/dbclean.php | 35 ++---------- include/dbupdate.php | 22 +------- include/delivery.php | 26 +-------- include/directory.php | 37 ++----------- include/discover_poco.php | 41 +------------- include/expire.php | 26 +-------- include/gprobe.php | 29 +--------- include/notifier.php | 74 +------------------------ include/onepoll.php | 31 +---------- include/poller.php | 8 ++- include/pubsubpublish.php | 94 ++++++++------------------------ include/queue.php | 60 ++++---------------- include/remove_contact.php | 22 -------- include/shadowupdate.php | 32 ++++++----- include/spool_post.php | 21 +------ include/tagupdate.php | 22 +------- include/threadupdate.php | 24 +------- include/update_gcontact.php | 31 +---------- mod/worker.php | 2 +- view/templates/admin_site.tpl | 15 ++--- view/templates/admin_summary.tpl | 2 +- 25 files changed, 103 insertions(+), 737 deletions(-) diff --git a/include/create_shadowentry.php b/include/create_shadowentry.php index 005295c978..98db23f9ef 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 2fc8de51c5..d2471c2bf7 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 @@ -213,14 +158,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 +272,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 +422,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 72b86be427..af5ab9f922 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]) { @@ -62,13 +36,12 @@ 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'); @@ -76,8 +49,3 @@ function cronhooks_run(&$argv, &$argc){ 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 f0a56370b8..5cc2bf1323 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/dbclean.php b/include/dbclean.php index 8408ad1882..bff4ff2a24 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/dbupdate.php b/include/dbupdate.php index 14709208fa..21528c5730 100644 --- a/include/dbupdate.php +++ b/include/dbupdate.php @@ -2,23 +2,8 @@ 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. @@ -26,8 +11,3 @@ function dbupdate_run(&$argv, &$argc) { 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 5000a1edb9..45ca68cf37 100644 --- a/include/delivery.php +++ b/include/delivery.php @@ -2,7 +2,6 @@ use \Friendica\Core\Config; -require_once("boot.php"); require_once('include/queue_fn.php'); require_once('include/html2plain.php'); require_once("include/Scrape.php"); @@ -11,35 +10,17 @@ 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/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]; @@ -577,8 +558,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 2ca367d369..057c156ad7 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 8146368784..6308a982af 100644 --- a/include/discover_poco.php +++ b/include/discover_poco.php @@ -2,34 +2,12 @@ use \Friendica\Core\Config; -require_once("boot.php"); require_once("include/socgraph.php"); +require_once('include/datetime.php'); function discover_poco_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(); - - // 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")) { @@ -42,15 +20,6 @@ function discover_poco_run(&$argv, &$argc){ } 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) @@ -207,9 +176,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 855d7fb5e4..35b109a50a 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/gprobe.php b/include/gprobe.php index 4407fa6d6c..2f1758f377 100644 --- a/include/gprobe.php +++ b/include/gprobe.php @@ -2,33 +2,11 @@ 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) return; @@ -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/notifier.php b/include/notifier.php index 24830a11ab..c05d00e63f 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -2,7 +2,6 @@ use \Friendica\Core\Config; -require_once("boot.php"); require_once('include/queue_fn.php'); require_once('include/html2plain.php'); require_once("include/Scrape.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/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]; @@ -495,12 +476,6 @@ function notifier_run(&$argv, &$argc){ ); } - $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)) { @@ -517,26 +492,6 @@ function notifier_run(&$argv, &$argc){ } } - - // 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]; @@ -545,25 +500,9 @@ function notifier_run(&$argv, &$argc){ } 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); - } - } + proc_run(PRIORITY_HIGH,'include/delivery.php', $cmd, $item_id, $contact['id']); continue; } - - // be sure to pick up any stragglers - if (count($this_batch)) { - proc_run(PRIORITY_HIGH,'include/delivery.php',$cmd,$item_id,$this_batch); - } } // send salmon slaps to mentioned remote tags (@foo@example.com) in OStatus posts @@ -639,9 +578,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 +630,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 5219d9f3bd..9e156751b9 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -2,7 +2,6 @@ use \Friendica\Core\Config; -require_once("boot.php"); require_once("include/follow.php"); function RemoveReply($subject) { @@ -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; @@ -59,11 +40,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, @@ -670,8 +646,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 8be4c1835c..0629735163 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()) { @@ -561,7 +565,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; } @@ -573,7 +577,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; } diff --git a/include/pubsubpublish.php b/include/pubsubpublish.php index 428103a971..f88ca98a49 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 bcd32985db..6bbfdaae81 100644 --- a/include/queue.php +++ b/include/queue.php @@ -1,41 +1,18 @@ set_baseurl(get_config('system','url')); - - load_hooks(); + global $a; if($argc > 1) $queue_id = intval($argv[1]); @@ -53,20 +30,11 @@ 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); - } } } @@ -111,16 +79,14 @@ function queue_run(&$argv, &$argc){ // queue_predeliver hooks may have changed the queue db details, // so check again if this entry still needs processing - if($queue_id) + if ($queue_id) { $qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1", intval($queue_id)); - elseif (get_config("system", "worker")) { + } else { 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'])); + } if(! count($qi)) continue; @@ -225,10 +191,4 @@ function queue_run(&$argv, &$argc){ } 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 aa20621116..68bf2adfea 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/shadowupdate.php b/include/shadowupdate.php index 83a785fe1f..5b0a1b94b0 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/spool_post.php b/include/spool_post.php index b4cce46b57..f64b39e4b6 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 b4de121e9f..1e97135c5b 100644 --- a/include/tagupdate.php +++ b/include/tagupdate.php @@ -1,24 +1,6 @@ diff --git a/include/threadupdate.php b/include/threadupdate.php index dc528c6b87..3a4028603e 100644 --- a/include/threadupdate.php +++ b/include/threadupdate.php @@ -1,25 +1,7 @@ diff --git a/include/update_gcontact.php b/include/update_gcontact.php index 6aa8bcac29..f59f487653 100644 --- a/include/update_gcontact.php +++ b/include/update_gcontact.php @@ -2,31 +2,12 @@ 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(); - logger('update_gcontact: start'); if(($argc > 1) && (intval($argv[1]))) @@ -37,11 +18,6 @@ function update_gcontact_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('update_gcontact'.$contact_id, '', 540)) - return; - $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id)); if (!$r) @@ -98,8 +74,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/worker.php b/mod/worker.php index c202a28d64..4949b830f4 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/view/templates/admin_site.tpl b/view/templates/admin_site.tpl index 2edfddb885..df50c0fb48 100644 --- a/view/templates/admin_site.tpl +++ b/view/templates/admin_site.tpl @@ -120,10 +120,6 @@ {{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}} @@ -157,13 +153,10 @@

{{$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 c8e8af2294..a8243b6149 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}}
From 733caa56695ad171ae3e709e6df6558ca474e6a6 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Feb 2017 23:19:13 +0000 Subject: [PATCH 03/60] Removed admin settings --- mod/admin.php | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index 1475130834..a8fe219a17 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -468,12 +468,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 +481,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), @@ -630,8 +625,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); @@ -666,7 +659,6 @@ function admin_page_site_post(App $a) { $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); @@ -719,8 +711,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); @@ -817,7 +807,6 @@ function admin_page_site_post(App $a) { 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); @@ -1036,8 +1025,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.")), @@ -1069,7 +1056,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.")), From 46308fa1ef00365e38f85c00b344a6d0ab917b18 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 26 Feb 2017 23:27:10 +0000 Subject: [PATCH 04/60] Removed worker config stuff --- boot.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/boot.php b/boot.php index 1e0c300e19..8218c80040 100644 --- a/boot.php +++ b/boot.php @@ -1386,17 +1386,15 @@ class App { // 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; - } + $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); } + // Set the timestamp of the last proc_run + Cache::set($cachekey, time(), CACHE_MINUTE); $args[0] = ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'); } @@ -2000,7 +1998,8 @@ 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'))) { + /// @todo I guess we can remove it, since we don't call it with something different + if (is_string($run_parameter) AND ($run_parameter != 'php')) { $a->proc_run($args); return; } From 99fb15037bde3017b8fe270ddcaa802548f5ed8c Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 27 Feb 2017 06:27:22 +0000 Subject: [PATCH 05/60] Removed some more unneeded stuff --- boot.php | 99 +++++------------------------------ include/pidfile.php | 41 --------------- include/poller.php | 4 +- mod/admin.php | 4 -- view/templates/admin_site.tpl | 1 - 5 files changed, 15 insertions(+), 134 deletions(-) delete mode 100644 include/pidfile.php diff --git a/boot.php b/boot.php index 8218c80040..ec028770ac 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'); @@ -1346,58 +1345,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. - $cachekey = "app:proc_run:started"; - $result = Cache::get($cachekey); - if (!is_null($result)) { - if ((time() - $result) < 10) { - return; - } + // If the last worker fork was less than 10 seconds before then don't fork another one. + // This should prevent the forking of masses of workers. + $cachekey = "app:proc_run:started"; + $result = Cache::get($cachekey); + if (!is_null($result)) { + if ((time() - $result) < 10) { + return; } - // Set the timestamp of the last proc_run - Cache::set($cachekey, time(), CACHE_MINUTE); - - $args[0] = ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'); } + // 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(); @@ -1950,10 +1916,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); * @@ -1998,12 +1963,6 @@ function proc_run($cmd){ if (!$arr['run_cmd'] OR !count($args)) return; - /// @todo I guess we can remove it, since we don't call it with something different - if (is_string($run_parameter) AND ($run_parameter != 'php')) { - $a->proc_run($args); - return; - } - $priority = PRIORITY_MEDIUM; $dont_fork = get_config("system", "worker_dont_fork"); @@ -2051,7 +2010,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); } @@ -2385,38 +2344,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/include/pidfile.php b/include/pidfile.php deleted file mode 100644 index 3093e149ae..0000000000 --- a/include/pidfile.php +++ /dev/null @@ -1,41 +0,0 @@ -_file = "$dir/$name.pid"; - - if (file_exists($this->_file)) { - $pid = trim(@file_get_contents($this->_file)); - if (($pid != "") AND posix_kill($pid, 0)) { - $this->_running = true; - } - } - - if (! $this->_running) { - $pid = getmypid(); - file_put_contents($this->_file, $pid); - } - } - - public function __destruct() { - if ((! $this->_running) && file_exists($this->_file)) { - @unlink($this->_file); - } - } - - public function is_already_running() { - return $this->_running; - } - - public function running_time() { - return(time() - @filectime($this->_file)); - } - - public function kill() { - if (file_exists($this->_file)) - return(posix_kill(file_get_contents($this->_file), SIGTERM)); - } -} -?> diff --git a/include/poller.php b/include/poller.php index 0629735163..89ab85a1f5 100644 --- a/include/poller.php +++ b/include/poller.php @@ -458,7 +458,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); } @@ -604,7 +604,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/mod/admin.php b/mod/admin.php index a8fe219a17..d599220d65 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -650,7 +650,6 @@ function admin_page_site_post(App $a) { $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'])) : ''); @@ -801,7 +800,6 @@ function admin_page_site_post(App $a) { 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); @@ -925,7 +923,6 @@ function admin_page_site(App $a) { // Automatically create temporary paths get_temppath(); - get_lockpath(); get_itemcachepath(); //echo "
"; var_dump($lang_choices); die("
"); @@ -1044,7 +1041,6 @@ function admin_page_site(App $a) { '$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.")), diff --git a/view/templates/admin_site.tpl b/view/templates/admin_site.tpl index df50c0fb48..2faf64e268 100644 --- a/view/templates/admin_site.tpl +++ b/view/templates/admin_site.tpl @@ -125,7 +125,6 @@ {{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}} From df6913f7e1eb86e441c9a4a996d59241f95af0b5 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 27 Feb 2017 06:31:49 +0000 Subject: [PATCH 06/60] pidfile.php is in use by two addons. So we restore it here. --- include/pidfile.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/pidfile.php diff --git a/include/pidfile.php b/include/pidfile.php new file mode 100644 index 0000000000..3093e149ae --- /dev/null +++ b/include/pidfile.php @@ -0,0 +1,41 @@ +_file = "$dir/$name.pid"; + + if (file_exists($this->_file)) { + $pid = trim(@file_get_contents($this->_file)); + if (($pid != "") AND posix_kill($pid, 0)) { + $this->_running = true; + } + } + + if (! $this->_running) { + $pid = getmypid(); + file_put_contents($this->_file, $pid); + } + } + + public function __destruct() { + if ((! $this->_running) && file_exists($this->_file)) { + @unlink($this->_file); + } + } + + public function is_already_running() { + return $this->_running; + } + + public function running_time() { + return(time() - @filectime($this->_file)); + } + + public function kill() { + if (file_exists($this->_file)) + return(posix_kill(file_get_contents($this->_file), SIGTERM)); + } +} +?> From 3c220dd40cc5cabb991d23f20636f2a973d6806c Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 27 Feb 2017 21:07:32 +0000 Subject: [PATCH 07/60] Queue.php is now reworked --- include/queue.php | 235 ++++++++++++++++++++-------------------------- 1 file changed, 103 insertions(+), 132 deletions(-) diff --git a/include/queue.php b/include/queue.php index 6bbfdaae81..509fb19d26 100644 --- a/include/queue.php +++ b/include/queue.php @@ -1,7 +1,5 @@ 1) + if ($argc > 1) $queue_id = intval($argv[1]); else $queue_id = 0; - $deadguys = array(); - $deadservers = array(); - $serverlist = array(); - if (!$queue_id) { logger('queue: start'); @@ -34,7 +28,7 @@ function queue_run(&$argv, &$argc){ if ($r) { foreach ($r as $rr) { logger('queue: deliverq'); - proc_run(PRIORITY_HIGH,'include/delivery.php',$rr['cmd'],$rr['item'],$rr['contact']); + proc_run(PRIORITY_HIGH,'include/delivery.php', $rr['cmd'], $rr['item'], $rr['contact']); } } @@ -53,142 +47,119 @@ 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) { + 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 ($queue_id) { - $qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1", - intval($queue_id)); - } else { - logger('Call queue for id '.$q_item['id']); - proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']); - continue; - } - - if(! count($qi)) - continue; - - - $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; - } - if(in_array($c[0]['notify'],$deadguys)) { - logger('queue: skipping known dead url: ' . $c[0]['notify']); - update_queue_time($q_item['id']); - continue; - } - - $server = poco_detect_server($c[0]['url']); - - if (($server != "") AND !in_array($server, $serverlist)) { - logger("Check server ".$server." (".$c[0]["network"].")"); - if (!poco_check_server($server, $c[0]["network"], true)) - $deadservers[] = $server; - - $serverlist[] = $server; - } - - if (($server != "") AND in_array($server, $deadservers)) { - logger('queue: skipping known dead server: '.$server); - update_queue_time($q_item['id']); - continue; - } - - $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 == (-1)) { - update_queue_time($q_item['id']); - $deadguys[] = $contact['notify']; - } 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); - - if($deliver_status == (-1)) { - update_queue_time($q_item['id']); - $deadguys[] = $contact['notify']; - } 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']); - $deadguys[] = $contact['notify']; - } 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 - update_queue_time($q_item['id']); - - break; - - } - logger('Deliver status '.$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>'); + if (!dbm::is_result($r)) { + return; } + $q_item = $r[0]; + + $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; + } + + $server = poco_detect_server($c[0]['url']); + + if ($server != "") { + logger("Check server ".$server." (".$c[0]["network"].")"); + + if (!poco_check_server($server, $c[0]["network"], true)) { + logger('queue: skipping dead server: '.$server); + update_queue_time($q_item['id']); + return; + } + } + + $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; + } + + $data = $q_item['content']; + $public = $q_item['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 == (-1)) { + update_queue_time($q_item['id']); + } 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); + + if ($deliver_status == (-1)) { + update_queue_time($q_item['id']); + } 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']); + } 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 + update_queue_time($q_item['id']); + + break; + + } + logger('Deliver status '.$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>'); + return; } From 39386ded36c666ff072be92cdead1a79eddd1b89 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 27 Feb 2017 21:26:37 +0000 Subject: [PATCH 08/60] "old_share" is removed --- include/api.php | 22 +++++++++------------- mod/admin.php | 3 --- mod/share.php | 26 ++++++++------------------ view/templates/admin_site.tpl | 1 - 4 files changed, 17 insertions(+), 35 deletions(-) diff --git a/include/api.php b/include/api.php index d7fa1d5875..701e527cc8 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/mod/admin.php b/mod/admin.php index 1475130834..5cfeeb376f 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -649,7 +649,6 @@ 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); @@ -805,7 +804,6 @@ 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); @@ -996,7 +994,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.")), diff --git a/mod/share.php b/mod/share.php index 928ccdef26..36a4d5945f 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/view/templates/admin_site.tpl b/view/templates/admin_site.tpl index 2edfddb885..e778b7ad49 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}}
From 997e94555b1511b907662f688207f17d4ad868e2 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 27 Feb 2017 21:46:37 +0000 Subject: [PATCH 09/60] The old pager is removed --- include/Contact.php | 30 ++---------------------------- mod/admin.php | 3 --- mod/community.php | 27 +-------------------------- mod/network.php | 19 +------------------ mod/profile.php | 25 ++----------------------- view/templates/admin_site.tpl | 1 - 6 files changed, 6 insertions(+), 99 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 2aab828f8a..9e3e6e010d 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -675,15 +675,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` @@ -699,11 +690,7 @@ function posts_from_gcontact(App $a, $gcontact_id) { $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; } @@ -736,15 +723,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), @@ -755,11 +733,7 @@ function posts_from_contact_url(App $a, $contact_url) { $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/mod/admin.php b/mod/admin.php index 1475130834..d91b2d0a5f 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -662,7 +662,6 @@ function admin_page_site_post(App $a) { $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'])) : ''); @@ -815,7 +814,6 @@ function admin_page_site_post(App $a) { 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); @@ -1061,7 +1059,6 @@ function admin_page_site(App $a) { '$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.")), diff --git a/mod/community.php b/mod/community.php index 7c92ff462f..91b09bba9a 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)) { @@ -107,11 +86,7 @@ function community_content(App $a, $update = 0) { $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 23cf098b65..284bf3d961 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) { @@ -793,10 +778,8 @@ function network_content(App $a, $update = 0) { if (!$update) { 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/profile.php b/mod/profile.php index 5dd8293c7f..ab7b7cff76 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -240,23 +240,6 @@ function profile_content(App $a, $update = 0) { $sql_extra2 .= protect_sprintf(sprintf(" AND `thread`.`created` >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); } - 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_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) { @@ -328,12 +311,8 @@ function profile_content(App $a, $update = 0) { $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/view/templates/admin_site.tpl b/view/templates/admin_site.tpl index 2edfddb885..7434993705 100644 --- a/view/templates/admin_site.tpl +++ b/view/templates/admin_site.tpl @@ -153,7 +153,6 @@ {{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}}

From cc86d8ea14e4c1a6c57945ee248a659a1003df58 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 27 Feb 2017 23:59:05 +0000 Subject: [PATCH 10/60] Language data won't be displayed anymore (it was experimental stuff) --- mod/admin.php | 3 --- object/Item.php | 27 --------------------------- view/templates/admin_site.tpl | 1 - 3 files changed, 31 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index 1475130834..4b8182dfee 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -651,7 +651,6 @@ function admin_page_site_post(App $a) { $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'])) : ''); @@ -734,7 +733,6 @@ 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); @@ -1052,7 +1050,6 @@ 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.")), diff --git a/object/Item.php b/object/Item.php index d95af3419a..b693520b93 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 2edfddb885..9c02131f06 100644 --- a/view/templates/admin_site.tpl +++ b/view/templates/admin_site.tpl @@ -132,7 +132,6 @@ {{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}} From a3cd804ff12e4cca5e2adc2b750378007bca4146 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 1 Mar 2017 23:23:14 -0500 Subject: [PATCH 11/60] Fix default paginate.tpl Adding missing curly braces --- view/templates/paginate.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/templates/paginate.tpl b/view/templates/paginate.tpl index 21d56509aa..fcd580b071 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}} From 07aefe61bfeab5046f74a7f7940963011c81baf5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 1 Mar 2017 23:26:49 -0500 Subject: [PATCH 12/60] Update paginate_data() - Formatting: Normalize quotes, spaces, braces - Add "disabled" CSS class to links previously ommitted - Add "previous" and "next" CSS classes to minimal pager links - Add main pager CSS class depending on type --- include/text.php | 89 ++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/include/text.php b/include/text.php index 11248902ba..580bd95fc7 100644 --- a/include/text.php +++ b/include/text.php @@ -268,90 +268,89 @@ 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); + 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); + 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); + $d[$name] = array('url' => $url, 'text' => $text, 'class' => $class); } - 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')); + 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) { + if ($numpages > 14) { $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1); $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14)); } $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')) { /** From 21cad46d19f4a049b9d4d69a0a569e023c652b6d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 1 Mar 2017 23:40:34 -0500 Subject: [PATCH 13/60] Backward compatibility for theme other than frio - Add .pager .disabled CSS rule --- view/theme/duepuntozero/style.css | 3 +++ view/theme/frost-mobile/style.css | 3 +++ view/theme/frost/style.css | 3 +++ view/theme/quattro/green/style.css | 3 +++ view/theme/quattro/lilac/style.css | 3 +++ view/theme/quattro/quattro.less | 3 +++ view/theme/smoothly/style.css | 4 ++++ view/theme/vier/style.css | 4 ++++ 8 files changed, 26 insertions(+) diff --git a/view/theme/duepuntozero/style.css b/view/theme/duepuntozero/style.css index c1e8067443..8e2c5d4478 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/frost-mobile/style.css b/view/theme/frost-mobile/style.css index c005e838f1..7c5d2c7609 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 46eb650ec1..9b65da9c8c 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 8eba0e4cf7..af5cfcedf0 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 b424534206..0c17b00331 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 6c01986888..53bb7e38a6 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 e91eccfe17..ec52277bdd 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 8454c7e0ae..32617867cb 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; From 57ce6cf5daaff5d1d4433b9a8059f5dea7b68bf5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 1 Mar 2017 23:41:54 -0500 Subject: [PATCH 14/60] Improve pagination on frio theme - Add pager class discrimination - Change links order to first / prev / 1 / ... / 10 / next / last - Enable dynamic pagination coloring - Prevent click on disabled links --- view/theme/frio/css/style.css | 20 ++++++++++++++++++++ view/theme/frio/templates/paginate.tpl | 13 +++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 view/theme/frio/templates/paginate.tpl diff --git a/view/theme/frio/css/style.css b/view/theme/frio/css/style.css index df9585d070..ea4db0d532 100644 --- a/view/theme/frio/css/style.css +++ b/view/theme/frio/css/style.css @@ -2515,3 +2515,23 @@ body .tread-wrapper .hovercard:hover .hover-card-content a { section .profile-match-wrapper { float: left; } + +/* Pagination improvements */ + +.pagination > li > a, +.pagination > li > span { + color: $link_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; +} + +.disabled > a { + pointer-events: none; +} \ 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 0000000000..a9c3ae480d --- /dev/null +++ b/view/theme/frio/templates/paginate.tpl @@ -0,0 +1,13 @@ +{{if $pager}} +
+ {{if $pager.first}}
  • {{$pager.first.text}}
  • {{/if}} + + {{if $pager.prev}}
  • {{$pager.prev.text}}
  • {{/if}} + + {{foreach $pager.pages as $p}}
  • {{$p.text}}
  • {{/foreach}} + + {{if $pager.next}}
  • {{$pager.next.text}}
  • {{/if}} + + {{if $pager.last}} 
  • {{$pager.last.text}}
  • {{/if}} +
    +{{/if}} From ebdc9667f796de83c6b4da2247d11f8658725a1b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 2 Mar 2017 11:30:41 -0500 Subject: [PATCH 15/60] Improve readability - Move CSS block above the temporary block - Add template description --- view/theme/frio/css/style.css | 20 +++++++++----------- view/theme/frio/templates/paginate.tpl | 1 + 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/view/theme/frio/css/style.css b/view/theme/frio/css/style.css index ea4db0d532..34bcb833db 100644 --- a/view/theme/frio/css/style.css +++ b/view/theme/frio/css/style.css @@ -2508,16 +2508,7 @@ body .tread-wrapper .hovercard:hover .hover-card-content a { color: $link_color !important; } -/* - * some temporary workarounds until this will solved - * elsewhere (e.g. new templates) - */ -section .profile-match-wrapper { - float: left; -} - /* Pagination improvements */ - .pagination > li > a, .pagination > li > span { color: $link_color; @@ -2531,7 +2522,14 @@ section .profile-match-wrapper { background-color: $link_color; border-color: $link_color; } - .disabled > a { pointer-events: none; -} \ No newline at end of file +} + +/* + * some temporary workarounds until this will solved + * elsewhere (e.g. new templates) + */ +section .profile-match-wrapper { + float: left; +} diff --git a/view/theme/frio/templates/paginate.tpl b/view/theme/frio/templates/paginate.tpl index a9c3ae480d..ab65cdd406 100644 --- a/view/theme/frio/templates/paginate.tpl +++ b/view/theme/frio/templates/paginate.tpl @@ -1,3 +1,4 @@ +{{* Pager template, uses output of paginate_data() in include/text.php *}} {{if $pager}}
    {{if $pager.first}}
  • {{$pager.first.text}}
  • {{/if}} From 99650613591cdf7da5ecd683c1590d17d0f27fca Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 2 Mar 2017 21:20:33 +0000 Subject: [PATCH 16/60] Better detection for Hubzilla --- include/socgraph.php | 50 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index 6968704bf2..407a3074da 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -680,7 +680,13 @@ function poco_to_boolean($val) { return ($val); } -function poco_detect_friendica_server($body) { +/** + * @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(); @@ -709,6 +715,27 @@ function poco_detect_friendica_server($body) { } } + 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"))) { + $server = array(); + $server["platform"] = $attr['content']; + $server["version"] = ""; + $server["network"] = NETWORK_DIASPORA; + } + } + } + } + if (!$server) { return false; } @@ -794,13 +821,22 @@ function poco_check_server($server_url, $network = "", $force = false) { $last_contact = datetime_convert(); if (!$failure) { - // Test for Diaspora + // Test for Diaspora, Hubzilla, Mastodon or older Friendica servers $serverret = z_fetch_url($server_url); if (!$serverret["success"] OR ($serverret["body"] == "")) { $last_failure = datetime_convert(); $failure = true; } 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)) { foreach($lines as $line) { @@ -824,15 +860,6 @@ function poco_check_server($server_url, $network = "", $force = false) { } } } - - $friendica_server = poco_detect_friendica_server($serverret["body"]); - if ($friendica_server) { - $platform = $friendica_server['platform']; - $network = $friendica_server['network']; - $version = $friendica_server['version']; - $site_name = $friendica_server['site_name']; - $last_contact = datetime_convert(); - } } } @@ -859,6 +886,7 @@ function poco_check_server($server_url, $network = "", $force = false) { $last_contact = datetime_convert(); } + // Test for Hubzilla, Redmatrix or Friendica $serverret = z_fetch_url($server_url."/api/statusnet/config.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); From 024908a3ece9f94c615072dd026b6ec1b5cda6e3 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 2 Mar 2017 19:00:22 -0500 Subject: [PATCH 17/60] Delete frio obsolete Colors.php library --- view/theme/frio/php/Colors.php | 292 --------------------------------- 1 file changed, 292 deletions(-) delete mode 100644 view/theme/frio/php/Colors.php diff --git a/view/theme/frio/php/Colors.php b/view/theme/frio/php/Colors.php deleted file mode 100644 index d6ba15fbc1..0000000000 --- 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 From 25e62449509e48d3ea4efc10d31616388cf31658 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 4 Mar 2017 07:57:55 +0000 Subject: [PATCH 18/60] BlaBlaNet is now detected again. No false positive for Statusnet anymore --- include/socgraph.php | 94 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 15 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index 407a3074da..cf78024dee 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -680,6 +680,42 @@ 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 (Hubzilla or Friendica) via the front page body * @@ -726,7 +762,7 @@ function poco_detect_server_type($body) { } } if ($attr['property'] == 'generator') { - if (in_array($attr['content'], array("hubzilla"))) { + if (in_array($attr['content'], array("hubzilla", "BlaBlaNet"))) { $server = array(); $server["platform"] = $attr['content']; $server["version"] = ""; @@ -820,6 +856,35 @@ function poco_check_server($server_url, $network = "", $force = false) { } 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) { + $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); @@ -863,7 +928,7 @@ function poco_check_server($server_url, $network = "", $force = false) { } } - 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 @@ -885,7 +950,8 @@ function poco_check_server($server_url, $network = "", $force = false) { $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"]) { @@ -893,6 +959,16 @@ function poco_check_server($server_url, $network = "", $force = false) { 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; @@ -993,18 +1069,6 @@ 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; From b42167f0ac5b76fc42e6da1ced2b001862417f5e Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 4 Mar 2017 11:04:00 +0000 Subject: [PATCH 19/60] We can now return a list of known servers --- include/socgraph.php | 21 +++++++++++++++++++++ mod/poco.php | 15 +++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index cf78024dee..6a97e285cf 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -2024,4 +2024,25 @@ 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 `id`, `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; + } + $list = array(); + foreach ($r AS $server) { + $server['id'] = (int)$server['id']; + $list[] = $server; + } + return $list; +} ?> diff --git a/mod/poco.php b/mod/poco.php index 4ce075301c..422bfe5b7c 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -27,6 +27,12 @@ function poco_init(App $a) { $justme = false; $global = false; + if($a->argc > 1 && $a->argv[1] === '@server') { + $ret = poco_serverlist(); + header('Content-type: application/json'); + echo json_encode($ret); + killme(); + } if($a->argc > 1 && $a->argv[1] === '@global') { $global = true; $update_limit = date("Y-m-d H:i:s", time() - 30 * 86400); @@ -314,11 +320,9 @@ function poco_init(App $a) { $ret['entry'][] = $entry; } - } - else + } else $ret['entry'][] = array(); - } - else + } else http_status_exit(500); logger("End of poco", LOGGER_DEBUG); @@ -332,8 +336,7 @@ function poco_init(App $a) { header('Content-type: application/json'); echo json_encode($ret); killme(); - } - else + } else http_status_exit(500); From 953477de87f113492415d005e3bf9a754012a613 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 4 Mar 2017 13:30:34 +0000 Subject: [PATCH 20/60] Improved check for the server base url --- include/socgraph.php | 59 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index 6a97e285cf..21e27e52b7 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); From 9a71472be6e79554d3aea7480f752920fece39f6 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 4 Mar 2017 14:32:40 +0000 Subject: [PATCH 21/60] Only store a new gserver entry if it is a valid one --- include/socgraph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/socgraph.php b/include/socgraph.php index 21e27e52b7..f35459d79b 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1157,7 +1157,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), From 07516c318c07c06acf51ed0c0795c08dfc2cbebd Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Mar 2017 21:56:50 +0000 Subject: [PATCH 22/60] We now support PDO for database connections as well --- include/dba.php | 321 ++++++++++++++++++++++++++++---------------- include/uimport.php | 9 +- 2 files changed, 205 insertions(+), 125 deletions(-) diff --git a/include/dba.php b/include/dba.php index 8e2d18db60..09d705cbdb 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,49 @@ class dba { } } - if (class_exists('mysqli')) { + 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; + } + } elseif (class_exists('mysqli')) { + $this->driver = 'mysqli'; $this->db = @new mysqli($server,$user,$pass,$db); - if (! mysqli_connect_errno()) { + 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 (!$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 +100,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 +135,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 +183,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; @@ -204,11 +216,19 @@ 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); + 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; } + $connstr = ($connected ? "Connected" : "Disonnected"); $stamp1 = microtime(true); @@ -219,10 +239,16 @@ class dba { $sql = "/*".$a->callstack()." */ ".$sql; } - if ($this->mysqli) { - $result = @$this->db->query($sql); - } else { - $result = @mysql_query($sql,$this->db); + switch ($this->driver) { + case 'pdo': + $result = @$this->db->query($sql); + 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 +269,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 +303,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; } } @@ -302,18 +345,28 @@ class dba { } $r = array(); - if ($this->mysqli) { - if ($result->num_rows) { - 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)) - $r[] = $x; - mysql_free_result($result); - } + switch ($this->driver) { + case 'pdo': + if ($result->rowCount()) { + while($x = $result->fetch(PDO::FETCH_ASSOC)) + $r[] = $x; + $result->closeCursor(); + } + break; + case 'mysqli': + if ($result->num_rows) { + while($x = $result->fetch_array(MYSQLI_ASSOC)) + $r[] = $x; + $result->free_result(); + } + break; + case 'mysql': + if (mysql_num_rows($result)) { + while($x = mysql_fetch_array($result, MYSQL_ASSOC)) + $r[] = $x; + mysql_free_result($result); + } + break; } //$a->save_timestamp($stamp1, "database"); @@ -328,12 +381,22 @@ class dba { $x = false; if ($this->result) { - if ($this->mysqli) { - if ($this->result->num_rows) - $x = $this->result->fetch_array(MYSQLI_ASSOC); - } else { - if (mysql_num_rows($this->result)) - $x = mysql_fetch_array($this->result, MYSQL_ASSOC); + switch ($this->driver) { + case 'pdo': + if ($this->result->rowCount()) { + $x = $this->result->fetch(PDO::FETCH_ASSOC); + } + break; + case 'mysqli': + if ($this->result->num_rows) { + $x = $this->result->fetch_array(MYSQLI_ASSOC); + } + break; + case 'mysql': + if (mysql_num_rows($this->result)) { + $x = mysql_fetch_array($this->result, MYSQL_ASSOC); + } + break; } } return($x); @@ -341,10 +404,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 +424,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 +490,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 +539,7 @@ function q($sql) { */ logger('dba: no database: ' . print_r($args,true)); return false; - -}} +} /** * @brief Performs a query with "dirty reads" @@ -458,8 +551,8 @@ function q($sql) { * @return array Query array */ function qu($sql) { - global $db; + $args = func_get_args(); unset($args[0]); @@ -484,7 +577,6 @@ function qu($sql) { */ logger('dba: no database: ' . print_r($args,true)); return false; - } /** @@ -492,40 +584,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/uimport.php b/include/uimport.php index b774d78c6d..0d7ce5d27a 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() { From 2ea50d9c47bad0517513cb39dd5187fbb4ee0be0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Mar 2017 23:59:53 +0000 Subject: [PATCH 23/60] Emulation for the mysqli behaviour when executing insert, update, ... --- include/dba.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/dba.php b/include/dba.php index 09d705cbdb..000b5b49ec 100644 --- a/include/dba.php +++ b/include/dba.php @@ -334,6 +334,9 @@ class dba { if (file_exists('dbfail.out')) { file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND); } + } elseif (($this->driver == 'pdo') AND (strtolower(substr($orig_sql, 0, 6)) != "select")) { + // mysqli separates the return value between "select" and "update" - pdo doesn't + $result = true; } if (($result === true) || ($result === false)) { From da5bbe8b50226435a1ec7dc34cd4c40c8d024e5e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 6 Mar 2017 05:06:05 -0500 Subject: [PATCH 24/60] Add public_contact() function - Add function to retrieve the public contact id (uid = 0) of the current logged-in user --- boot.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/boot.php b/boot.php index b8e9267070..a5774aaad8 100644 --- a/boot.php +++ b/boot.php @@ -1889,11 +1889,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 * From 67ae0fed7fac98b71076e501bf6595cf917d3b13 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 6 Mar 2017 05:07:17 -0500 Subject: [PATCH 25/60] Fix response "self" assigment - Switch from unreliable `uid` matching to `author-id` using public_contact() --- include/conversation.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index a1d086cb9d..93c42cd7b1 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; From d686bdcf0905c82780e0c4edd79638dcef67825c Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 6 Mar 2017 10:10:22 +0000 Subject: [PATCH 26/60] Quickfix for SQL commands that should return "true" instead of an empty array --- include/dba.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/include/dba.php b/include/dba.php index 000b5b49ec..3742ba7018 100644 --- a/include/dba.php +++ b/include/dba.php @@ -63,18 +63,21 @@ class dba { $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"]); + + if (isset($a->config["system"]["db_charset"])) { + $this->db->set_charset($a->config["system"]["db_charset"]); + } } } 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); + } } - 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) { @@ -334,9 +337,6 @@ class dba { if (file_exists('dbfail.out')) { file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND); } - } elseif (($this->driver == 'pdo') AND (strtolower(substr($orig_sql, 0, 6)) != "select")) { - // mysqli separates the return value between "select" and "update" - pdo doesn't - $result = true; } if (($result === true) || ($result === false)) { @@ -372,6 +372,11 @@ class dba { break; } + if (($this->driver == 'pdo') AND (strtolower(substr($orig_sql, 0, 6)) != "select") AND (count($r) == 0)) { + // mysqli separates the return value between "select" and "update" - pdo doesn't + $r = true; + } + //$a->save_timestamp($stamp1, "database"); if ($this->debug) { From 4931ecafbb2bd3cd18a44d3a366c1051f64a08e0 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 6 Mar 2017 05:28:01 -0500 Subject: [PATCH 27/60] Rewriting of do_like() - Fix behavior where event actions had to be performed twice to switch from one to another - Simplify the contact data retrieval - Make sure contact-id, owner-id and author-id are correctly set --- include/like.php | 264 +++++++++++++++++++++++------------------------ 1 file changed, 130 insertions(+), 134 deletions(-) diff --git a/include/like.php b/include/like.php index 210bde6906..a53b90c039 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; } From f09a8609dff388a4344170ae61aea910361bd6a7 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 7 Mar 2017 17:16:17 +0000 Subject: [PATCH 28/60] Better separation between queries with or without result --- include/dba.php | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/include/dba.php b/include/dba.php index 3742ba7018..7a1e3a2597 100644 --- a/include/dba.php +++ b/include/dba.php @@ -242,9 +242,13 @@ class dba { $sql = "/*".$a->callstack()." */ ".$sql; } + $columns = 0; + switch ($this->driver) { case 'pdo': $result = @$this->db->query($sql); + // Is used to separate between queries that returning data - or not + $columns = $result->columnCount(); break; case 'mysqli': $result = @$this->db->query($sql); @@ -350,31 +354,30 @@ class dba { $r = array(); switch ($this->driver) { case 'pdo': - if ($result->rowCount()) { - while($x = $result->fetch(PDO::FETCH_ASSOC)) - $r[] = $x; - $result->closeCursor(); + while ($x = $result->fetch(PDO::FETCH_ASSOC)) { + $r[] = $x; } + $result->closeCursor(); break; case 'mysqli': - if ($result->num_rows) { - while($x = $result->fetch_array(MYSQLI_ASSOC)) - $r[] = $x; - $result->free_result(); + while ($x = $result->fetch_array(MYSQLI_ASSOC)) { + $r[] = $x; } + $result->free_result(); break; case 'mysql': - if (mysql_num_rows($result)) { - while($x = mysql_fetch_array($result, MYSQL_ASSOC)) - $r[] = $x; - mysql_free_result($result); + while ($x = mysql_fetch_array($result, MYSQL_ASSOC)) { + $r[] = $x; } + mysql_free_result($result); break; } - if (($this->driver == 'pdo') AND (strtolower(substr($orig_sql, 0, 6)) != "select") AND (count($r) == 0)) { - // mysqli separates the return value between "select" and "update" - pdo doesn't - $r = true; + // 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"); @@ -391,19 +394,13 @@ class dba { if ($this->result) { switch ($this->driver) { case 'pdo': - if ($this->result->rowCount()) { - $x = $this->result->fetch(PDO::FETCH_ASSOC); - } + $x = $this->result->fetch(PDO::FETCH_ASSOC); break; case 'mysqli': - if ($this->result->num_rows) { - $x = $this->result->fetch_array(MYSQLI_ASSOC); - } + $x = $this->result->fetch_array(MYSQLI_ASSOC); break; case 'mysql': - if (mysql_num_rows($this->result)) { - $x = mysql_fetch_array($this->result, MYSQL_ASSOC); - } + $x = mysql_fetch_array($this->result, MYSQL_ASSOC); break; } } From d898616f8df8900834d70e5b33e2f40c711b8027 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 8 Mar 2017 05:40:57 +0000 Subject: [PATCH 29/60] Remove junk from the version number --- include/socgraph.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index f35459d79b..cf6a799cbf 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -983,7 +983,9 @@ 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(); } @@ -993,11 +995,14 @@ 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(); } } +echo "3"; if (!$failure) { // Test for Hubzilla, Redmatrix or Friendica $serverret = z_fetch_url($server_url."/api/statusnet/config.json"); @@ -1141,7 +1146,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), @@ -1157,7 +1162,7 @@ function poco_check_server($server_url, $network = "", $force = false) { dbesc($last_failure), dbesc(normalise_link($server_url)) ); - elseif (!$failure) + } 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), From 32f1b2de200dd737129e8cd8a31a898712da79ac Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 8 Mar 2017 13:15:24 +0000 Subject: [PATCH 30/60] Forgotten debug output --- include/socgraph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/socgraph.php b/include/socgraph.php index cf6a799cbf..7acd7725fb 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1002,7 +1002,7 @@ function poco_check_server($server_url, $network = "", $force = false) { $last_contact = datetime_convert(); } } -echo "3"; + if (!$failure) { // Test for Hubzilla, Redmatrix or Friendica $serverret = z_fetch_url($server_url."/api/statusnet/config.json"); From df6304cc423db5efceedfa4a523425e011f65d96 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Sun, 12 Mar 2017 01:11:35 +0100 Subject: [PATCH 31/60] Fix "remember me" cookie for OpenID logins Closes #2432 NOTE: in order to obtain the same "cookie hash" it was required to include unneeded fields in the user record structure, this would be good to change in the future... --- include/auth.php | 48 ++------------------------------------- include/security.php | 54 ++++++++++++++++++++++++++++++++++++++++++++ mod/openid.php | 2 +- 3 files changed, 57 insertions(+), 47 deletions(-) diff --git a/include/auth.php b/include/auth.php index e3c8d92eeb..62ca3563a4 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,8 @@ 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 - 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 +195,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/security.php b/include/security.php index c379518562..93df6ff255 100644 --- a/include/security.php +++ b/include/security.php @@ -1,5 +1,41 @@ $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 +130,24 @@ 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']); + } + else { + new_cookie(0); // 0 means delete on browser exit + } + } + + + if ($login_initial) { call_hooks('logged_in', $a->user); diff --git a/mod/openid.php b/mod/openid.php index 59a7530140..b45cd97975 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 From 3a3fa017a635a4549a5b6e801abafe6cf23129e7 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 12 Mar 2017 09:13:04 +0000 Subject: [PATCH 32/60] Discovery of new servers --- include/discover_poco.php | 28 ++++++++++++++++++++++++---- include/socgraph.php | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/include/discover_poco.php b/include/discover_poco.php index 10c741ae5f..6a3df27c8c 100644 --- a/include/discover_poco.php +++ b/include/discover_poco.php @@ -36,11 +36,14 @@ function discover_poco_run(&$argv, &$argc){ $mode = 2; } elseif(($argc == 2) && ($argv[1] == "suggestions")) { $mode = 3; + } elseif(($argc == 3) && ($argv[1] == "server")) { + $mode = 4; } 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") @@ -53,11 +56,28 @@ function discover_poco_run(&$argv, &$argc){ logger('start '.$search); - if ($mode==3) + if ($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)) { diff --git a/include/socgraph.php b/include/socgraph.php index 7acd7725fb..f7bb061e7b 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1441,6 +1441,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'); @@ -1456,8 +1483,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. @@ -1502,6 +1530,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"; From bfad58a777592a972e275fa40b228ee877718f8b Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 12 Mar 2017 09:41:10 +0000 Subject: [PATCH 33/60] We don't need to show the id. --- include/socgraph.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index f7bb061e7b..2d27c863b2 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -2113,7 +2113,7 @@ function gs_discover() { * @return array List of server urls */ function poco_serverlist() { - $r = q("SELECT `id`, `url`, `site_name` AS `displayName`, `network`, `platform`, `version` FROM `gserver` + $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", @@ -2121,11 +2121,6 @@ function poco_serverlist() { if (!dbm::is_result($r)) { return false; } - $list = array(); - foreach ($r AS $server) { - $server['id'] = (int)$server['id']; - $list[] = $server; - } - return $list; + return $r; } ?> From 49b22de70561fb29559e34dd6497452dd17aa55b Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 12 Mar 2017 21:57:09 +0000 Subject: [PATCH 34/60] Changes from previous pull request applied again --- include/queue.php | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/include/queue.php b/include/queue.php index 509fb19d26..67119aea44 100644 --- a/include/queue.php +++ b/include/queue.php @@ -8,14 +8,19 @@ 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; - if ($argc > 1) + if ($argc > 1) { $queue_id = intval($argv[1]); - else + } else { $queue_id = 0; + } + + $cachekey_deadguy = 'queue_run:deadguy:'; + $cachekey_server = 'queue_run:server:'; if (!$queue_id) { @@ -38,7 +43,7 @@ function queue_run(&$argv, &$argc){ 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"); } @@ -50,7 +55,7 @@ function queue_run(&$argv, &$argc){ call_hooks('queue_predeliver', $a, $r); - if (dbm::is_result) { + 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']); @@ -83,12 +88,27 @@ function queue_run(&$argv, &$argc){ 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 != "") { - logger("Check server ".$server." (".$c[0]["network"].")"); + $vital = Cache::get($cachekey_server.$server); - if (!poco_check_server($server, $c[0]["network"], true)) { + 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); + } + + if (!is_null($vital) AND !$vital) { logger('queue: skipping dead server: '.$server); update_queue_time($q_item['id']); return; @@ -118,6 +138,7 @@ function queue_run(&$argv, &$argc){ 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']); } @@ -129,6 +150,7 @@ function queue_run(&$argv, &$argc){ 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']); } @@ -141,6 +163,7 @@ function queue_run(&$argv, &$argc){ 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']); } @@ -151,15 +174,15 @@ function queue_run(&$argv, &$argc){ $params = array('owner' => $owner, 'contact' => $contact, 'queue' => $q_item, 'result' => false); call_hooks('queue_deliver', $a, $params); - if ($params['result']) + if ($params['result']) { remove_queue_item($q_item['id']); - else + } else { update_queue_time($q_item['id']); - + } break; } - logger('Deliver status '.$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; } From 97d3176754ce7b9dce50d83290a6d3746deff0e8 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 Mar 2017 00:03:27 +0000 Subject: [PATCH 35/60] Querying via nodeinfo --- include/socgraph.php | 122 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/include/socgraph.php b/include/socgraph.php index dee3bfc198..e3e5773b7f 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -763,6 +763,110 @@ function poco_detect_poco_data($data) { 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; + } + } + + 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 * @@ -1103,6 +1207,24 @@ function poco_check_server($server_url, $network = "", $force = false) { } } + // Query nodeinfo. Working for (at least) Diaspora and Friendica. + if (!$failure) { + $server = poco_fetch_nodeinfo($server_url); + if ($server) { + $register_policy = $server['register_policy']; + $platform = $server['platform']; + $network = $server['network']; + + if ($version == "") { + $version = $server['version']; + } + + $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))) { From 80e58964ceac470b2571e542e53de2558b3fb499 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 Mar 2017 00:09:32 +0000 Subject: [PATCH 36/60] Standard stuff --- include/Contact.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 3d4d6ded7f..85dc1008eb 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -717,7 +717,7 @@ function posts_from_gcontact(App $a, $gcontact_id) { $o = conversation($a,$r,'community',false); - $o .= alt_pager($a,count($r)); + $o .= alt_pager($a, count($r)); return $o; } @@ -760,7 +760,7 @@ function posts_from_contact_url(App $a, $contact_url) { $o = conversation($a,$r,'community',false); - $o .= alt_pager($a,count($r)); + $o .= alt_pager($a, count($r)); return $o; } From eb6a6228f752d56e20b897dec8b9525281363ef0 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 Mar 2017 05:57:37 +0000 Subject: [PATCH 37/60] more spaces --- include/Contact.php | 4 ++-- mod/community.php | 4 ++-- mod/network.php | 6 +++--- mod/profile.php | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 85dc1008eb..9fd61f8d5e 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -715,7 +715,7 @@ function posts_from_gcontact(App $a, $gcontact_id) { intval($a->pager['itemspage']) ); - $o = conversation($a,$r,'community',false); + $o = conversation($a, $r, 'community', false); $o .= alt_pager($a, count($r)); @@ -758,7 +758,7 @@ 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); $o .= alt_pager($a, count($r)); diff --git a/mod/community.php b/mod/community.php index 91b09bba9a..1743304010 100644 --- a/mod/community.php +++ b/mod/community.php @@ -84,9 +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); - $o .= alt_pager($a,count($r)); + $o .= alt_pager($a, count($r)); return $o; } diff --git a/mod/network.php b/mod/network.php index 284bf3d961..a1181a74cb 100644 --- a/mod/network.php +++ b/mod/network.php @@ -773,13 +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(); } else { - $o .= alt_pager($a,count($items)); + $o .= alt_pager($a, count($items)); } } diff --git a/mod/profile.php b/mod/profile.php index 93f2602e23..fbce509d29 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -318,10 +318,10 @@ function profile_content(App $a, $update = 0) { ); } - $o .= conversation($a,$items,'profile',$update); + $o .= conversation($a, $items, 'profile', $update); if (!$update) { - $o .= alt_pager($a,count($items)); + $o .= alt_pager($a, count($items)); } return $o; From acadb8ecdbb4b74b9fdc3d8d913b697f14753938 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 Mar 2017 06:09:00 +0000 Subject: [PATCH 38/60] Remove redundancies. --- include/dba.php | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/include/dba.php b/include/dba.php index 7a1e3a2597..4b0498ad3c 100644 --- a/include/dba.php +++ b/include/dba.php @@ -218,21 +218,7 @@ class dba { $this->error = ''; - // Check the connection (This can reconnect the connection - if configured) - 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; - } - - $connstr = ($connected ? "Connected" : "Disonnected"); + $connstr = ($this->connected() ? "Connected" : "Disonnected"); $stamp1 = microtime(true); From 44888590e5e33157ba30d1df1d4f257e184a9648 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 Mar 2017 06:32:33 +0000 Subject: [PATCH 39/60] One error, one documentation, one brace --- include/discover_poco.php | 8 ++++++++ include/socgraph.php | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/discover_poco.php b/include/discover_poco.php index 6a3df27c8c..9a32790ea0 100644 --- a/include/discover_poco.php +++ b/include/discover_poco.php @@ -29,6 +29,14 @@ function discover_poco_run(&$argv, &$argc){ if ($a->maxload_reached()) return; + /* + 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. + */ + if(($argc > 2) && ($argv[1] == "dirsearch")) { $search = urldecode($argv[2]); $mode = 1; diff --git a/include/socgraph.php b/include/socgraph.php index e3e5773b7f..549e7c0dd2 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -431,7 +431,7 @@ function poco_detect_server($profile) { // Wild guess if ($server_url == "") { $base = preg_replace("=(https?://)(.*?)/(.*)=ism", "$1$2", $profile); - if (base != $profile) { + if ($base != $profile) { $server_url = $base; $network = NETWORK_PHANTOM; } @@ -1303,7 +1303,7 @@ function poco_check_server($server_url, $network = "", $force = false) { dbesc($last_failure), dbesc(normalise_link($server_url)) ); - } elseif (!$failure) + } 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), @@ -1321,7 +1321,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; From cbaf196f509cc5b21f04574cbf80ddd3ecf9f8db Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 13 Mar 2017 11:57:10 +0100 Subject: [PATCH 40/60] Only remove the "remember me" cookie at submitting the auth form Fixes loss of remember (Friendica) cookie on switching Managed accounts --- include/auth.php | 4 ++++ include/security.php | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/auth.php b/include/auth.php index 62ca3563a4..8512abe486 100644 --- a/include/auth.php +++ b/include/auth.php @@ -179,6 +179,10 @@ if (isset($_SESSION) && x($_SESSION,'authenticated') && (!x($_POST,'auth-params' goaway(z_root()); } + 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'); diff --git a/include/security.php b/include/security.php index 93df6ff255..23fc400b3a 100644 --- a/include/security.php +++ b/include/security.php @@ -141,9 +141,6 @@ function authenticate_success($user_record, $login_initial = false, $interactive new_cookie(604800, $user_record); unset($_SESSION['remember']); } - else { - new_cookie(0); // 0 means delete on browser exit - } } From ae64f6f7e293dfc254e0c599349460ca3094e53c Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 Mar 2017 14:37:51 +0000 Subject: [PATCH 41/60] z_fetch_url now always returns an array --- include/network.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/network.php b/include/network.php index b0e71fab7f..f9d35c52c3 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); From d2bad13e8380d6c2a2d36bebe712f12f35a97a45 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 Mar 2017 14:57:11 +0000 Subject: [PATCH 42/60] Added documentation --- mod/poco.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mod/poco.php b/mod/poco.php index 422bfe5b7c..cdf64a3a1a 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -27,25 +27,30 @@ function poco_init(App $a) { $justme = false; $global = false; - if($a->argc > 1 && $a->argv[1] === '@server') { + 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') { + 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) { $r = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid` From f2a0c9fad16286c4471fe1bffb2775eb2f3f5116 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 13 Mar 2017 12:10:03 -0400 Subject: [PATCH 43/60] Fix scrollToItem breaking dropItem functionality - Add doc - Refactor function by removing double jQuery wrapping --- view/theme/frio/js/theme.js | 27 ++++++++++++++--------- view/theme/frio/templates/wall_thread.tpl | 4 ++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/view/theme/frio/js/theme.js b/view/theme/frio/js/theme.js index b4ba2fd357..62cd85df9b 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/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index 1977f541c2..e71dc7b84c 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 *}} From 327b00117defd8b233ef86667733729b8292e1e9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 13 Mar 2017 12:12:13 -0400 Subject: [PATCH 44/60] Improve dropItem() functionality - Drop the obsolete `#` char - Add error case when deleting item - Add item drop support to search items - Add doc --- view/theme/frio/js/textedit.js | 32 ++++++++++++++--------- view/theme/frio/templates/search_item.tpl | 4 +-- view/theme/frio/templates/wall_thread.tpl | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/view/theme/frio/js/textedit.js b/view/theme/frio/js/textedit.js index 9226646b7b..02191f33de 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(); + }).error(function() { + // @todo Show related error message + $el.show(); + }).always(function() { $('body').css('cursor', 'auto'); }); }); diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index 90fbe03bbc..0a6eca0c27 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 e71dc7b84c..85091cf1c6 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -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}} From 0dbc72c4ead8b72455fe6770a5bdb126c40976e2 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 Mar 2017 16:18:45 +0000 Subject: [PATCH 45/60] Embrace the braces and spaces ... --- mod/admin.php | 2 +- mod/poco.php | 208 ++++++++++++++++++++++++++++---------------------- 2 files changed, 116 insertions(+), 94 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index e7f579d4b9..e1c73ac00a 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -333,7 +333,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=='Friendi%%a') { + if ($p=='Friendi%%a') { $newV = array(); $newVv = array(); foreach ($v as $vv) { diff --git a/mod/poco.php b/mod/poco.php index cdf64a3a1a..30648acab6 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); @@ -48,32 +48,34 @@ function poco_init(App $a) { 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), @@ -81,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 { @@ -95,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) { @@ -116,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`, @@ -145,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; @@ -175,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); @@ -241,108 +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); - - + } } From eaf93dc041385bd5b556f11cc97bd03e05ffaf24 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 Mar 2017 17:23:02 +0000 Subject: [PATCH 46/60] I guess, @Hypolite will still find something to change ... --- mod/admin.php | 330 +++++++++++++++++++++++++++----------------------- 1 file changed, 177 insertions(+), 153 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index e1c73ac00a..83a46503bc 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 ''; @@ -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=='Friendi%%a') { + 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); @@ -506,19 +518,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 +563,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'); } @@ -670,14 +682,14 @@ function admin_page_site_post(App $a) { $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:'), @@ -695,8 +707,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:'), @@ -736,7 +747,7 @@ function admin_page_site_post(App $a) { 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"), @@ -746,7 +757,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); @@ -754,12 +765,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); @@ -819,7 +830,7 @@ function admin_page_site_post(App $a) { 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); @@ -847,7 +858,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'); @@ -858,12 +869,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); @@ -875,7 +886,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; @@ -924,8 +935,9 @@ 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); @@ -950,9 +962,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); @@ -1091,42 +1103,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'); @@ -1139,8 +1154,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; } } @@ -1180,7 +1196,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, @@ -1231,31 +1247,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); } } @@ -1276,31 +1292,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 @@ -1316,7 +1332,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); } @@ -1333,22 +1349,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` @@ -1362,7 +1378,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'),
    @@ -1388,22 +1404,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));
     	}
     
    @@ -1480,19 +1495,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));
    @@ -1509,22 +1524,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); @@ -1616,8 +1631,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; } @@ -1636,8 +1651,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 { @@ -1655,11 +1670,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']; } } @@ -1689,15 +1705,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? @@ -1712,12 +1731,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 ''; } @@ -1726,25 +1746,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)); } @@ -1757,22 +1776,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; @@ -1783,8 +1802,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); } @@ -1797,9 +1818,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( @@ -1845,7 +1866,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'])); } } @@ -1970,25 +1991,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); @@ -2016,22 +2037,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); + } } } @@ -2055,18 +2078,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'))) From 8517ba1fab5257fbd3e5cb99677797b5dd9ed69e Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 13 Mar 2017 23:08:03 +0100 Subject: [PATCH 47/60] Remove extra space after open parentheses --- include/auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/auth.php b/include/auth.php index 8512abe486..57e9d9bf61 100644 --- a/include/auth.php +++ b/include/auth.php @@ -179,7 +179,7 @@ if (isset($_SESSION) && x($_SESSION,'authenticated') && (!x($_POST,'auth-params' goaway(z_root()); } - if ( ! $_POST['remember']) { + if (! $_POST['remember']) { new_cookie(0); // 0 means delete on browser exit } From 0b46a5f935e7e3a669e68455dce294dc70a94182 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 13 Mar 2017 23:09:09 +0100 Subject: [PATCH 48/60] Standards: add braces (thanks @Hypolite) --- include/security.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/security.php b/include/security.php index 23fc400b3a..afb37a72d8 100644 --- a/include/security.php +++ b/include/security.php @@ -21,15 +21,18 @@ function cookie_hash($user) { */ function new_cookie($time, $user = array()) { - if ($time != 0) + if ($time != 0) { $time = $time + time(); + } - if ($user) + if ($user) { $value = json_encode(array("uid" => $user["uid"], "hash" => cookie_hash($user), "ip" => $_SERVER['REMOTE_ADDR'])); - else + } + else { $value = ""; + } setcookie("Friendica", $value, $time, "/", "", (get_config('system', 'ssl_policy') == SSL_POLICY_FULL), true); From a2b7b2a968bef61b8fc4c6f40cf936e2bfb7cd1d Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 Mar 2017 22:16:09 +0000 Subject: [PATCH 49/60] Daily updating the server status --- include/cron.php | 2 ++ include/discover_poco.php | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/cron.php b/include/cron.php index 2fc8de51c5..cf9b9fc622 100644 --- a/include/cron.php +++ b/include/cron.php @@ -123,6 +123,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); diff --git a/include/discover_poco.php b/include/discover_poco.php index 9a32790ea0..9de0303208 100644 --- a/include/discover_poco.php +++ b/include/discover_poco.php @@ -35,6 +35,7 @@ function discover_poco_run(&$argv, &$argc){ - 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(($argc > 2) && ($argv[1] == "dirsearch")) { @@ -46,6 +47,8 @@ function discover_poco_run(&$argv, &$argc){ $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; @@ -64,7 +67,9 @@ function discover_poco_run(&$argv, &$argc){ logger('start '.$search); - if ($mode == 4) { + if ($mode == 5) { + update_server(); + } elseif ($mode == 4) { $server_url = base64_decode($argv[2]); if ($server_url == "") { return; @@ -102,6 +107,34 @@ 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; + } +echo $server["url"]."\n"; + 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); From 748caa0807ef13dd8591a689fab07149eaa07f72 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 14 Mar 2017 04:58:05 +0000 Subject: [PATCH 50/60] Removed debug output --- include/discover_poco.php | 1 - 1 file changed, 1 deletion(-) diff --git a/include/discover_poco.php b/include/discover_poco.php index 9de0303208..91cc0b6083 100644 --- a/include/discover_poco.php +++ b/include/discover_poco.php @@ -124,7 +124,6 @@ function update_server() { if (!poco_do_update($server["created"], "", $server["last_failure"], $server["last_contact"])) { continue; } -echo $server["url"]."\n"; logger('Update server status for server '.$server["url"], LOGGER_DEBUG); proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", base64_encode($server["url"])); From f73389dd125157a87e638d99be20847f5255c4b6 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 14 Mar 2017 15:17:21 +0000 Subject: [PATCH 51/60] Standard stuff --- include/cron.php | 4 ++-- include/cronhooks.php | 2 +- include/dbupdate.php | 2 +- include/delivery.php | 8 ++++---- include/directory.php | 2 +- include/discover_poco.php | 2 +- include/gprobe.php | 4 ++-- include/notifier.php | 6 +++--- include/onepoll.php | 2 +- include/pubsubpublish.php | 2 +- include/update_gcontact.php | 7 ++++--- 11 files changed, 21 insertions(+), 20 deletions(-) diff --git a/include/cron.php b/include/cron.php index d2471c2bf7..0ae336e33f 100644 --- a/include/cron.php +++ b/include/cron.php @@ -1,8 +1,8 @@ 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; } From 0d32f0be4674a9631f13f2f3342f3b02039f7a5f Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 14 Mar 2017 15:18:56 +0000 Subject: [PATCH 52/60] One forgotten standard --- include/cronhooks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cronhooks.php b/include/cronhooks.php index 8fa62e1b91..bea0f6a198 100644 --- a/include/cronhooks.php +++ b/include/cronhooks.php @@ -45,7 +45,7 @@ function cronhooks_run(&$argv, &$argc){ logger('cronhooks: end'); - set_config('system','last_cronhook', time()); + set_config('system', 'last_cronhook', time()); return; } From 0143369e54bb8a0c7b6c9b970ffcde1fd60171ff Mon Sep 17 00:00:00 2001 From: rabuzarus Date: Tue, 14 Mar 2017 18:31:03 +0100 Subject: [PATCH 53/60] limit pagination page buttons to max 10 --- include/text.php | 9 +++-- view/theme/frio/css/style.css | 52 +++++++++++++++++++++----- view/theme/frio/templates/paginate.tpl | 16 ++++---- 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/include/text.php b/include/text.php index 580bd95fc7..6619dec93a 100644 --- a/include/text.php +++ b/include/text.php @@ -291,8 +291,8 @@ function paginate_data(App $a, $count = null) { } $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); @@ -318,9 +318,10 @@ function paginate_data(App $a, $count = null) { $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(); diff --git a/view/theme/frio/css/style.css b/view/theme/frio/css/style.css index 34bcb833db..8d7a5f7696 100644 --- a/view/theme/frio/css/style.css +++ b/view/theme/frio/css/style.css @@ -2509,21 +2509,53 @@ body .tread-wrapper .hovercard:hover .hover-card-content a { } /* Pagination improvements */ +.pagination { + text-align: center; + display: block; +} .pagination > li > a, .pagination > li > span { - color: $link_color; + color: $link_color; + float: none; } -.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; +.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; } -.disabled > a { - pointer-events: none; +.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; } /* diff --git a/view/theme/frio/templates/paginate.tpl b/view/theme/frio/templates/paginate.tpl index ab65cdd406..252dd7e5b0 100644 --- a/view/theme/frio/templates/paginate.tpl +++ b/view/theme/frio/templates/paginate.tpl @@ -1,14 +1,16 @@ + {{* Pager template, uses output of paginate_data() in include/text.php *}} + {{if $pager}} -
    - {{if $pager.first}}
  • {{$pager.first.text}}
  • {{/if}} +
    + {{if $pager.last}}
  • >∣
  • {{/if}} + {{/if}} From 35ec1c8f266d944f1b4d0359cd80a35c2f120ffa Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 14 Mar 2017 21:14:09 +0000 Subject: [PATCH 54/60] Bugfix for pull request 3216 - feed items were mixed --- include/feed.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/feed.php b/include/feed.php index e0fef50dbb..13833d22ef 100644 --- a/include/feed.php +++ b/include/feed.php @@ -177,6 +177,10 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { foreach (array_reverse($entrylist) AS $entry) { $item = array_merge($header, $author); + $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") @@ -217,10 +221,6 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { 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 == "") From dc3fcf0487f67c50e19d166a64229f63e577c42a Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 15 Mar 2017 06:00:22 +0000 Subject: [PATCH 55/60] Standard stuff --- include/feed.php | 203 +++++++++++++++++++++++++---------------------- 1 file changed, 108 insertions(+), 95 deletions(-) diff --git a/include/feed.php b/include/feed.php index 13833d22ef..2959933703 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,37 +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); $alternate = $xpath->query("atom:link[@rel='alternate']", $entry)->item(0)->attributes; - if (!is_object($alternate)) + 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") + } + 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) { @@ -215,50 +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; - + } $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); + } } ?> From 35ba3cce709d761fb396541fc5a6678efe44c780 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 15 Mar 2017 14:42:34 -0400 Subject: [PATCH 56/60] Fix wrong deferred function name --- view/theme/frio/js/textedit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/theme/frio/js/textedit.js b/view/theme/frio/js/textedit.js index 02191f33de..d212ee0038 100644 --- a/view/theme/frio/js/textedit.js +++ b/view/theme/frio/js/textedit.js @@ -181,7 +181,7 @@ function dropItem(url, elementId) { $el.fadeTo('fast', 0.33, function () { $.get(url).then(function() { $el.remove(); - }).error(function() { + }).fail(function() { // @todo Show related error message $el.show(); }).always(function() { From 4812f4c0f93915c20e4b3a9727fe0535a9d72721 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 16 Mar 2017 07:30:59 +0000 Subject: [PATCH 57/60] Without only the worker queue we don't need the deliverq anymore. --- database.sql | 14 +------------- include/dbstructure.php | 12 ------------ include/delivery.php | 24 ------------------------ include/notifier.php | 31 ++----------------------------- include/queue.php | 8 -------- 5 files changed, 3 insertions(+), 86 deletions(-) diff --git a/database.sql b/database.sql index b133489e4e..c7ab893d72 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/dbstructure.php b/include/dbstructure.php index 4ad54e6ba2..c1ed4bb986 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/delivery.php b/include/delivery.php index c48e606f48..faa1cad674 100644 --- a/include/delivery.php +++ b/include/delivery.php @@ -30,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; } diff --git a/include/notifier.php b/include/notifier.php index ada871e927..e3d7d10d6b 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -471,7 +471,8 @@ 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) ); } @@ -480,28 +481,12 @@ function notifier_run(&$argv, &$argc){ 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']) - ); - } - } - - 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); proc_run(PRIORITY_HIGH,'include/delivery.php', $cmd, $item_id, $contact['id']); - continue; } } @@ -553,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 diff --git a/include/queue.php b/include/queue.php index 67119aea44..c0c73cda61 100644 --- a/include/queue.php +++ b/include/queue.php @@ -29,14 +29,6 @@ function queue_run(&$argv, &$argc){ // Handling the pubsubhubbub requests proc_run(PRIORITY_HIGH,'include/pubsubpublish.php'); - $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']); - } - } - $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"); From 58bf1c50afc1c442776c549b2481939b157269dc Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 16 Mar 2017 09:23:12 +0000 Subject: [PATCH 58/60] Bugfix: When a query fails we mustn't use the result value. --- include/dba.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/dba.php b/include/dba.php index 4b0498ad3c..62728acaed 100644 --- a/include/dba.php +++ b/include/dba.php @@ -234,7 +234,9 @@ class dba { case 'pdo': $result = @$this->db->query($sql); // Is used to separate between queries that returning data - or not - $columns = $result->columnCount(); + if (!is_bool($result)) { + $columns = $result->columnCount(); + } break; case 'mysqli': $result = @$this->db->query($sql); @@ -329,7 +331,7 @@ class dba { } } - if (($result === true) || ($result === false)) { + if (is_bool($result)) { return $result; } if ($onlyquery) { From 24a57020b92b468607d4b3c9eb61b26f26bb6ce2 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 16 Mar 2017 21:34:53 +0000 Subject: [PATCH 59/60] Better version transformation for nodeinfo and statistics.json --- include/socgraph.php | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index 549e7c0dd2..05f47e659d 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -823,6 +823,9 @@ function poco_fetch_nodeinfo($server_url) { 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']); } } @@ -1186,21 +1189,28 @@ function poco_check_server($server_url, $network = "", $force = false) { $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(); @@ -1212,14 +1222,22 @@ function poco_check_server($server_url, $network = "", $force = false) { $server = poco_fetch_nodeinfo($server_url); if ($server) { $register_policy = $server['register_policy']; - $platform = $server['platform']; - $network = $server['network']; - if ($version == "") { + if (isset($server['platform'])) { + $platform = $server['platform']; + } + + if (isset($server['network'])) { + $network = $server['network']; + } + + if (isset($server['version'])) { $version = $server['version']; } - $site_name = $server['site_name']; + if (isset($server['site_name'])) { + $site_name = $server['site_name']; + } $last_contact = datetime_convert(); } From f3bcf63d465d7ec7902d8f3ec08fd377a71c4bf8 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 17 Mar 2017 19:25:01 +0000 Subject: [PATCH 60/60] Standards and some logging improvements --- include/discover_poco.php | 57 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/include/discover_poco.php b/include/discover_poco.php index 8e392f67d3..f0bfb646bd 100644 --- a/include/discover_poco.php +++ b/include/discover_poco.php @@ -5,7 +5,7 @@ use \Friendica\Core\Config; require_once('include/socgraph.php'); require_once('include/datetime.php'); -function discover_poco_run(&$argv, &$argc){ +function discover_poco_run(&$argv, &$argc) { /* This function can be called in these ways: @@ -19,13 +19,13 @@ function discover_poco_run(&$argv, &$argc){ 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")) { + } elseif (($argc == 3) && ($argv[1] == "server")) { $mode = 4; - } elseif(($argc == 2) && ($argv[1] == "update_server")) { + } elseif (($argc == 2) && ($argv[1] == "update_server")) { $mode = 5; } elseif ($argc == 1) { $search = ""; @@ -113,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) { @@ -140,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); @@ -171,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)); @@ -179,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); } @@ -224,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) {