Exemple #1
0
/**
 * Return fields of users
 * @param  string|array $args
 * @return object
 */
function ap_user_get_fields($args = '', $group = 'basic')
{
    $defaults = array('user_id' => get_current_user_id(), 'form' => array());
    $args = wp_parse_args($args, $defaults);
    $args['form'] = wp_parse_args($args['form'], array('is_ajaxified' => true, 'name' => 'ap_user_profile_form', 'user_id' => $args['user_id'], 'nonce_name' => 'nonce_user_profile_' . $args['user_id'] . '_' . $group, 'fields' => ap_get_user_fields($group)));
    $args['form']['fields'][] = array('name' => 'group', 'type' => 'hidden', 'value' => $group);
    anspress()->form = new AnsPress_Form($args['form']);
    return anspress()->form->get_form();
}
Exemple #2
0
/**
 * Generate answer form
 * @param  integer $question_id  Question iD.
 * @param  boolean $editing      true if post is being edited.
 * @return void
 */
function ap_answer_form($question_id, $editing = false)
{
    if (!ap_user_can_answer($question_id) && !$editing) {
        return;
    }
    global $editing_post;
    $is_private = isset($_POST['is_private']) ? (bool) $_POST['is_private'] : false;
    if ($editing) {
        $is_private = $editing_post->post_status == 'private_post' ? true : false;
    }
    $args = array('name' => 'answer_form', 'is_ajaxified' => true, 'submit_button' => $editing ? __('Update answer', 'anspress-question-answer') : __('Post answer', 'anspress-question-answer'), 'nonce_name' => 'nonce_answer_' . $question_id, 'fields' => array(array('name' => 'description', 'type' => 'editor', 'value' => $editing ? apply_filters('the_content', $editing_post->post_content) : wp_kses_post(@$_POST['description']), 'settings' => apply_filters('ap_answer_form_editor_settings', array('textarea_rows' => 8, 'tinymce' => ap_opt('answer_text_editor') ? false : true, 'quicktags' => ap_opt('answer_text_editor') ? true : false, 'media_buttons' => false)), 'placeholder' => __('Your answer..', 'anspress-question-answer')), array('name' => 'form_question_id', 'type' => 'hidden', 'value' => $editing ? $editing_post->post_parent : $question_id, 'order' => 20)));
    if (!is_user_logged_in() && ap_opt('allow_anonymous')) {
        $args['fields'][] = array('name' => 'name', 'label' => __('Name', 'anspress-question-answer'), 'type' => 'text', 'placeholder' => __('Enter your name to display', 'anspress-question-answer'), 'value' => sanitize_text_field(@$_POST['name']), 'order' => 12);
    }
    // If private posts is allowed then show the checkbox.
    if (ap_opt('allow_private_posts')) {
        $args['fields'][] = array('name' => 'is_private', 'type' => 'checkbox', 'desc' => __('Only visible to admin and moderator.', 'anspress-question-answer'), 'value' => $is_private, 'order' => 12, 'show_desc_tip' => false);
    }
    if (ap_show_captcha_to_user()) {
        // Show recpatcha if key exists and enabled.
        if (ap_opt('recaptcha_site_key') == '') {
            $reCaptcha_html = '<div class="ap-notice red">' . __('reCaptach keys missing, please add keys', 'anspress-question-answer') . '</div>';
        } else {
            $reCaptcha_html = '<div class="g-recaptcha" id="recaptcha" data-sitekey="' . ap_opt('recaptcha_site_key') . '"></div>';
            $reCaptcha_html .= '<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=' . get_locale() . '&onload=onloadCallback&render=explicit" async defer></script>';
            $reCaptcha_html .= '<script type="text/javascript">';
            $reCaptcha_html .= 'var onloadCallback = function() {';
            $reCaptcha_html .= 'widgetId1 = grecaptcha.render("recaptcha", {';
            $reCaptcha_html .= '"sitekey" : "' . ap_opt('recaptcha_site_key') . '"';
            $reCaptcha_html .= '});';
            $reCaptcha_html .= '};</script>';
        }
        $args['fields'][] = array('name' => 'captcha', 'type' => 'custom', 'order' => 100, 'html' => $reCaptcha_html);
    }
    $args['fields'][] = array('name' => 'ap_upload', 'type' => 'custom', 'html' => ap_post_upload_form(), 'order' => 11);
    /**
     * FILTER: ap_ask_form_fields
     * Filter for modifying $args
     * @var array
     * @since  2.0
     */
    $args = apply_filters('ap_answer_form_fields', $args, $editing);
    if ($editing) {
        $args['fields'][] = array('name' => 'edit_post_id', 'type' => 'hidden', 'value' => $editing_post->ID, 'order' => 20);
    }
    anspress()->form = new AnsPress_Form($args);
    echo anspress()->form->get_form();
    // Post image upload form.
    echo ap_post_upload_hidden_form();
}
Exemple #3
0
 /**
  * Output single question page
  * @return void
  */
 public function question_page()
 {
     global $questions;
     ap_get_question(get_question_id());
     if (ap_have_questions()) {
         while (anspress()->questions->have_posts()) {
             anspress()->questions->the_post();
             global $post;
             setup_postdata($post);
         }
         include ap_get_theme_location('question.php');
         wp_reset_postdata();
     } else {
         include ap_get_theme_location('not-found.php');
     }
 }
