]> git.mxchange.org Git - friendica.git/blob - mod/notes.php
Use short form array syntax everywhere
[friendica.git] / mod / notes.php
1 <?php
2 /**
3  * @file mod/notes.php
4  */
5 use Friendica\App;
6 use Friendica\Database\DBM;
7 use Friendica\Model\Profile;
8
9 function notes_init(App $a) {
10
11         if (! local_user()) {
12                 return;
13         }
14
15         $profile = 0;
16
17         $which = $a->user['nickname'];
18
19         nav_set_selected('home');
20
21         //Profile::load($a, $which, $profile);
22
23 }
24
25
26 function notes_content(App $a, $update = false) {
27
28         if (! local_user()) {
29                 notice( t('Permission denied.') . EOL);
30                 return;
31         }
32
33         require_once("include/bbcode.php");
34         require_once('include/security.php');
35         require_once('include/conversation.php');
36         require_once('include/acl_selectors.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>' . 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' => t('Save'),
69                         'acl_data' => '',
70                 ];
71
72                 $o .= status_editor($a,$x,$a->contact['id']);
73
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(), item_condition(),
88                 intval(local_user())
89
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(), 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                 $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(), item_joins(), item_condition(),
122                         intval(local_user()),
123                         dbesc($parents_str)
124                 );
125
126                 if (DBM::is_result($r)) {
127                         $items = conv_sort($r,"`commented`");
128
129                         $o .= conversation($a,$items,'notes',$update);
130                 }
131         }
132
133
134         $o .= paginate($a);
135         return $o;
136 }