]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
More replaced "q" calls
[friendica.git] / mod / photos.php
index 1c9e85be8c2f03c5978021621bd7862f324485c3..0d8744055aaf5bd448d6a3a8fb5ebeef74033419 100644 (file)
@@ -200,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
@@ -219,11 +214,7 @@ function photos_post(App $a)
                // RENAME photo album
                $newalbum = Strings::escapeTags(trim($_POST['albumname']));
                if ($newalbum != $album) {
-                       q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
-                               DBA::escape($newalbum),
-                               DBA::escape($album),
-                               intval($page_owner_uid)
-                       );
+                       Photo::update(['album' => $newalbum], ['album' => $album, 'uid' => $page_owner_uid]);
                        // Update the photo albums cache
                        Photo::clearAlbumCache($page_owner_uid);
 
@@ -239,16 +230,16 @@ function photos_post(App $a)
 
                        // get the list of photos we are about to delete
                        if ($visitor) {
-                               $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
-                                       intval($visitor),
-                                       intval($page_owner_uid),
-                                       DBA::escape($album)
-                               );
+                               $r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = ? AND `uid` = ? AND `album` = ?",
+                                       $visitor,
+                                       $page_owner_uid,
+                                       $album
+                               ));
                        } else {
-                               $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
-                                       intval(local_user()),
-                                       DBA::escape($album)
-                               );
+                               $r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = ? AND `album` = ?",
+                                       local_user(),
+                                       $album
+                               ));
                        }
 
                        if (DBA::isResult($r)) {
@@ -321,7 +312,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);
 
@@ -681,7 +672,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');
 
@@ -701,14 +692,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;
@@ -737,7 +728,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;
        }
@@ -986,11 +977,11 @@ function photos_content(App $a)
                $album = hex2bin($datum);
 
                $total = 0;
-               $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
+               $r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND `album` = ?
                        AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
-                       intval($owner_uid),
-                       DBA::escape($album)
-               );
+                       $owner_uid,
+                       $album
+               ));
                if (DBA::isResult($r)) {
                        $total = count($r);
                }
@@ -1005,28 +996,30 @@ function photos_content(App $a)
                        $order = 'DESC';
                }
 
-               $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
+               $r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
                        ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
                        ANY_VALUE(`created`) as `created`
-                       FROM `photo` WHERE `uid` = %d AND `album` = '%s'
-                       AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
+                       FROM `photo` WHERE `uid` = ? AND `album` = ?
+                       AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT ? , ?",
                        intval($owner_uid),
                        DBA::escape($album),
                        $pager->getStart(),
                        $pager->getItemsPerPage()
-               );
+               ));
 
                if ($cmd === 'drop') {
                        $drop_url = DI::args()->getQueryString();
 
                        return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
-                               '$method' => 'post',
-                               '$message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'),
-                               '$confirm' => DI::l10n()->t('Delete Album'),
-                               '$confirm_url' => $drop_url,
-                               '$confirm_name' => 'dropalbum',
+                               '$l10n'           => [
+                                       'message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'),
+                                       'confirm' => DI::l10n()->t('Delete Album'),
+                                       'cancel'  => DI::l10n()->t('Cancel'),
+                               ],
+                               '$method'        => 'post',
+                               '$confirm_url'   => $drop_url,
+                               '$confirm_name'  => 'dropalbum',
                                '$confirm_value' => 'dropalbum',
-                               '$cancel' => DI::l10n()->t('Cancel'),
                        ]);
                }
 
@@ -1127,13 +1120,15 @@ function photos_content(App $a)
                        $drop_url = DI::args()->getQueryString();
 
                        return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
-                               '$method' => 'post',
-                               '$message' => DI::l10n()->t('Do you really want to delete this photo?'),
-                               '$confirm' => DI::l10n()->t('Delete Photo'),
-                               '$confirm_url' => $drop_url,
-                               '$confirm_name' => 'delete',
+                               '$l10n'           => [
+                                       'message' => DI::l10n()->t('Do you really want to delete this photo?'),
+                                       'confirm' => DI::l10n()->t('Delete Photo'),
+                                       'cancel'  => DI::l10n()->t('Cancel'),
+                               ],
+                               '$method'        => 'post',
+                               '$confirm_url'   => $drop_url,
+                               '$confirm_name'  => 'delete',
                                '$confirm_value' => 'delete',
-                               '$cancel' => DI::l10n()->t('Cancel'),
                        ]);
                }
 
@@ -1394,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))) {
@@ -1566,29 +1561,29 @@ function photos_content(App $a)
        // Default - show recent photos with upload link (if applicable)
        //$o = '';
        $total = 0;
-       $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
+       $r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND NOT `album` IN (?, ?)
                $sql_extra GROUP BY `resource-id`",
-               intval($user['uid']),
-               DBA::escape(Photo::CONTACT_PHOTOS),
-               DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS))
-       );
+               $user['uid'],
+               Photo::CONTACT_PHOTOS,
+               DI::l10n()->t(Photo::CONTACT_PHOTOS)
+       ));
        if (DBA::isResult($r)) {
                $total = count($r);
        }
 
        $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
 
-       $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
+       $r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
                ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
                ANY_VALUE(`created`) AS `created` FROM `photo`
-               WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
-               $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
-               intval($user['uid']),
-               DBA::escape(Photo::CONTACT_PHOTOS),
-               DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS)),
+               WHERE `uid` = ? AND NOT `album` IN (?, ?)
+               $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT ? , ?",
+               $user['uid'],
+               Photo::CONTACT_PHOTOS,
+               DI::l10n()->t(Photo::CONTACT_PHOTOS),
                $pager->getStart(),
                $pager->getItemsPerPage()
-       );
+       ));
 
        $photos = [];
        if (DBA::isResult($r)) {