render($template, $data); } function q() { static $caterpillar = false; if(!$caterpillar) { $logdir = __DIR__.'/../scripts/logs/'; $caterpillar = new Caterpillar('telegraph', '127.0.0.1', 11300, $logdir); } return $caterpillar; } function random_string($len) { $charset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $str = ''; $c = strlen($charset)-1; for($i=0; $i<$len; $i++) { $str .= $charset[mt_rand(0, $c)]; } return $str; } function display_url($url) { return preg_replace(['/^https?:\/\//','/\/$/'], '', $url); } function session($k, $default=null) { if(!isset($_SESSION)) return $default; return array_key_exists($k, $_SESSION) ? $_SESSION[$k] : $default; }