This repository was archived by the owner on Nov 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.php
More file actions
221 lines (204 loc) · 6.91 KB
/
start.php
File metadata and controls
221 lines (204 loc) · 6.91 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
/**
* Elgg libform_utils plugin
*
* @package ElggLibFormUtils
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Diego Andrés Ramírez Aragón <dramirezaragon@gmail.com>
* @copyright Diego Andrés Ramírez Aragón 2010
* @link http://github.com/lowfill/libform_utils
*/
/**
* libform_utils initialization
*/
function libform_utils_init(){
$root = dirname(__FILE__);
$url_root = elgg_get_site_url()."mod/libform_utils";
//Register css and javascripts
elgg_register_css("libform:css","$url_root/css/libform.css");
// Comboselect
elgg_register_css("libform:comboselect","$url_root/vendors/jquery-comboselect/jquery-comboselect.css");
elgg_register_js("libform:comboselect", "$url_root/vendors/jquery-comboselect/jquery-comboselect.js");
// Autosuggest
elgg_register_css("libform:autosuggest","$url_root/vendors/jquery-tokeninput/token-input.css");
elgg_register_css("libform:autosuggest:facebook","$url_root/vendors/jquery-tokeninput/token-input-facebook.css");
elgg_register_js("libform:autosuggest","$url_root/vendors/jquery-tokeninput/jquery.tokeninput.js");
// Location
elgg_register_js("libform:location:i18n","$url_root/vendors/location/location.php");
elgg_register_js("libform:location","$url_root/vendors/location/location.js");
// Flexigrid
elgg_register_css("libform:grid","$url_root/vendors/flexigrid/css/flexigrid/flexigrid.css");
elgg_register_js("libform:grid","$url_root/vendors/flexigrid/flexigrid.js");
// Validator
elgg_register_js("libform:validator","$url_root/vendors/jquery-validate/jquery.validate.js");
elgg_register_js("libform:validator:aditional","$url_root/vendors/jquery-validate/additional-methods.js");
elgg_register_js("libform:validator:metadata","$url_root/vendors/jquery-validate/lib/jquery.metadata.js");
$current_language = get_language();
if($current_language != "en" && file_exists("$root/vendors/jquery-validate/localization/messages_{$current_language}.js")){
elgg_register_js("libform:validator:i18n","$url_root/vendors/jquery-validate/localization/messages_{$current_language}.js");
}
//Register handlers
elgg_register_page_handler('libform','libform_page_handler');
elgg_register_page_handler('suggest','suggest_page_handler');
elgg_register_page_handler('grid','grid_page_handler');
elgg_register_page_handler('timeline','timeline_page_handler');
set_include_path(dirname(__FILE__)."/vendors/pear/:".get_include_path());
}
/**
* libform_utils page handler
* @todo Implements this
* @param $page
*/
function libform_page_handler($page){
$pages = dirname(__FILE__)."/pages/libform";
include "$pages/examples.php";
elgg_pop_context();
return true;
}
/**
* Suggest page handler
*
* Process urls that match /pg/suggest/(user|group)
* @param $page
*/
function suggest_page_handler($page){
global $CONFIG;
$query=get_input("q");
if(count($page)>0 && in_array($page[0],array('user','group'))){
if(!empty($query)){
switch($page[0]){
case 'user':
$join = "JOIN {$CONFIG->dbprefix}users_entity ue ON e.guid = ue.guid";
$where = "(ue.guid = e.guid AND (ue.username LIKE '%$query%' OR ue.name LIKE '%$query%'))";
break;
case 'group':
$join = "JOIN {$CONFIG->dbprefix}groups_entity ue ON e.guid = ue.guid";
$where = "(ue.guid = e.guid AND (ue.name LIKE '%$query%'))";
break;
}
$options = array(
'type'=>$page[0],
'subtype'=>ELGG_ENTITIES_NO_VALUE,
'joins'=>array($join),
'wheres'=>array($where),
);
$entities = elgg_get_entities($options);
}
$data = array();
if(!empty($entities)){
foreach($entities as $entity){
$data[]=array('id'=>$entity->guid,'name'=>$entity->name,'url'=>$entity->getURL());
}
}
}
else{
$function_name = "{$page[0]}_suggest_hook";
$extra_param = (isset($page[1]))?$page[1]:"";
if(function_exists($function_name)){
$data = $function_name($query,$extra_param);
}
}
header("Content-type: application/json");
echo json_encode($data);
exit;
}
/**
* Grid page handler
* @param $page
*/
function grid_page_handler($page){
$handler = (isset($page[0]))?$page[0]:"users";
$view = "grid/{$handler}_data";
if(elgg_view_exists($view)){
header("Content-type: application/json");
echo elgg_view($view);
exit;
}
}
/**
* Timeline page handler
* @param $page
*/
function timeline_page_handler($page){
$handler = (isset($page[0]))?$page[0]:"users";
$view = "timeline/{$handler}_data";
if(elgg_view_exists($view)){
header("Content-type: application/json");
echo elgg_view($view);
exit;
}
}
/**
* Get the list of validators and messages from an string
*
* @param string $validator_str ';' separated validators string
* @param string $messages String with the custom messages for the field
* @return string
*/
function libform_get_validators($validator_str,$messages=""){
$validators = array();
$u_validators = explode(";",$validator_str);
if(!is_array($u_validators)){
$u_validators = array($u_validators);
}
foreach($u_validators as $validator){
if(empty($validator)) continue;
if(strpos($validator,":")>0){
$validators["data-rule-".substr($validator,0,strpos($validator,":"))]=substr($validator,strpos($validator,":")+1);
}
else{
$validators["data-rule-$validator"]="true";
}
}
if(!empty($messages)){
$u_messages = explode(",",$messages);
if(!empty($u_messages)){
foreach($u_messages as $message){
list($validator,$message) = explode(':',$message);
$validators['data-msg-'.$validator]=$message;
}
}
}
return $validators;
}
function libform_get_countries(){
static $countries = array();
$raw = file(dirname(__FILE__)."/vendors/countries.txt");
if(empty($countries)){
foreach($raw as $country){
$country = explode(";",$country);
$countries[$country[0]]=$country[1];
}
$countries = array_map(elgg_echo,$countries);
}
return $countries;
}
function libform_get_country($code){
$countries = libform_get_countries();
return $countries[$code];
}
function libform_format_attributes(array $attrs,$type='text'){
if(array_key_exists('internalname', $attrs) && !array_key_exists('internalid', $attrs)){
$attrs['internalid']=$attrs['internalname'];
}
if(array_key_exists('multiple', $attrs) && $attrs['multiple']===true){
$attrs['internalname'].="[]";
}
if(array_key_exists('validate', $attrs)){
switch($type){
case "comboselect":
//FIXME Implements automatic validator for this kind of field
break;
default:
$validators = libform_get_validators($attrs['validate'],$attrs['validate_messages']);
}
$attrs += $validators;
unset($attrs['validate']);
unset($attrs['validate_messages']);
}
// Cleaning old parameters
unset($attrs['separator']);
return $attrs;
}
elgg_register_event_handler('init','system','libform_utils_init');
?>