X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fphotos.php;h=e823da59ff1f1a451e56ba6e9659f6cb2495b9db;hb=22bbfdadd058d2bddc780f220d77918cf872cb64;hp=30d3728d36865db24d5d14441daec2752894d308;hpb=8329705ebab61159b114b274e794bf6c3d6a6a95;p=friendica.git diff --git a/mod/photos.php b/mod/photos.php index 30d3728d36..e823da59ff 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -19,6 +19,7 @@ use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\Photo; use Friendica\Model\Profile; +use Friendica\Model\User; use Friendica\Network\Probe; use Friendica\Object\Image; use Friendica\Protocol\DFRN; @@ -171,23 +172,18 @@ function photos_post(App $a) } if (!$can_post) { - notice(L10n::t('Permission denied.') . EOL ); + notice(L10n::t('Permission denied.') . EOL); killme(); } - $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid` - WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1", - intval($page_owner_uid) - ); + $owner_record = User::getOwnerDataById($page_owner_uid); - if (!DBM::is_result($r)) { + if (!$owner_record) { notice(L10n::t('Contact information unavailable') . EOL); logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid); killme(); } - $owner_record = $r[0]; - if ($a->argc > 3 && $a->argv[2] === 'album') { $album = hex2bin($a->argv[3]); @@ -279,7 +275,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) ); @@ -376,7 +372,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(); @@ -454,7 +450,7 @@ function photos_post(App $a) if (!$item_id) { // Create item container $title = ''; - $uri = item_new_uri($a->get_hostname(),$page_owner_uid); + $uri = Item::newURI($page_owner_uid); $arr = []; $arr['guid'] = get_guid(32); @@ -487,14 +483,11 @@ function photos_post(App $a) } if ($item_id) { - $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($item_id), - intval($page_owner_uid) - ); + $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]); } - if (DBM::is_result($r)) { - $old_tag = $r[0]['tag']; - $old_inform = $r[0]['inform']; + if (DBM::is_result($item)) { + $old_tag = $item['tag']; + $old_inform = $item['inform']; } if (strlen($rawtags)) { @@ -624,7 +617,7 @@ function photos_post(App $a) if (count($taginfo)) { foreach ($taginfo as $tagged) { - $uri = item_new_uri($a->get_hostname(), $page_owner_uid); + $uri = Item::newURI($page_owner_uid); $arr = []; $arr['guid'] = get_guid(32); @@ -848,7 +841,7 @@ function photos_post(App $a) $smallest = 2; } - $uri = item_new_uri($a->get_hostname(), $page_owner_uid); + $uri = Item::newURI($page_owner_uid); // Create item container $lat = $lon = null; @@ -925,7 +918,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; } @@ -1223,7 +1216,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,9 +1224,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') { @@ -1268,8 +1263,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 @@ -1281,6 +1278,7 @@ function photos_content(App $a) } $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']); + $tools = null; $lock = null; @@ -1291,15 +1289,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, @@ -1307,8 +1305,9 @@ function photos_content(App $a) ]); } - if ($prevlink) + if ($prevlink) { $prevlink = [$prevlink, ''] ; + } $photo = [ 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']], @@ -1333,7 +1332,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) ); @@ -1341,7 +1341,8 @@ function photos_content(App $a) $link_item = []; if (DBM::is_result($linked_items)) { - $link_item = $linked_items[0]; + // This is a workaround to not being forced to rewrite the while $sql_extra handling + $link_item = Item::selectFirstForUser(local_user(), [], ['id' => $linked_items[0]['id']]); $r = q("SELECT COUNT(*) AS `total` FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` @@ -1532,14 +1533,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 = ''; } @@ -1669,8 +1666,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;