]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Merge pull request #8749 from MrPetovan/task/8676-ap-attachments
[friendica.git] / mod / photos.php
index db30c7d94c0e908569873a87fb0c0f6eab2ad823..2b72fd3e4ec91c70b5d9eb52071d47ab83afd683 100644 (file)
@@ -1,6 +1,22 @@
 <?php
 /**
- * @file mod/photos.php
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
 
 use Friendica\App;
@@ -9,9 +25,7 @@ use Friendica\Content\Nav;
 use Friendica\Content\Pager;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\ACL;
-use Friendica\Core\Config;
 use Friendica\Core\Hook;
-use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\Core\Session;
@@ -22,7 +36,9 @@ use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\Photo;
 use Friendica\Model\Profile;
+use Friendica\Model\Tag;
 use Friendica\Model\User;
+use Friendica\Module\BaseProfile;
 use Friendica\Network\Probe;
 use Friendica\Object\Image;
 use Friendica\Protocol\Activity;
@@ -37,7 +53,7 @@ use Friendica\Util\XML;
 
 function photos_init(App $a) {
 
-       if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
+       if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
                return;
        }
 
@@ -59,14 +75,14 @@ function photos_init(App $a) {
 
                $account_type = Contact::getAccountType($profile);
 
-               $tpl = Renderer::getMarkupTemplate("widget/vcard.tpl");
+               $tpl = Renderer::getMarkupTemplate('widget/vcard.tpl');
 
                $vcard_widget = Renderer::replaceMacros($tpl, [
                        '$name' => $profile['name'],
                        '$photo' => $profile['photo'],
                        '$addr' => $profile['addr'] ?? '',
                        '$account_type' => $account_type,
-                       '$pdesc' => $profile['pdesc'] ?? '',
+                       '$about' => BBCode::convert($profile['about']),
                ]);
 
                $albums = Photo::getAlbums($a->data['user']['uid']);
@@ -189,13 +205,13 @@ function photos_post(App $a)
 
                if (!DBA::isResult($r)) {
                        notice(DI::l10n()->t('Album not found.') . EOL);
-                       DI::baseUrl()->redirect($_SESSION['photo_return']);
+                       DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album');
                        return; // NOTREACHED
                }
 
                // Check if the user has responded to a delete confirmation query
                if (!empty($_REQUEST['canceled'])) {
-                       DI::baseUrl()->redirect($_SESSION['photo_return']);
+                       DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album/' . $a->argv[3]);
                }
 
                // RENAME photo album
@@ -252,7 +268,7 @@ function photos_post(App $a)
                        }
                }
 
-               DI::baseUrl()->redirect('photos/' . $a->argv[1]);
+               DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album');
        }
 
        if ($a->argc > 3 && $a->argv[2] === 'image') {
@@ -294,7 +310,7 @@ function photos_post(App $a)
                $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'])   ? Strings::escapeTags(trim($_POST['albname']))   : '';
+               $albname     = !empty($_POST['albname'])   ? trim($_POST['albname'])                        : '';
                $origaname   = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
 
                $aclFormatter = DI::aclFormatter();
@@ -406,16 +422,14 @@ function photos_post(App $a)
                }
 
                if ($item_id) {
-                       $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
+                       $item = Item::selectFirst(['tag', 'inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
 
                        if (DBA::isResult($item)) {
-                               $old_tag    = $item['tag'];
                                $old_inform = $item['inform'];
                        }
                }
 
                if (strlen($rawtags)) {
-                       $str_tags = '';
                        $inform   = '';
 
                        // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
@@ -495,38 +509,33 @@ function photos_post(App $a)
 
                                                if ($profile) {
                                                        if (!empty($contact)) {
-                                                               $taginfo[] = [$newname, $profile, $notify, $contact, '@[url=' . str_replace(',', '%2c', $profile) . ']' . $newname . '[/url]'];
+                                                               $taginfo[] = [$newname, $profile, $notify, $contact];
                                                        } else {
-                                                               $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
-                                                       }
-
-                                                       if (strlen($str_tags)) {
-                                                               $str_tags .= ',';
+                                                               $taginfo[] = [$newname, $profile, $notify, null];
                                                        }
 
                                                        $profile = str_replace(',', '%2c', $profile);
-                                                       $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
+
+                                                       if (!empty($item['uri-id'])) {
+                                                               Tag::store($item['uri-id'], Tag::MENTION, $newname, $profile);
+                                                       }       
                                                }
                                        } elseif (strpos($tag, '#') === 0) {
                                                $tagname = substr($tag, 1);
-                                               $str_tags .= '#[url=' . DI::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url],';
+                                               if (!empty($item['uri-id'])) {
+                                                       Tag::store($item['uri-id'], Tag::HASHTAG, $tagname);
+                                               }
                                        }
                                }
                        }
 
-                       $newtag = $old_tag ?? '';
-                       if (strlen($newtag) && strlen($str_tags)) {
-                               $newtag .= ',';
-                       }
-                       $newtag .= $str_tags;
-
                        $newinform = $old_inform ?? '';
                        if (strlen($newinform) && strlen($inform)) {
                                $newinform .= ',';
                        }
                        $newinform .= $inform;
 
-                       $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
+                       $fields = ['inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
                        $condition = ['id' => $item_id];
                        Item::update($fields, $condition);
 
@@ -570,7 +579,6 @@ function photos_post(App $a)
                                        $arr['gravity']       = GRAVITY_PARENT;
                                        $arr['object-type']   = Activity\ObjectType::PERSON;
                                        $arr['target-type']   = Activity\ObjectType::IMAGE;
-                                       $arr['tag']           = $tagged[4];
                                        $arr['inform']        = $tagged[2];
                                        $arr['origin']        = 1;
                                        $arr['body']          = DI::l10n()->t('%1$s was tagged in %2$s by %3$s', '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . DI::l10n()->t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
@@ -600,10 +608,10 @@ function photos_post(App $a)
        Hook::callAll('photo_post_init', $_POST);
 
        // Determine the album to use
-       $album    = !empty($_REQUEST['album'])    ? Strings::escapeTags(trim($_REQUEST['album']))    : '';
-       $newalbum = !empty($_REQUEST['newalbum']) ? Strings::escapeTags(trim($_REQUEST['newalbum'])) : '';
+       $album    = trim($_REQUEST['album'] ?? '');
+       $newalbum = trim($_REQUEST['newalbum'] ?? '');
 
-       Logger::log('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , Logger::DEBUG);
+       Logger::info('album= ' . $album . ' newalbum= ' . $newalbum);
 
        if (!strlen($album)) {
                if (strlen($newalbum)) {
@@ -691,13 +699,11 @@ function photos_post(App $a)
                return;
        }
 
-       if ($type == "") {
-               $type = Images::guessType($filename);
-       }
+       $type = Images::getMimeTypeBySource($src, $filename, $type);
 
        Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
 
-       $maximagesize = Config::get('system', 'maximagesize');
+       $maximagesize = DI::config()->get('system', 'maximagesize');
 
        if ($maximagesize && ($filesize > $maximagesize)) {
                notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)) . EOL);
@@ -733,7 +739,7 @@ function photos_post(App $a)
        $exif = $image->orient($src);
        @unlink($src);
 
-       $max_length = Config::get('system', 'max_image_length');
+       $max_length = DI::config()->get('system', 'max_image_length');
        if (!$max_length) {
                $max_length = MAX_IMAGE_LENGTH;
        }
@@ -834,7 +840,7 @@ function photos_content(App $a)
        // photos/name/image/xxxxx/edit
        // photos/name/image/xxxxx/drop
 
-       if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
+       if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
                notice(DI::l10n()->t('Public access denied.') . EOL);
                return;
        }
@@ -916,7 +922,7 @@ function photos_content(App $a)
 
        // tabs
        $is_owner = (local_user() && (local_user() == $owner_uid));
-       $o .= Profile::getTabs($a, 'photos', $is_owner, $a->data['user']['nickname']);
+       $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $a->data['user']['nickname']);
 
        // Display upload form
        if ($datatype === 'upload') {
@@ -1008,7 +1014,7 @@ function photos_content(App $a)
                        $total = count($r);
                }
 
-               $pager = new Pager(DI::args()->getQueryString(), 20);
+               $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
 
                /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
                $order_field = $_GET['order'] ?? '';
@@ -1158,7 +1164,7 @@ function photos_content(App $a)
                 * The query leads to a really intense used index.
                 * By now we hide it if someone wants to.
                 */
