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
118 <li class="selected"><a href="#stats"><h2>Traffic statistics</h2></a></li>
\r
119 <li><a href="#location"><h2>Traffic location</h2></a></li>
\r
120 <li><a href="#sources"><h2>Traffic sources</h2></a></li>
\r
121 <li><a href="#share"><h2>Share</h2></a></li>
\r
125 <div id="stats" class="tab first_tab">
\r
126 <h2>Traffic statistics</h2>
\r
128 <h3>Number of hits per day</h3>
\r
130 <p><?php yourls_stats_clicks_line( $dates ); ?></p>
\r
132 <?php $best = yourls_stats_get_best_day( $dates ); ?>
\r
135 <p><strong><?php echo $best['max'];?></strong> hit<?php echo ($best['max'] > 1 ? 's' : ''); ?> on <?php echo date("F j, Y", strtotime($best['day'])); ?>.
\r
136 <a href="" class='details' id="more_clicks">Click for more details</a></p>
\r
137 <ul id="details_clicks" style="display:none">
\r
139 foreach( $dates as $year=>$months ) {
\r
140 foreach( $months as $month=>$days) {
\r
141 foreach( $days as $day=>$visits ) {
\r
142 echo '<li>'.date("F j, Y", strtotime("$year-$month-$day"))." : $visits ".yourls_plural( 'hit', $visits )."</li>\n";
\r
151 <div id="location" class="tab">
\r
152 <h2>Traffic location</h2>
\r
154 <table border="0" cellspacing="2">
\r
157 <h3>Top 5 countries</h3>
\r
158 <?php yourls_stats_pie( $countries, 5 ); ?>
\r
159 <p><a href="" class='details' id="more_countries">Click for more details</a></p>
\r
160 <ul id="details_countries" style="display:none" class="no_bullet">
\r
162 foreach( $countries as $code=>$count ) {
\r
163 echo "<li><img src='".yourls_geo_get_flag( $code )."' /> $code (".yourls_geo_countrycode_to_countryname( $code ).") : $count ".yourls_plural('hit', $count)."</li>\n";
\r
170 <h3>Overall traffic</h3>
\r
171 <?php yourls_stats_countries_map( $countries ); ?>
\r
178 <div id="sources" class="tab">
\r
179 <h2>Traffic Sources</h2>
\r
181 <table border="0" cellspacing="2">
\r
184 <h3>Referrer shares</h3>
\r
186 $referrer_sort['Others'] = count( $referrers );
\r
187 yourls_stats_pie( $referrer_sort, 5, '440x220' );
\r
188 unset( $referrer_sort['Others'] );
\r
191 <ul class="no_bullet">
\r
194 foreach( $referrer_sort as $site => $count ) {
\r
196 echo "<li class='sites_list'><img src='http://$site/favicon.ico'/ width='16'> $site: <strong>$count</strong> <a href='' class='details' id='more_url$i'>(details)</a></li>\n";
\r
197 echo "<ul id='details_url$i' style='display:none'>";
\r
198 foreach( $referrers[$site] as $url => $count ) {
\r
199 echo "<li>"; yourls_html_link($url); echo ": <strong>$count</strong></li>\n";
\r
202 unset( $referrers[$site] );
\r
204 echo "<li id='sites_various'>Various: <strong>". count( $referrers ). "</strong> <a href='' class='details' id='more_various'>(details)</a></li>\n";
\r
205 echo "<ul id='details_various' style='display:none'>";
\r
206 foreach( $referrers as $url ) {
\r
207 echo "<li>"; yourls_html_link(key($url)); echo ": 1</li>\n";
\r
217 <h3>Direct vs Referrer Traffic</h3>
\r
219 $ref_traffic = count($referrer_sort) + count($referrers);
\r
220 yourls_stats_pie( array('Direct'=>$direct, 'Referrers'=> $ref_traffic), 5, '440x220' );
\r
222 <p>Direct traffic: <strong><?php echo $direct; ?></strong> <?php echo yourls_plural( 'hit', $direct ); ?> </p>
\r
223 <p>Referrer traffic: <strong><?php echo $ref_traffic; ?></strong> <?php echo yourls_plural( 'hit', $ref_traffic ); ?> </p>
\r
231 <div id="share" class="tab">
\r
234 <?php yourls_share_box( $longurl, YOURLS_SITE.'/'.$keyword, '', '', '<h3>Short link</h3>', '<h3>Quick Share</h3>'); ?>
\r
241 <?php yourls_html_footer(); ?>