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.

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