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']);
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,
51 /*$sql_extra = permissions_sql($a->data['user']['uid']);
53 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
54 intval($a->data['user']['uid'])
58 $a->data['albums'] = $albums;
60 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
63 $o .= '<div id="side-bar-photos-albums" class="widget">';
64 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
67 foreach($albums as $album) {
69 // don't show contact photos. We once translated this name, but then you could still access it under
70 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
72 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
74 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
78 if(local_user() && $a->data['user']['uid'] == local_user()) {
79 $o .= '<div id="photo-albums-upload-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
85 if(! x($a->page,'aside'))
86 $a->page['aside'] = '';
87 $a->page['aside'] .= $vcard_widget;
90 $tpl = get_markup_template("videos_head.tpl");
91 $a->page['htmlhead'] .= replace_macros($tpl,array(
92 '$baseurl' => $a->get_baseurl(),
95 $tpl = get_markup_template("videos_end.tpl");
96 $a->page['end'] .= replace_macros($tpl,array(
97 '$baseurl' => $a->get_baseurl(),
107 function videos_post(&$a) {
109 $owner_uid = $a->data['user']['uid'];
111 if (local_user() != $owner_uid) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
113 if(($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
115 // Check if we should do HTML-based delete confirmation
116 if(!x($_REQUEST,'confirm')) {
117 if(x($_REQUEST,'canceled')) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
119 $drop_url = $a->query_string;
120 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
122 '$message' => t('Do you really want to delete this video?'),
123 '$extra_inputs' => array(
124 array('name'=>'id', 'value'=> $_POST['id']),
125 array('name'=>'delete', 'value'=>'x')
127 '$confirm' => t('Delete Video'),
128 '$confirm_url' => $drop_url,
129 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
130 '$cancel' => t('Cancel'),
133 $a->error = 1; // Set $a->error so the other module functions don't execute
137 $video_id = $_POST['id'];
140 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
141 intval(local_user()),
146 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
147 intval(local_user()),
150 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
154 #echo "<pre>"; var_dump($i); killme();
156 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
157 dbesc(datetime_convert()),
158 dbesc(datetime_convert()),
162 create_tags_from_itemuri($i[0]['uri'], local_user());
163 delete_thread_uri($i[0]['uri'], local_user());
165 $url = $a->get_baseurl();
166 $drop_id = intval($i[0]['id']);
169 proc_run('php',"include/notifier.php","drop","$drop_id");
173 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
174 return; // NOTREACHED
177 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
183 function videos_content(&$a) {
185 // URLs (most aren't currently implemented):
187 // videos/name/upload
188 // videos/name/upload/xxxxx (xxxxx is album name)
189 // videos/name/album/xxxxx
190 // videos/name/album/xxxxx/edit
191 // videos/name/video/xxxxx
192 // videos/name/video/xxxxx/edit
195 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
196 notice( t('Public access denied.') . EOL);
201 require_once('include/bbcode.php');
202 require_once('include/security.php');
203 require_once('include/conversation.php');
205 if(! x($a->data,'user')) {
206 notice( t('No videos selected') . EOL );
210 //$phototypes = Photo::supportedTypes();
212 $_SESSION['video_return'] = $a->cmd;
219 $datatype = $a->argv[2];
220 $datum = $a->argv[3];
222 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
223 $datatype = 'upload';
225 $datatype = 'summary';
233 // Setup permissions structures
239 $remote_contact = false;
242 $owner_uid = $a->data['user']['uid'];
244 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
246 if((local_user()) && (local_user() == $owner_uid))
249 if($community_page && remote_user()) {
250 if(is_array($_SESSION['remote'])) {
251 foreach($_SESSION['remote'] as $v) {
252 if($v['uid'] == $owner_uid) {
253 $contact_id = $v['cid'];
260 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
267 $remote_contact = true;
274 // perhaps they're visiting - but not a community page, so they wouldn't have write access
276 if(remote_user() && (! $visitor)) {
278 if(is_array($_SESSION['remote'])) {
279 foreach($_SESSION['remote'] as $v) {
280 if($v['uid'] == $owner_uid) {
281 $contact_id = $v['cid'];
287 $groups = init_groups_visitor($contact_id);
288 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
294 $remote_contact = true;
299 if(! $remote_contact) {
301 $contact_id = $_SESSION['cid'];
302 $contact = $a->contact;
306 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
307 notice( t('Access to this item is restricted.') . EOL);
311 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
316 $_is_owner = (local_user() && (local_user() == $owner_uid));
317 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
324 if($datatype === 'upload') {
325 return; // no uploading for now
327 // DELETED -- look at mod/photos.php if you want to implement
330 if($datatype === 'album') {
332 return; // no albums for now
334 // DELETED -- look at mod/photos.php if you want to implement
338 if($datatype === 'video') {
340 return; // no single video view for now
342 // DELETED -- look at mod/photos.php if you want to implement
345 // Default - show recent videos (no upload link for now)
348 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
349 $sql_extra GROUP BY hash",
350 intval($a->data['user']['uid'])
353 $a->set_pager_total(count($r));
354 $a->set_pager_itemspage(20);
357 $r = q("SELECT hash, `id`, `filename`, filetype FROM `attach`
358 WHERE `uid` = %d AND filetype LIKE '%%video%%'
359 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
360 intval($a->data['user']['uid']),
361 intval($a->pager['start']),
362 intval($a->pager['itemspage'])
370 if($a->theme['template_engine'] === 'internal') {
371 $alt_e = template_escape($rr['filename']);
372 $name_e = template_escape($rr['album']);
375 $alt_e = $rr['filename'];
376 $name_e = $rr['album'];
381 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
382 'title' => t('View Video'),
383 'src' => $a->get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0',
385 'mime' => $rr['filetype'],
387 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
389 'alt' => t('View Album'),
396 $tpl = get_markup_template('videos_recent.tpl');
397 $o .= replace_macros($tpl, array(
398 '$title' => t('Recent Videos'),
399 '$can_post' => $can_post,
400 '$upload' => array(t('Upload New Videos'), $a->get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'),
401 '$videos' => $videos,
402 '$delete_url' => (($can_post)?$a->get_baseurl().'/videos/'.$a->data['user']['nickname']:False)