Example #1
0
 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;
 }
function do_response_ping($message, $results = array())
{
    $results = (object) $results;
    if (isset($results->parent) && !is_null($results->parent)) {
        $prefix = File::B(File::D($results->path));
        $name = is_callable('Get::' . $prefix . 'Anchor') ? call_user_func('Get::' . $prefix . 'Anchor', $results->parent)->name : $results->parent;
        $to = '<a href="#' . $prefix . '-' . $results->parent . '">@' . $name . '</a>';
        return strpos($message, '<p>') === 0 ? str_replace('^<p>', '<p>' . $to . ' ', '^' . $message) : $message . '<p>' . $to . '</p>';
    }
    return $message;
}
Example #3
0
    foreach ($files as $file) {
        ?>
              <?php 
        if (strpos($file->path, $shield_path . 'states' . DS) === 0 || strpos($file->path, $shield_path . 'workers' . DS) === 0) {
            continue;
        }
        ?>
              <?php 
        $url = File::url(str_replace($shield_path, "", $file->path));
        ?>
              <tr<?php 
        echo Session::get('recent_item_update') === File::B($file->path) ? ' class="active"' : "";
        ?>
>
                <td><?php 
        echo strpos($url, '/') !== false ? Jot::span('fade', File::D($url) . '/') . File::B($url) : $url;
        ?>
</td>
                <td class="td-icon">
                <?php 
        echo Jot::a('construct', $shield_url_repair . $url, Jot::icon('pencil'), array('title' => $speak->edit));
        ?>
                </td>
                <td class="td-icon">
                <?php 
        echo Jot::a('destruct', $shield_url_kill . $url, Jot::icon('times'), array('title' => $speak->delete));
        ?>
                </td>
              </tr>
              <?php 
    }
