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