Skip to content

Commit

Permalink
Various fixes for protocol handler loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbj committed Nov 28, 2024
1 parent ec33e65 commit b76e357
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 104 deletions.
100 changes: 51 additions & 49 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.44',
'version' => '4.26.45',
'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 @@ -1022,6 +1022,52 @@ public function init() {
if(method_exists('Tracy\Debugger', 'getFireLogger')) Debugger::$showFireLogger = $this->data['showFireLogger'];
if(isset(Debugger::$reservedMemorySize)) Debugger::$reservedMemorySize = $this->data['reservedMemorySize'];

// EDITOR PROTOCOL HANDLER
// build up array of replacements to pass to Debugger::$editorMapping
// they have to be completely separate replacements because Tracy uses strtr()
// which won't replace the same substring more than once
$mappingReplacements = array();
$compilerCachePath = isset($this->wire('config')->fileCompilerOptions['cachePath']) && $this->wire('config')->fileCompilerOptions['cachePath'] != '' ? $this->wire('config')->fileCompilerOptions['cachePath'] : $this->wire('config')->paths->cache . 'FileCompiler/';
$compilerCachePath = str_replace('/', DIRECTORY_SEPARATOR, $compilerCachePath);

static::$useOnlineEditor = (static::$allowedSuperuser || self::$validLocalUser || self::$validSwitchedUser) &&
(static::$isLocal && in_array('local', $this->data['useOnlineEditor'])) ||
(!static::$isLocal && in_array('live', $this->data['useOnlineEditor']) ||
(isset(static::$showPanels) && in_array('fileEditor', static::$showPanels) && $this->data['forceEditorLinksToTracy'])
);

if(static::$useOnlineEditor) {
if($this->data['onlineEditor'] == 'processFileEdit' &&
$this->wire('modules')->isInstalled('ProcessFileEdit') &&
$this->wire('user')->hasPermission('file-edit'))
{
static::$onlineEditor = 'processFileEdit';
Debugger::$editor = $this->wire('config')->urls->admin . 'setup/file-editor/?f=%file&l=%line';
$processFileEditSettings = $this->wire('modules')->getModuleConfigData('ProcessFileEdit');
static::$onlineFileEditorDirPath = $processFileEditSettings['dirPath'];
}
else {
static::$onlineEditor = 'tracy';
Debugger::$editor = 'tracy://?f=%file&l=%line';
static::$onlineFileEditorDirPath = $this->wire('config')->paths->root;
}
$mappingReplacements[$compilerCachePath . str_replace($this->wire('config')->paths->root,'' , static::$onlineFileEditorDirPath)] = '';
$mappingReplacements[static::$onlineFileEditorDirPath] = '';
}
else {
Debugger::$editor = $this->data['editor'];

if($this->data['localRootPath'] != '') {
$mappingReplacements[$compilerCachePath] = $this->data['localRootPath'];
$mappingReplacements[$this->wire('config')->paths->root] = $this->data['localRootPath'];
}
else {
$mappingReplacements[$compilerCachePath] = $this->wire('config')->paths->root;
}
}

Debugger::$editorMapping = $mappingReplacements;

