]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Merge pull request #5711 from annando/and-again
[friendica.git] / mod / photos.php
index b7e678487a8ac2978552d169ad111f247ef6bcbc..5fb6ba368354aab0735da2000e17d1d55354b6de 100644 (file)
@@ -79,6 +79,7 @@ function photos_init(App $a) {
 
                if ($albums) {
                        $a->data['albums'] = $albums;
+
                        if ($albums_visible) {
                                $ret['success'] = true;
                        }
@@ -117,13 +118,15 @@ function photos_init(App $a) {
                        ]);
                }
 
-
                if (empty($a->page['aside'])) {
                        $a->page['aside'] = '';
                }
 
                $a->page['aside'] .= $vcard_widget;
-               $a->page['aside'] .= $photo_albums_widget;
+
+               if (!empty($photo_albums_widget)) {
+                       $a->page['aside'] .= $photo_albums_widget;
+               }
 
                $tpl = get_markup_template("photos_head.tpl");
 
@@ -163,7 +166,7 @@ function photos_post(App $a)
                        }
                }
 
-               if ($contact_id) {
+               if ($contact_id > 0) {
                        $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
                                intval($contact_id),
                                intval($page_owner_uid)
@@ -201,6 +204,7 @@ function photos_post(App $a)
                        DBA::escape($album),
                        intval($page_owner_uid)
                );
+
                if (!DBA::isResult($r)) {
                        notice(L10n::t('Album not found.') . EOL);
                        goaway($_SESSION['photo_return']);
@@ -250,6 +254,7 @@ function photos_post(App $a)
                                        '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
                                        '$cancel' => L10n::t('Cancel'),
                                ]);
+
                                $a->error = 1; // Set $a->error so the other module functions don't execute
                                return;
                        }
@@ -270,6 +275,7 @@ function photos_post(App $a)
                                        DBA::escape($album)
                                );
                        }
+
                        if (DBA::isResult($r)) {
                                foreach ($r as $rr) {
                                        $res[] = "'" . DBA::escape($rr['rid']) . "'" ;
@@ -310,6 +316,7 @@ function photos_post(App $a)
                // Check if we should do HTML-based delete confirmation
                if (!empty($_REQUEST['confirm'])) {
                        $drop_url = $a->query_string;
+
                        $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
                                '$method' => 'post',
                                '$message' => L10n::t('Do you really want to delete this photo?'),
@@ -319,6 +326,7 @@ function photos_post(App $a)
                                '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
                                '$cancel' => L10n::t('Cancel'),
                        ]);
+
                        $a->error = 1; // Set $a->error so the other module functions don't execute
                        return;
                }
@@ -431,6 +439,7 @@ function photos_post(App $a)
                        DBA::escape($resource_id),
                        intval($page_owner_uid)
                );
