commit 87ceb2a0dd97cbbdd235bc7db27b29290c33956c Author: Dan Ponte Date: Sun Nov 6 10:48:21 2011 -0500 initial import diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..bdd0208 --- /dev/null +++ b/COPYING @@ -0,0 +1,31 @@ +PurpleInk v0.1-ALPHA + +Copyright (c) 2011, Dan Ponte +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the author nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/DB b/DB new file mode 100644 index 0000000..afbb690 --- /dev/null +++ b/DB @@ -0,0 +1,76 @@ +Master database layout: + +collection sites +{ + { + _id: sitename, + dbname: (string), + } +} + +Site database layout: + +collection settings +{ + { + _id: (string)property_name, + value: object + } +} + +collection users +{ + { + _id: (string)Username, + passwd: (md5) + } +} + +collection templates +{ + { + _id: (MongoID), + name: (string), + theme: (string), + type: (int) enum { page, include, iter }, + notes: (text), + body: (Twig code) + } +} + +collection versions +{ + { + _id: (MongoID), + page: (MongoID)pages._id, + version: (int), /* yes, it's a copy of body.version. we know. */ + body: embed pages.body + } +} + +collection pages +{ + { + _id: (MongoID), + parent: ObjectID, + path: (string), + template: (string)templatename, + order: (int), + display: (bool), + disable: (bool), + access: { /* possibly not implemented */ + owner: users._id, + read_acl: { /* user's _ids, or '@group' */ }, + write_acl: { /* same as read_acl */ }, + }, + body: { + title: (string), + author: users._id, + content: (text), + version: (int), + uattr: /* user defined attributes */ { + blahblahblah: blah + } + } + } +} diff --git a/README b/README new file mode 100644 index 0000000..2bc1e21 --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +purpleInk. (C)2011 Dan Ponte. +This is a CMS written in PHP that uses MongoDB. It also uses Twig as its templating engine. diff --git a/index.php b/index.php new file mode 100644 index 0000000..50d882a --- /dev/null +++ b/index.php @@ -0,0 +1,59 @@ +rend(isset($_REQUEST['path']) ? $_REQUEST['path'] : '/'); +} catch(Exception $e) { + echo '
';
+	die(print_r($e, 1));
+}
+
+$e_time = microtime(true);
+
+$runtime = $e_time - $st_time;
+
+header('X-RunTime: ' . round($runtime, 7) . 's');
+ob_end_flush();
+
+?>
diff --git a/src/adm.php b/src/adm.php
new file mode 100644
index 0000000..300e729
--- /dev/null
+++ b/src/adm.php
@@ -0,0 +1,10 @@
+outputTreeUL();
+?>
diff --git a/src/c.AdminView.php b/src/c.AdminView.php
new file mode 100644
index 0000000..5e13080
--- /dev/null
+++ b/src/c.AdminView.php
@@ -0,0 +1,65 @@
+DB = DBConnectorFactory::create();
+		$this->tree = TreeGrove::create();
+		$this->tree->makeTree();
+		
+	}
+	
+	private function ulRec($t)
+	{
+		echo "\n";
+	}
+
+	public function outputTreeUL()
+	{
+		$this->ulRec($this->tree);
+	}
+}
diff --git a/src/c.DB.php b/src/c.DB.php
new file mode 100644
index 0000000..c472e4f
--- /dev/null
+++ b/src/c.DB.php
@@ -0,0 +1,118 @@
+m = new Mongo;
+		} catch (MongoConnectionException $e) {
+			die('Error connecting to DB');
+		}
+		$this->mast_db_name = Config::get('mast_db_name');
+		$mast_db_name = $this->mast_db_name;
+		$this->master = $this->m->$mast_db_name;
+		$this->siteSelected = false;
+	}
+
+	public function selectSite($siteID)
+	{
+		$site = $this->master->sites->findOne(array('_id' => $siteID));
+		if(count($site) === 0) {
+			throw new Exception('No such site');
+		}
+		$site = $site['dbname'];
+		$site = $this->m->$site;
+		$this->site = $site;
+		$this->siteSelected = true;
+		$this->cSettings = $this->site->settings;
+		$this->cUsers = $this->site->users;
+		$this->cTemplates = $this->site->templates;
+		$this->cVersions = $this->site->versions;
+		$this->cPages = $this->site->pages;
+	}
+
+	public function getTplByName($name)
+	{
+		$rt = $this->cTemplates->findOne(array('name' => $name));
+		return $rt['body'];
+	}
+
+	public function getPageByPath($path)
+	{
+		if(!$this->siteSelected) {
+			throw new Exception('No site selected');
+		}
+
+		return ar2ob($this->cPages->findOne(array('path' => $path)));
+	}
+
+	public function getPagesByParent($parent)
+	{
+		return $this->cPages->find(array('parent' => new MongoID($parent)));
+	}
+}
+
+class DBConnectorFactory
+{
+	private static $_inst;
+
+	public static function create()
+	{
+		if(!isset(self::$_inst)) {
+			self::$_inst = new DBConnector;
+		}
+
+		return self::$_inst;
+	}
+}
+
+?>
diff --git a/src/c.Page.php b/src/c.Page.php
new file mode 100644
index 0000000..0731a5a
--- /dev/null
+++ b/src/c.Page.php
@@ -0,0 +1,65 @@
+DB = DBConnectorFactory::create();
+		if(is_string($path)) {
+			$pd = $this->DB->getPageByPath($path);
+		} else {
+			$pd = $path; /* load directly from object */
+		}
+		$this->body = $pd->body;
+		if($twig === NULL) {
+			$twig = TwigFact::create();
+		}
+		$this->T = $twig;
+		$this->templ = $pd->template;
+	}
+
+	public function render()
+	{
+		echo $this->T->render($this->templ, array('Page' => $this->body));
+	}
+}
+?>
diff --git a/src/c.PurpleInk.php b/src/c.PurpleInk.php
new file mode 100644
index 0000000..a2b94d5
--- /dev/null
+++ b/src/c.PurpleInk.php
@@ -0,0 +1,114 @@
+DB = DBConnectorFactory::create();
+	}
+
+	public function getSource($name)
+	{
+		return $this->DB->getTplByName($name);
+	}
+
+	public function getCacheKey($name)
+	{
+		return $name;
+	}
+
+	public function isFresh($name, $time)
+	{
+		return false;
+	}
+}
+
+class TwigFact
+{
+	static public $_inst;
+	static public $_twl;
+
+	static public function create()
+	{
+		if(!isset(self::$_inst)) {
+			self::$_twl = new Twig_Loader_PurpleInk;
+			self::$_inst = new Twig_Environment(self::$_twl, array(
+				));
+		}
+		return self::$_inst;
+	}
+
+	static public function getTwl()
+	{
+		if(!isset(self::$_twl)) {
+			self::create();
+		}
+		return self::$_twl;
+	}
+}
+
+
+class PurpleInk
+{
+	protected $DB;
+	protected $twLoad;
+	protected $T;
+
+	function __construct($site)
+	{
+		$this->DB = DBConnectorFactory::create();
+		$this->DB->selectSite($site);
+		$this->T = TwigFact::create();
+		$this->twLoad = TwigFact::getTwl();
+	}
+
+	function rend($path)
+	{
+		$page = new Page($path, $this->T);
+		$tr = TreeGrove::create();
+		$tr->makeTree();
+		$page->render();
+	}
+}
+
+?>
diff --git a/src/c.Tree.php b/src/c.Tree.php
new file mode 100644
index 0000000..2454636
--- /dev/null
+++ b/src/c.Tree.php
@@ -0,0 +1,93 @@
+byPath[$tree->path] = &$tree;
+		$this->byID[$id] = &$tree;
+		$pwp = $this->DB->getPagesByParent($id);
+		if($pwp->count() > 0) {
+			foreach($pwp as $c) {
+				$id = (string)$c['_id'];
+				$tree->children[$id] = new Page(ar2ob($c));
+				$node = &$tree->children[$id];
+				$node->parent = &$tree;
+				$node->path = $c['path'];
+				$this->recTree($id, $node);
+			}
+		}
+	}
+
+	public function makeTree()
+	{
+		$pgs = $this->DB->getPageByPath('/');
+		$this->tree = (Object) array(
+				'path' => '/',
+				'id' => (string)$pgs->_id,
+				'children' => array()
+				);
+		$this->recTree((string)$pgs->_id, $this->tree);
+	}
+
+	public function __construct()
+	{
+		$this->DB = DBConnectorFactory::create();
+		
+	}
+
+	
+}
+
+class TreeGrove
+{
+	private static $_inst;
+
+	public static function create()
+	{
+		if(!isset(self::$_inst)) {
+			self::$_inst = new Tree;
+		}
+
+		return self::$_inst;
+	}
+}
+
diff --git a/src/purpleink.php b/src/purpleink.php
new file mode 100644
index 0000000..929b587
--- /dev/null
+++ b/src/purpleink.php
@@ -0,0 +1,60 @@
+ 'purp_master'
+		);
+	}
+
+	static public function get($t)
+	{
+		return self::$config[$t];
+	}
+}
+
+Config::setvars();
+
+require_once 'Twig/Autoloader.php';
+Twig_Autoloader::register();
+
+require_once 'util.php';
+
+require_once 'c.PurpleInk.php';
diff --git a/src/util.php b/src/util.php
new file mode 100644
index 0000000..68d17b9
--- /dev/null
+++ b/src/util.php
@@ -0,0 +1,61 @@
+ $v) {
+		if(is_array($v) && !isVect($v)) {
+			$o->$k = ar2ob($v);
+		} else {
+			$o->$k = $v;
+		}
+	}
+
+	return $o;
+*/
+	return (Object)$ar;
+}