Source for file Compiler.php
Documentation is available at Compiler.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | MCMS: a PHP Content Management System for creating accessible sites. |
// | Copyright (C) 2005 Silvio Moioli |
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or |
// | (at your option) any later version. |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
// +----------------------------------------------------------------------+
// | Authors: Silvio Moioli <silvio at moioli dot net> www.moioli.net |
// +----------------------------------------------------------------------+
/** Carica la classe base di MCMS per l'interfacciamento al Database */
require_once $_SERVER["DOCUMENT_ROOT"]. "/admin/lib/model/Engine.php";
/** Carica la classe dei siti di MCMS */
require_once $_SERVER["DOCUMENT_ROOT"]. "/admin/lib/model/Site.php";
/** Carica il gestore dei template (Smarty) */
require_once $_SERVER["DOCUMENT_ROOT"]. "/admin/include/smarty/libs/Smarty.class.php";
/** Carica la libreria per semplificare l'aggiunta di tag XML */
require_once $_SERVER["DOCUMENT_ROOT"]. "/admin/lib/view/Tagger.php";
/** Carica le pagine della vista User */
require_once $_SERVER["DOCUMENT_ROOT"]. "/admin/lib/view/alluser.inc";
* Compilatore di interfacce XHTML. Crea/aggiorna i file
* XHTML di cui è composto un sito.
* @author Silvio Moioli <silvio at moioli dot net>
/** @var Smarty l'oggetto per la gestione dei template */
/** @var string il nome del template da usare per questo sito */
/** @var string il nome della directory dove creare i file XHTML */
/** @var il path dell'utility Tidy */
/** @var string il nome dell'eseguibile di Tidy per Windows */
/** @var string il nome dell'eseguibile di Tidy per Linux */
/** @var bool Tidy è supportato? */
/** @var string il path del log degli errori di Tidy */
* Costruttore di default.
* Costruisce un compilatore di interfacce XHTML per il sito specificato.
"templates/userTemplate.tpl";
$tidyDir = $_SERVER["DOCUMENT_ROOT"]. "/admin/include/tidy/";
$this->tidyLog = $tidyDir. "error.log";
* Visualizza direttamente la pagina passata.
* @param Compilable $page la pagina da visualizzare
//Assegno le variabili a Smarty
$this->smarty->assign('title',$page->getTitle());
$this->smarty->assign('menuEntries',$page->getMenuEntries());
$this->smarty->assign('contents',$page->getContents());
$this->smarty->assign('keywords',$page->getKeywords());
$this->smarty->assign('description',$page->getDescription());
$this->smarty->display($page->getTemplate());
* Salva la pagina su file.
* @param Savable $page la pagina da salvare
$contents = $page->getContents();
$menuEntries = $page->getMenuEntries();
$title = $page->getTitle();
$description = $page->getDescription();
$keywords = $page->getKeywords();
//Applico i componenti opzionali, se possibile.
if (is_a($page,"UserPage")) {
$components = $page->getComponents();
foreach ($components as $i) {
$i->applyComponent($contents, $menuEntries, $title, $description,
//Assegno le variabili a Smarty
$this->smarty->assign('title',$title);
$this->smarty->assign('menuEntries',$menuEntries);
$this->smarty->assign('contents',$contents);
$this->smarty->assign('keywords',$keywords);
$this->smarty->assign('description',$description);
//Ritorno come stringa e ripulisco
$this->fileSave($page->getFileName(), $result, true);
* Salva su file i contenuti XHTML specificati, se indicato tramite Tidy.
* @param string $fileName il nome del file su cui salvare (deve essere
* @param string il contenuto XHTML del file
* @param bool $useTidy true se utilizzare Tidy (se possibile)
function fileSave($fileName, $contents, $useTidy= true)
//Se è abilitato, usa Tidy
/* $fp = fopen($this->tidyLog, 'a');
fwrite($fp, "Processing: $fileName\n");
"--indent true --indent-spaces 4 --wrap 160 ".
"--char-encoding latin1 --output-xhtml true",$contents,$code);
$fp = fopen($fullName, 'w');
* Salva su file tutti gli elementi un sito.
* @param Site $site il sito da salvare
$articles = $site->getArticles();
foreach ($articles as $i) {
$categories = $site->getCategories();
foreach ($categories as $i) {
* Permette a tutti i plugin attivati sul sito specificato
* di salvare i loro file aggiuntivi.
* @param Site $site il sito di cui salvare i file dei plugin
$components = $site->getComponents();
foreach ($components as $i) {
$i->saveFiles($site, $this);
* Cancella il file corrispondente a una pagina di un sito (se esiste).
* @param Savable $savable l'oggetto Savable da eliminare
* Elimina tutti gli elementi di questo sito (cancellando i file relativi).
$articles = $site->getArticles();
foreach ($articles as $i) {
$categories = $site->getCategories();
foreach ($categories as $i) {
//TODO: removeComponents...
* Filtra la stringa specificata in stdin attraverso un programma
* @param string command il comando da eseguire
* @param string stdin la stringa da filtrare
* @return string la stringa filtrata
$descriptorSpec = array(0 => array("pipe", "r"),
2 => array('pipe', 'w'));
$process = proc_open($command, $descriptorSpec, $pipes);
$txOff = 0; $txLen = strlen($stdin);
$stdout = ''; $stdoutDone = FALSE;
$stderr = ''; $stderrDone = FALSE;
if ($txLen == 0) fclose($pipes[0]);
$rx = array(); // The program's stdout/stderr
if (!$stdoutDone) $rx[] = $pipes[1];
if (!$stderrDone) $rx[] = $pipes[2];
$tx = array(); // The program's stdin
if ($txOff < $txLen) $tx[] = $pipes[0];
stream_select($rx, $tx, $ex = NULL, NULL, NULL); // Block til r/w possible
if ($txRet !== FALSE) $txOff += $txRet;
if ($txOff >= $txLen) fclose($pipes[0]);
$stdout .= fread($pipes[1], 8192);
else if ($r == $pipes[2]) {
$stderr .= fread($pipes[2], 8192);
if ($txOff >= $txLen && $stdoutDone && $stderrDone) break;
|