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