mostly filebased Content Presentation System
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

index.php 6.5KB

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