Example #1
0
 public function testRouteMethodPlugins()
 {
     $r = new Route('/test/', '\\Pex\\HttpTest\\View');
     $this->assertTrue($r->accept('/test/decor'));
     $fn = $r->match('GET', '/test/decor', $parameters);
     $this->assertEquals([new \Pex\HttpTest\View(), 'decor'], $fn->getCallable());
     $dummyPlugin = function ($name, $args) {
         return [$name, $args];
     };
     $this->assertEquals([['decor', ['foo', 'bar']], ['view', ['abc.php']]], $fn->buildPlugins(['view' => $dummyPlugin, 'decor' => $dummyPlugin]));
 }
<?php

Route::accept($config->manager->slug . '/plugin/' . File::B(__DIR__) . '/update', function () use($config, $speak) {
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        unset($request['token']);
        $request['twitter_site'] = trim(Text::parse($request['twitter_site'], '->array_key'), '_');
        $request['twitter_creator'] = trim(Text::parse($request['twitter_creator'], '->array_key'), '_');
        File::serialize($request)->saveTo(__DIR__ . DS . 'states' . DS . 'config.txt', 0600);
        Notify::success(Config::speak('notify_success_updated', $speak->plugin));
        Guardian::kick(File::D($config->url_current));
    }
});
Example #3
0
/**
 * 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');
/**
 * Do Routing
Example #4
0
<?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');
});
Example #5
0
<?php

// The `__launch.php` file will be included only in the backend
Route::accept($config->manager->slug . '/plugin/' . File::B(__DIR__) . '/update', function () use($config, $speak) {
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        // [2]
        File::write('test!')->saveTo(__DIR__ . DS . 'states' . DS . 'config.txt', 0600);
        Notify::success(Config::speak('notify_success_updated', $speak->plugin));
        // [3]
        Guardian::kick(File::D($config->url_current));
        // [4]
    }
});
<?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>'));
    }
Example #7
0
<?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

Route::accept($config->manager->slug . '/plugin/' . File::B(__DIR__) . '/update', function () use($config, $speak) {
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        File::write($request['content'])->saveTo(__DIR__ . DS . 'workers' . DS . '404.php');
        Notify::success(Config::speak('notify_success_updated', $speak->plugin));
        Guardian::kick(File::D($config->url_current));
    }
});
<?php

define('PRIVATE_POST_SALT', 'VGF1ZmlrIE51cnJvaG1hbg==' . date('Y-m-d'));
// should be valid for 1 day
Route::accept(File::B(__DIR__) . '/do:access', function () use($config, $speak) {
    if ($request = Request::post()) {
        Guardian::checkToken($request['token'], $request['kick']);
        if (!isset($request['_'])) {
            Notify::error($speak->plugin_private_post->error);
        }
        // your answer can't contains a `:` because `:` is the separator
        // if the `:` is very important for the answer, then you must
        // replace all `:` character(s) in the password field with `&#58;`
        $request['access'] = str_replace(':', '&#58;', $request['access']);
        $access = md5($request['access'] . PRIVATE_POST_SALT);
        if ((string) $request['_'] === (string) $access) {
            Session::set('is_allow_post_access', $access);
            Guardian::kick($request['kick']);
        }
        Notify::error($speak->plugin_private_post->error);
        Guardian::kick($request['kick']);
    }
    Shield::abort();
});
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;
Example #10
0
<?php

/**
 * Plugin Updater
 * --------------
 */
Route::accept($config->manager->slug . '/plugin/' . File::B(__DIR__) . '/update', function () use($config, $speak) {
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        unset($request['token']);
        // Remove token from request array
        $results = array();
        foreach (explode("\n", $request['content']) as $path) {
            $s = explode(' ~', $path, 2);
            if (trim($path) !== "" && trim($s[0]) !== "") {
                $results[trim($s[0])] = isset($s[1]) && trim($s[1]) !== "" ? (double) trim($s[1]) : true;
            }
        }
        unset($request['content']);
        // Remove content from request array
        $request['path'] = $results;
        File::serialize($request)->saveTo(__DIR__ . DS . 'states' . DS . 'config.txt', 0600);
        Notify::success(Config::speak('notify_success_updated', $speak->plugin));
        Guardian::kick(File::D($config->url_current));
    }
});
/**
 * Cache Killer
 * ------------
 */
