1 year //-------------------------------------------- $unit = "year"; $amount = floor($delta / 31536000); } $suffix = ($amount > 1) ? 's' : ''; if($delta > 300) { //-------------------------------------------- // If this was posted over 5 minutes ago //-------------------------------------------- $ret = "$amount $unit$suffix ago"; } else { //-------------------------------------------- // This was created within 3 minutes //-------------------------------------------- $ret = "just now"; } return $ret; } //-------------------------------------------- // Replace spaces and other symbols with underscores or // alphabetical letters for when they are put into the // URL's. (for readability) //-------------------------------------------- function k4_us($str) { $str = strtr($str, 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ/\\','AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn__'); $str = preg_replace('~[^a-z0-9_\-]+~i', '_', $str); // ,.?!:\(\)\[\]#@\$%\^\/\\\'"\~`= //$str = preg_replace('~(\s|\r|\n|\t)+~', '_', $str); return str_replace('__', '_', $str); } //-------------------------------------------- // Format a number with commas, e.g.: 1,024 function k4_numfmt($num) { return number_format($num); } //-------------------------------------------- // Truncate a string to the nearest space //-------------------------------------------- function str_truncate(&$str, $length = 200) { $len = strlen_utf($str); //-------------------------------------------- // Make sure that we don't waste time :P //-------------------------------------------- if($len > $length) { //-------------------------------------------- // Look for the first space after the $length cutoff //-------------------------------------------- $s = strpos($str, " ", $length); if($s !== FALSE) { $str = substr_utf($str, 0, $s); } else { //-------------------------------------------- // Reverse the string and look for a space before // the $length cutoff. //-------------------------------------------- $sstr = strrev($str); $fs = strpos($sstr, " ", $len - $length); //-------------------------------------------- // If we find a space, go there, otherwise, do the // normal, direct cutoff. //-------------------------------------------- if($fs !== FALSE) { $str = substr_utf($str, 0, $length - $fs); } else { $str = substr_utf($str, 0, $length); } } //-------------------------------------------- // So we've cut the string, append '...' to it to let // people know it continues. //-------------------------------------------- $str = $str ."..."; } return $str; } //-------------------------------------------- // Truncate a string to the nearest space around 300 // characters and strip all HTML tags from the string // so that nothing in the rest of the page is broken. //-------------------------------------------- function k4_excerpt($str) { return str_truncate(strip_tags($str), 300); } function k4_excerpt_small($str) { return str_truncate(strip_tags($str), 150); } function k4_excerpt_mini($str) { return str_truncate(strip_tags($str), 200); } function k4_name_short($str) { return str_truncate($str, 40); } function k4_rem_spaces($str) { return str_replace(" ", " ", $str);; } //-------------------------------------------- // Clean a string. //-------------------------------------------- function k4_clean_string($str) { return htmlentities($str, ENT_QUOTES, K4_CHARSET); } ?>