Example #1
0
 /**
  * Helper function that handles Gigya API calls.
  *
  * @param mixed $method
  *   The Gigya API method.
  * @param mixed $params
  *   The method parameters.
  *
  * @return array
  *   The Gigya response.
  */
 public function call($method, $params)
 {
     // Initialize new request.
     $request = new GSRequest($this->api_key, $this->api_secret, $method);
     $user_info = NULL;
     if (!empty($params)) {
         foreach ($params as $param => $val) {
             $request->setParam($param, $val);
         }
         $user_info = in_array('getUserInfo', $params);
     }
     // To be define on CMS code (or not).
     $api_domain = GIGYA__API_DOMAIN;
     // Set the request path.
     $domain = !empty($api_domain) ? $api_domain : 'us1.gigya.com';
     $request->setAPIDomain($domain);
     // Make the request.
     ini_set('arg_separator.output', '&');
     $response = $request->send();
     ini_restore('arg_separator.output');
     // Check for errors
     $err_code = $response->getErrorCode();
     if ($err_code != 0) {
         if (function_exists('_gigya_error_log')) {
             $log = explode("\r\n", $response->getLog());
             _gigya_error_log($log);
             return new WP_Error($err_code, $response->getErrorMessage());
         }
     } else {
         if (!empty($user_info)) {
             // Check validation in the response.
             $valid = SigUtils::validateUserSignature($response->getString("UID", ""), $response->getString("signatureTimestamp", ""), $this->api_secret, $response->getString("UIDSignature", ""));
             if (!empty($valid)) {
                 return $err_code;
             }
         }
     }
     return $this->jsonToArray($response->getResponseText());
 }
 public function gigyaSocialLoginScode($attrs)
 {
     require_once GIGYA__PLUGIN_DIR . 'features/login/GigyaLoginSet.php';
     $login = new GigyaLoginSet();
     $defaults = $login->getParams();
     if (empty($attrs)) {
         $attrs = $defaults;
         if (isset($attrs['advanced'])) {
             $advanced = gigyaCms::jsonToArray($attrs['advanced']);
             if (is_array($advanced)) {
                 $attrs = array_merge($attrs, $advanced);
             } else {
                 if (is_string($advanced)) {
                     _gigya_error_log("Error in " . __FUNCTION__ . " shortcode advanced parameters message: " . $advanced);
                 }
             }
         }
     } else {
         $attrs = $this->attrs_to_gigya($attrs);
         // If custom attributes are passed with shortcode, use them to replace the ui array of the default ui values
         $ui_arr = $defaults['ui'];
         $ui_arr_updated = array_replace($ui_arr, $attrs);
         $defaults['ui'] = $ui_arr_updated;
         $attrs = $defaults;
     }
     if (!is_user_logged_in()) {
         $output = '<div class="gigya-login-widget"></div>';
         $output .= '<script class="data-login" type="application/json">' . json_encode($attrs) . '</script>';
     } else {
         $current_user = wp_get_current_user();
         $output = '<div class="gigya-wp-account-widget">';
         $output .= '<a class="gigya-wp-avatar" href="' . user_admin_url('profile.php') . '">' . get_avatar($current_user->ID) . '</a>';
         $output .= '<div class="gigya-wp-info">';
         $output .= '<a class="gigya-wp-name" href="' . user_admin_url('profile.php') . '">' . $current_user->display_name . '</a>';
         $output .= '<a class="gigya-wp-logout" href="' . wp_logout_url() . '">' . __('Log Out') . '</a>';
         $output .= '</div></div>';
     }
     return $output;
 }