]> git.mxchange.org Git - friendica.git/blobdiff - include/Photo.php
Small text correction
[friendica.git] / include / Photo.php
index e0cb23008ab31abb4bc50d383133a66a1faaa34c..d87bce478704fccb6489097269e2e83163a4fd5f 100644 (file)
@@ -720,7 +720,17 @@ function guess_image_type($filename, $fromcurl=false) {
 
 }
 
-function update_contact_avatar($avatar,$uid,$cid) {
+/**
+ * @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
+ * @param bool $force force picture update
+ *
+ * @return array Returns array of the different avatar sizes
+ */
+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)
@@ -728,7 +738,7 @@ function update_contact_avatar($avatar,$uid,$cid) {
        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) {
@@ -813,9 +823,12 @@ function get_photo_info($url) {
 
        $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"))
@@ -836,8 +849,7 @@ function get_photo_info($url) {
                        $data["size"] = $filesize;
 
                Cache::set($url, serialize($data));
-       } else
-               $data = unserialize($data);
+       }
 
        return $data;
 }