3 require_once( dirname(__FILE__).'/includes/config.php' );
\r
4 require_once( dirname(__FILE__).'/includes/functions-infos.php' );
\r
5 yourls_maybe_require_auth();
\r
7 if ( !isset( $_GET['id'] ) )
\r
8 yourls_redirect( YOURLS_SITE, 307 );
\r
10 // Get basic infos for this shortened URL
\r
11 $keyword = yourls_sanitize_string( $_GET['id'] );
\r
12 $longurl = yourls_get_keyword_longurl( $keyword );
\r
13 $clicks = yourls_get_keyword_clicks( $keyword );
\r
14 $timestamp = yourls_get_keyword_timestamp( $keyword );
\r
15 if ( $longurl === false )
\r
16 yourls_redirect( YOURLS_SITE, 307 );
\r
18 // Fetch all information from the table log
\r
19 $table = YOURLS_DB_TABLE_LOG;
\r
20 $hits = $ydb->get_results( "SELECT `click_time`, `referrer`, `user_agent`, `country_code` FROM `$table` WHERE `shorturl` = '$keyword';" );
\r
22 $referrers = array();
\r
24 $countries = array();
\r
27 // Loop through all results and build list of referrers, countries and hits per day
\r
28 foreach( $hits as $hit ) {
\r
29 extract( (array)$hit );
\r
31 if ( isset( $country_code ) && $country_code ) {
\r
32 if( !array_key_exists( $country_code, $countries ) )
\r
33 $countries[$country_code] = 0;
\r
34 $countries[$country_code]++;
\r
37 if( isset( $referrer ) ) {
\r
38 if ( $referrer == 'direct' ) {
\r
41 $parse = parse_url( $referrer );
\r
42 $host = $parse['host'];
\r
44 if( !array_key_exists( $host, $referrers ) )
\r
45 $referrers[$host] = array( );
\r
46 if( !array_key_exists( $referrer, $referrers[$host] ) )
\r
47 $referrers[$host][$referrer] = 0;
\r
48 $referrers[$host][$referrer]++;
\r
52 if( isset( $click_time ) ) {
\r
53 preg_match('/(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/', $click_time, $matches);
\r
54 list( $temp, $year, $month, $day ) = $matches;
\r
56 if( !array_key_exists( $year, $dates ) )
\r
57 $dates[$year] = array();
\r
58 if( !array_key_exists( $month, $dates[$year] ) )
\r
59 $dates[$year][$month] = array();
\r
60 if( !array_key_exists( $day, $dates[$year][$month] ) )
\r
61 $dates[$year][$month][$day] = 0;
\r
62 $dates[$year][$month][$day]++;
\r
66 // Sort dates, chronologically from [2007][12][24] to [2009][02][19]
\r
68 foreach( $dates as $year=>$months ) {
\r
69 ksort( $dates[$year] );
\r
70 foreach( $months as $month=>$day ) {
\r
71 ksort( $dates[$year][$month] );
\r
75 // Sort countries, most frequent first
\r
77 arsort( $countries );
\r
79 // Sort referrers. $referrer_sort is a array of most frequent domains
\r
80 arsort( $referrers );
\r
81 $referrer_sort = array();
\r
82 foreach( $referrers as $site => $urls ) {
\r
83 if( count($urls) > 1 )
\r
84 $referrer_sort[$site] = array_sum( $urls );
\r
86 arsort($referrer_sort);
\r
90 echo "referrers: "; print_r( $referrers );
\r
91 echo "referrer sort: "; print_r( $referrer_sort );
\r
92 echo "dates: "; print_r( $dates );
\r
93 echo "countries: "; print_r( $countries );
\r
98 yourls_html_head( 'infos' );
\r
102 <a href="<?php echo YOURLS_SITE; ?>/admin/index.php" title="YOURLS"><span>YOURLS</span>: <span>Y</span>our <span>O</span>wn <span>URL</span> <span>S</span>hortener<br/>
\r
103 <img src="<?php echo YOURLS_SITE; ?>/images/yourls-logo.png" alt="YOURLS" title="YOURLS" style="border: 0px;" /></a>
\r
105 <?php if ( yourls_is_private() ) { ?>
\r
106 <p>Your are logged in as: <strong><?php echo YOURLS_USER; ?></strong>. <a href="?mode=logout" title="Logout">Logout</a></p>
\r
109 <h2>Informations</h2>
\r
111 <h3>Short URL: <?php yourls_html_link( YOURLS_SITE."/$keyword" ); ?></h3>
\r
112 <p>Long URL: <?php yourls_html_link( yourls_get_keyword_longurl( $keyword ) ); ?></p>
\r
113 <p>Number of hits since <?php echo date("F j, Y, g:i a", strtotime($timestamp)); ?>: <strong><?php echo $clicks; ?></strong> hit<?php echo ($clicks > 1 ? 's' : ''); ?></p>
\r
115 <h2>Traffic statistics</h2>
\r
117 <p><?php yourls_stats_clicks_bar( $dates ); ?></p>
\r
119 <?php $best = yourls_stats_get_best_day( $dates ); ?>
\r
120 <p>Best day: <strong><?php echo $best['max'];?></strong> hit<?php echo ($best['max'] > 1 ? 's' : ''); ?> on <?php echo date("F j, Y", strtotime($best['day'])); ?>.
\r
121 <a href="#" class='details' onclick="$('#details_clicks').toggle(); return false">Click for more details</a></p>
\r
122 <ul id="details_clicks" style="display:none">
\r
124 foreach( $dates as $year=>$months ) {
\r
125 foreach( $months as $month=>$days) {
\r
126 foreach( $days as $day=>$visits ) {
\r
127 echo '<li>'.date("F j, Y", strtotime("$year-$month-$day"))." : $visits ".yourls_plural( 'hit', $visits )."</li>\n";
\r
134 <h2>Traffic location</h2>
\r
136 <table border="0" cellspacing="2">
\r
139 <p>Top 5 countries. <a href="#" class='details' onclick="$('#details_countries').toggle(); return false">Click for more details</a></p></p>
\r
140 <?php yourls_stats_countries_pie( $countries, 5 ); ?>
\r
141 <ul id="details_countries" style="display:none">
\r
143 foreach( $countries as $code=>$count ) {
\r
144 echo "<li><img src='".yourls_geo_get_flag( $code )."' /> $code (".yourls_geo_countrycode_to_countryname( $code ).") : $count ".yourls_plural('hit', $count)."</li>\n";
\r
151 <p>Overall traffic</p>
\r
152 <?php yourls_stats_countries_map( $countries ); ?>
\r
157 <h2>Traffic sources</h2>
\r
160 <li>Direct: <?php echo $direct; ?></li>
\r
163 foreach( $referrer_sort as $site => $count ) {
\r
165 echo "<li>$site: $count. <a href='#' class='details' onclick='javascript:$(\"#details_url$i\").toggle(); return false;'>Details</a></li>\n";
\r
166 echo "<ul id='details_url$i' style='display:none'>";
\r
167 foreach( $referrers[$site] as $url => $count ) {
\r
168 echo "<li>"; yourls_html_link($url); echo ": $count</li>\n";
\r
171 unset( $referrers[$site] );
\r
173 echo "<li>Various: ". count( $referrers ). " <a href='#' class='details' onclick='javascript:$(\"#details_various\").toggle(); return false;'>Details</a></li>\n";
\r
174 echo "<ul id='details_various' style='display:none'>";
\r
175 foreach( $referrers as $url ) {
\r
176 echo "<li>"; yourls_html_link(key($url)); echo ": 1</li>\n";
\r
185 <?php yourls_html_footer(); ?>