public static function placeholder($url = null) { if (is_array($url)) { return Mecha::eat($url)->shake()->get(0); } return 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; }
/** * =================================================================== * 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()) { $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(); } }
/** * ============================================================== * 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; }
/** * ========================================================================== * EXTRACT PAGE FILE INTO LIST OF PAGE DATA FROM ITS PATH/SLUG/ID * ========================================================================== * * -- CODE: ----------------------------------------------------------------- * * var_dump(Get::page('about')); * * -------------------------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * ---------- | ------ | --------------------------------------------------- * $reference | mixed | Slug, ID, path or array of `Get::pageExtract()` * $excludes | array | Exclude some field(s) from result(s) * $folder | string | Folder of the page(s) * $connector | string | Path connector for page URL * $FP | string | Filter prefix for `Text::toPage()` * ---------- | ------ | --------------------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function page($reference, $excludes = array(), $folder = PAGE, $connector = '/', $FP = 'page:') { $config = Config::get(); $speak = Config::speak(); $excludes = array_flip($excludes); $results = false; // From `Get::pageExtract()` if (is_array($reference)) { $results = $reference; } else { // By path => `cabinet\pages\0000-00-00-00-00-00_1,2,3_page-slug.txt` if (strpos($reference, $folder) === 0) { $results = self::pageExtract($reference, $FP); } else { // By slug => `page-slug` or by ID => 12345 $results = self::pageExtract(self::pagePath($reference, $folder), $FP); } } if (!$results || !file_exists($results['path'])) { return false; } /** * RULES: Do not do any tags looping, content Markdown-ing * and external file requesting if it has been marked as * the excluded field(s). For better performance. */ $results = $results + Text::toPage(File::open($results['path'])->read(), isset($excludes['content']) ? false : 'content', $FP); $content = isset($results['content_raw']) ? $results['content_raw'] : ""; $time = str_replace(array(' ', ':'), '-', $results['time']); $extension = File::E($results['path']); if ($php_file = File::exist(File::D($results['path']) . DS . $results['slug'] . '.php')) { ob_start(); include $php_file; $results['content'] = ob_get_clean(); } $results['date'] = self::AMF(Date::extract($results['time']), $FP, 'date'); $results['url'] = self::AMF($config->url . $connector . $results['slug'], $FP, 'url'); $results['link'] = ""; $results['excerpt'] = ""; if (!isset($results['author'])) { $results['author'] = self::AMF($config->author, $FP, 'author'); } if (!isset($results['description'])) { $summary = Converter::curt($content, $config->excerpt_length, $config->excerpt_tail); $results['description'] = self::AMF($summary, $FP, 'description'); } $content_test = isset($excludes['content']) && strpos($content, '<!--') !== false ? Text::toPage(Text::ES($content), 'content', $FP) : $results; $content_test = $content_test['content']; $content_test = is_array($content_test) ? implode("", $content_test) : $content_test; // Redirect 301 with `<!-- kick: "http://example.com" -->` if (strpos($content_test, '<!-- kick:') !== false && $config->page_type === rtrim($FP, ':')) { preg_match('#<!-- kick\\: *([\'"]?)(.*?)\\1 -->#', $content_test, $matches); Guardian::kick($matches[2]); } // External link with `<!-- link: "http://example.com" -->` if (strpos($content_test, '<!-- link:') !== false) { preg_match('#<!-- link\\: *([\'"]?)(.*?)\\1 -->#', $content_test, $matches); $results['link'] = $matches[2]; $results['content'] = preg_replace('#<!-- link\\:.*? -->#', "", $results['content']); } // Manual post excerpt with `<!-- cut+ "Read More" -->` if (strpos($content_test, '<!-- cut+ ') !== false) { preg_match('#<!-- cut\\+( +([\'"]?)(.*?)\\2)? -->#', $content_test, $matches); $more = !empty($matches[3]) ? $matches[3] : $speak->read_more; $content_test = preg_replace('#<!-- cut\\+( +(.*?))? -->#', '<p><a class="fi-link" href="' . $results['url'] . '#read-more:' . $results['id'] . '">' . $more . '</a></p><!-- cut -->', $content_test); } // ... or `<!-- cut -->` if (strpos($content_test, '<!-- cut -->') !== false) { $parts = explode('<!-- cut -->', $content_test, 2); $results['excerpt'] = self::AMF(trim($parts[0]), $FP, 'excerpt'); $results['content'] = preg_replace('#<p><a class="fi-link" href=".*?">.*?<\\/a><\\/p>#', "", trim($parts[0])) . NL . NL . '<span class="fi" id="read-more:' . $results['id'] . '" aria-hidden="true"></span>' . NL . NL . trim($parts[1]); } if (!isset($excludes['tags'])) { $tags = array(); foreach ($results['kind'] as $id) { $tags[] = self::rawTag($id); } $results['tags'] = self::AMF(Mecha::eat($tags)->order('ASC', 'name')->vomit(), $FP, 'tags'); } if (!isset($excludes['css']) || !isset($excludes['js'])) { if ($file = File::exist(CUSTOM . DS . $time . '.' . $extension)) { $custom = explode(SEPARATOR, File::open($file)->read()); $css = isset($custom[0]) ? Text::DS(trim($custom[0])) : ""; $js = isset($custom[1]) ? Text::DS(trim($custom[1])) : ""; /** * CSS * --- * * css_raw * page:css_raw * custom:css_raw * * shortcode * page:shortcode * custom:shortcode * * css * page:css * custom:css * */ $css = self::AMF($css, $FP, 'css_raw'); $results['css_raw'] = Filter::apply('custom:css_raw', $css); $css = self::AMF($css, $FP, 'shortcode'); $css = Filter::apply('custom:shortcode', $css); $css = self::AMF($css, $FP, 'css'); $results['css'] = Filter::apply('custom:css', $css); /** * JS * -- * * js_raw * page:js_raw * custom:js_raw * * shortcode * page:shortcode * custom:shortcode * * js * page:js * custom:js * */ $js = self::AMF($js, $FP, 'js_raw'); $results['js_raw'] = Filter::apply('custom:js_raw', $js); $js = self::AMF($js, $FP, 'shortcode'); $js = Filter::apply('custom:shortcode', $js); $js = self::AMF($js, $FP, 'js'); $results['js'] = Filter::apply('custom:js', $js); } else { $results['css'] = $results['js'] = $results['css_raw'] = $results['js_raw'] = ""; } $custom = $results['css'] . $results['js']; } else { $custom = ""; } $results['images'] = self::AMF(self::imagesURL($results['content'] . $custom), $FP, 'images'); $results['image'] = self::AMF(isset($results['images'][0]) ? $results['images'][0] : Image::placeholder(), $FP, 'image'); $comments = self::comments($results['id'], 'ASC', Guardian::happy() ? 'txt,hold' : 'txt'); $results['total_comments'] = self::AMF($comments !== false ? count($comments) : 0, $FP, 'total_comments'); $results['total_comments_text'] = self::AMF($results['total_comments'] . ' ' . ($results['total_comments'] === 1 ? $speak->comment : $speak->comments), $FP, 'total_comments_text'); if (!isset($excludes['comments'])) { if ($comments) { $results['comments'] = array(); foreach ($comments as $comment) { $results['comments'][] = self::comment($comment); } $results['comments'] = self::AMF($results['comments'], $FP, 'comments'); } } unset($comments); /** * Custom Field(s) * --------------- */ if (!isset($excludes['fields'])) { /** * Initialize custom field(s) with the default value(s) so that * user(s) don't have to write `isset()` function multiple time(s) * just to prevent error message(s) because of the object key(s) * that is not available in the old post(s). */ $fields = self::state_field(rtrim($FP, ':'), null, array(), false); $init = array(); foreach ($fields as $key => $value) { $init[$key] = $value['value']; } /** * Start re-writing ... */ if (isset($results['fields']) && is_array($results['fields'])) { foreach ($results['fields'] as $key => $value) { if (is_array($value) && isset($value['type'])) { // <= 1.1.3 $value = isset($value['value']) ? $value['value'] : false; } $init[$key] = self::AMF($value, $FP, 'fields.' . $key); } } $results['fields'] = $init; unset($fields, $init); } /** * Exclude some field(s) from result(s) */ foreach ($results as $key => $value) { if (isset($excludes[$key])) { unset($results[$key]); } } return Mecha::O($results); }
<?php /** * Post Manager * ------------ */ Route::accept(array($config->manager->slug . '/(' . $post . ')', $config->manager->slug . '/(' . $post . ')/(:num)'), function ($segment = "", $offset = 1) use($config, $speak) { $posts = false; $offset = (int) $offset; $s = call_user_func('Get::' . $segment . 's', strtoupper(Request::get('order', 'DESC')), Request::get('filter', ""), 'txt,draft,archive'); if ($files = Mecha::eat($s)->chunk($offset, $config->manager->per_page)->vomit()) { $posts = Mecha::walk($files, function ($v) use($segment) { return call_user_func('Get::' . $segment . 'Header', $v); }); } else { if ($offset !== 1) { Shield::abort(); } } Config::set(array('page_title' => $speak->{$segment . 's'} . $config->title_separator . $config->manager->title, 'pages' => $posts, 'offset' => $offset, 'pagination' => Navigator::extract($s, $offset, $config->manager->per_page, $config->manager->slug . '/' . $segment), 'cargo' => 'cargo.post.php')); Shield::lot(array('segment' => $segment))->attach('manager'); }); /** * Post Repairer/Igniter * --------------------- */ Route::accept(array($config->manager->slug . '/(' . $post . ')/ignite', $config->manager->slug . '/(' . $post . ')/repair/id:(:num)'), function ($segment = "", $id = false) use($config, $speak, $response) { $units = array('title', 'slug', 'link', 'content', 'content_type', 'description', 'post' . DS . 'author'); foreach ($units as $k => $v) { Weapon::add('tab_content_1_before', function ($page, $segment) use($config, $speak, $v) { include __DIR__ . DS . 'unit' . DS . 'form' . DS . $v . '.php';
/** * ========================================================================== * GET LIST OF RESPONSE(S) DETAIL(S) * ========================================================================== * * -- CODE: ----------------------------------------------------------------- * * foreach(Get::responsesExtract() as $file) { * echo $file['path'] . '<br>'; * } * * -------------------------------------------------------------------------- * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Parameter | Type | Description * --------- | ------ | ---------------------------------------------------- * $sorter | string | The key of array item as sorting reference * --------- | ------ | ---------------------------------------------------- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * */ public static function responsesExtract($order = 'ASC', $sorter = 'time', $filter = "", $e = 'txt', $FP = 'response:', $folder = RESPONSE) { if ($files = self::responses($order, $filter, $e, $folder)) { $results = array(); foreach ($files as $file) { $results[] = self::responseExtract($file, $FP); } unset($files); return !empty($results) ? Mecha::eat($results)->order($order, $sorter)->vomit() : false; } return false; }
if (is_string($v)) { $menus[$k] = $v; } else { $stack = isset($v['stack']) ? $v['stack'] : 10; $_k = (strpos($v['icon'], '<') === false ? Jot::icon($v['icon'], 'fw') : $v['icon']) . ' <span class="label">' . $k . '</span>' . (isset($v['count']) && ($v['count'] === '∞' || (double) $v['count'] > 0) ? ' <span class="counter">' . $v['count'] . '</span>' : ""); $menus[$_k] = isset($v['url']) ? $v['url'] : null; } } } Menu::add('manager', $menus); $html .= Menu::manager('ul', $T1); } if ($type === 'BAR') { $bars = array(); if ($_bars = Mecha::A(Config::get('manager_bar'))) { $_bars = Mecha::eat($_bars)->order('ASC', 'stack', true, 10)->vomit(); foreach ($_bars as $k => $v) { if (is_string($v)) { $bar = $v; } else { $t = ' data-tooltip="' . Text::parse(isset($v['description']) ? $v['description'] : $k, '->encoded_html') . '"'; if (isset($v['url'])) { $url = Filter::colon('manager:url', Converter::url($v['url'])); $c = $config->url_current === $url ? ' ' . Widget::$config['classes']['current'] : ""; $bar = '<a class="item' . $c . '" href="' . $url . '"' . $t . '>'; } else { $bar = '<span class="item a"' . $t . '>'; } $bar .= isset($v['icon']) ? strpos($v['icon'], '<') === false ? Jot::icon($v['icon']) : $v['icon'] : $k; $bar .= ' <span class="label">' . $k . '</span>'; if (isset($v['count']) && ($v['count'] === '∞' || (double) $v['count'] > 0)) {
/** * Widget Related Post * ------------------- * * [1]. Widget::relatedPost(); * [2]. Widget::relatedPost(5); * */ public static function relatedPost($total = 7) { $T1 = TAB; $T2 = str_repeat($T1, 2); $config = Config::get(); if ($config->page_type !== 'article') { return self::randomPost($total); } else { if (!($files = Get::articles('DESC', 'kind:' . implode(',', (array) $config->article->kind)))) { return O_BEGIN . '<div class="widget widget-related widget-related-post">' . Config::speak('notify_empty', strtolower($speak->posts)) . '</div>' . O_END; } if (count($files) <= 1) { return self::randomPost($total); } $files = Mecha::eat($files)->shake()->vomit(); $html = O_BEGIN . '<div class="widget widget-related widget-related-post" id="widget-related-post-' . self::$id['related_post'] . '">' . NL; self::$id['related_post']++; $html .= $T1 . '<ul>' . NL; for ($i = 0, $count = count($files); $i < $total; ++$i) { if ($i === $count) { break; } if ($files[$i] !== $config->article->path) { $article = Get::articleAnchor($files[$i]); $html .= $T2 . '<li><a href="' . $article->url . '">' . $article->title . '</a></li>' . NL; } } $html .= $T1 . '</ul>' . NL; $html .= '</div>' . O_END; $html = Filter::apply('widget', $html); return Filter::apply('widget:related.post', Filter::apply('widget:related', $html)); } }
/** * =========================================================================== * 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']); } } } }
}); $P = array('data' => $_FILES); Weapon::fire(array('on_asset_update', 'on_asset_construct'), array($P, $P)); } if (!Notify::errors()) { Guardian::kick($config->manager->slug . '/asset/' . $offset . str_replace('&', '&', HTTP::query('path', $p))); } else { $tab_id = 'tab-content-3'; include __DIR__ . DS . 'task.js.tab.php'; } } } $filter = Request::get('q', ""); $filter = $filter ? Text::parse($filter, '->safe_file_name') : ""; $files = Get::closestFiles($d, "", 'ASC', 'path', $filter); $files_chunk = Mecha::eat($files)->chunk($offset, $config->per_page * 2)->vomit(); Config::set(array('page_title' => $speak->assets . $config->title_separator . $config->manager->title, 'offset' => $offset, 'pagination' => Navigator::extract($files, $offset, $config->per_page * 2, $config->manager->slug . '/asset'), 'cargo' => 'cargo.asset.php')); Shield::lot(array('segment' => 'asset', 'files' => $files_chunk ? Mecha::O($files_chunk) : false))->attach('manager'); }); /** * Asset Repairer * -------------- */ Route::accept($config->manager->slug . '/asset/repair/(file|files):(:all)', function ($path = "", $old = "") use($config, $speak) { if (!Guardian::happy(1)) { Shield::abort(); } $old = File::path($old); $p = Request::get('path', false); if (!($file = File::exist(ASSET . DS . $old))) { Shield::abort();
<?php /** * Page Manager * ------------ */ Route::accept(array($config->manager->slug . '/page', $config->manager->slug . '/page/(:num)'), function ($offset = 1) use($config, $speak) { $pages = false; $offset = (int) $offset; if ($files = Mecha::eat(Get::pages('DESC', "", 'txt,draft,archive'))->chunk($offset, $config->manager->per_page)->vomit()) { $pages = array(); foreach ($files as $file) { $pages[] = Get::pageHeader($file); } unset($files); } else { if ($offset !== 1) { Shield::abort(); } } Config::set(array('page_title' => $speak->pages . $config->title_separator . $config->manager->title, 'offset' => $offset, 'pages' => $pages, 'pagination' => Navigator::extract(Get::pages('DESC', "", 'txt,draft,archive'), $offset, $config->manager->per_page, $config->manager->slug . '/page'), 'cargo' => DECK . DS . 'workers' . DS . 'cargo.page.php')); Shield::lot('segment', 'page')->attach('manager', false); }); /** * Page Composer/Updater * --------------------- */ Route::accept(array($config->manager->slug . '/page/ignite', $config->manager->slug . '/page/repair/id:(:num)'), function ($id = false) use($config, $speak) { Config::set('cargo', DECK . DS . 'workers' . DS . 'repair.page.php'); if ($id && ($page = Get::page($id, array('content', 'excerpt', 'tags', 'comments')))) { $extension_o = $page->state === 'published' ? '.txt' : '.draft';
/** * Widget Related Post * ------------------- * * [1]. Widget::relatedPost(); * [2]. Widget::relatedPost(5); * */ public static function relatedPost($total = 7, $folder = ARTICLE) { $T1 = TAB; $T2 = str_repeat($T1, 2); $p = $folder !== POST ? File::B($folder) : 'post'; $id = Config::get('widget_related_' . $p . '_id', 0) + 1; $config = Config::get(); $speak = Config::speak(); $kind = isset($config->{$p}->kind) ? (array) $config->{$p}->kind : array(); $html = O_BEGIN . '<div class="widget widget-related widget-related-post" id="widget-related-post-' . $id . '">' . NL; if ($config->page_type !== $p) { return self::randomPost($total, $folder); } else { if ($files = call_user_func('Get::' . $p . 's', 'DESC', 'kind:' . implode(',', $kind))) { if (count($files) <= 1) { return self::randomPost($total, $folder); } $files = Mecha::eat($files)->shake()->vomit(); $html .= $T1 . '<ul>' . NL; for ($i = 0, $count = count($files); $i < $total; ++$i) { if ($i === $count) { break; } if ($files[$i] !== $config->{$p}->path) { $post = call_user_func('Get::' . $p . 'Anchor', $files[$i]); $html .= $T2 . '<li><a href="' . $post->url . '">' . $post->title . '</a></li>' . NL; } } $html .= $T1 . '</ul>' . NL; } else { $html .= $T1 . Config::speak('notify_empty', strtolower($speak->{$p . 's'})) . NL; } } $html .= '</div>' . O_END; Config::set('widget_related_' . $p . '_id', $id); return Filter::apply(array('widget:related.' . $p, 'widget:related.post', 'widget:related', 'widget'), $html, $id); }
} }); Config::set(array('page_title' => $page->title . $config->title_separator . $config->title, 'page' => $page)); Shield::attach('page-' . $slug); }, 100); /** * Home Page * --------- * * [1]. / * */ Route::accept('/', function () use($config) { Session::kill('search_query'); Session::kill('search_results'); if ($files = Mecha::eat(Get::articles())->chunk(1, $config->index->per_page)->vomit()) { $articles = array(); foreach ($files as $file) { $articles[] = Get::article($file, array('content', 'tags', 'css', 'js', 'comments')); } unset($files); } else { $articles = false; } Config::set(array('articles' => $articles, 'pagination' => Navigator::extract(Get::articles(), 1, $config->index->per_page, $config->index->slug))); Shield::attach('page-home'); }, 110); /** * Do Routing * ---------- */
/** * =========================================================================== * EXECUTE THE ADDED ROUTE(S) * =========================================================================== * * -- CODE: ------------------------------------------------------------------ * * Route::execute(); * * --------------------------------------------------------------------------- * * Route::execute('foo/(:num)', array(4)); // Re-execute this route * * --------------------------------------------------------------------------- * */ public static function execute($pattern = null, $arguments = array(), $stack = null) { $routes = Mecha::eat(self::$routes)->order('ASC', 'stack')->vomit(); if (!is_null($pattern)) { $pattern = self::path($pattern); foreach ($routes as $route) { if ($route['pattern'] === $pattern) { if (!is_null($stack)) { if ((double) $route['stack'] === (double) $stack) { call_user_func_array($route['fn'], $arguments); } } else { call_user_func_array($route['fn'], $arguments); } } } } else { $url = Config::get('url_path'); foreach ($routes as $route) { $pattern = $route['pattern']; // If not rejected if (!isset(self::$routes_e[$pattern . '->' . $route['stack']])) { // If matched with URL path if (preg_match('#^' . self::fix($pattern) . '$#', $url, $arguments)) { array_shift($arguments); // Loading cargo(s) ... if (isset(self::$routes_over[$pattern]) && is_array(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'], array_values($arguments)); } } // Passed! return call_user_func_array($route['fn'], array_values($arguments)); } } } } }
<?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']) ? ');' : "");
Route::accept(array($config->manager->slug . '/(' . $response . ')', $config->manager->slug . '/(' . $response . ')/(:num)'), function ($segment = "", $offset = 1) use($config, $speak, $post) { if (!Guardian::happy(1)) { Shield::abort(); } File::write($config->{'__total_' . $segment . 's'})->saveTo(LOG . DS . $segment . 's.total.log', 0600); if ($files = call_user_func('Get::' . $segment . 's', 'DESC', Request::get('filter', ""), 'txt,hold')) { $responses_id = Mecha::walk($files, function ($v) { $parts = explode('_', File::B($v)); return $parts[1]; }); if (strtoupper(Request::get('order', 'DESC')) === 'DESC') { rsort($responses_id); } else { sort($responses_id); } $responses_id = Mecha::eat($responses_id)->chunk($offset, $config->manager->per_page)->vomit(); $responses = Mecha::walk($responses_id, function ($v) use($segment) { return call_user_func('Get::' . $segment, $v); }); } else { $files = array(); $responses = false; } Config::set(array('page_title' => $speak->{$segment . 's'} . $config->title_separator . $config->manager->title, 'pages' => $responses, 'offset' => $offset, 'pagination' => Navigator::extract($files, $offset, $config->manager->per_page, $config->manager->slug . '/' . $segment), 'cargo' => 'cargo.response.php')); Shield::lot(array('segment' => array($segment, $post)))->attach('manager'); }); /** * Response Repairer/Igniter * ------------------------- */ Route::accept(array($config->manager->slug . '/(' . $response . ')/ignite', $config->manager->slug . '/(' . $response . ')/repair/id:(:num)'), function ($segment = "", $id = false) use($config, $speak, $post) {
$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(); }
*/ Route::accept(array($config->manager->slug . '/comment', $config->manager->slug . '/comment/(:num)'), function ($offset = 1) use($config, $speak) { if (Guardian::get('status') !== 'pilot') { Shield::abort(); } $offset = (int) $offset; File::write($config->total_comments_backend)->saveTo(SYSTEM . DS . 'log' . DS . 'comments.total.log', 0600); if ($files = Get::comments(null, 'DESC', 'txt,hold')) { $comments = array(); $comments_id = array(); foreach ($files as $file) { $parts = explode('_', File::B($file)); $comments_id[] = $parts[1]; } rsort($comments_id); foreach (Mecha::eat($comments_id)->chunk($offset, $config->manager->per_page)->vomit() as $comment) { $comments[] = Get::comment($comment); } unset($comments_id, $files); } else { $comments = false; } Config::set(array('page_title' => $speak->comments . $config->title_separator . $config->manager->title, 'offset' => $offset, 'responses' => $comments, 'pagination' => Navigator::extract(Get::comments(null, 'DESC', 'txt,hold'), $offset, $config->manager->per_page, $config->manager->slug . '/comment'), 'cargo' => DECK . DS . 'workers' . DS . 'cargo.comment.php')); Shield::lot('segment', 'comment')->attach('manager', false); }); /** * Comment Repair * -------------- */ Route::accept($config->manager->slug . '/comment/repair/id:(:num)', function ($id = "") use($config, $speak) { if (Guardian::get('status') !== 'pilot' || !($comment = Get::comment($id))) {
} }); 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 * -----------------
<?php /** * Cache Manager * ------------- */ Route::accept(array($config->manager->slug . '/cache', $config->manager->slug . '/cache/(:num)'), function ($offset = 1) use($config, $speak) { if (Guardian::get('status') !== 'pilot') { Shield::abort(); } $offset = (int) $offset; $filter = Request::get('q', false); $filter = $filter ? Text::parse($filter, '->safe_file_name') : ""; $takes = Get::files(CACHE, '*', 'DESC', 'update', $filter); if ($_files = Mecha::eat($takes)->chunk($offset, $config->per_page * 2)->vomit()) { $files = array(); foreach ($_files as $_file) { $files[] = $_file; } unset($_files); } else { $files = false; } Config::set(array('page_title' => $speak->caches . $config->title_separator . $config->manager->title, 'offset' => $offset, 'files' => $files, 'pagination' => Navigator::extract($takes, $offset, $config->per_page * 2, $config->manager->slug . '/cache'), 'cargo' => DECK . DS . 'workers' . DS . 'cargo.cache.php')); Shield::lot('segment', 'cache')->attach('manager', false); }); /** * Cache Repair * ------------ */ Route::accept($config->manager->slug . '/cache/repair/(file|files):(:all)', function ($prefix = "", $path = "") use($config, $speak) {