6 use Friendica\Content\Nav;
7 use Friendica\Core\Config;
8 use Friendica\Core\L10n;
9 use Friendica\Core\System;
10 use Friendica\Core\Worker;
11 use Friendica\Database\DBM;
12 use Friendica\Model\Contact;
13 use Friendica\Model\Group;
14 use Friendica\Model\Profile;
15 use Friendica\Protocol\DFRN;
17 require_once 'include/items.php';
18 require_once 'include/acl_selectors.php';
19 require_once 'include/bbcode.php';
20 require_once 'include/security.php';
22 function videos_init(App $a) {
25 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",
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 = get_markup_template("vcard-widget.tpl");
53 $vcard_widget = replace_macros($tpl, [
54 '$name' => $profile['name'],
55 '$photo' => $profile['photo'],
56 '$addr' => defaults($profile, 'addr', ''),
57 '$account_type' => $account_type,
58 '$pdesc' => defaults($profile, 'pdesc', ''),
62 /*$sql_extra = permissions_sql($a->data['user']['uid']);
64 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
65 intval($a->data['user']['uid'])
69 $a->data['albums'] = $albums;
71 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
74 $o .= '<div id="sidebar-photos-albums" class="widget">';
75 $o .= '<h3>' . '<a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '">' . L10n::t('Photo Albums') . '</a></h3>';
78 foreach($albums as $album) {
80 // don't show contact photos. We once translated this name, but then you could still access it under
81 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
83 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos')))
85 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
89 if(local_user() && $a->data['user']['uid'] == local_user()) {
90 $o .= '<div id="photo-albums-upload-link"><a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .L10n::t('Upload New Photos') . '</a></div>';
96 if(! x($a->page,'aside'))
97 $a->page['aside'] = '';
98 $a->page['aside'] .= $vcard_widget;
101 $tpl = get_markup_template("videos_head.tpl");
102 $a->page['htmlhead'] .= replace_macros($tpl,[
103 '$baseurl' => System::baseUrl(),
106 $tpl = get_markup_template("videos_end.tpl");
107 $a->page['end'] .= replace_macros($tpl,[
108 '$baseurl' => System::baseUrl(),
118 function videos_post(App $a) {
120 $owner_uid = $a->data['user']['uid'];
122 if (local_user() != $owner_uid) {
123 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
126 if (($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
128 // Check if we should do HTML-based delete confirmation
129 if (!x($_REQUEST,'confirm')) {
130 if (x($_REQUEST,'canceled')) {
131 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
134 $drop_url = $a->query_string;
135 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
137 '$message' => L10n::t('Do you really want to delete this video?'),
139 ['name'=>'id', 'value'=> $_POST['id']],
140 ['name'=>'delete', 'value'=>'x']
142 '$confirm' => L10n::t('Delete Video'),
143 '$confirm_url' => $drop_url,
144 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
145 '$cancel' => L10n::t('Cancel'),
148 $a->error = 1; // Set $a->error so the other module functions don't execute
152 $video_id = $_POST['id'];
154 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
155 intval(local_user()),
159 if (DBM::is_result($r)) {
160 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
161 intval(local_user()),
164 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
168 //echo "<pre>"; var_dump($i); killme();
169 if (DBM::is_result($i)) {
170 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
171 dbesc(datetime_convert()),
172 dbesc(datetime_convert()),
176 create_tags_from_itemuri($i[0]['uri'], local_user());
177 delete_thread_uri($i[0]['uri'], local_user());
179 $url = System::baseUrl();
180 $drop_id = intval($i[0]['id']);
182 if ($i[0]['visible']) {
183 Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
188 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
189 return; // NOTREACHED
192 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
198 function videos_content(App $a) {
200 // URLs (most aren't currently implemented):
202 // videos/name/upload
203 // videos/name/upload/xxxxx (xxxxx is album name)
204 // videos/name/album/xxxxx
205 // videos/name/album/xxxxx/edit
206 // videos/name/video/xxxxx
207 // videos/name/video/xxxxx/edit
210 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
211 notice(L10n::t('Public access denied.') . EOL);
216 require_once('include/bbcode.php');
217 require_once('include/security.php');
218 require_once('include/conversation.php');
220 if(! x($a->data,'user')) {
221 notice(L10n::t('No videos selected') . EOL );
225 //$phototypes = Photo::supportedTypes();
227 $_SESSION['video_return'] = $a->cmd;
234 $datatype = $a->argv[2];
235 $datum = $a->argv[3];
237 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
238 $datatype = 'upload';
240 $datatype = 'summary';
248 // Setup permissions structures
254 $remote_contact = false;
257 $owner_uid = $a->data['user']['uid'];
259 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
261 if((local_user()) && (local_user() == $owner_uid))
264 if($community_page && remote_user()) {
265 if(is_array($_SESSION['remote'])) {
266 foreach($_SESSION['remote'] as $v) {
267 if($v['uid'] == $owner_uid) {
268 $contact_id = $v['cid'];
275 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
279 if (DBM::is_result($r)) {
282 $remote_contact = true;
283 $visitor = $contact_id;
291 // perhaps they're visiting - but not a community page, so they wouldn't have write access
292 if(remote_user() && (! $visitor)) {
294 if(is_array($_SESSION['remote'])) {
295 foreach($_SESSION['remote'] as $v) {
296 if($v['uid'] == $owner_uid) {
297 $contact_id = $v['cid'];
303 $groups = Group::getIdsByContactId($contact_id);
304 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
308 if (DBM::is_result($r)) {
310 $remote_contact = true;
315 if(! $remote_contact) {
317 $contact_id = $_SESSION['cid'];
318 $contact = $a->contact;
322 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
323 notice(L10n::t('Access to this item is restricted.') . EOL);
327 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
332 $_is_owner = (local_user() && (local_user() == $owner_uid));
333 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
340 if($datatype === 'upload') {
341 return; // no uploading for now
343 // DELETED -- look at mod/photos.php if you want to implement
346 if($datatype === 'album') {
348 return; // no albums for now
350 // DELETED -- look at mod/photos.php if you want to implement
354 if($datatype === 'video') {
356 return; // no single video view for now
358 // DELETED -- look at mod/photos.php if you want to implement
361 // Default - show recent videos (no upload link for now)
364 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
365 $sql_extra GROUP BY hash",
366 intval($a->data['user']['uid'])
368 if (DBM::is_result($r)) {
369 $a->set_pager_total(count($r));
370 $a->set_pager_itemspage(20);
373 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
374 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
376 WHERE `uid` = %d AND filetype LIKE '%%video%%'
377 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
378 intval($a->data['user']['uid']),
379 intval($a->pager['start']),
380 intval($a->pager['itemspage'])
386 if (DBM::is_result($r)) {
387 foreach ($r as $rr) {
388 $alt_e = $rr['filename'];
389 $name_e = $rr['album'];
393 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
394 'title' => L10n::t('View Video'),
395 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
397 'mime' => $rr['filetype'],
399 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
401 'alt' => L10n::t('View Album'),
408 $tpl = get_markup_template('videos_recent.tpl');
409 $o .= replace_macros($tpl, [
410 '$title' => L10n::t('Recent Videos'),
411 '$can_post' => $can_post,
412 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl().'/videos/'.$a->data['user']['nickname'].'/upload'],
413 '$videos' => $videos,
414 '$delete_url' => (($can_post)?System::baseUrl().'/videos/'.$a->data['user']['nickname']:False)