Exemple #1
0
 /**
  * Widget Manager
  * --------------
  *
  * [1]. Widget::manager('MENU');
  * [2]. Widget::manager('BAR');
  *
  */
 public static function manager($type = 'MENU')
 {
     if (!Guardian::happy()) {
         return "";
     }
     $T1 = TAB;
     if ($type === 'MENU') {
         $menus = array();
         if ($_menus = Mecha::A(Config::get('manager_menu'))) {
             $_menus = Mecha::eat($_menus)->order('ASC', 'stack', true, 10)->vomit();
             foreach ($_menus as $k => $v) {
                 // < 1.1.3
                 if (is_string($v)) {
                     $menus[$k] = $v;
                 } else {
                     $stack = isset($v['stack']) ? $v['stack'] : 10;
                     $_k = (strpos($v['icon'], '<') === false ? '<i class="fa fa-fw fa-' . $v['icon'] . '"></i>' : $v['icon']) . ' <span class="label">' . $k . '</span>' . (isset($v['count']) && ($v['count'] === '&infin;' || (double) $v['count'] > 0) ? ' <span class="counter">' . $v['count'] . '</span>' : "");
                     $menus[$_k] = isset($v['url']) ? $v['url'] : null;
                 }
             }
         }
         $html = O_BEGIN . '<div class="widget widget-manager widget-manager-menu" id="widget-manager-menu-' . self::$id['manager_menu'] . '">' . NL;
         self::$id['manager_menu']++;
         $html .= Menu::get($menus, 'ul', $T1, 'manager:');
         $html .= '</div>' . O_END;
         $html = Filter::apply('widget', $html);
         return Filter::apply('widget:manager.menu', Filter::apply('widget:manager', $html));
     }
     if ($type === 'BAR') {
         $html = O_BEGIN . '<div class="widget widget-manager widget-manager-bar" id="widget-manager-bar-' . self::$id['manager_bar'] . '">' . NL;
         self::$id['manager_bar']++;
         $bars = array();
         if ($_bars = Mecha::A(Config::get('manager_bar'))) {
             $_bars = Mecha::eat($_bars)->order('ASC', 'stack', true, 10)->vomit();
             foreach ($_bars as $k => $v) {
                 if (is_string($v)) {
                     $bar = $v;
                 } else {
                     $t = ' data-tooltip="' . Text::parse(isset($v['description']) ? $v['description'] : $k, '->encoded_html') . '"';
                     $bar = isset($v['url']) ? '<a class="item" href="' . Converter::url($v['url']) . '"' . $t . '>' : '<span class="item a"' . $t . '>';
                     $bar .= isset($v['icon']) ? strpos($v['icon'], '<') === false ? Jot::icon($v['icon']) : $v['icon'] : $k;
                     $bar .= ' <span class="label">' . $k . '</span>';
                     if (isset($v['count']) && ($v['count'] === '&infin;' || (double) $v['count'] > 0)) {
                         $bar .= ' <span class="counter">' . $v['count'] . '</span>';
                     }
                     $bar .= isset($v['url']) ? '</a>' : '</span>';
                 }
                 $bars[] = Filter::apply('manager:bar.item', $bar);
             }
         }
         $html .= $T1 . Filter::apply('manager:bar', implode(' ', $bars)) . NL;
         $html .= '</div>';
         return Filter::apply('widget:manager.bar', Filter::apply('widget:manager', $html));
     }
 }