Example #4
0
 /**
  * ==========================================================================
  *  EXTRACT POST FILE INTO LIST OF POST DATA FROM ITS PATH/SLUG/ID
  * ==========================================================================
  *
  * -- CODE: -----------------------------------------------------------------
  *
  *    var_dump(Get::post('about'));
  *
  * --------------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter  | Type   | Description
  *  ---------- | ------ | ---------------------------------------------------
  *  $reference | mixed  | Slug, ID, path or array of `Get::postExtract()`
  *  $excludes  | array  | Exclude some field(s) from result(s)
  *  $folder    | string | Folder of the post(s)
  *  $connector | string | Path connector for post URL
  *  $FP        | string | Filter prefix for `Text::toPage()`
  *  ---------- | ------ | ---------------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function post($reference, $excludes = array(), $folder = POST, $connector = '/', $FP = 'post:')
 {
     $config = Config::get();
     $speak = Config::speak();
     $excludes = array_flip($excludes);
     $results = false;
     if (!is_array($reference)) {
         // By slug => `post-slug` or by ID => `1403355917`
         if (strpos($reference, $folder) !== 0) {
             $reference = self::postPath($reference, $folder);
         }
         // By path => `lot\posts\$folder\2014-06-21-20-05-17_1,2,3_page-slug.txt`
         $results = self::postExtract($reference, $FP);
     } else {
         // From `Get::postExtract()`
         $results = $reference;
     }
     if (!$results || !file_exists($results['path'])) {
         return false;
     }
     // RULES: Do not do any tags looping, content parsing
     // and external file requesting if it has been marked as
     // the excluded field(s). For better performance.
     $results = $results + Text::toPage(file_get_contents($results['path']), isset($excludes['content']) ? false : 'content', $FP, array('link' => "", 'author' => $config->author->name, 'description' => "", 'content_type' => $config->html_parser->active, 'fields' => array(), 'content' => "", 'css' => "", 'js' => ""), $results);
     $content = $results['content_raw'];
     $time = str_replace(array(' ', ':'), '-', $results['time']);
     $e = File::E($results['path']);
     // Custom post content with PHP file, named as the post slug
     if ($php = File::exist(File::D($results['path']) . DS . $results['slug'] . '.php')) {
         ob_start();
         include $php;
         $results['content'] = ob_get_clean();
     }
     $results['date'] = Filter::colon($FP . 'date', Date::extract($results['time']), $results);
     $results['url'] = Filter::colon($FP . 'url', $config->url . $connector . $results['slug'], $results);
     $results['excerpt'] = $more = "";
     if ($content !== "") {
         $exc = isset($excludes['content']) && strpos($content, '<!--') !== false ? Text::toPage(Converter::ES($content), 'content', $FP, array(), $results) : $results;
         $exc = $exc['content'];
         $exc = is_array($exc) ? implode("", $exc) : $exc;
         // Generate fake description data
         if ($results['description'] === "") {
             $results['description'] = Converter::curt($exc, $config->excerpt->length, $config->excerpt->suffix);
         }
         // Manual post excerpt with `<!-- cut+ "Read More" -->`
         if (strpos($exc, '<!-- cut+ ') !== false) {
             preg_match('#<!-- cut\\+( +([\'"]?)(.*?)\\2)? -->#', $exc, $matches);
             $more = !empty($matches[3]) ? $matches[3] : $speak->read_more;
             $more = '<p><a class="fi-link" href="' . $results['url'] . '#' . sprintf($config->excerpt->id, $results['id']) . '">' . $more . '</a></p>';
             $exc = preg_replace('#<!-- cut\\+( +(.*?))? -->#', '<!-- cut -->', $exc);
         }
         // ... or `<!-- cut -->`
         if (strpos($exc, '<!-- cut -->') !== false) {
             $parts = explode('<!-- cut -->', $exc, 2);
             $results['excerpt'] = Filter::colon($FP . 'excerpt', trim($parts[0]) . $more, $results);
             $results['content'] = trim($parts[0]) . NL . NL . '<span class="fi" id="' . sprintf($config->excerpt->id, $results['id']) . '" aria-hidden="true"></span>' . NL . NL . trim($parts[1]);
         }
     }
     // Post Tags
     if (!isset($excludes['tags'])) {
         $tags = array();
         foreach ($results['kind'] as $id) {
             $tags[] = call_user_func('self::' . rtrim($FP, ':') . 'Tag', 'id:' . $id);
         }
         $results['tags'] = Filter::colon($FP . 'tags', Mecha::eat($tags)->order('ASC', 'name')->vomit(), $results);
     }
     // Post Images
     $results['images'] = Filter::colon($FP . 'images', self::imagesURL($results['content']), $results);
     $results['image'] = Filter::colon($FP . 'image', isset($results['images'][0]) ? $results['images'][0] : Image::placeholder(), $results);
     // Post CSS and JS
     if ($file = File::exist(CUSTOM . DS . Date::slug($results['time']) . '.' . File::E($results['path']))) {
         $custom = explode(SEPARATOR, File::open($file)->read());
         $css = isset($custom[0]) ? Converter::DS(trim($custom[0])) : "";
         $js = isset($custom[1]) ? Converter::DS(trim($custom[1])) : "";
         // css_raw
         // post:css_raw
         // custom:css_raw
         // shortcode
         // custom:shortcode
         // css:shortcode
         // css
         // post:css
         // custom:css
         $css = Filter::colon($FP . 'css_raw', $css, $results);
         $results['css_raw'] = Filter::apply('custom:css_raw', $css, $results);
         $css = Filter::colon('css:shortcode', $css, $results);
         $css = Filter::apply('custom:shortcode', $css, $results);
         $css = Filter::colon($FP . 'css', $css, $results);
         $results['css'] = Filter::apply('custom:css', $css, $results);
         // js_raw
         // post:js_raw
         // custom:js_raw
         // shortcode
         // custom:shortcode
         // js:shortcode
         // js
         // post:js
         // custom:js
         $js = Filter::colon($FP . 'js_raw', $js, $results);
         $results['js_raw'] = Filter::apply('custom:js_raw', $js, $results);
         $js = Filter::colon('js:shortcode', $js, $results);
         $js = Filter::apply('custom:shortcode', $js, $results);
         $js = Filter::colon($FP . 'js', $js, $results);
         $results['js'] = Filter::apply('custom:js', $js, $results);
     }
     // Post Field(s)
     if (!isset($excludes['fields'])) {
         self::__fields($results, $FP);
     }
     // Exclude some field(s) from result(s)
     foreach ($results as $key => $value) {
         if (isset($excludes[$key])) {
             unset($results[$key]);
         }
     }
     return Mecha::O($results);
 }
// New file data
if (isset($_FILES) && !empty($_FILES)) {
    $accept = File::$config['file_extension_allow'];
    foreach ($_FILES as $k => $v) {
        if (isset($field[$k]['accept'])) {
            File::$config['file_extension_allow'] = explode(',', $field[$k]['accept']);
        }
        if ($v['size'] > 0 && $v['error'] === 0) {
            $name = $name_o = Text::parse($v['name'], '->safe_file_name');
            // Group substance by extension
            if ($e = File::E($name, false)) {
                $name = $e . DS . $name;
            }
            // File already exists. Don't overwrite and don't show the error message
            if (file_exists(SUBSTANCE . DS . $name)) {
                $field[$k]['value'] = File::url($name_o);
                Notify::info(Config::speak('notify_file_exist', '<code>' . $name . '</code>'));
                // Upload new file
            } else {
                File::upload($v, SUBSTANCE . DS . File::D($name));
                if (!Notify::errors()) {
                    $field[$k]['value'] = File::url($name_o);
                    Weapon::fire(array('on_substance_update', 'on_substance_construct'), array($G, $P));
                }
            }
        }
        File::$config['file_extension_allow'] = $accept;
    }
    unset($accept);
}
Example #6
0
<?php

/**
 * Error Log
 * ---------
 */
