diff --git a/Conjuro/Builder.php b/Conjuro/Builder.php
new file mode 100644
index 0000000..e37d22a
--- /dev/null
+++ b/Conjuro/Builder.php
@@ -0,0 +1,3 @@
+
\ No newline at end of file
diff --git a/Conjuro/Config.php b/Conjuro/Config.php
new file mode 100644
index 0000000..8af977d
--- /dev/null
+++ b/Conjuro/Config.php
@@ -0,0 +1,25 @@
+"index",
+ "admin-page"=>"admin",
+ "error-page"=>"error",
+ "login-page"=>"login",
+
+ // mySQL/mariaDB Database connection settings
+ "db-host"=>"localhost",
+ "db-name"=>"conjuro",
+ "db-user"=>"root",
+ "db-pass"=>"toor",
+ "db-charset"=>"utf8mb4",
+ "db-prefix"=>"cj-",
+
+ // Site defaults
+ "site-title"=>"Conjuro",
+ "default-layout"=>"default",
+ "default-header"=>"#header",
+ "default-footer"=>"#footer",
+ "bootusers"=>[["Admin","Admin3"]], // Comment on production
+ "debug"=>true
+ ];
+?>
\ No newline at end of file
diff --git a/Conjuro/Conjuro.php b/Conjuro/Conjuro.php
index 3e4d19c..6ef0519 100644
--- a/Conjuro/Conjuro.php
+++ b/Conjuro/Conjuro.php
@@ -130,6 +130,9 @@
return $this->modules[$name];
}
+ /**
+ * Load a control library
+ */
private function loadControlLibrary($name){
if (!isset($name) || strpos($name,".")!==false || strpos($name,"/")!==false){
throw new Exception("Name error");
@@ -143,15 +146,33 @@
}
}
+ /**
+ * Load control libraries installed
+ */
private function loadControls(){
+ // TODO- glob directoty to fetch all libraries.
$this->loadControlLibrary("common");
}
+ /**
+ * Return a control
+ */
public function control($name){
if (isset($this->controls[$name]))
return $this->controls[$name];
return new ErrorControl($name);
}
+
+ /**
+ * Return the available controls.
+ */
+ public function listControls(){
+ $arr=[];
+ foreach($this->controls as $k => $ctrl){
+ $arr[]=$k;
+ }
+ return $arr;
+ }
}
/**
@@ -200,7 +221,9 @@
}
public function render($meta=null,$data=null){
+ echo "
";
$this->renderControl($meta,$data);
+ echo "
";
}
abstract protected function renderControl($meta,$data);
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..3844e62
--- /dev/null
+++ b/README.md
@@ -0,0 +1,18 @@
+# Conjuro Web Editor
+Extremely simple web page editor,
+no PHP knowledge is needed but you can use it if you want.
+
+Only needs php web server with mysql/mariadb connection
+
+## Setup
+
+Copy all files to your web server, making index.php your initial page.
+When ready open the "/admin" page.
+Default user is "Admin" and password "Admin3" (both with no quotes)
+Change admin password to your one, or create a new admin user.
+
+## Editiom
+
+Open page in editor mode.
+Add different modules to the web.
+Options to customize PHP files or CSS are present.
diff --git a/content/controls/common.php b/content/controls/common.php
index 3324e7e..9dd05bc 100644
--- a/content/controls/common.php
+++ b/content/controls/common.php
@@ -7,6 +7,11 @@
protected function renderControl($meta,$data) {
echo $meta["html"];
}
- }
+ },
+ new class("builder") extends Control{
+ protected function renderControl($meta,$data) {
+ include "Conjuro/Builder.php";
+ }
+ },
];
?>
\ No newline at end of file
diff --git a/content/modules/Page.php b/content/modules/Page.php
new file mode 100644
index 0000000..4207799
--- /dev/null
+++ b/content/modules/Page.php
@@ -0,0 +1,159 @@
+name=$name;
+ $this->basedir="content/pages/$name/";
+ $this->meta=Conjuro::loadJson(self::filePath("page.json"));
+ if(!isset($this->meta["title"]))
+ $this->meta["title"]=$conf["site-title"];
+ if(!isset($this->meta["layout"]))
+ $this->meta["layout"]=$conf["default-layout"];
+ // Sections
+ if (isset($this->meta["sections"])){
+ $this->c_header=$this->meta["sections"]["header"];
+ $this->c_body=$this->meta["sections"]["body"];
+ $this->c_footer=$this->meta["sections"]["footer"];
+ }
+ if ($this->c_header===NULL)
+ $this->c_header=[$conf["default-header"]];
+ if ($this->c_body==NULL)
+ $this->c_body=[];
+ if ($this->c_footer===NULL)
+ $this->c_footer=[$conf["default-footer"]];
+ }
+
+ // Renders an entire section
+ private function showSection($secc){
+ foreach($secc as $i => $v){
+ $this->showFragment($v);
+ }
+ }
+
+ // META:TITLE
+ protected function getTitle(){
+ return $this->meta["title"];
+ }
+ // META:LAYOUT
+ protected function getLayoutFile(){
+ return "content/layout/".$this->meta["layout"].".php";
+ }
+ // META:NAME
+ protected function getName(){
+ return $this->name;
+ }
+
+ // Renders a fragmet (but in child class context)
+ abstract protected function showFragment($name);
+
+ // Returns the path of a file relative to page
+ protected function filePath($file){
+ if ($file=="")
+ return "";
+ if ($file[0]=="#"){
+ $fl=substr($file,1);
+ return "content/common/$fl";
+ }
+ return $this->basedir.$file;
+ }
+
+ // Renders the header
+ protected function renderHeader(){
+ self::showSection($this->c_header);
+ }
+
+ // Renders the body
+ protected function renderBody(){
+ self::showSection($this->c_body);
+ }
+
+ // Renders the footer
+ protected function renderFooter(){
+ self::showSection($this->c_footer);
+ }
+
+ public function needSession(){
+ return isset($this->meta["auth"]);
+ }
+
+ public function auth(){
+
+ }
+}
+
+class Page extends PageBase{
+
+ // Renders the page
+ public function showPage(){
+ include(self::getLayoutFile());
+ }
+
+ // Renders a fragment
+ protected function showFragment($name){
+ include self::filePath($name.".php");
+ }
+
+}
+
+return new class($conf) extends Module{
+
+ private $pages=[];
+ private $page="";
+
+ // Render current page
+ public function showPage(){
+ $this->processRequest();
+ $page=$this->getPage($this->currentPage());
+ if ($page->needSession() && !$_SESSION['user']){
+ $page=$this->getPage($this->conf["login-page"]);
+ }
+ $page->showPage();
+ }
+
+ //Loads page meta from page name (id)
+ private function getPage($name){
+ if (!isset($this->pages[$name]))
+ $this->pages[$name]=new Page($name,$this->conf);
+ return $this->pages[$name];
+ }
+
+ private function processRequest(){
+ // Current page
+ if (isset($_GET["page"]))
+ $this->page=$_GET["page"];
+ else if (isset($_SESSION["page"]))
+ $this->page=$_SESSION["page"];
+ else
+ $this->page=$this->conf["index-page"];
+ $_SESSION["page"]=$this->page;
+ // Session
+ if ($_POST['user'])
+ $_SESSION['user']=$this->doLogin($_POST['user'],$_POST['pwd']);
+ else if ($_SESSION['user']) // refresh user data
+ $_SESSION['user']=$this->db->selectOne('users',null,'where user=?','s',$_SESSION['user']['user']);
+ if ($_GET['logout']=='yes')
+ session_reset();
+ }
+
+ private function doLogin($user,$access){
+ return $this->db->selectOne("users",null,'where user=? and pass=sha1(?)','ss',$user,$access);
+ }
+
+ // Get current selected page
+ private function currentPage(){
+ return $this->page;
+ }
+
+ public function init(){
+ $this->register("showPage",function(){
+ $this->showPage();
+ });
+ }
+}
+?>
\ No newline at end of file
diff --git a/index.php b/index.php
index 64edbd1..81a8ae1 100644
--- a/index.php
+++ b/index.php
@@ -5,10 +5,10 @@
include_once "Conjuro/Conjuro.php" ;
session_start();
- //c()->showPage();
- //M("Page")->call("showPage");
- //M("Page")->showPage();
- //M("Builder")->call("edit","index");
- c()->control("pollas")->render();
+ M("Page")->call("showPage");
+ /*
c()->control("html")->render(["html"=>"Hola caracola
"]);
+ var_dump(c()->listControls());
+ c()->control("builder")->render(,["page"=>"index"]);
+ */
?>
\ No newline at end of file