Merge branch 'develop' of github.com:friendica/friendica into rhaeder-develop

This commit is contained in:
Roland Haeder 2016-03-12 18:50:14 +01:00
commit c60605ce0c
No known key found for this signature in database
GPG key ID: B72F8185C6C7BD78
50 changed files with 2266 additions and 1619 deletions

View file

@ -34,22 +34,17 @@ function cron_run(&$argv, &$argc){
require_once('include/Contact.php');
require_once('include/email.php');
require_once('include/socgraph.php');
require_once('include/pidfile.php');
require_once('mod/nodeinfo.php');
load_config('config');
load_config('system');
$maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1)
$maxsysload = 50;
$load = current_load();
if($load) {
if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. cron deferred to next scheduled run.');
// Don't check this stuff if the function is called by the poller
if (App::callstack() != "poller_run") {
if (App::maxload_reached())
return;
if (App::is_already_running('cron', 'include/cron.php', 540))
return;
}
}
$last = get_config('system','last_cron');
@ -66,23 +61,6 @@ function cron_run(&$argv, &$argc){
}
}
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, 'cron');
if($pidfile->is_already_running()) {
logger("cron: Already running");
if ($pidfile->running_time() > 9*60) {
$pidfile->kill();
logger("cron: killed stale process");
// Calling a new instance
proc_run('php','include/cron.php');
}
exit;
}
}
$a->set_baseurl(get_config('system','url'));
load_hooks();
@ -379,7 +357,7 @@ function cron_clear_cache(&$a) {
continue;
// Calculate fragmentation
$fragmentation = $table["Data_free"] / $table["Data_length"];
$fragmentation = $table["Data_free"] / ($table["Data_length"] + $table["Index_length"]);
logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG);

View file

@ -19,21 +19,16 @@ function cronhooks_run(&$argv, &$argc){
require_once('include/session.php');
require_once('include/datetime.php');
require_once('include/pidfile.php');
load_config('config');
load_config('system');
$maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1)
$maxsysload = 50;
$load = current_load();
if($load) {
if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. Cronhooks deferred to next scheduled run.');
// Don't check this stuff if the function is called by the poller
if (App::callstack() != "poller_run") {
if (App::maxload_reached())
return;
if (App::is_already_running('cronhooks', 'include/cronhooks.php', 1140))
return;
}
}
$last = get_config('system','last_cronhook');
@ -50,21 +45,6 @@ function cronhooks_run(&$argv, &$argc){
}
}
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, 'cronhooks');
if($pidfile->is_already_running()) {
logger("cronhooks: Already running");
if ($pidfile->running_time() > 19*60) {
$pidfile->kill();
logger("cronhooks: killed stale process");
// Calling a new instance
proc_run('php','include/cronhooks.php');
}
exit;
}
}
$a->set_baseurl(get_config('system','url'));
load_hooks();

View file

@ -57,17 +57,8 @@ function delivery_run(&$argv, &$argc){
continue;
}
$maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1)
$maxsysload = 50;
$load = current_load();
if($load) {
if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. Delivery deferred to next queue run.');
return;
}
}
if (App::maxload_reached())
return;
// It's ours to deliver. Remove it from the queue.

View file

@ -700,12 +700,10 @@ function diaspora_request($importer,$xml) {
return;
}
$g = q("select def_gid from user where uid = %d limit 1",
intval($importer['uid'])
);
if($g && intval($g[0]['def_gid'])) {
$def_gid = get_default_group($importer['uid'], $ret["network"]);
if (intval($def_gid)) {
require_once('include/group.php');
group_add_member($importer['uid'],'',$contact_record['id'],$g[0]['def_gid']);
group_add_member($importer['uid'], '', $contact_record['id'], $def_gid);
}
if($importer['page-flags'] == PAGE_NORMAL) {

View file

@ -20,22 +20,14 @@ function discover_poco_run(&$argv, &$argc){
require_once('include/session.php');
require_once('include/datetime.php');
require_once('include/pidfile.php');
load_config('config');
load_config('system');
$maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1)
$maxsysload = 50;
$load = current_load();
if($load) {
if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. discover_poco deferred to next scheduled run.');
// Don't check this stuff if the function is called by the poller
if (App::callstack() != "poller_run")
if (App::maxload_reached())
return;
}
}
if(($argc > 2) && ($argv[1] == "dirsearch")) {
$search = urldecode($argv[2]);
@ -50,21 +42,10 @@ function discover_poco_run(&$argv, &$argc){
} else
die("Unknown or missing parameter ".$argv[1]."\n");
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, 'discover_poco'.$mode.urlencode($search));
if($pidfile->is_already_running()) {
logger("discover_poco: Already running");
if ($pidfile->running_time() > 19*60) {
$pidfile->kill();
logger("discover_poco: killed stale process");
// Calling a new instance
if ($mode == 0)
proc_run('php','include/discover_poco.php');
}
exit;
}
}
// 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'));

