]> git.mxchange.org Git - friendica.git/blob - mod/notes.php
Merge pull request #12041 from nupplaphil/feat/usersession_Module
[friendica.git] / mod / notes.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, 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\Nav;
24 use Friendica\Content\Pager;
25 use Friendica\Database\DBA;
26 use Friendica\DI;
27 use Friendica\Model\Item;
28 use Friendica\Model\Post;
29 use Friendica\Module\BaseProfile;
30
31 function notes_init(App $a)
32 {
33         if (! DI::userSession()->getLocalUserId()) {
34                 return;
35         }
36
37         Nav::setSelected('home');
38 }
39
40
41 function notes_content(App $a, bool $update = false)
42 {
43         if (!DI::userSession()->getLocalUserId()) {
44                 DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
45                 return;
46         }
47
48         $o = BaseProfile::getTabsHTML($a, 'notes', true, $a->getLoggedInUserNickname(), false);
49
50         if (!$update) {
51                 $o .= '<h3>' . DI::l10n()->t('Personal Notes') . '</h3>';
52
53                 $x = [
54                         'lockstate' => 'lock',
55                         'acl' => \Friendica\Core\ACL::getSelfOnlyHTML(DI::userSession()->getLocalUserId(), DI::l10n()->t('Personal notes are visible only by yourself.')),
56                         'button' => DI::l10n()->t('Save'),
57                         'acl_data' => '',
58                 ];
59
60                 $o .= DI::conversation()->statusEditor($x, $a->getContactId());
61         }
62
63         $condition = ['uid' => DI::userSession()->getLocalUserId(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => Item::GRAVITY_PARENT,
64                 'contact-id'=> $a->getContactId()];
65
66         if (DI::mode()->isMobile()) {
67                 $itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
68                         DI::config()->get('system', 'itemspage_network_mobile'));
69         } else {
70                 $itemsPerPage = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
71                         DI::config()->get('system', 'itemspage_network'));
72         }
73
74         $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
75
76         $params = ['order' => ['created' => true],
77                 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
78         $r = Post::selectThreadForUser(DI::userSession()->getLocalUserId(), ['uri-id'], $condition, $params);
79
80         $count = 0;
81
82         if (DBA::isResult($r)) {
83                 $notes = Post::toArray($r);
84
85                 $count = count($notes);
86
87                 $o .= DI::conversation()->create($notes, 'notes', $update);
88         }
89
90         $o .= $pager->renderMinimal($count);
91
92         return $o;
93 }