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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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.$f3->get('templatepath'),
  83. ROOT.'app/views/',
  84. ROOT.$f3->get('CONTENT_BASE') // content folders can contain .html templates
  85. )));
  86. function menu_recursion($m,$root="") {
  87. $f3 = \Base::instance();
  88. //$url = explode("/", $f3->get('url'));
  89. $out=[];
  90. foreach ($m as $key=>$value) {
  91. $folder = $key == "index" ? "" : "/".$key;
  92. $path = $root.$folder;
  93. if (is_array($value)) {
  94. # submenu
  95. $submenu=menu_recursion($value,$path);
  96. $out[$path]=$submenu[$path];
  97. unset($submenu[$path]);
  98. $out[$path]['submenu']=$submenu;
  99. } else {
  100. $class="";
  101. $ex = explode(":=", $value);
  102. if (count($ex) > 1) {
  103. # external link
  104. $href = trim($ex[1]);
  105. if(!strncmp($href,"?",1)) {
  106. // if 'external link' starts with '?'
  107. // probably it is language switch
  108. foreach (explode("&",substr($href,1)) as $option) {
  109. if(!strncmp($option, "lang=", 5) !== FALSE) {
  110. $value = substr( $option, 5);
  111. $class .= ($value == $f3->get('LANG')) ? ' active' : ' away';
  112. }
  113. }
  114. }
  115. } else {
  116. # internal link
  117. $href = $f3->get('SITE_URL').$path;
  118. $href .= count($f3->get('GET')) ? "?".query_string_from_array($f3->get('GET')):"";
  119. $class .= in_array($path,$f3->get('url')) ? ' active' : ' away';
  120. }
  121. $out[$path]['name']=$ex[0];
  122. $out[$path]['href']=$href;
  123. $out[$path]['class']=$class;
  124. }
  125. }
  126. return $out;
  127. }
  128. function read_menu($menu_name) {
  129. $f3 = \Base::instance();
  130. if(array_key_exists($f3->get('LANG'), $f3->get('nav.'.$menu_name))) {
  131. $menu=$f3->get('nav.'.$menu_name.'.'.$f3->get('LANG'));
  132. } else {
  133. $menu=$f3->get('nav.'.$menu_name.'.'.$f3->get('default_lang'));
  134. }
  135. if (is_array($menu)) {
  136. $menu=menu_recursion($menu);
  137. }
  138. $f3->set('navi.'.$menu_name, $menu);
  139. }
  140. // this is needed so the menu can compare the current page with a link to it
  141. // and use this information to determine the active state
  142. $tmp_url = substr($_SERVER['REQUEST_URI'],1);
  143. $url=substr($tmp_url,0,(strpos($tmp_url,'?') === false) ? 999 : strpos($tmp_url,'?'));
  144. $url_ex=explode('/',$url);
  145. $url=array();
  146. for ($i=1;$i<=count($url_ex);$i++) {
  147. $url[]="/".implode("/",array_slice($url_ex,0,$i));
  148. }
  149. $f3->set('url', $url);
  150. $f3->set('is_home', in_array($url[0],["/","/home"]));
  151. $f3->set('level', 1); // this is for templates, to be abl to count nesting
  152. if (is_array($f3->get('nav'))) {
  153. foreach ($f3->get('nav') as $k=>$v) {
  154. read_menu($k);
  155. }
  156. }
  157. ///////////////////////////////////
  158. // development utility functions //
  159. ///////////////////////////////////
  160. ##############################################################################
  161. // this need to go away from here -----------------------------------------
  162. // just to be more tidy etc.
  163. function is_image($path) {
  164. $ex = explode('.',$path);
  165. $ext = array_pop($ex);
  166. return in_array($ext,array( 'jpg', 'jpeg', 'png' ));
  167. }
  168. function pic_cache($in1,$inwidth=360){
  169. $f3 = \Base::instance();
  170. if(is_image($in1)) {
  171. $info = pathinfo($in1);
  172. $fn = basename($in1,'.'.$info['extension']);
  173. $width=$inwidth;
  174. $name = md5($in1.$width);
  175. $name = sprintf("%s%s.png",$fn,$name);
  176. $out ='rsc/img_display/s'.$name;
  177. if(!file_exists($in1)) { $in1='rsc/img/default.png'; }
  178. if(!file_exists($out)) {
  179. $img1 = new Image($in1);
  180. $img1->resize($width);
  181. $f3->write($out,$img1->dump('png',9));
  182. }
  183. } elseif(!strncmp("locallink:",$in1, strlen("locallink:"))) {
  184. $key = substr($in1, strlen("locallink:"));
  185. // localize internal links
  186. if($f3->get('LANG') != 'DE') {
  187. $key .= "?lang=".$f3->get('LANG');
  188. }
  189. $out = $key;
  190. } else {
  191. $out = $in1;
  192. }
  193. return $out;
  194. }
  195. //------------------------------------------------------------------------
  196. ###############################################################################
  197. // HTML preloading of images
  198. // this could also find some better place
  199. $f3->mset(array(
  200. 'cached_images' => array(\Controller\Page::check_folder_for_backgroundimage($f3->get('CONTENT_BASE'))
  201. )
  202. ));
  203. debug("before run fatfree");
  204. $bbb = new \Controller\Cart();
  205. $bbb->index();
  206. $f3->run();
  207. if ($f3->get("GET.admin")) {
  208. $admin = new \Controller\Admin;
  209. $f3->set('backend',$admin->index());
  210. } else {
  211. $f3->set('backend',false);
  212. }
  213. echo \Template::instance()->render($f3->get('template'));