Example #1
0
 public function testMerge()
 {
     $xml1 = '<?xml version="1.0" ?>
             <slimdump>
                 <table name="dicht*" dump="full" />
             </slimdump>';
     $config1 = new Config(new \SimpleXMLElement($xml1));
     $xml2 = '<?xml version="1.0" ?>
             <slimdump>
                 <table name="dicht*" dump="noblob" />
             </slimdump>';
     $config2 = new Config(new \SimpleXMLElement($xml2));
     $config1->merge($config2);
     $table = $config1->findTable('dichtikowski');
     $this->assertEquals('NULL', $table->getSelectExpression('testColumnName', true));
 }
Example #2
0
 /**
  * Start the application.
  */
 static function start($dispatch = true)
 {
     ob_start();
     // Set error reporting level.
     error_reporting(E_ALL ^ E_NOTICE);
     // Setup default error handelers.
     set_error_handler(array('Request', 'default_error_handler'), E_ALL);
     set_exception_handler(array('Request', 'default_exception_handler'));
     // Setup autoloader.
     spl_autoload_register(array('Request', 'autoload'));
     // Load app config.
     self::$config = new Config('app');
     $config =& self::$config;
     // Get current environment (default local).
     self::$env = is_file(APP_ROOT . 'config/.env') ? trim(file_get_contents(APP_ROOT . 'config/.env')) : 'local';
     // Load environment config.
     if (is_file(APP_ROOT . 'config/' . self::$env . '.yml')) {
         self::$env_config = new Config(self::$env);
         $env_config =& self::$env_config;
         // Merge environment config into app config.
         $config = Config::merge($config, $env_config);
     }
     // Setup app defaults.
     $default_app_config = array('view_path' => APP_ROOT . 'app/templates/', 'public_path' => APP_ROOT . 'public/', 'default_controller' => 'index', 'default_action' => 'index', 'default_output' => 'html', 'default_layout' => 'default', 'default_locale' => 'en_US.UTF-8', 'ajax_layout' => null);
     $config->app = Config::merge($default_app_config, $config->app);
     // Setup default locale.
     setlocale(LC_ALL, $config->app['default_locale']);
     // Setup default route.
     if (!is_array($config->routes)) {
         $config->routes = array();
     }
     array_push($config->routes, array('/'));
     array_push($config->routes, array('/:controller/:action/*'));
     // Include core and app helpers.
     self::include_helpers(APP_ROOT . 'app/helpers/');
     self::include_helpers(APP_ROOT . 'core/helpers/');
     // Include core and app models.
     self::include_models(APP_ROOT . 'app/models/', false);
     self::include_models(APP_ROOT . 'core/models/', false);
     // Include core and app plugins.
     self::include_plugins(APP_ROOT . 'app/plugins/');
     self::include_plugins(APP_ROOT . 'core/plugins/');
     // Dispatch request?
     if ($dispatch) {
         return self::dispatch($_SERVER['REQUEST_URI'] ?: $_SERVER['argv'][1]);
     }
 }
