Vergleich inc/datahandlers/pm.php - 1.6.1 - 1.6.10

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 6Zeile 6
 * Website: http://mybb.com
* License: http://mybb.com/about/license
*

 * Website: http://mybb.com
* License: http://mybb.com/about/license
*

 * $Id: pm.php 5168 2010-08-02 07:52:27Z RyanGordon $

 * $Id$

 */

// Disallow direct access to this file for security reasons

 */

// Disallow direct access to this file for security reasons

Zeile 34Zeile 34
	* @var string
*/
public $language_prefix = 'pmdata';

	* @var string
*/
public $language_prefix = 'pmdata';

	



	/**
* Array of data inserted in to a private message.

	/**
* Array of data inserted in to a private message.

	 *
* @var array
*/

	 *
* @var array
*/

	public $pm_insert_data = array();

	public $pm_insert_data = array();





	/**
* Array of data used to update a private message.
*
* @var array
*/
public $pm_update_data = array();

	/**
* Array of data used to update a private message.
*
* @var array
*/
public $pm_update_data = array();

	



	/**
* PM ID currently being manipulated by the datahandlers.
*/

	/**
* PM ID currently being manipulated by the datahandlers.
*/

	public $pmid = 0;	

	public $pmid = 0;


/**
* Verifies a private message subject.


/**
* Verifies a private message subject.

Zeile 141Zeile 141
	 */
function verify_recipient()
{

	 */
function verify_recipient()
{

		global $db, $mybb, $lang;


		global $cache, $db, $mybb, $lang;


		$pm = &$this->data;

		$pm = &$this->data;





		$recipients = array();

		$recipients = array();





		$invalid_recipients = array();
// We have our recipient usernames but need to fetch user IDs
if(array_key_exists("to", $pm))

		$invalid_recipients = array();
// We have our recipient usernames but need to fetch user IDs
if(array_key_exists("to", $pm))

Zeile 162Zeile 162
				if(!is_array($pm[$recipient_type]))
{
$pm[$recipient_type] = array($pm[$recipient_type]);

				if(!is_array($pm[$recipient_type]))
{
$pm[$recipient_type] = array($pm[$recipient_type]);

				}
foreach($pm[$recipient_type] as $username)
{
$username = trim($username);
if(empty($username))
{
continue;
}
// Check that this recipient actually exists
$query = $db->simple_select("users", "*", "username='".$db->escape_string($username)."'");
$user = $db->fetch_array($query);
if($recipient_type == "bcc")
{

				}

$recipientUsernames = array_map('trim', $pm[$recipient_type]);
$recipientUsernames = array_filter($recipientUsernames);
$recipientUsernames = array_map(array($db, 'escape_string'), $recipientUsernames);
$recipientUsernames = "'".implode("','", $recipientUsernames)."'";

$query = $db->simple_select('users', '*', 'username IN('.$recipientUsernames.')');

$validUsernames = array();

while ($user = $db->fetch_array($query)) {
if ($recipient_type == "bcc") {

						$user['bcc'] = 1;

						$user['bcc'] = 1;

					}
if($user['uid'])
{
$recipients[] = $user;
}
else
{
$invalid_recipients[] = $username;
}


					}

$recipients[] = $user;
$validUsernames[] = $user['username'];
}

foreach ($pm[$recipient_type] as $username) {
if (!in_array($username, $validUsernames) AND trim($username)) {
$invalid_recipients[] = $username;
}

				}
}
}

				}
}
}

