コード例 #1
0
ファイル: common-frontend.php プロジェクト: jeanpage/ca_learn
/**
 * 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);
    }
}
コード例 #2
0
ファイル: nrelate-related.php プロジェクト: jeanpage/ca_learn
function nrelate_related($opt = false)
{
    global $post, $nr_counter, $rc_styleclass, $rc_layout;
    $animation_fix = $nr_rc_nonjsbody = '';
    if (nrelate_related_is_loading()) {
        $nr_counter++;
        $nrelate_related_options = get_option('nrelate_related_options');
        $style_options = get_option('nrelate_related_options_styles');
        $style_code = 'nrelate_' . ($rc_styleclass ? $rc_styleclass : "default");
        $layout_code = 'nr_' . ($rc_layout ? $rc_layout : "1col");
        $nr_width_class = 'nr_' . ($nrelate_related_options['related_thumbnail'] == 'Thumbnails' ? $nrelate_related_options['related_thumbnail_size'] : "text");
        // Get the page title and url array
        $nrelate_title_url = nrelate_title_url(false);
        $nonjs = $nrelate_related_options['related_nonjs'];
        $nr_url = "http://api.nrelate.com/rcw_wp/" . NRELATE_RELATED_PLUGIN_VERSION . "/?tag=nrelate_related";
        $nr_url .= "&keywords=" . urlencode($nrelate_title_url['post_title']) . "&domain=" . NRELATE_BLOG_ROOT . "&url=" . urlencode($nrelate_title_url['post_urlencoded']) . "&nr_div_number=" . $nr_counter;
        $nr_url .= is_home() ? '&source=hp' : '';
        $nr_url = apply_filters('nrelate_api_url', $nr_url, $post->ID);
        //is loaded only once per page for related
        if (!defined('NRELATE_RELATED_HOME')) {
            define('NRELATE_RELATED_HOME', true);
            $nrelate_related_options_ads = get_option('nrelate_related_options_ads');
            $animation_fix = '<style type="text/css">.nrelate_related .nr_sponsored{ left:0px !important; }</style>';
            if (!empty($nrelate_related_options_ads['related_ad_animation'])) {
                $animation_fix = '';
            }
        }
        if ($nonjs && nrelate_is_crawler()) {
            $args = array("timeout" => 5);
            $response = wp_remote_get($nr_url . "&nonjs=1", $args);
            if (!is_wp_error($response)) {
                if ($response['response']['code'] == 200 && $response['response']['message'] == 'OK') {
                    $nr_rc_nonjsbody = $response['body'];
                } else {
                    $nr_rc_nonjsbody = "<!-- nrelate server not 200. -->";
                }
            } else {
                $nr_rc_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_related_placeholder" data-permalink="{$s_permalink}" data-title="{$s_title}">{$nr_rc_nonjsbody}</div>
EOD;
        if ($opt) {
            return $markup;
        } else {
            echo $markup;
        }
    }
}