Пример #1
0
function __dem_polls_preview()
{
    ?>
	<ul class="group">
		<li class="block polls-preview">
			<?php 
    $poll = new DemPoll();
    $poll->cachegear_on = false;
    $poll->hasVoted = 1;
    $answers = (array) wp_list_pluck($poll->poll->answers, 'aid');
    $poll->votedFor = $answers ? $answers[array_rand($answers)] : false;
    echo '<div class="poll"><p class="tit">' . __('Вид результатов:', 'dem') . '</p>' . $poll->get_screen('voted') . '</div>';
    echo '<div class="poll"><p class="tit">' . __('Вид голосования:', 'dem') . '</p>' . $poll->get_screen('force_vote') . '</div>';
    echo '<div class="poll show-loader"><p class="tit">' . __('Вид AJAX загрузчика:', 'dem') . '</p>' . $poll->get_screen('vote') . '</div>';
    ?>
			<input type="text" class="iris_color preview-bg">
		</li>
    </ul>
	<?php 
}
    public function column_default($poll, $col)
    {
        global $wpdb;
        $cache =& self::$cache;
        if (!isset($cache[$poll->id])) {
            $cache[$poll->id] = $wpdb->get_results("SELECT * FROM {$wpdb->democracy_a} WHERE qid = " . (int) $poll->id);
        }
        $answ =& $cache[$poll->id];
        $url = Dem::$i->admin_page_url();
        $date_format = get_option('date_format');
        // вывод
        if (0) {
        } elseif ($col == 'question') {
            $statuses = '<span class="statuses">' . ($poll->democratic ? '<span class="dashicons dashicons-megaphone" title="' . __('Пользователи могут добавить свои ответы (democracy).', 'dem') . '"></span>' : '') . ($poll->revote ? '<span class="dashicons dashicons-update" title="' . __('Пользователи могут изменить мнение (переголосование).', 'dem') . '"></span>' : '') . ($poll->forusers ? '<span class="dashicons dashicons-admin-users" title="' . __('Голосовать могут только зарегистрированные пользователи.', 'dem') . '"></span>' : '') . '</span>';
            return $statuses . $poll->question . '
			<div class="row-actions">
				<span class="edit"><a href="' . add_query_arg(array('edit_poll' => $poll->id), $url) . '">' . __('Редактировать', 'dem') . '</a> | </span>' . (Dem::$opt['keep_logs'] ? '<span class="edit"><a href="' . add_query_arg(array('subpage' => 'logs', 'poll' => $poll->id), $url) . '">' . __('Логи', 'dem') . '</a> | </span>' : '') . '<span class="delete"><a href="' . add_query_arg(array('delete_poll' => $poll->id), $url) . '" onclick="return confirm(\'' . __('Точно удалить?', 'dem') . '\');">' . __('Удалить', 'dem') . '</a> | </span>
				<span style="color:#999">' . DemPoll::shortcode_html($poll->id) . '</span>
			</div>
			';
        } elseif ($col == 'votes') {
            return array_sum(wp_list_pluck((array) $answ, 'votes'));
        } elseif ($col == 'winner') {
            if (!$answ) {
                return 'Нет';
            }
            //			$winner = $answ[ key($answ) ];
            //			foreach( (array) $answ as $ans )
            //				if( $ans->votes > $winner->votes )
            //					$winner = $ans;
            //
            //			return $winner->answer;
            usort($answ, function ($a, $b) {
                return $a->votes == $b->votes ? 0 : ($a->votes < $b->votes ? 1 : -1);
            });
            $_answ = array();
            foreach ($answ as $ans) {
                $_answ[] = '<small>' . $ans->votes . '</small> ' . $ans->answer;
            }
            return '<div class="compact-answ">' . implode('<br>', $_answ) . '</div>';
        } elseif ($col == 'active') {
            return dem_activatation_buttons($poll);
        } elseif ($col == 'open') {
            return dem_opening_buttons($poll);
        } elseif ($col == 'added') {
            $date = date($date_format, $poll->added);
            $end = $poll->end ? date($date_format, $poll->end) : '';
            return "{$date}<br>{$end}";
        } else {
            return isset($poll->{$col}) ? $poll->{$col} : print_r($poll, true);
        }
    }
    public function column_default($log, $col)
    {
        global $wpdb;
        // вывод
        if (0) {
        } elseif ($col == 'ip') {
            return '<a title="' . __('Поиск по IP', 'dem') . '" href="' . esc_url(add_query_arg(array('ip' => $log->ip, 'poll' => null))) . '">' . long2ip($log->ip) . '</a>';
        } elseif ($col == 'qid') {
            if (!($poll = $this->cache('polls', $log->qid))) {
                $poll = $this->cache('polls', $log->qid, DemPoll::get_poll($log->qid));
            }
            $url = Dem::$i->admin_page_url();
            return esc_html($poll->question) . '
			<div class="row-actions">
				<span class="edit"><a href="' . add_query_arg(array('edit_poll' => $poll->id), $url) . '">' . __('Редактировать', 'dem') . '</a> | </span>
				<span class="edit"><a href="' . esc_url(add_query_arg(array('ip' => null, 'poll' => $log->qid))) . '">' . __('Логи опроса', 'dem') . '</a></span>
			</div>
			';
        } elseif ($col == 'userid') {
            if (!($user = $this->cache('users', $log->userid))) {
                $user = $this->cache('users', $log->userid, $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE ID = " . (int) $log->userid));
            }
            return esc_html(@$user->user_nicename);
        } elseif ($col == 'aids') {
            $out = array();
            foreach (explode(',', $log->aids) as $aid) {
                if (!($answ = $this->cache('answs', $aid))) {
                    $answ = $this->cache('answs', $aid, $wpdb->get_row("SELECT * FROM {$wpdb->democracy_a} WHERE aid = " . (int) $aid));
                }
                $out[] = '- ' . esc_html($answ->answer);
            }
            return implode('<br>', $out);
        } else {
            return isset($log->{$col}) ? $log->{$col} : print_r($log, true);
        }
    }
Пример #4
0
 function not_ajax_request_handler()
 {
     extract($this->__sanitize_request_vars());
     if (!$act || !$pid || !isset($_SERVER['HTTP_REFERER'])) {
         return;
     }
     $poll = new DemPoll($pid);
     if ($act == 'vote' && $aids) {
         $poll->addVote($aids);
         wp_redirect(remove_query_arg(array('dem_act', 'dem_pid'), $_SERVER['HTTP_REFERER']));
         exit;
     } elseif ($act == 'delVoted') {
         $poll->unsetVotedData();
         wp_redirect(remove_query_arg(array('dem_act', 'dem_pid'), $_SERVER['HTTP_REFERER']));
         exit;
     }
 }
Пример #5
0
function poll_edit_form($poll_id = false)
{
    global $wpdb;
    if (!$poll_id && isset($_GET['edit_poll'])) {
        $poll_id = (int) $_GET['edit_poll'];
    }
    $edit = !!$poll_id;
    $answers = false;
    $title = $poll = $shortcode = '';
    if ($edit) {
        $title = __('Редактировать опрос', 'dem');
        $shortcode = DemPoll::shortcode_html($poll_id) . ' - ' . __('шоткод для использования в записи', 'dem');
        $poll = $wpdb->get_row("SELECT * FROM {$wpdb->democracy_q} WHERE id = {$poll_id} LIMIT 1");
        $answers = $wpdb->get_results("SELECT * FROM {$wpdb->democracy_a} WHERE qid = {$poll_id}");
        $hidden_inputs = "<input type='hidden' name='dmc_update_poll' value='{$poll_id}'>";
    } else {
        //$title = __('Добавить новый опрос','dem');
        $hidden_inputs = "<input type='hidden' name='dmc_create_poll' value='1'>";
    }
    $poll = $poll ? wp_unslash($poll) : false;
    echo demenu() . ($title ? "<h2>{$title}</h2>{$shortcode}" : '') . '<form action="" method="POST" class="dem-new-poll">
			<input type="hidden" name="dmc_qid" value="' . $poll_id . '">
			' . wp_nonce_field('dem_insert_poll', '_demnonce', $referer = 0, $echo = 0) . '
			
			<label>
				' . __('Вопрос:', 'dem') . '
				<input type="text" id="the-question" name="dmc_question" value="' . esc_attr(@$poll->question) . '">
			</label>
			
			' . __('Варианты ответов:', 'dem') . '
		';
    ?>
		
		<ol class="new-poll-answers">
			<?php 
    if ($answers) {
        $_answers = Dem::objects_array_sort($answers, array('votes' => 'desc'));
        foreach ($_answers as $answer) {
            $by_user = $answer->added_by ? '<i>*</i>' : '';
            echo '
					<li class="answ">
						<input class="answ-text" type="text" name="dmc_old_answers[' . $answer->aid . '][answer]" value="' . esc_attr($answer->answer) . '">
						<input type="text" name="dmc_old_answers[' . $answer->aid . '][votes]" value="' . $answer->votes . '" style="width:50px;min-width:50px;">
						' . $by_user . '
					</li>';
        }
    } else {
        for ($i = 0; $i < 2; $i++) {
            echo '<li class="answ"><input type="text" name="dmc_new_answers[]" value=""></li>';
        }
    }
    ?>
			
			<?php 
    if (!Dem::$opt['democracy_off']) {
        ?>
			<li>
				<label>
					<input type="hidden" name='dmc_democratic' value=''>
					<input type="checkbox" name="dmc_democratic" value="1" <?php 
        checked(!isset($poll->democratic) || $poll->democratic, 1);
        ?>
 > 
					<?php 
        _e('Разрешить пользователям добавлять свои ответы (democracy).', 'dem');
        ?>
				</label>
			</li>
			<?php 
    }
    ?>
		</ol>
		
		<ol class="poll-options">				
			<li>
				<label>
					<input type="hidden" name='dmc_active' value=''>
					<input type="checkbox" name='dmc_active' value='1' <?php 
    $edit ? checked(@$poll->active, 1) : 'checked="true"';
    ?>
 > 
					<?php 
    _e('Сделать этот опрос активным.', 'dem');
    ?>
				</label>
			</li>
			
			<li>
				<label>
					<?php 
    $ml = (int) @$poll->multiple;
    ?>
					<input type="hidden" name='dmc_multiple' value=''>
					<input type="checkbox" name="dmc_multiple" value="<?php 
    echo $ml;
    ?>
" <?php 
    echo $ml ? 'checked="checked"' : '';
    ?>
 >
					<input type="number" min=0 value="<?php 
    echo $ml == 1 || $ml == 0 ? '' : $ml;
    ?>
" style="width:50px; <?php 
    echo !$ml ? 'display:none;' : '';
    ?>
">
					<?php 
    _e('Разрешить выбирать несколько ответов (множественный).', 'dem');
    ?>
				</label>
			</li>
			
			<li>
				<label>
					<input type="text" name="dmc_end" value="<?php 
    echo @$poll->end ? date('d-m-Y', $poll->end) : '';
    ?>
" style="width:120px;min-width:120px;" > 
					<?php 
    _e('Дата, когда опрос был/будет закрыт. Формат: dd-mm-yyyy.', 'dem');
    ?>
				</label>
			</li>
			
			<?php 
    if (!Dem::$opt['revote_off']) {
        ?>
			<li>
				<label>
					<input type="hidden" name='dmc_revote' value=''>
					<input type="checkbox" name="dmc_revote" value="1" <?php 
        checked(!isset($poll->revote) || $poll->revote, 1);
        ?>
 > 
					<?php 
        _e('Разрешить изменять мнение (переголосование).', 'dem');
        ?>
				</label>
			</li>
			<?php 
    }
    ?>
			<?php 
    if (!Dem::$opt['only_for_users']) {
        ?>
			<li>
				<label>
					<input type="hidden" name='dmc_forusers' value=''>
					<input type="checkbox" name="dmc_forusers" value="1" <?php 
        checked(@$poll->forusers, 1);
        ?>
 > 
					<?php 
        _e('Голосовать могут только зарегистрированные пользователи.', 'dem');
        ?>
				</label>
			</li>
			<?php 
    }
    ?>
			
			<?php 
    if (!Dem::$opt['dont_show_results']) {
        ?>
			<li>
				<label>
					<input type="hidden" name='dmc_show_results' value=''>
					<input type="checkbox" name="dmc_show_results" value="1" <?php 
        checked(!isset($poll->show_results) || @$poll->show_results, 1);
        ?>
 > 
					<?php 
        _e('Показывать результаты опроса.', 'dem');
        ?>
				</label>
			</li>
			<?php 
    }
    ?>
			
			<li><label> <?php 
    _e('Заметка: текст будет добавлен под опросом.', 'dem');
    ?>
<br>
					<textarea name="dmc_note" style="height:3.5em;" ><?php 
    echo esc_textarea(@$poll->note);
    ?>
</textarea>
				</label>
			</li>
		</ol>

		<?php 
    echo $hidden_inputs;
    ?>
		<input type="submit" class="button-primary" value="<?php 
    echo $edit ? __('Внести изменения', 'dem') : __('Добавить опрос', 'dem');
    ?>
">
		
		<?php 
    // если редактируем
    if ($edit) {
        // открыть
        echo dem_opening_buttons($poll);
        // активировать
        echo dem_activatation_buttons($poll);
        echo '<a href="' . add_query_arg(array('delete_poll' => $poll->id), Dem::$i->admin_page_url()) . '" class="button" onclick="return confirm(\'' . __('Точно удалить?', 'dem') . '\');" title="' . __('Удалить', 'dem') . '"><span class="dashicons dashicons-trash"></span></a>';
    }
    ?>
	</form>
	<?php 
}
 public function column_default($log, $col)
 {
     global $wpdb;
     // вывод
     if (0) {
     } elseif ($col == 'ip') {
         return '<a href="' . esc_url(add_query_arg(array('ip' => $log->ip, 'poll' => null))) . '">' . long2ip($log->ip) . '</a>';
     } elseif ($col == 'qid') {
         if (!($poll = $this->cache('polls', $log->qid))) {
             $poll = $this->cache('polls', $log->qid, DemPoll::get_poll($log->qid));
         }
         return '<a href="' . esc_url(add_query_arg(array('ip' => null, 'poll' => $log->qid))) . '">' . esc_html($poll->question) . '</a>';
     } elseif ($col == 'userid') {
         if (!($user = $this->cache('users', $log->userid))) {
             $user = $this->cache('users', $log->userid, $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE ID = " . (int) $log->userid));
         }
         return esc_html(@$user->user_nicename);
     } elseif ($col == 'aids') {
         $out = array();
         foreach (explode(',', $log->aids) as $aid) {
             if (!($answ = $this->cache('answs', $aid))) {
                 $answ = $this->cache('answs', $aid, $wpdb->get_row("SELECT * FROM {$wpdb->democracy_a} WHERE aid = " . (int) $aid));
             }
             $out[] = '- ' . esc_html($answ->answer);
         }
         return implode('<br>', $out);
     } else {
         return isset($log->{$col}) ? $log->{$col} : print_r($log, true);
     }
 }