Exemple #4
0
 /**
  * Filter AnsPress page title for user sub pages
  * @param  string $title Title.
  * @return string
  */
 public function ap_page_title($title)
 {
     if (is_ap_user()) {
         $active = ap_active_user_page();
         $name = ap_user_get_the_display_name();
         $my = ap_is_my_profile();
         $user_pages = anspress()->user_pages;
         if ('activity' == $active) {
             $title = $my ? __('My activity', 'anspress-question-answer') : sprintf(__('%s\'s activity', 'anspress-question-answer'), $name);
         } elseif ('profile' == $active) {
             $title = $my ? __('My profile', 'anspress-question-answer') : sprintf(__('%s\'s profile', 'anspress-question-answer'), $name);
         } elseif ('questions' == $active) {
             $title = $my ? __('My questions', 'anspress-question-answer') : sprintf(__('%s\'s questions', 'anspress-question-answer'), $name);
         } elseif ('answers' == $active) {
             $title = $my ? __('My answers', 'anspress-question-answer') : sprintf(__('%s\'s answers', 'anspress-question-answer'), $name);
         } elseif ('reputation' == $active) {
             $title = $my ? __('My reputation', 'anspress-question-answer') : sprintf(__('%s\'s reputation', 'anspress-question-answer'), $name);
         } elseif ('about' == $active) {
             $title = $my ? __('About me', 'anspress-question-answer') : sprintf(__('%s', 'anspress-question-answer'), $name);
         } elseif ('followers' == $active) {
             $title = $my ? __('My followers', 'anspress-question-answer') : sprintf(__('%s\'s followers', 'anspress-question-answer'), $name);
         } elseif ('following' == $active) {
             $title = __('Following', 'anspress-question-answer');
         } elseif ('subscription' == $active) {
             $title = __('My subscriptions', 'anspress-question-answer');
         } elseif ('notification' == $active) {
             $title = __('My notification', 'anspress-question-answer');
         } else {
             $title = $user_pages[$active]['title'];
         }
     }
     return $title;
 }
            }
            foreach ($this->actions as $hook) {
                add_action($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']);
            }
        }
    }
}
/**
 * Run AnsPress thingy
 * @return object
 */
function anspress()
{
    return AnsPress::instance();
}
anspress();
/*
 ----------------------------------------------------------------------------*
 * Dashboard and Administrative Functionality
 *----------------------------------------------------------------------------*/
/*
 * The code below is intended to to give the lightest footprint possible.
 */
if (is_admin()) {
    require_once plugin_dir_path(__FILE__) . 'admin/anspress-admin.php';
    add_action('plugins_loaded', array('AnsPress_Admin', 'get_instance'));
}
/*
 * Register hooks that are fired when the plugin is activated or deactivated.
 * When the plugin is deleted, the uninstall.php file is loaded.
 */
Exemple #6
0
/**
* Output current anspress page
* @return void
* @since 2.0.0-beta
*/
function ap_page()
{
    $pages = anspress()->pages;
    $current_page = get_query_var('ap_page');
    if (is_question()) {
        $current_page = ap_opt('question_page_slug');
    } elseif ($current_page == '' && !is_question() && get_query_var('question_name') == '') {
        $current_page = 'base';
    }
    if (isset($pages[$current_page]['func'])) {
        call_user_func($pages[$current_page]['func']);
    } else {
        include ap_get_theme_location('not-found.php');
    }
}
Exemple #7
0
			<span class="ap-about-rep-label"><?php 
_e('Total', 'ap');
?>
</span>
			<span class="ap-about-rep-count"><?php 
ap_user_the_reputation();
?>
</span>
		</div>
		<div class="ap-about-rep-chart">
			<span data-action="ap_chart" data-type="bar" data-peity='{"fill" : ["#8fc77e"], "height": 45, "width": "100%"}'><?php 
echo ap_user_get_28_days_reputation();
?>
</span>		
		</div>
		<div class="ap-user-rep">
			<?php 
