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