Commit f2ced242 authored by David Libeau's avatar David Libeau

Add Content with markdown support

parent 1d3c5ee9
......@@ -4,6 +4,7 @@ function autoloader($class) {
if(file_exists("controllers/".$class.".php")){
require_once("controllers/".$class.".php");
}
require_once("../lib/Parsedown.php");
}
spl_autoload_register('autoloader');
?>
\ No newline at end of file
<?php
class Content{
protected $initDone=false;
protected $id;
protected $data;
public function __construct(){
//return(1);
}
public function init($id){
global $core;
/*
Init
@params: $id
*/
if(!$this->initDone){
$this->data=file_get_contents("../".$id.".txt");
if(!$this->data){
$core->error("404");
}
$this->id=$id;
}
}
public function get($var){
return($this->$var);
}
public function view($id) {
$this->init($id);
View::render("content",$this);
}
public function dump($id) {
$this->init($id);
View::render("dump",$this);
}
}
?>
\ No newline at end of file
......@@ -11,6 +11,10 @@ class User{
}
public function init($id){
global $core;
/*
Init
@params: $id
*/
if(!$this->initDone){
$this->data=simplexml_load_file("../data/user/".$id.".xml");
if(!$this->data){
......
<?php
class View{
public static function render($viewName,$object) {
global $core;
if($viewName=="raw"){
echo($object);
}else if($viewName=="dump"){
......@@ -13,9 +15,23 @@ class View{
echo($object);
}else{
$view=file_get_contents("views/".$viewName.".xml");
//Transform xml to html via the base template here
preg_match_all("/\{\{([^\}]*)\}\}/", $view, $matches);
if($view==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}}
foreach($matches[1] as $i=>$m){
if (preg_match("/(.+\(.+\).*){1}/", $m)) {
$vfunction=strtolower(explode("(",$m)[0]);
$vparam=str_replace(")","",explode("(",$m)[1]);
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);
}
}
}
if($m[0]=="$"){
$view=str_replace($matches[0][$i],Secure::that($object->get(substr($m,1))),$view);
}
......
<?xml version="1.0" encoding="UTF-8"?>
<view>
<head>
<title>Content : {{$id}}</title>
</head>
<body>
<main class="content">
{{markdown($data)}}
</main>
</body>
</view>
\ 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