'default'); private $keyfiles = array(); public $structs = array(); public $EXT=array( 'txt'=>array( 'txt', 'text', 'md' ), 'pic'=>array( 'jpg', 'jpeg', 'png', 'svg' ), 'tpl'=>array( 'html', 'htm' ), 'audio'=>array('mp3','wav','ogg'), 'csv'=>array( 'csv' ) ); public $config = array(); private $state=array(); function __construct($folder,$conf=array()) { debug("about to construct FIF: $folder"); $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] = ""; } debug("constructed files in folder: $folder"); } ///////////////////////////// // 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() { $f3 = \Base::instance(); $md = new \freaParsedown(); $md->deactivate_ol(); //var_dump($md->get_BlockTypes()); foreach($this->domains as $domain_key=>$domain) { // don't act on hidden files if ($domain == 'hidden') { continue; } $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", $str); $this->content[$domain][$key."30text"] = sprintf( "
", '', $key, $key, $str ); } $includeTemplates = array_key_exists('includeTemplates', $this->config) ? $this->config['includeTemplates'] : ($f3->get('includeTemplates') ? : FALSE) ; if ($includeTemplates) { foreach($this->structs[$domain_key]['tpl'] as $key=>$file) { $str = \Template::instance()->render(substr($file,7)); $str = self::linkify($str); $this->content[$domain][$key."00tpl"] = sprintf( "%s | ", $key, $value); } $str .= sprintf("