Last active
December 26, 2022 02:11
-
-
Save donwilson/0bc0ec7c3701fb20747777a1a7b4cab4 to your computer and use it in GitHub Desktop.
PHP Serialized Data previewer in Adminer Editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Display PHP serialized values as table in edit. Using Jakub Vrana and Martin Zeman's JSON Adminer plugin (https://raw.githubusercontent.com/vrana/adminer/master/plugins/json-column.php) as a skeleton for this plugin. | |
* @link https://www.adminer.org/plugins/#use | |
* @author Don Wilson, https://pyxol.com/ | |
* @author Jakub Vrana, https://www.vrana.cz/ | |
* @author Martin Zeman (Zemistr), http://www.zemistr.eu/ | |
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 | |
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) | |
*/ | |
class AdminerPHPSerializedColumn { | |
private function _testSerial($value) { | |
if(false !== ($unserialized = @unserialize($value))) { | |
return $unserialized; | |
} | |
return $value; | |
} | |
private function _buildTable($unserialized) { | |
echo '<table cellspacing="0" style="margin:2px; font-size:100%;">'; | |
foreach ($unserialized as $key => $val) { | |
echo '<tr>'; | |
echo '<th>' . h($key) . '</th>'; | |
echo '<td>'; | |
if (is_scalar($val) || $val === null) { | |
if (is_bool($val)) { | |
$val = $val ? 'true' : 'false'; | |
} elseif ($val === null) { | |
$val = 'null'; | |
} elseif (!is_numeric($val)) { | |
$val = '"' . h(addcslashes($val, "\r\n\"")) . '"'; | |
} | |
echo '<code class="jush-js">' . $val . '</code>'; | |
} else { | |
$this->_buildTable($val); | |
} | |
echo '</td>'; | |
echo '</tr>'; | |
} | |
echo '</table>'; | |
} | |
function editInput($table, $field, $attrs, $value) { | |
$serial = $this->_testSerial($value); | |
if ($serial !== $value) { | |
$this->_buildTable($serial); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment