]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
More indentions
[friendica.git] / mod / photos.php
index a789ac64131df430cf68097d85c7ef3958d73e46..9bc870ca13fe34265dac0fbf5d08071c1d7f33af 100644 (file)
@@ -2,29 +2,32 @@
 /**
  * @file mod/photos.php
  */
+
 use Friendica\App;
 use Friendica\Content\Feature;
 use Friendica\Content\Nav;
+use Friendica\Content\Text\BBCode;
+use Friendica\Core\ACL;
 use Friendica\Core\Addon;
+use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
-use Friendica\Core\Config;
 use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
+use Friendica\Model\Item;
 use Friendica\Model\Photo;
 use Friendica\Model\Profile;
 use Friendica\Network\Probe;
 use Friendica\Object\Image;
 use Friendica\Protocol\DFRN;
+use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Map;
+use Friendica\Util\Temporal;
 
 require_once 'include/items.php';
-require_once 'include/acl_selectors.php';
-require_once 'include/bbcode.php';
 require_once 'include/security.php';
-require_once 'include/tags.php';
-require_once 'include/threads.php';
 
 function photos_init(App $a) {
 
@@ -281,27 +284,7 @@ function photos_post(App $a)
                        );
 
                        // find and delete the corresponding item with all the comments and likes/dislikes
-                       $r = q("SELECT `id`, `parent-uri`, `visible` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
-                               intval($page_owner_uid)
-                       );
-                       if (DBM::is_result($r)) {
-                               foreach ($r as $rr) {
-                                       q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
-                                               dbesc(datetime_convert()),
-                                               dbesc($rr['parent-uri']),
-                                               intval($page_owner_uid)
-                                       );
-                                       create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
-                                       delete_thread_uri($rr['parent-uri'], $page_owner_uid);
-
-                                       $drop_id = intval($rr['id']);
-
-                                       // send the notification upstream/downstream as the case may be
-                                       if ($rr['visible']) {
-                                               Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
-                                       }
-                               }
-                       }
+                       Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
 
                        // Update the photo albums cache
                        Photo::clearAlbumCache($page_owner_uid);
@@ -354,30 +337,11 @@ function photos_post(App $a)
                                intval($page_owner_uid),
                                dbesc($r[0]['resource-id'])
                        );
-                       $i = q("SELECT `id`, `uri`, `visible` FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
-                               dbesc($r[0]['resource-id']),
-                               intval($page_owner_uid)
-                       );
-                       if (DBM::is_result($i)) {
-                               q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
-                                       dbesc(datetime_convert()),
-                                       dbesc(datetime_convert()),
-                                       dbesc($i[0]['uri']),
-                                       intval($page_owner_uid)
-                               );
-                               create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
-                               delete_thread_uri($i[0]['uri'], $page_owner_uid);
 
-                               $url = System::baseUrl();
-                               $drop_id = intval($i[0]['id']);
+                       Item::deleteForUser(['resource-id' => $r[0]['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
 
-                               // Update the photo albums cache
-                               Photo::clearAlbumCache($page_owner_uid);
-
-                               if ($i[0]['visible']) {
-                                       Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
-                               }
-                       }
+                       // Update the photo albums cache
+                       Photo::clearAlbumCache($page_owner_uid);
                }
 
                goaway('photos/' . $a->data['user']['nickname']);
@@ -398,7 +362,7 @@ function photos_post(App $a)
                $resource_id = $a->argv[2];
 
                if (!strlen($albname)) {
-                       $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
+                       $albname = DateTimeFormat::localNow('Y');
                }
 
                if (x($_POST,'rotate') !== false &&
@@ -519,7 +483,7 @@ function photos_post(App $a)
                                                . '[img]' . System::baseUrl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
                                                . '[/url]';
 
-                       $item_id = item_store($arr);
+                       $item_id = Item::insert($arr);
                }
 
                if ($item_id) {
@@ -642,16 +606,9 @@ function photos_post(App $a)
                        }
                        $newinform .= $inform;
 
-                       $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
-                               dbesc($newtag),
-                               dbesc($newinform),
-                               dbesc(datetime_convert()),
-                               dbesc(datetime_convert()),
-                               intval($item_id),
-                               intval($page_owner_uid)
-                       );
-                       create_tags_from_item($item_id);
-                       update_thread($item_id);
+                       $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
+                       $condition = ['id' => $item_id];
+                       Item::update($fields, $condition);
 
                        $best = 0;
                        foreach ($p as $scales) {
@@ -709,7 +666,7 @@ function photos_post(App $a)
                                                . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
                                        $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . System::baseUrl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
 
-                                       $item_id = item_store($arr);
+                                       $item_id = Item::insert($arr);
                                        if ($item_id) {
                                                Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
                                        }
@@ -734,7 +691,7 @@ function photos_post(App $a)
                if (strlen($newalbum)) {
                        $album = $newalbum;
                } else {
-                       $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
+                       $album = DateTimeFormat::localNow('Y');
                }
        }
 
@@ -869,7 +826,7 @@ function photos_post(App $a)
 
        $smallest = 0;
 
-       $photo_hash = photo_new_resource();
+       $photo_hash = Photo::newResource();
 
        $r = Photo::store($Image, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
 
@@ -895,7 +852,7 @@ function photos_post(App $a)
 
        // Create item container
        $lat = $lon = null;
-       if ($exif && $exif['GPS'] && Feature::isEnabled($channel_id, 'photo_location')) {
+       if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
                $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
                $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
        }
@@ -931,7 +888,7 @@ function photos_post(App $a)
                                . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$Image->getExt() . '[/img]'
                                . '[/url]';
 
-       $item_id = item_store($arr);
+       $item_id = Item::insert($arr);
        // Update the photo albums cache
        Photo::clearAlbumCache($page_owner_uid);
 
@@ -964,7 +921,6 @@ function photos_content(App $a)
                return;
        }
 
