Beispiel #1
0
 /**
  * ==========================================================
  *  RENDER A PAGE
  * ==========================================================
  *
  * -- CODE: -------------------------------------------------
  *
  *    Shield::attach('article', true, false);
  *
  * ----------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type    | Description
  *  --------- | ------- | -----------------------------------
  *  $name     | string  | Name of the shield
  *  $minify   | boolean | Minify HTML output?
  *  $cache    | boolean | Create a cache file on page visit?
  *  $expire   | integer | Define cache file expiration time
  *  --------- | ------- | -----------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function attach($name, $minify = null, $cache = false, $expire = null)
 {
     $config = Config::get();
     if (is_null($minify)) {
         $minify = $config->html_minifier;
     }
     $G = array('data' => array('name' => $name, 'minify' => $minify, 'cache' => $cache, 'expire' => $expire));
     $shield = false;
     $shield_base = explode('-', $name, 2);
     if ($_file = File::exist(self::path($name))) {
         $shield = $_file;
     } else {
         if ($_file = File::exist(self::path($shield_base[0]))) {
             $shield = $_file;
         } else {
             Guardian::abort(Config::speak('notify_file_not_exist', '<code>' . self::path($name) . '</code>'));
         }
     }
     $G['data']['path'] = $shield;
     $q = !empty($config->url_query) ? '.' . md5($config->url_query) : "";
     $cache_path = is_string($cache) ? $cache : CACHE . DS . str_replace(array('/', ':'), '.', $config->url_path) . $q . '.cache';
     if ($G['data']['cache'] && file_exists($cache_path)) {
         if (is_null($expire) || is_int($expire) && time() - $expire < filemtime($cache_path)) {
             // Begin shield cache
             Weapon::fire('shield_cache_before', array($G, $G));
             echo Filter::apply('shield:cache', File::open($cache_path)->read());
             // Clear session
             Notify::clear();
             Guardian::forget();
             self::$lot = array();
             // End shield cache
             Weapon::fire('shield_cache_after', array($G, $G));
             exit;
         }
     }
     // Begin shield
     Weapon::fire('shield_before', array($G, $G));
     ob_start($minify ? 'self::s_o' : 'self::s_o_d');
     extract(Filter::apply('shield:lot', self::cargo()));
     require Filter::apply('shield:path', $shield);
     // Clear session
     Notify::clear();
     Guardian::forget();
     self::$lot = array();
     // Get shield content
     $content = ob_get_contents();
     ob_end_flush();
     // Create shield cache
     $G['data']['content'] = $minify ? self::s_o($content) : self::s_o_d($content);
     if ($G['data']['cache']) {
         $G['data']['cache'] = $cache_path;
         File::write($G['data']['content'])->saveTo($cache_path);
         Weapon::fire('on_cache_construct', array($G, $G));
     }
     // End shield
     Weapon::fire('shield_after', array($G, $G));
     exit;
 }
Beispiel #2
0
        $info_path = array();
        $is_folder_or_file = count($deletes) === 1 && is_dir(ASSET . DS . $deletes[0]) ? 'folder' : 'file';
        foreach ($deletes as $file_to_delete) {
            $_path = ASSET . DS . $file_to_delete;
            $info_path[] = $_path;
            File::open($_path)->delete();
        }
        $P = array('data' => array('files' => $info_path));
        Notify::success(Config::speak('notify_' . $is_folder_or_file . '_deleted', '<code>' . implode('</code>, <code>', $deletes) . '</code>'));
        Weapon::fire('on_asset_update', array($P, $P));
        Weapon::fire('on_asset_destruct', array($P, $P));
        Guardian::kick($config->manager->slug . '/asset/1' . $p);
    } else {
        Notify::warning(count($deletes) === 1 ? Config::speak('notify_confirm_delete_', '<code>' . File::path($name) . '</code>') : $speak->notify_confirm_delete);
    }
    Shield::lot('segment', 'asset')->attach('manager', false);
});
/**
 * Multiple Asset Killer
 * ---------------------
 */
