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())) {
22 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
29 $a->data['user'] = $r[0];
30 $a->profile_uid = $r[0]['uid'];
32 $profilephoto = $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg');
34 $tpl = get_markup_template("vcard-widget.tpl");
36 $vcard_widget = replace_macros($tpl, array(
37 '$name' => $a->data['user']['username'],
38 '$photo' => $profilephoto
42 /*$sql_extra = permissions_sql($a->data['user']['uid']);
44 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
45 intval($a->data['user']['uid'])
49 $a->data['albums'] = $albums;
51 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
54 $o .= '<div id="side-bar-photos-albums" class="widget">';
55 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
58 foreach($albums as $album) {
60 // don't show contact photos. We once translated this name, but then you could still access it under
61 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
63 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
65 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
69 if(local_user() && $a->data['user']['uid'] == local_user()) {
70 $o .= '<div id="photo-albums-upload-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
76 if(! x($a->page,'aside'))
77 $a->page['aside'] = '';
78 $a->page['aside'] .= $vcard_widget;
81 $tpl = get_markup_template("videos_head.tpl");
82 $a->page['htmlhead'] .= replace_macros($tpl,array(
83 '$baseurl' => $a->get_baseurl(),
86 $tpl = get_markup_template("videos_end.tpl");
87 $a->page['end'] .= replace_macros($tpl,array(
88 '$baseurl' => $a->get_baseurl(),
98 function videos_post(&$a) {
100 $owner_uid = $a->data['user']['uid'];
102 if (local_user() != $owner_uid) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
104 if(($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
106 // Check if we should do HTML-based delete confirmation
107 if(!x($_REQUEST,'confirm')) {
108 if(x($_REQUEST,'canceled')) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
110 $drop_url = $a->query_string;
111 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
113 '$message' => t('Do you really want to delete this video?'),
115 ['name'=>'id', 'value'=> $_POST['id']],
116 ['name'=>'delete', 'value'=>'x']
118 '$confirm' => t('Delete Video'),
119 '$confirm_url' => $drop_url,
120 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
121 '$cancel' => t('Cancel'),
124 $a->error = 1; // Set $a->error so the other module functions don't execute
128 $video_id = $_POST['id'];
131 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
132 intval(local_user()),
137 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
138 intval(local_user()),
141 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
145 #echo "<pre>"; var_dump($i); killme();
147 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
148 dbesc(datetime_convert()),
149 dbesc(datetime_convert()),
153 create_tags_from_itemuri($i[0]['uri'], local_user());
154 delete_thread_uri($i[0]['uri'], local_user());
156 $url = $a->get_baseurl();
157 $drop_id = intval($i[0]['id']);
160 proc_run('php',"include/notifier.php","drop","$drop_id");
164 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
165 return; // NOTREACHED
168 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
174 function videos_content(&$a) {
176 // URLs (most aren't currently implemented):
178 // videos/name/upload
179 // videos/name/upload/xxxxx (xxxxx is album name)
180 // videos/name/album/xxxxx
181 // videos/name/album/xxxxx/edit
182 // videos/name/video/xxxxx
183 // videos/name/video/xxxxx/edit
186 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
187 notice( t('Public access denied.') . EOL);
192 require_once('include/bbcode.php');
193 require_once('include/security.php');
194 require_once('include/conversation.php');
196 if(! x($a->data,'user')) {
197 notice( t('No videos selected') . EOL );
201 //$phototypes = Photo::supportedTypes();
203 $_SESSION['video_return'] = $a->cmd;
210 $datatype = $a->argv[2];
211 $datum = $a->argv[3];
213 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
214 $datatype = 'upload';
216 $datatype = 'summary';
224 // Setup permissions structures
230 $remote_contact = false;
233 $owner_uid = $a->data['user']['uid'];
235 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
237 if((local_user()) && (local_user() == $owner_uid))
240 if($community_page && remote_user()) {
241 if(is_array($_SESSION['remote'])) {
242 foreach($_SESSION['remote'] as $v) {
243 if($v['uid'] == $owner_uid) {
244 $contact_id = $v['cid'];
251 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
258 $remote_contact = true;
265 // perhaps they're visiting - but not a community page, so they wouldn't have write access
267 if(remote_user() && (! $visitor)) {
269 if(is_array($_SESSION['remote'])) {
270 foreach($_SESSION['remote'] as $v) {
271 if($v['uid'] == $owner_uid) {
272 $contact_id = $v['cid'];
278 $groups = init_groups_visitor($contact_id);
279 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
285 $remote_contact = true;
290 if(! $remote_contact) {
292 $contact_id = $_SESSION['cid'];
293 $contact = $a->contact;
297 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
298 notice( t('Access to this item is restricted.') . EOL);
302 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
307 $_is_owner = (local_user() && (local_user() == $owner_uid));
308 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
315 if($datatype === 'upload') {
316 return; // no uploading for now
318 // DELETED -- look at mod/photos.php if you want to implement
321 if($datatype === 'album') {
323 return; // no albums for now
325 // DELETED -- look at mod/photos.php if you want to implement
329 if($datatype === 'video') {
331 return; // no single video view for now
333 // DELETED -- look at mod/photos.php if you want to implement
336 // Default - show recent videos (no upload link for now)
339 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
340 $sql_extra GROUP BY hash",
341 intval($a->data['user']['uid'])
344 $a->set_pager_total(count($r));
345 $a->set_pager_itemspage(20);
348 $r = q("SELECT hash, `id`, `filename`, filetype FROM `attach`
349 WHERE `uid` = %d AND filetype LIKE '%%video%%'
350 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
351 intval($a->data['user']['uid']),
352 intval($a->pager['start']),
353 intval($a->pager['itemspage'])
361 if($a->theme['template_engine'] === 'internal') {
362 $alt_e = template_escape($rr['filename']);
363 $name_e = template_escape($rr['album']);
366 $alt_e = $rr['filename'];
367 $name_e = $rr['album'];
372 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
373 'title' => t('View Video'),
374 'src' => $a->get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0',
376 'mime' => $rr['filetype'],
378 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
380 'alt' => t('View Album'),
387 $tpl = get_markup_template('videos_recent.tpl');
388 $o .= replace_macros($tpl, array(
389 '$title' => t('Recent Videos'),
390 '$can_post' => $can_post,
391 '$upload' => array(t('Upload New Videos'), $a->get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'),
392 '$videos' => $videos,
393 '$delete_url' => (($can_post)?$a->get_baseurl().'/videos/'.$a->data['user']['nickname']:False)