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