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