folder = $folder; } if (is_array($config)) { $this->config = $config; } } function content_element($request = [], $body = null) { $f3 = \Base::instance(); $md = new \freaParsedown(); $md->deactivate_ol(); $new = ""; switch($request[0]) { case 'test': $new="seems to work"; break; case ';': $new=""; break; case 'path': $new="/".$this->folder; break; case 'space': $new=sprintf("
", $request[1] ); break; case 'span': $new=sprintf("%s", $request[1], $request[2] ? : implode("\n",$body) ); break; case 'small-text': if(count($body)) { $new=sprintf("
%s
", $md->text(implode("\n",$body)) ); } else { $new=sprintf("%s", $request[1] ); } break; case 'CE': switch($request[1]) { case 'publication': $CE = new \Modules\CPublication($this->config,['path'=>$this->folder]); if(count($request)>2) { $CE->set_layout($request[2]); } $new = $CE; break; } break; case 'TOC': // throw away TOC part of request, we don't need it array_shift($request); $toc = new \Modules\TOC($request,$this->folder,$body); $toc->dispatch(); $new=sprintf("
%s
", array_shift($request), $toc); break; case 'sql': //array_shift($request); switch ($request[1]) { case 'sqlite': $array = []; $db = new \DB\SQL('sqlite:' . $this->folder . $request[2]); $sql = implode(" ", $body); if ( strpos($sql,'insert')===false && strpos($sql,'update')===false && strpos($sql,'drop')===false) { $rows = $db->exec($sql); foreach ($rows as $res) { switch (count($res)) { case 1: $keys=array_keys($res); $array[] = $res[$keys[0]]; break; case 2: $keys=array_keys($res); $array[$res[$keys[0]]] = $res[$keys[1]]; break; } } } $new = sprintf("", implode("
  • ",$array)); unset($array); break; } break; case 'form': $token_db = $f3->get('TEMP') . "CEform/"; $form_config_file = sprintf("%s%s.cfg", ROOT.$this->folder, $request[1]); $db = new \DB\Jig($token_db,\DB\Jig::FORMAT_JSON); $formcall = new \DB\Jig\Mapper($db,'form_calls'); $timestamp = time(); $token = md5($timestamp . $form_config_file . rand(100,999)); $f3->config($form_config_file); $fields = $f3->get('fields'); foreach ($fields as $k => $v) { if ($v['type'] == 'custom') { $fields[$k]['template'] = sprintf( "%s%s", substr($this->folder,strlen($f3->get('CONTENT_BASE'))), $v['template'] ); } if (array_key_exists('db',$v)) { switch ($v['db']['type']) { case 'sqlite': $array = []; $db = new \DB\SQL('sqlite:' . $this->folder . $v['db']['file']); $sql = $v['db']['sql']; if ( strpos($sql,'insert')===false && strpos($sql,'update')===false && strpos($sql,'drop')===false) { $rows = $db->exec($sql); foreach ($rows as $res) { switch (count($res)) { case 2: $keys=array_keys($res); $array[$res[$keys[0]]] = $res[$keys[1]]; break; } } } $fields[$k]['el'] = $array; unset($array); break; } } } $f3->set('fields', array_merge( $fields, ['xss-token'=>[ 'type'=>'hidden', 'value'=>$token, 'length'=>strlen($token) ]] )); $formcall->token = $token; $formcall->timestamp = $timestamp; $formcall->form = $form_config_file; $formcall->path = ROOT.$this->folder; $formcall->save(); $form_view = new \Template; $new=$form_view->render('form.htm'); break; case 'box': array_shift($request); //get rid of identifier $type = array_shift($request); $pics = explode(":",array_shift($body)); $pic = $pics[0]; $pic_hover = count($pics) > 1 ? $pics[1] : $pic; if (count($body) >= 3) { $caption = ['normal'=>['cap1' => array_shift($body), 'cap2' => array_shift($body)], 'hover'=> ['cap1' => array_shift($body), 'cap2' => array_shift($body)]]; $caption_html=[]; foreach ($caption as $state => $set) { if(!$set['cap2']) { $caption_html[$state] = [ sprintf(' '), sprintf('%s',$set['cap1']) ]; } else if (!$set['cap1'] && $set['cap2']) { $caption_html[$state] = [ sprintf('%s',$set['cap2']) ]; } else { $caption_html[$state] = [ sprintf('%s',$set['cap1']?:" "), sprintf('%s',$set['cap2']) ]; } } $has_caption = TRUE; } else { $has_caption = FALSE; } if (file_exists($this->folder.$pic)) { $pic = $this->folder.$pic; } else { $pic = $f3->get('RESOURCES')."img/default_img.png"; } if (file_exists($this->folder.$pic_hover)) { $pic_hover = $this->folder.$pic_hover; } else { $pic_hover = $pic; } if(0) { $PIC = new \Image($pic); $orientation = $PIC->width() > $PIC->height() ? 'landscape' : 'portrait' ; unset($PIC); } else { list($wwidth, $hheight) = getimagesize($pic); $orientation = $wwidth > $hheight ? 'landscape' : 'portrait'; } $pic = new CachedImage($pic); $pic_hover = new CachedImage($pic_hover); $class=""; $add=""; switch($type) { case 'plain': $link=false; break; case 'download': $file = "/".$this->folder.implode(":",$request); $link='href="'.$file.'" download '; break; case 'lightbox': $body = implode("\n",$body); if (count($request) % 2) { $class = array_pop($request); } if (count($request) >= 2) { $body=str_replace([$request[0],$request[1]],["{|","|}"],$body); $body=$this->content_element_dispatcher($body); } $hash=md5($body); $add=sprintf("
    \n%s\n
    ", $hash, $md->text($body)); $link='href="#" data-featherlight="#'.$hash.'" '; break; case 'internal': $dest=implode(":",$request); $data = []; $base = substr($dest,0,strpos($dest,'?') ? : strlen($dest)); parse_str(parse_url($dest,PHP_URL_QUERY),$data); $fragment = parse_url($dest,PHP_URL_FRAGMENT); if ($f3->get('LANG') != $f3->get('default_lang')) { if (!array_key_exists('lang',$data)) { $data['lang'] = $f3->get('LANG'); } } $new_dest = $base; if (count($data) > 0) { $new_dest .= "?" . http_build_query($data); } if ($fragment) { $new_dest .= "#" . $fragment; } //if ($f3->get('LANG') != $f3->get('default_lang')) { // $dest .= "?lang=".$f3->get('LANG'); //} $link=sprintf('href="%s" ',$f3->get('SITE_URL')."/".$new_dest); break; case 'external': $dest=implode(":",$request); $target = $f3->get('external_links_open_in_new_window') ? 'target="_blank"' : '' ; $link=sprintf('href="%s" %s',$dest, $target); break; default: $link='href="#"'; break; } $new=sprintf("
    \n\n
    %s %s \n
    \n
    \n%s\n
    ", implode(" ",[$orientation,$class,$type]), $link, $pic->get_src(1600), $pic_hover->get_src(1600), ($has_caption ? "
    ".implode("
    ",$caption_html['normal'])."
    ": " "), ($has_caption ? "
    ".implode("
    ",$caption_html['hover'])."
    " : " " ), $add ); break; case 'brick': array_shift($request); $class = array_shift($request); $new = sprintf("
    \n%s\n
    ", $class, $md->text(implode("\n",$body)) ); break; case 'calendar': array_shift($request); $conf = array('path', $this->folder); $v = $this->read_config(); $cal = new \Modules\CCalendar($v,$conf); $new=sprintf("
    \n%s\n
    ", $cal); break; case 'header': array_shift($request); $conf = array('path', $this->folder); $v = $this->read_config(); switch (array_shift($request)) { case 'event': $el = new CEvent($v,$conf); $el->set_layout('archive'); $new = $el; break; case 'concert': $el = new CConcert($v,$conf); $el->set_layout('header'); $new = $el; break; } break; case 'data': $method = strtoupper($request[1]); //$keys = []; if (in_array($method,['POST','GET','SESSION'])) { foreach ($body as $line) { $key = explode("=",$line); $raw = $f3->get($method.'.'.$key[0]); if (count($key) >= 2) { $type=$key[1]; } else { $type = false; } switch ($type) { case 'base64': $new = urlsafe_b64decode($raw); break; default: $new = $raw; } } //var_dump($new); } break; case 'buy': // synopsis: // buy:name:price // TODO: become currency aware (now EURO is hardcoded) $new = ''; if (count($request)>=2) { $name=$request[1]; } else { $name="item"; } if (count($request)>=3) { $price=$request[2]; } else { $price=1.0; } $fields = [ 'caller' => $f3->get('page'), 'name'=>$name, 'price'=>$price, 'amount'=>1 ]; $hidden_inputs = []; foreach ($fields as $k=>$v) { $hidden_inputs[] = sprintf('',$k,$v); } $new = sprintf('
    %s %s
    ', '/api/cart/add', implode("\n",$hidden_inputs), $price ."€" ); break; case 'checkout': //first argument, if present, is a path to folder containing order database $path = ''; if (count($request) > 1) { $add_path = $request[1]; if (strncmp($add_path,"/",1)) { $path = $this->folder.$add_path; } else { $path = $add_path; } } else { $path = $this->folder; } $checkout = new \Controller\Checkout($path); $new = $checkout->index(); break; case 'only_cart': $checkout = new \Controller\Checkout($this->folder); $new = $checkout->html_cart(); break; case 'image': $module = new CEimage($request, $body, $this->structs, $this->content); $new = $module->index(); unset($module); break; case 'devide': $contents = explode($request[1],implode("\n",$body)); $c=count($contents); $str=""; for ($iiii=0;$iiii<$c;$iiii++) { $str .= sprintf(" %f%%",100/$c); } $template = sprintf('grid-template-columns:%s;', $str); $counter=0; $new = sprintf('
    ',$template); foreach($contents as $part) { $counter++; if (count($request) >= 4) { $part=str_replace([$request[2],$request[3]],["{|","|}"],$part); $part=$this->content_element_dispatcher($part); } $new .= sprintf("
    \n%s\n
    ", $md->text($part) ); } $new.="
    "; break; case 'page': array_shift($request); $target = array_shift($request); $class = array_shift($request); $folder = $this->folder.$target."/"; $anchor_name=array_pop(explode("/",$target)); $fff = new \Modules\FilesInFolders( $folder, ['content'=>[ 'secondary'=>'secondary', 'zzz'=>'hidden', 'unpublish'=>'hidden'], 'keyfiles'=>[ 'banner'=>[ 'until'=>$folder, 'type'=>'pic']]] ); $fff->prepare_files(); foreach ($body as $line) { $ccc = explode(":",$line); if (count($ccc) == 2) { if ($ccc[1] == 'false') { $ccc[1] = false; } $fff->config[$ccc[0]] = $ccc[1]; } } $fff->fill_content(); //var_dump($fff->config); $banner = ""; if ($fff->extras['banner']) { $banner=sprintf("\"section", $fff->extras['banner']); } $new = sprintf("
    " ."%s\n%s\n
    ", $class, $anchor_name, $banner, implode("\n",$fff->content['default'])); break; case 'youtube': $vid=array_shift($request); $pos= array_shift($request); if( in_array($pos,array('left','right','full'))) { $class = $pos; } else { $class = 'left'; } $video=sprintf("", $vid); $thumbnail = sprintf("
    " ."\"video-preview\"/" ."\"play-button\"" ."
    %s
    ", "https://www.youtube.com/watch?v=".$vid, $vid, $vid, "/rsc/img/play-button.png", $vid, $video ); foreach ($body as $k=>$line) { if (strpos($line,"©") !== FALSE || strpos($line,"©") !== FALSE) { $body[$k] = sprintf("%s",$line); } } $new=sprintf("
    " ."
    %s
    " ."
    %s
    " ."
    ", $class, $thumbnail, $md->text(implode("\n",$body))); break; default: $new=self::warn("Content Module \"".$request[0]."\" unknown"); break; } return $new; } }