コード例 #1
0
ファイル: twig-init.php プロジェクト: Halfnhav4/datawrapper
function dwInitTwigEnvironment(Twig_Environment $twig)
{
    $twig->setCache(ROOT_PATH . '/tmp/twig');
    $twig->enableAutoReload();
    $twig->addExtension(new Twig_I18n_Extension());
    $twig->addFilter(new Twig_SimpleFilter('purify', function ($dirty) {
        return dwGetHTMLPurifier()->purify($dirty);
    }));
    $twig->addFilter(new Twig_SimpleFilter('json', function ($arr) {
        $mask = 0;
        if (!empty($opts)) {
            if (!empty($opts['pretty'])) {
                $mask = $mask | JSON_PRETTY_PRINT;
            }
        }
        return json_encode($arr, $mask);
    }));
    $twig->addFilter(new Twig_SimpleFilter('css', function ($arr) {
        $css = '';
        foreach ($arr as $prop => $val) {
            $css .= $prop . ':' . $val . ';';
        }
        return $css;
    }));
    $twig->addFunction(new Twig_SimpleFunction('hook', function () {
        call_user_func_array(array(DatawrapperHooks::getInstance(), 'execute'), func_get_args());
    }));
    $twig->addFunction(new Twig_SimpleFunction('has_hook', function ($hook) {
        return DatawrapperHooks::getInstance()->hookRegistered($hook);
    }));
    $twig->addFunction(new Twig_SimpleFunction('has_plugin', function ($plugin) {
        return DatawrapperPluginManager::loaded($plugin);
    }));
    $twig->addFilter(new Twig_SimpleFilter('lettering', function ($text) {
        $out = '';
        foreach (str_split($text) as $i => $char) {
            $out .= '<span class="char' . $i . '">' . $char . '</span>';
        }
        return $out;
    }, array('is_safe' => array('html'))));
    $loc = DatawrapperSession::getLanguage();
    if ($loc == 'en') {
        $loc = 'en-US';
    }
    \Moment\Moment::setLocale(str_replace('-', '_', $loc));
    $twig->addFilter(new Twig_SimpleFilter('reltime', function ($time) {
        // return $time;
        return (new \Moment\Moment($time))->fromNow()->getRelative();
    }));
    if (!empty($GLOBALS['dw_config']['debug'])) {
        $twig->addFilter('var_dump', new Twig_Filter_Function('var_dump'));
    }
    return $twig;
}
コード例 #2
0
ファイル: Time.php プロジェクト: ponydevs/MLPVC-RR
 /**
  * Converts $timestamp to an "X somthing ago" format
  * Always uses the largest unit available
  *
  * @param int $timestamp
  * @param int $now       For use in tests
  *
  * @return string
  */
 private static function _from(int $timestamp, $now = null) : string
 {
     Moment::setLocale('en_US');
     $out = new Moment(date('c', $timestamp));
     if (isset($now)) {
         $out = $out->from(new Moment(date('c', $now)));
     } else {
         $out = $out->fromNow();
     }
     return $out->getRelative();
 }
コード例 #3
0
 /**
  * @param array $params
  * @param Di $di
  * @return array
  */
 public static function convertDate(array $params, Di $di)
 {
     foreach ($params as $key => $value) {
         if (!is_string($value) or !self::isDate($value) or !strtotime($value)) {
             continue;
         }
         try {
             $timezoneOffset = self::getTimezoneOffset($di);
             $moment = new Moment($value, 'CET');
             if ($timezoneOffset > 0) {
                 $moment->subtractMinutes(abs($timezoneOffset));
             }
             if ($timezoneOffset < 0) {
                 $moment->addMinutes(abs($timezoneOffset));
             }
             $params[$key] = $moment->format('Y-m-d H:i:s');
         } catch (MomentException $exception) {
         }
     }
     return $params;
 }
コード例 #4
0
            ?>
       <div class="col col-4">
        <h2><?php 
            echo __('[:es]Títulos[:en]Titles');
            ?>
</h2>
<?php 
            foreach ($books as $book) {
                $releaseDate = get_post_meta($book->ID, '_igv_release_date');
                if (!empty($releaseDate)) {
                    if (qtranxf_getLanguage() == 'es') {
                        $locale = 'es_ES';
                    } else {
                        $locale = 'en_US';
                    }
                    \Moment\Moment::setLocale($locale);
                    $m = new \Moment\Moment($releaseDate[0]);
                    ?>

            <div class="collection-book font-mono u-cf">
              <div class="book-image"><a href="<?php 
                    echo get_permalink($book->ID);
                    ?>
"><?php 
                    echo get_the_post_thumbnail($book->ID, 'book-cover');
                    ?>
</a></div>
              <span class="book-date"><a class="color-black" href="<?php 
                    echo get_permalink($book->ID);
                    ?>
"><?php 
コード例 #5
0
ファイル: cs_CZ.php プロジェクト: Stowers-LIMS/moment.php
<?php

require __DIR__ . '/../vendor/autoload.php';
\Moment\Moment::setLocale('cs_CZ');
$m1 = new \Moment\Moment('2013-02-01T07:00:00');
$m2 = $m1->cloning();
$m2->subtractDays(1);
echo $m2->from($m1)->getRelative() . "\n";
echo $m1->from($m2)->getRelative() . "\n";
echo "\n";
$m2->subtractDays(1);
echo $m2->from($m1)->getRelative() . "\n";
echo $m1->from($m2)->getRelative() . "\n";
echo "\n";
$m2->subtractDays(3);
echo $m2->from($m1)->getRelative() . "\n";
echo $m1->from($m2)->getRelative() . "\n";
echo "\n";
$m2->subtractDays(30);
echo $m2->from($m1)->getRelative() . "\n";
echo $m1->from($m2)->getRelative() . "\n";
echo "\n";
$m2->subtractDays(60);
echo $m2->from($m1)->getRelative() . "\n";
echo $m1->from($m2)->getRelative() . "\n";
echo "\n";
$m2->subtractDays(60);
echo $m2->from($m1)->getRelative() . "\n";
echo $m1->from($m2)->getRelative() . "\n";
echo "\n";
$m2->subtractDays(210);
コード例 #6
0
 protected function findPrevTableName(array $names)
 {
     $name = array_pop($names);
     $dateTime = \DateTime::createFromFormat('ymd', substr($name, 5));
     $date = new Moment($dateTime->format('Y-m-d'));
     while ($date->isAfter($this->exchangeRateDate) && count($names) > 0) {
         $name = array_pop($names);
         $dateTime = \DateTime::createFromFormat('ymd', substr($name, 5));
         $date = new Moment($dateTime->format('Y-m-d'));
     }
     return $name;
 }
コード例 #7
0
 public static function anio($fecha)
 {
     $fecha = isset($fecha) && $fecha !== '' ? $fecha : '';
     $dato = new Moment($fecha);
     return $dato->getYear();
 }
コード例 #8
0
ファイル: Moment.php プロジェクト: danhunsaker/calends
 /**
  * {@inheritdoc}
  */
 public static function convert(Calends $cal)
 {
     return ['start' => Source::createFromFormat('U.u', BC::add($cal->getDate('unix'), 0, 6)), 'duration' => new DateInterval("PT{$cal->getDuration(0)}S"), 'end' => Source::createFromFormat('U.u', BC::add($cal->getEndDate('unix'), 0, 6))];
 }