|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- <?php
-
- namespace Controller;
-
- class Page {
-
- public static $keyword = "page"; // variable in URL (query string)
-
-
- function index(\Base $f3, $params) {
- /////////////////////////////
- // what page are we watching?
- $page = $params[self::$keyword];
- $f3->set('page', $page);
- $f3->set('bodyClass',"page-$page");
-
- switch ($page) {
- case 'home':
- default:
- $f3->mset(array(
- 'template'=>'tpl/index.html',
- 'templateContent'=>'maincontent.html'
- ));
- self::folder2();
- break;
- }
- }
-
-
- ////////////////
- // interfaces //
- ////////////////
- function home(\Base $f3) {
- self::index($f3, array('page'=>'home'));
- }
- function secondLevel(\Base $f3,$params) {
- self::index($f3, array('page'=>$params['level1']."/".$params['level2']));
- }
- function thirdLevel(\Base $f3,$params) {
- self::index($f3, array('page'=>$params['level1']."/".$params['level2']."/".$params['level3']));
- }
- function fourthLevel(\Base $f3,$params) {
- self::index($f3, array('page'=>$params['level1']."/".$params['level2']."/".$params['level3']."/".$params['level4']));
- }
-
-
-
-
- //////////////////
- // main program //
- //////////////////
- function folder2() {
- $f3 = \Base::instance();
- $page = $f3->get('page');
- $f3->set('current_page_folder', $f3->get('CONTENT').$page."/");
-
- $folder = new \Modules\FilesInFolders(
- $f3->get('current_page_folder'),
- array(
- 'content'=>array(
- 'secondary'=>'secondary',
- 'zzz'=>'hidden',
- 'unpublish'=>'hidden'
- ),
- 'keyfiles'=>array(
- 'banner'=>array(
- 'until'=>$f3->get("CONTENT"),
- 'type'=>'pic'
- ),
- 'background'=>array(
- 'until'=>$f3->get("CONTENT"),
- 'type'=>'pic'
- ),
- 'colors'=>array(
- 'until'=>$f3->get("CONTENT"),
- 'type'=>'txt'
- )
- )
- )
- );
-
- $folder->prepare_files();
- if($folder->extras['colors']) {
- $folder->structs['default']['txt']['colors']=$folder->extras['colors'];
- }
- $folder->fill_content();
- foreach($f3->get('siteColors') as $k=>$v){
- $f3->set($k,
- array_key_exists($k,$folder->config)
- ? $folder->config[$k]
- : $v
- );
- }
- $f3->set('hasBanner',
- array_key_exists('includeBanner',$folder->config)
- ? $folder->config['includeBanner']
- : $f3->get('templateVars.includeBanner')
- );
-
- if ($f3->get('hasBanner')) {
- $banner = new \Modules\CachedImage($folder->extras['banner']);
- $f3->set('banner',$banner->get_src(2000));
- }
- if ($folder->extras['background']
- && !$folder->config['supressBackground']) {
- $background = new \Modules\CachedImage($folder->extras['background']);
- $f3->set('backgroundImage',$background->get_src(3000));
- }
- // $f3->set('background',$background);
- $f3->set('content', implode("\n", $folder->content['default']));
- $f3->set('secondary_content', implode("\n", $folder->content['secondary']));
-
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- // function folder() {
- // $f3 = \Base::instance();
- // $page = $f3->get('page');
- // $folder = $f3->get("CONTENT").$page."/";
- //
- // $EXT=array(
- // 'pic'=>array( 'jpg', 'jpeg', 'png', 'svg' ),
- // 'tpl'=>array( 'html', 'htm', 'tpl' ),
- // 'txt'=>array( 'txt', 'text', 'md' ),
- // 'csv'=>array( 'csv' )
- // );
- //
- // $background = "";
- // $banner = "";
- // $c1 = array(
- // // 'background'=>'',
- // 'pic'=>array(),
- // 'txt'=>array(),
- // 'tpl'=>array(),
- // 'csv'=>array()
- // );
- // $c2 = array(
- // // 'background'=>'',
- // 'pic'=>array(),
- // 'txt'=>array(),
- // 'tpl'=>array(),
- // 'csv'=>array()
- // );
- // $primary = array();
- // $secondary = array();
- //
- //
- // // collect contents of folder into an organised array
- // if(!is_dir($folder)) $folder=$f3->get("CONTENT")."../404/";
- // $ls = scandir($folder);
- // foreach ($ls as $key=>$f) {
- // if(!strncmp($f,'.',1)) continue; // ignore hidden files
- // $ex=explode(".", $f);
- // $ext=end($ex);
- // if(in_array(strtolower($ext), $EXT['pic'])) {
- // if($ex[0]=='background') {
- // $background=pic_cache($folder.$f,836);
- // } elseif($ex[0]=='banner') {
- // $banner=$folder.$f;
- // } elseif($ex[0]=='secondary') {
- // $c2['pic'][$ex[1]] = $folder.$f;
- // } else {
- // $c1['pic'][$ex[0]] = $folder.$f;
- // }
- // } elseif(in_array(strtolower($ext), $EXT['txt'])) {
- // if($ex[0]=='secondary') {
- // $c2['txt'][$ex[1]] = $folder.$f;
- // } else {
- // $c1['txt'][$ex[0]] = $folder.$f;
- // }
- // } elseif(in_array(strtolower($ext), $EXT['tpl'])) {
- // if($ex[0]=='secondary') {
- // $c2['tpl'][$ex[1]] = $folder.$f;
- // } else {
- // $c1['tpl'][$ex[0]] = $folder.$f;
- // }
- // } elseif (in_array(strtolower($ext), $EXT['csv'])) {
- // if($ex[0]=='secondary') {
- // $c2['csv'][$ex[1]] = $folder.$f;
- // } else {
- // $c1['csv'][$ex[0]] = $folder.$f;
- // }
- // } else { }
- // }
- //
- // if(!$banner) {
- // $banner = self::search_up("banner", array($folder,$f3->get("CONTENT")), $EXT['pic']);
- // }
- //
- // // compose elements based on the organised array
- // $md = new \Parsedown();
- // foreach($c1['txt'] as $key=>$file) {
- // $str = file_get_contents($file);
- // $str = self::linkify($str);
- // $str = self::get_config_from_content($str);
- // $str = $md->text($str);
- // $str = sprintf("<div class='post'>%s</div>", $str);
- // $primary[$key] = sprintf("<div class=\"item %s %s\">%s</div>", $page,$key,$str);
- // }
- // foreach($c1['tpl'] as $key=>$file) {
- // $str = file_get_contents($file);
- // $str = \Template::instance()->render($file);
- // $str = self::linkify($str);
- // if(array_key_exists($key,$c1['pic'])) {
- // $str = sprintf("%s\n%s",
- // \Modules\Pictures::makeImageLink($c1['pic'][$key]),
- // $str);
- // unset($c1['pic'][$key]);
- // }
- // $primary[$key] = sprintf("<div class=\"item %s %s\">%s</div>", $page ,$key,$str);
- // }
- // foreach($c1['pic'] as $key=>$file) {
- // $primary[$key] = sprintf("<img src=\"$file\" />");
- // }
- // foreach($c1['csv'] as $key=>$file) {
- // $csv = new \Modules\Ography($file,TRUE);
- // // $c1sv->filter_field("file");
- // $str="<table>";
- // foreach($csv->entries as $entry) {
- // $tmp="";
- // foreach($entry as $key=>$value) {
- // $tmp .= sprintf("<td class=\"%s\">%s</td>", $key, $value);
- // }
- // $str .= sprintf("<tr>%s</tr>",$tmp);
- // }
- // $str.="</table>";
- // $primary[$key] = $str;
- // }
- //
- // foreach($c2['txt'] as $key=>$file) {
- // $str = file_get_contents($file);
- // $str = self::linkify($str);
- // $str = self::get_config_from_content($str);
- // $str = $md->text($str);
- // $str = sprintf("<div class='post'>%s</div>", $str);
- // $secondary[$key] = sprintf("<div class=\"item %s %s\">%s</div>", $page,$key,$str);
- // }
- // foreach($c2['tpl'] as $key=>$file) {
- // $str = file_get_contents($file);
- // $str = \Template::instance()->render($file);
- // $str = self::linkify($str);
- // if(array_key_exists($key,$c2['pic'])) {
- // $str = sprintf("%s\n%s",
- // \Modules\Pictures::makeImageLink($c2['pic'][$key]),
- // $str);
- // unset($c2['pic'][$key]);
- // }
- // $secondary[$key] = sprintf("<div class=\"item %s %s\">%s</div>", $page ,$key,$str);
- // }
- // foreach($c2['pic'] as $key=>$file) {
- // $secondary[$key] = sprintf("<img src=\"$file\" />");
- // }
- // foreach($c2['csv'] as $key=>$file) {
- // $csv = new \Modules\Ography($file,TRUE);
- // // $c2sv->filter_field("file");
- // $str="<table>";
- // foreach($csv->entries as $entry) {
- // $tmp="";
- // foreach($entry as $key=>$value) {
- // $tmp .= sprintf("<td class=\"%s\">%s</td>", $key, $value);
- // }
- // $str .= sprintf("<tr>%s</tr>",$tmp);
- // }
- // $str.="</table>";
- // $secondary[$key] = $str;
- // }
- //
- // // set template variables
- // $f3->set('banner',$banner);
- // $f3->set('background',$background);
- // $f3->set('content', implode("\n", $primary));
- // $f3->set('secondary_content', implode("\n", $secondary));
- // }
-
- ////////////////
- // recursions //
- ////////////////
- function search_up($key,$paths,$ext) {
- $return = "";
-
- if(count($paths) == 2) {
- $current = $paths[0];
- $last_try = $paths[1];
- $ls=scandir($current);
- foreach($ls as $f) {
- if(!strncmp($f,'.',1)) continue; // ignore hidden files
- $ex=explode(".", $f);
- if(in_array(strtolower(end($ex)),$ext)) {
- if($ex[0]==$key) {
- $return = $current.$f;
- break;
- }
- }
- }
- }
-
- if ($return) {
- return $return;
- } elseif($current == $last_try) {
- return false;
- } else {
- $p = explode('/',$current);
- array_pop($p);
- array_pop($p);
- return self::search_up($key,array(implode("/",$p)."/",$last_try),$ext);
- }
- }
-
-
-
-
-
- ///////////////////////
- // Utility functions //
- ///////////////////////
- function linkify($string) {
- $pattern = "/\s@(\w+)[=]([\w,]+)\s/";
- $count = 0;
- $new = preg_replace_callback
- ($pattern,
- function($m){
- $f3 = \Base::instance();
- return $f3->get('SITE_URL')
- .$f3->alias($m[1],self::$keyword."=".$m[2])
- ;},
- $string);
- return $new;
- }
- function get_config_from_content($string) {
- $f3 = \Base::instance();
- $f = 0;
- $pattern = "/#\+(\w+):\s?(.*)/";
-
- $f = preg_match_all($pattern, $string,$matches,PREG_PATTERN_ORDER);
- foreach($matches[0] as $match) {
- $string = str_replace($match,"",$string);
- }
- foreach($matches[1] as $key => $match) {
- $f3->set('content_config_'.$match,$matches[2][$key]);
- }
- return $string;
- }
- public static function check_folder_for_backgroundimage($folder){
- $EXT=array(
- 'pic'=>array( 'jpg', 'jpeg', 'png' ),
- 'tpl'=>array( 'html', 'htm', 'tpl' ),
- 'txt'=>array( 'txt', 'text', 'md' )
- );
- $ls = scandir($folder);
- $background = false;
- foreach ($ls as $key=>$f) {
- if(!strncmp($f,'.',1)) continue;
- $ex=explode(".", $f);
- $ext=array_pop($ex);
- if(in_array(strtolower($ext), $EXT['pic'])) {
- if($ex[0]=='background') {
- $background=pic_cache($folder.$f,836);
- break;
- }
- }
- }
- return $background;
- }
- }
|