mostly filebased Content Presentation System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 line
8.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'=>$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. foreach($f3->get('customVars') as $key=>$value) {
  85. $f3->set($key,$value);
  86. $this->register_key($key,$folder);
  87. }
  88. $folder->fill_content();
  89. foreach($f3->get('siteColors') as $k=>$v){
  90. $f3->set($k,
  91. array_key_exists($k,$folder->config)
  92. ? $folder->config[$k]
  93. : $v
  94. );
  95. }
  96. $f3->set('hasBanner',
  97. array_key_exists('includeBanner',$folder->config)
  98. ? $folder->config['includeBanner']
  99. : $f3->get('templateVars.includeBanner')
  100. );
  101. if ($f3->get('hasBanner')) {
  102. //$banner = new \Modules\CachedImage($folder->extras['banner']);
  103. $f3->set('banner',$folder->extras['banner']);//$banner->get_src(2000));
  104. }
  105. if (isset($folder->extras['logo'])) {
  106. $f3->set('logo', $folder->extras['logo']);
  107. }
  108. if ($folder->extras['background']
  109. && !$folder->config['supressBackground']) {
  110. //$background = new \Modules\CachedImage($folder->extras['background']);
  111. //$f3->set('backgroundImage',$background->get_src(3000));
  112. $background = $folder->extras['background'];
  113. $f3->set('backgroundImage',$background);
  114. }
  115. // $f3->set('background',$background);
  116. $f3->set('content', implode("\n", $folder->content['default']));
  117. $f3->set('secondary_content', implode("\n", $folder->content['secondary']));
  118. }
  119. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  120. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  121. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  122. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  123. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  124. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  125. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  126. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  127. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  128. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  129. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  130. ////////////////
  131. // recursions //
  132. ////////////////
  133. function search_up($key,$paths,$ext) {
  134. $return = "";
  135. if(count($paths) == 2) {
  136. $current = $paths[0];
  137. $last_try = $paths[1];
  138. $ls=scandir($current);
  139. foreach($ls as $f) {
  140. if(!strncmp($f,'.',1)) continue; // ignore hidden files
  141. $ex=explode(".", $f);
  142. if(in_array(strtolower(end($ex)),$ext)) {
  143. if($ex[0]==$key) {
  144. $return = $current.$f;
  145. break;
  146. }
  147. }
  148. }
  149. }
  150. if ($return) {
  151. return $return;
  152. } elseif($current == $last_try) {
  153. return false;
  154. } else {
  155. $p = explode('/',$current);
  156. array_pop($p);
  157. array_pop($p);
  158. return self::search_up($key,array(implode("/",$p)."/",$last_try),$ext);
  159. }
  160. }
  161. ///////////////////////
  162. // Utility functions //
  163. ///////////////////////
  164. function register_key($name, &$ff) {
  165. $f3 = \Base::instance();
  166. if (array_key_exists($name,$ff->config)) {
  167. $f3->set($name,$ff->config[$name]);
  168. }
  169. }
  170. function linkify($string) {
  171. $pattern = "/\s@(\w+)[=]([\w,]+)\s/";
  172. $count = 0;
  173. $new = preg_replace_callback
  174. ($pattern,
  175. function($m){
  176. $f3 = \Base::instance();
  177. return $f3->get('SITE_URL')
  178. .$f3->alias($m[1],self::$keyword."=".$m[2])
  179. ;},
  180. $string);
  181. return $new;
  182. }
  183. function get_config_from_content($string) {
  184. $f3 = \Base::instance();
  185. $f = 0;
  186. $pattern = "/#\+(\w+):\s?(.*)/";
  187. $f = preg_match_all($pattern, $string,$matches,PREG_PATTERN_ORDER);
  188. foreach($matches[0] as $match) {
  189. $string = str_replace($match,"",$string);
  190. }
  191. foreach($matches[1] as $key => $match) {
  192. $f3->set('content_config_'.$match,$matches[2][$key]);
  193. }
  194. return $string;
  195. }
  196. public static function check_folder_for_backgroundimage($folder){
  197. $EXT=array(
  198. 'pic'=>array( 'jpg', 'jpeg', 'png' ),
  199. 'tpl'=>array( 'html', 'htm', 'tpl' ),
  200. 'txt'=>array( 'txt', 'text', 'md' )
  201. );
  202. $ls = scandir($folder);
  203. $background = false;
  204. foreach ($ls as $key=>$f) {
  205. if(!strncmp($f,'.',1)) continue;
  206. $ex=explode(".", $f);
  207. $ext=array_pop($ex);
  208. if(in_array(strtolower($ext), $EXT['pic'])) {
  209. if($ex[0]=='background') {
  210. $background=pic_cache($folder.$f,836);
  211. break;
  212. }
  213. }
  214. }
  215. return $background;
  216. }
  217. }