<commit_before><?php
/**
 * ACM (facebook) Modulo para crear apps en Facebook.
 *
 * @author <NAME> [Avenidanet]
 * @link http://www.avenidanet.com
 * @copyright <NAME> 2006-2013
 * @license http://mit-license.org
 *
 */

class facebookController extends AbstractController{
	
	public $user;
	
	private function base64_url_decode($input){
		return base64_decode(strtr($input, '-_', '+/'));
	}
	
	private function parse_signed_request() {
		$secret = $this->acore->fb_secret;
		$signed_request = $_POST['signed_request'];
		list($encoded_sig, $payload) = explode('.', $signed_request, 2);
	
		$sig = $this->base64_url_decode($encoded_sig);
		$data = json_decode($this->base64_url_decode($payload), true);
	
		if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
			error_log('Unknown algorithm. Expected HMAC-SHA256');
			return null;
		}
	
		$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
		if ($sig !== $expected_sig) {
			error_log('Bad Signed JSON signature!');
			return null;
		}
		return $data;
	}
	
	public function install(){
		return "<a href='https://www.facebook.com/dialog/pagetab?app_id=".$this->acore->fb_apikey."&next=".$this->acore->fb_url."'>Instalar tab</a>";
	}
	
	public function info($data=''){
		if($data == 'liked' || $data == 'admin' || $data == 'id'){
			$result = $this->parse_signed_request();
			return $result['page'][$data];
		}else{
			echo "Use 'liked','admin','id'";
		}
	}
	
	public function request(){
		return $this->parse_signed_request();
	}	
	
	public function header($init_script = '',$canvas=TRUE){
		$script = "<div id='fb-root'></div>
		<script>
				window.fbAsyncInit = function() {
		
		        FB.init({
		          appId: '".$this->acore->fb_apikey."',
		          status : true,
		          cookie: true,
		          xfbml: true,
		          oauth: true
		        });";
		
		//Canvas
		if($canvas=TRUE){
			$script .= "FB.Canvas.setAutoGrow();";
		}
		
		$script .= $init_script;
		$script .= "};
		
		      (function() {
		        var e = document.createElement('script'); e.async = true;
		        e.src = document.location.protocol +
		          '//connect.facebook.net/en_US/all.js';
		        document.getElementById('fb-root').appendChild(e);
		      }());
		</script>";
		echo $script;
	}
	
	public function footer(){
		$script = "<!-- NO FACEBOOK --><script>
			if (parent.location.href == self.location.href) {
				window.location.href = '".$this->acore->fb_url."';
			}";
	
		if(preg_match('/apps.facebook.com/',$_SERVER[HTTP_REFERER])){
			$script = "top.location.href = '".$this->acore->fb_url."';";
		}
	
		$script .= "</script>";
		echo $script;
	}
	
	public function authorized(){
		$facebook = new Facebook(array(
				'appId'  => $this->acore->fb_apikey,
				'secret' => $this->acore->fb_secret,
		));
		$user = $facebook->getUser();
		if ($user) {
			try {
				$this->user = $facebook->api('/me');
				return TRUE;
			} catch (FacebookApiException $e) {
				$user = null;
				return FALSE;
			}
		}		
	}<commit_msg>Se agrega la opción de acceso al objeto Facebook<commit_after><?php
/**
 * ACM (facebook) Modulo para crear apps en Facebook.
 *
 * @author <NAME> [Avenidanet]
 * @link http://www.avenidanet.com
 * @copyright <NAME> 2006-2013
 * @license http://mit-license.org
 *
 */

class facebookController extends AbstractController{
	
	public $user;
	public $fb;
	
	private function base64_url_decode($input){
		return base64_decode(strtr($input, '-_', '+/'));
	}
	
	private function parse_signed_request() {
		$secret = $this->acore->fb_secret;
		$signed_request = $_POST['signed_request'];
		list($encoded_sig, $payload) = explode('.', $signed_request, 2);
	
		$sig = $this->base64_url_decode($encoded_sig);
		$data = json_decode($this->base64_url_decode($payload), true);
	
		if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
			error_log('Unknown algorithm. Expected HMAC-SHA256');
			return null;
		}
	
		$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
		if ($sig !== $expected_sig) {
			error_log('Bad Signed JSON signature!');
			return null;
		}
		return $data;
	}
	
	public function install(){
		return "<a href='https://www.facebook.com/dialog/pagetab?app_id=".$this->acore->fb_apikey."&next=".$this->acore->fb_url."'>Instalar tab</a>";
	}
	
	public function info($data=''){
		if($data == 'liked' || $data == 'admin' || $data == 'id'){
			$result = $this->parse_signed_request();
			return $result['page'][$data];
		}else{
			echo "Use 'liked','admin','id'";
		}
	}
	
	public function request(){
		return $this->parse_signed_request();
	}	
	
	public function header($init_script = '',$canvas=TRUE){
		$script = "<div id='fb-root'></div>
		<script>
				window.fbAsyncInit = function() {
		
		        FB.init({
		          appId: '".$this->acore->fb_apikey."',
		          status : true,
		          cookie: true,
		          xfbml: true,
		          oauth: true
		        });";
		
		//Canvas
		if($canvas=TRUE){
			$script .= "FB.Canvas.setAutoGrow();";
		}
		
		$script .= $init_script;
		$script .= "};
		
		      (function() {
		        var e = document.createElement('script'); e.async = true;
		        e.src = document.location.protocol +
		          '//connect.facebook.net/en_US/all.js';
		        document.getElementById('fb-root').appendChild(e);
		      }());
		</script>";
		echo $script;
	}
	
	public function footer(){
		$script = "<!-- NO FACEBOOK --><script>
			if (parent.location.href == self.location.href) {
				window.location.href = '".$this->acore->fb_url."';
			}";
	
		if(preg_match('/apps.facebook.com/',$_SERVER[HTTP_REFERER])){
			$script = "top.location.href = '".$this->acore->fb_url."';";
		}
	
		$script .= "</script>";
		echo $script;
	}
	
	public function authorized(){
		$this->fb = new Facebook(array(
				'appId'  => $this->acore->fb_apikey,
				'secret' => $this->acore->fb_secret,
		));
		$user = $this->fb->getUser();
		if ($user) {
			try {
				$this->user = $this->fb->api('/me');
				return TRUE;
			} catch (FacebookApiException $e) {
				$user = null;
				return FALSE;
			}
		}		
	}
{'fraction_non_alphanumeric': 0.19610432485968968, 'fraction_numerical': 0.008583690987124463, 'mean_word_length': 3.130197682344922, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 78, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2990501', 'n_tokens_mistral': 2426, 'n_tokens_neox': 2081, 'n_words': 388}