7 use Friendica\Content\Nav;
8 use Friendica\Core\Config;
9 use Friendica\Core\L10n;
10 use Friendica\Core\System;
11 use Friendica\Database\DBA;
12 use Friendica\Model\Contact;
13 use Friendica\Model\Group;
14 use Friendica\Model\Item;
15 use Friendica\Model\Profile;
16 use Friendica\Protocol\DFRN;
18 require_once 'include/items.php';
19 require_once 'include/security.php';
21 function videos_init(App $a) {
24 DFRN::autoRedir($a, $a->argv[1]);
26 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
30 Nav::setSelected('home');
36 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
43 $a->data['user'] = $user[0];
44 $a->profile_uid = $user[0]['uid'];
46 $profile = Profile::getByNickname($nick, $a->profile_uid);
48 $account_type = Contact::getAccountType($profile);
50 $tpl = get_markup_template("vcard-widget.tpl");
52 $vcard_widget = replace_macros($tpl, [
53 '$name' => $profile['name'],
54 '$photo' => $profile['photo'],
55 '$addr' => defaults($profile, 'addr', ''),
56 '$account_type' => $account_type,
57 '$pdesc' => defaults($profile, 'pdesc', ''),
61 /*$sql_extra = permissions_sql($a->data['user']['uid']);
63 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
64 intval($a->data['user']['uid'])
68 $a->data['albums'] = $albums;
70 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
73 $o .= '<div id="sidebar-photos-albums" class="widget">';
74 $o .= '<h3>' . '<a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '">' . L10n::t('Photo Albums') . '</a></h3>';
77 foreach($albums as $album) {
79 // don't show contact photos. We once translated this name, but then you could still access it under
80 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
82 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos')))
84 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
88 if(local_user() && $a->data['user']['uid'] == local_user()) {
89 $o .= '<div id="photo-albums-upload-link"><a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .L10n::t('Upload New Photos') . '</a></div>';
95 if(! x($a->page,'aside'))
96 $a->page['aside'] = '';
97 $a->page['aside'] .= $vcard_widget;
100 $tpl = get_markup_template("videos_head.tpl");
101 $a->page['htmlhead'] .= replace_macros($tpl,[
102 '$baseurl' => System::baseUrl(),
105 $tpl = get_markup_template("videos_end.tpl");
106 $a->page['end'] .= replace_macros($tpl,[
107 '$baseurl' => System::baseUrl(),
117 function videos_post(App $a) {
119 $owner_uid = $a->data['user']['uid'];
121 if (local_user() != $owner_uid) {
122 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
125 if (($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
127 // Check if we should do HTML-based delete confirmation
128 if (!x($_REQUEST,'confirm')) {
129 if (x($_REQUEST,'canceled')) {
130 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
133 $drop_url = $a->query_string;
134 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
136 '$message' => L10n::t('Do you really want to delete this video?'),
138 ['name'=>'id', 'value'=> $_POST['id']],
139 ['name'=>'delete', 'value'=>'x']
141 '$confirm' => L10n::t('Delete Video'),
142 '$confirm_url' => $drop_url,
143 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
144 '$cancel' => L10n::t('Cancel'),
147 $a->error = 1; // Set $a->error so the other module functions don't execute
151 $video_id = $_POST['id'];
153 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
154 intval(local_user()),
155 DBA::escape($video_id)
158 if (DBA::isResult($r)) {
159 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
160 intval(local_user()),
161 DBA::escape($video_id)
163 $i = q("SELECT `id` FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
164 DBA::escape($video_id),
168 if (DBA::isResult($i)) {
169 Item::deleteForUser(['id' => $i[0]['id']], local_user());
173 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
174 return; // NOTREACHED
177 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
183 function videos_content(App $a) {
185 // URLs (most aren't currently implemented):
187 // videos/name/upload
188 // videos/name/upload/xxxxx (xxxxx is album name)
189 // videos/name/album/xxxxx
190 // videos/name/album/xxxxx/edit
191 // videos/name/video/xxxxx
192 // videos/name/video/xxxxx/edit
195 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
196 notice(L10n::t('Public access denied.') . EOL);
200 require_once('include/security.php');
201 require_once('include/conversation.php');
203 if(! x($a->data,'user')) {
204 notice(L10n::t('No videos selected') . EOL );
208 //$phototypes = Photo::supportedTypes();
210 $_SESSION['video_return'] = $a->cmd;
217 $datatype = $a->argv[2];
218 $datum = $a->argv[3];
220 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
221 $datatype = 'upload';
223 $datatype = 'summary';
231 // Setup permissions structures
237 $remote_contact = false;
240 $owner_uid = $a->data['user']['uid'];
242 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
244 if((local_user()) && (local_user() == $owner_uid))
247 if($community_page && remote_user()) {
248 if(is_array($_SESSION['remote'])) {
249 foreach($_SESSION['remote'] as $v) {
250 if($v['uid'] == $owner_uid) {
251 $contact_id = $v['cid'];
258 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
262 if (DBA::isResult($r)) {
265 $remote_contact = true;
266 $visitor = $contact_id;
274 // perhaps they're visiting - but not a community page, so they wouldn't have write access
275 if(remote_user() && (! $visitor)) {
277 if(is_array($_SESSION['remote'])) {
278 foreach($_SESSION['remote'] as $v) {
279 if($v['uid'] == $owner_uid) {
280 $contact_id = $v['cid'];
286 $groups = Group::getIdsByContactId($contact_id);
287 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
291 if (DBA::isResult($r)) {
293 $remote_contact = true;
298 if(! $remote_contact) {
300 $contact_id = $_SESSION['cid'];
301 $contact = $a->contact;
305 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
306 notice(L10n::t('Access to this item is restricted.') . EOL);
310 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
315 $_is_owner = (local_user() && (local_user() == $owner_uid));
316 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
323 if($datatype === 'upload') {
324 return; // no uploading for now
326 // DELETED -- look at mod/photos.php if you want to implement
329 if($datatype === 'album') {
331 return; // no albums for now
333 // DELETED -- look at mod/photos.php if you want to implement
337 if($datatype === 'video') {
339 return; // no single video view for now
341 // DELETED -- look at mod/photos.php if you want to implement
344 // Default - show recent videos (no upload link for now)
347 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
348 $sql_extra GROUP BY hash",
349 intval($a->data['user']['uid'])
351 if (DBA::isResult($r)) {
352 $a->set_pager_total(count($r));
353 $a->set_pager_itemspage(20);
356 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
357 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
359 WHERE `uid` = %d AND filetype LIKE '%%video%%'
360 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
361 intval($a->data['user']['uid']),
362 intval($a->pager['start']),
363 intval($a->pager['itemspage'])
369 if (DBA::isResult($r)) {
370 foreach ($r as $rr) {
371 $alt_e = $rr['filename'];
372 $name_e = $rr['album'];
376 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
377 'title' => L10n::t('View Video'),
378 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
380 'mime' => $rr['filetype'],
382 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
384 'alt' => L10n::t('View Album'),
391 $tpl = get_markup_template('videos_recent.tpl');
392 $o .= replace_macros($tpl, [
393 '$title' => L10n::t('Recent Videos'),
394 '$can_post' => $can_post,
395 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl().'/videos/'.$a->data['user']['nickname'].'/upload'],
396 '$videos' => $videos,
397 '$delete_url' => (($can_post)?System::baseUrl().'/videos/'.$a->data['user']['nickname']:False)