| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
define('user_session_name', 'elgguser'); |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
define('AUTH_COOKIE', 'elggperm'); |
|---|
| 21 |
define('AUTH_COOKIE_LENGTH', 31556926); |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
define('AUTH_MSG_OK', __gettext("You have been logged on.")); |
|---|
| 25 |
define('AUTH_MSG_BADLOGIN', __gettext("Unrecognised username or password. The system could not log you on, or you may not have activated your account.")); |
|---|
| 26 |
define('AUTH_MSG_MISSING', __gettext("Either the username or password were not specified. The system could not log you on.")); |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
function user_info($fieldname, $user_id) { |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
static $id_to_name_table; |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
$user_id = (int) $user_id; |
|---|
| 40 |
|
|---|
| 41 |
$user_id)) { |
|---|
| 42 |
$id_to_name_table[$user_id][$fieldname])) { |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
$id_to_name_table[$user_id] = (array) get_record('users','ident',$user_id); |
|---|
| 48 |
|
|---|
| 49 |
$id_to_name_table[$user_id][$fieldname])) { |
|---|
| 50 |
$id_to_name_table[$user_id][$fieldname]; |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
return false; |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
function user_info_username($fieldname, $username) { |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
static $name_to_id_table; |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
if (!empty($username)) { |
|---|
| 69 |
$name_to_id_table[$username][$fieldname])) { |
|---|
| 70 |
|
|---|
| 71 |
$name_to_id_table[$username] = (array) get_record('users','username',$username); |
|---|
| 72 |
|
|---|
| 73 |
$name_to_id_table[$username][$fieldname])){ |
|---|
| 74 |
$name_to_id_table[$username][$fieldname]; |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
return false; |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
function user_type($user_id) { |
|---|
| 85 |
|
|---|
| 86 |
user_info('user_type', $user_id); |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
function user_flag_get($flag_name, $user_id) { |
|---|
| 94 |
$result = get_record('user_flags','flag',$flag_name,'user_id',$user_id)) { |
|---|
| 95 |
$result->value; |
|---|
| 96 |
|
|---|
| 97 |
false; |
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
function user_flag_unset($flag_name, $user_id) { |
|---|
| 102 |
delete_records('user_flags','flag',$flag_name,'user_id',$user_id); |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
function user_flag_set($flag_name, $value, $user_id) { |
|---|
| 107 |
$flag_name = trim($flag_name); |
|---|
| 108 |
$flag_name) { |
|---|
| 109 |
|
|---|
| 110 |
user_flag_unset($flag_name, $user_id); |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
$flag = new StdClass; |
|---|
| 114 |
$flag->flag = $flag_name; |
|---|
| 115 |
$flag->user_id = $user_id; |
|---|
| 116 |
$flag->value = $value; |
|---|
| 117 |
insert_record('user_flags',$flag); |
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
function accesslevel($owner = -1) { |
|---|
| 127 |
$currentaccess = 0; |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
if (logged_on == 1) { |
|---|
| 131 |
$currentaccess++; |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
$_SESSION['userid'] == $owner) { |
|---|
| 135 |
$currentaccess += 1000; |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
$currentaccess; |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
function protect($level, $owner = -1) { |
|---|
| 143 |
accesslevel($owner) < $level) { |
|---|
| 144 |
run("access_denied"); |
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
function message_user($to, $from, $title, $message) { |
|---|
| 154 |
|
|---|
| 155 |
$messages, $CFG; |
|---|
| 156 |
|
|---|
| 157 |
$to->ident)) { |
|---|
| 158 |
$to = $to->ident; |
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
$notifications = user_flag_get("emailnotifications",$to); |
|---|
| 162 |
$notifications) { |
|---|
| 163 |
$email_from = new StdClass; |
|---|
| 164 |
$email_from->email = $CFG->noreplyaddress; |
|---|
| 165 |
$email_from->name = $CFG->sitename; |
|---|
| 166 |
|
|---|
| 167 |
$email_to = get_record_sql("select * from ".$CFG->prefix."users where ident = " . $to)) { |
|---|
| 168 |
|
|---|
| 169 |
email_to_user($email_to,$email_from,$title,$message . "\n\n\n" . __gettext("You cannot reply to this message by email."))) { |
|---|
| 170 |
$messages[] = __gettext("Failed to send email. An unknown error occurred."); |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
$m = new StdClass; |
|---|
| 176 |
$m->title = $title; |
|---|
| 177 |
$m->body = $message; |
|---|
| 178 |
$m->from_id = $from; |
|---|
| 179 |
$m->to_id = $to; |
|---|
| 180 |
$m->posted = time(); |
|---|
| 181 |
$m->status = 'unread'; |
|---|
| 182 |
|
|---|
| 183 |
insert_record('messages',$m)) { |
|---|
| 184 |
$messages[] = __gettext("Failed to send message. An unknown error occurred."); |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
function get_messages($user_id, $number = null, $timeframe = null) { |
|---|
| 192 |
|
|---|
| 193 |
$CFG; |
|---|
| 194 |
|
|---|
| 195 |
$where = ""; |
|---|
| 196 |
$limit = ""; |
|---|
| 197 |
$number != null) { |
|---|
| 198 |
$limit = "limit $number"; |
|---|
| 199 |
|
|---|
| 200 |
$timeframe != null) { |
|---|
| 201 |
$where = " and posted > ". (time() - $timeframe); |
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
get_records_sql("select * from ".$CFG->prefix."messages where to_id = $user_id $where order by posted desc $limit"); |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
function display_message($message) { |
|---|
| 212 |
|
|---|
| 213 |
$CFG; |
|---|
| 214 |
|
|---|
| 215 |
$message->from_id == -1) { |
|---|
| 216 |
$from->name = __gettext("System"); |
|---|
| 217 |
|
|---|
| 218 |
$from = get_record_sql("select * from ".$CFG->prefix."users where ident = " . $message->from_id); |
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
$title = "[Message from "; |
|---|
| 222 |
$message->from_id != -1) { |
|---|
| 223 |
$title .= "<a href=\"" . $CFG->wwwroot . user_info("username",$message->from_id) . "/\">"; |
|---|
| 224 |
|
|---|
| 225 |
$title .= $from->name; |
|---|
| 226 |
$message->from_id != -1) { |
|---|
| 227 |
$title .= "</a>"; |
|---|
| 228 |
|
|---|
| 229 |
$title .= "] " . $message->title; |
|---|
| 230 |
$body = "<p>" . nl2br(str_replace("\t"," ",activate_urls($message->body))) . "</p>"; |
|---|
| 231 |
|
|---|
| 232 |
$body = templates_draw(array( |
|---|
| 233 |
'context' => 'databox1', |
|---|
| 234 |
'name' => $title, |
|---|
| 235 |
'column1' => $body |
|---|
| 236 |
) |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
$body; |
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
function notify_user($user_id, $title, $message) { |
|---|
| 247 |
|
|---|
| 248 |
message_user($user_id, -1, $title, $message); |
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
function messages_read($user_id) { |
|---|
| 255 |
|
|---|
| 256 |
$CFG; |
|---|
| 257 |
|
|---|
| 258 |
set_field('messages', 'status', 'read', 'to_id', $user_id); |
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
function cleanup_messages($older_than) { |
|---|
| 265 |
|
|---|
| 266 |
$CFG, $messages; |
|---|
| 267 |
execute_sql("delete from ".$CFG->prefix."messages where posted < " . $older_than,false); |
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
function count_users($type = '', $last_action = 0) { |
|---|
| 279 |
|
|---|
| 280 |
$CFG; |
|---|
| 281 |
|
|---|
| 282 |
$where = "1 = 1"; |
|---|
| 283 |
$type)) { |
|---|
| 284 |
$where .= " AND user_type = '$type'"; |
|---|
| 285 |
|
|---|
| 286 |
$last_action > 0) { |
|---|
| 287 |
$where .= " AND last_action > " . $last_action; |
|---|
| 288 |
|
|---|
| 289 |
$users = get_records_sql('SELECT user_type, count(ident) AS numusers |
|---|
| 290 |
.$CFG->prefix.'users |
|---|
| 291 |
.$where.' |
|---|
| 292 |
)) { |
|---|
| 293 |
sizeof($users) > 1) { |
|---|
| 294 |
$users; |
|---|
| 295 |
|
|---|
| 296 |
$users as $user) { |
|---|
| 297 |
$user->numusers; |
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
false; |
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
?> |
|---|