forked from hacklabcbba/Ciudadania-Activa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
1521 lines (1351 loc) · 50.7 KB
/
functions.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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// theme setup main function
add_action( 'after_setup_theme', 'quincem_theme_setup' );
function quincem_theme_setup() {
// theme global vars
if (!defined('QUINCEM_BLOGNAME'))
define('QUINCEM_BLOGNAME', get_bloginfo('name'));
if (!defined('QUINCEM_BLOGDESC'))
define('QUINCEM_BLOGDESC', get_bloginfo('description','display'));
if (!defined('QUINCEM_BLOGURL'))
define('QUINCEM_BLOGURL', get_bloginfo('url'));
if (!defined('QUINCEM_BLOGTHEME'))
define('QUINCEM_BLOGTHEME', get_bloginfo('template_directory'));
/* Set up media options: sizes, featured images... */
add_action( 'init', 'quincem_media_options' );
add_filter( 'image_size_names_choose', 'quincem_custom_sizes' );
/* Load JavaScript files on the 'wp_enqueue_scripts' action hook. */
add_action( 'wp_enqueue_scripts', 'quincem_load_scripts' );
// Custom post types
add_action( 'init', 'quincem_create_post_type', 0 );
// Extra meta boxes in editor
add_filter( 'cmb_meta_boxes', 'quincem_metaboxes' );
// Initialize the metabox class
add_action( 'init', 'quincem_init_metaboxes', 9999 );
// excerpt support in pages
add_post_type_support( 'page', 'excerpt' );
// add page order to itinerarios
add_post_type_support( 'itinerarios', 'page-attributes' );
add_post_type_support( 'badge', 'page-attributes' );
// disable admin bar in front end
add_filter('show_admin_bar', '__return_false');
// adding classes to post_class()
add_filter('post_class', 'quincem_classes');
//add_action('wp_insert_post', 'quincem_write_badge_metadata');
add_action('save_post', 'quincem_write_badge_metadata',9999);
//add_action('wp_insert_post', 'quincem_write_earner_metadata');
add_action('draft_to_publish', 'quincem_earner_admited');
//add_action('wp_insert_post', 'quincem_write_badge_metadata');
add_action('save_post', 'quincem_write_issuer_metadata',9999);
// Enable support for Post Formats.
add_theme_support( 'post-formats', array(
'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio', 'chat'
) );
// register and init widget bars
add_action( 'widgets_init', 'quincem_widgets_init' );
// Add post types to api
add_action( 'init', 'quincem_api_post_type_support', 25 );
} // end quincem theme setup function
// register and init widget bars
function quincem_widgets_init() {
register_sidebar( array(
'name' => 'Barra lateral derecha del blog',
'id' => 'blog_right',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-tit"><span class="glyphicon glyphicon-star"></span> ',
'after_title' => '</h2>',
) );
}
// set up media options
function quincem_media_options() {
/* Add theme support for post thumbnails (featured images). */
add_theme_support( 'post-thumbnails', array( 'post','page','badge','itinerario','actividad','earner','issuer') );
// add icon and extra sizes
add_image_size( 'icon', '32', '32', true );
add_image_size( 'bigicon', '48', '48', true );
add_image_size( 'small', '234', '0', false );
add_image_size( 'larger', '672', '0', false );
add_image_size( 'extralarge', '819', '0', false );
/* set up image sizes*/
update_option('thumbnail_size_w', 117);
update_option('thumbnail_size_h', 0);
update_option('medium_size_w', 351);
update_option('medium_size_h', 0);
update_option('large_size_w', 468);
update_option('large_size_h', 0);
} // end set up media options
function quincem_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'icon' => __('Icon'),
'small' => __('Small'),
'larger' => __('Larger'),
'extralarge' => __('Extra Large'),
) );
}
// load js scripts to avoid conflicts
function quincem_load_scripts() {
wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/bootstrap/css/bootstrap.min.css' );
wp_enqueue_style( 'bootstrap-theme-css', get_template_directory_uri() . '/bootstrap/css/bootstrap-theme.min.css' );
wp_enqueue_style( 'fontsquirrel-css', get_template_directory_uri() . '/fonts/stylesheet.css' );
wp_enqueue_script('jquery');
wp_enqueue_script(
'bootstrap-js',
get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js',
array( 'jquery' ),
'3.1.1',
FALSE
);
if ( is_front_page() ) {
wp_enqueue_script(
'smooth-scroll-js',
get_template_directory_uri() . '/js/smooth.scroll.js',
array( 'bootstrap-js' ),
'0.1',
FALSE
);
}
if ( is_page_template("page-about.php") ) {
wp_enqueue_script(
'smooth-scroll-page-js',
get_template_directory_uri() . '/js/smooth.scroll.page.js',
array( 'bootstrap-js' ),
'0.1',
FALSE
);
}
if ( !is_page() || is_front_page() ) {
wp_enqueue_script(
'tit-position-js',
get_template_directory_uri() . '/js/tit.position.js',
array( 'bootstrap-js' ),
'0.1',
FALSE
);
}
if ( is_page_template("page-solicita-badge.php") ) {
wp_enqueue_script(
'form-empty-fields-js',
get_template_directory_uri() . '/js/form.empty.fields.js',
array( 'jquery' ),
'0.1',
FALSE
);
}
} // end load js scripts to avoid conflicts
// register post types
function quincem_create_post_type() {
// Módulo post type
register_post_type( 'badge', array(
'labels' => array(
'name' => __( 'Parche' ),
'singular_name' => __( 'Parche' ),
'add_new_item' => __( 'Añadir parche' ),
'edit' => __( 'Editar' ),
'edit_item' => __( 'Editar este parche' ),
'new_item' => __( 'Nuevo parche' ),
'view' => __( 'Ver parche' ),
'view_item' => __( 'Ver este parche' ),
'search_items' => __( 'Buscar parches' ),
'not_found' => __( 'Ningún parche encontrado' ),
'not_found_in_trash' => __( 'Ningún parche en la papelera' ),
'parent' => __( 'Aprende' )
),
'description' => 'A través de los Parches irás aprendiendo distintas cosas: habilidades, saberes y herramientas que creemos importante poner en juego para construir una ciudad mejor.',
'has_archive' => false,
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'menu_position' => 5,
'menu_icon' => get_template_directory_uri() . '/images/quincem-dashboard-pt-badge.png',
'hierarchical' => true, // if true this post type will be as pages
'query_var' => true,
'supports' => array('title', 'editor','excerpt','author','trackbacks','thumbnail'),
'rewrite' => array('slug'=>'badge','with_front'=>false),
'can_export' => true,
'_builtin' => false,
));
// Itinerario post type
register_post_type( 'itinerario', array(
'labels' => array(
'name' => __( 'Itinerarios' ),
'singular_name' => __( 'Itinerario' ),
'add_new_item' => __( 'Añadir itinerario' ),
'edit' => __( 'Editar' ),
'edit_item' => __( 'Editar este itinerario' ),
'new_item' => __( 'Nuevo itinerario' ),
'view' => __( 'Ver itinerario' ),
'view_item' => __( 'Ver este itinerario' ),
'search_items' => __( 'Buscar itinerarios' ),
'not_found' => __( 'Ningún itinerario encontrado' ),
'not_found_in_trash' => __( 'Ningún itinerario en la papelera' ),
'parent' => __( 'Descubre' )
),
'description' => 'Los itinerarios pedagógicos ensayan un recorrido práctico y teórico sobre otras formas de participación: imaginarios, herramientas, juegos y lenguajes que queremos que sirvan para acercarnos de otra manera a nuestras realidades.',
'has_archive' => false,
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'menu_position' => 5,
'menu_icon' => get_template_directory_uri() . '/images/quincem-dashboard-pt-itinerario.png',
'hierarchical' => true, // if true this post type will be as pages
'query_var' => true,
'supports' => array('title', 'editor','excerpt','author','trackbacks','thumbnail','page-attributes' ),
'rewrite' => array('slug'=>'itinerario','with_front'=>false),
'can_export' => true,
'_builtin' => false,
));
// Actividad post type
register_post_type( 'actividad', array(
'labels' => array(
'name' => __( 'Actividades' ),
'singular_name' => __( 'Actividad' ),
'add_new_item' => __( 'Añadir actividad' ),
'edit' => __( 'Editar' ),
'edit_item' => __( 'Editar este actividad' ),
'new_item' => __( 'Nuevo actividad' ),
'view' => __( 'Ver actividad' ),
'view_item' => __( 'Ver este actividad' ),
'search_items' => __( 'Buscar actividades' ),
'not_found' => __( 'Ningún actividad encontrado' ),
'not_found_in_trash' => __( 'Ningún actividad en la papelera' ),
'parent' => __( 'Haz' )
),
'description' => 'Echa un vistazo a todas las actividades en las que puedes inscribirte y participar: desde talleres de auto-construcción a seminarios teóricos, pasando por debates virtuales o acciones colaborativas.',
'has_archive' => false,
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'menu_position' => 5,
'menu_icon' => get_template_directory_uri() . '/images/quincem-dashboard-pt-actividad.png',
'hierarchical' => false, // if true this post type will be as pages
'query_var' => true,
'supports' => array('title', 'editor','excerpt','author','trackbacks','thumbnail' ),
'rewrite' => array('slug'=>'actividad','with_front'=>false),
'can_export' => true,
'_builtin' => false,
));
// Earners post type
register_post_type( 'earner', array(
'labels' => array(
'name' => __( 'Personas' ),
'singular_name' => __( 'Earner' ),
'add_new_item' => __( 'Añadir earner' ),
'edit' => __( 'Editar' ),
'edit_item' => __( 'Editar este earner' ),
'new_item' => __( 'Nuevo earner' ),
'view' => __( 'Ver earner' ),
'view_item' => __( 'Ver este earner' ),
'search_items' => __( 'Buscar earners' ),
'not_found' => __( 'Ningún earner encontrado' ),
'not_found_in_trash' => __( 'Ningún earner en la papelera' ),
'parent' => __( 'Comunidad' )
),
'description' => 'Conoce a personas, que como tú, están aprendiendo y activándose a través de formas alternativas de reconocimiento. Además, podrás ver los parches que obtienen y el material que han producido.',
'has_archive' => false,
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'menu_position' => 5,
'menu_icon' => get_template_directory_uri() . '/images/quincem-dashboard-pt-earner.png',
'hierarchical' => false, // if true this post type will be as pages
'query_var' => true,
'supports' => array('title','author','trackbacks','thumbnail'),
'rewrite' => array('slug'=>'earner','with_front'=>false),
'can_export' => true,
'_builtin' => false,
));
// Issuer post type
register_post_type( 'issuer', array(
'labels' => array(
'name' => __( 'Issuers' ),
'singular_name' => __( 'Issuer' ),
'add_new_item' => __( 'Añadir issuer' ),
'edit' => __( 'Editar' ),
'edit_item' => __( 'Editar este issuer' ),
'new_item' => __( 'Nuevo issuer' ),
'view' => __( 'Ver issuer' ),
'view_item' => __( 'Ver este issuer' ),
'search_items' => __( 'Buscar issuers' ),
'not_found' => __( 'Ningún issuer encontrado' ),
'not_found_in_trash' => __( 'Ningún issuer en la papelera' ),
'parent' => __( 'Emisor de badges' )
),
'description' => 'Éste es el perfil de una de las organizaciones que emiten badges en Ciudadanía Activa. Si lo prefieres puedes ponerte en contacto con el emisor directamente en la sección contacto. Si te interesa ser un emisor escribe a info[a]martadero.org.',
'has_archive' => false,
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-welcome-learn-more',
'hierarchical' => false, // if true this post type will be as pages
'query_var' => true,
'supports' => array('title', 'editor','excerpt','author','trackbacks','thumbnail'),
'rewrite' => array('slug'=>'issuer','with_front'=>false),
'can_export' => true,
'_builtin' => false,
));
} // end register post types
// get all posts from a post type to be used in select or multicheck forms
function quincem_get_list( $post_type,$output = 'form_select' ) {
if ( $post_type == 'badge' ) {
$args = array(
'posts_per_page' => -1,
'post_type' => $post_type,
'post_parent' => 0
);
$badges = get_posts($args);
$not_in = array();
foreach ( $badges as $b ) {
$args = array(
'post_type' => $post_type,
'post_parent' => $b->ID,
'meta_key' => '_quincem_version',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
$children = get_posts($args);
if ( count($children) == 1 ) { $not_in[] = $b->ID; }
elseif ( count($children) >= 2 ) {
$not_in[] = $b->ID;
$ch_count = 0;
foreach ( $children as $ch ) {
if ( $ch_count != 0 ) { $not_in[] = $ch->ID; }
$ch_count++;
}
}
}
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => $post_type,
'orderby' => 'menu_order title',
'order' => 'ASC',
'post__not_in' => $not_in
));
} else {
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => $post_type,
'orderby' => 'title',
'order' => 'ASC'
));
}
if ( count($posts) > 0 ) {
if ( $output == 'form_select' ) { $list[] = ''; }
foreach ( $posts as $post ) {
$list[$post->ID] = $post->post_title;
}
return $list;
}
}// END quincem_get_list
// get a list of users to use in select or multicheck form fields
function quincem_get_users( $role,$first_element_empty = false ) {
if ( $role != 'all' ) {
$args = array(
'role' => $role,
'orderby' => 'nicename',
'order' => 'ASC'
);
} else {
$args = array(
'orderby' => 'nicename',
'order' => 'ASC'
);
}
$users = get_users($args);
if ( count($users) > 0 ) {
if ( $first_element_empty == true ) { $list[] = ''; }
foreach ( $users as $u ) {
$list[$u->ID] = $u->display_name;
}
return $list;
}
} // END quincem_get_users
//Add metaboxes to several post types edit screen
function quincem_metaboxes( $meta_boxes ) {
$prefix = '_quincem_'; // Prefix for all fields
// get data for select and multicheck fields
//$itinerarios = quincem_get_list("itinerario");
$actividades = quincem_get_list("actividad");
$badges = quincem_get_list("badge");
$issuers = quincem_get_list("issuer",'form_select');
$users = quincem_get_users('all',true);
// CUSTOM FIELDS FOR ISSUERS
$meta_boxes[] = array(
'id' => 'quincem_issuer',
'title' => 'Metadatos del emisor',
'pages' => array('issuer'), // post type
'context' => 'normal', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => true, // Show field names on the left
'fields' => array(
array(
'name' => 'URL',
'desc' => '',
'id' => $prefix . 'issuer_url',
'type' => 'text_url',
),
array(
'name' => 'E-mail',
'desc' => 'La dirección de email no podrá cambiarse.',
'id' => $prefix . 'issuer_email',
'type' => 'text_email',
),
),
);
$meta_boxes[] = array(
'id' => 'quincem_issuer_notifica',
'title' => 'Datos para notificaciones',
'pages' => array('issuer'), // post type
'context' => 'normal', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => true, // Show field names on the left
'fields' => array(
array(
'name' => 'E-mail',
'desc' => 'En esta dirección se recibirán las peticiones de emisión de badges.',
'id' => $prefix . 'issuer_notifica_email',
'type' => 'text_email',
),
),
);
$meta_boxes[] = array(
'id' => 'quincem_issuer_user',
'title' => 'Usuario Ciudadanía Activa',
'pages' => array('issuer'), // post type
'context' => 'side', // 'normal', 'advanced', or 'side'
'priority' => 'default', // 'high', 'core', 'default' or 'low'
'show_names' => false, // Show field names on the left
'fields' => array(
array(
'name' => 'Usuario',
'desc' => 'Usuario Ciudadanía Activa asociado a este emisor.',
'id' => $prefix . 'issuer_user',
'type' => 'select',
'options' => $users
),
),
);
// CUSTOM FIELDS FOR ITINERARIOS AND BADGES
$meta_boxes[] = array(
'id' => 'quincem_subtit',
'title' => 'Subtítulo',
'pages' => array('itinerario','badge'), // post type
'context' => 'normal', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => false, // Show field names on the left
'fields' => array(
array(
'name' => 'Subtítulo',
'desc' => 'Únicamente el subtítulo, sin paréntesis.',
'id' => $prefix . 'subtit',
'type' => 'text',
),
),
);
$meta_boxes[] = array(
'id' => 'quincem_issuers_list',
'title' => 'Emisor',
'pages' => array('itinerario','badge'), // post type
'context' => 'side', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => false, // Show field names on the left
'fields' => array(
array(
'name' => 'Selecciona un emisor',
'desc' => 'Emisor de este badge o itinerario.',
'id' => $prefix . 'issuer',
'type' => 'select',
'options' => $issuers
),
),
);
// CUSTOM FIELDS FOR ITINERARIOS AND BADGES AND ISSUERS
$meta_boxes[] = array(
'id' => 'quincem_icono',
'title' => 'Icono',
'pages' => array('itinerario','badge','issuer'), // post type
'context' => 'side', // 'normal', 'advanced', or 'side'
'priority' => 'default', // 'high', 'core', 'default' or 'low'
'show_names' => false, // Show field names on the left
'fields' => array(
array(
'name' => 'Icono',
'desc' => '',
'id' => $prefix . 'icono',
'type' => 'file',
'allow' => array( 'attachment' )
),
),
);
// CUSTOM FIELDS FOR ITINERARIOS
///
// modulos multicheckbox
$meta_boxes[] = array(
'id' => 'quincem_modulos',
'title' => 'Módulos en el itinerario',
'pages' => array('itinerario'), // post type
'context' => 'side', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => false, // Show field names on the left
'fields' => array(
array(
'name' => 'Badges',
'id' => $prefix . 'badges',
'type' => 'multicheck',
'options' => $badges
),
),
);
// CUSTOM FIELDS FOR BADGES
///
// actividades multicheckbox
$meta_boxes[] = array(
'id' => 'quincem_actividades',
'title' => 'Actividades',
'pages' => array('badge'), // post type
'context' => 'side', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => false, // Show field names on the left
'fields' => array(
array(
'name' => 'Actividades',
'id' => $prefix . 'actividades',
'type' => 'multicheck',
'options' => $actividades
),
),
);
// modulos multicheckbox
$meta_boxes[] = array(
'id' => 'quincem_dependencias',
'title' => 'Dependencias (otros parches)',
'pages' => array('badge'), // post type
'context' => 'side', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => false, // Show field names on the left
'fields' => array(
array(
'name' => 'Dependencias',
'id' => $prefix . 'dependencias',
'type' => 'multicheck',
'options' => $badges
),
),
);
// Cómo ganar el badge
$meta_boxes[] = array(
'id' => 'quincem_badge_como',
'title' => 'Cómo ganar el parche',
'pages' => array('badge'), // post type
'context' => 'normal', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => false, // Show field names on the left
'fields' => array(
array(
'name' => 'Cómo ganar el parche',
'id' => $prefix . 'badge_como',
'type' => 'wysiwyg',
'options' => array(),
),
),
);
// Material de trabajo
$meta_boxes[] = array(
'id' => 'quincem_material',
'title' => 'Material de trabajo',
'pages' => array('badge'), // post type
'context' => 'normal', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => false, // Show field names on the left
'fields' => array(
array(
'name' => 'Material de trabajo',
'id' => $prefix . 'material',
'type' => 'wysiwyg',
'options' => array(),
),
),
);
// Version
$meta_boxes[] = array(
'id' => 'quincem_version',
'title' => 'Versión del badge',
'pages' => array('badge'), // post type
'context' => 'side', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => false, // Show field names on the left
'fields' => array(
array(
'name' => 'Versión',
'id' => $prefix . 'version',
'type' => 'text',
'description' => 'Número de versión del badge: solo números naturales.'
),
),
);
// CUSTOM FIELDS FOR ACTIVIDADES
///
// On/Off, escenario, fechas for actividades
$meta_boxes[] = array(
'id' => 'quincem_actividad_meta',
'title' => 'Información sobre la actividad',
'pages' => array('actividad'), // post type
'context' => 'side', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => false, // Show field names on the left
'fields' => array(
array(
'name' => 'Tipo: On/offline',
'id' => $prefix . 'onoff',
'type' => 'multicheck',
'options' => array(
'on' => 'Online',
'off' => 'Offline',
),
),
array(
'name' => 'Escenario',
'id' => $prefix . 'escenario',
'type' => 'text'
),
array(
'name' => 'Fecha inicio',
'id' => $prefix . 'date_begin',
'type' => 'text_date_timestamp',
'repeatable' => false,
),
array(
'name' => 'Fecha fin',
'id' => $prefix . 'date_end',
'type' => 'text_date_timestamp',
'repeatable' => false,
),
),
);
// Info de contacto for actividades
$meta_boxes[] = array(
'id' => 'quincem_contact',
'title' => 'Contacto',
'pages' => array('actividad'), // post type
'context' => 'normal', // 'normal', 'advanced', or 'side'
'priority' => 'default', // 'high', 'core', 'default' or 'low'
'show_names' => false, // Show field names on the left
'fields' => array(
array(
'name' => 'Contacto',
'id' => $prefix . 'contacto',
'type' => 'wysiwyg',
'options' => array(),
),
),
);
// CUSTOM FIELDS FOR EARNERS
///
// mail, evidence, badge
$meta_boxes[] = array(
'id' => 'quincem_earner_meta',
'title' => 'Información sobre el earner',
'pages' => array('earner'), // post type
'context' => 'normal', // 'normal', 'advanced', or 'side'
'priority' => 'high', // 'high', 'core', 'default' or 'low'
'show_names' => true, // Show field names on the left
'fields' => array(
array(
'name' => 'Nombre',
'id' => $prefix . 'earner_name',
'type' => 'text',
),
array(
'name' => 'Dirección email',
'id' => $prefix . 'earner_mail',
'type' => 'text',
),
array(
'name' => 'URL del material producido',
'id' => $prefix . 'earner_material',
'type' => 'text'
),
array(
'name' => 'Actividad realizada',
'id' => $prefix . 'earner_actividad',
'type' => 'text'
),
array(
'name' => 'Badge conseguido',
'id' => $prefix . 'earner_badge',
'type' => 'select',
'options' => $badges,
'default' => 'none',
),
),
);
return $meta_boxes;
} // end Add metaboxes
// Initialize the metabox class
function quincem_init_metaboxes() {
if ( !class_exists( 'cmb_Meta_Box' ) ) {
require_once( 'lib/metabox/init.php' );
}
} // end Init metaboxes
// adding classes to post_class()
function quincem_classes($classes) {
// add bootstrap classes to post elements
global $post;
if ( is_front_page() ) { $new_classes = array("thumbnail");}
elseif ( is_single() ) { $new_classes = array("row");}
foreach( $new_classes as $class ) {
$classes[] = $class;
return $classes;
}
} // end adding classes to post_class()
// create issuer json metadata
function quincem_write_issuer_metadata() {
global $post;
if ( $post ) {
// If this is just a revision, don't continue
if ( wp_is_post_revision( $post->ID ) )
return;
if ( $post->post_type == 'issuer' && $post->post_status == 'publish' ) {
$issuer_json = get_template_directory() . "/openbadges/issuer-" .$post->post_name. ".json";
$issuer_url = get_post_meta($post->ID,'_quincem_issuer_url',true);
$issuer_email = get_post_meta( $post->ID, '_quincem_issuer_email',true );
$data = '{
"name": "' .$post->post_title. '",
"url": "' .$issuer_url. '",
"description": "' .$post->post_excerpt. '",
"email": "' .$issuer_email. '"
}';
// json metadata file
$handle = fopen( $issuer_json, 'w') or die("Cannot create the file index.html. Be sure that " .$issuer_json. " directory is writable."); //open file for writing
$write_success = fwrite($handle, $data);
fclose($handle);
}
} // end if $post is set
} // end create badge json metadata
// create badge json metadata
function quincem_write_badge_metadata() {
global $post;
if ( $post ) {
// If this is just a revision, don't continue
if ( wp_is_post_revision( $post->ID ) )
return;
if ( $post->post_type == 'badge' && $post->post_status == 'publish' ) {
$badge_json = get_template_directory() . "/openbadges/badge-" .$post->post_name. ".json";
$badge_img = get_template_directory() . "/openbadges/images/badge-" .$post->post_name. ".png";
$perma = get_permalink($post->ID);
$subtit = get_post_meta( $post->ID, '_quincem_subtit',true );
$wp_img_id = get_post_thumbnail_id( $post->ID );
$issuer_id = get_post_meta( $post->ID, '_quincem_issuer',true);
$args = array(
'post_type' => 'issuer',
'include' => array($issuer_id)
);
$issuers = get_posts( $args );
foreach ( $issuers as $i ) { $issuer_slug = $i->post_name; }
$data = '{
"name": "' .$post->post_title. '. ' .$subtit. '",
"description": "' .$post->post_excerpt. '",
"image": "' .get_template_directory_uri(). '/openbadges/images/badge-' .$post->post_name. '.png",
"criteria": "' .$perma. '",
"issuer": "' .get_template_directory_uri(). '/openbadges/issuer-'.$issuer_slug.'.json"
}';
// json metadata file
$handle = fopen( $badge_json, 'w') or die("Cannot create the file index.html. Be sure that " .$badge_json. " directory is writable."); //open file for writing
$write_success = fwrite($handle, $data);
fclose($handle);
// badge image
if ( $wp_img_id == '' || $wp_img_id == FALSE ) {} else {
//copy( wp_get_attachment_url($wp_img_id), $badge_img );
$wp_img = wp_get_attachment_image_src($wp_img_id,'large');
copy( $wp_img[0], $badge_img );
}
}
} // end if $post is set
} // end create badge json metadata
// create earner json metadata and notificate him/her by mail
function quincem_earner_admited() {
global $post;
if ( $post ) {
// If this is just a revision, don't continue
if ( wp_is_post_revision( $post->ID ) )
return;
//if ( $post->post_type == 'earner' && $post->post_status == 'publish' ) {
if ( $post->post_type == 'earner' ) {
$earner_name = get_post_meta( $post->ID, '_quincem_earner_name',true );
$earner_mail = get_post_meta( $post->ID, '_quincem_earner_mail',true );
$earner_evidence = get_post_meta( $post->ID, '_quincem_earner_material',true );
$earner_date = $post->post_date;
$earner_badge = get_post_meta( $post->ID, '_quincem_earner_badge',true );
$earner_actividad = get_post_meta( $post->ID, '_quincem_earner_actividad',true );
$earner_perma = get_permalink($post->ID);
$args = array(
'post_type' => 'badge',
'include' => $earner_badge
);
$badges = get_posts($args);
foreach ( $badges as $badge ) {
$earner_badge_tit = $badge->post_title;
$earner_badge_slug = $badge->post_name;
$badge_perma = get_permalink($badge->ID);
/*
* badge info is requested from theme openbadges folder through http
*/
$badge_json = get_template_directory_uri(). "/openbadges/badge-" .$badge->post_name. ".json";
$badge_img = get_template_directory_uri(). "/openbadges/images/badge-" .$badge->post_name. ".png";
$earner_json_url = get_template_directory_uri(). "/openbadges/assertions/badge-" .$badge->post_name. "-" .$post->ID. ".json";
$earner_json_path = get_template_directory() . "/openbadges/assertions/badge-" .$badge->post_name. "-" .$post->ID. ".json";
$badge_issuer = get_post_meta($badge->ID,'_quincem_issuer',true);
$args = array(
'post_type' => 'issuer',
'include' => $badge_issuer
);
$issuers = get_posts($args);
foreach ( $issuers as $i ) {
$issuer_name = $i->post_title;
$issuer_notifica_email = get_post_meta($i->ID,'_quincem_issuer_notifica_email',true);
if ( $issuer_notifica_email == '' ) { $issuer_notifica_email = get_post_meta($i->ID,'_quincem_issuer_email',true); }
}
}
$data = '{
"uid": "' .$post->ID. '",
"recipient": {
"type": "email",
"hashed": false,
"identity": "' .$earner_mail. '"
},
"evidence": "' .$earner_evidence. '",
"issuedOn": "' .$earner_date. '",
"badge": "' .$badge_json. '",
"image": "' .$badge_img. '",
"verify": {
"type": "hosted",
"url": "' .$earner_json_url. '"
}
}';
// json metadata file
$handle = fopen( $earner_json_path, 'w') or die("Cannot create the file index.html. Be sure that " .$earner_json_path. " directory is writable."); //open file for writing
$write_success = fwrite($handle, $data);
fclose($handle);
// notificate user when badge application is admited
if ( $write_success != FALSE ) {
$to = $earner_mail;
$subject = "Has ganado el parche " .$earner_badge_tit;
$message = '
¡Enhorabuena ' .$earner_name. '!'
. "\r\n\r\n" .
'has ganado el parche ' .$earner_badge_tit. ' por tu participación en la actividad ' .$earner_actividad. '.'
. "\r\n\r\n" .
'Para añadirlo a tu mochila, y poder así mostrárselo al mundo, puedes visitar el siguiente enlace: ' .$earner_perma. '.'
. "\r\n\r\n" .
'Te hemos incluido en la lista de personas que ganaron este badge, para que otros puedan consultar el material que has generado. Puedes ver la lista en la sección "Ganaron el badge" del siguiente enlace: ' .$badge_perma. '.'
. "\r\n\r\n" .
'Si prefieres no figurar en la lista, comunícanoslo: el badge es tuyo y tú decides dónde y cómo mostrarlo. Puedes escribirnos a '.$issuer_notifica_email. '.'
. "\r\n\r\n" .
'Un saludo de '.$issuer_name.'.'
;
$headers[] = 'From: '.$issuer_name. ' <' .$issuer_notifica_email. '>' . "\r\n";
$headers[] = 'Sender: Sistema de emisión de badge de Ciudadanía Activa <[email protected]>' . "\r\n";
$headers[] = 'Reply-To: '.$issuer_name. ' <' .$issuer_notifica_email. '>' . "\r\n";
$headers[] = 'To: ' .$earner_name. ' <' .$to. '>' . "\r\n";
// To send HTML mail, the Content-type header must be set, uncomment the following two lines
//$headers[] = 'MIME-Version: 1.0' . "\r\n";
//$headers[] = 'Content-type: text/html; charset=utf-8' . "\r\n";
wp_mail( $to, $subject, $message, $headers);
} // end if metadata write success
// end notificate user
} // end if post type earner
} // end if $post is set
} // end create badge json metadata
// reclaim a badge form
function quincem_reclaim_badge_form() {
$action = get_permalink();
// which badge
if ( array_key_exists('badge_id', $_GET) ) {
$badge_from = sanitize_text_field( $_GET['badge_id']);
} else { $badge_from = ""; }
$badges = quincem_get_list("badge","form_select_first_not_empty");
$options_badges = "<option></option>";
while ( $badge = current($badges) ) {
if ( $badge_from == key($badges) ) {
$options_badges .= "<option value='" .key($badges). "' selected>" .$badge. "</option>";
} else {
$options_badges .= "<option value='" .key($badges). "'>" .$badge. "</option>";
}
next($badges);
}
$form_out = "
<form id='quincem-form-content' method='post' action='" .$action. "' enctype='multipart/form-data'>
<div class='row'>
<div class='form-horizontal col-md-12'>
<legend>Tus datos</legend>
<div class='form-group'>
<label for='quincem-form-badge-name' class='col-sm-6 control-label'>Nombre</label>
<div class='col-sm-6'>
<input class='form-control req' type='text' value='' name='quincem-form-badge-name' />
</div>
</div>
<div class='form-group'>
<label for='quincem-form-badge-mail' class='col-sm-6 control-label'>Dirección de correo electrónico</label>
<div class='col-sm-6'>
<input class='form-control req' type='text' value='' name='quincem-form-badge-mail' />
<p class='help-block'><small>Usa siempre la misma dirección de correo electrónico para que aparezcan todos en tu perfil.</strong>.</small></p>
</div>
</div>
<div class='form-group'>