]> git.mxchange.org Git - friendica.git/blob - mod/notes.php
Update .gitignore for new php-cs-fixer filename
[friendica.git] / mod / notes.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2024, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 use Friendica\App;
23 use Friendica\Content\Conversation;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Database\DBA;
27 use Friendica\DI;
28 use Friendica\Model\Item;
29 use Friendica\Model\Post;
30 use Friendica\Module\BaseProfile;
31
32 function notes_init(App $a)
33 {
34         if (! DI::userSession()->getLocalUserId()) {
35                 return;
36         }
37
38         Nav::setSelected('home');
39 }
40
41
42 function notes_content(App $a, bool $update = false)
43 {
44         if (!DI::userSession()->getLocalUserId()) {
45                 DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
46                 return;
47         }
48
49         $o = BaseProfile::getTabsHTML('notes', true, $a->getLoggedInUserNickname(), false);
50
51         if (!$update) {
52                 $o .= '<h3>' . DI::l10n()->t('Personal Notes') . '</h3>';
53
54                 $x = [
55                         'lockstate' => 'lock',
56                         'acl' => \Friendica\Core\ACL::getSelfOnlyHTML(DI::userSession()->getLocalUserId(), DI::l10n()->t('Personal notes are visible only by yourself.')),
57                         'button' => DI::l10n()->t('Save'),
58                         'acl_data' => '',
59                 ];
60
61                 $o .= DI::conversation()->statusEditor($x, $a->getContactId());
62         }
63
64         $condition = ['uid' => DI::userSession()->getLocalUserId(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => Item::GRAVITY_PARENT,
65                 'contact-id'=> $a->getContactId()];
66
67         if (DI::mode()->isMobile()) {
68                 $itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
69                         DI::config()->get('system', 'itemspage_network_mobile'));
70         } else {
71                 $itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
72                         DI::config()->get('system', 'itemspage_network'));
73         }
74
75         $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
76
77         $params = ['order' => ['created' => true],
78                 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
79         $r = Post::selectThreadForUser(DI::userSession()->getLocalUserId(), ['uri-id'], $condition, $params);
80
81         $count = 0;
82
83         if (DBA::isResult($r)) {
84                 $notes = Post::toArray($r);
85
86                 $count = count($notes);
87
88                 $o .= DI::conversation()->render($notes, Conversation::MODE_NOTES, $update);
89         }
90
91         $o .= $pager->renderMinimal($count);
92
93         return $o;
94 }