]> git.mxchange.org Git - friendica.git/blob - mod/notes.php
The central item fetch does work now and the API now uses these functions
[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/security.php';
35         require_once 'include/conversation.php';
36         $groups = [];
37
38
39         $o = '';
40
41         $remote_contact = false;
42
43         $contact_id = $_SESSION['cid'];
44         $contact = $a->contact;
45
46         $is_owner = true;
47
48         $o ="";
49         $o .= Profile::getTabs($a, true);
50
51         if (!$update) {
52                 $o .= '<h3>' . L10n::t('Personal Notes') . '</h3>';
53
54                 $commpage = false;
55                 $commvisitor = false;
56
57                 $x = [
58                         'is_owner' => $is_owner,
59                         'allow_location' => (($a->user['allow_location']) ? true : false),
60                         'default_location' => $a->user['default-location'],
61                         'nickname' => $a->user['nickname'],
62                         'lockstate' => 'lock',
63                         'acl' => '',
64                         'bang' => '',
65                         'visitor' => 'block',
66                         'profile_uid' => local_user(),
67                         'button' => L10n::t('Save'),
68                         'acl_data' => '',
69                 ];
70
71                 $o .= status_editor($a, $x, $a->contact['id']);
72         }
73
74         // Construct permissions
75
76         // default permissions - anonymous user
77
78         $sql_extra = " AND `item`.`allow_cid` = '<" . $a->contact['id'] . ">' ";
79
80         $r = q("SELECT COUNT(*) AS `total`
81                 FROM `item` %s
82                 WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note'
83                 AND `contact`.`self` AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall`
84                 $sql_extra ",
85                 item_joins(local_user()),
86                 item_condition(),
87                 intval(local_user())
88         );
89
90         if (DBM::is_result($r)) {
91                 $a->set_pager_total($r[0]['total']);
92                 $a->set_pager_itemspage(40);
93         }
94
95         $r = q("SELECT `item`.`id` AS `item_id` FROM `item` %s
96                 WHERE %s AND `item`.`uid` = %d AND `item`.`type` = 'note'
97                 AND `item`.`id` = `item`.`parent` AND NOT `item`.`wall`
98                 $sql_extra
99                 ORDER BY `item`.`created` DESC LIMIT %d ,%d ",
100                 item_joins(local_user()),
101                 item_condition(),
102                 intval(local_user()),
103                 intval($a->pager['start']),
104                 intval($a->pager['itemspage'])
105
106         );
107
108         $parents_arr = [];
109         $parents_str = '';
110
111         if (DBM::is_result($r)) {
112                 foreach ($r as $rr) {
113                         $parents_arr[] = $rr['item_id'];
114                 }
115                 $parents_str = implode(', ', $parents_arr);
116
117                 $r = q("SELECT %s FROM `item` %s
118                         WHERE %s AND `item`.`uid` = %d AND `item`.`parent` IN (%s)
119                         $sql_extra
120                         ORDER BY `parent` DESC, `gravity` ASC, `item`.`id` ASC ",
121                         item_fieldlists(),
122                         item_joins(local_user()),
123                         item_condition(),
124                         intval(local_user()),
125                         dbesc($parents_str)
126                 );
127
128                 if (DBM::is_result($r)) {
129                         $items = conv_sort($r, "`commented`");
130
131                         $o .= conversation($a, $items, 'notes', $update);
132                 }
133         }
134
135         $o .= paginate($a);
136         return $o;
137 }