7 use Friendica\Content\Nav;
8 use Friendica\Core\Config;
9 use Friendica\Core\L10n;
10 use Friendica\Core\System;
11 use Friendica\Core\Worker;
12 use Friendica\Database\DBM;
13 use Friendica\Model\Contact;
14 use Friendica\Model\Group;
15 use Friendica\Model\Profile;
16 use Friendica\Model\Term;
17 use Friendica\Protocol\DFRN;
18 use Friendica\Util\DateTimeFormat;
20 require_once 'include/items.php';
21 require_once 'include/acl_selectors.php';
22 require_once 'include/bbcode.php';
23 require_once 'include/security.php';
25 function videos_init(App $a) {
28 DFRN::autoRedir($a, $a->argv[1]);
30 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
34 Nav::setSelected('home');
40 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
47 $a->data['user'] = $user[0];
48 $a->profile_uid = $user[0]['uid'];
50 $profile = Profile::getByNickname($nick, $a->profile_uid);
52 $account_type = Contact::getAccountType($profile);
54 $tpl = get_markup_template("vcard-widget.tpl");
56 $vcard_widget = replace_macros($tpl, [
57 '$name' => $profile['name'],
58 '$photo' => $profile['photo'],
59 '$addr' => defaults($profile, 'addr', ''),
60 '$account_type' => $account_type,
61 '$pdesc' => defaults($profile, 'pdesc', ''),
65 /*$sql_extra = permissions_sql($a->data['user']['uid']);
67 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
68 intval($a->data['user']['uid'])
72 $a->data['albums'] = $albums;
74 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
77 $o .= '<div id="sidebar-photos-albums" class="widget">';
78 $o .= '<h3>' . '<a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '">' . L10n::t('Photo Albums') . '</a></h3>';
81 foreach($albums as $album) {
83 // don't show contact photos. We once translated this name, but then you could still access it under
84 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
86 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos')))
88 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
92 if(local_user() && $a->data['user']['uid'] == local_user()) {
93 $o .= '<div id="photo-albums-upload-link"><a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .L10n::t('Upload New Photos') . '</a></div>';
99 if(! x($a->page,'aside'))
100 $a->page['aside'] = '';
101 $a->page['aside'] .= $vcard_widget;
104 $tpl = get_markup_template("videos_head.tpl");
105 $a->page['htmlhead'] .= replace_macros($tpl,[
106 '$baseurl' => System::baseUrl(),
109 $tpl = get_markup_template("videos_end.tpl");
110 $a->page['end'] .= replace_macros($tpl,[
111 '$baseurl' => System::baseUrl(),
121 function videos_post(App $a) {
123 $owner_uid = $a->data['user']['uid'];
125 if (local_user() != $owner_uid) {
126 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
129 if (($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
131 // Check if we should do HTML-based delete confirmation
132 if (!x($_REQUEST,'confirm')) {
133 if (x($_REQUEST,'canceled')) {
134 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
137 $drop_url = $a->query_string;
138 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
140 '$message' => L10n::t('Do you really want to delete this video?'),
142 ['name'=>'id', 'value'=> $_POST['id']],
143 ['name'=>'delete', 'value'=>'x']
145 '$confirm' => L10n::t('Delete Video'),
146 '$confirm_url' => $drop_url,
147 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
148 '$cancel' => L10n::t('Cancel'),
151 $a->error = 1; // Set $a->error so the other module functions don't execute
155 $video_id = $_POST['id'];
157 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
158 intval(local_user()),
162 if (DBM::is_result($r)) {
163 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
164 intval(local_user()),
167 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
171 //echo "<pre>"; var_dump($i); killme();
172 if (DBM::is_result($i)) {
173 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
174 dbesc(DateTimeFormat::utcNow()),
175 dbesc(DateTimeFormat::utcNow()),
179 Term::insertFromTagFieldByItemUri($i[0]['uri'], local_user());
180 delete_thread_uri($i[0]['uri'], local_user());
182 $url = System::baseUrl();
183 $drop_id = intval($i[0]['id']);
185 if ($i[0]['visible']) {
186 Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
191 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
192 return; // NOTREACHED
195 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
201 function videos_content(App $a) {
203 // URLs (most aren't currently implemented):
205 // videos/name/upload
206 // videos/name/upload/xxxxx (xxxxx is album name)
207 // videos/name/album/xxxxx
208 // videos/name/album/xxxxx/edit
209 // videos/name/video/xxxxx
210 // videos/name/video/xxxxx/edit
213 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
214 notice(L10n::t('Public access denied.') . EOL);
219 require_once('include/bbcode.php');
220 require_once('include/security.php');
221 require_once('include/conversation.php');
223 if(! x($a->data,'user')) {
224 notice(L10n::t('No videos selected') . EOL );
228 //$phototypes = Photo::supportedTypes();
230 $_SESSION['video_return'] = $a->cmd;
237 $datatype = $a->argv[2];
238 $datum = $a->argv[3];
240 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
241 $datatype = 'upload';
243 $datatype = 'summary';
251 // Setup permissions structures
257 $remote_contact = false;
260 $owner_uid = $a->data['user']['uid'];
262 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
264 if((local_user()) && (local_user() == $owner_uid))
267 if($community_page && remote_user()) {
268 if(is_array($_SESSION['remote'])) {
269 foreach($_SESSION['remote'] as $v) {
270 if($v['uid'] == $owner_uid) {
271 $contact_id = $v['cid'];
278 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
282 if (DBM::is_result($r)) {
285 $remote_contact = true;
286 $visitor = $contact_id;
294 // perhaps they're visiting - but not a community page, so they wouldn't have write access
295 if(remote_user() && (! $visitor)) {
297 if(is_array($_SESSION['remote'])) {
298 foreach($_SESSION['remote'] as $v) {
299 if($v['uid'] == $owner_uid) {
300 $contact_id = $v['cid'];
306 $groups = Group::getIdsByContactId($contact_id);
307 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
311 if (DBM::is_result($r)) {
313 $remote_contact = true;
318 if(! $remote_contact) {
320 $contact_id = $_SESSION['cid'];
321 $contact = $a->contact;
325 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
326 notice(L10n::t('Access to this item is restricted.') . EOL);
330 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
335 $_is_owner = (local_user() && (local_user() == $owner_uid));
336 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
343 if($datatype === 'upload') {
344 return; // no uploading for now
346 // DELETED -- look at mod/photos.php if you want to implement
349 if($datatype === 'album') {
351 return; // no albums for now
353 // DELETED -- look at mod/photos.php if you want to implement
357 if($datatype === 'video') {
359 return; // no single video view for now
361 // DELETED -- look at mod/photos.php if you want to implement
364 // Default - show recent videos (no upload link for now)
367 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
368 $sql_extra GROUP BY hash",
369 intval($a->data['user']['uid'])
371 if (DBM::is_result($r)) {
372 $a->set_pager_total(count($r));
373 $a->set_pager_itemspage(20);
376 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
377 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
379 WHERE `uid` = %d AND filetype LIKE '%%video%%'
380 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
381 intval($a->data['user']['uid']),
382 intval($a->pager['start']),
383 intval($a->pager['itemspage'])
389 if (DBM::is_result($r)) {
390 foreach ($r as $rr) {
391 $alt_e = $rr['filename'];
392 $name_e = $rr['album'];
396 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
397 'title' => L10n::t('View Video'),
398 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
400 'mime' => $rr['filetype'],
402 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
404 'alt' => L10n::t('View Album'),
411 $tpl = get_markup_template('videos_recent.tpl');
412 $o .= replace_macros($tpl, [
413 '$title' => L10n::t('Recent Videos'),
414 '$can_post' => $can_post,
415 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl().'/videos/'.$a->data['user']['nickname'].'/upload'],
416 '$videos' => $videos,
417 '$delete_url' => (($can_post)?System::baseUrl().'/videos/'.$a->data['user']['nickname']:False)