138 lines
4.7 KiB
PHP
138 lines
4.7 KiB
PHP
<?php
|
|
require_once(ABSPATH."/wp-content/plugins/EISGE-API-Core/EISGE_Library_Core.php");
|
|
|
|
/**
|
|
* Class Reporter
|
|
* This class defines routes for the Kalifast Bug Reporter
|
|
*/
|
|
class Reporter extends EISGE_Library_Core {
|
|
public function getActions(){
|
|
return array(
|
|
"post_kalifast_ticket" => array(
|
|
"mode" => "EDIT",
|
|
"guest_mod" => true,
|
|
"desc" => "Send a ticket to the Kalifast Application",
|
|
"args" => array(
|
|
array(
|
|
"name" => "title",
|
|
"type" => "string",
|
|
"description" => "Title of the ticket"
|
|
),
|
|
array(
|
|
"name" => "content",
|
|
"type" => "string",
|
|
"description" => "Content of the ticket"
|
|
),
|
|
array(
|
|
"name" => "contact",
|
|
"type" => "string",
|
|
"description" => "Contact of the ticket's author"
|
|
),
|
|
)
|
|
),
|
|
"get_kalifast_api_configuration" => array(
|
|
"mode" => "DISPLAY",
|
|
"guest_mod" => false,
|
|
"desc" => "Get the Kalifast API host and key",
|
|
"args" => "no_args"
|
|
),
|
|
"configure_kalifast_api" => array(
|
|
"mode" => "EDIT",
|
|
"guest_mod" => false,
|
|
"desc" => "Configure the Kalifast API host and key",
|
|
"args" => array(
|
|
array(
|
|
"name" => "kft_api_host",
|
|
"type" => "string",
|
|
"description" => "Host of the Kalifast App"
|
|
),
|
|
array(
|
|
"name" => "kft_api_key",
|
|
"type" => "string",
|
|
"description" => "API Key of the Kalifast App"
|
|
),
|
|
)
|
|
)
|
|
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
* This function is called when the user wants to send a ticket to the Kalifast Application
|
|
*/
|
|
public function post_kalifast_ticket(){
|
|
|
|
/* Check the parameters */
|
|
$parameters = $this->checkArguments($this->dataIn,
|
|
array(
|
|
"title" => "string",
|
|
"content" => "string",
|
|
"contact" => "string"
|
|
)
|
|
);
|
|
if (!$parameters) {
|
|
return $this->functionFailed("parameters", "Syntax error on parameters!");
|
|
}
|
|
|
|
|
|
return $this->functionFailed("not_implemented", "Not implemented yet!");
|
|
}
|
|
|
|
|
|
/**
|
|
* This function is called when the user wants to get the Kalifast API host and key
|
|
*/
|
|
public function get_kalifast_api_configuration(){
|
|
|
|
try {
|
|
$stmt = $this->PDO->prepare("SELECT kft_api_host, kft_api_key FROM kalifast_bug_reporter_config ORDER BY last_update DESC LIMIT 1");
|
|
$stmt->execute();
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
if($row) {
|
|
return $this->functionSuccess($row);
|
|
}
|
|
return $this->functionFailed("no_data", "No data found in the database");
|
|
|
|
|
|
} catch (PDOException $e) {
|
|
error_log($e->getMessage());
|
|
return $this->functionFailed("database_error", "Error while getting kalifast API data from the database");
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* This function is called when the user wants to configure the Kalifast API host and key
|
|
*/
|
|
public function configure_kalifast_api(){
|
|
|
|
/* Check the parameters */
|
|
$parameters = $this->checkArguments($this->dataIn,
|
|
array(
|
|
"kft_api_host" => "string",
|
|
"kft_api_key" => "string"
|
|
)
|
|
);
|
|
if (!$parameters) {
|
|
return $this->functionFailed("parameters", "Syntax error on parameters!");
|
|
}
|
|
|
|
|
|
try {
|
|
$stmt = $this->PDO->prepare("DELETE FROM kalifast_bug_reporter_config");
|
|
|
|
$stmt = $this->PDO->prepare("INSERT INTO kalifast_bug_reporter_config (kft_api_host, kft_api_key) VALUES (:kft_api_host, :kft_api_key)");
|
|
$stmt->bindParam(':kft_api_host', $parameters["kft_api_host"]);
|
|
$stmt->bindParam(':kft_api_key', $parameters["kft_api_key"]);
|
|
$stmt->execute();
|
|
return $this->functionSuccess("Kalifast API data inserted into the database");
|
|
|
|
} catch (PDOException $e) {
|
|
error_log($e->getMessage());
|
|
return $this->functionFailed("database_error", "Error while inserting kalifast API data the database");
|
|
}
|
|
|
|
}
|
|
}
|