Route::accept($config->manager->slug . '/asset/kill', function ($path = "") use($config, $speak) {
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        if (!isset($request['selected'])) {
            Notify::error($speak->notify_error_no_files_selected);
            Guardian::kick($config->manager->slug . '/asset/1');
        }
        $files = array();
        foreach ($request['selected'] as $file) {
            $files[] = str_replace('%2F', '/', Text::parse($file, '->encoded_url'));
Beispiel #3
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));
});
Beispiel #4
0
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        $info_path = Mecha::walk($deletes, function ($v) {
            $_path = ASSET . DS . $v;
            File::open($_path)->delete();
            return $_path;
        });
        $is_folder_or_file = count($deletes) === 1 && is_dir(ASSET . DS . $deletes[0]) ? 'folder' : 'file';
        $P = array('data' => array('files' => $info_path));
        Notify::success(Config::speak('notify_' . $is_folder_or_file . '_deleted', '<code>' . implode('</code>, <code>', $deletes) . '</code>'));
        Weapon::fire(array('on_asset_update', 'on_asset_destruct'), array($P, $P));
        Guardian::kick($config->manager->slug . '/asset/1' . str_replace('&', '&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'));
        });
Beispiel #5
0
        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));
Beispiel #6
0
        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);
});
Beispiel #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);
});
Beispiel #8
0
<?php

/**
 * Custom Function(s)
 * ------------------
 *
 * Add your own custom function(s) here. You can do something like
 * making custom widget(s), custom route(s), custom filter(s),
 * custom weapon(s), loading custom asset(s), etc. So that you can
 * manipulate the site output without having to touch the CMS core.
 *
 */
// Link generator for the current article tag(s)
Widget::add('tagLinks', function ($connect = ', ') use($config, $speak) {
    $links = array();
    $article = Shield::lot('article');
    if (!$article || !isset($article->tags)) {
        return "";
    }
    foreach ($article->tags as $tag) {
        if ($tag && $tag->id !== 0) {
            $url = Filter::colon('tag:url', $config->url . '/' . $config->tag->slug . '/' . $tag->slug);
            $links[] = '<a href="' . $url . '" rel="tag">' . $tag->name . '</a>';
        }
    }
    $text = count($links) > 1 ? $speak->tags : $speak->tag;
    return !empty($links) ? $text . ': ' . implode($connect, $links) : "";
});
// HTML output manipulation
Filter::add('chunk:output', function ($content, $path) use($config, $speak) {
    $name = File::N($path);
Beispiel #9
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' => DECK . DS . 'workers' . DS . 'cargo.error.php'));
    Shield::lot(array('segment' => 'error', 'the_content' => File::open(SYSTEM . DS . 'log' . DS . 'errors.log')->read(false)))->attach('manager', false);
});
/**
 * Error Log Killer
 * ----------------
 */
Route::accept($config->manager->slug . '/error/kill', function () use($config, $speak) {
    if (Guardian::get('status') !== 'pilot') {
        Shield::abort();
    }
    $errors = SYSTEM . DS . '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));
});
Beispiel #10
0
            $P = array('data' => $_FILES);
            Weapon::fire('on_restore_construct', array($P, $P));
            $task_connect_kick = 'backup';
            include DECK . DS . 'workers' . DS . 'task.package.2.php';
        } else {
            Weapon::add('SHIPMENT_REGION_BOTTOM', function () {
                echo '<script>
(function($) {
    $(\'.tab-area .tab[href$="#tab-content-2"]\').trigger("click");
})(window.Zepto || window.jQuery);
</script>';
            }, 11);
        }
    }
    Config::set(array('page_title' => $speak->backup . '/' . $speak->restore . $config->title_separator . $config->manager->title, 'cargo' => DECK . DS . 'workers' . DS . 'cargo.' . $segment . '.php'));
    Shield::lot('segment', $segment)->attach('manager', false);
});
/**
 * Backup Action(s)
 * ----------------
 */
