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\Attach;
15 use Friendica\Model\Contact;
16 use Friendica\Model\Group;
17 use Friendica\Model\Item;
18 use Friendica\Model\Profile;
19 use Friendica\Model\User;
20 use Friendica\Protocol\DFRN;
21 use Friendica\Util\Security;
23 function videos_init(App $a)
26 DFRN::autoRedir($a, $a->argv[1]);
29 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
33 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 // If not there, create 'aside' empty
63 if (!isset($a->page['aside'])) {
64 $a->page['aside'] = '';
67 $a->page['aside'] .= $vcard_widget;
69 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
70 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl);
76 function videos_post(App $a)
78 $owner_uid = $a->data['user']['uid'];
80 if (local_user() != $owner_uid) {
81 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
84 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
85 // Check if we should do HTML-based delete confirmation
86 if (empty($_REQUEST['confirm'])) {
87 if (!empty($_REQUEST['canceled'])) {
88 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
91 $drop_url = $a->query_string;
93 $a->page['content'] = Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
95 '$message' => L10n::t('Do you really want to delete this video?'),
97 ['name' => 'id' , 'value' => $_POST['id']],
98 ['name' => 'delete', 'value' => 'x']
100 '$confirm' => L10n::t('Delete Video'),
101 '$confirm_url' => $drop_url,
102 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
103 '$cancel' => L10n::t('Cancel'),
107 $a->error = 1; // Set $a->error so the other module functions don't execute
112 $video_id = $_POST['id'];
114 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
115 // delete the attachment
116 Attach::delete(['id' => $video_id, 'uid' => local_user()]);
118 // delete items where the attach is used
119 Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
120 '%attach/' . $video_id . '%',
125 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
126 return; // NOTREACHED
129 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
132 function videos_content(App $a)
134 // URLs (most aren't currently implemented):
136 // videos/name/upload
137 // videos/name/upload/xxxxx (xxxxx is album name)
138 // videos/name/album/xxxxx
139 // videos/name/album/xxxxx/edit
140 // videos/name/video/xxxxx
141 // videos/name/video/xxxxx/edit
144 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
145 notice(L10n::t('Public access denied.') . EOL);
149 if (empty($a->data['user'])) {
150 notice(L10n::t('No videos selected') . EOL );
154 //$phototypes = Photo::supportedTypes();
156 $_SESSION['video_return'] = $a->cmd;
162 $datatype = $a->argv[2];
163 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
164 $datatype = 'upload';
166 $datatype = 'summary';
170 // Setup permissions structures
175 $remote_contact = false;
178 $owner_uid = $a->data['user']['uid'];
180 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
182 if ((local_user()) && (local_user() == $owner_uid)) {
184 } elseif ($community_page && remote_user()) {
185 if (!empty($_SESSION['remote'])) {
186 foreach ($_SESSION['remote'] as $v) {
187 if ($v['uid'] == $owner_uid) {
188 $contact_id = $v['cid'];
194 if ($contact_id > 0) {
195 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
200 if (DBA::isResult($r)) {
202 $remote_contact = true;
203 $visitor = $contact_id;
210 // perhaps they're visiting - but not a community page, so they wouldn't have write access
211 if (remote_user() && (!$visitor)) {
214 if (!empty($_SESSION['remote'])) {
215 foreach($_SESSION['remote'] as $v) {
216 if($v['uid'] == $owner_uid) {
217 $contact_id = $v['cid'];
223 if ($contact_id > 0) {
224 $groups = Group::getIdsByContactId($contact_id);
225 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
230 if (DBA::isResult($r)) {
231 $remote_contact = true;
236 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (!$remote_contact)) {
237 notice(L10n::t('Access to this item is restricted.') . EOL);
241 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
246 $_is_owner = (local_user() && (local_user() == $owner_uid));
247 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
252 if ($datatype === 'upload') {
253 return; // no uploading for now
255 // DELETED -- look at mod/photos.php if you want to implement
258 if ($datatype === 'album') {
259 return; // no albums for now
261 // DELETED -- look at mod/photos.php if you want to implement
265 if ($datatype === 'video') {
266 return; // no single video view for now
268 // DELETED -- look at mod/photos.php if you want to implement
271 // Default - show recent videos (no upload link for now)
275 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
276 $sql_extra GROUP BY hash",
277 intval($a->data['user']['uid'])
279 if (DBA::isResult($r)) {
283 $pager = new Pager($a->query_string, 20);
285 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
286 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
288 WHERE `uid` = %d AND filetype LIKE '%%video%%'
289 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
290 intval($a->data['user']['uid']),
292 $pager->getItemsPerPage()
297 if (DBA::isResult($r)) {
298 foreach ($r as $rr) {
299 $alt_e = $rr['filename'];
300 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
302 $name_e = $rr['album'];
306 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
307 'title' => L10n::t('View Video'),
308 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
310 'mime' => $rr['filetype'],
312 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
314 'alt' => L10n::t('View Album'),
320 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
321 $o .= Renderer::replaceMacros($tpl, [
322 '$title' => L10n::t('Recent Videos'),
323 '$can_post' => $can_post,
324 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
325 '$videos' => $videos,
326 '$delete_url' => (($can_post) ? System::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
329 $o .= $pager->renderFull($total);