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((intval($profile['page-flags']) == PAGE_COMMUNITY) || (intval($profile['page-flags']) == PAGE_PRVGROUP))
37 $account_type = t('Forum');
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,
48 '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
52 /*$sql_extra = permissions_sql($a->data['user']['uid']);
54 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
55 intval($a->data['user']['uid'])
59 $a->data['albums'] = $albums;
61 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
64 $o .= '<div id="sidebar-photos-albums" class="widget">';
65 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
68 foreach($albums as $album) {
70 // don't show contact photos. We once translated this name, but then you could still access it under
71 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
73 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
75 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
79 if(local_user() && $a->data['user']['uid'] == local_user()) {
80 $o .= '<div id="photo-albums-upload-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
86 if(! x($a->page,'aside'))
87 $a->page['aside'] = '';
88 $a->page['aside'] .= $vcard_widget;
91 $tpl = get_markup_template("videos_head.tpl");
92 $a->page['htmlhead'] .= replace_macros($tpl,array(
93 '$baseurl' => $a->get_baseurl(),
96 $tpl = get_markup_template("videos_end.tpl");
97 $a->page['end'] .= replace_macros($tpl,array(
98 '$baseurl' => $a->get_baseurl(),
108 function videos_post(&$a) {
110 $owner_uid = $a->data['user']['uid'];
112 if (local_user() != $owner_uid) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
114 if(($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
116 // Check if we should do HTML-based delete confirmation
117 if(!x($_REQUEST,'confirm')) {
118 if(x($_REQUEST,'canceled')) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
120 $drop_url = $a->query_string;
121 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
123 '$message' => t('Do you really want to delete this video?'),
124 '$extra_inputs' => array(
125 array('name'=>'id', 'value'=> $_POST['id']),
126 array('name'=>'delete', 'value'=>'x')
128 '$confirm' => t('Delete Video'),
129 '$confirm_url' => $drop_url,
130 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
131 '$cancel' => t('Cancel'),
134 $a->error = 1; // Set $a->error so the other module functions don't execute
138 $video_id = $_POST['id'];
141 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
142 intval(local_user()),
147 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
148 intval(local_user()),
151 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
155 #echo "<pre>"; var_dump($i); killme();
157 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
158 dbesc(datetime_convert()),
159 dbesc(datetime_convert()),
163 create_tags_from_itemuri($i[0]['uri'], local_user());
164 delete_thread_uri($i[0]['uri'], local_user());
166 $url = $a->get_baseurl();
167 $drop_id = intval($i[0]['id']);
170 proc_run('php',"include/notifier.php","drop","$drop_id");
174 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
175 return; // NOTREACHED
178 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
184 function videos_content(&$a) {
186 // URLs (most aren't currently implemented):
188 // videos/name/upload
189 // videos/name/upload/xxxxx (xxxxx is album name)
190 // videos/name/album/xxxxx
191 // videos/name/album/xxxxx/edit
192 // videos/name/video/xxxxx
193 // videos/name/video/xxxxx/edit
196 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
197 notice( t('Public access denied.') . EOL);
202 require_once('include/bbcode.php');
203 require_once('include/security.php');
204 require_once('include/conversation.php');
206 if(! x($a->data,'user')) {
207 notice( t('No videos selected') . EOL );
211 //$phototypes = Photo::supportedTypes();
213 $_SESSION['video_return'] = $a->cmd;
220 $datatype = $a->argv[2];
221 $datum = $a->argv[3];
223 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
224 $datatype = 'upload';
226 $datatype = 'summary';
234 // Setup permissions structures
240 $remote_contact = false;
243 $owner_uid = $a->data['user']['uid'];
245 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
247 if((local_user()) && (local_user() == $owner_uid))
250 if($community_page && remote_user()) {
251 if(is_array($_SESSION['remote'])) {
252 foreach($_SESSION['remote'] as $v) {
253 if($v['uid'] == $owner_uid) {
254 $contact_id = $v['cid'];
261 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
268 $remote_contact = true;
275 // perhaps they're visiting - but not a community page, so they wouldn't have write access
277 if(remote_user() && (! $visitor)) {
279 if(is_array($_SESSION['remote'])) {
280 foreach($_SESSION['remote'] as $v) {
281 if($v['uid'] == $owner_uid) {
282 $contact_id = $v['cid'];
288 $groups = init_groups_visitor($contact_id);
289 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
295 $remote_contact = true;
300 if(! $remote_contact) {
302 $contact_id = $_SESSION['cid'];
303 $contact = $a->contact;
307 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
308 notice( t('Access to this item is restricted.') . EOL);
312 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
317 $_is_owner = (local_user() && (local_user() == $owner_uid));
318 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
325 if($datatype === 'upload') {
326 return; // no uploading for now
328 // DELETED -- look at mod/photos.php if you want to implement
331 if($datatype === 'album') {
333 return; // no albums for now
335 // DELETED -- look at mod/photos.php if you want to implement
339 if($datatype === 'video') {
341 return; // no single video view for now
343 // DELETED -- look at mod/photos.php if you want to implement
346 // Default - show recent videos (no upload link for now)
349 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
350 $sql_extra GROUP BY hash",
351 intval($a->data['user']['uid'])
354 $a->set_pager_total(count($r));
355 $a->set_pager_itemspage(20);
358 $r = q("SELECT hash, `id`, `filename`, filetype FROM `attach`
359 WHERE `uid` = %d AND filetype LIKE '%%video%%'
360 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
361 intval($a->data['user']['uid']),
362 intval($a->pager['start']),
363 intval($a->pager['itemspage'])
371 if($a->theme['template_engine'] === 'internal') {
372 $alt_e = template_escape($rr['filename']);
373 $name_e = template_escape($rr['album']);
376 $alt_e = $rr['filename'];
377 $name_e = $rr['album'];
382 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
383 'title' => t('View Video'),
384 'src' => $a->get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0',
386 'mime' => $rr['filetype'],
388 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
390 'alt' => t('View Album'),
397 $tpl = get_markup_template('videos_recent.tpl');
398 $o .= replace_macros($tpl, array(
399 '$title' => t('Recent Videos'),
400 '$can_post' => $can_post,
401 '$upload' => array(t('Upload New Videos'), $a->get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'),
402 '$videos' => $videos,
403 '$delete_url' => (($can_post)?$a->get_baseurl().'/videos/'.$a->data['user']['nickname']:False)