Skip to content

Commit 6f37e58

Browse files
committed
Added support for viewing values with encoding different then UTF-8
1 parent 57bdedc commit 6f37e58

File tree

6 files changed

+14
-11
lines changed

6 files changed

+14
-11
lines changed

README.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ git clone https://github.com/nrk/predis.git vendor
4242
TODO
4343
====
4444

45+
* Encoding support for editing
4546
* Javascript sorting of tables
4647
* Better error handling
4748
* Move or Copy key to different server

includes/common.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
$server = $config['servers'][$i];
5757
$server['id'] = $i;
58+
$server['charset'] = isset($server['charset']) && $server['charset'] ? $server['charset'] : mb_internal_encoding();
5859

5960

6061
if (isset($login, $login['servers'])) {

includes/config.sample.inc.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
'db' => 1 // Optional database number, see http://redis.io/commands/select
2626
'filter' => 'something:*' // Show only parts of database for speed or security reasons
2727
'seperator' => '/', // Use a different seperator on this database
28-
'flush' => false // Set to true to enable the flushdb button for this instance.
28+
'flush' => false, // Set to true to enable the flushdb button for this instance.
29+
'encoding' => 'cp1251', // Set for view values in other encoding
2930
)*/
3031
),
3132

includes/functions.inc.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
4-
function format_html($str) {
5-
return htmlentities($str, ENT_COMPAT, 'UTF-8');
3+
function format_html($str, $from_encoding = FALSE) {
4+
$res = $from_encoding ? mb_convert_encoding($str, 'utf-8', $from_encoding) : $str;
5+
$res = htmlentities($res, ENT_QUOTES | ENT_SUBSTITUTE, 'utf-8');
6+
return ($res || !$str) ? $res : '(' . strlen($str) . ' bytes)';
67
}
78

8-
99
function format_ago($time, $ago = false) {
1010
$minute = 60;
1111
$hour = $minute * 60;

overview.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
<?php foreach ($config['servers'] as $i => $server) { ?>
6767
<div class="server">
68-
<h2><?php echo isset($server['name']) ? $server['name'] : format_html($server['host'])?></h2>
68+
<h2><?php echo isset($server['name']) ? format_html($server['name']) : format_html($server['host'])?></h2>
6969

7070
<?php if(!$info[$i]): ?>
7171
<div style="text-align:center;color:red">Server Down</div>

view.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
if ($type == 'string') { ?>
138138

139139
<table>
140-
<tr><td><div><?php echo nl2br(format_html($value))?></div></td><td><div>
140+
<tr><td><div><?php echo nl2br(format_html($value, $server['charset']))?></div></td><td><div>
141141
<a href="edit.php?s=<?php echo $server['id']?>&amp;type=string&amp;key=<?php echo urlencode($_GET['key'])?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
142142
</div></td><td><div>
143143
<a href="delete.php?s=<?php echo $server['id']?>&amp;type=string&amp;key=<?php echo urlencode($_GET['key'])?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
@@ -155,7 +155,7 @@
155155
<tr><th><div>Key</div></th><th><div>Value</div></th><th><div>&nbsp;</div></th><th><div>&nbsp;</div></th></tr>
156156

157157
<?php foreach ($values as $hkey => $value) { ?>
158-
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo format_html($hkey)?></div></td><td><div><?php echo nl2br(format_html($value))?></div></td><td><div>
158+
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo format_html($hkey, $server['charset'])?></div></td><td><div><?php echo nl2br(format_html($value, $server['charset']))?></div></td><td><div>
159159
<a href="edit.php?s=<?php echo $server['id']?>&amp;type=hash&amp;key=<?php echo urlencode($_GET['key'])?>&amp;hkey=<?php echo urlencode($hkey)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
160160
</div></td><td><div>
161161
<a href="delete.php?s=<?php echo $server['id']?>&amp;type=hash&amp;key=<?php echo urlencode($_GET['key'])?>&amp;hkey=<?php echo urlencode($hkey)?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
@@ -183,7 +183,7 @@
183183
for ($i = $start; $i < $end; ++$i) {
184184
$value = $redis->lIndex($_GET['key'], $i);
185185
?>
186-
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo $i?></div></td><td><div><?php echo nl2br(format_html($value))?></div></td><td><div>
186+
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo $i?></div></td><td><div><?php echo nl2br(format_html($value, $server['charset']))?></div></td><td><div>
187187
<a href="edit.php?s=<?php echo $server['id']?>&amp;type=list&amp;key=<?php echo urlencode($_GET['key'])?>&amp;index=<?php echo $i?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
188188
</div></td><td><div>
189189
<a href="delete.php?s=<?php echo $server['id']?>&amp;type=list&amp;key=<?php echo urlencode($_GET['key'])?>&amp;index=<?php echo $i?>" class="delval"><img src="images/delete.png" width="16" height="16" title="Delete" alt="[X]"></a>
@@ -202,7 +202,7 @@
202202
<tr><th><div>Value</div></th><th><div>&nbsp;</div></th><th><div>&nbsp;</div></th></tr>
203203

204204
<?php foreach ($values as $value) {
205-
$display_value = $redis->exists($value) ? '<a href="http://github.com/view.php?s=%3C/span%3E'.$server['id'].'&key='.urlencode($value).'">'.nl2br(format_html($value)).'</a>' : nl2br(format_html($value));
205+
$display_value = $redis->exists($value) ? '<a href="http://github.com/view.php?s=%3C/span%3E'.$server['id'].'&key='.urlencode($value).'">'.nl2br(format_html($value, $server['charset'])).'</a>' : nl2br(format_html($value, $server['charset']));
206206
?>
207207
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo $display_value ?></div></td><td><div>
208208
<a href="edit.php?s=<?php echo $server['id']?>&amp;type=set&amp;key=<?php echo urlencode($_GET['key'])?>&amp;value=<?php echo urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>
@@ -223,7 +223,7 @@
223223

224224
<?php foreach ($values as $value) {
225225
$score = $redis->zScore($_GET['key'], $value);
226-
$display_value = $redis->exists($value) ? '<a href="http://github.com/view.php?s=%3C/span%3E'.$server['id'].'&key='.urlencode($value).'">'.nl2br(format_html($value)).'</a>' : nl2br(format_html($value));
226+
$display_value = $redis->exists($value) ? '<a href="http://github.com/view.php?s=%3C/span%3E'.$server['id'].'&key='.urlencode($value).'">'.nl2br(format_html($value, $server['charset'])).'</a>' : nl2br(format_html($value, $server['charset']));
227227
?>
228228
<tr <?php echo $alt ? 'class="alt"' : ''?>><td><div><?php echo $score?></div></td><td><div><?php echo $display_value ?></div></td><td><div>
229229
<a href="edit.php?s=<?php echo $server['id']?>&amp;type=zset&amp;key=<?php echo urlencode($_GET['key'])?>&amp;score=<?php echo $score?>&amp;value=<?php echo urlencode($value)?>"><img src="images/edit.png" width="16" height="16" title="Edit" alt="[E]"></a>

0 commit comments

Comments
 (0)