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.

250 Zeilen
8.5KB

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