Route::accept($config->manager->slug . '/backup/origin:(:all)', function ($path = "", $origin = "") use($config, $speak) {
    if (Guardian::get('status') !== 'pilot') {
        Shield::abort();
    }
    $time = date('Y-m-d-H-i-s');
    $site = Text::parse($config->title, '->slug');
    if (trim($origin, '.') === "") {
        $name = $site . '_' . $time . '.zip';
        Package::take(ROOT)->pack(ROOT . DS . $name);
    } else {
Beispiel #11
0
        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, 'file' => $info, 'cargo' => DECK . DS . 'workers' . DS . 'kill.plugin.php'));
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        File::open(PLUGIN . DS . $slug)->delete();
        $P = array('data' => array('id' => $slug));
        Notify::success(Config::speak('notify_success_deleted', $speak->plugin));
        Weapon::fire('on_plugin_update', array($P, $P));
        Weapon::fire('on_plugin_destruct', array($P, $P));
        Weapon::fire('on_plugin_' . md5($slug) . '_update', array($P, $P));
        Weapon::fire('on_plugin_' . md5($slug) . '_destruct', array($P, $P));
        Guardian::kick($config->manager->slug . '/plugin');
    } else {
        Notify::warning(Config::speak('notify_confirm_delete_', '<strong>' . $info['title'] . '</strong>'));
    }
    Shield::lot('segment', 'plugin')->attach('manager', false);
});
/**
 * Plugin Backup
 * -------------
 */
Route::accept($config->manager->slug . '/plugin/backup/id:(:any)', function ($folder = "") use($config, $speak) {
    $name = $folder . '.zip';
    Package::take(PLUGIN . 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);
});
Beispiel #12
0
<?php

// Run after shield lot data up-to-date
Weapon::add('shield_lot_after', function () {
    ob_start();
    $config = Config::get();
    $config->cargo = (string) $config->cargo;
    $cargo = strpos($config->cargo, ROOT) === false ? __DIR__ . DS . $config->cargo : $config->cargo;
    // No buffer for backend cargo, so `chunk:input` and `chunk:output` filter(s) won't work here
    Shield::chunk($cargo, false, false);
    $content = ob_get_clean();
    $o = (object) array('title' => $config->page_title, 'url' => "", 'link' => "", 'content_type' => $config->html_parser->active, 'content' => $content);
    Shield::lot(array('page' => $o));
}, 1);
Beispiel #13
0
 * Field Killer
 * ------------
 */
Route::accept($config->manager->slug . '/field/kill/key:(:any)', function ($key = "") use($config, $speak) {
    if (Guardian::get('status') !== 'pilot') {
        Shield::abort();
    }
    $fields = Get::state_field(null, null, array(), false);
    if (!isset($fields[$key])) {
        Shield::abort();
    } else {
        $data = $fields[$key];
    }
    Config::set(array('page_title' => $speak->deleting . ': ' . $data['title'] . $config->title_separator . $config->manager->title, 'file' => $data, 'cargo' => DECK . DS . 'workers' . DS . 'kill.field.php'));
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        $P = array('data' => $request);
        $P['data']['key'] = $key;
        $deleted_field = $fields[$key]['title'];
        unset($fields[$key]);
        // delete ...
        File::serialize($fields)->saveTo(STATE . DS . 'field.txt', 0600);
        Notify::success(Config::speak('notify_success_deleted', $deleted_field));
        Weapon::fire('on_field_update', array($P, $P));
        Weapon::fire('on_field_destruct', array($P, $P));
        Guardian::kick($config->manager->slug . '/field');
    } else {
        Notify::warning(Config::speak('notify_confirm_delete_', '<strong>' . $data['title'] . '</strong>'));
    }
    Shield::lot(array('segment' => 'field', 'the_key' => $key))->attach('manager', false);
});
Beispiel #14
0
                // refresh ...
            }
            if ($destination === PLUGIN) {
                Plugin::reload();
                // refresh ...
            }
            $P = array('data' => $_FILES);
            Weapon::fire('on_restore_construct', array($P, $P));
            include PLUGIN . DS . 'manager' . DS . 'workers' . DS . 'task.package.php';
        } else {
            $tab_id = 'tab-content-2';
            include PLUGIN . DS . 'manager' . DS . 'workers' . DS . 'task.js.tab.php';
        }
    }
    Config::set(array('page_title' => $speak->backup . '/' . $speak->restore . $config->title_separator . $config->manager->title, 'cargo' => __DIR__ . DS . 'cargo.backup.php'));
    Shield::lot(array('segment' => 'backup'))->attach('manager');
});
/**
 * Backup Action(s)
 * ----------------
 */
