]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Suppress InvalidArgument exceptions handling URLs in Model\Item::containsLink
[friendica.git] / mod / photos.php
index d953569edcbc714af7b4867ff2ef0d32a4b8a5dc..ccf0525cb00040c36ae74def0f9fd8f6d080db2c 100644 (file)
@@ -30,7 +30,6 @@ use Friendica\Core\Addon;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
-use Friendica\Core\Session;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
@@ -57,7 +56,7 @@ use Friendica\Network\HTTPException;
 
 function photos_init(App $a)
 {
-       if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
+       if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
                return;
        }
 
@@ -69,11 +68,11 @@ function photos_init(App $a)
                        throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
                }
 
-               $is_owner = (local_user() && (local_user() == $owner['uid']));
+               $is_owner = (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $owner['uid']));
 
                $albums = Photo::getAlbums($owner['uid']);
 
-               $albums_visible = ((intval($owner['hidewall']) && !Session::isAuthenticated()) ? false : true);
+               $albums_visible = ((intval($owner['hidewall']) && !DI::userSession()->isAuthenticated()) ? false : true);
 
                // add various encodings to the array so we can just loop through and pick them out in a template
                $ret = ['success' => false];
@@ -96,7 +95,7 @@ function photos_init(App $a)
                        }
                }
 
-               if (local_user() && $owner['uid'] == local_user()) {
+               if (DI::userSession()->getLocalUserId() && $owner['uid'] == DI::userSession()->getLocalUserId()) {
                        $can_post = true;
                } else {
                        $can_post = false;
@@ -148,23 +147,23 @@ function photos_post(App $a)
        $page_owner_uid = intval($user['uid']);
        $community_page = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
 
-       if (local_user() && (local_user() == $page_owner_uid)) {
+       if (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $page_owner_uid)) {
                $can_post = true;
-       } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) {
-               $contact_id = Session::getRemoteContactID($page_owner_uid);
+       } elseif ($community_page && !empty(DI::userSession()->getRemoteContactID($page_owner_uid))) {
+               $contact_id = DI::userSession()->getRemoteContactID($page_owner_uid);
                $can_post = true;
                $visitor = $contact_id;
        }
 
        if (!$can_post) {
-               notice(DI::l10n()->t('Permission denied.'));
+               DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
                System::exit();
        }
 
        $owner_record = User::getOwnerDataById($page_owner_uid);
 
        if (!$owner_record) {
-               notice(DI::l10n()->t('Contact information unavailable'));
+               DI::sysmsg()->addNotice(DI::l10n()->t('Contact information unavailable'));
                DI::logger()->info('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
                System::exit();
        }
@@ -193,7 +192,7 @@ function photos_post(App $a)
                $album = hex2bin(DI::args()->getArgv()[3]);
 
                if (!DBA::exists('photo', ['album' => $album, 'uid' => $page_owner_uid, 'photo-type' => Photo::DEFAULT])) {
-                       notice(DI::l10n()->t('Album not found.'));
+                       DI::sysmsg()->addNotice(DI::l10n()->t('Album not found.'));
                        DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
                        return; // NOTREACHED
                }
@@ -229,7 +228,7 @@ function photos_post(App $a)
                                ));
                        } else {
                                $r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = ? AND `album` = ?",
-                                       local_user(),
+                                       DI::userSession()->getLocalUserId(),
                                        $album
                                ));
                        }
@@ -247,9 +246,9 @@ function photos_post(App $a)
 
                                // Update the photo albums cache
                                Photo::clearAlbumCache($page_owner_uid);
-                               notice(DI::l10n()->t('Album successfully deleted'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Album successfully deleted'));
                        } else {
-                               notice(DI::l10n()->t('Album was empty.'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Album was empty.'));
                        }
                }
 
@@ -268,7 +267,7 @@ function photos_post(App $a)
                                $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => DI::args()->getArgv()[3]];
 
                        } else {
-                               $condition = ['uid' => local_user(), 'resource-id' => DI::args()->getArgv()[3]];
+                               $condition = ['uid' => DI::userSession()->getLocalUserId(), 'resource-id' => DI::args()->getArgv()[3]];
                        }
 
                        $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
