Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2744e4fb80 | ||
|
|
5179a7ec05 | ||
|
|
18a5d23d07 | ||
|
|
f43b3f2fd3 | ||
|
|
ea30d3ca56 | ||
|
|
e86542d8f7 | ||
|
|
dab55b9562 | ||
|
|
c2cd361171 | ||
|
|
eaee6b7c81 | ||
|
|
282e3bcaf1 | ||
|
|
c037edbc58 | ||
|
|
2c4c05acd6 | ||
|
|
39fa71faba | ||
|
|
9ecf83b1d6 | ||
|
|
54d1d030ec | ||
|
|
8651e6a157 | ||
|
|
28632834af | ||
|
|
a19031d444 | ||
|
|
bae23caa87 | ||
|
|
0d8cb8688d | ||
|
|
430c9fa09a |
+3
-3
@@ -33,14 +33,14 @@ class curl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function request($url, $data) {
|
public static function request($callback, $data) {
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($callback->url);
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER,
|
curl_setopt($ch, CURLOPT_HTTPHEADER,
|
||||||
array(
|
array(
|
||||||
"Content-Type: application/json",
|
"Content-Type: application/" . $callback->type,
|
||||||
"Content-Length: " . strlen($data))
|
"Content-Length: " . strlen($data))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+27
-6
@@ -39,9 +39,9 @@ class events {
|
|||||||
* @param object $event
|
* @param object $event
|
||||||
*/
|
*/
|
||||||
public static function handler($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();
|
$data = $event->get_data();
|
||||||
self::transmitter($data);
|
self::transmitter($data);
|
||||||
}
|
}
|
||||||
@@ -59,13 +59,36 @@ class events {
|
|||||||
|
|
||||||
if ($callbacks->valid()) {
|
if ($callbacks->valid()) {
|
||||||
foreach ($callbacks as $callback) {
|
foreach ($callbacks as $callback) {
|
||||||
self::send($data, $callback);
|
self::handler_callback($data, $callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$callbacks->close();
|
$callbacks->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes each callback.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @param object $callback
|
||||||
|
*/
|
||||||
|
private static function handler_callback($data, $callback) {
|
||||||
|
if ($callback->enable) {
|
||||||
|
if (!empty($callback->events)) {
|
||||||
|
$events = unserialize(gzuncompress(base64_decode($callback->events)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (boolval($events[$data["eventname"]])) {
|
||||||
|
/* Adding to the data token */
|
||||||
|
if (boolval($callback->token)) {
|
||||||
|
$data["token"] = $callback->token;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::send($data, $callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sending data to the node.
|
* Sending data to the node.
|
||||||
*
|
*
|
||||||
@@ -73,11 +96,9 @@ class events {
|
|||||||
* @param object $callback
|
* @param object $callback
|
||||||
*/
|
*/
|
||||||
private static function send($data, $callback) {
|
private static function send($data, $callback) {
|
||||||
if ($callback->enable) {
|
|
||||||
$curl = new curl();
|
$curl = new curl();
|
||||||
$package = self::packup($data);
|
$package = self::packup($data);
|
||||||
$curl::request($callback->url, $package);
|
$curl::request($callback, $package);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+44
-1
@@ -28,6 +28,7 @@ defined("MOODLE_INTERNAL") || die();
|
|||||||
|
|
||||||
require_once($CFG->libdir . "/formslib.php");
|
require_once($CFG->libdir . "/formslib.php");
|
||||||
|
|
||||||
|
use report_eventlist_list_generator;
|
||||||
use lang_string;
|
use lang_string;
|
||||||
use moodleform;
|
use moodleform;
|
||||||
|
|
||||||
@@ -45,6 +46,16 @@ class service_edit_form extends moodleform {
|
|||||||
parent::__construct($baseurl);
|
parent::__construct($baseurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unpacks data for display.
|
||||||
|
*
|
||||||
|
* @param object $record
|
||||||
|
*/
|
||||||
|
public function set_data($record) {
|
||||||
|
$record->events = unserialize(gzuncompress(base64_decode($record->events)));
|
||||||
|
return parent::set_data($record);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the standard structure of the form.
|
* Defines the standard structure of the form.
|
||||||
*/
|
*/
|
||||||
@@ -70,12 +81,44 @@ class service_edit_form extends moodleform {
|
|||||||
$mform->addRule("url", null, "required");
|
$mform->addRule("url", null, "required");
|
||||||
|
|
||||||
/* Enabling the service */
|
/* Enabling the service */
|
||||||
$mform->addElement("checkbox", "enable",
|
$mform->addElement("advcheckbox", "enable",
|
||||||
new lang_string("enable", "moodle"));
|
new lang_string("enable", "moodle"));
|
||||||
$mform->setType("enable", PARAM_BOOL);
|
$mform->setType("enable", PARAM_BOOL);
|
||||||
$mform->setDefault("enable", 1);
|
$mform->setDefault("enable", 1);
|
||||||
$mform->setAdvanced("enable");
|
$mform->setAdvanced("enable");
|
||||||
|
|
||||||
|
/* Token */
|
||||||
|
$mform->addElement("text", "token",
|
||||||
|
new lang_string("token", "webservice"),
|
||||||
|
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"));
|
||||||
|
|
||||||
|
/* List of events */
|
||||||
|
$eventlist = report_eventlist_list_generator::get_all_events_list(true);
|
||||||
|
$events = array();
|
||||||
|
|
||||||
|
/* Formation of the list of elements */
|
||||||
|
foreach ($eventlist as $event) {
|
||||||
|
$events[$event["component"]][] =&
|
||||||
|
$mform->createElement("checkbox", $event["eventname"], $event["eventname"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Displays groups of items */
|
||||||
|
foreach ($events as $key => $event) {
|
||||||
|
$mform->addGroup($event, "events", $key, "<br />", true);
|
||||||
|
}
|
||||||
|
|
||||||
/* Control Panel */
|
/* Control Panel */
|
||||||
$this->add_action_buttons(true);
|
$this->add_action_buttons(true);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<XMLDB PATH="blocks/local_webhooks/db" VERSION="20171022" COMMENT="XMLDB file for Moodle" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd">
|
<XMLDB PATH="blocks/local_webhooks/db" VERSION="20171026" COMMENT="XMLDB file for Moodle" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd">
|
||||||
<TABLES>
|
<TABLES>
|
||||||
<TABLE NAME="local_webhooks_service" COMMENT="A table for storing callback services.">
|
<TABLE NAME="local_webhooks_service" COMMENT="A table for storing callback services.">
|
||||||
<FIELDS>
|
<FIELDS>
|
||||||
@@ -7,6 +7,9 @@
|
|||||||
<FIELD NAME="enable" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" />
|
<FIELD NAME="enable" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" />
|
||||||
<FIELD NAME="title" TYPE="text" NOTNULL="true" SEQUENCE="false" />
|
<FIELD NAME="title" TYPE="text" NOTNULL="true" SEQUENCE="false" />
|
||||||
<FIELD NAME="url" TYPE="char" LENGTH="255" 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>
|
</FIELDS>
|
||||||
<KEYS>
|
<KEYS>
|
||||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
|
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
|
||||||
|
|||||||
+4
-3
@@ -59,8 +59,9 @@ if ($idediting = boolval($idservice)) {
|
|||||||
|
|
||||||
/* Processing of received data */
|
/* Processing of received data */
|
||||||
if ($data = $mform->get_data()) {
|
if ($data = $mform->get_data()) {
|
||||||
if (empty($data->enable)) {
|
/* Packing of data */
|
||||||
$data->enable = 0;
|
if (!empty($data->events)) {
|
||||||
|
$data->events = base64_encode(gzcompress(serialize($data->events), 9));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($idediting) {
|
if ($idediting) {
|
||||||
@@ -79,7 +80,7 @@ $PAGE->set_heading($titlepage);
|
|||||||
$PAGE->set_title($titlepage);
|
$PAGE->set_title($titlepage);
|
||||||
|
|
||||||
/* The page title */
|
/* The page title */
|
||||||
$PAGE->navbar->add(new lang_string("local", "moodle"));
|
$PAGE->navbar->add(new lang_string("localplugins", "moodle"));
|
||||||
$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"));
|
$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"));
|
||||||
$PAGE->navbar->add(new lang_string("managerservice", "local_webhooks"), $managerservice);
|
$PAGE->navbar->add(new lang_string("managerservice", "local_webhooks"), $managerservice);
|
||||||
$PAGE->navbar->add($titlepage);
|
$PAGE->navbar->add($titlepage);
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ $PAGE->set_title($titlepage);
|
|||||||
$PAGE->set_heading($titlepage);
|
$PAGE->set_heading($titlepage);
|
||||||
|
|
||||||
/* The page title */
|
/* The page title */
|
||||||
$PAGE->navbar->add(new lang_string("local", "moodle"));
|
$PAGE->navbar->add(new lang_string("localplugins", "moodle"));
|
||||||
$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"));
|
$PAGE->navbar->add(new lang_string("pluginname", "local_webhooks"));
|
||||||
$PAGE->navbar->add($titlepage, $baseurl);
|
$PAGE->navbar->add($titlepage, $baseurl);
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
|
|||||||
+3
-3
@@ -23,8 +23,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
defined("MOODLE_INTERNAL") || die();
|
defined("MOODLE_INTERNAL") || die();
|
||||||
$plugin->release = "0.1.0 (Build: 2017102500)";
|
$plugin->release = "0.4.0 (Build: 2017102620)";
|
||||||
$plugin->version = 2017102500;
|
$plugin->version = 2017102620;
|
||||||
$plugin->requires = 2016112900;
|
$plugin->requires = 2016112900;
|
||||||
$plugin->component = "local_webhooks";
|
$plugin->component = "local_webhooks";
|
||||||
$plugin->maturity = MATURITY_ALPHA;
|
$plugin->maturity = MATURITY_BETA;
|
||||||
Reference in New Issue
Block a user