Ignore:
Timestamp:
Apr 9, 2013, 6:17:32 PM (12 years ago)
Author:
Eric
Message:

Rebuild version 2.5.6 due to last commit corruption

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Register_FluxBB/include/functions.inc.php

    r22039 r22091  
    1515}
    1616
    17 /**
    18  * Add new registered user in FluxBB user table
    19  */
    20 function Register_FluxBB_Adduser($register_user)
    21 {
    22   global $errors, $conf;
    23        
    24   // Exclusion of Adult_Content users
    25   if ($register_user['username'] != "16" and $register_user['username'] != "18")
    26   {
    27     // Warning : FluxBB uses Sha1 hash instead of a salted md5 for Piwigo! // TODO: Reset password
    28     FluxBB_Adduser($register_user['id'], $register_user['username'], sha1($_POST['password']), $register_user['email']);
    29   }
    30 }
    31 
    32 /**
    33  * Delete registered user in FluxBB user table
    34  */
    35 function Register_FluxBB_Deluser($user_id)
    36 {
    37   FluxBB_Deluser(FluxBB_Searchuser($user_id), true);
    38 }
    3917
    4018/**
    4119 * Change user's password in FluxBB user table if a new password is set in Piwigo
    42  */
    43 function Register_FluxBB_InitPage()
    44 {
    45   global $conf, $user;
     20 * or an account synchronization was set
     21 */
     22function Register_FluxBB_InitProfile()
     23{
     24  global $template, $conf, $user;
     25
     26  if (Reg_FluxBB_PwdSynch($user['id']))
     27  {
     28    $template->append('errors', l10n('RegFluxBB_Password_Reset_Msg'));
     29  }
    4630
    4731  if (isset($_POST['validate']))
     
    5741
    5842      list($username) = pwg_db_fetch_row(pwg_query($query));
    59       // Warning : FluxBB uses Sha1 hash instead of a salted md5 for Piwigo! // TODO: Reset password
    6043      FluxBB_Updateuser($user['id'], stripslashes($username), sha1($_POST['use_new_pwd']), $_POST['mail_address']);
    6144    }
    6245  }
     46}
     47
     48
     49/**
     50 * Triggered on login_success
     51 *
     52 * Redirect user to profile page and displays a message to make him change his password for synch with FluxBB
     53 *
     54 */
     55function Register_FluxBB_Login()
     56{
     57  global $conf, $user;
     58
     59    if (Reg_FluxBB_PwdSynch($user['id']))
     60    {
     61      redirect(PHPWG_ROOT_PATH.'profile.php');
     62    }
     63}
     64
     65
     66/**
     67 * Checks special users exclusion befaore add new registered user in FluxBB user table
     68 */
     69function Register_FluxBB_Adduser($register_user)
     70{
     71  global $errors, $conf;
     72       
     73  // Exclusion of Adult_Content users
     74  if ($register_user['username'] != "16" and $register_user['username'] != "18")
     75  {
     76    FluxBB_Adduser($register_user['id'], $register_user['username'], sha1($_POST['password']), $register_user['email']);
     77  }
     78}
     79
     80/**
     81 * Delete registered user in FluxBB user table
     82 */
     83function Register_FluxBB_Deluser($user_id)
     84{
     85  FluxBB_Deluser(FluxBB_Searchuser($user_id), true);
    6386}
    6487
     
    85108
    86109      list($username,$mail_address) = pwg_db_fetch_row(pwg_query($query));
    87       // Warning : FluxBB uses Sha1 hash instead of a salted md5 for Piwigo! // TODO: Reset password
    88110      FluxBB_Updateuser($user_id, stripslashes($username), sha1($_POST['use_new_pwd']), $mail_address);
    89111    }
     
    199221 * Users linking in a dedicated links table
    200222 */
    201 function FluxBB_Linkuser($pwg_id, $bb_id)
    202 {
     223function FluxBB_Linkuser($pwg_id, $bb_id, $PwdSync)
     224{
     225  global $conf;
     226
     227  $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']);
     228
    203229  $query = '
    204230SELECT pwg.id as pwg_id, bb.id as bb_id
     
    209235  AND pwg.username NOT IN ("18","16")
    210236;';
    211  
     237
    212238  $data = pwg_db_fetch_row(pwg_query($query));
    213  
    214   if (!empty($data))
     239
     240  if (!empty($data) and !is_null($PwdSync))
    215241  {
    216242    $subquery = '
     
    220246;';
    221247
    222     $subresult = pwg_query($subquery);
     248    pwg_query($subquery);
    223249
    224250    $subquery = '
    225251INSERT INTO '.Register_FluxBB_ID_TABLE.'
    226   (id_user_pwg, id_user_FluxBB)
    227 VALUES ('.$pwg_id.', '.$bb_id.')
    228 ;';
    229 
    230     $subresult = pwg_query($subquery);
     252  (id_user_pwg, id_user_FluxBB, PwdSynch)
     253VALUES ('.$pwg_id.', '.$bb_id.', "'.$PwdSync.'")
     254;';
     255
     256    pwg_query($subquery);
     257  }
     258  else
     259  {
     260    $PwdSync = NULL;
     261    $subquery = '
     262DELETE FROM '.Register_FluxBB_ID_TABLE.'
     263WHERE id_user_pwg = "'.$pwg_id.'"
     264OR id_user_FluxBB = "'.$bb_id.'"
     265;';
     266
     267    pwg_query($subquery);
     268
     269    $subquery = '
     270INSERT INTO '.Register_FluxBB_ID_TABLE.'
     271  (id_user_pwg, id_user_FluxBB, PwdSynch)
     272VALUES ('.$pwg_id.', '.$bb_id.', "'.$PwdSync.'")
     273;';
     274
     275    pwg_query($subquery);
    231276  }
    232277}
     
    243288;';
    244289
    245   $result = pwg_query($query);
     290  pwg_query($query);
    246291}
    247292
     
    259304  $registred = time();
    260305  $registred_ip = $_SERVER['REMOTE_ADDR'];
    261  
    262   // Check if UAM is installed and if bridge is set - Exception for admins and webmasters
     306
     307  // Set default FluxBB group - Check if UAM is installed and if bridge is set
    263308  if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB['FLUXBB_UAM_LINK']) and $conf_Register_FluxBB['FLUXBB_UAM_LINK'] == 'true')
    264309  {
     
    276321  }
    277322
    278 // Check for FluxBB version 1.4.x or higher and get the correct value
     323// Check for timezone settings in FluxBB version 1.4.x or higher
    279324  $query1 = '
    280325SELECT conf_value
     
    285330  $count1 = pwg_db_num_rows(pwg_query($query1));
    286331
    287 // Check for FluxBB version 1.2.x and get the correct value
     332// Check for timezone settings in FluxBB version 1.2.x
    288333  $query2 = '
    289334SELECT conf_value
     
    293338
    294339  $count2 = pwg_db_num_rows(pwg_query($query2));
    295  
     340
     341// Set timezone var according of FluxBB version
    296342  if ($count1 == 1 and $count2 == 0)
    297343  {
     
    302348    $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query2));
    303349  }
    304  
    305  
     350
     351// Get FluxBB default language
    306352  $query = '
    307353SELECT conf_value
     
    311357
    312358  $o_default_lang = pwg_db_fetch_assoc(pwg_query($query));
    313  
     359
     360// Get FluxBB default style
    314361  $query = '
    315362SELECT conf_value
     
    320367  $o_default_style = pwg_db_fetch_assoc(pwg_query($query));
    321368
    322   // Check if UAM is installed and if bridge is set - Exception for admins and webmasters
     369  // Add user - Check if UAM is installed and if bridge is set
    323370  if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB['FLUXBB_UAM_LINK']) and $conf_Register_FluxBB['FLUXBB_UAM_LINK'] == 'true')
    324371  {
     
    349396  );";
    350397 
    351     $result = pwg_query($query);
     398    pwg_query($query);
    352399  }
    353400  else
     
    379426  )
    380427;";
    381     $result = pwg_query($query);
     428    pwg_query($query);
    382429  }
    383430
    384431  $bb_id = pwg_db_insert_id();
    385  
    386   FluxBB_Linkuser($pwg_id, $bb_id);
    387 }
    388 
    389 
    390 /**
    391  * Search linked users
    392  */
    393 function FluxBB_Searchuser($id_user_pwg)
    394 {
    395   $query = '
    396 SELECT id_user_FluxBB, id_user_pwg
    397 FROM '.Register_FluxBB_ID_TABLE.'
    398 WHERE id_user_pwg = '.$id_user_pwg.'
    399 LIMIT 1
    400 ;';
    401 
    402   $data = pwg_db_fetch_assoc(pwg_query($query));
    403  
    404   if (!empty($data))
    405     return $data['id_user_FluxBB'];
    406   else
    407     return '0'; 
    408 }
    409 
    410 
    411 /**
    412  * Delete user from FluxBB users table
    413  * Called from Register_FluxBB_Deluser()
    414  */
    415 function FluxBB_Deluser($id_user_FluxBB, $SuppTopicsPosts)
     432
     433  FluxBB_Linkuser($pwg_id, $bb_id, "OK");
     434}
     435
     436
     437/**
     438 * Update user information in FluxBB users table
     439 */
     440function FluxBB_Updateuser($pwg_id, $username, $password, $adresse_mail)
    416441{
    417442  global $conf;
    418 
     443 
     444  include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
    419445  $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']);
    420446
    421   $query0 = '
    422 SELECT username, id
    423 FROM '.FluxBB_USERS_TABLE.'
    424 WHERE id = '.$id_user_FluxBB.'
    425 LIMIT 1
    426 ;';
    427 
    428   $data0 = pwg_db_fetch_assoc(pwg_query($query0));
    429 
    430   // If True, delete related topics and posts
    431   if ($SuppTopicsPosts and $conf_Register_FluxBB['FLUXBB_DEL_PT'])
    432   {
    433     // Delete posts and topics of this user
    434     $subquery = '
    435 DELETE FROM '.FluxBB_POSTS_TABLE.'
    436 WHERE poster_id = '.$id_user_FluxBB.'
    437 ;';
    438 
    439     $subresult = pwg_query($subquery);
    440 
    441     // Delete topics of this user
    442     $subquery = '
    443 DELETE FROM '.FluxBB_TOPICS_TABLE.'
    444 WHERE BINARY poster = BINARY "'.pwg_db_real_escape_string($data0['username']).'"
    445 ;';
    446 
    447     $subresult = pwg_query($subquery);
    448   }
    449 
    450   // Delete user's subscriptions
    451   $subquery = '
    452 DELETE FROM '.FluxBB_SUBSCRIPTIONS_TABLE.'
    453 WHERE user_id = '.$id_user_FluxBB.'
    454 ;';
    455 
    456   $subresult = pwg_query($subquery);
    457  
    458   // Delete user's account
    459   $subquery = '
    460 DELETE FROM '.FluxBB_USERS_TABLE.'
    461 WHERE id = '.$id_user_FluxBB.'
    462 ;';
    463 
    464   $subresult = pwg_query($subquery);
    465 
    466   FluxBB_Unlinkuser($id_user_FluxBB);
    467 }
    468 
    469 
    470 /**
    471  * Update user information in FluxBB users table
    472  */
    473 function FluxBB_Updateuser($pwg_id, $username, $password, $adresse_mail)
    474 {
    475   include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
    476 
     447// Select users to update in ID link table
    477448  $query = '
    478449SELECT id_user_FluxBB as FluxBB_id
     
    491462AND "'.pwg_db_real_escape_string($username).'" NOT IN ("18","16")
    492463;';
    493    
    494     $result = pwg_query($query);
    495      
    496     FluxBB_Linkuser($pwg_id, $row['FluxBB_id']);
     464
     465    pwg_query($query);
     466
     467    FluxBB_Linkuser($pwg_id, $row['FluxBB_id'], "OK");
    497468  }
    498469  else
     
    505476
    506477    $row = pwg_db_fetch_assoc(pwg_query($query));
    507  
     478
    508479    if (!empty($row))
    509480    {
     
    514485AND "'.pwg_db_real_escape_string($username).'" NOT IN ("18","16")
    515486;';
    516      
    517       $result = pwg_query($query);
    518      
    519       FluxBB_Linkuser($pwg_id, $row['FluxBB_id']);
     487
     488      pwg_query($query);
     489
     490      FluxBB_Linkuser($pwg_id, $row['FluxBB_id'], "OK");
    520491    }
    521492  }
    522493}
     494
     495
     496/**
     497 * Add new registered user in fluxBB users table from audit/synch action
     498 * Standard FluxBB_Adduser() function is not used because of existing password mismatch
     499 * To solve password synch problem, passwords are reset to NULL to force users to get a new password on their profile page
     500 */
     501function Synch_FluxBB_Adduser($pwg_id, $login, $adresse_mail)
     502{
     503  global $errors, $conf;
     504
     505  $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']);
     506
     507  $registred = time();
     508  $registred_ip = $_SERVER['REMOTE_ADDR'];
     509  $password = NULL;
     510
     511  // Set default FluxBB group - Check if UAM is installed and if bridge is set
     512  if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB['FLUXBB_UAM_LINK']) and $conf_Register_FluxBB['FLUXBB_UAM_LINK'] == 'true')
     513  {
     514    $o_default_user_group1 = $conf_Register_FluxBB['FLUXBB_GROUP'];
     515  }
     516  else
     517  {
     518    $query = '
     519SELECT conf_value
     520FROM '.FluxBB_CONFIG_TABLE.'
     521WHERE conf_name = "o_default_user_group"
     522;';
     523
     524    $o_default_user_group = pwg_db_fetch_assoc(pwg_query($query));
     525  }
     526
     527// Check for timezone settings in FluxBB version 1.4.x or higher
     528  $query1 = '
     529SELECT conf_value
     530FROM '.FluxBB_CONFIG_TABLE.'
     531WHERE conf_name = "o_default_timezone"
     532;';
     533
     534  $count1 = pwg_db_num_rows(pwg_query($query1));
     535
     536// Check for timezone settings in FluxBB version 1.2.x
     537  $query2 = '
     538SELECT conf_value
     539FROM '.FluxBB_CONFIG_TABLE.'
     540WHERE conf_name = "o_server_timezone"
     541;';
     542
     543  $count2 = pwg_db_num_rows(pwg_query($query2));
     544
     545// Set timezone var according of FluxBB version
     546  if ($count1 == 1 and $count2 == 0)
     547  {
     548    $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query1));
     549  }
     550  else if ($count1 == 0 and $count2 == 1)
     551  {
     552    $o_default_timezone = pwg_db_fetch_assoc(pwg_query($query2));
     553  }
     554
     555// Get FluxBB default language
     556  $query = '
     557SELECT conf_value
     558FROM '.FluxBB_CONFIG_TABLE.'
     559WHERE conf_name = "o_default_lang"
     560;';
     561
     562  $o_default_lang = pwg_db_fetch_assoc(pwg_query($query));
     563
     564// Get FluxBB default style
     565  $query = '
     566SELECT conf_value
     567FROM '.FluxBB_CONFIG_TABLE.'
     568WHERE conf_name = "o_default_style"
     569;';
     570
     571  $o_default_style = pwg_db_fetch_assoc(pwg_query($query));
     572
     573  // Add user - Check if UAM is installed and if bridge is set
     574  if (function_exists('FindAvailableConfirmMailID') and isset($conf_Register_FluxBB['FLUXBB_UAM_LINK']) and $conf_Register_FluxBB['FLUXBB_UAM_LINK'] == 'true')
     575  {
     576    $query = "
     577INSERT INTO ".FluxBB_USERS_TABLE." (
     578  username,
     579  ". ( isset($o_default_user_group1) ? 'group_id' : '' ) .",
     580  password,
     581  email,
     582  ". ( isset($o_default_timezone['conf_value']) ? 'timezone' : '' ) .",
     583  ". ( isset($o_default_lang['conf_value']) ? 'language' : '' ) .",
     584  ". ( isset($o_default_style['conf_value']) ? 'style' : '' ) .",
     585  registered,
     586  registration_ip,
     587  last_visit
     588  )
     589VALUES(
     590  '".pwg_db_real_escape_string($login)."',
     591  ". ( isset($o_default_user_group1) ? "'".$o_default_user_group1."'" : '' ) .",
     592  '".$password."',
     593        '".$adresse_mail."',
     594  ". ( isset($o_default_timezone['conf_value']) ? "'".$o_default_timezone['conf_value']."'" : '' ) .",
     595  ". ( isset($o_default_lang['conf_value']) ? "'".$o_default_lang['conf_value']."'" : '' ) .",
     596  ". ( isset($o_default_style['conf_value']) ? "'".$o_default_style['conf_value']."'" : '' ) .",
     597  '".$registred."',
     598  '".$registred_ip."',
     599  '".$registred."'
     600  );";
     601 
     602    pwg_query($query);
     603  }
     604  else
     605  {
     606    $query = "
     607INSERT INTO ".FluxBB_USERS_TABLE." (
     608  username,
     609  ". ( isset($o_default_user_group['conf_value']) ? 'group_id' : '' ) .",
     610  password,
     611  email,
     612  ". ( isset($o_default_timezone['conf_value']) ? 'timezone' : '' ) .",
     613  ". ( isset($o_default_lang['conf_value']) ? 'language' : '' ) .",
     614  ". ( isset($o_default_style['conf_value']) ? 'style' : '' ) .",
     615  registered,
     616  registration_ip,
     617  last_visit
     618  )
     619VALUES(
     620  '".pwg_db_real_escape_string($login)."',
     621  ". ( isset($o_default_user_group['conf_value']) ? "'".$o_default_user_group['conf_value']."'" : '' ) .",
     622  '".$password."',
     623        '".$adresse_mail."',
     624  ". ( isset($o_default_timezone['conf_value']) ? "'".$o_default_timezone['conf_value']."'" : '' ) .",
     625  ". ( isset($o_default_lang['conf_value']) ? "'".$o_default_lang['conf_value']."'" : '' ) .",
     626  ". ( isset($o_default_style['conf_value']) ? "'".$o_default_style['conf_value']."'" : '' ) .",
     627  '".$registred."',
     628  '".$registred_ip."',
     629  '".$registred."'
     630  )
     631;";
     632    pwg_query($query);
     633  }
     634
     635  $bb_id = pwg_db_insert_id();
     636
     637  FluxBB_Linkuser($pwg_id, $bb_id, "NOK");
     638}
     639
     640
     641/**
     642 * Search linked users
     643 */
     644function FluxBB_Searchuser($id_user_pwg)
     645{
     646  $query = '
     647SELECT id_user_FluxBB, id_user_pwg
     648FROM '.Register_FluxBB_ID_TABLE.'
     649WHERE id_user_pwg = '.$id_user_pwg.'
     650LIMIT 1
     651;';
     652
     653  $data = pwg_db_fetch_assoc(pwg_query($query));
     654 
     655  if (!empty($data))
     656    return $data['id_user_FluxBB'];
     657  else
     658    return '0'; 
     659}
     660
     661
     662/**
     663 * Delete user from FluxBB users table
     664 * Called from Register_FluxBB_Deluser()
     665 */
     666function FluxBB_Deluser($id_user_FluxBB, $SuppTopicsPosts)
     667{
     668  global $conf;
     669
     670  $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']);
     671
     672  $query0 = '
     673SELECT username, id
     674FROM '.FluxBB_USERS_TABLE.'
     675WHERE id = '.$id_user_FluxBB.'
     676LIMIT 1
     677;';
     678
     679  $data0 = pwg_db_fetch_assoc(pwg_query($query0));
     680
     681  // If True, delete related topics and posts
     682  if ($SuppTopicsPosts and $conf_Register_FluxBB['FLUXBB_DEL_PT'])
     683  {
     684    // Delete posts and topics of this user
     685    $subquery = '
     686DELETE FROM '.FluxBB_POSTS_TABLE.'
     687WHERE poster_id = '.$id_user_FluxBB.'
     688;';
     689
     690    $subresult = pwg_query($subquery);
     691
     692    // Delete topics of this user
     693    $subquery = '
     694DELETE FROM '.FluxBB_TOPICS_TABLE.'
     695WHERE BINARY poster = BINARY "'.pwg_db_real_escape_string($data0['username']).'"
     696;';
     697
     698    $subresult = pwg_query($subquery);
     699  }
     700
     701  // Delete user's subscriptions
     702  $subquery = '
     703DELETE FROM '.FluxBB_SUBSCRIPTIONS_TABLE.'
     704WHERE user_id = '.$id_user_FluxBB.'
     705;';
     706
     707  $subresult = pwg_query($subquery);
     708 
     709  // Delete user's account
     710  $subquery = '
     711DELETE FROM '.FluxBB_USERS_TABLE.'
     712WHERE id = '.$id_user_FluxBB.'
     713;';
     714
     715  $subresult = pwg_query($subquery);
     716
     717  FluxBB_Unlinkuser($id_user_FluxBB);
     718}
     719
    523720
    524721/**
Note: See TracChangeset for help on using the changeset viewer.