| 1 | == FireStats API == |
| 2 | '''This is for historical reference, please use the latest version of the [wiki:API]''' |
| 3 | |
| 4 | As of version 1.0.0, FireStats provide several API calls that allow you to access statistics and other FireStats resources.[[BR]] |
| 5 | At the moment, the API is officially supported only under Wordpress. (if you would like support for other platform please submit an enhancment request).[[BR]] |
| 6 | However, if you feel like hacking, the APIs are defined in the file '''php/api.php'''.[[BR]] |
| 7 | |
| 8 | if the API file is included, 'FS_API' is defined. this allow you to test if its safe to call FireStats API functions like this: |
| 9 | |
| 10 | {{{ |
| 11 | #!php |
| 12 | <?php |
| 13 | if (defined('FS_API')) |
| 14 | { |
| 15 | // call API here. |
| 16 | } |
| 17 | ?> |
| 18 | }}} |
| 19 | |
| 20 | The following APIs are supported: |
| 21 | {{{ |
| 22 | #!php |
| 23 | <?php |
| 24 | /* |
| 25 | Returns the number of pages displayed in the specified time period. |
| 26 | days_ago is an optional parameter which specifies how many days ago to start counting. |
| 27 | if days_ago is not specified, the count will begin when you installed FireStats. |
| 28 | */ |
| 29 | function fs_api_get_hit_count($days_ago = NULL); |
| 30 | |
| 31 | /* |
| 32 | Returns the number of unique hits in the specified time period. |
| 33 | days_ago is an optional parameter which specifies how many days ago to start counting. |
| 34 | if days_ago is not specified, the count will begin when you installed FireStats. |
| 35 | */ |
| 36 | function fs_api_get_unique_hit_count($days_ago = NULL); |
| 37 | |
| 38 | /* |
| 39 | Returns image tags of images representing the useragent |
| 40 | 3 Icons may be returned: |
| 41 | * OS Icon |
| 42 | * Browser Icon |
| 43 | * PDA Icon (if the useagent is of a phone) |
| 44 | |
| 45 | To access the user agent of the current user in PHP use $_SERVER['HTTP_USER_AGENT'] |
| 46 | */ |
| 47 | function fs_api_get_browser_and_os_images($useragent); |
| 48 | |
| 49 | |
| 50 | /* |
| 51 | Returns an image tag with the flag of the country this ip_address blonged to. |
| 52 | if unknown, an empty string is returned. |
| 53 | */ |
| 54 | function fs_api_get_country_flag_image($ip_address); |
| 55 | |
| 56 | /* |
| 57 | Returns a two characters country code of the country this ip address is belonged to. |
| 58 | if unknown, false is returned. |
| 59 | */ |
| 60 | function fs_api_get_country_code($ip_address); |
| 61 | |
| 62 | ?> |
| 63 | }}} |
| 64 | |
| 65 | |
| 66 | == Example == |
| 67 | Here is an example usage of the FireStats API. |
| 68 | {{{ |
| 69 | #!php |
| 70 | <?php |
| 71 | if (defined('FS_API')) |
| 72 | { |
| 73 | echo "Hit count ever : ".fs_api_get_hit_count()."<BR/>"; |
| 74 | echo "Hit count in last day : ".fs_api_get_hit_count(1)."<BR/>"; |
| 75 | echo "Your browser and OS icons are :". fs_api_get_browser_and_os_images($_SERVER['HTTP_USER_AGENT'])."<BR/>"; |
| 76 | echo "Your country flag is : " .fs_api_get_country_flag_image($_SERVER['REMOTE_ADDR'])."<BR/>"; |
| 77 | } |
| 78 | ?> |
| 79 | }}} |