Skip to content

Commit

Permalink
修复 低版本PHP(5.2) 兼容问题
Browse files Browse the repository at this point in the history
  • Loading branch information
fghrsh committed Jun 14, 2017
1 parent cf72368 commit 16e1dc4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions function.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function parseCallback($post, $config) {
'addition' => isset($atts['addition']) ? explode('|', $atts['addition']) : null ));
if (empty($data['danmaku']['api']) or !$config->danmaku) $data['danmaku'] = null;
if (isset($atts['danmu'])) if (!self::str2bool($atts['danmu'])) $data['danmaku'] = null;
$js .= "\nDPlayerOptions.push(".self::json_encode_pretty(array_filter($data, 'self::is_not_null')).");";
$js .= "\nDPlayerOptions.push(".self::json_encode_pretty($data).");";
$out = empty($out) ?
self::str_replace_once($matches[0][$i], '<div id="dp'.$data['id'].'" class="dplayer"></div>', $post):
self::str_replace_once($matches[0][$i], '<div id="dp'.$data['id'].'" class="dplayer"></div>', $out);
Expand All @@ -48,8 +48,7 @@ function json_encode_pretty($src) {
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
return json_encode($src, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
} else {
array_walk_recursive($src, 'self::json_encode_unescaped');
$src = urldecode(json_encode($src));
$src = urldecode(json_encode(self::json_encode_unescaped($src)));
$ret = ''; $pos = 0; $newline = "\n"; $prevchar = '';
$length = strlen($src); $indent = ' '; $outofquotes = true;
for ($i=0; $i<=$length; $i++) {
Expand All @@ -62,9 +61,12 @@ function json_encode_pretty($src) {
$ret .= $newline; if ($char=='{' || $char=='[') $pos ++; for ($j=0; $j<$pos; $j++) $ret .= $indent; }
$prevchar = $char;
}
return str_replace(array('":', '"0"', '"1"', '"2"', '"3"'), array('": ', '0', '1', '2', '3'), $ret);
return str_replace(array('":', '"0"', '"1"', '"2"', '"3"', '""'), array('": ', '0', '1', '2', '3', '0'), $ret);
} }
function json_encode_unescaped(&$val) { if ($val!==true && $val!==false && $val!==null) $val = urlencode($val); }
function json_encode_unescaped($src) {
if (is_array($src)) foreach ($src as $key => $val)
$out[urlencode($key)] = self::json_encode_unescaped($val);
else $out = urlencode($src); return $out; }

function shortcode_parse_atts($text) {
$atts = array();
Expand All @@ -86,7 +88,6 @@ function get_shortcode_regex($tagnames = null) {
return '\\[(\\[?)('.join('|', array_map('preg_quote', $tagnames)).
')(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)'; }

function is_not_null($val) { return !is_null($val); }
function str2bool($str) { return $str == 'true' ? true : ($str == 'false' ? false : $str); }
function str_replace_nbsp($str) { return strip_tags(htmlspecialchars_decode(str_replace('&nbsp;',' ',$str))); }
function str_replace_once($n, $r, $h) { return ($p = strpos($h, $n)) === false ? $h : substr_replace($h, $r, $p, strlen($n)); }
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<adapted>140614</adapted>
<version>1.8</version>
<pubdate>2016-05-30</pubdate>
<modified>2017-05-29</modified>
<modified>2017-06-14</modified>
<price>0</price>
<advanced>
<dependency></dependency>
Expand Down

0 comments on commit 16e1dc4

Please sign in to comment.