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];
31 $profilephoto = $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg');
33 $tpl = get_markup_template("vcard-widget.tpl");
35 $vcard_widget = replace_macros($tpl, array(
36 '$name' => $a->data['user']['username'],
37 '$photo' => $profilephoto
41 /*$sql_extra = permissions_sql($a->data['user']['uid']);
43 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
44 intval($a->data['user']['uid'])
48 $a->data['albums'] = $albums;
50 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
53 $o .= '<div id="side-bar-photos-albums" class="widget">';
54 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
57 foreach($albums as $album) {
59 // don't show contact photos. We once translated this name, but then you could still access it under
60 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
62 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
64 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
68 if(local_user() && $a->data['user']['uid'] == local_user()) {
69 $o .= '<div id="photo-albums-upload-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
75 if(! x($a->page,'aside'))
76 $a->page['aside'] = '';
77 $a->page['aside'] .= $vcard_widget;
80 $tpl = get_markup_template("videos_head.tpl");
81 $a->page['htmlhead'] .= replace_macros($tpl,array(
82 '$baseurl' => $a->get_baseurl(),
85 $tpl = get_markup_template("videos_end.tpl");
86 $a->page['end'] .= replace_macros($tpl,array(
87 '$baseurl' => $a->get_baseurl(),
97 function videos_post(&$a) {
99 $owner_uid = $a->data['user']['uid'];
101 if (local_user() != $owner_uid) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
103 if(($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
105 // Check if we should do HTML-based delete confirmation
106 if(!x($_REQUEST,'confirm')) {
107 if(x($_REQUEST,'canceled')) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
109 $drop_url = $a->query_string;
110 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
112 '$message' => t('Do you really want to delete this video?'),
114 ['name'=>'id', 'value'=> $_POST['id']],
115 ['name'=>'delete', 'value'=>'x']
117 '$confirm' => t('Delete Video'),
118 '$confirm_url' => $drop_url,
119 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
120 '$cancel' => t('Cancel'),
123 $a->error = 1; // Set $a->error so the other module functions don't execute
127 $video_id = $_POST['id'];
130 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
131 intval(local_user()),
136 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
137 intval(local_user()),
140 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
144 #echo "<pre>"; var_dump($i); killme();
146 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
147 dbesc(datetime_convert()),
148 dbesc(datetime_convert()),
152 create_tags_from_itemuri($i[0]['uri'], local_user());
153 delete_thread_uri($i[0]['uri'], local_user());
155 $url = $a->get_baseurl();
156 $drop_id = intval($i[0]['id']);
159 proc_run('php',"include/notifier.php","drop","$drop_id");
163 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
164 return; // NOTREACHED
167 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
173 function videos_content(&$a) {
175 // URLs (most aren't currently implemented):
177 // videos/name/upload
178 // videos/name/upload/xxxxx (xxxxx is album name)
179 // videos/name/album/xxxxx
180 // videos/name/album/xxxxx/edit
181 // videos/name/video/xxxxx
182 // videos/name/video/xxxxx/edit
185 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
186 notice( t('Public access denied.') . EOL);
191 require_once('include/bbcode.php');
192 require_once('include/security.php');
193 require_once('include/conversation.php');
195 if(! x($a->data,'user')) {
196 notice( t('No videos selected') . EOL );
200 //$phototypes = Photo::supportedTypes();
202 $_SESSION['video_return'] = $a->cmd;
209 $datatype = $a->argv[2];
210 $datum = $a->argv[3];
212 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
213 $datatype = 'upload';
215 $datatype = 'summary';
223 // Setup permissions structures
229 $remote_contact = false;
232 $owner_uid = $a->data['user']['uid'];
234 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
236 if((local_user()) && (local_user() == $owner_uid))
239 if($community_page && remote_user()) {
240 if(is_array($_SESSION['remote'])) {
241 foreach($_SESSION['remote'] as $v) {
242 if($v['uid'] == $owner_uid) {
243 $contact_id = $v['cid'];
250 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
257 $remote_contact = true;
264 // perhaps they're visiting - but not a community page, so they wouldn't have write access
266 if(remote_user() && (! $visitor)) {
268 if(is_array($_SESSION['remote'])) {
269 foreach($_SESSION['remote'] as $v) {
270 if($v['uid'] == $owner_uid) {
271 $contact_id = $v['cid'];
277 $groups = init_groups_visitor($contact_id);
278 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
284 $remote_contact = true;
289 if(! $remote_contact) {
291 $contact_id = $_SESSION['cid'];
292 $contact = $a->contact;
296 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
297 notice( t('Access to this item is restricted.') . EOL);
301 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
306 $_is_owner = (local_user() && (local_user() == $owner_uid));
307 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
314 if($datatype === 'upload') {
315 return; // no uploading for now
317 // DELETED -- look at mod/photos.php if you want to implement
320 if($datatype === 'album') {
322 return; // no albums for now
324 // DELETED -- look at mod/photos.php if you want to implement
328 if($datatype === 'video') {
330 return; // no single video view for now
332 // DELETED -- look at mod/photos.php if you want to implement
335 // Default - show recent videos (no upload link for now)
338 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
339 $sql_extra GROUP BY hash",
340 intval($a->data['user']['uid'])
343 $a->set_pager_total(count($r));
344 $a->set_pager_itemspage(20);
347 $r = q("SELECT hash, `id`, `filename`, filetype FROM `attach`
348 WHERE `uid` = %d AND filetype LIKE '%%video%%'
349 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
350 intval($a->data['user']['uid']),
351 intval($a->pager['start']),
352 intval($a->pager['itemspage'])
360 if($a->theme['template_engine'] === 'internal') {
361 $alt_e = template_escape($rr['filename']);
362 $name_e = template_escape($rr['album']);
365 $alt_e = $rr['filename'];
366 $name_e = $rr['album'];
371 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
372 'title' => t('View Video'),
373 'src' => $a->get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0',
375 'mime' => $rr['filetype'],
377 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
379 'alt' => t('View Album'),
386 $tpl = get_markup_template('videos_recent.tpl');
387 $o .= replace_macros($tpl, array(
388 '$title' => t('Recent Videos'),
389 '$can_post' => $can_post,
390 '$upload' => array(t('Upload New Videos'), $a->get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'),
391 '$videos' => $videos,
392 '$delete_url' => (($can_post)?$a->get_baseurl().'/videos/'.$a->data['user']['nickname']:False)