/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { //$kod[] = "<script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>"; $title = apply_filters('widget_title', $instance['title']); echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } $poll_id = !empty($instance['poll_id']) ? intval($instance['poll_id']) : -1; if ($poll_id > 0) { $oPoll = GFontsDB::GetPoll($poll_id); if ($oPoll) { $client_mode = $oPoll->client_mode; $allowed = true; $ip = $_SERVER['REMOTE_ADDR']; if (isset($_SERVER['HTTP_X_REAL_IP'])) { $ip = $_SERVER['HTTP_X_REAL_IP']; } $allowed = $oPoll->voting_enabled == 1; if ($allowed) { $enddate = strtotime($oPoll->voting_end_date); $today = time(); if ($enddate < $today) { $allowed = false; } } if ($client_mode == 0) { $w = $_COOKIE; if (isset($_COOKIE['poll_vote_' . $poll_id])) { $allowed = false; } } else { $c = GFontsDB::CheckVoteIpForPoll($poll_id, $ip); if ($c > 0) { $allowed = false; } } if (!$allowed) { echo "<div>" . $oPoll->title . "</div>"; ?> <div id="wgarea_<?php echo $args['widget_id']; ?> _<?php echo $poll_id; ?> "><?php echo GF_Poll_Output::GeneratePollOutput($oPoll, 'wgarea_' . $args['widget_id'] . '_' . $poll_id, $instance['chwidth'], $instance['chheight'], $instance['chlegend']); ?> </div><br/><?php } else { wp_enqueue_script('gf-poll-service-' . $poll_id, PLUGIN_URL . "js/gf-poll.php?id=" . $poll_id . '&wid=' . $args['widget_id'] . '&width=' . $instance['chwidth'] . '&height=' . $instance['chheight'] . '&legend=' . $instance['chlegend']); $trans = array('noanswer' => GFontsLang::GetTranslation('Please select answer'), 'ajaxerror' => GFontsLang::GetTranslation('Some error happened'), 'ajaxurl' => admin_url('admin-ajax.php')); wp_localize_script('gf-poll-service-' . $poll_id, 'objPollServiceTrans', $trans); echo "<div>" . $oPoll->title . "</div>"; ?> <div id="wgarea_<?php echo $args['widget_id']; ?> _<?php echo $poll_id; ?> "><?php $answers = GFontsDB::GetAnswersForPoll($poll_id); if (is_array($answers)) { ?> <form method="post" action="#"><?php foreach ($answers as $answer) { ?> <input type="radio" name="poll_<?php echo $args['widget_id']; ?> " id="poll_<?php echo $args['widget_id'] . '-' . $answer->id; ?> " value="<?php echo $answer->id; ?> "/> <label for="poll_<?php echo $args['widget_id'] . '-' . $answer->id; ?> "><?php echo stripslashes($answer->answer); ?> </label><br/><?php } ?> </form><br/><center><input type="submit" value="<?php _e(trim($oPoll->button_title) != '' ? $oPoll->button_title : 'Vote'); ?> " id="btn_<?php echo $poll_id; ?> _<?php echo $args['widget_id']; ?> "/></center> <?php } ?> </div><br/><?php } } } echo $args['after_widget']; }
public static function PollOutputForShortCode($poll_id, $width, $height, $legend = 'none') { $output = ""; $oPoll = GFontsDB::GetPoll($poll_id); if ($oPoll) { $client_mode = $oPoll->client_mode; $allowed = true; $ip = $_SERVER['REMOTE_ADDR']; if (isset($_SERVER['HTTP_X_REAL_IP'])) { $ip = $_SERVER['HTTP_X_REAL_IP']; } $allowed = $oPoll->voting_enabled == 1; if ($allowed) { $enddate = strtotime($oPoll->voting_end_date); $today = time(); if ($enddate < $today) { $allowed = false; } } if ($client_mode == 0) { $w = $_COOKIE; if (isset($_COOKIE['poll_vote_' . $poll_id])) { $allowed = false; } } else { $c = GFontsDB::CheckVoteIpForPoll($poll_id, $ip); if ($c > 0) { $allowed = false; } } $args['widget_id'] = uniqid(); if (!$allowed) { $output .= $oPoll->title . "<br/>"; $output .= '<span id="wgarea_' . $args['widget_id'] . '_' . $poll_id . '" style="width: 100%;">'; $output .= GF_Poll_Output::GeneratePollOutput($oPoll, 'wgarea_' . $args['widget_id'] . '_' . $poll_id, $width, $height, $legend); $output .= '</span>'; } else { wp_enqueue_script('gf-poll-service-' . $poll_id, PLUGIN_URL . "js/gf-poll.php?id=" . $poll_id . '&wid=' . $args['widget_id'] . '&width=' . $width . '&height=' . $height . '&legend=' . $legend); $trans = array('noanswer' => GFontsLang::GetTranslation('Please select answer'), 'ajaxerror' => GFontsLang::GetTranslation('Some error happened'), 'ajaxurl' => admin_url('admin-ajax.php')); wp_localize_script('gf-poll-service-' . $poll_id, 'objPollServiceTrans', $trans); $output .= $oPoll->title . '<br/>'; $output .= '<span id="wgarea_' . $args['widget_id'] . '_' . $poll_id . '">'; $answers = GFontsDB::GetAnswersForPoll($poll_id); if (is_array($answers)) { $output .= '<span style="text-align: left; float: left;">'; foreach ($answers as $answer) { $output .= '<input type="radio" name="poll_' . $args['widget_id'] . '" id="poll_' . $args['widget_id'] . '-' . $answer->id . '" value="' . $answer->id . '" style="-webkit-appearance: radio;"/> <label for="poll_' . $args['widget_id'] . '-' . $answer->id . '">' . stripslashes($answer->answer) . '</label><br/>'; } $output .= '</span><br/><br/><center><input type="submit" value="' . __(trim($oPoll->button_title) != '' ? $oPoll->button_title : 'Vote') . '" id="btn_' . $poll_id . '_' . $args['widget_id'] . '"/></center>'; } } } $output .= '</span>'; return $output; }