* @param string $avatar Link to avatar picture
* @param int $uid User id of contact owner
* @param int $cid Contact id
+ * @param bool $force force picture update
*
* @return array Returns array of the different avatar sizes
*/
-function update_contact_avatar($avatar,$uid,$cid) {
+function update_contact_avatar($avatar,$uid,$cid, $force = false) {
$r = q("SELECT `avatar`, `photo`, `thumb`, `micro` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
if (!$r)
else
$data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
- if ($r[0]["avatar"] != $avatar) {
+ if (($r[0]["avatar"] != $avatar) OR $force) {
$photos = import_profile_photo($avatar,$uid,$cid, true);
if ($photos) {
$data = Cache::get($url);
- if (is_null($data)) {
- $img_str = fetch_url($url, true, $redirects, 4);
+ // Unserialise to be able to check in the next step if the cached data is alright.
+ if (!is_null($data))
+ $data = unserialize($data);
+ if (is_null($data) OR !$data) {
+ $img_str = fetch_url($url, true, $redirects, 4);
$filesize = strlen($img_str);
if (function_exists("getimagesizefromstring"))
$data["size"] = $filesize;
Cache::set($url, serialize($data));
- } else
- $data = unserialize($data);
+ }
return $data;
}