function do_private_post($content, $results)
{
    global $config, $speak;
    $results = Mecha::O($results);
    $results = $config->is->post ? Get::postHeader($results->path, POST . DS . $config->page_type, '/', $config->page_type . ':') : false;
    if ($results === false) {
        return $speak->plugin_private_post->description;
    }
    $s = isset($results->fields->pass) ? $results->fields->pass : "";
    if (strpos($s, ':') !== false) {
        $s = explode(':', $s, 2);
        if (isset($s[1])) {
            $speak->plugin_private_post->hint = ltrim($s[1]);
        }
        // override password hint
        $s = $s[0];
    }
    $hash = md5($s . PRIVATE_POST_SALT);
    $html = Notify::read(false) . '<div class="overlay--' . File::B(__DIR__) . '"></div><form class="form--' . File::B(__DIR__) . '" action="' . $config->url . '/' . File::B(__DIR__) . '/do:access" method="post">' . NL;
    $html .= TAB . Form::hidden('token', Guardian::token()) . NL;
    $html .= TAB . Form::hidden('_', $hash) . NL;
    $html .= TAB . Form::hidden('kick', $config->url_current) . NL;
    $html .= TAB . '<p>' . $speak->plugin_private_post->hint . '</p>' . NL;
    $html .= TAB . '<p>' . Form::text('access', "", $speak->password . '&hellip;', array('autocomplete' => 'off')) . ' ' . Form::button($speak->submit, null, 'submit') . '</p>' . NL;
    $html .= '</form>' . O_END;
    if ($results && isset($results->fields->pass) && trim($results->fields->pass) !== "") {
        if (!Guardian::happy() && Session::get('is_allow_post_access') !== $hash) {
            return $html;
        }
    }
    return $content;
}
示例#2
0
 public static function info($folder = null, $array = false)
 {
     $config = Config::get();
     $speak = Config::speak();
     // Check whether the localized "about" file is available
     if (!($info = File::exist(PLUGIN . DS . $folder . DS . 'about.' . $config->language . '.txt'))) {
         $info = PLUGIN . DS . $folder . DS . 'about.txt';
     }
     $default = 'Title' . S . ' ' . ucwords(Text::parse($folder, '->text')) . "\n" . 'Author' . S . ' ' . $speak->anon . "\n" . 'URL' . S . ' #' . "\n" . 'Version' . S . ' 0.0.0' . "\n" . "\n" . SEPARATOR . "\n" . "\n" . Config::speak('notify_not_available', $speak->description);
     $info = Text::toPage(File::open($info)->read($default), 'content', 'plugin:');
     return $array ? $info : Mecha::O($info);
 }
示例#3
0
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        $info_path = Mecha::walk($deletes, function ($v) {
            $_path = ASSET . DS . $v;
            File::open($_path)->delete();
            return $_path;
        });
        $is_folder_or_file = count($deletes) === 1 && is_dir(ASSET . DS . $deletes[0]) ? 'folder' : 'file';
        $P = array('data' => array('files' => $info_path));
        Notify::success(Config::speak('notify_' . $is_folder_or_file . '_deleted', '<code>' . implode('</code>, <code>', $deletes) . '</code>'));
        Weapon::fire(array('on_asset_update', 'on_asset_destruct'), array($P, $P));
        Guardian::kick($config->manager->slug . '/asset/1' . str_replace('&', '&amp;', HTTP::query('path', $p)));
    } else {
        Notify::warning(count($deletes) === 1 ? Config::speak('notify_confirm_delete_', '<code>' . File::path($name) . '</code>') : $speak->notify_confirm_delete);
    }
    Shield::lot(array('segment' => 'asset', 'files' => Mecha::O($deletes)))->attach('manager');
});
/**
 * Multiple Asset Action
 * ---------------------
 */
