7 use Friendica\Content\Nav;
8 use Friendica\Content\Pager;
9 use Friendica\Content\Text\BBCode;
10 use Friendica\Core\Renderer;
11 use Friendica\Core\Session;
12 use Friendica\Database\DBA;
14 use Friendica\Model\Attach;
15 use Friendica\Model\Contact;
16 use Friendica\Model\Item;
17 use Friendica\Model\Profile;
18 use Friendica\Model\User;
19 use Friendica\Module\BaseProfile;
20 use Friendica\Util\Security;
22 function videos_init(App $a)
24 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
28 Nav::setSelected('home');
32 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
36 if (!DBA::isResult($user)) {
40 $a->data['user'] = $user[0];
41 $a->profile_uid = $user[0]['uid'];
43 $profile = Profile::getByNickname($nick, $a->profile_uid);
45 $account_type = Contact::getAccountType($profile);
47 $tpl = Renderer::getMarkupTemplate('widget/vcard.tpl');
49 $vcard_widget = Renderer::replaceMacros($tpl, [
50 '$name' => $profile['name'],
51 '$photo' => $profile['photo'],
52 '$addr' => $profile['addr'] ?? '',
53 '$account_type' => $account_type,
54 '$about' => BBCode::convert($profile['about'] ?? ''),
57 // If not there, create 'aside' empty
58 if (!isset(DI::page()['aside'])) {
59 DI::page()['aside'] = '';
62 DI::page()['aside'] .= $vcard_widget;
64 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
65 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl);
71 function videos_post(App $a)
73 $owner_uid = $a->data['user']['uid'];
75 if (local_user() != $owner_uid) {
76 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
79 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
80 $video_id = $_POST['id'];
82 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
83 // delete the attachment
84 Attach::delete(['id' => $video_id, 'uid' => local_user()]);
86 // delete items where the attach is used
87 Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
88 '%attach/' . $video_id . '%',
93 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
97 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
100 function videos_content(App $a)
102 // URLs (most aren't currently implemented):
104 // videos/name/upload
105 // videos/name/upload/xxxxx (xxxxx is album name)
106 // videos/name/album/xxxxx
107 // videos/name/album/xxxxx/edit
108 // videos/name/video/xxxxx
109 // videos/name/video/xxxxx/edit
112 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
113 notice(DI::l10n()->t('Public access denied.') . EOL);
117 if (empty($a->data['user'])) {
118 notice(DI::l10n()->t('No videos selected') . EOL );
122 //$phototypes = Photo::supportedTypes();
124 $_SESSION['video_return'] = DI::args()->getCommand();
130 $datatype = $a->argv[2];
131 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
132 $datatype = 'upload';
134 $datatype = 'summary';
138 // Setup permissions structures
143 $remote_contact = false;
146 $owner_uid = $a->data['user']['uid'];
148 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
150 if ((local_user()) && (local_user() == $owner_uid)) {
152 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
153 $contact_id = Session::getRemoteContactID($owner_uid);
155 $remote_contact = true;
156 $visitor = $contact_id;
159 // perhaps they're visiting - but not a community page, so they wouldn't have write access
160 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
161 $contact_id = Session::getRemoteContactID($owner_uid);
162 $remote_contact = true;
165 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
166 notice(DI::l10n()->t('Access to this item is restricted.') . EOL);
170 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
175 $_is_owner = (local_user() && (local_user() == $owner_uid));
176 $o .= BaseProfile::getTabsHTML($a, 'videos', $_is_owner, $a->data['user']['nickname']);
181 if ($datatype === 'upload') {
182 return; // no uploading for now
184 // DELETED -- look at mod/photos.php if you want to implement
187 if ($datatype === 'album') {
188 return; // no albums for now
190 // DELETED -- look at mod/photos.php if you want to implement
194 if ($datatype === 'video') {
195 return; // no single video view for now
197 // DELETED -- look at mod/photos.php if you want to implement
200 // Default - show recent videos (no upload link for now)
204 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
205 $sql_extra GROUP BY hash",
206 intval($a->data['user']['uid'])
208 if (DBA::isResult($r)) {
212 $pager = new Pager(DI::args()->getQueryString(), 20);
214 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
215 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
217 WHERE `uid` = %d AND filetype LIKE '%%video%%'
218 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
219 intval($a->data['user']['uid']),
221 $pager->getItemsPerPage()
226 if (DBA::isResult($r)) {
227 foreach ($r as $rr) {
228 $alt_e = $rr['filename'];
229 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
231 $name_e = $rr['album'];
235 'link' => DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
236 'title' => DI::l10n()->t('View Video'),
237 'src' => DI::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
239 'mime' => $rr['filetype'],
241 'link' => DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
243 'alt' => DI::l10n()->t('View Album'),
249 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
250 $o .= Renderer::replaceMacros($tpl, [
251 '$title' => DI::l10n()->t('Recent Videos'),
252 '$can_post' => $can_post,
253 '$upload' => [DI::l10n()->t('Upload New Videos'), DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
254 '$videos' => $videos,
255 '$delete_url' => (($can_post) ? DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
258 $o .= $pager->renderFull($total);