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

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