Route::accept($config->manager->slug . '/backup/origin:(:all)', function ($origin = "") use($config, $speak) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    $time = Date::slug(time());
    $site = Text::parse($config->title, '->slug');
    if (trim($origin, '.') === "") {
        $name = $site . '_' . $time . '.zip';
        Package::take(ROOT)->pack(ROOT . DS . $name);
    } else {
Beispiel #15
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');
});
Beispiel #16
0
    if (!($article = Get::article($id, array('comments')))) {
        Shield::abort();
    }
    if (Guardian::get('status') !== 'pilot' && Guardian::get('author') !== $article->author) {
        Shield::abort();
    }
    Config::set(array('page_title' => $speak->deleting . ': ' . $article->title . $config->title_separator . $config->manager->title, 'article' => $article, 'cargo' => DECK . DS . 'workers' . DS . 'kill.article.php'));
    $G = array('data' => Mecha::A($article));
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        File::open($article->path)->delete();
        // Deleting comment(s) ...
        if ($comments = Get::comments($id, 'DESC', 'txt,hold')) {
            foreach ($comments as $comment) {
                File::open($comment)->delete();
            }
        }
        $task_connect = $article;
        $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', $article->title));
        Weapon::fire('on_article_update', array($G, $G));
        Weapon::fire('on_article_destruct', array($G, $G));
        Guardian::kick($config->manager->slug . '/article');
    } else {
        Notify::warning(Config::speak('notify_confirm_delete_', '<strong>' . $article->title . '</strong>'));
        Notify::warning(Config::speak('notify_confirm_delete_page', strtolower($speak->article)));
    }
    Shield::lot('segment', 'article')->attach('manager', false);
});
Beispiel #17
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');
});
Beispiel #18
0
<?php

// DEPRECATED. Please use `Shield::lot()`
Shield::plug('define', function ($key, $value = "") {
    return Shield::lot($key, $value);
});
// DEPRECATED. Please use `Shield::apart()`
Shield::plug('undefine', function ($data) {
    return Shield::apart($data);
});
Beispiel #19
0
    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');
});
Beispiel #20
0
    $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()) {
        $request = Filter::apply('request:__plugin', $request);
        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');
});
/**
 * Plugin Updater (Base)
 * ---------------------
 */
