Skip to content

Commit e31f435

Browse files
committed
Show editor and add functions to 2 x buttons
Include settings instead, plus CodeMirror lib and CSS Set some CSS classes, and CodeMirror CSS files Display clickable list of backups DIV container added for editor display and buttons Display CodeMirror instance and setup 2 x functions to open backup in new tab or diff pane
1 parent 80acab0 commit e31f435

1 file changed

Lines changed: 75 additions & 2 deletions

File tree

lib/backup-versions.php

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
// Load common functions
33
include("headers.php");
4-
include_once("settings-common.php");
4+
include("settings.php");
55
$text = $_SESSION['text'];
66
$t = $text['backup-versions'];
77

@@ -17,6 +17,30 @@
1717
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
1818
<meta name="robots" content="noindex, nofollow">
1919
<link rel="stylesheet" type="text/css" href="backup-versions.css?microtime=<?php echo microtime(true);?>">
20+
<link rel="stylesheet" href="../<?php echo $ICEcoder["codeMirrorDir"]; ?>/lib/codemirror.css?microtime=<?php echo microtime(true);?>">
21+
<script src="../<?php echo $ICEcoder["codeMirrorDir"]; ?>/lib/codemirror-compressed.js?microtime=<?php echo microtime(true);?>"></script>
22+
23+
<style type="text/css">
24+
.CodeMirror {position: absolute; width: 409px; height: 180px; font-size: <?php echo $ICEcoder["fontSize"];?>}
25+
.CodeMirror-scroll {overflow: hidden}
26+
/* Make sure this next one remains the 3rd item, updated with JS */
27+
.cm-tab {border-left-width: <?php echo $ICEcoder["visibleTabs"] ? "1px" : "0";?>; margin-left: <?php echo $ICEcoder["visibleTabs"] ? "-1px" : "0";?>; border-left-style: solid; border-left-color: rgba(255,255,255,0.2)}
28+
</style>
29+
<link rel="stylesheet" href="editor.css?microtime=<?php echo microtime(true);?>">
30+
<?php
31+
$themeArray = array();
32+
$handle = opendir('../'.$ICEcoder["codeMirrorDir"].'/theme/');
33+
34+
while (false !== ($cssFile = readdir($handle))) {
35+
if ($cssFile !== "." && $cssFile != "..") {
36+
array_push($themeArray,basename($cssFile,".css"));
37+
}
38+
}
39+
sort($themeArray);
40+
for ($i=0;$i<count($themeArray);$i++) {
41+
echo '<link rel="stylesheet" href="../'.$ICEcoder["codeMirrorDir"].'/theme/'.$themeArray[$i].'.css?microtime='.microtime(true).'">'.PHP_EOL;
42+
}
43+
?>
2044
</head>
2145

2246
<body class="backup-versions">
@@ -25,20 +49,69 @@
2549
<h2><?php echo $file;?></h2>
2650

2751
<br>
52+
<div style="display: inline-block">
2853
<?php
2954
$dateCounts = $fileCountInfo['dateCounts'];
3055
$displayVersions = $versions;
3156

57+
// Establish the base, host and date dir parts...
58+
$backupDirHost = isset($ftpSite) ? parse_url($ftpSite,PHP_URL_HOST) : "localhost";
59+
3260
foreach ($dateCounts as $key => $value) {
3361
echo "<b>".date("jS M Y",strtotime($key))." (".$value." ".($value != 1 ? $t["backups"] : $t["backup"]).")</b>";
3462
echo '<br>';
3563
for ($j=0; $j<$value; $j++) {
36-
echo "Backup ".$displayVersions.'<br>';
64+
echo '<a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fbackup-versions-preview-loader.php%3Ffile%3D%3C%2Fspan%3E%3Cspan+class%3D"x">'.str_replace("/","|",$backupDirHost.'/'.$key.$file).' ('.$displayVersions.')&csrf='.$_SESSION['csrf'].'" target="previewLoader">Backup '.$displayVersions.'<br>';
3765
$displayVersions--;
3866
}
3967
echo '<br>';
4068
}
4169
?>
70+
</div>
71+
<div style="display: inline-block; height: 300px; width: 400px; margin-left: 30px">
72+
<textarea id="code" name="code">Click a backup to the left to preview it</textarea>
73+
</div>
74+
<div style="display: none; width: 180px; margin-left: 30px" id="buttonsContainer">
75+
<div class="button" onclick="openNew()">Open in new tab</div>
76+
<div class="button" onclick="openDiff()">Open in diff mode</div>
77+
<!--
78+
<div class="button" onclick="alert('Function not available yet - Coming in v5.4')">Restore as new version</div>
79+
//-->
80+
</div>
81+
<div style="display: none">
82+
<iframe name="previewLoader"></iframe>
83+
</div>
84+
85+
<script>
86+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
87+
lineNumbers: true,
88+
readOnly: "nocursor",
89+
indentUnit: top.ICEcoder.indentSize,
90+
tabSize: top.ICEcoder.indentSize,
91+
mode: "javascript",
92+
theme: "<?php echo $ICEcoder["theme"]=="default" ? 'icecoder' : $ICEcoder["theme"];?>"
93+
});
94+
editor.setSize("400px","330px");
95+
96+
var openNew = function() {
97+
var cM;
98+
99+
top.ICEcoder.showHide('hide',top.document.getElementById('blackMask'))
100+
top.ICEcoder.newTab();
101+
cM = top.ICEcoder.getcMInstance();
102+
cM.setValue(editor.getValue());
103+
}
104+
105+
var openDiff = function() {
106+
var cMDiff;
107+
108+
top.ICEcoder.showHide('hide',top.document.getElementById('blackMask'))
109+
top.ICEcoder.setSplitPane('on');
110+
cMDiff = top.ICEcoder.getcMdiffInstance();
111+
top.ICEcoder.focus('diff');
112+
cMDiff.setValue(editor.getValue());
113+
}
114+
</script>
42115

43116
</body>
44117

0 commit comments

Comments
 (0)