]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - yourls-infos.php
Merge pull request #2452 from adigitalife/patch-1
[Github/YOURLS.git] / yourls-infos.php
1 <?php
2 // TODO: make things cleaner. This file is an awful HTML/PHP soup.
3 define( 'YOURLS_INFOS', true );
4 require_once( dirname( __FILE__ ).'/includes/load-yourls.php' );
5 require_once( YOURLS_INC.'/functions-infos.php' );
6 yourls_maybe_require_auth();
7
8 // Variables should be defined in yourls-loader.php, if not try GET request (old behavior of yourls-infos.php)
9 if( !isset( $keyword ) && isset( $_GET['id'] ) )
10         $keyword = $_GET['id'];
11 if( !isset( $aggregate ) && isset( $_GET['all'] ) && $_GET['all'] == 1 && yourls_allow_duplicate_longurls() )
12         $aggregate = true;
13
14 if ( !isset( $keyword ) ) {
15         yourls_do_action( 'infos_no_keyword' );
16         yourls_redirect( YOURLS_SITE, 302 );
17 }
18
19 // Get basic infos for this shortened URL
20 $keyword = yourls_sanitize_string( $keyword );
21 $longurl = yourls_get_keyword_longurl( $keyword );
22 $clicks = yourls_get_keyword_clicks( $keyword );
23 $timestamp = yourls_get_keyword_timestamp( $keyword );
24 $title = yourls_get_keyword_title( $keyword );
25
26 // Update title if it hasn't been stored yet
27 if( $title == '' ) {
28         $title = yourls_get_remote_title( $longurl );
29         yourls_edit_link_title( $keyword, $title );
30 }
31
32 if ( $longurl === false ) {
33         yourls_do_action( 'infos_keyword_not_found' );
34         yourls_redirect( YOURLS_SITE, 302 );
35 }
36
37 yourls_do_action( 'pre_yourls_infos', $keyword );
38
39
40 if( yourls_do_log_redirect() ) {
41
42         $table = YOURLS_DB_TABLE_LOG;
43         $referrers = array();
44         $direct = $notdirect = 0;
45         $countries = array();
46         $dates = array();
47         $list_of_days = array();
48         $list_of_months = array();
49         $list_of_years = array();
50         $last_24h = array();
51
52         if( yourls_allow_duplicate_longurls() )
53                 $keyword_list = yourls_get_longurl_keywords( $longurl );
54         // Define keyword query range : either a single keyword or a list of keywords
55         if( $aggregate ) {
56                 $keyword_range = 'IN ( :list )';
57         $keyword_binds = array('list' => $keyword_list);
58         } else {
59                 $keyword_range = '= :keyword';
60         $keyword_binds = array('keyword' => $keyword);
61         }
62
63
64         // *** Referrers ***
65     $sql = "SELECT `referrer`, COUNT(*) AS `count` FROM `$table` WHERE `shorturl` $keyword_range GROUP BY `referrer`;";
66     $sql = yourls_apply_filter('stat_query_referrer', $sql);
67         $rows = $ydb->fetchObjects($sql, $keyword_binds);
68
69         // Loop through all results and build list of referrers, countries and hits per day
70         foreach( (array)$rows as $row ) {
71                 if ( $row->referrer == 'direct' ) {
72                         $direct = $row->count;
73                         continue;
74                 }
75
76                 $host = yourls_get_domain( $row->referrer );
77                 if( !array_key_exists( $host, $referrers ) )
78                         $referrers[$host] = array( );
79                 if( !array_key_exists( $row->referrer, $referrers[$host] ) ) {
80                         $referrers[$host][$row->referrer] = $row->count;
81                         $notdirect += $row->count;
82                 } else {
83                         $referrers[$host][$row->referrer] += $row->count;
84                         $notdirect += $row->count;
85                 }
86         }
87
88         // Sort referrers. $referrer_sort is a array of most frequent domains
89         arsort( $referrers );
90         $referrer_sort = array();
91         $number_of_sites = count( array_keys( $referrers ) );
92         foreach( $referrers as $site => $urls ) {
93                 if( count($urls) > 1 || $number_of_sites == 1 )
94                         $referrer_sort[$site] = array_sum( $urls );
95         }
96         arsort($referrer_sort);
97
98
99         // *** Countries ***
100         $sql = "SELECT `country_code`, COUNT(*) AS `count` FROM `$table` WHERE `shorturl` $keyword_range GROUP BY `country_code`;";
101     $sql = yourls_apply_filter('stat_query_country', $sql);
102         $rows = $ydb->fetchObjects($sql, $keyword_binds);
103
104         // Loop through all results and build list of countries and hits
105         foreach( (array)$rows as $row ) {
106                 if ("$row->country_code")
107                         $countries["$row->country_code"] = $row->count;
108         }
109
110         // Sort countries, most frequent first
111         if ( $countries )
112                 arsort( $countries );
113
114
115         // *** Dates : array of $dates[$year][$month][$day] = number of clicks ***
116         $sql = "SELECT
117                 DATE_FORMAT(`click_time`, '%Y') AS `year`,
118                 DATE_FORMAT(`click_time`, '%m') AS `month`,
119                 DATE_FORMAT(`click_time`, '%d') AS `day`,
120                 COUNT(*) AS `count`
121         FROM `$table`
122         WHERE `shorturl` $keyword_range
123         GROUP BY `year`, `month`, `day`;";
124     $sql = yourls_apply_filter('stat_query_dates', $sql);
125         $rows = $ydb->fetchObjects($sql, $keyword_binds);
126
127         // Loop through all results and fill blanks
128         foreach( (array)$rows as $row ) {
129                 if( !array_key_exists($row->year, $dates ) )
130                         $dates[$row->year] = array();
131                 if( !array_key_exists( $row->month, $dates[$row->year] ) )
132                         $dates[$row->year][$row->month] = array();
133                 if( !array_key_exists( $row->day, $dates[$row->year][$row->month] ) )
134                         $dates[$row->year][$row->month][$row->day] = $row->count;
135                 else
136                         $dates[$row->year][$row->month][$row->day] += $row->count;
137         }
138
139         // Sort dates, chronologically from [2007][12][24] to [2009][02][19]
140         ksort( $dates );
141         foreach( $dates as $year=>$months ) {
142                 ksort( $dates[$year] );
143                 foreach( $months as $month=>$day ) {
144                         ksort( $dates[$year][$month] );
145                 }
146         }
147
148         // Get $list_of_days, $list_of_months, $list_of_years
149         reset( $dates );
150         if( $dates ) {
151         $_lists = yourls_build_list_of_days( $dates );
152         $list_of_days   = $_lists['list_of_days'];
153         $list_of_months = $_lists['list_of_months'];
154         $list_of_years  = $_lists['list_of_years'];
155         unset($_lists);
156         }
157
158         // *** Last 24 hours : array of $last_24h[ $hour ] = number of click ***
159         $sql = "SELECT
160                 DATE_FORMAT(DATE_ADD(`click_time`, INTERVAL " . YOURLS_HOURS_OFFSET . " HOUR), '%H %p') AS `time`,
161                 COUNT(*) AS `count`
162         FROM `$table`
163         WHERE `shorturl` $keyword_range AND DATE_ADD(`click_time`, INTERVAL " . YOURLS_HOURS_OFFSET . " HOUR) > (DATE_ADD(CURRENT_TIMESTAMP, INTERVAL " . YOURLS_HOURS_OFFSET . " HOUR) - INTERVAL 1 DAY)
164         GROUP BY `time`;";
165     $sql = yourls_apply_filter('stat_query_last24h', $sql);
166         $rows = $ydb->fetchObjects($sql, $keyword_binds);
167
168         $_last_24h = array();
169         foreach( (array)$rows as $row ) {
170                 if ( isset( $row->time ) )
171                         $_last_24h[ "$row->time" ] = $row->count;
172         }
173
174         $now = intval( date('U') );
175         for ($i = 23; $i >= 0; $i--) {
176                 $h = date('H A', ($now - ($i * 60 * 60) + (YOURLS_HOURS_OFFSET * 60 * 60)) );
177                 // If the $last_24h doesn't have all the hours, insert missing hours with value 0
178                 $last_24h[ $h ] = array_key_exists( $h, $_last_24h ) ? $_last_24h[ $h ] : 0 ;
179         }
180         unset( $_last_24h );
181
182         // *** Queries all done, phew ***
183
184         // Filter all this junk if applicable. Be warned, some are possibly huge datasets.
185         $referrers      = yourls_apply_filter( 'pre_yourls_info_referrers', $referrers );
186         $referrer_sort  = yourls_apply_filter( 'pre_yourls_info_referrer_sort', $referrer_sort );
187         $direct         = yourls_apply_filter( 'pre_yourls_info_direct', $direct );
188         $notdirect      = yourls_apply_filter( 'pre_yourls_info_notdirect', $notdirect );
189         $dates          = yourls_apply_filter( 'pre_yourls_info_dates', $dates );
190         $list_of_days   = yourls_apply_filter( 'pre_yourls_info_list_of_days', $list_of_days );
191         $list_of_months = yourls_apply_filter( 'pre_yourls_info_list_of_months', $list_of_months );
192         $list_of_years  = yourls_apply_filter( 'pre_yourls_info_list_of_years', $list_of_years );
193         $last_24h       = yourls_apply_filter( 'pre_yourls_info_last_24h', $last_24h );
194         $countries      = yourls_apply_filter( 'pre_yourls_info_countries', $countries );
195
196         // I can haz debug data
197         /**
198         echo "<pre>";
199         echo "referrers: "; print_r( $referrers );
200         echo "referrer sort: "; print_r( $referrer_sort );
201         echo "direct: $direct\n";
202         echo "notdirect: $notdirect\n";
203         echo "dates: "; print_r( $dates );
204         echo "list of days: "; print_r( $list_of_days );
205         echo "list_of_months: "; print_r( $list_of_months );
206         echo "list_of_years: "; print_r( $list_of_years );
207         echo "last_24h: "; print_r( $last_24h );
208         echo "countries: "; print_r( $countries );
209         die();
210         **/
211
212 }
213
214 yourls_html_head( 'infos', yourls_s( 'Statistics for %s', YOURLS_SITE.'/'.$keyword ) );
215 yourls_html_logo();
216 yourls_html_menu();
217 ?>
218
219 <h2 id="informations"><?php echo yourls_esc_html( $title ); ?></h2>
220
221 <h3><span class="label"><?php yourls_e( 'Short URL'); ?>:</span> <img src="<?php yourls_favicon() ?>"/>
222 <?php if( $aggregate ) {
223         $i = 0;
224         foreach( $keyword_list as $k ) {
225                 $i++;
226                 if ( $i == 1 ) {
227                         yourls_html_link( yourls_link($k) );
228                 } else {
229                         yourls_html_link( yourls_link($k), "/$k" );
230                 }
231                 if ( $i < count( $keyword_list ) )
232                         echo ' + ';
233         }
234 } else {
235         yourls_html_link( yourls_link($keyword) );
236         if( isset( $keyword_list ) && count( $keyword_list ) > 1 )
237                 echo ' <a href="'. yourls_link($keyword).'+all" title="' . yourls_esc_attr__( 'Aggregate stats for duplicate short URLs' ) . '"><img src="' . yourls_match_current_protocol( YOURLS_SITE ) . '/images/chart_bar_add.png" border="0" /></a>';
238 } ?></h3>
239 <h3 id="longurl"><span class="label"><?php yourls_e( 'Long URL'); ?>:</span> <img class="fix_images" src="<?php echo yourls_get_favicon_url( $longurl );?>" /> <?php yourls_html_link( $longurl, yourls_trim_long_string( $longurl ), 'longurl' ); ?></h3>
240
241 <div id="tabs">
242         <div class="wrap_unfloat">
243         <ul id="headers" class="toggle_display stat_tab">
244                 <?php if( yourls_do_log_redirect() ) { ?>
245                 <li class="selected"><a href="#stat_tab_stats"><h2><?php yourls_e( 'Traffic statistics'); ?></h2></a></li>
246                 <li><a href="#stat_tab_location"><h2><?php yourls_e( 'Traffic location'); ?></h2></a></li>
247                 <li><a href="#stat_tab_sources"><h2><?php yourls_e( 'Traffic sources'); ?></h2></a></li>
248                 <?php } ?>
249                 <li><a href="#stat_tab_share"><h2><?php yourls_e( 'Share'); ?></h2></a></li>
250         </ul>
251         </div>
252
253
254 <?php if( yourls_do_log_redirect() ) { ?>
255         <div id="stat_tab_stats" class="tab">
256                 <h2><?php yourls_e( 'Traffic statistics'); ?></h2>
257
258                 <?php yourls_do_action( 'pre_yourls_info_stats', $keyword ); ?>
259
260                 <?php if ( $list_of_days ) { ?>
261
262                         <?php
263                         $graphs = array(
264                                 '24' => yourls__( 'Last 24 hours' ),
265                                 '7'  => yourls__( 'Last 7 days' ),
266                                 '30' => yourls__( 'Last 30 days' ),
267                                 'all'=> yourls__( 'All time' ),
268                         );
269
270                         // Which graph to generate ?
271                         $do_all = $do_30 = $do_7 = $do_24 = false;
272                         $hits_all = array_sum( $list_of_days );
273                         $hits_30  = array_sum( array_slice( $list_of_days, -30 ) );
274                         $hits_7   = array_sum( array_slice( $list_of_days, -7 ) );
275                         $hits_24  = array_sum( $last_24h );
276                         if( $hits_all > 0 )
277                                 $do_all = true; // graph for all days range
278                         if( $hits_30 > 0 && count( array_slice( $list_of_days, -30 ) ) == 30 )
279                                 $do_30 = true; // graph for last 30 days
280                         if( $hits_7 > 0 && count( array_slice( $list_of_days, -7 ) ) == 7 )
281                                 $do_7 = true; // graph for last 7 days
282                         if( $hits_24 > 0 )
283                                 $do_24 = true; // graph for last 24 hours
284
285                         // Which graph to display ?
286                         $display_all = $display_30 = $display_7 = $display_24 = false;
287                         if( $do_24 ) {
288                                 $display_24 = true;
289                         } elseif ( $do_7 ) {
290                                 $display_7 = true;
291                         } elseif ( $do_30 ) {
292                                 $display_30 = true;
293                         } elseif ( $do_all ) {
294                                 $display_all = true;
295                         }
296                         ?>
297
298                         <table border="0" cellspacing="2">
299                         <tr>
300                                 <td valign="top">
301                                 <ul id="stats_lines" class="toggle_display stat_line">
302                                 <?php
303                                 if( $do_24 == true )
304                                         echo '<li><a href="#stat_line_24">' . yourls__( 'Last 24 hours' ) . '</a>';
305                                 if( $do_7 == true )
306                                         echo '<li><a href="#stat_line_7">' . yourls__( 'Last 7 days' ) . '</a>';
307                                 if( $do_30 == true )
308                                         echo '<li><a href="#stat_line_30">' . yourls__( 'Last 30 days' ) . '</a>';
309                                 if( $do_all == true )
310                                         echo '<li><a href="#stat_line_all">' . yourls__( 'All time' ) . '</a>';
311                                 ?>
312                                 </ul>
313                                 <?php
314                                 // Generate, and display if applicable, each needed graph
315                                 foreach( $graphs as $graph => $graphtitle ) {
316                                         if( ${'do_'.$graph} == true ) {
317                                                 $display = ( ${'display_'.$graph} === true ? 'display:block' : 'display:none' );
318                                                 echo "<div id='stat_line_$graph' class='stats_line line' style='$display'>";
319                                                 echo '<h3>' . yourls_s( 'Number of hits : %s' , $graphtitle ) . '</h3>';
320                                                 switch( $graph ) {
321                                                         case '24':
322                                                                 yourls_stats_line( $last_24h, "stat_line_$graph" );
323                                                                 break;
324
325                                                         case '7':
326                                                         case '30':
327                                                                 $slice = array_slice( $list_of_days, intval( $graph ) * -1 );
328                                                                 yourls_stats_line( $slice, "stat_line_$graph" );
329                                                                 unset( $slice );
330                                                                 break;
331
332                                                         case 'all':
333                                                                 yourls_stats_line( $list_of_days, "stat_line_$graph" );
334                                                                 break;
335                                                 }
336                                                 echo "</div>\n";
337                                         }
338                                 } ?>
339
340                                 </td>
341                                 <td valign="top">
342                                 <h3><?php yourls_e( 'Historical click count' ); ?></h3>
343                                 <?php
344                                 $ago = round( (date('U') - strtotime($timestamp)) / (24* 60 * 60 ) );
345                                 if( $ago <= 1 ) {
346                                         $daysago = '';
347                                 } else {
348                                         $daysago = ' (' . sprintf( yourls_n( 'about 1 day ago', 'about %s days ago', $ago ), $ago ) . ')';
349                                 }
350                                 ?>
351                                 <p><?php echo /* //translators: eg Short URL created on March 23rd 1972 */ yourls_s( 'Short URL created on %s', yourls_date_i18n( "F j, Y @ g:i a", ( strtotime( $timestamp ) + YOURLS_HOURS_OFFSET * 3600 ) ) ) . $daysago; ?></p>
352                                 <div class="wrap_unfloat">
353                                         <ul class="no_bullet toggle_display stat_line" id="historical_clicks">
354                                         <?php
355                                         foreach( $graphs as $graph => $graphtitle ) {
356                                                 if ( ${'do_'.$graph} ) {
357                                                         $link = "<a href='#stat_line_$graph'>$graphtitle</a>";
358                                                 } else {
359                                                         $link = $graphtitle;
360                                                 }
361                                                 $stat = '';
362                                                 if( ${'do_'.$graph} ) {
363                                                         switch( $graph ) {
364                                                                 case '7':
365                                                                 case '30':
366                                                                         $stat = yourls_s( '%s per day', round( ( ${'hits_'.$graph} / intval( $graph ) ) * 100 ) / 100 );
367                                                                         break;
368                                                                 case '24':
369                                                                         $stat = yourls_s( '%s per hour', round( ( ${'hits_'.$graph} / 24 ) * 100 ) / 100 );
370                                                                         break;
371                                                                 case 'all':
372                                                                         if( $ago > 0 )
373                                                                                 $stat = yourls_s( '%s per day', round( ( ${'hits_'.$graph} / $ago ) * 100 ) / 100 );
374                                                         }
375                                                 }
376                                                 $hits = sprintf( yourls_n( '%s hit', '%s hits', ${'hits_'.$graph} ), ${'hits_'.$graph} );
377                                                 echo "<li><span class='historical_link'>$link</span> <span class='historical_count'>$hits</span> $stat</li>\n";
378                                         }
379                                         ?>
380                                         </ul>
381                                 </div>
382
383                                 <h3><?php yourls_e( 'Best day' ); ?></h3>
384                                 <?php
385                                 $best = yourls_stats_get_best_day( $list_of_days );
386                                 $best_time['day']   = date( "d", strtotime( $best['day'] ) );
387                                 $best_time['month'] = date( "m", strtotime( $best['day'] ) );
388                                 $best_time['year']  = date( "Y", strtotime( $best['day'] ) );
389                                 ?>
390                                 <p><?php echo sprintf( /* //translators: eg. 43 hits on January 1, 1970 */ yourls_n( '<strong>%1$s</strong> hit on %2$s', '<strong>%1$s</strong> hits on %2$s', $best['max'] ), $best['max'],  yourls_date_i18n( "F j, Y", strtotime( $best['day'] ) ) ); ?>.
391                                 <a href="" class='details hide-if-no-js' id="more_clicks"><?php yourls_e( 'Click for more details' ); ?></a></p>
392                                 <ul id="details_clicks" style="display:none">
393                                         <?php
394                                         foreach( $dates as $year=>$months ) {
395                                                 $css_year = ( $year == $best_time['year'] ? 'best_year' : '' );
396                                                 if( count( $list_of_years ) > 1 ) {
397                                                         $li = "<a href='' class='details' id='more_year$year'>" . yourls_s( 'Year %s', $year ) . '</a>';
398                                                         $display = 'none';
399                                                 } else {
400                                                         $li = yourls_s( 'Year %s', $year );
401                                                         $display = 'block';
402                                                 }
403                                                 echo "<li><span class='$css_year'>$li</span>";
404                                                 echo "<ul style='display:$display' id='details_year$year'>";
405                                                 foreach( $months as $month=>$days ) {
406                                                         $css_month = ( ( $month == $best_time['month'] && ( $css_year == 'best_year' ) ) ? 'best_month' : '' );
407                                                         $monthname = yourls_date_i18n( "F", mktime( 0, 0, 0, $month, 1 ) );
408                                                         if( count( $list_of_months ) > 1 ) {
409                                                                 $li = "<a href='' class='details' id='more_month$year$month'>$monthname</a>";
410                                                                 $display = 'none';
411                                                         } else {
412                                                                 $li = "$monthname";
413                                                                 $display = 'block';
414                                                         }
415                                                         echo "<li><span class='$css_month'>$li</span>";
416                                                         echo "<ul style='display:$display' id='details_month$year$month'>";
417                                                                 foreach( $days as $day=>$hits ) {
418                                                                         $class = ( $hits == $best['max'] ? 'class="bestday"' : '' );
419                                                                         echo "<li $class>$day: " . sprintf( yourls_n( '1 hit', '%s hits', $hits ), $hits ) ."</li>\n";
420                                                                 }
421                                                         echo "</ul>\n";
422                                                 }
423                                                 echo "</ul>\n";
424                                         }
425                                         ?>
426                                 </ul>
427
428                                 </td>
429
430                         </tr>
431                         </table>
432
433                 <?php yourls_do_action( 'post_yourls_info_stats', $keyword ); ?>
434
435                 <?php } else {
436                         echo '<p>' . yourls__( 'No traffic yet. Get some clicks first!' ) . '</p>';
437                 } ?>
438         </div>
439
440
441         <div id="stat_tab_location" class="tab">
442                 <h2><?php yourls_e( 'Traffic location' ); ?></h2>
443
444                 <?php yourls_do_action( 'pre_yourls_info_location', $keyword ); ?>
445
446                 <?php if ( $countries ) { ?>
447
448                         <table border="0" cellspacing="2">
449                         <tr>
450                                 <td valign="top">
451                                         <h3><?php yourls_e( 'Top 5 countries' ); ?></h3>
452                                         <?php yourls_stats_pie( $countries, 5, '340x220', 'stat_tab_location_pie' ); ?>
453                                         <p><a href="" class='details hide-if-no-js' id="more_countries"><?php yourls_e( 'Click for more details' ); ?></a></p>
454                                         <ul id="details_countries" style="display:none" class="no_bullet">
455                                         <?php
456                                         foreach( $countries as $code=>$count ) {
457                                                 echo "<li><img src='".yourls_geo_get_flag( $code )."' /> $code (".yourls_geo_countrycode_to_countryname( $code ) . ') : ' . sprintf( yourls_n( '1 hit', '%s hits', $count ), $count ) . "</li>\n";
458                                         }
459                                         ?>
460                                         </ul>
461
462                                 </td>
463                                 <td valign="top">
464                                         <h3><?php yourls_e( 'Overall traffic' ); ?></h3>
465                                         <?php yourls_stats_countries_map( $countries, 'stat_tab_location_map' ); ?>
466                                 </td>
467                         </tr>
468                         </table>
469
470                 <?php yourls_do_action( 'post_yourls_info_location', $keyword ); ?>
471
472                 <?php } else {
473                         echo '<p>' . yourls__( 'No country data.' ) . '</p>';
474                 } ?>
475         </div>
476
477
478         <div id="stat_tab_sources" class="tab">
479                 <h2><?php yourls_e( 'Traffic sources' ); ?></h2>
480
481                 <?php yourls_do_action( 'pre_yourls_info_sources', $keyword ); ?>
482
483                 <?php if ( $referrers ) { ?>
484
485                         <table border="0" cellspacing="2">
486                         <tr>
487                                 <td valign="top">
488                                         <h3><?php yourls_e( 'Referrer shares' ); ?></h3>
489                                         <?php
490                                         if ( $number_of_sites > 1 )
491                                                 $referrer_sort[ yourls__( 'Others' ) ] = count( $referrers );
492                                         yourls_stats_pie( $referrer_sort, 5, '440x220', 'stat_tab_source_ref' );
493                                         unset( $referrer_sort[yourls__('Others')] );
494                                         ?>
495                                         <h3><?php yourls_e( 'Referrers' ); ?></h3>
496                                         <ul class="no_bullet">
497                                                 <?php
498                                                 $i = 0;
499                                                 foreach( $referrer_sort as $site => $count ) {
500                                                         $i++;
501                                                         $favicon = yourls_get_favicon_url( $site );
502                                                         echo "<li class='sites_list'><img src='$favicon' class='fix_images'/> $site: <strong>$count</strong> <a href='' class='details hide-if-no-js' id='more_url$i'>" . yourls__( '(details)' ) . "</a></li>\n";
503                                                         echo "<ul id='details_url$i' style='display:none'>";
504                                                         foreach( $referrers[$site] as $url => $count ) {
505                                                                 echo "<li>"; yourls_html_link($url); echo ": <strong>$count</strong></li>\n";
506                                                         }
507                                                         echo "</ul>\n";
508                                                         unset( $referrers[$site] );
509                                                 }
510                                                 // Any referrer left? Group in "various"
511                                                 if ( $referrers ) {
512                                                         echo "<li id='sites_various'>" . yourls__( 'Various:' ) . " <strong>". count( $referrers ). "</strong> <a href='' class='details hide-if-no-js' id='more_various'>" . yourls__( '(details)' ) . "</a></li>\n";
513                                                         echo "<ul id='details_various' style='display:none'>";
514                                                         foreach( $referrers as $url ) {
515                                                                 echo "<li>"; yourls_html_link(key($url)); echo ": 1</li>\n";
516                                                         }
517                                                         echo "</ul>\n";
518                                                 }
519                                                 ?>
520
521                                         </ul>
522
523                                 </td>
524
525                                 <td valign="top">
526                                         <h3><?php yourls_e( 'Direct vs Referrer Traffic' ); ?></h3>
527                                         <?php
528                                         yourls_stats_pie( array( yourls__( 'Direct' ) => $direct, yourls__( 'Referrers' ) => $notdirect ), 5, '440x220', 'stat_tab_source_direct' );
529                                         ?>
530                                         <p><?php yourls_e( 'Direct traffic:' ); echo ' ' . sprintf( yourls_n( '<strong>%s</strong> hit', '<strong>%s</strong> hits', $direct ), $direct ); ?> </p>
531                                         <p><?php yourls_e( 'Referrer traffic:' ); echo ' ' . sprintf( yourls_n( '<strong>%s</strong> hit', '<strong>%s</strong> hits', $notdirect ), $notdirect ); ?> </p>
532
533                                 </td>
534                         </tr>
535                         </table>
536
537                 <?php yourls_do_action( 'post_yourls_info_sources', $keyword ); ?>
538
539                 <?php } else {
540                         echo '<p>' . yourls__( 'No referrer data.' ) . '</p>';
541                 } ?>
542
543         </div>
544
545 <?php } // endif do log redirect ?>
546
547
548         <div id="stat_tab_share" class="tab">
549                 <h2><?php yourls_e( 'Share' ); ?></h2>
550
551                 <?php yourls_share_box( $longurl, yourls_link($keyword), $title, '', '<h3>' . yourls__( 'Short link' ) . '</h3>', '<h3>' . yourls__( 'Quick Share' ) . '</h3>'); ?>
552
553         </div>
554
555 </div>
556
557
558 <?php yourls_html_footer(); ?>