Route::accept($config->manager->slug . '/error', function () use($config, $speak) {
    Config::set(array('page_title' => $speak->errors . $config->title_separator . $config->manager->title, 'cargo' => 'cargo.error.php'));
    Shield::lot(array('segment' => 'error', 'content' => File::open(ini_get('error_log'))->read(false)))->attach('manager');
});
/**
 * Error Log Killer
 * ----------------
 */
Route::accept($config->manager->slug . '/error/kill', function () use($config, $speak) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    $errors = LOG . DS . 'errors.log';
    $G = array('data' => array('content' => File::open($errors)->read()));
    File::open($errors)->delete();
    Weapon::fire('on_error_destruct', array($G, $G));
    Notify::success(Config::speak('notify_success_deleted', $speak->file));
    Guardian::kick(File::D($config->url_current));
});
Example #7
0
<?php

// Deleting custom CSS and JavaScript file of article ...
File::open(CUSTOM . DS . Date::format($id, 'Y-m-d-H-i-s') . '.txt')->delete();
File::open(CUSTOM . DS . Date::format($id, 'Y-m-d-H-i-s') . '.draft')->delete();
Weapon::fire('on_custom_update', array($G, $P));
Weapon::fire('on_custom_destruct', array($G, $P));
// Deleting custom PHP file of article ...
File::open(File::D($task_connect->path) . DS . $task_connect->slug . '.php')->delete();
Example #8
0
<?php

/**
 * Login Page
 * ----------
 *
 * [1]. manager/login
 *
 */
Route::accept($config->manager->slug . '/login', function () use($config, $speak) {
    if (!File::exist(File::D(__DIR__) . DS . 'launch.php')) {
        Shield::abort('404-manager');
    }
    if (Guardian::happy()) {
        Guardian::kick($config->manager->slug . '/article');
    }
    Config::set(array('page_title' => $speak->log_in . $config->title_separator . $config->title, 'cargo' => 'cargo.login.php'));
    include __DIR__ . DS . 'cargo.php';
    if ($request = Request::post()) {
        Guardian::authorize()->kick(isset($request['kick']) ? $request['kick'] : $config->manager->slug . '/article');
    }
    Shield::attach('manager-login');
}, 20);
/**
 * Logout Page
 * -----------
 *
 * [1]. manager/logout
 *
 */
Route::accept($config->manager->slug . '/logout', function () use($config, $speak) {
Example #9
0
            $task_connect_page_css = $config->defaults->page_custom_css;
            $task_connect_page_js = $config->defaults->page_custom_js;
            // Ignite
            if (!$id) {
                Page::header($header)->content($content)->saveTo(PAGE . DS . Date::format($date, 'Y-m-d-H-i-s') . '__' . $slug . $extension);
                include DECK . DS . 'workers' . DS . 'task.custom.2.php';
                Notify::success(Config::speak('notify_success_created', $title) . ($extension === '.txt' ? ' <a class="pull-right" href="' . $config->url . '/' . $slug . '" target="_blank"><i class="fa fa-eye"></i> ' . $speak->view . '</a>' : ""));
                Weapon::fire('on_page_update', array($G, $P));
                Weapon::fire('on_page_construct', array($G, $P));
                Guardian::kick($config->manager->slug . '/page/repair/id:' . Date::format($date, 'U'));
                // Repair
            } else {
                Page::open($page->path)->header($header)->content($content)->save();
                File::open($page->path)->renameTo(Date::format($date, 'Y-m-d-H-i-s') . '__' . $slug . $extension);
                include DECK . DS . 'workers' . DS . 'task.custom.1.php';
                if ($page->slug !== $slug && ($php_file = File::exist(File::D($page->path) . DS . $page->slug . '.php'))) {
                    File::open($php_file)->renameTo($slug . '.php');
                }
                Notify::success(Config::speak('notify_success_updated', $title) . ($extension === '.txt' ? ' <a class="pull-right" href="' . $config->url . '/' . $slug . '" target="_blank"><i class="fa fa-eye"></i> ' . $speak->view . '</a>' : ""));
                Weapon::fire('on_page_update', array($G, $P));
                Weapon::fire('on_page_repair', array($G, $P));
                Guardian::kick($config->manager->slug . '/page/repair/id:' . Date::format($date, 'U'));
            }
        }
    }
    Weapon::add('SHIPMENT_REGION_BOTTOM', function () {
        echo Asset::javascript('manager/assets/sword/editor.compose.js', "", 'sword/editor.compose.min.js');
    }, 11);
    Shield::lot(array('segment' => 'page', 'default' => $page))->attach('manager', false);
});
/**
Example #10
0
 * =============================================================
 *
 * -- CODE: ----------------------------------------------------
 *
 *    Config::load();
 *
 * -------------------------------------------------------------
 *
 */
