]> git.mxchange.org Git - friendica.git/blob - src/Model/Photo.php
Move L10n::getDay() calls to DI::l10n()->getDay() calls
[friendica.git] / src / Model / Photo.php
1 <?php
2
3 /**
4  * @file src/Model/Photo.php
5  * This file contains the Photo class for database interface
6  */
7 namespace Friendica\Model;
8
9 use Friendica\Core\Cache\Duration;
10 use Friendica\Core\Config;
11 use Friendica\Core\L10n;
12 use Friendica\Core\Logger;
13 use Friendica\Core\System;
14 use Friendica\Database\DBA;
15 use Friendica\Database\DBStructure;
16 use Friendica\DI;
17 use Friendica\Model\Storage\SystemResource;
18 use Friendica\Object\Image;
19 use Friendica\Util\DateTimeFormat;
20 use Friendica\Util\Images;
21 use Friendica\Util\Network;
22 use Friendica\Util\Security;
23 use Friendica\Util\Strings;
24
25 require_once "include/dba.php";
26
27 /**
28  * Class to handle photo dabatase table
29  */
30 class Photo
31 {
32         /**
33          * Select rows from the photo table and returns them as array
34          *
35          * @param array $fields     Array of selected fields, empty for all
36          * @param array $conditions Array of fields for conditions
37          * @param array $params     Array of several parameters
38          *
39          * @return boolean|array
40          *
41          * @throws \Exception
42          * @see   \Friendica\Database\DBA::selectToArray
43          */
44         public static function selectToArray(array $fields = [], array $conditions = [], array $params = [])
45         {
46                 if (empty($fields)) {
47                         $fields = self::getFields();
48                 }
49
50                 return DBA::selectToArray('photo', $fields, $conditions, $params);
51         }
52
53         /**
54          * Retrieve a single record from the photo table
55          *
56          * @param array $fields     Array of selected fields, empty for all
57          * @param array $conditions Array of fields for conditions
58          * @param array $params     Array of several parameters
59          *
60          * @return bool|array
61          *
62          * @throws \Exception
63          * @see   \Friendica\Database\DBA::select
64          */
65         public static function selectFirst(array $fields = [], array $conditions = [], array $params = [])
66         {
67                 if (empty($fields)) {
68                         $fields = self::getFields();
69                 }
70
71                 return DBA::selectFirst("photo", $fields, $conditions, $params);
72         }
73
74         /**
75          * Get photos for user id
76          *
77          * @param integer $uid        User id
78          * @param string  $resourceid Rescource ID of the photo
79          * @param array   $conditions Array of fields for conditions
80          * @param array   $params     Array of several parameters
81          *
82          * @return bool|array
83          *
84          * @throws \Exception
85          * @see   \Friendica\Database\DBA::select
86          */
87         public static function getPhotosForUser($uid, $resourceid, array $conditions = [], array $params = [])
88         {
89                 $conditions["resource-id"] = $resourceid;
90                 $conditions["uid"] = $uid;
91
92                 return self::selectToArray([], $conditions, $params);
93         }
94
95         /**
96          * Get a photo for user id
97          *
98          * @param integer $uid        User id
99          * @param string  $resourceid Rescource ID of the photo
100          * @param integer $scale      Scale of the photo. Defaults to 0
101          * @param array   $conditions Array of fields for conditions
102          * @param array   $params     Array of several parameters
103          *
104          * @return bool|array
105          *
106          * @throws \Exception
107          * @see   \Friendica\Database\DBA::select
108          */
109         public static function getPhotoForUser($uid, $resourceid, $scale = 0, array $conditions = [], array $params = [])
110         {
111                 $conditions["resource-id"] = $resourceid;
112                 $conditions["uid"] = $uid;
113                 $conditions["scale"] = $scale;
114
115                 return self::selectFirst([], $conditions, $params);
116         }
117
118         /**
119          * Get a single photo given resource id and scale
120          *
121          * This method checks for permissions. Returns associative array
122          * on success, "no sign" image info, if user has no permission,
123          * false if photo does not exists
124          *
125          * @param string  $resourceid Rescource ID of the photo
126          * @param integer $scale      Scale of the photo. Defaults to 0
127          *
128          * @return boolean|array
129          * @throws \Exception
130          */
131         public static function getPhoto($resourceid, $scale = 0)
132         {
133                 $r = self::selectFirst(["uid"], ["resource-id" => $resourceid]);
134                 if (!DBA::isResult($r)) {
135                         return false;
136                 }
137
138                 $uid = $r["uid"];
139
140                 $sql_acl = Security::getPermissionsSQLByUserId($uid);
141
142                 $conditions = ["`resource-id` = ? AND `scale` <= ? " . $sql_acl, $resourceid, $scale];
143                 $params = ["order" => ["scale" => true]];
144                 $photo = self::selectFirst([], $conditions, $params);
145
146                 return $photo;
147         }
148
149         /**
150          * Check if photo with given conditions exists
151          *
152          * @param array $conditions Array of extra conditions
153          *
154          * @return boolean
155          * @throws \Exception
156          */
157         public static function exists(array $conditions)
158         {
159                 return DBA::exists("photo", $conditions);
160         }
161
162
163         /**
164          * Get Image object for given row id. null if row id does not exist
165          *
166          * @param array $photo Photo data. Needs at least 'id', 'type', 'backend-class', 'backend-ref'
167          *
168          * @return \Friendica\Object\Image
169          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
170          * @throws \ImagickException
171          */
172         public static function getImageForPhoto(array $photo)
173         {
174                 $backendClass = DI::storageManager()->getByName($photo['backend-class'] ?? '');
175                 if ($backendClass === null) {
176                         // legacy data storage in "data" column
177                         $i = self::selectFirst(['data'], ['id' => $photo['id']]);
178                         if ($i === false) {
179                                 return null;
180                         }
181                         $data = $i['data'];
182                 } else {
183                         $backendRef = $photo['backend-ref'] ?? '';
184                         $data = $backendClass->get($backendRef);
185                 }
186
187                 if (empty($data)) {
188                         return null;
189                 }
190
191                 return new Image($data, $photo['type']);
192         }
193
194         /**
195          * Return a list of fields that are associated with the photo table
196          *
197          * @return array field list
198          * @throws \Exception
199          */
200         private static function getFields()
201         {
202                 $allfields = DBStructure::definition(DI::app()->getBasePath(), false);
203                 $fields = array_keys($allfields["photo"]["fields"]);
204                 array_splice($fields, array_search("data", $fields), 1);
205                 return $fields;
206         }
207
208         /**
209          * Construct a photo array for a system resource image
210          *
211          * @param string $filename Image file name relative to code root
212          * @param string $mimetype Image mime type. Defaults to "image/jpeg"
213          *
214          * @return array
215          * @throws \Exception
216          */
217         public static function createPhotoForSystemResource($filename, $mimetype = "image/jpeg")
218         {
219                 $fields = self::getFields();
220                 $values = array_fill(0, count($fields), "");
221
222                 $photo                  = array_combine($fields, $values);
223                 $photo['backend-class'] = SystemResource::NAME;
224                 $photo['backend-ref']   = $filename;
225                 $photo['type']          = $mimetype;
226                 $photo['cacheable']     = false;
227
228                 return $photo;
229         }
230
231
232         /**
233          * store photo metadata in db and binary in default backend
234          *
235          * @param Image   $Image     Image object with data
236          * @param integer $uid       User ID
237          * @param integer $cid       Contact ID
238          * @param integer $rid       Resource ID
239          * @param string  $filename  Filename
240          * @param string  $album     Album name
241          * @param integer $scale     Scale
242          * @param integer $profile   Is a profile image? optional, default = 0
243          * @param string  $allow_cid Permissions, allowed contacts. optional, default = ""
244          * @param string  $allow_gid Permissions, allowed groups. optional, default = ""
245          * @param string  $deny_cid  Permissions, denied contacts.optional, default = ""
246          * @param string  $deny_gid  Permissions, denied greoup.optional, default = ""
247          * @param string  $desc      Photo caption. optional, default = ""
248          *
249          * @return boolean True on success
250          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
251          */
252         public static function store(Image $Image, $uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = "", $allow_gid = "", $deny_cid = "", $deny_gid = "", $desc = "")
253         {
254                 $photo = self::selectFirst(["guid"], ["`resource-id` = ? AND `guid` != ?", $rid, ""]);
255                 if (DBA::isResult($photo)) {
256                         $guid = $photo["guid"];
257                 } else {
258                         $guid = System::createGUID();
259                 }
260
261                 $existing_photo = self::selectFirst(["id", "created", "backend-class", "backend-ref"], ["resource-id" => $rid, "uid" => $uid, "contact-id" => $cid, "scale" => $scale]);
262                 $created = DateTimeFormat::utcNow();
263                 if (DBA::isResult($existing_photo)) {
264                         $created = $existing_photo["created"];
265                 }
266
267                 // Get defined storage backend.
268                 // if no storage backend, we use old "data" column in photo table.
269                 // if is an existing photo, reuse same backend
270                 $data = "";
271                 $backend_ref = "";
272
273                 if (DBA::isResult($existing_photo)) {
274                         $backend_ref = (string)$existing_photo["backend-ref"];
275                         $storage = DI::storageManager()->getByName($existing_photo["backend-class"] ?? '');
276                 } else {
277                         $storage = DI::storage();
278                 }
279
280                 if ($storage === null) {
281                         $data = $Image->asString();
282                 } else {
283                         $backend_ref = $storage->put($Image->asString(), $backend_ref);
284                 }
285
286
287                 $fields = [
288                         "uid" => $uid,
289                         "contact-id" => $cid,
290                         "guid" => $guid,
291                         "resource-id" => $rid,
292                         "created" => $created,
293                         "edited" => DateTimeFormat::utcNow(),
294                         "filename" => basename($filename),
295                         "type" => $Image->getType(),
296                         "album" => $album,
297                         "height" => $Image->getHeight(),
298                         "width" => $Image->getWidth(),
299                         "datasize" => strlen($Image->asString()),
300                         "data" => $data,
301                         "scale" => $scale,
302                         "profile" => $profile,
303                         "allow_cid" => $allow_cid,
304                         "allow_gid" => $allow_gid,
305                         "deny_cid" => $deny_cid,
306                         "deny_gid" => $deny_gid,
307                         "desc" => $desc,
308                         "backend-class" => (string)$storage,
309                         "backend-ref" => $backend_ref
310                 ];
311
312                 if (DBA::isResult($existing_photo)) {
313                         $r = DBA::update("photo", $fields, ["id" => $existing_photo["id"]]);
314                 } else {
315                         $r = DBA::insert("photo", $fields);
316                 }
317
318                 return $r;
319         }
320
321
322         /**
323          * Delete info from table and data from storage
324          *
325          * @param array $conditions Field condition(s)
326          * @param array $options    Options array, Optional
327          *
328          * @return boolean
329          *
330          * @throws \Exception
331          * @see   \Friendica\Database\DBA::delete
332          */
333         public static function delete(array $conditions, array $options = [])
334         {
335                 // get photo to delete data info
336                 $photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions);
337
338                 foreach($photos as $photo) {
339                         $backend_class = DI::storageManager()->getByName($photo['backend-class'] ?? '');
340                         if ($backend_class !== null) {
341                                 $backend_class->delete($photo["backend-ref"] ?? '');
342                         }
343                 }
344
345                 return DBA::delete("photo", $conditions, $options);
346         }
347
348         /**
349          * Update a photo
350          *
351          * @param array         $fields     Contains the fields that are updated
352          * @param array         $conditions Condition array with the key values
353          * @param Image         $img        Image to update. Optional, default null.
354          * @param array|boolean $old_fields Array with the old field values that are about to be replaced (true = update on duplicate)
355          *
356          * @return boolean  Was the update successfull?
357          *
358          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
359          * @see   \Friendica\Database\DBA::update
360          */
361         public static function update($fields, $conditions, Image $img = null, array $old_fields = [])
362         {
363                 if (!is_null($img)) {
364                         // get photo to update
365                         $photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions);
366
367                         foreach($photos as $photo) {
368                                 $backend_class = DI::storageManager()->getByName($photo['backend-class'] ?? '');
369                                 if ($backend_class !== null) {
370                                         $fields["backend-ref"] = $backend_class->put($img->asString(), $photo['backend-ref']);
371                                 } else {
372                                         $fields["data"] = $img->asString();
373                                 }
374                         }
375                         $fields['updated'] = DateTimeFormat::utcNow();
376                 }
377
378                 $fields['edited'] = DateTimeFormat::utcNow();
379
380                 return DBA::update("photo", $fields, $conditions, $old_fields);
381         }
382
383         /**
384          * @param string  $image_url     Remote URL
385          * @param integer $uid           user id
386          * @param integer $cid           contact id
387          * @param boolean $quit_on_error optional, default false
388          * @return array
389          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
390          * @throws \ImagickException
391          */
392         public static function importProfilePhoto($image_url, $uid, $cid, $quit_on_error = false)
393         {
394                 $thumb = "";
395                 $micro = "";
396
397                 $photo = DBA::selectFirst(
398                         "photo", ["resource-id"], ["uid" => $uid, "contact-id" => $cid, "scale" => 4, "album" => "Contact Photos"]
399                 );
400                 if (!empty($photo['resource-id'])) {
401                         $resource_id = $photo["resource-id"];
402                 } else {
403                         $resource_id = self::newResource();
404                 }
405
406                 $photo_failure = false;
407
408                 $filename = basename($image_url);
409                 if (!empty($image_url)) {
410                         $ret = Network::curl($image_url, true);
411                         $img_str = $ret->getBody();
412                         $type = $ret->getContentType();
413                 } else {
414                         $img_str = '';
415                 }
416
417                 if ($quit_on_error && ($img_str == "")) {
418                         return false;
419                 }
420
421                 if (empty($type)) {
422                         $type = Images::guessType($image_url, true);
423                 }
424
425                 $Image = new Image($img_str, $type);
426                 if ($Image->isValid()) {
427                         $Image->scaleToSquare(300);
428
429                         $r = self::store($Image, $uid, $cid, $resource_id, $filename, "Contact Photos", 4);
430
431                         if ($r === false) {
432                                 $photo_failure = true;
433                         }
434
435                         $Image->scaleDown(80);
436
437                         $r = self::store($Image, $uid, $cid, $resource_id, $filename, "Contact Photos", 5);
438
439                         if ($r === false) {
440                                 $photo_failure = true;
441                         }
442
443                         $Image->scaleDown(48);
444
445                         $r = self::store($Image, $uid, $cid, $resource_id, $filename, "Contact Photos", 6);
446
447                         if ($r === false) {
448                                 $photo_failure = true;
449                         }
450
451                         $suffix = "?ts=" . time();
452
453                         $image_url = DI::baseUrl() . "/photo/" . $resource_id . "-4." . $Image->getExt() . $suffix;
454                         $thumb = DI::baseUrl() . "/photo/" . $resource_id . "-5." . $Image->getExt() . $suffix;
455                         $micro = DI::baseUrl() . "/photo/" . $resource_id . "-6." . $Image->getExt() . $suffix;
456
457                         // Remove the cached photo
458                         $a = DI::app();
459                         $basepath = $a->getBasePath();
460
461                         if (is_dir($basepath . "/photo")) {
462                                 $filename = $basepath . "/photo/" . $resource_id . "-4." . $Image->getExt();
463                                 if (file_exists($filename)) {
464                                         unlink($filename);
465                                 }
466                                 $filename = $basepath . "/photo/" . $resource_id . "-5." . $Image->getExt();
467                                 if (file_exists($filename)) {
468                                         unlink($filename);
469                                 }
470                                 $filename = $basepath . "/photo/" . $resource_id . "-6." . $Image->getExt();
471                                 if (file_exists($filename)) {
472                                         unlink($filename);
473                                 }
474                         }
475                 } else {
476                         $photo_failure = true;
477                 }
478
479                 if ($photo_failure && $quit_on_error) {
480                         return false;
481                 }
482
483                 if ($photo_failure) {
484                         $image_url = DI::baseUrl() . "/images/person-300.jpg";
485                         $thumb = DI::baseUrl() . "/images/person-80.jpg";
486                         $micro = DI::baseUrl() . "/images/person-48.jpg";
487                 }
488
489                 return [$image_url, $thumb, $micro];
490         }
491
492         /**
493          * @param array $exifCoord coordinate
494          * @param string $hemi      hemi
495          * @return float
496          */
497         public static function getGps($exifCoord, $hemi)
498         {
499                 $degrees = count($exifCoord) > 0 ? self::gps2Num($exifCoord[0]) : 0;
500                 $minutes = count($exifCoord) > 1 ? self::gps2Num($exifCoord[1]) : 0;
501                 $seconds = count($exifCoord) > 2 ? self::gps2Num($exifCoord[2]) : 0;
502
503                 $flip = ($hemi == "W" || $hemi == "S") ? -1 : 1;
504
505                 return floatval($flip * ($degrees + ($minutes / 60) + ($seconds / 3600)));
506         }
507
508         /**
509          * @param string $coordPart coordPart
510          * @return float
511          */
512         private static function gps2Num($coordPart)
513         {
514                 $parts = explode("/", $coordPart);
515
516                 if (count($parts) <= 0) {
517                         return 0;
518                 }
519
520                 if (count($parts) == 1) {
521                         return $parts[0];
522                 }
523
524                 return floatval($parts[0]) / floatval($parts[1]);
525         }
526
527         /**
528          * Fetch the photo albums that are available for a viewer
529          *
530          * The query in this function is cost intensive, so it is cached.
531          *
532          * @param int  $uid    User id of the photos
533          * @param bool $update Update the cache
534          *
535          * @return array Returns array of the photo albums
536          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
537          */
538         public static function getAlbums($uid, $update = false)
539         {
540                 $sql_extra = Security::getPermissionsSQLByUserId($uid);
541
542                 $key = "photo_albums:".$uid.":".local_user().":".remote_user();
543                 $albums = DI::cache()->get($key);
544                 if (is_null($albums) || $update) {
545                         if (!Config::get("system", "no_count", false)) {
546                                 /// @todo This query needs to be renewed. It is really slow
547                                 // At this time we just store the data in the cache
548                                 $albums = q("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album`, ANY_VALUE(`created`) AS `created`
549                                         FROM `photo`
550                                         WHERE `uid` = %d  AND `album` != '%s' AND `album` != '%s' $sql_extra
551                                         GROUP BY `album` ORDER BY `created` DESC",
552                                         intval($uid),
553                                         DBA::escape("Contact Photos"),
554                                         DBA::escape(DI::l10n()->t("Contact Photos"))
555                                 );
556                         } else {
557                                 // This query doesn't do the count and is much faster
558                                 $albums = q("SELECT DISTINCT(`album`), '' AS `total`
559                                         FROM `photo` USE INDEX (`uid_album_scale_created`)
560                                         WHERE `uid` = %d  AND `album` != '%s' AND `album` != '%s' $sql_extra",
561                                         intval($uid),
562                                         DBA::escape("Contact Photos"),
563                                         DBA::escape(DI::l10n()->t("Contact Photos"))
564                                 );
565                         }
566                         DI::cache()->set($key, $albums, Duration::DAY);
567                 }
568                 return $albums;
569         }
570
571         /**
572          * @param int $uid User id of the photos
573          * @return void
574          * @throws \Exception
575          */
576         public static function clearAlbumCache($uid)
577         {
578                 $key = "photo_albums:".$uid.":".local_user().":".remote_user();
579                 DI::cache()->set($key, null, Duration::DAY);
580         }
581
582         /**
583          * Generate a unique photo ID.
584          *
585          * @return string
586          * @throws \Exception
587          */
588         public static function newResource()
589         {
590                 return System::createGUID(32, false);
591         }
592
593         /**
594          * Extracts the rid from a local photo URI
595          *
596          * @param string $image_uri The URI of the photo
597          * @return string The rid of the photo, or an empty string if the URI is not local
598          */
599         public static function ridFromURI(string $image_uri)
600         {
601                 if (!stristr($image_uri, DI::baseUrl() . '/photo/')) {
602                         return '';
603                 }
604                 $image_uri = substr($image_uri, strrpos($image_uri, '/') + 1);
605                 $image_uri = substr($image_uri, 0, strpos($image_uri, '-'));
606                 if (!strlen($image_uri)) {
607                         return '';
608                 }
609                 return $image_uri;
610         }
611
612         /**
613          * Changes photo permissions that had been embedded in a post
614          *
615          * @todo This function currently does have some flaws:
616          * - Sharing a post with a forum will create a photo that only the forum can see.
617          * - Sharing a photo again that been shared non public before doesn't alter the permissions.
618          *
619          * @return string
620          * @throws \Exception
621          */
622         public static function setPermissionFromBody($body, $uid, $original_contact_id, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny)
623         {
624                 // Simplify image codes
625                 $img_body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
626                 $img_body = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", '[img]$1[/img]', $img_body);
627
628                 // Search for images
629                 if (!preg_match_all("/\[img\](.*?)\[\/img\]/", $img_body, $match)) {
630                         return false;
631                 }
632                 $images = $match[1];
633                 if (empty($images)) {
634                         return false;
635                 }
636
637                 foreach ($images as $image) {
638                         $image_rid = self::ridFromURI($image);
639                         if (empty($image_rid)) {
640                                 continue;
641                         }
642
643                         // Ensure to only modify photos that you own
644                         $srch = '<' . intval($original_contact_id) . '>';
645
646                         $condition = [
647                                 'allow_cid' => $srch, 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '',
648                                 'resource-id' => $image_rid, 'uid' => $uid
649                         ];
650                         if (!Photo::exists($condition)) {
651                                 continue;
652                         }
653
654                         /// @todo Check if $str_contact_allow does contain a public forum. Then set the permissions to public.
655
656                         $fields = ['allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow,
657                                         'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny];
658                         $condition = ['resource-id' => $image_rid, 'uid' => $uid];
659                         Logger::info('Set permissions', ['condition' => $condition, 'permissions' => $fields]);
660                         Photo::update($fields, $condition);
661                 }
662
663                 return true;
664         }
665
666         /**
667          * Strips known picture extensions from picture links
668          *
669          * @param string $name Picture link
670          * @return string stripped picture link
671          * @throws \Exception
672          */
673         public static function stripExtension($name)
674         {
675                 $name = str_replace([".jpg", ".png", ".gif"], ["", "", ""], $name);
676                 foreach (Images::supportedTypes() as $m => $e) {
677                         $name = str_replace("." . $e, "", $name);
678                 }
679                 return $name;
680         }
681
682         /**
683          * Returns the GUID from picture links
684          *
685          * @param string $name Picture link
686          * @return string GUID
687          * @throws \Exception
688          */
689         public static function getGUID($name)
690         {
691                 $base = DI::baseUrl()->get();
692
693                 $guid = str_replace([Strings::normaliseLink($base), '/photo/'], '', Strings::normaliseLink($name));
694
695                 $guid = self::stripExtension($guid);
696                 if (substr($guid, -2, 1) != "-") {
697                         return '';
698                 }
699
700                 $scale = intval(substr($guid, -1, 1));
701                 if (!is_numeric($scale)) {
702                         return '';
703                 }
704
705                 $guid = substr($guid, 0, -2);
706                 return $guid;
707         }
708
709         /**
710          * Tests if the picture link points to a locally stored picture
711          *
712          * @param string $name Picture link
713          * @return boolean
714          * @throws \Exception
715          */
716         public static function isLocal($name)
717         {
718                 $guid = self::getGUID($name);
719
720                 if (empty($guid)) {
721                         return false;
722                 }
723
724                 return DBA::exists('photo', ['resource-id' => $guid]);
725         }
726
727         /**
728          * Tests if the link points to a locally stored picture page
729          *
730          * @param string $name Page link
731          * @return boolean
732          * @throws \Exception
733          */
734         public static function isLocalPage($name)
735         {
736                 $base = DI::baseUrl()->get();
737
738                 $guid = str_replace(Strings::normaliseLink($base), '', Strings::normaliseLink($name));
739                 $guid = preg_replace("=/photos/.*/image/(.*)=ism", '$1', $guid);
740                 if (empty($guid)) {
741                         return false;
742                 }
743
744                 return DBA::exists('photo', ['resource-id' => $guid]);
745         }
746 }