Example #3
0
            $type = $config->page_type;
            $id = $config->{$type}->id;
            $text = Config::speak($type);
            $text_repair = Config::speak('manager._this_', array($speak->edit, $text));
            $text_kill = Config::speak('manager._this_', array($speak->delete, $text));
            $bars[$text] = array('icon' => 'plus', 'url' => $config->manager->slug . '/' . $type . '/ignite', 'description' => Config::speak('manager.title_new_', $text), 'stack' => 9.029999999999999);
            $bars[$speak->edit] = array('icon' => 'pencil', 'url' => $config->manager->slug . '/' . $type . '/repair/id:' . $id, 'description' => $text_repair, 'stack' => 9.039999999999999);
            $bars[$speak->delete] = array('icon' => 'times', 'url' => $config->manager->slug . '/' . $type . '/kill/id:' . $id, 'description' => $text_kill, 'stack' => 9.050000000000001);
        } else {
            $link = Cell::a($config->manager->slug . '/article/ignite', Config::speak('manager.title_new_', $speak->article));
            $link .= ' &middot; ';
            $link .= Cell::a($config->manager->slug . '/page/ignite', Config::speak('manager.title_new_', $speak->page));
            $bars[$speak->add] = array('icon' => 'plus', 'url' => $config->manager->slug . '/article/ignite', 'description' => $link, 'stack' => 9.029999999999999);
        }
        Config::merge('manager_menu', $menus);
        Config::merge('manager_bar', $bars);
    });
}
// Loading frontend task(s) and route(s)
Weapon::add('routes_before', function () use($config, $speak) {
    require __DIR__ . DS . 'workers' . DS . 'task.comment.ignite.php';
    require __DIR__ . DS . 'workers' . DS . 'route.login.php';
});
// Add log in/out link in shield footer
function do_footer_manager_link($content, $path)
{
    global $config, $speak;
    if (File::N($path) === 'block.footer.bar') {
        $s = Guardian::happy() ? '<a href="' . Filter::colon('manager:url', $config->url . '/' . $config->manager->slug . '/logout') . '" rel="nofollow">' . $speak->log_out . '</a>' : '<a href="' . Filter::colon('manager:url', $config->url . '/' . $config->manager->slug . '/login') . '" rel="nofollow">' . $speak->log_in . '</a>';
        return str_replace('<div class="blog-footer-right">', '<div class="blog-footer-right">' . $s, $content);
    }
Example #4
0
    Weapon::add('SHIPMENT_REGION_BOTTOM', function () {
        echo Asset::javascript(SHIELD . DS . 'widgets.js', "", 'sword/widgets.min.js');
    });
}
/**
 * Loading Plugin(s)
 * -----------------
 */