-               if ($cmd === 'view' && !Config::get('system', 'no_count', false)) {
+               if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
                        $order_field = $_GET['order'] ?? '';
 
                        if ($order_field === 'posted') {
@@ -1238,7 +1244,7 @@ function photos_content(App $a)
                        } else {
                                $tools['edit'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
                                $tools['delete'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
-                               $tools['profile'] = ['profile_photo/use/'.$ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
+                               $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
                        }
 
                        if (
@@ -1281,10 +1287,10 @@ function photos_content(App $a)
                }
 
                if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
-                       $condition = ["`parent` = ? AND `parent` != `id`",  $link_item['parent']];
+                       $condition = ["`parent` = ? AND `gravity` != ?",  $link_item['parent'], GRAVITY_PARENT];
                        $total = DBA::count('item', $condition);
 
-                       $pager = new Pager(DI::args()->getQueryString());
+                       $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
 
                        $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
                        $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
@@ -1301,8 +1307,9 @@ function photos_content(App $a)
 
                $tags = null;
 
-               if (!empty($link_item['id']) && !empty($link_item['tag'])) {
-                       $arr = explode(',', $link_item['tag']);
+               if (!empty($link_item['id'])) {
+                       $tag_text = Tag::getCSVByURIId($link_item['uri-id']);
+                       $arr = explode(',', $tag_text);
                        // parse tags and add links
                        $tag_arr = [];
                        foreach ($arr as $tag) {
@@ -1357,7 +1364,6 @@ function photos_content(App $a)
                $likebuttons = '';
                $comments = '';
                $paginate = '';
-               $responses = '';
 
                if (!empty($link_item['id']) && !empty($link_item['uri'])) {
                        $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
@@ -1369,7 +1375,7 @@ function photos_content(App $a)
                                $likebuttons = Renderer::replaceMacros($like_tpl, [
                                        '$id' => $link_item['id'],
                                        '$likethis' => DI::l10n()->t("I like this \x28toggle\x29"),
-                                       '$nolike' => DI::l10n()->t("I don't like this \x28toggle\x29"),
+                                       '$dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike') ? '' : DI::l10n()->t("I don't like this \x28toggle\x29"),
                                        '$wait' => DI::l10n()->t('Please wait'),
                                        '$return_path' => DI::args()->getQueryString(),
                                ]);
@@ -1389,6 +1395,7 @@ function photos_content(App $a)
                                                '$comment' => DI::l10n()->t('Comment'),
                                                '$submit' => DI::l10n()->t('Submit'),
                                                '$preview' => DI::l10n()->t('Preview'),
+                                               '$loading' => DI::l10n()->t('Loading...'),
                                                '$sourceapp' => DI::l10n()->t($a->sourcename),
                                                '$ww' => '',
                                                '$rand_num' => Crypto::randomDigits(12)
@@ -1397,10 +1404,17 @@ function photos_content(App $a)
                        }
 
                        $conv_responses = [
-                               'like' => ['title' => DI::l10n()->t('Likes','title')],'dislike' => ['title' => DI::l10n()->t('Dislikes','title')],
-                               'attendyes' => ['title' => DI::l10n()->t('Attending','title')], 'attendno' => ['title' => DI::l10n()->t('Not attending','title')], 'attendmaybe' => ['title' => DI::l10n()->t('Might attend','title')]
+                               'like'        => [],
+                               'dislike'     => [],
+                               'attendyes'   => [],
+                               'attendno'    => [],
+                               'attendmaybe' => []
                        ];
 
+                       if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
+                               unset($conv_responses['dislike']);
+                       }
+
                        // display comments
                        if (DBA::isResult($items)) {
                                foreach ($items as $item) {
@@ -1437,13 +1451,12 @@ function photos_content(App $a)
                                foreach ($items as $item) {
                                        $comment = '';
                                        $template = $tpl;
-                                       $sparkle = '';
 
                                        $activity = DI::activity();
 
                                        if (($activity->match($item['verb'], Activity::LIKE) ||
                                             $activity->match($item['verb'], Activity::DISLIKE)) &&
-                                           ($item['id'] != $item['parent'])) {
+                                           ($item['gravity'] != GRAVITY_PARENT)) {
                                                continue;
                                        }
 
@@ -1499,9 +1512,6 @@ function photos_content(App $a)
                                        }
                                }
                        }
-                       $response_verbs = ['like'];
-                       $response_verbs[] = 'dislike';
-                       $responses = get_responses($conv_responses, $response_verbs, $link_item);
 
                        $paginate = $pager->renderFull($total);
                }
@@ -1522,7 +1532,6 @@ function photos_content(App $a)
                        '$likebuttons' => $likebuttons,
                        '$like' => $like,
                        '$dislike' => $dislike,
-                       'responses' => $responses,
                        '$comments' => $comments,
                        '$paginate' => $paginate,
                ]);
@@ -1549,7 +1558,7 @@ function photos_content(App $a)
                $total = count($r);
        }
 
-       $pager = new Pager(DI::args()->getQueryString(), 20);
+       $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
 
        $r = q("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`,