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