]> git.mxchange.org Git - friendica.git/blobdiff - include/Photo.php
Changed documentation
[friendica.git] / include / Photo.php
index 73419357678418bf70547d8f6b709c54d97446d1..5920f80b38e779389d60188152e6972c03de7d2b 100644 (file)
@@ -778,8 +778,7 @@ function guess_image_type($filename, $fromcurl=false) {
  * @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));
+       $r = q("SELECT `avatar`, `photo`, `thumb`, `micro`, `nurl` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
        if (!dbm::is_result($r)) {
                return false;
        } else {
@@ -793,6 +792,15 @@ function update_contact_avatar($avatar, $uid, $cid, $force = false) {
                        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));
+
+                       // Update the public contact (contact id = 0)
+                       if ($uid != 0) {
+                               $pcontact = dba::select('contact', array('id'), array('nurl' => $r[0]['nurl']), array('limit' => 1));
+                               if (dbm::is_result($pcontact)) {
+                                       update_contact_avatar($avatar, 0, $pcontact['id'], $force);
+                               }
+                       }
+
                        return $photos;
                }
        }
@@ -847,9 +855,30 @@ function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) {
                        $photo_failure = true;
                }
 
-               $photo = App::get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt();
-               $thumb = App::get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt();
-               $micro = App::get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt();
+               $suffix = '?ts='.time();
+
+               $photo = App::get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt() . $suffix;
+               $thumb = App::get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt() . $suffix;
+               $micro = App::get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt() . $suffix;
+
+               // Remove the cached photo
+               $a = get_app();
+               $basepath = $a->get_basepath();
+
+               if (is_dir($basepath."/photo")) {
+                       $filename = $basepath.'/photo/'.$hash.'-4.'.$img->getExt();
+                       if (file_exists($filename)) {
+                               unlink($filename);
+                       }
+                       $filename = $basepath.'/photo/'.$hash.'-5.'.$img->getExt();
+                       if (file_exists($filename)) {
+                               unlink($filename);
+                       }
+                       $filename = $basepath.'/photo/'.$hash.'-6.'.$img->getExt();
+                       if (file_exists($filename)) {
+                               unlink($filename);
+                       }
+               }
        } else {
                $photo_failure = true;
        }