if ($route = Route::is($config->manager->slug . '/plugin/(: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:__plugin', $request, $s);
                    Guardian::checkToken($request['token']);
                    unset($request['token']);
                    // remove token from request array
Beispiel #21
0
<?php

Shield::chunk('header');
Shield::chunk('sidebar');
?>
<div class="blog-main posts">
  <?php 
if ($config->total_articles > 0) {
    ?>
  <?php 
    foreach ($articles as $article) {
        ?>
  <?php 
        Shield::lot(array('article' => $article));
        ?>
  <article class="post post-index" id="post-<?php 
        echo $article->id;
        ?>
">
    <?php 
        Shield::chunk('article.header.index');
        ?>
    <?php 
        Shield::chunk('article.body.index');
        ?>
    <?php 
        Shield::chunk('article.footer.index');
        ?>
  </article>
  <?php 
    }
Beispiel #22
0
<ol class="comments-body">
  <?php 
if ($article->total_comments > 0) {
    ?>
  <?php 
    foreach ($article->comments as $comment) {
        ?>
  <?php 
        Shield::lot(array('comment' => $comment));
        ?>
  <?php 
        Shield::chunk('block.comment.index');
        ?>
  <?php 
    }
    ?>
  <?php 
} else {
    ?>
  <li class="comment">
    <?php 
    Shield::chunk('comment.body.204');
    ?>
  </li>
  <?php 
}
?>
</ol>
<?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>'));
    }
Beispiel #24
0
<?php

/**
 * Shortcode Manager
 * -----------------
 */
Route::accept($config->manager->slug . '/shortcode', function () use($config, $speak) {
    if (Guardian::get('status') !== 'pilot') {
        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, 'files' => $shortcodes, 'cargo' => DECK . DS . 'workers' . DS . 'cargo.shortcode.php'));
    if ($request = Request::post()) {
        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('segment', 'shortcode')->attach('manager', false);
});
Beispiel #25
0
 /**
  * ==========================================================
  *  RENDER A SHIELD CHUNK
  * ==========================================================
  *
  * -- CODE: -------------------------------------------------
  *
  *    Shield::chunk('header');
  *
  * ----------------------------------------------------------
  *
  *    Shield::chunk('header', array('title' => 'Yo!'));
  *
  * ----------------------------------------------------------
  *
  */
 public static function chunk($name, $fallback = false, $buffer = true)
 {
     $path__ = File::path($name);
     $G = array('data' => array('name' => $name));
     if (is_array($fallback)) {
         self::$lot = array_merge(self::$lot, $fallback);
         $fallback = false;
     }
     $path__ = Filter::apply('chunk:path', self::path($path__, $fallback));
     $G['data']['lot'] = self::$lot;
     $G['data']['path'] = $path__;
     $out = "";
     if ($path__) {
         // Begin chunk
         Weapon::fire('chunk_lot_before', array($G, $G));
         extract(Filter::apply('chunk:lot', self::$lot));
         Weapon::fire('chunk_lot_after', array($G, $G));
         Weapon::fire('chunk_before', array($G, $G));
         if ($buffer) {
             ob_start(function ($content) use($path__, &$out) {
                 $content = Filter::apply('chunk:input', $content, $path__);
                 $out = Filter::apply('chunk:output', $content, $path__);
                 return $out;
             });
             require $path__;
             ob_end_flush();
         } else {
             require $path__;
         }
         $G['data']['content'] = $out;
         // End chunk
         Weapon::fire('chunk_after', array($G, $G));
     }
 }
Beispiel #26
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');
});
Beispiel #27
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');
});
Beispiel #28
0
            // 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');
});
Beispiel #29
0
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        $P = array('data' => array('path' => $file));
        File::open($file)->delete();
        if ($path) {
            Notify::success(Config::speak('notify_file_deleted', '<code>' . File::B($path) . '</code>'));
        } else {
            Notify::success(Config::speak('notify_success_deleted', $speak->shield));
        }
        Weapon::fire('on_shield_update', array($P, $P));
        Weapon::fire('on_shield_destruct', array($P, $P));
        Guardian::kick($config->manager->slug . '/shield' . ($path ? '/' . $folder : ""));
    } else {
        Notify::warning(Config::speak('notify_confirm_delete_', $path ? '<code>' . File::path($path) . '</code>' : '<strong>' . $info['title'] . '</strong>'));
    }
    Shield::lot(array('segment' => 'shield', 'the_shield' => $folder, 'the_name' => $path, 'the_info' => $info))->attach('manager', false);
});
/**
 * Shield Attacher
 * ---------------
 */
Route::accept($config->manager->slug . '/shield/(attach|eject)/id:(:any)', function ($path = "", $slug = "") use($config, $speak) {
    $new_config = Get::state_config();
    $new_config['shield'] = $path === 'attach' ? $slug : 'normal';
    File::serialize($new_config)->saveTo(STATE . DS . 'config.txt', 0600);
    $G = array('data' => array('id' => $slug, 'action' => $path));
    $mode = $path === 'eject' ? 'eject' : 'mount';
    Notify::success(Config::speak('notify_success_updated', $speak->shield));
    Weapon::fire('on_shield_update', array($G, $G));
    Weapon::fire('on_shield_' . $mode, array($G, $G));
    Weapon::fire('on_shield_' . md5($slug) . '_update', array($G, $G));
<?php

if ($config->is->post) {
    Weapon::add('shield_lot_before', function () {
        $config = Config::get();
        $s = $config->page_type;
        $allow = isset($config->{$s}->fields->allow_comments) && $config->{$s}->fields->allow_comments !== false;
        $config->comments->allow = $allow;
        Config::set('comments.allow', $allow);
        Shield::lot(array('config' => $config));
    });
}