Programmation PHP/Exemples/MiniCMS/Premier noyau
Nous préparons la première version de notre solution myTinyCMS. Comme nous sommes nominal pour les quatre phases, myTinyCMS permets :
- [1] De gérer les données
- [2] De gérer les utilisateurs
- [3] De gérer un frameset complexe
- [4] D'effectuer des mouvements par son webservice
La première intégration ou version 1 de notre noyau consistera en des contrôleurs de test préfigurant la première beta de myTinyCMS.
L'objectif de ce contrôleur est d'intégrer le frameset sur trois thèmes :
- [1] authentification
- [2] lecture / écriture contenu
- [3] navigation
- [4] gestion de contenu
Le contenu sera géré directement sur le frameset par défaut. Backoffice et Frontoffice étant distingué par le switch Mod||Adm vs Usr, déverrouillant les contrôles de gestion et d'encodage.
Fonctionnellement le noyau présente deux phase d'affichage :
- La première serveur vers client (output total du frameset)
- La seconde cliente appelant l'injection dans les containers
Le Second noyau
modifierMyTinyCMS est maintenant un mini content manager system orienté wiki. L'orientation du CMS génère le code métier suivant
Classes
modifierClasses/contentPane.class.php regroupe les flux d'entrée et sortie comme les menus. Il est spécialisé pour notre solution. Le code peut être amélioré.
<?php
class contentPane
/*
* this class contains the mod menu treats
*/
{
public $data ;
public function setFeed()
/*
* only letters and numbers can be placed in data feed name data["abc.."]
*/
{
$this->data["menuPane"] = '
<div class="panel">
<span onclick="showHide($(\'cMenu\'),1);collapse(this);" class="click">[+]</span>
<span id="cMenu" class="click"> <a href="'.$_SERVER['PHP_SELF'].'?entry='.(@$_REQUEST["entry"]?$_REQUEST["entry"]:'Dummy').'&crop=1">!.crop</a> | <a href="'.$_SERVER['PHP_SELF'].'?entry='.(@$_REQUEST["entry"]?$_REQUEST["entry"]:'Dummy').'&page=1">!.page</a>
<p />
<form action="" method="post" name="form1">
{{loginPane}}
</form>
{{cropPane}}
{{userPane}}
{{pagePane}}
</span>
</div>
' ;
$this->data["loginPane"] = '
<span onclick="showHide($(\'loginPane\'),2);">:: Login Pane ::</span>
<span>
<div>
<input id="iLogin" name="iLogin" type="text" value=" " style="width:96%;" /><br/>
<input id="iButton" type="submit" value="log on" style="width:100%;" />
</div>
</span>
' ;
}
public function setTagFeed($pTag,$pFeed)
{
$this->data[$pTag] = $pFeed ;
}
public function contentPane()
{
$this->init();
}
public function placePane()
{
preg_match_all('/{{[a-z0-9A-Z]*}}/',$this->data["menuPane"],$matches) ;
foreach($matches[0] as $v)
{
$v = str_replace(array('{','[','}',']'),array('',' ','',''),$v);
if(!$this->special($v))
{
$this->data["menuPane"] = preg_replace('/{{'.$v.'}}/',@$this->data[$v],$this->data["menuPane"]) ;
}
}
}
public function special($pTag)
{
return false ;
}
public function tagReserved()
{
switch (true)
{
case (isset( $_SESSION["autho"]['credit'])) :
$this->data["loginPane"] = "<div>
<br/>
<input type='submit' value='unlog' name='iUnlog' style='width:96%;' />
</div>" ;
# CROP PANE
// set the crop list
$cropList = getFileList($_SESSION["path"] . "/Contents") ;
$this->data["cropPane"] = "<p/><div class='dark' onclick='showHide($(\"cCropPane\"),1)' style='cursor:pointer;'>:: Crop pane ::</div><p/><div id='cCropPane'>" ;
foreach($cropList as $v)
{
$this->data["cropPane"] .= '<a href="
' . ($_SERVER["PHP_SELF"]) . '?entry=' . @$_REQUEST["entry"] . '&crop=' . $v . '">' . $v . '</a><br />' ;
}
$this->data["cropPane"] .= "</div>" ;
# USER PANE
$this->data["userPane"] = "<p/><a href='".$_SERVER['PHP_SELF']."?entry=".$_REQUEST['entry']."&user=1'>[ users ]</a> ";
# PAGE PANE
$this->data["pagePane"] = "<a href='".$_SERVER['PHP_SELF']."?entry=".$_REQUEST['entry']."&page=1'>[ pages ]</a>";
break ;
}
}
public function getNewCrop()
{
return "
<script>
function saveNewCrop()
{
var tab = $('cCropId').value
+ '~~'
+$('cTopic').value
+'~~'
+$('cScope').value;
new Ajax.Request('./main.php',
{
method:'get',
parameters:'qry=22&value=' + tab + '&owner=" . $_REQUEST["entry"] . "',
onSuccess: function(transport)
{
$('cComCrop').innerHTML = transport.responseText ;
},
onFailure: function(){ }
});
}
</script>
<div class='bottomTool' style=''>
<form action='' method='post' name='frm2'>
<div onclick='showHide($(\"cCropPanel\"));collapse(this);' class='click'>[_]</div>
<div id='cCropPanel'>
<table width='600'>
<tr>
<td width='50'>Id</td>
<td width='500'>
<input type='text' value='' class='encoder' id='cCropId'/>
</td>
</tr>
<tr>
<td>Topic</td>
<td><input class='encoder' id='cTopic' type='text' value='' /></td>
</tr>
<tr>
<td>Scope</td>
<td><input class='encoder' id='cScope' type='text' value=''/></td>
</tr>
<tr>
<td colspan='2'>
<p><span class='specButton' onclick='saveNewCrop();/* location.href=\"".($_SERVER['PHP_SELF'].'?'."entry=".$_REQUEST['entry'])."\";*/'><b>[ save ]</b></span> <span id='cComCrop' class='green'></span></p>
<td>
</tr>
</table>
</div>
</div>
</form>
";
}
public function getCropPane($pCrop)
{
$this->getFieldList("field",$pCrop) ;
// set crop dropdownlist
$lst = "<select>" ;$i=1;
foreach($this->data["list"] as $k=>$v)
{
$lst .= "<option value='".$i++."'></option>" ;
}
$lst .= "</select>" ;
return "
<script>
function setNodes(pNode)
{
var dataNodes = _.oa.getNodesWithId(pNode,'|');
for(i=0;i<dataNodes.length;i++)
{
var dataContent = reformat(dataNodes[i].innerHTML);
new Ajax.Request('./main.php',
{
method:'post',
parameters:'qry=30&id='+dataNodes[i].id+'&owner='+$('customerName').value+'&data='+dataContent+'&key='+$('userKey').value,
onSuccess: function(trs)
{
$('cComCrop').innerHTML = trs.responseText;
},
onFailure:function() {}
});
}
}
function getCropContent(itemValue,cropName)
{
new Ajax.Request('./main.php',
{
method:'get',
parameters:'qry=15&item=' + itemValue + '&crop=' + cropName,
onSuccess: function(transport)
{
var nfo = segment(transport.responseText) ;
$('cTextSubject').value = nfo[0] ;
$('cTextContent').value = nfo[1] ;
},
onFailure: function(){ }
});
}
function saveNewItemCrop()
{
var tab = $('cCropSelect').value+'~~'+$('cCropId').innerHTML
+ '~~'
+$('cTopic').value
+'~~'
+$('cScope').value
+'~~'
+$('cTextSubject').value
+'~~'
+$('cTextContent').value ;
new Ajax.Request('./main.php',
{
method:'get',
parameters:'qry=21&owner='+$('customerName').value+'&value=' + tab,
onSuccess: function(transport)
{
$('cComCrop').innerHTML = transport.responseText ;
},
onFailure: function(){ }
});
}
function saveCropItem()
{
var tab = $('cCropSelect').value+'~~'+$('cCropId').innerHTML
+ '~~'
+$('cTopic').value
+'~~'
+$('cScope').value
+'~~'
+$('cTextSubject').value
+'~~'
+reformat($('cTextContent').value);
new Ajax.Request('./main.php',
{
method:'get',
parameters:'qry=20&owner='+$('customerName').value+'&value=' + tab,
onSuccess: function(transport)
{
$('cComCrop').innerHTML = transport.responseText ;
},
onFailure: function(){ }
});
}
</script>
<div class='bottomTool' style=''>
<form action='' method='post' name='frm2'>
<div onclick='showHide($(\"cCropPanel\"));collapse(this);' class='click'>[_]</div>
<div id='cCropPanel'>
<table width='600'>
<tr>
<td width='50'>Id</td>
<td width='500' id='cCropId'>".$_REQUEST["crop"]."</td>
</tr>
<tr>
<td>Topic</td>
<td><input class='encoder' id='cTopic' type='text' value='".@$this->data["list"]["topic"]."' /></td>
</tr>
<tr>
<td>Scope</td>
<td><input class='encoder' id='cScope' type='text' value='".@$this->data["list"]["scope"]."'/></td>
</tr>
<tr>
<td>Item</td>
<td>
<select class='encoder' id='cCropSelect' onchange='getCropContent(this.value,\"".$_REQUEST['crop']."\");'>
".getCropOptions($_REQUEST['crop'])."
</select>
</td>
</tr>
<tr>
<td colspan='2'>
<p>:: Crop Item :: <span class='specButton' onclick='saveCropItem()'>[ save</span> | <span class='specButton' onclick='saveNewItemCrop();'>new ]</span>
<span id='cComCrop' class='green'></span>
</p>
<input type='text' value='' id='cTextSubject' class='encoder'/>
<textarea id='cTextContent' rows='10' class='encoder'></textarea>
</td>
</tr>
</table>
</div>
</div>
</form>
";
}
public function getFieldList($pNodeName,$pCrop)
{
$this->data["list"] = getNodeList($pNodeName,$pCrop) ;
}
public function getPagePane( )
{
return "<div class='bottomTool'><span onclick='showHide($(\"cPagePanel\"));collapse(this);' class='click'>[_]</span>
<div id='cPagePanel'><p>:: Page Pane :: </p>
"
. getPagesPanel($_REQUEST["entry"]) .
"
</div>
</div>";
}
public function getUserPane( )
{
$dom = new DOMDocument() ;
$dom->load("./Owners/" . (@$_REQUEST["entry"]?$_REQUEST["entry"] : 'Dummy'). '/Contents/user.xml') ;
$users = $dom->getElementsByTagName("users") ;
$val = "
<script>
function userEdit(pVal)
/*
edit the user line
*/
{
var tab =[] ;
if($('login_'+pVal).innerHTML.substring(0,1) == '<')
{
$('login_'+pVal).innerHTML = tab[0] = $('iLog_'+pVal).value ;
$('pass_'+pVal).innerHTML = tab[1] = $('iPas_'+pVal).value ;
$('forname_'+pVal).innerHTML = tab[2] = $('iFor_'+pVal).value ;
$('lastname_'+pVal).innerHTML = tab[3] = $('iLas_'+pVal).value ;
$('customer_'+pVal).innerHTML = tab[4] = $('iCus_'+pVal).value ;
$('b'+pVal).innerHTML = '[edit]';
new Ajax.Request('./main.php',
{
method:'get',
parameters:'qry=25&item=' + pVal + '&value=' + tab + '&owner=' + $('customerName').value + '&key='+$('userKey').value,
onSuccess: function(transport)
{
$('cComUser').innerHTML = transport.responseText ;
location.href='".($_SERVER['PHP_SELF'].'?'."entry=".$_REQUEST['entry'])."&user=1';
},
onFailure: function(){ }
});
}
else
{
$('login_'+pVal).innerHTML = \"<input id='iLog_\"+pVal+\"' type='text' value='\"+ ($('login_'+pVal).innerHTML) +\"' />\" ;
$('pass_'+pVal).innerHTML = \"<input id='iPas_\"+pVal+\"' type='text' value='\"+ ($('pass_'+pVal).innerHTML) +\"' />\" ;
$('forname_'+pVal).innerHTML = \"<input id='iFor_\"+pVal+\"' type='text' value='\"+ ($('forname_'+pVal).innerHTML) +\"' />\" ;
$('lastname_'+pVal).innerHTML = \"<input id='iLas_\"+pVal+\"' type='text' value='\"+ ($('lastname_'+pVal).innerHTML) +\"' />\" ;
$('customer_'+pVal).innerHTML = \"<input id='iCus_\"+pVal+\"' type='text' value='\"+ ($('customer_'+pVal).innerHTML )+\"' />\" ;
$('b'+pVal).innerHTML = '[save]';
}
}
function saveNew()
{
var tab = [] ;
tab[0] = $('iLogNew').value;
tab[1] = $('iPasNew').value;
tab[2] = $('iForNew').value;
tab[3] = $('iLasNew').value;
tab[4] = $('iCusNew').value;
new Ajax.Request('./main.php',
{
method:'get',
parameters:'qry=26&value=' + tab+ '&owner=' + $('customerName').value +'&key=' + $('userKey').value,
onSuccess: function(transport)
{
$('cComUser').innerHTML = transport.responseText ;
location.href='".($_SERVER['PHP_SELF'].'?'."entry=".$_REQUEST['entry'])."&user=1';
$('new').innerHTML = '';
},
onFailure: function(){ }
});
;
}
function addUser()
{
$('new').innerHTML = '<p/><table width=\"600\"><tr class=\"title\"><td onclick=\"saveNew();\" class=\"specButton\"><b>[save]</b></td><td><input type=\"text\" id=\"iLogNew\"/></td><td><input type=\"text\" id=\"iPasNew\"/></td><td><input type=\"text\" id=\"iForNew\"/></td><td><input type=\"text\" id=\"iLasNew\"/></td><td><input type=\"text\" id=\"iCusNew\"/></td></tr></table><p/>' ;
}
</script>
<table width='600'>
<tr class='title'><td/>
<td>login</td>
<td>pass</td>
<td>lastname</td>
<td>forename</td>
<td>customer</td>
</tr>" ;
$i = 0;
foreach($users->item(0)->childNodes as $v)
{
if($v->nodeType != XML_TEXT_NODE)
{
if(isset($_SESSION['autho']['admin']))
{
$val .= "<tr>
<td onclick='userEdit(".$i.");'><b id='b".$i."' class='specButton'>[edit]</b></td><td id='login_".$i."'>" . trim($v->getAttribute("login")) . "</td><td id='pass_".$i."'>" . trim($v->getAttribute("pass")) . "</td><td id='lastname_".$i."'>" . trim($v->getAttribute("lastname")) . "</td><td id='forname_".$i."'>" . trim($v->getAttribute("forname")) . "</td><td id='customer_".$i."'>" . trim($v->getAttribute("customer")) ."</td>
</tr>" ;
}
}
$i++;
}
if(!isset($_SESSION['autho']['admin']))
$val .= "<tr><td colspan='5'>You're not authorized to modify the privileges</td></tr>";
$val .= "</table>";
return "<div class='bottomTool'>" . $val . "<hr /><div id='new'></div><span class='specButton' onclick='addUser();'>[add user]</span> <span id='cComUser' class='green'></span></div>";
}
public function init()
{
$this->setFeed() ;
$this->tagReserved() ;
$this->placePane() ;
}
}
# Ouput
$_container["content"] = new contentPane() ;
?>
Voici Classes/dataManager.class.php dans sa version finale. Il est orienté données.
<?php
class dataManager
{//
private $pattern;
protected $stack;
//
public
$domDoc,
$crop
= array(
"std"=> '<?xml version="1.0" encoding="UTF-8"?>
<crop><topic /><fields /></crop>'
,""=>''
),
$data
= array(
"root"=>"./Owners/"
);
# TODO GETTER/SETTER
public function setDocument($pPath)
{
$this->domDoc->load( $pPath );
}
public static function getNodeByData($pData)
/**
* get the content from data
*/
{
$res = xpathExtension::getNodes($this->domDoc, $pXPath);
return $res['content'];
}
public function dispatch($pData)
/**
* switch direction by value
*/
{
}
public static function getContentByData($pDocument, $pData)
/**
* get the content from data
*/
{
if(@$pData['attribute'])
{
return utilities::searchNodesByAttribute($pDocument, $pData) ;
}
else
{
return utilities::searchNodesByContent($pDocument, $pData) ;
}
}
public function setContentByData($pDocument,$pData)
/**
* set the content to data
*/
{
if(@$pData['attribute'])
{
utilities::writeContentByAttribute($pDocument, $pData) ;
}
else
{
utilities::writeContentByContent($pDocument, $pData) ;
}
$this->saveDocument();
}
public static function setCropForCustomer($pPath, $pCrop)
/**
* set crop to customer directory
*/
{
file_put_contents($pPath, trim($pCrop));
}
# STATE
public function dataManager()
{
$this->initialize();
}
public function initialize()
/**
* init
*/
{
$this->domDoc = new DOMDocument();
if(@$this->data['path'])
{
$this->domDoc->load( $this->data['path'] );
}
return $this->domDoc;
}
public function saveDocument()
/**
* save document
*/
{
$this->domDoc->save($this->data['path']) ;
}
}
?>
Voici le Classes/templateControler.class.php orienté layout.
<?php
class templateControler
{
/**
* Control the templates
*
* @var (mixed) ($domDoc, $data, $stack)
*/
//
private $pattern
= array(
'inc'=>'/{{inc:[a-zA-Z]*[\[\]\*a-zA-Z]*}}/' // inclusion patterns
,''=>''
);
protected $domDoc, $stack;
//
public $data;
/*
public function __construct()
{//
$this->domDoc = new DOMDocument();
$this->initialize();
}
*/
/**
* Enter description here...
*
* @param unknown_type $pVar
* @return templateControler
*/
public function templateControler($pVar)
{
$this->domDoc = new DOMDocument();
$this->setter($pVar);
$this->initialize();
}
/**
* Enter description here...
*
* @param unknown_type $pVar
*/
public function setter($pVar)
{//
$this->data = $pVar;
}
// TODO GETTER
public function initialize()
{//
$this->domDoc->load( $this->data['path'] );
}
public function initFrame($pDomValue)
/**
*
*/
{//
$this->data['frameset'] = trim($pDomValue[0]->nodeValue) ;
}
/**
* Enter description here...
*
*/
public function getNode($pXPath)
{//
$this->data['feed'] = utilities::getNodes($this->domDoc, $pXPath);
return $this->data['feed'];
}
/**
* getContent retourne le contenu du/des nœuds demandés
*
* > (nodeName, nodeId) - (string) >
*/
public function getContent($nodeName,$nodeId)
{//
// set expression
$_expr = "//" . $nodeName . ($nodeId&&$nodeId!='*'?"[@id='$nodeId']":"");
$set = $this->getNode($_expr);
$content=null;
if($set)
foreach($set as $k=>$v)
{
$content .= "\r\n" . ($v->nodeValue)."\r\n" ;
}
return $content?$content:"";
}
/**
* replace anchor by content
*/
public function anchorContentReplacer()
{//
$i=0;
foreach($this->data['result'][0] as $k=>$v)
{
// formatting anchor's syllabes
$v = str_replace(array('{','[','}',']'),array('',' ','',''),$v);
$tmp = explode(":",$v);$_ = explode(' ',$tmp[1]);
// replacing
$this->data['result'][0][$i++] = array("node"=>$_[0],"value"=>$this->getContent($_[0], @$_[1]),"id"=>@$_[1]);
}
}
public function setTag($pAnchor,$pValue)
/**
* put the frameset out
*/
{
$this->data['frameset'] = preg_replace('/{{inc:' . $pAnchor . '}}/',$pValue, $this->data['frameset'] ) ;
}
public function setFrame()
/**
* put the frameset out
*/
{
foreach($this->data['result'][0] as $v)
{
if( $v['node'] != 'page' || isset($_REQUEST['admin']))
$this->data['frameset'] = preg_replace('/{{inc:' . $v['node'] . '[\[\]\*'.$v['id'].']*}}/', $v['value'], $this->data['frameset'] ) ;
else
{
$this->data['frameset'] = preg_replace('/{{inc:' . $v['node'] . '[\[\]\*'.$v['id'].']*}}/', getPage(@$_REQUEST['page']?$_REQUEST['page']:$v['id']), $this->data['frameset'] ) ;
}
}
}
public function getAnchors($pFeed)
{//
preg_match_all($this->pattern['inc'], $pFeed, $this->data['result']);
return $this->data['result']; // on prefere les données centralisées dans la classe
}
public function publicTemplate()
{//
return $this->domDoc->saveXML();
}
}
?>
Classes/utilities.class.php dans sa version finale
<?php
class utilities
{
public static function getNodes($pDomDoc, $pXpathString)
/**
* get the node from DomDoc with XpathString
*/
{
$xp = new DOMXPath($pDomDoc);
$xp->registerNamespace('x', 'http://www.w3.org/1999/xhtml');
$xp->registerNamespace('xhtml', 'http://www.w3.org/1999/xhtml');
$xp->registerNamespace('i18n', 'http://apache.org/cocoon/i18n/2.1');
$ret = array();
$nodes = $xp->query($pXpathString);
foreach ($nodes as $node)
{
array_push($ret, $node);
}
return count($ret)?$ret:false;
}
public static function isContent($pPattern, $pFeed)
/**
* check is pattern in feed
*/
{
return preg_match('/('.$pPattern.')/',$pFeed)?true:false;
}
public static function searchNodesByContent($pDocument, $pQueries)
/**
* return node matching request by content
*/
{
$_fields = $pDocument->getElementsByTagName('fields'); $i = 0;
// ceci est un exemple de mauvais code de service, il ne fonctionne que pour un nombre limité de structure de crop
// c'est donc un code métier à surcharger.
foreach ($_fields->item(0)->childNodes as $u)
{
if ($u->nodeType != XML_TEXT_NODE)
{
foreach ( $u->childNodes as $v )
{
if( $v->nodeName == $pQueries['node'] && ! utilities::isContent ( $pQueries['value'] , $v->nodeValue ) )
{
@$tab[++$i] = $u ;
}
}
}
}
// removing
if(isset($tab))
foreach($tab as $v)
$_fields->item(0)->removeChild($v) ;
/* DEPRECIEE - Malheureusement, ce code ne marche une fois appelée par getNodes
for($i=0; $i<count($pNodeSet); $i++)
{
$_content = $pNodeSet[$i]->childNodes ;
// cette fonction ne descend qu'à un niveau
foreach($_content as $v)
{
if( $v->nodeName == $pQueries['node'] && ! utilities::isContent ( $pQueries['value'] , $v->nodeValue ) )
{
$pNodeSet[$i]->parentNode->removeChild($pNodeSet[$i]) ;
}
}
}
*/
return $pDocument ;
}
public static function searchNodesByAttribute($pDocument, $pQueries)
/**
* return node matching request by attribute
*/
{
$_fields = $pDocument->getElementsByTagName('fields');$i=0;
// ceci est un exemple de mauvais code de service, il ne fonctionne que pour un nombre limité de structure de crop
// c'est donc un code métier à surcharger.
foreach ($_fields->item(0)->childNodes as $u)
{
if ($u->nodeType != XML_TEXT_NODE)
{
if( !($u->getAttribute($pQueries['attribute']) == $pQueries['value']) ) // 1:1 match
@$tab[++$i] = $u ;
}
}
// removing
if(isset($tab))
foreach($tab as $v)
$_fields->item(0)->removeChild($v) ;
return $pDocument ;
}
public static function getAttributesContents($pNode)
/**
*
*/
{
foreach ($pNode->attributes as $attrName => $attrNode)
{
$_tab[$attrName] = $attrNode->value ;
}
return $_tab ;
}
public static function getLineByAttribute($pDocument, $pQueries)
/**
* return node matching request by attribute
*/
{
$_users = $pDocument->getElementsByTagName('user');
// ceci est un exemple de mauvais code de service, il ne fonctionne que pour un nombre limité de structure de crop
// c'est donc un code métier à surcharger.
foreach ($_users as $u)
{
if ($u->nodeType != XML_TEXT_NODE)
{
$_flg = false ;$i=$j=0;
foreach($pQueries as $_qa )
{
if( ($u->getAttribute($_qa['attribute']) == trim($_qa['value'])) )
{ // 1:1 match
++$j;
} else {
--$j;
}
$i++;
}
if($i==$j)
return utilities::getAttributesContents($u) ;
}
}
return false ;
}
public static function writeContentByContent($pDocument, $pQueries)
/**
* write node content matching request by attribute
*/
{
$_fields = $pDocument->getElementsByTagName('fields');
$_flg = false ;
foreach ($_fields->item(0)->childNodes as $u)
{
if ($u->nodeType != XML_TEXT_NODE)
{
foreach ( $u->childNodes as $v )
{
if( $v->nodeName == $pQueries['node'] && utilities::isContent ( $pQueries['value'] , $v->nodeValue ) )
{
$v->nodeValue = $pQueries['content'] ;
$_flg = true ;
}
}
}
}
return $_flg ;
}
public static function writeContentByAttribute($pDocument, $pQueries)
/**
* write node content matching request by attribute
*/
{
$_fields = $pDocument->getElementsByTagName('fields');
$_flg = false ;
foreach ($_fields->item(0)->childNodes as $u)
{
if ($u->nodeType != XML_TEXT_NODE)
{
if( $u->getAttribute($pQueries['attribute']) == $pQueries['value'] ) // 1:1 match
{
$v = $u->getElementsByTagName($pQueries['node']) ;
$ct = $v->item(0)->ownerDocument->createCDATASection("\n" . $pQueries['replacement'] . "\n");
$v->item(0)->appendChild($ct) ;
$_flg = true ;
}
}
}
if (!$_flg)
// attribute is note set yet
{
$node = $_fields->item(0)->firstChild->nextSibling->cloneNode(true) ;
$_fields->item(0)->appendChild($node) ;
// filling id
$_fields->item(0)->lastChild->setAttribute("id", $pQueries['value']) ;
// filling number
$_fields->item(0)->setAttribute("count", $cpt = ((int)$_fields->item(0)->getAttribute("count"))+1) ;
$_fields->item(0)->lastChild->setAttribute("number", $cpt) ;
utilities::writeContentByAttribute($pDocument, $pQueries) ;
}
return $_flg ;
}
public static function deleteContentByContent($pDocument, $pQueries)
/**
* delete node matching request by attribute
*/
{
$_fields = $pDocument->getElementsByTagName('fields');
$_flg = false ;
foreach ($_fields->item(0)->childNodes as $u)
{
if ($u->nodeType != XML_TEXT_NODE)
{
foreach ( $u->childNodes as $v )
{
if( $v->nodeName == $pQueries['node'] && utilities::isContent ( $pQueries['value'] , $v->nodeValue ) )
{
$_fields->item(0)->removeChild($u) ;
$_flg = true ;
}
}
}
}
return $_flg ;
}
public static function deleteContentByAttribute($pDocument, $pQueries)
/**
* delete node matching request by attribute
*/
{
$_fields = $pDocument->getElementsByTagName('fields');
$_flg = false ;
foreach ($_fields->item(0)->childNodes as $u)
{
if ($u->nodeType != XML_TEXT_NODE)
if( $u->getAttribute($pQueries['attribute']) == $pQueries['value'] ) // 1:1 match
{
$_fields->item(0)->removeChild($u) ;
$_flg = true ;
}
}
return $_flg ;
}
}
?>
Functions
modifierFunctions/common.inc.php dans sa version finale
<?php
/*
common application functiunalities
would be fine to merge all request to requestForData
*/
require_once CLA . "/utilities.class.php" ;
require_once CLA . "/dataManager.class.php" ;
require_once CLA . "/templateControler.class.php" ;
function requestForLayout($pTerm,$pOwner="Root",$pTemplate="default")
/**
* layout request
*/
{
$tmp = new templateControler(array("path"=>"./Owners/" . $pOwner . "/Templates/" . $pTemplate . ".xml")) ;
$node = $tmp->getNode('//page[@id="' . $pTerm . '"]') ;
return $node[0]->nodeValue ;
}
function requestForData($pTerm,$pOwner)
/**
* data request
*/
{
$_lst = explode("|",$pTerm) ;
$_manager = new dataManager() ;
$_manager->data['path'] = $_manager->data['root'] . $pOwner . "/Contents/" . $_lst[0] . ".xml" ; //
$_document = $_manager->initialize() ;
if($_lst[1])
$_manager->data['query_1'] = array("attribute"=>"number", "value"=>$_lst[1]) ;
if($_lst[2])
$_manager->data['query_2'] = array("attribute"=>"id", "value"=>$_lst[2]) ;
$res = dataManager::getContentByData(
dataManager::getContentByData($_document, $_manager->data['query_1'])
,$_manager->data['query_2']) ;
$node = isset($_lst[3]) ? $_lst[3] : "content" ;
$str = $res->getElementsByTagName($node) ;
return $str->item(0)->nodeValue ;
}
function getPagesPanel($pEntry)
{
if( $_SESSION["autho"]["admin"] || $_SESSION["autho"]["moderator"] )
{
$dom = new DOMDocument() ;
$dom->load("./Owners/" . $pEntry . "/Contents/page.xml") ;
$root = $dom->getElementsByTagName("pages");
$str = "
<script>
function pageEdit(pVal)
{
var tab =[] ;
if($('number_'+pVal).innerHTML.substring(0,1) == '<')
{
$('number_'+pVal).innerHTML = tab[0] = $('iNum_'+pVal).value ;
$('id_'+pVal).innerHTML = tab[1] = $('iId_'+pVal).value ;
$('entry_'+pVal).innerHTML = tab[2] = $('iEnt_'+pVal).value ;
$('b'+pVal).innerHTML = '[edit]';
new Ajax.Request('./main.php',
{
method:'get',
parameters:'qry=35&item=' + pVal + '&value=' + tab + '&owner=' + $('customerName').value + '&key='+$('userKey').value,
onSuccess: function(transport)
{
$('cComPage').innerHTML = transport.responseText ;
location.href='".($_SERVER['PHP_SELF'].'?'."entry=".$_REQUEST['entry'])."&page=1';
},
onFailure: function(){ }
});
}
else
{
$('number_'+pVal).innerHTML = \"<input id='iNum_\"+pVal+\"' type='text' value='\"+ ($('number_'+pVal).innerHTML) +\"' />\" ;
$('id_'+pVal).innerHTML = \"<input id='iId_\"+pVal+\"' type='text' value='\"+ ($('id_'+pVal).innerHTML) +\"' />\" ;
$('entry_'+pVal).innerHTML = \"<input id='iEnt_\"+pVal+\"' type='text' value='\"+ ($('entry_'+pVal).innerHTML) +\"' />\" ;
$('b'+pVal).innerHTML = '[save]';
}
}
function saveNewPage()
{
var tab = [] ;
tab[0] = $('iNumNew').value;
tab[1] = $('iIdNew').value;
tab[2] = $('iEntNew').value;
new Ajax.Request('./main.php',
{
method:'get',
parameters:'qry=36&value=' + tab+ '&owner=' + $('customerName').value +'&key=' + $('userKey').value,
onSuccess: function(transport)
{
$('cComPage').innerHTML = transport.responseText ;
location.href='".($_SERVER['PHP_SELF'].'?'."entry=".$_REQUEST['entry'])."&page=1';
$('new').innerHTML = '';
},
onFailure: function(){ }
});
;
}
function addPage()
{
$('new').innerHTML = '<p/><table width=\"600\"><tr class=\"title\"><td onclick=\"saveNewPage();\" class=\"specButton\"><b>[save]</b></td><td><input type=\"text\" id=\"iNumNew\"/></td><td><input type=\"text\" id=\"iIdNew\"/></td><td><input type=\"text\" id=\"iEntNew\"/></td></tr></table><p/>' ;
}
</script>
<table width='600'>
<tr class='title'>
<td/>
<td>number</td>
<td>id</td>
<td>entry</td>
</tr>
";
$i = 0 ;
foreach($root->item(0)->childNodes as $v)
{
if($v->nodeType != XML_TEXT_NODE)
{
@$str .= "<tr><td><span onclick='pageEdit(".$i.");'><b id='b".$i."' class='specButton'>[edit]</b></td><td id='number_".$i."'>". $v->getAttribute("number") . "</td><td id='id_".$i."'>" . $v->getAttribute("id") . "</td><td id='entry_".$i."'>" . $v->getAttribute("entry") . "</td></tr>" ;
}
$i++ ;
}
return $str .= "</table> <hr /><div id='new'></div><span class='specButton' onclick='addPage();'>[add page]</span> <span id='cComPage' class='green'></span>" ;
}
}
function reformat($pContent)
{
$in = array("``i", "``o","``q","``e","``u","``a");
$out = array("=","\"", "?","&","%","#");
return stripslashes(str_replace($in,$out,$pContent)) ;
}
function formatData($pContent)
/**
* data formatter
*/
{
$pContent = reformat($pContent);
$_pattern = '/(\[)([a-zA-Z0-9]*)(:)?([a-zA-Z0-9]*)?(\[)([<>\-(\"\'a-zA-Z0-9:\[\] ]*)(\]\])/' ;
$_manager = new dataManager() ;
// TODO
$_manager->data['path'] = $_manager->data['root'] . "Root/Contents/" . "1.xml"; //$_lst[0] .
$_document = $_manager->initialize() ;
$flg = preg_match($_pattern, $pContent, $_matches )? true: false ;
if ( $flg )
{
// save feed
$_manager->data['query_1'] = array("attribute"=>"id", "value"=>$_matches[4], "node"=>"content",
"replacement"=>$_matches[6]) ;
// query test
$_manager->setContentByData($_document, $_manager->data['query_1']) ;
$_str = preg_replace($_pattern, ("<" . $_matches[2] . " id='".$_matches[4]."'>" . $_matches[6] . "</" . $_matches[2] . ">"), $pContent) ;
} else {
$_str = $pContent ;
}
return $_str ;
}
function getPage($pId)
{
$dom = new DOMDocument() ;
$fileName = "./Owners/" . $_REQUEST['entry'] . '/Contents/page.xml' ;
$dom->load($fileName) ;
$node = $dom->getElementsByTagName("pages") ;
foreach($node->item(0)->childNodes as $v )
if($v->nodeType != XML_TEXT_NODE)
if($v->getAttribute("id") == $pId)
return "<div id='".$v->getAttribute("entry") . "'></div>" ;
}
function getFileList($pPath)
/*
* Lists all the files in a directory
*/
{
$i = 0 ; $lst = "" ;
if (@$handle = opendir($pPath))
while (false !== ($file = readdir($handle)))
{
if ( $file == "." || $file == ".." || preg_match("/page/",$file) || preg_match("/user/",$file) )
{}
else
{
@$lst[@++$i]=$pPath . "/" . $file ;
}
}
return $lst ;
}
function getCropOptions($pDoc)
{
$dom = new DOMDocument();
$dom->load( $pDoc );
$nodes = $dom->getElementsByTagName("fields");
foreach( $nodes->item(0)->childNodes as $v )
{
if($v->nodeType != XML_TEXT_NODE)
@$opt .= "<option value='" . $v->getAttribute("number") . "'>" . $v->getAttribute("number") . " | " . $v->getAttribute("id") . "</option>" ;
}
return $opt ;
}
function getCropItem($pItemValue,$pCrop)
{
$dom =new DOMDocument();
$dom->load($pCrop);
$node = $dom->getElementsByTagName("fields");
foreach( $node->item(0)->childNodes as $v )
{
if($v->nodeType != XML_TEXT_NODE && $v->getAttribute("number") == trim($pItemValue))
{
$subNodes = $v->childNodes ;
foreach($subNodes as $u)
{
if($u->nodeName == "subject")
$tab = $u->nodeValue ;
if($u->nodeName == "content")
$tab .= "~~" . $u->nodeValue;
}
return @$tab ;
}
}
}
function saveCropItem($pValue,$pOwner)
{
$pValue = reformat($pValue) ;
$tab = explode("~~",$pValue) ;
$dom =new DOMDocument();
$dom->load($tab[1]);
$node = $dom->getElementsByTagName("fields");
$topic = $dom->getElementsByTagName("topic");
$topic->item(0)->nodeValue = $tab[2];
$scope = $dom->getElementsByTagName("scope");
$scope->item(0)->nodeValue = $tab[3];
foreach( $node->item(0)->childNodes as $v )
{
if($v->nodeType != XML_TEXT_NODE && $v->getAttribute("number") == $tab[0])
{
try
{
$subNodes = $v->childNodes ;
foreach($subNodes as $u)
{
if($u->nodeName == "subject")
$u->nodeValue = $tab[4] ;
if($u->nodeName == "content")
$u->nodeValue = $tab[5] ;
}
$dom->save($tab[1]);
return "Crop item saved !" ;
}
catch(Exception $ex)
{
return "Error when saving" ;
}
}
}
}
function saveCropNewItem($pValue,$pOwner)
{
$tab = explode("~~",$pValue) ;
$dom =new DOMDocument();
$dom->load($tab[1]);
$_fields = $dom->getElementsByTagName("fields");
$_fields->item(0)->setAttribute("count", $cpt = ((int)$_fields->item(0)->getAttribute("count"))+1) ;
try
{
$node = $dom->createElement("field");
$node->setAttribute("id",$tab[4]) ;
$node->setAttribute("number",$cpt) ;
$subject = $dom->createElement("subject");
$subject->nodeValue=$tab[4];
$content = $dom->createElement("content");
$ct = $content->ownerDocument->createCDATASection("\n" . $tab[5] . "\n");
$content->appendChild($ct);
$node->appendChild($subject) ;
$node->appendChild($content) ;
$_fields->item(0)->appendChild($node) ;
$dom->save($tab[1]);
return "New item saved !" ;
}
catch(Exception $ex)
{
return "Error when saving" ;
}
}
function createCrop($pOwner,$pPath)
{
copy( OWN . "/Root/Dummies/1.xml", $pPath ) ;
return 'One new crop created but without data !';
}
function saveCrop($pOwner, $pId, $pData,$pKey)
{
$pData = reformat($pData) ;
try
{
$tab = explode("|",$pId) ;
$dom =new DOMDocument();
$cropName = './Owners/'.$pOwner.'/Contents/'.$tab[0].".xml" ;
if(is_file($cropName))
{
$dom->load($cropName);
$nodes = $dom->getElementsByTagName("fields") ;
$flg = false;
foreach($nodes->item(0)->childNodes as $v)
{
if($v->nodeType != XML_TEXT_NODE)
{
if($v->getAttribute("number")==@$tab[1])
{
foreach($v->childNodes as $u)
if($u->nodeType != XML_TEXT_NODE && $u->nodeName=="content")
{
$u->nodeValue = $pData ;$flg=true;
}
}
}
}
$dom->save($cropName) ;
return $flg ? 'Crop updated !' : 'Crop missing reference(s) !' ;
} else {
createCrop($pOwner,$cropName) ;
}
}
catch(Exception $ex)
{
return $ex;
}
}
function saveNewCrop($pOwner,$pValue)
{
try
{
$tab = explode("~~",$pValue) ;
if(!is_file('Owners/'.(@$_REQUEST["entry"]?$_REQUEST["entry"]:'Dummy').'/Contents/'.$tab[0]))
{
$dom =new DOMDocument("1.0");
$root = $dom->createElement("fields");
$root->setAttribute("count", 0) ;
$topic = $dom->createElement("topic");
$topic->nodeValue = $tab[1];
$scope = $dom->createElement("scope");
$scope->nodeValue = $tab[2];
$root->appendChild($topic) ;
$root->appendChild($scope) ;
$dom->appendChild($root) ;
$dom->save('./Owners/'.$pOwner.'/Contents/'.$tab[0].".xml");
return "New crop created !" ;
} else {
return "Crop already exists !" ;
}
}
catch(Exception $ex)
{
return "Error when saving" ;
}
}
function saveUser($pOwner,$pValue,$pKey,$pStatus)
{
require_once CLA . "/dataManager.class.php" ;
require_once CLA . "/utilities.class.php" ;
$_manager = new dataManager() ;
//
$_manager->data['path'] = $_manager->data['root'] . $pOwner . "/Contents/user.xml" ; //
$_manager->data['query_1'] = array(
array("attribute"=>"key", "value"=>$pKey)
) ;
$_res = utilities::getLineByAttribute($_manager->initialize(), $_manager->data['query_1']) ;
$flg=false;
if(isset($_res["login"]))
{
$flg = true;
}
$tab = explode(",", $pValue) ;
//TODO
switch ($pStatus)
{
case 1 :
if($flg)
{
$dom = new DOMDocument() ;
$userFile = "./Owners/" . $pOwner . "/Contents/user.xml" ;
$dom->load($userFile) ;
$root = $dom->getElementsByTagName("users");
$i=0;
$nodes = $root->item(0)->childNodes ;
$nodes->item($_REQUEST["item"])->setAttribute("login",$tab[0]) ;
$nodes->item($_REQUEST["item"])->setAttribute("pass",$tab[1]) ;
$nodes->item($_REQUEST["item"])->setAttribute("forname",$tab[2]) ;
$nodes->item($_REQUEST["item"])->setAttribute("lastname",$tab[3]) ;
$nodes->item($_REQUEST["item"])->setAttribute("customer",$tab[4]) ;
$nodes->item($_REQUEST["item"])->setAttribute("key",md5($tab[2])) ;
$dom->save($userFile) ;
return 'User updated';
}else{
return 'Nothing has been done';
}
break;
case 2 :
if($flg)
{
try
{
$dom = new DOMDocument() ;
$userFile = "./Owners/" . $pOwner . "/Contents/user.xml" ;
$dom->load($userFile) ;
$root = $dom->getElementsByTagName("users");
$new = $dom->createElement("user");
$new->setAttribute("login",$tab[0]);
$new->setAttribute("pass",$tab[1]);
$new->setAttribute("forname",$tab[2]);
$new->setAttribute("lastname",$tab[3]);
$new->setAttribute("customer",$tab[4]);
$new->setAttribute("key",md5($tab[2]));
$root->item(0)->appendChild($new);
$dom->save($userFile);
return 'New user add !' ;
}
catch (Exception $ex) {
return $ex ;
}
}else{
return 'Nothing has been done' ;
}
break;
}
}
function savePage($pOwner,$pValue,$pKey,$pStatus)
{
require_once CLA . "/dataManager.class.php" ;
require_once CLA . "/utilities.class.php" ;
$_manager = new dataManager() ;
//
$_manager->data['path'] = $_manager->data['root'] . $pOwner . "/Contents/user.xml" ; //
$_manager->data['query_1'] = array(
array("attribute"=>"key", "value"=>$pKey)
) ;
$_res = utilities::getLineByAttribute($_manager->initialize(), $_manager->data['query_1']) ;
$flg=false;
if(isset($_res["login"]))
{
$flg = true;
}
$tab = explode(",", $pValue) ;
//TODO
switch ($pStatus)
{
case 1 :
if($flg)
{
$dom = new DOMDocument() ;
$pageFile = "./Owners/" . $pOwner . "/Contents/page.xml" ;
$dom->load($pageFile) ;
$root = $dom->getElementsByTagName("pages");
$i=0;
$nodes = $root->item(0)->childNodes ;
$nodes->item($_REQUEST["item"])->setAttribute("number",$tab[0]) ;
$nodes->item($_REQUEST["item"])->setAttribute("id",$tab[1]) ;
$nodes->item($_REQUEST["item"])->setAttribute("entry",$tab[2]) ;
$dom->save($pageFile) ;
return 'Page updated';
}else{
return 'Nothing has been done';
}
break;
case 2 :
if($flg)
{
try
{
$dom = new DOMDocument() ;
$pageFile = "./Owners/" . $pOwner . "/Contents/page.xml" ;
$dom->load($pageFile) ;
$root = $dom->getElementsByTagName("pages");
$new = $dom->createElement("page");
$new->setAttribute("number",$tab[0]);
$new->setAttribute("id",$tab[1]);
$new->setAttribute("entry",$tab[2]);
$root->item(0)->appendChild($new);
$dom->save($pageFile);
return 'New page add !' ;
}
catch (Exception $ex) {
return $ex ;
}
}else{
return 'Nothing has been done' ;
}
break;
}
}
function getNodeList($pNodeName,$pPath)
/*
* Lists all the files in a directory
*/
{
return xml2phpArray(simplexml_load_string(file_get_contents($pPath)),array());
}
function getAttribute($node)
{// >((dom)node) ((array)tab)>
$tab=array() ;
foreach($node->attributes() as $k1->$v1)
{
$tab[$k1->{''}->name]=$k1->{''}->value ;
}
return $tab;
}//
function xml2phpArray($xml,$arr){
$iter = 0;
foreach($xml->children() as $b){
$a = $b->getName();
if(!$b->children()){
$arr[$a] = trim($b[0]);
}
else{
$arr[$a][$iter] = array();
$arr[$a][$iter] = xml2phpArray($b,$arr[$a][$iter]);
}
$iter++;
}
return $arr;
}
function print_r_html($data,$return_data=false)
/*
* Print_r_htl modified to return array
*/
{
$data = print_r($data,true) ;
$data = str_replace( " "," ", $data) ;
$data = str_replace( "\r\n","<br/>\r\n", $data) ;
$data = str_replace( "\r","<br/>\r", $data) ;
$data = str_replace( "\n","<br/>\n", $data) ;
if (!$return_data)
return $data ;
else
return $data ;
}
?>
Backend
modifierLe backend est implémenter suivant quelques règles métier imposées par l'orientation du CMS également.
Objects/Backend/authorize.inc.php
<?php
/*
* Authorize component
*/
require_once CLA . "/dataManager.class.php" ;
require_once CLA . "/utilities.class.php" ;
$_manager = new dataManager() ;
//
$_manager->data['path'] = $_manager->data['root'] . (@$_REQUEST["entry"]?$_REQUEST["entry"]:"Root") . "/Contents/user.xml" ; //
$_credit = isset($_SESSION['autho']['credit'])?trim($_SESSION['autho']['credit']):null ;
//
if ( isset($_REQUEST['iLogin']) )
$_credit = trim($_REQUEST['iLogin']) ;
if( isset($_REQUEST['iUnlog']))
{
unset($_SESSION["autho"]["credit"]) ;
unset($_credit) ;
}
try
{
# QUERY TESTS
$_manager->data['query_1'] = array(
array("attribute"=>"pass", "value"=>@$_credit)) ;
// query test
$_res = utilities::getLineByAttribute($_manager->initialize(), $_manager->data['query_1']) ;
if(isset($_res["login"]))
{
$_SESSION["autho"]["credit"] = $_res["pass"] ;
}
else
{
unset($_SESSION["autho"]["credit"]) ;
}
# REGION [0] - Keep order of privileges
if(preg_match('/u/',@$_res['rights']))
{
$_SESSION["autho"]["user"] = 1 ;
unset($_SESSION["autho"]["moderator"]) ;
unset($_SESSION["autho"]["admin"]) ;
}
if(preg_match('/m/',@$_res['rights']))
{
$_SESSION["autho"]["moderator"] = 1 ;
unset($_SESSION["autho"]["admin"]) ;
}
if(preg_match('/a/',@$_res['rights']))
{
$_SESSION["autho"]["admin"] = 1 ;
}
# END REGION [0]
} catch(Exception $ex) { }
//var_dump($_res);
?>
Objects/Backend/responder.inc.php dans sa version finale
<?php
//
$_ = explode(":",@$_REQUEST['id']) ;
$_qry = $_REQUEST['qry'] ;
$_content = "" ;
switch( true )
/**
* content type switcher
*/
{
case ($_[0] == "lay") :
// single query order : template request
$_content = requestForLayout( $_[1], $_REQUEST['owner'], @$_REQUEST['template']?$_REQUEST['template']:'default' ) ;
break ;
case ($_[0] == "data") :
// single query order : data request
$_content = requestForData( $_[1], $_REQUEST['owner'] ) ;
break ;
case(@$_qry == 2) :
// single query order : formatData
$_content = formatData(@$_REQUEST['content']) ;
break ;
case(@$_qry == 3) :
// composed query instruction :
//$_content = ;
break ;
case(@$_qry == 4) :
// single query order : getCustomerEntryList
require_once BCK . "/services.inc.php" ;
if( @$_SESSION["autho"]["credit"] )
{
$_adminPage = new adminPage() ;
$_adminPage->prepareAdminPage( getCustomerEntryList( OWN ) ) ;
$_content = $_adminPage->str ;
} else {
$_content = "no access granted" ;
}
break ;
case (@$_qry == 5) :
// create entries for customer
$_content = $_REQUEST['nu']." !.added [ refresh the page ]" ;
mkdir( OWN . "/" . $_REQUEST['nu'] , 0700);
mkdir( OWN . "/" . $_REQUEST['nu']."/Contents" , 0700);
copy( OWN . "/Root/Dummies/1.xml", OWN . "/" . $_REQUEST['nu'] . "/Contents/1.xml" ) ;
copy( OWN . "/Root/Dummies/user.xml", OWN . "/" . $_REQUEST['nu'] . "/Contents/user.xml" ) ;
copy( OWN . "/Root/Dummies/page.xml", OWN . "/" . $_REQUEST['nu'] . "/Contents/page.xml" ) ;
mkdir( OWN . "/" . $_REQUEST['nu']."/Templates" , 0700);
copy( OWN . "/Root/Dummies/default.xml", OWN . "/" . $_REQUEST['nu'] . "/Templates/default.xml" ) ;
copy( OWN . "/Root/Dummies/admin.xml", OWN . "/" . $_REQUEST['nu'] . "/Templates/admin.xml" ) ;
mkdir( OWN . "/" . $_REQUEST['nu']."/Users" , 0700);
mkdir( OWN . "/" . $_REQUEST['nu']."/Tmp" , 0700);
break ;
case (@$_qry == 6) :
// save file modified
require_once "services.inc.php" ;
$_content = $_REQUEST['path']." !.saved" ;
file_put_contents($_REQUEST['path'], noHtml($_REQUEST['content']));
doFlush();
break ;
case (@$_qry == 7) :
//
$_content = "> crop page" ;
break;
case (@$_qry == 8) :
//
$_content = "> item page" ;
break;
case (@$_qry == 9) :
//
$_content = "> page page" ;
break;
case (@$_qry == 15) :
$_content = getCropItem($_REQUEST['item'],$_REQUEST['crop']) ;
break;
case (@$_qry == 20) :
$_content = saveCropItem($_REQUEST['value'],$_REQUEST['owner']) ;
break;
case (@$_qry == 21) :
$_content = saveCropNewItem($_REQUEST['value'],$_REQUEST['owner']) ;
break;
case (@$_qry == 22) :
$_content = saveNewCrop($_REQUEST["owner"],$_REQUEST['value']) ;
break;
case (@$_qry == 25) :
$_content = saveUser($_REQUEST['owner'], $_REQUEST['value'], $_REQUEST['key'], 1) ;
break;
case (@$_qry == 26) :
$_content = saveUser($_REQUEST['owner'], $_REQUEST['value'], $_REQUEST['key'], 2) ;
break;
case (@$_qry == 30) :
$_content = saveCrop($_REQUEST['owner'], $_REQUEST['id'], $_REQUEST['data'], $_REQUEST['key']) ;
break;
case (@$_qry == 35) :
$_content = savePage($_REQUEST['owner'], $_REQUEST['value'], $_REQUEST['key'],1) ;
break;
case (@$_qry == 36) :
$_content = savePage($_REQUEST['owner'], $_REQUEST['value'], $_REQUEST['key'],2) ;
break;
}
# OUTPUT
switch(true)
{
case ($_qry==6):
echo $_content ;
break;
case ($_qry==15) :
echo $_content;
break;
case ($_qry==20) :
echo $_content;
break;
case ($_qry==21) :
echo $_content;
break;
case ($_qry==22) :
echo $_content;
break;
case ($_qry==25) :
echo $_content;
break;
case ($_qry==26) :
echo $_content;
break;
case ($_qry==30) :
echo $_content;
break;
case ($_qry==35) :
echo $_content;
break;
case ($_qry==36) :
echo $_content;
break;
default:
echo @$_REQUEST['id'] . "~~" . ( @$_[1] ? $_[1] : $_[0] ) . "~~" . $_content ;
break;
}
?>
Objects/Backend/services.inc.php
<?php
/*
* Backoffices Services
*
* here comes all the backoffice treatments as
*
*/
function noHtml ($pString)
{
$_in = array('/</','/>/') ;
$_out = array('<','>') ;
return preg_replace($_in,$_out,$pString) ;
}
function doFlush ()
{
// check that buffer is actually set before flushing
if (ob_get_length())
{
@ob_flush();
@flush();
@ob_end_flush();
}
@ob_start();
}
function getUserList ()
{
return $lst ;
}
function getCustomerEntryList( $pPath, &$_lst=array() )
/*
* get recursively the files in a given initial path
*/
{
$tmp = getFileList( $pPath ) ;
try
{
if ( $tmp )
foreach ( @$tmp as $k=>$v )
{
if( is_dir($v) )
{
$_lst[$pPath][$v] = array() ;
getCustomerEntryList ( $v, $_lst[$pPath] ) ;
}
else
{
$_lst[$pPath][@++$i] = $v ;
}
}
}
catch (Exception $ex) {}
return $_lst ;
}
class adminPage
/*
* prepare admin page
*/
{
public $str = "
<div id='editPanel' class='adminMenu'>
<input type='text' id='iCustomer' value=':: add customer ::' onclick='this.value=\"\";' />
<input type='button' value='do' onclick='setContent(\"addUserCom\",\"qry=5&nu=\"+$(\"iCustomer\").value) ;' />
<div id='addUserCom' class='green'></div>
<input type='hidden' name='iPath' id='iPath' value='' />
<div id='cMod' style='display:none' ><!-- -->
<textarea id='iMod' rows='10' cols='100' style='width:100%;font-size:10px;font-family:verdana;'>content</textarea>
<input type='button' value='save' onclick='saveMod();' />
</div>
</div>
<br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br />
";
function deployArray ( $pArray, &$str )
/*
*
*/
{
//echo "tmp:".count($pArray) ;
try
{
if (is_array($pArray))
foreach( @$pArray as $k=>$v )
{
$this->str .= ( preg_match( '/\//', $k ) ? "<p><b>" . ((substr_count($k,'/')>2)?" <span class='dirPath'>" . $k:$k) . "</span></b></p>": "" ) . ( ! is_array( $v ) ? " <a style='cursor:pointer;' onclick='editFileContent(\"$v\");'>[edit]</a> <a href='$v'>" . $v . "</a>" : "" ) . " <br />" ;
if( count( $v ) )
$this->deployArray( $v, $this->str ) ;
}
} catch( Exception $ex ) {}
}
function prepareAdminPage( $pArray )
/*
*
*/
{
$tmp = array () ;
$this->deployArray( $pArray, $tmp ) ;
}
}
class cropPage
{
public function cropPage()
{
}
public function getCropList()
{
}
}
?>
Objects/Backend/webservices.inc.php
<?php
?>
FrontEnd
modifierDeux points d'entrées : Objects/Frontend/admin.inc.php
<?php
//
require_once CLA . "/utilities.class.php" ;
require_once CLA . "/templateControler.class.php" ;
require_once FUN. "/common.inc.php" ;
//
$tmp = new templateControler(array("path"=>"./Owners/".(@$_REQUEST["entry"]?@$_REQUEST["entry"]:"Dummy")."/Templates/admin.xml"));
# STATE
// get the content main page
$tmp->initFrame(
$tmp
->getNode("//template/frameset/content")
) ;
// authentification
$tmp->setTag("customer","<input type='hidden' value='".(@$_REQUEST['entry']?$_REQUEST['entry']:"Root")."' id='customerName' />" );
if(@$_SESSION["autho"]["credit"])
$tmp->setTag("logged","<input type='hidden' value='1' id='iLogged' />" );
$tmp->getAnchors( $tmp->data['feed'][0]->nodeValue ) ;
$tmp->anchorContentReplacer() ;
$tmp->setFrame() ;
# OUTPUT
echo $tmp->data['frameset'] ;
?>
Objects/Frontend/entry.inc.php dans sa version finale
<?php
require_once CLA . "/utilities.class.php" ;
require_once CLA . "/templateControler.class.php" ;
require_once FUN. "/common.inc.php" ;
require_once CLA . "/contentPane.class.php" ;
$_SESSION["path"] = $_path = "./Owners/" . (@$_REQUEST['entry']?$_REQUEST['entry']:"Root") ;
//
$tmp = new templateControler
(
array("path"=>$_path
. "/Templates/default.xml")
);
//echo print_r_html($_SESSION) ;
# STATE
$tmp->initFrame(
$tmp
->getNode("//template/frameset/content")
) ;
// authentification
$tmp->setTag("customer","<input type='hidden' value='".(@$_REQUEST['entry']?$_REQUEST['entry']:"Dummy")."' id='customerName' />
<input type='hidden' value='".md5(@$_SESSION["autho"]["credit"])."' id='userKey' />
<input type='hidden' value='" . (@$_cms['status']?1:0) . "' id='contentKey' />
<input type='hidden' value='0' id='iCounter' />
" );
if(@$_SESSION["autho"]["credit"])
{
$tmp->setTag("logged","<input type='hidden' value='1' id='iLogged' />" );
}
// if cms entry - display menu
if(@$_cms["status"] == 1)
{
$tmp->setTag("menuPane", $_container["content"]->data["menuPane"] );
if(@$_SESSION['autho']['credit'])
switch(true)
{
case ( isset($_REQUEST["crop"]) && $_REQUEST["crop"] != 1 && !@$_REQUEST["page"]==1 ) :
$tmp->setTag("bottomPane", $_container["content"]->getCropPane(@$_REQUEST["crop"]) );
break;
case isset( $_REQUEST["page"] ) :
$tmp->setTag("bottomPane", $_container["content"]->getPagePane( ));
break;
case isset( $_REQUEST["user"] ) :
$tmp->setTag("bottomPane", $_container["content"]->getUserPane( ));
break;
case ( @$_REQUEST["crop"] == 1 ) :
$tmp->setTag("bottomPane", $_container["content"]->getNewCrop() );
break;
}
}
$tmp->getAnchors( $tmp->data['feed'][0]->nodeValue ) ;
$tmp->anchorContentReplacer() ;
// customer name
$tmp->setFrame() ;
# OUTPUT
echo $tmp->data['frameset'] ;
?>
Le Troisieme noyau
modifierMyTinyCMS est ici un CMS orienté données et frontEnd. Avec le frontOffice ajaxifié présenté dans la rubrique relatif à la vue, il permet la création de sites customer directement dans moyennant quelques connaissances en html.
L'applicabilité des modules ayant été démontrée. Cette solution est achevée ici mais peut être augmentée ou améliorée.
myTinyCMS est sous licence GNU copyLeft et utilisable. Si vous implémentez la solution, laissez votre copyright ou alias derrière le mien.
Le copy étant
Copyright (C) zulul Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".
Télécharger
modifierMyTinyCMS est nominal... Il peut être telechargé ici