/**
  * Populate view manager with Facebook interaction UI, like the Facebook Add User button and page dropdown.
  * @param array $options 'facebook_app_id' and 'facebook_api_secret'
  */
 protected function setUpFacebookInteractions($options)
 {
     $facebook_app_id = $options['facebook_app_id']->option_value;
     // Plant unique token for CSRF protection during auth per https://developers.facebook.com/docs/authentication/
     if (SessionCache::get('facebook_auth_csrf') == null) {
         SessionCache::put('facebook_auth_csrf', md5(uniqid(rand(), true)));
     }
     if (isset($this->owner) && $this->owner->isMemberAtAnyLevel()) {
         if ($this->owner->isMemberLevel()) {
             $instance_dao = DAOFactory::getDAO('InstanceDAO');
             $owner_instances = $instance_dao->getByOwnerAndNetwork($this->owner, 'facebook');
             if (sizeof($owner_instances) > 0) {
                 $this->do_show_add_button = false;
                 $this->addInfoMessage("To connect another Facebook account to ThinkUp, upgrade your membership.", 'membership_cap');
             }
         }
     }
     $scope = 'user_posts,email';
     $state = SessionCache::get('facebook_auth_csrf');
     $redirect_url = Utils::getApplicationURL() . 'account/?p=facebook';
     $fbconnect_link = FacebookGraphAPIAccessor::getLoginURL($facebook_app_id, $scope, $state, $redirect_url);
     //For expired connections
     $this->addToView('fb_reconnect_link', $fbconnect_link);
     if ($this->do_show_add_button) {
         $this->addToView('fbconnect_link', $fbconnect_link);
     }
     self::processPageActions($options);
     $logger = Logger::getInstance();
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     $instances = $instance_dao->getByOwnerAndNetwork($this->owner, 'facebook');
     $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
     foreach ($instances as $instance) {
         $tokens = $owner_instance_dao->getOAuthTokens($instance->id);
         $access_token = $tokens['oauth_access_token'];
         if (isset($tokens['auth_error']) && $tokens['auth_error'] != '') {
             $instance->auth_error = $tokens['auth_error'];
         }
     }
     $this->addToView('instances', $instances);
 }