Salut,
Code PHP:
require_once('./global.php');
require_once(DIR . '/includes/functions_user.php');
require_once(DIR . '/includes/functions_misc.php');
require_once(DIR . '/includes/functions_newpost.php');
// bootstrap framework
require_once(DIR . '/includes/class_bootstrap_framework.php');
vB_Bootstrap_Framework::init();
// Mets à jour les compteurs de message
// Fonction copiée depuis private.php.
function build_pm_counters()
{
global $vbulletin;
$pmcount = $vbulletin->db->query_first("
SELECT
COUNT(pmid) AS pmtotal,
SUM(IF(messageread = 0 AND folderid >= 0, 1, 0)) AS pmunread
FROM " . TABLE_PREFIX . "pm AS pm
WHERE pm.userid = " . $vbulletin->userinfo['userid'] . "
");
$pmcount['pmtotal'] = intval($pmcount['pmtotal']);
$pmcount['pmunread'] = intval($pmcount['pmunread']);
if ($vbulletin->userinfo['pmtotal'] != $pmcount['pmtotal'] OR $vbulletin->userinfo['pmunread'] != $pmcount['pmunread'])
{
// init user data manager
$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
$userdata->set_existing($vbulletin->userinfo);
$userdata->set('pmtotal', $pmcount['pmtotal']);
$userdata->set('pmunread', $pmcount['pmunread']);
$userdata->save();
}
}
function send_pm(array $pm) {
global $vbulletin, $permissions;
$pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY);
$pmdm->set_info('savecopy', $pm['savecopy']);
$pmdm->set_info('receipt', $pm['receipt']);
$pmdm->set_info('cantrackpm', $cantrackpm);
$pmdm->set_info('forward', $pm['forward']);
$pmdm->set_info('bccrecipients', $pm['bccrecipients']);
$pmdm->set('fromuserid', isset($pm['fromuserid']) ? $pm['fromuserid'] : $vbulletin->userinfo['userid']);
$pmdm->set('fromusername', isset($pm['fromusername']) ? $pm['fromusername'] : $vbulletin->userinfo['username']);
$pmdm->setr('title', $pm['title']);
$pmdm->set_recipients($pm['recipients'], $permissions, 'cc');
$pmdm->set_recipients($pm['bccrecipients'], $permissions, 'bcc');
$pmdm->setr('message', $pm['message']);
$pmdm->setr('iconid', $pm['iconid']);
$pmdm->set('dateline', TIMENOW);
$pmdm->setr('showsignature', $pm['signature']);
$pmdm->set('allowsmilie', $pm['disablesmilies'] ? 0 : 1);
$pmdm->overridequota = true; /* Contourne les quotas */
($hook = vBulletinHook::fetch_hook('private_insertpm_process')) ? eval($hook) : false;
$pmdm->pre_save();
$pmdm->save();
$vbulletin->userinfo['pmunread'] = -1;
build_pm_counters();
($hook = vBulletinHook::fetch_hook('private_insertpm_complete')) ? eval($hook) : false;
}
send_pm(array(
'fromuserid' => 1, /* ID de l'expéditeur */
'fromusername' => 'Simon', /* Expéditeur */
'recipients' => 'Simon', /* Destinataire */
'message' => 'Hello World', /* Message */
'title' => 'Dit bonjour!' /* Titre */
));
Liens sociaux