Ejemplo n.º 1
0
 public function create(int $year = NULL, int $month = NULL) : string
 {
     $today = getdate();
     if (!isset($this->url)) {
         $this->url = suffix(CURRENT_CFURL);
     }
     if ($month === NULL && $year === NULL) {
         if (!is_numeric(URI::segment(-1))) {
             $month = $today['mon'];
         } else {
             $month = URI::segment(-1);
         }
         if (!is_numeric(URI::segment(-2))) {
             $year = $today['year'];
         } else {
             $year = URI::segment(-2);
         }
     } else {
         if (!is_numeric($month)) {
             $month = $today['mon'];
         }
         if (!is_numeric($year)) {
             $year = $today['year'];
         }
     }
     if (isset($_SERVER['HTTP_REFERER'])) {
         $arrays = array_diff(explode('/', prevUrl()), explode('/', currentUrl()));
         $prevMonth = end($arrays);
     } else {
         $prevMonth = $month;
     }
     $monthNamesConfig = VIEWOBJECTS_CALENDAR_CONFIG['monthNames'][getLang()];
     if ($this->monthNames === 'long') {
         $monthNames = array_keys($monthNamesConfig);
     } else {
         $monthNames = array_values($monthNamesConfig);
     }
     $dayNamesConfig = VIEWOBJECTS_CALENDAR_CONFIG['dayNames'][getLang()];
     $monthName = $monthNames[$month - 1];
     $dayNames = $this->dayNames === 'long' ? array_keys($dayNamesConfig) : array_values($dayNamesConfig);
     $firstDay = getdate(mktime(0, 0, 0, $month, 1, $year));
     $lastDay = getdate(mktime(0, 0, 0, $month + 1, 0, $year));
     $tableClass = !empty($this->css['table']) ? ' class="' . $this->css['table'] . '"' : '';
     $tableStyle = !empty($this->style['table']) ? ' style="' . $this->style['table'] . '"' : '';
     $monthRowClass = !empty($this->css['monthName']) ? ' class="' . $this->css['monthName'] . '"' : '';
     $monthRowStyle = !empty($this->style['monthName']) ? ' style="' . $this->style['monthName'] . '"' : '';
     $dayRowClass = !empty($this->css['dayName']) ? ' class="' . $this->css['dayName'] . '"' : '';
     $dayRowStyle = !empty($this->style['dayName']) ? ' style="' . $this->style['dayName'] . '"' : '';
     $rowsClass = !empty($this->css['days']) ? ' class="' . $this->css['days'] . '"' : '';
     $rowsStyle = !empty($this->style['days']) ? ' style="' . $this->style['days'] . '"' : '';
     $buttonClass = !empty($this->css['links']) ? ' class="' . $this->css['links'] . '"' : '';
     $buttonStyle = !empty($this->style['links']) ? ' style="' . $this->style['links'] . '"' : '';
     $eol = EOL;
     $url = suffix($this->url);
     $pcyear = $month == 1 ? $year - 1 : $year;
     $pcmonth = $month - 1 == 0 ? 12 : $month - 1;
     $ncyear = $month == 12 ? $year + 1 : $year;
     $ncmonth = $month + 1 == 13 ? 1 : $month + 1;
     $prevDate = $pcyear . "/" . $pcmonth;
     $nextDate = $ncyear . "/" . $ncmonth;
     if ($this->type === 'ajax') {
         $prevUrl = '#cdate=' . $prevDate;
         $nextUrl = '#cdate=' . $nextDate;
         $prevAttr = ' ctype="ajax" cyear="' . $pcyear . '" cmonth="' . $pcmonth . '"';
         $nextAttr = ' ctype="ajax" cyear="' . $ncyear . '" cmonth="' . $ncmonth . '"';
     } else {
         $prevUrl = $url . $prevDate;
         $nextUrl = $url . $nextDate;
         $prevAttr = '';
         $nextAttr = '';
     }
     $prev = "<a href='" . $prevUrl . "' {$buttonClass}{$buttonStyle}{$prevAttr}>{$this->prev}</a>";
     $next = "<a href='" . $nextUrl . "' {$buttonClass}{$buttonStyle}{$nextAttr}>{$this->next}</a>";
     $str = "<table{$tableClass}{$tableStyle}>" . $eol;
     $str .= "\t<tr>" . $eol . "\t\t<th{$monthRowClass}{$monthRowStyle} colspan=\"7\">{$prev} {$monthName} - {$year} {$next}</th></tr>" . $eol;
     $str .= "\t<tr>" . $eol;
     foreach ($dayNames as $day) {
         $str .= "\t\t<td{$dayRowClass}{$dayRowStyle}>{$day}</td>" . $eol;
     }
     $str .= "\t<tr>" . $eol;
     if ($firstDay['wday'] == 0) {
         $firstDay['wday'] = 7;
     }
     for ($i = 1; $i < $firstDay['wday']; $i++) {
         $str .= "\t\t<td{$rowsClass}{$rowsStyle}>&nbsp;</td>" . $eol;
     }
     $activeDay = 0;
     for ($i = $firstDay['wday']; $i <= 7; $i++) {
         $activeDay++;
         if ($activeDay == $today['mday'] && $year == $today['year'] && $month == $today['mon']) {
             $class = !empty($this->css['current']) ? ' class="' . $this->css['current'] . '"' : '';
             $style = !empty($this->style['current']) ? ' style="' . $this->style['current'] . '"' : '';
         } else {
             $class = !empty($this->css['days']) ? ' class="' . $this->css['days'] . '"' : '';
             $style = !empty($this->style['days']) ? ' style="' . $this->style['days'] . '"' : '';
         }
         $str .= "\t\t<td{$class}{$style}>{$activeDay}</td>" . $eol;
     }
     $str .= "\t</tr>" . $eol;
     $weekCount = floor(($lastDay['mday'] - $activeDay) / 7);
     for ($i = 0; $i < $weekCount; $i++) {
         $str .= "\t<tr>";
         for ($j = 0; $j < 7; $j++) {
             $activeDay++;
             if ($activeDay == $today['mday'] && $year == $today['year'] && $month == $today['mon']) {
                 $class = !empty($this->css['current']) ? ' class="' . $this->css['current'] . '"' : '';
                 $style = !empty($this->style['current']) ? ' style="' . $this->style['current'] . '"' : '';
             } else {
                 $class = !empty($this->css['days']) ? ' class="' . $this->css['days'] . '"' : '';
                 $style = !empty($this->style['days']) ? ' style="' . $this->style['days'] . '"' : '';
             }
             $str .= "\t\t<td{$class}{$style}>{$activeDay}</td>" . $eol;
         }
         $str .= "\t</tr>" . $eol;
     }
     if ($activeDay < $lastDay['mday']) {
         $str .= "\t<tr>" . $eol;
         for ($i = 0; $i < 7; $i++) {
             $activeDay++;
             if ($activeDay == $today['mday']) {
                 $class = !empty($this->css['current']) ? ' class="' . $this->css['current'] . '"' : '';
                 $style = !empty($this->style['current']) ? ' style="' . $this->style['current'] . '"' : '';
             } else {
                 $class = !empty($this->css['days']) ? ' class="' . $this->css['days'] . '"' : '';
                 $style = !empty($this->style['days']) ? ' style="' . $this->style['days'] . '"' : '';
             }
             if ($activeDay <= $lastDay['mday']) {
                 $str .= "\t\t<td{$class}{$style}>{$activeDay}</td>" . $eol;
             } else {
                 $str .= "\t\t<td{$class}{$style}>&nbsp;</td>" . $eol;
             }
         }
         $str .= "\t</tr>" . $eol;
     }
     $str .= "</table>";
     $this->_defaultVariables();
     return $str;
 }
Ejemplo n.º 2
0
//--------------------------------------------------------------------------------------------------
// CURRENT_URL
//--------------------------------------------------------------------------------------------------
//
// @return example.com/aktive
//
//--------------------------------------------------------------------------------------------------
define('CURRENT_URL', currentUrl());
//--------------------------------------------------------------------------------------------------
// PREV_URL
//--------------------------------------------------------------------------------------------------
//
// @return example.com/prev
//
//--------------------------------------------------------------------------------------------------
define('PREV_URL', prevUrl());
//--------------------------------------------------------------------------------------------------
// HOST_URL
//--------------------------------------------------------------------------------------------------
//
// @return hostname
//
//--------------------------------------------------------------------------------------------------
define('HOST_URL', hostUrl());
//--------------------------------------------------------------------------------------------------
// BASE_PATH
//--------------------------------------------------------------------------------------------------
//
// @return example.com/
//
//--------------------------------------------------------------------------------------------------
Ejemplo n.º 3
0
 public function prev() : string
 {
     return prevUrl();
 }