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