j'ai besoin de votre aide

j'ai besoin de votre aide - PHP - Programmation

Marsh Posté le 08-05-2014 à 20:08:03    

Bonjour,
 
j'ai besoin de votre aide :  
 
je possède un forum très actif : ce forum fonctionne avec phorum.
 
je voudrais limiter l'accès de la messagerie privée en l'interdisant à un groupe d'utilisateurs bien précis.
j'ai cherché sur le site de phorum si un module existait et je n'en ai pas trouvé. En revanche, j'ai trouvé un module qui permet le contraire, c'est à dire, d'autoriser la MP aux membres de groupes (tous) en même temps qu'il permet de la limiter à des usagers qui ne sont pas inscrits depuis longtemps et/ou à d'autres qui n'ont pas posté plus de x messages.
Bref, je sens bien qu'en bidouillant ce module, je dois arriver à mes fins, mais j'ai peur de faire une connerie car je susi vraiment une bille en programmation.
 
je vous livre le scipt de ce fichier : si quelqu'un peut m'aider .... en échange, à part vous conseiller sur tel ou tel vin, je ne vois pas. à votre bon coeur m'sieur dame !
 
<html>
<head>
<?php /*
Private Message Restrctions module for Phorum 5.2
Author: Frank Montmarquet, Phorum user: fmon
 
Version: 2.0.1 , Jan 8, 2008
 
This script is Free.
*/
 
if(!defined("PHORUM" )) return;
 
define( 'SECONDS_IN_DAY', 86400);
 
if( ! isset( $GLOBALS["PHORUM"]['mod_pmrestrictions']['any_group_ok']))
$GLOBALS["PHORUM"]['mod_pmrestrictions']['any_group_ok'] = 0;
 
if( ! isset( $GLOBALS["PHORUM"]['mod_pmrestrictions']['min_reg_time']))
$GLOBALS["PHORUM"]['mod_pmrestrictions']['min_reg_time'] = 5;
 
if( ! isset( $GLOBALS["PHORUM"]['mod_pmrestrictions']['min_post_number']))
$GLOBALS["PHORUM"]['mod_pmrestrictions']['min_post_number'] = 5;
 
// to do add list of groups
// check for altered forms and shut down PMs?? arrays should be arrays etc.
// regestered time in whole days?
// find way to allow non-aproved users reply to PM without adding nonapproved users
 
function phorum_mod_pmrestrictions_common() {
 
$PHORUM = $GLOBALS["PHORUM"];
 
if( ! $PHORUM["enable_pm"] || ! $PHORUM["DATA"]["LOGGEDIN"]) return;
 
if( phorum_mod_pmrestrictions_check_user( $PHORUM['user'])) {
// bad user
$GLOBALS["PHORUM"]["enable_pm"] = FALSE; // disable PM system and quit
$GLOBALS["PHORUM"]["DATA"]["ENABLE_PM"] = '';
 
$GLOBALS["PHORUM"]["DATA"]["LANG"]["PMDisabled"] =
$PHORUM["DATA"]["LANG"]["mod_pmrestrictions"]["NoPmPrivilege"];
 
return;
}
 
if( phorum_page != 'pm') return; // only proceed if in PM system
 
if( isset( $_POST['action']) && $_POST['action'] == 'buddies' && isset($_POST["send_pm"]) ) {
if( isset($_POST['checked'])) phorum_mod_pmrestrictions_check_buddy_list();
return;
}
 
// check to or if adding a recipiant
 
if( (isset($_POST["to_name"]) && ! empty($_POST["to_name"])) ||
(isset($_POST["to_id"]) && ! empty($_POST["to_id"])) ) {
phorum_mod_pmrestrictions_check_new_recipient();
// return;
}
 
// check the recipient list, except if deleting a recipient
 
if(isset( $_POST["recipients"]) && is_array($_POST["recipients"])) {
 
$del_rcpt = FALSE;
foreach ($_POST as $key => $val) {
 
if( stripos($key, "del_rcpt" ) !== FALSE) { $del_rcpt = TRUE ; break ;}
}
 
if( ! $del_rcpt ) phorum_mod_pmrestrictions_check_recipient_list();
// return;
}
}
 
// check if added recipiant meets requirments
// leave things as found if OK
 
