From 6f662b8c74ddc6e896e74e6b563e0769bb66fef5 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 28 Jan 2016 01:26:19 +0100 Subject: [PATCH 01/12] New avatar picture fields to better cope with changing avatars --- include/Contact.php | 3 +- include/Photo.php | 110 +++++++++++++++++++++++--------------- include/dbstructure.php | 4 ++ include/diaspora.php | 9 +++- include/discover_poco.php | 1 + include/follow.php | 5 +- include/gprobe.php | 4 +- include/ostatus.php | 8 +-- include/socgraph.php | 33 ++++++++++-- mod/contacts.php | 5 +- mod/crepair.php | 5 +- mod/dfrn_confirm.php | 4 ++ mod/item.php | 1 + mod/poco.php | 5 +- mod/wall_upload.php | 5 ++ 15 files changed, 143 insertions(+), 59 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 86e67bbe86..1c99dd0298 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -488,9 +488,10 @@ function get_contact($url, $uid = 0) { $photos = import_profile_photo($data["photo"],$uid,$contactid); - q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s', + q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s', `name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d", + dbesc($data["photo"]), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), diff --git a/include/Photo.php b/include/Photo.php index 5fdd682e74..e0cb23008a 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -720,65 +720,91 @@ function guess_image_type($filename, $fromcurl=false) { } -function import_profile_photo($photo,$uid,$cid) { +function update_contact_avatar($avatar,$uid,$cid) { - $a = get_app(); + $r = q("SELECT `avatar`, `photo`, `thumb`, `micro` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid)); + if (!$r) + return false; + else + $data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]); - $r = q("select `resource-id` from photo where `uid` = %d and `contact-id` = %d and `scale` = 4 and `album` = 'Contact Photos' limit 1", - intval($uid), - intval($cid) - ); - if(count($r) && strlen($r[0]['resource-id'])) { - $hash = $r[0]['resource-id']; - } - else { - $hash = photo_new_resource(); - } + if ($r[0]["avatar"] != $avatar) { + $photos = import_profile_photo($avatar,$uid,$cid, true); - $photo_failure = false; + if ($photos) { + q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d", + dbesc($avatar), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), + dbesc(datetime_convert()), intval($cid)); + return $photos; + } + } - $filename = basename($photo); - $img_str = fetch_url($photo,true); + return $data; +} - $type = guess_image_type($photo,true); - $img = new Photo($img_str, $type); - if($img->is_valid()) { +function import_profile_photo($photo,$uid,$cid, $quit_on_error = false) { - $img->scaleImageSquare(175); + $a = get_app(); - $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4 ); + $r = q("select `resource-id` from photo where `uid` = %d and `contact-id` = %d and `scale` = 4 and `album` = 'Contact Photos' limit 1", + intval($uid), + intval($cid) + ); + if(count($r) && strlen($r[0]['resource-id'])) { + $hash = $r[0]['resource-id']; + } else { + $hash = photo_new_resource(); + } - if($r === false) - $photo_failure = true; + $photo_failure = false; - $img->scaleImage(80); + $filename = basename($photo); + $img_str = fetch_url($photo,true); - $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5 ); + if ($quit_on_error AND ($img_str == "")) + return false; - if($r === false) - $photo_failure = true; + $type = guess_image_type($photo,true); + $img = new Photo($img_str, $type); + if($img->is_valid()) { - $img->scaleImage(48); + $img->scaleImageSquare(175); - $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6 ); + $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4 ); - if($r === false) - $photo_failure = true; + if($r === false) + $photo_failure = true; - $photo = $a->get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt(); - $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt(); - $micro = $a->get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt(); - } - else - $photo_failure = true; + $img->scaleImage(80); - if($photo_failure) { - $photo = $a->get_baseurl() . '/images/person-175.jpg'; - $thumb = $a->get_baseurl() . '/images/person-80.jpg'; - $micro = $a->get_baseurl() . '/images/person-48.jpg'; - } + $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5 ); - return(array($photo,$thumb,$micro)); + if($r === false) + $photo_failure = true; + + $img->scaleImage(48); + + $r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6 ); + + if($r === false) + $photo_failure = true; + + $photo = $a->get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt(); + $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt(); + $micro = $a->get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt(); + } else + $photo_failure = true; + + if($photo_failure AND $quit_on_error) + return false; + + if($photo_failure) { + $photo = $a->get_baseurl() . '/images/person-175.jpg'; + $thumb = $a->get_baseurl() . '/images/person-80.jpg'; + $micro = $a->get_baseurl() . '/images/person-48.jpg'; + } + + return(array($photo,$thumb,$micro)); } diff --git a/include/dbstructure.php b/include/dbstructure.php index 43dfbd7b35..fd5883911a 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -453,6 +453,7 @@ function db_definition() { "keywords" => array("type" => "text", "not null" => "1"), "gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""), "attag" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), + "avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "photo" => array("type" => "text", "not null" => "1"), "thumb" => array("type" => "text", "not null" => "1"), "micro" => array("type" => "text", "not null" => "1"), @@ -656,7 +657,10 @@ function db_definition() { "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), + "avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), + "thumb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), + "micro" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "connect" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"), "updated" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"), diff --git a/include/diaspora.php b/include/diaspora.php index b72239c4ce..3f0b4be432 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -740,6 +740,7 @@ function diaspora_request($importer,$xml) { $new_relation = CONTACT_IS_FOLLOWER; $r = q("UPDATE `contact` SET + `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', @@ -752,6 +753,7 @@ function diaspora_request($importer,$xml) { `writable` = 1 WHERE `id` = %d ", + dbesc($contact_record['photo']), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), @@ -2491,12 +2493,15 @@ function diaspora_profile($importer,$xml,$msg) { /// @TODO Update name on item['author-name'] if the name changed. See consume_feed() /// (Not doing this currently because D* protocol is scheduled for revision soon). - $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d", + $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', + `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s', + `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($name), dbesc($nick), dbesc($diaspora_handle), dbesc(datetime_convert()), dbesc($image_url), + dbesc($images[0]), dbesc($images[1]), dbesc($images[2]), dbesc(datetime_convert()), @@ -2516,7 +2521,7 @@ function diaspora_profile($importer,$xml,$msg) { } update_gcontact(array("url" => $contact['url'], "network" => NETWORK_DIASPORA, "generation" => 2, - "photo" => $image_url, "name" => $name, "location" => $location, + "avatar" => $image_url, "name" => $name, "location" => $location, "about" => $about, "birthday" => $birthday, "gender" => $gender, "addr" => $diaspora_handle, "nick" => $nick, "keywords" => $keywords, "hide" => !$searchable, "nsfw" => $nsfw)); diff --git a/include/discover_poco.php b/include/discover_poco.php index a8f670334b..63d1175a71 100644 --- a/include/discover_poco.php +++ b/include/discover_poco.php @@ -222,6 +222,7 @@ function gs_search_user($search) { $contact = probe_url($user->site_address."/".$user->name); if ($contact["network"] != NETWORK_PHANTOM) { $contact["about"] = $user->description; + $contact["avatar"] = $contact["photo"]; update_gcontact($contact); } } diff --git a/include/follow.php b/include/follow.php index 21c05c8f3e..8e6094cb4d 100644 --- a/include/follow.php +++ b/include/follow.php @@ -266,13 +266,16 @@ function new_contact($uid,$url,$interactive = false) { $photos = import_profile_photo($ret['photo'],$uid,$contact_id); - $r = q("UPDATE `contact` SET `photo` = '%s', + $r = q("UPDATE `contact` SET + `avatar` = '%s', + `photo` = '%s', `thumb` = '%s', `micro` = '%s', `name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d", + dbesc($ret['photo']), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), diff --git a/include/gprobe.php b/include/gprobe.php index dfa9137d7d..8e4d3715c0 100644 --- a/include/gprobe.php +++ b/include/gprobe.php @@ -58,8 +58,10 @@ function gprobe_run(&$argv, &$argc){ if (is_null($result)) Cache::set("gprobe:".$urlparts["host"],serialize($arr)); - if (!in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) + if (!in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) { + $arr["avatar"] = $arr["photo"]; update_gcontact($arr); + } $r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1", dbesc(normalise_link($url)) diff --git a/include/ostatus.php b/include/ostatus.php index 4ccd13130d..eeacd40de4 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -166,13 +166,13 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) "", "", "", datetime_convert(), 2, $contact["id"], $contact["uid"]); } - if (isset($author["author-avatar"]) AND ($author["author-avatar"] != $r[0]['photo'])) { + if (isset($author["author-avatar"]) AND ($author["author-avatar"] != $r[0]['avatar'])) { logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG); $photos = import_profile_photo($author["author-avatar"], $importer["uid"], $contact["id"]); - q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d AND `network` = '%s'", - dbesc($author["author-avatar"]), dbesc($photos[1]), dbesc($photos[2]), + q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d AND `network` = '%s'", + dbesc($author["author-avatar"]), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS)); } @@ -180,7 +180,7 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) if ($contact["network"] == NETWORK_OSTATUS) { /// @todo Add the "addr" field $contact["generation"] = 2; - $contact["photo"] = $author["author-avatar"]; + $contact["avatar"] = $author["author-avatar"]; update_gcontact($contact); } } diff --git a/include/socgraph.php b/include/socgraph.php index c545343393..241e2df7f0 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -10,7 +10,7 @@ require_once('include/datetime.php'); require_once("include/Scrape.php"); require_once("include/html2bbcode.php"); - +require_once("include/Contact.php"); /* * poco_load @@ -294,7 +294,7 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca "alias" => $alias, "name" => $name, "network" => $network, - "photo" => $profile_photo, + "avatar" => $profile_photo, "about" => $about, "location" => $location, "gender" => $gender, @@ -1517,7 +1517,7 @@ function update_gcontact($contact) { if (!$gcontact_id) return false; - $r = q("SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`, + $r = q("SELECT `name`, `nick`, `avatar`, `photo`, `thumb`, `micro`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`, `hide`, `nsfw`, `network`, `alias`, `notify`, `server_url`, `connect`, `updated`, `url` FROM `gcontact` WHERE `id` = %d LIMIT 1", intval($gcontact_id)); @@ -1552,14 +1552,37 @@ function update_gcontact($contact) { if ($contact["generation"] < $r[0]["generation"]) $update = true; + if (isset($contact["avatar"]) AND (($contact["avatar"] != $r[0]["avatar"]) OR + ($r[0]["photo"] == $r[0]["avatar"]) OR ($r[0]["thumb"] == "") OR ($r[0]["micro"] == ""))) { + + $cid = get_contact($contact["url"]); + + // We always store avatar picture with a contact-id. + // We don't have a contact-id when we use the gcontact table. + // Solution is to use a matching entry in the contact table. (Which is not totally clean) + if (($cid == 0) AND isset($contact["uid"])) + $cid = get_contact($contact["url"], $contact["uid"]); + + $photos = update_contact_avatar($contact["avatar"], 0, $cid); + + if ($photos) { + $contact["photo"] = $photos[0]; + $contact["thumb"] = $photos[1]; + $contact["micro"] = $photos[2]; + } + } + if ($update) { - q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s', + + q("UPDATE `gcontact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', + `name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s', `birthday` = '%s', `gender` = '%s', `keywords` = %d, `hide` = %d, `nsfw` = %d, `alias` = '%s', `notify` = '%s', `url` = '%s', `location` = '%s', `about` = '%s', `generation` = %d, `updated` = '%s', `server_url` = '%s', `connect` = '%s' WHERE `nurl` = '%s' AND (`generation` = 0 OR `generation` >= %d)", - dbesc($contact["photo"]), dbesc($contact["name"]), dbesc($contact["nick"]), + dbesc($contact["avatar"]), dbesc($contact["photo"]), dbesc($contact["thumb"]), + dbesc($contact["micro"]), dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["addr"]), dbesc($contact["network"]), dbesc($contact["birthday"]), dbesc($contact["gender"]), dbesc($contact["keywords"]), intval($contact["hide"]), intval($contact["nsfw"]), dbesc($contact["alias"]), dbesc($contact["notify"]), diff --git a/mod/contacts.php b/mod/contacts.php index 21578a3295..1ef201490c 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -295,7 +295,9 @@ function _contact_update_profile($contact_id) { $photos = import_profile_photo($data['photo'], local_user(), $contact_id); - $r = q("UPDATE `contact` SET `photo` = '%s', + $r = q("UPDATE `contact` SET + `avatar` = '%s', + `photo` = '%s', `thumb` = '%s', `micro` = '%s', `name-date` = '%s', @@ -303,6 +305,7 @@ function _contact_update_profile($contact_id) { `avatar-date` = '%s' WHERE `id` = %d", dbesc($data["photo"]), + dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), dbesc(datetime_convert()), diff --git a/mod/crepair.php b/mod/crepair.php index 6f951bdf6e..606c388458 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -82,7 +82,9 @@ function crepair_post(&$a) { $photos = import_profile_photo($photo,local_user(),$contact['id']); - $x = q("UPDATE `contact` SET `photo` = '%s', + $x = q("UPDATE `contact` SET + `avatar` = '%s', + `photo` = '%s', `thumb` = '%s', `micro` = '%s', `name-date` = '%s', @@ -90,6 +92,7 @@ function crepair_post(&$a) { `avatar-date` = '%s' WHERE `id` = %d ", + dbesc($photo), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index d5dbab951e..8528ba9ffd 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -329,6 +329,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { $duplex = 0; $r = q("UPDATE `contact` SET + `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', @@ -342,6 +343,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { `hidden` = %d, `network` = '%s' WHERE `id` = %d ", + dbesc($contact['photo']), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), @@ -695,6 +697,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { $duplex = 0; $r = q("UPDATE `contact` SET + `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', @@ -709,6 +712,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { `prv` = %d, `network` = '%s' WHERE `id` = %d ", + dbesc($photo), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), diff --git a/mod/item.php b/mod/item.php index 8c5a479646..bf0ead4932 100644 --- a/mod/item.php +++ b/mod/item.php @@ -1146,6 +1146,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo if (!$r) { $probed = probe_url($name); if (isset($probed["url"])) { + $probed["avatar"] = $probed["photo"]; update_gcontact($probed); $r = q("SELECT `url`, `name`, `nick`, `network`, `alias`, `notify` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link($probed["url"]))); diff --git a/mod/poco.php b/mod/poco.php index 0a1b392169..3927f125ea 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -179,6 +179,9 @@ function poco_init(&$a) { $rr['generation'] = 2; } + if ($rr["avatar"] == "") + $rr["avatar"] = $rr["photo"]; + if (($rr['about'] == "") AND isset($rr['pabout'])) $rr['about'] = $rr['pabout']; @@ -258,7 +261,7 @@ function poco_init(&$a) { $entry['updated'] = date("c", strtotime($entry['updated'])); } if($fields_ret['photos']) - $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile')); + $entry['photos'] = array(array('value' => $rr['avatar'], 'type' => 'profile')); if($fields_ret['network']) { $entry['network'] = $rr['network']; if ($entry['network'] == NETWORK_STATUSNET) diff --git a/mod/wall_upload.php b/mod/wall_upload.php index 8bf471d3d2..a1dab53779 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -158,6 +158,7 @@ function wall_upload_post(&$a, $desktopmode = true) { killme(); } + logger("Check size of picture.", LOGGER_DEBUG); $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", intval($page_owner_uid) ); @@ -176,6 +177,7 @@ function wall_upload_post(&$a, $desktopmode = true) { } + logger("Picture will be processed.", LOGGER_DEBUG); $imagedata = @file_get_contents($src); $ph = new Photo($imagedata, $filetype); @@ -210,6 +212,7 @@ function wall_upload_post(&$a, $desktopmode = true) { $defperm = '<' . $default_cid . '>'; + logger("Picture will be stored", LOGGER_DEBUG); $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, $defperm); if(! $r) { @@ -266,6 +269,8 @@ function wall_upload_post(&$a, $desktopmode = true) { return $picture; } + logger("Picture is stored.", LOGGER_DEBUG); + if ($r_json) { echo json_encode(array('ok'=>true)); killme(); From 78e79de7c974732e6cb8cee58536fa9b6f98e06f Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 28 Jan 2016 11:09:08 +0100 Subject: [PATCH 02/12] New central function to store avatar data in contacts --- include/Contact.php | 12 +++--------- include/diaspora.php | 27 +++++---------------------- include/discover_poco.php | 1 - include/follow.php | 23 ++--------------------- include/gprobe.php | 4 +--- include/ostatus.php | 25 ++++++++++--------------- include/socgraph.php | 30 ++++-------------------------- mod/contacts.php | 22 ++-------------------- mod/crepair.php | 22 +--------------------- mod/dfrn_confirm.php | 37 ++++--------------------------------- mod/item.php | 1 - 11 files changed, 32 insertions(+), 172 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 1c99dd0298..3799e0b189 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -486,22 +486,16 @@ function get_contact($url, $uid = 0) { require_once("Photo.php"); - $photos = import_profile_photo($data["photo"],$uid,$contactid); + update_contact_avatar($data["photo"],$uid,$contactid); - q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', - `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s', - `name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d", - dbesc($data["photo"]), - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), + q("UPDATE `contact` SET `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s', + `name-date` = '%s', `uri-date` = '%s' WHERE `id` = %d", dbesc($data["addr"]), dbesc($data["alias"]), dbesc($data["name"]), dbesc($data["nick"]), dbesc(datetime_convert()), dbesc(datetime_convert()), - dbesc(datetime_convert()), intval($contactid) ); diff --git a/include/diaspora.php b/include/diaspora.php index 3f0b4be432..1b71d4f2bd 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -728,7 +728,7 @@ function diaspora_request($importer,$xml) { require_once('include/Photo.php'); - $photos = import_profile_photo($contact_record['photo'],$importer['uid'],$contact_record['id']); + update_contact_avatar($contact_record['photo'],$importer['uid'],$contact_record['id']); // technically they are sharing with us (CONTACT_IS_SHARING), // but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX @@ -739,28 +739,17 @@ function diaspora_request($importer,$xml) { else $new_relation = CONTACT_IS_FOLLOWER; - $r = q("UPDATE `contact` SET - `avatar` = '%s', - `photo` = '%s', - `thumb` = '%s', - `micro` = '%s', - `rel` = %d, + $r = q("UPDATE `contact` SET `rel` = %d, `name-date` = '%s', `uri-date` = '%s', - `avatar-date` = '%s', `blocked` = 0, `pending` = 0, `writable` = 1 WHERE `id` = %d ", - dbesc($contact_record['photo']), - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), intval($new_relation), dbesc(datetime_convert()), dbesc(datetime_convert()), - dbesc(datetime_convert()), intval($contact_record['id']) ); @@ -2475,7 +2464,7 @@ function diaspora_profile($importer,$xml,$msg) { require_once('include/Photo.php'); - $images = import_profile_photo($image_url,$importer['uid'],$contact['id']); + update_contact_avatar($image_url,$importer['uid'],$contact['id']); // Generic birthday. We don't know the timezone. The year is irrelevant. @@ -2493,18 +2482,12 @@ function diaspora_profile($importer,$xml,$msg) { /// @TODO Update name on item['author-name'] if the name changed. See consume_feed() /// (Not doing this currently because D* protocol is scheduled for revision soon). - $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', - `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s', + $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', `bd` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($name), dbesc($nick), dbesc($diaspora_handle), dbesc(datetime_convert()), - dbesc($image_url), - dbesc($images[0]), - dbesc($images[1]), - dbesc($images[2]), - dbesc(datetime_convert()), dbesc($birthday), dbesc($location), dbesc($about), @@ -2521,7 +2504,7 @@ function diaspora_profile($importer,$xml,$msg) { } update_gcontact(array("url" => $contact['url'], "network" => NETWORK_DIASPORA, "generation" => 2, - "avatar" => $image_url, "name" => $name, "location" => $location, + "photo" => $image_url, "name" => $name, "location" => $location, "about" => $about, "birthday" => $birthday, "gender" => $gender, "addr" => $diaspora_handle, "nick" => $nick, "keywords" => $keywords, "hide" => !$searchable, "nsfw" => $nsfw)); diff --git a/include/discover_poco.php b/include/discover_poco.php index 63d1175a71..a8f670334b 100644 --- a/include/discover_poco.php +++ b/include/discover_poco.php @@ -222,7 +222,6 @@ function gs_search_user($search) { $contact = probe_url($user->site_address."/".$user->name); if ($contact["network"] != NETWORK_PHANTOM) { $contact["about"] = $user->description; - $contact["avatar"] = $contact["photo"]; update_gcontact($contact); } } diff --git a/include/follow.php b/include/follow.php index 8e6094cb4d..22ff079b63 100644 --- a/include/follow.php +++ b/include/follow.php @@ -264,27 +264,8 @@ function new_contact($uid,$url,$interactive = false) { require_once("include/Photo.php"); - $photos = import_profile_photo($ret['photo'],$uid,$contact_id); - - $r = q("UPDATE `contact` SET - `avatar` = '%s', - `photo` = '%s', - `thumb` = '%s', - `micro` = '%s', - `name-date` = '%s', - `uri-date` = '%s', - `avatar-date` = '%s' - WHERE `id` = %d", - dbesc($ret['photo']), - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval($contact_id) - ); - + // Update the avatar + update_contact_avatar($ret['photo'],$uid,$contact_id); // pull feed and consume it, which should subscribe to the hub. diff --git a/include/gprobe.php b/include/gprobe.php index 8e4d3715c0..dfa9137d7d 100644 --- a/include/gprobe.php +++ b/include/gprobe.php @@ -58,10 +58,8 @@ function gprobe_run(&$argv, &$argc){ if (is_null($result)) Cache::set("gprobe:".$urlparts["host"],serialize($arr)); - if (!in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) { - $arr["avatar"] = $arr["photo"]; + if (!in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) update_gcontact($arr); - } $r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1", dbesc(normalise_link($url)) diff --git a/include/ostatus.php b/include/ostatus.php index eeacd40de4..d4c5d1617c 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -127,7 +127,8 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) $author["owner-link"] = $author["author-link"]; $author["owner-avatar"] = $author["author-avatar"]; - if ($r AND !$onlyfetch) { + // Only update the contacts if it is an OStatus contact + if ($r AND !$onlyfetch AND ($contact["network"] == NETWORK_OSTATUS)) { // Update contact data $value = $xpath->query("atom:link[@rel='salmon']", $context)->item(0)->nodeValue; @@ -158,9 +159,9 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) logger("Update contact data for contact ".$contact["id"], LOGGER_DEBUG); - q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', `name-date` = '%s' WHERE `id` = %d AND `network` = '%s'", + q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', `name-date` = '%s' WHERE `id` = %d", dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["about"]), dbesc($contact["location"]), - dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS)); + dbesc(datetime_convert()), intval($contact["id"])); poco_check($contact["url"], $contact["name"], $contact["network"], $author["author-avatar"], $contact["about"], $contact["location"], "", "", "", datetime_convert(), 2, $contact["id"], $contact["uid"]); @@ -169,20 +170,14 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) if (isset($author["author-avatar"]) AND ($author["author-avatar"] != $r[0]['avatar'])) { logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG); - $photos = import_profile_photo($author["author-avatar"], $importer["uid"], $contact["id"]); - - q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d AND `network` = '%s'", - dbesc($author["author-avatar"]), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), - dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS)); + update_contact_avatar($author["author-avatar"], $importer["uid"], $contact["id"]); } - // Only update the global contact if it is an OStatus contact - if ($contact["network"] == NETWORK_OSTATUS) { - /// @todo Add the "addr" field - $contact["generation"] = 2; - $contact["avatar"] = $author["author-avatar"]; - update_gcontact($contact); - } + + /// @todo Add the "addr" field + $contact["generation"] = 2; + $contact["photo"] = $author["author-avatar"]; + update_gcontact($contact); } return($author); diff --git a/include/socgraph.php b/include/socgraph.php index 241e2df7f0..268b5d3e72 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -294,7 +294,7 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca "alias" => $alias, "name" => $name, "network" => $network, - "avatar" => $profile_photo, + "photo" => $profile_photo, "about" => $about, "location" => $location, "gender" => $gender, @@ -1517,7 +1517,7 @@ function update_gcontact($contact) { if (!$gcontact_id) return false; - $r = q("SELECT `name`, `nick`, `avatar`, `photo`, `thumb`, `micro`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`, + $r = q("SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`, `hide`, `nsfw`, `network`, `alias`, `notify`, `server_url`, `connect`, `updated`, `url` FROM `gcontact` WHERE `id` = %d LIMIT 1", intval($gcontact_id)); @@ -1552,37 +1552,15 @@ function update_gcontact($contact) { if ($contact["generation"] < $r[0]["generation"]) $update = true; - if (isset($contact["avatar"]) AND (($contact["avatar"] != $r[0]["avatar"]) OR - ($r[0]["photo"] == $r[0]["avatar"]) OR ($r[0]["thumb"] == "") OR ($r[0]["micro"] == ""))) { - - $cid = get_contact($contact["url"]); - - // We always store avatar picture with a contact-id. - // We don't have a contact-id when we use the gcontact table. - // Solution is to use a matching entry in the contact table. (Which is not totally clean) - if (($cid == 0) AND isset($contact["uid"])) - $cid = get_contact($contact["url"], $contact["uid"]); - - $photos = update_contact_avatar($contact["avatar"], 0, $cid); - - if ($photos) { - $contact["photo"] = $photos[0]; - $contact["thumb"] = $photos[1]; - $contact["micro"] = $photos[2]; - } - } - if ($update) { - q("UPDATE `gcontact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', - `name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s', + q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s', `birthday` = '%s', `gender` = '%s', `keywords` = %d, `hide` = %d, `nsfw` = %d, `alias` = '%s', `notify` = '%s', `url` = '%s', `location` = '%s', `about` = '%s', `generation` = %d, `updated` = '%s', `server_url` = '%s', `connect` = '%s' WHERE `nurl` = '%s' AND (`generation` = 0 OR `generation` >= %d)", - dbesc($contact["avatar"]), dbesc($contact["photo"]), dbesc($contact["thumb"]), - dbesc($contact["micro"]), dbesc($contact["name"]), dbesc($contact["nick"]), + dbesc($contact["photo"]), dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["addr"]), dbesc($contact["network"]), dbesc($contact["birthday"]), dbesc($contact["gender"]), dbesc($contact["keywords"]), intval($contact["hide"]), intval($contact["nsfw"]), dbesc($contact["alias"]), dbesc($contact["notify"]), diff --git a/mod/contacts.php b/mod/contacts.php index 1ef201490c..0b421433e0 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -293,26 +293,8 @@ function _contact_update_profile($contact_id) { intval(local_user()) ); - $photos = import_profile_photo($data['photo'], local_user(), $contact_id); - - $r = q("UPDATE `contact` SET - `avatar` = '%s', - `photo` = '%s', - `thumb` = '%s', - `micro` = '%s', - `name-date` = '%s', - `uri-date` = '%s', - `avatar-date` = '%s' - WHERE `id` = %d", - dbesc($data["photo"]), - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval($contact_id) - ); + // Update the entry in the contact table + update_contact_avatar($data['photo'], local_user(), $contact_id); // Update the entry in the gcontact table update_gcontact_from_probe($data["url"]); diff --git a/mod/crepair.php b/mod/crepair.php index 606c388458..5b4db09dac 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -80,27 +80,7 @@ function crepair_post(&$a) { logger('mod-crepair: updating photo from ' . $photo); require_once("include/Photo.php"); - $photos = import_profile_photo($photo,local_user(),$contact['id']); - - $x = q("UPDATE `contact` SET - `avatar` = '%s', - `photo` = '%s', - `thumb` = '%s', - `micro` = '%s', - `name-date` = '%s', - `uri-date` = '%s', - `avatar-date` = '%s' - WHERE `id` = %d - ", - dbesc($photo), - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval($contact['id']) - ); + update_contact_avatar($photo,local_user(),$contact['id']); } if($r) diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 8528ba9ffd..27c04a908d 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -315,7 +315,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { require_once('include/Photo.php'); - $photos = import_profile_photo($contact['photo'],$uid,$contact_id); + update_contact_avatar($contact['photo'],$uid,$contact_id); logger('dfrn_confirm: confirm - imported photos'); @@ -328,29 +328,18 @@ function dfrn_confirm_post(&$a,$handsfree = null) { if(($relation == CONTACT_IS_SHARING) && ($duplex)) $duplex = 0; - $r = q("UPDATE `contact` SET - `avatar` = '%s', - `photo` = '%s', - `thumb` = '%s', - `micro` = '%s', - `rel` = %d, + $r = q("UPDATE `contact` SET `rel` = %d, `name-date` = '%s', `uri-date` = '%s', - `avatar-date` = '%s', `blocked` = 0, `pending` = 0, `duplex` = %d, `hidden` = %d, `network` = '%s' WHERE `id` = %d ", - dbesc($contact['photo']), - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), intval($new_relation), dbesc(datetime_convert()), dbesc(datetime_convert()), - dbesc(datetime_convert()), intval($duplex), intval($hidden), dbesc(NETWORK_DFRN), @@ -396,12 +385,8 @@ function dfrn_confirm_post(&$a,$handsfree = null) { ); - $r = q("UPDATE `contact` SET `photo` = '%s', - `thumb` = '%s', - `micro` = '%s', - `name-date` = '%s', + $r = q("UPDATE `contact` SET `name-date` = '%s', `uri-date` = '%s', - `avatar-date` = '%s', `notify` = '%s', `poll` = '%s', `blocked` = 0, @@ -412,10 +397,6 @@ function dfrn_confirm_post(&$a,$handsfree = null) { `rel` = %d WHERE `id` = %d ", - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), - dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc($notify), @@ -685,7 +666,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { require_once("include/Photo.php"); - $photos = import_profile_photo($photo,$local_uid,$dfrn_record); + update_contact_avatar($photo,$local_uid,$dfrn_record); logger('dfrn_confirm: request - photos imported'); @@ -697,14 +678,9 @@ function dfrn_confirm_post(&$a,$handsfree = null) { $duplex = 0; $r = q("UPDATE `contact` SET - `avatar` = '%s', - `photo` = '%s', - `thumb` = '%s', - `micro` = '%s', `rel` = %d, `name-date` = '%s', `uri-date` = '%s', - `avatar-date` = '%s', `blocked` = 0, `pending` = 0, `duplex` = %d, @@ -712,14 +688,9 @@ function dfrn_confirm_post(&$a,$handsfree = null) { `prv` = %d, `network` = '%s' WHERE `id` = %d ", - dbesc($photo), - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), intval($new_relation), dbesc(datetime_convert()), dbesc(datetime_convert()), - dbesc(datetime_convert()), intval($duplex), intval($forum), intval($prv), diff --git a/mod/item.php b/mod/item.php index bf0ead4932..8c5a479646 100644 --- a/mod/item.php +++ b/mod/item.php @@ -1146,7 +1146,6 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo if (!$r) { $probed = probe_url($name); if (isset($probed["url"])) { - $probed["avatar"] = $probed["photo"]; update_gcontact($probed); $r = q("SELECT `url`, `name`, `nick`, `network`, `alias`, `notify` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link($probed["url"]))); From 04725d12837e024a17285ae7454b69e995521846 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 28 Jan 2016 11:14:13 +0100 Subject: [PATCH 03/12] Reverted some work ... --- include/socgraph.php | 2 -- mod/poco.php | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index 268b5d3e72..23ef05cb25 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -10,7 +10,6 @@ require_once('include/datetime.php'); require_once("include/Scrape.php"); require_once("include/html2bbcode.php"); -require_once("include/Contact.php"); /* * poco_load @@ -1553,7 +1552,6 @@ function update_gcontact($contact) { $update = true; if ($update) { - q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s', `birthday` = '%s', `gender` = '%s', `keywords` = %d, `hide` = %d, `nsfw` = %d, `alias` = '%s', `notify` = '%s', `url` = '%s', diff --git a/mod/poco.php b/mod/poco.php index 3927f125ea..0a1b392169 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -179,9 +179,6 @@ function poco_init(&$a) { $rr['generation'] = 2; } - if ($rr["avatar"] == "") - $rr["avatar"] = $rr["photo"]; - if (($rr['about'] == "") AND isset($rr['pabout'])) $rr['about'] = $rr['pabout']; @@ -261,7 +258,7 @@ function poco_init(&$a) { $entry['updated'] = date("c", strtotime($entry['updated'])); } if($fields_ret['photos']) - $entry['photos'] = array(array('value' => $rr['avatar'], 'type' => 'profile')); + $entry['photos'] = array(array('value' => $rr['photo'], 'type' => 'profile')); if($fields_ret['network']) { $entry['network'] = $rr['network']; if ($entry['network'] == NETWORK_STATUSNET) From eba9f15daab5e4c2d246aaa7c3d9a0aacc945f01 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 28 Jan 2016 11:18:57 +0100 Subject: [PATCH 04/12] Removed some more work --- include/dbstructure.php | 3 --- include/socgraph.php | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index fd5883911a..96d18cd789 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -657,10 +657,7 @@ function db_definition() { "nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "nurl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), - "avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), - "thumb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), - "micro" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "connect" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"), "updated" => array("type" => "datetime", "default" => "0000-00-00 00:00:00"), diff --git a/include/socgraph.php b/include/socgraph.php index 23ef05cb25..c545343393 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -11,6 +11,7 @@ require_once('include/datetime.php'); require_once("include/Scrape.php"); require_once("include/html2bbcode.php"); + /* * poco_load * From 845a769dc224f9e654a983711bf0f4687788f5fb Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 28 Jan 2016 12:28:04 +0100 Subject: [PATCH 05/12] Only check size if needed - should speed up the uploading. --- mod/wall_upload.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mod/wall_upload.php b/mod/wall_upload.php index a1dab53779..b815348c70 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -158,14 +158,18 @@ function wall_upload_post(&$a, $desktopmode = true) { killme(); } - logger("Check size of picture.", LOGGER_DEBUG); - $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", - intval($page_owner_uid) - ); $limit = service_class_fetch($page_owner_uid,'photo_upload_limit'); - if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) { + if ($limit) { + $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", + intval($page_owner_uid) + ); + $size = $r[0]['total']; + } else + $size = 0; + + if(($limit !== false) && (($size + strlen($imagedata)) > $limit)) { $msg = upgrade_message(true); if ($r_json) { echo json_encode(array('error'=>$msg)); @@ -177,7 +181,6 @@ function wall_upload_post(&$a, $desktopmode = true) { } - logger("Picture will be processed.", LOGGER_DEBUG); $imagedata = @file_get_contents($src); $ph = new Photo($imagedata, $filetype); @@ -212,7 +215,6 @@ function wall_upload_post(&$a, $desktopmode = true) { $defperm = '<' . $default_cid . '>'; - logger("Picture will be stored", LOGGER_DEBUG); $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, $defperm); if(! $r) { @@ -269,7 +271,6 @@ function wall_upload_post(&$a, $desktopmode = true) { return $picture; } - logger("Picture is stored.", LOGGER_DEBUG); if ($r_json) { echo json_encode(array('ok'=>true)); From 410ebb4cbf0a674967a8599647a042922ea3d5ef Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 28 Jan 2016 12:35:07 +0100 Subject: [PATCH 06/12] Added documentation --- include/Photo.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/Photo.php b/include/Photo.php index e0cb23008a..3f1608d3ec 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -720,6 +720,15 @@ function guess_image_type($filename, $fromcurl=false) { } +/** + * @brief Updates the avatar links in a contact only if needed + * + * @param string $avatar Link to avatar picture + * @param int $uid User id of contact owner + * @param int $cid Contact id + * + * @return array Returns array of the different avatar sizes + */ function update_contact_avatar($avatar,$uid,$cid) { $r = q("SELECT `avatar`, `photo`, `thumb`, `micro` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid)); From a93d35bfdabb083b1234b7c65c2e9e05219370a4 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 28 Jan 2016 18:06:17 +0100 Subject: [PATCH 07/12] gcontact-id now depends on the owner, not the author of a post --- include/items.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/include/items.php b/include/items.php index cf044d8837..5ebf41c057 100644 --- a/include/items.php +++ b/include/items.php @@ -971,7 +971,9 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa // The contact-id should be set before "item_store" was called - but there seems to be some issues if ($arr["contact-id"] == 0) { // First we are looking for a suitable contact that matches with the author of the post - $arr["contact-id"] = get_contact($arr['author-link'], $uid); + // This is done only for comments (See below explanation at "gcontact-id") + if($arr['parent-uri'] != $arr['uri']) + $arr["contact-id"] = get_contact($arr['author-link'], $uid); // If not present then maybe the owner was found if ($arr["contact-id"] == 0) @@ -983,12 +985,20 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa if ($r) $arr["contact-id"] = $r[0]["id"]; } - logger("Contact-id was missing for post ".$arr["guid"]." - now set to ".$arr["contact-id"], LOGGER_DEBUG); + logger("Contact-id was missing for post ".$arr["guid"]." from user id ".$uid." - now set to ".$arr["contact-id"], LOGGER_DEBUG); } - if ($arr["gcontact-id"] == 0) - $arr["gcontact-id"] = get_gcontact_id(array("url" => $arr['author-link'], "network" => $arr['network'], - "photo" => $arr['author-avatar'], "name" => $arr['author-name'])); + if ($arr["gcontact-id"] == 0) { + // The gcontact should mostly behave like the contact. But is is supposed to be global for the system. + // This means that wall posts, repeated posts, etc. should have the gcontact id of the owner. + // On comments the author is the better choice. + if($arr['parent-uri'] === $arr['uri']) + $arr["gcontact-id"] = get_gcontact_id(array("url" => $arr['owner-link'], "network" => $arr['network'], + "photo" => $arr['owner-avatar'], "name" => $arr['owner-name'])); + else + $arr["gcontact-id"] = get_gcontact_id(array("url" => $arr['author-link'], "network" => $arr['network'], + "photo" => $arr['author-avatar'], "name" => $arr['author-name'])); + } if ($arr['guid'] != "") { // Checking if there is already an item with the same guid From b3e86f4e6b0953b09ce0556de3bec72edcd285d7 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 28 Jan 2016 22:58:05 +0100 Subject: [PATCH 08/12] There is now a central function for item notifications --- include/diaspora.php | 43 +---------- include/enotify.php | 94 ++++++++++++++++++++++++ include/items.php | 171 ++----------------------------------------- include/ostatus.php | 45 ------------ 4 files changed, 100 insertions(+), 253 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index b72239c4ce..f1e6f7ff02 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -14,6 +14,7 @@ require_once('include/queue_fn.php'); require_once('include/lock.php'); require_once('include/threads.php'); require_once('mod/share.php'); +require_once('include/enotify.php'); function diaspora_dispatch_public($msg) { @@ -1598,47 +1599,6 @@ function diaspora_comment($importer,$xml,$msg) { proc_run('php','include/notifier.php','comment-import',$message_id); } - $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0 ", - dbesc($parent_item['uri']), - intval($importer['uid']) - ); - - if(count($myconv)) { - $importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname']; - - foreach($myconv as $conv) { - - // now if we find a match, it means we're in this conversation - - if(! link_compare($conv['author-link'],$importer_url)) - continue; - - require_once('include/enotify.php'); - - $conv_parent = $conv['parent']; - - notification(array( - 'type' => NOTIFY_COMMENT, - 'notify_flags' => $importer['notify-flags'], - 'language' => $importer['language'], - 'to_name' => $importer['username'], - 'to_email' => $importer['email'], - 'uid' => $importer['uid'], - 'item' => $datarray, - 'link' => $a->get_baseurl().'/display/'.urlencode($datarray['guid']), - 'source_name' => $datarray['author-name'], - 'source_link' => $datarray['author-link'], - 'source_photo' => $datarray['author-avatar'], - 'verb' => ACTIVITY_POST, - 'otype' => 'item', - 'parent' => $conv_parent, - 'parent_uri' => $parent_uri - )); - - // only send one notification - break; - } - } return; } @@ -1793,7 +1753,6 @@ function diaspora_conversation($importer,$xml,$msg) { intval($conversation['id']) ); - require_once('include/enotify.php'); notification(array( 'type' => NOTIFY_MAIL, 'notify_flags' => $importer['notify-flags'], diff --git a/include/enotify.php b/include/enotify.php index e02c613831..80fd4d3363 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -633,4 +633,98 @@ function notification($params) { } +/** + * @brief Checks for item related notifications and sends them + * + * @param int $itemid ID of the item for which the check should be done + * @param int $uid User ID + * @param str $profile (Optional) Can be used for connector post. Otherwise empty. + */ +function check_item_notification($itemid, $uid, $profile = "", $defaulttype = "") { + + $user = q("SELECT `notify-flags`, `language`, `username`, `email` FROM `user` WHERE `uid` = %d", intval($uid)); + if (!$user) + return false; + + $owner = q("SELECT `id`, `url` FROM `contact` WHERE `self` AND `uid` = %d LIMIT 1", intval($uid)); + if (!$owner) + return false; + $local_profile = $owner[0]["url"]; + + if ($profile == "") + $profile = $local_profile; + + // Only act if it is a "real" post + // We need the additional check for the "local_profile" because of mixed situations on connector networks + $item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-name`, `author-link`, `author-avatar`, `guid`, + `parent-uri`, `uri`, `contact-id` + FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND + `author-link` != '%s' AND `author-link` != '%s' LIMIT 1", + intval($itemid), dbesc(ACTIVITY_POST), dbesc($profile), dbesc($local_profile)); + if (!$item) + return false; + + // Generate the notification array + $params = array(); + $params["uid"] = $uid; + $params["notify_flags"] = $user[0]["notify-flags"]; + $params["language"] = $user[0]["language"]; + $params["to_name"] = $user[0]["username"]; + $params["to_email"] = $user[0]["email"]; + $params["item"] = $item[0]; + $params["parent"] = $item[0]["parent"]; + $params["link"] = App::get_baseurl().'/display/'.urlencode($item[0]["guid"]); + $params["otype"] = 'item'; + $params["source_name"] = $item[0]["author-name"]; + $params["source_link"] = $item[0]["author-link"]; + $params["source_photo"] = $item[0]["author-avatar"]; + + if ($item[0]["parent-uri"] === $item[0]["uri"]) { + // Send a notification for every new post? + $r = q("SELECT `notify_new_posts` FROM `contact` WHERE `id` = %d AND `uid` = %d AND `notify_new_posts` LIMIT 1", + intval($item[0]['contact-id']), + intval($uid) + ); + $send_notification = count($r); + + if (!$send_notification) { + $tags = q("SELECT `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` = %d AND `uid` = %d", + intval(TERM_OBJ_POST), intval($itemid), intval(TERM_MENTION), intval($uid)); + + if (count($tags)) { + foreach ($tags AS $tag) { + $r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `notify_new_posts`", + normalise_link($tag["url"]), intval($uid)); + if (count($r)) + $send_notification = true; + } + } + } + + if ($send_notification) { + $params["type"] = NOTIFY_SHARE; + $params["verb"] = ACTIVITY_TAG; + } + } + + // Is the user mentioned in this post? + if ($item[0]["mention"] OR strpos($item[0]["tag"], "=".$profile."]") OR ($defaulttype == NOTIFY_TAGSELF)) { + $params["type"] = NOTIFY_TAGSELF; + $params["verb"] = ACTIVITY_TAG; + } + + // Is it a post that the user had started or where he interacted? + $parent = q("SELECT `thread`.`iid` FROM `thread` INNER JOIN `item` ON `item`.`parent` = `thread`.`iid` + WHERE `thread`.`iid` = %d AND `thread`.`uid` = %d AND NOT `thread`.`ignored` AND + (`thread`.`mention` OR `item`.`author-link` = '%s') + LIMIT 1", + intval($item[0]["parent"]), intval($uid), dbesc($profile)); + if ($parent AND !isset($params["type"])) { + $params["type"] = NOTIFY_COMMENT; + $params["verb"] = ACTIVITY_POST; + } + + if (isset($params["type"])) + notification($params); +} ?> diff --git a/include/items.php b/include/items.php index cf044d8837..5a3e021f94 100644 --- a/include/items.php +++ b/include/items.php @@ -16,6 +16,7 @@ require_once('include/ostatus.php'); require_once('include/feed.php'); require_once('include/Contact.php'); require_once('mod/share.php'); +require_once('include/enotify.php'); require_once('library/defuse/php-encryption-1.2.1/Crypto.php'); @@ -1313,67 +1314,15 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa create_files_from_item($current_post); // Only check for notifications on start posts - if ($arr['parent-uri'] === $arr['uri']) { + if ($arr['parent-uri'] === $arr['uri']) add_thread($current_post); - logger('item_store: Check notification for contact '.$arr['contact-id'].' and post '.$current_post, LOGGER_DEBUG); - - // Send a notification for every new post? - $r = q("SELECT `notify_new_posts` FROM `contact` WHERE `id` = %d AND `uid` = %d AND `notify_new_posts` LIMIT 1", - intval($arr['contact-id']), - intval($arr['uid']) - ); - $send_notification = count($r); - - if (!$send_notification) { - $tags = q("SELECT `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` = %d AND `uid` = %d", - intval(TERM_OBJ_POST), intval($current_post), intval(TERM_MENTION), intval($arr['uid'])); - - if (count($tags)) { - foreach ($tags AS $tag) { - $r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `notify_new_posts`", - normalise_link($tag["url"]), intval($arr['uid'])); - if (count($r)) - $send_notification = true; - } - } - } - - if ($send_notification) { - logger('item_store: Send notification for contact '.$arr['contact-id'].' and post '.$current_post, LOGGER_DEBUG); - $u = q("SELECT * FROM user WHERE uid = %d LIMIT 1", - intval($arr['uid'])); - - $item = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d", - intval($current_post), - intval($arr['uid']) - ); - - $a = get_app(); - - require_once('include/enotify.php'); - notification(array( - 'type' => NOTIFY_SHARE, - 'notify_flags' => $u[0]['notify-flags'], - 'language' => $u[0]['language'], - 'to_name' => $u[0]['username'], - 'to_email' => $u[0]['email'], - 'uid' => $u[0]['uid'], - 'item' => $item[0], - 'link' => $a->get_baseurl().'/display/'.urlencode($arr['guid']), - 'source_name' => $item[0]['author-name'], - 'source_link' => $item[0]['author-link'], - 'source_photo' => $item[0]['author-avatar'], - 'verb' => ACTIVITY_TAG, - 'otype' => 'item', - 'parent' => $arr['parent'] - )); - logger('item_store: Notification sent for contact '.$arr['contact-id'].' and post '.$current_post, LOGGER_DEBUG); - } - } else { + else { update_thread($parent_id); add_shadow_entry($arr); } + check_item_notification($current_post, $uid); + if ($notify) proc_run('php', "include/notifier.php", $notify_type, $current_post); @@ -1569,37 +1518,6 @@ function tag_deliver($uid,$item_id) { return; } - - // send a notification - - // use a local photo if we have one - - $r = q("select * from contact where uid = %d and nurl = '%s' limit 1", - intval($u[0]['uid']), - dbesc(normalise_link($item['author-link'])) - ); - $photo = (($r && count($r)) ? $r[0]['thumb'] : $item['author-avatar']); - - - require_once('include/enotify.php'); - notification(array( - 'type' => NOTIFY_TAGSELF, - 'notify_flags' => $u[0]['notify-flags'], - 'language' => $u[0]['language'], - 'to_name' => $u[0]['username'], - 'to_email' => $u[0]['email'], - 'uid' => $u[0]['uid'], - 'item' => $item, - 'link' => $a->get_baseurl() . '/display/'.urlencode(get_item_guid($item['id'])), - 'source_name' => $item['author-name'], - 'source_link' => $item['author-link'], - 'source_photo' => $photo, - 'verb' => ACTIVITY_TAG, - 'otype' => 'item', - 'parent' => $item['parent'] - )); - - $arr = array('item' => $item, 'user' => $u[0], 'contact' => $r[0]); call_hooks('tagged', $arr); @@ -3245,33 +3163,7 @@ function local_delivery($importer,$data) { } if($posted_id && $parent) { - proc_run('php',"include/notifier.php","comment-import","$posted_id"); - - if((! $is_like) && (! $importer['self'])) { - - require_once('include/enotify.php'); - - notification(array( - 'type' => NOTIFY_COMMENT, - 'notify_flags' => $importer['notify-flags'], - 'language' => $importer['language'], - 'to_name' => $importer['username'], - 'to_email' => $importer['email'], - 'uid' => $importer['importer_uid'], - 'item' => $datarray, - 'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($posted_id)), - 'source_name' => stripslashes($datarray['author-name']), - 'source_link' => $datarray['author-link'], - 'source_photo' => ((link_compare($datarray['author-link'],$importer['url'])) - ? $importer['thumb'] : $datarray['author-avatar']), - 'verb' => ACTIVITY_POST, - 'otype' => 'item', - 'parent' => $parent, - 'parent_uri' => $parent_uri, - )); - - } } return 0; @@ -3393,59 +3285,6 @@ function local_delivery($importer,$data) { $posted_id = item_store($datarray); - // find out if our user is involved in this conversation and wants to be notified. - - if(!x($datarray['type']) || $datarray['type'] != 'activity') { - - $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0", - dbesc($top_uri), - intval($importer['importer_uid']) - ); - - if(count($myconv)) { - $importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname']; - - // first make sure this isn't our own post coming back to us from a wall-to-wall event - if(! link_compare($datarray['author-link'],$importer_url)) { - - - foreach($myconv as $conv) { - - // now if we find a match, it means we're in this conversation - - if(! link_compare($conv['author-link'],$importer_url)) - continue; - - require_once('include/enotify.php'); - - $conv_parent = $conv['parent']; - - notification(array( - 'type' => NOTIFY_COMMENT, - 'notify_flags' => $importer['notify-flags'], - 'language' => $importer['language'], - 'to_name' => $importer['username'], - 'to_email' => $importer['email'], - 'uid' => $importer['importer_uid'], - 'item' => $datarray, - 'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($posted_id)), - 'source_name' => stripslashes($datarray['author-name']), - 'source_link' => $datarray['author-link'], - 'source_photo' => ((link_compare($datarray['author-link'],$importer['url'])) - ? $importer['thumb'] : $datarray['author-avatar']), - 'verb' => ACTIVITY_POST, - 'otype' => 'item', - 'parent' => $conv_parent, - 'parent_uri' => $parent_uri - - )); - - // only send one notification - break; - } - } - } - } continue; } } diff --git a/include/ostatus.php b/include/ostatus.php index 4ccd13130d..f2e33b1327 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -561,29 +561,6 @@ function ostatus_import($xml,$importer,&$contact, &$hub) { } logger("Item was stored with id ".$item_id, LOGGER_DEBUG); - $item["id"] = $item_id; - - if ($mention AND in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_SHARE))) { - $u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($item['uid'])); - $r = q("SELECT `parent` FROM `item` WHERE `id` = %d", intval($item_id)); - - notification(array( - 'type' => NOTIFY_TAGSELF, - 'notify_flags' => $u[0]["notify-flags"], - 'language' => $u[0]["language"], - 'to_name' => $u[0]["username"], - 'to_email' => $u[0]["email"], - 'uid' => $item["uid"], - 'item' => $item, - 'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($item_id)), - 'source_name' => $item["author-name"], - 'source_link' => $item["author-link"], - 'source_photo' => $item["author-avatar"], - 'verb' => ACTIVITY_TAG, - 'otype' => 'item', - 'parent' => $r[0]["parent"] - )); - } } } @@ -1028,28 +1005,6 @@ function ostatus_completion($conversation_url, $uid, $item = array()) { // Add the conversation entry (but don't fetch the whole conversation) ostatus_store_conversation($newitem, $conversation_url); - if ($mention) { - $u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($uid)); - $r = q("SELECT `parent` FROM `item` WHERE `id` = %d", intval($newitem)); - - notification(array( - 'type' => NOTIFY_TAGSELF, - 'notify_flags' => $u[0]["notify-flags"], - 'language' => $u[0]["language"], - 'to_name' => $u[0]["username"], - 'to_email' => $u[0]["email"], - 'uid' => $uid, - 'item' => $arr, - 'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($newitem)), - 'source_name' => $arr["author-name"], - 'source_link' => $arr["author-link"], - 'source_photo' => $arr["author-avatar"], - 'verb' => ACTIVITY_TAG, - 'otype' => 'item', - 'parent' => $r[0]["parent"] - )); - } - // If the newly created item is the top item then change the parent settings of the thread // This shouldn't happen anymore. This is supposed to be absolote. if ($arr["uri"] == $first_id) { From 8767ea5f5200fac985fd94fdaf68ee4b5d47c432 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 29 Jan 2016 01:18:18 +0100 Subject: [PATCH 09/12] Improved check against profile --- include/enotify.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/include/enotify.php b/include/enotify.php index 80fd4d3363..476703178c 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -654,13 +654,17 @@ function check_item_notification($itemid, $uid, $profile = "", $defaulttype = "" if ($profile == "") $profile = $local_profile; + $profile = normalise_link($profile); + + $profile_ssl = str_replace("http://", "https://", normalise_link($profile)); + // Only act if it is a "real" post // We need the additional check for the "local_profile" because of mixed situations on connector networks $item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-name`, `author-link`, `author-avatar`, `guid`, `parent-uri`, `uri`, `contact-id` FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND - `author-link` != '%s' AND `author-link` != '%s' LIMIT 1", - intval($itemid), dbesc(ACTIVITY_POST), dbesc($profile), dbesc($local_profile)); + NOT (`author-link` IN ('%s', '%s', '%s')) LIMIT 1", + intval($itemid), dbesc(ACTIVITY_POST), dbesc($profile), dbesc($profile_ssl), dbesc($local_profile)); if (!$item) return false; @@ -708,7 +712,8 @@ function check_item_notification($itemid, $uid, $profile = "", $defaulttype = "" } // Is the user mentioned in this post? - if ($item[0]["mention"] OR strpos($item[0]["tag"], "=".$profile."]") OR ($defaulttype == NOTIFY_TAGSELF)) { + if ($item[0]["mention"] OR strpos($item[0]["tag"], "=".$profile."]") OR strpos($item[0]["tag"], "=".$profile_ssl."]") OR + strpos($item[0]["tag"], "=".$local_profile."]") OR ($defaulttype == NOTIFY_TAGSELF)) { $params["type"] = NOTIFY_TAGSELF; $params["verb"] = ACTIVITY_TAG; } @@ -716,9 +721,10 @@ function check_item_notification($itemid, $uid, $profile = "", $defaulttype = "" // Is it a post that the user had started or where he interacted? $parent = q("SELECT `thread`.`iid` FROM `thread` INNER JOIN `item` ON `item`.`parent` = `thread`.`iid` WHERE `thread`.`iid` = %d AND `thread`.`uid` = %d AND NOT `thread`.`ignored` AND - (`thread`.`mention` OR `item`.`author-link` = '%s') + (`thread`.`mention` OR `item`.`author-link` IN ('%s', '%s', '%s')) LIMIT 1", - intval($item[0]["parent"]), intval($uid), dbesc($profile)); + intval($item[0]["parent"]), intval($uid), + dbesc($profile), dbesc($profile_ssl), dbesc($local_profile)); if ($parent AND !isset($params["type"])) { $params["type"] = NOTIFY_COMMENT; $params["verb"] = ACTIVITY_POST; From e4c4b8e13eae4c798f25b0ebe7b4adeee546a3e1 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 29 Jan 2016 03:02:15 +0100 Subject: [PATCH 10/12] It's better to ask the connectors for their profile data --- include/enotify.php | 53 +++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/include/enotify.php b/include/enotify.php index 476703178c..d3f1ab580b 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -638,9 +638,14 @@ function notification($params) { * * @param int $itemid ID of the item for which the check should be done * @param int $uid User ID - * @param str $profile (Optional) Can be used for connector post. Otherwise empty. + * @param str $defaulttype (Optional) Forces a notification with this type. */ -function check_item_notification($itemid, $uid, $profile = "", $defaulttype = "") { +function check_item_notification($itemid, $uid, $defaulttype = "") { + + $notification_data = array("uid" => $uid, "profiles" => array()); + call_hooks('check_item_notification', $notification_data); + + $profiles = $notification_data["profiles"]; $user = q("SELECT `notify-flags`, `language`, `username`, `email` FROM `user` WHERE `uid` = %d", intval($uid)); if (!$user) @@ -649,22 +654,36 @@ function check_item_notification($itemid, $uid, $profile = "", $defaulttype = "" $owner = q("SELECT `id`, `url` FROM `contact` WHERE `self` AND `uid` = %d LIMIT 1", intval($uid)); if (!$owner) return false; - $local_profile = $owner[0]["url"]; - if ($profile == "") - $profile = $local_profile; + $profiles[] = $owner[0]["url"]; - $profile = normalise_link($profile); + $profiles2 = array(); - $profile_ssl = str_replace("http://", "https://", normalise_link($profile)); + foreach ($profiles AS $profile) { + $profiles2[] = normalise_link($profile); + $profiles2[] = str_replace("http://", "https://", normalise_link($profile)); + } + + $profiles = $profiles2; + + $profile_list = ""; + + foreach ($profiles AS $profile) { + if ($profile_list != "") + $profile_list .= "', '"; + + $profile_list .= dbesc($profile); + } + + $profile_list = "'".$profile_list."'"; // Only act if it is a "real" post // We need the additional check for the "local_profile" because of mixed situations on connector networks $item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-name`, `author-link`, `author-avatar`, `guid`, `parent-uri`, `uri`, `contact-id` FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND - NOT (`author-link` IN ('%s', '%s', '%s')) LIMIT 1", - intval($itemid), dbesc(ACTIVITY_POST), dbesc($profile), dbesc($profile_ssl), dbesc($local_profile)); + NOT (`author-link` IN ($profile_list)) LIMIT 1", + intval($itemid), dbesc(ACTIVITY_POST)); if (!$item) return false; @@ -712,8 +731,14 @@ function check_item_notification($itemid, $uid, $profile = "", $defaulttype = "" } // Is the user mentioned in this post? - if ($item[0]["mention"] OR strpos($item[0]["tag"], "=".$profile."]") OR strpos($item[0]["tag"], "=".$profile_ssl."]") OR - strpos($item[0]["tag"], "=".$local_profile."]") OR ($defaulttype == NOTIFY_TAGSELF)) { + $tagged = false; + + foreach ($profiles AS $profile) { + if (strpos($item[0]["tag"], "=".$profile."]")) + $tagged = true; + } + + if ($item[0]["mention"] OR $tagged OR ($defaulttype == NOTIFY_TAGSELF)) { $params["type"] = NOTIFY_TAGSELF; $params["verb"] = ACTIVITY_TAG; } @@ -721,10 +746,10 @@ function check_item_notification($itemid, $uid, $profile = "", $defaulttype = "" // Is it a post that the user had started or where he interacted? $parent = q("SELECT `thread`.`iid` FROM `thread` INNER JOIN `item` ON `item`.`parent` = `thread`.`iid` WHERE `thread`.`iid` = %d AND `thread`.`uid` = %d AND NOT `thread`.`ignored` AND - (`thread`.`mention` OR `item`.`author-link` IN ('%s', '%s', '%s')) + (`thread`.`mention` OR `item`.`author-link` IN ($profile_list)) LIMIT 1", - intval($item[0]["parent"]), intval($uid), - dbesc($profile), dbesc($profile_ssl), dbesc($local_profile)); + intval($item[0]["parent"]), intval($uid)); + if ($parent AND !isset($params["type"])) { $params["type"] = NOTIFY_COMMENT; $params["verb"] = ACTIVITY_POST; From 56687f5bc8fc9e9a533b10fee27238689c60f83b Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 29 Jan 2016 03:46:43 +0100 Subject: [PATCH 11/12] Check the body for notifications as well --- include/enotify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/enotify.php b/include/enotify.php index d3f1ab580b..54b59857c2 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -734,7 +734,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { $tagged = false; foreach ($profiles AS $profile) { - if (strpos($item[0]["tag"], "=".$profile."]")) + if (strpos($item[0]["tag"], "=".$profile."]") OR strpos($item[0]["body"], "=".$profile."]")) $tagged = true; } From 4d33441c2ef5f576537c43d04fc3c4b0bf9a6561 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 29 Jan 2016 03:51:12 +0100 Subject: [PATCH 12/12] DB Version was forgotten ... --- boot.php | 2 +- update.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/boot.php b/boot.php index 955b89e56c..4ef30eadac 100644 --- a/boot.php +++ b/boot.php @@ -36,7 +36,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_CODENAME', 'Asparagus'); define ( 'FRIENDICA_VERSION', '3.5-dev' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1193 ); +define ( 'DB_UPDATE_VERSION', 1194 ); /** * @brief Constant with a HTML line break. diff --git a/update.php b/update.php index a825c82e92..0689aa19b3 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@