forked from Kolatzek/WPdoodlez
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WPdoodlez.php
2790 lines (2685 loc) · 130 KB
/
WPdoodlez.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
/**
Plugin Name: WP Doodlez
Plugin URI: https://github.com/svenbolte/WPdoodlez
Author URI: https://github.com/svenbolte
Description: plan appointments, query polls and place a quiz or a crossword or wordpuzzle game on your wordpress site (with csv import for questions)
Contributors: Robert Kolatzek, PBMod, others
License: GPL v3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Text Domain: WPdoodlez
Domain Path: /lang/
Author: PBMod
Version: 9.1.1.152
Stable tag: 9.1.1.152
Requires at least: 6.0
Tested up to: 6.7
Requires PHP: 8.2
*/
if (!defined('ABSPATH')) exit;
// Load plugin textdomain.
function WPdoodlez_load_textdomain() {
load_plugin_textdomain( 'WPdoodlez', false, plugin_basename( dirname( __FILE__ ) ) . '/lang' );
}
add_action( 'plugins_loaded', 'WPdoodlez_load_textdomain' );
/**
* Register own template for doodles
* @global post $post
* @param string $single_template
* @return string
*/
function wpdoodlez_template( $single_template ) {
global $post;
$wpxtheme = wp_get_theme(); // gets the current theme
if ( 'Penguin' == $wpxtheme->name || 'Penguin' == $wpxtheme->parent_theme ) { $xpenguin = true;} else { $xpenguin=false; }
if ( $post->post_type == 'wpdoodle' ) {
if ($xpenguin) { $single_template = dirname( __FILE__ ) . '/wpdoodle-template-penguin.php'; } else {
$single_template = dirname( __FILE__ ) . '/wpdoodle-template.php';
}
}
// quiztype
if ( $post->post_type == 'question' ) {
if ($xpenguin) { $single_template = dirname( __FILE__ ) . '/question-template-penguin.php'; } else {
$single_template = dirname( __FILE__ ) . '/question-template.php';
}
}
return $single_template;
}
add_filter( 'single_template', 'wpdoodlez_template' );
// IP-Adresse des Users bekommen
function wd_get_the_user_ip() {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
//check ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
//to check ip is pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
// letzte Stelle der IP anonymisieren (0 setzen)
$ip = long2ip(ip2long($ip) & 0xFFFFFF00);
return apply_filters( 'wpb_get_ip', $ip );
}
// wpdoodlez_sc(ID) - Call WPDoodles complete Content from another page or post as a shortcode
// only use one shortcode per page or post - not more of them on one page/post!
function wpdoodlez_sc_func($atts) {
wp_enqueue_script( "WPdoodlez", plugins_url( 'WPdoodlez.js', __FILE__ ), array('jquery'), null, true);
wp_enqueue_style( "WPdoodlez", plugins_url( 'WPdoodlez.css', __FILE__ ), array(), null, 'all');
global $post;
$args = shortcode_atts(array( 'id' => 0, 'chart' => 1 ), $atts);
$output ='';
$qargs = array(
'p' => $args['id'],
'post_type' => array('wpdoodle'),
'post_status' => 'publish',
'posts_per_page' => 2
);
$query1 = new WP_Query( $qargs );
if ( $query1->have_posts() ) {
while ( $query1->have_posts() ) {
$query1->the_post();
$output .= get_doodlez_content(intval($args['chart']));
$output .= '<script>var wpdoodle_ajaxurl = "' . admin_url( 'admin-ajax.php', is_ssl() ? 'https' : 'http' ).'";';
$output .= 'var wpdoodle = "'. md5( AUTH_KEY . get_the_ID() ). '";</script>';
}
wp_reset_postdata();
}
return $output;
}
add_shortcode('wpdoodlez_sc', 'wpdoodlez_sc_func');
// wpdoodlez-adminstats for polls
function wpdoodlez_stats_func($atts) {
global $wp,$post;
$args = shortcode_atts(array( 'id' => 0, 'type' => 'poll' ), $atts); // Type = poll oder doodlez
if (intval($args['id']) > 0) $idfilter=array(intval($args['id'])); else $idfilter='';
$wpdtype = esc_html($args['type']);
$output ='';
$qargs = array(
'post_type' => array('wpdoodle'),
'post_status' => 'publish',
'post__in' => $idfilter,
'posts_per_page' => -1
);
$query1 = new WP_Query( $qargs );
if ( $query1->have_posts() ) {
while ( $query1->have_posts() ) {
$query1->the_post();
$suggestions = $votes_cout = [ ];
$customs = get_post_custom( get_the_ID() );
foreach ( $customs as $key => $value ) {
if ( !preg_match( '/^_/is', $key ) ) {
$suggestions[ $key ] = $value;
$votes_cout[ $key ] = 0;
}
}
$polli = array_key_exists('vote1', $suggestions);
if ( $wpdtype == 'poll' && $polli ) {
$votes = get_option( 'wpdoodlez_' . md5( AUTH_KEY . get_the_ID() ), array() );
$cct = 0;
$voteip='';$firstvote='';$votezeit='';
foreach ( $votes as $name => $vote ) {
$cct += 1;
foreach ( $suggestions as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
if ( !empty($vote[ $key ]) ) { $votes_cout[ $key ] ++; }
}
}
if (isset($vote['zeit'])) {
$diff = time() - $vote['zeit'];
if (round((intval($diff) / 86400), 0) < 30) { $newcolor = "yellow"; } else { $newcolor = "white"; }
$votezeit = '<abbr title="'.__( 'vote', 'WPdoodlez' ).' '.$cct.'" class="newlabel '.$newcolor.'">'.date_i18n(get_option('date_format').' '.get_option('time_format'), $vote['zeit'] + date('Z')).' '.ago($vote['zeit']).'</abbr></br>';
if ($cct == 1 ) $firstvote = $votezeit;
} else { $votezeit=''; $firstvote=''; }
if (isset($vote['ipaddr'])) $voteip = $vote['ipaddr']; else $voteip='';
}
$xsum = 0;
foreach ( $votes_cout as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" )) && $value > 0 ) {
$xsum += $value;
}
}
$titelqm = get_the_title();
if ( substr($titelqm, -1, 1) != '?' ) $titelqm .= '?';
$output .= '<table>';
$output .= '<thead><tr><th colspan=3><i class="fa fa-lg fa-check-square-o"></i> <a title="'.__( 'Vote!', 'WPdoodlez' ).'" href="'.get_the_permalink().'">'.get_the_id().' '.$titelqm.'</a></th></tr></thead>';
$xperc = 0;
$votecounter = 0;
foreach ( $suggestions as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
$votecounter += 1;
if ($xsum>0) $xperc = round(($votes_cout[ $key ]/$xsum) * 100,1);
$output .= '<tr><td style="text-align:center">';
$output .= $value[ 0 ] .'</label></td><td style="text-align:center">'.$votes_cout[ $key ].'</td>';
$output .= '<td style="min-width:200px;width:30%"><progress style="width:100%" max="100" value="'.$xperc.'"></td></tr>';
}
}
$output .= '<tfoot><tr><td style="text-transform:none">' . __( 'total votes', 'WPdoodlez' ) . ' '.$firstvote.'</td><td style="text-align:center;font-size:1.2em">'.$xsum.'</td><td style="text-transform:none">'. $votezeit;
// Wenn ipflag plugin aktiv und user angemeldet
if( class_exists( 'ipflag' ) && is_user_logged_in() ) {
global $ipflag;
if(isset($ipflag) && is_object($ipflag)){
if(($info = $ipflag->get_info($voteip)) != false){
$output .= ' '.$info->code . ' ' .$info->name. ' ' . $ipflag->get_flag($info, '').' '.$voteip;
} else { $output .= ' '. $ipflag->get_flag($info, '').' '.$voteip; }
}
}
$output .= '</td></tr></tfoot>';
$output .= '</table>';
} else if ( $wpdtype == 'doodlez' && !$polli ) {
// Kopfzeilen // Type = 'doodlez'
$output .= '<table><thead><tr><th colspan=10><i class="fa fa-calendar-o"></i>
<a href="'.get_the_permalink().'">
' . __( 'Voting', 'WPdoodlez' ) . ': '.get_the_title().'</a> '. get_the_excerpt(). '</th></tr>';
$output .= '<tr><th>' . __( 'User name', 'WPdoodlez' ) . '</th><th><i class="fa fa-clock-o"></i></th>';
foreach ( $suggestions as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
$output .= '<th style="word-break:break-all;overflow-wrap:anywhere">';
// ICS Download zum Termin anbieten
if( function_exists('export_ics') && is_singular() ) {
$nextnth = strtotime($key);
$nextnth1h = strtotime($key);
$output .= ' <a title="'.__("ICS add reminder to your calendar","penguin").'" href="'.home_url(add_query_arg(array($_GET, 'start' =>wp_date('Ymd\THis', $nextnth), 'ende' => wp_date('Ymd\THis', $nextnth1h) ),$wp->request.'/icalfeed/')).'"><i class="fa fa-calendar-check-o"></i></a> ';
}
$output .= $key . '</th>';
}
}
$output .= '</tr></thead><tbody>';
$votes = get_option( 'wpdoodlez_' . md5( AUTH_KEY . get_the_ID() ), array() );
// Inhalt Abstimmungen
foreach ( $votes as $name => $vote ) {
$output .= '<tr>';
$output .= '<td style="text-align:left">'.$name.'</td>';
$output .= '<td style="text-align:left"><abbr>';
if (isset($vote['zeit'])) $votezeit = date_i18n(get_option('date_format').' '.get_option('time_format'), $vote['zeit'] + date('Z')); else $votezeit='';
if (isset($vote['ipaddr'])) $voteip = $vote['ipaddr']; else $voteip='';
// Wenn ipflag plugin aktiv und user angemeldet
$output .= ' ' . $votezeit.'</abbr></td>';
foreach ( $suggestions as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
$output .= '<td style="text-align:center">';
if ( !empty($vote[ $key ]) ) {
$votes_cout[ $key ] ++;
$output .= '<label data-key="' . $key . '">'. $value[ 0 ].'</label>';
} else {
$output .= '<label></label>';
}
$output .= '</td>';
}
}
$output .= '</tr>';
}
$output .= '</tbody><tfoot>';
$output .= '<tr><td>' . __( 'total votes', 'WPdoodlez' ).':</td><td></td>';
foreach ( $votes_cout as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
$output .= '<td>'. $value.'</td>';
}
}
$output .= '</tr></tfoot>';
$output .= '</table>';
}
}
wp_reset_postdata();
}
return $output;
}
add_shortcode('wpdoodlez_stats', 'wpdoodlez_stats_func');
/**
* Save a single vote as ajax request and set cookie with given user name
*/
function wpdoodlez_save_vote() {
$values = get_option( 'wpdoodlez_' . strval($_POST[ 'data' ][ 'wpdoodle' ]), array() );
$name = sanitize_text_field( $_POST[ 'data' ][ 'name' ]);
// insert only without cookie (or empty name in cookie) update only with same name in cookie
$nameInCookie = strval($_COOKIE[ 'wpdoodlez-' . $_POST[ 'data' ][ 'wpdoodle' ] ]);
if ( (isset( $values[ $name ] ) && $nameInCookie == $name) ||
(!isset( $values[ $name ] ) && empty( $nameInCookie ))
) {
$values[ $name ] = array();
$values[$name]['zeit'] = time();
$values[$name]['ipaddr'] = wd_get_the_user_ip();
foreach ( $_POST[ 'data' ][ 'vote' ] as $option ) {
$values[ $name ][ strval($option[ 'name' ]) ] = sanitize_text_field($option[ 'value' ]);
}
} else {
echo json_encode(
array(
'save' => false ,
'msg' => __('You have already voted but your vote was deleted. Your name was: ','WPdoodlez').$nameInCookie
)
);
wp_die();
}
update_option( 'wpdoodlez_' . (string)$_POST[ 'data' ][ 'wpdoodle' ], $values );
if ($_COOKIE['hidecookiebannerx']==2 ) setcookie( 'wpdoodlez-' . (string)$_POST[ 'data' ][ 'wpdoodle' ], $name, time() + (3600 * 24 * 30), COOKIEPATH, COOKIE_DOMAIN, is_ssl() );
echo json_encode( array( 'save' => true ) );
wp_die();
}
add_action( 'wp_ajax_wpdoodlez_save', 'wpdoodlez_save_vote' );
add_action( 'wp_ajax_nopriv_wpdoodlez_save', 'wpdoodlez_save_vote' );
/**
* Save a single poll as ajax request and set cookie with given user name
*/
function wpdoodlez_save_poll() {
$values = get_option( 'wpdoodlez_' . strval($_POST[ 'data' ][ 'wpdoodle' ]), array() );
$name = sanitize_text_field( $_POST[ 'data' ][ 'name' ]);
$values[ $name ] = array();
$values[$name]['zeit'] = time();
$values[$name]['ipaddr'] = wd_get_the_user_ip();
foreach ( $_POST[ 'data' ][ 'vote' ] as $option ) {
$values[ $name ][ strval($option[ 'name' ]) ] = sanitize_text_field($option[ 'value' ]);
}
update_option( 'wpdoodlez_' . (string)$_POST[ 'data' ][ 'wpdoodle' ], $values );
echo json_encode( array( 'save' => true ) );
wp_die();
}
add_action( 'wp_ajax_wpdoodlez_save_poll', 'wpdoodlez_save_poll' );
add_action( 'wp_ajax_nopriv_wpdoodlez_save_poll', 'wpdoodlez_save_poll' );
/**
* Delete a given vote identified by user name. Possible for all wp user with *delete_published_posts* right
*/
function wpdoodlez_delete_vote() {
if ( !current_user_can( 'delete_published_posts' ) ) {
echo json_encode( array( 'delete' => false ) );
wp_die();
}
$values = get_option( 'wpdoodlez_' . (string)$_POST[ 'data' ][ 'wpdoodle' ], array() );
$newvalues = [ ];
foreach ( $values as $key => $value ) {
if ( $key != (string) $_POST[ 'data' ][ 'name' ] ) {
$newvalues[ $key ] = $value;
}
}
update_option( 'wpdoodlez_' . (string)$_POST[ 'data' ][ 'wpdoodle' ], $newvalues );
echo json_encode( array( 'delete' => true ) );
wp_die();
}
add_action( 'wp_ajax_nopriv_wpdoodlez_delete', 'wpdoodlez_delete_vote' );
add_action( 'wp_ajax_wpdoodlez_delete', 'wpdoodlez_delete_vote' );
/**
* Register WPdoodle post type
* Set cookie with the name of user (used by voting)
*/
function wpdoodlez_cookie() {
$labels = [
'name' => 'WPdoodlez',
'singular_name' => 'WPdoodle',
'menu_name' => 'WPdoodle',
'parent_item_colon' => '',
'all_items' => __( 'All WPdoodlez', 'WPdoodlez' ),
'view_item' => __( 'Show WPdoodle', 'WPdoodlez' ),
'add_new_item' => __( 'New WPdoodle', 'WPdoodlez' ),
'add_new' => __( 'Add WPdoodle ', 'WPdoodlez' ),
'edit_item' => __( 'Edit WPdoodle', 'WPdoodlez' ),
'update_item' => __( 'Update WPdoodle', 'WPdoodlez' ),
'search_items' => __( 'Search WPdoodlez', 'WPdoodlez' ),
'not_found' => __( 'Not found', 'WPdoodlez' ),
'not_found_in_trash' => __( 'Not found in trash', 'WPdoodlez' ),
];
$args = [
'labels' => $labels,
'supports' => [ 'title', 'editor', 'thumbnail', 'comments', 'custom-fields', 'post-formats' ],
// 'show_in_rest' => true, // Gutenberg Anzeige des Editors, über ... / Ansicht dann Eigene Felder einschalten!
"taxonomies" => array("post_tag", "category"),
'description' => __( 'appointment planner, polls, quizzes', 'WPdoodlez' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-forms',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => [
'slug' => 'wpdoodle',
'with_front' => true,
'pages' => false,
'feeds' => true,
],
'capability_type' => 'page',
];
register_post_type( 'WPdoodle', $args );
foreach ( $_COOKIE as $key => $value ) {
if ( preg_match( '/wpdoodlez\-.+/i', (string)$key ) ) {
if ($_COOKIE['hidecookiebannerx']==2 ) setcookie( (string)$key, (string)$value, time() + (3600 * 24 * 30), COOKIEPATH, COOKIE_DOMAIN, is_ssl() );
}
}
}
add_action( 'init', 'wpdoodlez_cookie' );
function columns_wpdoodle($columns) {
$columns['Shortcode'] = 'Doodlez-Shortcode';
return $columns;
}
add_filter('manage_wpdoodle_posts_columns', 'columns_wpdoodle');
add_action ('manage_wpdoodle_posts_custom_column','wpdoo_post_custom_columns');
function wpdoo_post_custom_columns($column) {
global $post;
$custom = get_post_custom();
switch ($column) {
case "Shortcode":
echo '<input type="text" title="id="' . esc_attr( $post->ID ) . '"" class="copy-to-clipboard" value="[wpdoodlez_sc id="' . esc_attr( $post->ID ) . '"]" readonly>';
echo '<p class="newlabel yellow" style="display: none;">' . __( 'Shortcode copied to clipboard.', 'WPdoodlez' ) . '</p>';
break;
}
}
/**
* Register WPdoodle post type and refresh rewrite rules
*/
function wpdoodlez_rewrite_flush() {
wpdoodlez_cookie();
flush_rewrite_rules();
// Dateien ins uploads/quizbilder kopieren
require_once(ABSPATH . "wp-includes/pluggable.php");
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
$folder = plugin_dir_path( __FILE__ ) . "quizbilder";
$files = array();
$handler = opendir($folder);
while ($file = readdir($handler)) {
if ($file != '.' && $file != '..') $files[] = $file;
}
closedir($handler);
wp_mkdir_p(wp_upload_dir()['basedir'].'/quizbilder');
foreach ( $files as $file ) {
copy ($folder.'/'.$file, wp_upload_dir()['basedir'].'/quizbilder/'.$file);
}
}
register_activation_hook( __FILE__, 'wpdoodlez_rewrite_flush' );
add_action( 'after_switch_theme', 'wpdoodlez_rewrite_flush' );
// show doodles on home page
add_action( 'pre_get_posts', 'wpse_242473_add_post_type_to_home' );
function wpse_242473_add_post_type_to_home( $query ) {
if( $query->is_main_query() && $query->is_home() ) {
$query->set( 'post_type', array( 'post', 'wpdoodle') );
}
}
// Doodle Comments ab Werk aus
function default_comments_off( $data, $postarr ) {
if( $data['post_type'] == 'wpdoodle' ) {
//New posts don't have an ID - So this checks if the post is new or already exists
if( !($postarr['ID']) ){
$data['comment_status'] = 0; //0 = false | 1 = true
}
}
return $data;
}
add_filter( 'wp_insert_post_data', 'default_comments_off', '', 2);
// Menüs erweitern um Dokulink
function create_menupages_wpdoodle() {
add_submenu_page(
'edit.php?post_type=wpdoodle', // Parent slug
'Dokumentation', // Page title
'Dokumentation', // Menu title
'manage_options', // Capability
'', // Slug
'wpdoodle_doku',
);
}
add_action('admin_menu', 'create_menupages_wpdoodle');
function wpdoodle_doku() {
echo '<h1>'. __( 'WPdoodlez Documentation','WPdoodlez' ).'</h1>';
echo '<div class="postbox" style="padding:8px">';
?>
### WPDoodlez<br>
plan and vote to find a common appointment date with participiants for an event. Works similar to famous Doodle(TM) website.
It adds a custom post type "wpdoodlez".<br>
Add Shortcode [wpdoodlez_sc id=post-ID chart=true] to any page or post or html widget to embed poll/doodlez into them<br><br>
### Poll<br>
uses same technology and custom post type like WPDoodlez
create classic polls to let visitors vote about a question<br>
Add Shortcode [wpdoodlez_stats] to any page or post for stats on all polls in a list
<br><br>
### Quizzz<br>
Play a quiz game with one or four answers
Quizzz supports categories images and integrates them in single and header if used in theme. It adds a custom post type "question"
see readme.txt for more details. Put pictures in folder uploads/quizbilder do display quizfragen with a picture
Add Shortcode [random-question] to any post, page or html-widget<br>
#### Crossword<br>
display a crossword game built on the quizzz words
<br>
#### Wort-Shuffle<br>
rearrange word letters in correct order
<br>
#### Wordpuzzle
display a wordpuzzle with random words from quizfragen Answers
<br><br>
## Details for WPDoodlez
WPdoodlez can handle classic polls and doodle like appointment planning. It can be created in admin area<br>
Use custom post type to call posts or integrate post content to your normal posts using the shortcode<br><br>
If custom fields are named vote1...vote10, a poll is created, just displaying the vote summaries<br><br>
if custom fields are dates e.g name: 12.12.2020 value: ja<br>
then a doodlez is created where visitors can set their name or shortcut and vote for all given event dates<br>
<br>
Admins can invoke URL parameter /admin=1 to display alternate votes display (more features when logged in as admin)<br><br>
<?php
echo '</div><div class="postbox" style="padding:8px">';
?>
<h2>Highlights</h2>
* link to WPdoodlez is public, but post can have password <br>
* A WPdoodlez can be in a review and be published at given time<br>
* A WPdoodlez can have own URL <br>
* Poll users do not need to be valid logged in wordpress users<br>
* Users with "delete published post" rights can delete votes<br>
* Users shortname will be stored in a cookie for 30 days (user can change only his own vote, but on the same computer)<br>
* GDPR: If Cookie policy is set to: required only, no cookies will be set. For vote polls, no cookies will be set at all
* Every custom field set in a WPdoodle is a possible answer<br>
* The first value of the custom field will be displayed in the row as users answer<br>
* The last row in the table contains total votes count<br>
<?php
}
// Doodlez Inhalte anzeigen
function get_doodlez_content($chartan) {
global $wp;
$htmlout = '';
$suggestions = $votes_cout = [ ];
$customs = get_post_custom( get_the_ID() );
foreach ( $customs as $key => $value ) {
if ( !preg_match( '/^_/is', $key ) ) {
$suggestions[ $key ] = $value;
$votes_cout[ $key ] = 0;
}
}
// admin Details link für polls
if (is_user_logged_in()) {
$htmlout .= '<ul class="footer-menu" style="float:right">';
$htmlout .= '<li><a href="'.add_query_arg( array('exportteilnehmer'=>'1' ), home_url( $wp->request ) ).'">' . __( 'export to CSV', 'WPdoodlez' ) . '</a></li>';
if ( array_key_exists('vote1', $suggestions) ) {
if (!isset($_GET['admin']) ) {
$htmlout .= '<li><a href="'.add_query_arg( array('admin'=>'1' ), home_url( $wp->request ) ).'">' . __( 'poll details', 'WPdoodlez' ) . '</a></li>';
} else {
$htmlout .= '<li><a href="'.home_url( $wp->request ) .'">' . __( 'poll results', 'WPdoodlez' ) . '</a></li>';
}
}
$htmlout .= '</ul>';
}
/* password protected? */
if ( !post_password_required() ) {
// Wenn Feldnamen vote1...20, dann eine Umfrage machen, sonst eine Terminabstimmung
$polli = array_key_exists('vote1', $suggestions); // if polli add icon to content
if ( $polli && !isset($_GET['admin']) ) {
$htmlout .= '<i class="fa fa-lg fa-check-square-o"></i> Umfrage: '. get_the_content();
$hashuser = substr(md5(time()),1,20);
$votes = get_option( 'wpdoodlez_' . md5( AUTH_KEY . get_the_ID() ), array() );
$cct = 0;
$voteip='';$firstvote='';$votezeit='';
foreach ( $votes as $name => $vote ) {
$cct += 1;
foreach ( $suggestions as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
if ( !empty($vote[ $key ]) ) { $votes_cout[ $key ] ++; }
}
}
if (isset($vote['zeit'])) {
$diff = time() - $vote['zeit'];
if (round((intval($diff) / 86400), 0) < 30) { $newcolor = "yellow"; } else { $newcolor = "white"; }
$votezeit = '<abbr title="'.__( 'vote', 'WPdoodlez' ).' '.$cct.'" class="newlabel '.$newcolor.'">'.date_i18n(get_option('date_format').' '.get_option('time_format'), $vote['zeit'] + date('Z')).' '.ago($vote['zeit']).'</abbr></br>';
if ($cct == 1 ) $firstvote = $votezeit;
} else { $votezeit=''; $firstvote=''; }
if (isset($vote['ipaddr'])) $voteip = $vote['ipaddr']; else $voteip='';
}
$xsum = 0;
$pielabel = ''; $piesum = '';
foreach ( $votes_cout as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" )) && $value > 0 ) {
$xsum += $value;
$pielabel.=str_replace(',','',$suggestions[$key][0]).','; $piesum .= $value.',';
}
}
$htmlout .= '<br><table id="pollselect"><thead><th colspan="4">' . __( 'your choice', 'WPdoodlez' ) . '</th></thead>';
$xperc = 0;
$votecounter = 0;
foreach ( $suggestions as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
$votecounter += 1;
if ($xsum>0) $xperc = round(($votes_cout[ $key ]/$xsum) * 100,1);
$htmlout .= '<tr><td style="text-align:center"><label><input type="checkbox" name="'.$key.'" id="'.$key.'" onclick="selectOnlyThis(this.id)" class="wpdoodlez-input"></td><td>';
$htmlout .= $value[ 0 ] .'</label></td><td style="text-align:center">'.$votes_cout[ $key ].'</td>';
$htmlout .= '<td style="max-width:240px"><progress style="width:220px" max="100" value="'.$xperc.'"></td></tr>';
}
}
$htmlout .= '<tfoot><tr><td colspan=2 style="text-align:center">' . __( 'total votes', 'WPdoodlez' ) . ' '.$firstvote. '</td><td style="text-align:center;font-size:1.2em">'.$xsum.'</td><td style="text-transform:none">'. $votezeit;
// Wenn ipflag plugin aktiv und user angemeldet
if( class_exists( 'ipflag' ) && is_user_logged_in() ) {
global $ipflag;
if(isset($ipflag) && is_object($ipflag)){
if(($info = $ipflag->get_info($voteip)) != false){
$htmlout .= ' '.$info->code . ' ' .$info->name. ' ' . $ipflag->get_flag($info, '').' '.$voteip;
} else { $htmlout .= ' '. $ipflag->get_flag($info, '').' '.$voteip; }
}
}
$htmlout .= '</td></tr></tfoot>';
$htmlout .= '<tr><td colspan=4><input type="hidden" id="wpdoodlez-name" value="'.$hashuser.'">';
$htmlout .= '<button style="width:100%" id="wpdoodlez_poll">' . __( 'Vote!', 'WPdoodlez' ) . '</button></td></tr>';
$htmlout .= '</table>';
// only one selection allowed
$htmlout .= '<script>function selectOnlyThis(id) {';
$htmlout .= 'for (var i = 1;i <= '. $votecounter.'; i++) { document.getElementById("vote"+i).checked = false; }';
$htmlout .= ' document.getElementById(id).checked = true; }</script>';
} else {
// Dies nur ausführen, wenn Feldnamen nicht vote1...20 oder Admin Details Modus
$htmlout .= '<i class="fa fa-lg fa-calendar-o"></i> Terminabstimmung: '. get_the_content();
$htmlout .= '<h6>' . __( 'Voting', 'WPdoodlez' ) . '</h6>';
if ( !$polli && function_exists('timeline_calendar')) {
$outputed_values = array();
$xevents = array();
foreach ( $suggestions as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
array_push($xevents, $key);
}
}
foreach ( $suggestions as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
$workername = substr($key,6,4) . substr($key,3,2);
if (!in_array($workername, $outputed_values)){
$htmlout .= '<div style="font-size:0.9em;overflow:hidden;vertical-align:top;display:inline-block;max-width:32%;width:32%;margin-right:5px">'.timeline_calendar(substr($key,3,2),substr($key,6,4),$xevents).'</div>';
array_push($outputed_values, $workername);
}
}
}
}
$htmlout .= '<table><thead><tr><th>' . __( 'User name', 'WPdoodlez' ) . '</th><th><i class="fa fa-clock-o"></i></th>';
foreach ( $suggestions as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
$htmlout .= '<th style="word-break:break-all;overflow-wrap:anywhere">';
// ICS Download zum Termin anbieten
if( function_exists('export_ics') && is_singular() ) {
$nextnth = strtotime($key);
$nextnth1h = strtotime($key);
$htmlout .= ' <a title="'.__("ICS add reminder to your calendar","WPdoodlez").'" href="'.home_url(add_query_arg(array($_GET, 'start' =>wp_date('Ymd\THis', $nextnth), 'ende' => wp_date('Ymd\THis', $nextnth1h) ),$wp->request.'/icalfeed/')).'"><i class="fa fa-calendar-check-o"></i></a> ';
}
$htmlout .= $key . '</th>';
}
}
$htmlout .= '<th title="' . __( 'Manage vote', 'WPdoodlez' ). '"><i class="fa fa-cogs"></i></th>';
$htmlout .= '</tr></thead><tbody>';
if (!empty($_COOKIE[ 'wpdoodlez-' . md5( AUTH_KEY . get_the_ID() ) ] )) {
$myname = $_COOKIE[ 'wpdoodlez-' . md5( AUTH_KEY . get_the_ID() ) ];
}
$htmlout .= '<tr id="wpdoodlez-form">';
$htmlout .= '<td><input type="text" placeholder="'. __( 'Your name', 'WPdoodlez' ) .'" ';
$htmlout .= ' class="wpdoodlez-input" id="wpdoodlez-name" size="12"></td><td></td>';
$votecounter = 0;
foreach ( $suggestions as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
$votecounter += 1;
$htmlout .= '<td><label> <input type="checkbox" name="'. $key.'" id="doodsel'.$votecounter.'" class="wpdoodlez-input">';
$htmlout .= $value[ 0 ].'</label></td>';
}
}
$htmlout .= '<td><button id="wpdoodlez_vote" title="' . __( 'Vote!', 'WPdoodlez' ) . '" style="padding:6px">';
$htmlout .= '<i class="fa fa-check-square-o"></i> '. __( 'Go!', 'WPdoodlez' ) .'</button></td></tr>';
$votes = get_option( 'wpdoodlez_' . md5( AUTH_KEY . get_the_ID() ), array() );
// Page navigation
if ( $polli ) { $nb_elem_per_page = 25; } else { $nb_elem_per_page = 100; }
$number_of_pages = intval(count($votes)/$nb_elem_per_page)+1;
$page = isset($_GET['seite'])?intval($_GET['seite']):0;
// falls ohne paginierung: foreach ( $votes as $name => $vote ) {
foreach (array_slice($votes, $page*$nb_elem_per_page, $nb_elem_per_page) as $name => $vote) {
$htmlout .= '<tr id="wpdoodlez_' . md5( AUTH_KEY . get_the_ID() ) . '-' . md5( $name ) .'" ';
$htmlout .= 'class="'. @$myname == $name ? 'myvote' : '' .'">';
$htmlout .= '<td style="text-align:left">'.$name.'</td>';
$htmlout .= '<td style="text-align:left"><abbr>';
if (isset($vote['zeit'])) $votezeit = date_i18n(get_option('date_format').' '.get_option('time_format'), $vote['zeit'] + date('Z')); else $votezeit='';
if (isset($vote['ipaddr'])) $voteip = $vote['ipaddr']; else $voteip='';
// Wenn ipflag plugin aktiv und user angemeldet
if( class_exists( 'ipflag' ) && is_user_logged_in() ) {
global $ipflag;
if(isset($ipflag) && is_object($ipflag)){
if(($info = $ipflag->get_info($voteip)) != false){
$htmlout .= ' '.$info->code . ' ' .$info->name. ' ' . $ipflag->get_flag($info, '').' '.$voteip;
} else { $htmlout .= ' '. $ipflag->get_flag($info, '').' '.$voteip; }
}
}
$htmlout .= ' ' . $votezeit.'</abbr></td>';
foreach ( $suggestions as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
$htmlout .= '<td>';
if ( !empty($vote[ $key ]) ) {
$votes_cout[ $key ] ++;
$htmlout .= '<label data-key="' . $key . '">'. $value[ 0 ].'</label>';
} else {
$htmlout .= '<label></label>';
}
$htmlout .= '</td>';
}
}
$htmlout .= '<td>';
if ( current_user_can( 'delete_published_posts' ) ) {
$htmlout .= '<button title="' . __( 'delete', 'WPdoodlez' ) . '" style="padding:3px 6px 3px 6px" class="wpdoodlez-delete" data-vote="'. md5( $name ).'" data-realname="'. $name.'">';
$htmlout .= '<i class="fa fa-trash-o"></i></button>';
}
if ( !empty($myname) && $myname == $name ) {
$htmlout .= '<button title="'.__( 'edit', 'WPdoodlez' ).'" style="padding:3px 5px 3px 5px" class="wpdoodlez-edit" data-vote="'. md5( $name ). '" data-realname="'. $name.'">';
$htmlout .= '<i class="fa fa-edit"></i></button>';
}
$htmlout .= '</td></tr>';
}
$htmlout .= '</tbody><tfoot>';
$htmlout .= '<tr><td>' . __( 'total votes', 'WPdoodlez' ).':</td><td></td>';
$pielabel = ''; $piesum = '';
foreach ( $votes_cout as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
$htmlout .= '<td id="total-'. $key .'">'. $value.'</td>';
$pielabel .= strtoupper($key) . ',';
$piesum .= $value . ',';
}
}
$htmlout .= '<td><b>[' . ($nb_elem_per_page*($page) +1 ) . ' - '.($nb_elem_per_page*($page+1) ) .'</b>]</td>';
$htmlout .= '</tr></tfoot>';
} // Ende Terminabstimmung oder Umfrage, nun Fusszeile
$htmlout .= '</table>';
if ( isset($_GET['admin']) || !$polli) {
if ( $number_of_pages >1 ) {
// Page navigation
$html='<div class="nav-links">';
for($i=0;$i<$number_of_pages;$i++){
$seitennummer = $i+1;
$html .= ' <a class="page-numbers" href="'.add_query_arg( array('admin'=>'1', 'seite'=>$i), home_url( $wp->request ) ).'">'.$seitennummer.'</a>';
}
$htmlout .= $html . '</div>';
}
}
// Chart Pie anzeigen zu den Ergebnissen
$piesum = rtrim($piesum, ",");
$pielabel = rtrim($pielabel, ",");
if( class_exists( 'PB_ChartsCodes' ) && !empty($pielabel) && (1 === $chartan) ) {
$htmlout .= do_shortcode('[chartscodes_polar accentcolor="1" title="' . __( 'votes pie chart', 'WPdoodlez' ) . '" values="'.$piesum.'" labels="'.$pielabel.'" absolute="1"]');
}
} /* END password protected? */
return $htmlout;
} // end of get doodlez content
// Doodlez Teilnehmerliste Export CSV (nur als Admin, Aufruf aus WPD-Template)
function wpd_exportteilnehmer() {
if ( current_user_can('administrator') ) {
global $wp;
$htmlout = '';
$suggestions = $votes_cout = [ ];
$customs = get_post_custom( get_the_ID() );
foreach ( $customs as $key => $value ) {
if ( !preg_match( '/^_/is', $key ) ) {
$suggestions[ $key ] = $value;
$votes_cout[ $key ] = 0;
}
}
$polli = array_key_exists('vote1', $suggestions); // if polli add icon to content
if ($polli) $pollfilename = __('poll','WPdoodlez'); else $pollfilename = __('appointment','WPdoodlez');
$filename = 'wpd_teilnehmer_'.$pollfilename.'_'.trim(get_the_title(get_the_ID()));
$output = fopen('php://output', 'w');
ob_clean();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header('Content-Type: text/csv; charset=utf-8');
header("Content-Disposition: attachment; filename=\"" . $filename . ".csv\";" );
header("Content-Transfer-Encoding: binary");
/* password protected? */
if ( !post_password_required() ) {
$csvhead = array( __( 'User name', 'WPdoodlez' ),__( 'bookingdate', 'WPdoodlez' ),
__( 'ip-address', 'WPdoodlez' ), __( 'country', 'WPdoodlez' ) );
foreach ( $suggestions as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
$csvhead[] = $key;
}
}
// print_r($csvhead); // CSV Tabellenkopf schreiben
fputcsv( $output, $csvhead, ';');
// Tabellenzeilen
$votes = get_option( 'wpdoodlez_' . md5( AUTH_KEY . get_the_ID() ), array() );
foreach ( $votes as $name => $vote ) {
$csvout = array();
$csvout[] = mb_convert_encoding($name, 'ISO-8859-1', 'UTF-8');
if (isset($vote['zeit'])) $votezeit = date_i18n(get_option('date_format').' '.get_option('time_format'), $vote['zeit'] + date('Z')); else $votezeit='';
if (isset($vote['ipaddr'])) $voteip = $vote['ipaddr']; else $voteip='';
$csvout[] = $votezeit;
$csvout[] = $voteip;
// Wenn ipflag plugin aktiv und user angemeldet
if( class_exists( 'ipflag' ) && is_user_logged_in() ) {
global $ipflag;
if(isset($ipflag) && is_object($ipflag)){
if(($info = $ipflag->get_info($voteip)) != false){
$csvout[] = $info->code . ' ' .$info->name;
} else { $csvout[] = '-'; }
}
}
foreach ( $suggestions as $key => $value ) {
if (!in_array($key, array("post_views_count","post_views_timestamp","likes","limit_modified_date" ))) {
if ( !empty($vote[ $key ]) ) {
$votes_cout[ $key ] ++;
$csvout[] = mb_convert_encoding($value[ 0 ], 'ISO-8859-1', 'UTF-8');
} else {
$csvout[] = '';
}
}
}
fputcsv( $output, $csvout, ';');
// print_r($csvout);
}
fclose($output);
} /* END password protected? */
return $htmlout;
}
} // nur als Admin
// === ------------------- quizzz code and shortcode --------------------------------------------------------------- ===
function create_quiz_tax_category() {
$labels = array(
'name' => __( 'Quiz Categories', 'WPdoodlez' ),
'singular_name' => __( 'Quiz Category', 'WPdoodlez' ),
'search_items' => __( 'Search Quiz Categories', 'WPdoodlez' ),
'popular_items' => __( 'Popular Quiz Categories', 'WPdoodlez' ),
'all_items' => __( 'All Quiz Categories', 'WPdoodlez' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Quiz Category', 'WPdoodlez' ),
'update_item' => __( 'Update Quiz Category', 'WPdoodlez' ),
'add_new_item' => __( 'Add New Quiz Category', 'WPdoodlez' ),
'new_item_name' => __( 'New Quiz Category', 'WPdoodlez' ),
'separate_items_with_commas' => __( 'Separate categories with commas', 'WPdoodlez' ),
'add_or_remove_items' => __( 'Add or remove Quiz categories', 'WPdoodlez' ),
'choose_from_most_used' => __( 'Choose from the most used categories', 'WPdoodlez' )
);
register_taxonomy(
'quizcategory',
'Question', // this is the custom post type(s) I want to use this taxonomy for
array(
'hierarchical' => false,
'label' => __( 'Quiz-categories', 'WPdoodlez' ),
'query_var' => true,
'labels' => $labels,
'hierarchical' => true,
'show_ui' => true,
'rewrite' => true
)
);
}
add_action( 'init', 'create_quiz_tax_category' );
function create_quiz_post() {
$labels = array(
'name' => __( 'Questions', 'WPdoodlez' ),
'singular_name' => __( 'Question', 'WPdoodlez' ),
'add_new' => __( 'Add New Question', 'WPdoodlez' ),
'add_new_item' => __( 'Add New Question', 'WPdoodlez' ),
'edit_item' => __( 'Edit Question', 'WPdoodlez' ),
'new_item' => __( 'New Question', 'WPdoodlez' ),
'view_item' => __( 'View Question', 'WPdoodlez' ),
'search_items' => __( 'Search Questions', 'WPdoodlez' ),
'not_found' => __( 'No Questions found', 'WPdoodlez' ),
'not_found_in_trash' => __( 'No Questions found in Trash', 'WPdoodlez' ),
'parent_item_colon' => __( 'Parent Question:', 'WPdoodlez' ),
'menu_name' => __( 'Questions', 'WPdoodlez' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => __( 'questions with one or four answers and help mask', 'WPdoodlez' ),
'taxonomies' => array( 'quizcategory', 'post_tag' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-yes',
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post',
'supports' => array( 'title', 'editor', 'thumbnail' )
);
register_post_type( 'Question', $args );
flush_rewrite_rules();
// CSV Import starten, wenn Dateiname im upload dir public_histereignisse.csv ist
if( isset($_REQUEST['quizzzcsv']) && ( $_REQUEST['quizzzcsv'] == true ) && isset( $_REQUEST['nonce'] ) ) {
$nonce = filter_input( INPUT_GET, 'nonce', FILTER_SANITIZE_SPECIAL_CHARS );
if ( ! wp_verify_nonce( $nonce, 'dnonce' ) ) wp_die('Invalid nonce..!!');
importposts();
echo '<script>window.location.href="'.get_home_url().'/wp-admin/edit.php?post_type=question"</script>';
}
// CSV Export starten
if( isset($_REQUEST['quizzzcsvexport']) && ( $_REQUEST['quizzzcsvexport'] == true ) && isset( $_REQUEST['nonce'] ) ) {
$nonce = filter_input( INPUT_GET, 'nonce', FILTER_SANITIZE_SPECIAL_CHARS );
if ( ! wp_verify_nonce( $nonce, 'dnonce' ) ) wp_die('Invalid nonce..!!');
exportposts();
echo '<script>window.location.href="'.get_home_url().'/wp-admin/edit.php?post_type=question"</script>';
}
}
add_action( 'init', 'create_quiz_post' );
// Admin-Spalten ergänzen
// Tabellenkopf und -fuß um Felder erweitern
add_filter('manage_edit-question_columns','qu_edit_admin_columns') ;
function qu_edit_admin_columns($columns) {
unset($columns['shortcodes']);
unset($columns['tags']);
$columns['land'] = __('land of origin','WPdoodlez');
return $columns;
}
// Inhalte aus benutzerdefinierten Feldern holen und den Spalten hinzufügen
add_action ('manage_question_posts_custom_column','qu_post_custom_columns');
function qu_post_custom_columns($column) {
global $post;
$custom = get_post_custom();
switch ($column) {
case "land":
$hkland = get_post_custom_values('quizz_herkunftsland')[0];
$hkiso = get_post_custom_values('quizz_iso')[0];
echo $hkland.' '.$hkiso;
break;
}
}
// Spielesammlung einblenden
function wpd_games_bar() {
$spiele = '<ul class="footer-menu" style="display:inline-block">';
$spiele .= '<li><a style="padding:2px 5px" title="'.__('play crossword','WPdoodlez').'" href="'.add_query_arg( array('crossword'=>1), get_post_permalink() ).'"><i class="fa fa-th"></i> '. __('crossword','WPdoodlez').'</a></li>';
$spiele .= '<li><a style="padding:2px 5px" title="'.__('play word puzzle','WPdoodlez').'" href="'.add_query_arg( array('crossword'=>2), get_post_permalink() ).'"><i class="fa fa-puzzle-piece"></i> '. __('puzzle','WPdoodlez').'</a></li>';
$spiele .= '<li><a style="padding:2px 5px" title="'.__('play hangman','WPdoodlez').'" href="'.add_query_arg( array('crossword'=>3), get_post_permalink() ).'"><i class="fa fa-universal-access"></i> '. __('hangman','WPdoodlez').'</a></li>';
$spiele .= '<li><a style="padding:2px 5px" title="'.__('play sudoku','WPdoodlez').'" href="'.add_query_arg( array('crossword'=>4), get_post_permalink() ).'"><i class="fa fa-table"></i> '. __('Sudoku','WPdoodlez').'</a></li>';
$spiele .= '<li><a style="padding:2px 5px" title="'.__('play word shuffle','WPdoodlez').'" href="'.add_query_arg( array('crossword'=>5), get_post_permalink() ).'"><i class="fa fa-map-signs"></i> '. __('Shuffle','WPdoodlez').'</a></li>';
$spiele .= '</ul>';
return $spiele;
}
// Zusammenstellung eines Quiz mit Wertung Personengebunden
function personal_quiz_exam_func($atts) {
$atts = shortcode_atts( array(
'items' => 20, // Default value 20
'cats' => array('edv'), // Default Cat slug is edv
), $atts );
$catarg = sanitize_text_field($atts[ 'cats' ]);
$anzfragen = (int) $atts['items'];
if (! empty($_POST)) { // Antworten und Auswerten
// Beenden, wenn nonce nicht stimmt.
if ( !wp_verify_nonce( $_POST['quiz_exam_nonce'], 'quiz_exam_submit' ) ) return "Nonce not valid";
$auswertung='';
$erzpunkte = 0;
foreach ($_POST as $key => $value) {
if (str_contains($key,'tname')) $tname = esc_html($value);
if (str_contains($key,'zeit')) $tzeit = esc_html($value);
if (str_contains($key,'ans')) $given = preg_replace("/[^A-Za-z0-9]/", '', strtolower(esc_html($value)));
if (str_contains($key,'rt')) $correcta = preg_replace("/[^A-Za-z0-9]/", '', strtolower(esc_html(base64_decode($value))));
if (str_contains($key,'fra')) {
if ($given == $correcta) {
$erzpunkte += 1;
$auswertung .= '#'. $value.':R';
} else {
$auswertung .= '#'. $value.':F';
}
$auswertung .= ' | ';
}
}
$sperct = round( ( $erzpunkte / $anzfragen ) * 100 , 0 );
// Zertifikat ausgeben
$theForm = '<script>document.getElementsByClassName("entry-title")[0].style.display = "none";</script>';
$theForm .= '<div style="position:relative">
<div><img src="'.plugin_dir_url(__FILE__).'/lightbulb-1000-300.jpg" style="width:100%"></div>
<div class="middle" style="opacity:1;position:absolute;top:50%;bottom:50%;width:100%;text-align:center;color:white;font-size:4em;z-index:99999">'.__('quiz exam certificate','WPdoodlez') .'</div>
</div><div style="text-align:center;padding-top:20px;font-size:1.5em">';
$theForm .= '<h6>'.$tname.'</h6>'.__('you have ','WPdoodlez') .' '.__('at quiz-exam','WPdoodlez') .' "'. strtoupper($catarg)
.'"<br>'.__('within ','WPdoodlez') .' ['.$tzeit.'] '.__('minutes','WPdoodlez') .' '. $anzfragen .' '.__('questions answered','WPdoodlez')
.',<br>'.__('with','WPdoodlez').' '.$erzpunkte. ' ('.$sperct.'%) '.__('right','WPdoodlez').' '.__('and','WPdoodlez') .' '.$anzfragen - $erzpunkte.' ('. (100 - $sperct) .'%) '.__('wrong','WPdoodlez').'.';
$theForm .= '<p style="margin-top:20px"><progress id="file" value="'.$sperct.'" max="100"> '.$sperct.' </progress></p>';
if ( $sperct < 50 ) {
$fail='<span style="color:tomato"><i class="fa fa-thumbs-down"></i> '.__('unfortunately not','WPdoodlez').'</span>';
} else { $fail='<span style="color:green"><i class="fa fa-thumbs-up"></i> '; }
$theForm .= '<p style="margin-top:20px">'.__('in school grades','WPdoodlez').': '.get_schulnote( $sperct ).',<br>'.__('and','WPdoodlez').' <strong>'.$fail.' '.__('passed','WPdoodlez').'</strong>.</p>';
$theForm .= '<blockquote style="font-size:.8em">Auswertung: '.$auswertung.'</blockquote>';
$theForm .= '<p style="font-size:0.7em;margin-top:2em">'.date_i18n( 'D, j. F Y, H:i:s', false, false);
$theForm .= '<span style="font-family:Brush Script MT;font-size:2.6em;padding-left:24px">'.wp_get_current_user()->display_name.'</span></p>';
$theForm .= '<p style="font-size:0.7em">'. get_bloginfo('name') .' '. get_bloginfo('url') .'<br>'.get_bloginfo('description'). '</p></div>';
// Wenn Penguin Theme vorhanden, dann in Datenbank schreiben tabelle pruefungen, ansonsten Tabelle anlegen und speichern
global $wpdb;
// creates pruefungen in database if not exists
$table = $wpdb->prefix . "pruefungen";
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE IF NOT EXISTS " . $table . " (
id int(11) not null auto_increment,
name varchar(60) not null,
seminar varchar(200) not null,
gesamt int(3) not null,
erreicht int(3) not null,
erzielt int(3) not null,
falsch varchar(4000) not null,
dauer varchar(60) not null,
bewertung varchar(500) not null,
userip varchar(50) not null,
datum TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) ) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
$html = '';
// does the inserting, in case the form is filled and submitted
$table = $wpdb->prefix."pruefungen";
$name = strip_tags($_POST["tname"], "");
$seminar = 'Quiz-Examen - '.$catarg;