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(); foreach($f3->get('customVars') as $key=>$value) { $f3->set($key,$value); $this->register_key($key,$folder); } $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',$folder->extras['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)); $background = $folder->extras['background']; $f3->set('backgroundImage',$background); } // $f3->set('background',$background); $f3->set('content', implode("\n", $folder->content['default'])); $f3->set('secondary_content', implode("\n", $folder->content['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 register_key($name, &$ff) { $f3 = \Base::instance(); if (array_key_exists($name,$ff->config)) { $f3->set($name,$ff->config[$name]); } } 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; } }