Commit c323d8a2 authored by David Libeau's avatar David Libeau

Support "/" custom route

parent c3fbf12d
......@@ -14,13 +14,13 @@ class Content{
Init
@params: $id
*/
$this->type=$type;
if(!$this->initDone && !is_null($id)){
$this->content=file_get_contents("../".$id.".txt");
$this->content=file_get_contents("../".Server::get("path/content/".$this->type."/content")."/".$id.".txt");
if(!$this->content){
$core->error("404","../".$id.".txt was not found");
}
$this->id=$id;
$this->type=$type;
}
}
public function get($var){
......
......@@ -37,6 +37,8 @@ class Core{
if(Server::get("route/".$crparam)==$q){
$foundRoute=true;
$route=$currentRoute;
}elseif(Server::get("route/".$crparam)=="/"){
}
}
}
......@@ -50,13 +52,25 @@ class Core{
if(substr($currentRoute->content,0,1)==":"){ // :this :parent
$foundRoute=true;
$route=$currentRoute;
}elseif(substr((string)$currentRoute->content,0,1)=="$"){//Route is user config
$cr=substr((string)$currentRoute->content,1);
if (preg_match("/(.+\(.+\).*){1}/", $cr)) {
$crfunction=strtolower(explode("(",$cr)[0]);
$crparam=str_replace(")","",explode("(",$cr)[1]);
if($crfunction=="server"){
if(Server::get("route/".$crparam)=="/"){//If the user defined "/" as route, means that he/she wants the root
$foundRoute=true;
$route=$currentRoute->route;//Not this route but its child
}
}
}
}
}
}
}
}
foreach($currentRoute->route as $subRoute) {
foreach($currentRoute->route as $subRoute) {//subRoute
if($subRoute->content==""){
foreach($subRoute->content->attributes() as $attr => $attrvalue) {
if($attr=="type"){
......
......@@ -21,17 +21,28 @@ class Server{
switch(explode("/",$var)[1]){
case "content":
$route = $serverConfig->xpath("customPath/object[id='content/".explode("/",$var)[2]."']/route/text()");
return((string)$route[0]);
break;
case "user":
$route = $serverConfig->xpath("customPath/object[id='user']/route/text()");
break;
default:
break;
}
return((string)$route[0]);
break;
case "path":
switch(explode("/",$var)[1]){
case "content":
$route = $serverConfig->xpath("customPath/object[id='content/".explode("/",$var)[2]."']/path/".explode("/",$var)[3]."/text()");
return((string)$route[0]);
break;
case "user":
$route = $serverConfig->xpath("customPath/object[id='user']/path/".explode("/",$var)[2]."/text()");
return((string)$route[0]);
break;
defautl:
default:
break;
}
//return($serverConfig->customPath->$child);
break;
default:
$parent=explode("/",$var)[0];
......
......@@ -15,7 +15,7 @@ class User{
@params: $id
*/
if(!$this->initDone && !is_null($id)){
$this->data=simplexml_load_file("../fedidata/user/".$id.".xml");
$this->data=simplexml_load_file("../".Server::get("path/user/data")."/".$id.".xml");
if(!$this->data){
//$core->error("404");
}
......@@ -36,7 +36,7 @@ class User{
global $core;
$this->init($id);
$image=file_get_contents("../data/user/".$this->id."-".$type);
$image=file_get_contents("../".Server::get("path/user/data")."/".$this->id."-".$type);
if(!$image){
$core->error("404");
}
......
......@@ -55,12 +55,28 @@
</route>
</route>
<route>
<content>$server(content/media)</content><!--TO DO: make content/* for all content type-->
<content>$server(content/static)</content><!--TO DO: make content/* for all content type (Maybe not ?)-->
<route>
<content>:id</content>
<return method="get">
<function>Content->view</function>
<params>
<param1>:this</param1>
<param2>static</param2>
</params>
</return>
</route>
</route>
<route>
<content>$server(content/media)</content>
<route>
<content>:media</content>
<return method="get">
<function>Content->viewMedia</function>
<params>:this</params>
<params>
<param1>:this</param1>
<param2>media</param2>
</params>
</return>
</route>
</route>
......
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