Route::accept($config->manager->slug . '/asset/do', function ($path = "") use($config, $speak) {
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        if (!isset($request['selected'])) {
            Notify::error($speak->notify_error_no_files_selected);
            Guardian::kick($config->manager->slug . '/asset/1');
        }
        $files = Mecha::walk($request['selected'], function ($v) {
            return str_replace('%2F', '/', Text::parse($v, '->encoded_url'));
        });
示例#4
0
 /**
  * ==========================================================================
  *  GET MINIMUM DATA OF A PAGE
  * ==========================================================================
  *
  * -- CODE: -----------------------------------------------------------------
  *
  *    var_dump(Get::pageAnchor('about'));
  *
  * --------------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter  | Type   | Description
  *  ---------- | ------ | ---------------------------------------------------
  *  $path      | string | The URL path of the page file, or a page slug
  *  $folder    | string | Folder of the page(s)
  *  $connector | string | See `Get::page()`
  *  $FP        | string | See `Get::page()`
  *  ---------- | ------ | ---------------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function pageAnchor($path, $folder = PAGE, $connector = '/', $FP = 'page:')
 {
     $config = Config::get();
     if (strpos($path, ROOT) === false) {
         $path = self::pagePath($path, $folder);
         // By page slug, ID or time
     }
     if ($path && ($buffer = File::open($path)->get(1)) !== false) {
         $results = self::pageExtract($path);
         $parts = explode(S, $buffer, 2);
         $results['url'] = self::AMF($config->url . $connector . $results['slug'], $FP, 'url');
         $results['title'] = self::AMF(isset($parts[1]) ? Text::DS(trim($parts[1])) : "", $FP, 'title');
         return Mecha::O($results);
     }
     return false;
 }
示例#5
0
 if ($id && ($post = call_user_func('Get::' . $segment, $id, array('content', 'excerpt', 'tags')))) {
     $extension_o = '.' . File::E($post->path);
     if (!Guardian::happy(1) && Guardian::get('author') !== $post->author) {
         Shield::abort();
     }
     if (!File::exist(CUSTOM . DS . Date::slug($post->date->unix) . $extension_o)) {
         $post->css_raw = $config->defaults->{$segment . '_css'};
         $post->js_raw = $config->defaults->{$segment . '_js'};
     }
     $title = $speak->editing . ': ' . ($post->state !== 'drafted' ? Cell::a($post->url, $post->title, true) : $post->title) . $config->title_separator . $config->manager->title;
 } else {
     if ($id !== false) {
         Shield::abort();
         // File not found!
     }
     $post = Mecha::O(array('id' => "", 'path' => "", 'state' => 'drafted', 'date' => array('W3C' => ""), 'kind' => array(), 'slug' => "", 'title_raw' => $config->defaults->{$segment . '_title'}, 'link_raw' => "", 'description_raw' => "", 'author_raw' => Guardian::get('author'), 'content_type_raw' => $config->html_parser->active, 'fields_raw' => array(), 'content_raw' => $config->defaults->{$segment . '_content'}, 'css_raw' => $config->defaults->{$segment . '_css'}, 'js_raw' => $config->defaults->{$segment . '_js'}));
     $title = Config::speak('manager.title_new_', $speak->{$segment}) . $config->title_separator . $config->manager->title;
 }
 $G = array('data' => Mecha::A($post));
 Config::set(array('page_title' => $title, 'page' => $post, 'html_parser' => array('active' => $post->content_type_raw), 'cargo' => 'repair.post.php'));
 if ($request = Request::post()) {
     Guardian::checkToken($request['token']);
     // Check for invalid time pattern
     if (isset($request['date']) && trim($request['date']) !== "" && !preg_match('#^\\d{4,}\\-\\d{2}\\-\\d{2}T\\d{2}\\:\\d{2}\\:\\d{2}\\+\\d{2}\\:\\d{2}$#', $request['date'])) {
         Notify::error($speak->notify_invalid_time_pattern);
         Guardian::memorize($request);
     }
     $rid = (int) date('U', isset($request['date']) && trim($request['date']) !== "" ? strtotime($request['date']) : time());
     $request['path'] = $post->path;
     // Set post date by submitted time, or by input value if available
     $date = date('c', $rid);
示例#6
0
 * ----------
 */
Route::accept($config->manager->slug . '/tag/kill/id:(:any)', function ($id = false) use($config, $speak, $tags) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    if (!isset($tags[$id])) {
        Shield::abort();
        // Tag not found!
    }
    $title = $tags[$id]['name'];
    Config::set(array('page_title' => $speak->deleting . ': ' . $title . $config->title_separator . $config->manager->title, 'cargo' => 'kill.tag.php'));
    $G = array('data' => $tags);
    $G['data']['id'] = $id;
    if ($request = Request::post()) {
        $request = Filter::apply('request:__tag', $request, $id);
        Guardian::checkToken($request['token']);
        unset($tags[$id]);
        // delete ...
        ksort($tags);
        $P = array('data' => $tags);
        $P['data']['id'] = $id;
        File::serialize($tags)->saveTo(STATE . DS . 'tag.txt', 0600);
        Notify::success(Config::speak('notify_success_deleted', $title));
        Weapon::fire(array('on_tag_update', 'on_tag_destruct'), array($G, $P));
        Guardian::kick($config->manager->slug . '/tag');
    } else {
        Notify::warning(Config::speak('notify_confirm_delete_', '<strong>' . $title . '</strong>'));
    }
    Shield::lot(array('segment' => 'tag', 'id' => $id, 'file' => Mecha::O($tags[$id])))->attach('manager');
});
示例#7
0
 * -----------
 */
Route::accept($config->manager->slug . '/menu/kill/key:(:any)', function ($key = false) use($config, $speak) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    $menus = Get::state_menu(null, array(), false);
    if (!isset($menus[$key])) {
        Shield::abort();
        // Menu not found!
    }
    Config::set(array('page_title' => $speak->deleting . ': ' . $speak->menu . $config->title_separator . $config->manager->title, 'cargo' => 'kill.menu.php'));
    $G = array('data' => $menus);
    $G['data']['key'] = $key;
    if ($request = Request::post()) {
        $request = Filter::apply('request:__menu', $request, $key);
        Guardian::checkToken($request['token']);
        unset($menus[$key]);
        // delete ...
        ksort($menus);
        $P = array('data' => $menus);
        $P['data']['key'] = $key;
        File::serialize($menus)->saveTo(STATE . DS . 'menu.txt', 0600);
        Notify::success(Config::speak('notify_success_deleted', $speak->menu));
        Weapon::fire(array('on_menu_update', 'on_menu_destruct'), array($G, $P));
        Guardian::kick($config->manager->slug . '/menu');
    } else {
        Notify::warning(Config::speak('notify_confirm_delete_', '<code>Menu::' . $key . '()</code>'));
    }
    Shield::lot(array('segment' => 'menu', 'id' => $key, 'file' => Mecha::O($menus[$key])))->attach('manager');
});
示例#8
0
 /**
  * =============================================================
  *  GET CONFIGURATION DATA BY ITS KEY
  * =============================================================
  *
  * -- CODE: ----------------------------------------------------
  *
  *    echo Config::get('url');
  *
  * -------------------------------------------------------------
  *
  *    echo Config::get('index')->slug;
  *
  * -------------------------------------------------------------
  *
  *    echo Config::get('index.slug');
  *
  * -------------------------------------------------------------
  *
  *    $config = Config::get();
  *
  *    echo $config->url;
  *    echo $config->index->slug;
  *
  * -------------------------------------------------------------
  *
  *    $bucket = Config::get(array('foo', 'bar', 'baz'));
  *
  * -------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type   | Description
  *  --------- | ------ | ---------------------------------------
  *  $key      | string | Key of data to be called
  *  $fallback | mixed  | Fallback value if data does not exist
  *  --------- | ------ | ---------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function get($key = null, $fallback = false)
 {
     if (is_null($key)) {
         return Mecha::O(self::$bucket);
     }
     if (is_array($key)) {
         $results = array();
         foreach ($key as $k => $v) {
             $f = is_array($fallback) && array_key_exists($k, $fallback) ? $fallback[$k] : $fallback;
             $results[$v] = self::get($v, $f);
         }
         return (object) $results;
     }
     if (is_string($key) && strpos($key, '.') !== false) {
         $output = Mecha::GVR(self::$bucket, $key, $fallback);
         return is_array($output) ? Mecha::O($output) : $output;
     }
     return array_key_exists($key, self::$bucket) ? Mecha::O(self::$bucket[$key]) : $fallback;
 }
示例#9
0
<?php

/**
 * Shortcode Manager
 * -----------------
 */
