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