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.

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