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