]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
The conversation functionality moved to a class
[friendica.git] / mod / photos.php
index 37d3c467b402078fe87ff1c7d1862b518bf501e9..209b9fb7beca5ed61a47949255a62f62f0df42dc 100644 (file)
@@ -38,6 +38,7 @@ use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\Photo;
 use Friendica\Model\Post;
+use Friendica\Model\Profile;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
 use Friendica\Module\BaseProfile;
@@ -62,8 +63,11 @@ function photos_init(App $a) {
 
        Nav::setSelected('home');
 
-       if ($a->argc > 1) {
-               $owner = User::getOwnerDataByNick($a->argv[1]);
+       if (DI::args()->getArgc() > 1) {
+               $owner = User::getOwnerDataByNick(DI::args()->getArgv()[1]);
+               if (!$owner) {
+                       throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
+               }
 
                $is_owner = (local_user() && (local_user() == $owner['uid']));
 
@@ -75,8 +79,6 @@ function photos_init(App $a) {
                $ret = ['success' => false];
 
                if ($albums) {
-                       $a->data['albums'] = $albums;
-
                        if ($albums_visible) {
                                $ret['success'] = true;
                        }
@@ -136,7 +138,7 @@ function photos_init(App $a) {
 
 function photos_post(App $a)
 {
-       $user = User::getByNickname($a->argv[1]);
+       $user = User::getByNickname(DI::args()->getArgv()[1]);
        if (!DBA::isResult($user)) {
                throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
        }
@@ -187,11 +189,11 @@ function photos_post(App $a)
                $str_contact_allow .= $aclFormatter->toString(Contact::getPublicIdByUserId($page_owner_uid));
        }
 
-       if ($a->argc > 3 && $a->argv[2] === 'album') {
-               if (!Strings::isHex($a->argv[3])) {
+       if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'album') {
+               if (!Strings::isHex(DI::args()->getArgv()[3])) {
                        DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
                }
-               $album = hex2bin($a->argv[3]);
+               $album = hex2bin(DI::args()->getArgv()[3]);
 
                if ($album === DI::l10n()->t('Profile Photos') || $album === Photo::CONTACT_PHOTOS || $album === DI::l10n()->t(Photo::CONTACT_PHOTOS)) {
                        DI::baseUrl()->redirect($_SESSION['photo_return']);
@@ -211,7 +213,7 @@ function photos_post(App $a)
 
                // Check if the user has responded to a delete confirmation query
                if (!empty($_REQUEST['canceled'])) {
-                       DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album/' . $a->argv[3]);
+                       DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album/' . DI::args()->getArgv()[3]);
                }
 
                // RENAME photo album
@@ -225,7 +227,7 @@ function photos_post(App $a)
                        // Update the photo albums cache
                        Photo::clearAlbumCache($page_owner_uid);
 
-                       DI::baseUrl()->redirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum));
+                       DI::baseUrl()->redirect('photos/' . $a->getLoggedInUserNickname() . '/album/' . bin2hex($newalbum));
                        return; // NOTREACHED
                }
 
@@ -271,19 +273,19 @@ function photos_post(App $a)
                DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
        }
 
-       if ($a->argc > 3 && $a->argv[2] === 'image') {
+       if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'image') {
                // Check if the user has responded to a delete confirmation query for a single photo
                if (!empty($_POST['canceled'])) {
-                       DI::baseUrl()->redirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
+                       DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
                }
 
                if (!empty($_POST['delete'])) {
                        // same as above but remove single photo
                        if ($visitor) {
-                               $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => $a->argv[3]];
+                               $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => DI::args()->getArgv()[3]];
 
                        } else {
-                               $condition = ['uid' => local_user(), 'resource-id' => $a->argv[3]];
+                               $condition = ['uid' => local_user(), 'resource-id' => DI::args()->getArgv()[3]];
                        }
 
                        $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
@@ -297,22 +299,22 @@ function photos_post(App $a)
                                Photo::clearAlbumCache($page_owner_uid);
                        } else {
                                notice(DI::l10n()->t('Failed to delete the photo.'));
-                               DI::baseUrl()->redirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
+                               DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
                        }
 
-                       DI::baseUrl()->redirect('photos/' . $a->argv[1]);
+                       DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1]);
                        return; // NOTREACHED
                }
        }
 
