예제 #1
0
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;
        }
    }
}
예제 #2
0
function nrelate_flyout()
{
    global $post, $nr_fo_counter, $fo_styleclass, $fo_layout;
    $animation_fix = $nr_fo_nonjsbody = '';
    if (nrelate_flyout_is_loading()) {
        $nr_fo_counter++;
        $nrelate_flyout_options = get_option('nrelate_flyout_options');
        $fo_style_options = get_option('nrelate_flyout_options_styles');
        $fo_style_code = 'nrelate_' . ($fo_styleclass ? $fo_styleclass : "default");
        $fo_layout_code = 'nr_' . ($fo_layout ? $fo_layout : "1col");
        $fo_anim_style_options = get_option('nrelate_flyout_anim_options_styles');
        //$fo_anim_style_code = 'nrelate_animate_style_' . (($nrelate_flyout_options['flyout_animation']=='Slideout') ? $fo_anim_style_options['flyout_anim_slideout_style'] : $fo_anim_style_options['flyout_anim_fade_style']); // use for two styles
        $fo_anim_style_code = 'nrelate_animate_style_' . $fo_anim_style_options['flyout_anim_slideout_style'];
        $nr_fo_width_class = 'nr_' . ($nrelate_flyout_options['flyout_thumbnail'] == 'Thumbnails' ? $nrelate_flyout_options['flyout_thumbnail_size'] : "text");
        // Get the page title and url array
        $nrelate_title_url = nrelate_title_url(false);
        $nonjs = $nrelate_flyout_options['flyout_nonjs'];
        $nr_url = "http://api.nrelate.com/fow_wp/" . NRELATE_FLYOUT_PLUGIN_VERSION . "/?tag=nrelate_flyout";
        $nr_url .= "&keywords=" . urlencode($nrelate_title_url['post_title']) . "&domain=" . NRELATE_BLOG_ROOT . "&url=" . urlencode($nrelate_title_url['post_urlencoded']) . "&nr_div_number=" . $nr_fo_counter;
        $nr_url .= is_home() ? '&source=hp' : '';
        $nr_url = apply_filters('nrelate_api_url', $nr_url, $post->ID);
        //is loaded only once per page
        if (!defined('NRELATE_FLYOUT_HOME')) {
            define('NRELATE_FLYOUT_HOME', true);
            $animation_fix = '<style type="text/css">.nrelate_flyout .nr_sponsored{ left:0px !important; }</style>';
            $nrelate_flyout_options_ads = get_option('nrelate_flyout_options_ads');
            if (!empty($nrelate_flyout_options_ads['flyout_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_fo_nonjsbody = $response['body'];
                } else {
                    $nr_fo_nonjsbody = "<!-- nrelate error: nrelate server not 200. -->";
                }
            } else {
                $nr_fo_nonjsbody = "<!-- nrelate error: WP-request to nrelate server failed. -->";
            }
        }
        $markup = <<<EOD
{$animation_fix}
{$nr_fo_nonjsbody}
EOD;
        echo $markup;
    }
}
예제 #3
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;
        }
    }
}