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,[
71 '$baseurl' => System::baseUrl(),
78 function videos_post(App $a)
80 $owner_uid = $a->data['user']['uid'];
82 if (local_user() != $owner_uid) {
83 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
86 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
87 // Check if we should do HTML-based delete confirmation
88 if (empty($_REQUEST['confirm'])) {
89 if (!empty($_REQUEST['canceled'])) {
90 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
93 $drop_url = $a->query_string;
95 $a->page['content'] = Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
97 '$message' => L10n::t('Do you really want to delete this video?'),
99 ['name' => 'id' , 'value' => $_POST['id']],
100 ['name' => 'delete', 'value' => 'x']
102 '$confirm' => L10n::t('Delete Video'),
103 '$confirm_url' => $drop_url,
104 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
105 '$cancel' => L10n::t('Cancel'),
109 $a->error = 1; // Set $a->error so the other module functions don't execute
114 $video_id = $_POST['id'];
116 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
117 // delete the attachment
118 Attach::delete(['id' => $video_id, 'uid' => local_user()]);
120 // delete items where the attach is used
121 Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
122 '%attach/' . $video_id . '%',
127 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
128 return; // NOTREACHED
131 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
134 function videos_content(App $a)
136 // URLs (most aren't currently implemented):
138 // videos/name/upload
139 // videos/name/upload/xxxxx (xxxxx is album name)
140 // videos/name/album/xxxxx
141 // videos/name/album/xxxxx/edit
142 // videos/name/video/xxxxx
143 // videos/name/video/xxxxx/edit
146 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
147 notice(L10n::t('Public access denied.') . EOL);
151 if (empty($a->data['user'])) {
152 notice(L10n::t('No videos selected') . EOL );
156 //$phototypes = Photo::supportedTypes();
158 $_SESSION['video_return'] = $a->cmd;
164 $datatype = $a->argv[2];
165 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
166 $datatype = 'upload';
168 $datatype = 'summary';
172 // Setup permissions structures
177 $remote_contact = false;
180 $owner_uid = $a->data['user']['uid'];
182 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
184 if ((local_user()) && (local_user() == $owner_uid)) {
186 } elseif ($community_page && remote_user()) {
187 if (!empty($_SESSION['remote'])) {
188 foreach ($_SESSION['remote'] as $v) {
189 if ($v['uid'] == $owner_uid) {
190 $contact_id = $v['cid'];
196 if ($contact_id > 0) {
197 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
202 if (DBA::isResult($r)) {
204 $remote_contact = true;
205 $visitor = $contact_id;
212 // perhaps they're visiting - but not a community page, so they wouldn't have write access
213 if (remote_user() && (!$visitor)) {
216 if (!empty($_SESSION['remote'])) {
217 foreach($_SESSION['remote'] as $v) {
218 if($v['uid'] == $owner_uid) {
219 $contact_id = $v['cid'];
225 if ($contact_id > 0) {
226 $groups = Group::getIdsByContactId($contact_id);
227 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
232 if (DBA::isResult($r)) {
233 $remote_contact = true;
238 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (!$remote_contact)) {
239 notice(L10n::t('Access to this item is restricted.') . EOL);
243 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
248 $_is_owner = (local_user() && (local_user() == $owner_uid));
249 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
254 if ($datatype === 'upload') {
255 return; // no uploading for now
257 // DELETED -- look at mod/photos.php if you want to implement
260 if ($datatype === 'album') {
261 return; // no albums for now
263 // DELETED -- look at mod/photos.php if you want to implement
267 if ($datatype === 'video') {
268 return; // no single video view for now
270 // DELETED -- look at mod/photos.php if you want to implement
273 // Default - show recent videos (no upload link for now)
277 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
278 $sql_extra GROUP BY hash",
279 intval($a->data['user']['uid'])
281 if (DBA::isResult($r)) {
285 $pager = new Pager($a->query_string, 20);
287 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
288 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
290 WHERE `uid` = %d AND filetype LIKE '%%video%%'
291 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
292 intval($a->data['user']['uid']),
294 $pager->getItemsPerPage()
299 if (DBA::isResult($r)) {
300 foreach ($r as $rr) {
301 $alt_e = $rr['filename'];
302 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
304 $name_e = $rr['album'];
308 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
309 'title' => L10n::t('View Video'),
310 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
312 'mime' => $rr['filetype'],
314 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
316 'alt' => L10n::t('View Album'),
322 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
323 $o .= Renderer::replaceMacros($tpl, [
324 '$title' => L10n::t('Recent Videos'),
325 '$can_post' => $can_post,
326 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
327 '$videos' => $videos,
328 '$delete_url' => (($can_post) ? System::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
331 $o .= $pager->renderFull($total);