function __construct($id = 0, $is_view_results = "no", $question_sort = "poll_order", $question_sort_rule = "ASC", $answer_sort = "question_order", $answer_sort_rule = "ASC") { if ($id instanceof YOP_POLL_Abstract_Model) { $this->init($id->data, $is_view_results, $question_sort, $question_sort_rule, $answer_sort, $answer_sort_rule); return; } elseif (is_object($id)) { $this->init($id, $is_view_results, $question_sort, $question_sort_rule, $answer_sort, $answer_sort_rule); return; } if (!empty($id) && !is_numeric($id)) { $id = 0; } if ($id == "-3") { $filters = array(); $filters[] = array('field' => 'poll_type', 'value' => 'poll', 'operator' => '='); $filters[] = array('field' => 'poll_start_date', 'value' => current_time('mysql'), 'operator' => '<='); $args = array('return_fields' => 'ID ', 'filters' => $filters, 'search' => array(), 'orderby' => "poll_start_date", 'order' => 'DESC'); $total_polls = Yop_Poll_Model::get_polls_filter_search($args); $ok = 0; $current_date = yop_poll_get_mysql_curent_date(); if (count($total_polls) > 1) { while ($ok == 0) { $id = rand(1, count($total_polls)); $poll = new YOP_POLL_Poll_Model($id); if ($current_date <= convert_date($poll->poll_end_date, 'Y-m-d H:i:s')) { $ok = 1; } } } else { $id = rand(1, count($total_polls)); } } if ($id == "-2") { $filters = array(); $filters[] = array('field' => 'poll_type', 'value' => 'poll', 'operator' => '='); $filters[] = array('field' => 'poll_start_date', 'value' => current_time('mysql'), 'operator' => '<='); $args = array('return_fields' => 'ID ', 'filters' => $filters, 'search' => array(), 'orderby' => "poll_date", 'order' => 'ASC'); $total_polls = Yop_Poll_Model::get_polls_filter_search($args); $id = $total_polls[count($total_polls) - 1]['ID']; } if ($id == "-1") { $poll = self::get_current_active_poll(); $id = $poll['ID']; } $data = self::get_data_by('id', $id); if ($data) { $this->init($data, $is_view_results, $question_sort, $question_sort_rule, $answer_sort, $answer_sort_rule); } else { $this->default_init(); } $this->poll_start_date = convert_date($this->poll_start_date, "Y-m-d H:i:s"); $this->poll_end_date = convert_date($this->poll_end_date, "Y-m-d H:i:s"); }
private function view_bans() { global $wpdb, $page, $action, $orderby, $order, $period, $message; //load all options and display them $order_fields = array('name', 'type', 'period', 'unit'); $orderby = empty($GLOBALS['orderby']) ? 'name' : $GLOBALS['orderby']; $order = empty($GLOBALS['order']) ? 'desc' : $GLOBALS['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("Poll Bans"); $data['REQUEST'] = $_REQUEST; $data['per_page'] = isset($_GET['per_page']) ? intval($_GET['per_page']) : 100; $data['page_no'] = isset($_REQUEST['page_no']) ? (int) $_REQUEST['page_no'] : 1; $data['orderby'] = empty($data['REQUEST']['orderby']) ? 'name' : $data['REQUEST']['orderby']; $data['order_direction']['orderby'] = isset($data['REQUEST']['order']) && 'desc' == $data['REQUEST']['order'] ? 'asc' : 'desc'; $data['order_direction_reverse']['orderby'] = isset($data['REQUEST']['order']) && 'desc' == $data['REQUEST']['order'] ? 'desc' : 'asc'; $data['order_sortable']['orderby'] = 'sorted'; $data['poll_id'] = isset($_REQUEST['poll_id']) ? (int) $_REQUEST['poll_id'] : NULL; $data['type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : NULL; $data['period'] = isset($_REQUEST['period']) ? $_REQUEST['period'] : NULL; $data['id'] = isset($_REQUEST['id']) ? $_REQUEST['id'] : NULL; $data['yop_polls'] = Yop_Poll_Model::get_polls_filter_search('ID', 'asc'); $data['search'] = array('fields' => array($wpdb->yop_poll_bans . '.value'), 'value' => isset($_REQUEST['s']) ? trim($_REQUEST['s']) : ''); $data['total_bans'] = count(Yop_Poll_Model::get_bans_filter_search($orderby, $order, $data['search'], $data['type'], $data['poll_id'])); $data['total_bans_pages'] = ceil($data['total_bans'] / $data['per_page']); if (intval($data['page_no']) > intval($data['total_bans_pages'])) { $page_no = 1; } $data['bans'] = Yop_Poll_Model::get_bans_filter_search($orderby, $order, $data['search'], $data['type'], $data['poll_id'], ($data['page_no'] - 1) * $data['per_page'], $data['per_page']); $args = array('base' => remove_query_arg('page_no', $_SERVER['REQUEST_URI']) . '%_%', 'format' => '&page_no=%#%', 'total' => $data['total_bans_pages'], 'current' => max(1, $data['page_no']), 'prev_next' => true, 'prev_text' => __('« Previous'), 'next_text' => __('Next »')); $data['pagination'] = paginate_links($args); $_SERVER['REQUEST_URI'] = remove_query_arg(array('action'), $_SERVER['REQUEST_URI']); $data['request']['uri'] = $_SERVER["REQUEST_URI"]; //display $data['message'] = array('error' => $message['error'], 'succes' => $message['success']); $this->display('bans.html', $data); }
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); }