sPathToModule = BX_DOL_URL_ROOT . $this -> _oConfig -> getBaseUri(); $this -> aModuleInfo = $aModule; $this -> sHomeUrl = $this ->_oConfig -> _sHomeUrl; //Detect the browser $this -> userBrowser = strtolower($_SERVER['HTTP_USER_AGENT']); //Detect acceptable document types $this -> userAccept = strtolower($_SERVER['HTTP_ACCEPT']); $this -> oFacebook = new Facebook(array( 'appId' => (string)$this -> _oConfig -> mApiKey, 'secret' => (string)$this -> _oConfig -> mApiSecret, 'cookie' => true )); // define member id; $this -> iMemberId = getLoggedId(); // define FB profile's fields; $this -> aFacebookProfileFields = array( 'first_name', 'last_name', 'name', 'birthday', 'sex', 'proxied_email', 'email', 'about_me', 'books', 'interests', 'movies', 'music', 'religion', 'hometown_location','relationship_status','picture', ); $this -> aAlternativeNames = array( '_fb_id', '_facebook' ); } /** * Function will generate facebook's admin page; * * @return : (text) - html presentation data; */ function actionAdministration() { $GLOBALS['iAdminPage'] = 1; if( !isAdmin() ) { header('location: ' . BX_DOL_URL_ROOT); } $sb = $_POST['sb']; $sr = $_POST['sr']; if($sb == 1) { // save backup. $sOut = ''; $tmpDir = BX_DIRECTORY_PATH_MODULES . 'deano/deanos_facebook_connect/backup/'; $fn = $_POST['backupfn']; $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_api_key') . "' WHERE `Name` = 'dbcs_facebook_connect_api_key';" . "\r\n"; $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_secret_key') . "' WHERE `Name` = 'dbcs_facebook_connect_secret_key';" . "\r\n"; $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_permalinks') . "' WHERE `Name` = 'dbcs_facebook_connect_permalinks';" . "\r\n"; $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_option1') . "' WHERE `Name` = 'dbcs_facebook_connect_option1';" . "\r\n"; $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_option2') . "' WHERE `Name` = 'dbcs_facebook_connect_option2';" . "\r\n"; $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_option3') . "' WHERE `Name` = 'dbcs_facebook_connect_option3';" . "\r\n"; $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_redirect1') . "' WHERE `Name` = 'dbcs_facebook_connect_redirect1';" . "\r\n"; $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_redirect2') . "' WHERE `Name` = 'dbcs_facebook_connect_redirect2';" . "\r\n"; $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_nag_time') . "' WHERE `Name` = 'dbcs_facebook_connect_nag_time';" . "\r\n"; $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_autofriend_list') . "' WHERE `Name` = 'dbcs_facebook_connect_autofriend_list';" . "\r\n"; // $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_wml_redirect_join') . "' WHERE `Name` = 'dbcs_facebook_connect_wml_redirect_join';" . "\r\n"; // $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_wml_redirect') . "' WHERE `Name` = 'dbcs_facebook_connect_wml_redirect';" . "\r\n"; // $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_iphone_redirect_join') . "' WHERE `Name` = 'dbcs_facebook_connect_iphone_redirect_join';" . "\r\n"; // $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_iphone_redirect') . "' WHERE `Name` = 'dbcs_facebook_connect_iphone_redirect';" . "\r\n"; // $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_psp_redirect_join') . "' WHERE `Name` = 'dbcs_facebook_connect_psp_redirect_join';" . "\r\n"; // $sOut .= "UPDATE `sys_options` SET `VALUE` = '" . getParam('dbcs_facebook_connect_psp_redirect') . "' WHERE `Name` = 'dbcs_facebook_connect_psp_redirect';" . "\r\n"; $fbIDs = $this->_oDb->getFacebookIDs(); foreach ($fbIDs as $iID => $fbData) { $dID = (int)$fbData['ID']; $fbID = $fbData['dbcsFacebookProfile']; $sOut .= "UPDATE `Profiles` SET `dbcsFacebookProfile` = '$fbID' WHERE `ID` = '$dID';" . "\r\n"; } file_put_contents($tmpDir . $fn, $sOut); } if($sr == 1 && $_POST['delete'] == '') { // restore backup. $tmpDir = BX_DIRECTORY_PATH_MODULES . 'deano/deanos_facebook_connect/backup/'; $fn = $_POST['restorefn']; // convert old backup file format to new file format. $sConv = file_get_contents($tmpDir . $fn); $sConv = str_replace('`FacebookProfile`','`dbcsFacebookProfile`',$sConv); $sConv = str_replace('bx_facebook_connect','dbcs_facebook_connect',$sConv); file_put_contents($tmpDir . $fn, $sConv); // end convert. Execute sql to restore. execSqlFile($tmpDir . $fn); if ($GLOBALS['site']['ver'] == '7.0' && $GLOBALS['site']['build'] == 3) { $GLOBALS['MySQL']->cleanCache('sys_options'); } else { clearCacheFile(BX_DIRECTORY_PATH_DBCACHE . 'sys_options.php'); } } if($sr == 1 && $_POST['delete'] == 'Delete') { // delete backup. $tmpDir = BX_DIRECTORY_PATH_MODULES . 'deano/deanos_facebook_connect/backup/'; $fn = $_POST['restorefn']; unlink($tmpDir . $fn); } // get sys_option's category id; $iCatId = $this-> _oDb -> getSettingsCategoryId('dbcs_facebook_connect_api_key'); if(!$iCatId) { $sOptions = MsgBox( _t('_Empty') ); } else { bx_import('BxDolAdminSettings'); $oSettings = new BxDolAdminSettings($iCatId); $mixedResult = ''; if(isset($_POST['save']) && isset($_POST['cat'])) { $mixedResult = $oSettings -> saveChanges($_POST); } // get option's form; $sOptions = $oSettings -> getForm(); if($mixedResult !== true && !empty($mixedResult)) { $sOptions = $mixedResult . $sOptions; } } $sCssStyles = $this -> _oTemplate -> addCss('forms_adv.css', true); $this -> _oTemplate-> pageCodeAdminStart(); if($sb == 1) { echo MsgBox(_t('_dbcs_fb_Backup Saved'),4); } if($sr == 1 && $_POST['delete'] == '') { echo MsgBox(_t('_dbcs_fb_Backup Restored'),4); } if($sr == 1 && $_POST['delete'] == 'Delete') { echo MsgBox(_t('_dbcs_fb_Backup Deleted'),4); } echo DesignBoxAdmin( _t('_dbcs_facebook_information') , $GLOBALS['oSysTemplate'] -> parseHtmlByName('default_padding.html', array('content' => _t('_dbcs_facebook_information_block'))) ); echo DesignBoxAdmin( _t('_Settings') , $GLOBALS['oSysTemplate'] -> parseHtmlByName('default_padding.html', array('content' => $sCssStyles . $sOptions) )); echo DesignBoxAdmin( _t('_dbcs_fbc_Restore') , $GLOBALS['oSysTemplate'] -> parseHtmlByName('default_padding.html', array('content' => $this -> genRestoreForm()) )); echo DesignBoxAdmin( _t('_dbcs_fbc_Backup') , $GLOBALS['oSysTemplate'] -> parseHtmlByName('default_padding.html', array('content' => $this -> genBackupForm()) )); $this -> _oTemplate->pageCodeAdmin( _t('_dbcs_facebook_settings') ); } function url($url){ $dom = strstr($url,'//'); $dom = substr($dom,2); $mydom = explode("/",$dom); $suburl = strstr($mydom[0],'.'); if($suburl!=".com" || $suburl==".net" || $suburl==".org" || $suburl==".biz" || $suburl==".us" || $suburl==".cc" || $suburl==".tv" || $suburl==".info" || $suburl==".mobi" || $suburl==".co" || $suburl==".me") { $result = substr($suburl,1); return($result); } else { return($mydom[0]); } } /** * Function will get the facebook login form; * * @return : (text) - html presentation data; */ function actionLoginForm() { // here i will try to solve the oauth problems related to cookies once and for all. // On first hit to this logon form, delete all facebook cookies. and then set a cookie // to show we have hit this form once. if (intval($_COOKIE['dbcs_fb_logon_temp']) == 0) { // First logon attempt. Delete all FB cookies and set a temporary count cookie. $this -> deleteCookies(); setcookie('dbcs_fb_logon_temp', '1', 0, '/'); } else { // Remove the temporary count cookie. setcookie('dbcs_fb_logon_temp', '', time() - 96 * 3600, '/'); unset($_COOKIE['dbcs_fb_logon_temp']); } $wap = $_GET['wap']; // check Fb api keys; if(!$this -> _oConfig -> mApiKey || !$this -> _oConfig -> mApiSecret) { echo $this -> _oTemplate -> getPage( _t('_dbcs_facebook_error_occured') , MsgBox( _t('_dbcs_facebook_profile_error_api_keys') )); exit; } // try get the facebook uid; //$this -> iFacebookUid = $this -> oFacebook -> require_login(); $session = $this -> oFacebook ->getSession(); if ($session) { $me = null; $this -> iFacebookUid = $this -> oFacebook -> getUser(); $me = $this -> oFacebook -> api('/me?fields=picture&type=large'); $meLikes = $this -> oFacebook -> api('/me/likes/'); } /* $par['req_perms'] = "email, read_insights, read_stream, publish_stream, user_about_me, user_activities, user_birthday, user_education_history, user_events, user_groups, user_hometown, user_interests, user_likes, user_location, user_notes, user_online_presence, user_photo_video_tags, user_photos, user_relationships, user_religion_politics, user_status, user_videos, user_website, user_work_history, read_friendlists, read_requests"; */ $par['req_perms'] = "email,user_hometown,user_birthday,user_about_me,user_interests,user_likes,user_location"; if ($me) { $session = $this -> oFacebook ->getSession(); $this->logoutUrl = 'https://www.facebook.com/logout.php?api_key=' . getParam('dbcs_facebook_connect_api_key') . '&next=' . BX_DOL_URL_ROOT . 'logout.php?action=member_logout&session_key=' . $session['session_key']; setcookie('fb_base_domain', $session['base_domain'], 0, '/'); } else { $loginUrl = $this -> oFacebook -> getLoginUrl($par); if($wap == 'true') $loginUrl = str_replace('display=page','display=touch',$loginUrl); } // here if $me is not set then redirect to the loginurl otherwise process data. if (!$me) { header('Location: ' . $loginUrl); } else { $aFacebookProfileInfo['first_name'] = $me['first_name']; $aFacebookProfileInfo['last_name'] = $me['last_name']; $aFacebookProfileInfo['name'] = $me['name']; $aFacebookProfileInfo['birthday'] = $me['birthday']; $aFacebookProfileInfo['sex'] = $me['gender']; $aFacebookProfileInfo['proxied_email'] = $me['email']; $aFacebookProfileInfo['email'] = $me['email']; $aFacebookProfileInfo['about_me'] = $me['about']; //$aFacebookProfileInfo['religion'] = $me['last_name']; $aFacebookProfileInfo['hometown'] = $me['hometown']; $aFacebookProfileInfo['location'] = $me['location']; $aFacebookProfileInfo['relationship_status'] = $me['relationship_status']; //$aFacebookProfileInfo['picture'] = 'https://graph.facebook.com/' . $this -> iFacebookUid . '/picture&type=large'; $aFacebookProfileInfo['picture'] = $me['picture']; // Now pull the likes from facebook. New section added on Oct 28, 2010 $aMovies = array(); $aMusic = array(); $aInterests = array(); $aBooks = array(); foreach ($meLikes['data'] as $key => $value) { if ($meLikes['data'][$key]['category'] == 'Movie') $aMovies[] = $meLikes['data'][$key]['name']; if ($meLikes['data'][$key]['category'] == 'Music') $aMusic[] = $meLikes['data'][$key]['name']; if ($meLikes['data'][$key]['category'] == 'Interest') $aInterests[] = $meLikes['data'][$key]['name']; if ($meLikes['data'][$key]['category'] == 'Book') $aBooks[] = $meLikes['data'][$key]['name']; } $aFacebookProfileInfo['books'] = implode(",", $aBooks); $aFacebookProfileInfo['interests'] = implode(",", $aInterests); $aFacebookProfileInfo['movies'] = implode(",", $aMovies); $aFacebookProfileInfo['music'] = implode(",", $aMusic); $aDolphinProfileInfo = array(); $aFacebookProfileInfo['first_name'] = $this -> _proccesNickName($aFacebookProfileInfo['first_name']); $aFacebookProfileInfo['last_name'] = $this -> _proccesNickName($aFacebookProfileInfo['last_name']); // see if this facebook id is already in db. // ************************************************************************************************** // START NEW SECTION OF CODE TO MATCH EMAIL ADDRESS. // ************************************************************************************************** $q = "SELECT `ID` FROM `Profiles` WHERE `Email`='" . $aFacebookProfileInfo['email'] . "' limit 1"; $dbr = db_res($q); $dbrow = mysql_fetch_array($dbr); $num_rows = mysql_num_rows($dbr); if($num_rows > 0) { // we have a match on email. Found, so log member in. // First store their facebook ID. $fbID = $this -> iFacebookUid; $iProfileId = $dbrow['ID']; $q = "UPDATE `Profiles` SET `dbcsFacebookProfile` = '$fbID' WHERE `ID` = '$iProfileId';"; $result = db_res($q); $aDolphinProfileInfo = getProfileInfo($iProfileId); // when mobile features are done and working, comment next 3 and uncomment 4 $sRedirect2 = getParam('dbcs_facebook_connect_redirect2'); $sRedirect2 = str_replace("{memberid}",$iProfileId,$sRedirect2); $sRedirect2 = str_replace("{nickname}",getNickName($iProfileId),$sRedirect2); //$sRedirect2 = $this->mobileDetect($iProfileId,0); $sCallbackUrl = BX_DOL_URL_ROOT . $sRedirect2; $this -> setLogged($iProfileId, $aDolphinProfileInfo['Password'], $sCallbackUrl); } else { // ************************************************************************************************** // END NEW SECTION OF CODE TO MATCH EMAIL ADDRESS. // ************************************************************************************************** $q = "SELECT * FROM `Profiles` WHERE `dbcsFacebookProfile`='" . $this -> iFacebookUid . "' limit 1"; $dbr = db_res($q); $dbrow = mysql_fetch_array($dbr); $iProfileId = $dbrow['ID']; if ($iProfileId > 0) { // Found, so log member in. $aDolphinProfileInfo = getProfileInfo($iProfileId); // when mobile features are done and working, comment next 3 and uncomment 4 $sRedirect2 = getParam('dbcs_facebook_connect_redirect2'); $sRedirect2 = str_replace("{memberid}",$iProfileId,$sRedirect2); $sRedirect2 = str_replace("{nickname}",getNickName($iProfileId),$sRedirect2); //$sRedirect2 = $this->mobileDetect($iProfileId,0); $sCallbackUrl = BX_DOL_URL_ROOT . $sRedirect2; $this -> setLogged($iProfileId, $aDolphinProfileInfo['Password'], $sCallbackUrl); } else { // find an available user name to use. $nickType = getParam('dbcs_facebook_connect_option1'); $gotit = 0; // check pass 1 switch ($nickType) { case "FirstName": $dbcheck = getID($aFacebookProfileInfo['first_name']); break; case "FirstName_LastName": $dbcheck = getID($aFacebookProfileInfo['first_name'] . "_" . $aFacebookProfileInfo['last_name']); break; case "LastName": $dbcheck = getID($aFacebookProfileInfo['last_name']); break; } if (!$dbcheck) { $gotit = 1; $dbtype = $nickType; } if ($gotit == 0) { // check pass 2 $nickType = getParam('dbcs_facebook_connect_option2'); switch ($nickType) { case "FirstName": $dbcheck = getID($aFacebookProfileInfo['first_name']); break; case "FirstName_LastName": $dbcheck = getID($aFacebookProfileInfo['first_name'] . "_" . $aFacebookProfileInfo['last_name']); break; case "LastName": $dbcheck = getID($aFacebookProfileInfo['last_name']); break; } if (!$dbcheck) { $gotit = 1; $dbtype = $nickType; } } if ($gotit == 0) { // check pass 3 $nickType = getParam('dbcs_facebook_connect_option3'); switch ($nickType) { case "FirstName": $dbcheck = getID($aFacebookProfileInfo['first_name']); break; case "FirstName_LastName": $dbcheck = getID($aFacebookProfileInfo['first_name'] . "_" . $aFacebookProfileInfo['last_name']); break; case "LastName": $dbcheck = getID($aFacebookProfileInfo['last_name']); break; } if (!$dbcheck) { $gotit = 1; $dbtype = $nickType; } } if ($gotit == 0) { // failed to find a usable logon id. // generate error : profile exist; echo $this -> _oTemplate -> getPage( _t('_dbcs_facebook_error_occured') , MsgBox( _t('_dbcs_facebook_profile_exist', $aFacebookProfileInfo['first_name']) )); exit; } else { // create a member account. $iProfileId = $this -> _createProfile($aFacebookProfileInfo,$dbtype); } } } // end of else of if($num_rows == 1) } } /** * Function will set profile as logged; * * @param : $iProfileId (integer) - profile's Id; * @param : $sPassword (string) - profile's password; * @param : $sCallbackUrl (string) - redirect url that will use after profile logged; * @return : void; */ function setLogged($iProfileId, $sPassword, $sCallbackUrl = null) { $this ->_oDb ->saveLogoutURL($iProfileId,$this->logoutUrl); bx_login($iProfileId); $sCallbackUrl = ($sCallbackUrl) ? $sCallbackUrl : BX_DOL_URL_ROOT; header('location: ' . $sCallbackUrl); } /** * Function will get profile's alternative name * for join in dolphin DB; * * @param : $sName (string) - current profile's name; */ function getAlternativeName($sName) { $sRetName = null; foreach($this -> aAlternativeNames as $sAlternativeName) { $iProfileId = getID($sName . $sAlternativeName); if(!$iProfileId) { $sRetName = $sAlternativeName; break; } } return $sRetName; } /** * Function will create new profile; * * @param : $aProfileInfo (array) - some profile's information; * @see : $this -> aFacebookProfileFields; * @param : $sAlternativeName (string) - profiles alternative name; * @return : (integer) profile's id; */ function _createProfile(&$aProfileInfo, $dbtype, $sAlternativeName = null) { $aClearedInfo = array(); if(!$aProfileInfo || !$aProfileInfo['first_name']) { return; } // procces recived data; foreach($aProfileInfo as $sKey => $mValue) { if( is_array($mValue) ) { foreach($mValue as $sSubKey => $mSubValue) { $aClearedInfo[$sKey][$sSubKey] = $this -> _oDb -> escape($mSubValue); } } else { $aClearedInfo[$sKey] = $this -> _oDb -> escape($mValue); } } // procces the date of birth; if( isset($aClearedInfo['birthday']) ) { $aClearedInfo['birthday'] = date('Y-m-d', strtotime($aClearedInfo['birthday']) ); } // generate new password for profile; $sSalt = genRndSalt(); $aClearedInfo['password'] = encryptUserPwd(genRndPwd(), $sSalt); // define nick name; //$sNickName = $aClearedInfo['first_name'] . $sAlternativeName; switch ($dbtype) { case "FirstName": $sNickName = $aClearedInfo['first_name']; break; case "FirstName_LastName": $sNickName = $aClearedInfo['first_name'] . "_" . $aClearedInfo['last_name']; break; case "LastName": $sNickName = $aClearedInfo['last_name']; break; } // fill array with all needed values; if ($aClearedInfo['email'] == '') { $dbEmail = $aClearedInfo['proxied_email']; } else { $dbEmail = $aClearedInfo['email']; } $dbhometown = explode(",",$aClearedInfo['hometown']['name']); $dblocation = explode(",",$aClearedInfo['location']['name']); $dbcity = trim($dblocation[0]); if ($dbcity == '') $dbcity = trim($dbhometown[0]); $sRelationshipStatus = $aClearedInfo['relationship_status']; if ($sRelationshipStatus == 'Widowed' || $sRelationshipStatus == 'Separated' || $sRelationshipStatus == 'Divorced') $sRelationshipStatus = 'Single'; $aProfileFields = array( 'NickName' => $sNickName, 'Email' => $dbEmail, 'FirstName' => $aClearedInfo['first_name'], 'LastName' => $aClearedInfo['last_name'], 'Sex' => $aClearedInfo['sex'], 'DateOfBirth' => $aClearedInfo['birthday'], 'Password' => $aClearedInfo['password'], 'DescriptionMe' => $aClearedInfo['about_me'], 'FavoriteBooks' => $aClearedInfo['books'], 'Interests' => $aClearedInfo['interests'], 'FavoriteFilms' => $aClearedInfo['movies'], 'FavoriteMusic' => $aClearedInfo['music'], 'Religion' => $aClearedInfo['religion'], 'RelationshipStatus' => $sRelationshipStatus, //'City' => $aClearedInfo['hometown_location']['city'], 'City' => $dbcity, //'Country' => $this -> _oDb -> getCountryCode($aClearedInfo['hometown_location']['country']), 'Country' => $this -> _oDb -> getCountryCode(trim($dbhometown[1])), 'zip' => $aClearedInfo['hometown_location']['zip'], ); //if ($aProfileFields['Country'] == '') $aProfileFields['Country'] = 'US'; // check fields existence; foreach($aProfileFields as $sKey => $mValue) { if( !$this -> _oDb -> isFieldExist($sKey)) { // (field not existence) remove from array; unset($aProfileFields[$sKey]); } } // add some system values; $aProfileFields['Role'] = 1; $aProfileFields['dbcsFacebookProfile'] = $this -> iFacebookUid; $aProfileFields['DateReg'] = date( 'Y-m-d H:i:s' ); // set current date; // create new profile; $iProfileId = $this -> _oDb -> createProfile($aProfileFields); // New auto friend. Added on Oct 8, 2010 $sAutoFriendList = getParam('dbcs_facebook_connect_autofriend_list'); if ($sAutoFriendList != '') { $aAutoFriendList = explode(",",$sAutoFriendList); foreach($aAutoFriendList as $iAutoFriend) { if($iAutoFriend > 0) { db_res("INSERT INTO sys_friend_list SET `ID` = '{$iProfileId}', `Profile` = '{$iAutoFriend}', `Check` = 1"); } } } // End new Auto Friend. // check profile status; if ( getParam('autoApproval_ifNoConfEmail') == 'on' ) { if ( getParam('autoApproval_ifJoin') == 'on' ) { $sProfileStatus = 'Active'; } else { $sProfileStatus = 'Approval'; } } else { $sProfileStatus = 'Unconfirmed'; } // update profile's status; $this -> _oDb -> updateProfileStatus($iProfileId, $sProfileStatus); // create system event bx_import('BxDolAlerts'); $oZ = new BxDolAlerts('profile', 'join', $iProfileId); $oZ -> alert(); /* New Email Section added Oct 8, 2010 ************************************************************************************/ // This section needs to be skipped if a real email address was not obtained from facebook. if(substr_count($aProfileFields['Email'],"proxymail.facebook.com") == 0) { bx_import('BxDolEmailTemplates'); $oP = new BxDolEmailTemplates(); if ( getParam('autoApproval_ifNoConfEmail') == 'on' ) { if ( getParam('autoApproval_ifJoin') == 'on' ) { if ($sProfileStatus == 'Active') { $aTemplate = $oP -> getTemplate( 't_dbcs_FaceBookJoined' ) ; sendMail( $aProfileFields['Email'], $aTemplate['Subject'], $aTemplate['Body'], $iProfileId ); } } } else { if ($sProfileStatus == 'Unconfirmed') { global $site; $sConfCode = base64_encode( base64_encode( crypt( $aProfileFields['Email'], CRYPT_EXT_DES ? 'secret_ph' : 'se' ) ) ); $sConfLink = "{$site['url']}profile_activate.php?ConfID={$iProfileId}&ConfCode=" . urlencode( $sConfCode ); $aPlus = array( 'ConfCode' => $sConfCode, 'ConfirmationLink' => $sConfLink ); $aTemplate = $oP -> getTemplate( 't_dbcs_FaceBookUnconfirmed' ) ; sendMail( $aProfileFields['Email'], $aTemplate['Subject'], $aTemplate['Body'], $iProfileId, $aPlus ); } } } /* End new Email Section **************************************************************************************************/ // check avatar module; if( BxDolInstallerUtils::isModuleInstalled('avatar') ) { $sRedirect1 = getParam('dbcs_facebook_connect_redirect1'); $sRedirect1 = str_replace("{memberid}",$iProfileId,$sRedirect1); $sRedirect1 = str_replace("{nickname}",getNickName($iProfileId),$sRedirect1); if (strpos($sRedirect1,'avatar') > 0 || $sRedirect1 == '') { // check profile's logo; if($aClearedInfo['picture']) { BxDolService::call('avatar', 'set_image_for_cropping', array ($iProfileId, $aClearedInfo['picture'])); } if (BxDolService::call('avatar', 'join', array ($iProfileId, '_Join complete'))) { exit; } } else { $iAvaID = $this -> _oDb -> getNextAvaID(); if ($aClearedInfo['picture'] != '') { $iAvatarSaved = $this -> SaveAvatar($iAvaID,$aClearedInfo['picture'],$iProfileId); if ($iAvatarSaved == 1) { $this -> _oDb -> setAvatar($iProfileId,$iAvaID); } } $sCallbackUrl = BX_DOL_URL_ROOT . $sRedirect1; /* New Add Photo Section added Oct 8 2010 ***************************************************************************/ $sPass1 = getPassword($iProfileId); bx_login($iProfileId); check_logged(); if (BxDolRequest::serviceExists('photos', 'perform_photo_upload', 'Uploader')) { $sTempImageName = time() . ".jpg"; copy($aClearedInfo['picture'], $GLOBALS['dir']['tmp'] . $sTempImageName); $aFileInfo = array ( 'medTitle' => _t('_bx_ava_avatar'), 'medDesc' => _t('_bx_ava_avatar'), 'medTags' => _t('_ProfilePhotos'), 'Categories' => array(_t('_ProfilePhotos')), 'album' => str_replace('{nickname}', getNickName($iProfileId), getParam('bx_photos_profile_album_name')), ); BxDolService::call('photos', 'perform_photo_upload', array($GLOBALS['dir']['tmp'] . $sTempImageName, $aFileInfo, false), 'Uploader'); } /* End new Add Photo Section ****************************************************************************************/ $this -> setLogged($iProfileId, $aProfileInfo['Password'], $sCallbackUrl); } } else { // set logged and redirect on home page; $aProfileInfo = getProfileInfo($iProfileId); // when mobile features are done and working, comment next 3 and uncomment 4 $sRedirect2 = getParam('dbcs_facebook_connect_redirect2'); $sRedirect2 = str_replace("{memberid}",$iProfileId,$sRedirect2); $sRedirect2 = str_replace("{nickname}",getNickName($iProfileId),$sRedirect2); //$sRedirect2 = $this->mobileDetect($iProfileId,0); $sCallbackUrl = BX_DOL_URL_ROOT . $sRedirect2; /* New Add Photo Section added Oct 8 2010 ***************************************************************************/ $sPass1 = getPassword($iProfileId); bx_login($iProfileId); check_logged(); if (BxDolRequest::serviceExists('photos', 'perform_photo_upload', 'Uploader')) { $sTempImageName = time() . ".jpg"; copy($aClearedInfo['picture'], $GLOBALS['dir']['tmp'] . $sTempImageName); $aFileInfo = array ( 'medTitle' => _t('_bx_ava_avatar'), 'medDesc' => _t('_bx_ava_avatar'), 'medTags' => _t('_ProfilePhotos'), 'Categories' => array(_t('_ProfilePhotos')), 'album' => str_replace('{nickname}', getNickName($iProfileId), getParam('bx_photos_profile_album_name')), ); BxDolService::call('photos', 'perform_photo_upload', array($GLOBALS['dir']['tmp'] . $sTempImageName, $aFileInfo, false), 'Uploader'); } /* End new Add Photo Section ****************************************************************************************/ $this -> setLogged($iProfileId, $aProfileInfo['Password'], $sCallbackUrl); } } /** * Function will clear all unnecessary sybmols from profile's nickname; * * @param : $sProfileName (string) - profile's nickname; * @return : (string) - cleared nickname; */ function _proccesNickName($sProfileName) { $sProfileName = preg_replace("/^http:\/\/|^https:\/\/|\/$/", '', $sProfileName); $sProfileName = str_replace('/', '_', $sProfileName); $sProfileName = str_replace(' ', '_', $sProfileName); $sProfileName = str_replace('.', '', $sProfileName); $sProfileName = str_replace("'", '', $sProfileName); // convert accented characters. $sProfileName = $this->_normalize($sProfileName); return $sProfileName; } function _normalize ($string) { $table = array( 'Š'=>'S', 'š'=>'s', 'Đ'=>'Dj', 'đ'=>'dj', 'Ž'=>'Z', 'ž'=>'z', 'Č'=>'C', 'č'=>'c', 'Ć'=>'C', 'ć'=>'c', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'Ŕ'=>'R', 'ŕ'=>'r', ); return strtr($string, $table); } function genRestoreForm() { $tmpDir = BX_DIRECTORY_PATH_MODULES . 'deano/deanos_facebook_connect/backup/'; $fileCnt = 0; foreach (glob($tmpDir . "*-fb.bak") as $filename) { $fileCnt ++; } if ($fileCnt == 0) { $sCode = MsgBox(_t('_dbcs_fb_No Backups Found')); } else { $sCode = '
Select Backup to Restore:
 
