Skip to content

Commit

Permalink
Added code for clear cache and open screen
Browse files Browse the repository at this point in the history
  • Loading branch information
anayleeloolxp committed Dec 13, 2024
1 parent 87de2a8 commit 9b4d6e1
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 28 deletions.
45 changes: 45 additions & 0 deletions clearcache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Clear Cache file
*
* @package local_leeloolxpcontentapi
* @copyright 2024 Leeloo LXP (https://leeloolxp.com)
* @author Leeloo LXP <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


require_once('../../config.php');
require_once($CFG->libdir . '/adminlib.php');

// Basic security check to ensure the request is coming from an allowed source
$allowed_ips = ['51.159.101.252', '51.159.14.97']; // Add your Laravel server's IP here
if (!in_array($_SERVER['REMOTE_ADDR'], $allowed_ips)) {
header("HTTP/1.0 403 Forbidden");
echo "Access denied";
exit;
}

try {
$selected = array("other" => 1, "muc" => 1);
purge_caches($selected);
echo json_encode(['status' => 'success', 'message' => 'Cache cleared successfully']);
} catch (Exception $e) {
header("HTTP/1.0 500 Internal Server Error");
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
23 changes: 20 additions & 3 deletions js/local_leeloolxpcontentapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ function setLeeloolxpUrl(Y, leeloolxpUrl) {
}

require(["jquery"], function ($) {

function utf8_to_b64(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
function toSolidBytes(match, p1) {
return String.fromCharCode('0x' + p1);
}));
}

// And for decoding, use this function
function b64_to_utf8(str) {
return decodeURIComponent(atob(str).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}

$("#local_leeloolxpcontentapi_wrapper_close").click(function () {
$(".local_leeloolxpcontentapi_wrapper").removeClass("open");

Expand Down Expand Up @@ -44,8 +59,11 @@ require(["jquery"], function ($) {
let cmid = $("#leeloolxpcontentapi-js-vars").data("cmid");
let sectionid = $("#leeloolxpcontentapi-js-vars").data("sectionid");
let courseid = $("#leeloolxpcontentapi-js-vars").data("courseid");
let openpage = $("#leeloolxpcontentapi-js-vars").data("openpage");
let lang = $("#leeloolxpcontentapi-js-vars").data("lang");



var mootoolsresponseDe = JSON.parse(atob(mootoolsresponse));
if( lang != '' ){
mootoolsresponseDe.lang = lang;
Expand All @@ -54,11 +72,10 @@ require(["jquery"], function ($) {
mootoolsresponseDe.cmid = cmid;
mootoolsresponseDe.sectionid = sectionid;
mootoolsresponseDe.courseid = courseid;
mootoolsresponseDe.openpage = openpage;
mootoolsresponseDe.baseurl = mootoolsleeloourldecoded + '/';

var mootoolsresponseUp = btoa(JSON.stringify(mootoolsresponseDe));

console.log("Leeloo LXP URL:", window.leeloolxpUrl);
var mootoolsresponseUp = utf8_to_b64(JSON.stringify(mootoolsresponseDe));

leeloolxpssourl =
window.leeloolxpUrl + "?mootoolsleeloourl=" +
Expand Down
56 changes: 33 additions & 23 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ function local_leeloolxpcontentapi_before_footer() {
$mootoolsloginresponse = $_COOKIE['mootools_login_response'];
$mootoolsloginresponsearr = json_decode($mootoolsloginresponse);
$mootoolstoken = $mootoolsloginresponsearr->token;
$sendcmid = $mootoolsloginresponsearr->cmid;
}

$openpage = 'home';

if ($mootoolsenable && $mootoolsleeloourl && $mootoolstoken) {
global $USER, $DB;
if (isloggedin() && !is_siteadmin($USER)) {
Expand All @@ -44,10 +47,12 @@ function local_leeloolxpcontentapi_before_footer() {

$context = $PAGE->context;

if ($context && $context->contextlevel == CONTEXT_MODULE) {
//$sendcmid = 0;
$sendsectionid = 0;
$sendcourseid = 0;

if ($context && $context->contextlevel == CONTEXT_MODULE) {
$cmid = $context->instanceid;

$module = get_coursemodule_from_id('', $cmid, 0, false, MUST_EXIST);

$sectionid = $module->section;
Expand All @@ -68,35 +73,40 @@ function local_leeloolxpcontentapi_before_footer() {

if (isset($res_arr->status) && isset($res_arr->status) != '') {
if ($res_arr->status == 'success') {
$sendcmid = $cmid;
$sendsectionid = $sectionid;
$sendcourseid = $courseid;
$openpage = 'chat';
}
}
}


$user_lang = $DB->get_record_sql(
'SELECT u.lang AS preferred_language
$user_lang = $DB->get_record_sql(
'SELECT u.lang AS preferred_language
FROM {user} u
WHERE u.id = :userid',
['userid' => $USER->id]
);
['userid' => $USER->id]
);

if ($user_lang) {
$preferred_language = $user_lang->preferred_language;
} else {
$preferred_language = "";
}
if ($user_lang) {
$preferred_language = $user_lang->preferred_language;
} else {
$preferred_language = "";
}

echo '<div id="leeloolxpcontentapi-js-vars" data-mootoolsleeloourl="' . base64_encode($mootoolsleeloourl) . '" data-mootoolstoken="' . $mootoolstoken . '" data-lang="' . $preferred_language . '" data-cmid="' . $cmid . '" data-sectionid="' . $sectionid . '" data-courseid="' . $courseid . '" data-mootoolsloginresponse="' . base64_encode($mootoolsloginresponse) . '"></div>';
echo '<div id="leeloolxpcontentapi-js-vars" data-mootoolsleeloourl="' . base64_encode($mootoolsleeloourl) . '" data-mootoolstoken="' . $mootoolstoken . '" data-lang="' . $preferred_language . '" data-cmid="' . $sendcmid . '" data-sectionid="' . $sendsectionid . '" data-courseid="' . $sendcourseid . '" data-openpage="' . $openpage . '" data-mootoolsloginresponse="' . base64_encode($mootoolsloginresponse) . '"></div>';

$buildtype = get_config('local_leeloolxpcontentapi', 'buildtype');
$leeloolxpUrl = ($buildtype === 'development') ? 'https://ivxdev.wespher.com' : 'https://ivx.wespher.com';
$buildtype = get_config('local_leeloolxpcontentapi', 'buildtype');
$leeloolxpUrl = ($buildtype === 'development') ? 'https://ivxdev.wespher.com' : 'https://ivx.wespher.com';

// Pass the URL to JavaScript
$PAGE->requires->js_init_call('setLeeloolxpUrl', array($leeloolxpUrl));
// Pass the URL to JavaScript
$PAGE->requires->js_init_call('setLeeloolxpUrl', array($leeloolxpUrl));

$PAGE->requires->js(new moodle_url('/local/leeloolxpcontentapi/js/local_leeloolxpcontentapi.js'));
$logoUrl = new moodle_url('/local/leeloolxpcontentapi/images/logo.png');
echo '<button id="local_leeloolxpcontentapi_button"><img src="' . $logoUrl . '" style="width: 100%;height: auto;"></button>';
echo '<div class="local_leeloolxpcontentapi_wrapper"><div id="local_leeloolxpcontentapi_wrapper_close">X</div><div id="local_leeloolxpcontentapi_frame"></div></div>';
}
}
}
$PAGE->requires->js(new moodle_url('/local/leeloolxpcontentapi/js/local_leeloolxpcontentapi.js'));
$logoUrl = new moodle_url('/local/leeloolxpcontentapi/images/logo.png');
echo '<button id="local_leeloolxpcontentapi_button"><img src="' . $logoUrl . '" style="width: 100%;height: auto;"></button>';
echo '<div class="local_leeloolxpcontentapi_wrapper"><div id="local_leeloolxpcontentapi_wrapper_close">X</div><div id="local_leeloolxpcontentapi_frame"></div></div>';
}
}
}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'local_leeloolxpcontentapi';
$plugin->release = '1.0.1';
$plugin->version = 2024021202;
$plugin->release = '1.0.4';
$plugin->version = 2024021204;
$plugin->requires = 2019052000;
$plugin->maturity = MATURITY_STABLE;

0 comments on commit 9b4d6e1

Please sign in to comment.