eblib/facebook.php 程式修改

  1. facebook 連線導向網址只限 https,但程式設定 http。
    [root@dywang mod_tmp]# diff -uNwB elcentra/eblib/facebook.php ../auth/elcentra/eblib/facebook.php 
    --- elcentra/eblib/facebook.php	2014-01-21 15:09:52.000000000 +0800
    +++ ../auth/elcentra/eblib/facebook.php	2019-03-06 06:13:18.953760111 +0800
    @@ -6,7 +6,7 @@
    	var $config;
    	
    	function __construct() {
    -		$this->URL = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
    +		$this->URL = "https://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
    	}
    	
    	function setConfig($configArray) {
    
  2. 修改 facebook 連線存取 token 字串前後以大括號括起來,以逗號「,」分隔欄位,以冒號「:」指定欄位內容。但 php 內建 parse_str 解析每個欄位以「&」 隔開,且以等號「=」 指定欄位內容,所以先將 token 字串改成 parse_str 可解析的格式。
    @@ -40,6 +40,10 @@
    		$buildUrl.="&code=".$code;
     
    		$responseText = file_get_contents($buildUrl);
    +		$responseText=str_replace(":","=",$responseText);
    +		$responseText=str_replace(",","&",$responseText);
    +		$responseText=str_replace(array("{","}","\""),"",$responseText);
    +
    		parse_str($responseText,$responseArray);
    		if(!isset($responseArray['access_token'])) {
    			throw new moodle_exception("Unexpected error");
    
  3. 不指定存取 facebook 欄位 (fields) 時,只回傳 id 及 name,所以增加 &fields=id... 指定需要的欄位。
    @@ -48,11 +52,13 @@
    		$accessToken = $responseArray['access_token'];
    		
    		$buildUrl = $facebookConfig['retrieval_url'];
    +		$buildUrl.="&fields=id,email,first_name,last_name,name,timezone,verified";
    		$buildUrl.="&access_token=$accessToken";
    		$dataResponse = file_get_contents($buildUrl);
    		$details = json_decode($dataResponse);