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