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