<commit_before><?php

/**
 * @package     sfFacebookAppPlugin
 * @subpackage  filter
 * @author      <NAME> <<EMAIL>>
 */
class sfFacebookSignedRequestFilter extends sfFilter
{
  public function execute($filterChain)
  {
    if ($this->isFirstCall())
    {
      $context    = $this->getContext();
      $request    = $context->getRequest();
      $controller = $context->getController();
    
      $data = array();
      $signed_request = 0;
    
      if ($request->hasParameter('signed_request') && '' != $request->getParameter('signed_request')) 
      {
        $data           = sfFacebookAppUtil::getSignedRequest();
        $signed_request = $request->getParameter('signed_request');
      } 
      else 
      {
        // no signed_request
        // force page refresh
      }
    
      if (!is_array($data))
      {
        $data = array();
      }
    
      // get the current action instance
      $actionEntry    = $controller->getActionStack()->getLastEntry();
      $actionInstance = $actionEntry->getActionInstance();
    
      // check if like gate is enabled
      $like_gate_config = sfConfig::get('app_facebook_like_gate', array());
        
      if (isset($like_gate_config['enabled']) && true === $like_gate_config['enabled'])
      {
        // If we have no data - make them like the page :)
        if (empty($data)) $data['page']['liked'] = false;
          
        // check if a user has liked the page & redirect if they haven't
        if (!$data['page']['liked'] && ($actionInstance->getModuleName() != $like_gate_config['module'] || $actionInstance->getActionName() != $like_gate_config['action']))
        {
          $controller->redirect($like_gate_config['module'] . '/' . $like_gate_config['action']);
        }
      }
    
      // access token
      if (array_key_exists('oauth_token', $data))
      {
        $access_token = $data['oauth_token'];
    
        // check if user_id exist
        if (array_key_exists('user_id', $data))
        {
          $uid        = $data['user_id'];
          $user_data  = sfFacebookAppUtil::getUserData($uid, $access_token, $data);
          $actionInstance->user_data = $user_data;
        } 
      }
      else 
      {
        $access_token = false;
      }
      
      $actionInstance->signed_request = $signed_request;
      $actionInstance->data           = $data;
      $actionInstance->access_token   = $access_token;<commit_msg>If no page data don't redirect to like page - as we're prolly on a canvas page which doesn't have ['page'] data<commit_after><?php

/**
 * @package     sfFacebookAppPlugin
 * @subpackage  filter
 * @author      <NAME> <<EMAIL>>
 */
class sfFacebookSignedRequestFilter extends sfFilter
{
  public function execute($filterChain)
  {
    if ($this->isFirstCall())
    {
      $context    = $this->getContext();
      $request    = $context->getRequest();
      $controller = $context->getController();
    
      $data = array();
      $signed_request = 0;
    
      if ($request->hasParameter('signed_request') && '' != $request->getParameter('signed_request')) 
      {
        $data           = sfFacebookAppUtil::getSignedRequest();
        $signed_request = $request->getParameter('signed_request');
      } 
      else 
      {
        // no signed_request
        // force page refresh
      }
    
      if (!is_array($data))
      {
        $data = array();
      }
    
      // get the current action instance
      $actionEntry    = $controller->getActionStack()->getLastEntry();
      $actionInstance = $actionEntry->getActionInstance();
    
      // check if like gate is enabled
      $like_gate_config = sfConfig::get('app_facebook_like_gate', array());
        
      if (isset($like_gate_config['enabled']) && true === $like_gate_config['enabled'])
      {
        // If we have no data - make them like the page :)
        if (!empty($data) && isset($data['page']))
        {
          // check if a user has liked the page & redirect if they haven't
          if (!$data['page']['liked'] && ($actionInstance->getModuleName() != $like_gate_config['module'] || $actionInstance->getActionName() != $like_gate_config['action']))
          {
            $controller->redirect($like_gate_config['module'] . '/' . $like_gate_config['action']);
          }
        }
      }
    
      // access token
      if (array_key_exists('oauth_token', $data))
      {
        $access_token = $data['oauth_token'];
    
        // check if user_id exist
        if (array_key_exists('user_id', $data))
        {
          $uid        = $data['user_id'];
          $user_data  = sfFacebookAppUtil::getUserData($uid, $access_token, $data);
          $actionInstance->user_data = $user_data;
        } 
      }
      else 
      {
        $access_token = false;
      }
      
      $actionInstance->signed_request = $signed_request;
      $actionInstance->data           = $data;
      $actionInstance->access_token   = $access_token;
{'fraction_non_alphanumeric': 0.14501815248083905, 'fraction_numerical': 0.0004033884630899556, 'mean_word_length': 2.277594183740912, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2640749', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1412, 'n_words': 280}