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