-
Notifications
You must be signed in to change notification settings - Fork 0
/
redevents.php
443 lines (370 loc) · 14.6 KB
/
redevents.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
<?php
/*
Plugin Name: Redelivre Events
Version: 1.0
Plugin URI: https://github.com/redelivre/redevents
Description: Plugin for manage some events
Group: Rede Livre
Author: Maurilio Atila
Author URI: http://cabelotaina.github.io
Developer: https://github.com/cabelotaina
Text Domain: redevents
Domain Path: /languages/
References: http://www.noeltock.com/web-design/wordpress/custom-post-types-events-pt1/, http://www.noeltock.com/web-design/wordpress/how-to-custom-post-types-for-events-pt-2/
*/
require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'wp-divi'. DIRECTORY_SEPARATOR .'modules.php';
class Redevents {
public function __construct(){
add_action( 'init', array( $this , 'create_event_postype' ) );
//add_action( 'init', array( $this , 'create_eventcategory_taxonomy'));
add_filter( 'manage_edit-tf_events_columns', array( $this , 'tf_events_edit_columns' ) );
add_action( 'manage_posts_custom_column', array( $this , 'tf_events_custom_columns') );
add_action( 'admin_init', array( $this , 'tf_events_create' ) );
add_action( 'save_post', array( $this, 'save_tf_events' ) );
add_filter( 'post_updated_messages', array( $this, 'events_updated_messages' ) );
add_action( 'admin_print_styles-post.php', array( $this , 'events_styles' ), 1000 );
add_action( 'admin_print_styles-post-new.php', array( $this , 'events_styles' ), 1000 );
add_action( 'admin_print_scripts-post.php', array( $this , 'events_scripts' ), 1000 );
add_action( 'admin_print_scripts-post-new.php', array( $this , 'events_scripts' ), 1000 );
add_filter("the_content", array( $this , 'the_meta' ) );
}
function the_meta($content){
global $post_type;
global $post;
if( 'tf_events' == $post_type ){
$custom_fields = get_post_custom();
$new_content = "<br>";
foreach ( $custom_fields as $key => $value ) {
if($key == "tf_events_startdate" or $key == "tf_events_enddate"){
$value[0] = date("d-m-Y H:i", $value[0]);
}
if($key == "tf_events_startdate")
$key = "Data de Inicio";
if ($key == "tf_events_enddate") {
$key = "Data de Termino";
}
if ($key == "tf_events_city") {
$key = "Cidade";
}
if ($key == "tf_events_state") {
$key = "Estado";
}
if ($key == "_edit_last" or $key == "_edit_lock" or $key == "upload_file") {
continue;
}
$new_content .= "<label>" . $key . "</label>" . ": " . $value[0] . "<br />";
}
return $content.$new_content;
}
return $content;
}
function create_event_postype(){
$labels = array(
'name' => _x('Eventos', 'redevents'),
'singular_name' => _x('Evento', 'redevents'),
'add_new' => _x('Adicionar Novo', 'redevents'),
'add_new_item' => __('Adicionar Novo Evento', 'redevents'),
'edit_item' => __('Editar Evento', 'redevents'),
'new_item' => __('Novo Evento', 'redevents'),
'view_item' => __('Vizualizar Evento', 'redevents'),
'search_items' => __('Buscar Eventos', 'redevents'),
'not_found' => __('Nenhum evento encontrado', 'redevents'),
'not_found_in_trash' => __('Nenhum evento encontrado na Lixeira', 'redevents'),
'parent_item_colon' => '',
);
$args = array(
'label' => __('Eventos'),
'labels' => $labels,
'public' => true,
'can_export' => true,
'show_ui' => true,
'_builtin' => false,
'capability_type' => 'post',
'menu_icon' => 'dashicons-calendar',
'hierarchical' => false,
'rewrite' => array( "slug" => "events" ),
'supports'=> array('title', 'thumbnail', 'excerpt', 'editor') ,
'show_in_nav_menus' => true,
'taxonomies' => array( 'tf_eventcategory', 'post_tag')
);
register_post_type( 'tf_events', $args);
$labels = array(
'name' => _x( 'Categorias', 'taxonomy general name' ),
'singular_name' => _x( 'Categoria', 'taxonomy singular name' ),
'search_items' => __( 'Buscar Categorias' ),
'popular_items' => __( 'Popular Categorias' ),
'all_items' => __( 'Todas as Categorias' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Editar Categoria' ),
'update_item' => __( 'Atualizar Categoria' ),
'add_new_item' => __( 'Adicionar Nova Categoria' ),
'new_item_name' => __( 'Novo Nome de Categoria' ),
'separate_items_with_commas' => __( 'Separar categorias com virgulas' ),
'add_or_remove_items' => __( 'Adicionar ou remover categorias' ),
'choose_from_most_used' => __( 'Escolher das categorias mais usadas' ),
);
register_taxonomy('tf_eventcategory','tf_events', array(
'label' => __('Categoria dos Eventos'),
'labels' => $labels,
'hierarchical' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'event-category' ),
));
}
function tf_events_edit_columns($columns) {
$columns = array(
"cb" => "<input type=\"checkbox\" />",
"title" => "Evento",
"tf_col_ev_cat" => "Categoria",
"tf_col_ev_date" => "Data",
"tf_col_ev_times" => "Horas",
"tf_col_ev_city" => "Cidade",
"tf_col_ev_state" => "Estado",
//"tf_col_ev_thumb" => "Thumbnail",
//"tf_col_ev_desc" => "Description",
);
return $columns;
}
function tf_events_custom_columns($column)
{
global $post;
$custom = get_post_custom();
switch ($column)
{
case "tf_col_ev_desc";
the_excerpt();
break;
case "tf_col_ev_cat":
// - show taxonomy terms -
$eventcats = get_the_terms($post->ID, "tf_eventcategory");
$eventcats_html = array();
if ($eventcats) {
foreach ($eventcats as $eventcat)
array_push($eventcats_html, $eventcat->name);
echo implode($eventcats_html, ", ");
} else {
_e('None', 'themeforce');;
}
break;
case "tf_col_ev_date":
// - show dates -
$startd = $custom["tf_events_startdate"][0];
$endd = $custom["tf_events_enddate"][0];
$startdate = date("F j, Y", $startd);
$enddate = date("F j, Y", $endd);
echo $startdate . '<br /><em>' . $enddate . '</em>';
break;
case "tf_col_ev_city":
// - show dates -
$city = $custom["tf_events_city"][0];
echo '<em>' . $city . '</em>';
break;
case "tf_col_ev_state":
// - show dates -
$state = $custom["tf_events_state"][0];
echo '<em>' . $state . '</em>';
break;
case "tf_col_ev_times":
// - show times -
$startt = $custom["tf_events_startdate"][0];
$endt = $custom["tf_events_enddate"][0];
$time_format = get_option('time_format');
$starttime = date($time_format, $startt);
$endtime = date($time_format, $endt);
echo $starttime . ' - ' .$endtime;
break;
case "tf_col_ev_thumb":
// - show thumb -
$post_image_id = get_post_thumbnail_id(get_the_ID());
if ($post_image_id) {
$thumbnail = wp_get_attachment_image_src( $post_image_id, 'post-thumbnail', false);
if ($thumbnail) (string)$thumbnail = $thumbnail[0];
echo '<img src="';
echo bloginfo('template_url');
echo '/timthumb/timthumb.php?src=';
echo $thumbnail;
echo '&h=60&w=60&zc=1" alt="" />';
}
break;
}
}
function tf_events_create() {
add_meta_box('tf_events_meta', 'Eventos', array( $this , 'tf_events_meta' ), 'tf_events');
}
function tf_events_meta () {
// - grab data -
global $post;
$custom = get_post_custom($post->ID);
if (array_key_exists('tf_events_startdate', $custom)){
$meta_sd = $custom["tf_events_startdate"][0];
$meta_st = $meta_sd;
}
else{
$meta_sd = null;
}
if (array_key_exists('tf_events_enddate', $custom)){
$meta_ed = $custom["tf_events_enddate"][0];
$meta_et = $meta_ed;
}
if (array_key_exists('tf_events_city', $custom)){
$city = $custom["tf_events_city"][0];
}
else{
$city = "";
}
if (array_key_exists('tf_events_state', $custom)){
$state = $custom["tf_events_state"][0];
}
else{
$state = "";
}
// - grab wp time format -
$time_format = get_option('time_format');
// - populate today if empty, 00:00 for time -
if ($meta_sd == null) { $meta_sd = time(); $meta_ed = $meta_sd; $meta_st = 0; $meta_et = 0;}
// - convert to pretty formats -
$clean_sd = date("D, M d, Y", $meta_sd);
$clean_ed = date("D, M d, Y", $meta_ed);
$clean_st = date($time_format, $meta_st);
$clean_et = date($time_format, $meta_et);
// - security -
echo '<input type="hidden" name="tf-events-nonce" id="tf-events-nonce" value="' .
wp_create_nonce( 'tf-events-nonce' ) . '" />';
// - output -
?>
<div class="tf-meta">
<ul>
<li><label>Data de Inicio</label>
<p><input name="tf_events_startdate" class="tfdate" value="<?php echo $clean_sd; ?>" /></p>
</li>
<li><label>Horario de Inicio</label>
<p><input name="tf_events_starttime" value="<?php echo $clean_st; ?>" /></p>
<em>Use o formato de 24h</em>
</li>
<li><label>Data de Termino</label>
<p><input name="tf_events_enddate" class="tfdate" value="<?php echo $clean_ed; ?>" /></p>
</li>
<li><label>Horario de Termino</label>
<p><input name="tf_events_endtime" value="<?php echo $clean_et; ?>" /></p><em>Use o formato de 24h</em>
</li>
<li><label>Cidade</label>
<p><input name="tf_events_city" value="<?php echo $city; ?>" /></p>
</li>
<?php
$state_labels = array("Acre",
"Alagoas",
"Amapá",
"Amazonas",
"Bahia",
"Ceará",
"Distrito Federal",
"Espírito Santo",
"Goiás",
"Maranhão",
"Mato Grosso",
"Mato Grosso do Sul",
"Minas Gerais",
"Pará",
"Paraíba",
"Paraná",
"Pernambuco",
"Piauí",
"Rio de Janeiro",
"Rio Grande do Norte",
"Rio Grande do Sul",
"Rondônia",
"Roraima",
"Santa Catarina",
"São Paulo",
"Sergipe",
"Tocantins");
?>
<p>Estado:
<select name="tf_events_state">
<?php
foreach ($state_labels as $state_data) {?>
<option <?php echo (($state==$state_data)?"selected":""); ?>
value="<?php echo $state_data; ?>">
<?php echo $state_data;?>
</option>';
<?php } ?>
?>
</select>
</p>
</ul>
</div>
<?php
}
function save_tf_events(){
global $post;
if ($post == null)
return;
// - still require nonce
if ( !wp_verify_nonce( $_POST['tf-events-nonce'], 'tf-events-nonce' )) {
return $post->ID;
}
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
// - convert back to unix & update post
if(!isset($_POST["tf_events_startdate"])):
return $post;
endif;
$updatestartd = strtotime ( $_POST["tf_events_startdate"] . $_POST["tf_events_starttime"] );
update_post_meta($post->ID, "tf_events_startdate", $updatestartd );
if(!isset($_POST["tf_events_enddate"])):
return $post;
endif;
$updateendd = strtotime ( $_POST["tf_events_enddate"] . $_POST["tf_events_endtime"]);
update_post_meta($post->ID, "tf_events_enddate", $updateendd );
if(!isset($_POST["tf_events_city"])):
return $post;
endif;
$city = isset($_POST["tf_events_city"])? $_POST["tf_events_city"]: "";
update_post_meta($post->ID, "tf_events_city", $city);
if(!isset($_POST["tf_events_state"])):
return $post;
endif;
$city = isset($_POST["tf_events_state"])? $_POST["tf_events_state"]: "";
update_post_meta($post->ID, "tf_events_state", $city);
}
function events_updated_messages( $messages ) {
global $post, $post_ID;
$messages['tf_events'] = array(
0 => '', // Unused. Messages start at index 1.
1 => sprintf( __('Evento atualizado. <a href="%s">View item</a>'), esc_url( get_permalink($post_ID) ) ),
2 => __('Campo personalizado atualizado.'),
3 => __('Campo personalizado removido.'),
4 => __('Evento atualizado.'),
/* translators: %s: date and time of the revision */
5 => isset($_GET['revision']) ? sprintf( __('Evento recuperado para revisão de %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __('Evento publicado. <a href="%s">View event</a>'), esc_url( get_permalink($post_ID) ) ),
7 => __('Evento salvo.'),
8 => sprintf( __('Evento submetido. <a target="_blank" href="%s">Previsualizar evento</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
9 => sprintf( __('Evento agendado para: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Previsualizar evento</a>'),
// translators: Publish box date format, see http://php.net/date
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __('Rascunho de Evento atualizado. <a target="_blank" href="%s">Previsualizar Evento</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
return $messages;
}
function events_styles() {
global $post_type;
if( 'tf_events' != $post_type )
return;
wp_enqueue_style('ui-datepicker', plugin_dir_url( __FILE__ ) . 'css/jquery-ui-1.8.9.custom.css');
wp_enqueue_style('ui-datepicker', plugin_dir_url( __FILE__ ) . 'css/tf-functions.css');
}
function events_scripts() {
global $post_type;
if( 'tf_events' != $post_type )
return;
wp_enqueue_script('jquery-ui', plugin_dir_url( __FILE__ ) . 'js/jquery-ui-1.8.9.custom.min.js', array('jquery'));
wp_enqueue_script('ui-datepicker', plugin_dir_url( __FILE__ ) . 'js/jquery.ui.datepicker.js');
wp_enqueue_script('custom_script', plugin_dir_url( __FILE__ ) .'js/pubforce-admin.js', array('jquery'));
}
}
global $Redevents;
$Redevents = new Redevents();
?>