function do_remove_cache()
{
Example #11
0
    if ($mode === 'eject') {
        // Rename `launch.php` to `pending.php` or `__launch.php` to `__pending.php`
        File::open(PLUGIN . DS . $slug . DS . 'launch.php')->renameTo('pending.php');
        File::open(PLUGIN . DS . $slug . DS . '__launch.php')->renameTo('__pending.php');
    }
    Guardian::kick($config->manager->slug . '/plugin/' . $page_current);
});
/**
 * Plugin Killer
 * -------------
 */
Route::accept($config->manager->slug . '/plugin/kill/id:(:any)', function ($slug = "") use($config, $speak) {
    if (!Guardian::happy(1) || !($plugin = Plugin::exist($slug))) {
        Shield::abort();
    }
    $info = Plugin::info($slug, true);
    $info['slug'] = $slug;
    Config::set(array('page_title' => $speak->deleting . ': ' . $info['title'] . $config->title_separator . $config->manager->title, 'page' => $info, 'cargo' => 'kill.plugin.php'));
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        $P = array('data' => array('id' => $slug));
        Weapon::fire(array('on_plugin_update', 'on_plugin_destruct', 'on_plugin_' . md5($slug) . '_update', 'on_plugin_' . md5($slug) . '_destruct'), array($P, $P));
        File::open($plugin)->delete();
        // delete later ...
        Notify::success(Config::speak('notify_success_deleted', $speak->plugin));
        Guardian::kick($config->manager->slug . '/plugin');
    } else {
        Notify::warning(Config::speak('notify_confirm_delete_', '<strong>' . $info['title'] . '</strong>'));
    }
    Shield::lot(array('segment' => 'plugin'))->attach('manager');
});
Example #12
0
});
/**
 * Page Killer
 * -----------
 */
Route::accept($config->manager->slug . '/page/kill/id:(:num)', function ($id = "") use($config, $speak) {
    if (!($page = Get::page($id, array('comments')))) {
        Shield::abort();
    }
    if (Guardian::get('status') !== 'pilot' && Guardian::get('author') !== $page->author) {
        Shield::abort();
    }
    Config::set(array('page_title' => $speak->deleting . ': ' . $page->title . $config->title_separator . $config->manager->title, 'page' => $page, 'cargo' => DECK . DS . 'workers' . DS . 'kill.page.php'));
    $G = array('data' => Mecha::A($page));
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        File::open($page->path)->delete();
        $task_connect = $page;
        $P = array('data' => $request);
        include DECK . DS . 'workers' . DS . 'task.field.3.php';
        include DECK . DS . 'workers' . DS . 'task.custom.3.php';
        Notify::success(Config::speak('notify_success_deleted', $page->title));
        Weapon::fire('on_page_update', array($G, $G));
        Weapon::fire('on_page_destruct', array($G, $G));
        Guardian::kick($config->manager->slug . '/page');
    } else {
        Notify::warning(Config::speak('notify_confirm_delete_', '<strong>' . $page->title . '</strong>'));
        Notify::warning(Config::speak('notify_confirm_delete_page', strtolower($speak->page)));
    }
    Shield::lot('segment', 'page')->attach('manager', false);
});
Weapon::add('thumbnail_before', 'do_thumbnail_http_header', 1);
Route::accept('t/(:num)/(:all)', function ($size = 0, $path = "") {
    $path = Filter::colon('thumbnail:path', ASSET . DS . File::path($path));
    $G = array('data' => array('path' => $path, 'lot' => func_get_args()));
    if (!($path = File::exist($path))) {
        HTTP::status(404);
        exit;
    }
    Weapon::fire('thumbnail_before', array($G, $G));
    Image::take($path)->resize($size)->draw();
}, 12);
Route::accept('t/(:num)/(:num)/(:all)', function ($width = 0, $height = 0, $path = "") {
    $path = Filter::colon('thumbnail:path', ASSET . DS . File::path($path));
    $G = array('data' => array('path' => $path, 'lot' => func_get_args()));
    if (!($path = File::exist($path))) {
        HTTP::status(404);
        exit;
    }
    Weapon::fire('thumbnail_before', array($G, $G));
    Image::take($path)->crop($width, $height)->draw();
}, 11);
Route::accept('t/(:num)/(:num)/(:num)/(:num)/(:all)', function ($x = 0, $y = 0, $width = 0, $height = 0, $path = "") {
    $path = Filter::colon('thumbnail:path', ASSET . DS . File::path($path));
    $G = array('data' => array('path' => $path, 'lot' => func_get_args()));
    if (!($path = File::exist($path))) {
        HTTP::status(404);
        exit;
    }
    Weapon::fire('thumbnail_before', array($G, $G));
    Image::take($path)->crop($x, $y, $width, $height)->draw();
}, 10);
Example #14
0
<?php

