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;
16 use Friendica\Model\Attach;
17 use Friendica\Model\Contact;
18 use Friendica\Model\Group;
19 use Friendica\Model\Item;
20 use Friendica\Model\Profile;
21 use Friendica\Model\User;
22 use Friendica\Protocol\DFRN;
23 use Friendica\Util\Security;
25 function videos_init(App $a)
27 if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
31 Nav::setSelected('home');
35 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
39 if (!DBA::isResult($user)) {
43 $a->data['user'] = $user[0];
44 $a->profile_uid = $user[0]['uid'];
46 $profile = Profile::getByNickname($nick, $a->profile_uid);
48 $account_type = Contact::getAccountType($profile);
50 $tpl = Renderer::getMarkupTemplate("widget/vcard.tpl");
52 $vcard_widget = Renderer::replaceMacros($tpl, [
53 '$name' => $profile['name'],
54 '$photo' => $profile['photo'],
55 '$addr' => $profile['addr'] ?? '',
56 '$account_type' => $account_type,
57 '$pdesc' => $profile['pdesc'] ?? '',
60 // If not there, create 'aside' empty
61 if (!isset($a->page['aside'])) {
62 $a->page['aside'] = '';
65 $a->page['aside'] .= $vcard_widget;
67 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
68 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl);
74 function videos_post(App $a)
76 $owner_uid = $a->data['user']['uid'];
78 if (local_user() != $owner_uid) {
79 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
82 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
83 $video_id = $_POST['id'];
85 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
86 // delete the attachment
87 Attach::delete(['id' => $video_id, 'uid' => local_user()]);
89 // delete items where the attach is used
90 Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
91 '%attach/' . $video_id . '%',
96 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
100 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
103 function videos_content(App $a)
105 // URLs (most aren't currently implemented):
107 // videos/name/upload
108 // videos/name/upload/xxxxx (xxxxx is album name)
109 // videos/name/album/xxxxx
110 // videos/name/album/xxxxx/edit
111 // videos/name/video/xxxxx
112 // videos/name/video/xxxxx/edit
115 if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
116 notice(L10n::t('Public access denied.') . EOL);
120 if (empty($a->data['user'])) {
121 notice(L10n::t('No videos selected') . EOL );
125 //$phototypes = Photo::supportedTypes();
127 $_SESSION['video_return'] = $a->cmd;
133 $datatype = $a->argv[2];
134 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
135 $datatype = 'upload';
137 $datatype = 'summary';
141 // Setup permissions structures
146 $remote_contact = false;
149 $owner_uid = $a->data['user']['uid'];
151 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
153 if ((local_user()) && (local_user() == $owner_uid)) {
155 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
156 $contact_id = Session::getRemoteContactID($owner_uid);
158 $remote_contact = true;
159 $visitor = $contact_id;
162 // perhaps they're visiting - but not a community page, so they wouldn't have write access
163 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
164 $contact_id = Session::getRemoteContactID($owner_uid);
165 $remote_contact = true;
168 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
169 notice(L10n::t('Access to this item is restricted.') . EOL);
173 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
178 $_is_owner = (local_user() && (local_user() == $owner_uid));
179 $o .= Profile::getTabs($a, 'videos', $_is_owner, $a->data['user']['nickname']);
184 if ($datatype === 'upload') {
185 return; // no uploading for now
187 // DELETED -- look at mod/photos.php if you want to implement
190 if ($datatype === 'album') {
191 return; // no albums for now
193 // DELETED -- look at mod/photos.php if you want to implement
197 if ($datatype === 'video') {
198 return; // no single video view for now
200 // DELETED -- look at mod/photos.php if you want to implement
203 // Default - show recent videos (no upload link for now)
207 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
208 $sql_extra GROUP BY hash",
209 intval($a->data['user']['uid'])
211 if (DBA::isResult($r)) {
215 $pager = new Pager(DI::args()->getQueryString(), 20);
217 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
218 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
220 WHERE `uid` = %d AND filetype LIKE '%%video%%'
221 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
222 intval($a->data['user']['uid']),
224 $pager->getItemsPerPage()
229 if (DBA::isResult($r)) {
230 foreach ($r as $rr) {
231 $alt_e = $rr['filename'];
232 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
234 $name_e = $rr['album'];
238 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
239 'title' => L10n::t('View Video'),
240 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
242 'mime' => $rr['filetype'],
244 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
246 'alt' => L10n::t('View Album'),
252 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
253 $o .= Renderer::replaceMacros($tpl, [
254 '$title' => L10n::t('Recent Videos'),
255 '$can_post' => $can_post,
256 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
257 '$videos' => $videos,
258 '$delete_url' => (($can_post) ? System::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
261 $o .= $pager->renderFull($total);