-       require_once 'include/bbcode.php';
        require_once 'include/security.php';
        require_once 'include/conversation.php';
 
@@ -1116,7 +1072,7 @@ function photos_content(App $a)
 
                $tpl = get_markup_template('photos_upload.tpl');
 
-               $aclselect_e = ($visitor ? '' : populate_acl($a->user));
+               $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
 
                $o .= replace_macros($tpl,[
                        '$pagename' => L10n::t('Upload Photos'),
@@ -1275,9 +1231,11 @@ function photos_content(App $a)
                $prevlink = '';
                $nextlink = '';
 
-               /// @todo This query is totally bad, the whole functionality has to be changed
-               // The query leads to a really intense used index.
-               // By now we hide it if someone wants to.
+               /*
+                * @todo This query is totally bad, the whole functionality has to be changed
+                * The query leads to a really intense used index.
+                * By now we hide it if someone wants to.
+                */
                if (!Config::get('system', 'no_count', false)) {
                        $order_field = defaults($_GET, 'order', '');
                        if ($order_field === 'posted') {
@@ -1312,8 +1270,10 @@ function photos_content(App $a)
                        }
                }
 
-               if (count($ph) == 1)
+               if (count($ph) == 1) {
                        $hires = $lores = $ph[0];
+               }
+
                if (count($ph) > 1) {
                        if ($ph[1]['scale'] == 2) {
                                // original is 640 or less, we can display it directly
@@ -1325,6 +1285,7 @@ function photos_content(App $a)
                }
 
                $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
+
                $tools = null;
                $lock = null;
 
@@ -1351,13 +1312,14 @@ function photos_content(App $a)
                        ]);
                }
 
-               if ($prevlink)
+               if ($prevlink) {
                        $prevlink = [$prevlink, '<div class="icon prev"></div>'] ;
+               }
 
                $photo = [
                        'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
                        'title'=> L10n::t('View Full Size'),
-                       'src'  => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
+                       'src'  => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . DateTimeFormat::utcNow('ymdhis'),
                        'height' => $hires['height'],
                        'width' => $hires['width'],
                        'album' => $hires['album'],
@@ -1423,11 +1385,7 @@ function photos_content(App $a)
                        );
 
                        if (local_user() && (local_user() == $link_item['uid'])) {
-                               q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
-                                       intval($link_item['parent']),
-                                       intval(local_user())
-                               );
-                               update_thread($link_item['parent']);
+                               Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
                        }
 
                        if ($link_item['coord']) {
@@ -1445,7 +1403,7 @@ function photos_content(App $a)
                                if (strlen($tag_str)) {
                                        $tag_str .= ', ';
                                }
-                               $tag_str .= bbcode($t);
+                               $tag_str .= BBCode::convert($t);
                        }
                        $tags = [L10n::t('Tags: '), $tag_str];
                        if ($cmd === 'edit') {
@@ -1461,7 +1419,7 @@ function photos_content(App $a)
 
                        $album_e = $ph[0]['album'];
                        $caption_e = $ph[0]['desc'];
-                       $aclselect_e = populate_acl($ph[0]);
+                       $aclselect_e = ACL::getFullSelectorHTML($ph[0]);
 
                        $edit = replace_macros($edit_tpl, [
                                '$id' => $ph[0]['id'],
@@ -1469,8 +1427,8 @@ function photos_content(App $a)
                                '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
                                '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
                                '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
-                               '$rotate_cw' => ['rotate', L10n::t('Rotate CW (right)'),1,''],
-                               '$rotate_ccw' => ['rotate', L10n::t('Rotate CCW (left)'),2,''],
+                               '$rotate_cw' => ['rotate', L10n::t("Rotate CW \x28right\x29"),1,''],
+                               '$rotate_ccw' => ['rotate', L10n::t("Rotate CCW \x28left\x29"),2,''],
 
                                '$nickname' => $a->data['user']['nickname'],
                                '$resource_id' => $ph[0]['resource-id'],
@@ -1580,14 +1538,10 @@ function photos_content(App $a)
                                                continue;
                                        }
 
-                                       $redirect_url = 'redir/' . $item['cid'];
-
-                                       if (local_user() && ($item['contact-uid'] == local_user())
-                                               && ($item['network'] == NETWORK_DFRN) && !$item['self']) {
-                                               $profile_url = $redirect_url;
+                                       $profile_url = Contact::MagicLinkById($item['cid']);
+                                       if (strpos($profile_url, 'redir/') === 0) {
                                                $sparkle = ' sparkle';
                                        } else {
-                                               $profile_url = $item['url'];
                                                $sparkle = '';
                                        }
 
@@ -1608,7 +1562,7 @@ function photos_content(App $a)
 
                                        $name_e = $profile_name;
                                        $title_e = $item['title'];
-                                       $body_e = bbcode($item['body']);
+                                       $body_e = BBCode::convert($item['body']);
 
                                        $comments .= replace_macros($template,[
                                                '$id' => $item['item_id'],
@@ -1618,7 +1572,7 @@ function photos_content(App $a)
                                                '$sparkle' => $sparkle,
                                                '$title' => $title_e,
                                                '$body' => $body_e,
-                                               '$ago' => relative_date($item['created']),
+                                               '$ago' => Temporal::getRelativeDate($item['created']),
                                                '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
                                                '$drop' => $drop,
                                                '$comment' => $comment
@@ -1717,8 +1671,9 @@ function photos_content(App $a)
                $twist = false;
                foreach ($r as $rr) {
                        //hide profile photos to others
-                       if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos')))
+                       if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
                                continue;
+                       }
 
                        $twist = !$twist;