function doctype()
 {
     qa_html_theme_base::doctype();
     if (qa_opt('cp_enable') && ($this->template == 'ask' || isset($this->content['q_list']) || isset($this->content['q_view']))) {
         global $qa_request;
         global $wiki_enable;
         if ($this->template == 'ask' && !qa_user_permit_error('permit_post_q') && !qa_opt('site_maintenance') && qa_permit_check('permit_create_cp')) {
             $this->content['form']['tags'] .= ' onSubmit="pollSubmit(event)"';
             $this->content['form']['fields'][] = array('label' => qa_lang('cp/checkbox_text'), 'tags' => 'NAME="cp_community" ID="cp_community"', 'type' => 'checkbox', 'value' => qa_post_text('cp_community') ? 1 : 0);
         }
         if (isset($this->content['q_view'])) {
             $qid = $this->content['q_view']['raw']['postid'];
             $author = $this->content['q_view']['raw']['userid'];
             if (!isset($wiki_enable)) {
                 $result = qa_db_query_sub('SELECT * FROM ^postmeta WHERE meta_key=$ AND post_id=#', 'is_community', $qid);
                 $wiki_enable = $result->num_rows > 0;
             }
             if ($wiki_enable) {
                 // is a community post
                 $this->content['title'] .= ' ' . qa_lang('cp/question_title');
                 // $this->content['q_view']['content'] = @$this->content['q_view']['content'].'<div id="qa-wiki-div">'.$this->getPollDiv($qid,qa_get_logged_in_userid()).'</div>';
                 $this->content['q_view']['main_form_tags'] = @$this->content['q_view']['main_form_tags'] . ' class="qa-community-posts"';
                 // print_r($this->content['q_view']['form']['buttons']);
                 if (isset($this->content['q_view']['form']['buttons']['edit'])) {
                     $this->content['q_view']['form']['buttons']['edit']['label'] = qa_lang_html('cp/contribute');
                     $this->content['q_view']['form']['buttons']['edit']['popup'] = qa_lang_html('cp/contribute_description');
                 }
                 unset($this->content['q_view']['form']['buttons']['answer']);
                 unset($this->content['q_view']['form']['buttons']['comment']);
                 unset($this->content['a_form']);
                 unset($this->content['c_form']);
             }
         }
         if (isset($this->content['q_list'])) {
             $wiki_array = qa_db_read_all_assoc(qa_db_query_sub('SELECT * FROM ^postmeta WHERE meta_key=$', 'is_community'));
             foreach ($wiki_array as $q) {
                 $wiki[(int) $q['post_id']] = $q['meta_value'];
             }
             foreach ($this->content['q_list']['qs'] as $idx => $question) {
                 if (isset($wiki[$question['raw']['postid']])) {
                     $this->content['q_list']['qs'][$idx]['title'] .= ' ' . qa_lang('cp/question_title');
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 function getPollDiv($qid, $uid, $vid = null, $cancel = false)
 {
     $author = $this->content['q_view']['raw']['userid'];
     if (!$this->poll) {
         $this->poll = qa_db_read_one_value(qa_db_query_sub("SELECT meta_value FROM ^postmeta WHERE post_id=# AND meta_key='is_poll'", $qid), true);
     }
     $answers = qa_db_read_all_assoc(qa_db_query_sub('SELECT BINARY content as content, votes, id FROM ^polls WHERE parentid=#', $qid));
     $voted = false;
     if ($this->poll != 2) {
         foreach ($answers as $idx => $answer) {
             $votes = explode(',', $answer['votes']);
             if (in_array($uid, $votes)) {
                 $voted = true;
                 break;
             }
         }
     }
     // do voting
     if ($vid && $uid && qa_permit_check('permit_vote_poll') && $this->poll < 9 && (qa_opt('poll_vote_change') || !$voted || $this->poll == 2)) {
         // not closed, note voted or can change vote
         $vid = (int) $vid;
         foreach ($answers as $idx => $answer) {
             $votes = explode(',', $answer['votes']);
             if ($answer['id'] == $vid && !$cancel) {
                 if (in_array($uid, $votes)) {
                     return '### you\'ve already voted, cheater!';
                 }
                 $answers[$idx]['votes'] = ($answers[$idx]['votes'] ? $answers[$idx]['votes'] . ',' : '') . $uid;
                 qa_db_query_sub('UPDATE ^polls SET votes=$ WHERE id=#', $answers[$idx]['votes'], $vid);
             } else {
                 if (in_array($uid, $votes) && ($this->poll != 2 || $cancel && $answer['id'] == $vid)) {
                     // unvoting
                     foreach ($votes as $i => $vote) {
                         if ($uid == $vote) {
                             unset($votes[$i]);
                             break;
                         }
                     }
                     $answers[$idx]['votes'] = implode(',', $votes);
                     qa_db_query_sub('UPDATE ^polls SET votes=$ WHERE id=#', $answers[$idx]['votes'], $answer['id']);
                     if ($this->poll != 2) {
                         // cancel voted on unvoting
                         $voted = in_array($uid, $votes);
                     }
                 }
             }
         }
     }
     if (empty($answers)) {
         return '### no choices found for poll!';
     }
     $out = '<div id="qa-poll-choices-title">' . qa_lang('polls/answers_text') . '</div><div id="qa-poll-choices">';
     // check if voted
     $allow = true;
     $totalvotes = 0;
     foreach ($answers as $idx => $answer) {
         if (!$answer['votes']) {
             $votes = array();
         } else {
             $votes = explode(',', $answer['votes']);
         }
         $totalvotes += count($votes);
         if (!$uid || !qa_permit_check('permit_vote_poll') || $this->poll > 9 || $voted && !qa_opt('poll_vote_change') && !in_array($uid, $votes) && $this->poll != 2) {
             $answers[$idx]['vote'] = '<div class="qa-poll-disabled-button" title="' . qa_html(qa_lang('polls/disabled_button')) . '"></div>';
         } else {
             if ($voted && !qa_opt('poll_vote_change') && $this->poll != 2) {
                 // voted for this one, can't change, not multiple
                 $answers[$idx]['vote'] = '<div class="qa-poll-voted-button" title="' . qa_html(qa_lang('polls/voted_button')) . '" onclick="alert(\'' . qa_lang('polls/cannot_change') . '\')"></div>';
             } else {
                 if (!in_array($uid, $votes)) {
                     $answers[$idx]['vote'] = '<div class="qa-poll-vote-button" title="' . qa_html(qa_lang('polls/vote_button')) . '" onclick="pollVote(' . $qid . ',\'' . $uid . '\',' . $answer['id'] . ')"></div>';
                 } else {
                     $answers[$idx]['vote'] = '<div class="qa-poll-voted-button" title="' . qa_html(qa_lang('polls/voted_button')) . '" onclick="pollVote(' . $qid . ',\'' . $uid . '\',\'' . $answer['id'] . ',1)"></div>';
                     $voted = true;
                 }
             }
         }
     }
     foreach ($answers as $answer) {
         if (!$answer['votes']) {
             $votes = array();
         } else {
             $votes = explode(',', $answer['votes']);
         }
         $out .= '<div class="qa-poll-choice">' . @$answer['vote'] . '<span class="qa-poll-choice-title">' . qa_html($answer['content']) . '</span>';
         if (!qa_opt('poll_votes_hide') || $voted || qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
             $out .= ' (' . (count($votes) == 1 ? qa_lang('main/1_vote') : str_replace('^', count($votes), qa_lang('main/x_votes'))) . (qa_opt('poll_votes_percent') && !empty($votes) > 0 ? ', ' . round(100 * count($votes) / $totalvotes) . '%' : '') . ')';
         }
         $out .= '<table class="qa-poll-votes"><tr>';
         if ($answer['votes'] && (!qa_opt('poll_votes_hide') || $voted || qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN)) {
             // don't show if user hasn't voted and admin option is checked
             $c = 0;
             while ($c++ < count($votes)) {
                 $out .= '<td class="qa-poll-vote-block" title="' . (count($votes) == 1 ? qa_lang('main/1_vote') : str_replace('^', count($votes), qa_lang('main/x_votes'))) . '"></td>';
             }
         } else {
             $out .= '<td class="qa-poll-vote-block-empty"></td>';
         }
         $out .= '</tr></table></div>';
     }
     if ($this->poll > 9) {
         // poll closed
         $out .= '<div class="qa-poll-closed">' . qa_lang('polls/poll_closed') . '</div>';
         if (!qa_user_permit_error('permit_close_poll') || qa_get_logged_in_userid() == $author) {
             $out .= '<input type="submit" class="qa-poll-button" title="' . qa_lang('polls/reopen_poll_hover') . '" value="' . qa_lang('polls/reopen_poll') . '" name="poll_reopen">';
         }
     } else {
         if (!qa_user_permit_error('permit_close_poll') || qa_get_logged_in_userid() == $author) {
             $out .= '<input type="submit" class="qa-poll-button" title="' . qa_lang('polls/close_poll_hover') . '" value="' . qa_lang('polls/close_poll') . '" name="poll_close">';
         }
     }
     if (!qa_user_permit_error('permit_delete_poll') || qa_get_logged_in_userid() == $author) {
         $out .= '<input type="submit" class="qa-poll-button" title="' . qa_lang('polls/delete_poll_hover') . '" value="' . qa_lang('polls/delete_poll') . '" name="poll_delete">';
     }
     $out .= '</div>';
     return $out;
 }
 function c_item_main($c_item)
 {
     global $topage;
     if (qa_opt('voting_on_cs') && is_array($this->comment_votes) && isset($c_item['content']) && !isset($c_item['url']) && !strpos($c_item['content'], 'question-closed-message')) {
         $vote = 0;
         $flag = 0;
         foreach ($this->comment_votes as $vote) {
             if ($vote['postid'] == $c_item['raw']['postid']) {
                 $vote = (int) $vote['vote'];
                 break;
             }
         }
         $netvotes = $c_item['raw']['netvotes'] != 0 ? $c_item['raw']['netvotes'] : '';
         if (qa_permit_check('permit_vote_c')) {
             $this->output('<table class="comment-votable-container"><tr><td class="comment-vote-container">');
             switch ($vote) {
                 case 1:
                     $up = 0;
                     $up_type = '-selected';
                     $down_type = false;
                     break;
                 case -1:
                     $down = 0;
                     $down_type = '-selected';
                     $up_type = false;
                     break;
                 default:
                     $up = 1;
                     $down = -1;
                     $up_type = '';
                     $down_type = '';
                     break;
             }
             if (!qa_opt('voting_down_cs') && $vote != -1) {
                 $down_type = false;
             }
             // don't allow for own user
             if ($c_item['raw']['userid'] != qa_get_logged_in_userid()) {
                 $this->output(($up_type !== false ? '<div class="comment-vote-item' . $up_type . '" name="vote_' . $c_item['raw']['postid'] . '_' . $up . '_c' . $c_item['raw']['postid'] . '_1" onclick="ajaxCommentVote(this);" title="' . qa_lang_html('main/vote' . ($up == 0 ? 'd' : '') . '_up_popup') . '">▲</div>' : '') . ($netvotes ? '<div id="voting_' . $c_item['raw']['postid'] . '">' . $netvotes . '</div>' : '') . ($down_type !== false ? '<div class="comment-vote-item' . $down_type . '" onclick="ajaxCommentVote(this);" name="vote_' . $c_item['raw']['postid'] . '_' . $down . '_c' . $c_item['raw']['postid'] . '_-1" title="' . qa_lang_html('main/vote' . ($down == 0 ? 'd' : '') . '_down_popup') . '">▼</div>' : ''));
             } else {
                 if ($netvotes) {
                     $this->output('<div id="voting_' . $c_item['raw']['postid'] . '">' . $netvotes . '</div>');
                 }
             }
             $this->output('</td><td>');
             qa_html_theme_base::c_item_main($c_item);
             $this->output('</td></tr></table>');
         } else {
             if ($netvotes) {
                 $this->output('<table class="comment-votable-container"><tr><td class="comment-vote-container"><div id="voting_' . $c_item['raw']['postid'] . '">' . $netvotes . '</div></td><td>');
                 qa_html_theme_base::c_item_main($c_item);
                 $this->output('</td></tr></table>');
             } else {
                 qa_html_theme_base::c_item_main($c_item);
             }
         }
     } else {
         qa_html_theme_base::c_item_main($c_item);
     }
 }