-
Notifications
You must be signed in to change notification settings - Fork 59
/
plugin.datechanger.php
118 lines (92 loc) · 3.64 KB
/
plugin.datechanger.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/*
* Plugin Name: DateChanger
* Plugin URI: https://www.flatpress.org
* Type: Block
* Author: FlatPress
* Description: Allows to change the date and time for <a href="./admin.php?p=entry&action=write" title="Write Entry">new entries</a> via a drop-down menu. Part of the standard distribution. <a href="./fp-plugins/datechanger/doc_datechanger.txt" title="Instructions" target="_blank">[Instructions]</a>
* Version: 1.0.5
* Author URI: https://www.flatpress.org
*/
if (!(basename($_SERVER ['PHP_SELF']) == 'admin.php' && // must be admin area
@$_GET ['p'] == 'entry' && // must be right panel
@$_GET ['action'] == 'write' && // must be right action
!(@$_POST ['timestamp'] || @$_REQUEST ['entry']))) // must be a new entry
return;
function plugin_datechanger_toolbar() {
// $time = time();
// use UTC + timeoffset, coe.date.php. line 64
$time = date_time();
$h = date('H', $time);
$m = date('i', $time);
$s = date('s', $time);
$Y = date('Y', $time);
$M = date('m', $time);
$D = date('d', $time);
$lang = lang_load('plugin:datechanger'); // Multilingual support by Plugin
global $lang; // Multilingual support by FlatPress
echo '<div id="admin-date"><fieldset id="plugin_datechanger"><legend>' . $lang ['admin'] ['plugin'] ['datechanger'] ['title'] . '</legend><p>' . $lang ['admin'] ['plugin'] ['datechanger'] ['time'] . ': ';
// set time
echo '<label><select name="date[]">';
for($i = 0; $i < 24; $i++) {
$v = sprintf('%02d', $i);
echo '<option value="' . $v . '"' . (($v == $h) ? ' selected="selected"' : '') . '>' . $v . '</option>';
}
echo '</select></label>:';
echo '<label><select name="date[]">';
for($i = 0; $i < 60; $i++) {
$v = sprintf('%02d', $i);
echo '<option value="' . $v . '"' . (($v == $m) ? ' selected="selected"' : '') . '>' . $v . '</option>';
}
echo '</select></label>:';
echo '<label><select name="date[]">';
for($i = 0; $i < 60; $i++) {
$v = sprintf('%02d', $i);
echo '<option value="' . $v . '"' . (($v == $s) ? ' selected="selected"' : '') . '>' . $v . '</option>';
}
echo '</select> </label> ';
// set date
echo '' . $lang ['admin'] ['plugin'] ['datechanger'] ['date'] . ': <select name="date[]">';
for($i = 1; $i <= 31; $i++) {
$v = sprintf('%02d', $i);
echo '<option value="' . $v . '"' . (($v == $D) ? ' selected="selected"' : '') . '>' . $v . '</option>';
}
echo '</select> ';
$mths = $lang ['date'] ['month'];
echo '<select name="date[]">';
for($i = 0; $i < 12; $i++) {
$v = sprintf('%02d', $i + 1);
echo '<option value="' . $v . '"' . (($v == $M) ? ' selected="selected"' : '') . '>' . $mths [$i] . '</option>';
}
echo '</select> ';
echo '<select name="date[]">';
foreach (range(2000, intval($Y) + 10) as $v) {
echo '<option value="' . $v . '"' . (($v == $Y) ? ' selected="selected"' : '') . '>' . $v . '</option>';
}
echo '</select>';
echo '</p></fieldset></div><!-- end of #admin-date -->';
}
// Meh, {toolbar} no longer works with fp-1.3 dev -> #17
//add_action('editor_toolbar', 'plugin_datechanger_toolbar', 0);
add_filter('simple_datechanger_form', 'plugin_datechanger_toolbar', 0);
function plugin_datechanger_check() {
if ((isset($_GET ['p']) && $_GET ['p'] != 'entry') || (isset($_GET ['action']) && $_GET ['action'] != 'write'))
return;
if (empty($_POST))
return;
if (!empty($_POST ['date']))
$date = $_POST ['date'];
else
return;
foreach ($date as $v) {
if (!is_numeric($v))
return;
else
$date [] = intval($v);
}
list ($hour, $minute, $second, $day, $month, $year) = $date;
$time = mktime($hour, $minute, $second, $month, $day, $year);
$_POST ['timestamp'] = $time;
}
add_action('init', 'plugin_datechanger_check');
?>