Exemple #2
0
 /**
  * =============================================================
  *  REGISTER NEW VARIABLE(S)
  * =============================================================
  *
  * -- CODE: ----------------------------------------------------
  *
  *    Config::set('foo', 'bar');
  *
  * -------------------------------------------------------------
  *
  *    Config::set(array(
  *        'a' => 1,
  *        'b' => 2
  *    ));
  *
  * -------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type   | Description
  *  --------- | ------ | ---------------------------------------
  *  $key      | string | Key of data to be called
  *  $key      | array  | Array of data's key and value
  *  $value    | mixed  | The value of your data key
  *  --------- | ------ | ---------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function set($key, $value = "")
 {
     if (is_object($key)) {
         $key = Mecha::A($key);
     }
     if (is_object($value)) {
         $value = Mecha::A($value);
     }
     $cargo = array();
     if (!is_array($key)) {
         Mecha::SVR($cargo, $key, $value);
     } else {
         foreach ($key as $k => $v) {
             Mecha::SVR($cargo, $k, $v);
         }
     }
     Mecha::extend(self::$bucket, $cargo);
 }
Exemple #3
0
 public static function set($session, $value = "", $expire = 1, $path = '/', $domain = "", $secure = false, $http_only = false)
 {
     if (strpos($session, 'cookie:') === 0) {
         $name = substr($session, 7);
         $expire = time() + 60 * 60 * 24 * $expire;
         if (strpos($name, '.') !== false) {
             $parts = explode('.', $name);
             $name = array_shift($parts);
             $old = Converter::strEval(isset($_COOKIE[$name]) ? $_COOKIE[$name] : array());
             if (is_object($value)) {
                 $value = Mecha::A($value);
             }
             Mecha::SVR($old, implode('.', $parts), $value);
             $value = $old;
         }
         setcookie($name, base64_encode(json_encode($value, true)), $expire, $path, $domain, $secure, $http_only);
         setcookie('__' . $name, base64_encode(json_encode(array($expire, $path, $domain, $secure, $http_only), true)), $expire, '/', "", false, false);
     } else {
         Mecha::SVR($_SESSION, $session, $value);
     }
 }
Exemple #4
0
             // < 1.1.3
             if (is_string($v)) {
                 $menus[$k] = $v;
             } else {
                 $stack = isset($v['stack']) ? $v['stack'] : 10;
                 $_k = (strpos($v['icon'], '<') === false ? Jot::icon($v['icon'], 'fw') : $v['icon']) . ' <span class="label">' . $k . '</span>' . (isset($v['count']) && ($v['count'] === '&infin;' || (double) $v['count'] > 0) ? ' <span class="counter">' . $v['count'] . '</span>' : "");
                 $menus[$_k] = isset($v['url']) ? $v['url'] : null;
             }
         }
     }
     Menu::add('manager', $menus);
     $html .= Menu::manager('ul', $T1);
 }
 if ($type === 'BAR') {
     $bars = array();
     if ($_bars = Mecha::A(Config::get('manager_bar'))) {
         $_bars = Mecha::eat($_bars)->order('ASC', 'stack', true, 10)->vomit();
         foreach ($_bars as $k => $v) {
             if (is_string($v)) {
                 $bar = $v;
             } else {
                 $t = ' data-tooltip="' . Text::parse(isset($v['description']) ? $v['description'] : $k, '->encoded_html') . '"';
                 if (isset($v['url'])) {
                     $url = Filter::colon('manager:url', Converter::url($v['url']));
                     $c = $config->url_current === $url ? ' ' . Widget::$config['classes']['current'] : "";
                     $bar = '<a class="item' . $c . '" href="' . $url . '"' . $t . '>';
                 } else {
                     $bar = '<span class="item a"' . $t . '>';
                 }
                 $bar .= isset($v['icon']) ? strpos($v['icon'], '<') === false ? Jot::icon($v['icon']) : $v['icon'] : $k;
                 $bar .= ' <span class="label">' . $k . '</span>';
});
/**
 * 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);
});
Exemple #6
0
<?php

$tags = array();
$tags_wayback = ',' . Request::get('kind', implode(',', Guardian::wayback('kind', Mecha::A($page->kind)))) . ',';
foreach (call_user_func('Get::' . $segment . 'Tags') as $tag) {
    if ($tag && $tag->id !== 0) {
        $tags[] = '<div>' . Form::checkbox('kind[]', $tag->id, strpos($tags_wayback, ',' . $tag->id . ',') !== false, $tag->name) . '</div>';
    }
}
if (count($tags) > 0) {
    ?>
<div class="grid-group">
  <span class="grid span-1 form-label"><?php 
    echo $speak->tags;
    ?>
</span>
  <div class="grid span-5"><?php 
    echo implode("", $tags);
    ?>
</div>
</div>
<?php 
}
Exemple #7
0
 /**
  * ====================================================================
  *  CONVERT NESTED STRING INTO ASSOCIATIVE ARRAY
  * ====================================================================
  *
  * -- CODE: -----------------------------------------------------------
  *
  *    echo Converter::toArray('key_1: Value 1
  *    key_2: Value 2
  *    key_3: Value 3');
  *
  * --------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type   | Description
  *  --------- | ------ | ----------------------------------------------
  *  $input    | string | The string of data to be converted
  *  $s        | string | Separator between data key and data value
  *  $indent   | string | Indentation of nested string data level
  *  --------- | ------ | ----------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function toArray($input, $s = S, $indent = '    ')
 {
     if (is_array($input)) {
         return $input;
     }
     if (is_object($input)) {
         return Mecha::A($input);
     }
     return Text::toArray((string) $input, $s, $indent);
 }
Exemple #8
0
<?php

$bucket = array();
$url_base = $config->url . '/feed/json';
$json_order = strtoupper(Request::get('order', 'DESC'));
$json_filter = Request::get('filter', "");
$json_limit = Request::get('chunk', 25);
if ($pages = Mecha::eat(Get::articles($json_order, $json_filter))->chunk($config->offset, $json_limit)->vomit()) {
    foreach ($pages as $path) {
        $bucket[] = Get::articleHeader($path);
    }
}
$json = array('meta' => array('generator' => 'Mecha ' . MECHA_VERSION, 'title' => $config->title, 'slogan' => $config->slogan, 'url' => array('home' => $config->url, 'previous' => $config->offset > 1 ? Filter::colon('feed:url', $url_base . '/' . ($config->offset - 1)) : null, 'next' => $config->offset < ceil($config->total_articles / $json_limit) ? Filter::colon('feed:url', $url_base . '/' . ($config->offset + 1)) : null), 'description' => $config->description, 'update' => date('c'), 'author' => (array) $config->author, 'offset' => $config->offset, 'total' => $config->total_articles, 'tags' => Get::articleTags()), 'item' => null);
if (!empty($bucket)) {
    $json['item'] = array();
    foreach ($bucket as $i => $item) {
        $json['item'][$i] = array('title' => $item->title, 'url' => $item->url, 'date' => $item->date->W3C, 'update' => Date::format($item->update, 'c'), 'id' => $item->id, 'description' => $item->description, 'kind' => Mecha::A($item->kind));
        Weapon::fire('json_item', array(&$json['item'][$i], $item, $i));
    }
}
Weapon::fire('json_meta', array(&$json['meta']));
echo (isset($_GET['callback']) ? $_GET['callback'] . '(' : "") . json_encode($json) . (isset($_GET['callback']) ? ');' : "");
Exemple #9
0
echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
echo '<channel>';
echo '<generator>Mecha ' . MECHA_VERSION . '</generator>';
echo '<title>' . $config->title . '</title>';
echo '<link>' . $config->url . '/</link>';
echo '<description>' . $config->description . '</description>';
echo '<lastBuildDate>' . Date::format(time(), 'r') . '</lastBuildDate>';
echo '<atom:link rel="self" href="' . $config->url_current . '"/>';
echo $config->offset > 1 ? '<atom:link rel="previous" href="' . Filter::colon('feed:url', $url_base . '/' . ($config->offset - 1)) . '"/>' : "";
echo $config->offset < ceil($config->total_articles / $rss_limit) ? '<atom:link rel="next" href="' . Filter::colon('feed:url', $url_base . '/' . ($config->offset + 1)) . '"/>' : "";
Weapon::fire('rss_meta');
if (!empty($bucket)) {
    foreach ($bucket as $i => $item) {
        $title = strip_tags($item->title);
        $description = $item->description;
        $kind = Mecha::A($item->kind);
        echo '<item>';
        echo '<title><![CDATA[' . $title . ']]></title>';
        echo '<link>' . $item->url . '</link>';
        echo '<description><![CDATA[' . $description . ']]></description>';
        echo '<pubDate>' . Date::format($item->time, 'r') . '</pubDate>';
        echo '<guid>' . $item->url . '</guid>';
        if (!empty($kind)) {
            foreach ($kind as $k) {
                $tag = Get::articleTag($k);
                echo '<category domain="' . Filter::colon('tag:url', $config->url . '/' . $config->tag->slug . '/' . $tag->slug) . '">' . $tag->name . '</category>';
            }
        }
        echo '<source url="' . $item->url . '"><![CDATA[' . $config->title . ': ' . $title . ']]></source>';
        Weapon::fire('rss_item', array($item, $i));
        echo '</item>';
include 'unit.composer.1.php';
?>
      <label class="grid-group">
        <span class="grid span-1 form-label"><?php 
echo $speak->description;
?>
</span>
        <span class="grid span-5">
        <?php 
echo Form::textarea('description', Guardian::wayback('description', $default->description), Config::speak('manager.placeholder_description_', strtolower($speak->article)), array('class' => 'textarea-block'));
?>
        </span>
      </label>
      <?php 
$tags = array();
$tags_wayback = ',' . implode(',', Guardian::wayback('kind', Mecha::A($default->kind))) . ',';
foreach (Get::tags() as $tag) {
    if ($tag && $tag->id !== 0) {
        $tags[] = '<div>' . Form::checkbox('kind[]', $tag->id, strpos($tags_wayback, ',' . $tag->id . ',') !== false, $tag->name) . '</div>';
    }
}
?>
      <?php 
if (count($tags) > 0) {
    ?>
      <div class="grid-group">
        <span class="grid span-1 form-label"><?php 
    echo $speak->tags;
    ?>
</span>
        <div class="grid span-5"><?php 
Exemple #11
0
 /**
  * ============================================================
  *  STORE THE POSTED DATA INTO SESSION
  * ============================================================
  *
  * -- CODE: ---------------------------------------------------
  *
  *    if(Request::post()) {
  *        Guardian::memorize();
  *        // do another stuff ...
  *    }
  *
  * ------------------------------------------------------------
  *
  */
 public static function memorize($memo = null)
 {
     if (is_null($memo)) {
         $memo = $_SERVER['REQUEST_METHOD'] === 'POST' ? $_POST : array();
     }
     if (is_object($memo)) {
         $memo = Mecha::A($memo);
     }
     Session::set(self::$form, $memo);
 }
