]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
New item field "Post-type" and new table "permissionset" (#5408)
[friendica.git] / mod / photos.php
index 9cd3482746734f71696684bcc12af6b8fa6cbd44..bd1de938c89b6c38eaedd0b8db0668ea16c02925 100644 (file)
@@ -101,6 +101,8 @@ function photos_init(App $a) {
 
                if (local_user() && $a->data['user']['uid'] == local_user()) {
                        $can_post = true;
+               } else {
+                       $can_post = false;
                }
 
                if ($ret['success']) {
@@ -172,7 +174,7 @@ function photos_post(App $a)
        }
 
        if (!$can_post) {
-               notice(L10n::t('Permission denied.') . EOL );
+               notice(L10n::t('Permission denied.') . EOL);
                killme();
        }
 
@@ -275,7 +277,7 @@ function photos_post(App $a)
                        $str_res = implode(',', $res);
 
                        // remove the associated photos
-                       q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
+                       q("DELETE FROM `photo` WHERE `resource-id` IN ($str_res) AND `uid` = %d",
                                intval($page_owner_uid)
                        );
 
@@ -372,7 +374,7 @@ function photos_post(App $a)
                        if (DBM::is_result($r)) {
                                $Image = new Image($r[0]['data'], $r[0]['type']);
                                if ($Image->isValid()) {
-                                       $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
+                                       $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
                                        $Image->rotate($rotate_deg);
 
                                        $width  = $Image->getWidth();
@@ -453,11 +455,11 @@ function photos_post(App $a)
                        $uri = Item::newURI($page_owner_uid);
 
                        $arr = [];
-                       $arr['guid']          = get_guid(32);
+                       $arr['guid']          = System::createGUID(32);
                        $arr['uid']           = $page_owner_uid;
                        $arr['uri']           = $uri;
                        $arr['parent-uri']    = $uri;
-                       $arr['type']          = 'photo';
+                       $arr['post-type']     = Item::PT_IMAGE;
                        $arr['wall']          = 1;
                        $arr['resource-id']   = $p[0]['resource-id'];
                        $arr['contact-id']    = $owner_record['id'];
@@ -620,11 +622,10 @@ function photos_post(App $a)
                                        $uri = Item::newURI($page_owner_uid);
 
                                        $arr = [];
-                                       $arr['guid']          = get_guid(32);
+                                       $arr['guid']          = System::createGUID(32);
                                        $arr['uid']           = $page_owner_uid;
                                        $arr['uri']           = $uri;
                                        $arr['parent-uri']    = $uri;
-                                       $arr['type']          = 'activity';
                                        $arr['wall']          = 1;
                                        $arr['contact-id']    = $owner_record['id'];
                                        $arr['owner-name']    = $owner_record['name'];
@@ -640,6 +641,7 @@ function photos_post(App $a)
                                        $arr['deny_gid']      = $p[0]['deny_gid'];
                                        $arr['visible']       = 1;
                                        $arr['verb']          = ACTIVITY_TAG;
+                                       $arr['gravity']       = GRAVITY_PARENT;
                                        $arr['object-type']   = ACTIVITY_OBJ_PERSON;
                                        $arr['target-type']   = ACTIVITY_OBJ_IMAGE;
                                        $arr['tag']           = $tagged[4];
@@ -855,7 +857,7 @@ function photos_post(App $a)
                $arr['coord'] = $lat . ' ' . $lon;
        }
 
-       $arr['guid']          = get_guid(32);
+       $arr['guid']          = System::createGUID(32);
        $arr['uid']           = $page_owner_uid;
        $arr['uri']           = $uri;
        $arr['parent-uri']    = $uri;
@@ -918,7 +920,7 @@ function photos_content(App $a)
        require_once 'include/conversation.php';
 
        if (!x($a->data,'user')) {
-               notice(L10n::t('No photos selected') . EOL );
+               notice(L10n::t('No photos selected') . EOL);
                return;
        }
 
@@ -949,6 +951,7 @@ function photos_content(App $a)
        $contact        = null;
        $remote_contact = false;
        $contact_id     = 0;
+       $edit           = false;
 
        $owner_uid = $a->data['user']['uid'];
 
@@ -1216,7 +1219,7 @@ function photos_content(App $a)
                        if (DBM::is_result($ph)) {
                                notice(L10n::t('Permission denied. Access to this item may be restricted.'));
                        } else {
-                               notice(L10n::t('Photo not available') . EOL );
+                               notice(L10n::t('Photo not available') . EOL);
                        }
                        return;
                }
@@ -1231,6 +1234,7 @@ function photos_content(App $a)
                 */
                if (!Config::get('system', 'no_count', false)) {
                        $order_field = defaults($_GET, 'order', '');
+
                        if ($order_field === 'posted') {
                                $order = 'ASC';
                        } else {
@@ -1289,15 +1293,15 @@ function photos_content(App $a)
                        ];
 
                        // lock
-                       $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
-                                       || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
+                       $lock = ((($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
+                                       || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])))
                                        ? L10n::t('Private Message')
                                        : Null);
 
 
                }
 
