Skip to content

Commit

Permalink
Standalone option for Adminer. Propagate querystring to parent from A…
Browse files Browse the repository at this point in the history
…dminer iframe. Shift+Click to open links in full Adminer vs panel.
  • Loading branch information
adrianbj committed Apr 3, 2024
1 parent 50e4633 commit c9cb067
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 23 deletions.
19 changes: 18 additions & 1 deletion ProcessTracyAdminer.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,24 @@ public static function getModuleInfo() {
}

public function ___execute() {
return '<iframe src="'.str_replace('/adminer/', '/adminer-renderer/', wire('input')->url(true)).'" style="width:100%; height:calc(100vh - 25px); border: none; padding:0; margin:0;"></iframe>';

$data = wire('modules')->getModuleConfigData('TracyDebugger');

if($data['adminerStandAlone']) {
return $this->wire('modules')->get('ProcessTracyAdminerRenderer')->execute();
}
else {
// push querystring to parent window
return '
<script>
window.addEventListener("message", function(event) {
if(event.data != "") {
history.pushState(null, null, "?"+event.data);
}
});
</script>
<iframe src="'.str_replace('/adminer/', '/adminer-renderer/', $_SERVER['REQUEST_URI']).'" style="width:100%; height:calc(100vh - 25px); border: none; padding:0; margin:0;"></iframe>';
}
}

}
40 changes: 26 additions & 14 deletions TracyDebugger.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function getModuleInfo() {
'summary' => __('Tracy debugger from Nette with many PW specific custom tools.', __FILE__),
'author' => 'Adrian Jones',
'href' => 'https://processwire.com/talk/forum/58-tracy-debugger/',
'version' => '4.26.9',
'version' => '4.26.10',
'autoload' => 100000, // in PW 3.0.114+ higher numbers are loaded first - we want Tracy first
'singular' => true,
'requires' => 'ProcessWire>=2.7.2, PHP>=5.4.4',
Expand Down Expand Up @@ -254,8 +254,9 @@ static public function getDefaultData() {
"linksNewTab" => null,
"pWInfoPanelLinksNewTab" => null,
"customPWInfoPanelLinks" => array(11, 16, 22, 21, 29, 30, 31, 304),
"adminerThemeColor" => 'blue',
"adminerEditFieldLink" => 1,
"adminerStandAlone" => null,
"adminerThemeColor" => 'blue',
"adminerJsonMaxLevel" => 3,
"adminerJsonInTable" => 1,
"adminerJsonInEdit" => 1,
Expand Down Expand Up @@ -1148,10 +1149,12 @@ public function init() {
$event->page->addHookAfter('render', function($event) {
if(!$event->return) return;

$adminerModuleId = $this->wire('modules')->getModuleID("ProcessTracyAdminerRenderer");
$adminerRendererModuleId = $this->wire('modules')->getModuleID("ProcessTracyAdminerRenderer");
$adminerRendererUrl = $this->wire('pages')->get("process=$adminerRendererModuleId")->url;
$adminerModuleId = $this->wire('modules')->getModuleID("ProcessTracyAdminer");
$adminerUrl = $this->wire('pages')->get("process=$adminerModuleId")->url;

$event->return = str_replace("</body>", "<script>window.AdminerUrl = '".$adminerUrl."'; window.TracyMaxAjaxRows = ".$this->data['maxAjaxRows']."; window.TracyPanelZIndex = " . ($this->data['panelZindex'] + 1) . ";</script></body>", $event->return);
$event->return = str_replace("</body>", "<script>window.AdminerUrl = '".$adminerUrl."'; window.AdminerRendererUrl = '".$adminerRendererUrl."'; window.TracyMaxAjaxRows = ".$this->data['maxAjaxRows']."; window.TracyPanelZIndex = " . ($this->data['panelZindex'] + 1) . ";</script></body>", $event->return);

$tracyErrors = Debugger::getBar()->getPanel('Tracy:errors');
if(!is_array($tracyErrors->data) || count($tracyErrors->data) === 0) {
Expand Down Expand Up @@ -4033,26 +4036,35 @@ public function getModuleConfigInputfields(array $data) {
$fieldset->label = __('Adminer panel', __FILE__);
$wrapper->add($fieldset);

$f = $this->wire('modules')->get("InputfieldSelect");
$f->attr('name', 'adminerThemeColor');
$f->label = __('Theme color', __FILE__);
$f->addOption('blue', 'Blue');
$f->addOption('green', 'Green');
$f->addOption('orange', 'Orange');
$f->required = true;
$f->columnWidth = 50;
if($this->data['adminerThemeColor']) $f->attr('value', $this->data['adminerThemeColor']);
$f = $this->wire('modules')->get("InputfieldCheckbox");
$f->attr('name', 'adminerStandAlone');
$f->label = __('Standalone mode', __FILE__);
$f->description = __('Load Setup > Adminer in standalone mode.', __FILE__);
$f->notes = __('Adminer won\'t be embedded in PW admin via iframe.', __FILE__);
$f->columnWidth = 33;
$f->attr('checked', $this->data['adminerStandAlone'] == '1' ? 'checked' : '');
$fieldset->add($f);

$f = $this->wire('modules')->get("InputfieldCheckbox");
$f->attr('name', 'adminerEditFieldLink');
$f->label = __('Field edit links', __FILE__);
$f->description = __('Add adminer links to each field in the page edit interface.', __FILE__);
$f->notes = __('Will only appear when Adminer panel is enabled', __FILE__);
$f->columnWidth = 50;
$f->columnWidth = 34;
$f->attr('checked', $this->data['adminerEditFieldLink'] == '1' ? 'checked' : '');
$fieldset->add($f);

$f = $this->wire('modules')->get("InputfieldSelect");
$f->attr('name', 'adminerThemeColor');
$f->label = __('Theme color', __FILE__);
$f->addOption('blue', 'Blue');
$f->addOption('green', 'Green');
$f->addOption('orange', 'Orange');
$f->required = true;
$f->columnWidth = 33;
if($this->data['adminerThemeColor']) $f->attr('value', $this->data['adminerThemeColor']);
$fieldset->add($f);

$f = $this->wire('modules')->get("InputfieldText");
$f->attr('name', 'adminerJsonMaxLevel');
$f->label = __('JSON max level', __FILE__);
Expand Down
2 changes: 1 addition & 1 deletion panels/Adminer/plugins/AdminerProcessWireLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct($pwAdminUrl, $server = false, $db = false, $name = f
public function head() {
?>
<link rel="stylesheet" type="text/css" href="../../../site/modules/TracyDebugger/panels/Adminer/css/tweaks.css?v=1">
<script nonce="<?=get_nonce()?>" src="../../../site/modules/TracyDebugger/panels/Adminer/scripts/framed-check.js"></script>
<script nonce="<?=get_nonce()?>" src="../../../site/modules/TracyDebugger/panels/Adminer/scripts/main.js"></script>
<?php
}

Expand Down
1 change: 0 additions & 1 deletion panels/Adminer/scripts/framed-check.js

This file was deleted.

4 changes: 4 additions & 0 deletions panels/Adminer/scripts/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
document.documentElement.className += (window.self == window.top ? " top" : " framed");

const queryStr = new URLSearchParams(window.location.search).toString();
window.parent.postMessage(queryStr, "*");
6 changes: 3 additions & 3 deletions panels/AdminerPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function getTab() {

public function getPanel() {

$adminerModuleId = $this->wire('modules')->getModuleID("ProcessTracyAdminerRenderer");
$adminerUrl = $this->wire('pages')->get("process=$adminerModuleId")->url;
$adminerRendererModuleId = $this->wire('modules')->getModuleID("ProcessTracyAdminerRenderer");
$adminerRendererUrl = $this->wire('pages')->get("process=$adminerRendererModuleId")->url;
$contextLink = '';

if(\TracyDebugger::getDataValue('referencePageEdited') && $this->wire('input')->get('id') &&
Expand Down Expand Up @@ -128,7 +128,7 @@ public function getPanel() {
if($this->wire('modules')->isInstalled("ProcessTracyAdminer")) {
$out .= '
<div class="tracy-inner" style="padding: 0 !important">
<iframe id="adminer-iframe" src="'.$adminerUrl.'?iframe=1'.$contextLink.'" style="width:100%; height:calc(100% - 5px); border: none; padding:0; margin:0;"></iframe>';
<iframe id="adminer-iframe" src="'.$adminerRendererUrl.'?iframe=1'.$contextLink.'" style="width:100%; height:calc(100% - 5px); border: none; padding:0; margin:0;"></iframe>';
}
else {
$out .= '
Expand Down
9 changes: 6 additions & 3 deletions scripts/adminer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function openAdminer(queryStr) {
var url = window.AdminerUrl + "?" + queryStr;
var url = window.AdminerRendererUrl + "?" + queryStr;
if(document.getElementById("tracy-debug-panel-AdminerPanel").classList.contains("tracy-mode-window")) {
document.getElementById('adminer-iframe').src = url;
}
Expand All @@ -18,7 +18,6 @@ function openAdminer(queryStr) {
}
}
}

document.body.addEventListener("click", function(e) {
if(e.target) {
var curEl = e.target;
Expand All @@ -28,7 +27,11 @@ document.body.addEventListener("click", function(e) {
if(curEl && curEl.href && curEl.href.indexOf("adminer://") !== -1) {
e.preventDefault();
var queryStr = curEl.href.split('?')[1];
openAdminer(queryStr);
if (e.shiftKey) {
window.location = curEl.href.replace("adminer://", window.AdminerUrl);
} else {
openAdminer(queryStr);
}
}
}
});

0 comments on commit c9cb067

Please sign in to comment.