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;
23 function videos_init(App $a)
25 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
29 Nav::setSelected('home');
33 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
37 if (!DBA::isResult($user)) {
41 $a->data['user'] = $user[0];
42 $a->profile_uid = $user[0]['uid'];
44 $profile = Profile::getByNickname($nick, $a->profile_uid);
46 $account_type = Contact::getAccountType($profile);
48 $tpl = Renderer::getMarkupTemplate("widget/vcard.tpl");
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', ''),
58 // If not there, create 'aside' empty
59 if (!isset($a->page['aside'])) {
60 $a->page['aside'] = '';
63 $a->page['aside'] .= $vcard_widget;
65 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
66 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl);
72 function videos_post(App $a)
74 $owner_uid = $a->data['user']['uid'];
76 if (local_user() != $owner_uid) {
77 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
80 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
81 $video_id = $_POST['id'];
83 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
84 // delete the attachment
85 Attach::delete(['id' => $video_id, 'uid' => local_user()]);
87 // delete items where the attach is used
88 Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
89 '%attach/' . $video_id . '%',
94 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
98 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
101 function videos_content(App $a)
103 // URLs (most aren't currently implemented):
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
113 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
114 notice(L10n::t('Public access denied.') . EOL);
118 if (empty($a->data['user'])) {
119 notice(L10n::t('No videos selected') . EOL );
123 //$phototypes = Photo::supportedTypes();
125 $_SESSION['video_return'] = $a->cmd;
131 $datatype = $a->argv[2];
132 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
133 $datatype = 'upload';
135 $datatype = 'summary';
139 // Setup permissions structures
144 $remote_contact = false;
147 $owner_uid = $a->data['user']['uid'];
149 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
151 if ((local_user()) && (local_user() == $owner_uid)) {
153 } elseif ($community_page && !empty(remote_user($owner_uid))) {
154 $contact_id = remote_user($owner_uid);
156 $remote_contact = true;
157 $visitor = $contact_id;
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;
166 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
167 notice(L10n::t('Access to this item is restricted.') . EOL);
171 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
176 $_is_owner = (local_user() && (local_user() == $owner_uid));
177 $o .= Profile::getTabs($a, 'videos', $_is_owner, $a->data['user']['nickname']);
182 if ($datatype === 'upload') {
183 return; // no uploading for now
185 // DELETED -- look at mod/photos.php if you want to implement
188 if ($datatype === 'album') {
189 return; // no albums for now
191 // DELETED -- look at mod/photos.php if you want to implement
195 if ($datatype === 'video') {
196 return; // no single video view for now
198 // DELETED -- look at mod/photos.php if you want to implement
201 // Default - show recent videos (no upload link for now)
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'])
209 if (DBA::isResult($r)) {
213 $pager = new Pager($a->query_string, 20);
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`
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']),
222 $pager->getItemsPerPage()
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.
232 $name_e = $rr['album'];
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',
240 'mime' => $rr['filetype'],
242 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
244 'alt' => L10n::t('View Album'),
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)
259 $o .= $pager->renderFull($total);