'; } return $sCode; } function genBackupForm() { $sCode = '
Backup File Name:
 
'; return $sCode; } function actionGetMoreInfo() { $aVariables = array ( 'unit_text' => '', 'author' => '' ); $sCss = $this->_oTemplate->addCss('unit.css', true); $r = $sCss . $this->_oTemplate->parseHtmlByName('more_info.html', $aVariables); echo $r; } function SaveAvatar($iAvaID,$url,$iProfileId) { bx_import('BxDolImageResize'); $sTmpDir = BX_DIRECTORY_PATH_MODULES . 'boonex/avatar/data/tmp/'; $sImageDir = BX_DIRECTORY_PATH_MODULES . 'boonex/avatar/data/images/'; $sImageName = $iAvaID . ".jpg"; $sTempImageName = time() . ".jpg"; $sImageNameSmall = $iAvaID . "i.jpg"; $iAvatarSaved = 0; // Get Facebook Photo copy($url, $sTmpDir . $sTempImageName); // Save Avatar if image exists. if (file_exists($sTmpDir . $sTempImageName)) { $o =& BxDolImageResize::instance(64, 64); $o->setJpegOutput (true); $o->removeCropOptions (); $aSize = $o->getImageSize($sTmpDir . $sTempImageName); if ($aSize['w'] > $aSize['h']) { $s = $aSize['h']; } else { $s = $aSize['w']; } $o->setCropOptions(0,0,$s,$s); $o->setSize (64, 64); $o->setSquareResize (true); $o->resize($sTmpDir . $sTempImageName, $sTmpDir . $sImageName); unlink($sTmpDir . $sTempImageName); imageResize($sTmpDir . $sImageName, $sImageDir . $sImageName, 64, 64, true); imageResize($sTmpDir . $sImageName, $sImageDir . $sImageNameSmall, 32, 32, true); unlink($sTmpDir . $sImageName); $iAvatarSaved = 1; } return $iAvatarSaved; } function serviceCheckProfile () { $iMemID = intval($_COOKIE['memberID']); $r = ''; $iRequired = 0; if($iMemID > 0) { // see if any required profile fields are missing. $aProfileFields = $this -> _oDb -> getProfileFields(); foreach ($aProfileFields as $iID => $dbData) { $sLName = $dbData['Name']; $sValue = $this -> _oDb -> getProfileValue($iMemID,$sLName); if ($sValue == '') $iRequired++; } if($iRequired > 0) { $iNagValue = intval(getParam('dbcs_facebook_connect_nag_time')); if ($iNagValue > 0) { $iNagTime = $this -> _oDb -> getNagTime($iMemID); $iCurTime = time(); $iNagValueSeconds = 60 * 60 * $iNagValue; if ($iCurTime - $iNagTime > $iNagValueSeconds) { //$this -> _oDb -> updateNagTime($iMemID); $r = ' '; return $r; exit; } } } } return $r; } function checkidentity($fromThis,$identities){ foreach ($identities as $identity) { if (stristr($fromThis,$identity)){ return true; } } return false; } function mobileDetect($iProfileId,$isJoin) { if (stristr($this->userAccept,'wml')) { // This can accept wml (Wireless Meta Language files) so let's assume its WAP) // trouble is accept can contain wildcards ... but here we go $ub = "WML"; } else { // Lets look at the browser // specify an array of identities to match against $wapidentity = array('wapbrowser','up.browser','up/4','mib','cellphone','go.web', 'nokia','panasonic','wap','wml-browser','wml' ); // can add other identities to this list $pcidentity = array( 'mozilla','gecko','opera','omniweb','msie','konqueror','safari', 'netpositive' ,'lynx' ,'elinks' ,'links' ,'w3m' ,'webtv' ,'amaya' , 'dillo' ,'ibrowse' ,'icab' ,'crazy browser' ,'internet explorer' ); // can add other identities to this list $pspidentity = array('PlayStation Portable'); //can add other identities to this list $iPhoneidentity = array('iphone'); //can add other identities to this list if ($this->checkidentity($this->userBrowser,$wapidentity)){ $ub = "WML"; } elseif ($this->checkidentity($this->userBrowser,$iPhoneidentity)){ $ub = "iphone"; } elseif ($this->checkidentity($this->userBrowser,$pspidentity)){ $ub = "PSP"; } elseif ($this->checkidentity($this->userBrowser,$pcidentity)){ $ub = "PC"; } else { $ub = "WML"; // can't find anything else so let's hope it is WML } } //Code for redirecting based upon the results switch ($ub){ case 'PC': if ($isJoin == 1) { $sRedirect = getParam('dbcs_facebook_connect_redirect1'); $sRedirect = str_replace("{memberid}",$iProfileId,$sRedirect); $sRedirect = str_replace("{nickname}",getNickName($iProfileId),$sRedirect); } else { $sRedirect = getParam('dbcs_facebook_connect_redirect2'); $sRedirect = str_replace("{memberid}",$iProfileId,$sRedirect); $sRedirect = str_replace("{nickname}",getNickName($iProfileId),$sRedirect); } break; case 'WML': if ($isJoin == 1) { $sRedirect = getParam('dbcs_facebook_connect_wml_redirect_join'); $sRedirect = str_replace("{memberid}",$iProfileId,$sRedirect); $sRedirect = str_replace("{nickname}",getNickName($iProfileId),$sRedirect); } else { $sRedirect = getParam('dbcs_facebook_connect_wml_redirect'); $sRedirect = str_replace("{memberid}",$iProfileId,$sRedirect); $sRedirect = str_replace("{nickname}",getNickName($iProfileId),$sRedirect); } break; case 'PSP': if ($isJoin == 1) { $sRedirect = getParam('dbcs_facebook_connect_psp_redirect_join'); $sRedirect = str_replace("{memberid}",$iProfileId,$sRedirect); $sRedirect = str_replace("{nickname}",getNickName($iProfileId),$sRedirect); } else { $sRedirect = getParam('dbcs_facebook_connect_psp_redirect'); $sRedirect = str_replace("{memberid}",$iProfileId,$sRedirect); $sRedirect = str_replace("{nickname}",getNickName($iProfileId),$sRedirect); } break; case 'iphone': if ($isJoin == 1) { $sRedirect = getParam('dbcs_facebook_connect_iphone_redirect_join'); $sRedirect = str_replace("{memberid}",$iProfileId,$sRedirect); $sRedirect = str_replace("{nickname}",getNickName($iProfileId),$sRedirect); } else { $sRedirect = getParam('dbcs_facebook_connect_iphone_redirect'); $sRedirect = str_replace("{memberid}",$iProfileId,$sRedirect); $sRedirect = str_replace("{nickname}",getNickName($iProfileId),$sRedirect); } break; } return $sRedirect; } function deleteCookies() { // This function deletes all fabebook cookies. // It is a little wacked. This screwy method is to try a deal with cookies // regardless of what sub domain of the base domain it was set in. $sHost = $_SERVER['HTTP_HOST']; $aHost = explode(".",$sHost); // Loop through all cookies. foreach ($_COOKIE as $key => $value) { if ( strstr($key,"user_") || strstr($key,"session_key_") || strstr($key,"expires_") || strstr($key,"ss_") || strstr($key,"fbsetting_") || strstr($key,"base_domain_") || strstr($key,"fbs_") || strstr($key,"_user") || strstr($key,"_session_key") || strstr($key,"_expires") || strstr($key,"_ss") || strstr($key,"_fbsetting") || strstr($key,"_base_domain") || strstr($key,"_fbs") ) { if (count($aHost) == 2) { $sDomain = "." . $aHost[count($aHost)-2] . "." . $aHost[count($aHost)-1]; setcookie($key, '', time() - 96 * 3600, '/', $sDomain); } if (count($aHost) == 3) { $sDomain = "." . $aHost[count($aHost)-2] . "." . $aHost[count($aHost)-1]; setcookie($key, '', time() - 96 * 3600, '/', $sDomain); $sDomain = "." . $aHost[count($aHost)-3] . "." . $aHost[count($aHost)-2] . "." . $aHost[count($aHost)-1]; setcookie($key, '', time() - 96 * 3600, '/', $sDomain); } if (count($aHost) == 4) { $sDomain = "." . $aHost[count($aHost)-2] . "." . $aHost[count($aHost)-1]; setcookie($key, '', time() - 96 * 3600, '/', $sDomain); $sDomain = "." . $aHost[count($aHost)-3] . "." . $aHost[count($aHost)-2] . "." . $aHost[count($aHost)-1]; setcookie($key, '', time() - 96 * 3600, '/', $sDomain); $sDomain = "." . $aHost[count($aHost)-4] . "." . $aHost[count($aHost)-3] . "." . $aHost[count($aHost)-2] . "." . $aHost[count($aHost)-1]; setcookie($key, '', time() - 96 * 3600, '/', $sDomain); } unset($_COOKIE[$key]); } } $sCookieName = getParam('dbcs_facebook_connect_api_key'); if (count($aHost) == 2) { $sDomain = "." . $aHost[count($aHost)-2] . "." . $aHost[count($aHost)-1]; setcookie($sCookieName, '', time() - 96 * 3600, '/', $sDomain); } if (count($aHost) == 3) { $sDomain = "." . $aHost[count($aHost)-2] . "." . $aHost[count($aHost)-1]; setcookie($sCookieName, '', time() - 96 * 3600, '/', $sDomain); $sDomain = "." . $aHost[count($aHost)-3] . "." . $aHost[count($aHost)-2] . "." . $aHost[count($aHost)-1]; setcookie($sCookieName, '', time() - 96 * 3600, '/', $sDomain); } if (count($aHost) == 4) { $sDomain = "." . $aHost[count($aHost)-2] . "." . $aHost[count($aHost)-1]; setcookie($sCookieName, '', time() - 96 * 3600, '/', $sDomain); $sDomain = "." . $aHost[count($aHost)-3] . "." . $aHost[count($aHost)-2] . "." . $aHost[count($aHost)-1]; setcookie($sCookieName, '', time() - 96 * 3600, '/', $sDomain); $sDomain = "." . $aHost[count($aHost)-4] . "." . $aHost[count($aHost)-3] . "." . $aHost[count($aHost)-2] . "." . $aHost[count($aHost)-1]; setcookie($sCookieName, '', time() - 96 * 3600, '/', $sDomain); } unset($_COOKIE[$sCookieName]); // Delete the cookie i use to store the base domain as facebook sees it. if( isset($_COOKIE['fb_base_domain']) ) { setcookie('fb_base_domain', '', time() - 96 * 3600, '/'); unset($_COOKIE['fb_base_domain']); } } // ******************************************************* }