Weapon::fire('plugins_before');
foreach ($plugins = Plugin::load() as $k => $v) {
    $__ = PLUGIN . DS . $k . DS;
    if (!($language = File::exist($__ . 'languages' . DS . $config->language . DS . 'speak.txt'))) {
        $language = $__ . 'languages' . DS . 'en_US' . DS . 'speak.txt';
    }
    if (file_exists($language)) {
        Config::merge('speak', Text::toArray(File::open($language)->read(), S, '  '));
        $speak = Config::speak();
        // refresh ...
    }
    Weapon::fire(array('plugin_before', 'plugin_' . md5($k) . '_before'));
    if ($launch = File::exist($__ . 'launch.php')) {
        if (strpos(File::B($__), '__') === 0) {
            if (Guardian::happy() && $config->page_type === 'manager') {
                include $launch;
                // backend
            }
        } else {
            include $launch;
            // frontend
        }
    }
Example #5
0
<?php

if (Guardian::happy(1)) {
    Config::merge('manager_menu', array($speak->backup => array('icon' => 'life-ring', 'url' => $config->manager->slug . '/backup', 'stack' => 9.119999999999999)));
}
Example #6
0
 public function test_merge_returns_array_merged_with_supplied_options()
 {
     $config = new Config(array('api_key' => 'foo', 'http_open_timeout' => 10));
     $actual = $config->merge(array('api_key' => 'bar', 'host' => 'localhost'));
     $this->assertEquals('bar', $actual['api_key']);
     $this->assertEquals('localhost', $actual['host']);
     $this->assertEquals(10, $actual['http_open_timeout']);
 }
Example #7
0
// Load the configuration data
$editor_config = File::open(__DIR__ . DS . 'states' . DS . 'config.txt')->unserialize();
// Merge language data to the `DASHBOARD`
Weapon::add('shield_before', function () use($editor_config) {
    // Manage editor button(s)
    $editor = Config::speak('MTE');
    foreach ($editor->buttons as $k => $v) {
        if (!Text::check($k)->in(array('yes', 'no', 'ok', 'cancel', 'open', 'close'))) {
            if (!isset($editor_config['buttons'][$k])) {
                $editor->buttons->{$k} = false;
            }
        }
    }
    // Merge language data to the `DASHBOARD`
    Config::merge('DASHBOARD.languages.MTE', $editor);
}, 1);
// Inject editor's CSS
Weapon::add('shell_after', function () use($editor_config) {
    echo Asset::stylesheet(__DIR__ . DS . 'assets' . DS . 'shell' . DS . 'editor.css', "", 'shell/editor.min.css');
}, 2);
// Inject editor's JavaScript
Weapon::add('SHIPMENT_REGION_BOTTOM', function () use($config, $speak) {
    echo '<script>(function($){$(\'.MTE\').attr(\'data-MTE-config\',\'{"toolbar":true,"shortcut":true}\')})(DASHBOARD.$);</script>';
    $path = __DIR__ . DS . 'assets' . DS . 'sword' . DS;
    $editor = Config::get('MTE', 'HTE');
    echo Asset::javascript(array($path . 'editor.min.js', $path . 'hte.min.js'));
    echo '<script>var MTE=' . $editor . ';</script>';
    echo Asset::javascript($path . 'run.js', "", 'sword/run.min.js');
}, 2);
/**
Example #8
0
Route::accept($config->manager->slug . '/plugin/' . File::B(__DIR__) . '/update', function () use($config, $speak) {
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        $state = __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));
    }
});
// Editor ...
Weapon::add('shield_before', function () use($config, $speak) {
    $page = Config::get('page', array());
    $parser = isset($page->content_type_raw) ? $page->content_type_raw : $config->html_parser->active;
    if ($parser === 'Markdown' || $parser === 'Markdown Extra') {
        Config::merge('DASHBOARD.languages.MTE', $speak->__MTE);
        Config::set('MTE', 'MTE');
        Weapon::add('SHIPMENT_REGION_BOTTOM', function () {
            echo Asset::javascript(__DIR__ . DS . 'assets' . DS . 'sword' . DS . 'help.js');
        }, 11);
        Filter::add('asset:path', function ($path) {
            // Replace `HTE` with `MTE`
            if ($path === PLUGIN . DS . '__editor' . DS . 'assets' . DS . 'sword' . DS . 'hte.min.js') {
                return __DIR__ . DS . 'assets' . DS . 'sword' . DS . 'mte.min.js';
            }
            // Replace default `table` button with the new one
            if ($path === PLUGIN . DS . '__editor-button' . DS . 'assets' . DS . 'sword' . DS . 'table.js') {
                return __DIR__ . DS . 'assets' . DS . 'sword' . DS . 'table.js';
            }
            return $path;
        });
<?php

Config::merge('manager_menu', array($speak->snippet => array('icon' => 'puzzle-piece', 'url' => $config->manager->slug . '/snippet', 'stack' => 9.021000000000001)));
function do_snippet($content)
{
    global $config, $speak;
    if (strpos($content, '{{') === false) {
        return $content;
    }
    $content = function_exists('do_shortcode_x') ? do_shortcode_x($content) : $content;
    // plain text: `{{print:foo}}`
    if (strpos($content, '{{print:') !== false || strpos($content, '{{print=') !== false) {
        $content = preg_replace_callback('#\\{\\{print[:=](.*?)\\}\\}#', function ($matches) {
            $content = $matches[0];
            $e = File::E($matches[1], false);
            if ($e !== 'txt' && $e !== 'php') {
                $e = 'txt';
                $matches[1] .= '.txt';
            }
            if ($snippet = File::exist(ASSET . DS . '__snippet' . DS . $e . DS . $matches[1])) {
                return File::open($snippet)->read();
            }
            return $content;
        }, $content);
    }
    // plain text with wildcard(s): `{{print path="foo" lot="bar,baz,qux"}}`
    if (strpos($content, '{{print ') !== false) {
        $content = preg_replace_callback('#\\{\\{print\\s+(.*?)\\}\\}#', function ($matches) {
            $content = $matches[0];
            $data = Converter::attr($content, array('{{', '}}', ' '), array('"', '"', '='));
            $attr = (array) $data['attributes'];