-
Notifications
You must be signed in to change notification settings - Fork 2
/
snippet.adate.php
97 lines (83 loc) · 2.21 KB
/
snippet.adate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/*
** aDate - snippet
**
** example: [[aDate? &date=`[+pub_date+]` &alterDate=`[+createdon+]` &tpl=`news-date-Tpl` &monthFormat=`2` &Uppercase=`1` &lang=`en`]]
**
** template: chunk or @CODE
** &date or &alterDate parametre is required
**
*/
if(!defined('MODX_BASE_PATH')){die('What are you doing? Get out of here!');}
if (!extension_loaded('mbstring') ) {die('Snippet aDate requires extention mbstring!');}
require_once ('assets/snippets/adate/classes/adate.class.php');
$aDate = new aDate();
$output = '';
$tpl = isset($tpl) ? $tpl : '@CODE:[+day+].[+month+].[+year+] [+hour+].[+minute+].[+second+]';
$template = $aDate->getTemplate($tpl);
/* Language parameter
** Format en, ru etc.
** default ru
*/
$lang = isset($lang) ? $lang : 'ru';
/* Uppercase parameter
** 0 - default
** 1 - first letter to uppercase
** 2 - all letters to uppercase
*/
$Uppercase = isset($Uppercase) ? $Uppercase : 0;
/* Month Format
** default is 1 - returns numeric value of the month
** 2 - returns the month name in format: 'January';
** 3 - returns the month name in short format: 'Jan';
*/
$monthFormat = isset($monthFormat) ? $monthFormat : 1;
$langPath = 'assets/snippets/adate/lang/';
$format = "%d.%m.%Y.%H.%M.%S";
if (!empty($date) && $date > 0)
{
$date = strftime($format,$date);
}else{
$date = strftime($format,$alterDate);
}
$date = explode(".", $date);
$day = $date[0];
$month = $date[1];
$year = $date[2];
$hour = $date[3];
$minute = $date[4];
$second = $date[5];
/* Month Format and Translation*/
switch($monthFormat)
{
case 2:
require($langPath.$lang.'.php');
$month = str_replace($numeric, $alfabetic, $month);
break;
case 3:
require($langPath.$lang.'.php');
$month = str_replace($numeric, $alfabetic_short, $month);
break;
}
/* Uppercase*/
switch($Uppercase)
{
/*First letter to uppercase*/
case '1':
$month = $aDate->ucfirst_utf8($month);
break;
/*All letters to uppercase*/
case '2':
$month = mb_strtoupper($month, 'utf-8');
break;
}
$output = $modx->parseText($template, array(
'day' => $day,
'month' => $month,
'year' => $year,
'hour' => $hour,
'minute' => $minute,
'second' => $second
), '[+', '+]' );
return $output;
?>