Config::plug('load', function () {
    // Extract the configuration file
    $config = Get::state_config();
    // Define some default variable(s)
    $config['protocol'] = $config['url_protocol'] = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] === 443 ? 'https://' : 'http://';
    $config['host'] = $config['url_host'] = $_SERVER['HTTP_HOST'];
    $config['base'] = $config['url_base'] = trim(File::url(File::D($_SERVER['SCRIPT_NAME'])), '/');
    $config['url'] = rtrim($config['protocol'] . $config['host'] . '/' . $config['base'], '/');
    $config['url_path'] = trim(str_replace('/?', '?', $_SERVER['REQUEST_URI']), '/') === $config['base'] . '?' . trim('?' . $_SERVER['QUERY_STRING'], '/?') ? "" : preg_replace('#[?&].*$#', "", trim('?' . $_SERVER['QUERY_STRING'], '/?'));
    $config['url_current'] = rtrim($config['url'] . '/' . $config['url_path'], '/');
    $config['page_title'] = $config['title'];
    $config['index_query'] = $config['tag_query'] = $config['archive_query'] = $config['search_query'] = "";
    $config['articles'] = $config['article'] = $config['pages'] = $config['page'] = $config['responses'] = $config['response'] = $config['files'] = $config['file'] = $config['pagination'] = $config['cargo'] = false;
    $config['total_articles'] = count(glob(ARTICLE . DS . '*.txt', GLOB_NOSORT));
    $config['total_pages'] = count(glob(PAGE . DS . '*.txt', GLOB_NOSORT));
    $config['total_comments'] = count(glob(RESPONSE . DS . '*.txt', GLOB_NOSORT));
    $config['total_articles_backend'] = count(glob(ARTICLE . DS . '*.{txt,draft,archive}', GLOB_NOSORT | GLOB_BRACE));
    $config['total_pages_backend'] = count(glob(PAGE . DS . '*.{txt,draft,archive}', GLOB_NOSORT | GLOB_BRACE));
    $config['total_comments_backend'] = count(glob(RESPONSE . DS . '*.{txt,hold}', GLOB_NOSORT | GLOB_BRACE));
    $page = '404';
    $path = $config['url_path'];
    $s = explode('/', $path);
Example #11
0
 /**
  * ====================================================================
  *  SAVE IMAGE TO THE CURRENT DIRECTORY
  * ====================================================================
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type   | Description
  *  --------- | ------ | ----------------------------------------------
  *  $name     | string | New name for the image
  *  --------- | ------ | ----------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function saveAs($name = 'image-%d.png')
 {
     return self::saveTo(File::D(self::$placeholder) . DS . sprintf($name, time()));
 }
Example #12
0
<?php

$q_path = Request::get('path', "");
$q_path_dir = rtrim(File::D($q_path), '.');
$q = $q_path ? '?path=' . Text::parse($q_path, '->encoded_url') : "";
?>
<table class="table-bordered table-full-width">
  <thead>
    <tr>
      <th class="th-icon">
      <?php 
echo Form::checkbox(null, null, false, "", array('data-connection' => 'selected[]'));
?>
      </th>
      <th class="th-collapse"><?php 
echo Config::speak('last_', $speak->updated);
?>
</th>
      <th><?php 
echo $speak->file;
?>
</th>
      <th class="text-center" colspan="2"><?php 
echo $speak->action;
?>
</th>
    </tr>
  </thead>
  <tbody>
    <?php 
if ($files) {
Example #13
0
 /**
  * ====================================================================
  *  RENAME FILE(S) INSIDE A ZIP FILE
  * ====================================================================
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type  | Description
  *  --------- | ----- | -----------------------------------------------
  *  $old      | array | Array of old file name and new file name
  *  --------- | ----- | -----------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function renameFiles($old, $new = "")
 {
     $zip = new ZipArchive();
     if (File::exist(self::$open) && $zip->open(self::$open)) {
         if (is_array($old)) {
             foreach ($old as $k => $v) {
                 $k = File::path($k);
                 $v = File::path($v);
                 $root = trim(File::D($k), DS . '.') !== "" ? File::D($k) . DS : "";
                 $zip->renameName($k, $root . File::B($v));
             }
         } else {
             $old = File::path($old);
             $root = trim(File::D($old), DS . '.') !== "" ? File::D($old) . DS : "";
             $zip->renameName($old, $root . File::B($new));
         }
         $zip->close();
     }
     return new static();
 }
Example #14
0
Weapon::fire('main_action_before', $hooks);
?>
          <?php 
echo Jot::button('destruct', $speak->delete, 'action:kill');
?>
          <?php 
Weapon::fire('main_action_after', $hooks);
?>
        </div>
        <?php 
$asset_url = $config->manager->slug . '/asset';
$asset_url_kill = $asset_url . '/kill/file:';
$asset_url_repair = $asset_url . '/repair/file:';
$asset_path = ASSET . DS;
$q_path = Request::get('path', "");
$q_path_parent = File::D($q_path);
$q_path_ = str_replace('&', '&amp;', HTTP::query(array('path' => $q_path ? $q_path : false, 'q' => false)));
$q_path_parent_ = str_replace('&', '&amp;', HTTP::query(array('path' => $q_path_parent ? $q_path_parent : false, 'q' => false)));
?>
        <table class="table-bordered table-full-width">
          <thead>
            <tr>
              <th class="th-icon">
              <?php 
echo Form::checkbox(null, null, false, "", array('data-connection' => 'selected[]'));
?>
              </th>
              <th class="th-collapse"><?php 
echo Config::speak('last_', $speak->updated);
?>
</th>
Example #15
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');
});
Example #16
0
<a class="tab-button ajax-post" href="#tab-content-preview" data-action-url="<?php 
echo $config->url . '/' . $config->manager->slug . '/ajax/preview:' . File::url(str_replace(ROOT . DS, "", File::D(__DIR__, 3))) . '/' . (is_array($segment) ? $segment[0] : $segment);
?>
" data-text-progress="&lt;p&gt;<?php 
echo $speak->previewing;
?>
&hellip;&lt;/p&gt;" data-text-error="&lt;p&gt;<?php 
echo $speak->error;
?>
.&lt;/p&gt;" data-scope="#form-<?php 
echo $page->id ? 'repair' : 'ignite';
?>
" data-target="#form-<?php 
echo $page->id ? 'repair' : 'ignite';
?>
-preview"><?php 
echo Jot::icon('eye', 'fw') . ' ' . $speak->preview;
?>
</a>
Example #17
0
 /**
  * ==========================================================================
  *  EXTRACT PAGE FILE INTO LIST OF PAGE DATA FROM ITS PATH/SLUG/ID
  * ==========================================================================
  *
  * -- CODE: -----------------------------------------------------------------
  *
  *    var_dump(Get::page('about'));
  *
  * --------------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter  | Type   | Description
  *  ---------- | ------ | ---------------------------------------------------
  *  $reference | mixed  | Slug, ID, path or array of `Get::pageExtract()`
  *  $excludes  | array  | Exclude some field(s) from result(s)
  *  $folder    | string | Folder of the page(s)
  *  $connector | string | Path connector for page URL
  *  $FP        | string | Filter prefix for `Text::toPage()`
  *  ---------- | ------ | ---------------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function page($reference, $excludes = array(), $folder = PAGE, $connector = '/', $FP = 'page:')
 {
     $config = Config::get();
     $speak = Config::speak();
     $excludes = array_flip($excludes);
     $results = false;
     // From `Get::pageExtract()`
     if (is_array($reference)) {
         $results = $reference;
     } else {
         // By path => `cabinet\pages\0000-00-00-00-00-00_1,2,3_page-slug.txt`
         if (strpos($reference, $folder) === 0) {
             $results = self::pageExtract($reference, $FP);
         } else {
             // By slug => `page-slug` or by ID => 12345
             $results = self::pageExtract(self::pagePath($reference, $folder), $FP);
         }
     }
     if (!$results || !file_exists($results['path'])) {
         return false;
     }
     /**
      * RULES: Do not do any tags looping, content Markdown-ing
      * and external file requesting if it has been marked as
      * the excluded field(s). For better performance.
      */
     $results = $results + Text::toPage(File::open($results['path'])->read(), isset($excludes['content']) ? false : 'content', $FP);
     $content = isset($results['content_raw']) ? $results['content_raw'] : "";
     $time = str_replace(array(' ', ':'), '-', $results['time']);
     $extension = File::E($results['path']);
     if ($php_file = File::exist(File::D($results['path']) . DS . $results['slug'] . '.php')) {
         ob_start();
         include $php_file;
         $results['content'] = ob_get_clean();
     }
     $results['date'] = self::AMF(Date::extract($results['time']), $FP, 'date');
     $results['url'] = self::AMF($config->url . $connector . $results['slug'], $FP, 'url');
     $results['link'] = "";
     $results['excerpt'] = "";
     if (!isset($results['author'])) {
         $results['author'] = self::AMF($config->author, $FP, 'author');
     }
     if (!isset($results['description'])) {
         $summary = Converter::curt($content, $config->excerpt_length, $config->excerpt_tail);
         $results['description'] = self::AMF($summary, $FP, 'description');
     }
     $content_test = isset($excludes['content']) && strpos($content, '<!--') !== false ? Text::toPage(Text::ES($content), 'content', $FP) : $results;
     $content_test = $content_test['content'];
     $content_test = is_array($content_test) ? implode("", $content_test) : $content_test;
     // Redirect 301 with `<!-- kick: "http://example.com" -->`
     if (strpos($content_test, '<!-- kick:') !== false && $config->page_type === rtrim($FP, ':')) {
         preg_match('#<!-- kick\\: *([\'"]?)(.*?)\\1 -->#', $content_test, $matches);
         Guardian::kick($matches[2]);
     }
     // External link with `<!-- link: "http://example.com" -->`
     if (strpos($content_test, '<!-- link:') !== false) {
         preg_match('#<!-- link\\: *([\'"]?)(.*?)\\1 -->#', $content_test, $matches);
         $results['link'] = $matches[2];
         $results['content'] = preg_replace('#<!-- link\\:.*? -->#', "", $results['content']);
     }
     // Manual post excerpt with `<!-- cut+ "Read More" -->`
     if (strpos($content_test, '<!-- cut+ ') !== false) {
         preg_match('#<!-- cut\\+( +([\'"]?)(.*?)\\2)? -->#', $content_test, $matches);
         $more = !empty($matches[3]) ? $matches[3] : $speak->read_more;
         $content_test = preg_replace('#<!-- cut\\+( +(.*?))? -->#', '<p><a class="fi-link" href="' . $results['url'] . '#read-more:' . $results['id'] . '">' . $more . '</a></p><!-- cut -->', $content_test);
     }
     // ... or `<!-- cut -->`
     if (strpos($content_test, '<!-- cut -->') !== false) {
         $parts = explode('<!-- cut -->', $content_test, 2);
         $results['excerpt'] = self::AMF(trim($parts[0]), $FP, 'excerpt');
         $results['content'] = preg_replace('#<p><a class="fi-link" href=".*?">.*?<\\/a><\\/p>#', "", trim($parts[0])) . NL . NL . '<span class="fi" id="read-more:' . $results['id'] . '" aria-hidden="true"></span>' . NL . NL . trim($parts[1]);
     }
     if (!isset($excludes['tags'])) {
         $tags = array();
         foreach ($results['kind'] as $id) {
             $tags[] = self::rawTag($id);
         }
         $results['tags'] = self::AMF(Mecha::eat($tags)->order('ASC', 'name')->vomit(), $FP, 'tags');
     }
     if (!isset($excludes['css']) || !isset($excludes['js'])) {
         if ($file = File::exist(CUSTOM . DS . $time . '.' . $extension)) {
             $custom = explode(SEPARATOR, File::open($file)->read());
             $css = isset($custom[0]) ? Text::DS(trim($custom[0])) : "";
             $js = isset($custom[1]) ? Text::DS(trim($custom[1])) : "";
             /**
              * CSS
              * ---
              *
              * css_raw
              * page:css_raw
              * custom:css_raw
              *
              * shortcode
              * page:shortcode
              * custom:shortcode
              *
              * css
              * page:css
              * custom:css
              *
              */
             $css = self::AMF($css, $FP, 'css_raw');
             $results['css_raw'] = Filter::apply('custom:css_raw', $css);
             $css = self::AMF($css, $FP, 'shortcode');
             $css = Filter::apply('custom:shortcode', $css);
             $css = self::AMF($css, $FP, 'css');
             $results['css'] = Filter::apply('custom:css', $css);
             /**
              * JS
              * --
              *
              * js_raw
              * page:js_raw
              * custom:js_raw
              *
              * shortcode
              * page:shortcode
              * custom:shortcode
              *
              * js
              * page:js
              * custom:js
              *
              */
             $js = self::AMF($js, $FP, 'js_raw');
             $results['js_raw'] = Filter::apply('custom:js_raw', $js);
             $js = self::AMF($js, $FP, 'shortcode');
             $js = Filter::apply('custom:shortcode', $js);
             $js = self::AMF($js, $FP, 'js');
             $results['js'] = Filter::apply('custom:js', $js);
         } else {
             $results['css'] = $results['js'] = $results['css_raw'] = $results['js_raw'] = "";
         }
         $custom = $results['css'] . $results['js'];
     } else {
         $custom = "";
     }
     $results['images'] = self::AMF(self::imagesURL($results['content'] . $custom), $FP, 'images');
     $results['image'] = self::AMF(isset($results['images'][0]) ? $results['images'][0] : Image::placeholder(), $FP, 'image');
     $comments = self::comments($results['id'], 'ASC', Guardian::happy() ? 'txt,hold' : 'txt');
     $results['total_comments'] = self::AMF($comments !== false ? count($comments) : 0, $FP, 'total_comments');
     $results['total_comments_text'] = self::AMF($results['total_comments'] . ' ' . ($results['total_comments'] === 1 ? $speak->comment : $speak->comments), $FP, 'total_comments_text');
     if (!isset($excludes['comments'])) {
         if ($comments) {
             $results['comments'] = array();
             foreach ($comments as $comment) {
                 $results['comments'][] = self::comment($comment);
             }
             $results['comments'] = self::AMF($results['comments'], $FP, 'comments');
         }
     }
     unset($comments);
     /**
      * Custom Field(s)
      * ---------------
      */
     if (!isset($excludes['fields'])) {
         /**
          * Initialize custom field(s) with the default value(s) so that
          * user(s) don't have to write `isset()` function multiple time(s)
          * just to prevent error message(s) because of the object key(s)
          * that is not available in the old post(s).
          */
         $fields = self::state_field(rtrim($FP, ':'), null, array(), false);
         $init = array();
         foreach ($fields as $key => $value) {
             $init[$key] = $value['value'];
         }
         /**
          * Start re-writing ...
          */
         if (isset($results['fields']) && is_array($results['fields'])) {
             foreach ($results['fields'] as $key => $value) {
                 if (is_array($value) && isset($value['type'])) {
                     // <= 1.1.3
                     $value = isset($value['value']) ? $value['value'] : false;
                 }
                 $init[$key] = self::AMF($value, $FP, 'fields.' . $key);
             }
         }
         $results['fields'] = $init;
         unset($fields, $init);
     }
     /**
      * Exclude some field(s) from result(s)
      */
     foreach ($results as $key => $value) {
         if (isset($excludes[$key])) {
             unset($results[$key]);
         }
     }
     return Mecha::O($results);
 }
