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\Core\Session;
14 use Friendica\Database\DBA;
15 use Friendica\Model\Attach;
16 use Friendica\Model\Contact;
17 use Friendica\Model\Group;
18 use Friendica\Model\Item;
19 use Friendica\Model\Profile;
20 use Friendica\Model\User;
21 use Friendica\Protocol\DFRN;
22 use Friendica\Util\Security;
24 function videos_init(App $a)
26 if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
30 Nav::setSelected('home');
34 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
38 if (!DBA::isResult($user)) {
42 $a->data['user'] = $user[0];
43 $a->profile_uid = $user[0]['uid'];
45 $profile = Profile::getByNickname($nick, $a->profile_uid);
47 $account_type = Contact::getAccountType($profile);
49 $tpl = Renderer::getMarkupTemplate("widget/vcard.tpl");
51 $vcard_widget = Renderer::replaceMacros($tpl, [
52 '$name' => $profile['name'],
53 '$photo' => $profile['photo'],
54 '$addr' => $profile['addr'] ?? '',
55 '$account_type' => $account_type,
56 '$pdesc' => $profile['pdesc'] ?? '',
59 // If not there, create 'aside' empty
60 if (!isset($a->page['aside'])) {
61 $a->page['aside'] = '';
64 $a->page['aside'] .= $vcard_widget;
66 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
67 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl);
73 function videos_post(App $a)
75 $owner_uid = $a->data['user']['uid'];
77 if (local_user() != $owner_uid) {
78 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
81 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
82 $video_id = $_POST['id'];
84 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
85 // delete the attachment
86 Attach::delete(['id' => $video_id, 'uid' => local_user()]);
88 // delete items where the attach is used
89 Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
90 '%attach/' . $video_id . '%',
95 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
99 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
102 function videos_content(App $a)
104 // URLs (most aren't currently implemented):
106 // videos/name/upload
107 // videos/name/upload/xxxxx (xxxxx is album name)
108 // videos/name/album/xxxxx
109 // videos/name/album/xxxxx/edit
110 // videos/name/video/xxxxx
111 // videos/name/video/xxxxx/edit
114 if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
115 notice(L10n::t('Public access denied.') . EOL);
119 if (empty($a->data['user'])) {
120 notice(L10n::t('No videos selected') . EOL );
124 //$phototypes = Photo::supportedTypes();
126 $_SESSION['video_return'] = $a->cmd;
132 $datatype = $a->argv[2];
133 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
134 $datatype = 'upload';
136 $datatype = 'summary';
140 // Setup permissions structures
145 $remote_contact = false;
148 $owner_uid = $a->data['user']['uid'];
150 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
152 if ((local_user()) && (local_user() == $owner_uid)) {
154 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
155 $contact_id = Session::getRemoteContactID($owner_uid);
157 $remote_contact = true;
158 $visitor = $contact_id;
161 // perhaps they're visiting - but not a community page, so they wouldn't have write access
162 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
163 $contact_id = Session::getRemoteContactID($owner_uid);
164 $remote_contact = true;
167 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
168 notice(L10n::t('Access to this item is restricted.') . EOL);
172 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
177 $_is_owner = (local_user() && (local_user() == $owner_uid));
178 $o .= Profile::getTabs($a, 'videos', $_is_owner, $a->data['user']['nickname']);
183 if ($datatype === 'upload') {
184 return; // no uploading for now
186 // DELETED -- look at mod/photos.php if you want to implement
189 if ($datatype === 'album') {
190 return; // no albums for now
192 // DELETED -- look at mod/photos.php if you want to implement
196 if ($datatype === 'video') {
197 return; // no single video view for now
199 // DELETED -- look at mod/photos.php if you want to implement
202 // Default - show recent videos (no upload link for now)
206 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
207 $sql_extra GROUP BY hash",
208 intval($a->data['user']['uid'])
210 if (DBA::isResult($r)) {
214 $pager = new Pager($a->query_string, 20);
216 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
217 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
219 WHERE `uid` = %d AND filetype LIKE '%%video%%'
220 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
221 intval($a->data['user']['uid']),
223 $pager->getItemsPerPage()
228 if (DBA::isResult($r)) {
229 foreach ($r as $rr) {
230 $alt_e = $rr['filename'];
231 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
233 $name_e = $rr['album'];
237 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
238 'title' => L10n::t('View Video'),
239 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
241 'mime' => $rr['filetype'],
243 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
245 'alt' => L10n::t('View Album'),
251 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
252 $o .= Renderer::replaceMacros($tpl, [
253 '$title' => L10n::t('Recent Videos'),
254 '$can_post' => $can_post,
255 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
256 '$videos' => $videos,
257 '$delete_url' => (($can_post) ? System::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
260 $o .= $pager->renderFull($total);