Merge pull request #4206 from MrPetovan/task/fix-scrutinizer-issues
Improve dba::selectFirst calls
This commit is contained in:
commit
91198cb53d
30 changed files with 438 additions and 444 deletions
|
@ -226,7 +226,7 @@ function api_login(App $a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$record || !count($record)) {
|
if (DBM::is_result($record)) {
|
||||||
logger('API_login failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
|
logger('API_login failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
|
||||||
header('WWW-Authenticate: Basic realm="Friendica"');
|
header('WWW-Authenticate: Basic realm="Friendica"');
|
||||||
//header('HTTP/1.0 401 Unauthorized');
|
//header('HTTP/1.0 401 Unauthorized');
|
||||||
|
@ -4870,22 +4870,22 @@ function api_friendica_remoteauth()
|
||||||
|
|
||||||
// traditional DFRN
|
// traditional DFRN
|
||||||
|
|
||||||
$r = dba::selectFirst('contact', [], ['uid' => api_user(), 'nurl' => $c_url]);
|
$contact = dba::selectFirst('contact', [], ['uid' => api_user(), 'nurl' => $c_url]);
|
||||||
|
|
||||||
if (!DBM::is_result($r) || ($r['network'] !== NETWORK_DFRN)) {
|
if (!DBM::is_result($contact) || ($contact['network'] !== NETWORK_DFRN)) {
|
||||||
throw new BadRequestException("Unknown contact");
|
throw new BadRequestException("Unknown contact");
|
||||||
}
|
}
|
||||||
|
|
||||||
$cid = $r['id'];
|
$cid = $contact['id'];
|
||||||
|
|
||||||
$dfrn_id = defaults($r, 'issued-id', $r['dfrn-id']);
|
$dfrn_id = defaults($contact, 'issued-id', $contact['dfrn-id']);
|
||||||
|
|
||||||
if ($r['duplex'] && $r['issued-id']) {
|
if ($contact['duplex'] && $contact['issued-id']) {
|
||||||
$orig_id = $r['issued-id'];
|
$orig_id = $contact['issued-id'];
|
||||||
$dfrn_id = '1:' . $orig_id;
|
$dfrn_id = '1:' . $orig_id;
|
||||||
}
|
}
|
||||||
if ($r['duplex'] && $r['dfrn-id']) {
|
if ($contact['duplex'] && $contact['dfrn-id']) {
|
||||||
$orig_id = $r['dfrn-id'];
|
$orig_id = $contact['dfrn-id'];
|
||||||
$dfrn_id = '0:' . $orig_id;
|
$dfrn_id = '0:' . $orig_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4901,10 +4901,10 @@ function api_friendica_remoteauth()
|
||||||
intval(time() + 45)
|
intval(time() + 45)
|
||||||
);
|
);
|
||||||
|
|
||||||
logger($r['name'] . ' ' . $sec, LOGGER_DEBUG);
|
logger($contact['name'] . ' ' . $sec, LOGGER_DEBUG);
|
||||||
$dest = ($url ? '&destination_url=' . $url : '');
|
$dest = ($url ? '&destination_url=' . $url : '');
|
||||||
goaway(
|
goaway(
|
||||||
$r['poll'] . '?dfrn_id=' . $dfrn_id
|
$contact['poll'] . '?dfrn_id=' . $dfrn_id
|
||||||
. '&dfrn_version=' . DFRN_PROTOCOL_VERSION
|
. '&dfrn_version=' . DFRN_PROTOCOL_VERSION
|
||||||
. '&type=profile&sec=' . $sec . $dest . $quiet
|
. '&type=profile&sec=' . $sec . $dest . $quiet
|
||||||
);
|
);
|
||||||
|
|
|
@ -224,14 +224,14 @@ function common_friends_visitor_widget($profile_uid)
|
||||||
|
|
||||||
if (!$cid) {
|
if (!$cid) {
|
||||||
if (get_my_url()) {
|
if (get_my_url()) {
|
||||||
$r = dba::selectFirst('contact', ['id'],
|
$contact = dba::selectFirst('contact', ['id'],
|
||||||
['nurl' => normalise_link(get_my_url()), 'uid' => $profile_uid]);
|
['nurl' => normalise_link(get_my_url()), 'uid' => $profile_uid]);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($contact)) {
|
||||||
$cid = $r['id'];
|
$cid = $contact['id'];
|
||||||
} else {
|
} else {
|
||||||
$r = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(get_my_url())]);
|
$gcontact = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(get_my_url())]);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($gcontact)) {
|
||||||
$zcid = $r['id'];
|
$zcid = $gcontact['id'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -968,10 +968,15 @@ function best_link_url($item, &$sparkle, $url = '') {
|
||||||
$clean_url = normalise_link($item['author-link']);
|
$clean_url = normalise_link($item['author-link']);
|
||||||
|
|
||||||
if (local_user()) {
|
if (local_user()) {
|
||||||
$r = dba::selectFirst('contact', ['id'],
|
$condition = [
|
||||||
['network' => NETWORK_DFRN, 'uid' => local_user(), 'nurl' => normalise_link($clean_url), 'pending' => false]);
|
'network' => NETWORK_DFRN,
|
||||||
if (DBM::is_result($r)) {
|
'uid' => local_user(),
|
||||||
$best_url = 'redir/' . $r['id'];
|
'nurl' => normalise_link($clean_url),
|
||||||
|
'pending' => false
|
||||||
|
];
|
||||||
|
$contact = dba::selectFirst('contact', ['id'], $condition);
|
||||||
|
if (DBM::is_result($contact)) {
|
||||||
|
$best_url = 'redir/' . $contact['id'];
|
||||||
$sparkle = true;
|
$sparkle = true;
|
||||||
if ($url != '') {
|
if ($url != '') {
|
||||||
$hostname = get_app()->get_hostname();
|
$hostname = get_app()->get_hostname();
|
||||||
|
@ -1019,11 +1024,12 @@ function item_photo_menu($item) {
|
||||||
$cid = 0;
|
$cid = 0;
|
||||||
$network = '';
|
$network = '';
|
||||||
$rel = 0;
|
$rel = 0;
|
||||||
$r = dba::selectFirst('contact', array('id', 'network', 'rel'), array('uid' => local_user(), 'nurl' => normalise_link($item['author-link'])));
|
$condition = ['uid' => local_user(), 'nurl' => normalise_link($item['author-link'])];
|
||||||
if (DBM::is_result($r)) {
|
$contact = dba::selectFirst('contact', ['id', 'network', 'rel'], $condition);
|
||||||
$cid = $r['id'];
|
if (DBM::is_result($contact)) {
|
||||||
$network = $r['network'];
|
$cid = $contact['id'];
|
||||||
$rel = $r['rel'];
|
$network = $contact['network'];
|
||||||
|
$rel = $contact['rel'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sparkle) {
|
if ($sparkle) {
|
||||||
|
|
|
@ -106,8 +106,8 @@ function notification($params)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($params['type'] == NOTIFY_COMMENT) {
|
if ($params['type'] == NOTIFY_COMMENT) {
|
||||||
$p = dba::selectFirst('thread', ['ignored'], ['iid' => $parent_id]);
|
$thread = dba::selectFirst('thread', ['ignored'], ['iid' => $parent_id]);
|
||||||
if (DBM::is_result($p) && $p["ignored"]) {
|
if (DBM::is_result($thread) && $thread["ignored"]) {
|
||||||
logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG);
|
logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -128,13 +128,13 @@ function notification($params)
|
||||||
|
|
||||||
// if it's a post figure out who's post it is.
|
// if it's a post figure out who's post it is.
|
||||||
|
|
||||||
$p = null;
|
$item = null;
|
||||||
|
|
||||||
if ($params['otype'] === 'item' && $parent_id) {
|
if ($params['otype'] === 'item' && $parent_id) {
|
||||||
$p = dba::selectFirst('item', [], ['id' => $parent_id]);
|
$item = dba::selectFirst('item', [], ['id' => $parent_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$item_post_type = item_post_type($p);
|
$item_post_type = item_post_type($item);
|
||||||
|
|
||||||
// "a post"
|
// "a post"
|
||||||
$dest_str = sprintf(t('%1$s commented on [url=%2$s]a %3$s[/url]'),
|
$dest_str = sprintf(t('%1$s commented on [url=%2$s]a %3$s[/url]'),
|
||||||
|
@ -143,7 +143,7 @@ function notification($params)
|
||||||
$item_post_type);
|
$item_post_type);
|
||||||
|
|
||||||
// "George Bull's post"
|
// "George Bull's post"
|
||||||
if ($p) {
|
if ($item) {
|
||||||
$dest_str = sprintf(t('%1$s commented on [url=%2$s]%3$s\'s %4$s[/url]'),
|
$dest_str = sprintf(t('%1$s commented on [url=%2$s]%3$s\'s %4$s[/url]'),
|
||||||
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
|
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
|
||||||
$itemlink,
|
$itemlink,
|
||||||
|
@ -152,7 +152,7 @@ function notification($params)
|
||||||
}
|
}
|
||||||
|
|
||||||
// "your post"
|
// "your post"
|
||||||
if ($p['owner-name'] == $p['author-name'] && $p['wall']) {
|
if (DBM::is_result($item) && $item['owner-name'] == $item['author-name'] && $item['wall']) {
|
||||||
$dest_str = sprintf(t('%1$s commented on [url=%2$s]your %3$s[/url]'),
|
$dest_str = sprintf(t('%1$s commented on [url=%2$s]your %3$s[/url]'),
|
||||||
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
|
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
|
||||||
$itemlink,
|
$itemlink,
|
||||||
|
|
|
@ -154,28 +154,27 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array(), $
|
||||||
*
|
*
|
||||||
* @param string $nickname nick
|
* @param string $nickname nick
|
||||||
* @param int $uid uid
|
* @param int $uid uid
|
||||||
* @param int $profile ID of the profile
|
* @param int $profile_id ID of the profile
|
||||||
* @returns array
|
* @returns array
|
||||||
*/
|
*/
|
||||||
function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0)
|
function get_profiledata_by_nick($nickname, $uid = 0, $profile_id = 0)
|
||||||
{
|
{
|
||||||
if (remote_user() && count($_SESSION['remote'])) {
|
if (remote_user() && count($_SESSION['remote'])) {
|
||||||
foreach ($_SESSION['remote'] as $visitor) {
|
foreach ($_SESSION['remote'] as $visitor) {
|
||||||
if ($visitor['uid'] == $uid) {
|
if ($visitor['uid'] == $uid) {
|
||||||
$r = dba::selectFirst('contact', ['profile-id'], ['id' => $visitor['cid']]);
|
$contact = dba::selectFirst('contact', ['profile-id'], ['id' => $visitor['cid']]);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($contact)) {
|
||||||
$profile = $r['profile-id'];
|
$profile_id = $contact['profile-id'];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = null;
|
$profile = null;
|
||||||
|
|
||||||
if ($profile) {
|
if ($profile_id) {
|
||||||
$profile_int = intval($profile);
|
$profile = dba::fetch_first(
|
||||||
$r = dba::fetch_first(
|
|
||||||
"SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
|
"SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
|
||||||
`contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
|
`contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
|
||||||
`profile`.`uid` AS `profile_uid`, `profile`.*,
|
`profile`.`uid` AS `profile_uid`, `profile`.*,
|
||||||
|
@ -185,11 +184,11 @@ function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0)
|
||||||
INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
|
INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
|
||||||
WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
|
WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
|
||||||
$nickname,
|
$nickname,
|
||||||
$profile_int
|
intval($profile_id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!DBM::is_result($r)) {
|
if (!DBM::is_result($profile)) {
|
||||||
$r = dba::fetch_first(
|
$profile = dba::fetch_first(
|
||||||
"SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
|
"SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
|
||||||
`contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
|
`contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
|
||||||
`profile`.`uid` AS `profile_uid`, `profile`.*,
|
`profile`.`uid` AS `profile_uid`, `profile`.*,
|
||||||
|
@ -202,7 +201,7 @@ function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $r;
|
return $profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -215,7 +214,7 @@ function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0)
|
||||||
* @param int $block
|
* @param int $block
|
||||||
* @param boolean $show_connect Show connect link
|
* @param boolean $show_connect Show connect link
|
||||||
*
|
*
|
||||||
* @return HTML string stuitable for sidebar inclusion
|
* @return HTML string suitable for sidebar inclusion
|
||||||
*
|
*
|
||||||
* @note Returns empty string if passed $profile is wrong type or not populated
|
* @note Returns empty string if passed $profile is wrong type or not populated
|
||||||
*
|
*
|
||||||
|
|
|
@ -67,11 +67,8 @@ function send_message($recipient = 0, $body = '', $subject = '', $replyto = '')
|
||||||
$fields = array('uid' => local_user(), 'guid' => $conv_guid, 'creator' => $sender_handle,
|
$fields = array('uid' => local_user(), 'guid' => $conv_guid, 'creator' => $sender_handle,
|
||||||
'created' => datetime_convert(), 'updated' => datetime_convert(),
|
'created' => datetime_convert(), 'updated' => datetime_convert(),
|
||||||
'subject' => $subject, 'recips' => $handles);
|
'subject' => $subject, 'recips' => $handles);
|
||||||
dba::insert('conv', $fields);
|
if (dba::insert('conv', $fields)) {
|
||||||
|
$convid = dba::lastInsertId();
|
||||||
$r = dba::selectFirst('conv', ['id'], ['guid' => $conv_guid, 'uid' => local_user()]);
|
|
||||||
if (DBM::is_result($r)) {
|
|
||||||
$convid = $r['id'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +81,8 @@ function send_message($recipient = 0, $body = '', $subject = '', $replyto = '')
|
||||||
$replyto = $convuri;
|
$replyto = $convuri;
|
||||||
}
|
}
|
||||||
|
|
||||||
q("INSERT INTO `mail` ( `uid`, `guid`, `convid`, `from-name`, `from-photo`, `from-url`,
|
$post_id = null;
|
||||||
|
$result = q("INSERT INTO `mail` ( `uid`, `guid`, `convid`, `from-name`, `from-photo`, `from-url`,
|
||||||
`contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent-uri`, `created`)
|
`contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent-uri`, `created`)
|
||||||
VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s' )",
|
VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s' )",
|
||||||
intval(local_user()),
|
intval(local_user()),
|
||||||
|
@ -103,14 +101,8 @@ function send_message($recipient = 0, $body = '', $subject = '', $replyto = '')
|
||||||
dbesc($replyto),
|
dbesc($replyto),
|
||||||
datetime_convert()
|
datetime_convert()
|
||||||
);
|
);
|
||||||
|
if ($result) {
|
||||||
|
$post_id = dba::lastInsertId();
|
||||||
$r = q("SELECT * FROM `mail` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
|
||||||
dbesc($uri),
|
|
||||||
intval(local_user())
|
|
||||||
);
|
|
||||||
if (DBM::is_result($r)) {
|
|
||||||
$post_id = $r[0]['id'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -183,19 +175,19 @@ function send_wallmessage($recipient = '', $body = '', $subject = '', $replyto =
|
||||||
|
|
||||||
$handles = $recip_handle . ';' . $sender_handle;
|
$handles = $recip_handle . ';' . $sender_handle;
|
||||||
|
|
||||||
|
$convid = null;
|
||||||
$fields = array('uid' => $recipient['uid'], 'guid' => $conv_guid, 'creator' => $sender_handle,
|
$fields = array('uid' => $recipient['uid'], 'guid' => $conv_guid, 'creator' => $sender_handle,
|
||||||
'created' => datetime_convert(), 'updated' => datetime_convert(),
|
'created' => datetime_convert(), 'updated' => datetime_convert(),
|
||||||
'subject' => $subject, 'recips' => $handles);
|
'subject' => $subject, 'recips' => $handles);
|
||||||
dba::insert('conv', $fields);
|
if (dba::insert('conv', $fields)) {
|
||||||
|
$convid = dba::lastInsertId();
|
||||||
$r = dba::selectFirst('conv', ['id'], ['guid' => $conv_guid, 'uid' => $recipient['uid']]);
|
}
|
||||||
if (!DBM::is_result($r)) {
|
|
||||||
|
if (!$convid) {
|
||||||
logger('send message: conversation not found.');
|
logger('send message: conversation not found.');
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
$convid = $r['id'];
|
|
||||||
|
|
||||||
q("INSERT INTO `mail` ( `uid`, `guid`, `convid`, `from-name`, `from-photo`, `from-url`,
|
q("INSERT INTO `mail` ( `uid`, `guid`, `convid`, `from-name`, `from-photo`, `from-url`,
|
||||||
`contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent-uri`, `created`, `unknown`)
|
`contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent-uri`, `created`, `unknown`)
|
||||||
VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s', %d )",
|
VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s', %d )",
|
||||||
|
|
|
@ -94,9 +94,9 @@ function nav_info(App $a)
|
||||||
$nav['usermenu'][] = array('notes/', t('Personal notes'), '', t('Your personal notes'));
|
$nav['usermenu'][] = array('notes/', t('Personal notes'), '', t('Your personal notes'));
|
||||||
|
|
||||||
// user info
|
// user info
|
||||||
$r = dba::selectFirst('contact', ['micro'], ['uid' => $a->user['uid'], 'self' => true]);
|
$contact = dba::selectFirst('contact', ['micro'], ['uid' => $a->user['uid'], 'self' => true]);
|
||||||
$userinfo = array(
|
$userinfo = array(
|
||||||
'icon' => (DBM::is_result($r) ? $a->remove_baseurl($r['micro']) : 'images/person-48.jpg'),
|
'icon' => (DBM::is_result($contact) ? $a->remove_baseurl($contact['micro']) : 'images/person-48.jpg'),
|
||||||
'name' => $a->user['username'],
|
'name' => $a->user['username'],
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -33,10 +33,10 @@ function ref_session_read($id)
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = dba::selectFirst('session', ['data'], ['sid' => $id]);
|
$session = dba::selectFirst('session', ['data'], ['sid' => $id]);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($session)) {
|
||||||
$session_exists = true;
|
$session_exists = true;
|
||||||
return $r['data'];
|
return $session['data'];
|
||||||
} else {
|
} else {
|
||||||
logger("no data for session $id", LOGGER_TRACE);
|
logger("no data for session $id", LOGGER_TRACE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,11 +107,11 @@ if (!$a->is_backend()) {
|
||||||
* We have to do it here because the session was just now opened.
|
* We have to do it here because the session was just now opened.
|
||||||
*/
|
*/
|
||||||
if (x($_SESSION, 'authenticated') && !x($_SESSION, 'language')) {
|
if (x($_SESSION, 'authenticated') && !x($_SESSION, 'language')) {
|
||||||
// we didn't loaded user data yet, but we need user language
|
// we haven't loaded user data yet, but we need user language
|
||||||
$r = dba::selectFirst('user', ['language'], ['uid' => $_SESSION['uid']]);
|
$user = dba::selectFirst('user', ['language'], ['uid' => $_SESSION['uid']]);
|
||||||
$_SESSION['language'] = $lang;
|
$_SESSION['language'] = $lang;
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
$_SESSION['language'] = $r['language'];
|
$_SESSION['language'] = $user['language'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ function contacts_init(App $a)
|
||||||
$a->page['aside'] = '';
|
$a->page['aside'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$contact = [];
|
$contact = null;
|
||||||
if ((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
|
if ((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
|
||||||
$contact_id = intval($a->argv[1]);
|
$contact_id = intval($a->argv[1]);
|
||||||
$contact = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
|
$contact = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
|
||||||
|
@ -240,7 +240,7 @@ function _contact_update($contact_id)
|
||||||
|
|
||||||
$uid = $contact["uid"];
|
$uid = $contact["uid"];
|
||||||
|
|
||||||
if ($r[0]["network"] == NETWORK_OSTATUS) {
|
if ($contact["network"] == NETWORK_OSTATUS) {
|
||||||
$result = Contact::createFromProbe($uid, $contact["url"], false, $contact["network"]);
|
$result = Contact::createFromProbe($uid, $contact["url"], false, $contact["network"]);
|
||||||
|
|
||||||
if ($result['success']) {
|
if ($result['success']) {
|
||||||
|
|
|
@ -44,8 +44,8 @@ function hovercard_content()
|
||||||
$cid = 0;
|
$cid = 0;
|
||||||
if (local_user() && strpos($profileurl, 'redir/') === 0) {
|
if (local_user() && strpos($profileurl, 'redir/') === 0) {
|
||||||
$cid = intval(substr($profileurl, 6));
|
$cid = intval(substr($profileurl, 6));
|
||||||
$r = dba::selectFirst('contact', ['nurl'], ['id' => $cid]);
|
$remote_contact = dba::selectFirst('contact', ['nurl'], ['id' => $cid]);
|
||||||
$profileurl = defaults($r, 'nurl', '');
|
$profileurl = defaults($remote_contact, 'nurl', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
$contact = [];
|
$contact = [];
|
||||||
|
|
|
@ -517,7 +517,7 @@ function networkThreadedView(App $a, $update = 0) {
|
||||||
|
|
||||||
$datequery = $datequery2 = '';
|
$datequery = $datequery2 = '';
|
||||||
|
|
||||||
$group = 0;
|
$gid = 0;
|
||||||
|
|
||||||
if ($a->argc > 1) {
|
if ($a->argc > 1) {
|
||||||
for ($x = 1; $x < $a->argc; $x ++) {
|
for ($x = 1; $x < $a->argc; $x ++) {
|
||||||
|
@ -529,8 +529,8 @@ function networkThreadedView(App $a, $update = 0) {
|
||||||
$_GET['order'] = 'post';
|
$_GET['order'] = 'post';
|
||||||
}
|
}
|
||||||
} elseif (intval($a->argv[$x])) {
|
} elseif (intval($a->argv[$x])) {
|
||||||
$group = intval($a->argv[$x]);
|
$gid = intval($a->argv[$x]);
|
||||||
$def_acl = array('allow_gid' => '<' . $group . '>');
|
$def_acl = array('allow_gid' => '<' . $gid . '>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -565,8 +565,8 @@ function networkThreadedView(App $a, $update = 0) {
|
||||||
$tabs = network_tabs($a);
|
$tabs = network_tabs($a);
|
||||||
$o .= $tabs;
|
$o .= $tabs;
|
||||||
|
|
||||||
if ($group) {
|
if ($gid) {
|
||||||
if (($t = Contact::getOStatusCountByGroupId($group)) && !PConfig::get(local_user(), 'system', 'nowarn_insecure')) {
|
if (($t = Contact::getOStatusCountByGroupId($gid)) && !PConfig::get(local_user(), 'system', 'nowarn_insecure')) {
|
||||||
notice(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
|
notice(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
|
||||||
"Warning: This group contains %s members from a network that doesn't allow non public messages.",
|
"Warning: This group contains %s members from a network that doesn't allow non public messages.",
|
||||||
$t) . EOL);
|
$t) . EOL);
|
||||||
|
@ -596,12 +596,12 @@ function networkThreadedView(App $a, $update = 0) {
|
||||||
'allow_location' => $a->user['allow_location'],
|
'allow_location' => $a->user['allow_location'],
|
||||||
'default_location' => $a->user['default-location'],
|
'default_location' => $a->user['default-location'],
|
||||||
'nickname' => $a->user['nickname'],
|
'nickname' => $a->user['nickname'],
|
||||||
'lockstate'=> ((($group) || ($cid) || ($nets) || (is_array($a->user) &&
|
'lockstate'=> ((($gid) || ($cid) || ($nets) || (is_array($a->user) &&
|
||||||
((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
|
((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
|
||||||
(strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
|
(strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
|
||||||
'default_perms' => get_acl_permissions($a->user),
|
'default_perms' => get_acl_permissions($a->user),
|
||||||
'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), true),
|
'acl' => populate_acl((($gid || $cid || $nets) ? $def_acl : $a->user), true),
|
||||||
'bang' => (($group || $cid || $nets) ? '!' : ''),
|
'bang' => (($gid || $cid || $nets) ? '!' : ''),
|
||||||
'visitor' => 'block',
|
'visitor' => 'block',
|
||||||
'profile_uid' => local_user(),
|
'profile_uid' => local_user(),
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
|
@ -631,17 +631,18 @@ function networkThreadedView(App $a, $update = 0) {
|
||||||
|
|
||||||
$sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
|
$sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
|
||||||
|
|
||||||
if ($group) {
|
if ($gid) {
|
||||||
$r = dba::selectFirst('group', ['name'], ['id' => $group, 'uid' => $_SESSION['uid']]);
|
$group = dba::selectFirst('group', ['name'], ['id' => $gid, 'uid' => $_SESSION['uid']]);
|
||||||
if (!DBM::is_result($r)) {
|
if (!DBM::is_result($group)) {
|
||||||
if ($update)
|
if ($update) {
|
||||||
killme();
|
killme();
|
||||||
|
}
|
||||||
notice(t('No such group') . EOL);
|
notice(t('No such group') . EOL);
|
||||||
goaway('network/0');
|
goaway('network/0');
|
||||||
// NOTREACHED
|
// NOTREACHED
|
||||||
}
|
}
|
||||||
|
|
||||||
$contacts = Group::expand(array($group));
|
$contacts = Group::expand(array($gid));
|
||||||
|
|
||||||
if ((is_array($contacts)) && count($contacts)) {
|
if ((is_array($contacts)) && count($contacts)) {
|
||||||
$contact_str_self = "";
|
$contact_str_self = "";
|
||||||
|
@ -654,40 +655,40 @@ function networkThreadedView(App $a, $update = 0) {
|
||||||
|
|
||||||
$sql_post_table .= " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = ".$sql_table.".".$sql_parent;
|
$sql_post_table .= " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = ".$sql_table.".".$sql_parent;
|
||||||
$sql_extra3 .= " AND (`thread`.`contact-id` IN ($contact_str) ";
|
$sql_extra3 .= " AND (`thread`.`contact-id` IN ($contact_str) ";
|
||||||
$sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."' AND `temp1`.`private`))";
|
$sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '".protect_sprintf('%<'.intval($gid).'>%')."' AND `temp1`.`private`))";
|
||||||
} else {
|
} else {
|
||||||
$sql_extra3 .= " AND false ";
|
$sql_extra3 .= " AND false ";
|
||||||
info(t('Group is empty'));
|
info(t('Group is empty'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$o = replace_macros(get_markup_template("section_title.tpl"),array(
|
$o = replace_macros(get_markup_template("section_title.tpl"),array(
|
||||||
'$title' => t('Group: %s', $r['name'])
|
'$title' => t('Group: %s', $group['name'])
|
||||||
)) . $o;
|
)) . $o;
|
||||||
|
|
||||||
} elseif ($cid) {
|
} elseif ($cid) {
|
||||||
$fields = ['id', 'name', 'network', 'writable', 'nurl',
|
$fields = ['id', 'name', 'network', 'writable', 'nurl',
|
||||||
'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location'];
|
'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location'];
|
||||||
$condition = ["`id` = ? AND (NOT `blocked` OR `pending`)", $cid];
|
$condition = ["`id` = ? AND (NOT `blocked` OR `pending`)", $cid];
|
||||||
$r = dba::selectFirst('contact', $fields, $condition);
|
$contact = dba::selectFirst('contact', $fields, $condition);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($contact)) {
|
||||||
$sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid);
|
$sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid);
|
||||||
|
|
||||||
$entries[0] = array(
|
$entries[0] = array(
|
||||||
'id' => 'network',
|
'id' => 'network',
|
||||||
'name' => htmlentities($r['name']),
|
'name' => htmlentities($contact['name']),
|
||||||
'itemurl' => (($r['addr']) ? ($r['addr']) : ($r['nurl'])),
|
'itemurl' => defaults($contact, 'addr', $contact['nurl']),
|
||||||
'thumb' => proxy_url($r['thumb'], false, PROXY_SIZE_THUMB),
|
'thumb' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB),
|
||||||
'details' => $r['location'],
|
'details' => $contact['location'],
|
||||||
);
|
);
|
||||||
|
|
||||||
$entries[0]["account_type"] = Contact::getAccountType($r);
|
$entries[0]["account_type"] = Contact::getAccountType($contact);
|
||||||
|
|
||||||
$o = replace_macros(get_markup_template("viewcontact_template.tpl"),array(
|
$o = replace_macros(get_markup_template("viewcontact_template.tpl"),array(
|
||||||
'contacts' => $entries,
|
'contacts' => $entries,
|
||||||
'id' => 'network',
|
'id' => 'network',
|
||||||
)) . $o;
|
)) . $o;
|
||||||
|
|
||||||
if ($r['network'] === NETWORK_OSTATUS && $r['writable'] && !PConfig::get(local_user(),'system','nowarn_insecure')) {
|
if ($contact['network'] === NETWORK_OSTATUS && $contact['writable'] && !PConfig::get(local_user(),'system','nowarn_insecure')) {
|
||||||
notice(t('Private messages to this person are at risk of public disclosure.') . EOL);
|
notice(t('Private messages to this person are at risk of public disclosure.') . EOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,7 +699,7 @@ function networkThreadedView(App $a, $update = 0) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$group && !$cid && !$update && !Config::get('theme','hide_eventlist')) {
|
if (!$gid && !$cid && !$update && !Config::get('theme','hide_eventlist')) {
|
||||||
$o .= get_birthdays();
|
$o .= get_birthdays();
|
||||||
$o .= get_events();
|
$o .= get_events();
|
||||||
}
|
}
|
||||||
|
@ -887,7 +888,7 @@ function networkThreadedView(App $a, $update = 0) {
|
||||||
// level which items you've seen and which you haven't. If you're looking
|
// level which items you've seen and which you haven't. If you're looking
|
||||||
// at the top level network page just mark everything seen.
|
// at the top level network page just mark everything seen.
|
||||||
|
|
||||||
if (!$group && !$cid && !$star) {
|
if (!$gid && !$cid && !$star) {
|
||||||
$condition = array('unseen' => true, 'uid' => local_user());
|
$condition = array('unseen' => true, 'uid' => local_user());
|
||||||
networkSetSeen($condition);
|
networkSetSeen($condition);
|
||||||
} elseif ($parents_str) {
|
} elseif ($parents_str) {
|
||||||
|
|
|
@ -145,20 +145,19 @@ function proxy_init(App $a) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$valid = true;
|
$valid = true;
|
||||||
$r = array();
|
$photo = null;
|
||||||
|
|
||||||
if (!$direct_cache && ($cachefile == '')) {
|
if (!$direct_cache && ($cachefile == '')) {
|
||||||
$r = dba::selectFirst('photo', ['data', 'desc'], ['resource-id' => $urlhash]);
|
$photo = dba::selectFirst('photo', ['data', 'desc'], ['resource-id' => $urlhash]);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($photo)) {
|
||||||
$img_str = $r['data'];
|
$img_str = $photo['data'];
|
||||||
$mime = $r['desc'];
|
$mime = $photo['desc'];
|
||||||
if ($mime == '') {
|
if ($mime == '') {
|
||||||
$mime = 'image/jpeg';
|
$mime = 'image/jpeg';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DBM::is_result($r)) {
|
if (!DBM::is_result($photo)) {
|
||||||
// It shouldn't happen but it does - spaces in URL
|
// It shouldn't happen but it does - spaces in URL
|
||||||
$_REQUEST['url'] = str_replace(' ', '+', $_REQUEST['url']);
|
$_REQUEST['url'] = str_replace(' ', '+', $_REQUEST['url']);
|
||||||
$redirects = 0;
|
$redirects = 0;
|
||||||
|
|
12
mod/xrd.php
12
mod/xrd.php
|
@ -36,24 +36,24 @@ function xrd_init(App $a)
|
||||||
$name = substr($local, 0, strpos($local, '@'));
|
$name = substr($local, 0, strpos($local, '@'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = dba::selectFirst('user', [], ['nickname' => $name]);
|
$user = dba::selectFirst('user', [], ['nickname' => $name]);
|
||||||
if (!DBM::is_result($r)) {
|
if (!DBM::is_result($user)) {
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
|
||||||
$profile_url = System::baseUrl().'/profile/'.$r['nickname'];
|
$profile_url = System::baseUrl().'/profile/'.$user['nickname'];
|
||||||
|
|
||||||
$alias = str_replace('/profile/', '/~', $profile_url);
|
$alias = str_replace('/profile/', '/~', $profile_url);
|
||||||
|
|
||||||
$addr = 'acct:'.$r['nickname'].'@'.$a->get_hostname();
|
$addr = 'acct:'.$user['nickname'].'@'.$a->get_hostname();
|
||||||
if ($a->get_path()) {
|
if ($a->get_path()) {
|
||||||
$addr .= '/'.$a->get_path();
|
$addr .= '/'.$a->get_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($mode == 'xml') {
|
if ($mode == 'xml') {
|
||||||
xrd_xml($a, $addr, $alias, $profile_url, $r);
|
xrd_xml($a, $addr, $alias, $profile_url, $user);
|
||||||
} else {
|
} else {
|
||||||
xrd_json($a, $addr, $alias, $profile_url, $r);
|
xrd_json($a, $addr, $alias, $profile_url, $user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,9 @@ class OEmbed
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
|
|
||||||
$condition = ['url' => normalise_link($embedurl), 'maxwidth' => $a->videowidth];
|
$condition = ['url' => normalise_link($embedurl), 'maxwidth' => $a->videowidth];
|
||||||
$r = dba::selectFirst('oembed', ['content'], $condition);
|
$oembed = dba::selectFirst('oembed', ['content'], $condition);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($oembed)) {
|
||||||
$txt = $r["content"];
|
$txt = $oembed["content"];
|
||||||
} else {
|
} else {
|
||||||
$txt = Cache::get($a->videowidth . $embedurl);
|
$txt = Cache::get($a->videowidth . $embedurl);
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,10 +109,10 @@ class Cache
|
||||||
// Frequently clear cache
|
// Frequently clear cache
|
||||||
self::clear();
|
self::clear();
|
||||||
|
|
||||||
$r = dba::selectFirst('cache', ['v'], ['k' => $key]);
|
$cache = dba::selectFirst('cache', ['v'], ['k' => $key]);
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($cache)) {
|
||||||
$cached = $r['v'];
|
$cached = $cache['v'];
|
||||||
$value = @unserialize($cached);
|
$value = @unserialize($cached);
|
||||||
|
|
||||||
// Only return a value if the serialized value is valid.
|
// Only return a value if the serialized value is valid.
|
||||||
|
|
|
@ -97,10 +97,10 @@ class Config
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = dba::selectFirst('config', ['v'], ['cat' => $family, 'k' => $key]);
|
$config = dba::selectFirst('config', ['v'], ['cat' => $family, 'k' => $key]);
|
||||||
if (DBM::is_result($ret)) {
|
if (DBM::is_result($config)) {
|
||||||
// manage array value
|
// manage array value
|
||||||
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret['v']) ? unserialize($ret['v']) : $ret['v']);
|
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $config['v']) ? unserialize($config['v']) : $config['v']);
|
||||||
|
|
||||||
// Assign the value from the database to the cache
|
// Assign the value from the database to the cache
|
||||||
self::$cache[$family][$key] = $val;
|
self::$cache[$family][$key] = $val;
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file src/Core/NotificationsManager.php
|
* @file src/Core/NotificationsManager.php
|
||||||
* @brief Methods for read and write notifications from/to database
|
* @brief Methods for read and write notifications from/to database
|
||||||
* or for formatting notifications
|
* or for formatting notifications
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core;
|
||||||
|
|
||||||
|
use Friendica\BaseObject;
|
||||||
use Friendica\Core\PConfig;
|
use Friendica\Core\PConfig;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\DBM;
|
use Friendica\Database\DBM;
|
||||||
|
@ -20,18 +23,8 @@ require_once 'include/bbcode.php';
|
||||||
* @brief Methods for read and write notifications from/to database
|
* @brief Methods for read and write notifications from/to database
|
||||||
* or for formatting notifications
|
* or for formatting notifications
|
||||||
*/
|
*/
|
||||||
class NotificationsManager
|
class NotificationsManager extends BaseObject
|
||||||
{
|
{
|
||||||
private $a;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->a = get_app();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief set some extra note properties
|
* @brief set some extra note properties
|
||||||
*
|
*
|
||||||
|
@ -51,15 +44,14 @@ class NotificationsManager
|
||||||
$local_time = datetime_convert('UTC', date_default_timezone_get(), $n['date']);
|
$local_time = datetime_convert('UTC', date_default_timezone_get(), $n['date']);
|
||||||
$n['timestamp'] = strtotime($local_time);
|
$n['timestamp'] = strtotime($local_time);
|
||||||
$n['date_rel'] = relative_date($n['date']);
|
$n['date_rel'] = relative_date($n['date']);
|
||||||
$n['msg_html'] = bbcode($n['msg'], false, false, false, false);
|
$n['msg_html'] = bbcode($n['msg'], false, false, false, false);
|
||||||
$n['msg_plain'] = explode("\n", trim(html2plain($n['msg_html'], 0)))[0];
|
$n['msg_plain'] = explode("\n", trim(html2plain($n['msg_html'], 0)))[0];
|
||||||
|
|
||||||
$rets[] = $n;
|
$rets[] = $n;
|
||||||
}
|
}
|
||||||
return $rets;
|
return $rets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get all notifications for local_user()
|
* @brief Get all notifications for local_user()
|
||||||
*
|
*
|
||||||
|
@ -77,19 +69,19 @@ class NotificationsManager
|
||||||
foreach ($filter as $column => $value) {
|
foreach ($filter as $column => $value) {
|
||||||
$filter_str[] = sprintf("`%s` = '%s'", $column, dbesc($value));
|
$filter_str[] = sprintf("`%s` = '%s'", $column, dbesc($value));
|
||||||
}
|
}
|
||||||
if (count($filter_str)>0) {
|
if (count($filter_str) > 0) {
|
||||||
$filter_sql = "AND ".implode(" AND ", $filter_str);
|
$filter_sql = "AND " . implode(" AND ", $filter_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
$aOrder = explode(" ", $order);
|
$aOrder = explode(" ", $order);
|
||||||
$asOrder = array();
|
$asOrder = array();
|
||||||
foreach ($aOrder as $o) {
|
foreach ($aOrder as $o) {
|
||||||
$dir = "asc";
|
$dir = "asc";
|
||||||
if ($o[0]==="-") {
|
if ($o[0] === "-") {
|
||||||
$dir = "desc";
|
$dir = "desc";
|
||||||
$o = substr($o, 1);
|
$o = substr($o, 1);
|
||||||
}
|
}
|
||||||
if ($o[0]==="+") {
|
if ($o[0] === "+") {
|
||||||
$dir = "asc";
|
$dir = "asc";
|
||||||
$o = substr($o, 1);
|
$o = substr($o, 1);
|
||||||
}
|
}
|
||||||
|
@ -98,12 +90,12 @@ class NotificationsManager
|
||||||
$order_sql = implode(", ", $asOrder);
|
$order_sql = implode(", ", $asOrder);
|
||||||
|
|
||||||
if ($limit != "") {
|
if ($limit != "") {
|
||||||
$limit = " LIMIT ".$limit;
|
$limit = " LIMIT " . $limit;
|
||||||
}
|
}
|
||||||
$r = q(
|
$r = q(
|
||||||
"SELECT * FROM `notify` WHERE `uid` = %d $filter_sql ORDER BY $order_sql $limit",
|
"SELECT * FROM `notify` WHERE `uid` = %d $filter_sql ORDER BY $order_sql $limit",
|
||||||
intval(local_user())
|
intval(local_user())
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
return $this->_set_extra($r);
|
return $this->_set_extra($r);
|
||||||
|
@ -175,37 +167,37 @@ class NotificationsManager
|
||||||
$tabs = array(
|
$tabs = array(
|
||||||
array(
|
array(
|
||||||
'label' => t('System'),
|
'label' => t('System'),
|
||||||
'url'=>'notifications/system',
|
'url' => 'notifications/system',
|
||||||
'sel'=> (($this->a->argv[1] == 'system') ? 'active' : ''),
|
'sel' => ((self::getApp()->argv[1] == 'system') ? 'active' : ''),
|
||||||
'id' => 'system-tab',
|
'id' => 'system-tab',
|
||||||
'accesskey' => 'y',
|
'accesskey' => 'y',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'label' => t('Network'),
|
'label' => t('Network'),
|
||||||
'url'=>'notifications/network',
|
'url' => 'notifications/network',
|
||||||
'sel'=> (($this->a->argv[1] == 'network') ? 'active' : ''),
|
'sel' => ((self::getApp()->argv[1] == 'network') ? 'active' : ''),
|
||||||
'id' => 'network-tab',
|
'id' => 'network-tab',
|
||||||
'accesskey' => 'w',
|
'accesskey' => 'w',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'label' => t('Personal'),
|
'label' => t('Personal'),
|
||||||
'url'=>'notifications/personal',
|
'url' => 'notifications/personal',
|
||||||
'sel'=> (($this->a->argv[1] == 'personal') ? 'active' : ''),
|
'sel' => ((self::getApp()->argv[1] == 'personal') ? 'active' : ''),
|
||||||
'id' => 'personal-tab',
|
'id' => 'personal-tab',
|
||||||
'accesskey' => 'r',
|
'accesskey' => 'r',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'label' => t('Home'),
|
'label' => t('Home'),
|
||||||
'url' => 'notifications/home',
|
'url' => 'notifications/home',
|
||||||
'sel'=> (($this->a->argv[1] == 'home') ? 'active' : ''),
|
'sel' => ((self::getApp()->argv[1] == 'home') ? 'active' : ''),
|
||||||
'id' => 'home-tab',
|
'id' => 'home-tab',
|
||||||
'accesskey' => 'h',
|
'accesskey' => 'h',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'label' => t('Introductions'),
|
'label' => t('Introductions'),
|
||||||
'url' => 'notifications/intros',
|
'url' => 'notifications/intros',
|
||||||
'sel'=> (($this->a->argv[1] == 'intros') ? 'active' : ''),
|
'sel' => ((self::getApp()->argv[1] == 'intros') ? 'active' : ''),
|
||||||
'id' => 'intro-tab',
|
'id' => 'intro-tab',
|
||||||
'accesskey' => 'i',
|
'accesskey' => 'i',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -219,14 +211,14 @@ class NotificationsManager
|
||||||
* @param array $notifs The array from the db query
|
* @param array $notifs The array from the db query
|
||||||
* @param string $ident The notifications identifier (e.g. network)
|
* @param string $ident The notifications identifier (e.g. network)
|
||||||
* @return array
|
* @return array
|
||||||
* string 'label' => The type of the notification
|
* string 'label' => The type of the notification
|
||||||
* string 'link' => URL to the source
|
* string 'link' => URL to the source
|
||||||
* string 'image' => The avatar image
|
* string 'image' => The avatar image
|
||||||
* string 'url' => The profile url of the contact
|
* string 'url' => The profile url of the contact
|
||||||
* string 'text' => The notification text
|
* string 'text' => The notification text
|
||||||
* string 'when' => The date of the notification
|
* string 'when' => The date of the notification
|
||||||
* string 'ago' => T relative date of the notification
|
* string 'ago' => T relative date of the notification
|
||||||
* bool 'seen' => Is the notification marked as "seen"
|
* bool 'seen' => Is the notification marked as "seen"
|
||||||
*/
|
*/
|
||||||
private function formatNotifs($notifs, $ident = "")
|
private function formatNotifs($notifs, $ident = "")
|
||||||
{
|
{
|
||||||
|
@ -246,7 +238,7 @@ class NotificationsManager
|
||||||
switch ($ident) {
|
switch ($ident) {
|
||||||
case 'system':
|
case 'system':
|
||||||
$default_item_label = 'notify';
|
$default_item_label = 'notify';
|
||||||
$default_item_link = System::baseUrl(true).'/notify/view/'. $it['id'];
|
$default_item_link = System::baseUrl(true) . '/notify/view/' . $it['id'];
|
||||||
$default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO);
|
$default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO);
|
||||||
$default_item_url = $it['url'];
|
$default_item_url = $it['url'];
|
||||||
$default_item_text = strip_tags(bbcode($it['msg']));
|
$default_item_text = strip_tags(bbcode($it['msg']));
|
||||||
|
@ -256,7 +248,7 @@ class NotificationsManager
|
||||||
|
|
||||||
case 'home':
|
case 'home':
|
||||||
$default_item_label = 'comment';
|
$default_item_label = 'comment';
|
||||||
$default_item_link = System::baseUrl(true).'/display/'.$it['pguid'];
|
$default_item_link = System::baseUrl(true) . '/display/' . $it['pguid'];
|
||||||
$default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
|
$default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
|
||||||
$default_item_url = $it['author-link'];
|
$default_item_url = $it['author-link'];
|
||||||
$default_item_text = sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']);
|
$default_item_text = sprintf(t("%s commented on %s's post"), $it['author-name'], $it['pname']);
|
||||||
|
@ -266,7 +258,7 @@ class NotificationsManager
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$default_item_label = (($it['id'] == $it['parent']) ? 'post' : 'comment');
|
$default_item_label = (($it['id'] == $it['parent']) ? 'post' : 'comment');
|
||||||
$default_item_link = System::baseUrl(true).'/display/'.$it['pguid'];
|
$default_item_link = System::baseUrl(true) . '/display/' . $it['pguid'];
|
||||||
$default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
|
$default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
|
||||||
$default_item_url = $it['author-link'];
|
$default_item_url = $it['author-link'];
|
||||||
$default_item_text = (($it['id'] == $it['parent'])
|
$default_item_text = (($it['id'] == $it['parent'])
|
||||||
|
@ -281,7 +273,7 @@ class NotificationsManager
|
||||||
case ACTIVITY_LIKE:
|
case ACTIVITY_LIKE:
|
||||||
$notif = array(
|
$notif = array(
|
||||||
'label' => 'like',
|
'label' => 'like',
|
||||||
'link' => System::baseUrl(true).'/display/'.$it['pguid'],
|
'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
|
||||||
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
||||||
'url' => $it['author-link'],
|
'url' => $it['author-link'],
|
||||||
'text' => sprintf(t("%s liked %s's post"), $it['author-name'], $it['pname']),
|
'text' => sprintf(t("%s liked %s's post"), $it['author-name'], $it['pname']),
|
||||||
|
@ -294,7 +286,7 @@ class NotificationsManager
|
||||||
case ACTIVITY_DISLIKE:
|
case ACTIVITY_DISLIKE:
|
||||||
$notif = array(
|
$notif = array(
|
||||||
'label' => 'dislike',
|
'label' => 'dislike',
|
||||||
'link' => System::baseUrl(true).'/display/'.$it['pguid'],
|
'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
|
||||||
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
||||||
'url' => $it['author-link'],
|
'url' => $it['author-link'],
|
||||||
'text' => sprintf(t("%s disliked %s's post"), $it['author-name'], $it['pname']),
|
'text' => sprintf(t("%s disliked %s's post"), $it['author-name'], $it['pname']),
|
||||||
|
@ -307,7 +299,7 @@ class NotificationsManager
|
||||||
case ACTIVITY_ATTEND:
|
case ACTIVITY_ATTEND:
|
||||||
$notif = array(
|
$notif = array(
|
||||||
'label' => 'attend',
|
'label' => 'attend',
|
||||||
'link' => System::baseUrl(true).'/display/'.$it['pguid'],
|
'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
|
||||||
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
||||||
'url' => $it['author-link'],
|
'url' => $it['author-link'],
|
||||||
'text' => sprintf(t("%s is attending %s's event"), $it['author-name'], $it['pname']),
|
'text' => sprintf(t("%s is attending %s's event"), $it['author-name'], $it['pname']),
|
||||||
|
@ -320,7 +312,7 @@ class NotificationsManager
|
||||||
case ACTIVITY_ATTENDNO:
|
case ACTIVITY_ATTENDNO:
|
||||||
$notif = array(
|
$notif = array(
|
||||||
'label' => 'attendno',
|
'label' => 'attendno',
|
||||||
'link' => System::baseUrl(true).'/display/'.$it['pguid'],
|
'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
|
||||||
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
||||||
'url' => $it['author-link'],
|
'url' => $it['author-link'],
|
||||||
'text' => sprintf(t("%s is not attending %s's event"), $it['author-name'], $it['pname']),
|
'text' => sprintf(t("%s is not attending %s's event"), $it['author-name'], $it['pname']),
|
||||||
|
@ -333,7 +325,7 @@ class NotificationsManager
|
||||||
case ACTIVITY_ATTENDMAYBE:
|
case ACTIVITY_ATTENDMAYBE:
|
||||||
$notif = array(
|
$notif = array(
|
||||||
'label' => 'attendmaybe',
|
'label' => 'attendmaybe',
|
||||||
'link' => System::baseUrl(true).'/display/'.$it['pguid'],
|
'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
|
||||||
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
||||||
'url' => $it['author-link'],
|
'url' => $it['author-link'],
|
||||||
'text' => sprintf(t("%s may attend %s's event"), $it['author-name'], $it['pname']),
|
'text' => sprintf(t("%s may attend %s's event"), $it['author-name'], $it['pname']),
|
||||||
|
@ -344,13 +336,13 @@ class NotificationsManager
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTIVITY_FRIEND:
|
case ACTIVITY_FRIEND:
|
||||||
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
|
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
|
||||||
$obj = parse_xml_string($xmlhead.$it['object']);
|
$obj = parse_xml_string($xmlhead . $it['object']);
|
||||||
$it['fname'] = $obj->title;
|
$it['fname'] = $obj->title;
|
||||||
|
|
||||||
$notif = array(
|
$notif = array(
|
||||||
'label' => 'friend',
|
'label' => 'friend',
|
||||||
'link' => System::baseUrl(true).'/display/'.$it['pguid'],
|
'link' => System::baseUrl(true) . '/display/' . $it['pguid'],
|
||||||
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
|
||||||
'url' => $it['author-link'],
|
'url' => $it['author-link'],
|
||||||
'text' => sprintf(t("%s is now friends with %s"), $it['author-name'], $it['fname']),
|
'text' => sprintf(t("%s is now friends with %s"), $it['author-name'], $it['fname']),
|
||||||
|
@ -383,7 +375,7 @@ class NotificationsManager
|
||||||
/**
|
/**
|
||||||
* @brief Total number of network notifications
|
* @brief Total number of network notifications
|
||||||
* @param int|string $seen If 0 only include notifications into the query
|
* @param int|string $seen If 0 only include notifications into the query
|
||||||
* which aren't marked as "seen"
|
* which aren't marked as "seen"
|
||||||
*
|
*
|
||||||
* @return int Number of network notifications
|
* @return int Number of network notifications
|
||||||
*/
|
*/
|
||||||
|
@ -403,7 +395,6 @@ class NotificationsManager
|
||||||
$sql_seen",
|
$sql_seen",
|
||||||
intval(local_user())
|
intval(local_user())
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
return $r[0]['total'];
|
return $r[0]['total'];
|
||||||
}
|
}
|
||||||
|
@ -415,14 +406,14 @@ class NotificationsManager
|
||||||
* @brief Get network notifications
|
* @brief Get network notifications
|
||||||
*
|
*
|
||||||
* @param int|string $seen If 0 only include notifications into the query
|
* @param int|string $seen If 0 only include notifications into the query
|
||||||
* which aren't marked as "seen"
|
* which aren't marked as "seen"
|
||||||
* @param int $start Start the query at this point
|
* @param int $start Start the query at this point
|
||||||
* @param int $limit Maximum number of query results
|
* @param int $limit Maximum number of query results
|
||||||
*
|
*
|
||||||
* @return array with
|
* @return array with
|
||||||
* string 'ident' => Notification identifier
|
* string 'ident' => Notification identifier
|
||||||
* int 'total' => Total number of available network notifications
|
* int 'total' => Total number of available network notifications
|
||||||
* array 'notifications' => Network notifications
|
* array 'notifications' => Network notifications
|
||||||
*/
|
*/
|
||||||
public function networkNotifs($seen = 0, $start = 0, $limit = 80)
|
public function networkNotifs($seen = 0, $start = 0, $limit = 80)
|
||||||
{
|
{
|
||||||
|
@ -435,7 +426,6 @@ class NotificationsManager
|
||||||
$sql_seen = " AND `item`.`unseen` = 1 ";
|
$sql_seen = " AND `item`.`unseen` = 1 ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$r = q(
|
$r = q(
|
||||||
"SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
|
"SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
|
||||||
`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
|
`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
|
||||||
|
@ -449,16 +439,15 @@ class NotificationsManager
|
||||||
intval($start),
|
intval($start),
|
||||||
intval($limit)
|
intval($limit)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
$notifs = $this->formatNotifs($r, $ident);
|
$notifs = $this->formatNotifs($r, $ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
$arr = array (
|
$arr = [
|
||||||
'notifications' => $notifs,
|
'notifications' => $notifs,
|
||||||
'ident' => $ident,
|
'ident' => $ident,
|
||||||
'total' => $total,
|
'total' => $total,
|
||||||
);
|
];
|
||||||
|
|
||||||
return $arr;
|
return $arr;
|
||||||
}
|
}
|
||||||
|
@ -466,7 +455,7 @@ class NotificationsManager
|
||||||
/**
|
/**
|
||||||
* @brief Total number of system notifications
|
* @brief Total number of system notifications
|
||||||
* @param int|string $seen If 0 only include notifications into the query
|
* @param int|string $seen If 0 only include notifications into the query
|
||||||
* which aren't marked as "seen"
|
* which aren't marked as "seen"
|
||||||
*
|
*
|
||||||
* @return int Number of system notifications
|
* @return int Number of system notifications
|
||||||
*/
|
*/
|
||||||
|
@ -482,7 +471,6 @@ class NotificationsManager
|
||||||
"SELECT COUNT(*) AS `total` FROM `notify` WHERE `uid` = %d $sql_seen",
|
"SELECT COUNT(*) AS `total` FROM `notify` WHERE `uid` = %d $sql_seen",
|
||||||
intval(local_user())
|
intval(local_user())
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
return $r[0]['total'];
|
return $r[0]['total'];
|
||||||
}
|
}
|
||||||
|
@ -494,14 +482,14 @@ class NotificationsManager
|
||||||
* @brief Get system notifications
|
* @brief Get system notifications
|
||||||
*
|
*
|
||||||
* @param int|string $seen If 0 only include notifications into the query
|
* @param int|string $seen If 0 only include notifications into the query
|
||||||
* which aren't marked as "seen"
|
* which aren't marked as "seen"
|
||||||
* @param int $start Start the query at this point
|
* @param int $start Start the query at this point
|
||||||
* @param int $limit Maximum number of query results
|
* @param int $limit Maximum number of query results
|
||||||
*
|
*
|
||||||
* @return array with
|
* @return array with
|
||||||
* string 'ident' => Notification identifier
|
* string 'ident' => Notification identifier
|
||||||
* int 'total' => Total number of available system notifications
|
* int 'total' => Total number of available system notifications
|
||||||
* array 'notifications' => System notifications
|
* array 'notifications' => System notifications
|
||||||
*/
|
*/
|
||||||
public function systemNotifs($seen = 0, $start = 0, $limit = 80)
|
public function systemNotifs($seen = 0, $start = 0, $limit = 80)
|
||||||
{
|
{
|
||||||
|
@ -521,30 +509,29 @@ class NotificationsManager
|
||||||
intval($start),
|
intval($start),
|
||||||
intval($limit)
|
intval($limit)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
$notifs = $this->formatNotifs($r, $ident);
|
$notifs = $this->formatNotifs($r, $ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
$arr = array (
|
$arr = [
|
||||||
'notifications' => $notifs,
|
'notifications' => $notifs,
|
||||||
'ident' => $ident,
|
'ident' => $ident,
|
||||||
'total' => $total,
|
'total' => $total,
|
||||||
);
|
];
|
||||||
|
|
||||||
return $arr;
|
return $arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Addional SQL query string for the personal notifications
|
* @brief Additional SQL query string for the personal notifications
|
||||||
*
|
*
|
||||||
* @return string The additional sql query
|
* @return string The additional SQL query
|
||||||
*/
|
*/
|
||||||
private function personalSqlExtra()
|
private function personalSqlExtra()
|
||||||
{
|
{
|
||||||
$myurl = System::baseUrl(true) . '/profile/'. $this->a->user['nickname'];
|
$myurl = System::baseUrl(true) . '/profile/' . self::getApp()->user['nickname'];
|
||||||
$myurl = substr($myurl, strpos($myurl, '://') + 3);
|
$myurl = substr($myurl, strpos($myurl, '://') + 3);
|
||||||
$myurl = str_replace(array('www.','.'), array('','\\.'), $myurl);
|
$myurl = str_replace(array('www.', '.'), array('', '\\.'), $myurl);
|
||||||
$diasp_url = str_replace('/profile/', '/u/', $myurl);
|
$diasp_url = str_replace('/profile/', '/u/', $myurl);
|
||||||
$sql_extra = sprintf(
|
$sql_extra = sprintf(
|
||||||
" AND ( `item`.`author-link` regexp '%s' OR `item`.`tag` regexp '%s' OR `item`.`tag` regexp '%s' ) ",
|
" AND ( `item`.`author-link` regexp '%s' OR `item`.`tag` regexp '%s' OR `item`.`tag` regexp '%s' ) ",
|
||||||
|
@ -559,7 +546,7 @@ class NotificationsManager
|
||||||
/**
|
/**
|
||||||
* @brief Total number of personal notifications
|
* @brief Total number of personal notifications
|
||||||
* @param int|string $seen If 0 only include notifications into the query
|
* @param int|string $seen If 0 only include notifications into the query
|
||||||
* which aren't marked as "seen"
|
* which aren't marked as "seen"
|
||||||
*
|
*
|
||||||
* @return int Number of personal notifications
|
* @return int Number of personal notifications
|
||||||
*/
|
*/
|
||||||
|
@ -581,7 +568,6 @@ class NotificationsManager
|
||||||
AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ",
|
AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ",
|
||||||
intval(local_user())
|
intval(local_user())
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
return $r[0]['total'];
|
return $r[0]['total'];
|
||||||
}
|
}
|
||||||
|
@ -593,14 +579,14 @@ class NotificationsManager
|
||||||
* @brief Get personal notifications
|
* @brief Get personal notifications
|
||||||
*
|
*
|
||||||
* @param int|string $seen If 0 only include notifications into the query
|
* @param int|string $seen If 0 only include notifications into the query
|
||||||
* which aren't marked as "seen"
|
* which aren't marked as "seen"
|
||||||
* @param int $start Start the query at this point
|
* @param int $start Start the query at this point
|
||||||
* @param int $limit Maximum number of query results
|
* @param int $limit Maximum number of query results
|
||||||
*
|
*
|
||||||
* @return array with
|
* @return array with
|
||||||
* string 'ident' => Notification identifier
|
* string 'ident' => Notification identifier
|
||||||
* int 'total' => Total number of available personal notifications
|
* int 'total' => Total number of available personal notifications
|
||||||
* array 'notifications' => Personal notifications
|
* array 'notifications' => Personal notifications
|
||||||
*/
|
*/
|
||||||
public function personalNotifs($seen = 0, $start = 0, $limit = 80)
|
public function personalNotifs($seen = 0, $start = 0, $limit = 80)
|
||||||
{
|
{
|
||||||
|
@ -628,12 +614,11 @@ class NotificationsManager
|
||||||
intval($start),
|
intval($start),
|
||||||
intval($limit)
|
intval($limit)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
$notifs = $this->formatNotifs($r, $ident);
|
$notifs = $this->formatNotifs($r, $ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
$arr = array (
|
$arr = array(
|
||||||
'notifications' => $notifs,
|
'notifications' => $notifs,
|
||||||
'ident' => $ident,
|
'ident' => $ident,
|
||||||
'total' => $total,
|
'total' => $total,
|
||||||
|
@ -645,7 +630,7 @@ class NotificationsManager
|
||||||
/**
|
/**
|
||||||
* @brief Total number of home notifications
|
* @brief Total number of home notifications
|
||||||
* @param int|string $seen If 0 only include notifications into the query
|
* @param int|string $seen If 0 only include notifications into the query
|
||||||
* which aren't marked as "seen"
|
* which aren't marked as "seen"
|
||||||
*
|
*
|
||||||
* @return int Number of home notifications
|
* @return int Number of home notifications
|
||||||
*/
|
*/
|
||||||
|
@ -664,7 +649,6 @@ class NotificationsManager
|
||||||
$sql_seen",
|
$sql_seen",
|
||||||
intval(local_user())
|
intval(local_user())
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
return $r[0]['total'];
|
return $r[0]['total'];
|
||||||
}
|
}
|
||||||
|
@ -676,14 +660,14 @@ class NotificationsManager
|
||||||
* @brief Get home notifications
|
* @brief Get home notifications
|
||||||
*
|
*
|
||||||
* @param int|string $seen If 0 only include notifications into the query
|
* @param int|string $seen If 0 only include notifications into the query
|
||||||
* which aren't marked as "seen"
|
* which aren't marked as "seen"
|
||||||
* @param int $start Start the query at this point
|
* @param int $start Start the query at this point
|
||||||
* @param int $limit Maximum number of query results
|
* @param int $limit Maximum number of query results
|
||||||
*
|
*
|
||||||
* @return array with
|
* @return array with
|
||||||
* string 'ident' => Notification identifier
|
* string 'ident' => Notification identifier
|
||||||
* int 'total' => Total number of available home notifications
|
* int 'total' => Total number of available home notifications
|
||||||
* array 'notifications' => Home notifications
|
* array 'notifications' => Home notifications
|
||||||
*/
|
*/
|
||||||
public function homeNotifs($seen = 0, $start = 0, $limit = 80)
|
public function homeNotifs($seen = 0, $start = 0, $limit = 80)
|
||||||
{
|
{
|
||||||
|
@ -709,16 +693,15 @@ class NotificationsManager
|
||||||
intval($start),
|
intval($start),
|
||||||
intval($limit)
|
intval($limit)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
$notifs = $this->formatNotifs($r, $ident);
|
$notifs = $this->formatNotifs($r, $ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
$arr = array (
|
$arr = [
|
||||||
'notifications' => $notifs,
|
'notifications' => $notifs,
|
||||||
'ident' => $ident,
|
'ident' => $ident,
|
||||||
'total' => $total,
|
'total' => $total,
|
||||||
);
|
];
|
||||||
|
|
||||||
return $arr;
|
return $arr;
|
||||||
}
|
}
|
||||||
|
@ -726,7 +709,7 @@ class NotificationsManager
|
||||||
/**
|
/**
|
||||||
* @brief Total number of introductions
|
* @brief Total number of introductions
|
||||||
* @param bool $all If false only include introductions into the query
|
* @param bool $all If false only include introductions into the query
|
||||||
* which aren't marked as ignored
|
* which aren't marked as ignored
|
||||||
*
|
*
|
||||||
* @return int Number of introductions
|
* @return int Number of introductions
|
||||||
*/
|
*/
|
||||||
|
@ -755,7 +738,7 @@ class NotificationsManager
|
||||||
* @brief Get introductions
|
* @brief Get introductions
|
||||||
*
|
*
|
||||||
* @param bool $all If false only include introductions into the query
|
* @param bool $all If false only include introductions into the query
|
||||||
* which aren't marked as ignored
|
* which aren't marked as ignored
|
||||||
* @param int $start Start the query at this point
|
* @param int $start Start the query at this point
|
||||||
* @param int $limit Maximum number of query results
|
* @param int $limit Maximum number of query results
|
||||||
*
|
*
|
||||||
|
@ -793,16 +776,15 @@ class NotificationsManager
|
||||||
intval($start),
|
intval($start),
|
||||||
intval($limit)
|
intval($limit)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
$notifs = $this->formatIntros($r);
|
$notifs = $this->formatIntros($r);
|
||||||
}
|
}
|
||||||
|
|
||||||
$arr = array (
|
$arr = [
|
||||||
'ident' => $ident,
|
'ident' => $ident,
|
||||||
'total' => $total,
|
'total' => $total,
|
||||||
'notifications' => $notifs,
|
'notifications' => $notifs,
|
||||||
);
|
];
|
||||||
|
|
||||||
return $arr;
|
return $arr;
|
||||||
}
|
}
|
||||||
|
@ -820,10 +802,9 @@ class NotificationsManager
|
||||||
foreach ($intros as $it) {
|
foreach ($intros as $it) {
|
||||||
// There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
|
// There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
|
||||||
// We have to distinguish between these two because they use different data.
|
// We have to distinguish between these two because they use different data.
|
||||||
|
|
||||||
// Contact suggestions
|
// Contact suggestions
|
||||||
if ($it['fid']) {
|
if ($it['fid']) {
|
||||||
$return_addr = bin2hex($this->a->user['nickname'] . '@' . $this->a->get_hostname() . (($this->a->path) ? '/' . $this->a->path : ''));
|
$return_addr = bin2hex(self::getApp()->user['nickname'] . '@' . self::getApp()->get_hostname() . ((self::getApp()->path) ? '/' . self::getApp()->path : ''));
|
||||||
|
|
||||||
$intro = array(
|
$intro = array(
|
||||||
'label' => 'friend_suggestion',
|
'label' => 'friend_suggestion',
|
||||||
|
@ -839,7 +820,6 @@ class NotificationsManager
|
||||||
'knowyou' => $knowyou,
|
'knowyou' => $knowyou,
|
||||||
'note' => $it['note'],
|
'note' => $it['note'],
|
||||||
'request' => $it['frequest'] . '?addr=' . $return_addr,
|
'request' => $it['frequest'] . '?addr=' . $return_addr,
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Normal connection requests
|
// Normal connection requests
|
||||||
|
|
|
@ -90,9 +90,9 @@ class PConfig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $family, 'k' => $key]);
|
$pconfig = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $family, 'k' => $key]);
|
||||||
if (DBM::is_result($ret)) {
|
if (DBM::is_result($pconfig)) {
|
||||||
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret['v']) ? unserialize($ret['v']) : $ret['v']);
|
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $pconfig['v']) ? unserialize($pconfig['v']) : $pconfig['v']);
|
||||||
$a->config[$uid][$family][$key] = $val;
|
$a->config[$uid][$family][$key] = $val;
|
||||||
self::$in_db[$uid][$family][$key] = true;
|
self::$in_db[$uid][$family][$key] = true;
|
||||||
|
|
||||||
|
|
|
@ -165,9 +165,9 @@ class Worker
|
||||||
private static function highestPriority()
|
private static function highestPriority()
|
||||||
{
|
{
|
||||||
$condition = array("`executed` <= ? AND NOT `done`", NULL_DATE);
|
$condition = array("`executed` <= ? AND NOT `done`", NULL_DATE);
|
||||||
$s = dba::selectFirst('workerqueue', ['priority'], $condition, ['order' => ['priority']]);
|
$workerqueue = dba::selectFirst('workerqueue', ['priority'], $condition, ['order' => ['priority']]);
|
||||||
if (DBM::is_result($s)) {
|
if (DBM::is_result($workerqueue)) {
|
||||||
return $s["priority"];
|
return $workerqueue["priority"];
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,6 @@ class Contact extends BaseObject
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the self-contact for the provided user id
|
* Creates the self-contact for the provided user id
|
||||||
*
|
*
|
||||||
|
@ -145,13 +144,12 @@ class Contact extends BaseObject
|
||||||
public static function remove($id)
|
public static function remove($id)
|
||||||
{
|
{
|
||||||
// We want just to make sure that we don't delete our "self" contact
|
// We want just to make sure that we don't delete our "self" contact
|
||||||
$r = dba::selectFirst('contact', ['uid'], ['id' => $id, 'self' => false]);
|
$contact = dba::selectFirst('contact', ['uid'], ['id' => $id, 'self' => false]);
|
||||||
|
if (!DBM::is_result($contact) || !intval($contact['uid'])) {
|
||||||
if (!DBM::is_result($r) || !intval($r['uid'])) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$archive = PConfig::get($r['uid'], 'system', 'archive_removed_contacts');
|
$archive = PConfig::get($contact['uid'], 'system', 'archive_removed_contacts');
|
||||||
if ($archive) {
|
if ($archive) {
|
||||||
dba::update('contact', array('archive' => true, 'network' => 'none', 'writable' => false), array('id' => $id));
|
dba::update('contact', array('archive' => true, 'network' => 'none', 'writable' => false), array('id' => $id));
|
||||||
return;
|
return;
|
||||||
|
@ -433,19 +431,27 @@ class Contact extends BaseObject
|
||||||
// Fetch contact data from the contact table for the given user
|
// Fetch contact data from the contact table for the given user
|
||||||
$r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
|
$r = q("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
|
||||||
`keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`
|
`keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self`
|
||||||
FROM `contact` WHERE `addr` = '%s' AND `uid` = %d", dbesc($addr), intval($uid));
|
FROM `contact` WHERE `addr` = '%s' AND `uid` = %d",
|
||||||
|
dbesc($addr),
|
||||||
|
intval($uid)
|
||||||
|
);
|
||||||
// Fetch the data from the contact table with "uid=0" (which is filled automatically)
|
// Fetch the data from the contact table with "uid=0" (which is filled automatically)
|
||||||
if (!DBM::is_result($r))
|
if (!DBM::is_result($r)) {
|
||||||
$r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
|
$r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
|
||||||
`keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`
|
`keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`
|
||||||
FROM `contact` WHERE `addr` = '%s' AND `uid` = 0", dbesc($addr));
|
FROM `contact` WHERE `addr` = '%s' AND `uid` = 0",
|
||||||
|
dbesc($addr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch the data from the gcontact table
|
// Fetch the data from the gcontact table
|
||||||
if (!DBM::is_result($r))
|
if (!DBM::is_result($r)) {
|
||||||
$r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`,
|
$r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`,
|
||||||
`keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
|
`keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
|
||||||
FROM `gcontact` WHERE `addr` = '%s'", dbesc($addr));
|
FROM `gcontact` WHERE `addr` = '%s'",
|
||||||
|
dbesc($addr)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!DBM::is_result($r)) {
|
if (!DBM::is_result($r)) {
|
||||||
$data = Probe::uri($addr);
|
$data = Probe::uri($addr);
|
||||||
|
@ -490,9 +496,10 @@ class Contact extends BaseObject
|
||||||
return $menu;
|
return $menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = dba::selectFirst('contact', [], ['nurl' => $contact['nurl'], 'network' => $contact['network'], 'uid' => $uid]);
|
// Look for our own contact if the uid doesn't match and isn't public
|
||||||
if ($r) {
|
$contact_own = dba::selectFirst('contact', [], ['nurl' => $contact['nurl'], 'network' => $contact['network'], 'uid' => $uid]);
|
||||||
return self::photoMenu($r, $uid);
|
if (DBM::is_result($contact_own)) {
|
||||||
|
return self::photoMenu($contact_own, $uid);
|
||||||
} else {
|
} else {
|
||||||
$profile_link = zrl($contact['url']);
|
$profile_link = zrl($contact['url']);
|
||||||
$connlnk = 'follow/?url=' . $contact['url'];
|
$connlnk = 'follow/?url=' . $contact['url'];
|
||||||
|
@ -540,19 +547,18 @@ class Contact extends BaseObject
|
||||||
* Menu array:
|
* Menu array:
|
||||||
* "name" => [ "Label", "link", (bool)Should the link opened in a new tab? ]
|
* "name" => [ "Label", "link", (bool)Should the link opened in a new tab? ]
|
||||||
*/
|
*/
|
||||||
$menu = array(
|
$menu = [
|
||||||
'status' => array(t("View Status"), $status_link, true),
|
'status' => [t("View Status") , $status_link , true],
|
||||||
'profile' => array(t("View Profile"), $profile_link, true),
|
'profile' => [t("View Profile") , $profile_link , true],
|
||||||
'photos' => array(t("View Photos"), $photos_link, true),
|
'photos' => [t("View Photos") , $photos_link , true],
|
||||||
'network' => array(t("Network Posts"), $posts_link, false),
|
'network' => [t("Network Posts"), $posts_link , false],
|
||||||
'edit' => array(t("View Contact"), $contact_url, false),
|
'edit' => [t("View Contact") , $contact_url , false],
|
||||||
'drop' => array(t("Drop Contact"), $contact_drop_link, false),
|
'drop' => [t("Drop Contact") , $contact_drop_link, false],
|
||||||
'pm' => array(t("Send PM"), $pm_url, false),
|
'pm' => [t("Send PM") , $pm_url , false],
|
||||||
'poke' => array(t("Poke"), $poke_link, false),
|
'poke' => [t("Poke") , $poke_link , false],
|
||||||
);
|
];
|
||||||
|
|
||||||
|
$args = ['contact' => $contact, 'menu' => &$menu];
|
||||||
$args = array('contact' => $contact, 'menu' => &$menu);
|
|
||||||
|
|
||||||
call_hooks('contact_photo_menu', $args);
|
call_hooks('contact_photo_menu', $args);
|
||||||
|
|
||||||
|
@ -593,7 +599,9 @@ class Contact extends BaseObject
|
||||||
SELECT DISTINCT(`contact-id`)
|
SELECT DISTINCT(`contact-id`)
|
||||||
FROM `group_member`
|
FROM `group_member`
|
||||||
WHERE `uid` = %d
|
WHERE `uid` = %d
|
||||||
)", intval($uid), intval($uid)
|
)",
|
||||||
|
intval($uid),
|
||||||
|
intval($uid)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $r;
|
return $r;
|
||||||
|
@ -612,13 +620,18 @@ class Contact extends BaseObject
|
||||||
INNER JOIN `group` ON `group`.`id` = `group_member`.`gid`
|
INNER JOIN `group` ON `group`.`id` = `group_member`.`gid`
|
||||||
WHERE `group`.`uid` = %d
|
WHERE `group`.`uid` = %d
|
||||||
)
|
)
|
||||||
LIMIT %d, %d", intval($uid), intval($uid), intval($start), intval($count)
|
LIMIT %d, %d",
|
||||||
|
intval($uid),
|
||||||
|
intval($uid),
|
||||||
|
intval($start),
|
||||||
|
intval($count)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Fetch the contact id for a given url and user
|
* @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`,
|
* First lookup in the contact table to find a record matching either `url`, `nurl`,
|
||||||
* `addr` or `alias`.
|
* `addr` or `alias`.
|
||||||
|
@ -627,7 +640,7 @@ class Contact extends BaseObject
|
||||||
* If there's one, we check that it isn't time to update the picture else we
|
* If there's one, we check that it isn't time to update the picture else we
|
||||||
* directly return the found contact id.
|
* directly return the found contact id.
|
||||||
*
|
*
|
||||||
* Second, we probe the provided $url wether it's http://server.tld/profile or
|
* Second, we probe the provided $url whether it's http://server.tld/profile or
|
||||||
* nick@server.tld. We quit if we can't get any info back.
|
* nick@server.tld. We quit if we can't get any info back.
|
||||||
*
|
*
|
||||||
* Third, we create the contact record if it doesn't exist
|
* Third, we create the contact record if it doesn't exist
|
||||||
|
@ -664,9 +677,8 @@ class Contact extends BaseObject
|
||||||
if (!DBM::is_result($contact)) {
|
if (!DBM::is_result($contact)) {
|
||||||
// The link could be provided as http although we stored it as https
|
// The link could be provided as http although we stored it as https
|
||||||
$ssl_url = str_replace('http://', 'https://', $url);
|
$ssl_url = str_replace('http://', 'https://', $url);
|
||||||
$r = dba::selectFirst('contact', ['id', 'avatar', 'avatar-date'], ['`alias` IN (?, ?, ?) AND `uid` = ?', $url, normalise_link($url), $ssl_url, $uid]);
|
$condition = ['`alias` IN (?, ?, ?) AND `uid` = ?', $url, normalise_link($url), $ssl_url, $uid];
|
||||||
$contact = dba::fetch($r);
|
$contact = dba::selectFirst('contact', ['id', 'avatar', 'avatar-date'], $condition);
|
||||||
dba::close($r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBM::is_result($contact)) {
|
if (DBM::is_result($contact)) {
|
||||||
|
@ -697,12 +709,12 @@ class Contact extends BaseObject
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get data from the gcontact table
|
// Get data from the gcontact table
|
||||||
$gcontacts = dba::selectFirst('gcontact', ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'], ['nurl' => normalise_link($url)]);
|
$gcontact = dba::selectFirst('gcontact', ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'], ['nurl' => normalise_link($url)]);
|
||||||
if (!DBM::is_result($gcontacts)) {
|
if (!DBM::is_result($gcontact)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = array_merge($data, $gcontacts);
|
$data = array_merge($data, $gcontact);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url)) {
|
if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url)) {
|
||||||
|
@ -711,22 +723,39 @@ class Contact extends BaseObject
|
||||||
|
|
||||||
$url = $data["url"];
|
$url = $data["url"];
|
||||||
if (!$contact_id) {
|
if (!$contact_id) {
|
||||||
dba::insert(
|
dba::insert('contact', [
|
||||||
'contact', array('uid' => $uid, 'created' => datetime_convert(), 'url' => $data["url"],
|
'uid' => $uid,
|
||||||
'nurl' => normalise_link($data["url"]), 'addr' => $data["addr"],
|
'created' => datetime_convert(),
|
||||||
'alias' => $data["alias"], 'notify' => $data["notify"], 'poll' => $data["poll"],
|
'url' => $data["url"],
|
||||||
'name' => $data["name"], 'nick' => $data["nick"], 'photo' => $data["photo"],
|
'nurl' => normalise_link($data["url"]),
|
||||||
'keywords' => $data["keywords"], 'location' => $data["location"], 'about' => $data["about"],
|
'addr' => $data["addr"],
|
||||||
'network' => $data["network"], 'pubkey' => $data["pubkey"],
|
'alias' => $data["alias"],
|
||||||
'rel' => CONTACT_IS_SHARING, 'priority' => $data["priority"],
|
'notify' => $data["notify"],
|
||||||
'batch' => $data["batch"], 'request' => $data["request"],
|
'poll' => $data["poll"],
|
||||||
'confirm' => $data["confirm"], 'poco' => $data["poco"],
|
'name' => $data["name"],
|
||||||
'name-date' => datetime_convert(), 'uri-date' => datetime_convert(),
|
'nick' => $data["nick"],
|
||||||
'avatar-date' => datetime_convert(), 'writable' => 1, 'blocked' => 0,
|
'photo' => $data["photo"],
|
||||||
'readonly' => 0, 'pending' => 0)
|
'keywords' => $data["keywords"],
|
||||||
|
'location' => $data["location"],
|
||||||
|
'about' => $data["about"],
|
||||||
|
'network' => $data["network"],
|
||||||
|
'pubkey' => $data["pubkey"],
|
||||||
|
'rel' => CONTACT_IS_SHARING,
|
||||||
|
'priority' => $data["priority"],
|
||||||
|
'batch' => $data["batch"],
|
||||||
|
'request' => $data["request"],
|
||||||
|
'confirm' => $data["confirm"],
|
||||||
|
'poco' => $data["poco"],
|
||||||
|
'name-date' => datetime_convert(),
|
||||||
|
'uri-date' => datetime_convert(),
|
||||||
|
'avatar-date' => datetime_convert(),
|
||||||
|
'writable' => 1,
|
||||||
|
'blocked' => 0,
|
||||||
|
'readonly' => 0,
|
||||||
|
'pending' => 0]
|
||||||
);
|
);
|
||||||
|
|
||||||
$s = dba::select('contact', array('id'), array('nurl' => normalise_link($data["url"]), 'uid' => $uid), array('order' => array('id'), 'limit' => 2));
|
$s = dba::select('contact', ['id'], ['nurl' => normalise_link($data["url"]), 'uid' => $uid], ['order' => ['id'], 'limit' => 2]);
|
||||||
$contacts = dba::inArray($s);
|
$contacts = dba::inArray($s);
|
||||||
if (!DBM::is_result($contacts)) {
|
if (!DBM::is_result($contacts)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -751,8 +780,8 @@ class Contact extends BaseObject
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($contacts) > 1 && $uid == 0 && $contact_id != 0 && $data["url"] != "") {
|
if (count($contacts) > 1 && $uid == 0 && $contact_id != 0 && $data["url"] != "") {
|
||||||
dba::delete('contact', array("`nurl` = ? AND `uid` = 0 AND `id` != ? AND NOT `self`",
|
dba::delete('contact', ["`nurl` = ? AND `uid` = 0 AND `id` != ? AND NOT `self`",
|
||||||
normalise_link($data["url"]), $contact_id));
|
normalise_link($data["url"]), $contact_id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -860,7 +889,9 @@ class Contact extends BaseObject
|
||||||
// There are no posts with "uid = 0" with connector networks
|
// There are no posts with "uid = 0" with connector networks
|
||||||
// This speeds up the query a lot
|
// This speeds up the query a lot
|
||||||
$r = q("SELECT `network`, `id` AS `author-id`, `contact-type` FROM `contact`
|
$r = q("SELECT `network`, `id` AS `author-id`, `contact-type` FROM `contact`
|
||||||
WHERE `contact`.`nurl` = '%s' AND `contact`.`uid` = 0", dbesc(normalise_link($contact_url)));
|
WHERE `contact`.`nurl` = '%s' AND `contact`.`uid` = 0",
|
||||||
|
dbesc(normalise_link($contact_url))
|
||||||
|
);
|
||||||
|
|
||||||
if (!DBM::is_result($r)) {
|
if (!DBM::is_result($r)) {
|
||||||
return '';
|
return '';
|
||||||
|
@ -882,7 +913,6 @@ class Contact extends BaseObject
|
||||||
intval($a->pager['start']), intval($a->pager['itemspage'])
|
intval($a->pager['start']), intval($a->pager['itemspage'])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$o = conversation($a, $r, 'contact-posts', false);
|
$o = conversation($a, $r, 'contact-posts', false);
|
||||||
|
|
||||||
$o .= alt_pager($a, count($r));
|
$o .= alt_pager($a, count($r));
|
||||||
|
@ -919,6 +949,7 @@ class Contact extends BaseObject
|
||||||
if (isset($contact["contact-type"])) {
|
if (isset($contact["contact-type"])) {
|
||||||
$type = $contact["contact-type"];
|
$type = $contact["contact-type"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($contact["account-type"])) {
|
if (isset($contact["account-type"])) {
|
||||||
$type = $contact["account-type"];
|
$type = $contact["account-type"];
|
||||||
}
|
}
|
||||||
|
@ -965,10 +996,10 @@ class Contact extends BaseObject
|
||||||
$return = dba::update('contact', ['blocked' => false], ['id' => $uid]);
|
$return = dba::update('contact', ['blocked' => false], ['id' => $uid]);
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Updates the avatar links in a contact only if needed
|
* @brief Updates the avatar links in a contact only if needed
|
||||||
*
|
*
|
||||||
* @param string $avatar Link to avatar picture
|
* @param string $avatar Link to avatar picture
|
||||||
* @param int $uid User id of contact owner
|
* @param int $uid User id of contact owner
|
||||||
|
@ -979,15 +1010,14 @@ class Contact extends BaseObject
|
||||||
*/
|
*/
|
||||||
public static function updateAvatar($avatar, $uid, $cid, $force = false)
|
public static function updateAvatar($avatar, $uid, $cid, $force = false)
|
||||||
{
|
{
|
||||||
// Limit = 1 returns the row so no need for dba:inArray()
|
$contact = dba::selectFirst('contact', ['avatar', 'photo', 'thumb', 'micro', 'nurl'], ['id' => $cid]);
|
||||||
$r = dba::selectFirst('contact', ['avatar', 'photo', 'thumb', 'micro', 'nurl'], ['id' => $cid]);
|
if (!DBM::is_result($contact)) {
|
||||||
if (!DBM::is_result($r)) {
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
$data = array($r["photo"], $r["thumb"], $r["micro"]);
|
$data = array($contact["photo"], $contact["thumb"], $contact["micro"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($r["avatar"] != $avatar) || $force) {
|
if (($contact["avatar"] != $avatar) || $force) {
|
||||||
$photos = Photo::importProfilePhoto($avatar, $uid, $cid, true);
|
$photos = Photo::importProfilePhoto($avatar, $uid, $cid, true);
|
||||||
|
|
||||||
if ($photos) {
|
if ($photos) {
|
||||||
|
@ -999,7 +1029,7 @@ class Contact extends BaseObject
|
||||||
|
|
||||||
// Update the public contact (contact id = 0)
|
// Update the public contact (contact id = 0)
|
||||||
if ($uid != 0) {
|
if ($uid != 0) {
|
||||||
$pcontact = dba::selectFirst('contact', ['id'], ['nurl' => $r[0]['nurl']]);
|
$pcontact = dba::selectFirst('contact', ['id'], ['nurl' => $contact['nurl']]);
|
||||||
if (DBM::is_result($pcontact)) {
|
if (DBM::is_result($pcontact)) {
|
||||||
self::updateAvatar($avatar, 0, $pcontact['id'], $force);
|
self::updateAvatar($avatar, 0, $pcontact['id'], $force);
|
||||||
}
|
}
|
||||||
|
@ -1019,19 +1049,20 @@ class Contact extends BaseObject
|
||||||
public static function updateFromProbe($id)
|
public static function updateFromProbe($id)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Warning: Never ever fetch the public key via Probe::uri and write it into the contacts.
|
Warning: Never ever fetch the public key via Probe::uri and write it into the contacts.
|
||||||
This will reliably kill your communication with Friendica contacts.
|
This will reliably kill your communication with Friendica contacts.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$r = dba::selectFirst('contact', ['url', 'nurl', 'addr', 'alias', 'batch', 'notify', 'poll', 'poco', 'network'], ['id' => $id]);
|
$fields = ['url', 'nurl', 'addr', 'alias', 'batch', 'notify', 'poll', 'poco', 'network'];
|
||||||
if (!DBM::is_result($r)) {
|
$contact = dba::selectFirst('contact', $fields, ['id' => $id]);
|
||||||
|
if (!DBM::is_result($contact)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = Probe::uri($r["url"]);
|
$ret = Probe::uri($contact["url"]);
|
||||||
|
|
||||||
// If Probe::uri fails the network code will be different
|
// If Probe::uri fails the network code will be different
|
||||||
if ($ret["network"] != $r["network"]) {
|
if ($ret["network"] != $contact["network"]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1039,11 +1070,13 @@ class Contact extends BaseObject
|
||||||
|
|
||||||
// make sure to not overwrite existing values with blank entries
|
// make sure to not overwrite existing values with blank entries
|
||||||
foreach ($ret as $key => $val) {
|
foreach ($ret as $key => $val) {
|
||||||
if (isset($r[$key]) && ($r[$key] != "") && ($val == ""))
|
if (isset($contact[$key]) && ($contact[$key] != "") && ($val == "")) {
|
||||||
$ret[$key] = $r[$key];
|
$ret[$key] = $contact[$key];
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($r[$key]) && ($ret[$key] != $r[$key]))
|
if (isset($contact[$key]) && ($ret[$key] != $contact[$key])) {
|
||||||
$update = true;
|
$update = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$update) {
|
if (!$update) {
|
||||||
|
@ -1051,16 +1084,15 @@ class Contact extends BaseObject
|
||||||
}
|
}
|
||||||
|
|
||||||
dba::update(
|
dba::update(
|
||||||
'contact',
|
'contact', [
|
||||||
[
|
'url' => $ret['url'],
|
||||||
'url' => $ret['url'],
|
'nurl' => normalise_link($ret['url']),
|
||||||
'nurl' => normalise_link($ret['url']),
|
'addr' => $ret['addr'],
|
||||||
'addr' => $ret['addr'],
|
'alias' => $ret['alias'],
|
||||||
'alias' => $ret['alias'],
|
'batch' => $ret['batch'],
|
||||||
'batch' => $ret['batch'],
|
|
||||||
'notify' => $ret['notify'],
|
'notify' => $ret['notify'],
|
||||||
'poll' => $ret['poll'],
|
'poll' => $ret['poll'],
|
||||||
'poco' => $ret['poco']
|
'poco' => $ret['poco']
|
||||||
],
|
],
|
||||||
['id' => $id]
|
['id' => $id]
|
||||||
);
|
);
|
||||||
|
@ -1076,7 +1108,7 @@ class Contact extends BaseObject
|
||||||
* Currently if the contact is DFRN, interactive needs to be true, to redirect to the
|
* Currently if the contact is DFRN, interactive needs to be true, to redirect to the
|
||||||
* dfrn_request page.
|
* dfrn_request page.
|
||||||
*
|
*
|
||||||
* Otherwise this can be used to bulk add statusnet contacts, twitter contacts, etc.
|
* Otherwise this can be used to bulk add StatusNet contacts, Twitter contacts, etc.
|
||||||
*
|
*
|
||||||
* Returns an array
|
* Returns an array
|
||||||
* $return['success'] boolean true if successful
|
* $return['success'] boolean true if successful
|
||||||
|
@ -1203,7 +1235,9 @@ class Contact extends BaseObject
|
||||||
|
|
||||||
if (!DBM::is_result($r)) {
|
if (!DBM::is_result($r)) {
|
||||||
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` = '%s' LIMIT 1",
|
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` = '%s' LIMIT 1",
|
||||||
intval($uid), dbesc(normalise_link($url)), dbesc($ret['network'])
|
intval($uid),
|
||||||
|
dbesc(normalise_link($url)),
|
||||||
|
dbesc($ret['network'])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1217,33 +1251,30 @@ class Contact extends BaseObject
|
||||||
$new_relation = ((in_array($ret['network'], array(NETWORK_MAIL))) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING);
|
$new_relation = ((in_array($ret['network'], array(NETWORK_MAIL))) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING);
|
||||||
|
|
||||||
// create contact record
|
// create contact record
|
||||||
dba::insert(
|
dba::insert('contact', [
|
||||||
'contact',
|
'uid' => $uid,
|
||||||
[
|
'created' => datetime_convert(),
|
||||||
'uid' => $uid,
|
'url' => $ret['url'],
|
||||||
'created' => datetime_convert(),
|
'nurl' => normalise_link($ret['url']),
|
||||||
'url' => $ret['url'],
|
'addr' => $ret['addr'],
|
||||||
'nurl' => normalise_link($ret['url']),
|
'alias' => $ret['alias'],
|
||||||
'addr' => $ret['addr'],
|
'batch' => $ret['batch'],
|
||||||
'alias' => $ret['alias'],
|
'notify' => $ret['notify'],
|
||||||
'batch' => $ret['batch'],
|
'poll' => $ret['poll'],
|
||||||
'notify' => $ret['notify'],
|
'poco' => $ret['poco'],
|
||||||
'poll' => $ret['poll'],
|
'name' => $ret['name'],
|
||||||
'poco' => $ret['poco'],
|
'nick' => $ret['nick'],
|
||||||
'name' => $ret['name'],
|
'network' => $ret['network'],
|
||||||
'nick' => $ret['nick'],
|
'pubkey' => $ret['pubkey'],
|
||||||
'network' => $ret['network'],
|
'rel' => $new_relation,
|
||||||
'pubkey' => $ret['pubkey'],
|
'priority'=> $ret['priority'],
|
||||||
'rel' => $new_relation,
|
'writable'=> $writeable,
|
||||||
'priority' => $ret['priority'],
|
'hidden' => $hidden,
|
||||||
'writable' => $writeable,
|
'blocked' => 0,
|
||||||
'hidden' => $hidden,
|
'readonly'=> 0,
|
||||||
'blocked' => 0,
|
'pending' => 0,
|
||||||
'readonly' => 0,
|
'subhub' => $subhub
|
||||||
'pending' => 0,
|
]);
|
||||||
'subhub' => $subhub
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$contact = dba::selectFirst('contact', [], ['url' => $ret['url'], 'network' => $ret['network'], 'uid' => $uid]);
|
$contact = dba::selectFirst('contact', [], ['url' => $ret['url'], 'network' => $ret['network'], 'uid' => $uid]);
|
||||||
|
@ -1265,8 +1296,8 @@ class Contact extends BaseObject
|
||||||
Worker::add(PRIORITY_HIGH, "OnePoll", $contact_id, "force");
|
Worker::add(PRIORITY_HIGH, "OnePoll", $contact_id, "force");
|
||||||
|
|
||||||
$r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
|
$r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
|
||||||
WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
|
WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
|
||||||
intval($uid)
|
intval($uid)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($r)) {
|
||||||
|
|
|
@ -766,7 +766,7 @@ class GContact
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q(
|
$public_contact = q(
|
||||||
"SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`,
|
"SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`,
|
||||||
`contact-type`, `hide`, `nsfw`, `network`, `alias`, `notify`, `server_url`, `connect`, `updated`, `url`
|
`contact-type`, `hide`, `nsfw`, `network`, `alias`, `notify`, `server_url`, `connect`, `updated`, `url`
|
||||||
FROM `gcontact` WHERE `id` = %d LIMIT 1",
|
FROM `gcontact` WHERE `id` = %d LIMIT 1",
|
||||||
|
@ -775,7 +775,7 @@ class GContact
|
||||||
|
|
||||||
// Get all field names
|
// Get all field names
|
||||||
$fields = array();
|
$fields = array();
|
||||||
foreach ($r[0] as $field => $data) {
|
foreach ($public_contact[0] as $field => $data) {
|
||||||
$fields[$field] = $data;
|
$fields[$field] = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -789,22 +789,22 @@ class GContact
|
||||||
unset($contact["keywords"]);
|
unset($contact["keywords"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($r[0]["keywords"] == "0") {
|
if ($public_contact[0]["keywords"] == "0") {
|
||||||
$r[0]["keywords"] = "";
|
$public_contact[0]["keywords"] = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// assign all unassigned fields from the database entry
|
// assign all unassigned fields from the database entry
|
||||||
foreach ($fields as $field => $data) {
|
foreach ($fields as $field => $data) {
|
||||||
if (!isset($contact[$field]) || ($contact[$field] == "")) {
|
if (!isset($contact[$field]) || ($contact[$field] == "")) {
|
||||||
$contact[$field] = $r[0][$field];
|
$contact[$field] = $public_contact[0][$field];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($contact["hide"])) {
|
if (!isset($contact["hide"])) {
|
||||||
$contact["hide"] = $r[0]["hide"];
|
$contact["hide"] = $public_contact[0]["hide"];
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields["hide"] = $r[0]["hide"];
|
$fields["hide"] = $public_contact[0]["hide"];
|
||||||
|
|
||||||
if ($contact["network"] == NETWORK_STATUSNET) {
|
if ($contact["network"] == NETWORK_STATUSNET) {
|
||||||
$contact["network"] = NETWORK_OSTATUS;
|
$contact["network"] = NETWORK_OSTATUS;
|
||||||
|
@ -839,16 +839,16 @@ class GContact
|
||||||
$update = false;
|
$update = false;
|
||||||
unset($fields["generation"]);
|
unset($fields["generation"]);
|
||||||
|
|
||||||
if ((($contact["generation"] > 0) && ($contact["generation"] <= $r[0]["generation"])) || ($r[0]["generation"] == 0)) {
|
if ((($contact["generation"] > 0) && ($contact["generation"] <= $public_contact[0]["generation"])) || ($public_contact[0]["generation"] == 0)) {
|
||||||
foreach ($fields as $field => $data) {
|
foreach ($fields as $field => $data) {
|
||||||
if ($contact[$field] != $r[0][$field]) {
|
if ($contact[$field] != $public_contact[0][$field]) {
|
||||||
logger("Difference for contact ".$contact["url"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$r[0][$field]."'", LOGGER_DEBUG);
|
logger("Difference for contact ".$contact["url"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$public_contact[0][$field]."'", LOGGER_DEBUG);
|
||||||
$update = true;
|
$update = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($contact["generation"] < $r[0]["generation"]) {
|
if ($contact["generation"] < $public_contact[0]["generation"]) {
|
||||||
logger("Difference for contact ".$contact["url"]." in field 'generation'. new value: '".$contact["generation"]."', old value '".$r[0]["generation"]."'", LOGGER_DEBUG);
|
logger("Difference for contact ".$contact["url"]." in field 'generation'. new value: '".$contact["generation"]."', old value '".$public_contact[0]["generation"]."'", LOGGER_DEBUG);
|
||||||
$update = true;
|
$update = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -874,21 +874,18 @@ class GContact
|
||||||
|
|
||||||
// Now update the contact entry with the user id "0" as well.
|
// Now update the contact entry with the user id "0" as well.
|
||||||
// This is used for the shadow copies of public items.
|
// This is used for the shadow copies of public items.
|
||||||
$r = q(
|
|
||||||
"SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0 ORDER BY `id` LIMIT 1",
|
$public_contact = dba::selectFirst('contact', ['id'], ['nurl' => normalise_link($contact["url"]), 'uid' => 0]);
|
||||||
dbesc(normalise_link($contact["url"]))
|
if (DBM::is_result($public_contact)) {
|
||||||
);
|
logger("Update public contact ".$public_contact["id"], LOGGER_DEBUG);
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
Contact::updateAvatar($contact["photo"], 0, $public_contact["id"]);
|
||||||
logger("Update public contact ".$r[0]["id"], LOGGER_DEBUG);
|
|
||||||
|
|
||||||
Contact::updateAvatar($contact["photo"], 0, $r[0]["id"]);
|
|
||||||
|
|
||||||
$fields = array('name', 'nick', 'addr',
|
$fields = array('name', 'nick', 'addr',
|
||||||
'network', 'bd', 'gender',
|
'network', 'bd', 'gender',
|
||||||
'keywords', 'alias', 'contact-type',
|
'keywords', 'alias', 'contact-type',
|
||||||
'url', 'location', 'about');
|
'url', 'location', 'about');
|
||||||
$old_contact = dba::selectFirst('contact', $fields, ['id' => $r[0]["id"]]);
|
$old_contact = dba::selectFirst('contact', $fields, ['id' => $public_contact["id"]]);
|
||||||
|
|
||||||
// Update it with the current values
|
// Update it with the current values
|
||||||
$fields = array('name' => $contact['name'], 'nick' => $contact['nick'],
|
$fields = array('name' => $contact['name'], 'nick' => $contact['nick'],
|
||||||
|
@ -898,7 +895,7 @@ class GContact
|
||||||
'contact-type' => $contact['contact-type'], 'url' => $contact['url'],
|
'contact-type' => $contact['contact-type'], 'url' => $contact['url'],
|
||||||
'location' => $contact['location'], 'about' => $contact['about']);
|
'location' => $contact['location'], 'about' => $contact['about']);
|
||||||
|
|
||||||
dba::update('contact', $fields, array('id' => $r[0]["id"]), $old_contact);
|
dba::update('contact', $fields, array('id' => $public_contact["id"]), $old_contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,16 +38,16 @@ class Photo
|
||||||
*/
|
*/
|
||||||
public static function store(Image $Image, $uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '')
|
public static function store(Image $Image, $uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '')
|
||||||
{
|
{
|
||||||
$r = dba::selectFirst('photo', ['guid'], ["`resource-id` = ? AND `guid` != ?", $rid, '']);
|
$photo = dba::selectFirst('photo', ['guid'], ["`resource-id` = ? AND `guid` != ?", $rid, '']);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($photo)) {
|
||||||
$guid = $r['guid'];
|
$guid = $photo['guid'];
|
||||||
} else {
|
} else {
|
||||||
$guid = get_guid();
|
$guid = get_guid();
|
||||||
}
|
}
|
||||||
|
|
||||||
$x = dba::selectFirst('photo', ['id'], ['resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale]);
|
$existing_photo = dba::selectFirst('photo', ['id'], ['resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale]);
|
||||||
|
|
||||||
$fields = array(
|
$fields = [
|
||||||
'uid' => $uid,
|
'uid' => $uid,
|
||||||
'contact-id' => $cid,
|
'contact-id' => $cid,
|
||||||
'guid' => $guid,
|
'guid' => $guid,
|
||||||
|
@ -68,10 +68,10 @@ class Photo
|
||||||
'deny_cid' => $deny_cid,
|
'deny_cid' => $deny_cid,
|
||||||
'deny_gid' => $deny_gid,
|
'deny_gid' => $deny_gid,
|
||||||
'desc' => $desc
|
'desc' => $desc
|
||||||
);
|
];
|
||||||
|
|
||||||
if (DBM::is_result($x)) {
|
if (DBM::is_result($existing_photo)) {
|
||||||
$r = dba::update('photo', $fields, array('id' => $x['id']));
|
$r = dba::update('photo', $fields, ['id' => $existing_photo['id']]);
|
||||||
} else {
|
} else {
|
||||||
$r = dba::insert('photo', $fields);
|
$r = dba::insert('photo', $fields);
|
||||||
}
|
}
|
||||||
|
@ -80,34 +80,33 @@ class Photo
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $photo photo
|
* @param string $image_url Remote URL
|
||||||
* @param integer $uid user id
|
* @param integer $uid user id
|
||||||
* @param integer $cid contact id
|
* @param integer $cid contact id
|
||||||
* @param boolean $quit_on_error optional, default false
|
* @param boolean $quit_on_error optional, default false
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function importProfilePhoto($photo, $uid, $cid, $quit_on_error = false)
|
public static function importProfilePhoto($image_url, $uid, $cid, $quit_on_error = false)
|
||||||
{
|
{
|
||||||
$r = dba::selectFirst(
|
$photo = dba::selectFirst(
|
||||||
'photo', ['resource-id'], ['uid' => $uid, 'contact-id' => $cid, 'scale' => 4, 'album' => 'Contact Photos']
|
'photo', ['resource-id'], ['uid' => $uid, 'contact-id' => $cid, 'scale' => 4, 'album' => 'Contact Photos']
|
||||||
);
|
);
|
||||||
|
if (x($photo['resource-id'])) {
|
||||||
if (DBM::is_result($r) && strlen($r['resource-id'])) {
|
$hash = $photo['resource-id'];
|
||||||
$hash = $r['resource-id'];
|
|
||||||
} else {
|
} else {
|
||||||
$hash = photo_new_resource();
|
$hash = photo_new_resource();
|
||||||
}
|
}
|
||||||
|
|
||||||
$photo_failure = false;
|
$photo_failure = false;
|
||||||
|
|
||||||
$filename = basename($photo);
|
$filename = basename($image_url);
|
||||||
$img_str = fetch_url($photo, true);
|
$img_str = fetch_url($image_url, true);
|
||||||
|
|
||||||
if ($quit_on_error && ($img_str == "")) {
|
if ($quit_on_error && ($img_str == "")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$type = Image::guessType($photo, true);
|
$type = Image::guessType($image_url, true);
|
||||||
$Image = new Image($img_str, $type);
|
$Image = new Image($img_str, $type);
|
||||||
if ($Image->isValid()) {
|
if ($Image->isValid()) {
|
||||||
$Image->scaleToSquare(175);
|
$Image->scaleToSquare(175);
|
||||||
|
@ -136,7 +135,7 @@ class Photo
|
||||||
|
|
||||||
$suffix = '?ts=' . time();
|
$suffix = '?ts=' . time();
|
||||||
|
|
||||||
$photo = System::baseUrl() . '/photo/' . $hash . '-4.' . $Image->getExt() . $suffix;
|
$image_url = System::baseUrl() . '/photo/' . $hash . '-4.' . $Image->getExt() . $suffix;
|
||||||
$thumb = System::baseUrl() . '/photo/' . $hash . '-5.' . $Image->getExt() . $suffix;
|
$thumb = System::baseUrl() . '/photo/' . $hash . '-5.' . $Image->getExt() . $suffix;
|
||||||
$micro = System::baseUrl() . '/photo/' . $hash . '-6.' . $Image->getExt() . $suffix;
|
$micro = System::baseUrl() . '/photo/' . $hash . '-6.' . $Image->getExt() . $suffix;
|
||||||
|
|
||||||
|
@ -167,12 +166,12 @@ class Photo
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($photo_failure) {
|
if ($photo_failure) {
|
||||||
$photo = System::baseUrl() . '/images/person-175.jpg';
|
$image_url = System::baseUrl() . '/images/person-175.jpg';
|
||||||
$thumb = System::baseUrl() . '/images/person-80.jpg';
|
$thumb = System::baseUrl() . '/images/person-80.jpg';
|
||||||
$micro = System::baseUrl() . '/images/person-48.jpg';
|
$micro = System::baseUrl() . '/images/person-48.jpg';
|
||||||
}
|
}
|
||||||
|
|
||||||
return array($photo, $thumb, $micro);
|
return array($image_url, $thumb, $micro);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -63,11 +63,10 @@ class FKOAuth1 extends OAuthServer
|
||||||
$a->timezone = $a->user['timezone'];
|
$a->timezone = $a->user['timezone'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = dba::selectFirst('contact', [], ['uid' => $_SESSION['uid'], 'self' => 1]);
|
$contact = dba::selectFirst('contact', [], ['uid' => $_SESSION['uid'], 'self' => 1]);
|
||||||
|
if (DBM::is_result($contact)) {
|
||||||
if (DBM::is_result($r)) {
|
$a->contact = $contact;
|
||||||
$a->contact = $r;
|
$a->cid = $contact['id'];
|
||||||
$a->cid = $r['id'];
|
|
||||||
$_SESSION['cid'] = $a->cid;
|
$_SESSION['cid'] = $a->cid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,10 +88,9 @@ class FKOAuthDataStore extends OAuthDataStore
|
||||||
*/
|
*/
|
||||||
public function lookup_nonce($consumer, $token, $nonce, $timestamp)
|
public function lookup_nonce($consumer, $token, $nonce, $timestamp)
|
||||||
{
|
{
|
||||||
$r = dba::selectFirst('tokens', ['id', 'secret'], ['client_id' => $consumer->key, 'id' => $nonce, 'expires' => $timestamp]);
|
$token = dba::selectFirst('tokens', ['id', 'secret'], ['client_id' => $consumer->key, 'id' => $nonce, 'expires' => $timestamp]);
|
||||||
|
if (DBM::is_result($token)) {
|
||||||
if (DBM::is_result($r)) {
|
return new \OAuthToken($token['id'], $token['secret']);
|
||||||
return new \OAuthToken($r['id'], $r['secret']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -261,14 +261,14 @@ class Post extends BaseObject
|
||||||
'classundo' => $item['starred'] ? "" : "hidden",
|
'classundo' => $item['starred'] ? "" : "hidden",
|
||||||
'starred' => t('starred'),
|
'starred' => t('starred'),
|
||||||
);
|
);
|
||||||
$r = dba::selectFirst('thread', ['ignored'], ['uid' => $item['uid'], 'iid' => $item['id']]);
|
$thread = dba::selectFirst('thread', ['ignored'], ['uid' => $item['uid'], 'iid' => $item['id']]);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($thread)) {
|
||||||
$ignore = array(
|
$ignore = array(
|
||||||
'do' => t("ignore thread"),
|
'do' => t("ignore thread"),
|
||||||
'undo' => t("unignore thread"),
|
'undo' => t("unignore thread"),
|
||||||
'toggle' => t("toggle ignore status"),
|
'toggle' => t("toggle ignore status"),
|
||||||
'classdo' => $r['ignored'] ? "hidden" : "",
|
'classdo' => $thread['ignored'] ? "hidden" : "",
|
||||||
'classundo' => $r['ignored'] ? "" : "hidden",
|
'classundo' => $thread['ignored'] ? "" : "hidden",
|
||||||
'ignored' => t('ignored'),
|
'ignored' => t('ignored'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,10 +66,10 @@ class PortableContact
|
||||||
|
|
||||||
if ($cid) {
|
if ($cid) {
|
||||||
if (!$url || !$uid) {
|
if (!$url || !$uid) {
|
||||||
$r = dba::selectFirst('contact', ['poco', 'uid'], ['id' => $cid]);
|
$contact = dba::selectFirst('contact', ['poco', 'uid'], ['id' => $cid]);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($contact)) {
|
||||||
$url = $r['poco'];
|
$url = $contact['poco'];
|
||||||
$uid = $r['uid'];
|
$uid = $contact['uid'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$uid) {
|
if (!$uid) {
|
||||||
|
@ -813,30 +813,30 @@ class PortableContact
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$servers = dba::selectFirst('gserver', [], ['nurl' => normalise_link($server_url)]);
|
$gserver = dba::selectFirst('gserver', [], ['nurl' => normalise_link($server_url)]);
|
||||||
if (DBM::is_result($servers)) {
|
if (DBM::is_result($gserver)) {
|
||||||
if ($servers["created"] <= NULL_DATE) {
|
if ($gserver["created"] <= NULL_DATE) {
|
||||||
$fields = ['created' => datetime_convert()];
|
$fields = ['created' => datetime_convert()];
|
||||||
$condition = ['nurl' => normalise_link($server_url)];
|
$condition = ['nurl' => normalise_link($server_url)];
|
||||||
dba::update('gserver', $fields, $condition);
|
dba::update('gserver', $fields, $condition);
|
||||||
}
|
}
|
||||||
$poco = $servers["poco"];
|
$poco = $gserver["poco"];
|
||||||
$noscrape = $servers["noscrape"];
|
$noscrape = $gserver["noscrape"];
|
||||||
|
|
||||||
if ($network == "") {
|
if ($network == "") {
|
||||||
$network = $servers["network"];
|
$network = $gserver["network"];
|
||||||
}
|
}
|
||||||
|
|
||||||
$last_contact = $servers["last_contact"];
|
$last_contact = $gserver["last_contact"];
|
||||||
$last_failure = $servers["last_failure"];
|
$last_failure = $gserver["last_failure"];
|
||||||
$version = $servers["version"];
|
$version = $gserver["version"];
|
||||||
$platform = $servers["platform"];
|
$platform = $gserver["platform"];
|
||||||
$site_name = $servers["site_name"];
|
$site_name = $gserver["site_name"];
|
||||||
$info = $servers["info"];
|
$info = $gserver["info"];
|
||||||
$register_policy = $servers["register_policy"];
|
$register_policy = $gserver["register_policy"];
|
||||||
$registered_users = $servers["registered-users"];
|
$registered_users = $gserver["registered-users"];
|
||||||
|
|
||||||
if (!$force && !self::updateNeeded($servers["created"], "", $last_failure, $last_contact)) {
|
if (!$force && !self::updateNeeded($gserver["created"], "", $last_failure, $last_contact)) {
|
||||||
logger("Use cached data for server ".$server_url, LOGGER_DEBUG);
|
logger("Use cached data for server ".$server_url, LOGGER_DEBUG);
|
||||||
return ($last_contact >= $last_failure);
|
return ($last_contact >= $last_failure);
|
||||||
}
|
}
|
||||||
|
@ -853,7 +853,7 @@ class PortableContact
|
||||||
$last_contact = NULL_DATE;
|
$last_contact = NULL_DATE;
|
||||||
$last_failure = NULL_DATE;
|
$last_failure = NULL_DATE;
|
||||||
}
|
}
|
||||||
logger("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$servers["created"]." Failure: ".$last_failure." Contact: ".$last_contact, LOGGER_DEBUG);
|
logger("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$gserver["created"]." Failure: ".$last_failure." Contact: ".$last_contact, LOGGER_DEBUG);
|
||||||
|
|
||||||
$failure = false;
|
$failure = false;
|
||||||
$possible_failure = false;
|
$possible_failure = false;
|
||||||
|
@ -876,7 +876,7 @@ class PortableContact
|
||||||
|
|
||||||
// Quit if there is a timeout.
|
// Quit if there is a timeout.
|
||||||
// But we want to make sure to only quit if we are mostly sure that this server url fits.
|
// But we want to make sure to only quit if we are mostly sure that this server url fits.
|
||||||
if (DBM::is_result($servers) && ($orig_server_url == $server_url) &&
|
if (DBM::is_result($gserver) && ($orig_server_url == $server_url) &&
|
||||||
($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
|
($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
|
||||||
logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
|
logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
|
||||||
dba::update('gserver', array('last_failure' => datetime_convert()), array('nurl' => normalise_link($server_url)));
|
dba::update('gserver', array('last_failure' => datetime_convert()), array('nurl' => normalise_link($server_url)));
|
||||||
|
|
|
@ -384,16 +384,15 @@ Class OnePoll
|
||||||
// Have we seen it before?
|
// Have we seen it before?
|
||||||
$fields = ['deleted', 'id'];
|
$fields = ['deleted', 'id'];
|
||||||
$condition = ['uid' => $importer_uid, 'uri' => $datarray['uri']];
|
$condition = ['uid' => $importer_uid, 'uri' => $datarray['uri']];
|
||||||
$r = dba::selectFirst('item', $fields, $condition);
|
$item = dba::selectFirst('item', $fields, $condition);
|
||||||
|
if (DBM::is_result($item)) {
|
||||||
if (DBM::is_result($r)) {
|
|
||||||
logger("Mail: Seen before ".$msg_uid." for ".$mailconf['user']." UID: ".$importer_uid." URI: ".$datarray['uri'],LOGGER_DEBUG);
|
logger("Mail: Seen before ".$msg_uid." for ".$mailconf['user']." UID: ".$importer_uid." URI: ".$datarray['uri'],LOGGER_DEBUG);
|
||||||
|
|
||||||
// Only delete when mails aren't automatically moved or deleted
|
// Only delete when mails aren't automatically moved or deleted
|
||||||
if (($mailconf['action'] != 1) && ($mailconf['action'] != 3))
|
if (($mailconf['action'] != 1) && ($mailconf['action'] != 3))
|
||||||
if ($meta->deleted && ! $r['deleted']) {
|
if ($meta->deleted && ! $item['deleted']) {
|
||||||
$fields = array('deleted' => true, 'changed' => datetime_convert());
|
$fields = array('deleted' => true, 'changed' => datetime_convert());
|
||||||
dba::update('item', $fields, array('id' => $r['id']));
|
dba::update('item', $fields, array('id' => $item['id']));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($mailconf['action']) {
|
switch ($mailconf['action']) {
|
||||||
|
|
|
@ -68,18 +68,11 @@ class Queue
|
||||||
|
|
||||||
|
|
||||||
// delivering
|
// delivering
|
||||||
|
$q_item = dba::selectFirst('queue', [], ['id' => $queue_id]);
|
||||||
$r = q(
|
if (!DBM::is_result($q_item)) {
|
||||||
"SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
|
|
||||||
intval($queue_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!DBM::is_result($r)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$q_item = $r[0];
|
|
||||||
|
|
||||||
$contact = dba::selectFirst('contact', [], ['id' => $q_item['cid']]);
|
$contact = dba::selectFirst('contact', [], ['id' => $q_item['cid']]);
|
||||||
if (!DBM::is_result($contact)) {
|
if (!DBM::is_result($contact)) {
|
||||||
remove_queue_item($q_item['id']);
|
remove_queue_item($q_item['id']);
|
||||||
|
|
|
@ -57,8 +57,8 @@ if (in_array($net['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
$nurl = normalise_link($net['url']);
|
$nurl = normalise_link($net['url']);
|
||||||
$r = dba::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
|
$contact = dba::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($contact)) {
|
||||||
dba::update("contact", array("hidden" => true), array("id" => $r["id"]));
|
dba::update("contact", array("hidden" => true), array("id" => $r["id"]));
|
||||||
echo "NOTICE: The account should be silenced from the global community page\r\n";
|
echo "NOTICE: The account should be silenced from the global community page\r\n";
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue