'default'); private $keyfiles = array(); public $structs = array(); private $EXT=array( 'txt'=>array( 'txt', 'text', 'md' ), 'pic'=>array( 'jpg', 'jpeg', 'png', 'svg' ), 'tpl'=>array( 'html', 'htm', 'tpl' ), 'csv'=>array( 'csv' ) ); public $config = array(); private $state=array(); function __construct($folder,$conf=array()) { $f3 = \Base::instance(); if(is_dir($folder)) { // are we given a valid path? $this->folder = $folder; } else { // and if not? $this->folder = $f3->get('CONTENT')."./"; } if(is_array($conf)) { foreach($conf as $key=>$value) { switch($key) { case 'content': if(is_array($value)) { foreach($value as $k=>$v) { $this->domains[$k] = $v; } } break; case 'keyfiles': if(is_array($value)) { foreach($value as $k=>$v) { $this->keyfiles[$k] = $v; } } break; } } } foreach($this->domains as $domain) { $this->content[$domain] = array(); } foreach($this->keyfiles as $keys=>$d) { $this->extras[$keys] = ""; } } ///////////////////////////// // read folder into struct // ///////////////////////////// function prepare_files() { foreach ($this->domains as $k=>$v) { foreach($this->EXT as $cat=>$endings) { $this->structs[$k][$cat]=array(); } } $ls = scandir($this->folder); foreach ($ls as $k=>$f) { if (!strncmp($f,'.',1)) continue; // ignore hidden files $ex=explode(".", $f); $ext=strtolower(end($ex)); if (array_key_exists($ex[0],$this->domains)) { $domain_key=$ex[0]; $sort_key=1; } elseif (array_key_exists($ex[0], $this->keyfiles)) { if(in_array($ext,$this->EXT[$this->keyfiles[$ex[0]]['type']])) { $this->extras[$ex[0]]=$this->folder.$f; continue; } $domain_key='default'; $sort_key=0; } else { $domain_key='default'; $sort_key=0; } foreach ($this->EXT as $cat=>$endings) { if (in_array($ext, $endings)) { $this->structs[$domain_key][$cat][$ex[$sort_key]] = $this->folder.$f; break; } } } foreach($this->keyfiles as $key=>$param) { if(!$this->extras[$key]) { $this->extras[$key] = self::search_up( $key, array($this->folder,$param['until']), $this->EXT[$param['type']] ); } if($this->extras[$key]) { if ($param['type'] == 'txt') { $this->read_textfile($this->extras[$key]); } } } } /////////////////////////////////////// // prepare content as per the struct // /////////////////////////////////////// function fill_content() { $md = new \Parsedown(); foreach($this->domains as $domain_key=>$domain) { $this->state['current_domain'] = $domain_key; foreach($this->structs[$domain_key]['txt'] as $key=>$file) { $str = $this->read_textfile($file); $str = self::content_element_dispatcher($str); $str = $md->text($str); $str = sprintf("
%s | ", $key, $value); } $str .= sprintf("