7 use Friendica\Content\Nav;
8 use Friendica\Content\Pager;
9 use Friendica\Core\Config;
10 use Friendica\Core\L10n;
11 use Friendica\Core\Renderer;
12 use Friendica\Core\System;
13 use Friendica\Database\DBA;
14 use Friendica\Model\Contact;
15 use Friendica\Model\Group;
16 use Friendica\Model\Item;
17 use Friendica\Model\Profile;
18 use Friendica\Protocol\DFRN;
19 use Friendica\Util\Security;
21 function videos_init(App $a)
24 DFRN::autoRedir($a, $a->argv[1]);
27 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
31 Nav::setSelected('home');
37 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
41 if (!DBA::isResult($user)) {
45 $a->data['user'] = $user[0];
46 $a->profile_uid = $user[0]['uid'];
48 $profile = Profile::getByNickname($nick, $a->profile_uid);
50 $account_type = Contact::getAccountType($profile);
52 $tpl = Renderer::getMarkupTemplate("vcard-widget.tpl");
54 $vcard_widget = Renderer::replaceMacros($tpl, [
55 '$name' => $profile['name'],
56 '$photo' => $profile['photo'],
57 '$addr' => defaults($profile, 'addr', ''),
58 '$account_type' => $account_type,
59 '$pdesc' => defaults($profile, 'pdesc', ''),
62 /// @TODO Old-lost code?
63 /*$sql_extra = Security::getPermissionsSQLByUserId($a->data['user']['uid']);
65 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
66 intval($a->data['user']['uid'])
70 $a->data['albums'] = $albums;
72 $albums_visible = ((intval($a->data['user']['hidewall']) && (!local_user()) && (!remote_user())) ? false : true);
75 $o .= '<div id="sidebar-photos-albums" class="widget">';
76 $o .= '<h3>' . '<a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '">' . L10n::t('Photo Albums') . '</a></h3>';
79 foreach($albums as $album) {
81 // don't show contact photos. We once translated this name, but then you could still access it under
82 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
84 if((!strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos')))
86 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
90 if(local_user() && $a->data['user']['uid'] == local_user()) {
91 $o .= '<div id="photo-albums-upload-link"><a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .L10n::t('Upload New Photos') . '</a></div>';
97 // If not there, create 'aside' empty
98 if (!isset($a->page['aside'])) {
99 $a->page['aside'] = '';
102 $a->page['aside'] .= $vcard_widget;
104 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
105 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
106 '$baseurl' => System::baseUrl(),
113 function videos_post(App $a)
115 $owner_uid = $a->data['user']['uid'];
117 if (local_user() != $owner_uid) {
118 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
121 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
122 // Check if we should do HTML-based delete confirmation
123 if (empty($_REQUEST['confirm'])) {
124 if (!empty($_REQUEST['canceled'])) {
125 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
128 $drop_url = $a->query_string;
130 $a->page['content'] = Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
132 '$message' => L10n::t('Do you really want to delete this video?'),
134 ['name' => 'id' , 'value' => $_POST['id']],
135 ['name' => 'delete', 'value' => 'x']
137 '$confirm' => L10n::t('Delete Video'),
138 '$confirm_url' => $drop_url,
139 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
140 '$cancel' => L10n::t('Cancel'),
144 $a->error = 1; // Set $a->error so the other module functions don't execute
149 $video_id = $_POST['id'];
151 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
152 intval(local_user()),
153 DBA::escape($video_id)
156 if (DBA::isResult($r)) {
157 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
158 intval(local_user()),
159 DBA::escape($video_id)
162 $i = q("SELECT `id` FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
163 DBA::escape($video_id),
167 if (DBA::isResult($i)) {
168 Item::deleteForUser(['id' => $i[0]['id']], local_user());
172 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
173 return; // NOTREACHED
176 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
179 function videos_content(App $a)
181 // URLs (most aren't currently implemented):
183 // videos/name/upload
184 // videos/name/upload/xxxxx (xxxxx is album name)
185 // videos/name/album/xxxxx
186 // videos/name/album/xxxxx/edit
187 // videos/name/video/xxxxx
188 // videos/name/video/xxxxx/edit
191 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
192 notice(L10n::t('Public access denied.') . EOL);
196 if (empty($a->data['user'])) {
197 notice(L10n::t('No videos selected') . EOL );
201 //$phototypes = Photo::supportedTypes();
203 $_SESSION['video_return'] = $a->cmd;
209 $datatype = $a->argv[2];
210 $datum = $a->argv[3];
211 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
212 $datatype = 'upload';
214 $datatype = 'summary';
224 // Setup permissions structures
229 $remote_contact = false;
232 $owner_uid = $a->data['user']['uid'];
234 $community_page = (($a->data['user']['page-flags'] == Contact::PAGE_COMMUNITY) ? true : false);
236 if ((local_user()) && (local_user() == $owner_uid)) {
238 } elseif ($community_page && remote_user()) {
239 if (!empty($_SESSION['remote'])) {
240 foreach ($_SESSION['remote'] as $v) {
241 if ($v['uid'] == $owner_uid) {
242 $contact_id = $v['cid'];
248 if ($contact_id > 0) {
249 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
254 if (DBA::isResult($r)) {
257 $remote_contact = true;
258 $visitor = $contact_id;
265 // perhaps they're visiting - but not a community page, so they wouldn't have write access
266 if (remote_user() && (!$visitor)) {
269 if (!empty($_SESSION['remote'])) {
270 foreach($_SESSION['remote'] as $v) {
271 if($v['uid'] == $owner_uid) {
272 $contact_id = $v['cid'];
278 if ($contact_id > 0) {
279 $groups = Group::getIdsByContactId($contact_id);
280 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
285 if (DBA::isResult($r)) {
287 $remote_contact = true;
292 if (!$remote_contact && local_user()) {
293 $contact_id = $_SESSION['cid'];
294 $contact = $a->contact;
297 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (!$remote_contact)) {
298 notice(L10n::t('Access to this item is restricted.') . EOL);
302 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
307 $_is_owner = (local_user() && (local_user() == $owner_uid));
308 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
313 if ($datatype === 'upload') {
314 return; // no uploading for now
316 // DELETED -- look at mod/photos.php if you want to implement
319 if ($datatype === 'album') {
320 return; // no albums for now
322 // DELETED -- look at mod/photos.php if you want to implement
326 if ($datatype === 'video') {
327 return; // no single video view for now
329 // DELETED -- look at mod/photos.php if you want to implement
332 // Default - show recent videos (no upload link for now)
336 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
337 $sql_extra GROUP BY hash",
338 intval($a->data['user']['uid'])
340 if (DBA::isResult($r)) {
344 $pager = new Pager($a->query_string, 20);
346 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
347 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
349 WHERE `uid` = %d AND filetype LIKE '%%video%%'
350 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
351 intval($a->data['user']['uid']),
353 $pager->getItemsPerPage()
358 if (DBA::isResult($r)) {
359 foreach ($r as $rr) {
360 $alt_e = $rr['filename'];
361 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
363 $name_e = $rr['album'];
367 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
368 'title' => L10n::t('View Video'),
369 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
371 'mime' => $rr['filetype'],
373 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
375 'alt' => L10n::t('View Album'),
381 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
382 $o .= Renderer::replaceMacros($tpl, [
383 '$title' => L10n::t('Recent Videos'),
384 '$can_post' => $can_post,
385 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
386 '$videos' => $videos,
387 '$delete_url' => (($can_post) ? System::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
390 $o .= $pager->renderFull($total);