Example #1
0
/**
 * Load common jquery and styles
 */
function nrelate_jquery_styles()
{
    $popular_load = 0;
    $related_load = 0;
    $flyout_load = 0;
    $nsquared_load = 0;
    if (function_exists("nrelate_popular_is_loading")) {
        $popular_load = nrelate_popular_is_loading() || is_single() ? 1 : 0;
    }
    if (function_exists("nrelate_related_is_loading")) {
        $related_load = nrelate_related_is_loading() ? 1 : 0;
    }
    if (function_exists("nrelate_flyout_is_loading")) {
        $flyout_load = nrelate_flyout_is_loading() ? 1 : 0;
    }
    if (function_exists("nrelate_nsquared_is_loading")) {
        $nsquared_load = nrelate_nsquared_is_loading() ? 1 : 0;
    }
    if ($related_load || $popular_load || $flyout_load || $nsquared_load) {
        // Load Common CSS
        wp_register_style('nrelate-style-common-' . str_replace(".", "-", NRELATE_PLUGIN_VERSION), NRELATE_CSS_URL . 'nrelate-panels-common.min.css', array(), NRELATE_PLUGIN_VERSION);
        wp_enqueue_style('nrelate-style-common-' . str_replace(".", "-", NRELATE_PLUGIN_VERSION));
        $options = get_option('nrelate_products');
        if (isset($options["related"]["status"]) && $options["related"]["status"]) {
            $rc_options = get_option('nrelate_related_options_ads');
            if (isset($rc_options['related_display_ad']) && $rc_options['related_display_ad'] == true && $rc_options['related_number_of_ads'] > 0) {
                wp_enqueue_script('thickbox');
                wp_enqueue_style('thickbox');
            }
        }
        if (isset($options["popular"]["status"]) && $options["popular"]["status"]) {
            $mp_options = get_option('nrelate_popular_options_ads');
            if (isset($mp_options['popular_display_ad']) && $mp_options['popular_display_ad'] == true && $mp_options['popular_number_of_ads'] > 0) {
                wp_enqueue_script('thickbox');
                wp_enqueue_style('thickbox');
            }
        }
        add_action("wp_print_scripts", "nrelate_init_plugins", 1);
    }
}
Example #2
0
function nrelate_popular($opt = false)
{
    global $post, $nr_mp_counter, $mp_styleclass, $mp_layout;
    $animation_fix = $nr_mp_nonjsbody = '';
    if (nrelate_popular_is_loading()) {
        $nr_mp_counter++;
        // Assign options
        $nrelate_popular_options = get_option('nrelate_popular_options');
        $p_max_age = $nrelate_popular_options['popular_max_age_num'];
        $p_max_frame = $nrelate_popular_options['popular_max_age_frame'];
        switch ($p_max_frame) {
            case 'Hour(s)':
                $maxageposts = $p_max_age * 60;
                break;
            case 'Day(s)':
                $maxageposts = $p_max_age * 1440;
                break;
            case 'Week(s)':
                $maxageposts = $p_max_age * 10080;
                break;
            case 'Month(s)':
                $maxageposts = $p_max_age * 44640;
                break;
            case 'Year(s)':
                $maxageposts = $p_max_age * 525600;
                break;
        }
        $nr_mp_counter += 1;
        // Get the page title and url array
        $nrelate_title_url = nrelate_title_url(false);
        $nonjs = $nrelate_popular_options['popular_nonjs'];
        $nr_url = "http://api.nrelate.com/mpw_wp/" . NRELATE_POPULAR_PLUGIN_VERSION . "/?tag=nrelate_popular";
        $nr_url .= "&domain=" . NRELATE_BLOG_ROOT . "&url=" . urlencode($nrelate_title_url['post_urlencoded']) . "&nr_div_number=" . $nr_mp_counter . "&maxageposts=" . $maxageposts;
        $nr_url .= is_home() ? '&source=hp' : '';
        $nr_url .= is_single() ? '&increment=1' : '&increment=0';
        $nr_url = apply_filters('nrelate_api_url', $nr_url, $post->ID);
        //is loaded only once per page for popular
        if (!defined('NRELATE_POPULAR_HOME')) {
            define('NRELATE_POPULAR_HOME', true);
            // Added to create disjoint between keeping count and displaying
            // If this page is single, $increment=1
            // If this page is single, send increment as 1. Call this only once
            $nrelate_popular_options_ads = get_option('nrelate_popular_options_ads');
            $animation_fix = '<style type="text/css">.nrelate_popular .nr_sponsored{ left:0px !important; }</style>';
            if (!empty($nrelate_popular_options_ads['popular_ad_animation'])) {
                $animation_fix = '';
            }
        }
        if ($nonjs && nrelate_is_crawler()) {
            $args = array("timeout" => 2);
            $response = wp_remote_get($nr_url . "&nonjs=1", $args);
            if (!is_wp_error($response)) {
                if ($response['response']['code'] == 200 && $response['response']['message'] == 'OK') {
                    $nr_mp_nonjsbody = $response['body'];
                } else {
                    $nr_mp_nonjsbody = "<!-- nrelate server not 200. -->";
                }
            } else {
                $nr_mp_nonjsbody = "<!-- WP-request to nrelate server failed. -->";
            }
        }
        $s_title = esc_attr($nrelate_title_url['post_title']);
        $s_permalink = esc_attr($nrelate_title_url['post_urlencoded']);
        $markup = <<<EOD
{$animation_fix}
<div class="nr_popular_placeholder" data-permalink="{$s_permalink}" data-title="{$s_title}">{$nr_mp_nonjsbody}</div>
EOD;
        if ($opt) {
            return $markup;
        } else {
            echo $markup;
        }
    }
}