| 1 |
<?php |
| 2 |
|
| 3 |
function file_get_contents_clicky($url) { |
| 4 |
$ch = curl_init(); |
| 5 |
|
| 6 |
curl_setopt($ch, CURLOPT_HEADER, 0); |
| 7 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 8 |
curl_setopt($ch, CURLOPT_URL, $url); |
| 9 |
|
| 10 |
$data = curl_exec($ch); |
| 11 |
curl_close($ch); |
| 12 |
|
| 13 |
return $data; |
| 14 |
} |
| 15 |
|
| 16 |
function ca_tracking_code(){ |
| 17 |
global $current_user; |
| 18 |
|
| 19 |
$custom_tracking=""; |
| 20 |
|
| 21 |
get_currentuserinfo(); |
| 22 |
|
| 23 |
if ($current_user->user_login){ |
| 24 |
|
| 25 |
if ((get_option('ca_track_username')) AND ((get_option('ca_track_email')))){ |
| 26 |
|
| 27 |
$custom_tracking="<script type=\"text/javascript\"> |
| 28 |
var clicky_custom = {}; |
| 29 |
clicky_custom.session = { |
| 30 |
username: '".$current_user->user_login."', |
| 31 |
email: '". $current_user->user_email."' |
| 32 |
}; |
| 33 |
</script>"; |
| 34 |
|
| 35 |
} |
| 36 |
else if (get_option('ca_track_username')){ |
| 37 |
|
| 38 |
$custom_tracking="<script type=\"text/javascript\"> |
| 39 |
var clicky_custom = {}; |
| 40 |
clicky_custom.session = { |
| 41 |
username: '".$current_user->user_login."' |
| 42 |
}; |
| 43 |
</script>"; |
| 44 |
} |
| 45 |
else if (get_option('ca_track_email')){ |
| 46 |
$custom_tracking="<script type=\"text/javascript\"> |
| 47 |
var clicky_custom = {}; |
| 48 |
clicky_custom.session = { |
| 49 |
email: '". $current_user->user_email."' |
| 50 |
}; |
| 51 |
</script>"; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
$main_tracking="<script type=\"text/javascript\"> |
| 56 |
var clicky_site_ids = clicky_site_ids || []; |
| 57 |
clicky_site_ids.push(".get_option('ca_siteid')."); |
| 58 |
(function() { |
| 59 |
var s = document.createElement('script'); |
| 60 |
s.type = 'text/javascript'; |
| 61 |
s.async = true; |
| 62 |
s.src = '//static.getclicky.com/js'; |
| 63 |
( document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0] ).appendChild( s ); |
| 64 |
})(); |
| 65 |
</script>"; |
| 66 |
$video_tracking=""; |
| 67 |
if (get_option('ca_track_youtube')){ |
| 68 |
$video_tracking.="<script src='//static.getclicky.com/inc/javascript/video/youtube.js'></script>"; |
| 69 |
} |
| 70 |
if (get_option('ca_track_html5')){ |
| 71 |
$video_tracking.='<script src="//static.getclicky.com/inc/javascript/video/html.js"></script>'; |
| 72 |
} |
| 73 |
$tracking=$custom_tracking.$main_tracking.$video_tracking; |
| 74 |
|
| 75 |
return $tracking; |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
function ca_validation($item){ |
| 80 |
|
| 81 |
return str_replace(array("'",'"'),'',$item); |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
function ca_clear_cache(){ |
| 86 |
global $wpdb; |
| 87 |
$sqlquery=$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_clicky%%'"); |
| 88 |
$sqlquery=$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_clicky%%'"); |
| 89 |
} |
| 90 |
|
| 91 |
function ca_safe_get($key) { |
| 92 |
if (array_key_exists($key, $_POST)) { |
| 93 |
return $_POST[$key]; |
| 94 |
} |
| 95 |
return false; |
| 96 |
} |
| 97 |
|
| 98 |
// Get Top Pages |
| 99 |
function ca_top_pages($api_url, $siteid, $sitekey, $from){ |
| 100 |
|
| 101 |
$metric = 'type=pages'; |
| 102 |
try{ |
| 103 |
$serial='clicky_qr3'.$from; |
| 104 |
$transient = get_transient($serial); |
| 105 |
if ( empty( $transient ) ){ |
| 106 |
$url = $api_url."site_id=".$siteid."&sitekey=".$sitekey."&".$from."&".$metric."&limit=30&output=php"; |
| 107 |
//echo $url; |
| 108 |
$result = unserialize(file_get_contents($url)); |
| 109 |
set_transient( $serial, $result, get_option('ca_cachetime') ); |
| 110 |
//echo "QR3-Refresh"; |
| 111 |
}else{ |
| 112 |
$result = $transient; |
| 113 |
//echo "QR3-Cache"; |
| 114 |
} |
| 115 |
} |
| 116 |
catch(exception $e) { |
| 117 |
return "<br />ERROR LOG:<br /><br />".$e; |
| 118 |
} |
| 119 |
$i=0; |
| 120 |
foreach( $result as $item ) { |
| 121 |
foreach( $item as $date => $item1 ) { |
| 122 |
if (!$item1) { |
| 123 |
return; |
| 124 |
} |
| 125 |
foreach( $item1 as $item2) { |
| 126 |
$goores[$i][0]=ca_validation($item2['title']); |
| 127 |
$goores[$i][1]=ca_validation($item2['value']); |
| 128 |
$i++; |
| 129 |
|
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
$j=0; |
| 134 |
$ca_statsdata=""; |
| 135 |
for ($j=0;$j<=$i-1;$j++){ |
| 136 |
|
| 137 |
$ca_statsdata.="['".$goores[$j][0]."',".$goores[$j][1]."],"; |
| 138 |
|
| 139 |
} |
| 140 |
return rtrim($ca_statsdata,','); |
| 141 |
} |
| 142 |
|
| 143 |
// Get Top referrers |
| 144 |
function ca_top_referrers($api_url, $siteid, $sitekey, $from){ |
| 145 |
|
| 146 |
$metric = 'type=links-domains'; |
| 147 |
try{ |
| 148 |
$serial='clicky_qr4'.$from; |
| 149 |
$transient = get_transient($serial); |
| 150 |
if ( empty( $transient ) ){ |
| 151 |
$url = $api_url."site_id=".$siteid."&sitekey=".$sitekey."&".$from."&".$metric."&limit=30&output=php"; |
| 152 |
//echo $url; |
| 153 |
$result = unserialize(file_get_contents($url)); |
| 154 |
set_transient( $serial, $result, get_option('ca_cachetime') ); |
| 155 |
//echo "QR4-Refresh"; |
| 156 |
}else{ |
| 157 |
$result = $transient; |
| 158 |
//echo "QR4-Cache"; |
| 159 |
} |
| 160 |
} |
| 161 |
catch(exception $e) { |
| 162 |
return "<br />ERROR LOG:<br /><br />".$e; |
| 163 |
} |
| 164 |
$i=0; |
| 165 |
foreach( $result as $item ) { |
| 166 |
foreach( $item as $date => $item1 ) { |
| 167 |
if (!$item1) { |
| 168 |
return; |
| 169 |
} |
| 170 |
foreach( $item1 as $item2) { |
| 171 |
$goores[$i][0]=ca_validation($item2['title']); |
| 172 |
$goores[$i][1]=ca_validation($item2['value']); |
| 173 |
$i++; |
| 174 |
|
| 175 |
} |
| 176 |
} |
| 177 |
} |
| 178 |
$j=0; |
| 179 |
$ca_statsdata=""; |
| 180 |
for ($j=0;$j<=$i-1;$j++){ |
| 181 |
|
| 182 |
$ca_statsdata.="['".$goores[$j][0]."',".$goores[$j][1]."],"; |
| 183 |
|
| 184 |
} |
| 185 |
|
| 186 |
return rtrim($ca_statsdata,','); |
| 187 |
} |
| 188 |
// Get Top searches |
| 189 |
function ca_top_searches($api_url, $siteid, $sitekey, $from){ |
| 190 |
|
| 191 |
$metric = 'type=searches'; |
| 192 |
try{ |
| 193 |
$serial='clicky_qr5'.$from; |
| 194 |
$transient = get_transient($serial); |
| 195 |
if ( empty( $transient ) ){ |
| 196 |
$url = $api_url."site_id=".$siteid."&sitekey=".$sitekey."&".$from."&".$metric."&limit=30&output=php"; |
| 197 |
//echo $url; |
| 198 |
$result = unserialize(file_get_contents($url)); |
| 199 |
set_transient( $serial, $result, get_option('ca_cachetime') ); |
| 200 |
//echo "QR4-Refresh"; |
| 201 |
}else{ |
| 202 |
$result = $transient; |
| 203 |
//echo "QR4-Cache"; |
| 204 |
} |
| 205 |
} |
| 206 |
catch(exception $e) { |
| 207 |
return "<br />ERROR LOG:<br /><br />".$e; |
| 208 |
} |
| 209 |
$i=0; |
| 210 |
foreach( $result as $item ) { |
| 211 |
foreach( $item as $date => $item1 ) { |
| 212 |
if (!$item1) { |
| 213 |
return; |
| 214 |
} |
| 215 |
foreach( $item1 as $item2) { |
| 216 |
$goores[$i][0]=ca_validation($item2['title']); |
| 217 |
$goores[$i][1]=ca_validation($item2['value']); |
| 218 |
$i++; |
| 219 |
|
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
$j=0; |
| 224 |
$ca_statsdata=""; |
| 225 |
for ($j=0;$j<=$i-1;$j++){ |
| 226 |
|
| 227 |
$ca_statsdata.="['".$goores[$j][0]."',".$goores[$j][1]."],"; |
| 228 |
|
| 229 |
} |
| 230 |
return rtrim($ca_statsdata,','); |
| 231 |
} |
| 232 |
?> |