<?php

$comment_service_config = File::open(File::D(__DIR__) . DS . 'states' . DS . 'config.txt')->unserialize();
foreach (glob(__DIR__ . DS . '*', GLOB_ONLYDIR) as $option) {
    $option = File::B($option);
    $text = isset($speak->plugin_comment_service->title->{$option}) ? $speak->plugin_comment_service->title->{$option} : Text::parse($option, '->title');
    if ($comment_service_config['service'] === $option) {
        $text .= ' &#10004;';
    }
    $options[$speak->plugin_comment_service_title][$option] = $text;
}
$options[$speak->deactivate][0] = $speak->deactivate;
return array('comment_service' => array('title' => $speak->plugin_comment_service_title, 'type' => 'option', 'value' => $options, 'placeholder' => '&#10004;'));
Example #19
0
 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);
                 }
             }
         }
     }
 }
" class="page-<?php 
echo isset($segment) && $config->page_type !== '404' ? is_array($segment) ? $segment[0] : $segment : '404';
?>
">
  <head>
  <?php 
Weapon::fire('SHIPMENT_REGION_TOP');
?>
  <?php 
Weapon::fire('shell_before');
?>
  <?php 
$root_1 = PLUGIN . DS . 'manager' . DS . 'assets' . DS . 'shell' . DS;
?>
  <?php 
