PluginProbe
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls / 6.3.3
Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls v6.3.3
6.4.9 6.4.8 6.4.7 6.4.6 6.4.5 6.4.4 6.4.3 6.4.2 6.4.1 6.4.0 6.3.9 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 All 152 releases
poll-maker / public / partials / class-poll-maker-extra-shortcode.php

class-poll-maker-extra-shortcode.php in Poll Maker by AYS – Versus Polls, Anonymous Polls, Image Polls 6.3.3, at public/partials/class-poll-maker-extra-shortcode.php

805 lines 27.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The public-facing functionality of the plugin.
5 *
6 * @link https://ays-pro.com/
7 * @since 1.0.0
8 *
9 * @package Poll_Maker_Ays
10 * @subpackage Poll_Maker_Ays/public
11 */
12
13 /**
14 * The public-facing functionality of the plugin.
15 *
16 * Defines the plugin name, version, and two examples hooks for how to
17 * enqueue the public-facing stylesheet and JavaScript.
18 *
19 * @package Poll_Maker_Ays
20 * @subpackage Poll_Maker_Ays/public
21 * @author Poll Maker Team <info@ays-pro.com>
22 */
23 class Ays_Poll_Maker_Extra_Shortcodes_Public
24 {
25
26 /**
27 * The ID of this plugin.
28 *
29 * @since 1.0.0
30 * @access private
31 * @var string $plugin_name The ID of this plugin.
32 */
33 protected $plugin_name;
34
35 /**
36 * The version of this plugin.
37 *
38 * @since 1.0.0
39 * @access private
40 * @var string $version The current version of this plugin.
41 */
42 private $version;
43
44 private $html_class_prefix = 'ays-poll-extra-shortcodes-';
45 private $html_name_prefix = 'ays-poll-';
46 private $name_prefix = 'ays_poll_';
47 private $unique_id;
48 private $unique_id_in_class;
49
50 /**
51 * Initialize the class and set its properties.
52 *
53 * @since 1.0.0
54 * @param string $plugin_name The name of the plugin.
55 * @param string $version The version of this plugin.
56 */
57 public function __construct($plugin_name, $version){
58
59 $this->plugin_name = $plugin_name;
60 $this->version = $version;
61
62 add_shortcode('ays_poll_passed_users_count', array($this, 'ays_generate_passed_users_count_method'));
63 add_shortcode('ays_poll_user_first_name', array($this, 'ays_generate_user_first_name_method'));
64 add_shortcode('ays_poll_user_last_name', array($this, 'ays_generate_user_last_name_method'));
65 add_shortcode('ays_poll_user_display_name', array($this, 'ays_generate_user_display_name_method'));
66 add_shortcode('ays_poll_creation_date', array($this, 'ays_generate_creation_date_method'));
67 add_shortcode('ays_poll_user_email', array($this, 'ays_generate_user_email_method'));
68 add_shortcode('ays_poll_user_passed_polls_count', array($this, 'ays_generate_user_passed_polls_count_method'));
69 add_shortcode('ays_poll_user_all_passed_polls_count', array($this, 'ays_generate_user_all_passed_polls_count_method'));
70 add_shortcode('ays_poll_categories_descriptions', array($this, 'ays_generate_category_description_method'));
71 add_shortcode('ays_poll_categories_titles', array($this, 'ays_generate_category_title_method'));
72 add_shortcode('ays_poll_current_author', array($this, 'ays_generate_current_poll_author_method'));
73 add_shortcode('ays_poll_answers_count', array($this, 'ays_generate_poll_answers_count_method'));
74 }
75
76 /*
77 ==========================================
78 Passed users count | Start
79 ==========================================
80 */
81
82 public function ays_generate_passed_users_count_method( $attr ){
83
84 $id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
85
86 if (is_null($id) || $id == 0 ) {
87 $passed_users_count_html = "<p class='wrong_shortcode_text' style='color:red;'>" .esc_html__('Wrong shortcode initialized', "poll-maker") . "</p>";
88 return str_replace(array("\r\n", "\n", "\r"), "\n", $passed_users_count_html);
89 }
90
91 $unique_id = uniqid();
92 $this->unique_id = $unique_id;
93 $this->unique_id_in_class = $id . "-" . $unique_id;
94
95
96 $passed_users_count_html = $this->ays_poll_passed_users_count_html( $id );
97 return str_replace(array("\r\n", "\n", "\r"), "\n", $passed_users_count_html);
98 }
99
100 public function ays_poll_passed_users_count_html( $id ){
101
102 $results = array();
103 if ( class_exists( 'Poll_Maker_Ays_Public' ) ) {
104 $results = Poll_Maker_Ays_Public::get_poll_results_count_by_id( $id );
105 }
106
107 $content_html = array();
108 if( is_null( $results ) ){
109 $content_html = "<p style='text-align: center;font-style:italic;'>" .esc_html__( "There are no results yet.", "poll-maker" ) . "</p>";
110 return $content_html;
111 }
112
113 $passed_users_count = (isset( $results['res_count'] ) && $results['res_count'] != '') ? sanitize_text_field( $results['res_count'] ) : 0;
114
115 if ( $passed_users_count == 0 ) {
116 $content_html = "<p style='text-align: center;font-style:italic;'>" .esc_html__( "There are no results yet.", "poll-maker" ) . "</p>";
117 return $content_html;
118 }
119
120 $content_html[] = "<span class='". $this->html_name_prefix ."passed-users-count-box' id='". $this->html_name_prefix ."passed-users-count-box-". $this->unique_id_in_class ."' data-id='". $this->unique_id ."'>";
121 $content_html[] = $passed_users_count;
122 $content_html[] = "</span>";
123
124 $content_html = implode( '' , $content_html);
125
126 return $content_html;
127 }
128
129 /*
130 ==========================================
131 Passed users count | End
132 ==========================================
133 */
134
135 /*
136 ==========================================
137 Show users firstname | Start
138 ==========================================
139 */
140 public function ays_generate_user_first_name_method(){
141
142 $unique_id = uniqid();
143 $this->unique_id = $unique_id;
144 $this->unique_id_in_class = $unique_id;
145
146 $user_first_name_html = "";
147 if(is_user_logged_in()){
148 $user_first_name_html = $this->ays_generate_users_html('first');
149 }
150 return str_replace(array("\r\n", "\n", "\r"), "\n", $user_first_name_html);
151 }
152 /*
153 ==========================================
154 Show users firstname | End
155 ==========================================
156 */
157
158 /*
159 ==========================================
160 Show users lastname | Start
161 ==========================================
162 */
163 public function ays_generate_user_last_name_method(){
164
165 $unique_id = uniqid();
166 $this->unique_id = $unique_id;
167 $this->unique_id_in_class = $unique_id;
168
169 $user_last_name_html = "";
170 if(is_user_logged_in()){
171 $user_last_name_html = $this->ays_generate_users_html('last');
172 }
173 return str_replace(array("\r\n", "\n", "\r"), "\n", $user_last_name_html);
174 }
175 /*
176 ==========================================
177 Show users lastname | Start
178 ==========================================
179 */
180
181 /*
182 ==========================================
183 Show User Display name | Start
184 ==========================================
185 */
186
187 public function ays_generate_user_display_name_method(){
188
189 $unique_id = uniqid();
190 $this->unique_id = $unique_id;
191 $this->unique_id_in_class = $unique_id;
192
193 $user_display_name_html = "";
194 if(is_user_logged_in()){
195 $user_display_name_html = $this->ays_generate_users_html('display');
196 }
197 return str_replace(array("\r\n", "\n", "\r"), "\n", $user_display_name_html);
198 }
199
200 /*
201 ==========================================
202 Show User Display name | End
203 ==========================================
204 */
205
206 /*
207 ==========================================
208 Poll show creation date | Start
209 ==========================================
210 */
211 public function ays_generate_creation_date_method( $attr ){
212
213 $id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
214
215 if (is_null($id) || $id == 0 ) {
216 $poll_creation_date_html = "<p class='wrong_shortcode_text' style='color:red;'>" .esc_html__('Wrong shortcode initialized', "poll-maker") . "</p>";
217 return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_creation_date_html);
218 }
219
220 $unique_id = uniqid();
221 $this->unique_id = $unique_id;
222 $this->unique_id_in_class = $id . "-" . $unique_id;
223
224
225 $poll_creation_date_html = $this->ays_poll_creation_date_html( $id );
226 return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_creation_date_html);
227 }
228
229 public function ays_poll_creation_date_html( $id ){
230
231 $results = $this->get_curent_poll_creation_date($id);
232
233 $content_html = array();
234
235 if($results === null){
236 $content_html = "<p style='text-align: center;font-style:italic;'>" .esc_html__( "There are no results yet.", "poll-maker" ) . "</p>";
237 return $content_html;
238 }
239
240 $content_html[] = "<span class='". $this->html_name_prefix ."creation-date-box' id='". $this->html_name_prefix ."creation-date-box-". $this->unique_id_in_class ."' data-id='". $this->unique_id ."'>";
241 $content_html[] = $results;
242 $content_html[] = "</span>";
243
244 $content_html = implode( '' , $content_html);
245
246 return $content_html;
247 }
248 /*
249 ==========================================
250 Poll show creation date | End
251 ==========================================
252 */
253
254 /*
255 ==========================================
256 Show User Display name | Start
257 ==========================================
258 */
259
260 public function ays_generate_user_email_method(){
261
262 $unique_id = uniqid();
263 $this->unique_id = $unique_id;
264 $this->unique_id_in_class = $unique_id;
265
266 $user_email_html = "";
267 if(is_user_logged_in()){
268 $user_email_html = $this->ays_generate_users_html('email');
269 }
270 return str_replace(array("\r\n", "\n", "\r"), "\n", $user_email_html);
271 }
272
273 /*
274 ==========================================
275 Show User Display name | End
276 ==========================================
277 */
278
279 public function ays_generate_users_html($arg){
280
281 $results = $this->get_user_profile_data();
282
283 $content_html = array();
284
285 if( is_null( $results ) || $results == 0 ){
286 $content_html = "";
287 return $content_html;
288 }
289
290 $user_info = (isset( $results['user_'.$arg.'_name'] ) && $results['user_'.$arg.'_name'] != "") ? sanitize_text_field( $results['user_'.$arg.'_name'] ) : '';
291
292 $content_html[] = "<span class='ays-poll-user-".$arg."-name' id='ays-poll-user-".$arg."-name-". $this->unique_id_in_class ."' data-id='". $this->unique_id ."'>";
293 $content_html[] = $user_info;
294 $content_html[] = "</span>";
295
296 $content_html = implode( '' , $content_html);
297
298 return $content_html;
299 }
300
301 public function get_user_profile_data(){
302
303 $user_first_name = '';
304 $user_last_name = '';
305 $user_nickname = '';
306
307 $user_id = get_current_user_id();
308 if($user_id != 0){
309 $usermeta = get_user_meta( $user_id );
310 if($usermeta !== null){
311 $user_first_name = (isset($usermeta['first_name'][0]) && sanitize_text_field( $usermeta['first_name'][0] != '') ) ? sanitize_text_field( $usermeta['first_name'][0] ) : '';
312 $user_last_name = (isset($usermeta['last_name'][0]) && sanitize_text_field( $usermeta['last_name'][0] != '') ) ? sanitize_text_field( $usermeta['last_name'][0] ) : '';
313 $user_nickname = (isset($usermeta['nickname'][0]) && sanitize_text_field( $usermeta['nickname'][0] != '') ) ? sanitize_text_field( $usermeta['nickname'][0] ) : '';
314 }
315
316 $current_user_data = get_userdata( $user_id );
317 if ( ! is_null( $current_user_data ) && $current_user_data ) {
318 $user_display_name = ( isset( $current_user_data->data->display_name ) && $current_user_data->data->display_name != '' ) ? sanitize_text_field( $current_user_data->data->display_name ) : "";
319 $user_email = ( isset( $current_user_data->data->user_email ) && $current_user_data->data->user_email != '' ) ? sanitize_text_field( $current_user_data->data->user_email ) : "";
320 }
321 }
322
323 $message_data = array(
324 'user_first_name' => $user_first_name,
325 'user_last_name' => $user_last_name,
326 'user_nickname' => $user_nickname,
327 'user_display_name' => $user_display_name,
328 'user_email_name' => $user_email,
329 );
330
331 return $message_data;
332 }
333
334 public function get_curent_poll_creation_date( $id ){
335 global $wpdb;
336
337 $polls_table = esc_sql( $wpdb->prefix . "ayspoll_polls" );
338
339 if (is_null($id) || $id == 0 ) {
340 return null;
341 }
342
343 $id = absint( $id );
344
345 $sql = "SELECT `styles` FROM `{$polls_table}` WHERE `id` = {$id}";
346 $results = $wpdb->get_var($sql);
347
348 $styles = ( isset( $results ) && $results != '' ) ? json_decode( $results, true ) : '';
349
350 if ( is_null( $results ) || $results == "" ) {
351 $results = null;
352 }
353
354 $creation_date = (isset( $styles['create_date'] ) && $styles['create_date'] != '') ? date_i18n( get_option( 'date_format' ), strtotime( $styles['create_date'] ) ) : '';
355
356 return sanitize_text_field( $creation_date );
357 }
358
359 /*
360 ==========================================
361 Passed polls count per user | Start
362 ==========================================
363 */
364 public function get_user_passed_polls_count( $user_id ){
365 global $wpdb;
366
367 if (is_null($user_id) || $user_id == 0 ) {
368 return null;
369 }
370
371 $user_id = absint( $user_id );
372
373 $reports_table = esc_sql($wpdb->prefix."ayspoll_reports");
374 $answ_table = esc_sql($wpdb->prefix."ayspoll_answers");
375 $polls_table = esc_sql($wpdb->prefix."ayspoll_polls");
376
377 $sql = "SELECT COUNT(*) FROM {$reports_table} AS r
378 JOIN {$answ_table} AS a
379 ON a.id = r.answer_id
380 JOIN {$polls_table} AS p
381 ON a.poll_id = p.id
382 WHERE r.user_id = ".$user_id;
383
384 $results = $wpdb->get_var($sql);
385
386 if ( ! empty( $results ) ) {
387 $results = absint( $results );
388 } else {
389 $results = 0;
390 }
391
392 return $results;
393 }
394
395 public function ays_generate_user_passed_polls_count_method(){
396
397 $unique_id = uniqid();
398 $this->unique_id = $unique_id;
399 $this->unique_id_in_class = $unique_id;
400
401 $passed_polls_count_html = "";
402 if(is_user_logged_in()){
403 $passed_polls_count_html = $this->ays_generate_user_passed_polls_count_html();
404 }
405 return str_replace(array("\r\n", "\n", "\r"), "\n", $passed_polls_count_html);
406 }
407
408 public function ays_generate_user_passed_polls_count_html(){
409 $user_id = get_current_user_id();
410
411 $results = $this->get_user_passed_polls_count( $user_id );
412
413 $content_html = array();
414
415 if( is_null( $results ) || $results == 0 ){
416 $content_html = "";
417 return $content_html;
418 }
419
420 $content_html[] = "<span class='". $this->html_name_prefix ."passed-polls-count-per-user' id='". $this->html_name_prefix ."passed-polls-count-per-user-". $this->unique_id_in_class ."' data-id='". $this->unique_id ."'>";
421 $content_html[] = $results;
422 $content_html[] = "</span>";
423
424 $content_html = implode( '' , $content_html);
425
426 return $content_html;
427 }
428
429 /*
430 ==========================================
431 Passed polls count per user | End
432 ==========================================
433 */
434
435 /*
436 ==========================================
437 All passed polls count per user | Start
438 ==========================================
439 */
440 public function get_user_all_passed_polls_count( $user_id ){
441 global $wpdb;
442
443 $reports_table = esc_sql( $wpdb->prefix . "ayspoll_reports" );
444 $answ_table = esc_sql($wpdb->prefix . "ayspoll_answers");
445 $polls_table = esc_sql($wpdb->prefix . "ayspoll_polls");
446
447 if (is_null($user_id) || $user_id == 0 ) {
448 return null;
449 }
450
451 $user_id = absint( $user_id );
452
453 $sql = "SELECT SUM(a.count) FROM ( SELECT COUNT(*) AS count FROM {$reports_table} AS r
454 JOIN {$answ_table} AS a
455 ON a.id = r.answer_id
456 JOIN {$polls_table} AS p
457 ON a.poll_id = p.id
458 WHERE r.user_id = {$user_id} ) AS a";
459
460 $results = $wpdb->get_var($sql);
461
462 if ( ! empty( $results ) ) {
463 $results = absint( $results );
464 } else {
465 $results = 0;
466 }
467
468 return $results;
469 }
470
471 public function ays_generate_user_all_passed_polls_count_method(){
472
473 $unique_id = uniqid();
474 $this->unique_id = $unique_id;
475 $this->unique_id_in_class = $unique_id;
476
477 $all_passed_polls_count_html = "";
478 if(is_user_logged_in()){
479 $all_passed_polls_count_html = $this->ays_generate_user_all_passed_polls_count_html();
480 }
481 return str_replace(array("\r\n", "\n", "\r"), "\n", $all_passed_polls_count_html);
482 }
483
484 public function ays_generate_user_all_passed_polls_count_html(){
485 $user_id = get_current_user_id();
486
487 $results = $this->get_user_all_passed_polls_count( $user_id );
488
489 $content_html = array();
490
491 if( is_null( $results ) || $results == 0 ){
492 $content_html = "";
493 return $content_html;
494 }
495
496 $content_html[] = "<span class='". $this->html_name_prefix ."all-passed-polls-count-per-user' id='". $this->html_name_prefix ."all-passed-polls-count-per-user-". $this->unique_id_in_class ."' data-id='". $this->unique_id ."'>";
497 $content_html[] = $results;
498 $content_html[] = "</span>";
499
500 $content_html = implode( '' , $content_html);
501
502 return $content_html;
503 }
504
505 /*
506 ==========================================
507 All passed polls count per user | End
508 ==========================================
509 */
510
511 public static function get_poll_by_id($id){
512 global $wpdb;
513
514 $sql = "SELECT *
515 FROM {$wpdb->prefix}ayspoll_polls
516 WHERE id=" . absint($id);
517
518 $poll = $wpdb->get_row($sql, 'ARRAY_A');
519
520 return $poll;
521 }
522
523 /*
524 ==========================================
525 Show poll category description | Start
526 ==========================================
527 */
528
529 public function ays_generate_category_description_method( $attr ) {
530 $id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
531
532 if (is_null($id) || $id == 0 ) {
533 $poll_category_description = "";
534 return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_category_description);
535 }
536
537 $unique_id = uniqid();
538 $this->unique_id = $unique_id;
539 $this->unique_id_in_class = $unique_id;
540
541 $poll_category_description = $this->ays_generate_category_description_html( $id );
542
543 return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_category_description);
544 }
545
546 public function get_poll_category_by_id( $id ) {
547 global $wpdb;
548 $cat_table = esc_sql($wpdb->prefix."ayspoll_categories");
549 $sql = "SELECT * FROM ".$cat_table." WHERE id IN(".implode( ',', $id).")";
550 $result = $wpdb->get_results( $sql, 'ARRAY_A' );
551
552 return $result;
553 }
554
555 public function ays_generate_category_description_html( $id ) {
556 $poll_data = self::get_poll_by_id($id);
557
558 if( is_null( $poll_data ) || empty( $poll_data ) ){
559 $content_html = "";
560 return $content_html;
561 }
562
563 $poll_category_id = (isset($poll_data['categories']) && $poll_data['categories'] != '') ? explode( ',', $poll_data['categories']) : "";
564
565 if ( $poll_category_id == "") {
566 $content_html = "";
567 return $content_html;
568 }
569
570 $results = self::get_poll_category_by_id(array_filter( $poll_category_id ));
571 $content_html = array();
572
573 if( is_null( $results ) || empty( $results ) ){
574 $content_html = "";
575 return $content_html;
576 }
577
578 $content_html[] = "<div class='". $this->html_name_prefix ."category-description' id='". $this->html_name_prefix ."category-description-". $this->unique_id_in_class ."' data-id='". $this->unique_id ."'>";
579 foreach ($results as $key => $result) {
580 $category_description = (isset($result['description']) && $result['description'] != '') ? Poll_Maker_Data::ays_poll_autoembed($result['description']) : "";
581
582 if ( $category_description == "" ) {
583 $content_html = "";
584 return $content_html;
585 }
586
587 $content_html[] = $category_description;
588 }
589 $content_html[] = "</div>";
590
591 $content_html = implode( '' , $content_html);
592
593 return $content_html;
594 }
595
596 /*
597 ==========================================
598 Show poll category description | End
599 ==========================================
600 */
601 /*
602 ==========================================
603 Show poll category title | Start
604 ==========================================
605 */
606
607 public function ays_generate_category_title_method( $attr ) {
608 $id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
609
610 if (is_null($id) || $id == 0 ) {
611 $poll_category_title = "";
612 return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_category_title);
613 }
614
615 $unique_id = uniqid();
616 $this->unique_id = $unique_id;
617 $this->unique_id_in_class = $unique_id;
618
619 $poll_category_title = $this->ays_generate_category_title_html( $id );
620
621 return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_category_title);
622 }
623
624 public function ays_generate_category_title_html( $id ) {
625 $poll_data = self::get_poll_by_id($id);
626
627 if( is_null( $poll_data ) || empty( $poll_data ) ){
628 $content_html = "";
629 return $content_html;
630 }
631
632 $poll_category_id = (isset($poll_data['categories']) && $poll_data['categories'] != '') ? explode( ',', $poll_data['categories']) : "";
633
634 if ( $poll_category_id == "") {
635 $content_html = "";
636 return $content_html;
637 }
638
639 $results = self::get_poll_category_by_id(array_filter( $poll_category_id ));
640 $content_html = array();
641
642 if( is_null( $results ) || empty( $results ) ){
643 $content_html = "";
644 return $content_html;
645 }
646
647 $content_html[] = "<div class='". $this->html_name_prefix ."category-title' id='". $this->html_name_prefix ."category-title-". $this->unique_id_in_class ."' data-id='". $this->unique_id ."'>";
648 foreach ($results as $key => $result) {
649 $category_title = (isset($result['title']) && $result['title'] != '') ? Poll_Maker_Data::ays_poll_autoembed($result['title']) : "";
650
651 if ( $category_title == "" ) {
652 $content_html = "";
653 return $content_html;
654 }
655
656 $content_html[] = $category_title;
657 }
658 $content_html[] = "</div>";
659
660 $content_html = implode( '' , $content_html);
661
662 return $content_html;
663 }
664
665 /*
666 ==========================================
667 Show poll category title | End
668 ==========================================
669 */
670
671 /*
672 ==========================================
673 Show current poll author | Start
674 ==========================================
675 */
676
677 public function ays_generate_current_poll_author_method( $attr ) {
678
679 $id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
680
681 if (is_null($id) || $id == 0 ) {
682 $poll_author = "";
683 return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_author);
684 }
685
686 $unique_id = uniqid();
687 $this->unique_id = $unique_id;
688 $this->unique_id_in_class = $unique_id;
689
690 $poll_author = $this->ays_generate_current_poll_author_html( $id );
691 return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_author);
692 }
693
694 public function ays_generate_current_poll_author_html( $id ) {
695
696 global $wpdb;
697
698 $polls_table = esc_sql( $wpdb->prefix . "ayspoll_polls" );
699
700 if (is_null($id) || $id == 0 ) {
701 return null;
702 }
703
704 $id = absint( $id );
705
706 $sql = "SELECT `styles` FROM `{$polls_table}` WHERE `id` = {$id}";
707 $results = $wpdb->get_var($sql);
708
709 $content_html = array();
710
711 if( is_null( $results ) || empty( $results ) ){
712 $content_html = "";
713 return $content_html;
714 }
715
716 $options = ( json_decode($results, true) != null ) ? json_decode($results, true) : array();
717
718 if(isset($options['author'])){
719 if(is_array($options['author'])){
720 $author = $options['author'];
721 }else{
722 $author = json_decode($options['author'], true);
723 }
724 }else{
725 $author = array("name"=>"Unknown");
726 }
727
728 if(isset($author['name']) && $author['name'] == "Unknown"){
729 $author['name'] =esc_html__( "Unknown", "poll-maker" );
730 }
731
732 $poll_author = (isset($author['name']) && $author['name'] != '') ? sanitize_text_field( $author['name'] ) : "";
733
734 $content_html[] = "<span class='". $this->html_name_prefix ."current-poll-author' id='". $this->html_name_prefix ."current-poll-author-". $this->unique_id_in_class ."' data-id='". $this->unique_id ."'>";
735 $content_html[] = $poll_author;
736 $content_html[] = "</span>";
737
738 $content_html = implode( '' , $content_html);
739
740 return $content_html;
741 }
742
743 /*
744 ==========================================
745 Show current poll author | End
746 ==========================================
747 */
748
749 /*
750 ==========================================
751 Show poll answers count | Start
752 ==========================================
753 */
754
755 public function ays_generate_poll_answers_count_method( $attr ){
756
757 $id = (isset($attr['id']) && $attr['id'] != '') ? absint( sanitize_text_field($attr['id']) ) : null;
758
759 if (is_null($id) || $id == 0 ) {
760 $poll_answers_count = "";
761 return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_answers_count);
762 }
763
764 $unique_id = uniqid();
765 $this->unique_id = $unique_id;
766 $this->unique_id_in_class = $unique_id;
767
768 $poll_answers_count = $this->ays_generate_poll_answers_count_html( $id );
769
770 return str_replace(array("\r\n", "\n", "\r"), "\n", $poll_answers_count);
771 }
772
773 public function ays_generate_poll_answers_count_html($id) {
774 global $wpdb;
775 $answers_table = esc_sql($wpdb->prefix."ayspoll_answers");
776 $sql = "SELECT COUNT($id)
777 FROM {$answers_table}
778 WHERE poll_id=" . esc_sql( absint( $id ) );
779
780 $answers_str = $wpdb->get_var( $sql );
781 $count = intval( $answers_str );
782
783 $content_html = array();
784
785 if( is_null( $count ) || $count == 0 ){
786 $content_html = "";
787 return $content_html;
788 }
789
790 $content_html[] = "<span class='". $this->html_name_prefix ."poll-answers-count' id='". $this->html_name_prefix ."poll-answers-count". $this->unique_id_in_class ."' data-id='". $this->unique_id ."'>";
791 $content_html[] = $count;
792 $content_html[] = "</span>";
793
794 $content_html = implode( '' , $content_html);
795
796 return $content_html;
797 }
798
799 /*
800 ==========================================
801 Show poll answers count | End
802 ==========================================
803 */
804 }
805