if (ap_has_reputations()) {
    while (ap_reputations()) {
        ap_the_reputation();
        ap_get_template_part('user/reputation-content');
    }
    ap_pagination(false, anspress()->reputations->total_pages);
} else {
    _e('No reputation earned yet.', 'ap');
}
?>
		</div>
	</div>
</div>
Exemple #8
0
/**
 * Return the current reputation obejct
 * @return object
 */
function ap_reputation_the_object()
{
    $rep = anspress()->reputations->reputation;
    return $rep;
}
Exemple #9
0
 /**
  * Add current-menu-item class in AnsPress pages
  * @param  array  $class Menu class.
  * @param  object $item Current menu item.
  * @return array menu item.
  * @since  2.1
  */
 public function fix_nav_current_class($class, $item)
 {
     $pages = anspress()->pages;
     if (!empty($item) && is_object($item)) {
         foreach ($pages as $slug => $args) {
             if (in_array('anspress-page-link', $class)) {
                 if (ap_get_link_to(get_query_var('ap_page')) != $item->url) {
                     $pos = array_search('current-menu-item', $class);
                     unset($class[$pos]);
                 }
                 if (!in_array('ap-dropdown', $class) && (in_array('anspress-page-notification', $class) || in_array('anspress-page-profile', $class))) {
                     $class[] = 'ap-dropdown';
                 }
             }
         }
     }
     return $class;
 }
Exemple #10
0
/**
 * Register AnsPress menu.
 *
 * @param string $slug
 * @param string $title
 * @param string $link
 */
function ap_register_menu($slug, $title, $link)
{
    anspress()->menu[$slug] = array('title' => $title, 'link' => $link);
}
Exemple #11
0
/**
 * output questions page pagination
 * @return string pagination html tag
 */
function ap_questions_the_pagination()
{
    $questions = anspress()->questions;
    ap_pagination(false, $questions->max_num_pages);
}
Exemple #12
0
/**
 * Output current AnsPress page.
 * @since 2.0.0-beta
 */
function ap_page()
{
    $pages = anspress()->pages;
    $current_page = get_query_var('ap_page');
    if (is_question()) {
        $current_page = ap_opt('question_page_slug');
    } elseif ('' == $current_page && !is_question() && '' == get_query_var('question_name')) {
        $current_page = 'base';
    }
    if (isset($pages[$current_page]['func'])) {
        call_user_func($pages[$current_page]['func']);
    } else {
        global $wp_query;
        $wp_query->set_404();
        status_header(404);
        include ap_get_theme_location('not-found.php');
    }
}
Exemple #13
0
function ap_is_user_page_public($page)
{
    $user_pages = anspress()->user_pages;
    if (isset($user_pages[$page]) && $user_pages[$page]['public']) {
        return true;
    }
    return false;
}
Exemple #14
0
    /**
     * Shows AnsPress menu meta box in WP menu editor
     * @return void
     * @since unknown
     */
    public function wp_nav_menu_item_anspress_meta_box()
    {
        global $_nav_menu_placeholder, $nav_menu_selected_id;
        $_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1;
        $pages = anspress()->pages;
        echo '<div class="aplinks" id="aplinks">';
        echo '<input type="hidden" value="custom" name="menu-item[' . $_nav_menu_placeholder . '][menu-item-type]" />';
        echo '<ul>';
        $pages['profile'] = array('title' => __('User profile', 'anspress-question-answer'), 'show_in_menu' => true);
        $pages['notification'] = array('title' => __('User notification', 'anspress-question-answer'), 'show_in_menu' => true);
        foreach ($pages as $k => $args) {
            if ($args['show_in_menu']) {
                echo '<li>';
                echo '<label class="menu-item-title">';
                echo '<input type="radio" value="" name="menu-item[' . $_nav_menu_placeholder . '][menu-item-url]" class="menu-item-checkbox" data-url="' . strtoupper('ANSPRESS_PAGE_URL_' . $k) . '" data-title="' . $args['title'] . '"> ' . $args['title'] . '</label>';
                echo '</li>';
            }
        }
        echo '</ul><p class="button-controls">
					<span class="add-to-menu">
						<input type="submit"' . wp_nav_menu_disabled_check($nav_menu_selected_id) . ' class="button-secondary submit-add-to-menu right" value="' . __('Add to Menu', 'anspress-question-answer') . '" name="add-custom-menu-item" id="submit-aplinks" />
						<span class="spinner"></span>
					</span>
				</p>';
        echo '</div>';
    }
Exemple #15
0
/**
 * Return the count of total numbers of Answers
 * @return integer
 * @since 2.1
 */
function ap_answer_get_the_count()
{
    return anspress()->answers->found_posts;
}