-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod_notepad.php
More file actions
66 lines (50 loc) · 1.57 KB
/
mod_notepad.php
File metadata and controls
66 lines (50 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* @copyright @copyright Copyright (c) 2022 R2H (https://www.r2h.nl). All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
// no direct access
defined('_JEXEC') or die;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\Factory;
use \Joomla\CMS\Uri\Uri;
// get the user object
$user = Factory::getApplication()->getIdentity();
$isAdmin = false;
$hasRightToView = false;
$canEdit = false;
// If user is not logged in return
if ($user->guest) {
return;
}
// File path info
$location = $params->get('location', '');
$location = ltrim($location, '/');
$savePath = JPATH_SITE . '/' . $location;
$downloadPath = URI::root() . '/' . $location;
$file_info = pathinfo($savePath);
if (!is_dir($file_info['dirname'])) {
echo 'mod_notes has wrong directory path';
return;
}
// https://parsedown.org/
include_once('src/Parsedown.php');
$Parsedown = new Parsedown();
// Get the module settings
$groups = $params->get('usergroup', []);
// Check if user is Super Admin
$isAdmin = (bool) Factory::getApplication()->getIdentity()->authorise('core.admin');
// Check is the user has right to view
$hasRightToView = (bool) count(array_intersect($groups, $user->groups));
if ($isAdmin === true || $hasRightToView === true) {
$canEdit = true;
}
if (isset($_POST['text'])) {
$new_content = $_POST['text'];
file_put_contents($savePath, $new_content);
}
$fileContent = '';
if (file_exists($savePath)) {
$fileContent = file_get_contents ($savePath);
}
require ModuleHelper::getLayoutPath('mod_notepad', $params->get('layout', 'default'));