Example #1
0
 /**
  * ==========================================================================
  *  GET PAGE PATH
  * ==========================================================================
  *
  * -- CODE: -----------------------------------------------------------------
  *
  *    var_dump(Get::pagePath('lorem-ipsum'));
  *
  * --------------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type  | Description
  *  --------- | ----- | -----------------------------------------------------
  *  $detector | mixed | Slug, ID or time of the page
  *  --------- | ----- | -----------------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function pagePath($detector, $folder = PAGE)
 {
     foreach (glob($folder . DS . '*.{txt,draft,archive}', GLOB_NOSORT | GLOB_BRACE) as $path) {
         list($time, $kind, $slug) = explode('_', File::N($path), 3);
         if ($slug === $detector || (string) $time === Date::format($detector, 'Y-m-d-H-i-s')) {
             return $path;
         }
     }
     return false;
 }
Example #2
0
<?php

if ($responses = call_user_func('Get::' . $segment[0] . 's', 'DESC', 'post:' . Date::slug(Request::get('post', $page->post)))) {
    ?>
<div class="grid-group">
  <span class="grid span-1 form-label"><?php 
    echo $speak->parent;
    ?>
</span>
  <span class="grid span-5">
  <?php 
    if (count($responses) > 600) {
        // 600+ response(s), fallback to text input for performance reason
        $_parent = call_user_func('Get::' . $segment[0], $page->parent, array('message', 'message_raw'));
        echo Form::text('parent', Request::get('parent', Guardian::wayback('parent', $page->parent)), time());
        echo $_parent ? ' ' . Jot::btn('action:external-link', "", $_parent->permalink, array('title' => $_parent->name, 'target' => '_blank')) : "";
    } else {
        $results = array();
        $s = Date::slug($page->id);
        foreach ($responses as $v) {
            list($_post, $_time, $_parent) = explode('_', File::N($v), 3);
            $results[($s === $_time ? '.' : "") . Date::format($_time, 'U')] = Date::extract($_time, 'FORMAT_3');
        }
        krsort($results);
        echo Form::select('parent', array("" => '&mdash; ' . $speak->none . ' &mdash;') + $results, Request::get('parent', Guardian::wayback('parent', $page->parent)));
    }
    ?>
  </span>
</div>
<?php 
}
 function do_response_reply_x($post)
 {
     global $config, $speak, $parent;
     $s = Asset::loaded($config->protocol . ICON_LIBRARY_PATH) ? '<i class="fa fa-times-circle"></i> ' : "";
     echo '&#32;<a href="' . $post->url . '" class="btn btn-reject btn-reject-reply"' . ($parent === false ? ' style="display:none;"' : "") . '>' . $s . $speak->cancel . '</a>';
 }
 Weapon::add('comment_footer', 'do_response_reply', 20.1);
 Weapon::add('comment_form_button_after', 'do_response_reply_x');
 Weapon::add('shell_before', 'do_response_reply_css');
 Weapon::add('SHIPMENT_REGION_BOTTOM', 'do_response_reply_js');
 // No JavaScript
 if ($parent !== false) {
     Guardian::memorize('parent', $parent);
     if ($response = Get::commentAnchor($parent)) {
         Weapon::add('chunk_before', function ($G) use($speak, $parent, $response) {
             if (File::N($G['data']['path']) === 'comment.form') {
                 $prefix = File::B(File::D($response->path));
                 $to = Config::speak($prefix . '_reply_to_', Cell::a('#' . $prefix . '-' . $parent, $response->name));
                 echo Cell::h4($to);
             }
         });
     }
 }
 // Error
 if ($s = Request::post('parent', false)) {
     Filter::add('guardian:kick', function ($url) use($config, $s) {
         if (!Notify::errors()) {
             return $url;
         }
         $ss = explode('#', $url, 2);
         return $config->url_current . HTTP::query('reply', $s) . '#' . $ss[1];
Example #4
0
<?php

$bucket = array();
if ($config->total_pages > 0) {
    foreach (Get::pages() as $page) {
        list($time, $kind, $slug) = explode('_', File::N($page), 3);
        $bucket[] = (object) array('url' => $config->url . '/' . $slug, 'date' => Date::format($time, 'c'), 'changefreq' => 'weekly', 'priority' => (string) '0.5');
    }
}
if ($config->total_articles > 0) {
    foreach (Get::articles() as $article) {
        list($time, $kind, $slug) = explode('_', File::N($article), 3);
        $bucket[] = (object) array('url' => $config->url . '/' . $config->index->slug . '/' . $slug, 'date' => Date::format($time, 'c'), 'changefreq' => 'weekly', 'priority' => (string) '1.0');
    }
}
echo '<?xml version="1.0" encoding="UTF-8" ?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
if (!empty($bucket)) {
    foreach ($bucket as $i => $item) {
        echo '<url>';
        echo '<loc>' . $item->url . '</loc>';
        echo '<lastmod>' . $item->date . '</lastmod>';
        echo '<changefreq>' . $item->changefreq . '</changefreq>';
        echo '<priority>' . $item->priority . '</priority>';
        Weapon::fire('sitemap_item', array($item, $i));
        echo '</url>';
    }
}
echo '</urlset>';
Example #5
0
 *
 */
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) {
        if (isset($article->js) && trim($article->js) !== "") {
            echo O_BEGIN . $article->js . O_END;
Example #6
0
 *
 */
Route::accept($config->index->slug . '/(:any)', function ($slug = "") use($config, $speak) {
    if (!($article = Get::article($slug))) {
        Shield::abort('404-article');
    }
    if (isset($_GET['repair']) && Guardian::happy()) {
        Guardian::kick($config->manager->slug . '/article/repair/id:' . $article->id);
    }
    if ($article->state === 'draft') {
        Shield::abort('404-article');
    }
    // Collecting article slug ...
    if ($articles = Get::articles('DESC', "", File::E($article->path))) {
        foreach ($articles as &$v) {
            $parts = explode('_', File::N($v), 3);
            $v = $parts[2];
        }
        unset($parts, $v);
    }
    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) {
        if (isset($article->js) && trim($article->js) !== "") {
            echo O_BEGIN . $article->js . O_END;
        }
    });
Example #7
0
 /**
  * ====================================================================
  *  EXTRACTING
  * ====================================================================
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter    | Type   | Description
  *  ------------ | ------ | -------------------------------------------
  *  $destination | string | Path to a package file
  *  $bucket      | string | Load the extracted file(s) into this folder
  *  ------------ | ------ | -------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function extractTo($destination, $bucket = false)
 {
     if (is_null($destination)) {
         $destination = File::D(self::$open);
     } else {
         $destination = rtrim(File::path($destination), DS);
     }
     // Handling for `Package::take('file.zip')->extractTo('foo/bar', true)`
     if ($bucket === true) {
         $bucket = File::N(self::$open);
     }
     if ($bucket !== false && !File::exist($destination . DS . $bucket)) {
         $bucket = File::path($bucket);
         mkdir($destination . DS . $bucket, 0777, true);
     }
     if (self::$zip->open(self::$open) === true) {
         if ($bucket !== false) {
             self::$zip->extractTo($destination . DS . $bucket);
         } else {
             self::$zip->extractTo($destination);
         }
         self::$zip->close();
     }
     return new static();
 }
Example #8
0
 /**
  * ==========================================================
  *  RENDER A PAGE
  * ==========================================================
  *
  * -- CODE: -------------------------------------------------
  *
  *    Shield::attach('article');
  *
  * ----------------------------------------------------------
  *
  */
 public static function attach($name, $fallback = false, $buffer = true)
 {
     $path__ = File::path($name);
     $s = explode('-', File::N($name), 2);
     $G = array('data' => array('name' => $name, 'name_base' => $s[0]));
     if (strpos($path__, ROOT) === 0 && file_exists($path__) && is_file($path__)) {
         // do nothing ...
     } else {
         if ($_path = File::exist(self::path($path__, $fallback))) {
             $path__ = $_path;
         } else {
             if ($_path = File::exist(self::path($s[0], $fallback))) {
                 $path__ = $_path;
             } else {
                 Guardian::abort(Config::speak('notify_file_not_exist', '<code>' . $path__ . '</code>'));
             }
         }
     }
     $lot__ = self::cargo();
     $path__ = Filter::apply('shield:path', $path__);
     $G['data']['lot'] = $lot__;
     $G['data']['path'] = $path__;
     $G['data']['path_base'] = $s[0];
     $out = "";
     // Begin shield
     Weapon::fire('shield_lot_before', array($G, $G));
     extract(Filter::apply('shield:lot', $lot__));
     Weapon::fire('shield_lot_after', array($G, $G));
     Weapon::fire('shield_before', array($G, $G));
     if ($buffer) {
         ob_start(function ($content) use($path__, &$out) {
             $content = Filter::apply('shield:input', $content, $path__);
             $out = Filter::apply('shield:output', $content, $path__);
             return $out;
         });
         require $path__;
         ob_end_flush();
     } else {
         require $path__;
     }
     $G['data']['content'] = $out;
     // Reset shield lot
     self::$lot = array();
     // End shield
     Weapon::fire('shield_after', array($G, $G));
     exit;
 }
<?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 #10
0
<?php

/**
 * Custom Function(s)
 * ------------------
 *
 * Add your own custom function(s) here. You can do something like
 * making custom widget(s), custom route(s), custom filter(s),
 * custom weapon(s), loading custom asset(s), etc. So that you can
 * manipulate the site output without having to touch the CMS core.
 *
 */
// HTML output manipulation
Filter::add('chunk:output', function ($content, $path) use($config, $speak) {
    $name = File::N($path);
    // Add an icon to the log in form button
    if ($name === 'page.body' && Route::is($config->manager->slug . '/login')) {
        return str_replace('>' . $speak->login . '</button>', '><i class="fa fa-key"></i> ' . trim(strip_tags($speak->login)) . '</button>', $content);
    }
    // Add an icon to the older and newer link text
    if ($name === 'pager') {
        $content = str_replace('>' . $speak->newer . '</a>', '><i class="fa fa-angle-left"></i> ' . trim(strip_tags($speak->newer)) . '</a>', $content);
        $content = str_replace('>' . $speak->older . '</a>', '>' . trim(strip_tags($speak->older)) . ' <i class="fa fa-angle-right"></i></a>', $content);
    }
    // Add an icon to the article date
    if ($name === 'article.time') {
        $content = str_replace('<time ', '<i class="fa fa-calendar"></i> <time ', $content);
    }
    // Add an icon to the comments title
    if ($name === 'comments.header') {
        $content = str_replace('<h3>', '<h3><i class="fa fa-comments"></i> ', $content);
Example #11
0
 /**
  * Widget Archive
  * --------------
  *
  * [1]. Widget::archive('HIERARCHY');
  * [2]. Widget::archive('HIERARCHY', 'ASC');
  *
  */
 public static function archive($type = 'HIERARCHY', $sort = 'DESC', $folder = ARTICLE)
 {
     $T1 = TAB;
     $T2 = str_repeat($T1, 2);
     $T3 = str_repeat($T1, 3);
     $T4 = str_repeat($T1, 4);
     $kin = strtolower($type);
     $p = $folder !== POST ? File::B($folder) : 'post';
     $id = Config::get('widget_archive_' . $kin . '_id', 0) + 1;
     $config = Config::get();
     $speak = Config::speak();
     $query = $config->archive_query;
     $month_names = (array) $speak->month_names;
     $archives = array();
     $html = O_BEGIN . '<div class="widget widget-archive widget-archive-' . $kin . '" id="widget-archive-' . $kin . '-' . $id . '">' . NL;
     if ($files = call_user_func('Get::' . $p . 's', $sort)) {
         if ($type === 'HIERARCHY') {
             $i = 0;
             foreach ($files as $file) {
                 list($year, $month) = explode('-', File::N($file));
                 $archives[$year][$month][] = $file;
             }
             $html .= $T1 . '<ul>' . NL;
             foreach ($archives as $year => $months) {
                 if (is_array($months)) {
                     $posts_count_per_year = 0;
                     $s = explode('-', $query);
                     $expand = $query ? (int) $s[0] === (int) $year : $i === 0;
                     foreach ($months as $month) {
                         $posts_count_per_year += count($month);
                     }
                     $html .= $T2 . '<li class="' . ($expand ? 'open' : 'close') . ((int) $query === (int) $year ? ' ' . self::$config['classes']['current'] : "") . '">' . NL . $T3 . '<a href="javascript:;" class="toggle ' . ($expand ? 'open' : 'close') . '">' . ($expand ? '&#9660;' : '&#9658;') . '</a> <a href="' . Filter::colon('archive:url', $config->url . '/' . $config->archive->slug . '/' . $year) . '">' . $year . '</a> <span class="counter">' . $posts_count_per_year . '</span>' . NL;
                     $html .= $T3 . '<ul>' . NL;
                     foreach ($months as $month => $days) {
                         if (is_array($days)) {
                             $html .= $T4 . '<li' . ((string) $query === $year . '-' . $month ? ' class="' . self::$config['classes']['current'] . '"' : "") . '><a href="' . Filter::colon('archive:url', $config->url . '/' . $config->archive->slug . '/' . $year . '-' . $month) . '">' . $year . ' ' . $month_names[(int) $month - 1] . '</a> <span class="counter">' . count($days) . '</span></li>' . NL;
                         }
                     }
                     $html .= $T3 . '</ul>' . NL;
                     $html .= $T2 . '</li>' . NL;
                 }
                 $i++;
             }
             $html .= $T1 . '</ul>' . NL;
         }
         if ($type === 'LIST' || $type === 'DROPDOWN') {
             foreach ($files as $name) {
                 $s = explode('-', File::N($name));
                 $archives[] = $s[0] . '-' . $s[1];
             }
             $counter = array_count_values($archives);
             $archives = array_unique($archives);
             $i = 0;
             if ($type === 'LIST') {
                 $html .= $T1 . '<ul>' . NL;
                 foreach ($archives as $archive) {
                     list($year, $month) = explode('-', $archive);
                     $html .= $T2 . '<li' . ((string) $query === $year . '-' . $month ? ' class="' . self::$config['classes']['current'] . '"' : "") . '><a href="' . Filter::colon('archive:url', $config->url . '/' . $config->archive->slug . '/' . $archive) . '">' . $year . ' ' . $month_names[(int) $month - 1] . '</a> <span class="counter">' . $counter[$archive] . '</span></li>' . NL;
                     $i++;
                 }
                 $html .= $T1 . '</ul>' . NL;
             } else {
                 $html .= $T1 . '<select>' . NL . ($query === "" ? $T2 . '<option disabled selected>' . $speak->select . '&hellip;</option>' . NL : "");
                 foreach ($archives as $archive) {
                     list($year, $month) = explode('-', $archive);
                     $html .= $T2 . '<option value="' . Filter::colon('archive:url', $config->url . '/' . $config->archive->slug . '/' . $archive) . '"' . ((string) $query === $year . '-' . $month ? ' selected' : "") . '>' . $year . ' ' . $month_names[(int) $month - 1] . ' (' . $counter[$archive] . ')</option>' . NL;
                 }
                 $html .= $T1 . '</select>' . NL;
             }
         }
     } else {
         $html .= $T1 . Config::speak('notify_empty', strtolower($speak->{$p . 's'})) . NL;
     }
     $html .= '</div>' . O_END;
     Config::set('widget_archive_' . $kin . '_id', $id);
     return Filter::apply(array('widget:archive.' . $kin, 'widget:archive', 'widget'), $html, $id);
 }
?>
/update" method="post">
  <?php 
echo Form::hidden('token', $token);
?>
  <?php 
$twitter_cards_config = File::open(__DIR__ . DS . 'states' . DS . 'config.txt')->unserialize();
?>
  <label class="grid-group">
    <span class="grid span-2 form-label"><?php 
echo $speak->plugin_twitter_cards->twitter_site . ' ' . Jot::info($speak->plugin_twitter_cards->description);
?>
</span>
    <span class="grid span-4">
    <?php 
echo Form::text('twitter_site', $twitter_cards_config['twitter_site'], Text::parse(File::N($config->host), '->array_key', true), array('class' => 'input-block'));
?>
    </span>
  </label>
  <label class="grid-group">
    <span class="grid span-2 form-label"><?php 
echo $speak->plugin_twitter_cards->twitter_creator . ' ' . Jot::info($speak->plugin_twitter_cards->description);
?>
</span>
    <span class="grid span-4">
    <?php 
echo Form::text('twitter_creator', $twitter_cards_config['twitter_creator'], Text::parse($config->author->name, '->array_key', true), array('class' => 'input-block'));
?>
    </span>
  </label>
  <div class="grid-group">
<?php

$c_dashboard = $config->states->{'plugin_' . md5(File::B(__DIR__))};
$options = array();
foreach (glob(__DIR__ . DS . 'assets' . DS . 'shell' . DS . 'pigment' . DS . '*.css', GLOB_NOSORT) as $skin) {
    $s = File::N($skin);
    if ($ss = File::open($skin)->get(1)) {
        // Get title from CSS comment ...
        $ss = preg_replace('#\\/\\*!?\\s*(.*?)\\s*\\*\\/#', '$1', $ss);
    } else {
        $ss = Text::parse($s, '->title');
    }
    $options[$s] = $ss;
}
asort($options);
?>
<p><?php 
echo Form::select('skin', $options, $c_dashboard->skin) . ' ' . Jot::button('action', $speak->update);
?>
</p>
<fieldset>
  <legend>Disqus</legend>
  <label class="grid-group">
    <span class="grid span-1 form-label"><?php 
echo $speak->id . ' ' . Jot::info($speak->plugin_comment_service->description->disqus_id);
?>
</span>
    <span class="grid span-5"><?php 
echo Form::text('services[disqus][id]', $comment_service_config['services']['disqus']['id'], File::N($config->host));
?>
</span>
  </label>
</fieldset>
Example #15
0
        if (trim($request['email']) !== "" && !Guardian::check($request['email'], '->email')) {
            Notify::error($speak->notify_invalid_email);
            Guardian::memorize($request);
        }
        $P = array('data' => $request, 'action' => $request['action']);
        if (!Notify::errors()) {
            $name = $request['name'];
            $email = Text::parse($request['email'], '->broken_entity');
            $url = isset($request['url']) ? $request['url'] : false;
            $message = $request['message'];
            $field = Request::post('fields', array());
            include DECK . DS . 'workers' . DS . 'task.field.2.php';
            include DECK . DS . 'workers' . DS . 'task.field.1.php';
            // Update data
            Page::open($comment->path)->header(array('Name' => $name, 'Email' => $email, 'URL' => $url, 'Status' => $request['status'], 'Content Type' => Request::post('content_type', 'HTML'), 'UA' => $request['ua'] !== 'N/A' ? $request['ua'] : false, 'IP' => $request['ip'] !== 'N/A' ? $request['ip'] : false, 'Fields' => !empty($field) ? Text::parse($field, '->encoded_json') : false))->content($message)->save();
            File::open($comment->path)->renameTo(File::N($comment->path) . $extension);
            Notify::success(Config::speak('notify_success_updated', $speak->comment));
            Weapon::fire('on_comment_update', array($G, $P));
            Weapon::fire('on_comment_repair', array($G, $P));
            Guardian::kick($config->manager->slug . '/comment/repair/id:' . $id);
        }
    }
    Shield::lot(array('segment' => 'comment', 'default' => $comment))->attach('manager', false);
});
/**
 * Comment Killer
 * --------------
 */
Route::accept($config->manager->slug . '/comment/kill/id:(:num)', function ($id = "") use($config, $speak) {
    if (Guardian::get('status') !== 'pilot') {
        Shield::abort();
<?php

Weapon::add('shield_before', function () {
    $config = Config::get();
    if ($config->comments->allow) {
        $comment_service_config = File::open(__DIR__ . DS . 'states' . DS . 'config.txt')->unserialize();
        Config::set('plugins.comment_service_config', $comment_service_config);
        $active = $comment_service_config['service'];
        if ($s = Config::get($config->page_type)) {
            $active = isset($s->fields->comment_service) && trim($s->fields->comment_service) !== "" ? $s->fields->comment_service : $active;
        }
        if ($launch = File::exist(__DIR__ . DS . 'workers' . DS . $active . DS . 'launch.php')) {
            require $launch;
        }
        Filter::add('chunk:path', function ($path) use($active) {
            if ($active !== 0 && File::N($path) === 'comments') {
                return __DIR__ . DS . 'workers' . DS . $active . DS . 'comments.php';
            }
            return $path;
        });
    }
});
Example #17
0
 /**
  * ===========================================================================
  *  GET LIST OF RESPONSE(S) PATH
  * ===========================================================================
  *
  * -- CODE: ------------------------------------------------------------------
  *
  *    foreach(Get::responses() as $path) {
  *        echo $path . '<br>';
  *    }
  *
  *    // [1]. Filter by Post Time
  *    Get::responses('DESC', 'post:2014');
  *    Get::responses('DESC', 'post:2014-04');
  *    Get::responses('DESC', 'post:2014-04-21');
  *
  *    // [2]. Filter by Response Time
  *    Get::responses('DESC', 'time:2014');
  *    Get::responses('DESC', 'time:2014-11');
  *    Get::responses('DESC', 'time:2014-11-10');
  *
  *    // [3]. Filter by Response Parent Time
  *    Get::responses('DESC', 'parent:2014');
  *    Get::responses('DESC', 'parent:2014-04');
  *    Get::responses('DESC', 'parent:2014-04-21');
  *
  * ---------------------------------------------------------------------------
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *  Parameter | Type    | Description
  *  --------- | ------- | ----------------------------------------------------
  *  $order    | string  | Ascending or descending? ASC/DESC?
  *  $filter   | string  | The result(s) filter
  *  $e        | boolean | The file extension(s)
  *  --------- | ------- | ----------------------------------------------------
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
  */
 public static function responses($order = 'ASC', $filter = "", $e = 'txt', $folder = RESPONSE)
 {
     $results = array();
     $e = str_replace(' ', "", $e);
     $responses = strpos($e, ',') !== false ? glob($folder . DS . '*.{' . $e . '}', GLOB_NOSORT | GLOB_BRACE) : glob($folder . DS . '*.' . $e, GLOB_NOSORT);
     $total_responses = count($responses);
     if (!is_array($responses) || $total_responses === 0) {
         return false;
     }
     if ($order === 'DESC') {
         rsort($responses);
     } else {
         sort($responses);
     }
     if (!$filter) {
         return $responses;
     }
     if (strpos($filter, ':') !== false) {
         list($key, $value) = explode(':', $filter, 2);
         if (is_numeric($value)) {
             // filter by ID
             $value = Date::slug($value);
         }
         if ($key === 'post') {
             for ($i = 0; $i < $total_responses; ++$i) {
                 list($post, $time, $parent) = explode('_', File::N($responses[$i]), 3);
                 if (strpos($post, $value) === 0) {
                     $results[] = $responses[$i];
                 }
             }
         } else {
             if ($key === 'time') {
                 for ($i = 0; $i < $total_responses; ++$i) {
                     list($post, $time, $parent) = explode('_', File::N($responses[$i]), 3);
                     if (strpos($time, $value) === 0) {
                         $results[] = $responses[$i];
                     }
                 }
             } else {
                 if ($key === 'parent') {
                     for ($i = 0; $i < $total_responses; ++$i) {
                         list($post, $time, $parent) = explode('_', File::N($responses[$i]), 3);
                         if (strpos($parent, $value) === 0) {
                             $results[] = $responses[$i];
                         }
                     }
                 } else {
                     // if($key === 'keyword') {
                     for ($i = 0; $i < $total_responses; ++$i) {
                         if (strpos(File::N($responses[$i]), $value) !== false) {
                             $results[] = $responses[$i];
                         }
                     }
                 }
             }
         }
     } else {
         for ($i = 0; $i < $total_responses; ++$i) {
             if (strpos(File::N($responses[$i]), $filter) !== false) {
                 $results[] = $responses[$i];
             }
         }
     }
     unset($responses);
     return !empty($results) ? $results : false;
 }
Example #18
0
             Weapon::add('SHIPMENT_REGION_BOTTOM', function () {
                 echo '<script>
     (function($) {
         $(\'.tab-area .tab[href$="#tab-content-3"]\').trigger("click");
     })(window.Zepto || window.jQuery);
     </script>';
             }, 11);
         }
     }
 }
 $filter = Request::get('q', "");
 $filter = $filter ? Text::parse($filter, '->safe_file_name') : false;
 $takes = glob($d . DS . '*', GLOB_NOSORT);
 if ($filter) {
     foreach ($takes as $k => $v) {
         if (strpos(File::N($v), $filter) === false) {
             unset($takes[$k]);
         }
     }
 }
 if ($_files = Mecha::eat($takes)->chunk($offset, $config->per_page * 2)->vomit()) {
     $files = array();
     foreach ($_files as $_file) {
         $files[] = File::inspect($_file);
     }
     $files = Mecha::eat($files)->order('ASC', 'path')->vomit();
     unset($_files);
 } else {
     $files = false;
 }
 Config::set(array('page_title' => $speak->assets . $config->title_separator . $config->manager->title, 'offset' => $offset, 'files' => $files, 'pagination' => Navigator::extract($takes, $offset, $config->per_page * 2, $config->manager->slug . '/asset'), 'cargo' => DECK . DS . 'workers' . DS . 'cargo.asset.php'));
Example #19
0
 * Configuration Manager
 * ---------------------
 */
Route::accept($config->manager->slug . '/config', function () use($config, $speak) {
    if (!Guardian::happy(1)) {
        Shield::abort();
    }
    Config::set(array('page_title' => $speak->configs . $config->title_separator . $config->manager->title, 'cargo' => 'cargo.config.php'));
    if ($request = Request::post()) {
        Guardian::checkToken($request['token']);
        $bools = array('comments.allow' => false, 'comments.moderation' => false, 'widget_include_css' => false, 'widget_include_js' => false, 'html_parser.active' => Request::post('html_parser.active', false));
        $pages = array('index' => 'article', 'tag' => 'tag', 'archive' => 'archive', 'search' => 'search', 'manager' => 'manager');
        $slugs = array();
        if ($files = Get::pages()) {
            foreach ($files as $file) {
                list($_time, $_kind, $_slug) = explode('_', File::N($file), 3);
                $slugs[$_slug] = 1;
            }
            unset($files);
        }
        foreach ($bools as $bool => $fallback) {
            // Fix(es) for checkbox input(s)
            Mecha::SVR($request, $bool, Request::post($bool, $fallback));
        }
        foreach ($pages as $page => $default) {
            // Fix(es) for slug pattern input(s)
            $request[$page]['slug'] = Text::parse(Request::post($page . '.slug', $default), '->slug');
            if (Request::post($page . '.per_page') < 1 || floor(Request::post($page . '.per_page')) != Request::post($page . '.per_page')) {
                Notify::error($speak->notify_invalid_per_page_number);
                Guardian::memorize($request);
            }
Example #20
0
function do_footer_manager_link($content, $path)
{
    global $config, $speak;
    if (File::N($path) === 'block.footer.bar') {
        $s = Guardian::happy() ? '<a href="' . Filter::colon('manager:url', $config->url . '/' . $config->manager->slug . '/logout') . '" rel="nofollow">' . $speak->log_out . '</a>' : '<a href="' . Filter::colon('manager:url', $config->url . '/' . $config->manager->slug . '/login') . '" rel="nofollow">' . $speak->log_in . '</a>';
        return str_replace('<div class="blog-footer-right">', '<div class="blog-footer-right">' . $s, $content);
    }
    return $content;
}
Example #21
0
 /**
  * Widget Archive
  * --------------
  *
  * [1]. Widget::archive('HIERARCHY');
  * [2]. Widget::archive('HIERARCHY', 'ASC');
  *
  */
 public static function archive($type = 'HIERARCHY', $sort = 'DESC')
 {
     $T1 = TAB;
     $T2 = str_repeat($T1, 2);
     $T3 = str_repeat($T1, 3);
     $T4 = str_repeat($T1, 4);
     $config = Config::get();
     $speak = Config::speak();
     $year_first = $config->widget_year_first;
     $query = $config->archive_query;
     $months_array = explode(',', $speak->months);
     $archives = array();
     if (!($files = Get::articles($sort))) {
         return O_BEGIN . '<div class="widget widget-archive">' . Config::speak('notify_empty', strtolower($speak->posts)) . '</div>' . O_END;
     }
     if ($type === 'HIERARCHY') {
         $i = 0;
         foreach ($files as $file) {
             list($year, $month) = explode('-', File::N($file));
             $archives[$year][$month][] = $file;
         }
         $html = O_BEGIN . '<div class="widget widget-archive widget-archive-hierarchy" id="widget-archive-hierarchy-' . self::$id['archive_hierarchy'] . '">' . NL;
         self::$id['archive_hierarchy']++;
         $html .= $T1 . '<ul>' . NL;
         foreach ($archives as $year => $months) {
             if (is_array($months)) {
                 $posts_count_per_year = 0;
                 $expand = empty($query) ? $i === 0 : (int) substr($query, 0, 4) === (int) $year;
                 foreach ($months as $month) {
                     $posts_count_per_year += count($month);
                 }
                 $html .= $T2 . '<li class="' . ($expand ? 'expanded' : 'collapsed') . ((int) $query === (int) $year ? ' selected' : "") . '">' . NL . $T3 . '<a href="javascript:;" class="toggle ' . ($expand ? 'open' : 'close') . '">' . ($expand ? '&#9660;' : '&#9658;') . '</a> <a href="' . $config->url . '/' . $config->archive->slug . '/' . $year . '">' . $year . '</a> <span class="counter">' . $posts_count_per_year . '</span>' . NL;
                 $html .= $T3 . '<ul>' . NL;
                 foreach ($months as $month => $days) {
                     if (is_array($days)) {
                         $html .= $T4 . '<li' . ((string) $query === $year . '-' . $month ? ' class="selected"' : "") . '><a href="' . $config->url . '/' . $config->archive->slug . '/' . $year . '-' . $month . '">' . ($year_first ? $year . ' ' . $months_array[(int) $month - 1] : $months_array[(int) $month - 1] . ' ' . $year) . '</a> <span class="counter">' . count($days) . '</span></li>' . NL;
                     }
                 }
                 $html .= $T3 . '</ul>' . NL;
                 $html .= $T2 . '</li>' . NL;
             }
             $i++;
         }
         $html .= $T1 . '</ul>' . NL;
         $html .= '</div>' . O_END;
         $html = Filter::apply('widget', $html);
         return Filter::apply('widget:archive.hierarchy', Filter::apply('widget:archive', $html));
     }
     if ($type === 'LIST' || $type === 'DROPDOWN') {
         foreach ($files as $name) {
             $archives[] = substr(File::N($name), 0, 7);
         }
         $counter = array_count_values($archives);
         $archives = array_unique($archives);
         $i = 0;
         if ($type === 'LIST') {
             $html = O_BEGIN . '<div class="widget widget-archive widget-archive-list" id="widget-archive-list-' . self::$id['archive_list'] . '">' . NL;
             self::$id['archive_list']++;
             $html .= $T1 . '<ul>' . NL;
             foreach ($archives as $archive) {
                 list($year, $month) = explode('-', $archive);
                 $html .= $T2 . '<li' . ((string) $query === $year . '-' . $month ? ' class="selected"' : "") . '><a href="' . $config->url . '/' . $config->archive->slug . '/' . $archive . '">' . ($year_first ? $year . ' ' . $months_array[(int) $month - 1] : $months_array[(int) $month - 1] . ' ' . $year) . '</a> <span class="counter">' . $counter[$archive] . '</span></li>' . NL;
                 $i++;
             }
             $html .= $T1 . '</ul>' . NL;
             $html .= '</div>' . O_END;
             $html = Filter::apply('widget', $html);
             return Filter::apply('widget:archive.list', Filter::apply('widget:archive', $html));
         } else {
             $html = O_BEGIN . '<div class="widget widget-archive widget-archive-dropdown" id="widget-archive-dropdown-' . self::$id['archive_dropdown'] . '">' . NL;
             self::$id['archive_dropdown']++;
             $html .= $T1 . '<select>' . NL . ($query === "" ? $T2 . '<option disabled selected>' . $speak->select . '&hellip;</option>' . NL : "");
             foreach ($archives as $archive) {
                 list($year, $month) = explode('-', $archive);
                 $html .= $T2 . '<option value="' . $config->url . '/' . $config->archive->slug . '/' . $archive . '"' . ((string) $query === $year . '-' . $month ? ' selected' : "") . '>' . ($year_first ? $year . ' ' . $months_array[(int) $month - 1] : $months_array[(int) $month - 1] . ' ' . $year) . ' (' . $counter[$archive] . ')</option>' . NL;
             }
             $html .= $T1 . '</select>' . NL;
             $html .= '</div>' . O_END;
             $html = Filter::apply('widget', $html);
             return Filter::apply('widget:archive.dropdown', Filter::apply('widget:archive', $html));
         }
     }
 }