/**
 * Plugin Updater
 * --------------
 */
Route::accept($config->manager->slug . '/plugin/' . File::B(__DIR__) . '/update', function () use($config, $speak) {
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        $state = PLUGIN . DS . File::B(__DIR__) . DS . 'states' . DS;
        File::write(trim($request['abbr']))->saveTo($state . 'abbr.txt', 0600);
        File::write(trim($request['url']))->saveTo($state . 'url.txt', 0600);
        Notify::success(Config::speak('notify_success_updated', $speak->plugin));
        Guardian::kick(File::D($config->url_current));
    }
});
Example #15
0
<?php

/**
 * Plugin Updater
 * --------------
 */
Route::accept($config->manager->slug . '/plugin/' . File::B(__DIR__) . '/update', function () use($config, $speak) {
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        unset($request['token']);
        // Remove token from request array
        File::serialize($request)->saveTo(__DIR__ . DS . 'states' . DS . 'config.txt', 0600);
        Notify::success(Config::speak('notify_success_updated', $speak->plugin));
        Guardian::kick(File::D($config->url_current));
    }
});
Example #16
0
    $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));
    Notify::success(Config::speak('notify_success_updated', $speak->shield));
    foreach (glob(LOG . DS . 'asset.*.log', GLOB_NOSORT) as $asset_cache) {
        File::open($asset_cache)->delete();
    }
    Guardian::kick($config->manager->slug . '/shield/' . $slug);
});
/**
 * Shield Updater (Base)
 * ---------------------
 */
if ($route = Route::is($config->manager->slug . '/shield/(:any)/update')) {
    Weapon::add('routes_before', function () use($config, $speak, $route) {
        if (!Route::accepted($route['path'])) {
            Route::accept($route['path'], function () use($config, $speak, $route) {
                if ($request = Request::post()) {
                    $s = $route['lot'][0];
                    $request = Filter::apply('request:__shield', $request, $s);
                    Guardian::checkToken($request['token']);
                    unset($request['token']);
                    // remove token from request array
                    File::serialize($request)->saveTo(SHIELD . DS . $s . DS . 'states' . DS . 'config.txt', 0600);
                    Notify::success(Config::speak('notify_success_updated', $speak->shield));
                    Guardian::kick(File::D($config->url_current));
                }
            });
        }
    }, 1);
}
Example #17
0
Route::accept($config->manager->slug . '/(' . $post . ')/kill/id:(:num)', function ($segment = "", $id = "") use($config, $speak, $response) {
    if (!($post = call_user_func('Get::' . $segment, $id, array('content', 'tags')))) {
        Shield::abort();
    }
    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');
});
Example #18
0
 * Response Killer
 * ---------------
 */
Route::accept($config->manager->slug . '/(' . $response . ')/kill/id:(:num)', function ($segment = "", $id = "") use($config, $speak, $post) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    if (!($response = call_user_func('Get::' . $segment, $id))) {
        Shield::abort();
        // File not found!
    }
    Config::set(array('page_title' => $speak->deleting . ': ' . $speak->{$segment} . $config->title_separator . $config->manager->title, 'page' => $response, 'cargo' => 'kill.response.php'));
    if ($request = Request::post()) {
        $request = Filter::apply('request:__' . $segment, $request, $id);
        $P = array('data' => Mecha::A($response));
        Guardian::checkToken($request['token']);
        File::open($response->path)->delete();
        $post_o = $post;
        $post = $response;
        include __DIR__ . DS . 'task.substance.kill.php';
        $post = $post_o;
        File::write($config->{'__total_' . $segment . 's'} - 1)->saveTo(LOG . DS . $segment . 's.total.log', 0600);
        Notify::success(Config::speak('notify_success_deleted', $speak->{$segment}));
        Weapon::fire(array('on_' . $segment . '_update', 'on_' . $segment . '_destruct'), array($P, $P));
        Guardian::kick($config->manager->slug . '/' . $segment);
    } else {
        File::write($config->{'__total_' . $segment . 's'})->saveTo(LOG . DS . $segment . 's.total.log', 0600);
        Notify::warning($speak->notify_confirm_delete);
    }
    Shield::lot(array('segment' => array($segment, $post)))->attach('manager');
});
Example #19
0
 * 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);
Example #20
0
});
/**
 * Comment Killer
 * --------------
 */
Route::accept($config->manager->slug . '/comment/kill/id:(:num)', function ($id = "") use($config, $speak) {
    if (Guardian::get('status') !== 'pilot') {
        Shield::abort();
    }
    if (!($comment = Get::comment($id))) {
        Shield::abort();
        // File not found!
    }
    Config::set(array('page_title' => $speak->deleting . ': ' . $speak->comment . $config->title_separator . $config->manager->title, 'response' => $comment, 'cargo' => DECK . DS . 'workers' . DS . 'kill.comment.php'));
    if ($request = Request::post()) {
        $P = array('data' => Mecha::A($comment));
        Guardian::checkToken($request['token']);
        File::open($comment->path)->delete();
        $task_connect = $comment;
        include DECK . DS . 'workers' . DS . 'task.field.3.php';
        File::write($config->total_comments_backend - 1)->saveTo(SYSTEM . DS . 'log' . DS . 'comments.total.log', 0600);
        Notify::success(Config::speak('notify_success_deleted', $speak->comment));
        Weapon::fire('on_comment_update', array($P, $P));
        Weapon::fire('on_comment_destruct', array($P, $P));
        Guardian::kick($config->manager->slug . '/comment');
    } else {
        File::write($config->total_comments_backend)->saveTo(SYSTEM . DS . 'log' . DS . 'comments.total.log', 0600);
        Notify::warning($speak->notify_confirm_delete);
    }
    Shield::lot('segment', 'comment')->attach('manager', false);
});
Example #21
0
            $_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('&', '&amp;', 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));
    }
});
Example #22
0
Route::accept($config->manager->slug . '/config', function () use($config, $speak) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    Config::set(array('page_title' => $speak->configs . $config->title_separator . $config->manager->title, 'cargo' => 'cargo.config.php'));
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        $bools = array('comments.allow' => false, 'comments.moderation' => false, 'widget_include_css' => false, 'widget_include_js' => false, 'html_parser.active' => Request::post('html_parser.active', false));
        $pages = array('index' => 'article', 'tag' => 'tag', 'archive' => 'archive', 'search' => 'search', 'manager' => 'manager');
        $slugs = array();
        if ($files = Get::pages()) {
            foreach ($files as $file) {
                list($_time, $_kind, $_slug) = explode('_', File::N($file), 3);
                $slugs[$_slug] = 1;
            }
            unset($files);
        }
        foreach ($bools as $bool => $fallback) {
            // Fix(es) for checkbox input(s)
            Mecha::SVR($request, $bool, Request::post($bool, $fallback));
        }
        foreach ($pages as $page => $default) {
            // Fix(es) for slug pattern input(s)
            $request[$page]['slug'] = Text::parse(Request::post($page . '.slug', $default), '->slug');
            if (Request::post($page . '.per_page') < 1 || floor(Request::post($page . '.per_page')) != Request::post($page . '.per_page')) {
                Notify::error($speak->notify_invalid_per_page_number);
                Guardian::memorize($request);
            }
            // Check if slug already exists on static page(s)
            if (isset($slugs[$request[$page]['slug']])) {
                Notify::error(Config::speak('notify_error_slug_exist', $request[$page]['slug']));
                Guardian::memorize($request);
            }
        }
        if (Request::post('per_page') < 1 || floor(Request::post('per_page')) != Request::post('per_page')) {
            Notify::error($speak->notify_invalid_per_page_number);
            Guardian::memorize($request);
        }
        // Check for invalid email address
        if (trim($request['author']['email']) !== "" && !Guardian::check($request['author']['email'], '->email')) {
            Notify::error($speak->notify_invalid_email);
            Guardian::memorize($request);
        }
        unset($request['token']);
        // Remove token from request array
        $G = array('data' => Mecha::A($config));
        $P = array('data' => $request);
        if (!Notify::errors()) {
            File::serialize($request)->saveTo(STATE . DS . 'config.txt', 0600);
            Notify::success(Config::speak('notify_success_updated', $speak->config));
            foreach (glob(LOG . DS . 'asset.*.log', GLOB_NOSORT) as $asset_cache) {
                File::open($asset_cache)->delete();
            }
            Weapon::fire('on_config_update', array($G, $P));
            Guardian::kick($request['manager']['slug'] . '/config');
        }
    }
    Shield::lot(array('segment' => 'config'))->attach('manager');
});
Example #23
0
            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));
    Weapon::fire(array('on_shield_update', 'on_shield_' . $mode, 'on_shield_' . md5($slug) . '_update', 'on_shield_' . md5($slug) . '_' . $mode), array($G, $G));
    foreach (glob(LOG . DS . 'asset.*.log', GLOB_NOSORT) as $asset_cache) {
        File::open($asset_cache)->delete();
    }
    Guardian::kick($config->manager->slug . '/shield/' . $slug);
});
Example #24
0
 * -----------
 */
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');
});
Example #25
0
            $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'));
        }
        Guardian::kick($config->manager->slug . '/asset/kill/files:' . implode(';', $files));
    }
});
Example #26
0
 * ----------
 */
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');
});
Example #27
0
<?php