Exemple #12
0
    }, 11);
    Shield::lot(array('segment' => 'article', 'default' => $article))->attach('manager', false);
});
/**
 * Article Killer
 * --------------
 */
Route::accept($config->manager->slug . '/article/kill/id:(:num)', function ($id = "") use($config, $speak) {
    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));
Exemple #13
0
 * -------------------------------------------------------------
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *  Parameter | Type   | Description
 *  --------- | ------ | ---------------------------------------
 *  $key      | string | Key of language data to be called
 *  $vars     | array  | Array of value used in PHP `vsprintf()`
 *  --------- | ------ | ---------------------------------------
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 */
Config::plug('speak', function ($key = null, $vars = array()) {
    if (is_null($key)) {
        return Config::get('speak');
    }
    $speak = Mecha::A(Config::get('speak'));
    $fallback = $key;
    if (strpos($key, 'file:') === 0) {
        $key = File::path(str_replace('file:', "", $key));
        if ($file = File::exist(LANGUAGE . DS . Config::get('language') . DS . 'yapping' . DS . $key . '.txt')) {
            $wizard = Text::toPage(File::open($file)->read(), 'content', 'wizard:');
            return $wizard['content'];
        } else {
            if ($file = File::exist(ROOT . DS . $key . '.txt')) {
                $wizard = Text::toPage(File::open($file)->read(), 'content', 'wizard:');
                return $wizard['content'];
            }
        }
        return "";
    }
    if (!is_array($vars)) {
<?php

$fields = Get::state_field($segment);
Weapon::fire('unit_composer_3_before', array($segment, $fields));
if (!isset($default->fields)) {
    $default->fields = array();
}
if (!empty($fields)) {
    $html = "";
    $field = Guardian::wayback('fields', Mecha::A($default->fields));
    foreach ($fields as $key => $value) {
        // <= 1.1.3
        // "" is equal to `article,page`
        // '*' is equal to all scopes
        if ($value['scope'] === "") {
            $value['scope'] = 'article,page';
        }
        if ($value['scope'] === '*') {
            $value['scope'] = $segment;
        }
        if (isset($field[$key]['type'])) {
            $field[$key] = isset($field[$key]['value']) ? $field[$key]['value'] : "";
        }
        $type = $value['type'][0];
        if (strpos(',' . $value['scope'] . ',', ',' . $segment . ',') !== false) {
            $description = isset($value['description']) && trim($value['description']) !== "" ? ' <span class="text-info help" title="' . Text::parse($value['description'], '->encoded_html') . '">' . Jot::icon('question-circle') . '</span>' : "";
            $title = $value['title'] . $description;
            $html .= Form::hidden('fields[' . $key . '][type]', $type);
            if ($type === 't') {
                $html .= '<label class="grid-group grid-group-text">';
                $html .= '<span class="grid span-2 form-label">' . $title . '</span>';
Exemple #15
0
 /**
  * =====================================================================
  *  READ A TEXT FILE AS AN ASSOCIATIVE ARRAY
  * =====================================================================
  *
  * -- CODE: ------------------------------------------------------------
  *
  *    var_dump(Text::toArray("key 1: value 1\nkey 2: value 2"));
  *
  * ---------------------------------------------------------------------
  *
  */
 public static function toArray($text, $s = S, $indent = '    ')
 {
     if (is_array($text)) {
         return $text;
     }
     if (is_object($text)) {
         return Mecha::A($text);
     }
     $results = array();
     $data = array();
     $indent_length = strlen($indent);
     // Remove comment(s) and empty line break(s)
     $text = preg_replace(array('#\\r#', '#(^|\\n)\\s*\\#[^\\n]*#', '#\\n+#', '#^\\n+|\\n+$#'), array("", "\n", "\n", ""), $text);
     foreach (explode("\n", $text) as $line) {
         $depth = 0;
         // No `:` ... fix it!
         if (strpos($line, $s) === false) {
             $line .= $s . $line;
         }
         while (substr($line, 0, $indent_length) === $indent) {
             $depth += 1;
             $line = rtrim(substr($line, $indent_length));
         }
         while ($depth < count($data)) {
             array_pop($data);
         }
         $parts = explode($s, $line, 2);
         $data[$depth] = rtrim($parts[0]);
         $parent =& $results;
         foreach ($data as $depth => $key) {
             if (!isset($parent[$key])) {
                 $value = isset($parts[1]) && !empty($parts[1]) ? preg_replace('#^`|`$#', "", trim($parts[1])) : array();
                 $parent[rtrim($parts[0])] = Converter::strEval($value);
                 break;
             }
             $parent =& $parent[$key];
         }
     }
     return $results;
 }
Exemple #16
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');
});
Exemple #17
0
if (!defined('ROOT')) {
    die('Rejected!');
}
// Loading function(s)
foreach (glob(DECK . DS . 'workers' . DS . 'plug' . DS . '*.php', GLOB_NOSORT) as $plug) {
    require $plug;
}
$uri_end_parts = explode('/', $config->url_path);
$uri_end = $config->page_type === 'manager' ? $uri_end_parts[1] : $uri_end_parts[0];
// Hide `paragraph`, `superscript` and `subscript` button by default
$speak->MTE->buttons->paragraph = false;
$speak->MTE->buttons->superscript = false;
$speak->MTE->buttons->subscript = false;
// Merge language data to the `DASHBOARD`
Config::merge('DASHBOARD.languages.MTE', Mecha::A($speak->MTE));
/**
 * Backend Asset(s)
 * ----------------
 *
 * Inject the required asset(s) for manager.
 *
 */
Weapon::add('meta', function () use($config) {
    echo O_BEGIN . '<script>!function(a){var b=a.className;a.className=/(^|\\s)no-js(\\s|$)/.test(b)?b.replace(/(^|\\s)no-js(\\s|$)/,"$1js$2"):b+" js"}(document.documentElement);</script>' . O_END;
    if (!Asset::loaded($config->protocol . JS_LIBRARY_PATH)) {
        echo Asset::javascript($config->protocol . JS_LIBRARY_PATH);
    }
}, 20);
Weapon::add('shell_after', function () use($config) {
    echo Asset::stylesheet(array('manager/assets/shell/editor.css', 'manager/assets/shell/row.css', 'manager/assets/shell/check.css', 'manager/assets/shell/upload.css', 'manager/assets/shell/tab.css', 'manager/assets/shell/modal.css', 'manager/assets/shell/tooltip.css', 'manager/assets/shell/sortable.css', 'manager/assets/shell/accordion.css', 'manager/assets/shell/layout.css', 'assets/shell/manager.css', 'shell/manager.css'), "", 'shell/manager.min.css');
Exemple #18
0
    }
    Shield::lot(array('segment' => $segment))->attach('manager');
});
/**
 * Post Killer
 * -----------
 */
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));
Exemple #19
0
    }, 11);
    Shield::lot(array('segment' => 'page', 'default' => $page))->attach('manager', false);
});
/**
 * 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)));
    }
        $c->html_parser = (object) array('type' => array('HTML' => 'HTML'), 'active' => $c->html_parser);
    }
    $menus = Get::state_menu(null, false);
    if (!isset($menus['navigation'])) {
        $menus['navigation'] = $menus;
        File::serialize($menus)->saveTo(STATE . DS . 'menu.txt', 0600);
    }
    if ($tag = Get::state_tag(null, false)) {
        if (isset($tag[0]['id'])) {
            $tags = array();
            foreach ($tag as $t) {
                $tags[$t['id']] = array('name' => $t['name'], 'slug' => $t['slug'], 'description' => $t['description'], 'scope' => 'article');
            }
            File::serialize($tags)->saveTo(STATE . DS . 'tag.txt', 0600);
        }
    }
    if (is_string($c->author)) {
        $c->author = (object) array('name' => $c->author, 'email' => $c->author_email, 'url' => $c->author_profile_url);
        if ($c->page_type === 'manager') {
            Notify::info('<strong>1.2.0</strong> &mdash; In your <a href="' . $c->url . '/' . $c->manager->slug . '/shield">shield</a> files, change all <code>$c->author</code> data to <code>$c->author->name</code>, <code>$c->author_email</code> data to <code>$c->author->email</code> and <code>$c->author_profile_url</code> data to <code>$c->author->url</code>. Then go to the <a href="' . $c->url . '/' . $c->manager->slug . '/config">configuration manager page</a> to kill this message by pressing the <strong>Update</strong> button.');
        }
    }
    Config::set(Mecha::A($c));
    $config = $c;
}, 1);
Weapon::add('on_config_update', function () {
    // Self destruct ...
    File::open(__FILE__)->delete();
    Notify::clear();
    Notify::success(Config::speak('notify_success_updated', Config::speak('config')));
});
Exemple #21
0
 /**
  * ============================================================
  *  STORE THE POSTED DATA INTO SESSION
  * ============================================================
  *
  * -- CODE: ---------------------------------------------------
  *
  *    if(Request::post()) {
  *        Guardian::memorize();
  *        // do another stuff ...
  *    }
  *
  * ------------------------------------------------------------
  *
  */
 public static function memorize($name = null, $value = "")
 {
     if (is_null($name)) {
         $name = $_SERVER['REQUEST_METHOD'] === 'POST' ? $_POST : array();
     }
     if (is_object($name)) {
         $name = Mecha::A($name);
     }
     if (!is_array($name)) {
         $name = array($name => $value);
     }
     $memory = Session::get(self::$form, array());
     Session::set(self::$form, Mecha::extend($memory, $name));
 }
 function do_comment_construct()
 {
     $config = Config::get();
     $speak = Config::speak();
     if ($config->page_type === 'article') {
         $comment_id = 'comment-%d';
         // Your comment ID
         $comment_form_id = 'comment-form';
         // Your comment form ID
         $article = isset($config->article->path) ? $config->article : false;
         $G = array('data' => array('article' => Mecha::A($article), 'comment_id' => $comment_id, 'comment_form_id' => $comment_form_id));
         if ($article !== false && ($request = Request::post())) {
             if ($task = File::exist(SHIELD . DS . $config->shield . DS . 'workers' . DS . 'task.comment.php')) {
                 require $task;
                 // Custom comment constructor
             } else {
                 // Check token
                 Guardian::checkToken($request['token'], $article->url . '#' . $comment_form_id);
                 $extension = $config->comments->moderation && !Guardian::happy() ? '.hold' : '.txt';
                 // Check name
                 if (trim($request['name']) === "") {
                     Notify::error(Config::speak('notify_error_empty_field', $speak->name));
                 }
                 // Check email
                 if (trim($request['email']) !== "") {
                     if (!Guardian::check($request['email'], '->email')) {
                         Notify::error($speak->notify_invalid_email);
                     } else {
                         // Disallow passenger(s) from entering your email address in the comment email field
                         if (!Guardian::happy() && $request['email'] === $config->author->email) {
                             Notify::warning(Config::speak('notify_warning_forbidden_input', array('<em>' . $request['email'] . '</em>', strtolower($speak->email))));
                         }
                     }
                 } else {
                     Notify::error(Config::speak('notify_error_empty_field', $speak->email));
                 }
                 // Check URL
                 if (trim($request['url']) !== "" && !Guardian::check($request['url'], '->url')) {
                     Notify::error($speak->notify_invalid_url);
                 }
                 // Check message
                 if (trim($request['message']) === "") {
                     Notify::error(Config::speak('notify_error_empty_field', $speak->message));
                 }
                 // Check challenge
                 if (!Guardian::checkMath($request['math'])) {
                     Notify::error($speak->notify_invalid_math_answer);
                 }
                 // Check name length
                 if (Guardian::check($request['name'], '->too_long', 100)) {
                     Notify::error(Config::speak('notify_error_too_long', $speak->name));
                 }
                 // Check email length
                 if (Guardian::check($request['email'], '->too_long', 100)) {
                     Notify::error(Config::speak('notify_error_too_long', $speak->email));
                 }
                 // Check URL length
                 if (Guardian::check($request['url'], '->too_long', 100)) {
                     Notify::error(Config::speak('notify_error_too_long', $speak->url));
                 }
                 // Check message length
                 if (Guardian::check($request['message'], '->too_long', 1700)) {
                     Notify::error(Config::speak('notify_error_too_long', $speak->message));
                 }
                 // Check for spam keyword(s) in comment
                 $fucking_words = explode(',', $config->keywords_spam);
                 foreach ($fucking_words as $spam) {
                     if ($f**k = trim($spam)) {
                         if ($request['email'] === $f**k || strpos(strtolower($request['message']), strtolower($f**k)) !== false) {
                             Notify::warning($speak->notify_warning_intruder_detected . ' <strong class="text-error pull-right">' . $f**k . '</strong>');
                             break;
                         }
                     }
                 }
                 if (!Notify::errors()) {
                     $post = Date::slug($article->time);
                     $id = (int) time();
                     $parent = Request::post('parent');
                     $P = array('data' => $request);
                     $P['data']['id'] = $id;
                     $name = strip_tags($request['name']);
                     $email = Text::parse($request['email'], '->broken_entity');
                     $url = isset($request['url']) && trim($request['url']) !== "" ? $request['url'] : false;
                     $parser = strip_tags(Request::post('content_type', $config->html_parser->active));
                     $message = Text::parse($request['message'], '->text', WISE_CELL . '<img>', false);
                     $field = Request::post('fields', array());
                     include File::D(__DIR__, 2) . DS . 'task.fields.php';
                     // Temporarily disallow image(s) in comment to prevent XSS
                     $message = preg_replace('#<img(\\s[^<>]*?)>#i', '&lt;img$1&gt;', $message);
                     Page::header(array('Name' => $name, 'Email' => $email, 'URL' => $url, 'Status' => Guardian::happy() ? 1 : 2, 'Content Type' => $parser, 'Fields' => !empty($field) ? Text::parse($field, '->encoded_json') : false))->content($message)->saveTo(COMMENT . DS . $post . '_' . Date::slug($id) . '_' . ($parent ? Date::slug($parent) : '0000-00-00-00-00-00') . $extension);
                     Notify::success(Config::speak('notify_success_submitted', $speak->comment));
                     if ($extension === '.hold') {
                         Notify::info($speak->notify_info_comment_moderation);
                     }
                     Weapon::fire(array('on_comment_update', 'on_comment_construct'), array($G, $P));
                     Guardian::kick($config->url_current . $config->ur_query . (!Guardian::happy() && $config->comments->moderation ? '#' . $comment_form_id : '#' . sprintf($comment_id, Date::format($id, 'U'))));
                 } else {
                     Guardian::kick($config->url_current . $config->url_query . '#' . $comment_form_id);
                 }
             }
         }
     }
 }
