"Video" is replaced by a "Media" tab in contact and profile

This commit is contained in:
Michael 2021-10-02 15:09:43 +00:00
parent 1979b4775d
commit c3554ac0f4
8 changed files with 286 additions and 484 deletions

View file

@ -49,12 +49,13 @@ General
* h - Only show hidden contacts
* e - Edit contact groups
../contacts (single contact view)
../contact (single contact view)
-------------------------------
* m - Status messages
* p - Posts and Comments
* d - Media
* o - Profile
* t - Contacts
* d - Common friends
* r - Advanced
../message

View file

@ -1,261 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
use Friendica\App;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Content\Widget;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Attach;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Module\BaseProfile;
use Friendica\Security\Security;
use Friendica\Network\HTTPException;
function videos_init(App $a)
{
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
return;
}
Nav::setSelected('home');
if (DI::args()->getArgc() > 1) {
$owner = User::getOwnerDataByNick(DI::args()->getArgv()[1]);
if (empty($owner)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
// If not there, create 'aside' empty
if (!isset(DI::page()['aside'])) {
DI::page()['aside'] = '';
}
DI::page()['aside'] .= Widget\VCard::getHTML($owner);
$tpl = Renderer::getMarkupTemplate("videos_head.tpl");
DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl);
}
return;
}
function videos_post(App $a)
{
$user = User::getByNickname(DI::args()->getArgv()[1]);
if (!DBA::isResult($user)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
if (local_user() != $user['uid']) {
DI::baseUrl()->redirect('videos/' . $user['nickname']);
}
if ((DI::args()->getArgc() == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
$video_id = $_POST['id'];
if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
// delete the attachment
Attach::delete(['id' => $video_id, 'uid' => local_user()]);
// delete items where the attach is used
Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
'%attach/' . $video_id . '%',
local_user()
], local_user());
}
DI::baseUrl()->redirect('videos/' . $user['nickname']);
return; // NOTREACHED
}
DI::baseUrl()->redirect('videos/' . $user['nickname']);
}
function videos_content(App $a)
{
// URLs (most aren't currently implemented):
// videos/name
// videos/name/upload
// videos/name/upload/xxxxx (xxxxx is album name)
// videos/name/album/xxxxx
// videos/name/album/xxxxx/edit
// videos/name/video/xxxxx
// videos/name/video/xxxxx/edit
$user = User::getByNickname(DI::args()->getArgv()[1]);
if (!DBA::isResult($user)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
notice(DI::l10n()->t('Public access denied.'));
return;
}
if (empty($user)) {
notice(DI::l10n()->t('No videos selected') . EOL );
return;
}
$profile = Profile::getByUID($user['uid']);
//$phototypes = Photo::supportedTypes();
$_SESSION['video_return'] = DI::args()->getCommand();
//
// Parse arguments
//
if (DI::args()->getArgc() > 3) {
$datatype = DI::args()->getArgv()[2];
} elseif((DI::args()->getArgc() > 2) && (DI::args()->getArgv()[2] === 'upload')) {
$datatype = 'upload';
} else {
$datatype = 'summary';
}
//
// Setup permissions structures
//
$can_post = false;
$visitor = 0;
$remote_contact = false;
$contact_id = 0;
$community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
if ((local_user()) && (local_user() == $user['uid'])) {
$can_post = true;
} elseif ($community_page && !empty(Session::getRemoteContactID($user['uid']))) {
$contact_id = Session::getRemoteContactID($user['uid']);
$can_post = true;
$remote_contact = true;
$visitor = $contact_id;
}
// perhaps they're visiting - but not a community page, so they wouldn't have write access
if (!empty(Session::getRemoteContactID($user['uid'])) && !$visitor) {
$contact_id = Session::getRemoteContactID($user['uid']);
$remote_contact = true;
}
if ($user['hidewall'] && (local_user() != $user['uid']) && !$remote_contact) {
notice(DI::l10n()->t('Access to this item is restricted.'));
return;
}
$sql_extra = Security::getPermissionsSQLByUserId($user['uid']);
$o = "";
// tabs
$_is_owner = (local_user() && (local_user() == $user['uid']));
$o .= BaseProfile::getTabsHTML($a, 'videos', $_is_owner, $user['nickname'], $profile['hide-friends']);
//
// dispatch request
//
if ($datatype === 'upload') {
return; // no uploading for now
// DELETED -- look at mod/photos.php if you want to implement
}
if ($datatype === 'album') {
return; // no albums for now
// DELETED -- look at mod/photos.php if you want to implement
}
if ($datatype === 'video') {
return; // no single video view for now
// DELETED -- look at mod/photos.php if you want to implement
}
// Default - show recent videos (no upload link for now)
//$o = '';
$total = 0;
$r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
$sql_extra GROUP BY hash",
intval($user['uid'])
);
if (DBA::isResult($r)) {
$total = count($r);
}
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
$r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
FROM `attach`
WHERE `uid` = %d AND filetype LIKE '%%video%%'
$sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
intval($user['uid']),
$pager->getStart(),
$pager->getItemsPerPage()
);
$videos = [];
if (DBA::isResult($r)) {
foreach ($r as $rr) {
$alt_e = $rr['filename'];
/// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
$rr['album'] = '';
$name_e = $rr['album'];
$videos[] = [
'id' => $rr['id'],
'link' => DI::baseUrl() . '/videos/' . $user['nickname'] . '/video/' . $rr['hash'],
'title' => DI::l10n()->t('View Video'),
'src' => DI::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
'alt' => $alt_e,
'mime' => $rr['filetype'],
'album' => [
'link' => DI::baseUrl() . '/videos/' . $user['nickname'] . '/album/' . bin2hex($rr['album']),
'name' => $name_e,
'alt' => DI::l10n()->t('View Album'),
],
];
}
}
$tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
$o .= Renderer::replaceMacros($tpl, [
'$title' => DI::l10n()->t('Recent Videos'),
'$can_post' => $can_post,
'$upload' => [DI::l10n()->t('Upload New Videos'), DI::baseUrl() . '/videos/' . $user['nickname'] . '/upload'],
'$videos' => $videos,
'$delete_url' => (($can_post) ? DI::baseUrl() . '/videos/' . $user['nickname'] : false)
]);
$o .= $pager->renderFull($total);
return $o;
}

