mostly filebased Content Presentation System
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

218 lines
7.4KB

  1. <?php
  2. namespace Controller;
  3. class Page {
  4. public static $keyword = "page"; // variable in URL (query string)
  5. function index(\Base $f3, $params) {
  6. /////////////////////////////
  7. // what page are we watching?
  8. $page = $params[self::$keyword];
  9. $f3->set('page', $page);
  10. $f3->set('bodyClass',"page-$page");
  11. switch ($page) {
  12. case 'home':
  13. default:
  14. $f3->mset(array(
  15. 'template'=>'tpl/index.html',
  16. 'templateContent'=>'maincontent.html'
  17. ));
  18. self::folder2();
  19. break;
  20. }
  21. }
  22. ////////////////
  23. // interfaces //
  24. ////////////////
  25. function home(\Base $f3) {
  26. self::index($f3, array('page'=>'home'));
  27. }
  28. function secondLevel(\Base $f3,$params) {
  29. self::index($f3, array('page'=>$params['level1']."/".$params['level2']));
  30. }
  31. function thirdLevel(\Base $f3,$params) {
  32. self::index($f3, array('page'=>$params['level1']."/".$params['level2']."/".$params['level3']));
  33. }
  34. function fourthLevel(\Base $f3,$params) {
  35. self::index($f3, array('page'=>$params['level1']."/".$params['level2']."/".$params['level3']."/".$params['level4']));
  36. }
  37. //////////////////
  38. // main program //
  39. //////////////////
  40. function folder2() {
  41. $f3 = \Base::instance();
  42. $page = $f3->get('page');
  43. $f3->set('current_page_folder', $f3->get('CONTENT').$page."/");
  44. $folder = new \Modules\FilesInFolders(
  45. $f3->get('current_page_folder'),
  46. array(
  47. 'content'=>array(
  48. 'secondary'=>'secondary',
  49. 'zzz'=>'hidden',
  50. 'unpublish'=>'hidden'
  51. ),
  52. 'keyfiles'=>array(
  53. 'banner'=>array(
  54. 'until'=>$f3->get("CONTENT"),
  55. 'type'=>'pic'
  56. ),
  57. 'background'=>array(
  58. 'until'=>$f3->get("CONTENT"),
  59. 'type'=>'pic'
  60. ),
  61. 'colors'=>array(
  62. 'until'=>$f3->get("CONTENT"),
  63. 'type'=>'txt'
  64. )
  65. )
  66. )
  67. );
  68. $folder->prepare_files();
  69. if($folder->extras['colors']) {
  70. $folder->structs['default']['txt']['colors']=$folder->extras['colors'];
  71. }
  72. $folder->fill_content();
  73. foreach($f3->get('siteColors') as $k=>$v){
  74. $f3->set($k,
  75. array_key_exists($k,$folder->config)
  76. ? $folder->config[$k]
  77. : $v
  78. );
  79. }
  80. $f3->set('hasBanner',
  81. array_key_exists('includeBanner',$folder->config)
  82. ? $folder->config['includeBanner']
  83. : $f3->get('templateVars.includeBanner')
  84. );
  85. if ($f3->get('hasBanner')) {
  86. $banner = new \Modules\CachedImage($folder->extras['banner']);
  87. $f3->set('banner',$banner->get_src(2000));
  88. }
  89. if ($folder->extras['background']
  90. && !$folder->config['supressBackground']) {
  91. $background = new \Modules\CachedImage($folder->extras['background']);
  92. $f3->set('backgroundImage',$background->get_src(3000));
  93. }
  94. // $f3->set('background',$background);
  95. $f3->set('content', implode("\n", $folder->content['default']));
  96. $f3->set('secondary_content', implode("\n", $folder->content['secondary']));
  97. }
  98. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  99. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  100. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  101. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  102. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  103. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  104. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  105. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  106. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  107. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  108. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  109. ////////////////
  110. // recursions //
  111. ////////////////
  112. function search_up($key,$paths,$ext) {
  113. $return = "";
  114. if(count($paths) == 2) {
  115. $current = $paths[0];
  116. $last_try = $paths[1];
  117. $ls=scandir($current);
  118. foreach($ls as $f) {
  119. if(!strncmp($f,'.',1)) continue; // ignore hidden files
  120. $ex=explode(".", $f);
  121. if(in_array(strtolower(end($ex)),$ext)) {
  122. if($ex[0]==$key) {
  123. $return = $current.$f;
  124. break;
  125. }
  126. }
  127. }
  128. }
  129. if ($return) {
  130. return $return;
  131. } elseif($current == $last_try) {
  132. return false;
  133. } else {
  134. $p = explode('/',$current);
  135. array_pop($p);
  136. array_pop($p);
  137. return self::search_up($key,array(implode("/",$p)."/",$last_try),$ext);
  138. }
  139. }
  140. ///////////////////////
  141. // Utility functions //
  142. ///////////////////////
  143. function linkify($string) {
  144. $pattern = "/\s@(\w+)[=]([\w,]+)\s/";
  145. $count = 0;
  146. $new = preg_replace_callback
  147. ($pattern,
  148. function($m){
  149. $f3 = \Base::instance();
  150. return $f3->get('SITE_URL')
  151. .$f3->alias($m[1],self::$keyword."=".$m[2])
  152. ;},
  153. $string);
  154. return $new;
  155. }
  156. function get_config_from_content($string) {
  157. $f3 = \Base::instance();
  158. $f = 0;
  159. $pattern = "/#\+(\w+):\s?(.*)/";
  160. $f = preg_match_all($pattern, $string,$matches,PREG_PATTERN_ORDER);
  161. foreach($matches[0] as $match) {
  162. $string = str_replace($match,"",$string);
  163. }
  164. foreach($matches[1] as $key => $match) {
  165. $f3->set('content_config_'.$match,$matches[2][$key]);
  166. }
  167. return $string;
  168. }
  169. public static function check_folder_for_backgroundimage($folder){
  170. $EXT=array(
  171. 'pic'=>array( 'jpg', 'jpeg', 'png' ),
  172. 'tpl'=>array( 'html', 'htm', 'tpl' ),
  173. 'txt'=>array( 'txt', 'text', 'md' )
  174. );
  175. $ls = scandir($folder);
  176. $background = false;
  177. foreach ($ls as $key=>$f) {
  178. if(!strncmp($f,'.',1)) continue;
  179. $ex=explode(".", $f);
  180. $ext=array_pop($ex);
  181. if(in_array(strtolower($ext), $EXT['pic'])) {
  182. if($ex[0]=='background') {
  183. $background=pic_cache($folder.$f,836);
  184. break;
  185. }
  186. }
  187. }
  188. return $background;
  189. }
  190. }