Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit fcd2e51

Browse files
author
mattpass
committed
Fixed filename links to work, regex find & replace bold, simpler code
1 parent 94438fa commit fcd2e51

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lib/multiple-results.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
haveMatch = true;
102102
}
103103
if (
104-
// TODO: Find in filenames not working with regex, see all instances of findText and $findText below
105104
true === haveMatch && -1 < targetURL.indexOf('_perms')) {
106105
if (-1 < userTarget.indexOf("selected")) {
107106
for (let j = 0; j < parent.ICEcoder.selectedFiles.length; j++) {
@@ -123,23 +122,25 @@
123122
if (-1 < targetURLElem.parentNode.parentNode.className.indexOf('pft-directory')) {
124123
continue;
125124
}
125+
const tidiedFileName = targetURLDisplay.replace(/\|/g, "/").replace(/_perms/g, "");
126126
resultsDisplay +=
127127
'<a href="javascript:parent.ICEcoder.openFile(\'<?php echo $docRoot;?>' +
128-
targetURLDisplay.replace(/\|/g, "/").replace(/_perms/g,"") +
128+
tidiedFileName +
129129
'\');parent.ICEcoder.goFindAfterOpenInt = setInterval(function(){goFindAfterOpen(\'<?php echo $docRoot;?>' +
130-
targetURLDisplay.replace(/\|/g, "/").replace(/_perms/g, "") +
130+
tidiedFileName +
131131
'\')}, 20);parent.ICEcoder.showHide(\'hide\', parent.document.getElementById(\'blackMask\'))">';
132-
// TODO: get this line working
133-
resultsDisplay +=
134-
targetURLDisplay.replace(/\|/g, "/").replace(/_perms/g, "").replace(/<?php
135-
echo str_replace("/", "\/",strtolower(preg_quote($findText))); ?>/g, "<b>" +
136-
parent.ICEcoder.xssClean(findText).toLowerCase() + "</b>");
137-
resultsDisplay += '</a><br>';
132+
133+
134+
// Highlight our matches in filename via single regex () capturing group to use with $1
135+
const re = /(<?php echo str_replace("/", "\/",xssClean($findText, 'script')); ?>)/gi;
136+
resultsDisplay += tidiedFileName.replace(re, '<b>$1</b>') + '</a><br>';
137+
138+
// If replacing in filename
138139
<?php if (true === isset($_GET['replace'])) { ?>
139140
resultsDisplay +=
140141
'<div id="foundCount' + i + '">' +
141142
'<?php echo $t['rename to'];?> ' +
142-
targetURL.replace(/\|/g, "/").replace(/_perms/g, "").replace(/<?php echo str_replace("/", "\/",strtolower(preg_quote($findText))); ?>/g,"<b><?php
143+
tidiedFileName.replace(re, "<b><?php
143144
if (isset($_GET['replace'])) {echo str_replace("&amp;", "&", xssClean($_GET['replace'], 'script'));};
144145
?></b>")+'</div>';
145146
<?php
@@ -178,7 +179,7 @@ function phpGrep($q, $path, $base) {
178179
}
179180
// Exclude the dirs/files we wish to exclude from find & replace tasks (string in path name)
180181
for ($i = 0; $i < count($ICEcoder['findFilesExclude']); $i++) {
181-
if (false !== strpos($fullpath, str_replace("*", "", $ICEcoder['findFilesExclude'][$i]))) {
182+
if (false !== strpos($fullPath, str_replace("*", "", $ICEcoder['findFilesExclude'][$i]))) {
182183
$bFile = true;
183184
};
184185
}
@@ -234,7 +235,7 @@ function phpGrep($q, $path, $base) {
234235
targetName = "<?php echo $targetName;?>";
235236
selectedText = foundInSelected ? "<?php echo $t['selected'];?> " : "";
236237
document.getElementById('title').innerHTML =
237-
findText.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;") +
238+
parent.ICEcoder.xssClean(findText) +
238239
" <?php echo $t['found in'];?> " + foundArray.length + " " + selectedText + targetName + plural;
239240
document.getElementById('results').innerHTML = resultsDisplay;
240241

0 commit comments

Comments
 (0)