/**
 * Error Log
 * ---------
 */
Route::accept($config->manager->slug . '/error', function () use($config, $speak) {
    Config::set(array('page_title' => $speak->errors . $config->title_separator . $config->manager->title, 'cargo' => 'cargo.error.php'));
    Shield::lot(array('segment' => 'error', 'content' => File::open(ini_get('error_log'))->read(false)))->attach('manager');
});
/**
 * Error Log Killer
 * ----------------
 */
Route::accept($config->manager->slug . '/error/kill', function () use($config, $speak) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    $errors = LOG . DS . 'errors.log';
    $G = array('data' => array('content' => File::open($errors)->read()));
    File::open($errors)->delete();
    Weapon::fire('on_error_destruct', array($G, $G));
    Notify::success(Config::speak('notify_success_deleted', $speak->file));
    Guardian::kick(File::D($config->url_current));
});
Example #28
0
Route::accept($config->manager->slug . '/tag', function () use($config, $speak) {
    $tags = Get::rawTags('ASC', 'id');
    Config::set(array('page_title' => $speak->tags . $config->title_separator . $config->manager->title, 'files' => $tags, 'cargo' => DECK . DS . 'workers' . DS . 'cargo.tag.php'));
    $G = array('data' => $tags);
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        // Check for duplicate ID
        foreach (array_count_values($request['id']) as $id => $count) {
            if (trim($id) !== "" && $count > 1) {
                Notify::error(Config::speak('notify_invalid_duplicate', $speak->id));
                break;
            }
        }
        // Check for duplicate slug
        foreach (array_count_values($request['slug']) as $slug => $count) {
            if (trim($slug) !== "" && $count > 1) {
                Notify::error(Config::speak('notify_invalid_duplicate', strtolower($speak->slug)));
                break;
            }
        }
        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);
});
Example #29
0
/**
 * 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));
    Weapon::fire('on_shield_' . md5($slug) . '_' . $mode, array($G, $G));
    foreach (glob(SYSTEM . DS . 'log' . DS . 'asset.*.log', GLOB_NOSORT) as $asset_cache) {
        File::open($asset_cache)->delete();
    }
    Guardian::kick($config->manager->slug . '/shield/' . $slug);
});
/**
 * Shield Backup
 * -------------
 */
Route::accept($config->manager->slug . '/shield/backup/id:(:any)', function ($folder = "") use($config, $speak) {
    $name = $folder . '.zip';
    Package::take(SHIELD . DS . $folder)->pack(ROOT . DS . $name, true);
    $G = array('data' => array('path' => ROOT . DS . $name, 'file' => ROOT . DS . $name));
    Weapon::fire('on_backup_construct', array($G, $G));
    Guardian::kick($config->manager->slug . '/backup/send:' . $name);
});
Example #30
0
        Package::take(ROOT . DS . 'cabinet' . DS . $origin)->pack(ROOT . DS . $name);
        if ($origin === 'shields') {
            Package::take(ROOT . DS . $name)->deleteFiles(array('json.php', 'rss.php', 'sitemap.php', 'widgets.css', 'widgets.js'));
        }
    }
    Guardian::kick($config->manager->slug . '/backup/send:' . $name);
});
/**
 * Downloading Backup File(s)
 * --------------------------
 */
Route::accept($config->manager->slug . '/backup/send:(:any)', function ($file = "") use($config, $speak) {
    if (Guardian::get('status') !== 'pilot') {
        Shield::abort();
    }
    if ($backup = File::exist(ROOT . DS . $file)) {
        $G = array('data' => array('path' => $backup, 'file' => $backup));
        Weapon::fire('on_backup_construct', array($G, $G));
        header('Content-Type: application/zip');
        // header('Content-Length: ' . filesize($backup));
        header('Content-Disposition: attachment; filename=' . $file);
        ob_clean();
        readfile($backup);
        ignore_user_abort(true);
        File::open($backup)->delete();
        Weapon::fire('on_backup_destruct', array($G, $G));
    } else {
        Shield::abort();
    }
    exit;
});