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