function __do_response_reply_count($response)
{
    global $config, $speak, $segment;
    $e = File::E($response->path);
    $replies = count(glob(COMMENT . DS . '*_*_' . Date::slug($response->id) . '.{txt,hold}', GLOB_NOSORT | GLOB_BRACE));
    $t = Jot::icon('reply-all') . ' ' . $replies;
    $tt = array('title' => $replies . ' ' . ($replies === 1 ? $speak->{$segment[0] . '_reply'} : $speak->{$segment[0] . '_replies'}));
    echo ($e === 'hold' || $replies === 0 ? Cell::span($t, $tt) : Cell::a($config->manager->slug . '/' . $segment[0] . '?filter=parent%3A' . $response->id, $t, null, $tt)) . ' · ';
}
Example #2
0
 /**
  * ==========================================================
  *  GET SHIELD PATH BY ITS NAME
  * ==========================================================
  *
  * -- CODE: -------------------------------------------------
  *
  *    echo Shield::path('article');
  *
  * ----------------------------------------------------------
  *
  */
 public static function path($name)
 {
     $name = File::path($name) . '.' . File::E($name, 'php');
     if ($path = File::exist(SHIELD . DS . Config::get('shield') . DS . ltrim($name, DS))) {
         return $path;
     } else {
         if ($path = File::exist(ROOT . DS . ltrim($name, DS))) {
             return $path;
         }
     }
     return $name;
 }
Example #3
0
 /**
  * ==========================================================
  *  GET SHIELD PATH BY ITS NAME
  * ==========================================================
  *
  * -- CODE: -------------------------------------------------
  *
  *    echo Shield::path('article');
  *
  * ----------------------------------------------------------
  *
  */
 public static function path($name, $fallback = false)
 {
     $e = File::E($name, "") !== 'php' ? '.php' : "";
     $name = File::path($name) . $e;
     // Full path, be quick!
     if (strpos($name, ROOT) === 0) {
         return File::exist($name, $fallback);
     }
     if ($path = File::exist(SHIELD . DS . Config::get('shield') . DS . ltrim($name, DS))) {
         return $path;
     } else {
         if ($path = File::exist(CHUNK . DS . ltrim($name, DS))) {
             return $path;
         } else {
             if ($path = File::exist(ROOT . DS . ltrim($name, DS))) {
                 return $path;
             }
         }
     }
     return $fallback;
 }
Example #4
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);
 }
    if (!file_exists(ASSET . DS . '__snippet' . DS . $e . DS . $_file)) {
        continue;
    }
    $_files[] = File::url($_file);
}
?>
      <?php 
