You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

9 years ago
9 years ago
  1. <?php
  2. date_default_timezone_set('UTC');
  3. if(array_key_exists('ENV', $_ENV)) {
  4. require(dirname(__FILE__).'/../config.'.$_ENV['ENV'].'.php');
  5. } else {
  6. require(dirname(__FILE__).'/../config.php');
  7. }
  8. ORM::configure('mysql:host=' . Config::$db['host'] . ';dbname=' . Config::$db['database']);
  9. ORM::configure('username', Config::$db['username']);
  10. ORM::configure('password', Config::$db['password']);
  11. function view($template, $data=[]) {
  12. global $templates;
  13. return $templates->render($template, $data);
  14. }
  15. function q() {
  16. static $caterpillar = false;
  17. if(!$caterpillar) {
  18. $logdir = __DIR__.'/../scripts/logs/';
  19. $caterpillar = new Caterpillar('telegraph', '127.0.0.1', 11300, $logdir);
  20. }
  21. return $caterpillar;
  22. }
  23. function random_string($len) {
  24. $charset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  25. $str = '';
  26. $c = strlen($charset)-1;
  27. for($i=0; $i<$len; $i++) {
  28. $str .= $charset[mt_rand(0, $c)];
  29. }
  30. return $str;
  31. }
  32. function display_url($url) {
  33. return preg_replace(['/^https?:\/\//','/\/$/'], '', $url);
  34. }
  35. function session($k, $default=null) {
  36. if(!isset($_SESSION)) return $default;
  37. return array_key_exists($k, $_SESSION) ? $_SESSION[$k] : $default;
  38. }