2 require_once('include/items.php');
3 require_once('include/acl_selectors.php');
4 require_once('include/bbcode.php');
5 require_once('include/security.php');
6 require_once('include/redir.php');
9 function videos_init(&$a) {
12 auto_redir($a, $a->argv[1]);
14 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
18 nav_set_selected('home');
24 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
31 $a->data['user'] = $user[0];
32 $a->profile_uid = $user[0]['uid'];
34 $profile = get_profiledata_by_nick($nick, $a->profile_uid);
36 if((x($profile['page-flags']) == 1)
37 || (x($profile['page-flags']) == 2)
38 || (x($profile['page-flags']) == 5)) {
39 $account_type = page_type_translate($profile['page-flags']);
45 $tpl = get_markup_template("vcard-widget.tpl");
47 $vcard_widget .= replace_macros($tpl, array(
48 '$name' => $profile['name'],
49 '$photo' => $profile['photo'],
50 '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
51 '$account_type' => $account_type,
52 '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
56 /*$sql_extra = permissions_sql($a->data['user']['uid']);
58 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
59 intval($a->data['user']['uid'])
63 $a->data['albums'] = $albums;
65 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
68 $o .= '<div id="side-bar-photos-albums" class="widget">';
69 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
72 foreach($albums as $album) {
74 // don't show contact photos. We once translated this name, but then you could still access it under
75 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
77 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
79 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
83 if(local_user() && $a->data['user']['uid'] == local_user()) {
84 $o .= '<div id="photo-albums-upload-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
90 if(! x($a->page,'aside'))
91 $a->page['aside'] = '';
92 $a->page['aside'] .= $vcard_widget;
95 $tpl = get_markup_template("videos_head.tpl");
96 $a->page['htmlhead'] .= replace_macros($tpl,array(
97 '$baseurl' => $a->get_baseurl(),
100 $tpl = get_markup_template("videos_end.tpl");
101 $a->page['end'] .= replace_macros($tpl,array(
102 '$baseurl' => $a->get_baseurl(),
112 function videos_post(&$a) {
114 $owner_uid = $a->data['user']['uid'];
116 if (local_user() != $owner_uid) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
118 if(($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
120 // Check if we should do HTML-based delete confirmation
121 if(!x($_REQUEST,'confirm')) {
122 if(x($_REQUEST,'canceled')) goaway($a->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'];
145 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
146 intval(local_user()),
151 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
152 intval(local_user()),
155 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
159 #echo "<pre>"; var_dump($i); killme();
161 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
162 dbesc(datetime_convert()),
163 dbesc(datetime_convert()),
167 create_tags_from_itemuri($i[0]['uri'], local_user());
168 delete_thread_uri($i[0]['uri'], local_user());
170 $url = $a->get_baseurl();
171 $drop_id = intval($i[0]['id']);
174 proc_run('php',"include/notifier.php","drop","$drop_id");
178 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
179 return; // NOTREACHED
182 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
188 function videos_content(&$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",
272 $remote_contact = true;
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",
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'])
358 $a->set_pager_total(count($r));
359 $a->set_pager_itemspage(20);
362 $r = q("SELECT hash, `id`, `filename`, filetype FROM `attach`
363 WHERE `uid` = %d AND filetype LIKE '%%video%%'
364 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
365 intval($a->data['user']['uid']),
366 intval($a->pager['start']),
367 intval($a->pager['itemspage'])
375 if($a->theme['template_engine'] === 'internal') {
376 $alt_e = template_escape($rr['filename']);
377 $name_e = template_escape($rr['album']);
380 $alt_e = $rr['filename'];
381 $name_e = $rr['album'];
386 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
387 'title' => t('View Video'),
388 'src' => $a->get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0',
390 'mime' => $rr['filetype'],
392 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
394 'alt' => t('View Album'),
401 $tpl = get_markup_template('videos_recent.tpl');
402 $o .= replace_macros($tpl, array(
403 '$title' => t('Recent Videos'),
404 '$can_post' => $can_post,
405 '$upload' => array(t('Upload New Videos'), $a->get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'),
406 '$videos' => $videos,
407 '$delete_url' => (($can_post)?$a->get_baseurl().'/videos/'.$a->data['user']['nickname']:False)