Commit 8c60b1a6 authored by David Libeau's avatar David Libeau

Add first *in the content* function to list all the articles and render them in a specific view

parent a166daba
......@@ -226,6 +226,11 @@ $feed='<?xml version="1.0" encoding="utf-8"?>
$return.=$object->exportAtom();
}
break;
default:
foreach ($objects as $object) {
$return.=View::render($format,$object,"return");
}
break;
}
return($return);
}
......
<?php
class View{
public static function render($viewName,$object) {
public static function render($viewName,$object,$returnMethod="echo") {
global $core;
/*
Render view
*/
switch($viewName){
case "raw":
......@@ -44,13 +47,16 @@ echo('<?xml version="1.0" encoding="utf-8"?>
'.$object->exportAtom().'
</feed>');
break;
case "htmlSummary":
$render="<a href=\"/".Server::get("route/content/".$object->get("type"))."/".$object->get("id")."\">".$object->get("id")."</a>";
break;
default :
$view=file_get_contents("views/".$viewName.".xml");
if($view==false){
$render=file_get_contents("views/".$viewName.".xml");
if($render==false){
$core->error("404","View named \"$viewName\" was not found");
}
//TO DO : Transform xml to html via the base template here
preg_match_all("/\{\{([^\}]*)\}\}/", $view, $matches); //isolate {{this thing}}
preg_match_all("/\{\{([^\}]*)\}\}/", $render, $matches); //isolate {{this thing}} in the view
foreach($matches[1] as $i=>$m){
if (preg_match("/(.+\(.+\).*){1}/", $m)) {
$vfunction=strtolower(explode("(",$m)[0]);
......@@ -59,17 +65,40 @@ echo('<?xml version="1.0" encoding="utf-8"?>
if($vfunction=="markdown" || $vfunction=="parsedown"){
$Parsedown = new Parsedown();
if($vparam[0]=="$"){
$view=str_replace($matches[0][$i],$Parsedown->text($object->get(substr($vparam,1))),$view);
$render=str_replace($matches[0][$i],$Parsedown->text($object->get(substr($vparam,1))),$render);
//Check for {{things}} in the rendered view
preg_match_all("/\{\{([^\}]*)\}\}/", $render, $matches); //isolate {{this thing}}
foreach($matches[1] as $i=>$m){
if (preg_match("/(.+\(.+\).*){1}/", $m)) {
$vfunction=strtolower(explode("(",$m)[0]);
$vparam=str_replace(")","",explode("(",$m)[1]);
if($vfunction=="list"){
$vparam=explode(",",$vparam);
if($vparam[0]=="all"){
$render=str_replace($matches[0][$i],$core->listAll($vparam[1],$vparam[2]),$render);
}elseif($vparam[0][1]=="@"){
//user
}
}
}
}
}
}
}
if($m[0]=="$"){
$view=str_replace($matches[0][$i],Secure::that($object->get(substr($m,1))),$view);
$render=str_replace($matches[0][$i],$object->get(substr($m,1)),$render);
}
}
echo($view);
break;
}
//If not already return or echo (?)
if($returnMethod=="echo"){
echo(Secure::that($render));
}elseif($returnMethod=="return"){
return(Secure::that($render));
}
}
}
?>
\ No newline at end of file
# dev.fedi.blog
Hello world.
**This is a list of all articles :**
{{list(all,article,htmlSummary)}}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment