Use a constant for the profile photo album
This commit is contained in:
+1
-19
@@ -45,6 +45,7 @@ use Friendica\Util\Strings;
|
||||
class Photo
|
||||
{
|
||||
const CONTACT_PHOTOS = 'Contact Photos';
|
||||
const PROFILE_PHOTOS = 'Profile Photos';
|
||||
|
||||
const DEFAULT = 0;
|
||||
const USER_AVATAR = 10;
|
||||
@@ -563,25 +564,6 @@ class Photo
|
||||
$image_url = DI::baseUrl() . "/photo/" . $resource_id . "-4." . $Image->getExt() . $suffix;
|
||||
$thumb = DI::baseUrl() . "/photo/" . $resource_id . "-5." . $Image->getExt() . $suffix;
|
||||
$micro = DI::baseUrl() . "/photo/" . $resource_id . "-6." . $Image->getExt() . $suffix;
|
||||
|
||||
// Remove the cached photo
|
||||
$a = DI::app();
|
||||
$basepath = $a->getBasePath();
|
||||
|
||||
if (is_dir($basepath . "/photo")) {
|
||||
$filename = $basepath . "/photo/" . $resource_id . "-4." . $Image->getExt();
|
||||
if (file_exists($filename)) {
|
||||
unlink($filename);
|
||||
}
|
||||
$filename = $basepath . "/photo/" . $resource_id . "-5." . $Image->getExt();
|
||||
if (file_exists($filename)) {
|
||||
unlink($filename);
|
||||
}
|
||||
$filename = $basepath . "/photo/" . $resource_id . "-6." . $Image->getExt();
|
||||
if (file_exists($filename)) {
|
||||
unlink($filename);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$photo_failure = true;
|
||||
}
|
||||
|
||||
+3
-3
@@ -1161,7 +1161,7 @@ class User
|
||||
|
||||
$resource_id = Photo::newResource();
|
||||
|
||||
$r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 4);
|
||||
$r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 4);
|
||||
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
@@ -1169,7 +1169,7 @@ class User
|
||||
|
||||
$Image->scaleDown(80);
|
||||
|
||||
$r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 5);
|
||||
$r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 5);
|
||||
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
@@ -1177,7 +1177,7 @@ class User
|
||||
|
||||
$Image->scaleDown(48);
|
||||
|
||||
$r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 6);
|
||||
$r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 6);
|
||||
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
|
||||
@@ -98,7 +98,7 @@ class Crop extends BaseSettings
|
||||
0,
|
||||
$resource_id,
|
||||
$base_image['filename'],
|
||||
DI::l10n()->t('Profile Photos'),
|
||||
DI::l10n()->t(Photo::PROFILE_PHOTOS),
|
||||
4,
|
||||
Photo::USER_AVATAR
|
||||
);
|
||||
@@ -114,7 +114,7 @@ class Crop extends BaseSettings
|
||||
0,
|
||||
$resource_id,
|
||||
$base_image['filename'],
|
||||
DI::l10n()->t('Profile Photos'),
|
||||
DI::l10n()->t(Photo::PROFILE_PHOTOS),
|
||||
5,
|
||||
Photo::USER_AVATAR
|
||||
);
|
||||
@@ -130,7 +130,7 @@ class Crop extends BaseSettings
|
||||
0,
|
||||
$resource_id,
|
||||
$base_image['filename'],
|
||||
DI::l10n()->t('Profile Photos'),
|
||||
DI::l10n()->t(Photo::PROFILE_PHOTOS),
|
||||
6,
|
||||
Photo::USER_AVATAR
|
||||
);
|
||||
@@ -176,7 +176,7 @@ class Crop extends BaseSettings
|
||||
|
||||
// set an already uloaded photo as profile photo
|
||||
// if photo is in 'Profile Photos', change it in db
|
||||
if ($photos[0]['album'] == DI::l10n()->t('Profile Photos') && $havescale) {
|
||||
if ($photos[0]['album'] == DI::l10n()->t(Photo::PROFILE_PHOTOS) && $havescale) {
|
||||
Photo::update(['profile' => false], ['uid' => local_user()]);
|
||||
|
||||
Photo::update(['profile' => true], ['resource-id' => $resource_id, 'uid' => local_user()]);
|
||||
|
||||
@@ -92,13 +92,13 @@ class Index extends BaseSettings
|
||||
|
||||
$filename = '';
|
||||
|
||||
if (!Photo::store($Image, local_user(), 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 0)) {
|
||||
if (!Photo::store($Image, local_user(), 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 0)) {
|
||||
notice(DI::l10n()->t('Image upload failed.'));
|
||||
}
|
||||
|
||||
if ($width > 640 || $height > 640) {
|
||||
$Image->scaleDown(640);
|
||||
if (!Photo::store($Image, local_user(), 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 1)) {
|
||||
if (!Photo::store($Image, local_user(), 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 1)) {
|
||||
notice(DI::l10n()->t('Image size reduction [%s] failed.', '640'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -637,24 +637,6 @@ class Image
|
||||
$this->height = imagesy($this->image);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path file path
|
||||
* @return mixed
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function saveToFilePath($path)
|
||||
{
|
||||
if (!$this->isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$string = $this->asString();
|
||||
|
||||
DI::profiler()->stopRecording('file');
|
||||
file_put_contents($path, $string);
|
||||
DI::profiler()->stopRecording();
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method allowing string casting of an Image object
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user