]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
More indentions
[friendica.git] / mod / photos.php
index a9e77c7c39089590f8c00ee179e29d853d4014ac..9bc870ca13fe34265dac0fbf5d08071c1d7f33af 100644 (file)
@@ -2,13 +2,16 @@
 /**
  * @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;
@@ -19,13 +22,12 @@ 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) {
 
@@ -282,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);
@@ -355,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']);
@@ -399,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 &&
@@ -643,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) {
@@ -735,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');
                }
        }
 
@@ -870,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);
 
@@ -896,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']);
        }
@@ -965,7 +921,6 @@ function photos_content(App $a)
                return;
        }
 
-       require_once 'include/bbcode.php';
        require_once 'include/security.php';
        require_once 'include/conversation.php';
 
@@ -1117,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'),
@@ -1276,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') {
@@ -1313,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
@@ -1326,6 +1285,7 @@ function photos_content(App $a)
                }
 
                $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
+
                $tools = null;
                $lock = null;
 
@@ -1352,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'],
@@ -1424,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']) {
@@ -1446,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') {
@@ -1462,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'],
@@ -1581,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 = '';
                                        }
 
@@ -1609,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'],
@@ -1619,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
@@ -1718,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;