if (!empty($_files)) {
    ?>
      <table class="table-bordered table-full-width">
        <tbody>
          <?php 
    foreach ($_files as $_file) {
        ?>
          <?php 
        $e = File::E($_file);
        ?>
          <tr>
            <td><a href="javascript:do_snippet('<?php 
        echo str_replace('.' . $e . X, "", $_file . X);
        ?>
', '<?php 
        echo $e === 'php' ? 'include' : 'print';
        ?>
');" title="<?php 
        echo $speak->shortcode;
        ?>
"><?php 
        echo Jot::icon($e === 'php' ? 'file-code-o' : 'file-o', 'fw') . ' ' . $_file;
        ?>
</a></td>
Example #6
0
 if ($type === 'option' || $type === 'o') {
     $html .= '<label class="grid-group grid-group-option">';
     $html .= '<span class="grid span-2 form-label">' . $title . '</span>';
     $html .= '<span class="grid span-4">';
     $select = isset($field[$key]) ? $field[$key] : "";
     $options = Converter::toArray($value['value'], S, '  ');
     if (isset($value['placeholder']) && trim($value['placeholder']) !== "") {
         $options = array("" => $value['placeholder']) + $options;
     }
     $html .= Form::select('fields[' . $key . '][value]', $options, $select, array('class' => 'select-block'));
     $html .= '</span>';
     $html .= '</label>';
 } else {
     if ($type === 'file' || $type === 'f') {
         $v = isset($value['value']) && $value['value'] !== "" ? $value['value'] : false;
         $vv = isset($field[$key]) && $field[$key] !== "" ? File::E($field[$key]) . DS . File::path($field[$key]) : false;
         $has_file = $vv !== false && file_exists(SUBSTANCE . DS . $vv) && is_file(SUBSTANCE . DS . $vv);
         $html .= '<div class="grid-group grid-group-file' . ($has_file ? ' grid-group-boolean' : "") . '">';
         $html .= !$has_file ? '<span class="grid span-2 form-label">' . $title . '</span>' : '<span class="grid span-2"></span>';
         $html .= '<span class="grid span-4">';
         if (!$has_file) {
             $html .= Form::file($key);
             $e = strtolower(str_replace(' ', "", (string) $v));
             $html .= $v !== false ? Form::hidden('fields[' . $key . '][accept]', $e) . '<br><small><strong>' . $speak->accepted . ':</strong> <code>*.' . str_replace(',', '</code>, <code>*.', $e) . '</code></small>' : "";
         } else {
             $html .= Form::hidden('fields[' . $key . '][value]', $vv);
             $html .= '<span title="' . strip_tags($value['title']) . '">' . Form::checkbox('fields[' . $key . '][remove]', $vv, false, $speak->delete . ' <code>' . $vv . '</code>') . '</span>';
         }
         $html .= '</span>';
         $html .= '</div>';
     } else {
Example #7
0
         // include once ...
     }
 }, 20);
 Weapon::add('SHIPMENT_REGION_BOTTOM', function () use($config) {
     Session::kill('recent_item_update');
     $path = __DIR__ . DS . 'assets' . DS . 'sword' . DS;
     echo Asset::javascript(array($path . 'ajax.js', $path . 'row.js', $path . 'slug.js', $path . 'upload.js', $path . 'tab.js', $path . 'toggle.js', $path . 'modal.js', $path . 'tooltip.js', $path . 'sortable.js', $path . 'accordion.js', SHIELD . DS . $config->shield . DS . 'assets' . DS . 'sword' . DS . 'manager.js'), "", 'sword/manager.min.js');
 }, 1);
 /**
  * Footer Link(s)
  * --------------
  */
 if ($config->page_type === 'manager' || $config->is->post) {
     // Add default comment footer link(s)
     Weapon::add('comment_footer', function ($comment, $article) use($config, $speak) {
         $status = Mecha::alter(File::E($comment->path), array('hold' => Jot::span('info', Jot::icon('clock-o') . ' ' . $speak->pending) . ' &middot; '), "");
         echo $status . Cell::a($config->manager->slug . '/comment/repair/id:' . $comment->id, $speak->edit) . ' / ' . Cell::a($config->manager->slug . '/comment/kill/id:' . $comment->id, $speak->delete);
     }, 20);
 }
 /**
  * Widget Manager Menu(s) and Bar(s)
  * ---------------------------------
  *
  * [1]. Config::merge('manager_menu', array());
  * [2]. Config::merge('manager_bar', array());
  *
  */
 Weapon::add('shield_before', function () {
     $config = Config::get();
     $speak = Config::speak();
     $total = $config->__total_comments;
Example #8
0
 public static function merge($path, $name = null, $addon = "", $call = null)
 {
     $path = is_string($path) && strpos($path, ';') !== false ? explode(';', $path) : (array) $path;
     $the_path = ASSET . DS . File::path($name);
     $the_path_log = SYSTEM . DS . 'log' . DS . 'asset.' . str_replace(array(ASSET . DS, DS), array("", '__'), $the_path) . '.log';
     $is_valid = true;
     if (!file_exists($the_path_log)) {
         $is_valid = false;
     } else {
         $the_path_time = explode("\n", file_get_contents($the_path_log));
         if (count($the_path_time) !== count($path)) {
             $is_valid = false;
         } else {
             foreach ($the_path_time as $i => $time) {
                 $p = self::path($path[$i]);
                 if (!file_exists($p) || (int) filemtime($p) !== (int) $time) {
                     $is_valid = false;
                     break;
                 }
             }
         }
     }
     $time = "";
     $content = "";
     $e = File::E($name);
     if (!file_exists($the_path) || !$is_valid) {
         if (Text::check($e)->in(array('gif', 'jpeg', 'jpg', 'png'))) {
             foreach ($path as $p) {
                 if (!self::ignored($p)) {
                     $p = self::path($p);
                     if (file_exists($p)) {
                         $time .= filemtime($p) . "\n";
                     }
                 }
             }
             File::write(trim($time))->saveTo($the_path_log);
             Image::take($path)->merge()->saveTo($the_path);
         } else {
             foreach ($path as $p) {
                 if (!self::ignored($p)) {
                     $p = self::path($p);
                     if (file_exists($p)) {
                         $time .= filemtime($p) . "\n";
                         $c = file_get_contents($p);
                         if (strpos(File::B($p), '.min.') === false) {
                             if (strpos(File::B($the_path), '.min.css') !== false) {
                                 $content .= Converter::detractShell($c) . "\n";
                             } else {
                                 if (strpos(File::B($the_path), '.min.js') !== false) {
                                     $content .= Converter::detractSword($c) . "\n";
                                 } else {
                                     $content .= $c . "\n\n";
                                 }
                             }
                         } else {
                             $content .= $c . "\n\n";
                         }
                     }
                 }
             }
             File::write(trim($time))->saveTo($the_path_log);
             File::write(trim($content))->saveTo($the_path);
         }
     }
     if (is_null($call)) {
         $call = Mecha::alter($e, array('css' => 'stylesheet', 'js' => 'javascript', 'gif' => 'image', 'jpeg' => 'image', 'jpg' => 'image', 'png' => 'image'));
     }
     return call_user_func_array('self::' . $call, array($the_path, $addon));
 }
Example #9
0
            $P = array('data' => $request);
            if (!Notify::errors()) {
                if (Request::post('content')) {
                    File::open($file)->write($request['content'])->save();
                }
                File::open($file)->moveTo(ASSET . DS . $new);
                Notify::success(Config::speak('notify_' . (is_dir(ASSET . DS . $old) ? 'folder' : 'file') . '_updated', '<code>' . File::B($old) . '</code>'));
                $new = explode(DS, $new);
                Session::set('recent_file_update', $new[0]);
                Weapon::fire('on_asset_update', array($P, $P));
                Weapon::fire('on_asset_repair', array($P, $P));
                Guardian::kick($config->manager->slug . '/asset/1' . $p);
            }
        }
    }
    Shield::lot(array('segment' => 'asset', 'the_name' => $old, 'the_content' => is_file(ASSET . DS . $old) && strpos(',' . SCRIPT_EXT . ',', ',' . File::E($old) . ',') !== false ? File::open(ASSET . DS . $old)->read() : false))->attach('manager', false);
});
/**
 * Asset Killer
 * ------------
 */