@@ -281,7 +280,7 @@ function photos_post(App $a)
                                // Update the photo albums cache
                                Photo::clearAlbumCache($page_owner_uid);
                        } else {
-                               notice(DI::l10n()->t('Failed to delete the photo.'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Failed to delete the photo.'));
                                DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
                        }
 
@@ -629,21 +628,21 @@ function photos_post(App $a)
        if ($error !== UPLOAD_ERR_OK) {
                switch ($error) {
                        case UPLOAD_ERR_INI_SIZE:
-                               notice(DI::l10n()->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')));
                                break;
                        case UPLOAD_ERR_FORM_SIZE:
-                               notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($_REQUEST['MAX_FILE_SIZE'] ?? 0)));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($_REQUEST['MAX_FILE_SIZE'] ?? 0)));
                                break;
                        case UPLOAD_ERR_PARTIAL:
-                               notice(DI::l10n()->t('Image upload didn\'t complete, please try again'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Image upload didn\'t complete, please try again'));
                                break;
                        case UPLOAD_ERR_NO_FILE:
-                               notice(DI::l10n()->t('Image file is missing'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Image file is missing'));
                                break;
                        case UPLOAD_ERR_NO_TMP_DIR:
                        case UPLOAD_ERR_CANT_WRITE:
                        case UPLOAD_ERR_EXTENSION:
-                               notice(DI::l10n()->t('Server can\'t accept new file upload at this time, please contact your administrator'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Server can\'t accept new file upload at this time, please contact your administrator'));
                                break;
                }
                @unlink($src);
@@ -659,7 +658,7 @@ function photos_post(App $a)
        $maximagesize = DI::config()->get('system', 'maximagesize');
 
        if ($maximagesize && ($filesize > $maximagesize)) {
-               notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
+               DI::sysmsg()->addNotice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
                @unlink($src);
                $foo = 0;
                Hook::callAll('photo_post_end', $foo);
@@ -667,7 +666,7 @@ function photos_post(App $a)
        }
 
        if (!$filesize) {
-               notice(DI::l10n()->t('Image file is empty.'));
+               DI::sysmsg()->addNotice(DI::l10n()->t('Image file is empty.'));
                @unlink($src);
                $foo = 0;
                Hook::callAll('photo_post_end', $foo);
@@ -682,7 +681,7 @@ function photos_post(App $a)
 
        if (!$image->isValid()) {
                Logger::notice('unable to process image');
-               notice(DI::l10n()->t('Unable to process image.'));
+               DI::sysmsg()->addNotice(DI::l10n()->t('Unable to process image.'));
                @unlink($src);
                $foo = 0;
                Hook::callAll('photo_post_end',$foo);
@@ -708,7 +707,7 @@ function photos_post(App $a)
 
        if (!$r) {
                Logger::warning('image store failed');
-               notice(DI::l10n()->t('Image upload failed.'));
+               DI::sysmsg()->addNotice(DI::l10n()->t('Image upload failed.'));
                return;
        }
 
@@ -794,13 +793,13 @@ function photos_content(App $a)
                throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
        }
 
-       if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
-               notice(DI::l10n()->t('Public access denied.'));
+       if (DI::config()->get('system', 'block_public') && !DI::userSession()->isAuthenticated()) {
+               DI::sysmsg()->addNotice(DI::l10n()->t('Public access denied.'));
                return;
        }
 
        if (empty($user)) {
-               notice(DI::l10n()->t('No photos selected'));
+               DI::sysmsg()->addNotice(DI::l10n()->t('No photos selected'));
                return;
        }
 
@@ -840,10 +839,10 @@ function photos_content(App $a)
 
        $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
 
-       if (local_user() && (local_user() == $owner_uid)) {
+       if (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $owner_uid)) {
                $can_post = true;
-       } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
-               $contact_id = Session::getRemoteContactID($owner_uid);
+       } elseif ($community_page && !empty(DI::userSession()->getRemoteContactID($owner_uid))) {
+               $contact_id = DI::userSession()->getRemoteContactID($owner_uid);
                $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
 
                if (DBA::isResult($contact)) {
@@ -854,22 +853,22 @@ function photos_content(App $a)
        }
 
        // perhaps they're visiting - but not a community page, so they wouldn't have write access
-       if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
-               $contact_id = Session::getRemoteContactID($owner_uid);
+       if (!empty(DI::userSession()->getRemoteContactID($owner_uid)) && !$visitor) {
+               $contact_id = DI::userSession()->getRemoteContactID($owner_uid);
 
                $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
 
                $remote_contact = DBA::isResult($contact);
        }
 
-       if (!$remote_contact && local_user()) {
+       if (!$remote_contact && DI::userSession()->getLocalUserId()) {
                $contact_id = $_SESSION['cid'];
 
                $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
        }
 
-       if ($user['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
-               notice(DI::l10n()->t('Access to this item is restricted.'));
+       if ($user['hidewall'] && (DI::userSession()->getLocalUserId() != $owner_uid) && !$remote_contact) {
+               DI::sysmsg()->addNotice(DI::l10n()->t('Access to this item is restricted.'));
                return;
        }
 
@@ -878,13 +877,13 @@ function photos_content(App $a)
        $o = "";
 
        // tabs
-       $is_owner = (local_user() && (local_user() == $owner_uid));
+       $is_owner = (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserId() == $owner_uid));
        $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $user['nickname'], $profile['hide-friends']);
 
        // Display upload form
        if ($datatype === 'upload') {
                if (!$can_post) {
-                       notice(DI::l10n()->t('Permission denied.'));
+                       DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
                        return;
                }
 
@@ -1084,9 +1083,9 @@ function photos_content(App $a)
 
                if (!DBA::isResult($ph)) {
                        if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
-                               notice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
                        } else {
-                               notice(DI::l10n()->t('Photo not available'));
+                               DI::sysmsg()->addNotice(DI::l10n()->t('Photo not available'));
                        }
                        return;
                }
@@ -1197,7 +1196,7 @@ function photos_content(App $a)
                        }
 
                        if (
-                               $ph[0]['uid'] == local_user()
+                               $ph[0]['uid'] == DI::userSession()->getLocalUserId()
                                && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
                        ) {
                                $tools['lock'] = DI::l10n()->t('Private Photo');
@@ -1237,7 +1236,7 @@ function photos_content(App $a)
                        $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
                        $items = Post::toArray(Post::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params));
 
-                       if (local_user() == $link_item['uid']) {
+                       if (DI::userSession()->getLocalUserId() == $link_item['uid']) {
                                Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
                        }
                }
@@ -1251,15 +1250,17 @@ function photos_content(App $a)
                if (!empty($link_item['id'])) {
                        // parse tags and add links
                        $tag_arr = [];
-                       foreach (Tag::getByURIId($link_item['uri-id']) as $tag) {
-                               $tag_arr[] = [
-                                       'name' => $tag['name'],
-                                       'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag['name'])
-                               ];
+                       foreach (explode(',', Tag::getCSVByURIId($link_item['uri-id'])) as $tag_name) {
+                               if ($tag_name) {
+                                       $tag_arr[] = [
+                                               'name'      => BBCode::toPlaintext($tag_name),
+                                               'removeurl' => 'post/' . $link_item['id'] . '/tag/remove/' . bin2hex($tag_name) . '?return=' . urlencode(DI::args()->getCommand()),
+                                       ];
+                               }
                        }
                        $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
                        if ($cmd === 'edit') {
-                               $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
+                               $tags['removeanyurl'] = 'post/' . $link_item['id'] . '/tag/remove?return=' . urlencode(DI::args()->getCommand());
                                $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
                        }
                }
@@ -1315,7 +1316,7 @@ function photos_content(App $a)
                                         */
                                        $qcomment = null;
                                        if (Addon::isEnabled('qcomment')) {
-                                               $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
+                                               $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'qcomment', 'words');
                                                $qcomment = $words ? explode("\n", $words) : [];
                                        }
 
@@ -1346,7 +1347,7 @@ function photos_content(App $a)
                                'attendmaybe' => []
                        ];
 
-                       if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
+                       if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'hide_dislike')) {
                                unset($conv_responses['dislike']);
                        }
 
@@ -1371,7 +1372,7 @@ function photos_content(App $a)
                                         */
                                        $qcomment = null;
                                        if (Addon::isEnabled('qcomment')) {
-                                               $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
+                                               $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'qcomment', 'words');
                                                $qcomment = $words ? explode("\n", $words) : [];
                                        }
 
@@ -1413,7 +1414,7 @@ function photos_content(App $a)
                                                $sparkle = '';
                                        }
 
-                                       $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
+                                       $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == DI::userSession()->getLocalUserId()));
                                        $drop = [
                                                'dropping' => $dropping,
                                                'pagedrop' => false,
@@ -1445,7 +1446,7 @@ function photos_content(App $a)
                                                 */
                                                $qcomment = null;
                                                if (Addon::isEnabled('qcomment')) {
-                                                       $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
+                                                       $words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'qcomment', 'words');
                                                        $qcomment = $words ? explode("\n", $words) : [];
                                                }
 
@@ -1484,7 +1485,7 @@ function photos_content(App $a)
                                        '$dislike' => DI::l10n()->t('Dislike'),
                                        '$wait' => DI::l10n()->t('Please wait'),
                                        '$dislike_title' => DI::l10n()->t('I don\'t like this (toggle)'),
-                                       '$hide_dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike'),
+                                       '$hide_dislike' => DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'hide_dislike'),
                                        '$responses' => $responses,
                                        '$return_path' => DI::args()->getQueryString(),
                                ]);