forked from ewinslow/elgg-questions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.php
176 lines (134 loc) · 5.01 KB
/
start.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
function questions_init() {
elgg_register_library("elgg:questions", dirname(__FILE__) . "/lib/questions.php");
add_subtype("object", 'question', 'ElggQuestion');
update_subtype("object", 'question', 'ElggQuestion');
add_subtype("object", 'answer', 'ElggAnswer');
update_subtype("object", 'answer', 'ElggAnswer');
elgg_extend_view("css/elgg", "questions/css");
elgg_extend_view("js/elgg", "questions/js");
elgg_register_menu_item("site", array(
"name" => 'questions',
"text" => elgg_echo('questions'),
"href" => "/questions/all",
));
elgg_register_entity_type("object", 'questions');
elgg_register_widget_type('questions', elgg_echo("widget:questions:title"), elgg_echo("widget:questions:description"));
$actions_base = dirname(__FILE__) . '/actions/object/question';
elgg_register_action("object/question/save", "$actions_base/save.php");
elgg_register_action("object/question/delete", "$actions_base/delete.php");
elgg_register_entity_url_handler('object', 'question', 'questions_url_handler');
$plugin_dir = dirname(__FILE__);
elgg_register_entity_url_handler('object', 'answer', 'answers_url');
elgg_register_page_handler('questions', 'questions_page_handler');
$actions_base = "$plugin_dir/actions/object/answer";
elgg_register_action('object/answer/add', "$actions_base/save.php");
elgg_register_action('object/answer/edit', "$actions_base/save.php");
elgg_register_plugin_hook_handler("register", "menu:owner_block", 'questions_owner_block_menu_handler');
elgg_register_plugin_hook_handler("register", "menu:user_hover", 'questions_user_hover_menu_handler');
elgg_register_plugin_hook_handler("register", 'menu:entity', 'questions_entity_menu_handler');
elgg_register_plugin_hook_handler("notify:entity:message", "object", 'questions_notify_message_handler');
add_group_tool_option('questions', elgg_echo("questions:enable"), true);
elgg_extend_view("groups/tool_latest", "questions/group_module");
}
function questions_owner_block_menu_handler($hook, $type, $items, $params) {
$entity = $params['entity'];
if ($entity instanceof ElggGroup && $entity->questions_enable != 'no') {
$items[] = ElggMenuItem::factory(array(
'name' => 'questions',
'href' => "/questions/group/$entity->guid/all",
'text' => elgg_echo('questions:group'),
));
} elseif ($entity instanceof ElggUser) {
$items[] = ElggMenuItem::factory(array(
'name' => 'questions',
'href' => "/questions/owner/$entity->username",
'text' => elgg_echo('questions'),
));
}
return $items;
}
function questions_entity_menu_handler($hook, $type, $items, $params) {
$entity = $params['entity'];
if ($entity->getSubtype() == 'question' || $entity->getSubtype() == 'answer') {
if ($entity->canAnnotate(0, 'generic_comment')) {
$items[] = ElggMenuItem::factory(array(
'name' => 'comment',
'rel' => 'toggle',
'link_class' => 'elgg-toggler',
'href' => "#comments-add-$entity->guid",
'text' => elgg_view_icon('speech-bubble'),
'priority' => 600,
));
}
}
return $items;
}
function questions_notify_message_handler($hook, $entity_type, $returnvalue, $params) {
$entity = $params['entity'];
$to_entity = $params['to_entity'];
$method = $params['method'];
if (elgg_instanceof($entity, 'object', 'question')) {
$descr = $entity->description;
$title = $entity->title;
$url = $entity->getURL();
$owner = $entity->getOwnerEntity();
$via = elgg_echo("questions:via");
if ($method == 'sms') {
//shortening the url for sms
$url = elgg_get_site_url() . "view/$entity->guid";
return "$owner->name $via: $url ($title)";
}
if ($method == 'email') {
return "$owner->name $via: $title \n\n $descr \n\n $url";
}
if ($method == 'web') {
return "$owner->name $via: $title \n\n $descr \n\n $url";
}
}
return null;
}
function questions_page_handler($segments) {
elgg_push_breadcrumb(elgg_echo('questions'), "/questions/all");
$pages = dirname(__FILE__) . "/pages/questions";
switch ($segments[0]) {
case "all":
include "$pages/all.php";
break;
case "owner":
include "$pages/owner.php";
break;
case "friends":
gatekeeper();
include "$pages/friends.php";
break;
case "view":
set_input('guid', $segments[1]);
include "$pages/view.php";
break;
case "add":
gatekeeper();
include "$pages/add.php";
break;
case "edit":
gatekeeper();
set_input('guid', $segments[1]);
include "$pages/edit.php";
break;
case 'group':
group_gatekeeper();
include "$pages/owner.php";
break;
default:
return false;
}
elgg_pop_context();
return true;
}
function questions_url_handler($question) {
return "/questions/view/$question->guid/" . elgg_get_friendly_title($question->title);
}
function answers_url($answer) {
return get_entity($answer->container_guid)->getURL() . "#answer-$answer->guid";
}
elgg_register_event_handler('init', 'system', 'questions_init');