7 use Friendica\Content\Nav;
8 use Friendica\Content\Pager;
9 use Friendica\Core\Renderer;
10 use Friendica\Core\Session;
11 use Friendica\Database\DBA;
13 use Friendica\Model\Attach;
14 use Friendica\Model\Contact;
15 use Friendica\Model\Item;
16 use Friendica\Model\Profile;
17 use Friendica\Model\User;
18 use Friendica\Util\Security;
20 function videos_init(App $a)
22 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
26 Nav::setSelected('home');
30 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
34 if (!DBA::isResult($user)) {
38 $a->data['user'] = $user[0];
39 $a->profile_uid = $user[0]['uid'];
41 $profile = Profile::getByNickname($nick, $a->profile_uid);
43 $account_type = Contact::getAccountType($profile);
45 $tpl = Renderer::getMarkupTemplate("widget/vcard.tpl");
47 $vcard_widget = Renderer::replaceMacros($tpl, [
48 '$name' => $profile['name'],
49 '$photo' => $profile['photo'],
50 '$addr' => $profile['addr'] ?? '',
51 '$account_type' => $account_type,
52 '$pdesc' => $profile['pdesc'] ?? '',
55 // If not there, create 'aside' empty
56 if (!isset(DI::page()['aside'])) {
57 DI::page()['aside'] = '';
60 DI::page()['aside'] .= $vcard_widget;
62 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
63 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl);
69 function videos_post(App $a)
71 $owner_uid = $a->data['user']['uid'];
73 if (local_user() != $owner_uid) {
74 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
77 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
78 $video_id = $_POST['id'];
80 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
81 // delete the attachment
82 Attach::delete(['id' => $video_id, 'uid' => local_user()]);
84 // delete items where the attach is used
85 Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
86 '%attach/' . $video_id . '%',
91 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
95 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
98 function videos_content(App $a)
100 // URLs (most aren't currently implemented):
102 // videos/name/upload
103 // videos/name/upload/xxxxx (xxxxx is album name)
104 // videos/name/album/xxxxx
105 // videos/name/album/xxxxx/edit
106 // videos/name/video/xxxxx
107 // videos/name/video/xxxxx/edit
110 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
111 notice(DI::l10n()->t('Public access denied.') . EOL);
115 if (empty($a->data['user'])) {
116 notice(DI::l10n()->t('No videos selected') . EOL );
120 //$phototypes = Photo::supportedTypes();
122 $_SESSION['video_return'] = DI::args()->getCommand();
128 $datatype = $a->argv[2];
129 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
130 $datatype = 'upload';
132 $datatype = 'summary';
136 // Setup permissions structures
141 $remote_contact = false;
144 $owner_uid = $a->data['user']['uid'];
146 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
148 if ((local_user()) && (local_user() == $owner_uid)) {
150 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
151 $contact_id = Session::getRemoteContactID($owner_uid);
153 $remote_contact = true;
154 $visitor = $contact_id;
157 // perhaps they're visiting - but not a community page, so they wouldn't have write access
158 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
159 $contact_id = Session::getRemoteContactID($owner_uid);
160 $remote_contact = true;
163 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
164 notice(DI::l10n()->t('Access to this item is restricted.') . EOL);
168 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
173 $_is_owner = (local_user() && (local_user() == $owner_uid));
174 $o .= Profile::getTabs($a, 'videos', $_is_owner, $a->data['user']['nickname']);
179 if ($datatype === 'upload') {
180 return; // no uploading for now
182 // DELETED -- look at mod/photos.php if you want to implement
185 if ($datatype === 'album') {
186 return; // no albums for now
188 // DELETED -- look at mod/photos.php if you want to implement
192 if ($datatype === 'video') {
193 return; // no single video view for now
195 // DELETED -- look at mod/photos.php if you want to implement
198 // Default - show recent videos (no upload link for now)
202 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
203 $sql_extra GROUP BY hash",
204 intval($a->data['user']['uid'])
206 if (DBA::isResult($r)) {
210 $pager = new Pager(DI::args()->getQueryString(), 20);
212 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
213 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
215 WHERE `uid` = %d AND filetype LIKE '%%video%%'
216 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
217 intval($a->data['user']['uid']),
219 $pager->getItemsPerPage()
224 if (DBA::isResult($r)) {
225 foreach ($r as $rr) {
226 $alt_e = $rr['filename'];
227 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
229 $name_e = $rr['album'];
233 'link' => DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
234 'title' => DI::l10n()->t('View Video'),
235 'src' => DI::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
237 'mime' => $rr['filetype'],
239 'link' => DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
241 'alt' => DI::l10n()->t('View Album'),
247 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
248 $o .= Renderer::replaceMacros($tpl, [
249 '$title' => DI::l10n()->t('Recent Videos'),
250 '$can_post' => $can_post,
251 '$upload' => [DI::l10n()->t('Upload New Videos'), DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
252 '$videos' => $videos,
253 '$delete_url' => (($can_post) ? DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
256 $o .= $pager->renderFull($total);