$root_2 = File::D(__DIR__) . DS . 'assets' . DS . 'shell' . DS;
?>
  <?php 
echo Asset::stylesheet(array($root_1 . 'row.css', $root_1 . 'upload.css', $root_1 . 'tab.css', $root_1 . 'toggle.css', $root_1 . 'modal.css', $root_1 . 'tooltip.css', $root_1 . 'sortable.css', $root_1 . 'accordion.css', $root_1 . 'layout.css', $root_2 . 'atom.css', $root_2 . 'layout.css'), "", 'shell/dashboard.min.css');
?>
  <?php 
Weapon::fire('shell_after');
?>
  </head>
  <body>
  <?php 
Weapon::fire('cargo_before');
?>
  <div class="board cl cf">
    <aside class="board-left cl cf">
      <?php 
Example #21
0
    } else {
        if (!($_file = File::exist(SHIELD . DS . $folder))) {
            Shield::abort();
            // Folder not found!
        }
    }
    Config::set(array('page_title' => $speak->deleting . ': ' . ($file !== false ? File::B($file) : $info->title) . $config->title_separator . $config->manager->title, 'page' => $info, 'cargo' => 'kill.shield.php'));
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        $P = array('data' => array('path' => $_file));
        File::open($_file)->delete();
        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
 * ---------------