if(static::$allowedTracyUser === 'development') {

// TRACY TOGGLER
Expand All @@ -1042,53 +1088,6 @@ public function init() {

if(Debugger::$showBar) {

// EDITOR PROTOCOL HANDLER
// build up array of replacements to pass to Debugger::$editorMapping
// they have to be completely separate replacements because Tracy uses strtr()
// which won't replace the same substring more than once
$mappingReplacements = array();
$compilerCachePath = isset($this->wire('config')->fileCompilerOptions['cachePath']) && $this->wire('config')->fileCompilerOptions['cachePath'] != '' ? $this->wire('config')->fileCompilerOptions['cachePath'] : $this->wire('config')->paths->cache . 'FileCompiler/';
$compilerCachePath = str_replace('/', DIRECTORY_SEPARATOR, $compilerCachePath);

static::$useOnlineEditor = (static::$allowedSuperuser || self::$validLocalUser || self::$validSwitchedUser) &&
(static::$isLocal && in_array('local', $this->data['useOnlineEditor'])) ||
(!static::$isLocal && in_array('live', $this->data['useOnlineEditor']) ||
(in_array('fileEditor', static::$showPanels) && $this->data['forceEditorLinksToTracy'])
);

if(static::$useOnlineEditor) {
if($this->data['onlineEditor'] == 'processFileEdit' &&
$this->wire('modules')->isInstalled('ProcessFileEdit') &&
$this->wire('user')->hasPermission('file-edit'))
{
static::$onlineEditor = 'processFileEdit';
Debugger::$editor = $this->wire('config')->urls->admin . 'setup/file-editor/?f=%file&l=%line';
$processFileEditSettings = $this->wire('modules')->getModuleConfigData('ProcessFileEdit');
static::$onlineFileEditorDirPath = $processFileEditSettings['dirPath'];
}
else {
static::$onlineEditor = 'tracy';
Debugger::$editor = 'tracy://?f=%file&l=%line';
static::$onlineFileEditorDirPath = $this->wire('config')->paths->root;
}
$mappingReplacements[$compilerCachePath . str_replace($this->wire('config')->paths->root,'' , static::$onlineFileEditorDirPath)] = '';
$mappingReplacements[static::$onlineFileEditorDirPath] = '';
}
else {
Debugger::$editor = $this->data['editor'];

if($this->data['localRootPath'] != '') {
$mappingReplacements[$compilerCachePath] = $this->data['localRootPath'];
$mappingReplacements[$this->wire('config')->paths->root] = $this->data['localRootPath'];
}
else {
$mappingReplacements[$compilerCachePath] = $this->wire('config')->paths->root;
}
}

Debugger::$editorMapping = $mappingReplacements;


//CUSTOM CSS & JS
Debugger::$customCssFiles = array(
$this->wire('config')->paths->TracyDebugger.'styles/styles.css'
Expand Down Expand Up @@ -1365,7 +1364,10 @@ function bsZIndex() {
}

if(!$this->wire('input')->cookie->tracyHidden) {
Debugger::$customJsStr .= 'document.body.classList.add("has-tracy-debugbar");';
Debugger::$customJsStr .= '
document.addEventListener("DOMContentLoaded", function() {
document.body.classList.add("has-tracy-debugbar");
});';
}

}
Expand Down
31 changes: 17 additions & 14 deletions scripts/adminer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ function openAdminer(queryStr) {
}
}
}
document.body.addEventListener("click", function(e) {
if(e.target) {
var curEl = e.target;
while(curEl && curEl.tagName != "A") {
curEl = curEl.parentNode;
}
if(curEl && curEl.href && curEl.href.indexOf("adminer://") !== -1) {
e.preventDefault();
var queryStr = curEl.href.split('?')[1];
if (e.shiftKey) {
window.location = curEl.href.replace("adminer://", window.AdminerUrl);
} else {
openAdminer(queryStr);

document.addEventListener('DOMContentLoaded', function() {
document.body.addEventListener("click", function(e) {
if(e.target) {
var curEl = e.target;
while(curEl && curEl.tagName != "A") {
curEl = curEl.parentNode;
}
if(curEl && curEl.href && curEl.href.indexOf("adminer://") !== -1) {
e.preventDefault();
var queryStr = curEl.href.split('?')[1];
if (e.shiftKey) {
window.location = curEl.href.replace("adminer://", window.AdminerUrl);
} else {
openAdminer(queryStr);
}
}
}
}
});
});
49 changes: 26 additions & 23 deletions scripts/exception-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,34 @@ if(!tracyExceptionLoader) {
}
};

// click event added to body because of links on bluescreen
document.body.addEventListener("click", function(e) {
if(e.target) {
var curEl = e.target;
while(curEl && curEl.tagName != "A") {
curEl = curEl.parentNode;
}
if(curEl && curEl.href && curEl.href.indexOf("tracyexception://") !== -1) {
e.preventDefault();
var queryStr = curEl.href.split('?')[1];
var fullFilePath = tracyExceptionLoader.getFileLineVars(queryStr, "f");
tracyExceptionLoader.loadExceptionFile(fullFilePath);
}
document.addEventListener('DOMContentLoaded', function() {
// click event added to body because of links on bluescreen
const htmlElement = document.documentElement;
var doc = htmlElement.classList.contains('tracy-bs-visible') ? document.body : document;
doc.addEventListener("click", function(e) {
if(e.target) {
var curEl = e.target;
while(curEl && curEl.tagName != "A") {
curEl = curEl.parentNode;
}
if(curEl && curEl.href && curEl.href.indexOf("tracyexception://") !== -1) {
e.preventDefault();
var queryStr = curEl.href.split('?')[1];
var fullFilePath = tracyExceptionLoader.getFileLineVars(queryStr, "f");
tracyExceptionLoader.loadExceptionFile(fullFilePath);
}

let tracyExceptionFiles = document.getElementById("tracyExceptionFiles");
if(tracyExceptionFiles) {
let tracyExceptions = tracyExceptionFiles.getElementsByTagName("li");
var length = tracyExceptions.length;
for (var i = 0; i < length; i++) {
var queryStr = tracyExceptions[i].getElementsByTagName("a")[0].href.split('?')[1];
var currentFilePath = decodeURI(queryStr.replace('f=','').replace('&l=1','')).replace('site/assets/logs/tracy/', '');
tracyExceptions[i].getElementsByTagName("a")[0].className = document.getElementById('panelTitleFilePath').innerHTML == currentFilePath ? "active" : "";
let tracyExceptionFiles = document.getElementById("tracyExceptionFiles");
if(tracyExceptionFiles) {
let tracyExceptions = tracyExceptionFiles.getElementsByTagName("li");
var length = tracyExceptions.length;
for (var i = 0; i < length; i++) {
var queryStr = tracyExceptions[i].getElementsByTagName("a")[0].href.split('?')[1];
var currentFilePath = decodeURI(queryStr.replace('f=','').replace('&l=1','')).replace('site/assets/logs/tracy/', '');
tracyExceptions[i].getElementsByTagName("a")[0].className = document.getElementById('panelTitleFilePath').innerHTML == currentFilePath ? "active" : "";
}
}
}
}
});
});

}
32 changes: 18 additions & 14 deletions scripts/file-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,26 @@ if(!tracyFileEditorLoader) {
};
tracyFileEditorLoader.initializeEditor();

// click event added to body because of links on bluescreen
document.body.addEventListener("click", function(e) {
if(e.target) {
var curEl = e.target;
while(curEl && curEl.tagName != "A") {
curEl = curEl.parentNode;
}
if(curEl && curEl.href && curEl.href.indexOf("tracy://") !== -1) {
e.preventDefault();
var queryStr = curEl.href.split('?')[1];
var fullFilePath = tracyFileEditorLoader.getFileLineVars(queryStr, "f");
tracyFileEditorLoader.loadFileEditor(fullFilePath, tracyFileEditorLoader.getFileLineVars(queryStr, "l"));
document.addEventListener('DOMContentLoaded', function() {
// click event added to body because of links on bluescreen
const htmlElement = document.documentElement;
var doc = htmlElement.classList.contains('tracy-bs-visible') ? document.body : document;
doc.addEventListener("click", function(e) {
if(e.target) {
var curEl = e.target;
while(curEl && curEl.tagName != "A") {
curEl = curEl.parentNode;
}
if(curEl && curEl.href && curEl.href.indexOf("tracy://") !== -1) {
e.preventDefault();
var queryStr = curEl.href.split('?')[1];
var fullFilePath = tracyFileEditorLoader.getFileLineVars(queryStr, "f");
tracyFileEditorLoader.loadFileEditor(fullFilePath, tracyFileEditorLoader.getFileLineVars(queryStr, "l"));

tracyFileEditorLoader.addRecentlyOpenedFile(fullFilePath);
tracyFileEditorLoader.addRecentlyOpenedFile(fullFilePath);

}
}
}
});
});
}
2 changes: 1 addition & 1 deletion tracy-2.10.x/src/Tracy/Debugger/DeferredContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private function buildJsCss(): string

if(Debugger::$customJsStr) $str .= Debugger::$customJsStr;

if(Debugger::$customBodyStr) $str .= "(function(){var el = document.createElement('div'); el.className='tracy-debug'; el.innerHTML='".preg_replace('#\s+#u', ' ', Debugger::$customBodyStr)."'; document.body.appendChild(el);})();\n";
if(Debugger::$customBodyStr) $str .= "(function(){var el = document.createElement('div'); el.className='tracy-debug'; el.innerHTML='".preg_replace('#\s+#u', ' ', Debugger::$customBodyStr)."'; document.addEventListener('DOMContentLoaded', function() { document.body.appendChild(el);});})();\n";

return $str;
}
Expand Down
2 changes: 1 addition & 1 deletion tracy-2.5.x/src/Tracy/Bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,6 @@ private function renderAssets()

if(Debugger::$customJsStr) echo Debugger::$customJsStr;

if(Debugger::$customBodyStr) echo "(function(){var el = document.createElement('div'); el.className='tracy-debug'; el.innerHTML='".preg_replace('#\s+#u', ' ', Debugger::$customBodyStr)."'; document.body.appendChild(el);})();\n";
if(Debugger::$customBodyStr) echo "(function(){var el = document.createElement('div'); el.className='tracy-debug'; el.innerHTML='".preg_replace('#\s+#u', ' ', Debugger::$customBodyStr)."'; document.addEventListener('DOMContentLoaded', function() { document.body.appendChild(el);});})();\n";
}
}
2 changes: 1 addition & 1 deletion tracy-2.7.x/src/Tracy/Bar/Bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private function renderAssets(): void

if(Debugger::$customJsStr) echo Debugger::$customJsStr;

if(Debugger::$customBodyStr) echo "(function(){var el = document.createElement('div'); el.className='tracy-debug'; el.innerHTML='".preg_replace('#\s+#u', ' ', Debugger::$customBodyStr)."'; document.body.appendChild(el);})();\n";
if(Debugger::$customBodyStr) echo "(function(){var el = document.createElement('div'); el.className='tracy-debug'; el.innerHTML='".preg_replace('#\s+#u', ' ', Debugger::$customBodyStr)."'; document.addEventListener('DOMContentLoaded', function() { document.body.appendChild(el);});})();\n";

}
}
2 changes: 1 addition & 1 deletion tracy-2.9.x/src/Tracy/Debugger/DeferredContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private function buildJsCss(): string

if(Debugger::$customJsStr) $str .= Debugger::$customJsStr;

if(Debugger::$customBodyStr) $str .= "(function(){var el = document.createElement('div'); el.className='tracy-debug'; el.innerHTML='".preg_replace('#\s+#u', ' ', Debugger::$customBodyStr)."'; document.body.appendChild(el);})();\n";
if(Debugger::$customBodyStr) $str .= "(function(){var el = document.createElement('div'); el.className='tracy-debug'; el.innerHTML='".preg_replace('#\s+#u', ' ', Debugger::$customBodyStr)."'; document.addEventListener('DOMContentLoaded', function() { document.body.appendChild(el);});})();\n";

return $str;
}
Expand Down

0 comments on commit b76e357

Please sign in to comment.