]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Use HTTP-Signature to authenticate when fetching photos.
[friendica.git] / mod / photos.php
index c72b66f259fa380d2af5eae408692332f13ceef8..137e0adb563218b312b51fc3b0dc021899df677f 100644 (file)
@@ -9,13 +9,12 @@ use Friendica\Content\Nav;
 use Friendica\Content\Pager;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\ACL;
-use Friendica\Core\Addon;
 use Friendica\Core\Config;
+use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
-use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
@@ -154,7 +153,7 @@ function photos_post(App $a)
        $visitor   = 0;
 
        $page_owner_uid = $a->data['user']['uid'];
-       $community_page = $a->data['user']['page-flags'] == Contact::PAGE_COMMUNITY;
+       $community_page = $a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
 
        if (local_user() && (local_user() == $page_owner_uid)) {
                $can_post = true;
@@ -185,7 +184,7 @@ function photos_post(App $a)
 
        if (!$can_post) {
                notice(L10n::t('Permission denied.') . EOL);
-               killme();
+               exit();
        }
 
        $owner_record = User::getOwnerDataById($page_owner_uid);
@@ -193,7 +192,7 @@ function photos_post(App $a)
        if (!$owner_record) {
                notice(L10n::t('Contact information unavailable') . EOL);
                Logger::log('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
-               killme();
+               exit();
        }
 
        if ($a->argc > 3 && $a->argv[2] === 'album') {
@@ -344,7 +343,7 @@ function photos_post(App $a)
                }
 
                if (DBA::isResult($r)) {
-                       Photo::delete(['resource-id' => $r[0]['resource-id'], 'uid' => $page_owner_uid]);
+                       Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $r[0]['resource-id']]);
 
                        Item::deleteForUser(['resource-id' => $r[0]['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
 
@@ -410,9 +409,12 @@ function photos_post(App $a)
                        }
                }
 
-               $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
+               $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
 
-               if (DBA::isResult($photo)) {
+               $photos = DBA::toArray($photos_stmt);
+
+               if (DBA::isResult($photos)) {
+                       $photo = $photos[0];
                        $ext = $phototypes[$photo['type']];
                        Photo::update(
                                ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
@@ -423,16 +425,15 @@ function photos_post(App $a)
                        if ($albname !== $origaname) {
                                Photo::clearAlbumCache($page_owner_uid);
                        }
-               }
+                       /* Don't make the item visible if the only change was the album name */
 
-               /* Don't make the item visible if the only change was the album name */
-
-               $visibility = 0;
-               if ($photo['desc'] !== $desc || strlen($rawtags)) {
-                       $visibility = 1;
+                       $visibility = 0;
+                       if ($photo['desc'] !== $desc || strlen($rawtags)) {
+                               $visibility = 1;
+                       }
                }
 
-               if (!$item_id) {
+               if (DBA::isResult($photos) && !$item_id) {
                        // Create item container
                        $title = '';
                        $uri = Item::newURI($page_owner_uid);
@@ -519,7 +520,6 @@ function photos_post(App $a)
                                                        $taginfo[] = [$newname, $profile, $salmon];
                                                } else {
                                                        $newname = $name;
-                                                       $alias = '';
                                                        $tagcid = 0;
 
                                                        if (strrpos($newname, '+')) {
@@ -529,7 +529,7 @@ function photos_post(App $a)
                                                        if ($tagcid) {
                                                                $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
                                                                        intval($tagcid),
-                                                                       intval($profile_uid)
+                                                                       intval($page_owner_uid)
                                                                );
                                                        } else {
                                                                $newname = str_replace('_',' ',$name);
@@ -600,7 +600,7 @@ function photos_post(App $a)
                        Item::update($fields, $condition);
 
                        $best = 0;
-                       foreach ($p as $scales) {
+                       foreach ($photos as $scales) {
                                if (intval($scales['scale']) == 2) {
                                        $best = 2;
                                        break;
@@ -648,15 +648,15 @@ function photos_post(App $a)
                                        $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
                                        $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
                                        if ($tagged[3]) {
-                                               $arr['object'] .= XML::escape('<link rel="photo" type="'.$photo['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
+                                               $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
                                        }
                                        $arr['object'] .= '</link></object>' . "\n";
 
                                        $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
                                                . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
-                                       $arr['target'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$photo['type'].'" href="' . System::baseUrl() . "/photo/" . $photo['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
+                                       $arr['target'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '" />' . "\n" . '<link rel="preview" type="' . $photo['type'] . '" href="' . System::baseUrl() . "/photo/" . $photo['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
 
-                                       $item_id = Item::insert($arr);
+                                       Item::insert($arr);
                                }
                        }
                }
@@ -666,7 +666,7 @@ function photos_post(App $a)
 
 
        // default post action - upload a photo
-       Addon::callHooks('photo_post_init', $_POST);
+       Hook::callAll('photo_post_init', $_POST);
 
        // Determine the album to use
        $album    = !empty($_REQUEST['album'])    ? Strings::escapeTags(trim($_REQUEST['album']))    : '';
@@ -714,7 +714,7 @@ function photos_post(App $a)
 
        $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
 
-       Addon::callHooks('photo_post_file', $ret);
+       Hook::callAll('photo_post_file', $ret);
 
        if (!empty($ret['src']) && !empty($ret['filesize'])) {
                $src      = $ret['src'];
@@ -754,7 +754,7 @@ function photos_post(App $a)
                }
                @unlink($src);
                $foo = 0;
-               Addon::callHooks('photo_post_end', $foo);
+               Hook::callAll('photo_post_end', $foo);
                return;
        }
 
@@ -770,7 +770,7 @@ function photos_post(App $a)
                notice(L10n::t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)) . EOL);
                @unlink($src);
                $foo = 0;
-               Addon::callHooks('photo_post_end', $foo);
+               Hook::callAll('photo_post_end', $foo);
                return;
        }
 
@@ -778,7 +778,7 @@ function photos_post(App $a)
                notice(L10n::t('Image file is empty.') . EOL);
                @unlink($src);
                $foo = 0;
-               Addon::callHooks('photo_post_end', $foo);
+               Hook::callAll('photo_post_end', $foo);
                return;
        }
 
@@ -793,8 +793,8 @@ function photos_post(App $a)
                notice(L10n::t('Unable to process image.') . EOL);
                @unlink($src);
                $foo = 0;
-               Addon::callHooks('photo_post_end',$foo);
-               killme();
+               Hook::callAll('photo_post_end',$foo);
+               exit();
        }
 
        $exif = $image->orient($src);
@@ -820,7 +820,7 @@ function photos_post(App $a)
        if (!$r) {
                Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
                notice(L10n::t('Image upload failed.') . EOL);
-               killme();
+               exit();
        }
 
        if ($width > 640 || $height > 640) {
@@ -879,7 +879,7 @@ function photos_post(App $a)
        // Update the photo albums cache
        Photo::clearAlbumCache($page_owner_uid);
 
-       Addon::callHooks('photo_post_end', $item_id);
+       Hook::callAll('photo_post_end', $item_id);
 
        // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
        // if they do not wish to be redirected
@@ -940,7 +940,7 @@ function photos_content(App $a)
 
        $owner_uid = $a->data['user']['uid'];
 
-       $community_page = (($a->data['user']['page-flags'] == Contact::PAGE_COMMUNITY) ? true : false);
+       $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
 
        if (local_user() && (local_user() == $owner_uid)) {
                $can_post = true;
@@ -1042,7 +1042,7 @@ function photos_content(App $a)
                                'addon_text' => $uploader,
                                'default_upload' => true];
 
-               Addon::callHooks('photo_upload_form',$ret);
+               Hook::callAll('photo_upload_form',$ret);
 
                $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
                $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
@@ -1564,7 +1564,7 @@ function photos_content(App $a)
                        }
                        $response_verbs = ['like'];
                        $response_verbs[] = 'dislike';
-                       $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
+                       $responses = get_responses($conv_responses, $response_verbs, $link_item);
 
                        $paginate = $pager->renderFull($total);
                }