public static function load() { if ($plugins_order = File::exist(CACHE . DS . 'plugins.order.cache')) { return File::open($plugins_order)->unserialize(); } $plugins = array(); $plugins_list = glob(PLUGIN . DS . '*' . DS . 'launch.php', GLOB_NOSORT); $plugins_payload = count($plugins_list); sort($plugins_list); for ($i = 0; $i < $plugins_payload; ++$i) { $plugins[] = false; } for ($j = 0; $j < $plugins_payload; ++$j) { $plugins_list[$j] = str_replace(PLUGIN . DS, "", File::D($plugins_list[$j])); if ($overtake = File::exist(PLUGIN . DS . $plugins_list[$j] . DS . '__overtake.txt')) { $to_index = Mecha::edge((int) file_get_contents($overtake) - 1, 0, $plugins_payload - 1); array_splice($plugins, $to_index, 0, array($plugins_list[$j])); } else { $plugins[$j] = $plugins_list[$j]; } } File::serialize($plugins)->saveTo(CACHE . DS . 'plugins.order.cache', 0600); unset($plugins_list, $plugins_order, $plugins_payload); return $plugins; }
/** * ========================================================== * LOADING PLUGIN(S) * ========================================================== * * -- CODE: ------------------------------------------------- * * $plugins = Plugin::load(); * * ---------------------------------------------------------- * */ public static function load($cache = true, $name = 'plugins.order.cache') { if ($cache && ($plugins = File::exist(CACHE . DS . $name))) { return File::open($plugins)->unserialize(); } $plugins = array(); foreach (glob(PLUGIN . DS . '*', GLOB_NOSORT | GLOB_ONLYDIR) as $plugin) { $plugin = File::B($plugin); $plugins[$plugin] = (double) File::open(PLUGIN . DS . $plugin . DS . '__stack.txt')->read(10); } asort($plugins); File::serialize($plugins)->saveTo(CACHE . DS . $name, 0600); return $plugins; }
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)); 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 * -------------
<?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'); });
/** * Close FTP connection. */ public function close() { if (is_null($this->ftp)) { return; } if (!empty($this->conf['use_cache']) && count($this->cache) > 0) { if (mb_substr($this->conf['use_cache'], 0, 5) === 'file:') { File::serialize(mb_substr($this->conf['use_cache'], 5), $this->cache); } } if ($this->ftp) { if (!@ftp_close($this->ftp)) { throw new Exception('FTP close failed'); } $this->ftp = null; } $this->_log("FTP connection closed"); }
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>')); } if (trim($request['content']) === "") { // empty file content Notify::error($speak->notify_error_content_empty); } if (!Notify::errors()) { $recent = array_slice(File::open(CACHE . DS . 'plugin.snippet.cache')->unserialize(), 0, $config->per_page); File::serialize(array_merge(array($_path), $recent))->saveTo(CACHE . DS . 'plugin.snippet.cache', 0600); $url = $config->manager->slug . '/asset/repair/file:__snippet/' . $e . '/' . File::url($_path) . '?path=' . urlencode(rtrim('__snippet/' . $e . '/' . File::D(File::url($_path)), '/')); File::write($request['content'])->saveTo($file, 0600); Notify::success(Config::speak('notify_file_created', '<code>' . $_path_ . '</code>' . (!isset($request['redirect']) ? ' <a class="pull-right" href="' . $config->url . '/' . $url . '" target="_blank">' . Jot::icon('pencil') . ' ' . $speak->edit . '</a>' : ""))); Notify::info('<strong>' . $speak->shortcode . ':</strong> <code>{{' . ($e === 'php' ? 'include' : 'print') . ':' . str_replace('.' . $e . X, "", File::url($_path) . X) . '}}</code>'); Guardian::kick(isset($request['redirect']) ? $url : File::D($config->url_current)); } Guardian::kick(File::D($config->url_current)); });
<?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)); } });
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\');
* ----------- */ 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'); });
// 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'); });
$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); }
* Field Killer * ------------ */ Route::accept($config->manager->slug . '/field/kill/key:(:any)', function ($key = false) use($config, $speak, $fields) { if (!Guardian::happy(1)) { Shield::abort(); } if (!isset($fields[$key])) { Shield::abort(); // Field not found! } $title = $fields[$key]['title']; Config::set(array('page_title' => $speak->deleting . ': ' . $title . $config->title_separator . $config->manager->title, 'cargo' => 'kill.field.php')); $G = array('data' => $fields); $G['data']['key'] = $key; if ($request = Request::post()) { Guardian::checkToken($request['token']); unset($fields[$key]); // delete ... ksort($fields); $P = array('data' => $fields); $P['data']['key'] = $key; File::serialize($fields)->saveTo(STATE . DS . 'field.txt', 0600); Notify::success(Config::speak('notify_success_deleted', $title)); Weapon::fire(array('on_field_update', 'on_field_destruct'), array($G, $P)); Guardian::kick($config->manager->slug . '/field'); } else { Notify::warning(Config::speak('notify_confirm_delete_', '<strong>' . $title . '</strong>')); } Shield::lot(array('segment' => 'field', 'id' => $key, 'file' => Mecha::O($fields[$key])))->attach('manager'); });