use Friendica\Database\DBStructure;
use Friendica\Model\Storage\IStorage;
use Friendica\Object\Image;
-use Friendica\Protocol\DFRN;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Images;
use Friendica\Util\Network;
use Friendica\Util\Security;
use Friendica\Util\Strings;
*/
public static function getPhoto($resourceid, $scale = 0)
{
- $r = self::selectFirst(["uid", "allow_cid", "allow_gid", "deny_cid", "deny_gid"], ["resource-id" => $resourceid]);
- if ($r === false) {
+ $r = self::selectFirst(["uid"], ["resource-id" => $resourceid]);
+ if (!DBA::isResult($r)) {
return false;
}
- $uid = $r["uid"];
- // This is the first place, when retrieving just a photo, that we know who owns the photo.
- // Check if the photo is public (empty allow and deny means public), if so, skip auth attempt, if not
- // make sure that the requester's session is appropriately authenticated to that user
- // otherwise permissions checks done by getPermissionsSQLByUserId() won't work correctly
- if (!empty($r["allow_cid"]) || !empty($r["allow_gid"]) || !empty($r["deny_cid"]) || !empty($r["deny_gid"])) {
- $r = DBA::selectFirst("user", ["nickname"], ["uid" => $uid], []);
- // this will either just return (if auth all ok) or will redirect and exit (starting over)
- DFRN::autoRedir(self::getApp(), $r["nickname"]);
- }
+ $uid = $r["uid"];
$sql_acl = Security::getPermissionsSQLByUserId($uid);
- $conditions = [
- "`resource-id` = ? AND `scale` <= ? " . $sql_acl,
- $resourceid, $scale
- ];
-
+ $conditions = ["`resource-id` = ? AND `scale` <= ? " . $sql_acl, $resourceid, $scale];
$params = ["order" => ["scale" => true]];
-
$photo = self::selectFirst([], $conditions, $params);
return $photo;
"photo", ["resource-id"], ["uid" => $uid, "contact-id" => $cid, "scale" => 4, "album" => "Contact Photos"]
);
if (!empty($photo['resource-id'])) {
- $hash = $photo["resource-id"];
+ $resource_id = $photo["resource-id"];
} else {
- $hash = self::newResource();
+ $resource_id = self::newResource();
}
$photo_failure = false;
}
if (empty($type)) {
- $type = Image::guessType($image_url, true);
+ $type = Images::guessType($image_url, true);
}
$Image = new Image($img_str, $type);
if ($Image->isValid()) {
$Image->scaleToSquare(300);
- $r = self::store($Image, $uid, $cid, $hash, $filename, "Contact Photos", 4);
+ $r = self::store($Image, $uid, $cid, $resource_id, $filename, "Contact Photos", 4);
if ($r === false) {
$photo_failure = true;
$Image->scaleDown(80);
- $r = self::store($Image, $uid, $cid, $hash, $filename, "Contact Photos", 5);
+ $r = self::store($Image, $uid, $cid, $resource_id, $filename, "Contact Photos", 5);
if ($r === false) {
$photo_failure = true;
$Image->scaleDown(48);
- $r = self::store($Image, $uid, $cid, $hash, $filename, "Contact Photos", 6);
+ $r = self::store($Image, $uid, $cid, $resource_id, $filename, "Contact Photos", 6);
if ($r === false) {
$photo_failure = true;
$suffix = "?ts=" . time();
- $image_url = System::baseUrl() . "/photo/" . $hash . "-4." . $Image->getExt() . $suffix;
- $thumb = System::baseUrl() . "/photo/" . $hash . "-5." . $Image->getExt() . $suffix;
- $micro = System::baseUrl() . "/photo/" . $hash . "-6." . $Image->getExt() . $suffix;
+ $image_url = System::baseUrl() . "/photo/" . $resource_id . "-4." . $Image->getExt() . $suffix;
+ $thumb = System::baseUrl() . "/photo/" . $resource_id . "-5." . $Image->getExt() . $suffix;
+ $micro = System::baseUrl() . "/photo/" . $resource_id . "-6." . $Image->getExt() . $suffix;
// Remove the cached photo
$a = \get_app();
$basepath = $a->getBasePath();
if (is_dir($basepath . "/photo")) {
- $filename = $basepath . "/photo/" . $hash . "-4." . $Image->getExt();
+ $filename = $basepath . "/photo/" . $resource_id . "-4." . $Image->getExt();
if (file_exists($filename)) {
unlink($filename);
}
- $filename = $basepath . "/photo/" . $hash . "-5." . $Image->getExt();
+ $filename = $basepath . "/photo/" . $resource_id . "-5." . $Image->getExt();
if (file_exists($filename)) {
unlink($filename);
}
- $filename = $basepath . "/photo/" . $hash . "-6." . $Image->getExt();
+ $filename = $basepath . "/photo/" . $resource_id . "-6." . $Image->getExt();
if (file_exists($filename)) {
unlink($filename);
}
public static function stripExtension($name)
{
$name = str_replace([".jpg", ".png", ".gif"], ["", "", ""], $name);
- foreach (Image::supportedTypes() as $m => $e) {
+ foreach (Images::supportedTypes() as $m => $e) {
$name = str_replace("." . $e, "", $name);
}
return $name;
}
$scale = intval(substr($guid, -1, 1));
- if (empty($scale)) {
+ if (!is_numeric($scale)) {
return '';
}
return DBA::exists('photo', ['resource-id' => $guid]);
}
+
+ /**
+ * Tests if the link points to a locally stored picture page
+ *
+ * @param string $name Page link
+ * @return boolean
+ * @throws \Exception
+ */
+ public static function isLocalPage($name)
+ {
+ $a = \get_app();
+ $base = $a->getBaseURL();
+
+ $guid = str_replace(Strings::normaliseLink($base), '', Strings::normaliseLink($name));
+ $guid = preg_replace("=/photos/.*/image/(.*)=ism", '$1', $guid);
+ if (empty($guid)) {
+ return false;
+ }
+
+ return DBA::exists('photo', ['resource-id' => $guid]);
+ }
}