imported>Eupeodes (→Code) |
m (Replacing http://wiki.xkcd.com/geohashing/User:' with https://geohashing.site/geohashing/User:') |
||
(4 intermediate revisions by one other user not shown) | |||
Line 7: | Line 7: | ||
For calculating the number of expeditions the arrows of Aperfectbot are used. So the number of green arrows is the number of successes and the number of red and green arrows is the total. Data is cached for 24 hours, so it can take some time before an image is updated. | For calculating the number of expeditions the arrows of Aperfectbot are used. So the number of green arrows is the number of successes and the number of red and green arrows is the total. Data is cached for 24 hours, so it can take some time before an image is updated. | ||
− | + | Username and text need to be url encoded | |
− | + | Example: http://geohashing.info/statbar/Eupeodes%2FExpeditions/Geohashing%20stats | |
− | + | ===Code of old version=== | |
+ | |||
+ | directory cache is needed in same dir as index.php | ||
File: index.php | File: index.php | ||
Line 25: | Line 27: | ||
if(!file_exists($file) || filemtime($file) < time()-86400){ | if(!file_exists($file) || filemtime($file) < time()-86400){ | ||
− | $base_url = ' | + | $base_url = 'https://geohashing.site/geohashing/User:'; |
$url = $base_url.$user; | $url = $base_url.$user; | ||
$data = file_get_contents($url); | $data = file_get_contents($url); | ||
Line 44: | Line 46: | ||
echo file_get_contents($file); | echo file_get_contents($file); | ||
?> | ?> | ||
+ | [[Category:Eupeodes]] |
Latest revision as of 12:47, 19 February 2020
For geocaching a nice statistics bar is available. On my site I used this but also wanted one for geohashing. Since I don't know of any other bar I wrote one myself. The bar needs 2 parameters: user: The page where the expedition list is, can be just your username but can also be user/Expeditions text: A line of text displayed at the top.
For calculating the number of expeditions the arrows of Aperfectbot are used. So the number of green arrows is the number of successes and the number of red and green arrows is the total. Data is cached for 24 hours, so it can take some time before an image is updated.
Username and text need to be url encoded
Example: http://geohashing.info/statbar/Eupeodes%2FExpeditions/Geohashing%20stats
Code of old version
directory cache is needed in same dir as index.php
File: index.php
<?php $user = $_GET['user']; $text = $_GET['text']; $file = 'cache/'.urlencode($user.$text).".png"; header("Content-type: image/png"); header("Cache-Control: max-age=86400"); // HTTP/1.1 if(!file_exists($file) || filemtime($file) < time()-86400){ $base_url = 'https://geohashing.site/geohashing/User:'; $url = $base_url.$user; $data = file_get_contents($url); $success = substr_count($data, 'alt="Arrow2.png"'); $fail = substr_count($data, 'alt="Arrow4.png"'); $count = $success+$fail; $img = imagecreatetruecolor(200,50); $img2 = imagecreatefrompng('icon.png'); $bg_color = imagecolorallocate($img, 255,255,255); imagefilledrectangle($img,1,1,198,48,$bg_color); imagecopyresampled($img, $img2, 1,0,0,0,50,49,135,135); $text_color = imagecolorallocate($img, 0,0,0); imagestring($img, 3, 55, 3, $text, $text_color); imagestring($img, 2, 55, 18, "Attempts: ".$count, $text_color); imagestring($img, 2, 55, 32, "Successes: ".$success, $text_color); imagepng($img, $file); } echo file_get_contents($file); ?>