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)
26 DFRN::autoRedir($a, $a->argv[1]);
29 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
33 Nav::setSelected('home');
37 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
41 if (!DBA::isResult($user)) {
45 $a->data['user'] = $user[0];
46 $a->profile_uid = $user[0]['uid'];
48 $profile = Profile::getByNickname($nick, $a->profile_uid);
50 $account_type = Contact::getAccountType($profile);
52 $tpl = Renderer::getMarkupTemplate("widget/vcard.tpl");
54 $vcard_widget = Renderer::replaceMacros($tpl, [
55 '$name' => $profile['name'],
56 '$photo' => $profile['photo'],
57 '$addr' => defaults($profile, 'addr', ''),
58 '$account_type' => $account_type,
59 '$pdesc' => defaults($profile, 'pdesc', ''),
62 // If not there, create 'aside' empty
63 if (!isset($a->page['aside'])) {
64 $a->page['aside'] = '';
67 $a->page['aside'] .= $vcard_widget;
69 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
70 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl);
76 function videos_post(App $a)
78 $owner_uid = $a->data['user']['uid'];
80 if (local_user() != $owner_uid) {
81 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
84 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
85 $video_id = $_POST['id'];
87 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
88 // delete the attachment
89 Attach::delete(['id' => $video_id, 'uid' => local_user()]);
91 // delete items where the attach is used
92 Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
93 '%attach/' . $video_id . '%',
98 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
102 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
105 function videos_content(App $a)
107 // URLs (most aren't currently implemented):
109 // videos/name/upload
110 // videos/name/upload/xxxxx (xxxxx is album name)
111 // videos/name/album/xxxxx
112 // videos/name/album/xxxxx/edit
113 // videos/name/video/xxxxx
114 // videos/name/video/xxxxx/edit
117 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
118 notice(L10n::t('Public access denied.') . EOL);
122 if (empty($a->data['user'])) {
123 notice(L10n::t('No videos selected') . EOL );
127 //$phototypes = Photo::supportedTypes();
129 $_SESSION['video_return'] = $a->cmd;
135 $datatype = $a->argv[2];
136 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
137 $datatype = 'upload';
139 $datatype = 'summary';
143 // Setup permissions structures
148 $remote_contact = false;
151 $owner_uid = $a->data['user']['uid'];
153 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
155 if ((local_user()) && (local_user() == $owner_uid)) {
157 } elseif ($community_page && remote_user()) {
158 if (!empty($_SESSION['remote'])) {
159 foreach ($_SESSION['remote'] as $v) {
160 if ($v['uid'] == $owner_uid) {
161 $contact_id = $v['cid'];
167 if ($contact_id > 0) {
168 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
173 if (DBA::isResult($r)) {
175 $remote_contact = true;
176 $visitor = $contact_id;
183 // perhaps they're visiting - but not a community page, so they wouldn't have write access
184 if (remote_user() && (!$visitor)) {
187 if (!empty($_SESSION['remote'])) {
188 foreach($_SESSION['remote'] as $v) {
189 if($v['uid'] == $owner_uid) {
190 $contact_id = $v['cid'];
196 if ($contact_id > 0) {
197 $groups = Group::getIdsByContactId($contact_id);
198 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
203 if (DBA::isResult($r)) {
204 $remote_contact = true;
209 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (!$remote_contact)) {
210 notice(L10n::t('Access to this item is restricted.') . EOL);
214 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
219 $_is_owner = (local_user() && (local_user() == $owner_uid));
220 $o .= Profile::getTabs($a, 'videos', $_is_owner, $a->data['user']['nickname']);
225 if ($datatype === 'upload') {
226 return; // no uploading for now
228 // DELETED -- look at mod/photos.php if you want to implement
231 if ($datatype === 'album') {
232 return; // no albums for now
234 // DELETED -- look at mod/photos.php if you want to implement
238 if ($datatype === 'video') {
239 return; // no single video view for now
241 // DELETED -- look at mod/photos.php if you want to implement
244 // Default - show recent videos (no upload link for now)
248 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
249 $sql_extra GROUP BY hash",
250 intval($a->data['user']['uid'])
252 if (DBA::isResult($r)) {
256 $pager = new Pager($a->query_string, 20);
258 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
259 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
261 WHERE `uid` = %d AND filetype LIKE '%%video%%'
262 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
263 intval($a->data['user']['uid']),
265 $pager->getItemsPerPage()
270 if (DBA::isResult($r)) {
271 foreach ($r as $rr) {
272 $alt_e = $rr['filename'];
273 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
275 $name_e = $rr['album'];
279 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
280 'title' => L10n::t('View Video'),
281 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
283 'mime' => $rr['filetype'],
285 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
287 'alt' => L10n::t('View Album'),
293 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
294 $o .= Renderer::replaceMacros($tpl, [
295 '$title' => L10n::t('Recent Videos'),
296 '$can_post' => $can_post,
297 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
298 '$videos' => $videos,
299 '$delete_url' => (($can_post) ? System::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
302 $o .= $pager->renderFull($total);