function shutdown() { $error = error_get_last(); if (!empty($error)) { switch ($error['type']) { case E_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: case E_PARSE: echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . xmlresperror("Server error occurred: '{$error['message']} (" . basename($error['file']) . ":{$error['line']})'")->serialize('UTF-8'); break; } } }
function ignore_user_func() { global $mybb, $lang, $db, $cache; // Load global language phrases $lang->load("usercp"); if ($mybb->user['uid'] == 0 || $mybb->usergroup['canusercp'] == 0) { return tt_no_permission(); } if (!$mybb->user['pmfolders']) { $mybb->user['pmfolders'] = "1**" . $lang->folder_inbox . "\$%%\$2**" . $lang->folder_sent_items . "\$%%\$3**" . $lang->folder_drafts . "\$%%\$4**" . $lang->folder_trash; $db->update_query("users", array('pmfolders' => $mybb->user['pmfolders']), "uid='" . $mybb->user['uid'] . "'"); } $existing_users = array(); $selected_list = array(); if ($mybb->input['manage'] == "ignored") { if ($mybb->user['ignorelist']) { $existing_users = explode(",", $mybb->user['ignorelist']); } } else { if ($mybb->user['ignorelist']) { // Create a list of ignored users $selected_list = explode(",", $mybb->user['ignorelist']); } } $error_message = ""; $message = ""; $users = $mybb->input['user_id']; $mode = $mybb->input['mode']; // Adding one or more users to this list if (!empty($users) && $mode) { // Split up any usernames we have $found_users = 0; $adding_self = false; $users = explode(",", $users); $users = array_map("trim", $users); $users = array_unique($users); foreach ($users as $key => $user_id) { $user_id = intval($user_id); if (empty($user_id)) { continue; } $users[$key] = $user_id; } // Fetch out new users if (count($users) > 0) { $query = $db->simple_select("users", "uid", "uid IN ('" . implode("','", $users) . "')"); while ($user = $db->fetch_array($query)) { ++$found_users; // Make sure we're not adding a duplicate if (in_array($user['uid'], $existing_users) || in_array($user['uid'], $selected_list)) { if ($mybb->input['manage'] == "ignored") { $error_message = "ignore"; } else { $error_message = "buddy"; } // On another list? $string = "users_already_on_" . $error_message . "_list"; if (in_array($user['uid'], $selected_list)) { $string .= "_alt"; } $error_message = $lang->{$string}; array_pop($users); // To maintain a proper count when we call count($users) continue; } $existing_users[] = $user['uid']; } } if ($found_users < count($users)) { if ($error_message) { $error_message .= "<br />"; } $error_message .= $lang->invalid_user_selected; } if (($adding_self != true || $adding_self == true && count($users) > 0) && ($error_message == "" || count($users) > 1)) { if ($mybb->input['manage'] == "ignored") { $message = $lang->users_added_to_ignore_list; } else { $message = $lang->users_added_to_buddy_list; } } if ($adding_self == true) { if ($mybb->input['manage'] == "ignored") { $error_message = $lang->cant_add_self_to_ignore_list; } else { $error_message = $lang->cant_add_self_to_buddy_list; } } if (count($existing_users) == 0) { $message = ""; } } else { if ($mode == 0 && !empty($users)) { // Check if user exists on the list $key = array_search($users, $existing_users); if ($key !== false) { unset($existing_users[$key]); $user = get_user($users); if ($mybb->input['manage'] == "ignored") { $message = $lang->removed_from_ignore_list; } else { $message = $lang->removed_from_buddy_list; } $message = $lang->sprintf($message, $user['username']); } else { $error_message = $lang->invalid_user_selected; } } } if ($error_message) { return xmlrespfalse($error_message); } if (empty($message)) { return xmlresperror($lang->invalid_user_selected); } // Now we have the new list, so throw it all back together $new_list = implode(",", $existing_users); // And clean it up a little to ensure there is no possibility of bad values $new_list = preg_replace("#,{2,}#", ",", $new_list); $new_list = preg_replace("#[^0-9,]#", "", $new_list); if (my_substr($new_list, 0, 1) == ",") { $new_list = my_substr($new_list, 1); } if (my_substr($new_list, -1) == ",") { $new_list = my_substr($new_list, 0, my_strlen($new_list) - 2); } // And update $user = array(); if ($mybb->input['manage'] == "ignored") { $user['ignorelist'] = $db->escape_string($new_list); $mybb->user['ignorelist'] = $user['ignorelist']; } else { $user['buddylist'] = $db->escape_string($new_list); $mybb->user['buddylist'] = $user['buddylist']; } $db->update_query("users", $user, "uid='" . $mybb->user['uid'] . "'"); $result = new xmlrpcval(array('result' => new xmlrpcval(true, 'boolean'), 'result_text' => new xmlrpcval(strip_tags($message), 'base64')), 'struct'); return new xmlrpcresp($result); }
public function service($data = null, $return_payload = false) { if ($data === null) { // workaround for a known bug in php ver. 5.2.2 that broke $HTTP_RAW_POST_DATA $ver = phpversion(); if ($ver[0] >= 5) { $data = file_get_contents('php://input'); } else { $data = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : ''; } } $raw_data = $data; // reset internal debug info $this->debug_info = ''; // Echo back what we received, before parsing it if ($this->debug > 1) { $this->debugmsg("+++GOT+++\n" . $data . "\n+++END+++"); } // Dark: HAAAX try { $r = $this->parseRequestHeaders($data, $req_charset, $resp_charset, $resp_encoding); if (!$r) { $r = $this->parseRequest($data, $req_charset); } } catch (Exception $e) { $error = $e->getMessage(); if (!empty($error)) { $r = xmlresperror("Server error occurred [{$error}; darkxmlrpcs]"); } } // Dark: HAAAX x2 if (!empty($GLOBALS['tapatalk_error'])) { $r2 = xmlresperror($GLOBALS['tapatalk_error']); } if ($r === null) { $r = xmlresperror("Server error occurred [no response; darkxmlrpcs]"); } // triple check if (!empty($r2) && $r2 instanceof xmlrpcresp) { $r = $r2; } // save full body of request into response, for more debugging usages $r->raw_data = $raw_data; if ($this->debug > 2 && $GLOBALS['_xmlrpcs_occurred_errors']) { $this->debugmsg("+++PROCESSING ERRORS AND WARNINGS+++\n" . $GLOBALS['_xmlrpcs_occurred_errors'] . "+++END+++"); } $payload = $this->xml_header($resp_charset); if ($this->debug > 0) { $payload = $payload . $this->serializeDebug($resp_charset); } // G. Giunta 2006-01-27: do not create response serialization if it has // already happened. Helps building json magic if (empty($r->payload)) { $r->serialize($resp_charset); } $payload = $payload . $r->payload; if ($return_payload) { return $payload; } // if we get a warning/error that has output some text before here, then we cannot // add a new header. We cannot say we are sending xml, either... if (!headers_sent()) { header('Content-Type: ' . $r->content_type); // we do not know if client actually told us an accepted charset, but if he did // we have to tell him what we did header("Vary: Accept-Charset"); // http compression of output: only // if we can do it, and we want to do it, and client asked us to, // and php ini settings do not force it already $php_no_self_compress = ini_get('zlib.output_compression') == '' && ini_get('output_handler') != 'ob_gzhandler'; if ($this->compress_response && function_exists('gzencode') && $resp_encoding != '' && $php_no_self_compress) { if (strpos($resp_encoding, 'gzip') !== false) { $payload = gzencode($payload); header("Content-Encoding: gzip"); header("Vary: Accept-Encoding"); } elseif (strpos($resp_encoding, 'deflate') !== false) { $payload = gzcompress($payload); header("Content-Encoding: deflate"); header("Vary: Accept-Encoding"); } } // do not ouput content-length header if php is compressing output for us: // it will mess up measurements if ($php_no_self_compress) { header('Content-Length: ' . (int) strlen($payload)); } } else { error_log('XML-RPC: xmlrpc_server::service: http headers already sent before response is fully generated. Check for php warning or error messages'); } @ob_end_clean(); print $payload; // return request, in case subclasses want it return $r; }