*/ /** * Do not execute this file directly. */ if (!defined('ABSPATH')) { exit; } use \blobfolio\wp\meow\vendor\md; use \blobfolio\wp\meow\vendor\common; // Our help files. $Parsedown = new md\Parsedown(); $help = array( 'Constants'=>MEOW_PLUGIN_DIR . 'skel/help/constant.md', 'Hooks'=>MEOW_PLUGIN_DIR . 'skel/help/hook.md', 'WP-CLI'=>MEOW_PLUGIN_DIR . 'skel/help/cli.md', ); $links = array(); $locale = get_locale(); foreach ($help as $k=>$v) { $translated = common\mb::substr($v, 0, -3) . "-$locale.md"; // There might be a translation. if ($locale && @file_exists($translated)) { $v = $translated; $help[$k] = $help[$k]; } // Otherwise English. elseif (!file_exists($v)) { unset($help[$k]); continue; } try { $help[$k] = $Parsedown->text(file_get_contents($v)); // Ready for PrismJS. $help[$k] = preg_replace_callback( '/
(.*)<\/pre>/sU',
function($match) {
$classes = array();
// Is this PHP?
if (
(false !== strpos($match[1], '{$match[1]}";
},
$help[$k]
);
// Now generate the corresponding links.
$help[$k] = $help[$k] = preg_replace_callback(
'/<(h2|h3)>(.*)<\/\\1>/sU',
function($match) use(&$links, $k) {
if (!isset($links[$k])) {
$links[$k] = array();
}
$id = sanitize_title($k) . '--' . sanitize_title(str_replace('/', '_', $match[2]));
$links[$k][] = array(
'name'=>$match[2],
'id'=>"#$id",
'child'=>('h3' === $match[1] && count($links))
);
return "<{$match[1]} id=\"$id\">{$match[2]}{$match[1]}>";
},
$help[$k]
);
// Also, build up links.
} catch (Throwable $e) {
unset($help[$k]);
} catch (Exception $e) {
unset($help[$k]);
}
}
if (!count($help)) {
wp_die(__('The reference files are missing.', 'apocalypse-meow'), 'Error');
}
$first = array_keys($help);
$first = $first[0];
$data = array(
'help'=>common\format::array_to_indexed($help),
'links'=>$links,
'showingHelp'=>$first
);
// JSON doesn't appreciate broken UTF.
common\ref\sanitize::utf8($data);
?>