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 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
31 $a->data['user'] = $r[0];
32 $a->profile_uid = $r[0]['uid'];
34 $profilephoto = $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg');
36 $tpl = get_markup_template("vcard-widget.tpl");
38 $vcard_widget = replace_macros($tpl, array(
39 '$name' => $a->data['user']['username'],
40 '$photo' => $profilephoto
44 /*$sql_extra = permissions_sql($a->data['user']['uid']);
46 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
47 intval($a->data['user']['uid'])
51 $a->data['albums'] = $albums;
53 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
56 $o .= '<div id="side-bar-photos-albums" class="widget">';
57 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
60 foreach($albums as $album) {
62 // don't show contact photos. We once translated this name, but then you could still access it under
63 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
65 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
67 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
71 if(local_user() && $a->data['user']['uid'] == local_user()) {
72 $o .= '<div id="photo-albums-upload-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
78 if(! x($a->page,'aside'))
79 $a->page['aside'] = '';
80 $a->page['aside'] .= $vcard_widget;
83 $tpl = get_markup_template("videos_head.tpl");
84 $a->page['htmlhead'] .= replace_macros($tpl,array(
85 '$baseurl' => $a->get_baseurl(),
88 $tpl = get_markup_template("videos_end.tpl");
89 $a->page['end'] .= replace_macros($tpl,array(
90 '$baseurl' => $a->get_baseurl(),
100 function videos_post(&$a) {
102 $owner_uid = $a->data['user']['uid'];
104 if (local_user() != $owner_uid) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
106 if(($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
108 // Check if we should do HTML-based delete confirmation
109 if(!x($_REQUEST,'confirm')) {
110 if(x($_REQUEST,'canceled')) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
112 $drop_url = $a->query_string;
113 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
115 '$message' => t('Do you really want to delete this video?'),
116 '$extra_inputs' => array(
117 array('name'=>'id', 'value'=> $_POST['id']),
118 array('name'=>'delete', 'value'=>'x')
120 '$confirm' => t('Delete Video'),
121 '$confirm_url' => $drop_url,
122 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
123 '$cancel' => t('Cancel'),
126 $a->error = 1; // Set $a->error so the other module functions don't execute
130 $video_id = $_POST['id'];
133 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
134 intval(local_user()),
139 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
140 intval(local_user()),
143 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
147 #echo "<pre>"; var_dump($i); killme();
149 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
150 dbesc(datetime_convert()),
151 dbesc(datetime_convert()),
155 create_tags_from_itemuri($i[0]['uri'], local_user());
156 delete_thread_uri($i[0]['uri'], local_user());
158 $url = $a->get_baseurl();
159 $drop_id = intval($i[0]['id']);
162 proc_run('php',"include/notifier.php","drop","$drop_id");
166 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
167 return; // NOTREACHED
170 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
176 function videos_content(&$a) {
178 // URLs (most aren't currently implemented):
180 // videos/name/upload
181 // videos/name/upload/xxxxx (xxxxx is album name)
182 // videos/name/album/xxxxx
183 // videos/name/album/xxxxx/edit
184 // videos/name/video/xxxxx
185 // videos/name/video/xxxxx/edit
188 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
189 notice( t('Public access denied.') . EOL);
194 require_once('include/bbcode.php');
195 require_once('include/security.php');
196 require_once('include/conversation.php');
198 if(! x($a->data,'user')) {
199 notice( t('No videos selected') . EOL );
203 //$phototypes = Photo::supportedTypes();
205 $_SESSION['video_return'] = $a->cmd;
212 $datatype = $a->argv[2];
213 $datum = $a->argv[3];
215 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
216 $datatype = 'upload';
218 $datatype = 'summary';
226 // Setup permissions structures
232 $remote_contact = false;
235 $owner_uid = $a->data['user']['uid'];
237 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
239 if((local_user()) && (local_user() == $owner_uid))
242 if($community_page && remote_user()) {
243 if(is_array($_SESSION['remote'])) {
244 foreach($_SESSION['remote'] as $v) {
245 if($v['uid'] == $owner_uid) {
246 $contact_id = $v['cid'];
253 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
260 $remote_contact = true;
267 // perhaps they're visiting - but not a community page, so they wouldn't have write access
269 if(remote_user() && (! $visitor)) {
271 if(is_array($_SESSION['remote'])) {
272 foreach($_SESSION['remote'] as $v) {
273 if($v['uid'] == $owner_uid) {
274 $contact_id = $v['cid'];
280 $groups = init_groups_visitor($contact_id);
281 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
287 $remote_contact = true;
292 if(! $remote_contact) {
294 $contact_id = $_SESSION['cid'];
295 $contact = $a->contact;
299 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
300 notice( t('Access to this item is restricted.') . EOL);
304 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
309 $_is_owner = (local_user() && (local_user() == $owner_uid));
310 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
317 if($datatype === 'upload') {
318 return; // no uploading for now
320 // DELETED -- look at mod/photos.php if you want to implement
323 if($datatype === 'album') {
325 return; // no albums for now
327 // DELETED -- look at mod/photos.php if you want to implement
331 if($datatype === 'video') {
333 return; // no single video view for now
335 // DELETED -- look at mod/photos.php if you want to implement
338 // Default - show recent videos (no upload link for now)
341 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
342 $sql_extra GROUP BY hash",
343 intval($a->data['user']['uid'])
346 $a->set_pager_total(count($r));
347 $a->set_pager_itemspage(20);
350 $r = q("SELECT hash, `id`, `filename`, filetype FROM `attach`
351 WHERE `uid` = %d AND filetype LIKE '%%video%%'
352 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
353 intval($a->data['user']['uid']),
354 intval($a->pager['start']),
355 intval($a->pager['itemspage'])
363 if($a->theme['template_engine'] === 'internal') {
364 $alt_e = template_escape($rr['filename']);
365 $name_e = template_escape($rr['album']);
368 $alt_e = $rr['filename'];
369 $name_e = $rr['album'];
374 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
375 'title' => t('View Video'),
376 'src' => $a->get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0',
378 'mime' => $rr['filetype'],
380 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
382 'alt' => t('View Album'),
389 $tpl = get_markup_template('videos_recent.tpl');
390 $o .= replace_macros($tpl, array(
391 '$title' => t('Recent Videos'),
392 '$can_post' => $can_post,
393 '$upload' => array(t('Upload New Videos'), $a->get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'),
394 '$videos' => $videos,
395 '$delete_url' => (($can_post)?$a->get_baseurl().'/videos/'.$a->data['user']['nickname']:False)