initial import

This commit is contained in:
Dan Ponte 2011-11-06 10:48:21 -05:00
commit 87ceb2a0dd
12 changed files with 754 additions and 0 deletions

31
COPYING Normal file
View File

@ -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.

76
DB Normal file
View File

@ -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
}
}
}
}

2
README Normal file
View File

@ -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.

59
index.php Normal file
View File

@ -0,0 +1,59 @@
<?php
/*
* PurpleInk - index.php - main index file
*
* 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.
*/
$st_time = microtime(true);
ob_start();
include 'src/purpleink.php';
try {
$pink = new PurpleInk('theamigan');
$pink->rend(isset($_REQUEST['path']) ? $_REQUEST['path'] : '/');
} catch(Exception $e) {
echo '<pre>';
die(print_r($e, 1));
}
$e_time = microtime(true);
$runtime = $e_time - $st_time;
header('X-RunTime: ' . round($runtime, 7) . 's');
ob_end_flush();
?>

10
src/adm.php Normal file
View File

@ -0,0 +1,10 @@
<?php
require_once 'purpleink.php';
require_once 'c.AdminView.php';
$pink = new PurpleInk('theamigan');
$a = new AdminView;
$a->outputTreeUL();
?>

65
src/c.AdminView.php Normal file
View File

@ -0,0 +1,65 @@
<?php
/*
* PurpleInk - c.AdminView.php - admin view
*
* 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.
*/
Class AdminView
{
private $DB;
private $tree;
public function __construct()
{
$this->DB = DBConnectorFactory::create();
$this->tree = TreeGrove::create();
$this->tree->makeTree();
}
private function ulRec($t)
{
echo "<ul class='treetop'> p='" . $t->tree->path . "'\n";
foreach($t->tree->children as $i) {
echo "<li>\n";
$this->ulRec($i);
echo "</li>\n";
}
echo "</ul>\n";
}
public function outputTreeUL()
{
$this->ulRec($this->tree);
}
}

118
src/c.DB.php Normal file
View File

@ -0,0 +1,118 @@
<?php
/*
* PurpleInk - c.DB.php - database interface
*
* 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.
*/
interface iDBConnector
{
public function selectSite($siteID);
public function getPageByPath($path);
public function getTplByName($name);
public function getPagesByParent($id);
}
class DBConnector implements iDBConnector
{
private $m; /* MongoDB handle */
private $master, $site; /* Databases */
private $useMaster;
private $siteSelected, $mast_db_name;
private $cSettings, $cUsers, $cTemplates, $cVersions, $cPages; /* site collections */
public function __construct()
{
try {
$this->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;
}
}
?>

65
src/c.Page.php Normal file
View File

@ -0,0 +1,65 @@
<?php
/*
* PurpleInk - c.Page.php - Page class
*
* 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.
*/
class Page
{
private $DB;
private $body;
private $templ;
private $T;
public function __construct($path, Twig_Environment $twig = NULL)
{
$this->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));
}
}
?>

114
src/c.PurpleInk.php Normal file
View File

@ -0,0 +1,114 @@
<?php
/*
* PurpleInk - c.PurpleInk.php - main PurpleInk class
*
* 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.
*/
require_once 'c.DB.php';
require_once 'c.Page.php';
require_once 'c.Tree.php';
class Twig_Loader_PurpleInk implements Twig_LoaderInterface
{
private $DB;
public function __construct()
{
$this->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();
}
}
?>

93
src/c.Tree.php Normal file
View File

@ -0,0 +1,93 @@
<?php
/*
* PurpleInk - c.Tree.php - tree
*
* 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.
*/
Class Tree
{
private $DB;
public $tree;
private $byPath, $byID;
public function recTree($id, &$tree)
{
$this->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;
}
}

60
src/purpleink.php Normal file
View File

@ -0,0 +1,60 @@
<?php
/*
* PurpleInk - purpleink.php - main PurpleInk include and configuration
*
* 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.
*/
class Config
{
static private $config;
static public function setvars()
{
self::$config = Array(
'mast_db_name' => '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';

61
src/util.php Normal file
View File

@ -0,0 +1,61 @@
<?php
/*
* PurpleInk - util - util functions
*
* 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.
*/
function cbReduceNotArray($a, $b)
{
return ($b === $a ? $a + 1 : 0);
}
function isVect($arr)
{
return (0 !== array_reduce(array_keys($arr), 'cbReduceNotArray', 0));
}
function ar2ob($ar)
{
/*
$o = new stdClass;
foreach($ar as $k => $v) {
if(is_array($v) && !isVect($v)) {
$o->$k = ar2ob($v);
} else {
$o->$k = $v;
}
}
return $o;
*/
return (Object)$ar;
}