/**
 * Shortcode to display the rating result
 */
function mr_rating_result($atts = array(), $content = null, $tag)
{
    $can_do_shortcode = !(is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX));
    if (!apply_filters('mr_can_do_shortcode', $can_do_shortcode, 'mr_rating_result', $atts)) {
        return;
    }
    // get the post id
    global $post;
    $post_id = null;
    if (isset($post)) {
        $post_id = $post->ID;
    }
    $general_settings = (array) get_option(Multi_Rating::GENERAL_SETTINGS);
    $custom_text_settings = (array) get_option(Multi_Rating::CUSTOM_TEXT_SETTINGS);
    extract(shortcode_atts(array('post_id' => $post_id, 'no_rating_results_text' => $custom_text_settings[Multi_Rating::NO_RATING_RESULTS_TEXT_OPTION], 'show_rich_snippets' => false, 'show_title' => false, 'show_count' => true, 'result_type' => Multi_Rating::STAR_RATING_RESULT_TYPE, 'class' => '', 'before_count' => '(', 'after_count' => ')'), $atts));
    if ($post_id == null) {
        return;
        // No post Id available
    }
    if (is_string($show_rich_snippets)) {
        $show_rich_snippets = $show_rich_snippets == 'true' ? true : false;
    }
    if (is_string($show_title)) {
        $show_title = $show_title == 'true' ? true : false;
    }
    if (is_string($show_count)) {
        $show_count = $show_count == 'true' ? true : false;
    }
    return Multi_Rating_API::display_rating_result(array('post_id' => $post_id, 'no_rating_results_text' => $no_rating_results_text, 'show_rich_snippets' => $show_rich_snippets, 'show_title' => $show_title, 'show_date' => false, 'show_count' => $show_count, 'echo' => false, 'result_type' => $result_type, 'class' => $class . ' mr-shortcode', 'before_count' => $before_count, 'after_count' => $after_count));
}
/**
 * Filters the_title()
 *
 * @param $title
 * @return filtered title
 */
function mr_filter_the_title($title)
{
    // get the post id
    global $post;
    $post_id = null;
    if (!isset($post_id) && isset($post)) {
        $post_id = $post->ID;
    } else {
        if (!isset($post) && !isset($post_id)) {
            return $title;
            // No post id available to display rating result
        }
    }
    $can_apply_filter = !(!in_the_loop() || is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX));
    if (!apply_filters('mr_can_apply_filter', $can_apply_filter, 'the_title', $title, $post_id)) {
        return $title;
    }
    $rating_results_position = get_post_meta($post->ID, Multi_Rating::RATING_RESULTS_POSITION_POST_META, true);
    if ($rating_results_position == Multi_Rating::DO_NOT_SHOW) {
        return $title;
    }
    $position_settings = (array) get_option(Multi_Rating::POSITION_SETTINGS);
    // use default rating results position
    if ($rating_results_position == '') {
        $rating_results_position = $position_settings[Multi_Rating::RATING_RESULTS_POSITION_OPTION];
    }
    $rating_results_html = null;
    if ($rating_results_position == 'before_title' || $rating_results_position == 'after_title') {
        $rating_results_html = Multi_Rating_API::display_rating_result(array('post_id' => $post_id, 'echo' => false, 'show_date' => false, 'show_rich_snippets' => true, 'class' => $rating_results_position . ' mr-filter'));
    }
    $filtered_title = '';
    if ($rating_results_position == 'before_title' && $rating_results_html != null) {
        $filtered_title .= $rating_results_html;
    }
    $filtered_title .= $title;
    if ($rating_results_position == 'after_title' && $rating_results_html != null) {
        $filtered_title .= $rating_results_html;
    }
    do_action('mr_after_auto_placement', 'the_title', $post_id);
    return $filtered_title;
}
Beispiel #3
0
 /**
  * (non-PHPdoc)
  * @see WP_Widget::widget()
  */
 function widget($args, $instance)
 {
     // https://codex.wordpress.org/Function_Reference/url_to_postid
     // FIXME may not work with attachments. See here: https://pippinsplugins.com/retrieve-attachment-id-from-image-url/
     $post_id = url_to_postid(MR_Utils::get_current_url());
     if ($post_id == 0 || $post_id == null) {
         return;
         // Nothing to do.
     }
     if (!apply_filters('mr_can_apply_widget', true, $post_id, $args, $instance)) {
         return;
         // do nothing
     }
     extract($args);
     echo $before_widget;
     Multi_Rating_API::display_rating_result(array('class' => 'mr-widget', 'post_id' => $post_id));
     echo $after_widget;
 }