/** * Test that a regex route is matched correctly * * @return null */ public function testRegexRouteMatch() { $_SERVER['REQUEST_URI'] = '/testing123'; $_SERVER['REQUEST_METHOD'] = 'GET'; $app = new Shield(); $app->get('/testing[0-9]+', function () { echo 'match /'; }); ob_start(); $app->run(); $output = ob_get_clean(); $this->assertEquals('match /', $output); }
public static function initialize() { $valid = false; /* Get the king instance to parse the url to controller, method and parameters. */ $king = self::getInstance(); /* Validate the if the controller class based in the url exists. * If exists, then we include that controller class. */ $controller_class = ucfirst($king->getController()) . "Controller"; $controller_path = CONTROLLERS_PATH . $controller_class . ".php"; if (file_exists($controller_path)) { include_once $controller_path; /* Initialise the controller class. */ $class = new $controller_class(); /* Check if the method exist in the controller class and has the required parameters. * If it exists, then we call that method and pass the parameters. */ $method = $king->getMethod() ? $king->getMethod() : "index"; if (method_exists($class, $method)) { $classMethod = new ReflectionMethod($class, $method); if (sizeof($king->getParameters()) >= $classMethod->getNumberOfRequiredParameters()) { /* Call the Shield class and then checks if the request is secure. */ if (Shield::protect()) { $valid = true; call_user_func_array(array($class, $method), $king->getParameters()); } else { Error::display('UNDER_ATTACK'); } } } } /* Return an error if its an invalid path. */ if (!$valid) { Error::display('NOT_FOUND', "Something is WRONG in the Castle class, the path or controller was not found."); } }
echo Form::hidden('parent', Guardian::wayback('parent')); ?> <?php Weapon::fire('comment_form_input_after', $hooks); ?> <?php Weapon::fire('comment_form_textarea_before', $hooks); ?> <?php Shield::chunk('comment.form.message'); ?> <?php Weapon::fire('comment_form_textarea_after', $hooks); ?> <?php Shield::chunk('comment.form.math'); ?> <div class="grid-group"> <span class="grid span-1"></span> <div class="grid span-5"> <p> <?php Weapon::fire('comment_form_button_before', $hooks); ?> <?php echo Form::button($speak->publish, null, 'submit', null, array('class' => array('btn', 'btn-construct'))); ?> <?php Weapon::fire('comment_form_button_after', $hooks); ?> </p>
if ($request = Request::post()) { Guardian::checkToken($request['token']); $P = array('data' => array('path' => $file)); File::open($file)->delete(); if ($path) { Notify::success(Config::speak('notify_file_deleted', '<code>' . File::B($path) . '</code>')); } else { Notify::success(Config::speak('notify_success_deleted', $speak->shield)); } Weapon::fire('on_shield_update', array($P, $P)); Weapon::fire('on_shield_destruct', array($P, $P)); Guardian::kick($config->manager->slug . '/shield' . ($path ? '/' . $folder : "")); } else { Notify::warning(Config::speak('notify_confirm_delete_', $path ? '<code>' . File::path($path) . '</code>' : '<strong>' . $info['title'] . '</strong>')); } Shield::lot(array('segment' => 'shield', 'the_shield' => $folder, 'the_name' => $path, 'the_info' => $info))->attach('manager', false); }); /** * Shield Attacher * --------------- */ Route::accept($config->manager->slug . '/shield/(attach|eject)/id:(:any)', function ($path = "", $slug = "") use($config, $speak) { $new_config = Get::state_config(); $new_config['shield'] = $path === 'attach' ? $slug : 'normal'; File::serialize($new_config)->saveTo(STATE . DS . 'config.txt', 0600); $G = array('data' => array('id' => $slug, 'action' => $path)); $mode = $path === 'eject' ? 'eject' : 'mount'; Notify::success(Config::speak('notify_success_updated', $speak->shield)); Weapon::fire('on_shield_update', array($G, $G)); Weapon::fire('on_shield_' . $mode, array($G, $G)); Weapon::fire('on_shield_' . md5($slug) . '_update', array($G, $G));
<article class="post" id="post-<?php echo $page->id; ?> "> <?php Shield::chunk('page.header'); ?> <?php Shield::chunk('page.body'); ?> <?php Shield::chunk('page.footer'); ?> </article>
$info_path = array(); $is_folder_or_file = count($deletes) === 1 && is_dir(ASSET . DS . $deletes[0]) ? 'folder' : 'file'; foreach ($deletes as $file_to_delete) { $_path = ASSET . DS . $file_to_delete; $info_path[] = $_path; File::open($_path)->delete(); } $P = array('data' => array('files' => $info_path)); Notify::success(Config::speak('notify_' . $is_folder_or_file . '_deleted', '<code>' . implode('</code>, <code>', $deletes) . '</code>')); Weapon::fire('on_asset_update', array($P, $P)); Weapon::fire('on_asset_destruct', array($P, $P)); Guardian::kick($config->manager->slug . '/asset/1' . $p); } else { Notify::warning(count($deletes) === 1 ? Config::speak('notify_confirm_delete_', '<code>' . File::path($name) . '</code>') : $speak->notify_confirm_delete); } Shield::lot('segment', 'asset')->attach('manager', false); }); /** * Multiple Asset Killer * --------------------- */ Route::accept($config->manager->slug . '/asset/kill', function ($path = "") use($config, $speak) { if ($request = Request::post()) { Guardian::checkToken($request['token']); if (!isset($request['selected'])) { Notify::error($speak->notify_error_no_files_selected); Guardian::kick($config->manager->slug . '/asset/1'); } $files = array(); foreach ($request['selected'] as $file) { $files[] = str_replace('%2F', '/', Text::parse($file, '->encoded_url'));
/** * ========================================================== * RENDER A SHIELD CHUNK * ========================================================== * * -- CODE: ------------------------------------------------- * * Shield::chunk('header'); * * ---------------------------------------------------------- * * Shield::chunk('header', array('title' => 'Yo!')); * * ---------------------------------------------------------- * */ public static function chunk($name, $fallback = false, $buffer = true) { $path__ = File::path($name); $G = array('data' => array('name' => $name)); if (is_array($fallback)) { self::$lot = array_merge(self::$lot, $fallback); $fallback = false; } $path__ = Filter::apply('chunk:path', self::path($path__, $fallback)); $G['data']['lot'] = self::$lot; $G['data']['path'] = $path__; $out = ""; if ($path__) { // Begin chunk Weapon::fire('chunk_lot_before', array($G, $G)); extract(Filter::apply('chunk:lot', self::$lot)); Weapon::fire('chunk_lot_after', array($G, $G)); Weapon::fire('chunk_before', array($G, $G)); if ($buffer) { ob_start(function ($content) use($path__, &$out) { $content = Filter::apply('chunk:input', $content, $path__); $out = Filter::apply('chunk:output', $content, $path__); return $out; }); require $path__; ob_end_flush(); } else { require $path__; } $G['data']['content'] = $out; // End chunk Weapon::fire('chunk_after', array($G, $G)); } }
/** * ==================================================================== * CONVERT STRING OF VALUE INTO EXECUTABLE PHP CODE * ==================================================================== * * -- CODE: ----------------------------------------------------------- * * var_dump(Converter::phpEval('echo 1 + 1;')); * * -------------------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * --------- | ------ | ---------------------------------------------- * $input | string | The PHP string to be converted * --------- | ------ | ---------------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function phpEval($input) { ob_start(); extract(Shield::cargo()); // include default variables ... eval($input); return ob_get_clean(); }
<div class="post-body"><?php Shield::chunk('404.body', array('s' => $speak->page)); ?> </div>
echo Config::speak('manager.title_your_', $speak->shields); ?> </h3> <?php foreach ($folders as $folder) { $folder = File::B($folder); ?> <?php if ($config->shield !== $folder && strpos($folder, '__') !== 0) { ?> <?php $r = SHIELD . DS . $folder . DS; $c = File::exist($r . 'capture.png'); ?> <?php $page = Shield::info($folder); ?> <div class="media<?php if (!$c) { ?> no-capture<?php } ?> " id="shield:<?php echo $folder; ?> "> <?php if ($c) { ?> <div class="media-capture" style="background-image:url('<?php
<?php Shield::lot(array('article' => $article)); ?> <article class="post post-index" id="post-<?php echo $article->id; ?> "> <?php Shield::chunk('article.header.index'); ?> <?php Shield::chunk('article.body.index'); ?> <?php Shield::chunk('article.footer.index'); ?> </article>
* ---------- */ Route::accept($config->manager->slug . '/tag/kill/id:(:any)', function ($id = false) use($config, $speak, $tags) { if (!Guardian::happy(1)) { Shield::abort(); } if (!isset($tags[$id])) { Shield::abort(); // Tag not found! } $title = $tags[$id]['name']; Config::set(array('page_title' => $speak->deleting . ': ' . $title . $config->title_separator . $config->manager->title, 'cargo' => 'kill.tag.php')); $G = array('data' => $tags); $G['data']['id'] = $id; if ($request = Request::post()) { $request = Filter::apply('request:__tag', $request, $id); Guardian::checkToken($request['token']); unset($tags[$id]); // delete ... ksort($tags); $P = array('data' => $tags); $P['data']['id'] = $id; File::serialize($tags)->saveTo(STATE . DS . 'tag.txt', 0600); Notify::success(Config::speak('notify_success_deleted', $title)); Weapon::fire(array('on_tag_update', 'on_tag_destruct'), array($G, $P)); Guardian::kick($config->manager->slug . '/tag'); } else { Notify::warning(Config::speak('notify_confirm_delete_', '<strong>' . $title . '</strong>')); } Shield::lot(array('segment' => 'tag', 'id' => $id, 'file' => Mecha::O($tags[$id])))->attach('manager'); });
<p class="comment-time"> <time datetime="<?php echo $comment->date->W3C; ?> "><?php echo $comment->date->FORMAT_3; ?> </time><?php Shield::chunk('comment.permalink'); ?> </p>
<div class="post-body"><?php Shield::chunk('204.body', array('s' => $speak->articles)); ?> </div>
* ----------- */ Route::accept($config->manager->slug . '/menu/kill/key:(:any)', function ($key = false) use($config, $speak) { if (!Guardian::happy(1)) { Shield::abort(); } $menus = Get::state_menu(null, array(), false); if (!isset($menus[$key])) { Shield::abort(); // Menu not found! } Config::set(array('page_title' => $speak->deleting . ': ' . $speak->menu . $config->title_separator . $config->manager->title, 'cargo' => 'kill.menu.php')); $G = array('data' => $menus); $G['data']['key'] = $key; if ($request = Request::post()) { $request = Filter::apply('request:__menu', $request, $key); Guardian::checkToken($request['token']); unset($menus[$key]); // delete ... ksort($menus); $P = array('data' => $menus); $P['data']['key'] = $key; File::serialize($menus)->saveTo(STATE . DS . 'menu.txt', 0600); Notify::success(Config::speak('notify_success_deleted', $speak->menu)); Weapon::fire(array('on_menu_update', 'on_menu_destruct'), array($G, $P)); Guardian::kick($config->manager->slug . '/menu'); } else { Notify::warning(Config::speak('notify_confirm_delete_', '<code>Menu::' . $key . '()</code>')); } Shield::lot(array('segment' => 'menu', 'id' => $key, 'file' => Mecha::O($menus[$key])))->attach('manager'); });
if ($request = Request::post()) { Guardian::checkToken($request['token']); $info_path = Mecha::walk($deletes, function ($v) { $_path = ASSET . DS . $v; File::open($_path)->delete(); return $_path; }); $is_folder_or_file = count($deletes) === 1 && is_dir(ASSET . DS . $deletes[0]) ? 'folder' : 'file'; $P = array('data' => array('files' => $info_path)); Notify::success(Config::speak('notify_' . $is_folder_or_file . '_deleted', '<code>' . implode('</code>, <code>', $deletes) . '</code>')); Weapon::fire(array('on_asset_update', 'on_asset_destruct'), array($P, $P)); Guardian::kick($config->manager->slug . '/asset/1' . str_replace('&', '&', HTTP::query('path', $p))); } else { Notify::warning(count($deletes) === 1 ? Config::speak('notify_confirm_delete_', '<code>' . File::path($name) . '</code>') : $speak->notify_confirm_delete); } Shield::lot(array('segment' => 'asset', 'files' => Mecha::O($deletes)))->attach('manager'); }); /** * Multiple Asset Action * --------------------- */ Route::accept($config->manager->slug . '/asset/do', function ($path = "") use($config, $speak) { if ($request = Request::post()) { Guardian::checkToken($request['token']); if (!isset($request['selected'])) { Notify::error($speak->notify_error_no_files_selected); Guardian::kick($config->manager->slug . '/asset/1'); } $files = Mecha::walk($request['selected'], function ($v) { return str_replace('%2F', '/', Text::parse($v, '->encoded_url')); });
<?php Route::accept($config->manager->slug . '/snippet', function () use($config, $speak) { // Add `.htaccess` file to prevent direct access $htaccess = ASSET . DS . '__snippet' . DS . '.htaccess'; if (!File::exist($htaccess)) { File::write('deny from all')->saveTo($htaccess, 0600); } Config::set(array('page_title' => $speak->snippets . $config->title_separator . $config->manager->title, 'cargo' => __DIR__ . DS . 'cargo.snippet.php')); Shield::lot(array('segment' => 'snippet'))->attach('manager'); }); Route::post($config->manager->slug . '/snippet/ignite', function () use($config, $speak) { $request = Request::post(); $id = time(); Guardian::checkToken($request['token']); if (trim($request['name']) === "") { $request['name'] = $id . '.txt'; // empty file name } $_path = Text::parse(sprintf($request['name'], $id), '->safe_path_name'); $e = File::E($_path, false); if ($e !== 'txt' && $e !== 'php') { $e = 'txt'; $_path .= '.txt'; } $_path_ = File::path($_path); $file = ASSET . DS . '__snippet' . DS . $e . DS . $_path; if (File::exist($file)) { // file already exists Notify::error(Config::speak('notify_file_exist', '<code>' . $_path_ . '</code>')); }
<?php Shield::chunk('block.navigation');
echo Form::select('language_direction', array('ltr' => 'Left to Right (LTR)', 'rtl' => 'Right to Left (RTL)'), Guardian::wayback('language_direction', $config->language_direction), array('class' => 'select-block')); ?> </span> </label> <label class="grid-group"> <span class="grid span-2 form-label"><?php echo $speak->shield; ?> </span> <span class="grid span-4"> <?php $info = array(); foreach (glob(SHIELD . DS . '*', GLOB_ONLYDIR) as $folder) { $s = File::B($folder); if (strpos($s, '__') !== 0) { $info[$s] = Shield::info($s)->title; } } echo Form::select('shield', $info, Guardian::wayback('shield', $config->shield), array('class' => 'select-block')); ?> </span> </label> <label class="grid-group"> <span class="grid span-2 form-label"><?php echo $speak->manager->title_per_page; ?> (<?php echo $speak->all; ?> )</span> <span class="grid span-4">
?> " class="page-<?php echo $config->page_type ? $config->page_type : 'home'; ?> "> <head> <?php Weapon::fire('SHIPMENT_REGION_TOP'); ?> <?php Weapon::fire('shell_before'); ?> <?php echo Asset::stylesheet(array($config->protocol . ICON_LIBRARY_PATH, 'assets/shell/atom.css', 'assets/shell/layout.css')); ?> <?php Weapon::fire('shell_after'); ?> </head> <body> <?php Weapon::fire('cargo_before'); ?> <div class="blog-wrapper"> <?php Shield::chunk('block.header'); ?> <?php Shield::chunk('navigation'); ?> <div class="blog-content">
<header class="post-header"> <?php Shield::chunk('page.title.404'); ?> <?php if (Weapon::exist('page_header')) { ?> <div><?php Weapon::fire('page_header', array($page)); ?> </div> <?php } ?> </header>
if (!Notify::errors()) { $data = array(); $keys = $request['id']; for ($i = 0, $count = count($keys); $i < $count; ++$i) { if (trim($request['name'][$i]) !== "" && trim($request['id'][$i]) !== "" && is_numeric($request['id'][$i])) { $slug = trim($request['slug'][$i]) !== "" ? $request['slug'][$i] : $request['name'][$i]; $data[$i] = array('id' => (int) $keys[$i], 'name' => $request['name'][$i], 'slug' => Text::parse($slug, '->slug'), 'description' => $request['description'][$i]); } } $P = array('data' => $data); File::serialize($data)->saveTo(STATE . DS . 'tag.txt', 0600); Notify::success(Config::speak('notify_success_updated', $speak->tags)); Weapon::fire('on_tag_update', array($G, $P)); } Guardian::kick($config->url_current); } Weapon::add('SHIPMENT_REGION_BOTTOM', function () { echo '<script> (function($, base) { base.add(\'on_row_increase\', function() { $(\'input[name="id[]"]\').last().val(parseInt($(\'input[name="id[]"]\').last().closest(\'tr\').prev().find(\'input[name="id[]"]\').val(), 10) + 1 || ""); $(\'input[name="name[]"]\').each(function() { $.slug($(this), $(this).parent().next().find(\'input\'), \'-\'); }); }); base.fire(\'on_row_increase\'); })(window.Zepto || window.jQuery, DASHBOARD); </script>'; }, 11); Shield::lot('segment', 'tag')->attach('manager', false); });
<?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'); });
if (!Guardian::happy(1) && Guardian::get('author') !== $post->author) { Shield::abort(); } Config::set(array('page_title' => $speak->deleting . ': ' . $post->title . $config->title_separator . $config->manager->title, 'page' => $post, 'cargo' => 'kill.post.php')); $G = array('data' => Mecha::A($post)); if ($request = Request::post()) { Guardian::checkToken($request['token']); File::open($post->path)->delete(); // Deleting response(s) ... if ($responses = call_user_func('Get::' . $response . 's', 'DESC', 'post:' . $id, 'txt,hold')) { foreach ($responses as $v) { File::open($v)->delete(); } } $P = array('data' => $request); include __DIR__ . DS . 'task.kill.substance.php'; // Deleting custom CSS and JavaScript file of post ... File::open(CUSTOM . DS . Date::slug($id) . '.txt')->delete(); File::open(CUSTOM . DS . Date::slug($id) . '.draft')->delete(); Weapon::fire(array('on_custom_update', 'on_custom_destruct'), array($G, $P)); // Deleting custom PHP file of post ... File::open(File::D($post->path) . DS . $post->slug . '.php')->delete(); Notify::success(Config::speak('notify_success_deleted', $post->title)); Weapon::fire(array('on_' . $segment . '_update', 'on_' . $segment . '_destruct'), array($G, $G)); Guardian::kick($config->manager->slug . '/' . $segment); } else { Notify::warning(Config::speak('notify_confirm_delete_', '<strong>' . $post->title . '</strong>')); Notify::warning(Config::speak('notify_confirm_delete_page', strtolower($speak->{$segment}), strtolower($speak->{$response . 's'}))); } Shield::lot(array('segment' => $segment))->attach('manager'); });
$articles = Mecha::walk($articles, function ($path) use($excludes) { return Get::article($path, $excludes); }); } else { $articles = false; } Filter::add('pager:url', function ($url) { return Filter::apply('index:url', $url); }); Config::set(array('articles' => $articles, 'pagination' => Navigator::extract($s, 1, $config->index->per_page, $config->index->slug))); Shield::attach('page-home'); }, 110); /** * Route Hook: after * ----------------- */ Weapon::fire('routes_after'); /** * Do Routing * ---------- */ Route::execute(); /** * 404 Page * -------- * * Fallback to 404 page if nothing matched. * */ Shield::abort();
* Login Page * ---------- * * [1]. manager/login * */ Route::accept($config->manager->slug . '/login', function () use($config, $speak) { if (!File::exist(File::D(__DIR__) . DS . 'launch.php')) { Shield::abort('404-manager'); } if (Guardian::happy()) { Guardian::kick($config->manager->slug . '/article'); } Config::set(array('page_title' => $speak->log_in . $config->title_separator . $config->title, 'cargo' => 'cargo.login.php')); include __DIR__ . DS . 'cargo.php'; if ($request = Request::post()) { Guardian::authorize()->kick(isset($request['kick']) ? $request['kick'] : $config->manager->slug . '/article'); } Shield::attach('manager-login'); }, 20); /** * Logout Page * ----------- * * [1]. manager/logout * */ Route::accept($config->manager->slug . '/logout', function () use($config, $speak) { Notify::success(ucfirst(strtolower($speak->logged_out)) . '.'); Guardian::reject()->kick($config->manager->slug . '/login'); }, 21);
<section class="comment comment-<?php echo $comment->status; ?> " id="comment-<?php echo $comment->id; ?> "> <?php Shield::chunk('comment.avatar'); ?> <?php Shield::chunk('comment.header'); ?> <?php Shield::chunk('comment.body'); ?> <?php Shield::chunk('comment.footer'); ?> </section>
<?php /** * Menu Manager * ------------ */ Route::accept($config->manager->slug . '/menu', function () use($config, $speak) { if (Guardian::get('status') !== 'pilot') { Shield::abort(); } $menus = Get::state_menu(); Config::set(array('page_title' => $speak->menus . $config->title_separator . $config->manager->title, 'cargo' => DECK . DS . 'workers' . DS . 'cargo.menu.php')); $G = array('data' => array('content' => $menus)); if ($request = Request::post()) { Guardian::checkToken($request['token']); // Check for invalid input if (preg_match('#(^|\\n)(\\t| {1,3})(?:[^ ])#', $request['content'])) { Notify::error($speak->notify_invalid_indent_character); Guardian::memorize($request); } $P = array('data' => $request); if (!Notify::errors()) { File::write($request['content'])->saveTo(STATE . DS . 'menu.txt', 0600); Notify::success(Config::speak('notify_success_updated', $speak->menu)); Weapon::fire('on_menu_update', array($G, $P)); Guardian::kick($config->url_current); } } Shield::lot(array('segment' => 'menu', 'the_content' => $menus))->attach('manager', false); });
<?php Shield::chunk('block.sidebar');
<?php Shield::chunk('article.header.index'); ?> <?php Shield::chunk('article.body.index'); ?> <?php Shield::chunk('article.footer.index'); ?> </article> <?php } ?> <?php } else { ?> <article class="post"> <?php Shield::chunk('article.body.204'); ?> </article> <?php } ?> <?php Shield::chunk('pager'); ?> </div> <?php Shield::chunk('footer');