]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Some more "q" calls replaced
[friendica.git] / mod / photos.php
index 132222f046d4caf981c33eb8a3217b2e61e1f3d0..55e8add605c02ef6ecaaddda786e9ebffbed43f0 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;
@@ -64,6 +65,9 @@ function photos_init(App $a) {
 
        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']));
 
@@ -196,12 +200,7 @@ function photos_post(App $a)
                        return; // NOTREACHED
                }
 
-               $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
-                       DBA::escape($album),
-                       intval($page_owner_uid)
-               );
-
-               if (!DBA::isResult($r)) {
+               if (!DBA::exists('photo', ['album' => $album, 'uid' => $page_owner_uid])) {
                        notice(DI::l10n()->t('Album not found.'));
                        DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
                        return; // NOTREACHED
@@ -223,7 +222,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
                }
 
@@ -317,7 +316,7 @@ function photos_post(App $a)
                }
 
                if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
-                       Logger::log('rotate');
+                       Logger::notice('rotate');
 
                        $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
 
@@ -411,7 +410,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'];
@@ -677,7 +676,7 @@ function photos_post(App $a)
 
        $type = Images::getMimeTypeBySource($src, $filename, $type);
 
-       Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
+       Logger::info('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes');
 
        $maximagesize = DI::config()->get('system', 'maximagesize');
 
@@ -697,14 +696,14 @@ function photos_post(App $a)
                return;
        }
 
-       Logger::log('mod/photos.php: photos_post(): loading the contents of ' . $src , Logger::DEBUG);
+       Logger::info('loading the contents of ' . $src);
 
        $imagedata = @file_get_contents($src);
 
        $image = new Image($imagedata, $type);
 
        if (!$image->isValid()) {
-               Logger::log('mod/photos.php: photos_post(): unable to process image' , Logger::DEBUG);
+               Logger::info('unable to process image');
                notice(DI::l10n()->t('Unable to process image.'));
                @unlink($src);
                $foo = 0;
@@ -733,7 +732,7 @@ function photos_post(App $a)
        $r = Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
 
        if (!$r) {
-               Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
+               Logger::info('image store failed');
                notice(DI::l10n()->t('Image upload failed.'));
                return;
        }
@@ -830,6 +829,8 @@ function photos_content(App $a)
                return;
        }
 
+       $profile = Profile::getByUID($user['uid']);
+
        $phototypes = Images::supportedTypes();
 
        $_SESSION['photo_return'] = DI::args()->getCommand();
@@ -903,7 +904,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') {
@@ -945,7 +946,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 +959,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 +1020,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 +1127,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 +1307,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 +1389,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))) {