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\Protocol\DFRN;
20 use Friendica\Util\Security;
22 function videos_init(App $a)
25 DFRN::autoRedir($a, $a->argv[1]);
28 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
32 Nav::setSelected('home');
36 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
40 if (!DBA::isResult($user)) {
44 $a->data['user'] = $user[0];
45 $a->profile_uid = $user[0]['uid'];
47 $profile = Profile::getByNickname($nick, $a->profile_uid);
49 $account_type = Contact::getAccountType($profile);
51 $tpl = Renderer::getMarkupTemplate("vcard-widget.tpl");
53 $vcard_widget = Renderer::replaceMacros($tpl, [
54 '$name' => $profile['name'],
55 '$photo' => $profile['photo'],
56 '$addr' => defaults($profile, 'addr', ''),
57 '$account_type' => $account_type,
58 '$pdesc' => defaults($profile, 'pdesc', ''),
61 // If not there, create 'aside' empty
62 if (!isset($a->page['aside'])) {
63 $a->page['aside'] = '';
66 $a->page['aside'] .= $vcard_widget;
68 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
69 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
70 '$baseurl' => System::baseUrl(),
77 function videos_post(App $a)
79 $owner_uid = $a->data['user']['uid'];
81 if (local_user() != $owner_uid) {
82 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
85 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
86 // Check if we should do HTML-based delete confirmation
87 if (empty($_REQUEST['confirm'])) {
88 if (!empty($_REQUEST['canceled'])) {
89 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
92 $drop_url = $a->query_string;
94 $a->page['content'] = Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
96 '$message' => L10n::t('Do you really want to delete this video?'),
98 ['name' => 'id' , 'value' => $_POST['id']],
99 ['name' => 'delete', 'value' => 'x']
101 '$confirm' => L10n::t('Delete Video'),
102 '$confirm_url' => $drop_url,
103 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
104 '$cancel' => L10n::t('Cancel'),
108 $a->error = 1; // Set $a->error so the other module functions don't execute
113 $video_id = $_POST['id'];
115 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
116 // delete the attachment
117 Attach::delete(['id' => $video_id, 'uid' => local_user()]);
119 // delete items where the attach is used
120 Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
121 '%attach/' . $video_id . '%',
126 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
127 return; // NOTREACHED
130 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
133 function videos_content(App $a)
135 // URLs (most aren't currently implemented):
137 // videos/name/upload
138 // videos/name/upload/xxxxx (xxxxx is album name)
139 // videos/name/album/xxxxx
140 // videos/name/album/xxxxx/edit
141 // videos/name/video/xxxxx
142 // videos/name/video/xxxxx/edit
145 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
146 notice(L10n::t('Public access denied.') . EOL);
150 if (empty($a->data['user'])) {
151 notice(L10n::t('No videos selected') . EOL );
155 //$phototypes = Photo::supportedTypes();
157 $_SESSION['video_return'] = $a->cmd;
163 $datatype = $a->argv[2];
164 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
165 $datatype = 'upload';
167 $datatype = 'summary';
171 // Setup permissions structures
176 $remote_contact = false;
179 $owner_uid = $a->data['user']['uid'];
181 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
183 if ((local_user()) && (local_user() == $owner_uid)) {
185 } elseif ($community_page && remote_user()) {
186 if (!empty($_SESSION['remote'])) {
187 foreach ($_SESSION['remote'] as $v) {
188 if ($v['uid'] == $owner_uid) {
189 $contact_id = $v['cid'];
195 if ($contact_id > 0) {
196 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
201 if (DBA::isResult($r)) {
203 $remote_contact = true;
204 $visitor = $contact_id;
211 // perhaps they're visiting - but not a community page, so they wouldn't have write access
212 if (remote_user() && (!$visitor)) {
215 if (!empty($_SESSION['remote'])) {
216 foreach($_SESSION['remote'] as $v) {
217 if($v['uid'] == $owner_uid) {
218 $contact_id = $v['cid'];
224 if ($contact_id > 0) {
225 $groups = Group::getIdsByContactId($contact_id);
226 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
231 if (DBA::isResult($r)) {
232 $remote_contact = true;
237 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (!$remote_contact)) {
238 notice(L10n::t('Access to this item is restricted.') . EOL);
242 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
247 $_is_owner = (local_user() && (local_user() == $owner_uid));
248 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
253 if ($datatype === 'upload') {
254 return; // no uploading for now
256 // DELETED -- look at mod/photos.php if you want to implement
259 if ($datatype === 'album') {
260 return; // no albums for now
262 // DELETED -- look at mod/photos.php if you want to implement
266 if ($datatype === 'video') {
267 return; // no single video view for now
269 // DELETED -- look at mod/photos.php if you want to implement
272 // Default - show recent videos (no upload link for now)
276 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
277 $sql_extra GROUP BY hash",
278 intval($a->data['user']['uid'])
280 if (DBA::isResult($r)) {
284 $pager = new Pager($a->query_string, 20);
286 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
287 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
289 WHERE `uid` = %d AND filetype LIKE '%%video%%'
290 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
291 intval($a->data['user']['uid']),
293 $pager->getItemsPerPage()
298 if (DBA::isResult($r)) {
299 foreach ($r as $rr) {
300 $alt_e = $rr['filename'];
301 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
303 $name_e = $rr['album'];
307 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
308 'title' => L10n::t('View Video'),
309 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
311 'mime' => $rr['filetype'],
313 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
315 'alt' => L10n::t('View Album'),
321 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
322 $o .= Renderer::replaceMacros($tpl, [
323 '$title' => L10n::t('Recent Videos'),
324 '$can_post' => $can_post,
325 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
326 '$videos' => $videos,
327 '$delete_url' => (($can_post) ? System::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
330 $o .= $pager->renderFull($total);