+
                if (DBA::isResult($p)) {
                        $ext = $phototypes[$p[0]['type']];
                        $r = q("UPDATE `photo` SET `desc` = '%s', `album` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
@@ -518,28 +527,35 @@ function photos_post(App $a)
                                        if (strpos($tag, '@') === 0) {
                                                $profile = '';
                                                $name = substr($tag,1);
+
                                                if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
                                                        $newname = $name;
                                                        $links = @Probe::lrdd($name);
+
                                                        if (count($links)) {
                                                                foreach ($links as $link) {
                                                                        if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
                                                                                $profile = $link['@attributes']['href'];
                                                                        }
+
                                                                        if ($link['@attributes']['rel'] === 'salmon') {
                                                                                $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
+
                                                                                if (strlen($inform)) {
                                                                                        $inform .= ',';
                                                                                }
+
                                                                                $inform .= $salmon;
                                                                        }
                                                                }
                                                        }
+
                                                        $taginfo[] = [$newname, $profile, $salmon];
                                                } else {
                                                        $newname = $name;
                                                        $alias = '';
                                                        $tagcid = 0;
+
                                                        if (strrpos($newname, '+')) {
                                                                $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
                                                        }
@@ -571,6 +587,7 @@ function photos_post(App $a)
                                                        if (DBA::isResult($r)) {
                                                                $newname = $r[0]['name'];
                                                                $profile = $r[0]['url'];
+
                                                                $notify = 'cid:' . $r[0]['id'];
                                                                if (strlen($inform)) {
                                                                        $inform .= ',';
@@ -578,15 +595,18 @@ function photos_post(App $a)
                                                                $inform .= $notify;
                                                        }
                                                }
+
                                                if ($profile) {
                                                        if (substr($notify, 0, 4) === 'cid:') {
                                                                $taginfo[] = [$newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'];
                                                        } else {
                                                                $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
                                                        }
+
                                                        if (strlen($str_tags)) {
                                                                $str_tags .= ',';
                                                        }
+
                                                        $profile = str_replace(',', '%2c', $profile);
                                                        $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
                                                }
@@ -619,6 +639,7 @@ function photos_post(App $a)
                                        $best = 2;
                                        break;
                                }
+
                                if (intval($scales['scale']) == 4) {
                                        $best = 4;
                                        break;
@@ -900,7 +921,7 @@ function photos_post(App $a)
                Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
        }
 
-       Addon::callHooks('photo_post_end', intval($item_id));
+       Addon::callHooks('photo_post_end', $item_id);
 
        // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
        // if they do not wish to be redirected
@@ -1050,7 +1071,7 @@ function photos_content(App $a)
                $albumselect = '';
 
                $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '>&lt;current year&gt;</option>';
-               if (count($a->data['albums'])) {
+               if (!empty($a->data['albums'])) {
                        foreach ($a->data['albums'] as $album) {
                                if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
                                        continue;
@@ -1090,6 +1111,12 @@ function photos_content(App $a)
                        '$albumselect' => $albumselect,
                        '$permissions' => 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',
                        '$alt_uploader' => $ret['addon_text'],
                        '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
                        '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
@@ -1257,6 +1284,8 @@ function photos_content(App $a)
                        );
 
                        if (DBA::isResult($prvnxt)) {
+                               $prv = null;
+                               $nxt = null;
                                foreach ($prvnxt as $z => $entry) {
                                        if ($entry['resource-id'] == $ph[0]['resource-id']) {
                                                $prv = $z - 1;
@@ -1271,8 +1300,12 @@ function photos_content(App $a)
                                        }
                                }
                                $edit_suffix = ((($cmd === 'edit') && $can_post) ? '/edit' : '');
-                               $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
-                               $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
+                               if (!is_null($prv)) {
+                                       $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
+                               }
+                               if (!is_null($nxt)) {
+                                       $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
+                               }
                        }
                }
 
@@ -1361,7 +1394,7 @@ function photos_content(App $a)
                        $a->set_pager_total(DBA::count('item', $condition));
 
                        $params = ['order' => ['id'], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
-                       $result = Item::selectForUser($link_item['uid'], [], $condition, $params);
+                       $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
                        $items = Item::inArray($result);
 
                        if (local_user() && (local_user() == $link_item['uid'])) {
@@ -1399,7 +1432,7 @@ function photos_content(App $a)
 
                        $album_e = $ph[0]['album'];
                        $caption_e = $ph[0]['desc'];
-                       $aclselect_e = ACL::getFullSelectorHTML($ph[0]);
+                       $aclselect_e = ACL::getFullSelectorHTML($a->user, false, $ph[0]);
 
                        $edit = replace_macros($edit_tpl, [
                                '$id' => $ph[0]['id'],
@@ -1536,7 +1569,7 @@ function photos_content(App $a)
                                        $body_e = BBCode::convert($item['body']);
 
                                        $comments .= replace_macros($template,[
-                                               '$id' => $item['item_id'],
+                                               '$id' => $item['id'],
                                                '$profile_url' => $profile_url,
                                                '$name' => $item['author-name'],
                                                '$thumb' => $item['author-avatar'],