136
|
1 |
<?php |
|
2 |
/* |
|
3 |
Copyright (c) 2008, Alex Tingle. |
|
4 |
|
|
5 |
This program is free software; you can redistribute it and/or |
|
6 |
modify it under the terms of the GNU General Public License |
|
7 |
as published by the Free Software Foundation; either version 2 |
|
8 |
of the License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU General Public License |
|
16 |
along with this program; if not, write to the Free Software |
|
17 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 |
*/ |
|
19 |
|
|
20 |
/** Only include this file if a database upgrade is called for. |
|
21 |
* Otherwise it can be safely ignored. */ |
|
22 |
function ec3_upgrade_posts() |
|
23 |
{ |
|
24 |
global $ec3,$post,$wpdb; |
|
25 |
$ec3->advanced=false; |
|
26 |
$changed = ec3_upgrade_posts_apply(); |
|
27 |
|
|
28 |
$query =& new WP_Query(); |
|
29 |
$query->query( 'nopaging=1&cat=' . $ec3->event_category ); |
|
30 |
|
|
31 |
$format = 'Y-m-d H:i:s'; |
|
32 |
$now = time(); |
|
33 |
$rownum = 0; |
|
34 |
?> |
|
35 |
|
|
36 |
<?php if($changed): ?> |
|
37 |
|
|
38 |
<div id="message" class="updated fade"><p><strong> |
|
39 |
<?php if($changed==1) _e('Post upgraded.','ec3') ?> |
|
40 |
<?php if($changed>1) echo sprintf(__('%d posts upgraded.','ec3'),$changed) ?> |
|
41 |
</strong></p></div> |
|
42 |
|
|
43 |
<?php endif ?> |
|
44 |
|
|
45 |
<div class="wrap"> |
|
46 |
<form method="post"> |
|
47 |
<h2><?php _e('Upgrade Event Posts (from version 3.0)','ec3'); ?></h2> |
|
48 |
|
|
49 |
<?php if($query->have_posts()): ?> |
|
50 |
|
|
51 |
<input type="hidden" name="ec3_action" value="upgrade_posts" /> |
|
52 |
<table class="widefat"> |
|
53 |
|
|
54 |
<thead> |
|
55 |
<tr> |
|
56 |
<th scope="col">OK</th> |
|
57 |
<th scope="col">Title</th> |
|
58 |
<th scope="col">Post date</th> |
|
59 |
<th scope="col">Event date</th> |
|
60 |
</tr> |
|
61 |
</thead> |
|
62 |
|
|
63 |
<?php while($query->have_posts()): $query->the_post(); ?> |
|
64 |
|
|
65 |
<?php if(empty($post->ec3_schedule)): |
|
66 |
$post_date = get_post_time(); |
|
67 |
$post_modified_date = get_post_modified_time(); |
|
68 |
$rownum++; |
|
69 |
if($rownum % 2) |
|
70 |
{ |
|
71 |
$rowclass='alternate '; |
|
72 |
} |
|
73 |
else |
|
74 |
{ |
|
75 |
$rowclass=''; |
|
76 |
} |
|
77 |
|
|
78 |
if($post_modified_date >= $now) |
|
79 |
{ |
|
80 |
$errstyle='background-color:#fcc'; |
|
81 |
} |
|
82 |
else |
|
83 |
{ |
|
84 |
$errstyle=''; |
|
85 |
} |
|
86 |
?> |
|
87 |
|
|
88 |
<tr class="<?php echo $rowclass ?>"> |
|
89 |
<td> |
|
90 |
<input type="checkbox" name="ec3_upgrade_<?php the_ID() ?>" |
|
91 |
value="1" checked="checked" /> |
|
92 |
</td> |
|
93 |
<td title="Post ID: <?php the_ID() ?>"> |
|
94 |
<a target="_blank" href="<?php the_permalink() ?>"> |
|
95 |
<?php the_title() ?> |
|
96 |
</a> |
|
97 |
</td> |
|
98 |
<td> |
|
99 |
<input type="text" name="ec3_postdate_<?php the_ID() ?>" |
|
100 |
style="<?php echo $errstyle ?>" |
|
101 |
value="<?php echo date($format,$post_modified_date) ?>" /> |
|
102 |
</td> |
|
103 |
<td> |
|
104 |
<input type="text" name="ec3_eventdate_<?php the_ID() ?>" |
|
105 |
value="<?php echo date($format,$post_date) ?>" /> |
|
106 |
</td> |
|
107 |
</tr> |
|
108 |
|
|
109 |
<?php endif ?> |
|
110 |
<?php endwhile ?> |
|
111 |
<?php if($rownum==0): ?> |
|
112 |
|
|
113 |
<tr><td>No posts to upgrade.</td></tr> |
|
114 |
|
|
115 |
<?php endif ?> |
|
116 |
|
|
117 |
</table> |
|
118 |
|
|
119 |
<p class="submit"> |
|
120 |
|
|
121 |
<?php if($rownum>0): ?> |
|
122 |
|
|
123 |
<input type="submit" name="ec3_upgrade_posts" |
|
124 |
value="<?php _e('Upgrade Event Posts','ec3') ?>" /> |
|
125 |
<input type="submit" name="ec3_cancel_upgrade" |
|
126 |
value="<?php _e("Don't Upgrade Posts") ?>" /> |
|
127 |
|
|
128 |
<?php else: update_option('ec3_upgrade_posts',0) ?> |
|
129 |
|
|
130 |
<input type="submit" name="ec3_cancel_upgrade" |
|
131 |
value="<?php _e('OK') ?> »" /> |
|
132 |
|
|
133 |
<?php endif ?> |
|
134 |
|
|
135 |
</p> |
|
136 |
|
|
137 |
<?php endif ?> |
|
138 |
|
|
139 |
</form> |
|
140 |
</div> |
|
141 |
|
|
142 |
<?php |
|
143 |
|
|
144 |
} |
|
145 |
|
|
146 |
|
|
147 |
/** Process results from the 'ec3_upgrade_posts' form. */ |
|
148 |
function ec3_upgrade_posts_apply() |
|
149 |
{ |
|
150 |
if(!isset($_POST) || |
|
151 |
!isset($_POST['ec3_action']) || |
|
152 |
$_POST['ec3_action']!='upgrade_posts') |
|
153 |
{ |
|
154 |
return; |
|
155 |
} |
|
156 |
|
|
157 |
global $ec3,$wpdb; |
|
158 |
|
|
159 |
$changed_count=0; |
|
160 |
|
|
161 |
// Find all of our parameters |
|
162 |
$sched_entries=array(); |
|
163 |
$fields =array('postdate','eventdate'); |
|
164 |
foreach($_POST as $k => $v) |
|
165 |
{ |
|
166 |
if(preg_match('/^ec3_(upgrade|'.implode('|',$fields).')_(_?)([0-9]+)$/',$k,$match)) |
|
167 |
{ |
|
168 |
$pid=intval($match[3]); |
|
169 |
if(!isset( $sched_entries[$pid] )) |
|
170 |
$sched_entries[ $pid ]=array(); |
|
171 |
$sched_entries[ $pid ][ $match[1] ] = $v; |
|
172 |
} |
|
173 |
} |
|
174 |
|
|
175 |
foreach($sched_entries as $pid => $vals) |
|
176 |
{ |
|
177 |
if(empty($vals['upgrade']) || |
|
178 |
empty($vals['postdate']) || |
|
179 |
empty($vals['eventdate']) ) |
|
180 |
{ |
|
181 |
continue; |
|
182 |
} |
|
183 |
$postdate = "'".$wpdb->escape($vals['postdate'])."'"; |
|
184 |
$eventdate = "'".$wpdb->escape($vals['eventdate'])."'"; |
|
185 |
$cnt=$wpdb->get_var( |
|
186 |
"SELECT COUNT(0) FROM $ec3->schedule |
|
187 |
WHERE post_id=$pid"); |
|
188 |
if(!empty($cnt)) |
|
189 |
continue; |
|
190 |
// Create a schedule record. |
|
191 |
$wpdb->query( |
|
192 |
"INSERT INTO $ec3->schedule (post_id,start,end,allday,rpt) |
|
193 |
VALUES ($pid,$eventdate,$eventdate,0,'')" |
|
194 |
); |
|
195 |
// Modify the post date. |
|
196 |
$wpdb->query( |
|
197 |
"UPDATE $wpdb->posts |
|
198 |
SET post_date=$postdate, post_date_gmt=$postdate |
|
199 |
WHERE ID=$pid" |
|
200 |
); |
|
201 |
$changed_count++; |
|
202 |
} |
|
203 |
return $changed_count; |
|
204 |
} |
|
205 |
|
|
206 |
?> |