Zeile 192Zeile 193
		else
{
foreach(array("toid", "bccid") as $recipient_type)

		else
{
foreach(array("toid", "bccid") as $recipient_type)

			{

			{

				if(count($pm['toid']) <= 0)

				if(count($pm['toid']) <= 0)

				{

				{

					$this->set_error("no_recipients");
return false;
}
if(is_array($pm[$recipient_type]))

					$this->set_error("no_recipients");
return false;
}
if(is_array($pm[$recipient_type]))

				{
foreach($pm[$recipient_type] as $uid)
{
// Check that this recipient actually exists
$query = $db->simple_select("users", "*", "uid='".intval($uid)."'");
$user = $db->fetch_array($query);
if($recipient_type == "bccid")
{




				{
$recipientUids = array_map('intval', $pm[$recipient_type]);
$recipientUids = array_filter($recipientUids);
$recipientUids = "'".implode("','", $recipientUids)."'";

$query = $db->simple_select('users', '*', 'uid IN('.$recipientUids.')');

$validUids = array();

while ($user = $db->fetch_array($query)) {
if ($recipient_type == "bcc") {

							$user['bcc'] = 1;
}

							$user['bcc'] = 1;
}

						if($user['uid'])
{
$recipients[] = $user;
}
else
{



$recipients[] = $user;
$validUids[] = $user['uid'];
}

foreach ($pm[$recipient_type] as $uid) {
if (!in_array($uid, $validUids) AND trim($uid)) {

							$invalid_recipients[] = $uid;
}
}

							$invalid_recipients[] = $uid;
}
}

Zeile 243Zeile 248
		{
// Collect group permissions for this recipient.
$recipient_permissions = user_permissions($user['uid']);

		{
// Collect group permissions for this recipient.
$recipient_permissions = user_permissions($user['uid']);

	



			// See if the sender is on the recipients ignore list and that either
// - admin_override is set or
// - sender is an administrator

			// See if the sender is on the recipients ignore list and that either
// - admin_override is set or
// - sender is an administrator

			if($this->admin_override != true && $sender_permissions['cancp'] != 1)

			if(($this->admin_override != true && $sender_permissions['cancp'] != 1) && $sender_permissions['canoverridepm'] != 1)

			{
$ignorelist = explode(",", $user['ignorelist']);
if(!empty($ignorelist) && in_array($pm['fromid'], $ignorelist))
{
$this->set_error("recipient_is_ignoring", array($user['username']));
}

			{
$ignorelist = explode(",", $user['ignorelist']);
if(!empty($ignorelist) && in_array($pm['fromid'], $ignorelist))
{
$this->set_error("recipient_is_ignoring", array($user['username']));
}

				



				// Is the recipient only allowing private messages from their buddy list?
if($mybb->settings['allowbuddyonly'] == 1 && $user['receivefrombuddy'] == 1)
{

				// Is the recipient only allowing private messages from their buddy list?
if($mybb->settings['allowbuddyonly'] == 1 && $user['receivefrombuddy'] == 1)
{

Zeile 264Zeile 269
						$this->set_error("recipient_has_buddy_only", array(htmlspecialchars_uni($user['username'])));
}
}

						$this->set_error("recipient_has_buddy_only", array(htmlspecialchars_uni($user['username'])));
}
}

				



				// Can the recipient actually receive private messages based on their permissions or user setting?
if(($user['receivepms'] == 0 || $recipient_permissions['canusepms'] == 0) && !$pm['saveasdraft'])
{
$this->set_error("recipient_pms_disabled", array($user['username']));
return false;

				// Can the recipient actually receive private messages based on their permissions or user setting?
if(($user['receivepms'] == 0 || $recipient_permissions['canusepms'] == 0) && !$pm['saveasdraft'])
{
$this->set_error("recipient_pms_disabled", array($user['username']));
return false;

				}
}


				}
}


			// Check to see if the user has reached their private message quota - if they have, email them.
if($recipient_permissions['pmquota'] != "0" && $user['totalpms'] >= $recipient_permissions['pmquota'] && $recipient_permissions['cancp'] != 1 && $sender_permissions['cancp'] != 1 && !$pm['saveasdraft'] && !$this->admin_override)
{
if(trim($user['language']) != '' && $lang->language_exists($user['language']))
{
$uselang = trim($user['language']);

			// Check to see if the user has reached their private message quota - if they have, email them.
if($recipient_permissions['pmquota'] != "0" && $user['totalpms'] >= $recipient_permissions['pmquota'] && $recipient_permissions['cancp'] != 1 && $sender_permissions['cancp'] != 1 && !$pm['saveasdraft'] && !$this->admin_override)
{
if(trim($user['language']) != '' && $lang->language_exists($user['language']))
{
$uselang = trim($user['language']);

				}

				}

				elseif($mybb->settings['bblanguage'])
{
$uselang = $mybb->settings['bblanguage'];

				elseif($mybb->settings['bblanguage'])
{
$uselang = $mybb->settings['bblanguage'];

Zeile 304Zeile 309
				}
$emailmessage = $lang->sprintf($emailmessage, $user['username'], $mybb->settings['bbname'], $mybb->settings['bburl']);
$emailsubject = $lang->sprintf($emailsubject, $mybb->settings['bbname']);

				}
$emailmessage = $lang->sprintf($emailmessage, $user['username'], $mybb->settings['bbname'], $mybb->settings['bburl']);
$emailsubject = $lang->sprintf($emailsubject, $mybb->settings['bbname']);

				my_mail($user['email'], $emailsubject, $emailmessage);













$new_email = array(
"mailto" => $db->escape_string($user['email']),
"mailfrom" => '',
"subject" => $db->escape_string($emailsubject),
"message" => $db->escape_string($emailmessage),
"headers" => ''
);

$db->insert_query("mailqueue", $new_email);
$cache->update_mailqueue();


				if($this->admin_override != true)
{
$this->set_error("recipient_reached_quota", array($user['username']));
}
}

				if($this->admin_override != true)
{
$this->set_error("recipient_reached_quota", array($user['username']));
}
}

	



			// Everything looks good, assign some specifics about the recipient
$pm['recipients'][$user['uid']] = array(
"uid" => $user['uid'],

			// Everything looks good, assign some specifics about the recipient
$pm['recipients'][$user['uid']] = array(
"uid" => $user['uid'],

Zeile 322Zeile 337
				"pmnotify" => $user['pmnotify'],
"language" => $user['language']
);

				"pmnotify" => $user['pmnotify'],
"language" => $user['language']
);

			



			// If this recipient is defined as a BCC recipient, save it
if($user['bcc'] == 1)

			// If this recipient is defined as a BCC recipient, save it
if($user['bcc'] == 1)

			{

			{

				$pm['recipients'][$user['uid']]['bcc'] = 1;
}
}
return true;
}

				$pm['recipients'][$user['uid']]['bcc'] = 1;
}
}
return true;
}

	



	/**
* Verify that the user is not flooding the system.
*

	/**
* Verify that the user is not flooding the system.
*

Zeile 342Zeile 357
		global $mybb, $db;

$pm = &$this->data;

		global $mybb, $db;

$pm = &$this->data;

		



		// Check if post flooding is enabled within MyBB or if the admin override option is specified.
if($mybb->settings['pmfloodsecs'] > 0 && $pm['fromid'] != 0 && $this->admin_override == false)
{
// Fetch the senders profile data.
$sender = get_user($pm['fromid']);

		// Check if post flooding is enabled within MyBB or if the admin override option is specified.
if($mybb->settings['pmfloodsecs'] > 0 && $pm['fromid'] != 0 && $this->admin_override == false)
{
// Fetch the senders profile data.
$sender = get_user($pm['fromid']);

			



			// Calculate last post
$query = $db->simple_select("privatemessages", "dateline", "fromid='".$db->escape_string($pm['fromid'])."' AND toid != '0'", array('order_by' => 'dateline', 'order_dir' => 'desc', 'limit' => 1));
$sender['lastpm'] = $db->fetch_field($query, "dateline");

			// Calculate last post
$query = $db->simple_select("privatemessages", "dateline", "fromid='".$db->escape_string($pm['fromid'])."' AND toid != '0'", array('order_by' => 'dateline', 'order_dir' => 'desc', 'limit' => 1));
$sender['lastpm'] = $db->fetch_field($query, "dateline");

Zeile 408Zeile 423
		global $plugins;

$pm = &$this->data;

		global $plugins;

$pm = &$this->data;

		



		if(!$pm['savedraft'])
{
$this->verify_pm_flooding();

		if(!$pm['savedraft'])
{
$this->verify_pm_flooding();

Zeile 420Zeile 435
		$this->verify_sender();

$this->verify_recipient();

		$this->verify_sender();

$this->verify_recipient();

		
$this->verify_message();


$this->verify_message();


$this->verify_options();



$this->verify_options();


		$plugins->run_hooks_by_ref("datahandler_pm_validate", $this);

		$plugins->run_hooks("datahandler_pm_validate", $this);


// Choose the appropriate folder to save in.
if($pm['saveasdraft'])


// Choose the appropriate folder to save in.
if($pm['saveasdraft'])

Zeile 435Zeile 450
		else
{
$pm['folder'] = 1;

		else
{
$pm['folder'] = 1;

		}


		}


		// We are done validating, return.
$this->set_validated(true);
if(count($this->get_errors()) > 0)
{
return false;

		// We are done validating, return.
$this->set_validated(true);
if(count($this->get_errors()) > 0)
{
return false;

		}

		}

		else
{
return true;

		else
{
return true;

Zeile 456Zeile 471
	 */
function insert_pm()
{

	 */
function insert_pm()
{

		global $db, $mybb, $plugins, $lang;

		global $cache, $db, $mybb, $plugins, $lang;


// Yes, validating is required.
if(!$this->get_validated())
{
die("The PM needs to be validated before inserting it into the DB.");


// Yes, validating is required.
if(!$this->get_validated())
{
die("The PM needs to be validated before inserting it into the DB.");

		}

		}

		if(count($this->get_errors()) > 0)
{
die("The PM is not valid.");

		if(count($this->get_errors()) > 0)
{
die("The PM is not valid.");

Zeile 476Zeile 491
		if(!$pm['icon'] || $pm['icon'] < 0)
{
$pm['icon'] = 0;

		if(!$pm['icon'] || $pm['icon'] < 0)
{
$pm['icon'] = 0;

		}

$uid = 0;


		}

$uid = 0;


		if(!is_array($pm['recipients']))
{
$recipient_list = array();

		if(!is_array($pm['recipients']))
{
$recipient_list = array();

Zeile 500Zeile 515
				}
}
}

				}
}
}

		$recipient_list = serialize($recipient_list);

 

$this->pm_insert_data = array(
'fromid' => intval($pm['sender']['uid']),


$this->pm_insert_data = array(
'fromid' => intval($pm['sender']['uid']),

Zeile 514Zeile 528
			'smilieoff' => $pm['options']['disablesmilies'],
'receipt' => intval($pm['options']['readreceipt']),
'readtime' => 0,

			'smilieoff' => $pm['options']['disablesmilies'],
'receipt' => intval($pm['options']['readreceipt']),
'readtime' => 0,

			'recipients' => $db->escape_string($recipient_list)

			'recipients' => $db->escape_string(serialize($recipient_list))

		);

// Check if we're updating a draft or not.

		);

// Check if we're updating a draft or not.

Zeile 529Zeile 543
				// This draft was a reply to a PM
$pm['pmid'] = $draftcheck['deletetime'];
$pm['do'] = "reply";

				// This draft was a reply to a PM
$pm['pmid'] = $draftcheck['deletetime'];
$pm['do'] = "reply";

			}


			}


			// Delete the old draft as we no longer need it
