Minor - Flint fixes - refs BT#15941

pull/3377/head
Angel Fernando Quiroz Campos 7 years ago
parent e30585158a
commit 13e74c1bf6
  1. 2
      plugin/whispeakauth/WhispeakAuthPlugin.php
  2. 159
      plugin/whispeakauth/WhispeakAuthRequest.php
  3. 8
      plugin/whispeakauth/admin.php

@ -650,7 +650,7 @@ class WhispeakAuthPlugin extends Plugin implements HookPluginInterface
}
/**
* Display a error message
* Display a error message.
*
* @param string|null $error Optional. The message text
*/

@ -10,84 +10,6 @@ class WhispeakAuthRequest
{
const API_URL = 'http://api.whispeak.io:8080/v1.1/';
/**
* @param string $uri
* @param array $headers
* @param array|string $body
*
* @throws Exception
*
* @return array
*/
private static function doPost($uri, array $headers = [], $body = null)
{
$ch = curl_init(self::API_URL.$uri);
if ($headers) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
if ($body) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
}
$result = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if (!empty($error)) {
throw new Exception($error);
}
$result = json_decode($result, true);
if (!empty($result['error'])) {
throw new Exception($result['error']);
}
return $result;
}
/**
* @param string $uri
* @param array $headers
*
* @throws Exception
*
* @return array
*/
private static function doGet($uri, array $headers = [])
{
$ch = curl_init(self::API_URL.$uri);
if ($headers) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if (!empty($error)) {
throw new Exception($error);
}
$result = json_decode($result, true);
if (!empty($result['error'])) {
throw new Exception($result['error']);
}
return $result;
}
/**
* @param WhispeakAuthPlugin $plugin
*
@ -195,7 +117,8 @@ class WhispeakAuthRequest
*
* @return array
*/
public static function enrollment(WhispeakAuthPlugin $plugin, User $user, $wsId, $text, $filePath) {
public static function enrollment(WhispeakAuthPlugin $plugin, User $user, $wsId, $text, $filePath)
{
$headers = [
"Authorization: Bearer ".$plugin->getAccessToken(),
];
@ -311,4 +234,82 @@ class WhispeakAuthRequest
return $result;
}
/**
* @param string $uri
* @param array $headers
* @param array|string $body
*
* @throws Exception
*
* @return array
*/
private static function doPost($uri, array $headers = [], $body = null)
{
$ch = curl_init(self::API_URL.$uri);
if ($headers) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
if ($body) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
}
$result = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if (!empty($error)) {
throw new Exception($error);
}
$result = json_decode($result, true);
if (!empty($result['error'])) {
throw new Exception($result['error']);
}
return $result;
}
/**
* @param string $uri
* @param array $headers
*
* @throws Exception
*
* @return array
*/
private static function doGet($uri, array $headers = [])
{
$ch = curl_init(self::API_URL.$uri);
if ($headers) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if (!empty($error)) {
throw new Exception($error);
}
$result = json_decode($result, true);
if (!empty($result['error'])) {
throw new Exception($result['error']);
}
return $result;
}
}

@ -18,7 +18,8 @@ $plugin->protectTool();
*
* @return array
*/
function findWsIds(array $userIds) {
function findWsIds(array $userIds)
{
$wsIds = [];
foreach ($userIds as $userId) {
@ -47,7 +48,8 @@ function findWsIds(array $userIds) {
*
* @return array
*/
function groupResults(array $results) {
function groupResults(array $results)
{
$groups = [];
foreach ($results as $row) {
@ -187,4 +189,4 @@ $template->assign(
'content',
$form->returnForm().PHP_EOL.$pageContent
);
$template->display_one_col_template();;
$template->display_one_col_template();

Loading…
Cancel
Save