function phorum_mod_pmrestrictions_check_new_recipient() {
 
$PHORUM = $GLOBALS["PHORUM"];
// by name
if( isset($_POST["to_name"])) {
 
$to_name = trim($_POST["to_name"]);
 
if ($to_name != '') {
 
$to_user_ids = phorum_api_user_search('display_name', $to_name, '=', TRUE);
 
if ( empty($to_user_ids) || count($to_user_ids) > 1) {
// error, do nothing, let pm.php do it
}
else {
$_POST["to_id"] = array_shift($to_user_ids);
}
}
}
 
// or by id
if( isset($_POST["to_id"]) && is_numeric($_POST["to_id"])) {
 
$user = phorum_api_user_get($_POST["to_id"]); // pm.php checks for !user_active error
 
if ($user && $user["active"] == PHORUM_USER_ACTIVE) {
 
if( phorum_mod_pmrestrictions_check_user( $user)) {
 
// bad recipient, fake UserNotFound error and set error message
 
if( isset($_POST['rcpt_add'])) {
 
$GLOBALS["PHORUM"]["DATA"]["LANG"]["UserNotFound"] =
$PHORUM["DATA"]["LANG"]["mod_pmrestrictions"]["AddRecipientNotApproved"];
}
else
{
$GLOBALS["PHORUM"]["DATA"]["LANG"]["PMNoRecipients"] =
$PHORUM["DATA"]["LANG"]["mod_pmrestrictions"]["AddRecipientNotApproved"];
}
 
$_POST["to_id"] = -10000; // is ok? a better way?
if( isset($_POST["to_name"])) unset($_POST["to_name"]); // submit only bad id to get error display
}
}
}
 
if( isset($_POST["to_name"])) {
// POST to_name was submitted so unset to_id and let pm.php work as if we didn't exist
 
if( isset($_POST["to_id"])) unset($_POST["to_id"]);
}
 
}
 
// check post for valid recipient list
function phorum_mod_pmrestrictions_check_recipient_list() {
 
$PHORUM = $GLOBALS["PHORUM"];
 
// Get recipients from the form and check if valid
 
if (isset($_POST["recipients"]) && is_array($_POST["recipients"])) {
 
$bad_recip = FALSE;
 
foreach ($_POST["recipients"] as $id => $dummy) {
 
$user = phorum_api_user_get($id);
 
if( phorum_mod_pmrestrictions_check_user( $user)) {
 
// bad recipient
$bad_recip = TRUE;
unset( $_POST["recipients"][$id]);
}
}
 
if( $bad_recip) {
// set error and change to preview
 
$GLOBALS["PHORUM"]["DATA"]["LANG"]["PreviewExplain"] =
$PHORUM["DATA"]["LANG"]["mod_pmrestrictions"]["RecipientRemoved"];
 
$GLOBALS['PHORUM']["DATA"]["GLOBAL_ERROR"] =
$PHORUM["DATA"]["LANG"]["mod_pmrestrictions"]["RecipientListNotApproved"];
 
if( isset($_POST['post'])) unset($_POST['post']);
if( ! isset($_POST['preview'])) $_POST['preview']=1;
 
if( empty($_POST["recipients"])) $_POST["hide_userselect"] = "";
// none left, display user select
}
}
}
 
function phorum_mod_pmrestrictions_check_buddy_list() {
 
$PHORUM = $GLOBALS["PHORUM"];
 
if( isset($_POST["checked"]) && is_array($_POST["checked"])) {
 
foreach ($_POST["checked"] as $pm_id) {
 
$id = (int)$pm_id;
 
$user = phorum_api_user_get($id);
 
if( phorum_mod_pmrestrictions_check_user( $user)) {
 
// bad user, uncheck and issue error, uncheck only bad and issue global error?
 
unset( $_POST["checked"]); // to stay on same page
 
$GLOBALS['PHORUM']["DATA"]["GLOBAL_ERROR"] =
$PHORUM["DATA"]["LANG"]["mod_pmrestrictions"]["BadBuddyError"];
 
break;
}
}
}
 
}
 
// for now treat all users the same, to do - different for sender and recipient?
 
function phorum_mod_pmrestrictions_check_user( $user) {
 
$PHORUM = $GLOBALS["PHORUM"];
 
$deny_pm = FALSE;
 
// avoid unneeded checks, break as soon as user is no good
 
do {
 
if( empty($user) || $user["active"] != PHORUM_USER_ACTIVE) { $deny_pm = TRUE; break; }
if( ! empty($user['admin'])) break; // admin gets all groups
 
if( $PHORUM['mod_pmrestrictions']['any_group_ok']) {
 
// check if user is member of any group
 
if( isset( $user['groups'])) {
if( empty( $user['groups'])) { $deny_pm = TRUE; break; }
}
else {
if( ! phorum_api_user_check_group_access( PHORUM_USER_GROUP_APPROVED, PHORUM_ACCESS_ANY, $user['user_id']))
{ $deny_pm = TRUE; break; }
}
}
 
if( $PHORUM['mod_pmrestrictions']['min_post_number']) {
 
if( $user['posts'] < $PHORUM['mod_pmrestrictions']['min_post_number'] ) { $deny_pm = TRUE; break; }
}
 
if( $PHORUM['mod_pmrestrictions']['min_reg_time']) {
 
$regtime = time() - $user['date_added']; // in seconds
$regtime = (int)($regtime/SECONDS_IN_DAY); // in days
if( $regtime < $PHORUM['mod_pmrestrictions']['min_reg_time'] ) { $deny_pm = TRUE; break;}
}
 
} while(0); // one time
 
return $deny_pm;
}
 
?>
</head>
<body>
<br>
</body>
</html>
 

Reply

Marsh Posté le 08-05-2014 à 20:08:03   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed