<commit_before><?php

/**
 * sfGuardUser
 * 
 * @package    sfFacebookAppPlugin
 * @subpackage model
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
 */
class sfGuardUser extends PluginsfGuardUser
{
  private $fb = null;

  /**
   * Get a Facebook instance
   *
   * @return sfFacebook
   */
  public function getFacebook()
  {
    if (!$this->fb) 
    {
      $this->fb = sfFacebook::getInstance();
    }
    
    // access token for mobiles, no signed_request - it'll pull from FB otherwise
    if (sfContext::getInstance()->getUser()->hasAttribute('access_token')) 
    {
      $this->fb->setAccessToken($this->getUser()->getAttribute('access_token'));
    }
    
    // OR If using cacophony and tokens use this (also check out Cacophony module upgrade in Who's On Heart)
    /*// Set access token from DB - if not expired
    $token    = $this->getTokenFor('facebook');
    
    if ($token && !$token->isExpired())
    {
      $tokenData = $token->getContent();
      $this->fb->setAccessToken($tokenData['access_token']);
    }*/

    return $this->fb;
  }

	/**
   * If using cacophony and tokens use this (also check out Cacophony module upgrade in Who's On Heart)
   * Query the user's tokens for the selected provider
   * 
   * @param string $provider
   * @return Token
   */
  /*public function getTokenFor($provider)
  {
    // Check for existing token in DB
    $tokens = $this->getTokens();
    
    if ($tokens) 
    {
      foreach ($tokens as $token) 
      {
        if ($token['provider'] == $provider) return $token;
      }
    }
    
    return null;
  }*/
  
  /**
   * If using cacophony and tokens use this (also check out Cacophony module upgrade in Who's On Heart)
   * Upgrade to longer life access token so that app created users can
   * Log in using mobile / microsite and Cacophony (it relies on Token)
   * 
   * @return void
   */
  /*public function upgradeAccessToken($access_token = null)
  {
    if ($access_token) $this->getFacebook()->setAccessToken($access_token); // If existing user and token expired then use the one sent through from JS/FB to upgrade
    $token = $this->getTokenFor('facebook');
    
    // Check expiry if have existing token - and end here if do
    if ($token && $token->getDateTimeObject('expires_at')->getTimestamp() > time()) return; // Check elsewhere if need force upgrade and delete broken token before calling
    
    // Upgrade access token and store in DB.
    try {
      $output = $this->getFacebook()->getExtendedAccessToken();
    }
    catch (Exception $e) {
      if ($token) $token->delete(); // delete old token if error
      return;
    }
    
    if (!$output) {
      if ($token) $token->delete(); // delete old token if error
      return;
    }
    
    if (!$token) $token = new Token();
    
    $token->fromArray(array(
      'provider'          => 'facebook',
      'sf_guard_user_id'  => $this->id,
      'providers_user_id' => $this->fb_uid,
      'content'           => $output,
      'expires_at'        => date('Y-m-d H:i:s', (time() + $output['expires']))
    ));
    
    $this['Tokens']->add($token);
    // Now save user (in method this is called from)
  }*/
  
  /**
   * Example open graph post of object
   * 
   * @param Doctrine_Record $record
   * @param string $ogUrl
   * @return void
   */<commit_msg>Fixing id issue<commit_after><?php

/**
 * sfGuardUser
 * 
 * @package    sfFacebookAppPlugin
 * @subpackage model
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
 */
class sfGuardUser extends PluginsfGuardUser
{
  private $fb = null;

  /**
   * Get a Facebook instance
   *
   * @return sfFacebook
   */
  public function getFacebook()
  {
    if (!$this->fb) 
    {
      $this->fb = sfFacebook::getInstance();
    }
    
    // access token for mobiles, no signed_request - it'll pull from FB otherwise
    if (sfContext::getInstance()->getUser()->hasAttribute('access_token')) 
    {
      $this->fb->setAccessToken($this->getUser()->getAttribute('access_token'));
    }
    
    // OR If using cacophony and tokens use this (also check out Cacophony module upgrade in Who's On Heart)
    /*// Set access token from DB - if not expired
    $token    = $this->getTokenFor('facebook');
    
    if ($token && !$token->isExpired())
    {
      $tokenData = $token->getContent();
      $this->fb->setAccessToken($tokenData['access_token']);
    }*/

    return $this->fb;
  }

	/**
   * If using cacophony and tokens use this (also check out Cacophony module upgrade in Who's On Heart)
   * Query the user's tokens for the selected provider
   * 
   * @param string $provider
   * @return Token
   */
  /*public function getTokenFor($provider)
  {
    // Check for existing token in DB
    $tokens = $this->getTokens();
    
    if ($tokens) 
    {
      foreach ($tokens as $token) 
      {
        if ($token['provider'] == $provider) return $token;
      }
    }
    
    return null;
  }*/
  
  /**
   * If using cacophony and tokens use this (also check out Cacophony module upgrade in Who's On Heart)
   * Upgrade to longer life access token so that app created users can
   * Log in using mobile / microsite and Cacophony (it relies on Token)
   * 
   * @return void
   */
  /*public function upgradeAccessToken($access_token = null)
  {
    if ($access_token) $this->getFacebook()->setAccessToken($access_token); // If existing user and token expired then use the one sent through from JS/FB to upgrade
    $token = $this->getTokenFor('facebook');
    
    // Check expiry if have existing token - and end here if do
    if ($token && $token->getDateTimeObject('expires_at')->getTimestamp() > time()) return; // Check elsewhere if need force upgrade and delete broken token before calling
    
    // Upgrade access token and store in DB.
    try {
      $output = $this->getFacebook()->getExtendedAccessToken();
    }
    catch (Exception $e) {
      if ($token) $token->delete(); // delete old token if error
      return;
    }
    
    if (!$output) {
      if ($token) $token->delete(); // delete old token if error
      return;
    }
    
    if (!$token) $token = new Token();
    
    $token->fromArray(array(
      'provider'          => 'facebook',
      'sf_guard_user_id'  => $this->id,
      'providers_user_id' => $this->id,
      'content'           => $output,
      'expires_at'        => date('Y-m-d H:i:s', (time() + $output['expires']))
    ));
    
    $this['Tokens']->add($token);
    // Now save user (in method this is called from)
  }*/
  
  /**
   * Example open graph post of object
   * 
   * @param Doctrine_Record $record
   * @param string $ogUrl
   * @return void
   */
{'fraction_non_alphanumeric': 0.13687648456057008, 'fraction_numerical': 0.005344418052256532, 'mean_word_length': 2.547656661400737, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3752723', 'n_tokens_mistral': 2122, 'n_tokens_neox': 2051, 'n_words': 626}