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