6 use Friendica\Content\Nav;
7 use Friendica\Core\Config;
8 use Friendica\Core\System;
9 use Friendica\Core\Worker;
10 use Friendica\Database\DBM;
11 use Friendica\Model\Contact;
12 use Friendica\Model\Group;
13 use Friendica\Model\Profile;
14 use Friendica\Protocol\DFRN;
16 require_once 'include/items.php';
17 require_once 'include/acl_selectors.php';
18 require_once 'include/bbcode.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'] . '">' . 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'] === 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" >' .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' => t('Do you really want to delete this video?'),
138 ['name'=>'id', 'value'=> $_POST['id']],
139 ['name'=>'delete', 'value'=>'x']
141 '$confirm' => 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' => 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()),
158 if (DBM::is_result($r)) {
159 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
160 intval(local_user()),
163 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
167 //echo "<pre>"; var_dump($i); killme();
168 if (DBM::is_result($i)) {
169 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
170 dbesc(datetime_convert()),
171 dbesc(datetime_convert()),
175 create_tags_from_itemuri($i[0]['uri'], local_user());
176 delete_thread_uri($i[0]['uri'], local_user());
178 $url = System::baseUrl();
179 $drop_id = intval($i[0]['id']);
181 if ($i[0]['visible']) {
182 Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
187 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
188 return; // NOTREACHED
191 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
197 function videos_content(App $a) {
199 // URLs (most aren't currently implemented):
201 // videos/name/upload
202 // videos/name/upload/xxxxx (xxxxx is album name)
203 // videos/name/album/xxxxx
204 // videos/name/album/xxxxx/edit
205 // videos/name/video/xxxxx
206 // videos/name/video/xxxxx/edit
209 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
210 notice( t('Public access denied.') . EOL);
215 require_once('include/bbcode.php');
216 require_once('include/security.php');
217 require_once('include/conversation.php');
219 if(! x($a->data,'user')) {
220 notice( t('No videos selected') . EOL );
224 //$phototypes = Photo::supportedTypes();
226 $_SESSION['video_return'] = $a->cmd;
233 $datatype = $a->argv[2];
234 $datum = $a->argv[3];
236 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
237 $datatype = 'upload';
239 $datatype = 'summary';
247 // Setup permissions structures
253 $remote_contact = false;
256 $owner_uid = $a->data['user']['uid'];
258 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
260 if((local_user()) && (local_user() == $owner_uid))
263 if($community_page && remote_user()) {
264 if(is_array($_SESSION['remote'])) {
265 foreach($_SESSION['remote'] as $v) {
266 if($v['uid'] == $owner_uid) {
267 $contact_id = $v['cid'];
274 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
278 if (DBM::is_result($r)) {
281 $remote_contact = true;
282 $visitor = $contact_id;
290 // perhaps they're visiting - but not a community page, so they wouldn't have write access
291 if(remote_user() && (! $visitor)) {
293 if(is_array($_SESSION['remote'])) {
294 foreach($_SESSION['remote'] as $v) {
295 if($v['uid'] == $owner_uid) {
296 $contact_id = $v['cid'];
302 $groups = Group::getIdsByContactId($contact_id);
303 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
307 if (DBM::is_result($r)) {
309 $remote_contact = true;
314 if(! $remote_contact) {
316 $contact_id = $_SESSION['cid'];
317 $contact = $a->contact;
321 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
322 notice( t('Access to this item is restricted.') . EOL);
326 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
331 $_is_owner = (local_user() && (local_user() == $owner_uid));
332 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
339 if($datatype === 'upload') {
340 return; // no uploading for now
342 // DELETED -- look at mod/photos.php if you want to implement
345 if($datatype === 'album') {
347 return; // no albums for now
349 // DELETED -- look at mod/photos.php if you want to implement
353 if($datatype === 'video') {
355 return; // no single video view for now
357 // DELETED -- look at mod/photos.php if you want to implement
360 // Default - show recent videos (no upload link for now)
363 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
364 $sql_extra GROUP BY hash",
365 intval($a->data['user']['uid'])
367 if (DBM::is_result($r)) {
368 $a->set_pager_total(count($r));
369 $a->set_pager_itemspage(20);
372 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
373 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
375 WHERE `uid` = %d AND filetype LIKE '%%video%%'
376 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
377 intval($a->data['user']['uid']),
378 intval($a->pager['start']),
379 intval($a->pager['itemspage'])
385 if (DBM::is_result($r)) {
386 foreach ($r as $rr) {
387 $alt_e = $rr['filename'];
388 $name_e = $rr['album'];
392 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
393 'title' => t('View Video'),
394 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
396 'mime' => $rr['filetype'],
398 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
400 'alt' => t('View Album'),
407 $tpl = get_markup_template('videos_recent.tpl');
408 $o .= replace_macros($tpl, [
409 '$title' => t('Recent Videos'),
410 '$can_post' => $can_post,
411 '$upload' => [t('Upload New Videos'), System::baseUrl().'/videos/'.$a->data['user']['nickname'].'/upload'],
412 '$videos' => $videos,
413 '$delete_url' => (($can_post)?System::baseUrl().'/videos/'.$a->data['user']['nickname']:False)