Merge pull request #9815 from annando/post-again
[friendica.git/.git] / mod / notes.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
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\Module\BaseProfile;
29
30 function notes_init(App $a)
31 {
32         if (! local_user()) {
33                 return;
34         }
35
36         Nav::setSelected('home');
37 }
38
39
40 function notes_content(App $a, $update = false)
41 {
42         if (!local_user()) {
43                 notice(DI::l10n()->t('Permission denied.'));
44                 return;
45         }
46
47         $o = BaseProfile::getTabsHTML($a, 'notes', true);
48
49         if (!$update) {
50                 $o .= '<h3>' . DI::l10n()->t('Personal Notes') . '</h3>';
51
52                 $x = [
53                         'is_owner' => true,
54                         'allow_location' => (($a->user['allow_location']) ? true : false),
55                         'default_location' => $a->user['default-location'],
56                         'nickname' => $a->user['nickname'],
57                         'lockstate' => 'lock',
58                         'acl' => \Friendica\Core\ACL::getSelfOnlyHTML(local_user(), DI::l10n()->t('Personal notes are visible only by yourself.')),
59                         'bang' => '',
60                         'visitor' => 'block',
61                         'profile_uid' => local_user(),
62                         'button' => DI::l10n()->t('Save'),
63                         'acl_data' => '',
64                 ];
65
66                 $o .= status_editor($a, $x, $a->contact['id']);
67         }
68
69         $condition = ['uid' => local_user(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => GRAVITY_PARENT,
70                 'contact-id'=> $a->contact['id']];
71
72         if (DI::mode()->isMobile()) {
73                 $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
74                         DI::config()->get('system', 'itemspage_network_mobile'));
75         } else {
76                 $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
77                         DI::config()->get('system', 'itemspage_network'));
78         }
79
80         $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
81
82         $params = ['order' => ['created' => true],
83                 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
84         $r = Item::selectThreadForUser(local_user(), ['uri'], $condition, $params);
85
86         $count = 0;
87
88         if (DBA::isResult($r)) {
89                 $notes = Item::toArray($r);
90
91                 $count = count($notes);
92
93                 $o .= conversation($a, $notes, 'notes', $update);
94         }
95
96         $o .= $pager->renderMinimal($count);
97
98         return $o;
99 }