= $ambinfo_stale_time) { $color = $ambinfo_stale_color; } else { if ($age_in_millis == 0) { $div = 1; } else { $div = $ambinfo_stale_time / ($ambinfo_stale_time - $age_in_millis); } $red = _get_aged_color_part('red', $div); $green = _get_aged_color_part('green', $div); $blue = _get_aged_color_part('blue', $div); $color = strtoupper("#"._ambinfo_to_hex($red)._ambinfo_to_hex($green)._ambinfo_to_hex($blue)); } return $color; } /** * private function, get a single value for an rgb part */ function _get_aged_color_part( $color_part, $div ) { global $ambinfo_fresh_color, $ambinfo_stale_color; $fresh = _ambinfo_get_color_part( $color_part, $ambinfo_fresh_color ); $stale = _ambinfo_get_color_part( $color_part, $ambinfo_stale_color ); return abs($fresh - (abs($fresh - $stale) - (abs($fresh - $stale) / $div))); } /** *Take in a decimal number and return a 2 digit hex number. */ function _ambinfo_to_hex( $color ) { $result = dechex($color); if( strlen($result) == 1) { $result = "0" . $result; } return $result; } /** * Gets the RGB part of the given color. Format can be '#rrggbb', 'rrggbb', '#rgb', 'rgb' */ function _ambinfo_get_color_part($rgb, $color) { if( preg_match("/#.*/", $color)) { $color = substr( $color, 1 ); } if( strlen($color) == 3 ) { $color = preg_replace( "/(.)(.)(.)/", "$1$1$2$2$3$3", $color); } switch ($rgb) { case 'red': $hex = substr($color, 0, 2); break; case 'green': $hex = substr($color, 2, 2); break; case 'blue': $hex = substr($color, 4, 2); break; default: $hex = "ff"; break; } return hexdec($hex); } /** * Get the post id for the post with the atest time. */ function _ambinfo_get_newest_post_time($post_id) { global $wpdb, $tableposts; if( $post_id == "") { return $wpdb->get_var("SELECT UNIX_TIMESTAMP(post_modified) FROM $tableposts ORDER BY post_date DESC LIMIT 1"); } else { return $wpdb->get_var("SELECT UNIX_TIMESTAMP(post_modified) FROM $tableposts WHERE ID = $post_id"); } } ?>