$db->delete_query("privatemessages", "pmid='{$draftcheck['pmid']}'");
}

// Saving this message as a draft
if($pm['saveasdraft'])

			// Delete the old draft as we no longer need it
$db->delete_query("privatemessages", "pmid='{$draftcheck['pmid']}'");
}

// Saving this message as a draft
if($pm['saveasdraft'])

		{

		{

			$this->pm_insert_data['uid'] = $pm['sender']['uid'];

// If this is a reply, then piggyback into the deletetime to let us know in the future

			$this->pm_insert_data['uid'] = $pm['sender']['uid'];

// If this is a reply, then piggyback into the deletetime to let us know in the future

Zeile 545Zeile 559
			{
$this->pm_insert_data['deletetime'] = $pm['pmid'];
}

			{
$this->pm_insert_data['deletetime'] = $pm['pmid'];
}


$plugins->run_hooks_by_ref("datahandler_pm_insert_updatedraft", $this);


$plugins->run_hooks("datahandler_pm_insert_updatedraft", $this);

			$db->insert_query("privatemessages", $this->pm_insert_data);

// If this is a draft, end it here - below deals with complete messages

			$db->insert_query("privatemessages", $this->pm_insert_data);

// If this is a draft, end it here - below deals with complete messages

Zeile 554Zeile 568
				"draftsaved" => 1
);
}

				"draftsaved" => 1
);
}





		// Save a copy of the PM for each of our recipients
