| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: NBC UserAdvManager |
|---|
| 4 | Version: 2.12.7 |
|---|
| 5 | Description: Renforcer les possibilités de gestion des utilisateurs - Enforce users management |
|---|
| 6 | Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=216 |
|---|
| 7 | Author: Nicco, Eric |
|---|
| 8 | Author URI: http://gallery-nicco.no-ip.org, http://www.infernoweb.net |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | /* |
|---|
| 12 | ***** Plugin history (branch 2.10)***** |
|---|
| 13 | |
|---|
| 14 | -- 2.10.0-beta : Initial beta release for Piwigo compatibility |
|---|
| 15 | -- 2.10.1-beta : Small correction on generated path |
|---|
| 16 | -- 2.10.2-beta : Bug resolved on register validation page |
|---|
| 17 | |
|---|
| 18 | -- 2.10.3 : Final and fully functional release |
|---|
| 19 | Bug resolved on plugin activation |
|---|
| 20 | |
|---|
| 21 | -- 2.10.4 : Bug fixed on profiles update |
|---|
| 22 | |
|---|
| 23 | -- 2.10.5 : Improved code on profiles update |
|---|
| 24 | |
|---|
| 25 | -- 2.10.6 : Old language packs (iso) deleted (forget from PWG 1.7.x version) |
|---|
| 26 | |
|---|
| 27 | -- 2.10.7 : Bug fixed on user's validation email sending |
|---|
| 28 | |
|---|
| 29 | -- 2.10.8 : ConfirmMail page looks better (Sylvia theme only) |
|---|
| 30 | Improved code for checking author on guest comments |
|---|
| 31 | |
|---|
| 32 | -- 2.10.9 : Bug fixed - Missing english translation |
|---|
| 33 | Bug fixed - Notice on forbidden characters function use |
|---|
| 34 | Bug fixed - Audit on forbidden characters in username didn't work |
|---|
| 35 | Adding of email provider exclusion (like *@hotmail.com) - Warning ! -> Known bug : This feature doesn't work on user profile page. So, already registered users can change their email address to a forbiden one. |
|---|
| 36 | |
|---|
| 37 | -- 2.10.9a : Email provider exclusion is no longer case sensitive |
|---|
| 38 | |
|---|
| 39 | -- 2.10.9b : Bug fixed - Home icon wasn't linked to gallery url in ConfirmMail page. If GALLERY_URL is not set, Home icon gets the pwg root path. |
|---|
| 40 | |
|---|
| 41 | -- 2.10.9c : Bug fixed - If Email provider exclusion is set off, new registered user will have a PHP notice on "Undefined variable: ncsemail" |
|---|
| 42 | |
|---|
| 43 | -- 2.10.9d : Code simplification - need no more ""template"" sub-directory in plugin directory for enhance "back link" icon in ConfirMail.tpl |
|---|
| 44 | |
|---|
| 45 | -- 2.10.9e : Compatibility improvement with PHP 5.3 - Some old functions will be deprecated like : |
|---|
| 46 | ereg replaced by preg_match |
|---|
| 47 | eregi replace by preg_match with "i" moderator |
|---|
| 48 | split replace by preg_split |
|---|
| 49 | |
|---|
| 50 | -- 2.10.9f : Compatibility bug fixed when used with DynamicRecentPeriod plugin |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | ***** Plugin history (branch 2.11)***** |
|---|
| 54 | |
|---|
| 55 | -- 2.11.0 : New tabsheet menu to manage ConfirMail functions (setting a timeout without validation, Cleanup expired user's accounts, Force confirmation, Renew validation key, list unvalidated users,...) |
|---|
| 56 | Beautify plugin's main admin panel |
|---|
| 57 | |
|---|
| 58 | -- 2.11.1 : Bug fixed with install and upgrade functions |
|---|
| 59 | Language files correction |
|---|
| 60 | |
|---|
| 61 | -- 2.11.2 : Bug fixed on bad query for unvalidated users display in unvalidated users list |
|---|
| 62 | Bug fixed : Sql syntax error on plugin activation |
|---|
| 63 | |
|---|
| 64 | -- 2.11.3 : On Patricia's request (french forum and bug 1173), the unvalidated users management tab shows users according with the settings of unvalidated group and / or unvalidated status. |
|---|
| 65 | Feature 1172 added : Email providers exclusion list can be set with CR/LF between each entry. The comma seperator (,) is still mandatory. |
|---|
| 66 | Bug 1175 fixed : Bad translation tag in french language file. |
|---|
| 67 | Improvement of unvalidated users management tab (feature 1174)- Expired users are displayed in red color text. |
|---|
| 68 | |
|---|
| 69 | -- 2.11.4 : Bug 1177 fixed : Width of excluded email providers list reset to ancient value (80 col) |
|---|
| 70 | Bug 1179 fixed : Adding a notice in plugin inline documentation for use of validation groups and status. A default group must be set in Piwigo's groups settings and the "Guest" (or another user) must be set as default for status values. |
|---|
| 71 | Bug 1182 fixed : Language tag missing in confirmation email generation |
|---|
| 72 | |
|---|
| 73 | -- 2.11.5 : Bug 1195 fixed : Registration displays the good title |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | ***** Plugin history (branch 2.12)***** |
|---|
| 77 | |
|---|
| 78 | -- 2.12.0 : Bug 1206 fixed : All plugin functionnalities work in user's profile page |
|---|
| 79 | Plugin's core code and admin panel refactoring |
|---|
| 80 | Password control and enforcement : A complexity score is computed on user registration. If this score is less than the goal set by admin, the password choosen is rejected. |
|---|
| 81 | Feature 1194 "Ghost Tracker" added : New plugin tab displays users who don't comes back to the gallery since x days. Ability to send email reminders and to delete reminded but "dead" users. It's the reason why this feature is called "Ghost Tracker". |
|---|
| 82 | |
|---|
| 83 | -- 2.12.1 : Rollback on admin panel improvement (it was a bad idea) |
|---|
| 84 | |
|---|
| 85 | -- 2.12.2 : Bug 1221 fixed - Adding of a new funtion to populate the lastvisit table on Ghost Tracker activation |
|---|
| 86 | Bug 1224 fixed - Error in database after plugin activation |
|---|
| 87 | Bug 1225 fixed - "Reminder" status don't change from "false" to "true" after the sent of a reminder email |
|---|
| 88 | Some code beautify (SQL requests and HTML 4 strict for tpl) |
|---|
| 89 | |
|---|
| 90 | -- 2.12.3 : Bug 1226 fixed - "duplicate key error" when lastvisit table is not empty and on using Ghost Tracker init function |
|---|
| 91 | |
|---|
| 92 | -- 2.12.4 : Adding a password field control for SendMail2User - Neighborhood plugin compatibility improvement |
|---|
| 93 | Bug 1229 fixed - Email was no longer mandatory when plugin was active, even if Piwigo's email madatory option was set. |
|---|
| 94 | |
|---|
| 95 | -- 2.12.5 : Bug 1233 fixed - "duplicate key error" when a user wants to register with an existing username. In fact, all standard Piwigo's register controls didn't work when plugin was activated. That fixes this too. |
|---|
| 96 | Adding DE, ES and IT languages. All translations are not finalized and could be improved. |
|---|
| 97 | Adding of description.txt file in language directories. |
|---|
| 98 | |
|---|
| 99 | -- 2.12.6 : Bug 1236 fixed - Admins was unable to add a new user in the user_list page. |
|---|
| 100 | Beginning of IT translations |
|---|
| 101 | |
|---|
| 102 | -- 2.12.7 : Bug 1238 fixed - Simple custom email text wasn't send when Extended Description plugin wasn't set |
|---|
| 103 | Bug 1245 fixed - Semicolons (;) are no longer allowed in text areas (mail info text, ConfirmMail text, reminder text,...). They'll be replaced by dots (.). |
|---|
| 104 | Bug 1248 fixed - Php notice on user registration with a forbidden email domain |
|---|
| 105 | Bug 1250 fixed - Email provider didn't work after the third exclusion in list |
|---|
| 106 | Escaping all special characters typed in login name and recover them |
|---|
| 107 | */ |
|---|
| 108 | |
|---|
| 109 | /* |
|---|
| 110 | |
|---|
| 111 | ***** TODO List ***** |
|---|
| 112 | ++ No validation needed for admins users comments (new trigger needed in comments.php ?) |
|---|
| 113 | |
|---|
| 114 | ++ No single email check for admins (new trigger needed in functions_user.inc.php ?) |
|---|
| 115 | |
|---|
| 116 | ++ Password control and enforcement |
|---|
| 117 | ?? Can not be the same as username -> Could password score control be sufficient ? |
|---|
| 118 | |
|---|
| 119 | ++ Security : Blocking brut-force attacks ! |
|---|
| 120 | -> Way to do that : Count the number of failed attempts to connect and lock the targetted account after x attempts. Where x will be settable by admin. |
|---|
| 121 | To unlock the locked account : |
|---|
| 122 | -> A new table in admin's plugin panel which would display the locked accounts. |
|---|
| 123 | -> Sending an email to account owner to inform him his account is blocked due to multiple failed connexions attempts. This email could have a link with a security key to unlock the account. |
|---|
| 124 | -> Both of above solutions ? |
|---|
| 125 | |
|---|
| 126 | ++ Opportunity to copy a registered user for new user creation |
|---|
| 127 | ++ new copied user will (or not) belong to the same groups |
|---|
| 128 | ++ new copied user will (or not) get the same status (visitor, admin, webmaster, guest (??)) |
|---|
| 129 | ++ new copied user will (or not) get the same properties |
|---|
| 130 | ++ new copied user will (or not) get the same language |
|---|
| 131 | ... and so on |
|---|
| 132 | |
|---|
| 133 | */ |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | if (!defined('PHPWG_ROOT_PATH')) |
|---|
| 137 | { |
|---|
| 138 | die('Hacking attempt!'); |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | define('NBC_UserAdvManager_DIR' , basename(dirname(__FILE__))); |
|---|
| 142 | define('NBC_UserAdvManager_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
|---|
| 143 | |
|---|
| 144 | include_once (NBC_UserAdvManager_PATH.'include/constants.php'); |
|---|
| 145 | include_once (NBC_UserAdvManager_PATH.'include/functions_UserAdvManager.inc.php'); |
|---|
| 146 | |
|---|
| 147 | load_language('plugin.lang', NBC_UserAdvManager_PATH); |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | /* Plugin admin */ |
|---|
| 151 | add_event_handler('get_admin_plugin_menu_links', 'nbc_UserAdvManager_admin_menu'); |
|---|
| 152 | |
|---|
| 153 | function nbc_UserAdvManager_admin_menu($menu) |
|---|
| 154 | { |
|---|
| 155 | array_push($menu, |
|---|
| 156 | array( |
|---|
| 157 | 'NAME' => 'UserAdvManager', |
|---|
| 158 | 'URL' => get_admin_plugin_menu_link(NBC_UserAdvManager_PATH.'/admin/UserAdvManager_admin.php') |
|---|
| 159 | ) |
|---|
| 160 | ); |
|---|
| 161 | |
|---|
| 162 | return $menu; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | add_event_handler('loc_begin_index', 'UserAdvManager_GhostTracker'); |
|---|
| 167 | |
|---|
| 168 | function UserAdvManager_GhostTracker() |
|---|
| 169 | { |
|---|
| 170 | global $conf, $user; |
|---|
| 171 | |
|---|
| 172 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
|---|
| 173 | |
|---|
| 174 | if (isset($conf_nbc_UserAdvManager[17]) and $conf_nbc_UserAdvManager[17] == 'true' and !is_admin() and !is_a_guest()) |
|---|
| 175 | { |
|---|
| 176 | |
|---|
| 177 | $userid = get_userid($user['username']); |
|---|
| 178 | |
|---|
| 179 | /* Looking for existing entry in last visit table */ |
|---|
| 180 | $query = ' |
|---|
| 181 | SELECT * |
|---|
| 182 | FROM '.USER_LASTVISIT_TABLE.' |
|---|
| 183 | WHERE user_id = '.$userid.' |
|---|
| 184 | ;'; |
|---|
| 185 | |
|---|
| 186 | $count = mysql_num_rows(pwg_query($query)); |
|---|
| 187 | |
|---|
| 188 | if ($count == 0) |
|---|
| 189 | { |
|---|
| 190 | /* If not, data are inserted in table */ |
|---|
| 191 | $query = ' |
|---|
| 192 | INSERT INTO '.USER_LASTVISIT_TABLE.' (user_id, lastvisit, reminder) |
|---|
| 193 | VALUES ('.$userid.', now(), "false") |
|---|
| 194 | ;'; |
|---|
| 195 | pwg_query($query); |
|---|
| 196 | } |
|---|
| 197 | else if ($count > 0) |
|---|
| 198 | { |
|---|
| 199 | /* If yes, data are updated in table */ |
|---|
| 200 | $query = ' |
|---|
| 201 | UPDATE '.USER_LASTVISIT_TABLE.' |
|---|
| 202 | SET lastvisit = now(), reminder = "false" |
|---|
| 203 | WHERE user_id = '.$userid.' |
|---|
| 204 | LIMIT 1 |
|---|
| 205 | ;'; |
|---|
| 206 | pwg_query($query); |
|---|
| 207 | } |
|---|
| 208 | } |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | /* User creation */ |
|---|
| 213 | add_event_handler('register_user', 'UserAdvManager_Adduser'); |
|---|
| 214 | |
|---|
| 215 | function UserAdvManager_Adduser($register_user) |
|---|
| 216 | { |
|---|
| 217 | global $conf; |
|---|
| 218 | |
|---|
| 219 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
|---|
| 220 | |
|---|
| 221 | /* Sending registration confirmation by email */ |
|---|
| 222 | if ((isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or (isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true')) |
|---|
| 223 | { |
|---|
| 224 | $passwd = (isset($_POST['password'])) ? $_POST['password'] : ''; |
|---|
| 225 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); |
|---|
| 226 | } |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | /* User deletion */ |
|---|
| 232 | add_event_handler('delete_user', 'UserAdvManager_Deluser'); |
|---|
| 233 | |
|---|
| 234 | function UserAdvManager_Deluser($user_id) |
|---|
| 235 | { |
|---|
| 236 | /* Cleanup for ConfirmMail table */ |
|---|
| 237 | DeleteConfirmMail($user_id); |
|---|
| 238 | /* Cleanup for LastVisit table */ |
|---|
| 239 | DeleteLastVisit($user_id); |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | /* Check users registration */ |
|---|
| 244 | add_event_handler('register_user_check', 'UserAdvManager_RegistrationCheck', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
|---|
| 245 | |
|---|
| 246 | function UserAdvManager_RegistrationCheck($err, $user) |
|---|
| 247 | { |
|---|
| 248 | global $errors, $conf; |
|---|
| 249 | |
|---|
| 250 | /* *********************************************************** */ |
|---|
| 251 | /* We need to reset the standard Piwigo's register controls */ |
|---|
| 252 | /* because the call of register_user_check trigger resets them */ |
|---|
| 253 | /* *********************************************************** */ |
|---|
| 254 | /* ********************************** */ |
|---|
| 255 | /* Standard Piwigo's username control */ |
|---|
| 256 | /* ********************************** */ |
|---|
| 257 | if ($_POST['login'] == '') |
|---|
| 258 | { |
|---|
| 259 | return l10n('reg_err_login1'); |
|---|
| 260 | } |
|---|
| 261 | if (preg_match('/^.* $/', $_POST['login'])) |
|---|
| 262 | { |
|---|
| 263 | return l10n('reg_err_login2'); |
|---|
| 264 | } |
|---|
| 265 | if (preg_match('/^ .*$/', $_POST['login'])) |
|---|
| 266 | { |
|---|
| 267 | return l10n('reg_err_login3'); |
|---|
| 268 | } |
|---|
| 269 | if (get_userid($_POST['login'])) |
|---|
| 270 | { |
|---|
| 271 | return l10n('reg_err_login5'); |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list') /* not the same email variable if we are on users registration page or on admin's user registration page*/ |
|---|
| 275 | { |
|---|
| 276 | /* ***************************** */ |
|---|
| 277 | /* Standard Piwigo's email check */ |
|---|
| 278 | /* ***************************** */ |
|---|
| 279 | $atom = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]'; // before arobase |
|---|
| 280 | $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name |
|---|
| 281 | $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i'; |
|---|
| 282 | |
|---|
| 283 | if (!preg_match($regex, $_POST['email'])) |
|---|
| 284 | { |
|---|
| 285 | return l10n('reg_err_mail_address'); |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | if (!empty($_POST['email'])) |
|---|
| 289 | { |
|---|
| 290 | $query = ' |
|---|
| 291 | select count(*) |
|---|
| 292 | from '.USERS_TABLE.' |
|---|
| 293 | where upper('.$conf['user_fields']['email'].') = upper(\''.$_POST['email'].'\');'; |
|---|
| 294 | list($count) = mysql_fetch_assoc(pwg_query($query)); |
|---|
| 295 | if ($count != 0) |
|---|
| 296 | { |
|---|
| 297 | return l10n('reg_err_mail_address_dbl'); |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | } |
|---|
| 301 | /* ****************************************** */ |
|---|
| 302 | /* End of Piwigo's standard register controls */ |
|---|
| 303 | /* ****************************************** */ |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | /* ****************************************** */ |
|---|
| 307 | /* Here begins the advanced register controls */ |
|---|
| 308 | /* ****************************************** */ |
|---|
| 309 | $PasswordCheck = 0; |
|---|
| 310 | |
|---|
| 311 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
|---|
| 312 | |
|---|
| 313 | /* Password enforcement control */ |
|---|
| 314 | if (isset($conf_nbc_UserAdvManager[14]) and $conf_nbc_UserAdvManager[14] == 'true' and !empty($conf_nbc_UserAdvManager[15])) |
|---|
| 315 | { |
|---|
| 316 | if (!empty($user['password']) and !is_admin()) |
|---|
| 317 | { |
|---|
| 318 | $PasswordCheck = testpassword($user['password']); |
|---|
| 319 | |
|---|
| 320 | if ($PasswordCheck < $conf_nbc_UserAdvManager[15]) |
|---|
| 321 | { |
|---|
| 322 | $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck); |
|---|
| 323 | return($lang['reg_err_pass'] = l10n_args($message).$conf_nbc_UserAdvManager[15]); |
|---|
| 324 | } |
|---|
| 325 | } |
|---|
| 326 | else if (!empty($user['password']) and is_admin() and isset($conf_nbc_UserAdvManager[16]) and $conf_nbc_UserAdvManager[16] == 'true') |
|---|
| 327 | { |
|---|
| 328 | $PasswordCheck = testpassword($user['password']); |
|---|
| 329 | |
|---|
| 330 | if ($PasswordCheck < $conf_nbc_UserAdvManager[15]) |
|---|
| 331 | { |
|---|
| 332 | $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck); |
|---|
| 333 | return($lang['reg_err_pass'] = l10n_args($message).$conf_nbc_UserAdvManager[15]); |
|---|
| 334 | } |
|---|
| 335 | } |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | /* Username non case sensitive */ |
|---|
| 339 | if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true') |
|---|
| 340 | { |
|---|
| 341 | $new_username = NotSensibleSearchUsername($_POST['login']); |
|---|
| 342 | $_POST['login'] = $new_username == '' ? $_POST['login'] : $new_username; |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | /* Username without forbidden keys */ |
|---|
| 346 | if (isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' and !empty($_POST['login']) and !ValidateUsername($_POST['login'])) |
|---|
| 347 | { |
|---|
| 348 | $_POST['login'] = ''; |
|---|
| 349 | return($lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_nbc_UserAdvManager[8]."'"); |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | /* Email without forbidden domains */ |
|---|
| 353 | /* This doesn't work */ |
|---|
| 354 | // if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address']) and !ValidateEmailProvider($_POST['mail_address'])) |
|---|
| 355 | // { |
|---|
| 356 | // $_POST['mail_address'] = ''; |
|---|
| 357 | // return($lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'"); |
|---|
| 358 | // } |
|---|
| 359 | /* This work with a code copy of ValidateEmailProvider() function */ |
|---|
| 360 | if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address'])) |
|---|
| 361 | { |
|---|
| 362 | $ncsemail = strtolower($_POST['mail_address']); |
|---|
| 363 | $conf_nbc_MailExclusion = preg_split("/[\s,]+/",$conf_nbc_UserAdvManager[13]); |
|---|
| 364 | for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++) |
|---|
| 365 | { |
|---|
| 366 | $pattern = '/'.$conf_nbc_MailExclusion[$i].'/'; |
|---|
| 367 | if (preg_match($pattern, $ncsemail)) |
|---|
| 368 | { |
|---|
| 369 | $_POST['mail_address'] = ''; |
|---|
| 370 | return($lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'"); |
|---|
| 371 | } |
|---|
| 372 | } |
|---|
| 373 | } |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | |
|---|
| 377 | if (script_basename() == 'profile') |
|---|
| 378 | { |
|---|
| 379 | add_event_handler('loc_begin_profile', 'UserAdvManager_Profile_Init'); |
|---|
| 380 | |
|---|
| 381 | function UserAdvManager_Profile_Init() |
|---|
| 382 | { |
|---|
| 383 | global $conf, $user, $template; |
|---|
| 384 | |
|---|
| 385 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
|---|
| 386 | |
|---|
| 387 | if (isset($_POST['validate'])) |
|---|
| 388 | { |
|---|
| 389 | /* Email without forbidden domains */ |
|---|
| 390 | /* This doesn't work */ |
|---|
| 391 | // if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address'])) |
|---|
| 392 | // { |
|---|
| 393 | // if (!ValidateEmailProvider($_POST['mail_address'])) |
|---|
| 394 | // { |
|---|
| 395 | // $template->append('errors', l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'"); |
|---|
| 396 | // unset($_POST['validate']); |
|---|
| 397 | // } |
|---|
| 398 | // } |
|---|
| 399 | /* This work with a code copy of ValidateEmailProvider() function */ |
|---|
| 400 | if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['mail_address'])) |
|---|
| 401 | { |
|---|
| 402 | $ncsemail = strtolower($_POST['mail_address']); |
|---|
| 403 | $conf_nbc_MailExclusion = preg_split("/[\s,]+/",$conf_nbc_UserAdvManager[13]); |
|---|
| 404 | for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++) |
|---|
| 405 | { |
|---|
| 406 | $pattern = '/'.$conf_nbc_MailExclusion[$i].'/'; |
|---|
| 407 | if (preg_match($pattern, $ncsemail)) |
|---|
| 408 | { |
|---|
| 409 | $template->append('errors', l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'"); |
|---|
| 410 | unset($_POST['validate']); |
|---|
| 411 | } |
|---|
| 412 | } |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | $typemail = 3; |
|---|
| 416 | |
|---|
| 417 | if (!empty($_POST['use_new_pwd'])) |
|---|
| 418 | { |
|---|
| 419 | $typemail = 2; |
|---|
| 420 | |
|---|
| 421 | /* Password enforcement control */ |
|---|
| 422 | if (isset($conf_nbc_UserAdvManager[14]) and $conf_nbc_UserAdvManager[14] == 'true' and !empty($conf_nbc_UserAdvManager[15])) |
|---|
| 423 | { |
|---|
| 424 | $PasswordCheck = testpassword($_POST['use_new_pwd']); |
|---|
| 425 | |
|---|
| 426 | if ($PasswordCheck < $conf_nbc_UserAdvManager[15]) |
|---|
| 427 | { |
|---|
| 428 | $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck); |
|---|
| 429 | $template->append('errors', l10n_args($message).$conf_nbc_UserAdvManager[15]); |
|---|
| 430 | unset($_POST['use_new_pwd']); |
|---|
| 431 | unset($_POST['validate']); |
|---|
| 432 | } |
|---|
| 433 | } |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | /* Sending registration confirmation by email */ |
|---|
| 437 | if ((isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or (isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true')) |
|---|
| 438 | { |
|---|
| 439 | $confirm_mail_need = false; |
|---|
| 440 | |
|---|
| 441 | if (!empty($_POST['mail_address'])) |
|---|
| 442 | { |
|---|
| 443 | $query = ' |
|---|
| 444 | SELECT '.$conf['user_fields']['email'].' AS email |
|---|
| 445 | FROM '.USERS_TABLE.' |
|---|
| 446 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
|---|
| 447 | ;'; |
|---|
| 448 | |
|---|
| 449 | list($current_email) = mysql_fetch_row(pwg_query($query)); |
|---|
| 450 | |
|---|
| 451 | if ($_POST['mail_address'] != $current_email and ( isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2] == 'true')) |
|---|
| 452 | |
|---|
| 453 | $confirm_mail_need = true; |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | if ((!empty($_POST['use_new_pwd']) and (isset($conf_nbc_UserAdvManager[0]) and $conf_nbc_UserAdvManager[0] == 'true') or $confirm_mail_need)) |
|---|
| 457 | { |
|---|
| 458 | $query = ' |
|---|
| 459 | SELECT '.$conf['user_fields']['username'].' |
|---|
| 460 | FROM '.USERS_TABLE.' |
|---|
| 461 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
|---|
| 462 | ;'; |
|---|
| 463 | |
|---|
| 464 | list($username) = mysql_fetch_row(pwg_query($query)); |
|---|
| 465 | |
|---|
| 466 | SendMail2User($typemail, $user['id'], $username, $_POST['use_new_pwd'], $_POST['mail_address'], $confirm_mail_need); |
|---|
| 467 | } |
|---|
| 468 | } |
|---|
| 469 | } |
|---|
| 470 | } |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | |
|---|
| 474 | add_event_handler('init', 'UserAdvManager_InitPage'); |
|---|
| 475 | |
|---|
| 476 | function UserAdvManager_InitPage() |
|---|
| 477 | { |
|---|
| 478 | load_language('plugin.lang', NBC_UserAdvManager_PATH); |
|---|
| 479 | global $conf, $template, $page, $lang, $errors; |
|---|
| 480 | |
|---|
| 481 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
|---|
| 482 | |
|---|
| 483 | /* Username non case sensitive */ |
|---|
| 484 | if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true') |
|---|
| 485 | { |
|---|
| 486 | $lang['reg_err_login5'] = l10n('reg_err_login5'); |
|---|
| 487 | } |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | |
|---|
| 491 | /* User identification */ |
|---|
| 492 | if (script_basename() == 'identification') |
|---|
| 493 | { |
|---|
| 494 | if (isset($_POST['login'])) |
|---|
| 495 | { |
|---|
| 496 | /* User non case sensitive */ |
|---|
| 497 | if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' ) |
|---|
| 498 | { |
|---|
| 499 | $new_username = NotSensibleSearchUsername($_POST['username']); |
|---|
| 500 | $_POST['username'] = $new_username == '' ? $_POST['username'] : $new_username; |
|---|
| 501 | } |
|---|
| 502 | } |
|---|
| 503 | } |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | /* Admin user management */ |
|---|
| 507 | if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list') |
|---|
| 508 | { |
|---|
| 509 | if (isset($_POST['submit_add'])) |
|---|
| 510 | { |
|---|
| 511 | /* User non case sensitive */ |
|---|
| 512 | if (isset($conf_nbc_UserAdvManager[1]) and $conf_nbc_UserAdvManager[1] == 'true' ) |
|---|
| 513 | { |
|---|
| 514 | $new_username = NotSensibleSearchUsername($_POST['login']); |
|---|
| 515 | $_POST['login'] = $new_username == '' ? $_POST['login'] : $new_username; |
|---|
| 516 | } |
|---|
| 517 | |
|---|
| 518 | /* Username without forbidden keys */ |
|---|
| 519 | if (isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' and !empty($_POST['login']) and !ValidateUsername($_POST['login'])) |
|---|
| 520 | { |
|---|
| 521 | $template->append('errors', l10n('reg_err_login6')."'".$conf_nbc_UserAdvManager[8]."'"); |
|---|
| 522 | unset($_POST['submit_add']); |
|---|
| 523 | } |
|---|
| 524 | |
|---|
| 525 | /* Email without forbidden domains */ |
|---|
| 526 | /* This doesn't work */ |
|---|
| 527 | // if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['email']) and !ValidateEmailProvider($_POST['email'])) |
|---|
| 528 | // { |
|---|
| 529 | // $template->append('errors', l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'"); |
|---|
| 530 | // unset($_POST['submit_add']); |
|---|
| 531 | // } |
|---|
| 532 | /* This work with a code copy of ValidateEmailProvider() function */ |
|---|
| 533 | if (isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' and !empty($_POST['email'])) |
|---|
| 534 | { |
|---|
| 535 | $ncsemail = strtolower($_POST['email']); |
|---|
| 536 | $conf_nbc_MailExclusion = preg_split("/[\s,]+/",$conf_nbc_UserAdvManager[13]); |
|---|
| 537 | for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++) |
|---|
| 538 | { |
|---|
| 539 | $pattern = '/'.$conf_nbc_MailExclusion[$i].'/'; |
|---|
| 540 | if (preg_match($pattern, $ncsemail)) |
|---|
| 541 | { |
|---|
| 542 | $template->append('errors', l10n('reg_err_login7')."'".$conf_nbc_UserAdvManager[13]."'"); |
|---|
| 543 | unset($_POST['submit_add']); |
|---|
| 544 | } |
|---|
| 545 | } |
|---|
| 546 | } |
|---|
| 547 | } |
|---|
| 548 | } |
|---|
| 549 | } |
|---|
| 550 | |
|---|
| 551 | |
|---|
| 552 | add_event_handler('user_comment_check', 'UserAdvManager_CheckEmptyCommentAuthor', 50, 2); |
|---|
| 553 | |
|---|
| 554 | function UserAdvManager_CheckEmptyCommentAuthor($comment_action, $comm) |
|---|
| 555 | { |
|---|
| 556 | load_language('plugin.lang', NBC_UserAdvManager_PATH); |
|---|
| 557 | global $infos, $conf, $template; |
|---|
| 558 | |
|---|
| 559 | $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
|---|
| 560 | |
|---|
| 561 | /* User creation OR update */ |
|---|
| 562 | if (isset($conf_nbc_UserAdvManager[6]) and $conf_nbc_UserAdvManager[6] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest') |
|---|
| 563 | { |
|---|
| 564 | $comment_action = 'reject'; |
|---|
| 565 | |
|---|
| 566 | array_push($infos, l10n('UserAdvManager_Empty Author')); |
|---|
| 567 | } |
|---|
| 568 | |
|---|
| 569 | return $comment_action; |
|---|
| 570 | } |
|---|
| 571 | |
|---|
| 572 | ?> |
|---|