Bon, j'ai eu un peu de mal |-( ... mais la version ci-dessous permet de ne forcer les utilisateurs vers leur page de personnalisation
que lors de leur
première identification
// check_consult
// checks if a user id is registered as having already
// visited his profile.php page.
// @uid : the user id
// @user_idsOK : (returned) array of all users ids having already visited
// their profile.php pages
//
// @returns : true or false whether the users has already visited his
// profile.php page or not
function check_consult($uid, &$user_idsOK) {
$t = array(); $v = false;
if ($v = (
($t = mysql_fetch_row(pwg_query("
SELECT `value`
FROM `".CONFIG_TABLE."`
WHERE `param` = 'redir_profile';
"))) !== false)
) {
$user_idsOK = explode(',', $t[0]);
$v = (in_array($uid, $user_idsOK));
}
return $v;
}
// RedirectToProfile
// redirects a visitor (not generic (forbidden) neither admin) to his
// profile.php page
//
// no variable, no return
add_event_handler('login_success', 'RedirectToProfile');
function RedirectToProfile() {
global $user;
if (!is_generic() and !is_admin()) {
$user_idsOK = array();
if (!check_consult($user['id'], $user_idsOK))
redirect(PHPWG_ROOT_PATH.'profile.php');
}
}
// RegisterProfileConsult
// registers a user id when a visitor visits his profile.php page.
// Checks if the value "redir_profile" of table <pwg>_config exists or not,
// and creates it if needed.
//
// no variable, no return
add_event_handler('loc_begin_profile', 'RegisterProfileConsult');
function RegisterProfileConsult() {
global $user, $template, $errors;
$user_idsOK = array();
if (!check_consult($user['id'], $user_idsOK)) {
$user_idsOK[] = $user['id'];
if (!mysql_fetch_row(pwg_query("
SELECT `value`
FROM `".CONFIG_TABLE."`
WHERE `param` = 'redir_profile';
"))) {
$v = (pwg_query("
INSERT INTO `".CONFIG_TABLE."` (`param`,`value`,`comment`)
VALUES ('redir_profile', \"".implode(',', $user_idsOK)."\" ,'Ids of users having checked their profile page at least once');
") === false);
}
else {
$v = (pwg_query("
UPDATE `".CONFIG_TABLE."`
SET `value` = \"".implode(',', $user_idsOK)."\"
WHERE `param` = 'redir_profile';
") === false);
}
if ($v) {
$errors[]='Unable to register user id '.$user['id'].' in redir_profile';
$template->assign('errors', $errors);
}
}
}
A priori,
NE FONCTIONNE PAS avec une "entrée"
pour "visiteur" (généralement ce sont des "génériques") de
[extension by LucMorizur] Event Cats.