forked from cowboy/jquery-bbq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
190 lines (137 loc) · 5.71 KB
/
index.php
File metadata and controls
190 lines (137 loc) · 5.71 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?PHP
include "../index.php";
$shell['title3'] = "jQuery.deparam";
$shell['h2'] = 'The opposite of jQuery.param, pretty much.';
array_push( $shell['shBrush'], 'Php' );
// ========================================================================== //
// SCRIPT
// ========================================================================== //
ob_start();
?>
$(function(){
// Values are not coerced.
var params = $.deparam.querystring();
debug.log( 'not coerced', params );
$('#deparam_string').text( JSON.stringify( params, null, 2 ) );
// Values are coerced.
params = $.deparam.querystring( true );
debug.log( 'coerced', params );
$('#deparam_coerced').text( JSON.stringify( params, null, 2 ) );
// Highlight the current sample query string link
var qs = $.param.querystring();
$('li a').each(function(){
if ( $(this).attr( 'href' ) === '?' + qs ) {
$(this).addClass( 'current' );
}
});
});
<?
$shell['script'] = ob_get_contents();
ob_end_clean();
// ========================================================================== //
// HTML HEAD ADDITIONAL
// ========================================================================== //
ob_start();
?>
<script type="text/javascript" language="javascript">
// I want to use json2.js because it allows me to format stringified JSON with
// pretty indents, so let's nuke any existing browser-specific JSON parser.
window.JSON = null;
</script>
<script type="text/javascript" src="../../shared/json2.js"></script>
<script type="text/javascript" src="../../jquery.ba-bbq.js"></script>
<script type="text/javascript" language="javascript">
<?= $shell['script']; ?>
$(function(){
// Syntax highlighter.
SyntaxHighlighter.highlight();
});
</script>
<style type="text/css" title="text/css">
/*
bg: #FDEBDC
bg1: #FFD6AF
bg2: #FFAB59
orange: #FF7F00
brown: #913D00
lt. brown: #C4884F
*/
#page {
width: 700px;
}
#page * {
word-wrap: break-word;
}
.deparam {
width: 343px;
}
.deparam-1 {
float: left;
}
.deparam-2 {
float: right;
}
.current {
color: #FF7F00;
text-decoration: none;
}
li {
margin-bottom: 0.6em;
}
</style>
<?
$shell['html_head'] = ob_get_contents();
ob_end_clean();
// ========================================================================== //
// HTML BODY
// ========================================================================== //
ob_start();
?>
<?= $shell['donate'] ?>
<p>
<a href="http://benalman.com/projects/jquery-bbq-plugin/">jQuery BBQ</a> includes a powerful jQuery.deparam method that is capable of fully deserializing not only any params string that jQuery.param can create, but that PHP and Rails (and hopefully everything else) can create. And even though only the query string is being parsed this example, methods for parsing a params string out of the fragment (hash) as well parsing any stand-alone params string are included. jQuery BBQ can also be used to merge params from multiple URLs or objects into a new URL, even within element attributes. See <a href="../../docs/">the documentation</a> for a full list of methods!
</p>
<h3>Sample query strings for you to click:</h3>
<ol>
<li>Arrays encoded like this won't work as-expected in PHP / Rails, but work in BBQ and many older server-side frameworks (jQuery 1.3.2 or older $.param, jQuery 1.4 with $.param.traditional = true):<br>
<a href="?a=1&a=2&a=3&b=4&c=true&d=0">?a=1&a=2&a=3&b=4&c=true&d=0</a></li>
<li>Arrays encoded like this will work as-expected in PHP / Rails / BBQ (jQuery 1.4 or newer $.param):<br>
<a href="?a[]=1&a[]=2&a[]=3&b=4&c=true&d=0">?a[]=1&a[]=2&a[]=3&b=4&c=true&d=0</a></li>
<li>jQuery BBQ and PHP can handle non-shallow arrays, but Rails (rack) cannot (jQuery 1.4 or newer $.param):<br>
<a href="?a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17">?a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9
&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14
&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17</a></li>
<li>Some simple implicitly non-string values that BBQ can optionally coerce:<br>
<a href="?a=true&b=false&c=undefined&d=&f=1&g=2&h=hello+world">?a=true&b=false&c=undefined&d=&f=1&g=2&h=hello+world</a></li>
<li>More nested data structures. Since the arrays are shallow, this works in Rails (rack).<br>
<a href="?a[]=4&a[]=5&a[]=6&b[x][]=7&b[y]=8&b[z][]=9&b[z][]=0&b[z][]=true&b[z][]=false&b[z][]=undefined&b[z][]=&c=1">?a[]=4&a[]=5&a[]=6&b[x][]=7&b[y]=8&b[z][]=9&b[z][]=0&b[z][]=true&b[z][]=false&b[z][]=undefined&b[z][]=&c=1</a></li>
</ol>
<h3>Urldecoded query string</h3>
<?= urldecode( $_SERVER['QUERY_STRING'] ) ?>
<h3>Query string params, as parsed by jQuery BBQ (and converted to JSON)</h3>
<div class="deparam deparam-1">
<p><code>$.deparam.querystring();</code></p>
<pre class="brush:js" id="deparam_string"></pre>
</div>
<div class="deparam deparam-2">
<p><code>$.deparam.querystring( true );</code></p>
<pre class="brush:js" id="deparam_coerced"></pre>
</div>
<div style="clear:both;"></div>
<h3>GET params, as parsed by PHP</h3>
<p><code>print_r( $_GET );</code></p>
<pre class="brush:php">
<? print_r( $_GET ) ?>
</pre>
<h3>The code</h3>
<pre class="brush:js">
<?= htmlspecialchars( $shell['script'] ); ?>
</pre>
<?
$shell['html_body'] = ob_get_contents();
ob_end_clean();
// ========================================================================== //
// DRAW SHELL
// ========================================================================== //
draw_shell();
?>