helper->url); $parser->setMarkupEscaped(MARKDOWN_ESCAPE_HTML); return $parser->text($text); } /** * Format a file size * * @param integer $size Size in bytes * @param integer $precision Precision * @return string */ public function bytes($size, $precision = 2) { $base = log($size) / log(1024); $suffixes = array('', 'k', 'M', 'G', 'T'); return round(pow(1024, $base - floor($base)), $precision).$suffixes[(int)floor($base)]; } /** * Truncate a long text * * @param string $value Text * @param integer $max_length Max Length * @param string $end Text end * @return string */ public function truncate($value, $max_length = 85, $end = '[...]') { $length = mb_strlen($value); if ($length > $max_length) { return mb_substr($value, 0, $max_length).' '.$end; } return $value; } /** * Return true if needle is contained in the haystack * * @param string $haystack Haystack * @param string $needle Needle * @return boolean */ public function contains($haystack, $needle) { return strpos($haystack, $needle) !== false; } /** * Return a value from a dictionary * * @param mixed $id Key * @param array $listing Dictionary * @param string $default_value Value displayed when the key doesn't exists * @return string */ public function in($id, array $listing, $default_value = '?') { if (isset($listing[$id])) { return $this->helper->e($listing[$id]); } return $default_value; } }