Example #1
0
 public function index($args)
 {
     $t = Registry::getInstance()->twig->loadTemplate('form/filepicker.tpl');
     $c = array();
     $localpath = Functions::nz($args['path'], '');
     $mediapath = SITE_PATH . '/media/';
     $dir = new \DirectoryIterator($mediapath . $localpath);
     $picformats = array('png', 'jpg', 'gif');
     $files = array();
     foreach ($dir as $file) {
         if (!$dir->isDot()) {
             $path = URL_PATH . '/media/' . $localpath . $file;
             $f = new \stdClass();
             if (strlen($file) > 4 && in_array(substr($file, -3), $picformats)) {
                 $picture = $path;
             } elseif ($dir->isDir()) {
                 $picture = TEMPLATE_PATH . 'form/pics/folder.png';
             } else {
                 $picture = TEMPLATE_PATH . 'form/pics/file.png';
             }
             $f->path = $localpath;
             $f->picture = $picture;
             $f->name = (string) $file;
             $f->type = $dir->isDir() ? 'dir' : 'file';
             $files[] = $f;
         }
     }
     $c['files'] = $files;
     $t->display($c);
 }
Example #2
0
 public function __construct()
 {
     $this->registry = Registry::getInstance();
     $this->twig = $this->registry->twig;
     $this->twig->addGlobal('controller', $this);
     $tmp = explode('\\', get_class($this));
     $pattern = '/[A-Z]/';
     $to = '_$0';
     $class = preg_replace($pattern, $to, $tmp[2]);
     $name = substr(strtolower($class), 1);
     $controllerend = '_controller';
     if (substr($name, -1 * strlen($controllerend)) == $controllerend) {
         $name = substr($name, 0, -1 * strlen($controllerend));
     }
     $this->base_twig_path = $tmp[0] . '/' . $name . '/';
     $this->base_url = URL_PATH . '/' . $tmp[0] . '/' . str_replace('_', '-', $name) . '/';
 }
Example #3
0
 public function run()
 {
     $this->initDatabase();
     $this->initRoutes();
     $loader = new \Twig_Loader_Filesystem(array(SITE_PATH . '/src/twigs/', SITE_PATH . '/vendor/johsbk/penguin/src/twigs/'));
     $twig = new \Twig_Environment($loader, array('cache' => SITE_PATH . '/cache/', 'debug' => true));
     Registry::getInstance()->twig = $twig;
     try {
         $route = isset($_GET['rt']) ? $_GET['rt'] : '';
         unset($_GET['rt']);
         session_start();
         $twig->addGlobal('URL_PATH', URL_PATH);
         $twig->addGlobal('MEDIA_PATH', MEDIA_PATH);
         $twig->addGlobal('request', $_REQUEST);
         $twig->addGlobal('loggedin', Auth::isLoggedin());
         $twig->addGlobal('current_user', Auth::$profile);
         if ($this->preparetwig) {
             $fn = $this->preparetwig;
             $fn($twig);
         }
         $reg = \penguin\mvc\Registry::getInstance();
         $reg->project = $this;
         $reg->template = new \penguin\mvc\Template();
         $reg->router = new \penguin\mvc\Router();
         $reg->starttime = $reg->endtime = microtime(true);
         ob_start();
         if (!isset(\penguin\mvc\SessionRegistry::getInstance()->locale)) {
             $this->loadLocale();
         }
         $twig->addGlobal('locale', \penguin\mvc\SessionRegistry::getInstance()->locale);
         $reg->router->loader($route);
         ob_end_flush();
     } catch (\Exception $e) {
         $this->handleException($route, $e);
     }
     \penguin\db\DB::logout();
 }
Example #4
0
 public function reverseLookup($view, $args = array())
 {
     if (isset($this->urlCache[$view])) {
         $mypath = $this->urlCache[$view];
     } else {
         $mypath = $this->_reverseLookup(Registry::getInstance()->urls, $view);
         $this->urlCache[$view] = $mypath;
     }
     if (!$mypath) {
         return '';
     }
     $url = URL_PATH . '/';
     foreach ($mypath as $subpath) {
         if ($subpath[0] == '^') {
             $subpath = substr($subpath, 1);
         }
         if (substr($subpath, -1) == '$') {
             $subpath = substr($subpath, 0, -1);
         }
         $url .= $subpath;
     }
     if (count($args) > 0) {
         foreach ($args as $k => $v) {
             $url = preg_replace("/\\(\\?\\<(?<{$k}>\\w+)\\>[^\\)]+\\)/", $v, $url);
         }
     }
     return $url;
 }
Example #5
0
 public function handleException($route, \Exception $e)
 {
     $reg = Registry::getInstance();
     $t = $reg->twig->loadTemplate('error.tpl');
     $c = array();
     $c['route'] = $route;
     $c['type'] = get_class($e);
     $c['msg'] = $e->getMessage();
     $trace = $e->getTrace();
     foreach ($trace as $key => $entry) {
         $file = file_get_contents($entry['file']);
         $lines = explode("\n", $file);
         $start = $entry['line'] - 5;
         $end = $entry['line'] + 5;
         $trace[$key]['lines'] = array();
         if ($start < 0) {
             $start = 0;
         }
         if ($end > count($lines)) {
             $end = count($lines);
         }
         for ($i = $start; $i < $end; ++$i) {
             $trace[$key]['lines'][$i] = str_replace(array("\t", ' '), array('&nbsp;&nbsp;&nbsp;', '&nbsp;'), $lines[$i]);
         }
     }
     $c['trace'] = $trace;
     $out = $t->render($c);
     if (Auth::isLoggedin()) {
         $userid = Auth::$profile->id;
     } else {
         $userid = 0;
     }
     if (!DEBUG) {
         DB::query("INSERT into errorlog(time,message,user_id) values(now(),'" . DB::escape($out) . "',{$userid})");
         if (isset($reg->admin_email)) {
             $ms = new MailService('smtp.gmail.com', 465, '*****@*****.**', 'edderkop');
             $ms->send_mail($reg->admin_email, '*****@*****.**', 'Error occured', '', $out);
         }
     }
     echo $out;
 }