コード例 #1
0
 protected function translate_value($timestamp, $format = 'Y/m/d H:i')
 {
     if (empty($timestamp)) {
         return null;
     }
     $result = \Cibulka::Theme('Date')->get_time($timestamp, $format);
     return $result;
 }
コード例 #2
0
namespace Cibulka\Plugin\Base;

$plugin['CSS_Grid'] = function ($show = null) {
    if ($show === null) {
        $show = WP_ENV === 'development' ? true : false;
    }
    $obj = new HTML\CSS_Grid('debug-grid', 'debug-grid-handle', $show);
    return $obj;
};
$plugin['HTML'] = $plugin->factory(function ($name, array $attrs = array(), $self_close = null, $content = null) {
    $html = new HTML\HTML($name, $attrs, $self_close, $content);
    return $html;
});
$plugin['_Theme_Image'] = function () {
    $url_obj = \Cibulka::Base('URL');
    try {
        $theme_config = \Cibulka::Theme('Theme_Config');
        $breakpoints = $theme_config['theme']['breakpoints'];
        $sizes = $theme_config['theme']['img'];
    } catch (\Exception $e) {
        throw new \Exception("Theme must define Theme_Config with buildconfig.json content!");
    }
    $obj = new HTML\Srcset($breakpoints, $sizes, $url_obj);
    return $obj;
};
// - NOTE: Intentionally NOT a factory.
$plugin['Theme_Image'] = function ($filename, array $sizes, array $attrs = null, array $allowed_sizes = null, $src = null) {
    $obj = \Cibulka::Base('_Theme_Image');
    $obj->set_data($filename, $sizes, $attrs, $allowed_sizes, $src);
    return $obj;
};
コード例 #3
0
});
$dic['Excerpt'] = function ($post_id) {
    return apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id));
};
$dic['Content'] = function ($post_id) {
    return apply_filters('the_content', get_post_field('post_content', $post_id));
};
$dic['Reading_Time'] = $dic->factory(function ($post_id) {
    $content = \Cibulka::Plugin('theme')->Content($post_id);
    $words = str_word_count(strip_tags($content));
    $m = floor($words / 200);
    $m = 0 == $m ? 1 : $m;
    return \Cibulka::Plugin('theme')->Time()->say_of($m, 'minute');
});
$dic['Time'] = function () {
    $class = __NAMESPACE__ . '\\Time\\Time' . ucfirst(\Cibulka::Theme()->Lang());
    return new $class();
};
$dic['Relative_Date'] = $dic->factory(function ($time_1, $period = null, $default = 'j.n.', $time_2 = null, $timezone = null, $round_to_midnight = true) use($dic) {
    $time = $dic->get('Time', 'Cz');
    switch ($period) {
        case 'past':
            return $time->ago($time_1, $time_2, $default, $timezone, $round_to_midnight);
            break;
        case 'future':
            return $time->after($time_1, $time_2, $default, $timezone, $round_to_midnight);
            break;
        default:
            return $time->ago_or_after($time_1, $time_2, $default, $timezone, $round_to_midnight);
            break;
    }