mostly filebased Content Presentation System
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

179 行
5.1KB

  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. /////////////////////////
  17. // main configuration: //
  18. /////////////////////////
  19. $f3->config( ROOT.'main.cfg' );
  20. if(!setlocale(LC_TIME, 'de_DE.UTF-8')) {
  21. //echo "locale not set";
  22. }
  23. ///////////////////////////////////////////////
  24. // configuration based on configuration file //
  25. ///////////////////////////////////////////////
  26. // set language
  27. $languages = $f3->get('languages');
  28. $f3->set('default_lang', array_shift($languages));
  29. if (in_array(strtolower($f3->get('GET.lang')), $languages)) {
  30. $f3->set('LANG', strtolower($f3->get('GET.lang')));
  31. } else {
  32. $f3->set('LANG', $f3->get('default_lang'));
  33. }
  34. // set content dir
  35. if(array_key_exists($f3->get('LANG'), $f3->get('content'))) {
  36. $content_dir=$f3->get('content.'.$f3->get('LANG'));
  37. } else {
  38. $content_dir=$f3->get('content.'.$f3->get('default_lang'));
  39. }
  40. $f3->set('CONTENT', $content_dir);
  41. // set menu
  42. if(array_key_exists($f3->get('LANG'), $f3->get('nav.main'))) {
  43. $menu=$f3->get('nav.main.'.$f3->get('LANG'));
  44. } else {
  45. $menu=$f3->get('nav.main.'.$f3->get('default_lang'));
  46. }
  47. $f3->set('menuAddHome',$f3->get('nav.main.config.addHome'));
  48. $f3->set('menu', $menu);
  49. // set menu2
  50. if(array_key_exists($f3->get('LANG'), $f3->get('nav.footer'))) {
  51. $menu=$f3->get('nav.footer.'.$f3->get('LANG'));
  52. } else {
  53. $menu=$f3->get('nav.footer.'.$f3->get('default_lang'));
  54. }
  55. $f3->set('menu2AddHome',$f3->get('nav.footer.config.addHome'));
  56. $f3->set('menu2', $menu);
  57. if(array_key_exists($f3->get('LANG'), $f3->get('nav.network'))) {
  58. $menu=$f3->get('nav.network.'.$f3->get('LANG'));
  59. } else {
  60. $menu=$f3->get('nav.network.'.$f3->get('default_lang'));
  61. }
  62. foreach($menu as $k=>$v) {
  63. $ex = explode(": ", $menu[$k]);
  64. $menu[$k] = array(
  65. 'name' => trim($ex[0]),
  66. 'href' => count($ex) > 1 ? $ex[1] : $ex
  67. );
  68. }
  69. $f3->set('navi.network._config.addHome', $f3->get('nav.network.config.addHome'));
  70. $f3->set('navi.network', $menu);
  71. if(array_key_exists($f3->get('LANG'), $f3->get('nav.languages'))) {
  72. $menu=$f3->get('nav.languages.'.$f3->get('LANG'));
  73. } else {
  74. $menu=$f3->get('nav.languages.'.$f3->get('default_lang'));
  75. }
  76. if(is_array($menu)){
  77. foreach($menu as $k=>$v) {
  78. $ex = explode(": ", $menu[$k]);
  79. $menu[$k] = array(
  80. 'name' => trim($ex[0]),
  81. 'href' => count($ex) > 1 ? $ex[1] : $ex
  82. );
  83. }
  84. $f3->set('navi.languages._config.addHome', $f3->get('nav.languages.config.addHome'));
  85. $f3->set('navi.languages', $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'],strlen($f3->get('SITE_URL'))+1);
  90. $url=substr($tmp_url,0,(strpos($tmp_url,'?') === false) ? 999 : strpos($tmp_url,'?'));
  91. $f3->set('url', explode("/", $url));
  92. ///////////////////////////////////
  93. // development utility functions //
  94. ///////////////////////////////////
  95. function debug($Message=".") {
  96. if(DEBUG > 0) {
  97. echo "<br>".$Message;
  98. }
  99. }
  100. ##############################################################################
  101. // this need to go away from here -----------------------------------------
  102. // just to be more tidy etc.
  103. function is_image($path) {
  104. $ex = explode('.',$path);
  105. $ext = array_pop($ex);
  106. return in_array($ext,array( 'jpg', 'jpeg', 'png' ));
  107. }
  108. function pic_cache($in1,$inwidth=360){
  109. $f3 = \Base::instance();
  110. if(is_image($in1)) {
  111. $info = pathinfo($in1);
  112. $fn = basename($in1,'.'.$info['extension']);
  113. $width=$inwidth;
  114. $name = md5($in1.$width);
  115. $name = sprintf("%s%s.png",$fn,$name);
  116. $out ='rsc/img_display/s'.$name;
  117. if(!file_exists($in1)) { $in1='rsc/img/default.png'; }
  118. if(!file_exists($out)) {
  119. $img1 = new Image($in1);
  120. $img1->resize($width);
  121. $f3->write($out,$img1->dump('png',9));
  122. }
  123. } elseif(!strncmp("locallink:",$in1, strlen("locallink:"))) {
  124. $key = substr($in1, strlen("locallink:"));
  125. // localize internal links
  126. if($f3->get('LANG') != 'DE') {
  127. $key .= "?lang=".$f3->get('LANG');
  128. }
  129. $out = $key;
  130. } else {
  131. $out = $in1;
  132. }
  133. return $out;
  134. }
  135. //------------------------------------------------------------------------
  136. ###############################################################################
  137. if ($f3->get("GET.admin")) {
  138. $admin = new \Controller\Admin;
  139. $f3->set('backend',$admin->index());
  140. } else {
  141. $f3->set('backend',false);
  142. }
  143. // HTML preloading of images
  144. // this could also find some better place
  145. $f3->mset(array(
  146. 'cached_images' => array(\Controller\Page::check_folder_for_backgroundimage('content/'))
  147. ));
  148. $f3->run();
  149. echo \Template::instance()->render($f3->get('template'));