View file

@ -258,12 +258,10 @@ function new_contact($uid,$url,$interactive = false) {
$contact_id = $r[0]['id'];
$result['cid'] = $contact_id;
$g = q("select def_gid from user where uid = %d limit 1",
intval($uid)
);
if($g && intval($g[0]['def_gid'])) {
$def_gid = get_default_group($uid, $contact["network"]);
if (intval($def_gid)) {
require_once('include/group.php');
group_add_member($uid,'',$contact_id,$g[0]['def_gid']);
group_add_member($uid, '', $contact_id, $def_gid);
}
require_once("include/Photo.php");

View file

@ -188,7 +188,7 @@ function group_public_members($gid) {
}
function mini_group_select($uid,$gid = 0) {
function mini_group_select($uid,$gid = 0, $label = "") {
$grps = array();
$o = '';
@ -205,8 +205,11 @@ function mini_group_select($uid,$gid = 0) {
}
logger('groups: ' . print_r($grps,true));
if ($label == "")
$label = t('Default privacy group for new contacts');
$o = replace_macros(get_markup_template('group_selection.tpl'), array(
'$label' => t('Default privacy group for new contacts'),
'$label' => $label,
'$groups' => $grps
));
return $o;
@ -375,3 +378,28 @@ function groups_count_unseen() {
return $r;
}
/**
* @brief Returns the default group for a given user and network
*
* @param int $uid User id
* @param string $network network name
*
* @return int group id
*/
function get_default_group($uid, $network = "") {
$default_group = 0;
if ($network == NETWORK_OSTATUS)
$default_group = get_pconfig($uid, "ostatus", "default_group");
if ($default_group != 0)
return $default_group;
$g = q("SELECT `def_gid` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
if($g && intval($g[0]["def_gid"]))
$default_group = $g[0]["def_gid"];
return $default_group;
}

View file

@ -31,7 +31,6 @@ function onepoll_run(&$argv, &$argc){
require_once('include/Contact.php');
require_once('include/email.php');
require_once('include/socgraph.php');
require_once('include/pidfile.php');
require_once('include/queue_fn.php');
load_config('config');
@ -60,18 +59,10 @@ function onepoll_run(&$argv, &$argc){
return;
}
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, 'onepoll'.$contact_id);
if ($pidfile->is_already_running()) {
logger("onepoll: Already running for contact ".$contact_id);
if ($pidfile->running_time() > 9*60) {
$pidfile->kill();
logger("killed stale process");
}
exit;
}
}
// 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();

View file

@ -537,7 +537,7 @@ function ostatus_import($xml,$importer,&$contact, &$hub) {
} else
$item["parent-uri"] = $item["uri"];
$item_id = ostatus_completion($conversation, $importer["uid"], $item);
$item_id = ostatus_completion($conversation, $importer["uid"], $item, $self);
if (!$item_id) {
logger("Error storing item", LOGGER_DEBUG);
@ -676,17 +676,101 @@ function ostatus_conv_fetch_actor($actor) {
update_gcontact($contact);
}
/**
* @brief Fetches the conversation url for a given item link or conversation id
*
* @param string $self The link to the posting
* @param string $conversation_id The conversation id
*
* @return string The conversation url
*/
function ostatus_fetch_conversation($self, $conversation_id = "") {
function ostatus_completion($conversation_url, $uid, $item = array()) {
if ($conversation_id != "") {
$elements = explode(":", $conversation_id);
if ((count($elements) <= 2) OR ($elements[0] != "tag"))
return $conversation_id;
}
if ($self == "")
return "";
$json = str_replace(".atom", ".json", $self);
$raw = fetch_url($json);
if ($raw == "")
return "";
$data = json_decode($raw);
if (!is_object($data))
return "";
$conversation_id = $data->statusnet_conversation_id;
$pos = strpos($self, "/api/statuses/show/");
$base_url = substr($self, 0, $pos);
return $base_url."/conversation/".$conversation_id;
}
/**
* @brief Fetches actor details of a given actor and user id
*
* @param string $actor The actor url
* @param int $uid The user id
* @param int $contact_id The default contact-id
*
* @return array Array with actor details
*/
function ostatus_get_actor_details($actor, $uid, $contact_id) {
$details = array();
$contact = q("SELECT `id`, `rel`, `network` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'",
$uid, normalise_link($actor), NETWORK_STATUSNET);
if (!$contact)
$contact = q("SELECT `id`, `rel`, `network` FROM `contact` WHERE `uid` = %d AND `alias` IN ('%s', '%s') AND `network` != '%s'",
$uid, $actor, normalise_link($actor), NETWORK_STATUSNET);
if ($contact) {
logger("Found contact for url ".$actor, LOGGER_DEBUG);
$details["contact_id"] = $contact[0]["id"];
$details["network"] = $contact[0]["network"];
$details["not_following"] = !in_array($contact[0]["rel"], array(CONTACT_IS_SHARING, CONTACT_IS_FRIEND));
} else {
logger("No contact found for user ".$uid." and url ".$actor, LOGGER_DEBUG);
// Adding a global contact
/// @TODO Use this data for the post
$details["global_contact_id"] = get_contact($actor, 0);
logger("Global contact ".$global_contact_id." found for url ".$actor, LOGGER_DEBUG);
$details["contact_id"] = $contact_id;
$details["network"] = NETWORK_OSTATUS;
$details["not_following"] = true;
}
return $details;
}
function ostatus_completion($conversation_url, $uid, $item = array(), $self = "") {
$a = get_app();
$item_stored = -1;
$conversation_url = ostatus_convert_href($conversation_url);
//$conversation_url = ostatus_convert_href($conversation_url);
$conversation_url = ostatus_fetch_conversation($self, $conversation_url);
// If the thread shouldn't be completed then store the item and go away
if ((intval(get_config('system','ostatus_poll_interval')) == -2) AND (count($item) > 0)) {
// Don't do a completion on liked content
if (((intval(get_config('system','ostatus_poll_interval')) == -2) AND (count($item) > 0)) OR
($item["verb"] == ACTIVITY_LIKE) OR ($conversation_url == "")) {
//$arr["app"] .= " (OStatus-NoCompletion)";
$item_stored = item_store($item, true);
return($item_stored);
@ -725,7 +809,7 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
$pageno = 1;
$items = array();
logger('fetching conversation url '.$conv.' for user '.$uid);
logger('fetching conversation url '.$conv.' (Self: '.$self.') for user '.$uid);
do {
$conv_arr = z_fetch_url($conv."?page=".$pageno);
@ -778,6 +862,8 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
$r = q("SELECT `nurl` FROM `contact` WHERE `uid` = %d AND `self`", intval($uid));
$importer = $r[0];
$new_parent = true;
foreach ($items as $single_conv) {
// Update the gcontact table
@ -809,6 +895,9 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
// 2. This first post is a post inside our thread
// 3. This first post is a post inside another thread
if (($first_id != $parent["uri"]) AND ($parent["uri"] != "")) {
$new_parent = true;
$new_parents = q("SELECT `id`, `parent`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `id` IN
(SELECT `parent` FROM `item`
WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s')) LIMIT 1",
@ -909,30 +998,20 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
if (isset($single_conv->actor->url))
$actor = $single_conv->actor->url;
$contact = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'",
$uid, normalise_link($actor), NETWORK_STATUSNET);
$details = ostatus_get_actor_details($actor, $uid, $parent["contact-id"]);
if (count($contact)) {
logger("Found contact for url ".$actor, LOGGER_DEBUG);
$contact_id = $contact[0]["id"];
} else {
logger("No contact found for url ".$actor, LOGGER_DEBUG);
// Adding a global contact
/// @TODO Use this data for the post
$global_contact_id = get_contact($actor, 0);
logger("Global contact ".$global_contact_id." found for url ".$actor, LOGGER_DEBUG);
$contact_id = $parent["contact-id"];
// Do we only want to import threads that were started by our contacts?
if ($details["not_following"] AND $new_parent AND get_config('system','ostatus_full_threads')) {
logger("Don't import uri ".$first_id." because user ".$uid." doesn't follow the person ".$actor, LOGGER_DEBUG);
continue;
}
$arr = array();
$arr["network"] = NETWORK_OSTATUS;
$arr["network"] = $details["network"];
$arr["uri"] = $single_conv->id;
$arr["plink"] = $plink;
$arr["uid"] = $uid;
$arr["contact-id"] = $contact_id;
$arr["contact-id"] = $details["contact_id"];
$arr["parent-uri"] = $parent_uri;
$arr["created"] = $single_conv->published;
$arr["edited"] = $single_conv->published;
@ -1058,6 +1137,15 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
if (($item_stored < 0) AND (count($item) > 0)) {
//$arr["app"] .= " (OStatus-NoConvFound)";
if (get_config('system','ostatus_full_threads')) {
$details = ostatus_get_actor_details($item["owner-link"], $uid, $item["contact-id"]);
if ($details["not_following"]) {
logger("Don't import uri ".$item["uri"]." because user ".$uid." doesn't follow the person ".$item["owner-link"], LOGGER_DEBUG);
return false;
}
}
$item_stored = item_store($item, true);
if ($item_stored) {
logger("Uri ".$item["uri"]." wasn't found in conversation ".$conversation_url, LOGGER_DEBUG);

View file

@ -29,17 +29,8 @@ function poller_run(&$argv, &$argc){
if (poller_max_connections_reached())
return;
$load = current_load();
if($load) {
$maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1)
$maxsysload = 50;
if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. poller deferred to next scheduled run.');
return;
}
}
if (App::maxload_reached())
return;
// Checking the number of workers
if (poller_too_much_workers(1)) {

View file

@ -74,25 +74,14 @@ function pubsubpublish_run(&$argv, &$argc){
};
require_once('include/items.php');
require_once('include/pidfile.php');
load_config('config');
load_config('system');
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, 'pubsubpublish');
if($pidfile->is_already_running()) {
logger("Already running");
if ($pidfile->running_time() > 9*60) {
$pidfile->kill();
logger("killed stale process");
// Calling a new instance
proc_run('php',"include/pubsubpublish.php");
}
// 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'));

View file

@ -22,26 +22,15 @@ function queue_run(&$argv, &$argc){
require_once("include/datetime.php");
require_once('include/items.php');
require_once('include/bbcode.php');
require_once('include/pidfile.php');
require_once('include/socgraph.php');
load_config('config');
load_config('system');
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, 'queue');
if($pidfile->is_already_running()) {
logger("queue: Already running");
if ($pidfile->running_time() > 9*60) {
$pidfile->kill();
logger("queue: killed stale process");
// Calling a new instance
proc_run('php',"include/queue.php");
}
// Don't check this stuff if the function is called by the poller
if (App::callstack() != "poller_run")
if (App::is_already_running('queue', 'include/queue.php', 540))
return;
}
}
$a->set_baseurl(get_config('system','url'));

View file

@ -16,7 +16,6 @@ function update_gcontact_run(&$argv, &$argc){
unset($db_host, $db_user, $db_pass, $db_data);
};
require_once('include/pidfile.php');
require_once('include/Scrape.php');
require_once("include/socgraph.php");
@ -37,18 +36,10 @@ function update_gcontact_run(&$argv, &$argc){
return;
}
$lockpath = get_lockpath();
if ($lockpath != '') {
$pidfile = new pidfile($lockpath, 'update_gcontact'.$contact_id);
if ($pidfile->is_already_running()) {
logger("update_gcontact: Already running for contact ".$contact_id);
if ($pidfile->running_time() > 9*60) {
$pidfile->kill();
logger("killed stale process");
}
exit;
}
}
// 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));