Skip to content

Commit 4aa0260

Browse files
committed
Extending case insensitive find & replace
Checking if we have a $_GET['target'] before use to avoid PHP notices findText is converted to lowercase Global case insensitive searching with regex in open documents Find/replace in filenames now compares in a case insensitive way Split the resultsDisplay generation onto 3 lines to make it easier to read Fixed issue with showing 'replace with xxx' when you're actually just finding
1 parent f24aaf1 commit 4aa0260

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

lib/multiple-results.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
</div>
1717
<?php if (isset($_GET['replace'])) { ?>
1818
<div class="replaceAll" id="replaceAll" onClick="<?php
19-
if (strpos($_GET['target'],"filenames")) {
19+
if (isset($_GET['target']) && strpos($_GET['target'],"filenames")) {
2020
echo 'renameAll()';
21-
} else if (strpos($_GET['target'],"files")) {
21+
} else if (isset($_GET['target']) && strpos($_GET['target'],"files")) {
2222
echo 'replaceInFilesAll()';
2323
} else {
2424
echo 'replaceAll()';
2525
}
26-
?>" style="opacity: 0.1"><?php echo strpos($_GET['target'],"filenames") ? 'rename all' : 'replace all';?></div>
26+
?>" style="opacity: 0.1"><?php echo isset($_GET['target']) && strpos($_GET['target'],"filenames") ? 'rename all' : 'replace all';?></div>
2727
<?php ;}; ?>
2828

2929
<script>
@@ -34,15 +34,15 @@
3434
var foundArray = [];
3535
foundInSelected = false;
3636
userTarget = top.document.findAndReplace.target.value;
37-
findText = top.findAndReplace.find.value;
37+
findText = top.findAndReplace.find.value.toLowerCase();
3838
<?php
3939
$findText = str_replace("ICEcoder:","",str_replace("&#39;","\'",$_GET['find']));
4040
// Find in open docs?
4141
if (!isset($_GET['target'])) {
4242
$targetName = "document";
4343
?>
4444
var startTab = top.ICEcoder.selectedTab;
45-
var rExp = new RegExp(findText,"g");
45+
var rExp = new RegExp(findText,"gi");
4646
for (var i=1;i<=top.ICEcoder.openFiles.length;i++) {
4747
top.ICEcoder.switchTab(i);
4848
var cM = top.ICEcoder.getcMInstance();
@@ -68,7 +68,7 @@
6868
var spansArray = top.ICEcoder.filesFrame.contentWindow.document.getElementsByTagName('span');
6969
for (var i=0;i<spansArray.length;i++) {
7070
targetURL = spansArray[i].id.replace(/\|/g,"/");
71-
if (targetURL.indexOf(findText)>-1 && targetURL.indexOf('_perms')>-1) {
71+
if (targetURL.toLowerCase().indexOf(findText.toLowerCase())>-1 && targetURL.indexOf('_perms')>-1) {
7272
if (userTarget.indexOf("selected")>-1) {
7373
for (var j=0;j<top.ICEcoder.selectedFiles.length;j++) {
7474
if (top.ICEcoder.selectedFiles[j].indexOf(targetURL.replace(/\//g,"|").replace(/_perms/g,""))>-1) {
@@ -77,8 +77,16 @@
7777
}
7878
}
7979
if (userTarget.indexOf("all")>-1 || (userTarget.indexOf("selected")>-1 && foundInSelected)) {
80-
resultsDisplay += '<a href="javascript:top.ICEcoder.openFile(\'<?php echo $docRoot;?>'+targetURL.replace(/\|/g,"/").replace(/_perms/g,"")+'\');top.ICEcoder.showHide(\'hide\',top.document.getElementById(\'blackMask\'))">'+ targetURL.replace(/\|/g,"/").replace(/_perms/g,"").replace(/<?php echo str_replace("/","\/",$findText); ?>/g,"<b>"+findText+"</b>")+ '</a><br><div id="foundCount'+i+'">'+spansArray[i].innerHTML+', rename to '+targetURL.replace(/\|/g,"/").replace(/_perms/g,"").replace(/<?php echo str_replace("/","\/",$findText); ?>/g,"<b><?php if(isset($_GET['replace'])) {echo strClean($_GET['replace']);};?></b>")+'</div>';
81-
<?php if (isset($_GET['replace'])) { ?>
80+
resultsDisplay += '<a href="javascript:top.ICEcoder.openFile(\'<?php echo $docRoot;?>'+targetURL.replace(/\|/g,"/").replace(/_perms/g,"")+'\');top.ICEcoder.showHide(\'hide\',top.document.getElementById(\'blackMask\'))">';
81+
resultsDisplay += targetURL.toLowerCase().replace(/\|/g,"/").replace(/_perms/g,"").replace(/<?php echo str_replace("/","\/",strtolower($findText)); ?>/g,"<b>"+findText.toLowerCase()+"</b>");
82+
resultsDisplay += '</a><br>';
83+
<?php if (!isset($_GET['replace'])) { ?>
84+
resultsDisplay += '<div id="foundCount'+i+'">'+spansArray[i].innerHTML+'</div>';
85+
<?php ;} else { ?>
86+
resultsDisplay += '<div id="foundCount'+i+'">'+spansArray[i].innerHTML+', rename to '+targetURL.toLowerCase().replace(/\|/g,"/").replace(/_perms/g,"").replace(/<?php echo str_replace("/","\/",strtolower($findText)); ?>/g,"<b><?php if(isset($_GET['replace'])) {echo strtolower(strClean($_GET['replace']));};?></b>")+'</div>';
87+
<?php
88+
;};
89+
if (isset($_GET['replace'])) { ?>
8290
resultsDisplay += '<div class="replace" id="replace" onClick="renameSingle('+i+');this.style.display=\'none\'">rename</div>';
8391
<?php ;}; ?>
8492
resultsDisplay += '<hr>';

0 commit comments

Comments
 (0)