-
Notifications
You must be signed in to change notification settings - Fork 0
/
ossn_com.php
148 lines (121 loc) · 4.29 KB
/
ossn_com.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* notification sample
*
* @package Notification sample
* @author Rafael Amorim <amorim@rafaelamorim.com.br>
* @copyright (c) Rafael Amorim
* @license General Public Licence http://www.opensource-socialnetwork.org/licence
* @link https://www.rafaelamorim.com.br/
*
* Following instructions from https://www.opensource-socialnetwork.org/discussion/view/2967/how-to-send-notifications-to-users-using-ossnnotifications-class?offset=1
*
* By definition of the notification system, isn't allowed to user create a
* self notification. So, to make this function, it's necessary to create a
* dummy user and change "__notificationsample_dummy_guid__" value above.
* I will keep in 1, but you need to change. Or test with another user account.
* Otherwise, OSSN show an error message.
*
*/
define('__notificationsample_dummy_guid__',1);
function notificationsample_init(){
//css
ossn_extend_view('css/ossn.default', 'css/notificationsample');
//page
ossn_register_page('notificationsample', 'notificationsample_page');
//menu
ossn_register_sections_menu('newsfeed', array(
'name' => 'notificationsample',
'text' => ossn_print('notification:add:myself'),
'url' => ossn_site_url('notificationsample/myself'),
'parent' => 'links',
'icon' => false
));
//hooks
ossn_add_hook('notification:add', 'notification:message:tomyself', 'notificationsamplemyself_add_config');
ossn_add_hook('notification:view', 'notification:message:tomyself', 'notificationsamplemyself_view');
}
function notificationsamplemyself_add_config($hook, $type, $return, $params){
error_log("in notificationsamplemyself_add_config function");
$params['owner_guid'] = $params['notification_owner'];
return $params;
}
function notificationsamplemyself_view($hook, $type, $return, $params){
$notif = $params;
$user = ossn_user_by_guid($notif->poster_guid);
$display = true;
if(!$user){
return false;
}
switch($notif->type){
case 'notification:message:tomyself':
$display = true;
$url = ossn_site_url("u/".$user->username);
break;
}
if(!$display){
return false;
}
$iconURL = $user->iconURL()->small;
return ossn_plugin_view('notifications/template/view', array(
'iconURL' => $iconURL,
'guid' => $notif->guid,
'type' => 'notification:message:tomyself',
'viewed' => $notif->viewed,
'url' => $url,
'icon_type' => 'alert',
'fullname' => $user->fullname,
));
}
function addNotificationSampleAnnotation($type,$subject_guid){
$annotation = new \OssnAnnotation;
if (empty($type) || !isset($subject_guid)) {
return false;
}
$annotation->owner_guid = ossn_loggedin_user()->guid;
$annotation->subject_guid = $subject_guid;
$annotation->value = '... any ...'; //empty value result false in addAnnotation
$annotation->type = $type;
if ($result = $annotation->addAnnotation()) {
return $result;
}
return false;
}
function notificationsample_page($pages){
$notifications = new OssnNotifications();
$redirect = false;
if (empty($pages[0])) {
ossn_error_page();
}
//Dummy user cant send message to himself
if (__notificationsample_dummy_guid__ == ossn_loggedin_user()->guid){
ossn_trigger_message(ossn_print('notification:message:dummy:failed'), 'error');
redirect(REF);
}
switch ($pages[0]) {
case 'myself':
$auxAnnotation = addNotificationSampleAnnotation('notification:message:tomyself','1');
$who_sent_notification_guid = __notificationsample_dummy_guid__;
$who_will_receive_notification_guid = ossn_loggedin_user()->guid;
$subject_guid = $auxAnnotation;
$item_guid = NULL;
$auxNotifications = $notifications->add('notification:message:tomyself', $who_sent_notification_guid, $auxAnnotation, $item_guid, $who_will_receive_notification_guid);
if ($auxAnnotation && $auxNotifications){
error_log("success!");
$redirect = true;
} else {
error_log("Result of auxAnnotation is ".print_r($auxAnnotation,true));
error_log("Result of auxNotifications is ".print_r($auxNotifications,true));
}
break;
default:
break;
}
if ($redirect){
redirect('home');
} else {
ossn_trigger_message(ossn_print('notification:message:failed'), 'error');
redirect(REF);
}
}
ossn_register_callback('ossn', 'init', 'notificationsample_init');