BxFaceBookConnectDb.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup FacebookConnect Facebook Connect
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxFaceBookConnectDb extends BxBaseModConnectDb
  12. {
  13. /**
  14. * Constructor.
  15. */
  16. function __construct(&$oConfig)
  17. {
  18. parent::__construct($oConfig);
  19. }
  20. /**
  21. * Process big number
  22. *
  23. * @param $mValue mixed
  24. * @return integer
  25. */
  26. function _processBigNumber($mValue)
  27. {
  28. return preg_replace('/[^0-9]/', '', $mValue);
  29. }
  30. /**
  31. * Check fb profile id
  32. *
  33. * @param $iFbUid integer
  34. * @return integer
  35. */
  36. function getProfileId($iFbUid)
  37. {
  38. $iFbUidCopy = (int) $iFbUid;
  39. $iFbUid = $this -> _processBigNumber($iFbUid);
  40. //-- handle 64 bit number on 32bit system ( will need remove it in a feature version)--//
  41. if($iFbUidCopy != $iFbUid) {
  42. //update id
  43. $sQuery = $this -> prepare("UPDATE `{$this -> sTablePrefix}accounts` SET `fb_profile` = ?
  44. WHERE `fb_profile` = ?", $iFbUid, $iFbUidCopy);
  45. $this -> query($sQuery);
  46. }
  47. //--
  48. //-- new auth method --//
  49. $sQuery = $this -> prepare("SELECT `id_profile` FROM `{$this -> sTablePrefix}accounts` WHERE
  50. `fb_profile` = ? LIMIT 1", $iFbUid);
  51. $iProfileId = $this -> getOne($sQuery);
  52. //--
  53. return $iProfileId;
  54. }
  55. function getRemoteProfileId($iLocalId)
  56. {
  57. $sQuery = $this->prepare ("SELECT `fb_profile` FROM `{$this -> sTablePrefix}accounts` WHERE `id_profile` = ? LIMIT 1", (int)$iLocalId);
  58. return $this->getOne($sQuery);
  59. }
  60. /**
  61. * Save new Fb uid
  62. *
  63. * @param $iProfileId integer
  64. * @param $iFbUid integer
  65. * @return void
  66. */
  67. function saveRemoteId($iProfileId, $iFbUid)
  68. {
  69. $iFbUid = $this -> _processBigNumber($iFbUid);
  70. $iProfileId = (int) $iProfileId;
  71. $sQuery = $this -> prepare("REPLACE INTO `{$this -> sTablePrefix}accounts`
  72. SET `id_profile` = ?, `fb_profile` = ?", $iProfileId, $iFbUid);
  73. return $this -> query($sQuery);
  74. }
  75. /**
  76. * Delete Fb's uid
  77. *
  78. * @param $iProfileId integer
  79. * @return void
  80. */
  81. function deleteRemoteAccount($iProfileId)
  82. {
  83. $iProfileId = (int) $iProfileId;
  84. $sQuery = $this -> prepare("DELETE FROM `{$this -> sTablePrefix}accounts`
  85. WHERE `id_profile` = ?", $iProfileId);
  86. return $this -> query($sQuery);
  87. }
  88. }
  89. /** @} */