Merge remote-tracking branch 'upstream/develop' into develop

pull/3236/head
Michael 6 years ago
commit 187a81f159

@ -1 +1 @@
3.5.1
3.5.2-dev

@ -38,7 +38,7 @@ require_once('include/dbstructure.php');
define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Asparagus');
define ( 'FRIENDICA_VERSION', '3.5.1' );
define ( 'FRIENDICA_VERSION', '3.5.2-dev' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1215 );
@ -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
*

@ -1,7 +1,5 @@
<?php
require_once('include/Probe.php');
// Included here for completeness, but this is a very dangerous operation.
// It is the caller's responsibility to confirm the requestor's intent and
// authorisation to do this.
@ -355,6 +353,7 @@ function get_contact_details_by_addr($addr, $uid = -1) {
dbesc($addr));
if (!dbm::is_result($r)) {
require_once('include/Probe.php');
$data = Probe::uri($addr);
$profile = get_contact_details_by_url($data['url'], $uid);
@ -508,72 +507,96 @@ function contacts_not_grouped($uid,$start = 0,$count = 0) {
/**
* @brief Fetch the contact id for a given url and user
*
* First lookup in the contact table to find a record matching either `url`, `nurl`,
* `addr` or `alias`.
*
* If there's no record and we aren't looking for a public contact, we quit.
* If there's one, we check that it isn't time to update the picture else we
* directly return the found contact id.
*
* Second, we probe the provided $url wether it's http://server.tld/profile or
* nick@server.tld. We quit if we can't get any info back.
*
* Third, we create the contact record if it doesn't exist
*
* Fourth, we update the existing record with the new data (avatar, alias, nick)
* if there's any updates
*
* @param string $url Contact URL
* @param integer $uid The user id for the contact
* @param integer $uid The user id for the contact (0 = public contact)
* @param boolean $no_update Don't update the contact
*
* @return integer Contact ID
*/
function get_contact($url, $uid = 0, $no_update = false) {
require_once("include/Scrape.php");
logger("Get contact data for url ".$url." and user ".$uid." - ".App::callstack(), LOGGER_DEBUG);;
$data = array();
$contactid = 0;
// is it an address in the format user@server.tld?
/// @todo use gcontact and/or the addr field for a lookup
if (!strstr($url, "http") OR strstr($url, "@")) {
$data = probe_url($url);
$url = $data["url"];
if ($url == "")
return 0;
}
$contact_id = 0;
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
// We first try the nurl (http://server.tld/nick), most common case
$contacts = q("SELECT `id`, `avatar-date` FROM `contact`
WHERE `nurl` = '%s'
AND `uid` = %d",
dbesc(normalise_link($url)),
intval($uid));
if (!$contact)
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `uid` = %d ORDER BY `id` LIMIT 1",
dbesc($url),
dbesc(normalise_link($url)),
intval($uid));
if ($contact) {
$contactid = $contact[0]["id"];
// Then the addr (nick@server.tld)
if (! dbm::is_result($contacts)) {
$contacts = q("SELECT `id`, `avatar-date` FROM `contact`
WHERE `addr` = '%s'
AND `uid` = %d",
dbesc($url),
intval($uid));
}
// Then the alias (which could be anything)
if (! dbm::is_result($contacts)) {
$contacts = q("SELECT `id`, `avatar-date` FROM `contact`
WHERE `alias` IN ('%s', '%s')
AND `uid` = %d",
dbesc($url),
dbesc(normalise_link($url)),
intval($uid));
}
if (dbm::is_result($contacts)) {
$contact_id = $contacts[0]["id"];
// Update the contact every 7 days
$update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -7 days'));
//$update_photo = ($contact[0]['avatar-date'] < datetime_convert('','','now -12 hours'));
$update_photo = ($contacts[0]['avatar-date'] < datetime_convert('','','now -7 days'));
if (!$update_photo OR $no_update) {
return($contactid);
return $contact_id;
}
} elseif ($uid != 0)
} elseif ($uid != 0) {
// Non-existing user-specific contact, exiting
return 0;
}
if (!count($data))
$data = probe_url($url);
require_once('include/Probe.php');
$data = Probe::uri($url);
// Does this address belongs to a valid network?
if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) {
if ($uid != 0)
// Last try in gcontact for unsupported networks
if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_PUMPIO))) {
if ($uid != 0) {
return 0;
}
// Get data from the gcontact table
$r = q("SELECT `name`, `nick`, `url`, `photo`, `addr`, `alias`, `network` FROM `gcontact` WHERE `nurl` = '%s'",
$gcontacts = q("SELECT `name`, `nick`, `url`, `photo`, `addr`, `alias`, `network` FROM `gcontact` WHERE `nurl` = '%s'",
dbesc(normalise_link($url)));
if (!$r)
if (!$gcontacts) {
return 0;
}
$data = $r[0];
$data = $gcontacts[0];
}
$url = $data["url"];
if ($contactid == 0) {
if (!$contact_id) {
q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
`name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`,
`batch`, `request`, `confirm`, `poco`, `name-date`, `uri-date`,
@ -602,45 +625,48 @@ function get_contact($url, $uid = 0, $no_update = false) {
dbesc(datetime_convert())
);
$contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
$contacts = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
dbesc(normalise_link($data["url"])),
intval($uid));
if (!$contact)
if (!dbm::is_result($contacts)) {
return 0;
}
$contactid = $contact[0]["id"];
$contact_id = $contacts[0]["id"];
// Update the newly created contact from data in the gcontact table
$r = q("SELECT `location`, `about`, `keywords`, `gender` FROM `gcontact` WHERE `nurl` = '%s'",
$gcontacts = q("SELECT `location`, `about`, `keywords`, `gender` FROM `gcontact` WHERE `nurl` = '%s'",
dbesc(normalise_link($data["url"])));
if ($r) {
logger("Update contact ".$data["url"]);
if (dbm::is_result($gcontacts)) {
logger("Update contact " . $data["url"] . ' from gcontact');
q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d",
dbesc($r["location"]), dbesc($r["about"]), dbesc($r["keywords"]),
dbesc($r["gender"]), intval($contactid));
dbesc($gcontacts[0]["location"]), dbesc($gcontacts[0]["about"]), dbesc($gcontacts[0]["keywords"]),
dbesc($gcontacts[0]["gender"]), intval($contact_id));
}
}
if ((count($contact) > 1) AND ($uid == 0) AND ($contactid != 0) AND ($url != ""))
if (count($contacts) > 1 AND $uid == 0 AND $contact_id != 0 AND $url != "") {
q("DELETE FROM `contact` WHERE `nurl` = '%s' AND `id` != %d AND NOT `self`",
dbesc(normalise_link($url)),
intval($contactid));
intval($contact_id));
}
require_once("Photo.php");
require_once "Photo.php";
update_contact_avatar($data["photo"],$uid,$contactid);
update_contact_avatar($data["photo"], $uid, $contact_id);
$r = q("SELECT `addr`, `alias`, `name`, `nick` FROM `contact` WHERE `id` = %d", intval($contactid));
$contacts = q("SELECT `addr`, `alias`, `name`, `nick` FROM `contact` WHERE `id` = %d", intval($contact_id));
// This condition should always be true
if (!dbm::is_result($r))
return $contactid;
if (!dbm::is_result($contacts)) {
return $contact_id;
}
// Only update if there had something been changed
if (($data["addr"] != $r[0]["addr"]) OR
($data["alias"] != $r[0]["alias"]) OR
($data["name"] != $r[0]["name"]) OR
($data["nick"] != $r[0]["nick"]))
if ($data["addr"] != $contacts[0]["addr"] OR
$data["alias"] != $contacts[0]["alias"] OR
$data["name"] != $contacts[0]["name"] OR
$data["nick"] != $contacts[0]["nick"]) {
q("UPDATE `contact` SET `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s',
`name-date` = '%s', `uri-date` = '%s' WHERE `id` = %d",
dbesc($data["addr"]),
@ -649,10 +675,11 @@ function get_contact($url, $uid = 0, $no_update = false) {
dbesc($data["nick"]),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($contactid)
intval($contact_id)
);
}
return $contactid;
return $contact_id;
}
/**
@ -675,15 +702,6 @@ function posts_from_gcontact(App $a, $gcontact_id) {
else
$sql = "`item`.`uid` = %d";
if(get_config('system', 'old_pager')) {
$r = q("SELECT COUNT(*) AS `total` FROM `item`
WHERE `gcontact-id` = %d and $sql",
intval($gcontact_id),
intval(local_user()));
$a->set_pager_total($r[0]['total']);
}
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
`author-name` AS `name`, `owner-avatar` AS `photo`,
`owner-link` AS `url`, `owner-avatar` AS `thumb`
@ -697,13 +715,9 @@ function posts_from_gcontact(App $a, $gcontact_id) {
intval($a->pager['itemspage'])
);
$o = conversation($a,$r,'community',false);
$o = conversation($a, $r, 'community', false);
if(!get_config('system', 'old_pager')) {
$o .= alt_pager($a,count($r));
} else {
$o .= paginate($a);
}
$o .= alt_pager($a, count($r));
return $o;
}
@ -736,15 +750,6 @@ function posts_from_contact_url(App $a, $contact_url) {
$author_id = intval($r[0]["author-id"]);
if (get_config('system', 'old_pager')) {
$r = q("SELECT COUNT(*) AS `total` FROM `item`
WHERE `author-id` = %d and $sql",
intval($author_id),
intval(local_user()));
$a->set_pager_total($r[0]['total']);
}
$r = q(item_query()." AND `item`.`author-id` = %d AND ".$sql.
" ORDER BY `item`.`created` DESC LIMIT %d, %d",
intval($author_id),
@ -753,13 +758,9 @@ function posts_from_contact_url(App $a, $contact_url) {
intval($a->pager['itemspage'])
);
$o = conversation($a,$r,'community',false);
$o = conversation($a, $r, 'community', false);
if (!get_config('system', 'old_pager')) {
$o .= alt_pager($a,count($r));
} else {
$o .= paginate($a);
}
$o .= alt_pager($a, count($r));
return $o;
}

@ -60,11 +60,20 @@ class Probe {
$xrd_timeout = Config::get('system','xrd_timeout', 20);
$redirects = 0;
$xml = fetch_url($ssl_url, false, $redirects, $xrd_timeout, "application/xrd+xml");
$ret = z_fetch_url($ssl_url, false, $redirects, array('timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml'));
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false;
}
$xml = $ret['body'];
$xrd = parse_xml_string($xml, false);
if (!is_object($xrd)) {
$xml = fetch_url($url, false, $redirects, $xrd_timeout, "application/xrd+xml");
$ret = z_fetch_url($url, false, $redirects, array('timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml'));
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false;
}
$xml = $ret['body'];
$xrd = parse_xml_string($xml, false);
}
if (!is_object($xrd))
@ -430,7 +439,12 @@ class Probe {
$xrd_timeout = Config::get('system','xrd_timeout', 20);
$redirects = 0;
$data = fetch_url($url, false, $redirects, $xrd_timeout, "application/xrd+xml");
$ret = z_fetch_url($url, false, $redirects, array('timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml'));
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false;
}
$data = $ret['body'];
$xrd = parse_xml_string($data, false);
if (!is_object($xrd)) {
@ -482,9 +496,14 @@ class Probe {
* @return array noscrape data
*/
private function poll_noscrape($noscrape, $data) {
$content = fetch_url($noscrape);
if (!$content)
$ret = z_fetch_url($noscrape);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false;
}
$content = $ret['body'];
if (!$content) {
return false;
}
$json = json_decode($content, true);
if (!is_array($json))
@ -663,10 +682,14 @@ class Probe {
* @return array hcard data
*/
private function poll_hcard($hcard, $data, $dfrn = false) {
$content = fetch_url($hcard);
if (!$content)
$ret = z_fetch_url($hcard);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false;
}
$content = $ret['body'];
if (!$content) {
return false;
}
$doc = new DOMDocument();
if (!@$doc->loadHTML($content))
@ -859,8 +882,13 @@ class Probe {
$pubkey = substr($pubkey, strpos($pubkey, ',') + 1);
else
$pubkey = substr($pubkey, 5);
} elseif (normalise_link($pubkey) == 'http://')
$pubkey = fetch_url($pubkey);
} elseif (normalise_link($pubkey) == 'http://') {
$ret = z_fetch_url($pubkey);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false;
}
$pubkey = $ret['body'];
}
$key = explode(".", $pubkey);
@ -880,7 +908,11 @@ class Probe {
return false;
// Fetch all additional data from the feed
$feed = fetch_url($data["poll"]);
$ret = z_fetch_url($data["poll"]);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false;
}
$feed = $ret['body'];
$feed_data = feed_import($feed,$dummy1,$dummy2, $dummy3, true);
if (!$feed_data)
return false;
@ -1035,7 +1067,11 @@ class Probe {
* @return array feed data
*/
private function feed($url, $probe = true) {
$feed = fetch_url($url);
$ret = z_fetch_url($url);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false;
}
$feed = $ret['body'];
$feed_data = feed_import($feed, $dummy1, $dummy2, $dummy3, true);
if (!$feed_data) {

@ -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("&#x2672; ", 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;

@ -125,6 +125,7 @@ if (isset($_SESSION) && x($_SESSION,'authenticated') && (!x($_POST,'auth-params'
$openid = new LightOpenID;
$openid->identity = $openid_url;
$_SESSION['openid'] = $openid_url;
$_SESSION['remember'] = $_POST['remember'];
$openid->returnUrl = App::get_baseurl(true).'/openid';
goaway($openid->authUrl());
} catch (Exception $e) {
@ -178,17 +179,12 @@ if (isset($_SESSION) && x($_SESSION,'authenticated') && (!x($_POST,'auth-params'
goaway(z_root());
}
// If the user specified to remember the authentication, then set a cookie
// that expires after one week (the default is when the browser is closed).
// The cookie will be renewed automatically.
// The week ensures that sessions will expire after some inactivity.
if ($_POST['remember'])
new_cookie(604800, $r[0]);
else
if (! $_POST['remember']) {
new_cookie(0); // 0 means delete on browser exit
}
// if we haven't failed up this point, log them in.
$_SESSION['remember'] = $_POST['remember'];
$_SESSION['last_login_date'] = datetime_convert('UTC','UTC');
authenticate_success($record, true, true);
}
@ -203,39 +199,3 @@ function nuke_session() {
session_unset();
session_destroy();
}
/**
* @brief Calculate the hash that is needed for the "Friendica" cookie
*
* @param array $user Record from "user" table
*
* @return string Hashed data
*/
function cookie_hash($user) {
return(hash("sha256", get_config("system", "site_prvkey").
$user["uprvkey"].
$user["password"]));
}
/**
* @brief Set the "Friendica" cookie
*
* @param int $time
* @param array $user Record from "user" table
*/
function new_cookie($time, $user = array()) {
if ($time != 0)
$time = $time + time();
if ($user)
$value = json_encode(array("uid" => $user["uid"],
"hash" => cookie_hash($user),
"ip" => $_SERVER['REMOTE_ADDR']));
else
$value = "";
setcookie("Friendica", $value, $time, "/", "",
(get_config('system', 'ssl_policy') == SSL_POLICY_FULL), true);
}

@ -39,9 +39,9 @@ function diaspora2bb($s) {
$s = html_entity_decode($s, ENT_COMPAT, 'UTF-8');
// Handles single newlines
$s = str_replace("\r", '<br>', $s);
$s = str_replace("\r\n", "\n", $s);
$s = str_replace("\n", " \n", $s);
$s = str_replace("\r", " \n", $s);
// Replace lonely stars in lines not starting with it with literal stars
$s = preg_replace('/^([^\*]+)\*([^\*]*)$/im', '$1\*$2', $s);

@ -1163,8 +1163,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
// fix any escaped ampersands that may have been converted into links
$Text = preg_replace('/\<([^>]*?)(src|href)=(.*?)\&amp\;(.*?)\>/ism', '<$1$2=$3&$4>', $Text);
// sanitizes src attributes (only relative redir URIs or http URLs)
$Text = preg_replace('#<([^>]*?)(src)="(?!http|redir)(.*?)"(.*?)>#ism', '<$1$2=""$4 class="invalid-src" title="' . t('Invalid source protocol') . '">', $Text);
// sanitizes src attributes (http and redir URLs for displaying in a web page, cid used for inline images in emails)
static $allowed_src_protocols = array('http', 'redir', 'cid');
$Text = preg_replace('#<([^>]*?)(src)="(?!' . implode('|', $allowed_src_protocols) . ')(.*?)"(.*?)>#ism',
'<$1$2=""$4 class="invalid-src" title="' . t('Invalid source protocol') . '">', $Text);
// sanitize href attributes (only whitelisted protocols URLs)
// default value for backward compatibility

@ -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;

@ -398,7 +398,7 @@ function delivery_run(&$argv, &$argc){
logger('notifier: dfrn_delivery to '.$contact["url"].' with guid '.$target_item["guid"].' returns '.$deliver_status);
if ($deliver_status == (-1)) {
if ($deliver_status < 0) {
logger('notifier: delivery failed: queuing message');
add_to_queue($contact['id'],NETWORK_DFRN,$atom);

@ -391,7 +391,7 @@ class dfrn {
*
* @return object XML root object
*/
private function add_header($doc, $owner, $authorelement, $alternatelink = "", $public = false) {
private static function add_header($doc, $owner, $authorelement, $alternatelink = "", $public = false) {
if ($alternatelink == "")
$alternatelink = $owner['url'];
@ -462,7 +462,7 @@ class dfrn {
*
* @return object XML author object
*/
private function add_author($doc, $owner, $authorelement, $public) {
private static function add_author($doc, $owner, $authorelement, $public) {
// Is the profile hidden or shouldn't be published in the net? Then add the "hide" element
$r = q("SELECT `id` FROM `profile` INNER JOIN `user` ON `user`.`uid` = `profile`.`uid`
@ -591,7 +591,7 @@ class dfrn {
*
* @return object XML author object
*/
private function add_entry_author($doc, $element, $contact_url, $item) {
private static function add_entry_author($doc, $element, $contact_url, $item) {
$contact = get_contact_details_by_url($contact_url, $item["uid"]);
@ -631,7 +631,7 @@ class dfrn {
*
* @return object XML activity object
*/
private function create_activity($doc, $element, $activity) {
private static function create_activity($doc, $element, $activity) {
if($activity) {
$entry = $doc->createElement($element);
@ -685,7 +685,7 @@ class dfrn {
*
* @return object XML attachment object
*/
private function get_attachment($doc, $root, $item) {
private static function get_attachment($doc, $root, $item) {
$arr = explode('[/attach],',$item['attach']);
if(count($arr)) {
foreach($arr as $r) {
@ -720,7 +720,7 @@ class dfrn {
*
* @return object XML entry object
*/
private function entry($doc, $type, $item, $owner, $comment = false, $cid = 0) {
private static function entry($doc, $type, $item, $owner, $comment = false, $cid = 0) {
$mentioned = array();
@ -913,11 +913,18 @@ class dfrn {
logger('dfrn_deliver: ' . $url);
$xml = fetch_url($url);
$ret = z_fetch_url($url);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return -2; // timed out
}
$xml = $ret['body'];
$curl_stat = $a->get_curl_code();
if(! $curl_stat)
return(-1); // timed out
if (!$curl_stat) {
return -3; // timed out
}
logger('dfrn_deliver: ' . $xml, LOGGER_DATA);
@ -1017,24 +1024,24 @@ class dfrn {
$key = Crypto::createNewRandomKey();
} catch (CryptoTestFailed $ex) {
logger('Cannot safely create a key');
return -1;
return -4;
} catch (CannotPerformOperation $ex) {
logger('Cannot safely create a key');
return -1;
return -5;
}
try {
$data = Crypto::encrypt($postvars['data'], $key);
} catch (CryptoTestFailed $ex) {
logger('Cannot safely perform encryption');
return -1;
return -6;
} catch (CannotPerformOperation $ex) {
logger('Cannot safely perform encryption');
return -1;
return -7;
}
break;
default:
logger("rino: invalid requested verision '$rino_remote_version'");
return -1;
return -8;
}
$postvars['rino'] = $rino_remote_version;
@ -1068,16 +1075,18 @@ class dfrn {
logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars,true), LOGGER_DATA);
$xml = post_url($contact['notify'],$postvars);
$xml = post_url($contact['notify'], $postvars);
logger('dfrn_deliver: ' . "RECEIVED: " . $xml, LOGGER_DATA);
$curl_stat = $a->get_curl_code();
if((! $curl_stat) || (! strlen($xml)))
return(-1); // timed out
if ((!$curl_stat) || (!strlen($xml))) {
return -9; // timed out
}
if(($curl_stat == 503) && (stristr($a->get_curl_headers(),'retry-after')))
return(-1);
if (($curl_stat == 503) && (stristr($a->get_curl_headers(),'retry-after'))) {
return -10;
}
if(strpos($xml,'<?xml') === false) {
logger('dfrn_deliver: phase 2: no valid XML returned');
@ -1103,7 +1112,7 @@ class dfrn {
* @param string $birthday Birthday of the contact
*
*/
private function birthday_event($contact, $birthday) {
private static function birthday_event($contact, $birthday) {
// Check for duplicates
$r = q("SELECT `id` FROM `event` WHERE `uid` = %d AND `cid` = %d AND `start` = '%s' AND `type` = '%s' LIMIT 1",
@ -1146,7 +1155,7 @@ class dfrn {
*
* @return Returns an array with relevant data of the author
*/
private function fetchauthor($xpath, $context, $importer, $element, $onlyfetch, $xml = "") {
private static function fetchauthor($xpath, $context, $importer, $element, $onlyfetch, $xml = "") {
$author = array();
$author["name"] = $xpath->evaluate($element."/atom:name/text()", $context)->item(0)->nodeValue;
@ -1358,7 +1367,7 @@ class dfrn {
*
* @return string XML string
*/
private function transform_activity($xpath, $activity, $element) {
private static function transform_activity($xpath, $activity, $element) {
if (!is_object($activity))
return "";
@ -1403,7 +1412,7 @@ class dfrn {
* @param object $mail mail elements
* @param array $importer Record of the importer user mixed with contact of the content
*/
private function process_mail($xpath, $mail, $importer) {
private static function process_mail($xpath, $mail, $importer) {
logger("Processing mails");
@ -1454,7 +1463,7 @@ class dfrn {
* @param object $suggestion suggestion elements
* @param array $importer Record of the importer user mixed with contact of the content
*/
private function process_suggestion($xpath, $suggestion, $importer) {
private static function process_suggestion($xpath, $suggestion, $importer) {
$a = get_app();
logger("Processing suggestions");
@ -1556,7 +1565,7 @@ class dfrn {
* @param object $relocation relocation elements
* @param array $importer Record of the importer user mixed with contact of the content
*/
private function process_relocation($xpath, $relocation, $importer) {
private static function process_relocation($xpath, $relocation, $importer) {
logger("Processing relocations");
@ -1685,7 +1694,7 @@ class dfrn {
* @param array $importer Record of the importer user mixed with contact of the content
* @param int $entrytype Is it a toplevel entry, a comment or a relayed comment?
*/
private function update_content($current, $item, $importer, $entrytype) {
private static function update_content($current, $item, $importer, $entrytype) {
$changed = false;
if (edited_timestamp_is_newer($current, $item)) {
@ -1737,7 +1746,7 @@ class dfrn {
*
* @return int Is it a toplevel entry, a comment or a relayed comment?
*/
private function get_entry_type($importer, $item) {
private static function get_entry_type($importer, $item) {
if ($item["parent-uri"] != $item["uri"]) {
$community = false;
@ -1803,7 +1812,7 @@ class dfrn {
* @param array $importer Record of the importer user mixed with contact of the content
* @param int $posted_id The record number of item record that was just posted
*/
private function do_poke($item, $importer, $posted_id) {
private static function do_poke($item, $importer, $posted_id) {
$verb = urldecode(substr($item["verb"],strpos($item["verb"], "#")+1));
if(!$verb)
return;
@ -1858,7 +1867,7 @@ class dfrn {
*
* @return bool Should the processing of the entries be continued?
*/
private function process_verbs($entrytype, $importer, &$item, &$is_like) {
private static function process_verbs($entrytype, $importer, &$item, &$is_like) {
logger("Process verb ".$item["verb"]." and object-type ".$item["object-type"]." for entrytype ".$entrytype, LOGGER_DEBUG);
@ -1958,7 +1967,7 @@ class dfrn {
* @param object $links link elements
* @param array $item the item record
*/
private function parse_links($links, &$item) {
private static function parse_links($links, &$item) {
$rel = "";
$href = "";
$type = "";
@ -2001,7 +2010,7 @@ class dfrn {
* @param object $entry entry elements
* @param array $importer Record of the importer user mixed with contact of the content
*/
private function process_entry($header, $xpath, $entry, $importer) {
private static function process_entry($header, $xpath, $entry, $importer) {
logger("Processing entries");
@ -2010,6 +2019,20 @@ class dfrn {
// Get the uri
$item["uri"] = $xpath->query("atom:id/text()", $entry)->item(0)->nodeValue;
$item["edited"] = $xpath->query("atom:updated/text()", $entry)->item(0)->nodeValue;
$current = q("SELECT `id`, `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item["uri"]),
intval($importer["importer_uid"])
);
// Is there an existing item?
if (dbm::is_result($current) AND edited_timestamp_is_newer($current[0], $item) AND
(datetime_convert("UTC","UTC",$item["edited"]) < $current[0]["edited"])) {
logger("Item ".$item["uri"]." already existed.", LOGGER_DEBUG);
return;
}
// Fetch the owner
$owner = self::fetchauthor($xpath, $entry, $importer, "dfrn:owner", true);
@ -2027,7 +2050,6 @@ class dfrn {
$item["title"] = $xpath->query("atom:title/text()", $entry)->item(0)->nodeValue;
$item["created"] = $xpath->query("atom:published/text()", $entry)->item(0)->nodeValue;
$item["edited"] = $xpath->query("atom:updated/text()", $entry)->item(0)->nodeValue;
$item["body"] = $xpath->query("dfrn:env/text()", $entry)->item(0)->nodeValue;
$item["body"] = str_replace(array(' ',"\t","\r","\n"), array('','','',''),$item["body"]);
@ -2215,18 +2237,13 @@ class dfrn {
}
}
$r = q("SELECT `id`, `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item["uri"]),
intval($importer["importer_uid"])
);
if (!self::process_verbs($entrytype, $importer, $item, $is_like)) {
logger("Exiting because 'process_verbs' told us so", LOGGER_DEBUG);
return;
}
// Update content if 'updated' changes
if (dbm::is_result($r)) {
if (dbm::is_result($current)) {
if (self::update_content($r[0], $item, $importer, $entrytype))
logger("Item ".$item["uri"]." was updated.", LOGGER_DEBUG);
else
@ -2311,7 +2328,7 @@ class dfrn {
* @param object $deletion deletion elements
* @param array $importer Record of the importer user mixed with contact of the content
*/
private function process_deletion($xpath, $deletion, $importer) {
private static function process_deletion($xpath, $deletion, $importer) {
logger("Processing deletions");

@ -177,18 +177,6 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
foreach (array_reverse($entrylist) AS $entry) {
$item = array_merge($header, $author);
$item["title"] = $xpath->evaluate('atom:title/text()', $entry)->item(0)->nodeValue;
if ($item["title"] == "")
$item["title"] = $xpath->evaluate('title/text()', $entry)->item(0)->nodeValue;
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;
if (is_object($alternate))
foreach($alternate AS $attributes)
if ($attributes->name == "href")
@ -212,6 +200,27 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
$item["parent-uri"] = $item["uri"];
if (!$simulate) {
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s', '%s')",
intval($importer["uid"]), dbesc($item["uri"]), dbesc(NETWORK_FEED), dbesc(NETWORK_DFRN));
if ($r) {
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG);
continue;
}
}
$item["title"] = $xpath->evaluate('atom:title/text()', $entry)->item(0)->nodeValue;
if ($item["title"] == "")
$item["title"] = $xpath->evaluate('title/text()', $entry)->item(0)->nodeValue;
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 == "")
@ -250,15 +259,6 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
if ($creator != "")
$item["author-name"] = $creator;
if (!$simulate) {
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s', '%s')",
intval($importer["uid"]), dbesc($item["uri"]), dbesc(NETWORK_FEED), dbesc(NETWORK_DFRN));
if ($r) {
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG);
continue;
}
}
/// @TODO ?
// <category>Ausland</category>
// <media:thumbnail width="152" height="76" url="http://www.taz.de/picture/667875/192/14388767.jpg"/>

@ -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];
$owner_uid = $item['uid'];
$item = $items[0];
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;
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'])
);
if (! dbm::is_result($r)) {
return false;
}
if (! $r[0]['self']) {
$remote_owner = $r[0];
}
// 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;
}
// this represents the post owner on this system.
// Retrieve the current logged in user's public contact
$author_id = public_contact();
$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)
$contacts = q("SELECT * FROM `contact` WHERE `id` = %d",
intval($author_id)
);
if (dbm::is_result($r)) {
$owner = $r[0];
}
if (! $owner) {
logger('like: no owner');
if (dbm::is_result($contacts)) {
$author_contact = $contacts[0];
} else {
logger('like: unknown author ' . $author_id);
return false;
}
if (! $remote_owner) {
$remote_owner = $owner;
}
// This represents the person posting
if ((local_user()) && (local_user() == $owner_uid)) {
$contact = $owner;
// 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 {
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($_SESSION['visitor_id']),
intval($owner_uid)
$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)) {
$contact = $r[0];
if (dbm::is_result($contacts)) {
$item_contact = $contacts[0];
} else {
logger('like: unknown item contact ' . $item_contact_id);
return false;
}
}
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) . "' ";
}
$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),
if ($event_verb_flag) {
$verbs = "'" . dbesc(ACTIVITY_ATTEND) . "', '" . dbesc(ACTIVITY_ATTENDNO) . "', '" . dbesc(ACTIVITY_ATTENDMAYBE) . "'";
} else {
$verbs = "'".dbesc($activity)."'";
}
$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);
return true;
if (!$event_verb_flag || $like_item['verb'] == $activity) {
return true;
}
}
$uri = item_new_uri($a->get_hostname(),$owner_uid);
// Verb is "un-something", just trying to delete existing entries
if (strpos($verb, 'un') === 0) {
return true;
}
// 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('<link rel="alternate" type="text/html" href="' . App::get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
$objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ;
$link = xmlify('<link rel="alternate" type="text/html" href="' . App::get_baseurl() . '/display/' . $owner_self_contact['nick'] . '/' . $item['id'] . '" />' . "\n") ;
$body = $item['body'];
$obj = <<< EOT
@ -180,80 +194,62 @@ function do_like($item_id, $verb) {
<content>$body</content>
</object>
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]';
/// @TODO Or rewrite this to multi-line initialization of the array?
$arr = array();
$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);
$plink = '[url=' . App::get_baseurl() . '/display/' . $owner_self_contact['nick'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
$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
);
$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;
}

@ -143,6 +143,8 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
logger('fetch_url error fetching '.$url.': '.curl_error($ch), LOGGER_NORMAL);
}
$ret['errno'] = curl_errno($ch);
$base = $s;
$curl_info = @curl_getinfo($ch);

@ -15,11 +15,11 @@ function RemoveReply($subject) {
function onepoll_run(&$argv, &$argc){
global $a, $db;
if(is_null($a)) {
if (is_null($a)) {
$a = new App;
}
if(is_null($db)) {
if (is_null($db)) {
@include(".htconfig.php");
require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
@ -48,21 +48,25 @@ function onepoll_run(&$argv, &$argc){
$force = false;
$restart = false;
if(($argc > 1) && (intval($argv[1])))
if (($argc > 1) && (intval($argv[1]))) {
$contact_id = intval($argv[1]);
}
if(($argc > 2) && ($argv[2] == "force"))
if (($argc > 2) && ($argv[2] == "force")) {
$force = true;
}
if(! $contact_id) {
if (! $contact_id) {
logger('onepoll: no contact');
return;
}
// Don't check this stuff if the function is called by the poller
if (App::callstack() != "poller_run")
if (App::is_already_running('onepoll'.$contact_id, '', 540))
if (App::callstack() != "poller_run") {
if (App::is_already_running('onepoll'.$contact_id, '', 540)) {
return;
}
}
$d = datetime_convert();
@ -83,8 +87,9 @@ function onepoll_run(&$argv, &$argc){
intval($contact_id)
);
if(! count($contacts))
if (! count($contacts)) {
return;
}
$contact = $contacts[0];
@ -94,9 +99,11 @@ function onepoll_run(&$argv, &$argc){
where `cid` = %d and updated > UTC_TIMESTAMP() - INTERVAL 1 DAY",
intval($contact['id'])
);
if (dbm::is_result($r))
if (!$r[0]['total'])
if (dbm::is_result($r)) {
if (!$r[0]['total']) {
poco_load($contact['id'],$importer_uid,0,$contact['poco']);
}
}
}
/// @TODO Check why we don't poll the Diaspora feed at the moment (some guid problem in the items?)
@ -127,24 +134,24 @@ function onepoll_run(&$argv, &$argc){
$t = $contact['last-update'];
if($contact['subhub']) {
if ($contact['subhub']) {
$poll_interval = get_config('system','pushpoll_frequency');
$contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3);
$hub_update = false;
if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day"))
$hub_update = true;
}
else
if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) {
$hub_update = true;
}
} else {
$hub_update = false;
}
$importer_uid = $contact['uid'];
$r = q("SELECT `contact`.*, `user`.`page-flags` FROM `contact` INNER JOIN `user` on `contact`.`uid` = `user`.`uid` WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
intval($importer_uid)
);
if (! dbm::is_result($r)) {
if (!dbm::is_result($r)) {
return;
}
@ -158,7 +165,7 @@ function onepoll_run(&$argv, &$argc){
);
// Update the contact entry
if(($contact['network'] === NETWORK_OSTATUS) || ($contact['network'] === NETWORK_DIASPORA) || ($contact['network'] === NETWORK_DFRN)) {
if (($contact['network'] === NETWORK_OSTATUS) || ($contact['network'] === NETWORK_DIASPORA) || ($contact['network'] === NETWORK_DFRN)) {
if (!poco_reachable($contact['url'])) {
logger("Skipping probably dead contact ".$contact['url']);
return;
@ -167,40 +174,50 @@ function onepoll_run(&$argv, &$argc){
if (!update_contact($contact["id"])) {
mark_for_death($contact);
return;
} else
} else {
unmark_for_death($contact);
}
}
if($contact['network'] === NETWORK_DFRN) {
if ($contact['network'] === NETWORK_DFRN) {
$idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']);
if(intval($contact['duplex']) && $contact['dfrn-id'])
if (intval($contact['duplex']) && $contact['dfrn-id']) {
$idtosend = '0:' . $orig_id;
if(intval($contact['duplex']) && $contact['issued-id'])
}
if (intval($contact['duplex']) && $contact['issued-id']) {
$idtosend = '1:' . $orig_id;
}
// they have permission to write to us. We already filtered this in the contact query.
$perm = 'rw';
// But this may be our first communication, so set the writable flag if it isn't set already.
if(! intval($contact['writable']))
if (! intval($contact['writable'])) {
q("update contact set writable = 1 where id = %d", intval($contact['id']));
}
$url = $contact['poll'] . '?dfrn_id=' . $idtosend
. '&dfrn_version=' . DFRN_PROTOCOL_VERSION
. '&type=data&last_update=' . $last_update
. '&perm=' . $perm ;
$handshake_xml = fetch_url($url);
$ret = z_fetch_url($url);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return;
}