X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2FPhoto.php;h=5c3a52ffd5a0ef91ddfe17257bc0d49f781c93e7;hb=0cd9db9cb7f4c96f597e37590a536eaae123238d;hp=828dce82d7a33088c4bae02e1c350104a6e58114;hpb=12dd06f72677321006e8327636f517a2cb13fc13;p=friendica.git diff --git a/include/Photo.php b/include/Photo.php index 828dce82d7..5c3a52ffd5 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -4,6 +4,8 @@ * @brief This file contains the Photo class for image processing */ +use Friendica\App; + require_once("include/photos.php"); class Photo { @@ -68,7 +70,9 @@ class Photo { $this->image->destroy(); return; } - imagedestroy($this->image); + if (is_resource($this->image)) { + imagedestroy($this->image); + } } } @@ -324,6 +328,7 @@ class Photo { return; } + // if script dies at this point check memory_limit setting in php.ini $this->image = imagerotate($this->image,$degrees,0); $this->width = imagesx($this->image); $this->height = imagesy($this->image); @@ -620,7 +625,7 @@ class Photo { - public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') { + public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '') { $r = q("SELECT `guid` FROM `photo` WHERE `resource-id` = '%s' AND `guid` != '' LIMIT 1", dbesc($rid) @@ -657,7 +662,8 @@ class Photo { `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', - `deny_gid` = '%s' + `deny_gid` = '%s', + `desc` = '%s' WHERE `id` = %d", intval($uid), @@ -679,12 +685,13 @@ class Photo { dbesc($allow_gid), dbesc($deny_cid), dbesc($deny_gid), + dbesc($desc), intval($x[0]['id']) ); } else { $r = q("INSERT INTO `photo` - (`uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `datasize`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`) - VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s')", + (`uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `datasize`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `desc`) + VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s')", intval($uid), intval($cid), dbesc($guid), @@ -703,7 +710,8 @@ class Photo { dbesc($allow_cid), dbesc($allow_gid), dbesc($deny_cid), - dbesc($deny_gid) + dbesc($deny_gid), + dbesc($desc) ); } @@ -770,21 +778,29 @@ 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 { $data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]); } - if (($r[0]["avatar"] != $avatar) OR $force) { + if (($r[0]["avatar"] != $avatar) || $force) { $photos = import_profile_photo($avatar, $uid, $cid, true); if ($photos) { 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; } } @@ -809,7 +825,7 @@ function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) { $filename = basename($photo); $img_str = fetch_url($photo, true); - if ($quit_on_error AND ($img_str == "")) { + if ($quit_on_error && ($img_str == "")) { return false; } @@ -839,14 +855,35 @@ 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; } - if ($photo_failure AND $quit_on_error) { + if ($photo_failure && $quit_on_error) { return false; } @@ -865,7 +902,7 @@ function get_photo_info($url) { $data = Cache::get($url); - if (is_null($data) OR !$data OR !is_array($data)) { + if (is_null($data) || !$data || !is_array($data)) { $img_str = fetch_url($url, true, $redirects, 4); $filesize = strlen($img_str); @@ -959,7 +996,7 @@ function store_photo(App $a, $uid, $imagedata = "", $url = "") { /// $default_cid = $r[0]['id']; /// $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false); - if ((strlen($imagedata) == 0) AND ($url == "")) { + if ((strlen($imagedata) == 0) && ($url == "")) { logger("No image data and no url provided", LOGGER_DEBUG); return(array()); } elseif (strlen($imagedata) == 0) { @@ -1065,7 +1102,7 @@ function store_photo(App $a, $uid, $imagedata = "", $url = "") { } } - if ($width > 160 AND $height > 160) { + if ($width > 160 && $height > 160) { $x = 0; $y = 0;