+/*contact actions*/
+function _contact_update($contact_id) {
+ $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
+ if (!$r)
+ return;
+
+ $uid = $r[0]["uid"];
+
+ if ($uid != local_user())
+ return;
+
+ if ($r[0]["network"] == NETWORK_OSTATUS) {
+ $result = new_contact($uid, $r[0]["url"], false);
+
+ if ($result['success'])
+ $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
+ intval($contact_id));
+ } else
+ // pull feed and consume it, which should subscribe to the hub.
+ proc_run('php',"include/onepoll.php","$contact_id", "force");
+}
+
+function _contact_update_profile($contact_id) {
+ $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
+ if (!$r)
+ return;
+
+ $uid = $r[0]["uid"];
+
+ if ($uid != local_user())
+ return;
+
+ $data = probe_url($r[0]["url"]);
+
+ // "Feed" or "Unknown" is mostly a sign of communication problems
+ if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"]))
+ return;
+
+ $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
+ "poco", "network", "alias");
+ $update = array();
+
+ if ($data["network"] == NETWORK_OSTATUS) {
+ $result = new_contact($uid, $data["url"], false);
+
+ if ($result['success'])
+ $update["subhub"] = true;
+ }
+
+ foreach($updatefields AS $field)
+ if (isset($data[$field]) AND ($data[$field] != ""))
+ $update[$field] = $data[$field];
+
+ $update["nurl"] = normalise_link($data["url"]);
+
+ $query = "";
+
+ if (isset($data["priority"]) AND ($data["priority"] != 0))
+ $query = "`priority` = ".intval($data["priority"]);
+
+ foreach($update AS $key => $value) {
+ if ($query != "")
+ $query .= ", ";
+
+ $query .= "`".$key."` = '".dbesc($value)."'";
+ }
+
+ if ($query == "")
+ return;
+
+ $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
+ intval($contact_id),
+ intval(local_user())
+ );
+
+ $photos = import_profile_photo($data['photo'], local_user(), $contact_id);
+
+ $r = q("UPDATE `contact` SET `photo` = '%s',
+ `thumb` = '%s',
+ `micro` = '%s',
+ `name-date` = '%s',
+ `uri-date` = '%s',
+ `avatar-date` = '%s'
+ WHERE `id` = %d",
+ dbesc($photos[0]),
+ dbesc($photos[1]),
+ dbesc($photos[2]),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ intval($contact_id)
+ );
+
+}
+
+function _contact_block($contact_id, $orig_record) {
+ $blocked = (($orig_record['blocked']) ? 0 : 1);
+ $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
+ intval($blocked),
+ intval($contact_id),
+ intval(local_user())
+ );
+ return $r;
+
+}
+function _contact_ignore($contact_id, $orig_record) {
+ $readonly = (($orig_record['readonly']) ? 0 : 1);
+ $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
+ intval($readonly),
+ intval($contact_id),
+ intval(local_user())
+ );
+ return $r;
+}
+function _contact_archive($contact_id, $orig_record) {
+ $archived = (($orig_record['archive']) ? 0 : 1);
+ $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
+ intval($archived),
+ intval($contact_id),
+ intval(local_user())
+ );
+ if ($archived) {
+ q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
+ }
+ return $r;
+}
+function _contact_drop($contact_id, $orig_record) {
+ require_once('include/Contact.php');
+ $a = get_app();
+
+ terminate_friendship($a->user,$a->contact,$orig_record);
+ contact_remove($orig_record['id']);
+}