1
0
Fork 0

Merge remote-tracking branch 'upstream/develop' into 1512-ostatus-comment

Conflicts:
	include/ostatus.php
This commit is contained in:
Michael Vogel 2015-12-22 11:25:37 +01:00
commit 307beb47fd
57 changed files with 13448 additions and 11711 deletions

View file

@ -192,9 +192,6 @@ function unmark_for_death($contact) {
}}
function get_contact_details_by_url($url, $uid = -1) {
require_once("mod/proxy.php");
require_once("include/bbcode.php");
if ($uid == -1)
$uid = local_user();
@ -268,15 +265,6 @@ function get_contact_details_by_url($url, $uid = -1) {
} else
$profile["cid"] = 0;
if (isset($profile["photo"]))
$profile["photo"] = proxy_url($profile["photo"], false, PROXY_SIZE_SMALL);
if (isset($profile["location"]))
$profile["location"] = bbcode($profile["location"]);
if (isset($profile["about"]))
$profile["about"] = bbcode($profile["about"]);
if (($profile["cid"] == 0) AND ($profile["network"] == NETWORK_DIASPORA)) {
$profile["location"] = "";
$profile["about"] = "";

View file

@ -2,6 +2,27 @@
/* To-Do:
- Automatically detect if incoming data is HTML or BBCode
*/
/* Contact details:
Gerhard Seeber Mail: gerhard@seeber.at Friendica: http://mozartweg.dyndns.org/friendica/gerhard
*/
/*
* Change history:
Gerhard Seeber 2015-NOV-25 Add API call /friendica/group_show to return all or a single group
with the containing contacts (necessary for Windows 10 Universal app)
Gerhard Seeber 2015-NOV-27 Add API call /friendica/group_delete to delete the specified group id
(necessary for Windows 10 Universal app)
Gerhard Seeber 2015-DEC-01 Add API call /friendica/group_create to create a group with the specified
name and the given list of contacts (necessary for Windows 10 Universal
app)
Gerhard Seeber 2015-DEC-07 Add API call /friendica/group_update to update a group with the given
list of contacts (necessary for Windows 10 Universal app)
*
*/
require_once("include/bbcode.php");
require_once("include/datetime.php");
require_once("include/conversation.php");
@ -16,6 +37,7 @@
require_once('mod/wall_upload.php');
require_once("mod/proxy.php");
require_once("include/message.php");
require_once("include/group.php");
/*
@ -3012,6 +3034,205 @@ function api_best_nickname(&$contacts) {
$contacts = array($contacts[0]);
}
// return all or a specified group of the user with the containing contacts
function api_friendica_group_show(&$a, $type) {
if (api_user()===false) return false;
// params
$user_info = api_get_user($a);
$gid = (x($_REQUEST,'gid') ? $_REQUEST['gid'] : 0);
$uid = $user_info['uid'];
// get data of the specified group id or all groups if not specified
if ($gid != 0) {
$r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d AND `id` = %d",
intval($uid),
intval($gid));
// error message if specified gid is not in database
if (count($r) == 0)
die(api_error($a, $type, 'gid not available'));
}
else
$r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d",
intval($uid));
// loop through all groups and retrieve all members for adding data in the user array
foreach ($r as $rr) {
$members = group_get_members($rr['id']);
$users = array();
foreach ($members as $member) {
$user = api_get_user($a, $member['nurl']);
$users[] = $user;
}
$grps[] = array('name' => $rr['name'], 'gid' => $rr['id'], 'user' => $users);
}
return api_apply_template("group_show", $type, array('$groups' => $grps));
}
api_register_func('api/friendica/group_show', 'api_friendica_group_show', true);
// delete the specified group of the user
function api_friendica_group_delete(&$a, $type) {
if (api_user()===false) return false;
// params
$user_info = api_get_user($a);
$gid = (x($_REQUEST,'gid') ? $_REQUEST['gid'] : 0);
$name = (x($_REQUEST, 'name') ? $_REQUEST['name'] : "");
$uid = $user_info['uid'];
// error if no gid specified
if ($gid == 0 || $name == "")
die(api_error($a, $type, 'gid or name not specified'));
// get data of the specified group id
$r = q("SELECT * FROM `group` WHERE `uid` = %d AND `id` = %d",
intval($uid),
intval($gid));
// error message if specified gid is not in database
if (count($r) == 0)
die(api_error($a, $type, 'gid not available'));
// get data of the specified group id and group name
$rname = q("SELECT * FROM `group` WHERE `uid` = %d AND `id` = %d AND `name` = '%s'",
intval($uid),
intval($gid),
dbesc($name));
// error message if specified gid is not in database
if (count($rname) == 0)
die(api_error($a, $type, 'wrong group name'));
// delete group
$ret = group_rmv($uid, $name);
if ($ret) {
// return success
$success = array('success' => $ret, 'gid' => $gid, 'name' => $name, 'status' => 'deleted', 'wrong users' => array());
return api_apply_template("group_delete", $type, array('$result' => $success));
}
else
die(api_error($a, $type, 'other API error'));
}
api_register_func('api/friendica/group_delete', 'api_friendica_group_delete', true);
// create the specified group with the posted array of contacts
function api_friendica_group_create(&$a, $type) {
if (api_user()===false) return false;
// params
$user_info = api_get_user($a);
$name = (x($_REQUEST, 'name') ? $_REQUEST['name'] : "");
$uid = $user_info['uid'];
$json = json_decode($_POST['json'], true);
$users = $json['user'];
// error if no name specified
if ($name == "")
die(api_error($a, $type, 'group name not specified'));
// get data of the specified group name
$rname = q("SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' AND `deleted` = 0",
intval($uid),
dbesc($name));
// error message if specified group name already exists
if (count($rname) != 0)
die(api_error($a, $type, 'group name already exists'));
// check if specified group name is a deleted group
$rname = q("SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' AND `deleted` = 1",
intval($uid),
dbesc($name));
// error message if specified group name already exists
if (count($rname) != 0)
$reactivate_group = true;
// create group
$ret = group_add($uid, $name);
if ($ret)
$gid = group_byname($uid, $name);
else
die(api_error($a, $type, 'other API error'));
// add members
$erroraddinguser = false;
$errorusers = array();
foreach ($users as $user) {
$cid = $user['cid'];
// check if user really exists as contact
$contact = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d",
intval($cid),
intval($uid));
if (count($contact))
$result = group_add_member($uid, $name, $cid, $gid);
else {
$erroraddinguser = true;
$errorusers[] = $cid;
}
}
// return success message incl. missing users in array
$status = ($erroraddinguser ? "missing user" : ($reactivate_group ? "reactivated" : "ok"));
$success = array('success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers);
return api_apply_template("group_create", $type, array('result' => $success));
}
api_register_func('api/friendica/group_create', 'api_friendica_group_create', true);
// update the specified group with the posted array of contacts
function api_friendica_group_update(&$a, $type) {
if (api_user()===false) return false;
// params
$user_info = api_get_user($a);
$uid = $user_info['uid'];
$gid = (x($_REQUEST, 'gid') ? $_REQUEST['gid'] : 0);
$name = (x($_REQUEST, 'name') ? $_REQUEST['name'] : "");
$json = json_decode($_POST['json'], true);
$users = $json['user'];
// error if no name specified
if ($name == "")
die(api_error($a, $type, 'group name not specified'));
// error if no gid specified
if ($gid == "")
die(api_error($a, $type, 'gid not specified'));
// remove members
$members = group_get_members($gid);
foreach ($members as $member) {
$cid = $member['id'];
foreach ($users as $user) {
$found = ($user['cid'] == $cid ? true : false);
}
if (!$found) {
$ret = group_rmv_member($uid, $name, $cid);
}
}
// add members
$erroraddinguser = false;
$errorusers = array();
foreach ($users as $user) {
$cid = $user['cid'];
// check if user really exists as contact
$contact = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d",
intval($cid),
intval($uid));
if (count($contact))
$result = group_add_member($uid, $name, $cid, $gid);
else {
$erroraddinguser = true;
$errorusers[] = $cid;
}
}
// return success message incl. missing users in array
$status = ($erroraddinguser ? "missing user" : "ok");
$success = array('success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers);
return api_apply_template("group_update", $type, array('result' => $success));
}
api_register_func('api/friendica/group_update', 'api_friendica_group_update', true);
/*
To.Do:

View file

@ -5,6 +5,8 @@ require_once('include/security.php');
require_once('include/datetime.php');
function nuke_session() {
session_unset();
/*
new_cookie(0); // make sure cookie is deleted on browser close, as a security measure
unset($_SESSION['authenticated']);
@ -20,10 +22,11 @@ function nuke_session() {
unset($_SESSION['my_address']);
unset($_SESSION['addr']);
unset($_SESSION['return_url']);
*/
}
// login/logout
// login/logout
@ -31,7 +34,7 @@ function nuke_session() {
if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-params'))) || ($_POST['auth-params'] !== 'login'))) {
if(((x($_POST,'auth-params')) && ($_POST['auth-params'] === 'logout')) || ($a->module === 'logout')) {
// process logout request
call_hooks("logging_out");
nuke_session();
@ -203,9 +206,14 @@ else {
}
function new_cookie($time) {
$a = get_app();
$old_sid = session_id();
session_set_cookie_params("$time");
session_set_cookie_params($time);
//session_set_cookie_params($time, "/", $a->get_hostname());
session_regenerate_id(false);
q("UPDATE session SET sid = '%s' WHERE sid = '%s'", dbesc(session_id()), dbesc($old_sid));
logger("Session parameter lifetime: ".$time." - got: ".print_r(session_get_cookie_params(), true), LOGGER_DEBUG);
}

View file

@ -951,7 +951,7 @@ function item_photo_menu($item){
* @param array &$conv_responses (already created with builtin activity structure)
* @return void
*/
if(! function_exists(builtin_activity_puller)) {
if(! function_exists('builtin_activity_puller')) {
function builtin_activity_puller($item, &$conv_responses) {
foreach($conv_responses as $mode => $v) {
$url = '';

View file

@ -44,10 +44,11 @@ function cron_run(&$argv, &$argc){
$maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1)
$maxsysload = 50;
if(function_exists('sys_getloadavg')) {
$load = sys_getloadavg();
if(intval($load[0]) > $maxsysload) {
logger('system: load ' . $load[0] . ' too high. cron deferred to next scheduled run.');
$load = current_load();
if($load) {
if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. cron deferred to next scheduled run.');
return;
}
}
@ -189,24 +190,39 @@ function cron_run(&$argv, &$argc){
q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime);
}
// maximum table size in megabyte
// Maximum table size in megabyte
$max_tablesize = intval(get_config('system','optimize_max_tablesize')) * 1000000;
if ($max_tablesize == 0)
$max_tablesize = 100 * 1000000; // Default are 100 MB
// Minimum fragmentation level in percent
$fragmentation_level = intval(get_config('system','optimize_fragmentation')) / 100;
if ($fragmentation_level == 0)
$fragmentation_level = 0.3; // Default value is 30%
// Optimize some tables that need to be optimized
$r = q("SHOW TABLE STATUS");
foreach($r as $table) {
// Don't optimize tables that needn't to be optimized
if ($table["Data_free"] == 0)
continue;
// Don't optimize tables that are too large
if ($table["Data_length"] > $max_tablesize)
continue;
// Don't optimize empty tables
if ($table["Data_length"] == 0)
continue;
// Calculate fragmentation
$fragmentation = $table["Data_free"] / $table["Data_length"];
logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG);
// Don't optimize tables that needn't to be optimized
if ($fragmentation < $fragmentation_level)
continue;
// So optimize it
logger("Optimize Table ".$table["Name"], LOGGER_DEBUG);
q("OPTIMIZE TABLE `%s`", dbesc($table["Name"]));
}

View file

@ -27,10 +27,11 @@ function cronhooks_run(&$argv, &$argc){
$maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1)
$maxsysload = 50;
if(function_exists('sys_getloadavg')) {
$load = sys_getloadavg();
if(intval($load[0]) > $maxsysload) {
logger('system: load ' . $load[0] . ' too high. Cronhooks deferred to next scheduled run.');
$load = current_load();
if($load) {
if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. Cronhooks deferred to next scheduled run.');
return;
}
}

View file

@ -59,10 +59,11 @@ function delivery_run(&$argv, &$argc){
$maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1)
$maxsysload = 50;
if(function_exists('sys_getloadavg')) {
$load = sys_getloadavg();
if(intval($load[0]) > $maxsysload) {
logger('system: load ' . $load[0] . ' too high. Delivery deferred to next queue run.');
$load = current_load();
if($load) {
if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. Delivery deferred to next queue run.');
return;
}
}

View file

@ -28,10 +28,11 @@ function discover_poco_run(&$argv, &$argc){
$maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1)
$maxsysload = 50;
if(function_exists('sys_getloadavg')) {
$load = sys_getloadavg();
if(intval($load[0]) > $maxsysload) {
logger('system: load ' . $load[0] . ' too high. discover_poco deferred to next scheduled run.');
$load = current_load();
if($load) {
if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. discover_poco deferred to next scheduled run.');
return;
}
}

View file

@ -4,7 +4,8 @@
*/
require_once('include/forums.php');
require_once('include/bbcode.php');
require_once("mod/proxy.php");
/**
*
@ -108,7 +109,6 @@ if(! function_exists('profile_load')) {
else
$a->page['aside'] .= profile_sidebar($a->profile, $block);
/*if(! $block)
$a->page['aside'] .= contact_block();*/
@ -199,7 +199,7 @@ if(! function_exists('profile_sidebar')) {
if (($profile['network'] != "") AND ($profile['network'] != NETWORK_DFRN)) {
$profile['network_name'] = format_network_name($profile['network'],$profile['url']);
} else
} else
$profile['network_name'] = "";
call_hooks('profile_sidebar_enter', $profile);
@ -287,11 +287,11 @@ if(! function_exists('profile_sidebar')) {
}
// check if profile is a forum
if((x($profile['page-flags']) == 2)
|| (x($profile['page-flags']) == 5)
|| (x($profile['forum']))
|| (x($profile['prv']))
|| (x($profile['community'])))
if((intval($profile['page-flags']) == PAGE_COMMUNITY)
|| (intval($profile['page-flags']) == PAGE_PRVGROUP)
|| (intval($profile['forum']))
|| (intval($profile['prv']))
|| (intval($profile['community'])))
$account_type = t('Forum');
else
$account_type = "";
@ -360,6 +360,15 @@ if(! function_exists('profile_sidebar')) {
$p[$k] = $v;
}
if (isset($p["about"]))
$p["about"] = bbcode($p["about"]);
if (isset($p["location"]))
$p["location"] = bbcode($p["location"]);
if (isset($p["photo"]))
$p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
if($a->theme['template_engine'] === 'internal')
$location = template_escape($location);

View file

@ -4402,7 +4402,7 @@ function atom_author($tag,$name,$uri,$h,$w,$photo,$geo) {
$o .= "\t<poco:preferredUsername>".xmlify($r[0]["nick"])."</poco:preferredUsername>\r\n";
$o .= "\t<poco:displayName>".xmlify($r[0]["name"])."</poco:displayName>\r\n";
$o .= "\t<poco:note>".xmlify($r[0]["about"])."</poco:note>\r\n";
$o .= "\t<poco:note>".xmlify(bbcode($r[0]["about"]))."</poco:note>\r\n";
$o .= "\t<poco:address>\r\n";
$o .= "\t\t<poco:formatted>".xmlify($location)."</poco:formatted>\r\n";
$o .= "\t</poco:address>\r\n";

View file

@ -2,6 +2,7 @@
require_once("include/Contact.php");
require_once("include/threads.php");
require_once("include/html2bbcode.php");
require_once("include/bbcode.php");
require_once("include/items.php");
require_once("mod/share.php");
require_once("include/enotify.php");
@ -142,7 +143,7 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch)
$value = $xpath->evaluate('atom:author/poco:note/text()', $context)->item(0)->nodeValue;
if ($value != "")
$contact["about"] = $value;
$contact["about"] = html2bbcode($value);
$value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue;
if ($value != "")

View file

@ -26,18 +26,22 @@ function poller_run(&$argv, &$argc){
unset($db_host, $db_user, $db_pass, $db_data);
};
if(function_exists('sys_getloadavg')) {
$load = current_load();
if($load) {
$maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1)
$maxsysload = 50;
$load = sys_getloadavg();
if(intval($load[0]) > $maxsysload) {
logger('system: load ' . $load[0] . ' too high. poller deferred to next scheduled run.');
if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. poller deferred to next scheduled run.');
return;
}
}
// Checking the number of workers
if (poller_too_much_workers(1))
return;
if(($argc <= 1) OR ($argv[1] != "no_cron")) {
// Run the cron job that calls all other jobs
proc_run("php","include/cron.php");
@ -57,17 +61,21 @@ function poller_run(&$argv, &$argc){
}
} else
// Sleep two seconds before checking for running processes to avoid having too many workers
// Sleep four seconds before checking for running processes again to avoid having too many workers
sleep(4);
// Checking number of workers
if (poller_too_much_workers())
if (poller_too_much_workers(2))
return;
$starttime = time();
while ($r = q("SELECT * FROM `workerqueue` WHERE `executed` = '0000-00-00 00:00:00' ORDER BY `created` LIMIT 1")) {
// Count active workers and compare them with a maximum value that depends on the load
if (poller_too_much_workers(3))
return;
q("UPDATE `workerqueue` SET `executed` = '%s', `pid` = %d WHERE `id` = %d AND `executed` = '0000-00-00 00:00:00'",
dbesc(datetime_convert()),
intval(getmypid()),
@ -100,10 +108,10 @@ function poller_run(&$argv, &$argc){
$funcname=str_replace(".php", "", basename($argv[0]))."_run";
if (function_exists($funcname)) {
logger("Process ".getmypid().": ".$funcname." ".$r[0]["parameter"]);
logger("Process ".getmypid()." - ID ".$r[0]["id"].": ".$funcname." ".$r[0]["parameter"]);
$funcname($argv, $argc);
logger("Process ".getmypid().": ".$funcname." - done");
logger("Process ".getmypid()." - ID ".$r[0]["id"].": ".$funcname." - done");
q("DELETE FROM `workerqueue` WHERE `id` = %d", intval($r[0]["id"]));
} else
@ -112,15 +120,11 @@ function poller_run(&$argv, &$argc){
// Quit the poller once every hour
if (time() > ($starttime + 3600))
return;
// Count active workers and compare them with a maximum value that depends on the load
if (poller_too_much_workers())
return;
}
}
function poller_too_much_workers() {
function poller_too_much_workers($stage) {
$queues = get_config("system", "worker_queues");
@ -130,9 +134,8 @@ function poller_too_much_workers() {
$active = poller_active_workers();
// Decrease the number of workers at higher load
if(function_exists('sys_getloadavg')) {
$load = max(sys_getloadavg());
$load = current_load();
if($load) {
$maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1)
$maxsysload = 50;
@ -144,7 +147,7 @@ function poller_too_much_workers() {
$slope = $maxworkers / pow($maxsysload, $exponent);
$queues = ceil($slope * pow(max(0, $maxsysload - $load), $exponent));
logger("Current load: ".$load." - maximum: ".$maxsysload." - current queues: ".$active." - maximum: ".$queues, LOGGER_DEBUG);
logger("Current load stage ".$stage.": ".$load." - maximum: ".$maxsysload." - current queues: ".$active." - maximum: ".$queues, LOGGER_DEBUG);
}

View file

@ -79,7 +79,7 @@ ini_set('session.gc_probability', $gc_probability);
ini_set('session.use_only_cookies', 1);
ini_set('session.cookie_httponly', 1);
session_set_save_handler ('ref_session_open', 'ref_session_close',
'ref_session_read', 'ref_session_write',
'ref_session_destroy', 'ref_session_gc');
if (!get_config('system', 'disable_database_session'))
session_set_save_handler('ref_session_open', 'ref_session_close',
'ref_session_read', 'ref_session_write',
'ref_session_destroy', 'ref_session_gc');