4 use Friendica\Core\System;
6 require_once('include/items.php');
7 require_once('include/acl_selectors.php');
8 require_once('include/bbcode.php');
9 require_once('include/security.php');
10 require_once('include/redir.php');
12 function videos_init(App $a) {
15 auto_redir($a, $a->argv[1]);
17 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
21 nav_set_selected('home');
27 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
34 $a->data['user'] = $user[0];
35 $a->profile_uid = $user[0]['uid'];
37 $profile = get_profiledata_by_nick($nick, $a->profile_uid);
39 $account_type = account_type($profile);
41 $tpl = get_markup_template("vcard-widget.tpl");
43 $vcard_widget .= replace_macros($tpl, array(
44 '$name' => $profile['name'],
45 '$photo' => $profile['photo'],
46 '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
47 '$account_type' => $account_type,
48 '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
52 /*$sql_extra = permissions_sql($a->data['user']['uid']);
54 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
55 intval($a->data['user']['uid'])
59 $a->data['albums'] = $albums;
61 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
64 $o .= '<div id="sidebar-photos-albums" class="widget">';
65 $o .= '<h3>' . '<a href="' . App::get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
68 foreach($albums as $album) {
70 // don't show contact photos. We once translated this name, but then you could still access it under
71 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
73 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
75 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
79 if(local_user() && $a->data['user']['uid'] == local_user()) {
80 $o .= '<div id="photo-albums-upload-link"><a href="' . App::get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
86 if(! x($a->page,'aside'))
87 $a->page['aside'] = '';
88 $a->page['aside'] .= $vcard_widget;
91 $tpl = get_markup_template("videos_head.tpl");
92 $a->page['htmlhead'] .= replace_macros($tpl,array(
93 '$baseurl' => App::get_baseurl(),
96 $tpl = get_markup_template("videos_end.tpl");
97 $a->page['end'] .= replace_macros($tpl,array(
98 '$baseurl' => App::get_baseurl(),
108 function videos_post(App $a) {
110 $owner_uid = $a->data['user']['uid'];
112 if (local_user() != $owner_uid) {
113 goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
116 if (($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
118 // Check if we should do HTML-based delete confirmation
119 if (!x($_REQUEST,'confirm')) {
120 if (x($_REQUEST,'canceled')) {
121 goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
124 $drop_url = $a->query_string;
125 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
127 '$message' => t('Do you really want to delete this video?'),
128 '$extra_inputs' => array(
129 array('name'=>'id', 'value'=> $_POST['id']),
130 array('name'=>'delete', 'value'=>'x')
132 '$confirm' => t('Delete Video'),
133 '$confirm_url' => $drop_url,
134 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
135 '$cancel' => t('Cancel'),
138 $a->error = 1; // Set $a->error so the other module functions don't execute
142 $video_id = $_POST['id'];
144 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
145 intval(local_user()),
149 if (dbm::is_result($r)) {
150 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
151 intval(local_user()),
154 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
158 //echo "<pre>"; var_dump($i); killme();
159 if (dbm::is_result($i)) {
160 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
161 dbesc(datetime_convert()),
162 dbesc(datetime_convert()),
166 create_tags_from_itemuri($i[0]['uri'], local_user());
167 delete_thread_uri($i[0]['uri'], local_user());
169 $url = App::get_baseurl();
170 $drop_id = intval($i[0]['id']);
172 if ($i[0]['visible']) {
173 proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
178 goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
179 return; // NOTREACHED
182 goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
188 function videos_content(App $a) {
190 // URLs (most aren't currently implemented):
192 // videos/name/upload
193 // videos/name/upload/xxxxx (xxxxx is album name)
194 // videos/name/album/xxxxx
195 // videos/name/album/xxxxx/edit
196 // videos/name/video/xxxxx
197 // videos/name/video/xxxxx/edit
200 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
201 notice( t('Public access denied.') . EOL);
206 require_once('include/bbcode.php');
207 require_once('include/security.php');
208 require_once('include/conversation.php');
210 if(! x($a->data,'user')) {
211 notice( t('No videos selected') . EOL );
215 //$phototypes = Photo::supportedTypes();
217 $_SESSION['video_return'] = $a->cmd;
224 $datatype = $a->argv[2];
225 $datum = $a->argv[3];
227 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
228 $datatype = 'upload';
230 $datatype = 'summary';
238 // Setup permissions structures
244 $remote_contact = false;
247 $owner_uid = $a->data['user']['uid'];
249 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
251 if((local_user()) && (local_user() == $owner_uid))
254 if($community_page && remote_user()) {
255 if(is_array($_SESSION['remote'])) {
256 foreach($_SESSION['remote'] as $v) {
257 if($v['uid'] == $owner_uid) {
258 $contact_id = $v['cid'];
265 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
269 if (dbm::is_result($r)) {
272 $remote_contact = true;
273 $visitor = $contact_id;
279 // perhaps they're visiting - but not a community page, so they wouldn't have write access
281 if(remote_user() && (! $visitor)) {
283 if(is_array($_SESSION['remote'])) {
284 foreach($_SESSION['remote'] as $v) {
285 if($v['uid'] == $owner_uid) {
286 $contact_id = $v['cid'];
292 $groups = init_groups_visitor($contact_id);
293 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
297 if (dbm::is_result($r)) {
299 $remote_contact = true;
304 if(! $remote_contact) {
306 $contact_id = $_SESSION['cid'];
307 $contact = $a->contact;
311 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
312 notice( t('Access to this item is restricted.') . EOL);
316 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
321 $_is_owner = (local_user() && (local_user() == $owner_uid));
322 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
329 if($datatype === 'upload') {
330 return; // no uploading for now
332 // DELETED -- look at mod/photos.php if you want to implement
335 if($datatype === 'album') {
337 return; // no albums for now
339 // DELETED -- look at mod/photos.php if you want to implement
343 if($datatype === 'video') {
345 return; // no single video view for now
347 // DELETED -- look at mod/photos.php if you want to implement
350 // Default - show recent videos (no upload link for now)
353 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
354 $sql_extra GROUP BY hash",
355 intval($a->data['user']['uid'])
357 if (dbm::is_result($r)) {
358 $a->set_pager_total(count($r));
359 $a->set_pager_itemspage(20);
362 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
363 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
365 WHERE `uid` = %d AND filetype LIKE '%%video%%'
366 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
367 intval($a->data['user']['uid']),
368 intval($a->pager['start']),
369 intval($a->pager['itemspage'])
375 if (dbm::is_result($r)) {
376 foreach ($r as $rr) {
377 if ($a->theme['template_engine'] === 'internal') {
378 $alt_e = template_escape($rr['filename']);
379 $name_e = template_escape($rr['album']);
382 $alt_e = $rr['filename'];
383 $name_e = $rr['album'];
388 'link' => App::get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
389 'title' => t('View Video'),
390 'src' => App::get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0',
392 'mime' => $rr['filetype'],
394 'link' => App::get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
396 'alt' => t('View Album'),
403 $tpl = get_markup_template('videos_recent.tpl');
404 $o .= replace_macros($tpl, array(
405 '$title' => t('Recent Videos'),
406 '$can_post' => $can_post,
407 '$upload' => array(t('Upload New Videos'), App::get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'),
408 '$videos' => $videos,
409 '$delete_url' => (($can_post)?App::get_baseurl().'/videos/'.$a->data['user']['nickname']:False)