[7795] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Register PhpBB |
---|
| 4 | Version: 2.1.a |
---|
| 5 | Description: Link user registration from Piwigo to PhpBB forum (registration, password changing, deletion) - Original Eric's Register_FluxBB plugin adapted to PhpBB. / Liez l'inscription des utilisateurs de Piwigo avec votre forum PhpBB - Adaptation du plugin Register_FluxBB d'Eric. |
---|
| 6 | Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=129 |
---|
| 7 | Author: Pierric, Eric |
---|
| 8 | Author URI: http://www.infernoweb.net |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | /* |
---|
| 12 | -------------------------------------------------------------------------------- |
---|
| 13 | Author : Pierric, Eric |
---|
[8046] | 14 | email : pierrot007@gmail.com, eric@piwigo.org |
---|
[7795] | 15 | website : http://www.infernoweb.net |
---|
| 16 | PWG user : http://fr.piwigo.org/forum/profile.php?id=5784, http://forum.phpwebgallery.net/profile.php?id=1106 |
---|
| 17 | -------------------------------------------------------------------------------- |
---|
| 18 | |
---|
| 19 | :: HISTORY |
---|
| 20 | |
---|
| 21 | 2.1.a - 15/11/2010 - Initial release. |
---|
| 22 | -------------------------------------------------------------------------------- |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | // pour faciliter le debug - make debug easier :o) |
---|
| 26 | //ini_set('error_reporting', E_ALL); |
---|
| 27 | //ini_set('display_errors', true); |
---|
| 28 | |
---|
| 29 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 30 | |
---|
| 31 | if (!defined('REGPHPBB_DIR')) define('REGPHPBB_DIR' , basename(dirname(__FILE__))); |
---|
| 32 | if (!defined('REGPHPBB_PATH')) define('REGPHPBB_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
| 33 | |
---|
| 34 | include_once (REGPHPBB_PATH.'include/constants.php'); |
---|
| 35 | include_once (REGPHPBB_PATH.'include/functions.inc.php'); |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | /* plugin administration */ |
---|
| 39 | add_event_handler('get_admin_plugin_menu_links', 'Register_PhpBB_admin_menu'); |
---|
| 40 | |
---|
| 41 | function Register_PhpBB_admin_menu($menu) |
---|
| 42 | { |
---|
| 43 | array_push($menu, array( |
---|
| 44 | 'NAME' => 'Register PhpBB', |
---|
| 45 | 'URL' => get_admin_plugin_menu_link(REGPHPBB_PATH.'admin/admin.php'))); |
---|
| 46 | return $menu; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | /* user creation*/ |
---|
| 51 | add_event_handler('register_user', 'Register_PhpBB_Adduser'); |
---|
| 52 | |
---|
| 53 | function Register_PhpBB_Adduser($register_user) |
---|
| 54 | { |
---|
| 55 | global $conf; |
---|
| 56 | |
---|
| 57 | // Exclusion of Adult_Content users |
---|
| 58 | if ($register_user['username'] != "16" and $register_user['username'] != "18") |
---|
| 59 | { |
---|
| 60 | include_once (REGPHPBB_PATH.'include/functions.inc.php'); |
---|
| 61 | |
---|
| 62 | // Warning : PhpBB uses md5 hash like Piwigo, but not like PhpBB ! |
---|
| 63 | PhpBB_Adduser($register_user['id'], $register_user['username'], md5($_POST['password']), $register_user['email']); |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | /* user deletion */ |
---|
| 69 | add_event_handler('delete_user', 'Register_PhpBB_Deluser'); |
---|
| 70 | |
---|
| 71 | function Register_PhpBB_Deluser($user_id) |
---|
| 72 | { |
---|
| 73 | include_once (REGPHPBB_PATH.'include/functions.inc.php'); |
---|
| 74 | |
---|
| 75 | PhpBB_Deluser( PhpBB_Searchuser($user_id), true ); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | /* Profile management */ |
---|
| 80 | if (script_basename() == 'profile') |
---|
| 81 | { |
---|
| 82 | add_event_handler('loc_begin_profile', 'Register_PhpBB_InitPage', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
| 83 | |
---|
| 84 | function Register_PhpBB_InitPage() |
---|
| 85 | { |
---|
| 86 | global $conf, $user; |
---|
| 87 | include_once (REGPHPBB_PATH.'include/functions.inc.php'); |
---|
| 88 | |
---|
| 89 | if (isset($_POST['validate']) and !is_admin()) |
---|
| 90 | { |
---|
| 91 | if (!empty($_POST['use_new_pwd'])) |
---|
| 92 | { |
---|
| 93 | $query = ' |
---|
| 94 | SELECT '.$conf['user_fields']['username'].' AS username |
---|
| 95 | FROM '.USERS_TABLE.' |
---|
| 96 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
---|
| 97 | ;'; |
---|
| 98 | |
---|
| 99 | list($username) = pwg_db_fetch_row(pwg_query($query)); |
---|
| 100 | |
---|
| 101 | PhpBB_Updateuser($user['id'], stripslashes($username), md5($_POST['use_new_pwd']), $_POST['mail_address']); |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | /* Access validation in PhpBB when validated in Piwigo through UAM plugin */ |
---|
| 109 | add_event_handler('login_success', 'UAM_Bridge', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
| 110 | |
---|
| 111 | function UAM_Bridge() |
---|
| 112 | { |
---|
| 113 | global $conf, $user; |
---|
| 114 | |
---|
| 115 | $conf_Register_PhpBB = isset($conf['Register_PhpBB']) ? explode(";" , $conf['Register_PhpBB']) : array(); |
---|
| 116 | |
---|
| 117 | // Check if UAM is installed and if bridge is set - Exception for admins and webmasters |
---|
| 118 | $query =' |
---|
| 119 | SELECT user_id, status |
---|
| 120 | FROM '.USER_INFOS_TABLE.' |
---|
| 121 | WHERE user_id = '.$user['id'].' |
---|
| 122 | ;'; |
---|
| 123 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 124 | |
---|
| 125 | if ($data['status'] <> "admin" and $data['status'] <> "webmaster") |
---|
| 126 | { |
---|
| 127 | if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_PhpBB[5]) and $conf_Register_PhpBB[5] == 'true') |
---|
| 128 | { |
---|
| 129 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 130 | |
---|
| 131 | // Getting unvalidated users group else Piwigo's default group |
---|
| 132 | if (isset($conf_UAM[2]) and $conf_UAM[2] != '-1') |
---|
| 133 | { |
---|
| 134 | $Waitingroup = $conf_UAM[2]; |
---|
| 135 | } |
---|
| 136 | else |
---|
| 137 | { |
---|
| 138 | $query = ' |
---|
| 139 | SELECT id |
---|
| 140 | FROM '.GROUPS_TABLE.' |
---|
| 141 | WHERE is_default = "true" |
---|
| 142 | LIMIT 1 |
---|
| 143 | ;'; |
---|
| 144 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 145 | $Waitingroup = $data['id']; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | // check if logged in user is in a Piwigo's validated or unvalidated users group |
---|
| 149 | $query = ' |
---|
| 150 | SELECT * |
---|
| 151 | FROM '.USER_GROUP_TABLE.' |
---|
| 152 | WHERE user_id = '.$user['id'].' |
---|
| 153 | AND group_id = '.$Waitingroup.' |
---|
| 154 | ;'; |
---|
| 155 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
| 156 | |
---|
| 157 | // Check if logged in user is in a PhpBB's unvalidated group |
---|
| 158 | $query = " |
---|
| 159 | SELECT group_id |
---|
| 160 | FROM ".PhpBB_USERS_TABLE." |
---|
| 161 | WHERE user_id = ".PhpBB_Searchuser($user['id'])." |
---|
| 162 | ;"; |
---|
| 163 | |
---|
| 164 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 165 | |
---|
| 166 | $query = " |
---|
| 167 | SELECT group_id |
---|
| 168 | FROM ".PhpBB_GROUPS_TABLE." |
---|
| 169 | WHERE group_name = '".$conf_Register_PhpBB[6]."' |
---|
| 170 | ;"; |
---|
| 171 | $data1 = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 172 | |
---|
| 173 | // Logged in user switch to the default PhpBB's group if he'is validated |
---|
| 174 | if ($count == 0 and $data['group_id'] != $data1['group_id']) |
---|
| 175 | { |
---|
| 176 | $query = " |
---|
| 177 | SELECT group_id, group_colour |
---|
| 178 | FROM ".PhpBB_GROUPS_TABLE." |
---|
| 179 | WHERE group_name = '".$conf_Register_PhpBB[6]."' |
---|
| 180 | ;"; |
---|
| 181 | $default_user = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 182 | |
---|
| 183 | $query = " |
---|
| 184 | UPDATE ".PhpBB_USERS_TABLE." |
---|
| 185 | SET group_id = '".$default_user['group_id']."', user_colour = '".$default_user['group_colour']."' |
---|
| 186 | WHERE user_id = ".PhpBB_Searchuser($user['id'])." |
---|
| 187 | ;"; |
---|
| 188 | $result = pwg_query($query); |
---|
| 189 | |
---|
| 190 | $query = " |
---|
| 191 | UPDATE ".PhpBB_USERGROUP_TABLE." |
---|
| 192 | SET group_id = '".$default_user['group_id']."' |
---|
| 193 | WHERE user_id = ".PhpBB_Searchuser($user['id'])." |
---|
| 194 | ;"; |
---|
| 195 | $result = pwg_query($query); |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | ?> |
---|