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