<?php
use Friendica\App;
+use Friendica\Core\PConfig;
use Friendica\Core\System;
+use Friendica\Core\Worker;
use Friendica\Network\Probe;
// Included here for completeness, but this is a very dangerous operation.
// The user and related data will be deleted in "cron_expire_and_remove_users" (cronjobs.php)
q("UPDATE `user` SET `account_removed` = 1, `account_expires_on` = UTC_TIMESTAMP() WHERE `uid` = %d", intval($uid));
- proc_run(PRIORITY_HIGH, "include/notifier.php", "removeme", $uid);
+ Worker::add(PRIORITY_HIGH, "notifier", "removeme", $uid);
// Send an update to the directory
- proc_run(PRIORITY_LOW, "include/directory.php", $r['url']);
+ Worker::add(PRIORITY_LOW, "directory", $r['url']);
if($uid == local_user()) {
unset($_SESSION['authenticated']);
return;
}
- $archive = get_pconfig($r[0]['uid'], 'system','archive_removed_contacts');
+ $archive = PConfig::get($r[0]['uid'], 'system','archive_removed_contacts');
if ($archive) {
q("update contact set `archive` = 1, `network` = 'none', `writable` = 0 where id = %d",
intval($id)
dba::delete('contact', array('id' => $id));
// Delete the rest in the background
- proc_run(PRIORITY_LOW, 'include/remove_contact.php', $id);
+ Worker::add(PRIORITY_LOW, 'remove_contact', $id);
}
function unmark_for_death($contact) {
- $r = q("SELECT `term-date` FROM `contact` WHERE `id` = %d AND `term-date` > '%s'",
+ $r = q("SELECT `term-date` FROM `contact` WHERE `id` = %d AND (`term-date` > '%s' OR `archive`)",
intval($contact['id']),
dbesc('1000-00-00 00:00:00')
);
}
// It's a miracle. Our dead contact has inexplicably come back to life.
- q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
- dbesc(NULL_DATE),
- intval($contact['id'])
- );
+ $fields = array('term-date' => NULL_DATE, 'archive' => false);
+ dba::update('contact', $fields, array('id' => $contact['id']));
if ($contact['url'] != '') {
- q("UPDATE `contact` SET `term-date` = '%s' WHERE `nurl` = '%s'",
- dbesc(NULL_DATE),
- dbesc(normalise_link($contact['url']))
- );
+ dba::update('contact', $fields, array('nurl' => normalise_link($contact['url'])));
}
}
if ((($profile["addr"] == "") || ($profile["name"] == "")) && ($profile["gid"] != 0) &&
in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
- proc_run(PRIORITY_LOW, "include/update_gcontact.php", $profile["gid"]);
+ Worker::add(PRIORITY_LOW, "update_gcontact", $profile["gid"]);
}
// Show contact details of Diaspora contacts only if connected
// Update the contact every 7 days
$update_contact = ($contact['avatar-date'] < datetime_convert('','','now -7 days'));
+ // We force the update if the avatar is empty
+ if ($contact['avatar'] == '') {
+ $update_contact = true;
+ }
+
if (!$update_contact || $no_update) {
return $contact_id;
}
$data = array_merge($data, $gcontacts);
}
+ if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url)) {
+ $contact_id = get_contact($data["alias"], $uid, true);
+ }
+
$url = $data["url"];
if (!$contact_id) {
dba::insert('contact', array('uid' => $uid, 'created' => datetime_convert(), 'url' => $data["url"],
update_contact_avatar($data["photo"], $uid, $contact_id);
- $contact = dba::select('contact', array('addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date'),
+ $contact = dba::select('contact', array('url', 'nurl', 'addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date'),
array('id' => $contact_id), array('limit' => 1));
// This condition should always be true
$updated = array('addr' => $data['addr'],
'alias' => $data['alias'],
+ 'url' => $data['url'],
+ 'nurl' => normalise_link($data['url']),
'name' => $data['name'],
'nick' => $data['nick']);
return $contact_id;
}
+/**
+ * @brief Checks if the contact is blocked
+ *
+ * @param int $cid contact id
+ *
+ * @return boolean Is the contact blocked?
+ */
+function blockedContact($cid) {
+ if ($cid == 0) {
+ return false;
+ }
+
+ $blocked = dba::select('contact', array('blocked'), array('id' => $cid), array('limit' => 1));
+ if (!dbm::is_result($blocked)) {
+ return false;
+ }
+ return (bool)$blocked['blocked'];
+}
+
+/**
+ * @brief Checks if the contact is hidden
+ *
+ * @param int $cid contact id
+ *
+ * @return boolean Is the contact hidden?
+ */
+function hiddenContact($cid) {
+ if ($cid == 0) {
+ return false;
+ }
+
+ $hidden = dba::select('contact', array('hidden'), array('id' => $cid), array('limit' => 1));
+ if (!dbm::is_result($hidden)) {
+ return false;
+ }
+ return (bool)$hidden['hidden'];
+}
+
/**
* @brief Returns posts from a given gcontact
*
// There are no posts with "uid = 0" with connector networks
// This speeds up the query a lot
- $r = q("SELECT `network`, `id` AS `author-id` 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)));
- if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""))) {
- $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND `item`.`private`))";
- } else {
- $sql = "`item`.`uid` = %d";
- }
if (!dbm::is_result($r)) {
return '';
}
+ if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""))) {
+ $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND NOT `item`.`global`))";
+ } else {
+ $sql = "`item`.`uid` = %d";
+ }
+
$author_id = intval($r[0]["author-id"]);
- $r = q(item_query()." AND `item`.`author-id` = %d AND ".$sql.
+ $contact = ($r[0]["contact-type"] == ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id');
+
+ $r = q(item_query()." AND `item`.`".$contact."` = %d AND ".$sql.
" ORDER BY `item`.`created` DESC LIMIT %d, %d",
intval($author_id),
intval(local_user()),