-       if ($a->argc > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
+       if (DI::args()->getArgc() > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
                $desc        = !empty($_POST['desc'])      ? Strings::escapeTags(trim($_POST['desc']))      : '';
                $rawtags     = !empty($_POST['newtag'])    ? Strings::escapeTags(trim($_POST['newtag']))    : '';
                $item_id     = !empty($_POST['item_id'])   ? intval($_POST['item_id'])                      : 0;
                $albname     = !empty($_POST['albname'])   ? trim($_POST['albname'])                        : '';
                $origaname   = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
 
-               $resource_id = $a->argv[3];
+               $resource_id = DI::args()->getArgv()[3];
 
                if (!strlen($albname)) {
                        $albname = DateTimeFormat::localNow('Y');
@@ -413,7 +415,7 @@ function photos_post(App $a)
                }
 
                if ($item_id) {
-                       $item = Post::selectFirst(['tag', 'inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
+                       $item = Post::selectFirst(['inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
 
                        if (DBA::isResult($item)) {
                                $old_inform = $item['inform'];
@@ -817,7 +819,7 @@ function photos_content(App $a)
        // photos/name/image/xxxxx/edit
        // photos/name/image/xxxxx/drop
 
-       $user = User::getByNickname($a->argv[1]);
+       $user = User::getByNickname(DI::args()->getArgv()[1]);
        if (!DBA::isResult($user)) {
                throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
        }
@@ -832,23 +834,25 @@ function photos_content(App $a)
                return;
        }
 
+       $profile = Profile::getByUID($user['uid']);
+
        $phototypes = Images::supportedTypes();
 
        $_SESSION['photo_return'] = DI::args()->getCommand();
 
        // Parse arguments
        $datum = null;
-       if ($a->argc > 3) {
-               $datatype = $a->argv[2];
-               $datum = $a->argv[3];
-       } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
+       if (DI::args()->getArgc() > 3) {
+               $datatype = DI::args()->getArgv()[2];
+               $datum = DI::args()->getArgv()[3];
+       } elseif ((DI::args()->getArgc() > 2) && (DI::args()->getArgv()[2] === 'upload')) {
                $datatype = 'upload';
        } else {
                $datatype = 'summary';
        }
 
-       if ($a->argc > 4) {
-               $cmd = $a->argv[4];
+       if (DI::args()->getArgc() > 4) {
+               $cmd = DI::args()->getArgv()[4];
        } else {
                $cmd = 'view';
        }
@@ -890,7 +894,8 @@ function photos_content(App $a)
 
        if (!$remote_contact && local_user()) {
                $contact_id = $_SESSION['cid'];
-               $contact = $a->contact;
+
+               $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
        }
 
        if ($user['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
@@ -904,7 +909,7 @@ function photos_content(App $a)
 
        // tabs
        $is_owner = (local_user() && (local_user() == $owner_uid));
-       $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $user);
+       $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $user['nickname'], $profile['hide-friends']);
 
        // Display upload form
        if ($datatype === 'upload') {
@@ -918,8 +923,9 @@ function photos_content(App $a)
                $albumselect = '';
 
                $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '>&lt;current year&gt;</option>';
-               if (!empty($a->data['albums'])) {
-                       foreach ($a->data['albums'] as $album) {
+               $albums = Photo::getAlbums($owner_uid);
+               if (!empty($albums)) {
+                       foreach ($albums as $album) {
                                if (($album['album'] === '') || ($album['album'] === Photo::CONTACT_PHOTOS) || ($album['album'] === DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
                                        continue;
                                }
@@ -945,7 +951,7 @@ function photos_content(App $a)
 
                $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
 
-               $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML(DI::page(), $a->user));
+               $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId()));
 
                $o .= Renderer::replaceMacros($tpl,[
                        '$pagename' => DI::l10n()->t('Upload Photos'),
@@ -958,12 +964,7 @@ function photos_content(App $a)
                        '$albumselect' => $albumselect,
                        '$permissions' => DI::l10n()->t('Permissions'),
                        '$aclselect' => $aclselect_e,
-                       '$lockstate' => is_array($a->user)
-                                       && (strlen($a->user['allow_cid'])
-                                               || strlen($a->user['allow_gid'])
-                                               || strlen($a->user['deny_cid'])
-                                               || strlen($a->user['deny_gid'])
-                                       ) ? 'lock' : 'unlock',
+                       '$lockstate' => ACL::getLockstateForUserId($a->getLoggedInUserId()) ? 'lock' : 'unlock',
                        '$alt_uploader' => $ret['addon_text'],
                        '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
                        '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
@@ -1024,6 +1025,7 @@ function photos_content(App $a)
                                '$confirm' => DI::l10n()->t('Delete Album'),
                                '$confirm_url' => $drop_url,
                                '$confirm_name' => 'dropalbum',
+                               '$confirm_value' => 'dropalbum',
                                '$cancel' => DI::l10n()->t('Cancel'),
                        ]);
                }
@@ -1130,6 +1132,7 @@ function photos_content(App $a)
                                '$confirm' => DI::l10n()->t('Delete Photo'),
                                '$confirm_url' => $drop_url,
                                '$confirm_name' => 'delete',
+                               '$confirm_value' => 'delete',
                                '$cancel' => DI::l10n()->t('Cancel'),
                        ]);
                }
@@ -1309,7 +1312,7 @@ function photos_content(App $a)
 
                        $album_e = $ph[0]['album'];
                        $caption_e = $ph[0]['desc'];
-                       $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->user, false, ACL::getDefaultUserPermissions($ph[0]));
+                       $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), false, ACL::getDefaultUserPermissions($ph[0]));
 
                        $edit = Renderer::replaceMacros($edit_tpl, [
                                '$id' => $ph[0]['id'],
@@ -1391,15 +1394,15 @@ function photos_content(App $a)
                        // display comments
                        if (DBA::isResult($items)) {
                                foreach ($items as $item) {
-                                       builtin_activity_puller($item, $conv_responses);
+                                       DI::conversation()->builtinActivityPuller($item, $conv_responses);
                                }
 
                                if (!empty($conv_responses['like'][$link_item['uri']])) {
-                                       $like = format_activity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']);
+                                       $like = DI::conversation()->formatActivity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']);
                                }
 
                                if (!empty($conv_responses['dislike'][$link_item['uri']])) {
-                                       $dislike = format_activity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']);
+                                       $dislike = DI::conversation()->formatActivity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']);
                                }
 
                                if (($can_post || Security::canWriteToUserWall($owner_uid))) {
@@ -1624,7 +1627,7 @@ function photos_content(App $a)
        $o .= Renderer::replaceMacros($tpl, [
                '$title' => DI::l10n()->t('Recent Photos'),
                '$can_post' => $can_post,
-               '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/'.$user['nickname'].'/upload'],
+               '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload'],
                '$photos' => $photos,
                '$paginate' => $pager->renderFull($total),
        ]);