View file

@ -1346,12 +1346,13 @@ class Contact
* @param bool $thread_mode
* @param int $update Update mode
* @param int $parent Item parent ID for the update mode
* @param bool $only_media Only display media content
* @return string posts in HTML
* @throws \Exception
*/
public static function getPostsFromUrl($contact_url, $thread_mode = false, $update = 0, $parent = 0)
public static function getPostsFromUrl($contact_url, $thread_mode = false, $update = 0, $parent = 0, bool $only_media = false)
{
return self::getPostsFromId(self::getIdForURL($contact_url), $thread_mode, $update, $parent);
return self::getPostsFromId(self::getIdForURL($contact_url), $thread_mode, $update, $parent, $only_media);
}
/**
@ -1360,14 +1361,14 @@ class Contact
* @param int $cid Contact ID
* @param bool $thread_mode
* @param int $update Update mode
* @param int $parent Item parent ID for the update mode
* @param int $parent Item parent ID for the update mode
* @param bool $only_media Only display media content
* @return string posts in HTML
* @throws \Exception
*/
public static function getPostsFromId($cid, $thread_mode = false, $update = 0, $parent = 0)
public static function getPostsFromId($cid, $thread_mode = false, $update = 0, $parent = 0, bool $only_media = false)
{
$a = DI::app();
Logger::info('Blubb-1', ['cid' => $cid]);
$contact = DBA::selectFirst('contact', ['contact-type', 'network'], ['id' => $cid]);
if (!DBA::isResult($contact)) {
return '';
@ -1398,6 +1399,11 @@ class Contact
}
}
If ($only_media) {
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-media` WHERE `type` IN (?, ?, ?))",
Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]);
}
if (DI::mode()->isMobile()) {
$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
DI::config()->get('system', 'itemspage_network_mobile'));
@ -1423,6 +1429,7 @@ class Contact
$o .= DI::conversation()->create($items, 'contacts', $update, false, 'commented', local_user());
} else {
$items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params));
Logger::info('Blubb-2a', ['cid' => $cid, 'condition' => $condition]);
$o .= DI::conversation()->create($items, 'contact-posts', $update);
}

View file

@ -68,15 +68,14 @@ class BaseProfile extends BaseModule
'id' => 'photo-tab',
'accesskey' => 'h',
],
// @todo Currently deactivated since it doesn't really work
// [
// 'label' => DI::l10n()->t('Videos'),
// 'url' => DI::baseUrl() . '/videos/' . $nickname,
// 'sel' => $current == 'videos' ? 'active' : '',
// 'title' => DI::l10n()->t('Videos'),
// 'id' => 'video-tab',
// 'accesskey' => 'v',
// ],
[
'label' => DI::l10n()->t('Media'),
'url' => $baseProfileUrl . '/media',
'sel' => $current == 'media' ? 'active' : '',
'title' => DI::l10n()->t('Media'),
'id' => 'media-tab',
'accesskey' => 'd',
],
];
// the calendar link for the full featured events calendar

View file

@ -52,6 +52,7 @@ class Contact extends BaseModule
const TAB_PROFILE = 3;
const TAB_CONTACTS = 4;
const TAB_ADVANCED = 5;
const TAB_MEDIA = 6;
private static function batchActions()
{
@ -372,11 +373,11 @@ class Contact extends BaseModule
}
if ($cmd === 'posts') {
return self::getPostsHTML($a, $contact_id);
return self::getPostsHTML($contact_id, false);
}
if ($cmd === 'media') {
return self::getPostsHTML($a, $contact_id); // TODO
return self::getPostsHTML($contact_id, true);
}
if ($cmd === 'conversations') {
@ -915,6 +916,14 @@ class Contact extends BaseModule
'id' => 'posts-tab',
'accesskey' => 'p',
],
[
'label' => DI::l10n()->t('Media'),
'url' => 'contact/' . $pcid . '/media',
'sel' => (($active_tab == self::TAB_MEDIA) ? 'active' : ''),
'title' => DI::l10n()->t('Posts containing media objects'),
'id' => 'media-tab',
'accesskey' => 'd',
],
[
'label' => DI::l10n()->t('Profile'),
'url' => 'contact/' . $cid,
@ -983,7 +992,7 @@ class Contact extends BaseModule
return $o;
}
private static function getPostsHTML($a, $contact_id)
private static function getPostsHTML(int $contact_id, bool $only_media)
{
$contact = DBA::selectFirst('contact', ['uid', 'url', 'id'], ['id' => $contact_id, 'deleted' => false]);
@ -999,9 +1008,9 @@ class Contact extends BaseModule
DI::page()['aside'] = Widget\VCard::getHTML($profiledata);
if ($contact['uid'] == 0) {
$o .= Model\Contact::getPostsFromId($contact['id']);
$o .= Model\Contact::getPostsFromId($contact['id'], false, 0, 0, $only_media);
} else {
$o .= Model\Contact::getPostsFromUrl($contact['url']);
$o .= Model\Contact::getPostsFromUrl($contact['url'], false, 0, 0, $only_media);
}
}

View file

@ -0,0 +1,53 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Module\Profile;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile as ProfileModel;
use Friendica\Module\BaseProfile;
use Friendica\Network\HTTPException;
class Media extends BaseProfile
{
public static function content(array $parameters = [])
{
$a = DI::app();
$profile = ProfileModel::load($a, $parameters['nickname']);
if (empty($profile)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
}
if (!$profile['net-publish']) {
DI::page()['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
}
$is_owner = local_user() == $profile['uid'];
$o = self::getTabsHTML($a, 'media', $is_owner, $profile['nickname'], $profile['hide-friends']);
$o .= Contact::getPostsFromUrl($profile['url'], false, 0, 0, true);
return $o;
}
}

View file

@ -37,6 +37,7 @@ $profileRoutes = [
'/contacts/common' => [Module\Profile\Common::class, [R::GET]],
'/contacts[/{type}]' => [Module\Profile\Contacts::class, [R::GET]],
'/status[/{category}[/{date1}[/{date2}]]]' => [Module\Profile\Status::class, [R::GET]],
'/media' => [Module\Profile\Media::class, [R::GET]],
];
return [
@ -237,6 +238,7 @@ return [
'/{id:\d+}/contacts[/{type}]' => [Module\Contact\Contacts::class, [R::GET]],
'/{id:\d+}/drop' => [Module\Contact::class, [R::GET]],
'/{id:\d+}/ignore' => [Module\Contact::class, [R::GET]],
'/{id:\d+}/media' => [Module\Contact::class, [R::GET]],
'/{id:\d+}/poke' => [Module\Contact\Poke::class, [R::GET, R::POST]],
'/{id:\d+}/posts' => [Module\Contact::class, [R::GET]],
'/{id:\d+}/update' => [Module\Contact::class, [R::GET]],

File diff suppressed because it is too large Load diff