public function yop_poll_do_scheduler() { require_once YOP_POLL_MODELS . 'yop_poll_model.php'; $yop_polls = Yop_Poll_Model::get_polls_for_view(array('return_fields' => 'ID')); if (count($yop_polls) > 0) { foreach ($yop_polls as $yop_poll_id) { $yop_poll_options = Yop_Poll_Model::get_poll_options_by_id($yop_poll_id['ID']); if ('yes' == $yop_poll_options['schedule_reset_poll_stats']) { $reset_time = new DateTime($yop_poll_options['schedule_reset_poll_date']); $now_date = new DateTime(date("Y-m-d H:i:s", current_time('timestamp'))); if ($reset_time->format("Y-m-d H") == $now_date->format("Y-m-d H")) { $unit_multiplier = 0; switch (strtolower(trim($yop_poll_options['schedule_reset_poll_recurring_unit']))) { case 'hour': $unit_multiplier = 60 * 60; break; case 'day': $unit_multiplier = 60 * 60 * 24; break; } $next_reset_date = strtotime($yop_poll_options['schedule_reset_poll_date']) + intval($yop_poll_options['schedule_reset_poll_recurring_value']) * $unit_multiplier; if ($next_reset_date <= current_time('timestamp')) { $next_reset_date = strtotime(substr(current_time('mysql'), 0, 11) . substr(date('Y-m-d H:i:s', $yop_poll_options['schedule_reset_poll_date']), 11, 2) . ':00:00') + intval($yop_poll_options['schedule_reset_poll_recurring_value']) * $unit_multiplier; } $poll_options = get_yop_poll_meta($yop_poll_id['ID'], 'options', true); $poll_options['schedule_reset_poll_date'] = date('d-m-Y H:i:s', $next_reset_date); update_yop_poll_meta($yop_poll_id['ID'], 'options', $poll_options); //Call reset stats function YOP_POLL_Abstract_Model::reset_poll_stats_from_database($yop_poll_id['ID']); } } } } }
public function ajax_get_polls_for_html_editor() { check_ajax_referer('yop-poll-html-editor'); if (is_admin()) { require_once YOP_POLL_MODELS . 'yop_poll_model.php'; $yop_polls = Yop_Poll_Model::get_polls_for_view(); ?> <p style="text-align: center;"> <label for="yop-poll-id-html-dialog"> <span><?php _e('Poll to Display', 'yop_poll'); ?> :</span> <select class="widefat" name="yop_poll_id" id="yop-poll-id-html-dialog"> <option value="-3"><?php _e('Display Random Poll', 'yop_poll'); ?> </option> <option value="-2"><?php _e('Display Latest Poll', 'yop_poll'); ?> </option> <option value="-1"><?php _e('Display Current Active Poll', 'yop_poll'); ?> </option> <?php if (count($yop_polls) > 0) { foreach ($yop_polls as $yop_poll) { ?> <option value="<?php echo $yop_poll['ID']; ?> "><?php echo esc_html(stripslashes($yop_poll['poll_title'])); ?> </option> <?php } } ?> </select> </label> <br/><br/> <label for="yop-poll-tr-id-html-dialog"> <span><?php _e('Tracking ID', 'yop_poll'); ?> :</span> <input type="text" name="yop_poll_tr_id" id="yop-poll-tr-id-html-dialog" class="widefat" value=""/> </label> <br/><br/> <label for="yop-poll-tr-results-html-dialog"> <span><?php _e('Display results only', 'yop_poll'); ?> :</span> <select name="show_results" id="yop-poll-tr-results-html-dialog" class="widefat" > <option value="-1">-1</option> <option value="1">1</option> </select> </label> <br/> <br/> <input type="button" class="" value="<?php _e('Insert Poll', 'yop_poll'); ?> " onclick=" insertYopPoll( edCanvas, document.getElementById('yop-poll-id-html-dialog').value, document.getElementById('yop-poll-tr-id-html-dialog').value ,document.getElementById('yop-poll-tr-results-html-dialog'));"/> <br/> <br/> <input type="button" class="" value="<?php _e('Close', 'yop_poll'); ?> " onclick="tb_remove();"/> </p> <?php } die; }
public function ajax_get_polls_for_html_editor() { check_ajax_referer('yop-poll-html-editor'); if (is_admin()) { require_once YOP_POLL_MODELS . 'yop_poll_model.php'; $yop_polls = Yop_Poll_Model::get_polls_for_view(); ?> <title><?php _e("Insert Poll", 'yop_poll'); ?> </title> <style> body { background: #ffffff 50% 50% repeat-x; } select { background-color: #fff; outline: 0; transition: .05s border-color ease-in-out; margin: 1px; padding: 3px 5px; font-size: 13px; line-height: 26px; height: 28px; } input[type="text"] { background-color: #fff; outline: 0; transition: .05s border-color ease-in-out; margin: 1px; padding: 3px 5px; font-size: 13px; line-height: 26px; height: 28px; } input[type="radio"] { background-color: #fff; outline: 0; transition: .05s border-color ease-in-out; margin: 1px; padding: 3px 5px; font-size: 13px; line-height: 26px; } input[type="button"] { color: #555; border-color: #ccc; background: #f7f7f7; -webkit-box-shadow: inset 0 1px 0 #fff,0 1px 0 rgba(0,0,0,.08); box-shadow: inset 0 1px 0 #fff,0 1px 0 rgba(0,0,0,.08); vertical-align: top; display: inline-block; text-decoration: none; font-size: 13px; line-height: 26px; height: 28px; margin: 0; padding: 0 10px 1px; cursor: pointer; border-width: 1px; border-style: solid; -webkit-appearance: none; -webkit-border-radius: 3px; border-radius: 3px; white-space: nowrap; -webkit-box-sizing: border-box; } table { width: 95%; height: 95%; margin: auto; border: 1px solid #e5e5e5; -webkit-box-shadow: 0 1px 1px rgba(0,0,0,.04); box-shadow: 0 1px 1px rgba(0,0,0,.04); border-spacing: 0; width: 100%; clear: both; margin: 0; } tr { line-height: 40px; } td { padding-left: 10px; } </style> <script> var yop_display_results = "-1"; function getYOPDisplayResults(){ var yop_results_radio = document.getElementsByName( "show_results" ); if( yop_results_radio[1].checked ) { yop_display_results = "1"; } } </script> <table> <tr> <td> <?php _e("Poll to Display", 'yop_poll'); ?> : </td> <td> <select class="widefat" name="yop_poll_id" id="yop-poll-id-dialog"> <option value="-3"><?php _e("Display Random Poll", 'yop_poll'); ?> </option> <option value="-2"><?php _e("Display Latest Poll", 'yop_poll'); ?> </option> <option value="-1"><?php _e("Display Current Active Poll", 'yop_poll'); ?> </option> <?php if (count($yop_polls) > 0) { foreach ($yop_polls as $yop_poll) { ?> <option value="<?php echo $yop_poll['ID']; ?> "> <?php echo esc_html(stripslashes($yop_poll['poll_title'])); ?> </option> <?php } } ?> </select> </td> </tr> <tr> <td> <?php _e("Tracking ID", 'yop_poll'); ?> : </td> <td> <input type="text" name="yop_poll_tr_id" id="yop-poll-tr-id-dialog" size="35" placeholder="Leave empty if none" /> </td> </tr> <tr> <td> <?php _e("Display Results Only", 'yop-poll'); ?> : </td> <td> <input type="radio" name="show_results" value="-1" checked="checked">No <input type="radio" name="show_results" value="1">Yes </td> </tr> <tr> <td colspan="2" style="text-align:center;"> <input type="button" class="button" value="<?php _e("Insert Poll", 'yop_poll'); ?> " onclick="getYOPDisplayResults(); insertYopPoll( edCanvas, document.getElementById('yop-poll-id-dialog').value, document.getElementById('yop-poll-tr-id-dialog').value, yop_display_results);" /> </td> </tr> </table> <!-- <p style="text-align: center;"> <label for="yop-poll-id-html-dialog"> <span><?php _e('Pollsss to Display', 'yop_poll'); ?> :</span> <select class="widefat" name="yop_poll_id" id="yop-poll-id-html-dialog"> <option value="-3"><?php _e('Display Random Poll', 'yop_poll'); ?> </option> <option value="-2"><?php _e('Display Latest Poll', 'yop_poll'); ?> </option> <option value="-1"><?php _e('Display Current Active Poll', 'yop_poll'); ?> </option> <?php if (count($yop_polls) > 0) { foreach ($yop_polls as $yop_poll) { ?> <option value="<?php echo $yop_poll['ID']; ?> "> <?php echo esc_html(stripslashes($yop_poll['poll_title'])); ?> </option> <?php } } ?> </select> </label> <br/><br/> <label for="yop-poll-tr-id-html-dialog"> <span><?php _e('Tracking ID', 'yop_poll'); ?> :</span> <input type="text" name="yop_poll_tr_id" id="yop-poll-tr-id-html-dialog" class="widefat" value=""/> </label> <br/><br/> <label for="yop-poll-tr-results-html-dialog"> <span><?php _e('Display results only', 'yop_poll'); ?> :</span> <select name="show_results" id="yop-poll-tr-results-html-dialog" class="widefat" > <option value="-1">-1</option> <option value="1">1</option> </select> </label> <br/> <br/> <input type="button" class="" value="<?php _e('Insert Poll', 'yop_poll'); ?> " onclick=" insertYopPoll( edCanvas, document.getElementById('yop-poll-id-html-dialog').value, document.getElementById('yop-poll-tr-id-html-dialog').value ,document.getElementById('yop-poll-tr-results-html-dialog'));"/> <br/> </p> --> <?php } die; }
private function view_polls() { $data = array(); $data['ok'] = 0; $time_format = "H:i:s"; $options = get_option('yop_poll_options'); if ($options['date_format'] == "UE") { $date_format = "d-m-Y"; } else { $date_format = "m-d-Y"; } $data['date_format'] = $date_format . ' ' . $time_format; // wp_enqueue_style( 'yop-poll-add-edit-css', YOP_POLL_URL . 'css/polls/add-edit.css', array(), YOP_POLL_VERSION ); // wp_enqueue_style( 'yop-poll-admin-css', YOP_POLL_URL . 'css/yop-poll-admin.css', array(), YOP_POLL_VERSION ); wp_enqueue_style('yop-poll-slider-css', YOP_POLL_URL . 'css/yop-poll-slider.css', array(), YOP_POLL_VERSION); wp_enqueue_script('yop-poll-add-edit-js', YOP_POLL_URL . 'js/polls/yop-poll-add-edit.js', array('jquery', 'jquery-ui-sortable', 'jquery-ui-dialog'), YOP_POLL_VERSION, true); wp_enqueue_script('yop-poll-slider-js', YOP_POLL_URL . 'js/yop-poll-slider.js', array('jquery', 'jquery-ui-dialog'), YOP_POLL_VERSION, true); $data['poll_url'] = YOP_POLL_URL; $optin_box_modal_options = get_option('yop_poll_optin_box_modal_options_yop'); wp_enqueue_script('yop-poll-slider-pro-js', YOP_POLL_URL . 'js/yop-poll-slider-pro.js', array('jquery', 'jquery-ui-dialog'), YOP_POLL_VERSION, true); if ($optin_box_modal_options['show'] == 'yes') { wp_enqueue_script('yop-poll-modal-box-js', YOP_POLL_URL . "modal/js/jquery.modalbox-1.5.0-min.js", array('jquery'), YOP_POLL_VERSION, true); wp_enqueue_script('yop-poll-modal-functions', YOP_POLL_URL . "js/yop-poll-modal-functions.js", array('jquery', 'yop-poll-modal-box-js'), $this->_config->version, true); $yop_poll_modal_functions_config = array('ajax' => array('url' => admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'), 'action' => 'yop_poll_modal_option_signup')); wp_localize_script('yop-poll-modal-functions', 'yop_poll_modal_functions_config', $yop_poll_modal_functions_config); $data['optin_box_modal_query'] = admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'); $optin_box_modal_query = admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'); $data['optin_box_modal_query'] = add_query_arg('action', 'yop_poll_show_optin_box_modal', $optin_box_modal_query); wp_enqueue_script('link'); wp_enqueue_script('xfn'); wp_enqueue_script('yop-poll-optin-form', "http://app.getresponse.com/view_webform.js?wid=394041&mg_param1=1", NULL, YOP_POLL_VERSION, true); } else { if ($optin_box_modal_options['sidebar_had_submit'] == 'no') { $data['ok'] = 1; wp_enqueue_script('yop-poll-sidebar-option-functions', YOP_POLL_URL . "js/yop-poll-sidebar-optin-functions.js", array('jquery'), $this->_config->version, true); $yop_poll_sidebar_functions_config = array('ajax' => array('url' => admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'), 'action' => 'yop_poll_sidebar_option_signup')); wp_localize_script('yop-poll-sidebar-option-functions', 'yop_poll_sidebar_functions_config', $yop_poll_sidebar_functions_config); wp_enqueue_style('yop-poll-view-poll-css', YOP_POLL_URL . 'css/polls/view-poll.css', array(), YOP_POLL_VERSION); wp_enqueue_style('yop-poll-donate-css', YOP_POLL_URL . 'css/yop-poll-donate.css', array(), YOP_POLL_VERSION); // wp_enqueue_style( 'yop-poll-optin2-css', YOP_POLL_URL . 'css/yop-poll-optin2.css', array(), YOP_POLL_VERSION ); wp_enqueue_script('link'); wp_enqueue_script('xfn'); wp_enqueue_script('yop-poll-optin-form', "http://app.getresponse.com/view_webform.js?wid=394041&mg_param1=1", NULL, $this->_config->version, true); } } /* $optin_box_modal_options = get_option( 'yop_poll_optin_box_modal_options' ); if ( $optin_box_modal_options == 'no' ){ update_option( "yop_poll_optin_box_modal_options", 'no' ); wp_enqueue_script( 'yop-poll-modal-functions', YOP_POLL_URL."js/yop-poll-modal-functions.js", array( 'jquery', 'jquery-ui-dialog' ), $this->_config->version, true ); } wp_enqueue_script( 'yop-poll-sidebar-option-functions', YOP_POLL_URL."js/yop-poll-sidebar-optin-functions.js", array( 'jquery' ), $this->_config->version, true ); $yop_poll_sidebar_functions_config = array( 'ajax' => array( 'url' => admin_url( 'admin-ajax.php', ( is_ssl() ? 'https' : 'http' ) ), 'action' => 'yop_poll_sidebar_option_signup' ) ); wp_localize_script( 'yop-poll-sidebar-option-functions', 'yop_poll_sidebar_functions_config', $yop_poll_sidebar_functions_config ); /* wp_enqueue_script( 'yop-poll-modal-box-js', YOP_POLL_URL."js/jquery.modalbox-1.5.0-min.js", array( 'jquery' ), $this->_config->version, true ); wp_enqueue_script( 'yop-poll-modal-functions', YOP_POLL_URL."js/yop-poll-modal-functions.js", array( 'jquery', 'yop-poll-modal-box-js' ), $this->_config->version, true ); $yop_poll_modal_functions_config = array( 'ajax' => array( 'url' => admin_url( 'admin-ajax.php', ( is_ssl() ? 'https' : 'http' ) ), 'action' => 'yop_poll_modal_option_signup' ) ); wp_localize_script( 'yop-poll-modal-functions', 'yop_poll_modal_functions_config', $yop_poll_modal_functions_config ); wp_enqueue_style( 'yop-poll-modal-box-css', YOP_POLL_URL."css/jquery.modalbox-basic.css", array(), $this->_config->version ); wp_enqueue_style( 'yop-poll-modal-box-css', YOP_POLL_URL."css/jquery.modalbox-skin-precious-white.css", array(), $this->_config->version );*/ $per_page = isset($_REQUEST['per_page']) && intval($_REQUEST['per_page']) > 0 ? intval($_REQUEST['per_page']) : 100; $page_no = isset($_REQUEST['page_no']) && intval($_REQUEST['page_no']) > 0 ? intval($_REQUEST['page_no']) : 1; $orderby = empty($GLOBALS['orderby']) ? 'ID' : $GLOBALS['orderby']; $order = empty($GLOBALS['order']) ? 'asc' : $GLOBALS['order']; wp_enqueue_style('yop-poll-view-poll-css', YOP_POLL_URL . 'css/polls/view-poll.css', array(), YOP_POLL_VERSION); wp_enqueue_style('yop-poll-donate-css', YOP_POLL_URL . 'css/yop-poll-donate.css', array(), YOP_POLL_VERSION); wp_enqueue_style('yop-poll-optin2-css', YOP_POLL_URL . 'css/yop-poll-optin2.css', array(), YOP_POLL_VERSION); wp_enqueue_script('link'); wp_enqueue_script('xfn'); $order_fields = array('ID', 'poll_title', 'poll_start_date', 'poll_end_date', 'poll_total_votes'); wp_enqueue_script('yop-poll-add-edit-js', YOP_POLL_URL . '/js/polls/yop-poll-add-edit.js', array('jquery', 'jquery-ui-dialog'), YOP_POLL_VERSION, true); $filters = array(); $filters[] = array('field' => 'poll_type', 'value' => 'poll', 'operator' => '='); if (isset($_REQUEST['filters'])) { switch ($_REQUEST['filters']) { case 'started': $filters[] = array('field' => 'poll_start_date', 'value' => current_time('mysql'), 'operator' => '<='); break; case 'not_started': $filters[] = array('field' => 'poll_start_date', 'value' => current_time('mysql'), 'operator' => '>='); break; case 'never_expire': $filters[] = array('field' => 'poll_end_date', 'value' => '01-01-2038 23:59:59', 'operator' => '='); break; case 'expired': $filters[] = array('field' => 'poll_end_date', 'value' => current_time('mysql'), 'operator' => '<='); break; } } $args = array('return_fields' => 'COUNT(*) as total_polls', 'filters' => $filters, 'search' => array('fields' => array('poll_title'), 'value' => isset($_REQUEST['s']) ? $_REQUEST['s'] : ''), 'orderby' => $orderby, 'order' => $order); $total_polls = Yop_Poll_Model::get_polls_filter_search($args); if (!isset($total_polls[0]['total_polls'])) { $total_polls[0]['total_polls'] = 0; } $total_polls_pages = ceil($total_polls[0]['total_polls'] / $per_page); if (intval($page_no) > intval($total_polls_pages)) { $page_no = 1; } $args['limit'] = ($page_no - 1) * $per_page . ', ' . $per_page; $args['return_fields'] = "\r\n\t\t\tID,\r\n\t\t\tpoll_title,\r\n\t\t\t(SELECT user_nicename\r\n\t\t\tFROM {$GLOBALS['wpdb']->users} WHERE polls.poll_author = ID) as \"poll_author\",\r\n\t\t\tpoll_total_votes,\r\n\t\t\tpoll_start_date,\r\n\t\t\tpoll_end_date "; $data['REQUEST'] = $_REQUEST; $data['orderby'] = $orderby; $data['order'] = $order; $data['order_direction'] = $this->make_order_array($order_fields, 'asc', $orderby, 'desc' == $order ? 'asc' : 'desc'); $data['order_sortable'] = $this->make_order_array($order_fields, 'sortable', $orderby, 'sorted'); $data['order_direction_reverse'] = $this->make_order_array($order_fields, 'desc', $orderby, 'desc' == $order ? 'desc' : 'asc'); $data['title'] = __yop_poll('Yop Poll'); $data['polls'] = Yop_Poll_Model::get_polls_for_view($args); $data['total_items'] = $total_polls[0]['total_polls']; $data['current_user'] = $GLOBALS['current_user']; $paginate_args = array('base' => remove_query_arg('page_no', $_SERVER['REQUEST_URI']) . '%_%', 'format' => '&page_no=%#%', 'total' => $total_polls_pages, 'current' => max(1, $page_no), 'prev_next' => true, 'prev_text' => __('« Previous'), 'next_text' => __('Next »')); $_SERVER['REQUEST_URI'] = remove_query_arg(array('action'), $_SERVER['REQUEST_URI']); $data['pagination'] = paginate_links($paginate_args); $this->display('view.html', $data); }
function form($instance) { $instance = wp_parse_args((array) $instance, array('title' => __('Yop Polls', 'yop_poll'), 'poll_id' => -99)); $title = esc_attr($instance['title']); $poll_id = intval($instance['poll_id']); $tr_id = $instance['tr_id']; global $wpdb; require_once YOP_POLL_MODELS . 'yop_poll_model.php'; $yop_polls = Yop_Poll_Model::get_polls_for_view(); ?> <p> <label for = "<?php echo $this->get_field_id('title'); ?> "> <span>Title:</span> <input id = "<?php echo $this->get_field_id('title'); ?> " name = "<?php echo $this->get_field_name('title'); ?> " value = "<?php echo $title; ?> "/> </label> </p> <p> <label for = "<?php echo $this->get_field_id('poll_id'); ?> "> <span>Poll to Display:</span> <select id = "<?php echo $this->get_field_id('poll_id'); ?> " name = "<?php echo $this->get_field_name('poll_id'); ?> " class = "widefat"> <option value = "-99"<?php selected(-99, $poll_id); ?> ><?php _e('Do NOT Display Poll (Disable)', 'yop-poll'); ?> </option> <option value = "-3"<?php selected(-3, $poll_id); ?> ><?php _e('Display Random Poll', 'yop-poll'); ?> </option> <option value = "-2"<?php selected(-2, $poll_id); ?> ><?php _e('Display Latest Poll', 'yop-poll'); ?> </option> <option value = "-1"<?php selected(-1, $poll_id); ?> ><?php _e('Display Current Active Poll', 'yop-poll'); ?> </option> <?php if (count($yop_polls) > 0) { foreach ($yop_polls as $poll) { ?> <option value = "<?php echo $poll['ID']; ?> "<?php selected($poll['ID'], $poll_id); ?> ><?php echo esc_attr($poll['poll_title']); ?> </option> <?php } } ?> </select> </label> </p> <p> <label for = "<?php echo $this->get_field_id('tr_id'); ?> "> <span>Traking ID:</span> <input id = "<?php echo $this->get_field_id('tr_id'); ?> " name = "<?php echo $this->get_field_name('tr_id'); ?> " value = "<?php echo $tr_id; ?> "/> </label> </p> <input type = "hidden" id = "<?php echo $this->get_field_id('doSave'); ?> " name = "<?php echo $this->get_field_name('doSave'); ?> " value = "yes"/> <?php }