Example #1
1
 /**
  * Dodatkowe filtry Twig zwiazane z formatowaniem danych uzytkownika
  *
  * @return array
  */
 public function getFilters()
 {
     return [new Twig_SimpleFilter('format_date', function ($dateTime, $diffForHumans = true) {
         $format = Auth::check() ? auth()->user()->date_format : '%Y-%m-%d %H:%M';
         if (!$dateTime instanceof Carbon) {
             $dateTime = new Carbon($dateTime);
         }
         $now = Carbon::now();
         if (!$diffForHumans) {
             return $dateTime->formatLocalized($format);
         } elseif ($dateTime->diffInHours($now) < 1) {
             return $dateTime->diffForHumans(null, true) . ' temu';
         } elseif ($dateTime->isToday()) {
             return 'dziś, ' . $dateTime->format('H:i');
         } elseif ($dateTime->isYesterday()) {
             return 'wczoraj, ' . $dateTime->format('H:i');
         } else {
             return $dateTime->formatLocalized($format);
         }
     }), new Twig_SimpleFilter('timestamp', function ($dateTime) {
         if ($dateTime instanceof Carbon) {
             return $dateTime->getTimestamp();
         } else {
             return strtotime($dateTime);
         }
     })];
 }
 public function __construct($designation, Carbon $startTime, Carbon $endTime = null, $code = 0, Exception $previous = null)
 {
     switch ($code) {
         case 1:
             $startString = $startTime->isToday() ? 'today starting at ' . $startTime->format('g:ia') : $startTime->format('M jS g:ia');
             $endString = $endTime->isToday() ? $endTime->format('g:ia') : $endTime->format('M jS g:ia');
             $this->message = sprintf($this->messageBetween, $designation, $startString, $endString);
             break;
         case 2:
             $startString = $startTime->isToday() ? $startTime->format('g:ia') : $startTime->format('M jS g:ia');
             $this->message = sprintf($this->messageAfter, $designation, $startString);
             break;
         case 3:
             $endString = $endTime->isToday() ? $endTime->format('g:ia') : $endTime->format('M jS g:ia');
             $this->message = sprintf($this->messageBefore, $designation, $endString);
             break;
     }
     parent::__construct($this->message, $code, $previous);
 }
Example #3
0
 public static function formatHistory($val)
 {
     $time = new Carbon($val);
     $now = Carbon::now();
     if ($time->isToday() == $now->isToday()) {
         return 'Today at ' . $val->format('H:i');
     } elseif ($time->isYesterday()) {
         return 'Yesterday at ' . $val->format('H:i');
     } elseif ($time->format('Y') == $now->format('Y')) {
         return $val->format('d M, H:i');
     } elseif ($time->format('Y') != $now->format('Y')) {
         return $val->format('d M Y, H:i');
     }
 }
 /**
  * Make a calendar list of events.
  *
  * Outputs a list of events according to events for the specified range.
  *
  * @since  3.0.0
  * @access private
  *
  * @param  int $timestamp
  * @param  int $id
  *
  * @return string
  */
 private function draw_list($timestamp, $id = 0)
 {
     $calendar = $this->calendar;
     if (empty($calendar)) {
         $calendar = $this->calendar = simcal_get_calendar(intval($id));
         if (!$calendar instanceof Default_Calendar) {
             return '';
         }
     }
     date_default_timezone_set($calendar->timezone);
     $now = $calendar->now;
     $current_events = $this->get_events($timestamp);
     $day_format = explode(' ', $calendar->date_format);
     ob_start();
     // Draw the events.
     $block_tag = $calendar->compact_list && !empty($current_events) ? 'div' : 'dl';
     $data_heading = '';
     $heading = $this->get_heading();
     foreach ($heading as $k => $v) {
         $data_heading .= ' data-heading-' . $k . '="' . $v . '"';
     }
     echo '<' . $block_tag . ' class="simcal-events-list-container"' . ' data-prev="' . $this->prev . '"' . ' data-next="' . $this->next . '"' . $data_heading . '>';
     if (!empty($current_events) && is_array($current_events)) {
         foreach ($current_events as $ymd => $events) {
             $day_ts = Carbon::createFromFormat('Ymd', $ymd, $calendar->timezone)->getTimestamp();
             if (!$calendar->compact_list) {
                 $date = new Carbon('now', $calendar->timezone);
                 $date->setLocale(substr(get_locale(), 0, 2));
                 $date->setTimestamp($day_ts);
                 if ($date->isToday()) {
                     $the_color = new Color($calendar->today_color);
                 } else {
                     $the_color = new Color($calendar->days_events_color);
                 }
                 $bg_color = '#' . $the_color->getHex();
                 $color = $the_color->isDark() ? '#ffffff' : '#000000';
                 $border_style = ' style="border-bottom: 1px solid ' . $bg_color . ';" ';
                 $bg_style = ' style="background-color: ' . $bg_color . '; color: ' . $color . ';"';
                 echo "\t" . '<dt class="simcal-day-label"' . $border_style . '>';
                 echo '<span' . $bg_style . '>';
                 foreach ($day_format as $format) {
                     echo $format ? '<span class="simcal-date-format" data-date-format="' . $format . '">' . date_i18n($format, $day_ts) . '</span> ' : ' ';
                 }
                 echo '</span>';
                 echo '</dt>' . "\n";
             }
             $list_events = '<ul class="simcal-events">' . "\n";
             $calendar_classes = array();
             $day_classes = 'simcal-weekday-' . date('w', $day_ts);
             // Is this the present, the past or the future, Doc?
             if ($timestamp <= $now && $timestamp >= $now) {
                 $day_classes .= ' simcal-today simcal-present simcal-day';
             } elseif ($timestamp < $now) {
                 $day_classes .= ' simcal-past simcal-day';
             } elseif ($this->end > $now) {
                 $day_classes .= ' simcal-future simcal-day';
             }
             $count = 0;
             foreach ($events as $day_events) {
                 foreach ($day_events as $event) {
                     if ($event instanceof Event) {
                         $event_classes = $event_visibility = '';
                         $calendar_class = 'simcal-events-calendar-' . strval($event->calendar);
                         $calendar_classes[] = $calendar_class;
                         $recurring = $event->recurrence ? 'simcal-event-recurring ' : '';
                         $has_location = $event->venue ? 'simcal-event-has-location ' : '';
                         $event_classes .= 'simcal-event ' . $recurring . $has_location . $calendar_class;
                         // Toggle some events visibility if more than optional limit.
                         if ($calendar->events_limit > -1 && $count >= $calendar->events_limit) {
                             $event_classes .= ' simcal-event-toggled';
                             $event_visibility = ' style="display: none"';
                         }
                         $event_color = '';
                         $bullet = '';
                         $event_color = $event->get_color();
                         if (!empty($event_color)) {
                             $side = is_rtl() ? 'right' : 'left';
                             $event_color = ' style="border-' . $side . ': 4px solid ' . $event_color . '; padding-' . $side . ': 8px;"';
                         }
                         $list_events .= "\t" . '<li class="' . $event_classes . '"' . $event_visibility . $event_color . ' itemprop="event" itemscope itemtype="http://schema.org/Event">' . "\n";
                         $list_events .= "\t\t" . '<div class="simcal-event-details">' . $calendar->get_event_html($event) . '</div>' . "\n";
                         $list_events .= "\t" . '</li>' . "\n";
                         $count++;
                         // Event falls within today.
                         if ($this->end <= $now && $this->start >= $now) {
                             $day_classes .= ' simcal-today-has-events';
                         }
                         $day_classes .= ' simcal-day-has-events simcal-day-has-' . strval($count) . '-events';
                         if ($calendar_classes) {
                             $day_classes .= ' ' . trim(implode(' ', array_unique($calendar_classes)));
                         }
                     }
                 }
             }
             $list_events .= '</ul>' . "\n";
             // If events visibility is limited, print the button toggle.
             if ($calendar->events_limit > -1 && $count > $calendar->events_limit) {
                 $list_events .= '<button class="simcal-events-toggle"><i class="simcal-icon-down simcal-icon-animate"></i></button>';
             }
             // Print final list of events for the current day.
             $tag = $calendar->compact_list ? 'div' : 'dd';
             echo '<' . $tag . ' class="' . $day_classes . '" data-events-count="' . strval($count) . '">' . "\n";
             echo "\t" . $list_events . "\n";
             echo '</' . $tag . '>' . "\n";
         }
     } else {
         echo "\t" . '<p>';
         $message = get_post_meta($calendar->id, '_no_events_message', true);
         if ('events' == $calendar->group_type) {
             echo !empty($message) ? $message : __('Nothing to show.', 'google-calendar-events');
         } else {
             if (!empty($message)) {
                 echo $message;
             } else {
                 $from = Carbon::createFromTimestamp($this->start, $calendar->timezone)->getTimestamp();
                 $to = Carbon::createFromTimestamp($this->end, $calendar->timezone)->getTimestamp();
                 echo apply_filters('simcal_no_events_message', sprintf(__('Nothing from %1$s to %2$s.', 'google-calendar-events'), date_i18n($calendar->date_format, $from), date_i18n($calendar->date_format, $to)), $calendar->id, $from, $to);
             }
         }
         echo "\t" . '</p>' . "\n";
     }
     echo '</' . $block_tag . '>';
     date_default_timezone_set($calendar->site_timezone);
     return ob_get_clean();
 }
Example #5
0
File: Init.php Project: newset/wine
 protected function isToday($date)
 {
     $dt = new Carbon($date);
     return $dt->isToday();
 }
