5 require_once('include/items.php');
6 require_once('include/acl_selectors.php');
7 require_once('include/bbcode.php');
8 require_once('include/security.php');
9 require_once('include/redir.php');
11 function videos_init(App $a) {
14 auto_redir($a, $a->argv[1]);
16 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
20 nav_set_selected('home');
26 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
33 $a->data['user'] = $user[0];
34 $a->profile_uid = $user[0]['uid'];
36 $profile = get_profiledata_by_nick($nick, $a->profile_uid);
38 $account_type = account_type($profile);
40 $tpl = get_markup_template("vcard-widget.tpl");
42 $vcard_widget .= replace_macros($tpl, array(
43 '$name' => $profile['name'],
44 '$photo' => $profile['photo'],
45 '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
46 '$account_type' => $account_type,
47 '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
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="sidebar-photos-albums" class="widget">';
64 $o .= '<h3>' . '<a href="' . App::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="' . App::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' => App::get_baseurl(),
95 $tpl = get_markup_template("videos_end.tpl");
96 $a->page['end'] .= replace_macros($tpl,array(
97 '$baseurl' => App::get_baseurl(),
107 function videos_post(App $a) {
109 $owner_uid = $a->data['user']['uid'];
111 if (local_user() != $owner_uid) {
112 goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
115 if (($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
117 // Check if we should do HTML-based delete confirmation
118 if (!x($_REQUEST,'confirm')) {
119 if (x($_REQUEST,'canceled')) {
120 goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
123 $drop_url = $a->query_string;
124 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
126 '$message' => t('Do you really want to delete this video?'),
127 '$extra_inputs' => array(
128 array('name'=>'id', 'value'=> $_POST['id']),
129 array('name'=>'delete', 'value'=>'x')
131 '$confirm' => t('Delete Video'),
132 '$confirm_url' => $drop_url,
133 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
134 '$cancel' => t('Cancel'),
137 $a->error = 1; // Set $a->error so the other module functions don't execute
141 $video_id = $_POST['id'];
143 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
144 intval(local_user()),
148 if (dbm::is_result($r)) {
149 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
150 intval(local_user()),
153 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
157 //echo "<pre>"; var_dump($i); killme();
158 if (dbm::is_result($i)) {
159 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
160 dbesc(datetime_convert()),
161 dbesc(datetime_convert()),
165 create_tags_from_itemuri($i[0]['uri'], local_user());
166 delete_thread_uri($i[0]['uri'], local_user());
168 $url = App::get_baseurl();
169 $drop_id = intval($i[0]['id']);
171 if ($i[0]['visible']) {
172 proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
177 goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
178 return; // NOTREACHED
181 goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
187 function videos_content(App $a) {
189 // URLs (most aren't currently implemented):
191 // videos/name/upload
192 // videos/name/upload/xxxxx (xxxxx is album name)
193 // videos/name/album/xxxxx
194 // videos/name/album/xxxxx/edit
195 // videos/name/video/xxxxx
196 // videos/name/video/xxxxx/edit
199 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
200 notice( t('Public access denied.') . EOL);
205 require_once('include/bbcode.php');
206 require_once('include/security.php');
207 require_once('include/conversation.php');
209 if(! x($a->data,'user')) {
210 notice( t('No videos selected') . EOL );
214 //$phototypes = Photo::supportedTypes();
216 $_SESSION['video_return'] = $a->cmd;
223 $datatype = $a->argv[2];
224 $datum = $a->argv[3];
226 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
227 $datatype = 'upload';
229 $datatype = 'summary';
237 // Setup permissions structures
243 $remote_contact = false;
246 $owner_uid = $a->data['user']['uid'];
248 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
250 if((local_user()) && (local_user() == $owner_uid))
253 if($community_page && remote_user()) {
254 if(is_array($_SESSION['remote'])) {
255 foreach($_SESSION['remote'] as $v) {
256 if($v['uid'] == $owner_uid) {
257 $contact_id = $v['cid'];
264 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
268 if (dbm::is_result($r)) {
271 $remote_contact = true;
272 $visitor = $contact_id;
278 // perhaps they're visiting - but not a community page, so they wouldn't have write access
280 if(remote_user() && (! $visitor)) {
282 if(is_array($_SESSION['remote'])) {
283 foreach($_SESSION['remote'] as $v) {
284 if($v['uid'] == $owner_uid) {
285 $contact_id = $v['cid'];
291 $groups = init_groups_visitor($contact_id);
292 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
296 if (dbm::is_result($r)) {
298 $remote_contact = true;
303 if(! $remote_contact) {
305 $contact_id = $_SESSION['cid'];
306 $contact = $a->contact;
310 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
311 notice( t('Access to this item is restricted.') . EOL);
315 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
320 $_is_owner = (local_user() && (local_user() == $owner_uid));
321 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
328 if($datatype === 'upload') {
329 return; // no uploading for now
331 // DELETED -- look at mod/photos.php if you want to implement
334 if($datatype === 'album') {
336 return; // no albums for now
338 // DELETED -- look at mod/photos.php if you want to implement
342 if($datatype === 'video') {
344 return; // no single video view for now
346 // DELETED -- look at mod/photos.php if you want to implement
349 // Default - show recent videos (no upload link for now)
352 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
353 $sql_extra GROUP BY hash",
354 intval($a->data['user']['uid'])
356 if (dbm::is_result($r)) {
357 $a->set_pager_total(count($r));
358 $a->set_pager_itemspage(20);
361 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
362 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
364 WHERE `uid` = %d AND filetype LIKE '%%video%%'
365 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
366 intval($a->data['user']['uid']),
367 intval($a->pager['start']),
368 intval($a->pager['itemspage'])
374 if (dbm::is_result($r)) {
375 foreach ($r as $rr) {
376 if ($a->theme['template_engine'] === 'internal') {
377 $alt_e = template_escape($rr['filename']);
378 $name_e = template_escape($rr['album']);
381 $alt_e = $rr['filename'];
382 $name_e = $rr['album'];
387 'link' => App::get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
388 'title' => t('View Video'),
389 'src' => App::get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0',
391 'mime' => $rr['filetype'],
393 'link' => App::get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
395 'alt' => t('View Album'),
402 $tpl = get_markup_template('videos_recent.tpl');
403 $o .= replace_macros($tpl, array(
404 '$title' => t('Recent Videos'),
405 '$can_post' => $can_post,
406 '$upload' => array(t('Upload New Videos'), App::get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'),
407 '$videos' => $videos,
408 '$delete_url' => (($can_post)?App::get_baseurl().'/videos/'.$a->data['user']['nickname']:False)