function create_message_func($xmlrpc_params) { global $db, $lang, $theme, $plugins, $mybb, $session, $settings, $cache, $time, $mybbgroups, $pminfo, $pm; $input = Tapatalk_Input::filterXmlInput(array('user_name' => Tapatalk_Input::RAW, 'subject' => Tapatalk_Input::STRING, 'text_body' => Tapatalk_Input::STRING, 'action' => Tapatalk_Input::INT, 'pm_id' => Tapatalk_Input::INT), $xmlrpc_params); $lang->load("private"); $parser = new postParser(); if ($mybb->settings['enablepms'] == 0) { return xmlrespfalse($lang->pms_disabled); } if ($mybb->user['uid'] == '/' || $mybb->user['uid'] == 0 || $mybb->usergroup['canusepms'] == 0) { return tt_no_permission(); } if (!$mybb->user['pmfolders']) { $mybb->user['pmfolders'] = "1**\$%%\$2**\$%%\$3**\$%%\$4**"; $sql_array = array("pmfolders" => $mybb->user['pmfolders']); $db->update_query("users", $sql_array, "uid = " . $mybb->user['uid']); } $rand = my_rand(0, 9); if ($rand == 5) { update_pm_count(); } if ($mybb->usergroup['cansendpms'] == 0) { return tt_no_permission(); } $pmhandler = new PMDataHandler(); $pm = array("subject" => $input['subject'], "message" => $input['text_body'], "icon" => 0, "fromid" => $mybb->user['uid'], "do" => $input['action'] == 1 ? 'reply' : 'forward', "pmid" => $input['pm_id']); $pm['to'] = array_map("trim", $input['user_name']); $pm['options'] = array("signature" => 0, "disablesmilies" => 0, "savecopy" => 1, "readreceipt" => 0); $pmhandler->set_data($pm); if (!$pmhandler->validate_pm()) { $pm_errors = $pmhandler->get_friendly_errors(); return xmlrespfalse(implode(" :: ", $pm_errors)); } else { $pminfo = $pmhandler->insert_pm(); $plugins->run_hooks("private_do_send_end"); } return xmlresptrue(); }
} if (isset($mybb->input['options']['savecopy']) && $mybb->input['options']['savecopy'] == 1) { $pm['options']['savecopy'] = 1; } else { $pm['options']['savecopy'] = 0; } if (isset($mybb->input['options']['readreceipt'])) { $pm['options']['readreceipt'] = $mybb->input['options']['readreceipt']; } if (!empty($mybb->input['saveasdraft'])) { $pm['saveasdraft'] = 1; } $pmhandler->set_data($pm); // Now let the pm handler do all the hard work. if (!$pmhandler->validate_pm()) { $pm_errors = $pmhandler->get_friendly_errors(); $send_errors = inline_error($pm_errors); $mybb->input['action'] = "send"; } else { $pminfo = $pmhandler->insert_pm(); $plugins->run_hooks("private_do_send_end"); if (isset($pminfo['draftsaved'])) { redirect("private.php", $lang->redirect_pmsaved); } else { redirect("private.php", $lang->redirect_pmsent); } } } if ($mybb->input['action'] == "send") { if ($mybb->usergroup['cansendpms'] == 0) { error_no_permission();
function task_massmail($task) { global $db, $mybb, $lang; $query = $db->simple_select("massemails", "*", "senddate <= '" . TIME_NOW . "' AND status IN (1,2)"); while ($mass_email = $db->fetch_array($query)) { if ($mass_email['status'] == 1) { $db->update_query("massemails", array('status' => 2), "mid='{$mass_email['mid']}'", 1); } $sentcount = 0; if (!$mass_email['perpage']) { $mass_email['perpage'] = 50; } if (strpos($mass_email['htmlmessage'], '<br />') === false && strpos($mass_email['htmlmessage'], '<br>') === false) { $mass_email['htmlmessage'] = nl2br($mass_email['htmlmessage']); } $mass_email['orig_message'] = $mass_email['message']; $mass_email['orig_htmlmessage'] = $mass_email['htmlmessage']; // Need to perform the search to fetch the number of users we're emailing $member_query = build_mass_mail_query(unserialize($mass_email['conditions'])); $count_query = $db->simple_select("users u", "COUNT(uid) AS num", $member_query); $mass_email['totalcount'] = $db->fetch_field($count_query, "num"); $query2 = $db->simple_select("users u", "u.uid, u.language, u.pmnotify, u.lastactive, u.username, u.email", $member_query, array('limit_start' => $mass_email['sentcount'], 'limit' => $mass_email['perpage'], 'order_by' => 'u.uid', 'order_dir' => 'asc')); while ($user = $db->fetch_array($query2)) { $replacement_fields = array("{uid}" => $user['uid'], "{username}" => $user['username'], "{email}" => $user['email'], "{bbname}" => $mybb->settings['bbname'], "{bburl}" => $mybb->settings['bburl'], "[" . $lang->massmail_username . "]" => $user['username'], "[" . $lang->email_addr . "]" => $user['email'], "[" . $lang->board_name . "]" => $mybb->settings['bbname'], "[" . $lang->board_url . "]" => $mybb->settings['bburl']); foreach ($replacement_fields as $find => $replace) { $mass_email['message'] = str_replace($find, $replace, $mass_email['message']); $mass_email['htmlmessage'] = str_replace($find, $replace, $mass_email['htmlmessage']); } // Private Message if ($mass_email['type'] == 1) { $pm_handler = new PMDataHandler(); $pm_handler->admin_override = true; $pm = array("subject" => $mass_email['subject'], "message" => $mass_email['message'], "fromid" => $mass_email['uid'], "options" => array("savecopy" => 0)); $pm['to'] = explode(",", $user['username']); $pm_handler->set_data($pm); if (!$pm_handler->validate_pm()) { $friendly_errors = implode('\\n', $pm_handler->get_friendly_errors()); add_task_log($task, $lang->sprintf($lang->task_massmail_ran_errors, htmlspecialchars_uni($user['username']), $friendly_errors)); $friendly_errors = ""; } else { $pm_handler->insert_pm(); } } else { switch ($mass_email['format']) { case 2: $format = "both"; $text_message = $mass_email['message']; $mass_email['message'] = $mass_email['htmlmessage']; break; case 1: $format = "html"; $text_message = ""; $mass_email['message'] = $mass_email['htmlmessage']; break; default: $format = "text"; $text_message = ""; } my_mail($user['email'], $mass_email['subject'], $mass_email['message'], "", "", "", false, $format, $text_message); } ++$sentcount; $mass_email['message'] = $mass_email['orig_message']; $mass_email['htmlmessage'] = $mass_email['orig_htmlmessage']; } $update_array = array(); $update_array['sentcount'] = $mass_email['sentcount'] + $sentcount; $update_array['totalcount'] = $mass_email['totalcount']; if ($update_array['sentcount'] >= $mass_email['totalcount']) { $update_array['status'] = 3; } $db->update_query("massemails", $update_array, "mid='{$mass_email['mid']}'", 1); } add_task_log($task, $lang->task_massmail_ran); }
/** * Send a private message from someone to someone */ function sendPrivateMessage($data = array()) { // Let's do default values and check if all required data keys are passed $default_data = array('fromid' => 0, 'subject' => '', 'message' => '', 'icon' => 0, 'to_username' => ''); // Set default values if they are missing! foreach ($default_data as $default_data_key => $default_data_val) { if (!isset($data[$default_data_key])) { $data[$default_data_key] = $default_data_val; } } $this->lang->load('private'); $this->plugins->run_hooks('private_send_do_send'); // Attempt to see if this PM is a duplicate or not $time_cutoff = TIME_NOW - 5 * 60 * 60; $query = $this->db->query("\n\t\t\tSELECT pm.pmid\n\t\t\tFROM " . TABLE_PREFIX . "privatemessages pm\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "users u ON(u.uid=pm.toid)\n\t\t\tWHERE u.username='******'to_uername']) . "' AND pm.dateline > {$time_cutoff} AND pm.fromid='{" . $data['fromid'] . "}' AND pm.subject='" . $this->db->escape_string($data['subject']) . "' AND pm.message='" . $this->db->escape_string($data['message']) . "' AND pm.folder!='3'\n\t\t"); $duplicate_check = $this->db->fetch_field($query, "pmid"); if ($duplicate_check) { return $this->lang->error_pm_already_submitted; } require_once MYBB_ROOT . "inc/datahandlers/pm.php"; $pmhandler = new PMDataHandler(); // Split up any recipients we have $data['to'] = explode(",", $data['to_username']); $data['to'] = array_map("trim", $data['to']); if (!empty($data['bcc'])) { $data['bcc'] = explode(",", $data['bcc']); $data['bcc'] = array_map("trim", $data['bcc']); } $data['options'] = array("signature" => isset($data['options']['signature']) ? $data['options']['signature'] : NULL, "disablesmilies" => isset($data['options']['disablesmilies']) ? $data['options']['disablesmilies'] : NULL, "savecopy" => isset($data['options']['savecopy']) ? $data['options']['savecopy'] : NULL, "readreceipt" => isset($data['options']['readreceipt']) ? $data['options']['readreceipt'] : NULL); /* Unnecessary if($data['saveasdraft']) { $data['saveasdraft'] = 1; } */ $pmhandler->set_data($data); // Now let the pm handler do all the hard work. if (!$pmhandler->validate_pm()) { $pm_errors = $pmhandler->get_friendly_errors(); return inline_error($pm_errors); } else { $pminfo = $pmhandler->insert_pm(); $this->plugins->run_hooks("private_do_send_end"); if (isset($pminfo['draftsaved'])) { return $this->lang->redirect_pmsaved; } else { return $this->lang->redirect_pmsent; } } }
/** * Registers an user with Facebook data */ public function register($user) { if (!$user) { return false; } global $mybb, $session, $plugins, $lang; require_once MYBB_ROOT . "inc/datahandlers/user.php"; $userhandler = new UserDataHandler("insert"); $plength = 8; if ($mybb->settings['minpasswordlength']) { $plength = (int) $mybb->settings['minpasswordlength']; } $password = random_str($plength); $new_user = array("username" => $user['name'], "password" => $password, "password2" => $password, "email" => $user['email'], "email2" => $user['email'], "usergroup" => (int) $mybb->settings['myfbconnect_usergroup'], "regip" => $session->ipaddress, "longregip" => my_ip2long($session->ipaddress), "options" => array("hideemail" => 1)); /* Registration might fail for custom profile fields required at registration... workaround = IN_ADMINCP defined. Placed straight before the registration process to avoid conflicts with third party plugins messying around with templates (I'm looking at you, PHPTPL) */ define("IN_ADMINCP", 1); $userhandler->set_data($new_user); if ($userhandler->validate_user()) { $user_info = $userhandler->insert_user(); $plugins->run_hooks("member_do_register_end"); // Deliver a welcome PM if ($mybb->settings['myfbconnect_passwordpm']) { require_once MYBB_ROOT . "inc/datahandlers/pm.php"; $pmhandler = new PMDataHandler(); $pmhandler->admin_override = true; // Make sure admins haven't done something bad $fromid = (int) $mybb->settings['myfbconnect_passwordpm_fromid']; if (!$mybb->settings['myfbconnect_passwordpm_fromid'] or !user_exists($mybb->settings['myfbconnect_passwordpm_fromid'])) { $fromid = 0; } $message = $mybb->settings['myfbconnect_passwordpm_message']; $subject = $mybb->settings['myfbconnect_passwordpm_subject']; $thingsToReplace = array("{user}" => $user_info['username'], "{password}" => $password); // Replace what needs to be replaced foreach ($thingsToReplace as $find => $replace) { $message = str_replace($find, $replace, $message); } $pm = array("subject" => $subject, "message" => $message, "fromid" => $fromid, "toid" => array($user_info['uid'])); // Some defaults :) $pm['options'] = array("signature" => 1); $pmhandler->set_data($pm); // Now let the PM handler do all the hard work if ($pmhandler->validate_pm()) { $pmhandler->insert_pm(); } else { error($lang->sprintf($lang->myfbconnect_error_report, $pmhandler->get_friendly_errors())); } } // Post a message on the user's wall if ($mybb->settings['myfbconnect_postonwall']) { $this->post_on_wall($mybb->settings['myfbconnect_postonwall_message']); } // Finally return our new user data return $user_info; } else { return array('error' => $userhandler->get_friendly_errors()); } return true; }