From 6e46987515fc36210e58c080cc4c4348a935b2f5 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 20 Dec 2016 07:10:47 +0000 Subject: [PATCH 1/3] The object type "photo" is deprecated and was replaced by "image" --- include/diaspora.php | 2 +- include/like.php | 2 +- mod/photos.php | 4 ++-- mod/subthread.php | 2 +- mod/tagger.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index f2d484867..09dff5cfa 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2290,7 +2290,7 @@ class diaspora { $body = "[img]".unxmlify($photo->remote_photo_path). unxmlify($photo->remote_photo_name)."[/img]\n".$body; - $datarray["object-type"] = ACTIVITY_OBJ_PHOTO; + $datarray["object-type"] = ACTIVITY_OBJ_IMAGE; } else { $datarray["object-type"] = ACTIVITY_OBJ_NOTE; diff --git a/include/like.php b/include/like.php index 118ec81ca..e5c1867b4 100644 --- a/include/like.php +++ b/include/like.php @@ -163,7 +163,7 @@ function do_like($item_id, $verb) { $post_type = (($item['resource-id']) ? t('photo') : t('status')); if($item['object-type'] === ACTIVITY_OBJ_EVENT) $post_type = t('event'); - $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); + $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ); $link = xmlify('' . "\n") ; $body = $item['body']; diff --git a/mod/photos.php b/mod/photos.php index d72a82482..6d3ab2846 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -681,7 +681,7 @@ function photos_post(&$a) { $arr['visible'] = 1; $arr['verb'] = ACTIVITY_TAG; $arr['object-type'] = ACTIVITY_OBJ_PERSON; - $arr['target-type'] = ACTIVITY_OBJ_PHOTO; + $arr['target-type'] = ACTIVITY_OBJ_IMAGE; $arr['tag'] = $tagged[4]; $arr['inform'] = $tagged[2]; $arr['origin'] = 1; @@ -694,7 +694,7 @@ function photos_post(&$a) { $arr['object'] .= xmlify('' . "\n"); $arr['object'] .= '' . "\n"; - $arr['target'] = '' . ACTIVITY_OBJ_PHOTO . '' . $p[0]['desc'] . '' + $arr['target'] = '' . ACTIVITY_OBJ_IMAGE . '' . $p[0]['desc'] . '' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ''; $arr['target'] .= '' . xmlify('' . "\n" . '') . ''; diff --git a/mod/subthread.php b/mod/subthread.php index 33cf7489c..d98390362 100644 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -85,7 +85,7 @@ function subthread_content(&$a) { $uri = item_new_uri($a->get_hostname(),$owner_uid); $post_type = (($item['resource-id']) ? t('photo') : t('status')); - $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); + $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ); $link = xmlify('' . "\n") ; $body = $item['body']; diff --git a/mod/tagger.php b/mod/tagger.php index e0ef1ceb0..57f53d5dc 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -60,7 +60,7 @@ function tagger_content(&$a) { $uri = item_new_uri($a->get_hostname(),$owner_uid); $xterm = xmlify($term); $post_type = (($item['resource-id']) ? t('photo') : t('status')); - $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); + $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE ); $link = xmlify('' . "\n") ; From 4c77ae2fe903bf15d6a41fb3ff802036c08a82c7 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 20 Dec 2016 07:13:22 +0000 Subject: [PATCH 2/3] Only distribute items to active contacts --- include/notifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/notifier.php b/include/notifier.php index 812752a55..58240557b 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -575,7 +575,7 @@ function notifier_run(&$argv, &$argc){ $r0 = array(); $r1 = q("SELECT DISTINCT(`batch`), `id`, `name`,`network` FROM `contact` WHERE `network` = '%s' - AND `uid` = %d AND `rel` != %d group by `batch` ORDER BY rand() ", + AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch` ORDER BY rand()", dbesc(NETWORK_DIASPORA), intval($owner['uid']), intval(CONTACT_IS_SHARING) From 51716957b24d97c20f078d1f880a6ca112cae792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Dec 2016 15:37:27 +0100 Subject: [PATCH 3/3] converted more to dbm::is_result() + added braces/space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/dfrn.php | 2 +- include/items.php | 18 +++++++++++------- include/queue.php | 4 ++-- include/user.php | 13 ++++++++----- mod/common.php | 3 ++- mod/dfrn_confirm.php | 15 +++++++++------ mod/dfrn_poll.php | 4 ++-- mod/editpost.php | 2 +- mod/item.php | 3 ++- mod/photos.php | 2 +- mod/poco.php | 3 ++- mod/profile_photo.php | 31 +++++++++++++++++++------------ mod/videos.php | 2 +- 13 files changed, 61 insertions(+), 41 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 689c5c283..90ff1dfbb 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -2355,7 +2355,7 @@ class dfrn { dbesc($xt->id), intval($importer["importer_uid"]) ); - if(count($i)) { + if (dbm::is_result($i)) { // For tags, the owner cannot remove the tag on the author's copy of the post. diff --git a/include/items.php b/include/items.php index 20aa2e2e0..c75bc768c 100644 --- a/include/items.php +++ b/include/items.php @@ -704,7 +704,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa // If its a post from myself then tag the thread as "mention" logger("item_store: Checking if parent ".$parent_id." has to be tagged as mention for user ".$arr['uid'], LOGGER_DEBUG); $u = q("SELECT `nickname` FROM `user` WHERE `uid` = %d", intval($arr['uid'])); - if (count($u)) { + if (dbm::is_result($u)) { $a = get_app(); $self = normalise_link(App::get_baseurl() . '/profile/' . $u[0]['nickname']); logger("item_store: 'myself' is ".$self." for parent ".$parent_id." checking against ".$arr['author-link']." and ".$arr['owner-link'], LOGGER_DEBUG); @@ -1188,19 +1188,22 @@ function tag_deliver($uid,$item_id) { $u = q("select * from user where uid = %d limit 1", intval($uid) ); - if (! count($u)) + + if (! dbm::is_result($u)) { return; + } $community_page = (($u[0]['page-flags'] == PAGE_COMMUNITY) ? true : false); $prvgroup = (($u[0]['page-flags'] == PAGE_PRVGROUP) ? true : false); - $i = q("select * from item where id = %d and uid = %d limit 1", + $i = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item_id), intval($uid) ); - if (! count($i)) + if (! dbm::is_result($i)) { return; + } $item = $i[0]; @@ -1298,12 +1301,13 @@ function tgroup_check($uid,$item) { if (($item['wall']) || ($item['origin']) || ($item['uri'] != $item['parent-uri'])) return false; - - $u = q("select * from user where uid = %d limit 1", + /// @TODO Encapsulate this or find it encapsulated and replace all occurrances + $u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid) ); - if (! count($u)) + if (! dbm::is_result($u)) { return false; + } $community_page = (($u[0]['page-flags'] == PAGE_COMMUNITY) ? true : false); $prvgroup = (($u[0]['page-flags'] == PAGE_PRVGROUP) ? true : false); diff --git a/include/queue.php b/include/queue.php index ad7079e95..1cc2ee095 100644 --- a/include/queue.php +++ b/include/queue.php @@ -126,7 +126,7 @@ function queue_run(&$argv, &$argc){ $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($qi[0]['cid']) ); - if(! count($c)) { + if (! dbm::is_result($c)) { remove_queue_item($q_item['id']); continue; } @@ -156,7 +156,7 @@ function queue_run(&$argv, &$argc){ FROM `user` WHERE `uid` = %d LIMIT 1", intval($c[0]['uid']) ); - if(! count($u)) { + if (! dbm::is_result($u)) { remove_queue_item($q_item['id']); continue; } diff --git a/include/user.php b/include/user.php index ae05b9e11..d6970d475 100644 --- a/include/user.php +++ b/include/user.php @@ -262,7 +262,7 @@ function create_user($arr) { intval($netpublish) ); - if($r === false) { + if ($r === false) { $result['message'] .= t('An error occurred creating your default profile. Please try again.') . EOL; // Start fresh next time. $r = q("DELETE FROM `user` WHERE `uid` = %d", @@ -325,24 +325,27 @@ function create_user($arr) { $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4 ); - if($r === false) + if ($r === false) { $photo_failure = true; + } $img->scaleImage(80); $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5 ); - if($r === false) + if ($r === false) { $photo_failure = true; + } $img->scaleImage(48); $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6 ); - if($r === false) + if ($r === false) { $photo_failure = true; + } - if(! $photo_failure) { + if (! $photo_failure) { q("UPDATE `photo` SET `profile` = 1 WHERE `resource-id` = '%s' ", dbesc($hash) ); diff --git a/mod/common.php b/mod/common.php index e0cd65506..f3601c0fe 100644 --- a/mod/common.php +++ b/mod/common.php @@ -48,8 +48,9 @@ function common_content(App &$a) { $a->page['aside'] .= $vcard_widget; } - if(! count($c)) + if (! dbm::is_result($c)) { return; + } if(! $cid) { if(get_my_url()) { diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 6d97899af..ba8e27431 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -415,23 +415,26 @@ function dfrn_confirm_post(&$a,$handsfree = null) { ); } - if($r === false) - notice( t('Unable to set contact photo.') . EOL); + /// @TODO is dbm::is_result() working here? + if ($r === false) { + notice( t('Unable to set contact photo.') . EOL); + } // reload contact info $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($contact_id) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $contact = $r[0]; - else + } else { $contact = null; + } - if((isset($new_relation) && $new_relation == CONTACT_IS_FRIEND)) { + if ((isset($new_relation) && $new_relation == CONTACT_IS_FRIEND)) { - if(($contact) && ($contact['network'] === NETWORK_DIASPORA)) { + if (($contact) && ($contact['network'] === NETWORK_DIASPORA)) { require_once('include/diaspora.php'); $ret = diaspora::send_share($user[0],$r[0]); logger('share returns: ' . $ret); diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index f74429e58..a31a50ad2 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -137,7 +137,7 @@ function dfrn_poll_init(App &$a) { $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($r[0]['cid']) ); - if(! count($c)) { + if (! dbm::is_result($c)) { xml_status(3, 'No profile'); } $contact = $c[0]; @@ -234,7 +234,7 @@ function dfrn_poll_post(App &$a) { $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($r[0]['cid']) ); - if(! count($c)) { + if (! dbm::is_result($c)) { xml_status(3, 'No profile'); } $contact = $c[0]; diff --git a/mod/editpost.php b/mod/editpost.php index 1bf150a5d..a655801d7 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -23,7 +23,7 @@ function editpost_content(App &$a) { intval(local_user()) ); - if (! count($itm)) { + if (! dbm::is_result($itm)) { notice( t('Item not found') . EOL); return; } diff --git a/mod/item.php b/mod/item.php index a11845e55..864aa18e5 100644 --- a/mod/item.php +++ b/mod/item.php @@ -224,8 +224,9 @@ function item_post(App &$a) { intval($profile_uid), intval($post_id) ); - if(! count($i)) + if (! dbm::is_result($i)) { killme(); + } $orig_post = $i[0]; } diff --git a/mod/photos.php b/mod/photos.php index 94ddb91dd..8d97a3005 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -346,7 +346,7 @@ function photos_post(App &$a) { dbesc($r[0]['resource-id']), intval($page_owner_uid) ); - if (count($i)) { + if (dbm::is_result($i)) { q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d", dbesc(datetime_convert()), dbesc(datetime_convert()), diff --git a/mod/poco.php b/mod/poco.php index 787776b90..11f984757 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -16,8 +16,9 @@ function poco_init(App &$a) { } if(! x($user)) { $c = q("SELECT * FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1"); - if(! count($c)) + if (! dbm::is_result($c)) { http_status_exit(401); + } $system_mode = true; } diff --git a/mod/profile_photo.php b/mod/profile_photo.php index 356c507f7..0b6dd8d13 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -73,22 +73,25 @@ function profile_photo_post(App &$a) { $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 4, $is_default_profile); - if($r === false) + if ($r === false) { notice ( sprintf(t('Image size reduction [%s] failed.'),"175") . EOL ); + } $im->scaleImage(80); $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 5, $is_default_profile); - if($r === false) + if ($r === false) { notice( sprintf(t('Image size reduction [%s] failed.'),"80") . EOL ); + } $im->scaleImage(48); $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 6, $is_default_profile); - if($r === false) + if ($r === false) { notice( sprintf(t('Image size reduction [%s] failed.'),"48") . EOL ); + } // If setting for the default profile, unset the profile photo flag from any other photos I own @@ -282,15 +285,17 @@ function profile_photo_content(App &$a) { if(! function_exists('profile_photo_crop_ui_head')) { function profile_photo_crop_ui_head(&$a, $ph){ $max_length = get_config('system','max_image_length'); - if(! $max_length) + if (! $max_length) { $max_length = MAX_IMAGE_LENGTH; - if($max_length > 0) + } + if ($max_length > 0) { $ph->scaleImage($max_length); + } $width = $ph->getWidth(); $height = $ph->getHeight(); - if($width < 175 || $height < 175) { + if ($width < 175 || $height < 175) { $ph->scaleImageUp(200); $width = $ph->getWidth(); $height = $ph->getHeight(); @@ -303,19 +308,21 @@ function profile_photo_crop_ui_head(&$a, $ph){ $r = $ph->store(local_user(), 0 , $hash, $filename, t('Profile Photos'), 0 ); - if($r) + if ($r) { info( t('Image uploaded successfully.') . EOL ); - else + } else { notice( t('Image upload failed.') . EOL ); + } - if($width > 640 || $height > 640) { + if ($width > 640 || $height > 640) { $ph->scaleImage(640); $r = $ph->store(local_user(), 0 , $hash, $filename, t('Profile Photos'), 1 ); - - if($r === false) + + if ($r === false) { notice( sprintf(t('Image size reduction [%s] failed.'),"640") . EOL ); - else + } else { $smallest = 1; + } } $a->config['imagecrop'] = $hash; diff --git a/mod/videos.php b/mod/videos.php index 52176524a..58c4b6c65 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -154,7 +154,7 @@ function videos_post(App &$a) { intval(local_user()) ); //echo "
"; var_dump($i); killme();
-			if(count($i)) {
+			if (dbm::is_result($i)) {
 				q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
 					dbesc(datetime_convert()),
 					dbesc(datetime_convert()),