Route::accept($config->manager->slug . '/asset/kill/(file|files):(:all)', function ($path = "", $name = "") use($config, $speak) {
    if (Guardian::get('status') !== 'pilot') {
        Shield::abort();
    }
    $name = File::path($name);
    $p = Request::get('path');
    $p = $p ? '?path=' . urlencode($p) : "";
    if (strpos($name, ';') !== false) {
        $deletes = explode(';', $name);
    } else {
Example #10
0
 /**
  * ====================================================================
  *  SAVE THE IMAGE TO ANOTHER PLACE
  * ====================================================================
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter    | Type   | Description
  *  ------------ | ------ | -------------------------------------------
  *  $destination | string | Path to image file or directory
  *  ------------ | ------ | -------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function saveTo($destination)
 {
     if (is_dir($destination)) {
         $destination .= DS . File::B(self::$original);
     }
     $old_extension = File::E(self::$original);
     $new_extension = File::E($destination);
     if ($old_extension !== $new_extension) {
         self::gen();
         self::twin(null, $new_extension);
     }
     File::open(self::$placeholder)->moveTo($destination);
     imagedestroy(self::$GD);
 }
Example #11
0
        echo Session::get('recent_file_update') === File::B($file->path) ? ' class="active"' : "";
        ?>
>
      <td class="td-icon"><?php 
        echo Form::checkbox('selected[]', $url);
        ?>
</td>
      <td class="td-collapse"><time datetime="<?php 
        echo Date::format($file->update_raw, 'c');
        ?>
"><?php 
        echo str_replace('-', '/', $file->update);
        ?>
</time></td>
      <?php 
        $n = Jot::icon(is_file($file->path) ? 'file-' . Mecha::alter(File::E($file->path), array('xls' => 'excel-o', 'xlsx' => 'excel-o', 'doc' => 'word-o', 'docx' => 'word-o', 'ppt' => 'powerpoint-o', 'pptx' => 'powerpoint-o', 'pdf' => 'pdf-o', 'gz' => 'archive-o', 'iso' => 'archive-o', 'rar' => 'archive-o', 'tar' => 'archive-o', 'zip' => 'archive-o', 'zipx' => 'archive-o', 'bmp' => 'image-o', 'gif' => 'image-o', 'ico' => 'image-o', 'jpeg' => 'image-o', 'jpg' => 'image-o', 'png' => 'image-o', 'txt' => 'text-o', 'log' => 'text-o', 'mp3' => 'audio-o', 'ogg' => 'audio-o', 'wav' => 'audio-o', 'mkv' => 'video-o', 'flv' => 'video-o', 'avi' => 'video-o', 'mov' => 'video-o', 'mp4' => 'video-o', '3gp' => 'video-o', 'css' => 'code-o', 'js' => 'code-o', 'json' => 'code-o', 'jsonp' => 'code-o', 'htm' => 'code-o', 'html' => 'code-o', 'php' => 'code-o', 'xml' => 'code-o'), 'o') : 'folder') . ' ' . File::B($url);
        ?>
      <td>
        <?php 
        if (is_dir($file->path)) {
            ?>
        <a href="<?php 
            echo $config->url . '/' . $c_url . '/1?path=' . Text::parse(ltrim($q_path . '/' . File::B($url), '/'), '->encoded_url');
            ?>
" title="<?php 
            echo $speak->enter;
            ?>
&hellip;"><?php 
            echo $n;
            ?>
</a>
Example #12
0
 public static function merge($path, $name = null, $addon = "", $call = null)
 {
     $the_path = strpos($name, ROOT) === 0 ? File::path($name) : ASSET . DS . File::path($name);
     $the_log = LOG . DS . 'asset.' . str_replace(array(ASSET . DS, DS), array("", '__'), $the_path) . '.log';
     $is_valid = true;
     if (!file_exists($the_log)) {
         $is_valid = false;
     } else {
         $the_time = explode("\n", file_get_contents($the_log));
         if (count($the_time) !== count($path)) {
             $is_valid = false;
         } else {
             foreach ($the_time as $i => $unix) {
                 $p = self::path($path[$i]);
                 if (!file_exists($p) || (int) filemtime($p) !== (int) $unix) {
                     $is_valid = false;
                     break;
                 }
             }
         }
     }
     $unix = "";
     $content = "";
     $e = File::E($name);
     if (!file_exists($the_path) || !$is_valid) {
         if (Text::check($e)->in(array('gif', 'jpeg', 'jpg', 'png'))) {
             foreach ($path as &$p) {
                 $p = Filter::colon('asset:source', $p);
                 if (!self::ignored($p) && ($p = Filter::colon('asset:path', self::path($p, false)))) {
                     $unix .= filemtime($p) . "\n";
                 }
             }
             File::write(trim($unix))->saveTo($the_log);
             Image::take($path)->merge()->saveTo($the_path);
         } else {
             foreach ($path as $p) {
                 $p = Filter::colon('asset:source', $p);
                 if (!self::ignored($p) && ($p = Filter::colon('asset:path', self::path($p, false)))) {
                     $unix .= filemtime($p) . "\n";
                     $c = Filter::apply('asset:input', file_get_contents($p) . "\n", $p);
                     if (strpos(File::B($p), '.min.') === false) {
                         if (strpos(File::B($the_path), '.min.css') !== false) {
                             $c = Converter::detractShell($c);
                         } else {
                             if (strpos(File::B($the_path), '.min.js') !== false) {
                                 $c = Converter::detractSword($c);
                             } else {
                                 $c = $c . "\n";
                             }
                         }
                         $content .= Filter::apply('asset:output', $c, $p);
                     } else {
                         $content .= Filter::apply('asset:output', $c . "\n", $p);
                     }
                 }
             }
             File::write(trim($unix))->saveTo($the_log);
             File::write(trim($content))->saveTo($the_path);
         }
     }
     if (is_null($call)) {
         $call = Mecha::alter($e, array('css' => 'stylesheet', 'js' => 'javascript', 'gif' => 'image', 'jpeg' => 'image', 'jpg' => 'image', 'png' => 'image'));
     }
     return call_user_func('self::' . $call, $the_path, $addon);
 }
<?php

// 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);
    if (!File::exist($htaccess)) {
        File::write('deny from all')->saveTo($htaccess, 0600);
    }
    Config::set(array('page_title' => $speak->snippets . $config->title_separator . $config->manager->title, 'cargo' => __DIR__ . DS . 'cargo.snippet.php'));
    Shield::lot(array('segment' => 'snippet'))->attach('manager');
});
Route::post($config->manager->slug . '/snippet/ignite', function () use($config, $speak) {
    $request = Request::post();
    $id = time();
    Guardian::checkToken($request['token']);
    if (trim($request['name']) === "") {
        $request['name'] = $id . '.txt';
        // empty file name
    }
    $_path = Text::parse(sprintf($request['name'], $id), '->safe_path_name');
    $e = File::E($_path, false);
    if ($e !== 'txt' && $e !== 'php') {
        $e = 'txt';
        $_path .= '.txt';
    }
    $_path_ = File::path($_path);
    $file = ASSET . DS . '__snippet' . DS . $e . DS . $_path;
    if (File::exist($file)) {
        // file already exists
        Notify::error(Config::speak('notify_file_exist', '<code>' . $_path_ . '</code>'));
    }
    if (trim($request['content']) === "") {
        // empty file content
        Notify::error($speak->notify_error_content_empty);
    }
    if (!Notify::errors()) {
<?php

$name = $_FILES['file']['name'];
$mime = $_FILES['file']['type'];
$extension = File::E($name);
$mime_accept = array('application/download', 'application/octet-stream', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip');
$extension_accept = array('zip');
$path = File::N($name);
if (!empty($name)) {
    if (File::exist($destination . DS . $path)) {
        Notify::error(Config::speak('notify_folder_exist', '<code>' . $path . '</code>'));
    } else {
        if (!Mecha::walk($mime_accept)->has($mime) || !Mecha::walk($extension_accept)->has($extension)) {
            Notify::error(Config::speak('notify_invalid_file_extension', 'ZIP'));
        }
    }
} else {
    Notify::error($speak->notify_error_no_file_selected);
}
Example #16
0
     }
     $content = File::open($_file)->read();
     $title = $speak->editing . ': ' . File::B($file) . $config->title_separator . $config->manager->title;
 }
 $G = array('data' => array('path' => $_file, 'name' => $path, 'content' => $content));
 Config::set(array('page_title' => $title, 'cargo' => 'repair.shield.php'));
 if ($request = Request::post()) {
     Guardian::checkToken($request['token']);
     $name = Text::parse(File::path($request['name']), '->safe_path_name');
     if (trim($request['name']) === "") {
         Notify::error(Config::speak('notify_error_empty_field', $speak->name));
     } else {
         if ($path !== $name && File::exist($_folder . DS . $name)) {
             Notify::error(Config::speak('notify_file_exist', '<code>' . $name . '</code>'));
         }
         if (($e = File::E($name)) !== "") {
             if (strpos(',' . SCRIPT_EXT . ',', ',' . $e . ',') === false) {
                 Notify::error(Config::speak('notify_error_file_extension', $e));
             }
         } else {
             // Missing file extension
             Notify::error($speak->notify_error_file_extension_missing);
         }
     }
     $P = array('data' => $request);
     if (!Notify::errors()) {
         $s = $_file !== false ? $_file : $_folder . DS . $name;
         File::write($request['content'])->saveTo($s);
         if ($path !== false && $path !== $name) {
             File::open($s)->moveTo($_folder . DS . $name);
         }
Example #17
0
 * Footer Link(s)
 * --------------
 */
// Add default article footer link(s)
Weapon::add('article_footer', function ($article) use($config, $speak) {
    $e = File::E($article->path);
    $comments = count(glob(COMMENT . DS . Date::slug($article->id) . '_*_*.{txt,hold}', GLOB_NOSORT | GLOB_BRACE));
    $t = Jot::icon('comments') . ' ' . $comments;
    $tt = array('title' => $comments . ' ' . ($comments === 1 ? $speak->comment : $speak->comments));
    $comments = ($e === 'draft' || $comments === 0 ? Cell::span($t, $tt) : Cell::a($config->manager->slug . '/comment?filter=post%3A' . $article->id, $t, null, $tt)) . ' &middot; ';
    $status = Mecha::alter($e, array('draft' => Jot::span('info', Jot::icon('clock-o') . ' ' . $speak->draft) . ' &middot; ', 'archive' => Jot::span('info', Jot::icon('history') . ' ' . $speak->archive) . ' &middot; '), "");
    echo $comments . $status . Cell::a($config->manager->slug . '/article/repair/id:' . $article->id, $speak->edit) . ' / ' . Cell::a($config->manager->slug . '/article/kill/id:' . $article->id, $speak->delete);
}, 20);
// Add default page footer link(s)
Weapon::add('page_footer', function ($page) use($config, $speak) {
    $status = Mecha::alter(File::E($page->path), array('draft' => Jot::span('info', Jot::icon('clock-o') . ' ' . $speak->draft) . ' &middot; ', 'archive' => Jot::span('info', Jot::icon('history') . ' ' . $speak->archive) . ' &middot; '), "");
    echo $status . Cell::a($config->manager->slug . '/page/repair/id:' . $page->id, $speak->edit) . ' / ' . Cell::a($config->manager->slug . '/page/kill/id:' . $page->id, $speak->delete);
}, 20);
/**
 * Backend Route(s)
 * ----------------
 *
 * Load the routes.
 *
 */
Weapon::add('plugins_after', function () use($config, $speak, $segment) {
    // loading cargo ...
    require __DIR__ . DS . 'workers' . DS . 'cargo.php';
    if ($detour = File::exist(__DIR__ . DS . 'workers' . DS . 'route.' . $segment . '.php')) {
        require $detour;
    }
Example #18
0
<?php

foreach ($field as $k => $v) {
    $f = $v['type'] === 'file' || $v['type'] === 'f';
    // Remove asset field value and data
    if (isset($v['remove']) && $f) {
        File::open(SUBSTANCE . DS . $v['remove'])->delete();
        Weapon::fire(array('on_substance_update', 'on_substance_destruct'), array($G, $P));
        Notify::success(Config::speak('notify_file_deleted', '<code>' . $v['remove'] . '</code>'));
        unset($field[$k]);
    }
    // Remove empty field value
    if (!isset($v['value']) || $v['value'] === "") {
        unset($field[$k]);
    } else {
        $e = File::E($v['value']);
        if (!file_exists(SUBSTANCE . DS . $e . DS . $v['value']) && $f) {
            unset($field[$k]);
        } else {
            $field[$k] = $v['value'];
        }
    }
}
Example #19
0
 private static function __fields(&$results, $FP)
 {
     // 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(null, array(), true, rtrim($FP, ':'));
     foreach ($fields as $k => $v) {
         $s = isset($results['fields'][$k]) && trim($results['fields'][$k]) !== "" ? $results['fields'][$k] : "";
         if ($s === "") {
             // For `option` field type, the first option will be used as the default value
             if ($v['type'] === 'option' || $v['type'] === 'o') {
                 $vv = array_keys(Converter::toArray($v['value']));
                 if (isset($v['placeholder']) && trim($v['placeholder']) !== "") {
                     // do nothing ...
                 } else {
                     $s = isset($vv[0]) ? $vv[0] : "";
                 }
                 // For `boolean` field type, empty value is equal to `false`
             } else {
                 if ($v['type'] === 'boolean' || $v['type'] === 'b') {
                     $s = false;
                 }
             }
         } else {
             // For `file` field type, the original custom field value is used to limit the file extension
             // So we have to check the existence of the file first. If it does not exist, then it may be
             // contained with the file extension(s), not with a file name
             if ($v['type'] === 'file' || $v['type'] === 'f') {
                 $e = File::E($s, false);
                 $s = $e !== false ? File::exist(SUBSTANCE . DS . $e . DS . $s, "") : "";
             }
         }
         $results['fields'][$k] = $s;
     }
     unset($fields, $s);
 }
Example #20
0
<?php

$hooks = array($page, $segment);
echo $messages;
?>
<form class="form-repair form-cache" id="form-repair" action="<?php 
echo $config->url_current . $config->url_query;
?>
" method="post">
  <?php 
echo Form::hidden('token', $token);
?>
  <?php 
$e = File::E($path !== false ? $path : "");
$is_text = $path === false || strpos(',' . SCRIPT_EXT . ',', ',' . $e . ',') !== false;
$path = File::url($path);
?>
  <?php 
if ($is_text && $content !== false) {
    ?>
  <p>
  <?php 
    echo Form::textarea('content', Request::get('content', Guardian::wayback('content', $content)), $speak->manager->placeholder_content, array('class' => array('textarea-block', 'textarea-expand', 'code')));
    ?>
  </p>
  <?php 
}
?>
  <p>
    <?php 
echo Form::hidden('name', $path);
Example #21
0
<?php

$e = File::E(!is_null($the_name) ? $the_name : "");
$is_text = is_null($the_name) || strpos(',' . SCRIPT_EXT . ',', ',' . $e . ',') !== false;
if ($is_text && $the_content !== false) {
    ?>
<p>
<?php 
    echo Form::textarea('content', Guardian::wayback('content', $the_content), $speak->manager->placeholder_content, array('class' => array('textarea-block', 'textarea-expand', 'code')));
    ?>
</p>
<?php 
}
?>
<p>
  <?php 
if ($e === 'cache') {
    ?>
  <?php 
    echo Form::hidden('name', File::url($the_name));
    ?>
  <?php 
} else {
    ?>
  <?php 
    echo Form::text('name', Guardian::wayback('name', File::url($the_name)), $speak->manager->placeholder_file_name);
    ?>
  <?php 
}
?>
  <?php 
Example #22
0
 *
 * [1]. article/article-slug
 *
 */
Route::accept($config->index->slug . '/(:any)', function ($slug = "") use($config, $speak) {
    if (!($article = Get::article($slug))) {
        Shield::abort('404-article');
    }
    if ($article->state === 'drafted') {
        Shield::abort('404-article');
    }
    if (isset($_GET['repair']) && Guardian::happy()) {
        Guardian::kick($config->manager->slug . '/article/repair/id:' . $article->id);
    }
    // Collecting article slug ...
    if ($articles = Get::articles('DESC', "", File::E($article->path))) {
        $articles = Mecha::walk($articles, function ($path) {
            $parts = explode('_', File::N($path), 3);
            return $parts[2];
        });
    }
    Filter::add('pager:url', function ($url) {
        return Filter::apply('article:url', $url);
    });
    Config::set(array('page_title' => $article->title . $config->title_separator . $config->title, 'article' => $article, 'pagination' => Navigator::extract($articles, $slug, 1, $config->index->slug)));
    Weapon::add('shell_after', function () use($article) {
        if (isset($article->css) && trim($article->css) !== "") {
            echo O_BEGIN . $article->css . O_END;
        }
    });
    Weapon::add('sword_after', function () use($article) {
Example #23
0
 foreach ($units as $k => $v) {
     Weapon::add('tab_content_2_before', function ($page, $segment) use($config, $speak, $v) {
         include __DIR__ . DS . 'unit' . DS . 'form' . DS . $v . '.php';
     }, $k + 1);
 }
 Weapon::add('tab_content_3_before', function ($page, $segment) use($config, $speak) {
     include __DIR__ . DS . 'unit' . DS . 'form' . DS . 'fields[].php';
 }, 1);
 // Ignite
 if (strpos($config->url_path, '/id:') === false) {
     Weapon::add('SHIPMENT_REGION_BOTTOM', function () {
         echo '<script>(function($){$.slug(\'title\',\'slug\',\'-\')})(DASHBOARD.$);</script>';
     }, 11);
 }
 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;
Example #24
0
     Shield::abort();
     // File not found!
 }
 $content = File::open($file)->read();
 $G = array('data' => array('path' => $file, 'name' => $path, 'content' => $content));
 Config::set(array('page_title' => $speak->editing . ': ' . File::B($path) . $config->title_separator . $config->manager->title, 'cargo' => DECK . DS . 'workers' . DS . 'repair.shield.php'));
 if ($request = Request::post()) {
     Guardian::checkToken($request['token']);
     $name = File::path($request['name']);
     if (!Request::post('name')) {
         Notify::error(Config::speak('notify_error_empty_field', $speak->name));
     } else {
         if ($path !== $name && File::exist(SHIELD . DS . $folder . DS . $name)) {
             Notify::error(Config::speak('notify_file_exist', '<code>' . $name . '</code>'));
         }
         if (($extension = File::E($name)) !== "") {
             if (strpos(',' . SCRIPT_EXT . ',', ',' . $extension . ',') === false) {
                 Notify::error(Config::speak('notify_error_file_extension', $extension));
             }
         } else {
             // Missing file extension
             Notify::error($speak->notify_error_file_extension_missing);
         }
     }
     $P = array('data' => $request);
     if (!Notify::errors()) {
         File::open($file)->write($request['content'])->save();
         if ($path !== $name) {
             File::open($file)->moveTo(SHIELD . DS . $folder . DS . $name);
         }
         Notify::success(Config::speak('notify_file_updated', '<code>' . File::B($path) . '</code>'));
function do_snippet($content)
{
    global $config, $speak;
    if (strpos($content, '{{') === false) {
        return $content;
    }
    $content = function_exists('do_shortcode_x') ? do_shortcode_x($content) : $content;
    // plain text: `{{print:foo}}`
    if (strpos($content, '{{print:') !== false || strpos($content, '{{print=') !== false) {
        $content = preg_replace_callback('#\\{\\{print[:=](.*?)\\}\\}#', function ($matches) {
            $content = $matches[0];
            $e = File::E($matches[1], false);
            if ($e !== 'txt' && $e !== 'php') {
                $e = 'txt';
                $matches[1] .= '.txt';
            }
            if ($snippet = File::exist(ASSET . DS . '__snippet' . DS . $e . DS . $matches[1])) {
                return File::open($snippet)->read();
            }
            return $content;
        }, $content);
    }
    // plain text with wildcard(s): `{{print path="foo" lot="bar,baz,qux"}}`
    if (strpos($content, '{{print ') !== false) {
        $content = preg_replace_callback('#\\{\\{print\\s+(.*?)\\}\\}#', function ($matches) {
            $content = $matches[0];
            $data = Converter::attr($content, array('{{', '}}', ' '), array('"', '"', '='));
            $attr = (array) $data['attributes'];
            if (!isset($attr['path'])) {
                return $matches[0];
            }
            $e = File::E($attr['path'], false);
            if ($e !== 'txt' && $e !== 'php') {
                $e = 'txt';
                $attr['path'] .= '.txt';
            }
            if (!($snippet = File::exist(ASSET . DS . '__snippet' . DS . $e . DS . $attr['path']))) {
                return $matches[0];
            }
            $content = File::open($snippet)->read();
            if (isset($attr['lot']) && strpos($content, '%') !== false) {
                // `http://stackoverflow.com/a/2053931`
                if (preg_match_all('#%(?:(\\d+)[$])?[-+]?(?:[ 0]|[\'].)?(?:[-]?\\d+)?(?:[.]\\d+)?[%bcdeEfFgGosuxX]#', $content, $matches)) {
                    $lot = Mecha::walk(explode(',', $attr['lot']), function ($v) {
                        return str_replace('&#44;', ',', $v);
                    });
                    if (count($lot) >= count(array_unique($matches[1]))) {
                        $content = vsprintf($content, $lot);
                    }
                }
            }
            return $content;
        }, $content);
    }
    // executable code: `{{include:foo}}`
    if (strpos($content, '{{include:') !== false || strpos($content, '{{include=') !== false) {
        $content = preg_replace_callback('#\\{\\{include[:=](.*?)\\}\\}#', function ($matches) {
            $content = $matches[0];
            $e = File::E($matches[1], false);
            if ($e !== 'php') {
                $e = 'php';
                $matches[1] .= '.php';
            }
            if ($snippet = File::exist(ASSET . DS . '__snippet' . DS . $e . DS . $matches[1])) {
                ob_start();
                include $snippet;
                $content = ob_get_clean();
            }
            return $content;
        }, $content);
    }
    // executable code with variable(s): `{{include path="foo" lot="bar,baz,qux" another_var="1"}}`
    if (strpos($content, '{{include ') !== false) {
        $content = preg_replace_callback('#\\{\\{include\\s+(.*?)\\}\\}#', function ($matches) {
            $content = $matches[0];
            $data = Converter::attr($content, array('{{', '}}', ' '), array('"', '"', '='));
            $attr = (array) $data['attributes'];
            if (!isset($attr['path'])) {
                return $matches[0];
            }
            $e = File::E($attr['path'], false);
            if ($e !== 'php') {
                $e = 'php';
                $attr['path'] .= '.php';
            }
            if ($snippet = File::exist(ASSET . DS . '__snippet' . DS . $e . DS . $attr['path'])) {
                ob_start();
                if (isset($attr['lot'])) {
                    $lot = Mecha::walk(explode(',', str_replace('\\,', '&#44;', $attr['lot'])), function ($v) {
                        return Converter::strEval(str_replace('&#44;', ',', $v));
                    });
                } else {
                    $lot = array();
                }
                unset($attr['path'], $attr['lot']);
                extract($attr);
                include $snippet;
                $content = ob_get_clean();
            }
            return $content;
        }, $content);
    }
    return $content;
}