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