Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed

- Make the plugin compatible with the Content Security Policy

## [1.20.4] - 2026-11-05

### Fixed
Expand Down
5 changes: 1 addition & 4 deletions front/config.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@
} else {
Html::header(__s('Setup'), $_SERVER['PHP_SELF'], 'config', 'plugin');
// close frame if open
echo " <script type='text/javascript'>
if (top != self)
top.location = self.location;
</script>";
echo Html::scriptBlock('if (top != self) top.location = self.location;');
}

Html::footer();
6 changes: 3 additions & 3 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function plugin_treeview_uninstall()
function plugin_item_update_treeview($item)
{
if (in_array('locations_id', $item->updates)) {
echo "<script type='text/javascript'>parent.left.location.reload(true);</script>";
echo Html::scriptBlock('parent.left.location.reload(true);');
}
}

Expand All @@ -295,7 +295,7 @@ function plugin_item_update_treeview($item)
*/
function plugin_treeview_reload($item)
{
echo "<script type='text/javascript'>parent.left.location.reload(true);</script>";
echo Html::scriptBlock('parent.left.location.reload(true);');
}


Expand All @@ -306,6 +306,6 @@ function plugin_change_entity_Treeview()
&& (isset($_SESSION['glpi_plugin_treeview_loaded'])
&& $_SESSION['glpi_plugin_treeview_loaded'] == 1)
) {
echo "<script type='text/javascript'>parent.left.location.reload(true);</script>";
echo Html::scriptBlock('parent.left.location.reload(true);');
}
}
63 changes: 52 additions & 11 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
use Glpi\DBAL\QueryExpression;

use function Safe\json_encode;
use function Safe\ob_get_clean;
use function Safe\ob_start;

/**
* Contains the display configuration of the treeview
Expand Down Expand Up @@ -164,10 +166,8 @@ public function seeTreeview()
$CFG_GLPI['root_doc'] . "/pics/favicon.ico' >\n";

// Must be always the top window
echo '<script type="text/javascript">';
echo 'if (top != self)';
echo 'top.location = self.location;';
echo '</script></head>';
echo Html::scriptBlock('if (top != self) top.location = self.location;');
echo '</head>';
echo "<frameset cols='250,*'>";
echo "<frame src='" . $CFG_GLPI['root_doc'] . "/plugins/treeview/left.php' name='left' scrolling='yes'>";
echo "<frame src='" . $CFG_GLPI['root_doc'] . "/front/central.php' name='right'>";
Expand All @@ -185,10 +185,7 @@ public function seeTreeview()
**/
public function hideTreeview()
{
echo "<script type='text/javascript'>";
echo 'if (top != self)';
echo 'top.location = self.location;';
echo '</script>';
echo Html::scriptBlock('if (top != self) top.location = self.location;');
}

/**
Expand All @@ -205,13 +202,57 @@ public function buildTreeview()

//necessary files needed for the tree to work.
echo sprintf("<link rel='stylesheet' type='text/css' href='%s/css/dtree.css' type='text/css'>", $treeview_url);
echo sprintf("<script type='text/javascript' src='%s/lib/dtree/dtree.js'></script>", $treeview_url);
echo Html::script('/plugins/treeview/lib/dtree/dtree.js');

echo "<div class='dtree'>";
echo "<script type='text/javascript'>";
ob_start();
$this->getNodesFromDb();
echo '</script>';
echo Html::scriptBlock(ob_get_clean());
echo '</div>';

// dTree renders its links with inline handlers, rebind them once the tree is in the DOM
echo Html::scriptBlock(<<<'JS'
(function () {
var pattern = /^\s*javascript:\s*(\w+)\.([os])\((\d+)\);?\s*$/;
var takeCall = function (link, attribute) {
var match = (link.getAttribute(attribute) || '').match(pattern);
if (match !== null) {
link.removeAttribute(attribute);
}
return match;
};
var tree = document.querySelector('.dtree');
if (tree === null) {
return;
}
tree.querySelectorAll('a').forEach(function (link) {
var select = takeCall(link, 'onclick');
var toggle = takeCall(link, 'href');
if (toggle !== null) {
link.setAttribute('href', '#');
}
link.addEventListener('click', function (event) {
if (toggle !== null) {
event.preventDefault();
window[toggle[1]][toggle[2]](Number(toggle[3]));
}
if (select !== null) {
window[select[1]][select[2]](Number(select[3]));
}
});
if (link.hasAttribute('onmouseover')) {
link.removeAttribute('onmouseover');
link.removeAttribute('onmouseout');
link.addEventListener('mouseover', function () {
window.status = link.textContent;
});
link.addEventListener('mouseout', function () {
window.status = '';
});
}
});
})();
JS);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion public/left.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
echo '</div>';
echo '<div id=explorer_close>';

echo "<span role='button' name='explorer_close' class='btn btn-sm btn-ghost-secondary me-1 pe-2' onclick='parent.location.href = parent.right.location.href;''>";
echo "<span role='button' id='explorer_close_button' name='explorer_close' class='btn btn-sm btn-ghost-secondary me-1 pe-2'>";
echo "<i class='ti ti-square-rounded-x'></i>";
echo "</span>";
echo Html::scriptBlock('document.getElementById("explorer_close_button").addEventListener("click", () => { parent.location.href = parent.right.location.href; });');
echo '</div>';

echo '</div>';
Expand Down
1 change: 1 addition & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function plugin_version_treeview()
'license' => 'GPLv2+',
'author' => 'AL-Rubeiy Hussein, Xavier Caillaud, Nelly Mahu-Lasson',
'homepage' => 'https://forge.indepnet.net/projects/treeview',
'csp_compliant' => true,
'requirements' => [
'glpi' => [
'min' => PLUGIN_TREEVIEW_MIN_GLPI,
Expand Down
Loading