Route::accept($config->manager->slug . '/shortcode', function () use($config, $speak) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    $shortcodes = Get::state_shortcode(null, array(), false);
    $G = array('data' => $shortcodes);
    Config::set(array('page_title' => $speak->shortcodes . $config->title_separator . $config->manager->title, 'cargo' => 'cargo.shortcode.php'));
    if ($request = Request::post()) {
        $request = Filter::apply('request:__shortcode', $request);
        Guardian::checkToken($request['token']);
        $data = array();
        for ($i = 0, $keys = $request['key'], $count = count($keys); $i < $count; ++$i) {
            if (trim($keys[$i]) !== "") {
                $data[$keys[$i]] = $request['value'][$i];
            }
        }
        $P = array('data' => $data);
        File::serialize($data)->saveTo(STATE . DS . 'shortcode.txt', 0600);
        Notify::success(Config::speak('notify_success_updated', $speak->shortcode));
        Weapon::fire('on_shortcode_update', array($G, $P));
        Guardian::kick($config->url_current);
    }
    Shield::lot(array('segment' => 'shortcode', 'files' => Mecha::O($shortcodes)))->attach('manager');
});
示例#10
0
 Weapon::add('tab_content_2_before', function ($page, $segment) use($config, $speak) {
     $segment = $segment[0];
     include __DIR__ . DS . 'unit' . DS . 'form' . DS . 'fields[].php';
 }, 1);
 File::write($config->{'__total_' . $segment . 's'})->saveTo(LOG . DS . $segment . 's.total.log', 0600);
 if ($id && ($response = call_user_func('Get::' . $segment, $id, array('message')))) {
     if (!Guardian::happy(1)) {
         Shield::abort();
     }
     $title = $speak->editing . ': ' . ($response->permalink !== '#' ? Cell::a($response->permalink, $speak->{$segment}, true) : $speak->{$segment}) . $config->title_separator . $config->manager->title;
 } else {
     if ($id !== false) {
         Shield::abort();
         // File not found!
     }
     $response = Mecha::O(array('id' => "", 'path' => "", 'post' => "", 'parent' => "", 'state' => 'pending', 'date' => array('W3C' => ""), 'name_raw' => Guardian::get('author'), 'email' => Guardian::get('email'), 'url_raw' => "", 'status_raw' => Guardian::get('status_raw'), 'content_type_raw' => $config->html_parser->active, 'fields_raw' => array(), 'message_raw' => ""));
     $title = Config::speak('manager.title_new_', $speak->{$segment}) . $config->title_separator . $config->manager->title;
 }
 $G = array('data' => Mecha::A($response));
 Config::set(array('page_title' => $title, 'page' => $response, 'html_parser' => array('active' => $response->content_type_raw), 'cargo' => 'repair.response.php'));
 if ($request = Request::post()) {
     $request = Filter::apply('request:__' . $segment, $request, $id);
     Guardian::checkToken($request['token']);
     $rid = $id ? $id : time();
     $request['post'] = Request::post('post');
     $request['parent'] = Request::post('parent');
     $extension = $request['extension'];
     $name = $request['name'];
     $email = $request['email'];
     $url = isset($request['url']) && trim($request['url']) !== "" ? $request['url'] : false;
     $message = $request['message'];
示例#11
0
                    }
                }
            }
        } else {
            $tab_id = 'tab-content-2';
            include __DIR__ . DS . 'task.js.tab.php';
        }
    }
    $filter = Request::get('q', "");
    $filter = $filter ? Text::parse($filter, '->safe_file_name') : "";
    $s = Get::closestFolders($destination, 'ASC', 'path', $filter);
    if (!($folders = Mecha::eat($s)->chunk($offset, $config->manager->per_page)->vomit())) {
        Shield::abort();
    }
    Config::set(array('page_title' => $speak->plugins . $config->title_separator . $config->manager->title, 'offset' => $offset, 'pagination' => Navigator::extract($s, $offset, $config->manager->per_page, $config->manager->slug . '/plugin'), 'cargo' => 'cargo.plugin.php'));
    Shield::lot(array('segment' => 'plugin', 'folders' => Mecha::O($folders)))->attach('manager');
});
/**
 * Plugin Configurator
 * -------------------
 */
