Upload files to 'includes'
This commit is contained in:
@ -3,8 +3,11 @@
|
||||
/**
|
||||
* Echoes an image tag of Google Charts map from sorted array of 'country_code' => 'number of visits' (sort by DESC)
|
||||
*
|
||||
* @param array $countries Array of 'country_code' => 'number of visits'
|
||||
* @param string $id Optional HTML element ID
|
||||
* @return void
|
||||
*/
|
||||
function yourls_stats_countries_map( $countries, $id = null ) {
|
||||
function yourls_stats_countries_map($countries, $id = null) {
|
||||
|
||||
yourls_do_action( 'pre_stats_countries_map' );
|
||||
|
||||
@ -29,11 +32,17 @@ function yourls_stats_countries_map( $countries, $id = null ) {
|
||||
echo yourls_apply_filter( 'stats_countries_map', $map, $countries, $options, $id );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Echoes an image tag of Google Charts pie from sorted array of 'data' => 'value' (sort by DESC). Optional $limit = (integer) limit list of X first countries, sorted by most visits
|
||||
*
|
||||
* @param array $data Array of 'data' => 'value'
|
||||
* @param int $limit Optional limit list of X first countries
|
||||
* @param $size Optional size of the image
|
||||
* @param $id Optional HTML element ID
|
||||
* @return void
|
||||
*/
|
||||
function yourls_stats_pie( $data, $limit = 10, $size = '340x220', $id = null ) {
|
||||
function yourls_stats_pie($data, $limit = 10, $size = '340x220', $id = null) {
|
||||
|
||||
yourls_do_action( 'pre_stats_pie' );
|
||||
|
||||
@ -80,11 +89,14 @@ function yourls_stats_pie( $data, $limit = 10, $size = '340x220', $id = null ) {
|
||||
echo yourls_apply_filter( 'stats_pie', $pie, $data, $limit, $size, $options, $id );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build a list of all daily values between d1/m1/y1 to d2/m2/y2.
|
||||
*
|
||||
* @param array $dates
|
||||
* @return array[] Array of arrays of days, months, years
|
||||
*/
|
||||
function yourls_build_list_of_days( $dates ) {
|
||||
function yourls_build_list_of_days($dates) {
|
||||
/* Say we have an array like:
|
||||
$dates = array (
|
||||
2009 => array (
|
||||
@ -153,13 +165,17 @@ function yourls_build_list_of_days( $dates ) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Echoes an image tag of Google Charts line graph from array of values (eg 'number of clicks').
|
||||
*
|
||||
* $legend1_list & legend2_list are values used for the 2 x-axis labels. $id is an HTML/JS id
|
||||
*
|
||||
* @param array $values Array of values (eg 'number of clicks')
|
||||
* @param string $id HTML element id
|
||||
* @return void
|
||||
*/
|
||||
function yourls_stats_line( $values, $id = null ) {
|
||||
function yourls_stats_line($values, $id = null) {
|
||||
|
||||
yourls_do_action( 'pre_stats_line' );
|
||||
|
||||
@ -195,20 +211,27 @@ function yourls_stats_line( $values, $id = null ) {
|
||||
echo yourls_apply_filter( 'stats_line', $lineChart, $values, $options, $id );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the number of days in a month. From php.net, used if PHP built without calendar functions
|
||||
* Return the number of days in a month. From php.net.
|
||||
*
|
||||
* @param int $month
|
||||
* @param int $year
|
||||
* @return int
|
||||
*/
|
||||
function yourls_days_in_month( $month, $year ) {
|
||||
function yourls_days_in_month($month, $year) {
|
||||
// calculate number of days in a month
|
||||
return $month == 2 ? ( $year % 4 ? 28 : ( $year % 100 ? 29 : ( $year % 400 ? 28 : 29 ) ) ) : ( ( $month - 1 ) % 7 % 2 ? 30 : 31 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get max value from date array of 'Aug 12, 2012' = '1337'
|
||||
*
|
||||
* @param array $list_of_days
|
||||
* @return array
|
||||
*/
|
||||
function yourls_stats_get_best_day( $list_of_days ) {
|
||||
function yourls_stats_get_best_day($list_of_days) {
|
||||
$max = max( $list_of_days );
|
||||
foreach( $list_of_days as $k=>$v ) {
|
||||
if ( $v == $max )
|
||||
@ -219,8 +242,11 @@ function yourls_stats_get_best_day( $list_of_days ) {
|
||||
/**
|
||||
* Return domain of a URL
|
||||
*
|
||||
* @param string $url
|
||||
* @param bool $include_scheme
|
||||
* @return string
|
||||
*/
|
||||
function yourls_get_domain( $url, $include_scheme = false ) {
|
||||
function yourls_get_domain($url, $include_scheme = false) {
|
||||
$parse = @parse_url( $url ); // Hiding ugly stuff coming from malformed referrer URLs
|
||||
|
||||
// Get host & scheme. Fall back to path if not found.
|
||||
@ -236,19 +262,24 @@ function yourls_get_domain( $url, $include_scheme = false ) {
|
||||
return $host;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return favicon URL
|
||||
*
|
||||
* @param string $url
|
||||
* @return string
|
||||
*/
|
||||
function yourls_get_favicon_url( $url ) {
|
||||
function yourls_get_favicon_url($url) {
|
||||
return yourls_match_current_protocol( '//www.google.com/s2/favicons?domain=' . yourls_get_domain( $url, false ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale array of data from 0 to 100 max
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
function yourls_scale_data( $data ) {
|
||||
function yourls_scale_data($data ) {
|
||||
$max = max( $data );
|
||||
if( $max > 100 ) {
|
||||
foreach( $data as $k=>$v ) {
|
||||
@ -258,11 +289,19 @@ function yourls_scale_data( $data ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tweak granularity of array $array: keep only $grain values. This make less accurate but less messy graphs when too much values. See http://code.google.com/apis/chart/formats.html#granularity
|
||||
* Tweak granularity of array $array: keep only $grain values.
|
||||
*
|
||||
* This make less accurate but less messy graphs when too much values.
|
||||
* See https://developers.google.com/chart/image/docs/gallery/line_charts?hl=en#data-granularity
|
||||
*
|
||||
* @param array $array
|
||||
* @param int $grain
|
||||
* @param bool $preserve_max
|
||||
* @return array
|
||||
*/
|
||||
function yourls_array_granularity( $array, $grain = 100, $preserve_max = true ) {
|
||||
function yourls_array_granularity($array, $grain = 100, $preserve_max = true) {
|
||||
if ( count( $array ) > $grain ) {
|
||||
$max = max( $array );
|
||||
$step = intval( count( $array ) / $grain );
|
||||
@ -286,8 +325,10 @@ function yourls_array_granularity( $array, $grain = 100, $preserve_max = true )
|
||||
/**
|
||||
* Transform data array to data table for Google API
|
||||
*
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
function yourls_google_array_to_data_table( $data ){
|
||||
function yourls_google_array_to_data_table($data){
|
||||
$str = "var data = google.visualization.arrayToDataTable([\n";
|
||||
foreach( $data as $label => $values ){
|
||||
if( !is_array( $values ) ) {
|
||||
@ -310,8 +351,13 @@ function yourls_google_array_to_data_table( $data ){
|
||||
/**
|
||||
* Return javascript code that will display the Google Chart
|
||||
*
|
||||
* @param string $graph_type
|
||||
* @param string $data
|
||||
* @param var $options
|
||||
* @param string $id
|
||||
* @return string
|
||||
*/
|
||||
function yourls_google_viz_code( $graph_type, $data, $options, $id ) {
|
||||
function yourls_google_viz_code($graph_type, $data, $options, $id ) {
|
||||
$function_name = 'yourls_graph' . $id;
|
||||
$code = "\n<script id=\"$function_name\" type=\"text/javascript\">\n";
|
||||
$code .= "function $function_name() { \n";
|
||||
@ -336,4 +382,3 @@ function yourls_google_viz_code( $graph_type, $data, $options, $id ) {
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user