Exemple #23
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');
Exemple #24
0
 public static function upload($file, $destination = ROOT, $callback = null)
 {
     $config = Config::get();
     $speak = Config::speak();
     $destination = self::path($destination);
     $errors = Mecha::A($speak->notify_file);
     // Create a safe file name
     $file['name'] = Text::parse($file['name'], '->safe_file_name');
     $extension = self::E($file['name']);
     // Something goes wrong
     if ($file['error'] > 0 && isset($errors[$file['error']])) {
         Notify::error($errors[$file['error']]);
     } else {
         // Destination not found
         if (!file_exists($destination)) {
             self::pocket($destination);
         }
         // Unknown file type
         if (!isset($file['type']) || empty($file['type'])) {
             Notify::error($speak->notify_error_file_type_unknown);
         }
         // Bad file extension
         $extension_allow = ',' . implode(',', self::$config['file_extension_allow']) . ',';
         if (strpos($extension_allow, ',' . $extension . ',') === false) {
             Notify::error(Config::speak('notify_error_file_extension', $extension));
         }
         // Too small
         if ($file['size'] < self::$config['file_size_min_allow']) {
             Notify::error(Config::speak('notify_error_file_size_min', self::size(self::$config['file_size_min_allow'], 'KB')));
         }
         // Too large
         if ($file['size'] > self::$config['file_size_max_allow']) {
             Notify::error(Config::speak('notify_error_file_size_max', self::size(self::$config['file_size_max_allow'], 'KB')));
         }
     }
     if (!Notify::errors()) {
         // Move the uploaded file to the destination folder
         if (!file_exists($destination . DS . $file['name'])) {
             move_uploaded_file($file['tmp_name'], $destination . DS . $file['name']);
         } else {
             Notify::error(Config::speak('notify_file_exist', '<code>' . $file['name'] . '</code>'));
         }
         if (!Notify::errors()) {
             // Create public asset link to show on file uploaded
             $link = self::url($destination) . '/' . $file['name'];
             Notify::success(Config::speak('notify_file_uploaded', '<code>' . $file['name'] . '</code>'));
             self::$open = $destination . DS . $file['name'];
             if (is_callable($callback)) {
                 call_user_func($callback, $file['name'], $file['type'], $file['size'], $link);
             }
         }
         return new static();
     }
     return false;
 }
