function dem_l10n_options() { echo demenu(); __dem_polls_preview(); ?> <div class="local-n"> <form method="POST" action=""> <?php // получим все переводы из файлов $strs = array(); foreach (glob(DEMOC_PATH . '*') as $file) { if (is_dir($file)) { continue; } if (!preg_match('~\\.php$~', basename($file))) { continue; } preg_match_all('~__dem\\(\\s?[\'"](.*?)[\'"]\\s?\\)~', file_get_contents($file), $match); if ($match[1]) { $strs = array_merge($strs, $match[1]); } } $strs = array_unique($strs); // выводим таблицу // отпарсим английский перевод из файла $mofile = DEMOC_PATH . DEM_LANG_DIRNAME . '/en_US.mo'; $en_US = new MO(); $en_US->import_from_file($mofile); $en_US = $en_US->entries; $i = 0; $_l10n = get_option('democracy_l10n'); echo '<table class="wp-list-table widefat fixed posts"> <thead> <tr> <th>' . __('Оригинал', 'dem') . '</th> <th>' . __('Ваш вариант', 'dem') . '</th> </tr> </thead> <tbody id="the-list"> '; foreach ($strs as $str) { $i++; $en_str = $en_US[$str]->translations[0]; echo ' <tr class="' . ($i % 2 ? 'alternate' : '') . '"> <td>' . (get_locale() == 'ru_RU' ? $str : $en_str) . '</td> <td><textarea style="width:100%;height:50px;" name="l10n[' . esc_attr($str) . ']">' . (@$_l10n[$str] ?: __dem($str)) . '</textarea></td> </tr>'; } echo '<tbody> </table>'; ?> <p> <input class="button-primary" type="submit" name="dem_save_l10n" value="<?php _e('Сохранить тексты', 'dem'); ?> "> <input class="button" type="submit" name="dem_reset_l10n" value="<?php _e('Сбростиь на начальные', 'dem'); ?> "> </p> </form> </div> <?php }
/** * Получает код результатов голосования * @return HTML */ function getResultScreen() { if (!$this->id) { return false; } $___ = ''; $max = $total = 0; foreach ($this->poll->answers as $answer) { $total += $answer->votes; if ($max < $answer->votes) { $max = $answer->votes; } } $voted_class = 'dem-voted-this'; $voted_txt = __dem('Это Ваш голос. '); $___ .= '<ul class="dem-answers" data-voted-class="' . $voted_class . '" data-voted-txt="' . $voted_txt . '">'; foreach ($this->poll->answers as $answer) { $word = stripslashes($answer->answer); $votes = (int) $answer->votes; $is_voted_this = $this->hasVoted && in_array($answer->aid, explode(',', $this->votedFor)); $is_winner = $max == $votes; $novoted_class = $votes == 0 ? ' dem-novoted' : ''; $li_class = ' class="' . ($is_winner ? 'dem-winner' : '') . ($is_voted_this ? " {$voted_class}" : '') . $novoted_class . '"'; $sup = $answer->added_by ? ' <sup class="dem-star" title="' . __dem('Ответ добавлен посетителем') . '">*</sup>' : ''; $percent = $votes > 0 ? round($votes / $total * 100) : 0; $percent_txt = sprintf(__dem("%s%% от всех голосов"), $percent); $title = ($is_voted_this ? $voted_txt : '') . ' ' . $percent_txt; $title = " title='{$title}'"; // склонение голосов $sclonenie = function ($number, $titles) { $cases = array(2, 0, 1, 1, 1, 2); return $number . ' ' . $titles[$number % 100 > 4 && $number % 100 < 20 ? 2 : $cases[min($number % 10, 5)]]; }; $votes_txt = $sclonenie($votes, array(__dem('голос'), __dem('голоса'), __dem('голосов'))); $___ .= '<li' . $li_class . $title . ' data-aid="' . $answer->aid . '">'; $label_perc_txt = ' <span class="dem-label-percent-txt">' . $percent . '%, ' . $votes_txt . '</span>'; $percent_txt = '<div class="dem-percent-txt">' . $percent_txt . '</div>'; $votes_txt = '<div class="dem-votes-txt"> <span class="dem-votes-txt-votes">' . $votes_txt . '</span> ' . ($percent > 0 ? ' <span class="dem-votes-txt-percent">' . $percent . '%</span>' : '') . ' </div>'; $___ .= '<div class="dem-label">' . $word . $sup . $label_perc_txt . '</div>'; // css процент $graph_percent = (!Dem::$opt['graph_from_total'] && $percent != 0 ? round($votes / $max * 100) : $percent) . '%'; if ($graph_percent == 0) { $graph_percent = '1px'; } $___ .= '<div class="dem-graph">'; $___ .= '<div class="dem-fill" style="width:' . $graph_percent . ';"></div>'; $___ .= $votes_txt; $___ .= $percent_txt; $___ .= "</div>"; $___ .= "</li>"; } $___ .= '</ul>'; $___ .= '<div class="dem-bottom">'; $___ .= '<div class="dem-poll-info">'; $___ .= '<div class="dem-total-votes">' . sprintf(__dem('Всего голосов: %s'), $total) . '</div>'; $___ .= '<div class="dem-begin-date" title="' . __dem('Начало') . '">' . date_i18n(get_option('date_format'), $this->poll->added) . '</div>'; $___ .= $this->poll->end ? '<div class="dem-begin-date" title="' . __dem('Конец') . '">' . date_i18n(get_option('date_format'), $this->poll->end) . '</div>' : ''; $___ .= $answer->added_by ? '<div class="dem-added-by-user"><span class="dem-star">*</span>' . __dem(' - добавлен посетителем') . '</div>' : ''; $___ .= !$this->poll->open ? '<div>' . __dem('Опрос закрыт') . '</div>' : ''; if (!$this->inArchive && Dem::$opt['archive_page_id']) { $___ .= '<a class="dem-archive-link dem-link" href="' . get_permalink(Dem::$opt['archive_page_id']) . '" rel="nofollow">' . __dem('Архив опросов') . '</a>'; } $___ .= '</div>'; if ($this->poll->open) { // заметка для незарегистрированных пользователей $url = esc_url(wp_login_url($_SERVER['REQUEST_URI'])); $html_only_users = '<div class="dem-only-users">' . sprintf(__dem('Голосовать могут только зарегистрированные пользователи. <a href="%s" rel="nofollow">Войдите</a> для голосования.'), $url) . '</div>'; // переголосовать //$html_revote = '<a href="javascript:void(0);" class="dem-revote-link dem-link" data-dem-act="delVoted" data-confirm-text="'. __dem('Точно отменить голоса?') .'" rel="nofollow">'. __dem('Переголосовать') .'</a>'; $html_revote = '<form action="#democracy" method="post"> <input type="hidden" name="dem_act" value="delVoted"> <input type="hidden" name="dem_pid" value="' . $this->id . '"> <input type="submit" value="' . __dem('Переголосовать') . '" class="dem-revote-link dem-button" data-dem-act="delVoted" data-confirm-text="' . __dem('Точно отменить голоса?') . '"></form>'; // вернуться к голосованию $html_backvote = '<a href="javascript:void(0);" class="dem-button dem-vote-link" data-dem-act="vote_screen" rel="nofollow">' . __dem('Голосовать') . '</a>'; if (!$this->for_cache && $this->blockForVisitor) { $___ .= $html_only_users; } else { if ($this->for_cache || $this->hasVoted && $this->poll->revote) { $___ .= $html_revote; } else { $___ .= $html_backvote; } } if ($this->for_cache) { $___ .= '<div class="dem-cache-notice dem-youarevote" style="display:none;">' . __dem('Вы или с вашего IP уже голосовали.') . '</div>'; $___ .= str_replace(array('<div', 'class="'), array('<div style="display:none;"', 'class="dem-cache-notice '), $html_only_users); } } $___ .= '</div>'; return $___; }
function __voted_notice() { return ' <div class="dem-cache-notice dem-youarevote" style="display:none;"> <div class="dem-notice-close" onclick="jQuery(this).parent().fadeOut();">×</div> ' . __dem('Вы или с вашего IP уже голосовали.') . ' </div>'; }