|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BP2020 Ideas plugin |
|
4
|
|
|
* @package ideas |
|
5
|
|
|
* @author Emmanuel Salomon @ManUtopiK |
|
6
|
|
|
* @license Dual licensed under the MIT and GNU Affero General Public License, version 3 or late |
|
7
|
|
|
* @copyright (c) Emmanuel Salomon 2012 |
|
8
|
|
|
* @link http:// |
|
9
|
|
|
**/ |
|
10
|
|
|
|
|
11
|
|
|
elgg_register_event_handler('init', 'system', 'ideas_init'); |
|
12
|
|
|
|
|
13
|
|
|
function ideas_init() { |
|
14
|
|
|
|
|
15
|
|
|
$root = dirname(__FILE__); |
|
16
|
|
|
elgg_register_library('ideas:utilities', "$root/lib/utilities.php"); |
|
17
|
|
|
|
|
18
|
|
|
// actions |
|
19
|
|
|
$action_base = "$root/actions/ideas"; |
|
20
|
|
|
elgg_register_action('ideas/saveidea', "$action_base/saveidea.php"); |
|
21
|
|
|
elgg_register_action('ideas/editidea', "$action_base/editidea.php"); |
|
22
|
|
|
elgg_register_action("ideas/rateidea", "$action_base/rateidea.php"); |
|
23
|
|
|
elgg_register_action('ideas/delete', "$action_base/deleteidea.php"); |
|
24
|
|
|
elgg_register_action('ideas/settings', "$action_base/settings.php"); |
|
25
|
|
|
|
|
26
|
|
|
elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'ideas_owner_block_menu'); |
|
27
|
|
|
|
|
28
|
|
|
elgg_register_page_handler('ideas', 'ideas_page_handler'); |
|
29
|
|
|
|
|
30
|
|
|
// Extend view |
|
31
|
|
|
elgg_extend_view('css/elgg', 'ideas/css'); |
|
32
|
|
|
elgg_extend_view('js/elgg', 'ideas/js'); |
|
33
|
|
|
|
|
34
|
|
|
// Register widgets |
|
35
|
|
|
elgg_register_widget_type( |
|
36
|
|
|
'ideas', |
|
37
|
|
|
elgg_echo('ideas:widget:title'), |
|
38
|
|
|
elgg_echo('ideas:widget:description') |
|
39
|
|
|
); |
|
40
|
|
|
/* |
|
41
|
|
|
elgg_register_widget_type( |
|
42
|
|
|
'points_left', |
|
43
|
|
|
elgg_echo('ideas:widget:points_left:title'), |
|
44
|
|
|
elgg_echo('ideas:widget:points_left:description'), |
|
45
|
|
|
'dashboard' |
|
46
|
|
|
); |
|
47
|
|
|
*/ |
|
48
|
|
|
|
|
49
|
|
|
// Register granular notification for this type |
|
50
|
|
|
register_notification_object('object', 'ideas', elgg_echo('ideas:new')); |
|
51
|
|
|
|
|
52
|
|
|
// Listen to notification events and supply a more useful message |
|
53
|
|
|
elgg_register_plugin_hook_handler('notify:entity:message', 'object', 'ideas_notify_message'); |
|
54
|
|
|
|
|
55
|
|
|
// Register a URL handler for ideas |
|
56
|
|
|
elgg_register_entity_url_handler('object', 'idea', 'idea_url'); |
|
57
|
|
|
|
|
58
|
|
|
// Register entity type for search |
|
59
|
|
|
elgg_register_entity_type('object', 'idea'); |
|
60
|
|
|
|
|
61
|
|
|
// Temporary disable notifications REMOVE THIS BEFORE SENDING TO PROD |
|
62
|
|
|
// elgg_register_plugin_hook_handler('email', 'system', 'ideas_mailer'); |
|
63
|
|
|
|
|
64
|
|
|
// Groups |
|
65
|
|
|
add_group_tool_option('ideas', elgg_echo('ideas:enableideas'), true); |
|
66
|
|
|
elgg_extend_view('groups/tool_latest', 'ideas/group_module'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
function ideas_mailer($hook, $type, $return, $params) { |
|
70
|
|
|
// elgg_send_email('[email protected]', '[email protected]', 'blocked email', 'just blocked an email'); |
|
71
|
|
|
return true; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Dispatcher for ideas. |
|
76
|
|
|
* |
|
77
|
|
|
* @param array $page |
|
78
|
|
|
*/ |
|
79
|
|
|
function ideas_page_handler($page) { |
|
80
|
|
|
elgg_load_library('ideas:utilities'); |
|
81
|
|
|
|
|
82
|
|
|
elgg_push_breadcrumb(elgg_echo('ideas'), 'ideas/all'); |
|
83
|
|
|
|
|
84
|
|
|
$pages = dirname(__FILE__) . '/pages/ideas'; |
|
85
|
|
|
|
|
86
|
|
|
switch ($page[0]) { |
|
87
|
|
|
case "read": |
|
88
|
|
|
case "view": |
|
89
|
|
|
set_input('guid', $page[1]); |
|
90
|
|
|
include "$pages/view.php"; |
|
91
|
|
|
break; |
|
92
|
|
|
case "add": |
|
93
|
|
|
gatekeeper(); |
|
94
|
|
|
include "$pages/saveidea.php"; |
|
95
|
|
|
break; |
|
96
|
|
|
case "edit": |
|
97
|
|
|
gatekeeper(); |
|
98
|
|
|
set_input('guid', $page[1]); |
|
99
|
|
|
include "$pages/editidea.php"; |
|
100
|
|
|
break; |
|
101
|
|
|
case "all": |
|
102
|
|
|
include "$pages/all.php"; |
|
103
|
|
|
break; |
|
104
|
|
|
case "owner": |
|
105
|
|
|
include "$pages/owner.php"; |
|
106
|
|
|
break; |
|
107
|
|
|
case "friends": |
|
108
|
|
|
include "$pages/friends.php"; |
|
109
|
|
|
break; |
|
110
|
|
|
case 'group': |
|
111
|
|
|
group_gatekeeper(); |
|
112
|
|
|
switch ($page[2]) { |
|
113
|
|
|
case "all": |
|
114
|
|
|
include "$pages/all_group.php"; |
|
115
|
|
|
break; |
|
116
|
|
|
case "top": |
|
117
|
|
|
include "$pages/top.php"; |
|
118
|
|
|
break; |
|
119
|
|
|
case "hot": |
|
120
|
|
|
include "$pages/hot.php"; |
|
121
|
|
|
break; |
|
122
|
|
|
case "new": |
|
123
|
|
|
include "$pages/new.php"; |
|
124
|
|
|
break; |
|
125
|
|
|
case "tagcloud": |
|
126
|
|
|
include "$pages/tagcloud.php"; |
|
127
|
|
|
break; |
|
128
|
|
|
case "settings": |
|
129
|
|
|
include "$pages/settings.php"; |
|
130
|
|
|
break; |
|
131
|
|
|
default: |
|
132
|
|
|
forward(elgg_get_site_url() . 'ideas/group/' . $page[1] . '/top'); |
|
133
|
|
|
break; |
|
134
|
|
|
} |
|
135
|
|
|
break; |
|
136
|
|
|
|
|
137
|
|
|
default: |
|
138
|
|
|
return false; |
|
139
|
|
|
break; |
|
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
elgg_pop_context(); |
|
143
|
|
|
|
|
144
|
|
|
return true; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Populates the ->getUrl() method for idea objects |
|
150
|
|
|
* |
|
151
|
|
|
* @param ElggEntity $entity The idea object |
|
152
|
|
|
* @return string idea item URL |
|
153
|
|
|
*/ |
|
154
|
|
|
function idea_url($entity) { |
|
155
|
|
|
global $CONFIG; |
|
156
|
|
|
|
|
157
|
|
|
$title = $entity->title; |
|
158
|
|
|
$title = elgg_get_friendly_title($title); |
|
159
|
|
|
return $CONFIG->url . "ideas/view/" . $entity->getGUID() . "/" . $title; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Add a menu item to an ownerblock |
|
164
|
|
|
* |
|
165
|
|
|
* @param string $hook |
|
166
|
|
|
* @param string $type |
|
167
|
|
|
* @param array $return |
|
168
|
|
|
* @param array $params |
|
169
|
|
|
*/ |
|
170
|
|
View Code Duplication |
function ideas_owner_block_menu($hook, $type, $return, $params) { |
|
171
|
|
|
if (elgg_instanceof($params['entity'], 'user')) { |
|
172
|
|
|
$url = "ideas/owner/{$params['entity']->username}"; |
|
173
|
|
|
$item = new ElggMenuItem('ideas', elgg_echo('ideas'), $url); |
|
174
|
|
|
$return[] = $item; |
|
175
|
|
|
} else { |
|
176
|
|
|
if ($params['entity']->ideas_enable != 'no') { |
|
177
|
|
|
$url = "ideas/group/{$params['entity']->guid}/top"; |
|
178
|
|
|
$item = new ElggMenuItem('ideas', elgg_echo('ideas:group:idea'), $url); |
|
179
|
|
|
// if (elgg_in_context('ideas')) $item->setSelected(); |
|
180
|
|
|
$return[] = $item; |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
return $return; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Returns the body of a notification message |
|
189
|
|
|
* |
|
190
|
|
|
* @param string $hook |
|
191
|
|
|
* @param string $entity_type |
|
192
|
|
|
* @param string $returnvalue |
|
193
|
|
|
* @param array $params |
|
194
|
|
|
*/ |
|
195
|
|
|
function ideas_notify_message($hook, $entity_type, $returnvalue, $params) { |
|
196
|
|
|
$entity = $params['entity']; |
|
197
|
|
|
$to_entity = $params['to_entity']; |
|
198
|
|
|
$method = $params['method']; |
|
199
|
|
|
if (($entity instanceof ElggEntity) && ($entity->getSubtype() == 'idea')) { |
|
200
|
|
|
$descr = $entity->description; |
|
201
|
|
|
$title = $entity->title; |
|
202
|
|
|
|
|
203
|
|
|
$url = elgg_get_site_url() . "view/" . $entity->guid; |
|
204
|
|
View Code Duplication |
if ($method == 'sms') { |
|
205
|
|
|
$owner = $entity->getOwnerEntity(); |
|
206
|
|
|
return $owner->name . ' ' . elgg_echo("ideas:via") . ': ' . $url . ' (' . $title . ')'; |
|
207
|
|
|
} |
|
208
|
|
View Code Duplication |
if ($method == 'email') { |
|
209
|
|
|
$owner = $entity->getOwnerEntity(); |
|
210
|
|
|
return $owner->name . ' ' . elgg_echo("ideas:via") . ': ' . $title . "\n\n" . $descr . "\n\n" . $entity->getURL(); |
|
211
|
|
|
} |
|
212
|
|
View Code Duplication |
if ($method == 'web') { |
|
213
|
|
|
$owner = $entity->getOwnerEntity(); |
|
214
|
|
|
return $owner->name . ' ' . elgg_echo("ideas:via") . ': ' . $title . "\n\n" . $descr . "\n\n" . $entity->getURL(); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
} |
|
218
|
|
|
return null; |
|
219
|
|
|
} |
|
220
|
|
|
|
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.