]> git.mxchange.org Git - friendica.git/blob - mod/videos.php
e8f8356fbd814c6e472fbc94967c6cd6fa617ebb
[friendica.git] / mod / videos.php
1 <?php
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');
7
8 function videos_init(App $a) {
9
10         if($a->argc > 1)
11                 auto_redir($a, $a->argv[1]);
12
13         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
14                 return;
15         }
16
17         nav_set_selected('home');
18
19         $o = '';
20
21         if($a->argc > 1) {
22                 $nick = $a->argv[1];
23                 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
24                         dbesc($nick)
25                 );
26
27                 if(! count($user))
28                         return;
29
30                 $a->data['user'] = $user[0];
31                 $a->profile_uid = $user[0]['uid'];
32
33                 $profile = get_profiledata_by_nick($nick, $a->profile_uid);
34
35                 $account_type = account_type($profile);
36
37                 $tpl = get_markup_template("vcard-widget.tpl");
38
39                 $vcard_widget .= replace_macros($tpl, array(
40                         '$name' => $profile['name'],
41                         '$photo' => $profile['photo'],
42                         '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
43                         '$account_type' => $account_type,
44                         '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
45                 ));
46
47
48                 /*$sql_extra = permissions_sql($a->data['user']['uid']);
49
50                 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
51                         intval($a->data['user']['uid'])
52                 );
53
54                 if(count($albums)) {
55                         $a->data['albums'] = $albums;
56
57                         $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
58
59                         if($albums_visible) {
60                                 $o .= '<div id="sidebar-photos-albums" class="widget">';
61                                 $o .= '<h3>' . '<a href="' . App::get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
62
63                                 $o .= '<ul>';
64                                 foreach($albums as $album) {
65
66                                         // don't show contact photos. We once translated this name, but then you could still access it under
67                                         // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
68
69                                         if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
70                                                 continue;
71                                         $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
72                                 }
73                                 $o .= '</ul>';
74                         }
75                         if(local_user() && $a->data['user']['uid'] == local_user()) {
76                                 $o .= '<div id="photo-albums-upload-link"><a href="' . App::get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
77                         }
78
79                         $o .= '</div>';
80                 }*/
81
82                 if(! x($a->page,'aside'))
83                         $a->page['aside'] = '';
84                 $a->page['aside'] .= $vcard_widget;
85
86
87                 $tpl = get_markup_template("videos_head.tpl");
88                 $a->page['htmlhead'] .= replace_macros($tpl,array(
89                         '$baseurl' => App::get_baseurl(),
90                 ));
91
92                 $tpl = get_markup_template("videos_end.tpl");
93                 $a->page['end'] .= replace_macros($tpl,array(
94                         '$baseurl' => App::get_baseurl(),
95                 ));
96
97         }
98
99         return;
100 }
101
102
103
104 function videos_post(App $a) {
105
106         $owner_uid = $a->data['user']['uid'];
107
108         if (local_user() != $owner_uid) {
109                 goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
110         }
111
112         if (($a->argc == 2) && x($_POST,'delete') && x($_POST, 'id')) {
113
114                 // Check if we should do HTML-based delete confirmation
115                 if (!x($_REQUEST,'confirm')) {
116                         if (x($_REQUEST,'canceled')) {
117                                 goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
118                         }
119
120                         $drop_url = $a->query_string;
121                         $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
122                                 '$method' => 'post',
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')
127                                 ),
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'),
132
133                         ));
134                         $a->error = 1; // Set $a->error so the other module functions don't execute
135                         return;
136                 }
137
138                 $video_id = $_POST['id'];
139
140                 $r = q("SELECT `id`  FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
141                         intval(local_user()),
142                         dbesc($video_id)
143                 );
144
145                 if (dbm::is_result($r)) {
146                         q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
147                                 intval(local_user()),
148                                 dbesc($video_id)
149                         );
150                         $i = q("SELECT * FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
151                                 dbesc($video_id),
152                                 intval(local_user())
153                         );
154                         //echo "<pre>"; var_dump($i); killme();
155                         if (dbm::is_result($i)) {
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()),
159                                         dbesc($i[0]['uri']),
160                                         intval(local_user())
161                                 );
162                                 create_tags_from_itemuri($i[0]['uri'], local_user());
163                                 delete_thread_uri($i[0]['uri'], local_user());
164
165                                 $url = App::get_baseurl();
166                                 $drop_id = intval($i[0]['id']);
167
168                                 if ($i[0]['visible']) {
169                                         proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
170                                 }
171                         }
172                 }
173
174                 goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
175                 return; // NOTREACHED
176         }
177
178         goaway(App::get_baseurl() . '/videos/' . $a->data['user']['nickname']);
179
180 }
181
182
183
184 function videos_content(App $a) {
185
186         // URLs (most aren't currently implemented):
187         // videos/name
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
194
195
196         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
197                 notice( t('Public access denied.') . EOL);
198                 return;
199         }
200
201
202         require_once('include/bbcode.php');
203         require_once('include/security.php');
204         require_once('include/conversation.php');
205
206         if(! x($a->data,'user')) {
207                 notice( t('No videos selected') . EOL );
208                 return;
209         }
210
211         //$phototypes = Photo::supportedTypes();
212
213         $_SESSION['video_return'] = $a->cmd;
214
215         //
216         // Parse arguments
217         //
218
219         if($a->argc > 3) {
220                 $datatype = $a->argv[2];
221                 $datum = $a->argv[3];
222         }
223         elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
224                 $datatype = 'upload';
225         else
226                 $datatype = 'summary';
227
228         if($a->argc > 4)
229                 $cmd = $a->argv[4];
230         else
231                 $cmd = 'view';
232
233         //
234         // Setup permissions structures
235         //
236
237         $can_post       = false;
238         $visitor        = 0;
239         $contact        = null;
240         $remote_contact = false;
241         $contact_id     = 0;
242
243         $owner_uid = $a->data['user']['uid'];
244
245         $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
246
247         if((local_user()) && (local_user() == $owner_uid))
248                 $can_post = true;
249         else {
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'];
255                                                 break;
256                                         }
257                                 }
258                         }
259                         if($contact_id) {
260
261                                 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
262                                         intval($contact_id),
263                                         intval($owner_uid)
264                                 );
265                                 if (dbm::is_result($r)) {
266                                         $can_post = true;
267                                         $contact = $r[0];
268                                         $remote_contact = true;
269                                         $visitor = $contact_id;
270                                 }
271                         }
272                 }
273         }
274
275         // perhaps they're visiting - but not a community page, so they wouldn't have write access
276
277         if(remote_user() && (! $visitor)) {
278                 $contact_id = 0;
279                 if(is_array($_SESSION['remote'])) {
280                         foreach($_SESSION['remote'] as $v) {
281                                 if($v['uid'] == $owner_uid) {
282                                         $contact_id = $v['cid'];
283                                         break;
284                                 }
285                         }
286                 }
287                 if($contact_id) {
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",
290                                 intval($contact_id),
291                                 intval($owner_uid)
292                         );
293                         if (dbm::is_result($r)) {
294                                 $contact = $r[0];
295                                 $remote_contact = true;
296                         }
297                 }
298         }
299
300         if(! $remote_contact) {
301                 if(local_user()) {
302                         $contact_id = $_SESSION['cid'];
303                         $contact = $a->contact;
304                 }
305         }
306
307         if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
308                 notice( t('Access to this item is restricted.') . EOL);
309                 return;
310         }
311
312         $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
313
314         $o = "";
315
316         // tabs
317         $_is_owner = (local_user() && (local_user() == $owner_uid));
318         $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
319
320         //
321         // dispatch request
322         //
323
324
325         if($datatype === 'upload') {
326                 return; // no uploading for now
327
328                 // DELETED -- look at mod/photos.php if you want to implement
329         }
330
331         if($datatype === 'album') {
332
333                 return; // no albums for now
334
335                 // DELETED -- look at mod/photos.php if you want to implement
336         }
337
338
339         if($datatype === 'video') {
340
341                 return; // no single video view for now
342
343                 // DELETED -- look at mod/photos.php if you want to implement
344         }
345
346         // Default - show recent videos (no upload link for now)
347         //$o = '';
348
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'])
352         );
353         if (dbm::is_result($r)) {
354                 $a->set_pager_total(count($r));
355                 $a->set_pager_itemspage(20);
356         }
357
358         $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
359                 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
360                 FROM `attach`
361                 WHERE `uid` = %d AND filetype LIKE '%%video%%'
362                 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
363                 intval($a->data['user']['uid']),
364                 intval($a->pager['start']),
365                 intval($a->pager['itemspage'])
366         );
367
368
369
370         $videos = array();
371         if (dbm::is_result($r)) {
372                 foreach ($r as $rr) {
373                         if ($a->theme['template_engine'] === 'internal') {
374                                 $alt_e = template_escape($rr['filename']);
375                                 $name_e = template_escape($rr['album']);
376                         }
377                         else {
378                                 $alt_e = $rr['filename'];
379                                 $name_e = $rr['album'];
380                         }
381
382                         $videos[] = array(
383                                 'id'       => $rr['id'],
384                                 'link'     => App::get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
385                                 'title'    => t('View Video'),
386                                 'src'      => App::get_baseurl() . '/attach/' . $rr['id'] . '?attachment=0',
387                                 'alt'      => $alt_e,
388                                 'mime'     => $rr['filetype'],
389                                 'album' => array(
390                                         'link'  => App::get_baseurl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
391                                         'name'  => $name_e,
392                                         'alt'   => t('View Album'),
393                                 ),
394
395                         );
396                 }
397         }
398
399         $tpl = get_markup_template('videos_recent.tpl');
400         $o .= replace_macros($tpl, array(
401                 '$title'      => t('Recent Videos'),
402                 '$can_post'   => $can_post,
403                 '$upload'     => array(t('Upload New Videos'), App::get_baseurl().'/videos/'.$a->data['user']['nickname'].'/upload'),
404                 '$videos'     => $videos,
405                 '$delete_url' => (($can_post)?App::get_baseurl().'/videos/'.$a->data['user']['nickname']:False)
406         ));
407
408
409         $o .= paginate($a);
410         return $o;
411 }