From 358ffaef24e961dc6afd61090e86be1921106ca2 Mon Sep 17 00:00:00 2001 From: "Zvi ben Yaakov (a.k.a rdc)" Date: Mon, 18 Jun 2012 21:12:13 +0300 Subject: Added get_cached_avatar_image to App class for shared profile image access and reduced sql queries/load --- boot.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/boot.php b/boot.php index 06f18b784..465bdf0c1 100644 --- a/boot.php +++ b/boot.php @@ -332,6 +332,9 @@ if(! class_exists('App')) { private $curl_code; private $curl_headers; + private $cached_profile_image; + private $cached_profile_picdate; + function __construct() { global $default_timezone; @@ -543,6 +546,28 @@ if(! class_exists('App')) { return $this->curl_headers; } + function get_cached_avatar_image($avatar_image){ + if($this->cached_profile_image[$avatar_image]) + return $this->cached_profile_image[$avatar_image]; + + $path_parts = explode("/",$avatar_image); + $common_filename = $path_parts[count($path_parts)-1]; + + if($this->cached_profile_picdate[$common_filename]){ + $this->cached_profile_image[$avatar_image] = $avatar_image . $this->cached_profile_picdate[$common_filename]; + } else { + $r = q("SELECT `contact`.`avatar-date` AS picdate FROM `contact` WHERE `contact`.`thumb` like \"%%/%s\"", + $common_filename); + if(! count($r)){ + $this->cached_profile_image[$avatar_image] = $avatar_image; + } else { + $this->cached_profile_picdate[$common_filename] = "?rev=" . urlencode($r[0]['picdate']); + $this->cached_profile_image[$avatar_image] = $avatar_image . $this->cached_profile_picdate[$common_filename]; + } + } + return $this->cached_profile_image[$avatar_image]; + } + } } -- cgit v1.2.3 From 88e7fe67de734035ec35621dd0dc4b29807e8ed6 Mon Sep 17 00:00:00 2001 From: "Zvi ben Yaakov (a.k.a rdc)" Date: Mon, 18 Jun 2012 21:17:02 +0300 Subject: Beginning to use App::get_cached_avatar_image for loading profile images in conversations --- include/conversation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/conversation.php b/include/conversation.php index 1d5a92284..ee012232e 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -308,7 +308,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { if(($normalised != 'mailbox') && (x($a->contacts[$normalised]))) $profile_avatar = $a->contacts[$normalised]['thumb']; else - $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']); + $profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']); $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => ''); call_hooks('render_location',$locate); -- cgit v1.2.3 From 47650a0ee216463de43f7e837fcbbd5a5a0d8481 Mon Sep 17 00:00:00 2001 From: "Zvi ben Yaakov (a.k.a rdc)" Date: Mon, 18 Jun 2012 21:59:58 +0300 Subject: Now using App::get_cached_avatar_image for /directory page --- mod/directory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/directory.php b/mod/directory.php index 7f3a44ff4..930a575b6 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -73,7 +73,7 @@ function directory_content(&$a) { $order = " ORDER BY `name` ASC "; - $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `contact`.`avatar-date` AS picdate, `user`.`nickname`, `user`.`timezone` FROM `profile` LEFT join `contact` on `contact`.`uid` = `profile`.`uid` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `self` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ", + $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $sql_extra $order LIMIT %d , %d ", intval($a->pager['start']), intval($a->pager['itemspage']) ); @@ -116,7 +116,7 @@ function directory_content(&$a) { $entry = replace_macros($tpl,array( '$id' => $rr['id'], '$profile-link' => $profile_link, - '$photo' => $rr[$photo] . '?rev=' . urlencode($rr['picdate']), + '$photo' => $a->get_cached_avatar_image($rr[$photo]), '$alt-text' => $rr['name'], '$name' => $rr['name'], '$details' => $pdesc . $details -- cgit v1.2.3 From 428fce633feea10d0ba1b04be34a82fbc4448904 Mon Sep 17 00:00:00 2001 From: "Zvi ben Yaakov (a.k.a rdc)" Date: Mon, 18 Jun 2012 22:09:00 +0300 Subject: Now using App::get_cached_avatar_image for navigation bar --- include/nav.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nav.php b/include/nav.php index d760cc8ae..a67a8b614 100644 --- a/include/nav.php +++ b/include/nav.php @@ -53,9 +53,9 @@ function nav(&$a) { $nav['usermenu'][] = Array('notes/', t('Personal notes'), "", t('Your personal photos')); // user info - $r = q("SELECT `micro`,`avatar-date` FROM `contact` WHERE uid=%d AND self=1", intval($a->user['uid'])); + $r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid'])); $userinfo = array( - 'icon' => (count($r) ? $r[0]['micro']."?rev=".urlencode($r[0]['avatar-date']): $a->get_baseurl($ssl_state)."/images/person-48.jpg"), + 'icon' => (count($r) ? $a->get_cached_avatar_image($r[0]['micro']) : $a->get_baseurl($ssl_state)."/images/person-48.jpg"), 'name' => $a->user['username'], ); -- cgit v1.2.3 From 0c5476c6f27812e57ec515f330e3677080be29de Mon Sep 17 00:00:00 2001 From: "Zvi ben Yaakov (a.k.a rdc)" Date: Mon, 18 Jun 2012 22:18:43 +0300 Subject: Now using App::get_cached_avatar_image for /profile/{nickname} page --- mod/profiles.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/profiles.php b/mod/profiles.php index 7b6e61ad6..a9da5454c 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -635,7 +635,7 @@ function profiles_content(&$a) { } else { - $r = q("SELECT `profile`.*, `contact`.`avatar-date` AS picdate FROM `profile` LEFT JOIN `contact` on `contact`.`uid` = `profile`.`uid` WHERE `profile`.`uid` = %d and contact.self = 1", + $r = q("SELECT * FROM `profile` WHERE `uid` = %d", local_user()); if(count($r)) { @@ -652,7 +652,7 @@ function profiles_content(&$a) { foreach($r as $rr) { $o .= replace_macros($tpl, array( - '$photo' => $rr['thumb'] . '?rev=' . urlencode($rr['picdate']), + '$photo' => $a->get_cached_avatar_image($rr['thumb']), '$id' => $rr['id'], '$alt' => t('Profile Image'), '$profile_name' => $rr['profile-name'], -- cgit v1.2.3 From d1f81fff6b3d9528a2576ce4231479fddd01ba75 Mon Sep 17 00:00:00 2001 From: "Zvi ben Yaakov (a.k.a rdc)" Date: Mon, 18 Jun 2012 22:41:43 +0300 Subject: Now using App::get_cached_avatar_image for /photos page --- mod/photos.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index a6552994e..c6065f3ca 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -16,7 +16,7 @@ function photos_init(&$a) { if($a->argc > 1) { $nick = $a->argv[1]; - $r = q("SELECT `user`.*, `contact`.`avatar-date` AS picdate FROM `user` LEFT JOIN `contact` on `contact`.`uid` = `user`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 LIMIT 1", + $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1", dbesc($nick) ); @@ -36,7 +36,7 @@ function photos_init(&$a) { $o .= '
'; $o .= '
' . $a->data['user']['username'] . '
'; - $o .= '
' . $a->data['user']['username'] . '
'; + $o .= '
' . $a->data['user']['username'] . '
'; $o .= '
'; if(! intval($a->data['user']['hidewall'])) { -- cgit v1.2.3 From 45b4867bd31d54f76a366cdda68b5f90f2bca3b2 Mon Sep 17 00:00:00 2001 From: "Zvi ben Yaakov (a.k.a rdc)" Date: Tue, 19 Jun 2012 21:40:14 +0300 Subject: Added App::get_cached_avatar_image usage on conversation wall of Normal View --- include/conversation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/conversation.php b/include/conversation.php index ee012232e..2244e8df7 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -657,7 +657,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { if(($normalised != 'mailbox') && (x($a->contacts,$normalised))) $profile_avatar = $a->contacts[$normalised]['thumb']; else - $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $thumb); + $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb)); $like = ((x($alike,$item['id'])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : ''); $dislike = ((x($dlike,$item['id'])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : ''); -- cgit v1.2.3 From 5b057e5dee09e0cab5b78bb9b2ac2e27d59a11f7 Mon Sep 17 00:00:00 2001 From: "Zvi ben Yaakov (a.k.a rdc)" Date: Tue, 19 Jun 2012 22:24:31 +0300 Subject: Added App::get_cached_avater_image usage in profile_sidebar function for creating the $diaspora array that is used to populate diaspora_vcard.tpl. This allows the correct profile image revision to be used when dfrn_request friend requests are made. --- boot.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boot.php b/boot.php index 465bdf0c1..ecd95acec 100644 --- a/boot.php +++ b/boot.php @@ -1155,9 +1155,9 @@ if(! function_exists('profile_sidebar')) { 'fullname' => $profile['name'], 'firstname' => $firstname, 'lastname' => $lastname, - 'photo300' => $a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg', - 'photo100' => $a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg', - 'photo50' => $a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg', + 'photo300' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg'), + 'photo100' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg'), + 'photo50' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg'), ); if (!$block){ -- cgit v1.2.3 From 51ef8fb7ff77323382fa750827aa25f4652a1891 Mon Sep 17 00:00:00 2001 From: "Zvi ben Yaakov (a.k.a rdc)" Date: Mon, 25 Jun 2012 14:01:16 +0300 Subject: Added App::get_cached_avatar_image usage for displaying "Last users" avatar thumbs in right sidebar --- view/theme/diabook/theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/theme/diabook/theme.php b/view/theme/diabook/theme.php index 83079782e..53048df6c 100755 --- a/view/theme/diabook/theme.php +++ b/view/theme/diabook/theme.php @@ -528,7 +528,7 @@ if ($color=="dark") $color_path = "/diabook-dark/"; $entry = replace_macros($tpl,array( '$id' => $rr['id'], '$profile-link' => $profile_link, - '$photo' => $rr[$photo], + '$photo' => $a->get_cached_avatar_image($rr[$photo]), '$alt-text' => $rr['name'], )); $aside['$lastusers_items'][] = $entry; -- cgit v1.2.3