mostly filebased Content Presentation System
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

185 rindas
5.2KB

  1. <?php
  2. /////////////////////////////
  3. // configure installation: //
  4. /////////////////////////////
  5. define("ROOT", "./");
  6. require_once( ROOT.'lib/autoload.php' );
  7. /** @var \Base $f3 */
  8. $f3 = \Base::instance();
  9. $f3->set('DEBUG',3);
  10. $f3->set('CACHE',FALSE);
  11. $f3->set('AUTOLOAD', ROOT.'app/');
  12. $f3->set('UI', implode(';',array(
  13. ROOT.'app/views/',
  14. ROOT.'content/' // content folders can contain .html templates
  15. )));
  16. if(!is_dir($f3->get('TEMP'))) {
  17. mkdir($f3->get('TEMP'));
  18. }
  19. /////////////////////////
  20. // main configuration: //
  21. /////////////////////////
  22. $f3->config( ROOT.'main.cfg' );
  23. if(!setlocale(LC_TIME, 'de_DE.UTF-8')) {
  24. //echo "locale not set";
  25. }
  26. ///////////////////////////////////////////////
  27. // configuration based on configuration file //
  28. ///////////////////////////////////////////////
  29. // set language
  30. $languages = $f3->get('languages');
  31. $f3->set('default_lang', array_shift($languages));
  32. if (in_array(strtolower($f3->get('GET.lang')), $languages)) {
  33. $f3->set('LANG', strtolower($f3->get('GET.lang')));
  34. } else {
  35. $f3->set('LANG', $f3->get('default_lang'));
  36. }
  37. // set content dir
  38. if(array_key_exists($f3->get('LANG'), $f3->get('content'))) {
  39. $content_dir=$f3->get('content.'.$f3->get('LANG'));
  40. } else {
  41. $content_dir=$f3->get('content.'.$f3->get('default_lang'));
  42. }
  43. $f3->set('CONTENT', $content_dir);
  44. // set menu
  45. if(array_key_exists($f3->get('LANG'), $f3->get('nav.main'))) {
  46. $menu=$f3->get('nav.main.'.$f3->get('LANG'));
  47. } else {
  48. $menu=$f3->get('nav.main.'.$f3->get('default_lang'));
  49. }
  50. $f3->set('menuAddHome',$f3->get('nav.main.config.addHome'));
  51. $f3->set('menu', $menu);
  52. // set menu2
  53. if(array_key_exists($f3->get('LANG'), $f3->get('nav.footer'))) {
  54. $menu=$f3->get('nav.footer.'.$f3->get('LANG'));
  55. } else {
  56. $menu=$f3->get('nav.footer.'.$f3->get('default_lang'));
  57. }
  58. $f3->set('menu2AddHome',$f3->get('nav.footer.config.addHome'));
  59. $f3->set('menu2', $menu);
  60. if(array_key_exists($f3->get('LANG'), $f3->get('nav.network'))) {
  61. $menu=$f3->get('nav.network.'.$f3->get('LANG'));
  62. } else {
  63. $menu=$f3->get('nav.network.'.$f3->get('default_lang'));
  64. }
  65. if(is_array($menu)) {
  66. foreach($menu as $k=>$v) {
  67. $ex = explode(": ", $menu[$k]);
  68. $menu[$k] = array(
  69. 'name' => trim($ex[0]),
  70. 'href' => count($ex) > 1 ? $ex[1] : $ex
  71. );
  72. }
  73. }
  74. $f3->set('navi.network._config.addHome', $f3->get('nav.network.config.addHome'));
  75. $f3->set('navi.network', $menu);
  76. if(array_key_exists($f3->get('LANG'), $f3->get('nav.languages'))) {
  77. $menu=$f3->get('nav.languages.'.$f3->get('LANG'));
  78. } else {
  79. $menu=$f3->get('nav.languages.'.$f3->get('default_lang'));
  80. }
  81. if(is_array($menu)){
  82. foreach($menu as $k=>$v) {
  83. $ex = explode(": ", $menu[$k]);
  84. $menu[$k] = array(
  85. 'name' => trim($ex[0]),
  86. 'href' => count($ex) > 1 ? $ex[1] : $ex
  87. );
  88. }
  89. $f3->set('navi.languages._config.addHome', $f3->get('nav.languages.config.addHome'));
  90. $f3->set('navi.languages', $menu);
  91. }
  92. // this is needed so the menu can compare the current page with a link to it
  93. // and use this information to determine the active state
  94. $tmp_url = substr($_SERVER['REQUEST_URI'],strlen($f3->get('SITE_URL'))+1);
  95. $url=substr($tmp_url,0,(strpos($tmp_url,'?') === false) ? 999 : strpos($tmp_url,'?'));
  96. $f3->set('url', explode("/", $url));
  97. ///////////////////////////////////
  98. // development utility functions //
  99. ///////////////////////////////////
  100. function debug($Message=".") {
  101. if(DEBUG > 0) {
  102. echo "<br>".$Message;
  103. }
  104. }
  105. ##############################################################################
  106. // this need to go away from here -----------------------------------------
  107. // just to be more tidy etc.
  108. function is_image($path) {
  109. $ex = explode('.',$path);
  110. $ext = array_pop($ex);
  111. return in_array($ext,array( 'jpg', 'jpeg', 'png' ));
  112. }
  113. function pic_cache($in1,$inwidth=360){
  114. $f3 = \Base::instance();
  115. if(is_image($in1)) {
  116. $info = pathinfo($in1);
  117. $fn = basename($in1,'.'.$info['extension']);
  118. $width=$inwidth;
  119. $name = md5($in1.$width);
  120. $name = sprintf("%s%s.png",$fn,$name);
  121. $out ='rsc/img_display/s'.$name;
  122. if(!file_exists($in1)) { $in1='rsc/img/default.png'; }
  123. if(!file_exists($out)) {
  124. $img1 = new Image($in1);
  125. $img1->resize($width);
  126. $f3->write($out,$img1->dump('png',9));
  127. }
  128. } elseif(!strncmp("locallink:",$in1, strlen("locallink:"))) {
  129. $key = substr($in1, strlen("locallink:"));
  130. // localize internal links
  131. if($f3->get('LANG') != 'DE') {
  132. $key .= "?lang=".$f3->get('LANG');
  133. }
  134. $out = $key;
  135. } else {
  136. $out = $in1;
  137. }
  138. return $out;
  139. }
  140. //------------------------------------------------------------------------
  141. ###############################################################################
  142. if ($f3->get("GET.admin")) {
  143. $admin = new \Controller\Admin;
  144. $f3->set('backend',$admin->index());
  145. } else {
  146. $f3->set('backend',false);
  147. }
  148. // HTML preloading of images
  149. // this could also find some better place
  150. $f3->mset(array(
  151. 'cached_images' => array(\Controller\Page::check_folder_for_backgroundimage('content/'))
  152. ));
  153. $f3->run();
  154. echo \Template::instance()->render($f3->get('template'));