X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FPhoto.php;h=555df80e63df689fea8f056f22586783857f0574;hb=2a7327a41c3ea9b9910c9426956c93761bf56121;hp=fc6e60a9cef4d61a5b8167bf41c2c2a9e36a91cb;hpb=d53e53cceb2823cceec36f91f39f8b1e6459a648;p=friendica.git diff --git a/src/Model/Photo.php b/src/Model/Photo.php index fc6e60a9ce..555df80e63 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -1,4 +1,5 @@ $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale]); + $existing_photo = DBA::selectFirst('photo', ['id'], ['resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale]); $fields = [ 'uid' => $uid, 'contact-id' => $cid, 'guid' => $guid, 'resource-id' => $rid, - 'created' => datetime_convert(), - 'edited' => datetime_convert(), + 'created' => DateTimeFormat::utcNow(), + 'edited' => DateTimeFormat::utcNow(), 'filename' => basename($filename), 'type' => $Image->getType(), 'album' => $album, @@ -72,10 +72,10 @@ class Photo 'desc' => $desc ]; - if (DBM::is_result($existing_photo)) { - $r = dba::update('photo', $fields, ['id' => $existing_photo['id']]); + if (DBA::isResult($existing_photo)) { + $r = DBA::update('photo', $fields, ['id' => $existing_photo['id']]); } else { - $r = dba::insert('photo', $fields); + $r = DBA::insert('photo', $fields); } return $r; @@ -90,13 +90,16 @@ class Photo */ public static function importProfilePhoto($image_url, $uid, $cid, $quit_on_error = false) { - $photo = dba::selectFirst( + $thumb = ''; + $micro = ''; + + $photo = DBA::selectFirst( 'photo', ['resource-id'], ['uid' => $uid, 'contact-id' => $cid, 'scale' => 4, 'album' => 'Contact Photos'] ); if (x($photo['resource-id'])) { $hash = $photo['resource-id']; } else { - $hash = photo_new_resource(); + $hash = self::newResource(); } $photo_failure = false; @@ -236,8 +239,8 @@ class Photo WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra GROUP BY `album` ORDER BY `created` DESC", intval($uid), - dbesc('Contact Photos'), - dbesc(L10n::t('Contact Photos')) + DBA::escape('Contact Photos'), + DBA::escape(L10n::t('Contact Photos')) ); } else { // This query doesn't do the count and is much faster @@ -245,8 +248,8 @@ class Photo FROM `photo` USE INDEX (`uid_album_scale_created`) WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra", intval($uid), - dbesc('Contact Photos'), - dbesc(L10n::t('Contact Photos')) + DBA::escape('Contact Photos'), + DBA::escape(L10n::t('Contact Photos')) ); } Cache::set($key, $albums, CACHE_DAY); @@ -263,4 +266,14 @@ class Photo $key = "photo_albums:".$uid.":".local_user().":".remote_user(); Cache::set($key, null, CACHE_DAY); } + + /** + * Generate a unique photo ID. + * + * @return string + */ + public static function newResource() + { + return system::createGUID(32, false); + } }