Route::accept($config->manager->slug . '/plugin/(:any)', function ($slug = 1) use($config, $speak) {
    if (is_numeric($slug)) {
        // It's an index page
        Route::execute($config->manager->slug . '/plugin/(:num)', array($slug));
    }
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    if (!File::exist(PLUGIN . DS . $slug . DS . 'launch.php') && !File::exist(PLUGIN . DS . $slug . DS . '__launch.php')) {
        Shield::abort();
示例#12
0
         $page->css_raw = $config->defaults->page_custom_css;
         $page->js_raw = $config->defaults->page_custom_js;
     }
     // Remove automatic page description data from page composer
     $test = explode(SEPARATOR, str_replace("\r", "", file_get_contents($page->path)), 2);
     if (strpos($test[0], "\n" . 'Description' . S . ' ') === false) {
         $page->description = "";
     }
     unset($test);
     Config::set(array('page_title' => $speak->editing . ': ' . $page->title . $config->title_separator . $config->manager->title, 'page' => Mecha::A($page)));
 } else {
     if ($id !== false) {
         Shield::abort();
         // File not found!
     }
     $page = Mecha::O(array('id' => "", 'path' => "", 'state' => 'draft', 'date' => array('W3C' => ""), 'title' => $config->defaults->page_title, 'slug' => "", 'content_raw' => $config->defaults->page_content, 'content_type' => $config->html_parser, 'description' => "", 'author' => Guardian::get('author'), 'css_raw' => $config->defaults->page_custom_css, 'js_raw' => $config->defaults->page_custom_js, 'fields' => array()));
     Config::set(array('page_title' => Config::speak('manager.title_new_', $speak->page) . $config->title_separator . $config->manager->title, 'page' => Mecha::A($page)));
 }
 $G = array('data' => Mecha::A($page));
 Config::set('html_parser', $page->content_type);
 if ($request = Request::post()) {
     Guardian::checkToken($request['token']);
     $task_connect = $page;
     include DECK . DS . 'workers' . DS . 'task.field.5.php';
     include DECK . DS . 'workers' . DS . 'task.field.6.php';
     $extension = $request['action'] === 'publish' ? '.txt' : '.draft';
     // Check for duplicate slug, except for the current old slug.
     // Allow user(s) to change their post slug, but make sure they
     // do not type the slug of another post.
     if (trim($slug) !== "" && $slug !== $page->slug && ($files = Get::pages('DESC', "", 'txt,draft,archive'))) {
         foreach ($files as $file) {
示例#13
0
    echo $speak->name;
    ?>
</th>
      <th><?php 
    echo $speak->slug;
    ?>
</th>
      <th class="text-center" colspan="2"><?php 
    echo $speak->action;
    ?>
</th>
    </tr>
  </thead>
  <tbody>
    <?php 
    foreach (Mecha::O($files_all) as $key => $value) {
        ?>
    <tr<?php 
        echo Session::get('recent_item_update') === $key ? ' class="active"' : "";
        ?>
>
      <td class="text-right"><?php 
        echo $key;
        ?>
</td>
      <td><?php 
        echo $value->name;
        ?>
</td>
      <td><code><?php 
        echo $value->slug;
示例#14
0
        if ($_file !== false) {
            // Remove empty folder(s)
            $f = glob(File::D($_file) . DS . '*', GLOB_NOSORT);
            if (empty($f)) {
                File::open(File::D($_file))->delete();
            }
            Notify::success(Config::speak('notify_file_deleted', '<code>' . File::B($_file) . '</code>'));
        } else {
            Notify::success(Config::speak('notify_success_deleted', $speak->shield));
        }
        Weapon::fire(array('on_shield_update', 'on_shield_destruct'), array($P, $P));
        Guardian::kick($config->manager->slug . '/shield' . ($_file !== false ? '/' . $folder : ""));
    } else {
        Notify::warning(Config::speak('notify_confirm_delete_', $file !== false ? '<code>' . $path . '</code>' : '<strong>' . $info->title . '</strong>'));
    }
    Shield::lot(array('segment' => 'shield', 'folder' => $folder, 'files' => Mecha::O(Get::files(SHIELD . DS . $folder, '*')), 'path' => $path))->attach('manager');
});
/**
 * Shield Attacher
 * ---------------
 */
Route::accept($config->manager->slug . '/shield/(attach|eject)/id:(:any)', function ($path = "", $slug = "") use($config, $speak) {
    if (!Guardian::happy(1) || !file_exists(SHIELD . DS . $slug)) {
        Shield::abort();
    }
    $new_config = Get::state_config();
    $new_config['shield'] = $path === 'attach' ? $slug : 'normal';
    File::serialize($new_config)->saveTo(STATE . DS . 'config.txt', 0600);
    $G = array('data' => array('id' => $slug, 'action' => $path));
    $mode = $path === 'eject' ? 'eject' : 'mount';
    Notify::success(Config::speak('notify_success_updated', $speak->shield));
示例#15
0
 /**
  * =============================================================
  *  GET CONFIGURATION VALUE BY ITS KEY
  * =============================================================
  *
  * -- CODE: ----------------------------------------------------
  *
  *    echo Config::get('url');
  *
  * -------------------------------------------------------------
  *
  *    echo Config::get('index')->slug;
  *
  * -------------------------------------------------------------
  *
  *    echo Config::get('index.slug');
  *
  * -------------------------------------------------------------
  *
  *    $config = Config::get();
  *
  *    echo $config->url;
  *    echo $config->index->slug;
  *
  * -------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type   | Description
  *  --------- | ------ | ---------------------------------------
  *  $key      | string | Key of data to be called
  *  $fallback | mixed  | Fallback value if data does not exist
  *  --------- | ------ | ---------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function get($key = null, $fallback = false)
 {
     if (is_null($key)) {
         return Mecha::O(self::$bucket);
     }
     if (is_string($key) && strpos($key, '.') !== false) {
         $output = Mecha::GVR(self::$bucket, $key, $fallback);
         return is_array($output) ? Mecha::O($output) : $output;
     }
     return array_key_exists($key, self::$bucket) ? Mecha::O(self::$bucket[$key]) : $fallback;
 }
示例#16
0
 /**
  * ==========================================================
  *  GET SHIELD INFO
  * ==========================================================
  *
  * -- CODE: -------------------------------------------------
  *
  *    var_dump(Shield::info('normal'));
  *
  * ----------------------------------------------------------
  *
  */
 public static function info($folder = null, $array = false)
 {
     $config = Config::get();
     $speak = Config::speak();
     if (is_null($folder)) {
         $folder = $config->shield;
     }
     // Check whether the localized "about" file is available
     if (!($info = File::exist(SHIELD . DS . $folder . DS . 'about.' . $config->language . '.txt'))) {
         $info = SHIELD . DS . $folder . DS . 'about.txt';
     }
     $d = 'Title' . S . ' ' . Text::parse($folder, '->title') . "\n" . 'Author' . S . ' ' . $speak->anon . "\n" . 'URL' . S . ' #' . "\n" . 'Version' . S . ' 0.0.0' . "\n" . "\n" . SEPARATOR . "\n" . "\n" . Config::speak('notify_not_available', $speak->description);
     $info = Text::toPage(File::open($info)->read($d), 'content', 'shield:', array('id' => File::exist(SHIELD . DS . $folder) ? $folder : false));
     return $array ? $info : Mecha::O($info);
 }
示例#17
0
 /**
  * ==========================================================================
  *  EXTRACT RESPONSE FILE INTO LIST OF RESPONSE DATA FROM ITS PATH/ID/TIME
  * ==========================================================================
  *
  * -- CODE: -----------------------------------------------------------------
  *
  *    var_dump(Get::response(1399334470));
  *
  * --------------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter  | Type   | Description
  *  ---------- | ------ | ---------------------------------------------------
  *  $reference | string | Response path, ID or time
  *  $excludes  | array  | Exclude some field(s) from result(s)
  *  $folder    | string | Folder of response(s) and response(s)' post
  *  $connector | string | Path connector for permalink URL
  *  $FP        | string | Filter prefix for `Text::toPage()`
  *  ---------- | ------ | ---------------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function response($reference, $excludes = array(), $folder = array(), $connector = '/', $FP = 'response:')
 {
     $config = Config::get();
     $excludes = array_flip($excludes);
     $results = false;
     if (!is_array($reference)) {
         // By time => `2014-06-21-20-05-17` or by ID => `1403355917`
         if (strpos($reference, $folder[0]) !== 0) {
             $reference = self::responsePath($reference, $folder[0]);
         }
         // By path => `lot\responses\$folder[0]\2014-05-24-11-17-06_2014-06-21-20-05-17_0000-00-00-00-00-00.txt`
         $results = self::responseExtract($reference, $FP);
     } else {
         // From `Get::responseExtract()`
         $results = $reference;
     }
     if (!$results || !file_exists($results['path'])) {
         return false;
     }
     $results['date'] = Filter::colon($FP . 'date', Date::extract($results['time']), $results);
     $results = $results + Text::toPage(file_get_contents($results['path']), 'message', $FP, array('url' => '#', 'content_type' => $config->html_parser->active, 'fields' => array(), 'message' => ""), $results);
     if (!isset($excludes['permalink'])) {
         if ($path = self::postPath($results['post'], $folder[1])) {
             $link = self::postAnchor($path, $folder[1], $connector, "")->url . '#' . rtrim($FP, ':') . '-' . $results['id'];
         } else {
             $link = '#';
         }
         $results['permalink'] = Filter::colon($FP . 'permalink', $link, $results);
     }
     if (!isset($excludes['fields'])) {
         self::__fields($results, $FP);
     }
     foreach ($results as $key => $value) {
         if (isset($excludes[$key])) {
             unset($results[$key]);
         }
     }
     return Mecha::O($results);
 }
示例#18
0
 /**
  * ============================================================================
  *  PAGINATION EXTRACTOR FOR LIST OF FILE(S)
  * ============================================================================
  *
  * -- CODE: -------------------------------------------------------------------
  *
  *    $pager = Navigator::extract(glob('some/files/*.txt'), 1, 5, 'foo/bar');
  *    echo $pager->prev->anchor;
  *
  * ----------------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter  | Type    | Description
  *  ---------- | ------- | ----------------------------------------------------
  *  $pages     | array   | Array of file(s) to be paginated
  *  $current   | integer | The current page offset
  *  $current   | string  | The current page path
  *  $per_page  | integer | Number of file(s) to show per page request
  *  $connector | string  | Extra path to be inserted into URL
  *  ---------- | ------- | ----------------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function extract($pages = array(), $current = 1, $per_page = 10, $connector = '/')
 {
     // Set default next, previous and step data
     $bucket = array('prev' => false, 'next' => false, 'step' => false);
     $pages = (array) $pages;
     $config = Config::get();
     $speak = Config::speak();
     $base = $config->url;
     $q = str_replace('&', '&amp;', $config->url_query);
     $qq = strpos($connector, '?') !== false ? str_replace('?', '&amp;', $q) : $q;
     $total = count($pages);
     $c = self::$config;
     if (strpos($connector, '%s') === false) {
         if (trim($connector, '/') !== "") {
             $connector = '/' . trim($connector, '/') . '/%s';
         } else {
             $connector = '/%s';
         }
     }
     if (is_int($current)) {
         $current = (int) $current;
         $prev = $current > 1 ? $current - 1 : false;
         $next = $current < ceil($total / $per_page) ? $current + 1 : false;
         // Generate next/previous URL for index page
         $bucket['prev']['url'] = Filter::apply(array('pager:prev.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, $prev) . $qq : $base . $q, $prev, $connector);
         $bucket['next']['url'] = Filter::apply(array('pager:next.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $next) . $qq : $base . $q, $next, $connector);
         // Generate next/previous anchor for index page
         $bucket['prev']['anchor'] = Filter::apply(array('pager:prev.anchor', 'pager:anchor', 'anchor'), $prev ? '<a href="' . $bucket['prev']['url'] . '" rel="prev">' . $speak->newer . '</a>' : "", $prev, $connector);
         $bucket['next']['anchor'] = Filter::apply(array('pager:next.anchor', 'pager:anchor', 'anchor'), $next ? '<a href="' . $bucket['next']['url'] . '" rel="next">' . $speak->older . '</a>' : "", $next, $connector);
         // Generate pagination anchor(s) for index page
         $html = '<span' . ($c['classes']['pagination'] !== false ? ' class="' . $c['classes']['pagination'] . '"' : "") . '>';
         $chunk = (int) ceil($total / $per_page);
         $step = $chunk > self::$config['step'] ? self::$config['step'] : $chunk;
         $left = $current - $step;
         if ($left < 1) {
             $left = 1;
         }
         if ($chunk > 1) {
             $bucket['step']['url']['first'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, 1) . $qq : false, 1, $connector);
             $bucket['step']['url']['prev'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, $prev) . $qq : false, $prev, $connector);
             $bucket['step']['anchor']['first'] = Filter::apply(array('pager:step.anchor', 'pager:anchor', 'anchor'), $prev ? '<a href="' . $bucket['step']['url']['first'] . '">' . $speak->first . '</a>' : '<span>' . $speak->first . '</span>', 1, $connector);
             $bucket['step']['anchor']['prev'] = Filter::apply(array('pager:step.anchor', 'pager:anchor', 'anchor'), $prev ? '<a href="' . $bucket['step']['url']['prev'] . '" rel="prev">' . $speak->prev . '</a>' : '<span>' . $speak->prev . '</span>', $prev, $connector);
             $html .= $bucket['step']['anchor']['first'] . $bucket['step']['anchor']['prev'];
             $html .= '<span>';
             for ($i = $current - $step + 1; $i < $current + $step; ++$i) {
                 if ($chunk > 1) {
                     if ($i - 1 < $chunk && ($i > 0 && $i + 1 > $current - $left - round($chunk / 2))) {
                         $bucket['step']['url'][$i] = Filter::apply(array('pager:step.url', 'pager:url'), $i !== $current ? $base . sprintf($connector, $i) . $qq : false, $i, $connector);
                         $bucket['step']['anchor'][$i] = Filter::apply(array('pager:step.anchor', 'pager:anchor', 'anchor'), $i !== $current ? '<a href="' . $bucket['step']['url'][$i] . '">' . $i . '</a>' : '<strong' . ($c['classes']['current'] !== false ? ' class="' . $c['classes']['current'] . '"' : "") . '>' . $i . '</strong>', $i, $connector);
                         $html .= $bucket['step']['anchor'][$i];
                     }
                 }
             }
             $html .= '</span>';
             $bucket['step']['url']['next'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $next) . $qq : false, $next, $connector);
             $bucket['step']['url']['last'] = Filter::apply(array('pager:step.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $chunk) . $qq : false, $chunk, $connector);
             $bucket['step']['anchor']['next'] = Filter::apply(array('pager:step.anchor', 'pager:anchor'), $next ? '<a href="' . $bucket['step']['url']['next'] . '" rel="next">' . $speak->next . '</a>' : '<span>' . $speak->next . '</span>', $next, $connector);
             $bucket['step']['anchor']['last'] = Filter::apply(array('pager:step.anchor', 'pager:anchor'), $next ? '<a href="' . $bucket['step']['url']['last'] . '">' . $speak->last . '</a>' : '<span>' . $speak->last . '</span>', $chunk, $connector);
             $html .= $bucket['step']['anchor']['next'] . $bucket['step']['anchor']['last'];
         }
         $bucket['step']['html'] = Filter::apply('pager:step.html', $html . '</span>');
     }
     if (is_string($current)) {
         for ($i = 0; $i < $total; ++$i) {
             if ($pages[$i] === $current) {
                 $prev = isset($pages[$i - 1]) ? $pages[$i - 1] : false;
                 $next = isset($pages[$i + 1]) ? $pages[$i + 1] : false;
                 // Generate next/previous URL for single page
                 $bucket['prev']['url'] = Filter::apply(array('pager:prev.url', 'pager:url', 'url'), $prev ? $base . sprintf($connector, $prev) . $qq : $base . $q, $prev, $connector);
                 $bucket['next']['url'] = Filter::apply(array('pager:next.url', 'pager:url', 'url'), $next ? $base . sprintf($connector, $next) . $qq : $base . $q, $next, $connector);
                 // Generate next/previous anchor for single page
                 $bucket['prev']['anchor'] = Filter::apply(array('pager:prev.anchor', 'pager:anchor', 'anchor'), $bucket['prev']['url'] !== $base ? '<a href="' . $bucket['prev']['url'] . '" rel="prev">' . $speak->newer . '</a>' : "", $prev, $connector);
                 $bucket['next']['anchor'] = Filter::apply(array('pager:next.anchor', 'pager:anchor', 'anchor'), $bucket['next']['url'] !== $base ? '<a href="' . $bucket['next']['url'] . '" rel="next">' . $speak->older . '</a>' : "", $next, $connector);
                 break;
             }
         }
     }
     return Mecha::O($bucket);
 }
示例#19
0
 *
 */
Config::plug('speak', function ($key = "", $vars = array()) {
    if (!$key) {
        return Config::get('speak');
    }
    if (!is_array($vars)) {
        $vars = array_slice(func_get_args(), 1);
    }
    $speak = Mecha::A(Config::get('speak'));
    if (strpos($key, '.') !== false) {
        $value = Mecha::GVR($speak, $key, $key);
        return vsprintf($value, $vars);
    }
    if (isset($speak[$key])) {
        return !is_array($speak[$key]) ? vsprintf($speak[$key], $vars) : Mecha::O($speak[$key]);
    }
    return $key;
});
/**
 * =============================================================
 *  GET URL DATA
 * =============================================================
 *
 * -- CODE: ----------------------------------------------------
 *
 *    echo Config::url();
 *
 * -------------------------------------------------------------
 *
 *    echo Config::url('path');