7 use Friendica\Content\Nav;
8 use Friendica\Content\Pager;
9 use Friendica\Core\Config;
10 use Friendica\Core\Renderer;
11 use Friendica\Core\Session;
12 use Friendica\Database\DBA;
14 use Friendica\Model\Attach;
15 use Friendica\Model\Contact;
16 use Friendica\Model\Item;
17 use Friendica\Model\Profile;
18 use Friendica\Model\User;
19 use Friendica\Util\Security;
21 function videos_init(App $a)
23 if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
27 Nav::setSelected('home');
31 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
35 if (!DBA::isResult($user)) {
39 $a->data['user'] = $user[0];
40 $a->profile_uid = $user[0]['uid'];
42 $profile = Profile::getByNickname($nick, $a->profile_uid);
44 $account_type = Contact::getAccountType($profile);
46 $tpl = Renderer::getMarkupTemplate("widget/vcard.tpl");
48 $vcard_widget = Renderer::replaceMacros($tpl, [
49 '$name' => $profile['name'],
50 '$photo' => $profile['photo'],
51 '$addr' => $profile['addr'] ?? '',
52 '$account_type' => $account_type,
53 '$pdesc' => $profile['pdesc'] ?? '',
56 // If not there, create 'aside' empty
57 if (!isset(DI::page()['aside'])) {
58 DI::page()['aside'] = '';
61 DI::page()['aside'] .= $vcard_widget;
63 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
64 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl);
70 function videos_post(App $a)
72 $owner_uid = $a->data['user']['uid'];
74 if (local_user() != $owner_uid) {
75 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
78 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
79 $video_id = $_POST['id'];
81 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
82 // delete the attachment
83 Attach::delete(['id' => $video_id, 'uid' => local_user()]);
85 // delete items where the attach is used
86 Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
87 '%attach/' . $video_id . '%',
92 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
96 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
99 function videos_content(App $a)
101 // URLs (most aren't currently implemented):
103 // videos/name/upload
104 // videos/name/upload/xxxxx (xxxxx is album name)
105 // videos/name/album/xxxxx
106 // videos/name/album/xxxxx/edit
107 // videos/name/video/xxxxx
108 // videos/name/video/xxxxx/edit
111 if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
112 notice(DI::l10n()->t('Public access denied.') . EOL);
116 if (empty($a->data['user'])) {
117 notice(DI::l10n()->t('No videos selected') . EOL );
121 //$phototypes = Photo::supportedTypes();
123 $_SESSION['video_return'] = DI::args()->getCommand();
129 $datatype = $a->argv[2];
130 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
131 $datatype = 'upload';
133 $datatype = 'summary';
137 // Setup permissions structures
142 $remote_contact = false;
145 $owner_uid = $a->data['user']['uid'];
147 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
149 if ((local_user()) && (local_user() == $owner_uid)) {
151 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
152 $contact_id = Session::getRemoteContactID($owner_uid);
154 $remote_contact = true;
155 $visitor = $contact_id;
158 // perhaps they're visiting - but not a community page, so they wouldn't have write access
159 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
160 $contact_id = Session::getRemoteContactID($owner_uid);
161 $remote_contact = true;
164 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
165 notice(DI::l10n()->t('Access to this item is restricted.') . EOL);
169 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
174 $_is_owner = (local_user() && (local_user() == $owner_uid));
175 $o .= Profile::getTabs($a, 'videos', $_is_owner, $a->data['user']['nickname']);
180 if ($datatype === 'upload') {
181 return; // no uploading for now
183 // DELETED -- look at mod/photos.php if you want to implement
186 if ($datatype === 'album') {
187 return; // no albums for now
189 // DELETED -- look at mod/photos.php if you want to implement
193 if ($datatype === 'video') {
194 return; // no single video view for now
196 // DELETED -- look at mod/photos.php if you want to implement
199 // Default - show recent videos (no upload link for now)
203 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
204 $sql_extra GROUP BY hash",
205 intval($a->data['user']['uid'])
207 if (DBA::isResult($r)) {
211 $pager = new Pager(DI::args()->getQueryString(), 20);
213 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
214 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
216 WHERE `uid` = %d AND filetype LIKE '%%video%%'
217 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
218 intval($a->data['user']['uid']),
220 $pager->getItemsPerPage()
225 if (DBA::isResult($r)) {
226 foreach ($r as $rr) {
227 $alt_e = $rr['filename'];
228 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
230 $name_e = $rr['album'];
234 'link' => DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
235 'title' => DI::l10n()->t('View Video'),
236 'src' => DI::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
238 'mime' => $rr['filetype'],
240 'link' => DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
242 'alt' => DI::l10n()->t('View Album'),
248 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
249 $o .= Renderer::replaceMacros($tpl, [
250 '$title' => DI::l10n()->t('Recent Videos'),
251 '$can_post' => $can_post,
252 '$upload' => [DI::l10n()->t('Upload New Videos'), DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
253 '$videos' => $videos,
254 '$delete_url' => (($can_post) ? DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
257 $o .= $pager->renderFull($total);