]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Ensure *toArray returns an array
[friendica.git] / mod / photos.php
index f6deb327096645e8126ebcaf807c4ff615720b56..1ccfecdefe2acffeb5318713255b24a797880885 100644 (file)
@@ -29,8 +29,8 @@ use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Map;
 use Friendica\Util\Security;
-use Friendica\Util\Temporal;
 use Friendica\Util\Strings;
+use Friendica\Util\Temporal;
 use Friendica\Util\XML;
 
 function photos_init(App $a) {
@@ -61,7 +61,7 @@ function photos_init(App $a) {
 
                $account_type = Contact::getAccountType($profile);
 
-               $tpl = Renderer::getMarkupTemplate("vcard-widget.tpl");
+               $tpl = Renderer::getMarkupTemplate("widget/vcard.tpl");
 
                $vcard_widget = Renderer::replaceMacros($tpl, [
                        '$name' => $profile['name'],
@@ -113,7 +113,6 @@ function photos_init(App $a) {
                                '$title'    => L10n::t('Photo Albums'),
                                '$recent'   => L10n::t('Recent Photos'),
                                '$albums'   => $ret['albums'],
-                               '$baseurl'  => System::baseUrl(),
                                '$upload'   => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
                                '$can_post' => $can_post
                        ]);
@@ -150,7 +149,7 @@ function photos_post(App $a)
        $can_post  = false;
        $visitor   = 0;
 
-       $page_owner_uid = $a->data['user']['uid'];
+       $page_owner_uid = intval($a->data['user']['uid']);
        $community_page = $a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
 
        if (local_user() && (local_user() == $page_owner_uid)) {
@@ -189,6 +188,9 @@ function photos_post(App $a)
        }
 
        if ($a->argc > 3 && $a->argv[2] === 'album') {
+               if (!Strings::isHex($a->argv[3])) {
+                       $a->internalRedirect('photos/' . $a->data['user']['nickname'] . '/album');
+               }
                $album = hex2bin($a->argv[3]);
 
                if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
@@ -316,7 +318,7 @@ function photos_post(App $a)
                $str_group_deny    = !empty($_POST['group_deny'])    ? perms2str($_POST['group_deny'])    : '';
                $str_contact_deny  = !empty($_POST['contact_deny'])  ? perms2str($_POST['contact_deny'])  : '';
 
-               $resource_id = $a->argv[2];
+               $resource_id = $a->argv[3];
 
                if (!strlen($albname)) {
                        $albname = DateTimeFormat::localNow('Y');
@@ -419,10 +421,11 @@ function photos_post(App $a)
 
                if ($item_id) {
                        $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
-               }
-               if (DBA::isResult($item)) {
-                       $old_tag    = $item['tag'];
-                       $old_inform = $item['inform'];
+
+                       if (DBA::isResult($item)) {
+                               $old_tag    = $item['tag'];
+                               $old_inform = $item['inform'];
+                       }
                }
 
                if (strlen($rawtags)) {
@@ -525,13 +528,13 @@ function photos_post(App $a)
                                }
                        }
 
-                       $newtag = $old_tag;
+                       $newtag = $old_tag ?? '';
                        if (strlen($newtag) && strlen($str_tags)) {
                                $newtag .= ',';
                        }
                        $newtag .= $str_tags;
 
-                       $newinform = $old_inform;
+                       $newinform = $old_inform ?? '';
                        if (strlen($newinform) && strlen($inform)) {
                                $newinform .= ',';
                        }
@@ -736,7 +739,7 @@ function photos_post(App $a)
                @unlink($src);
                $foo = 0;
                Hook::callAll('photo_post_end',$foo);
-               exit();
+               return;
        }
 
        $exif = $image->orient($src);
@@ -762,7 +765,7 @@ function photos_post(App $a)
        if (!$r) {
                Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
                notice(L10n::t('Image upload failed.') . EOL);
-               exit();
+               return;
        }
 
        if ($width > 640 || $height > 640) {
@@ -951,7 +954,7 @@ function photos_content(App $a)
 
        // tabs
        $is_owner = (local_user() && (local_user() == $owner_uid));
-       $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
+       $o .= Profile::getTabs($a, 'photos', $is_owner, $a->data['user']['nickname']);
 
        // Display upload form
        if ($datatype === 'upload') {
@@ -960,7 +963,7 @@ function photos_content(App $a)
                        return;
                }
 
-               $selname = $datum ? hex2bin($datum) : '';
+               $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
 
                $albumselect = '';
 
@@ -1027,6 +1030,10 @@ function photos_content(App $a)
 
        // Display a single photo album
        if ($datatype === 'album') {
+               // if $datum is not a valid hex, redirect to the default page
+               if (!Strings::isHex($datum)) {
+                       $a->internalRedirect('photos/' . $a->data['user']['nickname']. '/album');
+               }
                $album = hex2bin($datum);
 
                $total = 0;
@@ -1294,6 +1301,10 @@ function photos_content(App $a)
                        'filename' => $hires['filename'],
                ];
 
+               $map = null;
+               $link_item = [];
+               $total = 0;
+
                // Do we have an item for this photo?
 
                // FIXME! - replace following code to display the conversation with our normal
@@ -1306,15 +1317,12 @@ function photos_content(App $a)
                $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
                        DBA::escape($datum)
                );
-
-               $map = null;
-               $link_item = [];
-               $total = 0;
-
                if (DBA::isResult($linked_items)) {
                        // This is a workaround to not being forced to rewrite the while $sql_extra handling
                        $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
+               }
 
+               if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
                        $condition = ["`parent` = ? AND `parent` != `id`",  $link_item['parent']];
                        $total = DBA::count('item', $condition);
 
@@ -1324,25 +1332,25 @@ function photos_content(App $a)
                        $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
                        $items = Item::inArray($result);
 
-                       if (local_user() && (local_user() == $link_item['uid'])) {
+                       if (local_user() == $link_item['uid']) {
                                Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
                        }
+               }
 
-                       if ($link_item['coord']) {
-                               $map = Map::byCoordinates($link_item['coord']);
-                       }
+               if (!empty($link_item['coord'])) {
+                       $map = Map::byCoordinates($link_item['coord']);
                }
 
                $tags = null;
 
-               if (count($linked_items) && strlen($link_item['tag'])) {
+               if (!empty($link_item['id']) && !empty($link_item['tag'])) {
                        $arr = explode(',', $link_item['tag']);
                        // parse tags and add links
                        $tag_arr = [];
                        foreach ($arr as $tag) {
                                $tag_arr[] = [
                                        'name' => BBCode::convert($tag),
-                                       'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag)
+                                       'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
                                ];
                        }
                        $tags = ['title' => L10n::t('Tags: '), 'tags' => $tag_arr];
@@ -1375,7 +1383,7 @@ function photos_content(App $a)
                                '$permissions' => L10n::t('Permissions'),
                                '$aclselect' => $aclselect_e,
 
-                               '$item_id' => defaults($link_item, 'id', 0),
+                               '$item_id' => $link_item['id'] ?? 0,
                                '$submit' => L10n::t('Submit'),
                                '$delete' => L10n::t('Delete Photo'),
 
@@ -1393,7 +1401,7 @@ function photos_content(App $a)
                $paginate = '';
                $responses = '';
 
-               if (count($linked_items)) {
+               if (!empty($link_item['id']) && !empty($link_item['uri'])) {
                        $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
                        $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
                        $return_path = $a->cmd;
@@ -1504,7 +1512,7 @@ function photos_content(App $a)
                                                '$title' => $title_e,
                                                '$body' => $body_e,
                                                '$ago' => Temporal::getRelativeDate($item['created']),
-                                               '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
+                                               '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
                                                '$drop' => $drop,
                                                '$comment' => $comment
                                        ]);
@@ -1513,7 +1521,7 @@ function photos_content(App $a)
                                                $comments .= Renderer::replaceMacros($cmnt_tpl, [
                                                        '$return_path' => '',
                                                        '$jsreload' => $return_path,
-                                                       '$id' => $item['item_id'],
+                                                       '$id' => $item['id'],
                                                        '$parent' => $item['parent'],
                                                        '$profile_uid' =>  $owner_uid,
                                                        '$mylink' => $contact['url'],