Exemplo n.º 1
0
 /**
  * Creates a SOAP client and initializes the headers etc
  *
  * @return \SoapClient|SoapClient
  */
 protected function getSoapClient()
 {
     if ($this->soap === null) {
         // Refactor to somewhere
         $options = array('trace' => 1, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS);
         $this->soap = new \SoapClient($this->provider->getBaseURL() . '/' . $this->service->getServiceURI(), $options);
         if ($this->needsAuthentication) {
             $this->soap->__setSoapHeaders(array($this->provider->getAuthentication()->getHeader()));
         }
     }
     return $this->soap;
 }
Exemplo n.º 2
0
 /**
  * Checks the user credentials for validty
  * Unfortunately i have not found a proper way to check for validity other than calling a function
  * that requires authorisation. So we do some basic checks by calling several methods to figure out
  * what we can do and what not.
  * I probably need to check on submodule, but seems your API user needs quite a high authentication
  * level to actually do anything at all.
  *
  * @param $data
  *
  * @return bool
  */
 protected function checkConnection($data)
 {
     if ($data['client_environment'] && $data['client_account'] && $data['client_username'] && $data['client_password']) {
         try {
             $tp = new TripolisProvider($data['client_account'], $data['client_username'], $data['client_password'], $data['client_environment']);
             // Check if server is working
             $infoResponse = $tp->contact()->info();
             // Check the user
             $user = $tp->user()->getByAuthInfo();
             if (!$user->hasRole(GetByAuthInfoResponse::ROLE_MODULE_CONTACT)) {
                 add_settings_error('client_account', 'unauthorized', __('Your user does not have acces to the Contact Module'));
                 return false;
             }
             // Check if we have access to the required components
             $databases = $tp->ContactDatabase()->all();
             $db = $databases->first();
             if ($db) {
                 // Test the COntact Group Service
                 $groups = $tp->ContactGroup()->all($db->id);
                 // Test the Contact service
                 $result = $tp->Contact()->countByContactDatabaseId($db->id);
                 add_settings_error('client_account', 'nodatabases', __('Settings ok, and validated'), 'updated');
                 return true;
             } else {
                 add_settings_error('client_account', 'nodatabases', __('You do not have access to any databases in this environment'));
             }
         } catch (UnauthorizedException $e) {
             add_settings_error('client_username', 'unauthorized', __('Wrong credentials, access was denied by the API'));
         } catch (\SoapFault $f) {
             add_settings_error('client_environment', $f->getCode(), $f->getMessage());
         } catch (\Exception $e) {
             add_settings_error('client_environment', $e->getCode(), $e->getMessage());
         }
         return false;
     }
     return false;
 }
 /**
  * Create a list of fields to show in the register form.
  *
  * @param TripolisProvider $provider
  * @param                  $database
  * @param                  $fields
  *
  * @return array
  * @throws \Exception
  * @throws \SoapFault
  * @throws \Exception
  */
 protected function getFieldDefinitions(TripolisProvider $provider, $database, $fields)
 {
     // Try gracefully, so not to upset the non-programmers
     try {
         $fieldGroups = $provider->ContactDatabaseFieldGroup()->database($database)->all();
         $tableFields = $provider->ContactDatabaseField()->database($database)->all();
     } catch (\SoapFault $f) {
         if (!WP_DEBUG) {
             return array();
         } else {
             throw $f;
         }
     } catch (\Exception $e) {
         if (!WP_DEBUG) {
             return array();
         } else {
             throw $e;
         }
     }
     $postData = isset($_POST[$this->plugin]) ? $_POST[$this->plugin] : false;
     $definition = array();
     if (!$fields) {
         $fields = array_keys($tableFields);
     }
     foreach ($fields as $field) {
         if (isset($tableFields[$field])) {
             $id = implode('_', array($this->plugin, $fieldGroups[$tableFields[$field]->contactDatabaseFieldGroupId]->name, $tableFields[$field]->name));
             $required = apply_filters($this->plugin . '_required', $tableFields[$field]->required, $tableFields[$field]);
             $classes = array($this->plugin, strtolower($tableFields[$field]->type));
             if ($required) {
                 $classes[] = 'required';
             }
             $definition[$field] = array('code' => $field, 'label' => apply_filters($this->plugin . '_label', $tableFields[$field]->label, $tableFields[$field]), 'name' => $this->getUniqueId() . '[' . $field . ']', 'id' => $id, 'value' => apply_filters($this->plugin . '_value', isset($postData[$field]) ? $postData[$field] : '', $tableFields[$field]), 'type' => $tableFields[$field]->type, 'required' => $required, 'class' => apply_filters($this->plugin . '_classes', $classes, $tableFields[$field]), 'group' => $fieldGroups[$tableFields[$field]->contactDatabaseFieldGroupId], 'message' => '');
         }
     }
     return $definition;
 }