foreach($pm['recipients'] as $recipient)
{

		// Save a copy of the PM for each of our recipients
foreach($pm['recipients'] as $recipient)
{

Zeile 570Zeile 584
				elseif($mybb->settings['bblanguage'])
{
$uselang = $mybb->settings['bblanguage'];

				elseif($mybb->settings['bblanguage'])
{
$uselang = $mybb->settings['bblanguage'];

				}

				}

				else
{
$uselang = "english";

				else
{
$uselang = "english";

Zeile 589Zeile 603
					$emailsubject = $userlang->emailsubject_newpm;
$emailmessage = $userlang->email_newpm;
}

					$emailsubject = $userlang->emailsubject_newpm;
$emailmessage = $userlang->email_newpm;
}

				



				if(!$pm['sender']['username'])
{
$pm['sender']['username'] = $lang->mybb_engine;
}

				if(!$pm['sender']['username'])
{
$pm['sender']['username'] = $lang->mybb_engine;
}

				



				$emailmessage = $lang->sprintf($emailmessage, $recipient['username'], $pm['sender']['username'], $mybb->settings['bbname'], $mybb->settings['bburl']);
$emailsubject = $lang->sprintf($emailsubject, $mybb->settings['bbname']);

				$emailmessage = $lang->sprintf($emailmessage, $recipient['username'], $pm['sender']['username'], $mybb->settings['bbname'], $mybb->settings['bburl']);
$emailsubject = $lang->sprintf($emailsubject, $mybb->settings['bbname']);

				my_mail($recipient['email'], $emailsubject, $emailmessage);












$new_email = array(
"mailto" => $db->escape_string($recipient['email']),
"mailfrom" => '',
"subject" => $db->escape_string($emailsubject),
"message" => $db->escape_string($emailmessage),
"headers" => ''
);

$db->insert_query("mailqueue", $new_email);
$cache->update_mailqueue();

			}

$this->pm_insert_data['uid'] = $recipient['uid'];
$this->pm_insert_data['toid'] = $recipient['uid'];


			}

