This repository was archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
128 lines (111 loc) · 4.48 KB
/
index.php
File metadata and controls
128 lines (111 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
declare(strict_types=1);
/*
* AUTHOR : AVONTURE Christophe
*
* Written date : 9 october 2018
*
* Interface allowing to copy a non formatted SQL statement (in one line) and
* get a SQL statement that is formatted (on multiple lines) and using color
* syntaxing. *
*
* @see SQL-Formatter on https://github.com/jdorn/sql-formatter
*/
define('REPO', 'https://github.com/cavo789/sql_formatter');
$task = filter_input(INPUT_POST, 'task', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if ('format' == $task) {
// Retrieve the SQL statement
$SQL = base64_decode(filter_input(INPUT_POST, 'sql', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
// Include the library
require_once __DIR__ . '/lib/SqlFormatter.php';
// Return the formatted SQL
header('Content-Type: text/html');
echo SqlFormatter::format($SQL);
die();
}
// Sample values
$SQL = 'SELECT LAT_N, CITY, TEMP_F FROM STATS, STATION ' .
'WHERE MONTH = 7 AND STATS.ID = STATION.ID ORDER BY TEMP_F';
// Get the GitHub corner
$github = '';
if (is_file($cat = __DIR__ . DIRECTORY_SEPARATOR . 'octocat.tmpl')) {
$github = str_replace('%REPO%', REPO, file_get_contents($cat));
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="author" content="Christophe Avonture" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8;" />
<title>SQL Formatter</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
</head>
<body>
<?php echo $github; ?>
<div class="container">
<div class="page-header">
<h1>SQL Formatter</h1>
</div>
<div class="container">
<details>
<summary>How to use?</summary>
<div class="container-fluid">
<div class="row">
<div class="col-sm">
<ol>
<li>Copy/Paste your SQL statement in the textbox</li>
<li>Click on the Format button</li>
</ol>
</div>
<div class="col-sm">
<img height="300px" src="https://raw.githubusercontent.com/cavo789/sql_formatter/master/images/demo.gif" alt="Demo">
</div>
</div>
</div>
</details>
<div class="form-group">
<label for="SQL">Copy/Paste your SQL statement in the
textbox below then click on the Format button:</label>
<textarea class="form-control" rows="5" id="SQL" name="SQL"><?php echo $SQL; ?></textarea>
</div>
<button type="button" id="btnFormat" class="btn btn-primary">Format</button>
<hr />
<pre id="Result"></pre>
<i style="display:block;font-size:0.6em;">
<a href="https://github.com/jdorn/sql-formatter">
SQL Formatter written by Jeremy Dorn
</a>
</i>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script type="text/javascript">
$('#btnFormat').click(function(e) {
e.stopImmediatePropagation();
var $data = new Object;
$data.task = "format";
$data.sql = window.btoa($('#SQL').val());
$.ajax({
beforeSend: function() {
$('#Result').html('<div><span class="ajax_loading"> </span><span style="font-style:italic;font-size:1.5em;">Formatting...</span></div>');
$('#btnFormat').prop("disabled", true);
},
async: true,
type: "POST",
url: "<?php echo basename(__FILE__); ?>",
data: $data,
datatype: "html",
success: function(data) {
$('#btnFormat').prop("disabled", false);
$('#Result').html(data);
}
}); // $.ajax()
});
</script>
</body>
</html>