-               if ( $cmd === 'edit') {
+               if ($cmd === 'edit') {
                        $tpl = get_markup_template('photo_edit_head.tpl');
                        $a->page['htmlhead'] .= replace_macros($tpl,[
                                '$prevlink' => $prevlink,
@@ -1332,7 +1336,8 @@ function photos_content(App $a)
                // The difference is that we won't be displaying the conversation head item
                // as a "post" but displaying instead the photo it is linked to
 
-               $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
+               /// @todo Rewrite this query. To do so, $sql_extra must be changed
+               $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
                        dbesc($datum)
                );
 
@@ -1340,42 +1345,15 @@ function photos_content(App $a)
                $link_item = [];
 
                if (DBM::is_result($linked_items)) {
-                       $link_item = $linked_items[0];
-
-                       $r = q("SELECT COUNT(*) AS `total`
-                               FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
-                               WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
-                               AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
-                               AND `item`.`uid` = %d
-                               $sql_extra ",
-                               dbesc($link_item['uri']),
-                               dbesc($link_item['uri']),
-                               intval($link_item['uid'])
-
-                       );
-
-                       if (DBM::is_result($r)) {
-                               $a->set_pager_total($r[0]['total']);
-                       }
-
+                       // This is a workaround to not being forced to rewrite the while $sql_extra handling
+                       $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
 
-                       $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
-                               `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
-                               `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
-                               `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
-                               FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
-                               WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
-                               AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
-                               AND `item`.`uid` = %d
-                               $sql_extra
-                               ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
-                               dbesc($link_item['uri']),
-                               dbesc($link_item['uri']),
-                               intval($link_item['uid']),
-                               intval($a->pager['start']),
-                               intval($a->pager['itemspage'])
+                       $condition = ["`parent` = ? AND `parent` != `id`",  $link_item['parent']];
+                       $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);
+                       $items = Item::inArray($result);
 
                        if (local_user() && (local_user() == $link_item['uid'])) {
                                Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
@@ -1462,12 +1440,11 @@ function photos_content(App $a)
                                ]);
                        }
 
-                       if (!DBM::is_result($r)) {
+                       if (!DBM::is_result($items)) {
                                if (($can_post || can_write_wall($owner_uid))) {
                                        $comments .= replace_macros($cmnt_tpl, [
                                                '$return_path' => '',
                                                '$jsreload' => $return_url,
-                                               '$type' => 'wall-comment',
                                                '$id' => $link_item['id'],
                                                '$parent' => $link_item['id'],
                                                '$profile_uid' =>  $owner_uid,
@@ -1490,8 +1467,8 @@ function photos_content(App $a)
                        ];
 
                        // display comments
-                       if (DBM::is_result($r)) {
-                               foreach ($r as $item) {
+                       if (DBM::is_result($items)) {
+                               foreach ($items as $item) {
                                        builtin_activity_puller($item, $conv_responses);
                                }
 
@@ -1506,7 +1483,6 @@ function photos_content(App $a)
                                        $comments .= replace_macros($cmnt_tpl,[
                                                '$return_path' => '',
                                                '$jsreload' => $return_url,
-                                               '$type' => 'wall-comment',
                                                '$id' => $link_item['id'],
                                                '$parent' => $link_item['id'],
                                                '$profile_uid' =>  $owner_uid,
@@ -1522,7 +1498,7 @@ function photos_content(App $a)
                                        ]);
                                }
 
-                               foreach ($r as $item) {
+                               foreach ($items as $item) {
                                        $comment = '';
                                        $template = $tpl;
                                        $sparkle = '';
@@ -1531,20 +1507,13 @@ function photos_content(App $a)
                                                continue;
                                        }
 
-                                       $profile_url = Contact::MagicLinkById($item['cid']);
+                                       $profile_url = Contact::MagicLinkById($item['author-id']);
                                        if (strpos($profile_url, 'redir/') === 0) {
                                                $sparkle = ' sparkle';
                                        } else {
                                                $sparkle = '';
                                        }
 
-                                       $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
-
-                                       $profile_name   = ((strlen($item['author-name'])   && $diff_author) ? $item['author-name']   : $item['name']);
-                                       $profile_avatar = ((strlen($item['author-avatar']) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
-
-                                       $profile_link = $profile_url;
-
                                        $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
                                        $drop = [
                                                'dropping' => $dropping,
@@ -1553,15 +1522,14 @@ function photos_content(App $a)
                                                'delete' => L10n::t('Delete'),
                                        ];
 
-                                       $name_e = $profile_name;
                                        $title_e = $item['title'];
                                        $body_e = BBCode::convert($item['body']);
 
                                        $comments .= replace_macros($template,[
                                                '$id' => $item['item_id'],
-                                               '$profile_url' => $profile_link,
-                                               '$name' => $name_e,
-                                               '$thumb' => $profile_avatar,
+                                               '$profile_url' => $profile_url,
+                                               '$name' => $item['author-name'],
+                                               '$thumb' => $item['author-avatar'],
                                                '$sparkle' => $sparkle,
                                                '$title' => $title_e,
                                                '$body' => $body_e,
@@ -1575,7 +1543,6 @@ function photos_content(App $a)
                                                $comments .= replace_macros($cmnt_tpl, [
                                                        '$return_path' => '',
                                                        '$jsreload' => $return_url,
-                                                       '$type' => 'wall-comment',
                                                        '$id' => $item['item_id'],
                                                        '$parent' => $item['parent'],
                                                        '$profile_uid' =>  $owner_uid,