mostly filebased Content Presentation System
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

187 lines
5.0KB

  1. <?php
  2. /////////////////////////////
  3. // configure installation: //
  4. /////////////////////////////
  5. define("ROOT", "./");
  6. require_once( ROOT.'lib/autoload.php' );
  7. /** @var \Base $f3 */
  8. $f3 = \Base::instance();
  9. $f3->set('DEBUG',3);
  10. $f3->set('CACHE',FALSE);
  11. $f3->set('AUTOLOAD', ROOT.'app/');
  12. $f3->set('UI', implode(';',array(
  13. ROOT.'app/views/',
  14. ROOT.'content/' // content folders can contain .html templates
  15. )));
  16. if(!is_dir($f3->get('TEMP'))) {
  17. mkdir($f3->get('TEMP'));
  18. }
  19. /////////////////////////
  20. // main configuration: //
  21. /////////////////////////
  22. $f3->config( ROOT.'main.cfg' );
  23. if(!setlocale(LC_TIME, 'de_DE.UTF-8')) {
  24. //echo "locale not set";
  25. }
  26. ///////////////////////////////////////////////
  27. // configuration based on configuration file //
  28. ///////////////////////////////////////////////
  29. // set language
  30. $languages = $f3->get('languages');
  31. $f3->set('default_lang', array_shift($languages));
  32. if (in_array(strtolower($f3->get('GET.lang')), $languages)) {
  33. $f3->set('LANG', strtolower($f3->get('GET.lang')));
  34. } else {
  35. $f3->set('LANG', $f3->get('default_lang'));
  36. }
  37. // set content dir
  38. if(array_key_exists($f3->get('LANG'), $f3->get('content'))) {
  39. $content_dir=$f3->get('content.'.$f3->get('LANG'));
  40. } else {
  41. $content_dir=$f3->get('content.'.$f3->get('default_lang'));
  42. }
  43. $f3->set('CONTENT', $content_dir);
  44. function menu_recursion($m,$root="") {
  45. $f3 = \Base::instance();
  46. $out=[];
  47. foreach ($m as $key=>$value) {
  48. $folder = $key == "index" ? "" : "/".$key;
  49. $path = $root.$folder;
  50. if (is_array($value)) {
  51. $submenu=menu_recursion($value,$path);
  52. $out[$path]=$submenu[$path];
  53. unset($submenu[$path]);
  54. $out[$path]['submenu']=$submenu;
  55. } else {
  56. $ex = explode(":=", $value);
  57. if (count($ex) > 1) {
  58. # external link
  59. $href = $ex[1];
  60. } else {
  61. # internal link
  62. $href = $f3->get('SITE_URL').$path;
  63. }
  64. $out[$path]['name']=$ex[0];
  65. $out[$path]['href']=$href;
  66. //print($path." - ".$ex[0]." - ".$href."<br>");
  67. }
  68. }
  69. return $out;
  70. }
  71. function read_menu($menu_name) {
  72. $f3 = \Base::instance();
  73. if(array_key_exists($f3->get('LANG'), $f3->get('nav.'.$menu_name))) {
  74. $menu=$f3->get('nav.'.$menu_name.'.'.$f3->get('LANG'));
  75. } else {
  76. $menu=$f3->get('nav.'.$menu_name.'.'.$f3->get('default_lang'));
  77. }
  78. if (is_array($menu)) {
  79. //var_dump($menu);
  80. //print("<br>");
  81. $menu=menu_recursion($menu);
  82. }
  83. $f3->set('navi.'.$menu_name, $menu);
  84. //var_dump($f3->get('navi.'.$menu_name));
  85. //print("<br>");
  86. }
  87. read_menu("main");
  88. read_menu("footer");
  89. read_menu("network");
  90. read_menu("languages");
  91. // this is needed so the menu can compare the current page with a link to it
  92. // and use this information to determine the active state
  93. $tmp_url = substr($_SERVER['REQUEST_URI'],strlen($f3->get('SITE_URL'))+1);
  94. $url=substr($tmp_url,0,(strpos($tmp_url,'?') === false) ? 999 : strpos($tmp_url,'?'));
  95. $f3->set('url', explode("/", $url));
  96. ///////////////////////////////////
  97. // development utility functions //
  98. ///////////////////////////////////
  99. function debug($Message=".") {
  100. if(DEBUG > 0) {
  101. echo "<br>".$Message;
  102. }
  103. }
  104. ##############################################################################
  105. // this need to go away from here -----------------------------------------
  106. // just to be more tidy etc.
  107. function is_image($path) {
  108. $ex = explode('.',$path);
  109. $ext = array_pop($ex);
  110. return in_array($ext,array( 'jpg', 'jpeg', 'png' ));
  111. }
  112. function pic_cache($in1,$inwidth=360){
  113. $f3 = \Base::instance();
  114. if(is_image($in1)) {
  115. $info = pathinfo($in1);
  116. $fn = basename($in1,'.'.$info['extension']);
  117. $width=$inwidth;
  118. $name = md5($in1.$width);
  119. $name = sprintf("%s%s.png",$fn,$name);
  120. $out ='rsc/img_display/s'.$name;
  121. if(!file_exists($in1)) { $in1='rsc/img/default.png'; }
  122. if(!file_exists($out)) {
  123. $img1 = new Image($in1);
  124. $img1->resize($width);
  125. $f3->write($out,$img1->dump('png',9));
  126. }
  127. } elseif(!strncmp("locallink:",$in1, strlen("locallink:"))) {
  128. $key = substr($in1, strlen("locallink:"));
  129. // localize internal links
  130. if($f3->get('LANG') != 'DE') {
  131. $key .= "?lang=".$f3->get('LANG');
  132. }
  133. $out = $key;
  134. } else {
  135. $out = $in1;
  136. }
  137. return $out;
  138. }
  139. //------------------------------------------------------------------------
  140. ###############################################################################
  141. if ($f3->get("GET.admin")) {
  142. $admin = new \Controller\Admin;
  143. $f3->set('backend',$admin->index());
  144. } else {
  145. $f3->set('backend',false);
  146. }
  147. // HTML preloading of images
  148. // this could also find some better place
  149. $f3->mset(array(
  150. 'cached_images' => array(\Controller\Page::check_folder_for_backgroundimage('content/'))
  151. ));
  152. $f3->run();
  153. echo \Template::instance()->render($f3->get('template'));