$this->pm_insert_data['uid'] = $recipient['uid'];
$this->pm_insert_data['toid'] = $recipient['uid'];


			$plugins->run_hooks_by_ref("datahandler_pm_insert", $this);

			$plugins->run_hooks("datahandler_pm_insert", $this);

			$this->pmid = $db->insert_query("privatemessages", $this->pm_insert_data);

// If PM noices/alerts are on, show!

			$this->pmid = $db->insert_query("privatemessages", $this->pm_insert_data);

// If PM noices/alerts are on, show!

Zeile 644Zeile 668
		// If we're saving a copy
if($pm['options']['savecopy'] != 0)
{

		// If we're saving a copy
if($pm['options']['savecopy'] != 0)
{

			if(count($recipient_list['to']) == 1)

			if(isset($recipient_list['to']) && count($recipient_list['to']) == 1)

			{
$this->pm_insert_data['toid'] = $uid;
}

			{
$this->pm_insert_data['toid'] = $uid;
}

Zeile 657Zeile 681
			$this->pm_insert_data['status'] = 1;
$this->pm_insert_data['receipt'] = 0;


			$this->pm_insert_data['status'] = 1;
$this->pm_insert_data['receipt'] = 0;


			$plugins->run_hooks_by_ref("datahandler_pm_insert_savedcopy", $this);

			$plugins->run_hooks("datahandler_pm_insert_savedcopy", $this);

			$db->insert_query("privatemessages", $this->pm_insert_data);

// Because the sender saved a copy, update their total pm count

			$db->insert_query("privatemessages", $this->pm_insert_data);

// Because the sender saved a copy, update their total pm count