-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpubdatefix.php
More file actions
130 lines (112 loc) · 4.34 KB
/
Copy pathpubdatefix.php
File metadata and controls
130 lines (112 loc) · 4.34 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/*
PubDateFix - plugin for GetSimple CMS (3.1+)
Makes GS page date field fixed (and editable), plus new replacement lastUpdate field
Helper functions / template tags:
- get_page_lastupdate([dateformat])
- return_page_lastupdate([dateformat])
(they work exactly like GetSimple's get_page_date() and return_page_date()
when this plugin is not installed)
A new editable Publication Date field is displayed in page options.
If the date/time entered is invalid, is will be saved as the current datetime ("now").
Default date[time] editing format is 'Y-m-d H:i' (for e.g. 2015-12-31 23:59)
You can define your custom format in your site's gsconfig.php file.
Some examples:
define('PUBDATEFORMAT','Y/m/d H.i'); // ==> 2015/12/31 23.59
define('PUBDATEFORMAT','Y-m-d'); // ==> 2015-12-31
...
To disable the datepicker, insert this in gsconfig.php:
define('PUBDATEPICKER', false);
(jQuery DateTimePicker by XDSoft <http://xdsoft.net/jqplugins/datetimepicker/>)
*/
define('PUBDATEFIXVERSION', '0.3');
// register plugin
$thisfile = basename(__FILE__, ".php");
register_plugin(
$thisfile,
'pubDateFix',
PUBDATEFIXVERSION,
'Carlos Navarro',
'http://www.cyberiada.org/cnb/',
'Makes pubDate field fixed and editable (with date/time picker), adds lastUpdate field'
);
add_action('changedata-save', 'pubdatefix_save');
if (basename($_SERVER['PHP_SELF']) == 'edit.php') {
i18n_merge($thisfile, $LANG) || (strlen($LANG) > 2 && i18n_merge($thisfile, substr($LANG,0,2))) || i18n_merge($thisfile, 'en');
add_action('edit-extras','pubdatefix_edit');
if ((!defined('PUBDATEPICKER') || PUBDATEPICKER) && function_exists('register_script')) { // GS 3.1+
register_script('jquery-datetimepicker', $SITEURL.'plugins/pubdatefix/js/jquery.datetimepicker.js', '2.3.2', false);
queue_script('jquery-datetimepicker', GSBACK);
register_style('jquery-datetimepicker', $SITEURL.'plugins/pubdatefix/css/jquery.datetimepicker.css', PUBDATEFIXVERSION, 'screen');
queue_style('jquery-datetimepicker', GSBACK);
add_action('footer', 'pubdatefix_footer');
}
}
function get_page_lastupdate($i = "l, F jS, Y - g:i A") {
echo return_page_lastupdate($i);
}
function return_page_lastupdate($i = "l, F jS, Y - g:i A") {
global $data_index;
global $TIMEZONE;
if ($TIMEZONE != '') {
if (function_exists('date_default_timezone_set')) {
date_default_timezone_set($TIMEZONE);
}
}
if (isset($data_index->lastUpdate)) {
return date($i, strtotime($data_index->lastUpdate));
} else {
return date($i, strtotime($data_index->pubDate));
}
}
function pubdatefix_save() {
global $xml;
if (isset($_POST['pubdatefix']) && strval(strtotime($_POST['pubdatefix']))!='') {
unset($xml->pubDate);
$xml->addChild('pubDate', date('r',strtotime($_POST['pubdatefix'])));
}
$xml->addChild('lastUpdate', date('r')); // now
}
function pubdatefix_edit() {
global $data_edit;
$format = pubdatefix_format();
echo '<div class="leftopt"><p>';
echo '<label for="pubdatefix">',i18n_r('pubdatefix/PUBDATE'),':</label>';
echo '<input class="text short" id="pubdatefix" name="pubdatefix" type="text" value="';
if (isset($data_edit->pubDate)) { echo date($format, strtotime($data_edit->pubDate)); }
echo '" placeholder="',date($format, strtotime(date('r'))),'" />';
echo '</p></div>';
echo '<div class="clear"></div>';
// backend last saved:
global $pubDate;
if (isset($data_edit->lastUpdate)) {
$pubDate = $data_edit->lastUpdate;
} else {
if (isset($data_edit->pubDate)) {
$pubDate = $data_edit->pubDate;
}
}
}
function pubdatefix_format() {
return defined('PUBDATEFORMAT') ? PUBDATEFORMAT : 'Y-m-d H:i';
}
function pubdatefix_footer() {
global $LANG;
$lg = substr($LANG, 0, 2);
if (in_array($lg, array('fi','sk', 'bg','ch','cs','da','de','el','es','fr','hu','it','nl','no','pl','pt','ru','se','sl','tr','vi')))
$start = 1; // week starts on Monday
else
$start = 0; // Sunday
if (!in_array($lg, array('bg','ch','cs','da','de','el','en','es','fa','fr','hu','it','ja','kr','nl','no','pl','pt','ru','se','sl','th','tr','vi')))
$lg = 'en'; // fallback to English if not supported by datetimepicker
$format = pubdatefix_format();
?>
<script type="text/javascript">
jQuery('#pubdatefix').datetimepicker({
format:'<?php echo $format; ?>',
lang:'<?php echo $lg; ?>',
dayOfWeekStart: <?php echo $start; ?>
});
</script>
<?php
}