function ivy_echo_date(\Carbon\Carbon $date)
{
    $date->setTimezone(config('params.user_timezone'));
    return $date->isToday() ? 'Mới @' . $date->format(config('params.user_hourformat')) : ($date->isYesterday() ? 'Hôm qua @' . $date->format(config('params.user_hourformat')) : $date->format(config('params.user_dateformat')));
}
Example #7
0
 public static function feedsAndCategories()
 {
     \DB::enableQueryLog();
     $oQuery = DB::table('categories')->join('feed_user', function ($join) {
         $join->on('categories.id', '=', 'feed_user.category_id')->where('categories.user_id', '=', Auth::id());
     })->join('feeditems', function ($join) {
         $join->on('feed_user.feed_id', '=', 'feeditems.feed_id');
         if (Request::has('feed')) {
             $join->where("feeditems.feed_id", "=", Request::get('feed'));
         }
     })->join('feeds', "feeds.id", "=", "feed_user.feed_id");
     $oQuery->orderBy('feeditems.pubDate', 'desc')->select(['feeditems.url as url', 'feeditems.title as title', 'feeds.url as feedurl', 'feeds.id as feed_id', 'feeditems.pubDate as date', 'feed_user.name as name', 'feeditems.thumb as thumb', 'feeds.thumb as feedthumb', 'feed_user.colour as feed_colour', 'categories.id as cat_id']);
     $iPage = Request::input("page", 1);
     $iPerPage = 20;
     $iTotalItems = 0;
     //$maFeedItems = $oQuery->skip(($iPage * $iPerPage)-$iPerPage)->take($iPerPage)->get();
     $maFeedItems = $oQuery->get();
     #print_r($maFeedItems);die();
     $iTotalItems = count($maFeedItems);
     $iTotalPages = ceil($iTotalItems / $iPerPage);
     $maFeedItems = array_slice($maFeedItems, $iPage * $iPerPage - $iPerPage, $iPerPage);
     #print_r(DB::getQueryLog());
     $oaFeedItems = [];
     foreach ($maFeedItems as $oFeedItem) {
         $sDate = '';
         $oDate = new Carbon($oFeedItem->date);
         if ($oDate->isToday()) {
             // 10:41 pm
             $sDate = $oDate->format('g:i a');
         } else {
             // Aug 12
             $sDate = $oDate->format('M j');
         }
         array_push($oaFeedItems, ["url" => $oFeedItem->url, "title" => $oFeedItem->title, "feedurl" => $oFeedItem->feedurl, "feed_id" => $oFeedItem->feed_id, "category_id" => $oFeedItem->cat_id, "date" => $sDate, "name" => $oFeedItem->name, "thumb" => $oFeedItem->thumb !== '' ? $oFeedItem->thumb : $oFeedItem->feedthumb, "feed_thumb" => $oFeedItem->feedthumb]);
     }
     if (Request::has('feed')) {
         $oQuery->where("feeds.id", "=", Request::get('feed'));
     }
     $oUser = Auth::user();
     $oUser->load('userCategories.userFeeds.feed');
     #$oaFeeds = Auth::user();->userCategories()->userFeeds;
     //$oaFeeds = $oUser->userCategories->userFeeds->feed;
     #foreach()
     // what to return
     // categories / feed structure
     // array of feed items
     $oData = ['iAvailablePages' => $iTotalPages, 'iPerPage' => $iPerPage];
     $oaCategoryFeeds = [];
     foreach ($oUser->userCategories as $oCategory) {
         // get feeds in category
         $aoFeeds = [];
         foreach ($oCategory->userFeeds as $oUserFeed) {
             array_push($aoFeeds, ["id" => $oUserFeed->id, "name" => $oUserFeed->name]);
         }
         // now add category with feeds
         array_push($oaCategoryFeeds, ["category_id" => $oCategory->id, "category_name" => $oCategory->name, "feeds" => $aoFeeds]);
     }
     return response()->json(['jsonFeedItems' => $oaFeedItems, 'jsonCategoryFeeds' => $oaCategoryFeeds, 'data' => $oData]);
     //return response(['jsonFeedItems' => $oaFeedItems, 'jsonFeeds' => $oaFeeds], 200);
 }
Example #8
0
<?php

use Carbon\Carbon;
if (count($events)) {
    ?>
                    
        @foreach ( $events as $key => $value )
            <div class="list-group-item disabled">
                <span class="text-uppercase">
                    <?php 
    $dt = new Carbon($key);
    ?>
                    <?php 
    if ($dt->isToday()) {
        echo "<strong>hoje</strong>, " . strftime("%A %d de %B", strtotime($key));
    } else {
        if ($dt->isTomorrow()) {
            echo "<strong>amanhã</strong>, " . strftime("%A %d de %B", strtotime($key));
        } else {
            if ($dt->isYesterday()) {
                echo "<strong>ontem</strong>, " . strftime("%A %d de %B", strtotime($key));
            } else {
                echo strftime("%A, %d de %B", strtotime($key));
            }
        }
    }
    ?>
                </span>
            </div>
            @foreach ( $value as $event )