/** * Get a vote link to something. * * @param int $id Object id * @param string $vote_type Type of vote: 'up' or 'down' * @param string $vote_type Current vote, if any * @param string $link_text The content of the link * @return string */ function get_link($id, $vote_type, $current_vote, $link_text) { $voted = $vote_type == $current_vote; if (!$voted) { $vote = $vote_type; } else { $vote = 'undo'; } $data = array('action' => 'qa_vote', 'post_id' => $id, 'vote_type' => $vote); $input_attr = array('type' => 'submit', 'title' => $link_text, 'class' => "vote-{$vote_type}-" . ($voted ? 'on' : 'off')); if (!is_user_logged_in()) { $input_attr['data-msg'] = 'login'; } elseif (get_post_field('post_author', $id) == get_current_user_id()) { $input_attr['data-msg'] = 'own'; } ob_start(); ?> <form method="post" action=""> <?php wp_nonce_field('qa_vote'); ?> <?php foreach ($data as $key => $value) { echo _qa_html('input', array('type' => 'hidden', 'name' => $key, 'value' => $value)); } ?> <?php echo _qa_html('input', $input_attr); ?> </form> <?php return ob_get_clean(); }
function get_the_answer_link($answer_id) { $question_id = get_post_field('post_parent', $answer_id); return _qa_html('a', array('class' => 'answer-link', 'href' => qa_get_url('single', $answer_id)), get_the_title($question_id)); }
function form($instance) { $instance = $this->parse_instance($instance); $this->title_field($instance['title']); ?> <label for="<?php echo $this->get_field_id('number'); ?> "> <?php _e('Number of users to show:', QA_TEXTDOMAIN); ?> </label> <?php echo _qa_html('input', array('type' => 'text', 'size' => 2, 'id' => $this->get_field_id('number'), 'name' => $this->get_field_name('number'), 'value' => $instance['number'])); }
function form($instance) { $instance = $this->parse_instance($instance); $this->title_field($instance['title']); ?> <p> <label for="<?php echo $this->get_field_id('which'); ?> "><?php _e('Which:', QA_TEXTDOMAIN); ?> </label> <select id="<?php echo $this->get_field_id('which'); ?> " name="<?php echo $this->get_field_name('which'); ?> "> <?php $options = array('recent' => __('Recent', QA_TEXTDOMAIN), 'popular' => __('Popular', QA_TEXTDOMAIN), 'unanswered' => __('Unanswered', QA_TEXTDOMAIN)); foreach ($options as $value => $title) { $attr = compact('value'); if ($instance['which'] == $value) { $attr['selected'] = 'selected'; } echo _qa_html('option', $attr, $title); } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('number'); ?> "><?php _e('Number of questions to show:', QA_TEXTDOMAIN); ?> </label> <?php echo _qa_html('input', array('type' => 'text', 'size' => 2, 'id' => $this->get_field_id('number'), 'name' => $this->get_field_name('number'), 'value' => $instance['number'])); ?> </p> <?php }
function the_answer_form() { global $wp_query, $wp_version; if (is_qa_page('edit')) { $answer = $wp_query->posts[0]; if (!current_user_can('edit_post', $answer->ID)) { return; } } elseif (!current_user_can('publish_answers')) { echo _qa_html('p', sprintf(__('Please <a href="%s">login</a> to post questions.', QA_TEXTDOMAIN), wp_login_url(qa_get_url('single', get_queried_object_id())))); return; } else { $answer = (object) array('ID' => '', 'post_parent' => get_the_ID(), 'post_content' => ''); } ?> <form id="answer-form" method="post" action="<?php echo qa_get_url('archive'); ?> "> <?php wp_nonce_field('qa_answer'); ?> <input type="hidden" name="qa_action" value="edit_answer" /> <input type="hidden" name="question_id" value="<?php echo esc_attr($answer->post_parent); ?> " /> <input type="hidden" name="answer_id" value="<?php echo esc_attr($answer->ID); ?> " /> <?php if (version_compare($wp_version, "3.3") >= 0) { ?> <p><?php wp_editor($answer->post_content, 'answer', array('media_buttons' => false)); ?> </p> <?php } else { ?> <p><textarea name="answer" class="wp32"><?php echo esc_textarea($answer->post_content); ?> </textarea></p> <?php } ?> <?php the_qa_submit_button(); ?> </form> <?php }
function notify($new_status, $old_status, $post) { global $current_site; if ('answer' != $post->post_type || 'publish' != $new_status || $new_status == $old_status) { return; } $author = get_userdata($post->post_author); $question_id = $post->post_parent; $question = get_post($question_id); $subscribers = get_post_meta($question_id, '_sub'); if (!in_array($question->post_author, $subscribers)) { $subscribers[] = $question->post_author; } // Notify question author too $subject = sprintf(__('[%s] New answer on "%s"'), get_option('blogname'), $question->post_title); $content = sprintf(__('%s added a new answer to %s:', QA_TEXTDOMAIN), _qa_html('a', array('href' => qa_get_url('user', $post->post_author)), $author->user_nicename), _qa_html('a', array('href' => qa_get_url('single', $question_id)), get_post_field('post_title', $question_id))); $content .= "<br/><br/>" . $post->post_content . "<br/><br/>"; cache_users($subscribers); $admin_email = get_site_option('admin_email'); if ($admin_email == '') { $admin_email = 'admin@' . $current_site->domain; } $from_email = $admin_email; $message_headers = "MIME-Version: 1.0\n" . "From: " . $current_site->site_name . " <{$from_email}>\n" . "Content-Type: text/html; charset=\"" . get_option('blog_charset') . "\"\n"; foreach ($subscribers as $subscriber_id) { // Don't notify the author of the answer if ($post->post_author != $subscriber_id) { $msg = $content . sprintf(__('To manage your subscription, visit <a href="%s">the question</a>.', QA_TEXTDOMAIN), qa_get_url('single', $post->ID)); } else { $msg = $content; } wp_mail(get_user_option('user_email', $subscriber_id), $subject, $msg, $message_headers); } }