]> git.mxchange.org Git - friendica.git/blob - mod/notes.php
Merge pull request #4399 from MrPetovan/task/3878-move-include-bbcode-to-src
[friendica.git] / mod / notes.php
1 <?php
2 /**
3  * @file mod/notes.php
4  */
5 use Friendica\App;
6 use Friendica\Content\Nav;
7 use Friendica\Core\L10n;
8 use Friendica\Database\DBM;
9 use Friendica\Model\Profile;
10
11 function notes_init(App $a)
12 {
13         if (! local_user()) {
14                 return;
15         }
16
17         $profile = 0;
18
19         $which = $a->user['nickname'];
20
21         Nav::setSelected('home');
22
23         //Profile::load($a, $which, $profile);
24 }
25
26
27 function notes_content(App $a, $update = false)
28 {
29         if (! local_user()) {
30                 notice(L10n::t('Permission denied.') . EOL);
31                 return;
32         }
33
34         require_once 'include/bbcode.php';
35         require_once 'include/security.php';
36         require_once 'include/conversation.php';
37         require_once 'include/acl_selectors.php';
38         $groups = [];
39
40
41         $o = '';
42
43         $remote_contact = false;
44
45         $contact_id = $_SESSION['cid'];
46         $contact = $a->contact;
47
48         $is_owner = true;
49
50         $o ="";
51         $o .= Profile::getTabs($a, true);
52
53         if (!$update) {
54                 $o .= '<h3>' . L10n::t('Personal Notes') . '</h3>';
55
56                 $commpage = false;
57                 $commvisitor = false;
58
59                 $x = [
60                         'is_owner' => $is_owner,
61                         'allow_location' => (($a->user['allow_location']) ? true : false),
62                         'default_location' => $a->user['default-location'],
63                         'nickname' => $a->user['nickname'],
64                         'lockstate' => 'lock',
65                         'acl' => '',
66                         'bang' => '',
67                         'visitor' => 'block',
68                         'profile_uid' => local_user(),
69                         'button' => L10n::t('Save'),
70                         'acl_data' => '',
71                 ];
72
73                 $o .= status_editor($a, $x, $a->contact['id']);
74         }
75
76         // Construct permissions
77
78         // default permissions - anonymous user
79
80         $sql_extra = " AND `item`.`allow_cid` = '<" . $a->contact['id'] . ">' ";
81
82         $r = q("SELECT COUNT(*) AS `total`
83                 FROM `item` %s
84                 WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note'
85                 AND `contact`.`self` AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall`
86                 $sql_extra ",
87                 item_joins(),
88                 item_condition(),
89                 intval(local_user())
90         );
91
92         if (DBM::is_result($r)) {
93                 $a->set_pager_total($r[0]['total']);
94                 $a->set_pager_itemspage(40);
95         }
96
97         $r = q("SELECT `item`.`id` AS `item_id` FROM `item` %s
98                 WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note'
99                 AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall`
100                 $sql_extra
101                 ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
102                 item_joins(),
103                 item_condition(),
104                 intval(local_user()),
105                 intval($a->pager['start']),
106                 intval($a->pager['itemspage'])
107
108         );
109
110         $parents_arr = [];
111         $parents_str = '';
112
113         if (DBM::is_result($r)) {
114                 foreach ($r as $rr) {
115                         $parents_arr[] = $rr['item_id'];
116                 }
117                 $parents_str = implode(', ', $parents_arr);
118
119                 $r = q("SELECT %s FROM `item` %s
120                         WHERE %s AND `item`.`uid` = %d AND `item`.`parent` IN (%s)
121                         $sql_extra
122                         ORDER BY `parent` DESC, `gravity` ASC, `item`.`id` ASC ",
123                         item_fieldlists(),
124                         item_joins(),
125                         item_condition(),
126                         intval(local_user()),
127                         dbesc($parents_str)
128                 );
129
130                 if (DBM::is_result($r)) {
131                         $items = conv_sort($r, "`commented`");
132
133                         $o .= conversation($a, $items, 'notes', $update);
134                 }
135         }
136
137         $o .= paginate($a);
138         return $o;
139 }