Example #22
0
 /**
  * ====================================================================
  *  RENAME A FILE INSIDE A ZIP FILE
  * ====================================================================
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type   | Description
  *  --------- | ------ | ----------------------------------------------
  *  $old      | string | The old name
  *  $new      | string | The new name
  *  --------- | ------ | ----------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function renameFile($old, $new = "")
 {
     if (self::$zip->open(self::$open) === true) {
         $old = File::path($old);
         $root = File::D($old) !== "" ? File::D($old) . DS : "";
         self::$zip->renameName($old, $root . File::B($new));
         self::$zip->close();
     }
     return new static();
 }
<?php

$brush = Request::get('brush', $x === 'php' ? 'php' : 'generic');
$brush = Text::parse($brush, '->text');
if (is_numeric($brush) && $brush <= 0) {
    $brush = false;
}
$_ = File::D(__DIR__) . DS . 'assets' . DS;
echo '<!DOCTYPE html>' . NL;
echo '<html dir="ltr">' . NL;
echo TAB . '<head>' . NL;
echo str_repeat(TAB, 2) . '<meta charset="' . $config->charset . '">' . NL;
echo str_repeat(TAB, 2) . '<title>' . File::B($snippet) . '</title>' . NL;
echo str_repeat(TAB, 2) . '<link href="' . Filter::colon('favicon:url', $config->url . '/favicon.ico') . '" rel="shortcut icon" type="image/x-icon">' . NL;
echo str_repeat(TAB, 2) . Asset::stylesheet(array($_ . 'shell' . DS . 'page.min.css', $_ . 'shell' . DS . 'brush.min.css'));
echo TAB . '</head>' . NL;
echo TAB . '<body>' . NL;
echo str_repeat(TAB, 2) . '<pre><code' . ($brush !== false ? ' data-language="' . $brush . '"' : "") . '>';
echo Filter::colon('snippet:content_raw', Text::parse($content, '->encoded_html'), $snippet);
echo '</code></pre>' . NL;
echo str_repeat(TAB, 2) . '<div>' . NL;
echo str_repeat(TAB, 3) . '<strong><a href="' . $config->url . '" title="' . $speak->home . '">' . $config->title . '</a></strong>' . NL;
echo str_repeat(TAB, 3) . '<a href="?raw=1" target="_blank">' . $speak->plugin_snippet_share_title_raw . '</a>' . NL;
echo str_repeat(TAB, 3) . '<a href="?file=1">' . $speak->download . '</a>' . NL;
echo str_repeat(TAB, 2) . '</div>' . NL;
echo str_repeat(TAB, 2) . Asset::javascript(array($_ . 'sword' . DS . 'brush.min.js', $_ . 'sword' . DS . 'brush.line.min.js'));
if ($brush !== false) {
    echo str_repeat(TAB, 2) . Asset::javascript($_ . 'sword' . DS . 'brush' . DS . 'generic.min.js');
    if ($brush !== 'generic' && ($f = File::exist($_ . 'sword' . DS . 'brush' . DS . $brush . '.min.js'))) {
        echo str_repeat(TAB, 2) . Asset::javascript($f);
    }
Example #24
0
<?php

/**
 * Wizard Loader
 * -------------
 *
 * [1]. Guardian::wizard('menu');
 *
 */
Guardian::plug('wizard', function ($name = "", $vars = array(), $folder = 'yap') {
    $name = File::path($name);
    $_file = false;
    $r = File::D(__DIR__, 3) . DS . 'languages' . DS;
    if ($file = File::exist($r . Config::get('language') . DS . $folder . DS . $name . '.txt')) {
        $_file = $file;
    } else {
        if ($file = File::exist($r . 'en_US' . DS . $folder . DS . $name . '.txt')) {
            $_file = $file;
        } else {
            if ($file = File::exist(ROOT . DS . $name . '.txt')) {
                $_file = $file;
            } else {
                if ($file = File::exist($name . '.txt')) {
                    $_file = $file;
                }
            }
        }
    }
    $wizard = $_file ? Text::toPage(File::open($_file)->read(), 'content', 'wizard:') : false;
    return $wizard ? vsprintf($wizard['content'], $vars) : "";
});