/** * Handle Shortcode(s) in Content * ------------------------------ */ function do_shortcode($content) { if (strpos($content, '{{') === false) { return $content; } foreach (Get::state_shortcode() as $key => $value) { $key = preg_quote($key, '#'); // %[a,b,c]: option(s) ... accept `a`, `b`, or `c` if (strpos($key, '%\\[') !== false) { $key = preg_replace_callback('#%\\\\\\[(.*?)\\\\\\]#', function ($matches) { return '(' . str_replace(array(',', '&\\#44;'), array('|', ','), $matches[1]) . ')'; }, $key); } // %s: accept any value(s) without line break(s) // %m: accept any value(s) with/without line break(s) // %i: accept integer number(s) // %f: accept float number(s) // %b: accept boolean value(s) $key = str_replace(array('%s', '%m', '%i', '%f', '%b'), array('(.+?)', '([\\s\\S]+?)', '(\\d+?)', '((?:\\d*\\.)?\\d+?)', '\\b(TRUE|FALSE|YES|NO|Y|N|ON|OFF|true|false|yes|no|y|n|on|off|1|0|\\+|\\-)\\b'), $key); $content = preg_replace('#(?<!`)' . $key . '|' . $key . '(?!`)#', Converter::DW($value), $content); } return $content; }
<?php /** * Shortcode Manager * ----------------- */ Route::accept($config->manager->slug . '/shortcode', function () use($config, $speak) { if (!Guardian::happy(1)) { Shield::abort(); } $shortcodes = Get::state_shortcode(null, array(), false); $G = array('data' => $shortcodes); Config::set(array('page_title' => $speak->shortcodes . $config->title_separator . $config->manager->title, 'cargo' => 'cargo.shortcode.php')); if ($request = Request::post()) { $request = Filter::apply('request:__shortcode', $request); Guardian::checkToken($request['token']); $data = array(); for ($i = 0, $keys = $request['key'], $count = count($keys); $i < $count; ++$i) { if (trim($keys[$i]) !== "") { $data[$keys[$i]] = $request['value'][$i]; } } $P = array('data' => $data); File::serialize($data)->saveTo(STATE . DS . 'shortcode.txt', 0600); Notify::success(Config::speak('notify_success_updated', $speak->shortcode)); Weapon::fire('on_shortcode_update', array($G, $P)); Guardian::kick($config->url_current); } Shield::lot(array('segment' => 'shortcode', 'files' => Mecha::O($shortcodes)))->attach('manager'); });
/** * Include User Defined Function(s) * -------------------------------- */ if ($function = File::exist(SHIELD . DS . $config->shield . DS . 'functions.php')) { include $function; } /** * Handle Shortcode(s) in Content * ------------------------------ */ Filter::add('shortcode', function ($content) use($config, $speak) { if (strpos($content, '{{') === false) { return $content; } foreach (Get::state_shortcode() as $key => $value) { $key = preg_quote($key, '#'); // %[a,b,c]: options ... accept `a`, `b`, or `c` if (strpos($key, '%\\[') !== false) { $key = preg_replace_callback('#%\\\\\\[(.*?)\\\\\\]#', function ($matches) { return '(' . str_replace(',', '|', $matches[1]) . ')'; }, $key); } // %s: accept any values without line breaks // %S: accept any values with/without line breaks // %i: accept integer numbers // %f: accept float numbers // %b: accept boolean values $key = str_replace(array('%s', '%S', '%i', '%f', '%b'), array('(.+?)', '([\\s\\S]+?)', '(\\d+?)', '((?:\\d*\\.)?\\d+?)', '\\b(TRUE|FALSE|YES|NO|ON|OFF|true|false|yes|no|on|off|1|0)\\b'), $key); $value = str_replace(array('\\n', '\\r', '\\t'), array("\n", "\r", "\t"), $value); $content = preg_replace('#(?<!`)' . $key . '(?!`)#', $value, $content);