|
- <?php
-
- function debug($message) {
- $f3 = \Base::instance();
- if ($f3->get('DEBUG')) {
- printf("<hr>%s:<br>Memory Usage: %s <br>", $message, memory_get_usage());
- }
- }
-
-
-
-
- define("ROOT", "./");
- require_once( ROOT.'lib/autoload.php' );
- error_reporting(0);
- ini_set("log_errors", 1);
- ini_set("error_log", "php-error.log");
-
-
- $f3 = \Base::instance();
- $f3->set('DEBUG', 0);
- $f3->set('CACHE', FALSE);
- $f3->set('AUTOLOAD', ROOT.'app/');
- $f3->set('UI', implode(';', array(
- ROOT.'app/views/',
- ROOT.'content/'
- )));
-
- if (!is_dir($f3->get('TEMP'))) {
- mkdir($f3->get('TEMP'));
- }
-
- function query_string_from_array($in){
- $out = [];
- foreach ($in as $key=>$value) {
- $out[] = sprintf("%s=%s", $key, $value);
- }
- return implode("&", $out);
- }
-
-
-
-
- debug("before read config");
- $f3->config( ROOT.'routes.cfg' );
- $f3->config( ROOT.'main.cfg' );
- if(!setlocale(LC_TIME, 'de_DE.UTF-8')) {
-
-
- }
-
-
-
-
-
- if(is_array($f3->get('reroutes'))) {
- foreach ($f3->get('reroutes') as $source=>$dest) {
- $f3->redirect('GET '.$source, $dest);
- }
- }
-
-
- $languages = $f3->get('languages');
- $f3->set('default_lang', array_shift($languages));
- if (in_array(strtolower($f3->get('GET.lang')), $languages)) {
- $f3->set('LANG', strtolower($f3->get('GET.lang')));
- } else {
- $f3->set('LANG', $f3->get('default_lang'));
- }
-
- if(array_key_exists($f3->get('LANG'), $f3->get('content'))) {
- $content_dir=$f3->get('content.'.$f3->get('LANG'));
- } else {
- $content_dir=$f3->get('content.'.$f3->get('default_lang'));
- }
- $f3->set('CONTENT', $content_dir);
-
-
- function menu_recursion($m,$root="") {
- $f3 = \Base::instance();
-
- $out=[];
- foreach ($m as $key=>$value) {
- $folder = $key == "index" ? "" : "/".$key;
- $path = $root.$folder;
-
- if (is_array($value)) {
-
- $submenu=menu_recursion($value,$path);
- $out[$path]=$submenu[$path];
- unset($submenu[$path]);
- $out[$path]['submenu']=$submenu;
- } else {
- $class="";
- $ex = explode(":=", $value);
- if (count($ex) > 1) {
-
- $href = trim($ex[1]);
-
- if(!strncmp($href,"?",1)) {
-
-
- foreach (explode("&",substr($href,1)) as $option) {
- if(!strncmp($option, "lang=", 5) !== FALSE) {
- $value = substr( $option, 5);
- $class .= ($value == $f3->get('LANG')) ? ' active' : ' away';
- }
- }
- }
-
- } else {
-
- $href = $f3->get('SITE_URL').$path;
- $href .= count($f3->get('GET')) ? "?".query_string_from_array($f3->get('GET')):"";
- $class .= in_array($path,$f3->get('url')) ? ' active' : ' away';
- }
- $out[$path]['name']=$ex[0];
- $out[$path]['href']=$href;
- $out[$path]['class']=$class;
- }
- }
- return $out;
- }
- function read_menu($menu_name) {
- $f3 = \Base::instance();
-
- if(array_key_exists($f3->get('LANG'), $f3->get('nav.'.$menu_name))) {
- $menu=$f3->get('nav.'.$menu_name.'.'.$f3->get('LANG'));
- } else {
- $menu=$f3->get('nav.'.$menu_name.'.'.$f3->get('default_lang'));
- }
-
- if (is_array($menu)) {
- $menu=menu_recursion($menu);
- }
-
- $f3->set('navi.'.$menu_name, $menu);
- }
-
-
-
- $tmp_url = substr($_SERVER['REQUEST_URI'],1);
- $url=substr($tmp_url,0,(strpos($tmp_url,'?') === false) ? 999 : strpos($tmp_url,'?'));
- $url_ex=explode('/',$url);
- $url=array();
- for ($i=1;$i<=count($url_ex);$i++) {
- $url[]="/".implode("/",array_slice($url_ex,0,$i));
- }
- $f3->set('url', $url);
- $f3->set('is_home', in_array($url[0],["/","/home"]));
- $f3->set('level', 1);
-
- if (is_array($f3->get('nav'))) {
- foreach ($f3->get('nav') as $k=>$v) {
- read_menu($k);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- function is_image($path) {
- $ex = explode('.',$path);
- $ext = array_pop($ex);
- return in_array($ext,array( 'jpg', 'jpeg', 'png' ));
- }
- function pic_cache($in1,$inwidth=360){
- $f3 = \Base::instance();
- if(is_image($in1)) {
- $info = pathinfo($in1);
- $fn = basename($in1,'.'.$info['extension']);
- $width=$inwidth;
- $name = md5($in1.$width);
-
- $name = sprintf("%s%s.png",$fn,$name);
-
- $out ='rsc/img_display/s'.$name;
-
- if(!file_exists($in1)) { $in1='rsc/img/default.png'; }
-
- if(!file_exists($out)) {
- $img1 = new Image($in1);
- $img1->resize($width);
- $f3->write($out,$img1->dump('png',9));
- }
- } elseif(!strncmp("locallink:",$in1, strlen("locallink:"))) {
- $key = substr($in1, strlen("locallink:"));
-
- if($f3->get('LANG') != 'DE') {
- $key .= "?lang=".$f3->get('LANG');
- }
- $out = $key;
- } else {
- $out = $in1;
- }
- return $out;
- }
-
-
-
- if ($f3->get("GET.admin")) {
- $admin = new \Controller\Admin;
- $f3->set('backend',$admin->index());
- } else {
- $f3->set('backend',false);
- }
-
-
-
- $f3->mset(array(
- 'cached_images' => array(\Controller\Page::check_folder_for_backgroundimage('content/'))
- ));
-
-
- debug("before run fatfree");
- $f3->run();
- echo \Template::instance()->render($f3->get('template'));
|