4 use Friendica\Core\Config;
5 use Friendica\Core\System;
6 use Friendica\Core\Worker;
8 require_once('include/items.php');
9 require_once('include/acl_selectors.php');
10 require_once('include/bbcode.php');
11 require_once('include/security.php');
12 require_once('include/redir.php');
14 function videos_init(App $a) {
17 auto_redir($a, $a->argv[1]);
19 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
23 nav_set_selected('home');
29 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
36 $a->data['user'] = $user[0];
37 $a->profile_uid = $user[0]['uid'];
39 $profile = get_profiledata_by_nick($nick, $a->profile_uid);
41 $account_type = account_type($profile);
43 $tpl = get_markup_template("vcard-widget.tpl");
45 $vcard_widget .= replace_macros($tpl, array(
46 '$name' => $profile['name'],
47 '$photo' => $profile['photo'],
48 '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
49 '$account_type' => $account_type,
50 '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
54 /*$sql_extra = permissions_sql($a->data['user']['uid']);
56 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
57 intval($a->data['user']['uid'])
61 $a->data['albums'] = $albums;
63 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
66 $o .= '<div id="sidebar-photos-albums" class="widget">';
67 $o .= '<h3>' . '<a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
70 foreach($albums as $album) {
72 // don't show contact photos. We once translated this name, but then you could still access it under
73 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
75 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
77 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
81 if(local_user() && $a->data['user']['uid'] == local_user()) {
82 $o .= '<div id="photo-albums-upload-link"><a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
88 if(! x($a->page,'aside'))
89 $a->page['aside'] = '';
90 $a->page['aside'] .= $vcard_widget;
93 $tpl = get_markup_template("videos_head.tpl");
94 $a->page['htmlhead'] .= replace_macros($tpl,array(
95 '$baseurl' => System::baseUrl(),
98 $tpl = get_markup_template("videos_end.tpl");
99 $a->page['end'] .= replace_macros($tpl,array(
100 '$baseurl' => System::baseUrl(),
110 function videos_post(App $a) {
112 $owner_uid = $a->data['user']['uid'];
114 if (local_user() != $owner_uid) {
115 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
118 if (($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
120 // Check if we should do HTML-based delete confirmation
121 if (!x($_REQUEST,'confirm')) {
122 if (x($_REQUEST,'canceled')) {
123 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
126 $drop_url = $a->query_string;
127 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
129 '$message' => t('Do you really want to delete this video?'),
130 '$extra_inputs' => array(
131 array('name'=>'id', 'value'=> $_POST['id']),
132 array('name'=>'delete', 'value'=>'x')
134 '$confirm' => t('Delete Video'),
135 '$confirm_url' => $drop_url,
136 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
137 '$cancel' => t('Cancel'),
140 $a->error = 1; // Set $a->error so the other module functions don't execute
144 $video_id = $_POST['id'];
146 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
147 intval(local_user()),
151 if (dbm::is_result($r)) {
152 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
153 intval(local_user()),
156 $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
160 //echo "<pre>"; var_dump($i); killme();
161 if (dbm::is_result($i)) {
162 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
163 dbesc(datetime_convert()),
164 dbesc(datetime_convert()),
168 create_tags_from_itemuri($i[0]['uri'], local_user());
169 delete_thread_uri($i[0]['uri'], local_user());
171 $url = System::baseUrl();
172 $drop_id = intval($i[0]['id']);
174 if ($i[0]['visible']) {
175 Worker::add(PRIORITY_HIGH, "notifier", "drop", $drop_id);
180 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
181 return; // NOTREACHED
184 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
190 function videos_content(App $a) {
192 // URLs (most aren't currently implemented):
194 // videos/name/upload
195 // videos/name/upload/xxxxx (xxxxx is album name)
196 // videos/name/album/xxxxx
197 // videos/name/album/xxxxx/edit
198 // videos/name/video/xxxxx
199 // videos/name/video/xxxxx/edit
202 if((Config::get('system','block_public')) && (! local_user()) && (! remote_user())) {
203 notice( t('Public access denied.') . EOL);
208 require_once('include/bbcode.php');
209 require_once('include/security.php');
210 require_once('include/conversation.php');
212 if(! x($a->data,'user')) {
213 notice( t('No videos selected') . EOL );
217 //$phototypes = Photo::supportedTypes();
219 $_SESSION['video_return'] = $a->cmd;
226 $datatype = $a->argv[2];
227 $datum = $a->argv[3];
229 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
230 $datatype = 'upload';
232 $datatype = 'summary';
240 // Setup permissions structures
246 $remote_contact = false;
249 $owner_uid = $a->data['user']['uid'];
251 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
253 if((local_user()) && (local_user() == $owner_uid))
256 if($community_page && remote_user()) {
257 if(is_array($_SESSION['remote'])) {
258 foreach($_SESSION['remote'] as $v) {
259 if($v['uid'] == $owner_uid) {
260 $contact_id = $v['cid'];
267 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
271 if (dbm::is_result($r)) {
274 $remote_contact = true;
275 $visitor = $contact_id;
281 // perhaps they're visiting - but not a community page, so they wouldn't have write access
283 if(remote_user() && (! $visitor)) {
285 if(is_array($_SESSION['remote'])) {
286 foreach($_SESSION['remote'] as $v) {
287 if($v['uid'] == $owner_uid) {
288 $contact_id = $v['cid'];
294 $groups = init_groups_visitor($contact_id);
295 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
299 if (dbm::is_result($r)) {
301 $remote_contact = true;
306 if(! $remote_contact) {
308 $contact_id = $_SESSION['cid'];
309 $contact = $a->contact;
313 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
314 notice( t('Access to this item is restricted.') . EOL);
318 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
323 $_is_owner = (local_user() && (local_user() == $owner_uid));
324 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
331 if($datatype === 'upload') {
332 return; // no uploading for now
334 // DELETED -- look at mod/photos.php if you want to implement
337 if($datatype === 'album') {
339 return; // no albums for now
341 // DELETED -- look at mod/photos.php if you want to implement
345 if($datatype === 'video') {
347 return; // no single video view for now
349 // DELETED -- look at mod/photos.php if you want to implement
352 // Default - show recent videos (no upload link for now)
355 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
356 $sql_extra GROUP BY hash",
357 intval($a->data['user']['uid'])
359 if (dbm::is_result($r)) {
360 $a->set_pager_total(count($r));
361 $a->set_pager_itemspage(20);
364 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
365 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
367 WHERE `uid` = %d AND filetype LIKE '%%video%%'
368 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
369 intval($a->data['user']['uid']),
370 intval($a->pager['start']),
371 intval($a->pager['itemspage'])
377 if (dbm::is_result($r)) {
378 foreach ($r as $rr) {
379 if ($a->theme['template_engine'] === 'internal') {
380 $alt_e = template_escape($rr['filename']);
381 $name_e = template_escape($rr['album']);
384 $alt_e = $rr['filename'];
385 $name_e = $rr['album'];
390 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
391 'title' => t('View Video'),
392 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
394 'mime' => $rr['filetype'],
396 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
398 'alt' => t('View Album'),
405 $tpl = get_markup_template('videos_recent.tpl');
406 $o .= replace_macros($tpl, array(
407 '$title' => t('Recent Videos'),
408 '$can_post' => $can_post,
409 '$upload' => array(t('Upload New Videos'), System::baseUrl().'/videos/'.$a->data['user']['nickname'].'/upload'),
410 '$videos' => $videos,
411 '$delete_url' => (($can_post)?System::baseUrl().'/videos/'.$a->data['user']['nickname']:False)