public static function __callStatic($id, $arguments = array()) { $c = get_called_class(); $d = Tree::$config; $dd = self::$config['classes']; if (!isset(self::$menus[$c][$id])) { return false; } $AD = array('ul', "", $id . ':'); $arguments = Mecha::extend($AD, $arguments); $type = $arguments[0]; $arguments[0] = self::$menus[$c][$id]; if (!is_array($arguments[0])) { return ""; } Tree::$config['trunk'] = $type; Tree::$config['branch'] = $type; Tree::$config['twig'] = 'li'; Tree::$config['classes']['trunk'] = $dd['parent']; Tree::$config['classes']['branch'] = $dd['child']; Tree::$config['classes']['twig'] = false; Tree::$config['classes']['current'] = $dd['current']; Tree::$config['classes']['chink'] = $dd['separator']; $output = call_user_func_array('Tree::grow', $arguments); Tree::$config = $d; // reset to the previous state return $output; }
public static function placeholder($url = null) { if (is_array($url)) { return Mecha::eat($url)->shake()->get(0); } return 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; }
function do_private_post($content, $results) { global $config, $speak; $results = Mecha::O($results); $results = $config->is->post ? Get::postHeader($results->path, POST . DS . $config->page_type, '/', $config->page_type . ':') : false; if ($results === false) { return $speak->plugin_private_post->description; } $s = isset($results->fields->pass) ? $results->fields->pass : ""; if (strpos($s, ':') !== false) { $s = explode(':', $s, 2); if (isset($s[1])) { $speak->plugin_private_post->hint = ltrim($s[1]); } // override password hint $s = $s[0]; } $hash = md5($s . PRIVATE_POST_SALT); $html = Notify::read(false) . '<div class="overlay--' . File::B(__DIR__) . '"></div><form class="form--' . File::B(__DIR__) . '" action="' . $config->url . '/' . File::B(__DIR__) . '/do:access" method="post">' . NL; $html .= TAB . Form::hidden('token', Guardian::token()) . NL; $html .= TAB . Form::hidden('_', $hash) . NL; $html .= TAB . Form::hidden('kick', $config->url_current) . NL; $html .= TAB . '<p>' . $speak->plugin_private_post->hint . '</p>' . NL; $html .= TAB . '<p>' . Form::text('access', "", $speak->password . '…', array('autocomplete' => 'off')) . ' ' . Form::button($speak->submit, null, 'submit') . '</p>' . NL; $html .= '</form>' . O_END; if ($results && isset($results->fields->pass) && trim($results->fields->pass) !== "") { if (!Guardian::happy() && Session::get('is_allow_post_access') !== $hash) { return $html; } } return $content; }
public static function get($param = null, $fallback = false, $str_eval = true) { if (is_null($param)) { return $_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET) && !empty($_GET) ? $str_eval ? Converter::strEval($_GET, false) : $_GET : $fallback; } $output = Mecha::GVR($_GET, $param, $fallback); return $output === '0' || !empty($output) ? $str_eval ? Converter::strEval($output, false) : $output : $fallback; }
public static function inspect($path, $output = null, $fallback = false) { $path = self::path($path); $n = self::N($path); $e = self::E($path); $update = self::T($path); $update_date = !is_null($update) ? date('Y-m-d H:i:s', $update) : null; $results = array('path' => $path, 'name' => $n, 'url' => self::url($path), 'extension' => is_file($path) ? $e : null, 'update_raw' => $update, 'update' => $update_date, 'size_raw' => file_exists($path) ? filesize($path) : null, 'size' => file_exists($path) ? self::size($path) : null, 'is' => array('hidden' => strpos($n, '__') === 0 || strpos($n, '.') === 0, 'file' => is_file($path), 'folder' => is_dir($path))); return !is_null($output) ? Mecha::GVR($results, $output, $fallback) : $results; }
public static function info($folder = null, $array = false) { $config = Config::get(); $speak = Config::speak(); // Check whether the localized "about" file is available if (!($info = File::exist(PLUGIN . DS . $folder . DS . 'about.' . $config->language . '.txt'))) { $info = PLUGIN . DS . $folder . DS . 'about.txt'; } $default = 'Title' . S . ' ' . ucwords(Text::parse($folder, '->text')) . "\n" . 'Author' . S . ' ' . $speak->anon . "\n" . 'URL' . S . ' #' . "\n" . 'Version' . S . ' 0.0.0' . "\n" . "\n" . SEPARATOR . "\n" . "\n" . Config::speak('notify_not_available', $speak->description); $info = Text::toPage(File::open($info)->read($default), 'content', 'plugin:'); return $array ? $info : Mecha::O($info); }
/** * ============================================================== * FIRE !!! * ============================================================== * * -- CODE: ----------------------------------------------------- * * Weapon::fire('tank'); * * -------------------------------------------------------------- * * Weapon::fire('jet', array('Blue', '1.1.0')); * * -------------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * ---------- | ------ | --------------------------------------- * $name | string | Hook name * $arguments | array | Hook function argument(s) * ---------- | ------ | --------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function fire($name, $arguments = array()) { $name = get_called_class() . '::' . $name; if (isset(self::$armaments[$name])) { if (func_num_args() > 2) { $arguments = array_slice(func_get_args(), 1); } $weapons = Mecha::eat(self::$armaments[$name])->order('ASC', 'stack')->vomit(); foreach ($weapons as $weapon => $cargo) { if (!isset(self::$armaments_e[$name . '->' . $cargo['stack']])) { call_user_func_array($cargo['fn'], $arguments); } } } else { self::$armaments[$name] = array(); } }
public static function header($data = array(), $value = "") { if (!is_array($data)) { $data = array(self::fix($data) => $value); } foreach ($data as $k => $v) { if ($v === false) { unset($data[self::fix($k)], self::$bucket[self::fix($k)]); } else { // Restrict user(s) from inputting the `SEPARATOR` constant // to prevent mistake(s) in parsing the file content $data[self::fix($k)] = Text::ES($v); } } Mecha::extend(self::$bucket, $data); return new static(); }
/** * =================================================================== * APPLY FILTER * =================================================================== * * -- CODE: ---------------------------------------------------------- * * Filter::apply('content', $content); * * ------------------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * --------- | ------ | --------------------------------------------- * $name | string | Filter name * $value | string | String to be manipulated * --------- | ------ | --------------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function apply($name, $value) { $name = get_called_class() . '::' . $name; if (!isset(self::$filters[$name])) { self::$filters[$name] = array(); return $value; } $params = array_slice(func_get_args(), 2); $filters = Mecha::eat(self::$filters[$name])->order('ASC', 'stack')->vomit(); foreach ($filters as $filter => $cargo) { if (!isset(self::$filters_e[$name . '->' . $cargo['stack']])) { $arguments = array_merge(array($value), $params); $value = call_user_func_array($cargo['fn'], $arguments); } } return $value; }
/** * ============================================================== * FIRE !!! * ============================================================== * * -- CODE: ----------------------------------------------------- * * Weapon::fire('tank'); * * -------------------------------------------------------------- * * Weapon::fire('jet', array('Blue', '1.1.0')); * * -------------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * ---------- | ------ | --------------------------------------- * $name | string | Hook name * $arguments | array | Hook function argument(s) * ---------- | ------ | --------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function fire($name, $arguments = array()) { if (!is_array($name)) { $c = get_called_class(); if (isset(self::$armaments[$c][$name])) { if (func_num_args() > 2) { $arguments = array_slice(func_get_args(), 1); } $weapons = Mecha::eat(self::$armaments[$c][$name])->order('ASC', 'stack')->vomit(); foreach ($weapons as $weapon => $cargo) { call_user_func_array($cargo['fn'], $arguments); } } else { self::$armaments[$c][$name] = array(); } } else { $arguments = func_get_args(); foreach ($name as $v) { $arguments[0] = $v; call_user_func_array('self::fire', $arguments); } } }
/** * =================================================================== * APPLY FILTER * =================================================================== * * -- CODE: ---------------------------------------------------------- * * Filter::apply('content', $content); * * Filter::apply(array('page:title', 'title'), $content); * * ------------------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * --------- | ------ | --------------------------------------------- * $name | string | Filter name * $value | string | String to be manipulated * --------- | ------ | --------------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function apply($name, $value) { if (!is_array($name)) { $c = get_called_class(); if (!isset(self::$filters[$c][$name])) { self::$filters[$c][$name] = array(); return $value; } $arguments = array_slice(func_get_args(), 1); $filters = Mecha::eat(self::$filters[$c][$name])->order('ASC', 'stack')->vomit(); foreach ($filters as $filter => $cargo) { $arguments[0] = $value; $value = call_user_func_array($cargo['fn'], $arguments); } } else { $arguments = func_get_args(); foreach (array_reverse($name) as $v) { $arguments[0] = $v; $arguments[1] = $value; $value = call_user_func_array('self::apply', $arguments); } } return $value; }
/** * ========================================================================== * GET MINIMUM DATA OF A PAGE * ========================================================================== * * -- CODE: ----------------------------------------------------------------- * * var_dump(Get::pageAnchor('about')); * * -------------------------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * ---------- | ------ | --------------------------------------------------- * $path | string | The URL path of the page file, or a page slug * $folder | string | Folder of the page(s) * $connector | string | See `Get::page()` * $FP | string | See `Get::page()` * ---------- | ------ | --------------------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function pageAnchor($path, $folder = PAGE, $connector = '/', $FP = 'page:') { $config = Config::get(); if (strpos($path, ROOT) === false) { $path = self::pagePath($path, $folder); // By page slug, ID or time } if ($path && ($buffer = File::open($path)->get(1)) !== false) { $results = self::pageExtract($path); $parts = explode(S, $buffer, 2); $results['url'] = self::AMF($config->url . $connector . $results['slug'], $FP, 'url'); $results['title'] = self::AMF(isset($parts[1]) ? Text::DS(trim($parts[1])) : "", $FP, 'title'); return Mecha::O($results); } return false; }
$filter = Request::get('q', ""); $filter = $filter ? Text::parse($filter, '->safe_file_name') : false; $takes = glob($d . DS . '*', GLOB_NOSORT); if ($filter) { foreach ($takes as $k => $v) { if (strpos(File::N($v), $filter) === false) { unset($takes[$k]); } } } if ($_files = Mecha::eat($takes)->chunk($offset, $config->per_page * 2)->vomit()) { $files = array(); foreach ($_files as $_file) { $files[] = File::inspect($_file); } $files = Mecha::eat($files)->order('ASC', 'path')->vomit(); unset($_files); } else { $files = false; } Config::set(array('page_title' => $speak->assets . $config->title_separator . $config->manager->title, 'offset' => $offset, 'files' => $files, 'pagination' => Navigator::extract($takes, $offset, $config->per_page * 2, $config->manager->slug . '/asset'), 'cargo' => DECK . DS . 'workers' . DS . 'cargo.asset.php')); Shield::lot('segment', 'asset')->attach('manager', false); }); /** * Asset Repair * ------------ */ Route::accept($config->manager->slug . '/asset/repair/(file|files):(:all)', function ($path = "", $old = "") use($config, $speak) { if (Guardian::get('status') !== 'pilot') { Shield::abort(); }
/** * ========================================================== * GET SHIELD INFO * ========================================================== * * -- CODE: ------------------------------------------------- * * var_dump(Shield::info('normal')); * * ---------------------------------------------------------- * */ public static function info($folder = null, $array = false) { $config = Config::get(); $speak = Config::speak(); if (is_null($folder)) { $folder = $config->shield; } // Check whether the localized "about" file is available if (!($info = File::exist(SHIELD . DS . $folder . DS . 'about.' . $config->language . '.txt'))) { $info = SHIELD . DS . $folder . DS . 'about.txt'; } $d = 'Title' . S . ' ' . Text::parse($folder, '->title') . "\n" . 'Author' . S . ' ' . $speak->anon . "\n" . 'URL' . S . ' #' . "\n" . 'Version' . S . ' 0.0.0' . "\n" . "\n" . SEPARATOR . "\n" . "\n" . Config::speak('notify_not_available', $speak->description); $info = Text::toPage(File::open($info)->read($d), 'content', 'shield:', array('id' => File::exist(SHIELD . DS . $folder) ? $folder : false)); return $array ? $info : Mecha::O($info); }
public static function configure($key, $value = null) { if (is_array($key)) { Mecha::extend(self::$config, $key); } else { if (is_array($value)) { Mecha::extend(self::$config[$key], $value); } else { self::$config[$key] = $value; } } return new static(); }
* =================================================================== * APPLY FILTER WITH PREFIX * =================================================================== * * -- CODE: ---------------------------------------------------------- * * Filter::colon('page:title', $content); * * // is equal to ... * * Filter::apply(array('page:title', 'title'), $content); * * ------------------------------------------------------------------- * */ Filter::plug('colon', function ($name, $value) { $arguments = func_get_args(); if (strpos($name, ':') !== false) { $s = explode(':', $name, 2); $arguments[0] = array($name, $s[1]); } return call_user_func_array('Filter::apply', $arguments); }); // Set response, comment and user `status` as `pilot`, `passenger` and `intruder` Filter::add(array('response:status', 'comment:status', 'user:status'), function ($status) { return Mecha::alter($status, array(0 => 'intruder', 1 => 'pilot', 2 => 'passenger')); }, 1); // Decode the obfuscated `email` value Filter::add(array('response:email', 'comment:email', 'user:email'), function ($data) { return Text::parse($data, '->decoded_html'); }, 1);
/** * ==================================================================== * CONVERT ATTRIBUTE(S) OF ELEMENT INTO ARRAY OF DATA * ==================================================================== * * -- CODE: ----------------------------------------------------------- * * var_dump(Converter::attr('<div id="foo">')); * * -------------------------------------------------------------------- * * var_dump(Converter::attr('<div id="foo">test content</div>')); * * -------------------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * --------- | ------- | --------------------------------------------- * $input | string | The string of element to be converted * $element | array | Tag open, tag close, tag separator * $attr | array | Value open, value close, attribute separator * $str_eval | boolean | Convert value with `Converter::strEval()` ? * --------- | ------- | --------------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function attr($input, $element = array(), $attr = array(), $str_eval = true) { $ED = array('<', '>', ' ', '/', '[a-zA-Z0-9\\-._:]+'); $AD = array('"', '"', '=', '[a-zA-Z0-9\\-._:]+'); $E = Mecha::extend($ED, $element); $A = Mecha::extend($AD, $attr); $E0 = preg_quote($E[0], '#'); $E1 = preg_quote($E[1], '#'); $E2 = preg_quote($E[2], '#'); $E3 = preg_quote($E[3], '#'); $A0 = preg_quote($A[0], '#'); $A1 = preg_quote($A[1], '#'); $A2 = preg_quote($A[2], '#'); if (!preg_match('#^\\s*(' . $E0 . ')(' . $E[4] . ')((' . $E2 . ')+(.*?))?((' . $E1 . ')([\\s\\S]*?)((' . $E0 . ')' . $E3 . '\\2(' . $E1 . '))|(' . $E2 . ')*' . $E3 . '?(' . $E1 . '))\\s*$#', $input, $M)) { return false; } $M[5] = preg_replace('#(^|(' . $E2 . ')+)(' . $A[3] . ')(' . $A2 . ')(' . $A0 . ')(' . $A1 . ')#', '$1$2$3$4$5<attr:value>$6', $M[5]); $results = array('element' => $M[2], 'attributes' => null, 'content' => isset($M[8]) && $M[9] === $E[0] . $E[3] . $M[2] . $E[1] ? $M[8] : null); if (preg_match_all('#(' . $A[3] . ')((' . $A2 . ')(' . $A0 . ')(.*?)(' . $A1 . '))?(?:(' . $E2 . ')|$)#', $M[5], $A)) { $results['attributes'] = array(); foreach ($A[1] as $k => $v) { $results['attributes'][$v] = isset($A[5][$k]) && !empty($A[5][$k]) ? strpos($A[5][$k], '<attr:value>') === false ? $A[5][$k] : str_replace('<attr:value>', "", $A[5][$k]) : $v; } } return $str_eval ? self::strEval($results) : $results; }
<?php $scopes = Mecha::walk(glob(POST . DS . '*', GLOB_NOSORT | GLOB_ONLYDIR), function ($v) { return File::B($v); }); return array('pass' => array('title' => $speak->password, 'type' => 'text', 'scope' => implode(',', $scopes), 'description' => $speak->plugin_private_post->__description));
<h4><i class="fa fa-users"></i> <?php echo $speak->users; ?> </h4> <?php if ($users = Guardian::ally()) { ?> <ul> <?php foreach ($users as $user) { ?> <li><?php echo $user['name']; ?> <i class="fa fa-user<?php echo Mecha::alter($user['status_raw'], array(0 => '-times', 1 => '-md', 2 => "")); ?> "></i></li> <?php } ?> </ul> <?php } ?> </div> </div> <div class="grid-group"> <div class="grid span-2"> <h4>Recently Updated</h4> <p>Nothing.</p>
/** * ============================================================================ * PAGINATION EXTRACTOR FOR LIST OF FILE(S) * ============================================================================ * * -- CODE: ------------------------------------------------------------------- * * $pager = Navigator::extract(glob('some/files/*.txt'), 1, 5, 'foo/bar'); * echo $pager->prev->anchor; * * ---------------------------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * ---------- | ------- | ---------------------------------------------------- * $pages | array | Array of file(s) to be paginated * $current | integer | The current page offset * $current | string | The current page path * $per_page | integer | Number of file(s) to show per page request * $connector | string | Extra path to be inserted into URL * ---------- | ------- | ---------------------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function extract($pages = array(), $current = 1, $per_page = 10, $connector = '/') { // Set default next, previous and step data $bucket = array('prev' => false, 'next' => false, 'step' => false); $pages = (array) $pages; $config = Config::get(); $speak = Config::speak(); $base = $config->url; $q = str_replace('&', '&', $config->url_query); $qq = strpos($connector, '?') !== false ? str_replace('?', '&', $q) : $q; $total = count($pages); $c = self::$config; if (strpos($connector, '%s') === false) { if (trim($connector, '/') !== "") { $connector = '/' . trim($connector, '/') . '/%s'; } else { $connector = '/%s'; } } if (is_int($current)) { $current = (int) $current; $prev = $current > 1 ? $current - 1 : false; $next = $current < ceil($total / $per_page) ? $current + 1 : false; // Generate next/previous URL for index page $bucket['prev']['url'] = Filter::apply(array('pager:prev.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, $prev) . $qq : $base . $q, $prev, $connector); $bucket['next']['url'] = Filter::apply(array('pager:next.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $next) . $qq : $base . $q, $next, $connector); // Generate next/previous anchor for index page $bucket['prev']['anchor'] = Filter::apply(array('pager:prev.anchor', 'pager:anchor', 'anchor'), $prev ? '<a href="' . $bucket['prev']['url'] . '" rel="prev">' . $speak->newer . '</a>' : "", $prev, $connector); $bucket['next']['anchor'] = Filter::apply(array('pager:next.anchor', 'pager:anchor', 'anchor'), $next ? '<a href="' . $bucket['next']['url'] . '" rel="next">' . $speak->older . '</a>' : "", $next, $connector); // Generate pagination anchor(s) for index page $html = '<span' . ($c['classes']['pagination'] !== false ? ' class="' . $c['classes']['pagination'] . '"' : "") . '>'; $chunk = (int) ceil($total / $per_page); $step = $chunk > self::$config['step'] ? self::$config['step'] : $chunk; $left = $current - $step; if ($left < 1) { $left = 1; } if ($chunk > 1) { $bucket['step']['url']['first'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, 1) . $qq : false, 1, $connector); $bucket['step']['url']['prev'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, $prev) . $qq : false, $prev, $connector); $bucket['step']['anchor']['first'] = Filter::apply(array('pager:step.anchor', 'pager:anchor', 'anchor'), $prev ? '<a href="' . $bucket['step']['url']['first'] . '">' . $speak->first . '</a>' : '<span>' . $speak->first . '</span>', 1, $connector); $bucket['step']['anchor']['prev'] = Filter::apply(array('pager:step.anchor', 'pager:anchor', 'anchor'), $prev ? '<a href="' . $bucket['step']['url']['prev'] . '" rel="prev">' . $speak->prev . '</a>' : '<span>' . $speak->prev . '</span>', $prev, $connector); $html .= $bucket['step']['anchor']['first'] . $bucket['step']['anchor']['prev']; $html .= '<span>'; for ($i = $current - $step + 1; $i < $current + $step; ++$i) { if ($chunk > 1) { if ($i - 1 < $chunk && ($i > 0 && $i + 1 > $current - $left - round($chunk / 2))) { $bucket['step']['url'][$i] = Filter::apply(array('pager:step.url', 'pager:url'), $i !== $current ? $base . sprintf($connector, $i) . $qq : false, $i, $connector); $bucket['step']['anchor'][$i] = Filter::apply(array('pager:step.anchor', 'pager:anchor', 'anchor'), $i !== $current ? '<a href="' . $bucket['step']['url'][$i] . '">' . $i . '</a>' : '<strong' . ($c['classes']['current'] !== false ? ' class="' . $c['classes']['current'] . '"' : "") . '>' . $i . '</strong>', $i, $connector); $html .= $bucket['step']['anchor'][$i]; } } } $html .= '</span>'; $bucket['step']['url']['next'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $next) . $qq : false, $next, $connector); $bucket['step']['url']['last'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $chunk) . $qq : false, $chunk, $connector); $bucket['step']['anchor']['next'] = Filter::apply(array('pager:step.anchor', 'pager:anchor'), $next ? '<a href="' . $bucket['step']['url']['next'] . '" rel="next">' . $speak->next . '</a>' : '<span>' . $speak->next . '</span>', $next, $connector); $bucket['step']['anchor']['last'] = Filter::apply(array('pager:step.anchor', 'pager:anchor'), $next ? '<a href="' . $bucket['step']['url']['last'] . '">' . $speak->last . '</a>' : '<span>' . $speak->last . '</span>', $chunk, $connector); $html .= $bucket['step']['anchor']['next'] . $bucket['step']['anchor']['last']; } $bucket['step']['html'] = Filter::apply('pager:step.html', $html . '</span>'); } if (is_string($current)) { for ($i = 0; $i < $total; ++$i) { if ($pages[$i] === $current) { $prev = isset($pages[$i - 1]) ? $pages[$i - 1] : false; $next = isset($pages[$i + 1]) ? $pages[$i + 1] : false; // Generate next/previous URL for single page $bucket['prev']['url'] = Filter::apply(array('pager:prev.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, $prev) . $qq : $base . $q, $prev, $connector); $bucket['next']['url'] = Filter::apply(array('pager:next.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $next) . $qq : $base . $q, $next, $connector); // Generate next/previous anchor for single page $bucket['prev']['anchor'] = Filter::apply(array('pager:prev.anchor', 'pager:anchor', 'anchor'), $bucket['prev']['url'] !== $base ? '<a href="' . $bucket['prev']['url'] . '" rel="prev">' . $speak->newer . '</a>' : "", $prev, $connector); $bucket['next']['anchor'] = Filter::apply(array('pager:next.anchor', 'pager:anchor', 'anchor'), $bucket['next']['url'] !== $base ? '<a href="' . $bucket['next']['url'] . '" rel="next">' . $speak->older . '</a>' : "", $next, $connector); break; } } } return Mecha::O($bucket); }
/** * =========================================================================== * EXECUTE THE ADDED ROUTE(S) * =========================================================================== * * -- CODE: ------------------------------------------------------------------ * * Route::execute(); * * --------------------------------------------------------------------------- * * Route::execute('foo/(:num)', array(4)); // Re-execute `foo/(:num)` * * --------------------------------------------------------------------------- * */ public static function execute($pattern = null, $arguments = array()) { if (!is_null($pattern)) { $pattern = self::path($pattern); if (isset(self::$routes[$pattern])) { call_user_func_array(self::$routes[$pattern]['fn'], $arguments); } } else { $routes = Mecha::eat(self::$routes)->order('ASC', 'stack', true)->vomit(); foreach ($routes as $pattern => $cargo) { // If matched with the URL path if ($route = self::is($pattern)) { // Loading cargo(s) ... if (isset(self::$routes_over[$pattern])) { $fn = Mecha::eat(self::$routes_over[$pattern])->order('ASC', 'stack')->vomit(); foreach ($fn as $v) { call_user_func_array($v['fn'], $route['lot']); } } // Passed! return call_user_func_array($cargo['fn'], $route['lot']); } } } }
<?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'); });
public static function merge($path, $name = null, $addon = "", $call = null) { $path = is_string($path) && strpos($path, ';') !== false ? explode(';', $path) : (array) $path; $the_path = ASSET . DS . File::path($name); $the_path_log = SYSTEM . DS . 'log' . DS . 'asset.' . str_replace(array(ASSET . DS, DS), array("", '__'), $the_path) . '.log'; $is_valid = true; if (!file_exists($the_path_log)) { $is_valid = false; } else { $the_path_time = explode("\n", file_get_contents($the_path_log)); if (count($the_path_time) !== count($path)) { $is_valid = false; } else { foreach ($the_path_time as $i => $time) { $p = self::path($path[$i]); if (!file_exists($p) || (int) filemtime($p) !== (int) $time) { $is_valid = false; break; } } } } $time = ""; $content = ""; $e = File::E($name); if (!file_exists($the_path) || !$is_valid) { if (Text::check($e)->in(array('gif', 'jpeg', 'jpg', 'png'))) { foreach ($path as $p) { if (!self::ignored($p)) { $p = self::path($p); if (file_exists($p)) { $time .= filemtime($p) . "\n"; } } } File::write(trim($time))->saveTo($the_path_log); Image::take($path)->merge()->saveTo($the_path); } else { foreach ($path as $p) { if (!self::ignored($p)) { $p = self::path($p); if (file_exists($p)) { $time .= filemtime($p) . "\n"; $c = file_get_contents($p); if (strpos(File::B($p), '.min.') === false) { if (strpos(File::B($the_path), '.min.css') !== false) { $content .= Converter::detractShell($c) . "\n"; } else { if (strpos(File::B($the_path), '.min.js') !== false) { $content .= Converter::detractSword($c) . "\n"; } else { $content .= $c . "\n\n"; } } } else { $content .= $c . "\n\n"; } } } } File::write(trim($time))->saveTo($the_path_log); File::write(trim($content))->saveTo($the_path); } } if (is_null($call)) { $call = Mecha::alter($e, array('css' => 'stylesheet', 'js' => 'javascript', 'gif' => 'image', 'jpeg' => 'image', 'jpg' => 'image', 'png' => 'image')); } return call_user_func_array('self::' . $call, array($the_path, $addon)); }
<?php $bucket = array(); $url_base = $config->url . '/feed/json'; $json_order = strtoupper(Request::get('order', 'DESC')); $json_filter = Request::get('filter', ""); $json_limit = Request::get('chunk', 25); if ($pages = Mecha::eat(Get::articles($json_order, $json_filter))->chunk($config->offset, $json_limit)->vomit()) { foreach ($pages as $path) { $bucket[] = Get::articleHeader($path); } } $json = array('meta' => array('generator' => 'Mecha ' . MECHA_VERSION, 'title' => $config->title, 'slogan' => $config->slogan, 'url' => array('home' => $config->url, 'previous' => $config->offset > 1 ? Filter::colon('feed:url', $url_base . '/' . ($config->offset - 1)) : null, 'next' => $config->offset < ceil($config->total_articles / $json_limit) ? Filter::colon('feed:url', $url_base . '/' . ($config->offset + 1)) : null), 'description' => $config->description, 'update' => date('c'), 'author' => (array) $config->author, 'offset' => $config->offset, 'total' => $config->total_articles, 'tags' => Get::articleTags()), 'item' => null); if (!empty($bucket)) { $json['item'] = array(); foreach ($bucket as $i => $item) { $json['item'][$i] = array('title' => $item->title, 'url' => $item->url, 'date' => $item->date->W3C, 'update' => Date::format($item->update, 'c'), 'id' => $item->id, 'description' => $item->description, 'kind' => Mecha::A($item->kind)); Weapon::fire('json_item', array(&$json['item'][$i], $item, $i)); } } Weapon::fire('json_meta', array(&$json['meta'])); echo (isset($_GET['callback']) ? $_GET['callback'] . '(' : "") . json_encode($json) . (isset($_GET['callback']) ? ');' : "");
Shield::attach('page-' . $slug); }, 100); /** * Home Page * --------- * * [1]. / * */ Route::accept('/', function () use($config, $excludes) { Session::kill('search.query'); Session::kill('search.results'); $s = Get::articles(); if ($articles = Mecha::eat($s)->chunk(1, $config->index->per_page)->vomit()) { $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');
function do_comment_construct() { $config = Config::get(); $speak = Config::speak(); if ($config->page_type === 'article') { $comment_id = 'comment-%d'; // Your comment ID $comment_form_id = 'comment-form'; // Your comment form ID $article = isset($config->article->path) ? $config->article : false; $G = array('data' => array('article' => Mecha::A($article), 'comment_id' => $comment_id, 'comment_form_id' => $comment_form_id)); if ($article !== false && ($request = Request::post())) { if ($task = File::exist(SHIELD . DS . $config->shield . DS . 'workers' . DS . 'task.comment.php')) { require $task; // Custom comment constructor } else { // Check token Guardian::checkToken($request['token'], $article->url . '#' . $comment_form_id); $extension = $config->comments->moderation && !Guardian::happy() ? '.hold' : '.txt'; // Check name if (trim($request['name']) === "") { Notify::error(Config::speak('notify_error_empty_field', $speak->name)); } // Check email if (trim($request['email']) !== "") { if (!Guardian::check($request['email'], '->email')) { Notify::error($speak->notify_invalid_email); } else { // Disallow passenger(s) from entering your email address in the comment email field if (!Guardian::happy() && $request['email'] === $config->author->email) { Notify::warning(Config::speak('notify_warning_forbidden_input', array('<em>' . $request['email'] . '</em>', strtolower($speak->email)))); } } } else { Notify::error(Config::speak('notify_error_empty_field', $speak->email)); } // Check URL if (trim($request['url']) !== "" && !Guardian::check($request['url'], '->url')) { Notify::error($speak->notify_invalid_url); } // Check message if (trim($request['message']) === "") { Notify::error(Config::speak('notify_error_empty_field', $speak->message)); } // Check challenge if (!Guardian::checkMath($request['math'])) { Notify::error($speak->notify_invalid_math_answer); } // Check name length if (Guardian::check($request['name'], '->too_long', 100)) { Notify::error(Config::speak('notify_error_too_long', $speak->name)); } // Check email length if (Guardian::check($request['email'], '->too_long', 100)) { Notify::error(Config::speak('notify_error_too_long', $speak->email)); } // Check URL length if (Guardian::check($request['url'], '->too_long', 100)) { Notify::error(Config::speak('notify_error_too_long', $speak->url)); } // Check message length if (Guardian::check($request['message'], '->too_long', 1700)) { Notify::error(Config::speak('notify_error_too_long', $speak->message)); } // Check for spam keyword(s) in comment $fucking_words = explode(',', $config->keywords_spam); foreach ($fucking_words as $spam) { if ($f**k = trim($spam)) { if ($request['email'] === $f**k || strpos(strtolower($request['message']), strtolower($f**k)) !== false) { Notify::warning($speak->notify_warning_intruder_detected . ' <strong class="text-error pull-right">' . $f**k . '</strong>'); break; } } } if (!Notify::errors()) { $post = Date::slug($article->time); $id = (int) time(); $parent = Request::post('parent'); $P = array('data' => $request); $P['data']['id'] = $id; $name = strip_tags($request['name']); $email = Text::parse($request['email'], '->broken_entity'); $url = isset($request['url']) && trim($request['url']) !== "" ? $request['url'] : false; $parser = strip_tags(Request::post('content_type', $config->html_parser->active)); $message = Text::parse($request['message'], '->text', WISE_CELL . '<img>', false); $field = Request::post('fields', array()); include File::D(__DIR__, 2) . DS . 'task.fields.php'; // Temporarily disallow image(s) in comment to prevent XSS $message = preg_replace('#<img(\\s[^<>]*?)>#i', '<img$1>', $message); Page::header(array('Name' => $name, 'Email' => $email, 'URL' => $url, 'Status' => Guardian::happy() ? 1 : 2, 'Content Type' => $parser, 'Fields' => !empty($field) ? Text::parse($field, '->encoded_json') : false))->content($message)->saveTo(COMMENT . DS . $post . '_' . Date::slug($id) . '_' . ($parent ? Date::slug($parent) : '0000-00-00-00-00-00') . $extension); Notify::success(Config::speak('notify_success_submitted', $speak->comment)); if ($extension === '.hold') { Notify::info($speak->notify_info_comment_moderation); } Weapon::fire(array('on_comment_update', 'on_comment_construct'), array($G, $P)); Guardian::kick($config->url_current . $config->ur_query . (!Guardian::happy() && $config->comments->moderation ? '#' . $comment_form_id : '#' . sprintf($comment_id, Date::format($id, 'U')))); } else { Guardian::kick($config->url_current . $config->url_query . '#' . $comment_form_id); } } } } }
// include once ... } }, 20); Weapon::add('SHIPMENT_REGION_BOTTOM', function () use($config) { Session::kill('recent_item_update'); $path = __DIR__ . DS . 'assets' . DS . 'sword' . DS; echo Asset::javascript(array($path . 'ajax.js', $path . 'row.js', $path . 'slug.js', $path . 'upload.js', $path . 'tab.js', $path . 'toggle.js', $path . 'modal.js', $path . 'tooltip.js', $path . 'sortable.js', $path . 'accordion.js', SHIELD . DS . $config->shield . DS . 'assets' . DS . 'sword' . DS . 'manager.js'), "", 'sword/manager.min.js'); }, 1); /** * Footer Link(s) * -------------- */ if ($config->page_type === 'manager' || $config->is->post) { // Add default comment footer link(s) Weapon::add('comment_footer', function ($comment, $article) use($config, $speak) { $status = Mecha::alter(File::E($comment->path), array('hold' => Jot::span('info', Jot::icon('clock-o') . ' ' . $speak->pending) . ' · '), ""); echo $status . Cell::a($config->manager->slug . '/comment/repair/id:' . $comment->id, $speak->edit) . ' / ' . Cell::a($config->manager->slug . '/comment/kill/id:' . $comment->id, $speak->delete); }, 20); } /** * Widget Manager Menu(s) and Bar(s) * --------------------------------- * * [1]. Config::merge('manager_menu', array()); * [2]. Config::merge('manager_bar', array()); * */ Weapon::add('shield_before', function () { $config = Config::get(); $speak = Config::speak(); $total = $config->__total_comments;
$_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')); }); Guardian::kick($config->manager->slug . '/asset/' . $request['action'] . '/files:' . implode(';', $files)); } });
?> </th> </tr> </thead> <tbody> <tr> <td><?php echo $file->title; ?> </td> <td><code><?php echo $id; ?> </code></td> <?php $s = Mecha::alter($file->type, array('text' => $speak->text, 'boolean' => $speak->boolean, 'option' => $speak->option, 'file' => $speak->file, 'composer' => $speak->composer, 'editor' => $speak->editor, 't' => $speak->text, 'b' => $speak->boolean, 'o' => $speak->option, 'f' => $speak->file, 'c' => $speak->composer, 'e' => $speak->editor), $speak->summary); ?> <td><?php echo Jot::em('info', $s); ?> </td> <td><?php echo isset($file->scope) ? str_replace(',', '/', $file->scope) : '<em>' . $speak->all . '</em>'; ?> </td> </tr> </tbody> </table> <form class="form-kill form-field" id="form-kill" action="<?php echo $config->url_current; ?>
if ($_file !== false) { // Remove empty folder(s) $f = glob(File::D($_file) . DS . '*', GLOB_NOSORT); if (empty($f)) { File::open(File::D($_file))->delete(); } Notify::success(Config::speak('notify_file_deleted', '<code>' . File::B($_file) . '</code>')); } else { Notify::success(Config::speak('notify_success_deleted', $speak->shield)); } Weapon::fire(array('on_shield_update', 'on_shield_destruct'), array($P, $P)); Guardian::kick($config->manager->slug . '/shield' . ($_file !== false ? '/' . $folder : "")); } else { Notify::warning(Config::speak('notify_confirm_delete_', $file !== false ? '<code>' . $path . '</code>' : '<strong>' . $info->title . '</strong>')); } Shield::lot(array('segment' => 'shield', 'folder' => $folder, 'files' => Mecha::O(Get::files(SHIELD . DS . $folder, '*')), 'path' => $path))->attach('manager'); }); /** * Shield Attacher * --------------- */ Route::accept($config->manager->slug . '/shield/(attach|eject)/id:(:any)', function ($path = "", $slug = "") use($config, $speak) { if (!Guardian::happy(1) || !file_exists(SHIELD . DS . $slug)) { Shield::abort(); } $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));