mostly filebased Content Presentation System
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. //$url = explode("/", $f3->get('url'));
  47. $out=[];
  48. foreach ($m as $key=>$value) {
  49. $folder = $key == "index" ? "" : "/".$key;
  50. $path = $root.$folder;
  51. if (is_array($value)) {
  52. # submenu
  53. $submenu=menu_recursion($value,$path);
  54. $out[$path]=$submenu[$path];
  55. unset($submenu[$path]);
  56. $out[$path]['submenu']=$submenu;
  57. } else {
  58. $class="";
  59. $ex = explode(":=", $value);
  60. if (count($ex) > 1) {
  61. # external link
  62. $href = $ex[1];
  63. } else {
  64. # internal link
  65. $href = $f3->get('SITE_URL').$path;
  66. $class .= in_array($path,$f3->get('url')) ? ' active' : ' away';
  67. }
  68. $out[$path]['name']=$ex[0];
  69. $out[$path]['href']=$href;
  70. $out[$path]['class']=$class;
  71. }
  72. }
  73. return $out;
  74. }
  75. function read_menu($menu_name) {
  76. $f3 = \Base::instance();
  77. if(array_key_exists($f3->get('LANG'), $f3->get('nav.'.$menu_name))) {
  78. $menu=$f3->get('nav.'.$menu_name.'.'.$f3->get('LANG'));
  79. } else {
  80. $menu=$f3->get('nav.'.$menu_name.'.'.$f3->get('default_lang'));
  81. }
  82. if (is_array($menu)) {
  83. $menu=menu_recursion($menu);
  84. }
  85. $f3->set('navi.'.$menu_name, $menu);
  86. }
  87. // this is needed so the menu can compare the current page with a link to it
  88. // and use this information to determine the active state
  89. $tmp_url = substr($_SERVER['REQUEST_URI'],1);
  90. $url=substr($tmp_url,0,(strpos($tmp_url,'?') === false) ? 999 : strpos($tmp_url,'?'));
  91. $url_ex=explode('/',$url);
  92. $url=array();
  93. for ($i=1;$i<=count($url_ex);$i++) {
  94. $url[]="/".implode("/",array_slice($url_ex,0,$i));
  95. }
  96. $f3->set('url', $url);
  97. $f3->set('level', 1); // this is for templates, to be abl to count nesting
  98. read_menu("main");
  99. read_menu("footer");
  100. read_menu("network");
  101. read_menu("languages");
  102. ///////////////////////////////////
  103. // development utility functions //
  104. ///////////////////////////////////
  105. function debug($Message=".") {
  106. if(DEBUG > 0) {
  107. echo "<br>".$Message;
  108. }
  109. }
  110. ##############################################################################
  111. // this need to go away from here -----------------------------------------
  112. // just to be more tidy etc.
  113. function is_image($path) {
  114. $ex = explode('.',$path);
  115. $ext = array_pop($ex);
  116. return in_array($ext,array( 'jpg', 'jpeg', 'png' ));
  117. }
  118. function pic_cache($in1,$inwidth=360){
  119. $f3 = \Base::instance();
  120. if(is_image($in1)) {
  121. $info = pathinfo($in1);
  122. $fn = basename($in1,'.'.$info['extension']);
  123. $width=$inwidth;
  124. $name = md5($in1.$width);
  125. $name = sprintf("%s%s.png",$fn,$name);
  126. $out ='rsc/img_display/s'.$name;
  127. if(!file_exists($in1)) { $in1='rsc/img/default.png'; }
  128. if(!file_exists($out)) {
  129. $img1 = new Image($in1);
  130. $img1->resize($width);
  131. $f3->write($out,$img1->dump('png',9));
  132. }
  133. } elseif(!strncmp("locallink:",$in1, strlen("locallink:"))) {
  134. $key = substr($in1, strlen("locallink:"));
  135. // localize internal links
  136. if($f3->get('LANG') != 'DE') {
  137. $key .= "?lang=".$f3->get('LANG');
  138. }
  139. $out = $key;
  140. } else {
  141. $out = $in1;
  142. }
  143. return $out;
  144. }
  145. //------------------------------------------------------------------------
  146. ###############################################################################
  147. if ($f3->get("GET.admin")) {
  148. $admin = new \Controller\Admin;
  149. $f3->set('backend',$admin->index());
  150. } else {
  151. $f3->set('backend',false);
  152. }
  153. // HTML preloading of images
  154. // this could also find some better place
  155. $f3->mset(array(
  156. 'cached_images' => array(\Controller\Page::check_folder_for_backgroundimage('content/'))
  157. ));
  158. $f3->run();
  159. echo \Template::instance()->render($f3->get('template'));