Exemple #25
0
<?php

$fields = Get::state_field(null, array(), true, $segment);
if (!empty($fields)) {
    $html = "";
    $field = Guardian::wayback('fields', Mecha::A($page->fields_raw));
    $_ = 'unit:' . time() . '--';
    foreach ($fields as $key => $value) {
        if (isset($field[$key]['type'])) {
            // `POST` request
            $field[$key] = isset($field[$key]['value']) ? $field[$key]['value'] : "";
        }
        $type = $value['type'];
        if (!isset($value['scope']) || strpos(',' . $value['scope'] . ',', ',' . $segment . ',') !== false) {
            $description = isset($value['description']) && trim($value['description']) !== "" ? ' ' . Jot::info($value['description']) : "";
            $title = $value['title'] . $description;
            $html .= Form::hidden('fields[' . $key . '][type]', $type);
            if ($type === 'hidden' || $type === 'h') {
                $html .= Form::hidden('fields[' . $key . '][value]', isset($field[$key]) ? $field[$key] : $value['value']);
            } else {
                if ($type === 'text' || $type === 't') {
                    $html .= '<label class="grid-group grid-group-text">';
                    $html .= '<span class="grid span-2 form-label">' . $title . '</span>';
                    $html .= '<span class="grid span-4">';
                    $html .= Form::text('fields[' . $key . '][value]', Converter::toText(isset($field[$key]) ? $field[$key] : $value['value']), Converter::toText(isset($value['placeholder']) ? $value['placeholder'] : $value['value']), array('class' => 'input-block'));
                    $html .= '</span>';
                    $html .= '</label>';
                } else {
                    if ($type === 'boolean' || $type === 'b') {
                        $html .= '<div class="grid-group grid-group-boolean">';
                        $html .= '<span class="grid span-2"></span>';