/**
 * View funcs
 */
require_once dirname(__FILE__) . '/_stats_view.funcs.php';
global $blog, $admin_url, $rsc_url;
// TOP REFERRING SEARCH ENGINES
?>

<h3><?php 
echo T_('Top referring search engines') . get_manual_link('top-referring-search-engines');
?>
</h3>

<?php 
global $res_stats, $row_stats;
refererList(20, 'global', 0, 0, "'search'", 'dom_name', $blog, true);
if (count($res_stats)) {
    ?>
	<table class="grouped table table-striped table-bordered table-hover table-condensed" cellspacing="0">
		<tr>
			<th class="firstcol"><?php 
    echo T_('Search engine');
    ?>
</th>
			<th><?php 
    echo T_('Hits');
    ?>
</th>
			<th class="lastcol"><?php 
    echo T_('% of total');
    ?>
// Requested URI (linked to blog's baseurlroot+URI):
$Results->cols[] = array('th' => T_('Requested URI'), 'order' => 'hit_uri', 'td' => '%stats_format_req_URI( #hit_blog_ID#, #hit_uri# )%');
// Remote address (IP):
$Results->cols[] = array('th' => T_('Remote IP'), 'order' => 'hit_remote_addr', 'td' => '% $GLOBALS[\'Plugins\']->get_trigger_event( \'FilterIpAddress\', $tmp_params = array(\'format\'=>\'htmlbody\', \'data\'=>\'$hit_remote_addr$\') ) %');
// Display results:
$Results->display();
?>
<h3><?php 
echo T_('Top referers');
?>
:</h3>

<?php 
// TODO: re-use $Results from above
global $res_stats, $row_stats;
refererList(30, 'global', 0, 0, "'referer'", 'dom_name', $blog, true);
if (count($res_stats)) {
    $chart['chart_data'][0][0] = "";
    $chart['chart_data'][1][0] = 'Top referers';
    // Needs UTF-8
    $count = 0;
    foreach ($res_stats as $row_stats) {
        if ($count < 8) {
            $count++;
            $chart['chart_data'][0][$count] = stats_basedomain(false);
        } else {
            $chart['chart_data'][0][$count] = 'Others';
            // Needs UTF-8
        }
        $chart['chart_data'][1][$count] = stats_hit_count(false);
    }