<?php

// TODO: use `$segment` data generated by `Shield::lot()`
if (Route::is($config->manager->slug . '/comment') || Route::is($config->manager->slug . '/comment/(:num)')) {
    $segment = array('comment', 'article');
}
// Eject all weapon(s) related to comment reply
Weapon::eject($segment[0] . '_footer', 'do_response_reply');
Weapon::eject($segment[0] . '_form_button_after', 'do_response_reply_x');
Weapon::eject('shell_before', 'do_response_reply_css');
Weapon::eject('SHIPMENT_REGION_BOTTOM', 'do_response_reply_js');
// Reply comment from dashboard :)
function __do_response_reply($response)
{
    global $config, $speak, $segment;
    $q = str_replace('&', '&amp;', HTTP::query(array('parent' => $response->id, 'post' => $response->post)));
    echo (Weapon::exist($segment[0] . '_footer') ? ' / ' : "") . Cell::a($config->manager->slug . '/' . $segment[0] . '/ignite' . $q, $speak->reply);
}
// Show total comment repl(y|ies)
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)) . ' &middot; ';
}
if (Route::is($config->manager->slug . '/' . $segment[0] . '/ignite') && ($parent = Request::get('parent', false))) {
    if ($response = call_user_func('Get::' . $segment[0], $parent)) {
        Weapon::add('tab_content_1_before', function () use($segment, $response) {