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