Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Markus Hermann
wp-polls
Commits
969cbb17
Unverified
Commit
969cbb17
authored
Dec 20, 2018
by
Lester Chan
Browse files
Remove PHP7 brackets
parent
3631b38a
Changes
1
Hide whitespace changes
Inline
Side-by-side
wp-polls.php
View file @
969cbb17
...
...
@@ -532,7 +532,7 @@ function display_pollvote($poll_id, $display_loading = true) {
### Function: Display Results Form
function
display_pollresult
(
$poll_id
,
$user_voted
=
array
(),
$display_loading
=
true
)
{
function
display_pollresult
(
$poll_id
,
$user_voted
=
array
(),
$display_loading
=
true
)
{
global
$wpdb
;
do_action
(
'wp_polls_display_pollresult'
,
$poll_id
,
$user_voted
);
$poll_id
=
(
int
)
$poll_id
;
...
...
@@ -558,8 +558,8 @@ function display_pollresult($poll_id, $user_voted = array(), $display_loading =
// Get Poll Question Data
$poll_question
=
$wpdb
->
get_row
(
$wpdb
->
prepare
(
"SELECT pollq_id, pollq_question, pollq_totalvotes, pollq_active, pollq_timestamp, pollq_expiry, pollq_multiple, pollq_totalvoters FROM
$wpdb->pollsq
WHERE pollq_id = %d LIMIT 1"
,
$poll_id
)
);
// No poll could be loaded from the database
if
(
!
$poll_question
)
{
return
removeslashes
(
get_option
(
'poll_template_disable'
)
);
if
(
!
$poll_question
)
{
return
removeslashes
(
get_option
(
'poll_template_disable'
)
);
}
// Poll Question Variables
$poll_question_text
=
wp_kses_post
(
removeslashes
(
$poll_question
->
pollq_question
)
);
...
...
@@ -567,45 +567,54 @@ function display_pollresult($poll_id, $user_voted = array(), $display_loading =
$poll_question_totalvotes
=
(
int
)
$poll_question
->
pollq_totalvotes
;
$poll_question_totalvoters
=
(
int
)
$poll_question
->
pollq_totalvoters
;
$poll_question_active
=
(
int
)
$poll_question
->
pollq_active
;
$poll_start_date
=
mysql2date
(
sprintf
(
__
(
'%s @ %s'
,
'wp-polls'
),
get_option
(
'date_format'
),
get_option
(
'time_format'
)
),
gmdate
(
'Y-m-d H:i:s'
,
$poll_question
->
pollq_timestamp
)
);
$poll_expiry
=
trim
(
$poll_question
->
pollq_expiry
);
if
(
empty
(
$poll_expiry
)
)
{
$poll_end_date
=
__
(
'No Expiry'
,
'wp-polls'
);
$poll_start_date
=
mysql2date
(
sprintf
(
__
(
'%s @ %s'
,
'wp-polls'
),
get_option
(
'date_format'
),
get_option
(
'time_format'
)
),
gmdate
(
'Y-m-d H:i:s'
,
$poll_question
->
pollq_timestamp
)
);
$poll_expiry
=
trim
(
$poll_question
->
pollq_expiry
);
if
(
empty
(
$poll_expiry
)
)
{
$poll_end_date
=
__
(
'No Expiry'
,
'wp-polls'
);
}
else
{
$poll_end_date
=
mysql2date
(
sprintf
(
__
(
'%s @ %s'
,
'wp-polls'
),
get_option
(
'date_format'
),
get_option
(
'time_format'
)
),
gmdate
(
'Y-m-d H:i:s'
,
$poll_expiry
)
);
$poll_end_date
=
mysql2date
(
sprintf
(
__
(
'%s @ %s'
,
'wp-polls'
),
get_option
(
'date_format'
),
get_option
(
'time_format'
)
),
gmdate
(
'Y-m-d H:i:s'
,
$poll_expiry
)
);
}
$poll_multiple_ans
=
(
int
)
$poll_question
->
pollq_multiple
;
$template_question
=
removeslashes
(
get_option
(
'poll_template_resultheader'
));
$template_question
=
str_replace
(
"%POLL_QUESTION%"
,
$poll_question_text
,
$template_question
);
$template_question
=
str_replace
(
"%POLL_ID%"
,
$poll_question_id
,
$template_question
);
$template_question
=
str_replace
(
"%POLL_TOTALVOTES%"
,
$poll_question_totalvotes
,
$template_question
);
$template_question
=
str_replace
(
"%POLL_TOTALVOTERS%"
,
$poll_question_totalvoters
,
$template_question
);
$template_question
=
str_replace
(
"%POLL_START_DATE%"
,
$poll_start_date
,
$template_question
);
$template_question
=
str_replace
(
"%POLL_END_DATE%"
,
$poll_end_date
,
$template_question
);
$template_question
=
removeslashes
(
get_option
(
'poll_template_resultheader'
)
);
$template_question
=
str_replace
(
array
(
'%POLL_QUESTION%'
,
'%POLL_ID%'
,
'%POLL_TOTALVOTES%'
,
'%POLL_TOTALVOTERS%'
,
'%POLL_START_DATE%'
,
'%POLL_END_DATE%'
),
array
(
$poll_question_text
,
$poll_question_id
,
$poll_question_totalvotes
,
$poll_question_totalvoters
,
$poll_start_date
,
$poll_end_date
),
$template_question
);
if
(
$poll_multiple_ans
>
0
)
{
$template_question
=
str_replace
(
"
%POLL_MULTIPLE_ANS_MAX%
"
,
$poll_multiple_ans
,
$template_question
);
$template_question
=
str_replace
(
'
%POLL_MULTIPLE_ANS_MAX%
'
,
$poll_multiple_ans
,
$template_question
);
}
else
{
$template_question
=
str_replace
(
"
%POLL_MULTIPLE_ANS_MAX%
"
,
'1'
,
$template_question
);
$template_question
=
str_replace
(
'
%POLL_MULTIPLE_ANS_MAX%
'
,
'1'
,
$template_question
);
}
// Get Poll Answers Data
list
(
$order_by
,
$sort_order
)
=
_polls_get_ans_result_sort
();
list
(
$order_by
,
$sort_order
)
=
_polls_get_ans_result_sort
();
$poll_answers
=
$wpdb
->
get_results
(
$wpdb
->
prepare
(
"SELECT polla_aid, polla_answers, polla_votes FROM
$wpdb->pollsa
WHERE polla_qid = %d ORDER BY
$order_by
$sort_order
"
,
$poll_question_id
)
);
// If There Is Poll Question With Answers
if
(
$poll_question
&&
$poll_answers
)
{
if
(
$poll_question
&&
$poll_answers
)
{
// Store The Percentage Of The Poll
$poll_answer_percentage_array
=
array
();
// Is The Poll Total Votes 0?
$poll_totalvotes_zero
=
true
;
if
(
$poll_question_totalvotes
>
0
)
{
if
(
$poll_question_totalvotes
>
0
)
{
$poll_totalvotes_zero
=
false
;
}
// Print Out Result Header Template
$temp_pollresult
.
=
"<div id=
\"
polls-
$poll_question_id
\"
class=
\"
wp-polls
\"
>
\n
"
;
$temp_pollresult
.
=
"
\t\t
$template_question
\n
"
;
foreach
(
$poll_answers
as
$poll_answer
)
{
foreach
(
$poll_answers
as
$poll_answer
)
{
// Poll Answer Variables
$poll_answer_id
=
(
int
)
$poll_answer
->
polla_aid
;
$poll_answer_text
=
wp_kses_post
(
removeslashes
(
$poll_answer
->
polla_answers
)
);
$poll_answer_text
=
wp_kses_post
(
removeslashes
(
$poll_answer
->
polla_answers
)
);
$poll_answer_votes
=
(
int
)
$poll_answer
->
polla_votes
;
// Calculate Percentage And Image Bar Width
$poll_answer_percentage
=
0
;
...
...
@@ -614,22 +623,20 @@ function display_pollresult($poll_id, $user_voted = array(), $display_loading =
if
(
!
$poll_totalvotes_zero
&&
$poll_answer_votes
>
0
)
{
$poll_answer_percentage
=
round
(
(
$poll_answer_votes
/
$poll_question_totalvotes
)
*
100
);
$poll_multiple_answer_percentage
=
round
(
(
$poll_answer_votes
/
$poll_question_totalvoters
)
*
100
);
$poll_answer_imagewidth
=
round
(
$poll_answer_percentage
);
if
(
$poll_answer_imagewidth
===
100
)
{
$poll_answer_imagewidth
=
round
(
$poll_answer_percentage
);
if
(
$poll_answer_imagewidth
===
100
)
{
$poll_answer_imagewidth
=
99
;
}
}
// Make Sure That Total Percentage Is 100% By Adding A Buffer To The Last Poll Answer
$round_percentage
=
apply_filters
(
'wp_polls_round_percentage'
,
false
);
if
(
$round_percentage
)
{
if
(
$poll_multiple_ans
===
0
)
{
$poll_answer_percentage_array
[]
=
$poll_answer_percentage
;
if
(
count
(
$poll_answer_percentage_array
)
===
count
(
$poll_answers
)
)
{
$percentage_error_buffer
=
100
-
array_sum
(
$poll_answer_percentage_array
);
$poll_answer_percentage
+=
$percentage_error_buffer
;
if
(
$poll_answer_percentage
<
0
)
{
$poll_answer_percentage
=
0
;
}
if
(
$round_percentage
&&
$poll_multiple_ans
===
0
)
{
$poll_answer_percentage_array
[]
=
$poll_answer_percentage
;
if
(
count
(
$poll_answer_percentage_array
)
===
count
(
$poll_answers
)
)
{
$percentage_error_buffer
=
100
-
array_sum
(
$poll_answer_percentage_array
);
$poll_answer_percentage
+=
$percentage_error_buffer
;
if
(
$poll_answer_percentage
<
0
)
{
$poll_answer_percentage
=
0
;
}
}
}
...
...
@@ -637,13 +644,13 @@ function display_pollresult($poll_id, $user_voted = array(), $display_loading =
// Let User See What Options They Voted
if
(
in_array
(
$poll_answer_id
,
$user_voted
,
true
)
)
{
// Results Body Variables
$template_answer
=
removeslashes
(
get_option
(
'poll_template_resultbody2'
)
);
$template_answer
=
removeslashes
(
get_option
(
'poll_template_resultbody2'
)
);
}
else
{
// Results Body Variables
$template_answer
=
removeslashes
(
get_option
(
'poll_template_resultbody'
)
);
$template_answer
=
removeslashes
(
get_option
(
'poll_template_resultbody'
)
);
}
$template_answer
=
str_replace
(
[
$template_answer
=
str_replace
(
array
(
'%POLL_ID%'
,
'%POLL_ANSWER_ID%'
,
'%POLL_ANSWER%'
,
...
...
@@ -651,8 +658,8 @@ function display_pollresult($poll_id, $user_voted = array(), $display_loading =
'%POLL_ANSWER_VOTES%'
,
'%POLL_ANSWER_PERCENTAGE%'
,
'%POLL_MULTIPLE_ANSWER_PERCENTAGE%'
,
'%POLL_ANSWER_IMAGEWIDTH%'
,
]
,
[
'%POLL_ANSWER_IMAGEWIDTH%'
)
,
array
(
$poll_question_id
,
$poll_answer_id
,
$poll_answer_text
,
...
...
@@ -660,8 +667,8 @@ function display_pollresult($poll_id, $user_voted = array(), $display_loading =
number_format_i18n
(
$poll_answer_votes
),
$poll_answer_percentage
,
$poll_multiple_answer_percentage
,
$poll_answer_imagewidth
,
]
,
$template_answer
);
$poll_answer_imagewidth
)
,
$template_answer
);
// Print Out Results Body Template
$temp_pollresult
.
=
"
\t\t
$template_answer
\n
"
;
...
...
@@ -683,42 +690,56 @@ function display_pollresult($poll_id, $user_voted = array(), $display_loading =
}
}
// Results Footer Variables
if
(
!
empty
(
$user_voted
)
||
$poll_question_active
===
0
||
!
check_allowtovote
())
{
$template_footer
=
removeslashes
(
get_option
(
'poll_template_resultfooter'
)
);
if
(
!
empty
(
$user_voted
)
||
$poll_question_active
===
0
||
!
check_allowtovote
()
)
{
$template_footer
=
removeslashes
(
get_option
(
'poll_template_resultfooter'
)
);
}
else
{
$template_footer
=
removeslashes
(
get_option
(
'poll_template_resultfooter2'
)
);
$template_footer
=
removeslashes
(
get_option
(
'poll_template_resultfooter2'
)
);
}
$template_footer
=
str_replace
(
"%POLL_START_DATE%"
,
$poll_start_date
,
$template_footer
);
$template_footer
=
str_replace
(
"%POLL_END_DATE%"
,
$poll_end_date
,
$template_footer
);
$template_footer
=
str_replace
(
"%POLL_ID%"
,
$poll_question_id
,
$template_footer
);
$template_footer
=
str_replace
(
"%POLL_TOTALVOTES%"
,
number_format_i18n
(
$poll_question_totalvotes
),
$template_footer
);
$template_footer
=
str_replace
(
"%POLL_TOTALVOTERS%"
,
number_format_i18n
(
$poll_question_totalvoters
),
$template_footer
);
$template_footer
=
str_replace
(
"%POLL_MOST_ANSWER%"
,
$poll_most_answer
,
$template_footer
);
$template_footer
=
str_replace
(
"%POLL_MOST_VOTES%"
,
number_format_i18n
(
$poll_most_votes
),
$template_footer
);
$template_footer
=
str_replace
(
"%POLL_MOST_PERCENTAGE%"
,
$poll_most_percentage
,
$template_footer
);
$template_footer
=
str_replace
(
"%POLL_LEAST_ANSWER%"
,
$poll_least_answer
,
$template_footer
);
$template_footer
=
str_replace
(
"%POLL_LEAST_VOTES%"
,
number_format_i18n
(
$poll_least_votes
),
$template_footer
);
$template_footer
=
str_replace
(
"%POLL_LEAST_PERCENTAGE%"
,
$poll_least_percentage
,
$template_footer
);
if
(
$poll_multiple_ans
>
0
)
{
$template_footer
=
str_replace
(
"%POLL_MULTIPLE_ANS_MAX%"
,
$poll_multiple_ans
,
$template_footer
);
$template_footer
=
str_replace
(
array
(
'%POLL_START_DATE%'
,
'%POLL_END_DATE%'
,
'%POLL_ID%'
,
'%POLL_TOTALVOTES%'
,
'%POLL_TOTALVOTERS%'
,
'%POLL_MOST_ANSWER%'
,
'%POLL_MOST_VOTES%'
,
'%POLL_MOST_PERCENTAGE%'
,
'%POLL_LEAST_ANSWER%'
,
'%POLL_LEAST_VOTES%'
,
'%POLL_LEAST_PERCENTAGE%'
),
array
(
$poll_start_date
,
$poll_end_date
,
$poll_question_id
,
number_format_i18n
(
$poll_question_totalvotes
),
number_format_i18n
(
$poll_question_totalvoters
),
$poll_most_answer
,
number_format_i18n
(
$poll_most_votes
),
$poll_most_percentage
,
$poll_least_answer
,
number_format_i18n
(
$poll_least_votes
),
$poll_least_percentage
),
$template_footer
);
if
(
$poll_multiple_ans
>
0
)
{
$template_footer
=
str_replace
(
'%POLL_MULTIPLE_ANS_MAX%'
,
$poll_multiple_ans
,
$template_footer
);
}
else
{
$template_footer
=
str_replace
(
"
%POLL_MULTIPLE_ANS_MAX%
"
,
'1'
,
$template_footer
);
$template_footer
=
str_replace
(
'
%POLL_MULTIPLE_ANS_MAX%
'
,
'1'
,
$template_footer
);
}
// Print Out Results Footer Template
$temp_pollresult
.
=
"
\t\t
$template_footer
\n
"
;
$temp_pollresult
.
=
"
\t\t
<input type=
\"
hidden
\"
id=
\"
poll_
{
$poll_question_id
}
_nonce
\"
name=
\"
wp-polls-nonce
\"
value=
\"
"
.
wp_create_nonce
(
'poll_'
.
$poll_question_id
.
'-nonce'
)
.
"
\"
/>
\n
"
;
$temp_pollresult
.
=
"</div>
\n
"
;
if
(
$display_loading
)
{
$poll_ajax_style
=
get_option
(
'poll_ajax_style'
);
if
(
(
int
)
$poll_ajax_style
[
'loading'
]
===
1
)
{
if
(
$display_loading
)
{
$poll_ajax_style
=
get_option
(
'poll_ajax_style'
);
if
(
(
int
)
$poll_ajax_style
[
'loading'
]
===
1
)
{
$temp_pollresult
.
=
"<div id=
\"
polls-
$poll_question_id
-loading
\"
class=
\"
wp-polls-loading
\"
><img src=
\"
"
.
plugins_url
(
'wp-polls/images/loading.gif'
)
.
"
\"
width=
\"
16
\"
height=
\"
16
\"
alt=
\"
"
.
__
(
'Loading'
,
'wp-polls'
)
.
" ...
\"
title=
\"
"
.
__
(
'Loading'
,
'wp-polls'
)
.
" ...
\"
class=
\"
wp-polls-image
\"
/> "
.
__
(
'Loading'
,
'wp-polls'
)
.
" ...</div>
\n
"
;
}
}
}
else
{
$temp_pollresult
.
=
removeslashes
(
get_option
(
'poll_template_disable'
)
);
$temp_pollresult
.
=
removeslashes
(
get_option
(
'poll_template_disable'
)
);
}
// Return Poll Result
return
apply_filters
(
'poll_result_markup'
,
$temp_pollresult
);
return
apply_filters
(
'poll_result_markup'
,
$temp_pollresult
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment