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.6KB

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