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 $o .= '<div class="vcard">';
32 $o .= '<div class="fn">' . $a->data['user']['username'] . '</div>';
33 $o .= '<div id="profile-photo-wrapper"><img class="photo" style="width: 175px; height: 175px;" src="' . $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg') . '" alt="' . $a->data['user']['username'] . '" /></div>';
37 /*$sql_extra = permissions_sql($a->data['user']['uid']);
39 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
40 intval($a->data['user']['uid'])
44 $a->data['albums'] = $albums;
46 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
49 $o .= '<div id="side-bar-photos-albums" class="widget">';
50 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
53 foreach($albums as $album) {
55 // don't show contact photos. We once translated this name, but then you could still access it under
56 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
58 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
60 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
64 if(local_user() && $a->data['user']['uid'] == local_user()) {
65 $o .= '<div id="photo-albums-upload-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
71 if(! x($a->page,'aside'))
72 $a->page['aside'] = '';
73 $a->page['aside'] .= $o;
76 $tpl = get_markup_template("videos_head.tpl");
77 $a->page['htmlhead'] .= replace_macros($tpl,array(
78 '$baseurl' => $a->get_baseurl(),
81 $tpl = get_markup_template("videos_end.tpl");
82 $a->page['end'] .= replace_macros($tpl,array(
83 '$baseurl' => $a->get_baseurl(),
93 function videos_post(&$a) {
95 $owner_uid = $a->data['user']['uid'];
97 if (local_user() != $owner_uid) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
99 if(($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
101 // Check if we should do HTML-based delete confirmation
102 if(!x($_REQUEST,'confirm')) {
103 if(x($_REQUEST,'canceled')) goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
105 $drop_url = $a->query_string;
106 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
108 '$message' => t('Do you really want to delete this video?'),
110 ['name'=>'id', 'value'=> $_POST['id']],
111 ['name'=>'delete', 'value'=>'x']
113 '$confirm' => t('Delete Video'),
114 '$confirm_url' => $drop_url,
115 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
116 '$cancel' => t('Cancel'),
119 $a->error = 1; // Set $a->error so the other module functions don't execute
123 $video_id = $_POST['id'];
126 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
127 intval(local_user()),
132 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
133 intval(local_user()),
136 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
140 #echo "<pre>"; var_dump($i); killme();
142 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
143 dbesc(datetime_convert()),
144 dbesc(datetime_convert()),
148 create_tags_from_itemuri($i[0]['uri'], local_user());
149 delete_thread_uri($i[0]['uri'], local_user());
151 $url = $a->get_baseurl();
152 $drop_id = intval($i[0]['id']);
155 proc_run('php',"include/notifier.php","drop","$drop_id");
159 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
160 return; // NOTREACHED
163 goaway($a->get_baseurl() . '/videos/' . $a->data['user']['nickname']);
169 function videos_content(&$a) {
171 // URLs (most aren't currently implemented):
173 // videos/name/upload
174 // videos/name/upload/xxxxx (xxxxx is album name)
175 // videos/name/album/xxxxx
176 // videos/name/album/xxxxx/edit
177 // videos/name/video/xxxxx
178 // videos/name/video/xxxxx/edit
181 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
182 notice( t('Public access denied.') . EOL);
187 require_once('include/bbcode.php');
188 require_once('include/security.php');
189 require_once('include/conversation.php');
191 if(! x($a->data,'user')) {
192 notice( t('No videos selected') . EOL );
196 //$phototypes = Photo::supportedTypes();
198 $_SESSION['video_return'] = $a->cmd;
205 $datatype = $a->argv[2];
206 $datum = $a->argv[3];
208 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
209 $datatype = 'upload';
211 $datatype = 'summary';
219 // Setup permissions structures
225 $remote_contact = false;
228 $owner_uid = $a->data['user']['uid'];
230 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
232 if((local_user()) && (local_user() == $owner_uid))
235 if($community_page && remote_user()) {
236 if(is_array($_SESSION['remote'])) {
237 foreach($_SESSION['remote'] as $v) {
238 if($v['uid'] == $owner_uid) {
239 $contact_id = $v['cid'];
246 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
253 $remote_contact = true;
260 // perhaps they're visiting - but not a community page, so they wouldn't have write access
262 if(remote_user() && (! $visitor)) {
264 if(is_array($_SESSION['remote'])) {
265 foreach($_SESSION['remote'] as $v) {
266 if($v['uid'] == $owner_uid) {
267 $contact_id = $v['cid'];
273 $groups = init_groups_visitor($contact_id);
274 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
280 $remote_contact = true;
285 if(! $remote_contact) {
287 $contact_id = $_SESSION['cid'];
288 $contact = $a->contact;
292 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
293 notice( t('Access to this item is restricted.') . EOL);
297 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
302 $_is_owner = (local_user() && (local_user() == $owner_uid));
303 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
310 if($datatype === 'upload') {
311 return; // no uploading for now
313 // DELETED -- look at mod/photos.php if you want to implement
316 if($datatype === 'album') {
318 return; // no albums for now
320 // DELETED -- look at mod/photos.php if you want to implement
324 if($datatype === 'video') {
326 return; // no single video view for now
328 // DELETED -- look at mod/photos.php if you want to implement
331 // Default - show recent videos (no upload link for now)
334 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
335 $sql_extra GROUP BY hash",
336 intval($a->data['user']['uid'])
339 $a->set_pager_total(count($r));
340 $a->set_pager_itemspage(20);
343 $r = q("SELECT hash, `id`, `filename`, filetype FROM `attach`
344 WHERE `uid` = %d AND filetype LIKE '%%video%%'
345 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
346 intval($a->data['user']['uid']),
347 intval($a->pager['start']),
348 intval($a->pager['itemspage'])
356 if($a->theme['template_engine'] === 'internal') {
357 $alt_e = template_escape($rr['filename']);
358 $name_e = template_escape($rr['album']);
361 $alt_e = $rr['filename'];
362 $name_e = $rr['album'];
367 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
368 'title' => t('View Video'),
369 'src' => $a->get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0',
371 'mime' => $rr['filetype'],
373 'link' => $a->get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
375 'alt' => t('View Album'),
382 $tpl = get_markup_template('videos_recent.tpl');
383 $o .= replace_macros($tpl, array(
384 '$title' => t('Recent Videos'),
385 '$can_post' => $can_post,
386 '$upload' => array(t('Upload New Videos'), $a->get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'),
387 '$videos' => $videos,
388 '$delete_url' => (($can_post)?$a->get_baseurl().'/videos/'.$a->data['user']['nickname']:False)