]> git.mxchange.org Git - friendica.git/blob - mod/videos.php
Removed obsolete code
[friendica.git] / mod / videos.php
1 <?php
2 /**
3  * @file mod/videos.php
4  */
5
6 use Friendica\App;
7 use Friendica\Content\Nav;
8 use Friendica\Content\Pager;
9 use Friendica\Core\Config;
10 use Friendica\Core\L10n;
11 use Friendica\Core\Renderer;
12 use Friendica\Core\System;
13 use Friendica\Database\DBA;
14 use Friendica\Model\Attach;
15 use Friendica\Model\Contact;
16 use Friendica\Model\Group;
17 use Friendica\Model\Item;
18 use Friendica\Model\Profile;
19 use Friendica\Model\User;
20 use Friendica\Protocol\DFRN;
21 use Friendica\Util\Security;
22
23 function videos_init(App $a)
24 {
25         if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
26                 return;
27         }
28
29         Nav::setSelected('home');
30
31         if ($a->argc > 1) {
32                 $nick = $a->argv[1];
33                 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
34                         DBA::escape($nick)
35                 );
36
37                 if (!DBA::isResult($user)) {
38                         return;
39                 }
40
41                 $a->data['user'] = $user[0];
42                 $a->profile_uid = $user[0]['uid'];
43
44                 $profile = Profile::getByNickname($nick, $a->profile_uid);
45
46                 $account_type = Contact::getAccountType($profile);
47
48                 $tpl = Renderer::getMarkupTemplate("widget/vcard.tpl");
49
50                 $vcard_widget = Renderer::replaceMacros($tpl, [
51                         '$name' => $profile['name'],
52                         '$photo' => $profile['photo'],
53                         '$addr' => defaults($profile, 'addr', ''),
54                         '$account_type' => $account_type,
55                         '$pdesc' => defaults($profile, 'pdesc', ''),
56                 ]);
57
58                 // If not there, create 'aside' empty
59                 if (!isset($a->page['aside'])) {
60                         $a->page['aside'] = '';
61                 }
62
63                 $a->page['aside'] .= $vcard_widget;
64
65                 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
66                 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl);
67         }
68
69         return;
70 }
71
72 function videos_post(App $a)
73 {
74         $owner_uid = $a->data['user']['uid'];
75
76         if (local_user() != $owner_uid) {
77                 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
78         }
79
80         if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
81                 $video_id = $_POST['id'];
82
83                 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
84                         // delete the attachment
85                         Attach::delete(['id' => $video_id, 'uid' => local_user()]);
86
87                         // delete items where the attach is used
88                         Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
89                                 '%attach/' . $video_id . '%',
90                                 local_user()
91                         ], local_user());
92                 }
93
94                 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
95                 return; // NOTREACHED
96         }
97
98         $a->internalRedirect('videos/' . $a->data['user']['nickname']);
99 }
100
101 function videos_content(App $a)
102 {
103         // URLs (most aren't currently implemented):
104         // videos/name
105         // videos/name/upload
106         // videos/name/upload/xxxxx (xxxxx is album name)
107         // videos/name/album/xxxxx
108         // videos/name/album/xxxxx/edit
109         // videos/name/video/xxxxx
110         // videos/name/video/xxxxx/edit
111
112
113         if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
114                 notice(L10n::t('Public access denied.') . EOL);
115                 return;
116         }
117
118         if (empty($a->data['user'])) {
119                 notice(L10n::t('No videos selected') . EOL );
120                 return;
121         }
122
123         //$phototypes = Photo::supportedTypes();
124
125         $_SESSION['video_return'] = $a->cmd;
126
127         //
128         // Parse arguments
129         //
130         if ($a->argc > 3) {
131                 $datatype = $a->argv[2];
132         } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
133                 $datatype = 'upload';
134         } else {
135                 $datatype = 'summary';
136         }
137
138         //
139         // Setup permissions structures
140         //
141         $can_post       = false;
142         $visitor        = 0;
143         $contact        = null;
144         $remote_contact = false;
145         $contact_id     = 0;
146
147         $owner_uid = $a->data['user']['uid'];
148
149         $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
150
151         if ((local_user()) && (local_user() == $owner_uid)) {
152                 $can_post = true;
153         } elseif ($community_page && !empty(remote_user($owner_uid))) {
154                 $contact_id = remote_user($owner_uid);
155                 $can_post = true;
156                 $remote_contact = true;
157                 $visitor = $contact_id;
158         }
159
160         // perhaps they're visiting - but not a community page, so they wouldn't have write access
161         if (!empty(remote_user($owner_uid)) && !$visitor) {
162                 $contact_id = remote_user($owner_uid);
163                 $remote_contact = true;
164         }
165
166         if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
167                 notice(L10n::t('Access to this item is restricted.') . EOL);
168                 return;
169         }
170
171         $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
172
173         $o = "";
174
175         // tabs
176         $_is_owner = (local_user() && (local_user() == $owner_uid));
177         $o .= Profile::getTabs($a, 'videos', $_is_owner, $a->data['user']['nickname']);
178
179         //
180         // dispatch request
181         //
182         if ($datatype === 'upload') {
183                 return; // no uploading for now
184
185                 // DELETED -- look at mod/photos.php if you want to implement
186         }
187
188         if ($datatype === 'album') {
189                 return; // no albums for now
190
191                 // DELETED -- look at mod/photos.php if you want to implement
192         }
193
194
195         if ($datatype === 'video') {
196                 return; // no single video view for now
197
198                 // DELETED -- look at mod/photos.php if you want to implement
199         }
200
201         // Default - show recent videos (no upload link for now)
202         //$o = '';
203
204         $total = 0;
205         $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
206                 $sql_extra GROUP BY hash",
207                 intval($a->data['user']['uid'])
208         );
209         if (DBA::isResult($r)) {
210                 $total = count($r);
211         }
212
213         $pager = new Pager($a->query_string, 20);
214
215         $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
216                 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
217                 FROM `attach`
218                 WHERE `uid` = %d AND filetype LIKE '%%video%%'
219                 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
220                 intval($a->data['user']['uid']),
221                 $pager->getStart(),
222                 $pager->getItemsPerPage()
223         );
224
225         $videos = [];
226
227         if (DBA::isResult($r)) {
228                 foreach ($r as $rr) {
229                         $alt_e = $rr['filename'];
230                         /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
231                         $rr['album'] = '';
232                         $name_e = $rr['album'];
233
234                         $videos[] = [
235                                 'id'       => $rr['id'],
236                                 'link'     => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
237                                 'title'    => L10n::t('View Video'),
238                                 'src'      => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
239                                 'alt'      => $alt_e,
240                                 'mime'     => $rr['filetype'],
241                                 'album' => [
242                                         'link'  => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
243                                         'name'  => $name_e,
244                                         'alt'   => L10n::t('View Album'),
245                                 ],
246                         ];
247                 }
248         }
249
250         $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
251         $o .= Renderer::replaceMacros($tpl, [
252                 '$title'      => L10n::t('Recent Videos'),
253                 '$can_post'   => $can_post,
254                 '$upload'     => [L10n::t('Upload New Videos'), System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
255                 '$videos'     => $videos,
256                 '$delete_url' => (($can_post) ? System::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
257         ]);
258
259         $o .= $pager->renderFull($total);
260
261         return $o;
262 }