diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index f422e97959..9cde0316d9 100755 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -947,16 +947,16 @@ class IndexManager } if (true === api_get_configuration_value('whispeak_auth_enabled')) { -// if (!WhispeakAuthPlugin::checkUserIsEnrolled($userId)) { - $itemTitle = WhispeakAuthPlugin::create()->get_title(); + //if (!WhispeakAuthPlugin::checkUserIsEnrolled($userId)) { + $itemTitle = WhispeakAuthPlugin::create()->get_title(); - $items[] = [ - 'class' => 'whispeak-enrollment', - 'icon' => Display::return_icon('addworkuser.png', $itemTitle), - 'link' => WhispeakAuthPlugin::getEnrollmentUrl(), - 'title' => $itemTitle, - ]; -// } + $items[] = [ + 'class' => 'whispeak-enrollment', + 'icon' => Display::return_icon('addworkuser.png', $itemTitle), + 'link' => WhispeakAuthPlugin::getEnrollmentUrl(), + 'title' => $itemTitle, + ]; + //} } return $items; diff --git a/plugin/whispeakauth/WhispeakAuthPlugin.php b/plugin/whispeakauth/WhispeakAuthPlugin.php index f2258cd807..81582d2dc2 100644 --- a/plugin/whispeakauth/WhispeakAuthPlugin.php +++ b/plugin/whispeakauth/WhispeakAuthPlugin.php @@ -127,57 +127,6 @@ class WhispeakAuthPlugin extends Plugin return api_get_path(WEB_PLUGIN_PATH).'whispeakauth/enrollment.php'; } - /** - * @return string - */ - private function getApiUrl() - { - $url = $this->get(self::SETTING_API_URL); - - return trim($url, " \t\n\r \v/"); - } - - /** - * @param string $endPoint - * @param array $metadata - * @param User $user - * @param string $filePath - * - * @return array - */ - private function sendRequest($endPoint, array $metadata, User $user, $filePath) - { - $moderator = $user->getCreatorId() ?: $user->getId(); - $apiUrl = $this->getApiUrl()."/$endPoint"; - $headers = [ - //"Content-Type: application/x-www-form-urlencoded", - "Authorization: Bearer ".$this->get(self::SETTING_TOKEN), - ]; - $post = [ - 'metadata' => json_encode($metadata), - 'moderator' => "moderator_$moderator", - 'client' => base64_encode($user->getUserId()), - 'voice' => new CURLFile($filePath), - ]; - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $apiUrl); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $result = curl_exec($ch); - curl_close($ch); - - $result = json_decode($result, true); - - if (!empty($result['error'])) { - return null; - } - - return json_decode($result, true); - } - /** * @param User $user * @param string $filePath @@ -286,4 +235,55 @@ class WhispeakAuthPlugin extends Plugin api_not_allowed($printHeaders); } + + /** + * @return string + */ + private function getApiUrl() + { + $url = $this->get(self::SETTING_API_URL); + + return trim($url, " \t\n\r \v/"); + } + + /** + * @param string $endPoint + * @param array $metadata + * @param User $user + * @param string $filePath + * + * @return array + */ + private function sendRequest($endPoint, array $metadata, User $user, $filePath) + { + $moderator = $user->getCreatorId() ?: $user->getId(); + $apiUrl = $this->getApiUrl()."/$endPoint"; + $headers = [ + //"Content-Type: application/x-www-form-urlencoded", + "Authorization: Bearer ".$this->get(self::SETTING_TOKEN), + ]; + $post = [ + 'metadata' => json_encode($metadata), + 'moderator' => "moderator_$moderator", + 'client' => base64_encode($user->getUserId()), + 'voice' => new CURLFile($filePath), + ]; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $apiUrl); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $result = curl_exec($ch); + curl_close($ch); + + $result = json_decode($result, true); + + if (!empty($result['error'])) { + return null; + } + + return json_decode($result, true); + } }