Compare commits

...
8 Commits
6 changed files with 24 additions and 16 deletions
+3 -3
View File
@@ -33,14 +33,14 @@ class curl {
}
}
public static function request($url, $data) {
$ch = curl_init($url);
public static function request($callback, $data) {
$ch = curl_init($callback->url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
"Content-Type: application/json",
"Content-Type: application/" . $callback->type,
"Content-Length: " . strlen($data))
);
+6 -4
View File
@@ -39,9 +39,9 @@ class events {
* @param object $event
*/
public static function handler($event) {
$config = get_config("local_webhooks");
$enable = get_config("local_webhooks", "enable");
if (boolval($config->enable)) {
if (boolval($enable)) {
$data = $event->get_data();
self::transmitter($data);
}
@@ -74,7 +74,9 @@ class events {
*/
private static function handler_callback($data, $callback) {
if ($callback->enable) {
$events = unserialize(gzuncompress(base64_decode($callback->events)));
if (!empty($callback->events)) {
$events = unserialize(gzuncompress(base64_decode($callback->events)));
}
if (boolval($events[$data["eventname"]])) {
/* Adding to the data token */
@@ -96,7 +98,7 @@ class events {
private static function send($data, $callback) {
$curl = new curl();
$package = self::packup($data);
$curl::request($callback->url, $package);
$curl::request($callback, $package);
}
/**
+9 -2
View File
@@ -81,7 +81,7 @@ class service_edit_form extends moodleform {
$mform->addRule("url", null, "required");
/* Enabling the service */
$mform->addElement("checkbox", "enable",
$mform->addElement("advcheckbox", "enable",
new lang_string("enable", "moodle"));
$mform->setType("enable", PARAM_BOOL);
$mform->setDefault("enable", 1);
@@ -93,6 +93,13 @@ class service_edit_form extends moodleform {
array("size" => 60));
$mform->setType("token", PARAM_NOTAGS);
/* Content type */
$mform->addElement("select", "type", "Content type",
array(
"json" => "application/json",
"x-www-form-urlencoded" => "application/x-www-form-urlencoded"));
$mform->setAdvanced("type");
/* Form heading */
$mform->addElement("header", "editserviceheaderevent",
new lang_string("edulevel", "moodle"));
@@ -104,7 +111,7 @@ class service_edit_form extends moodleform {
/* Formation of the list of elements */
foreach ($eventlist as $event) {
$events[$event["component"]][] =&
$mform->createElement("advcheckbox", $event["eventname"], $event["eventname"]);
$mform->createElement("checkbox", $event["eventname"], $event["eventname"]);
}
/* Displays groups of items */
+1
View File
@@ -7,6 +7,7 @@
<FIELD NAME="enable" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" />
<FIELD NAME="title" TYPE="text" NOTNULL="true" SEQUENCE="false" />
<FIELD NAME="url" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
<FIELD NAME="type" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
<FIELD NAME="token" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" />
<FIELD NAME="events" TYPE="text" NOTNULL="true" SEQUENCE="false" />
</FIELDS>
+3 -5
View File
@@ -59,12 +59,10 @@ if ($idediting = boolval($idservice)) {
/* Processing of received data */
if ($data = $mform->get_data()) {
if (empty($data->enable)) {
$data->enable = 0;
}
/* Packing of data */
$data->events = base64_encode(gzcompress(serialize($data->events), 9));
if (!empty($data->events)) {
$data->events = base64_encode(gzcompress(serialize($data->events), 9));
}
if ($idediting) {
$data->id = $idservice;
+2 -2
View File
@@ -23,8 +23,8 @@
*/
defined("MOODLE_INTERNAL") || die();
$plugin->release = "0.3.0 (Build: 2017102610)";
$plugin->version = 2017102610;
$plugin->release = "0.4.0 (Build: 2017102620)";
$plugin->version = 2017102620;
$plugin->requires = 2016112900;
$plugin->component = "local_webhooks";
$plugin->maturity = MATURITY_BETA;