Spool.php

00001 <?php
00002 /*
00003  * Copyright (C) 2003-2004 Polytechnique.org
00004  * http://opensource.polytechnique.org/
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 
00024 class Diogenes_VCS_Spool {
00026   var $alias;
00028   var $datadir;
00029 
00031   var $cmd_call;
00032   
00034   var $cmd_output;
00035   
00037   var $cmd_return;
00038   
00043   var $caller;
00044 
00050   function Diogenes_VCS_Spool(&$caller,$alias) {
00051     global $globals;
00052     $this->datadir = "{$globals->spoolroot}/$alias";
00053     $this->caller =& $caller;
00054     $this->alias = $alias;
00055   }
00056 
00057   
00062   function cmdExec($cmd)
00063   {
00064     $this->cmd_call = $cmd;    
00065     unset($this->cmd_output);
00066     unset($this->cmd_return);
00067     
00068     exec($cmd, $this->cmd_output, $this->cmd_return);
00069     
00070     return $this->cmd_return;
00071   }
00072   
00073   
00076   function cmdStatus()
00077   {
00078     $out  =
00079      "-- [ command information ] -- \n".
00080      "command : {$this->cmd_call}\n".
00081      "return value : {$this->cmd_return}\n".
00082      "-- [ command output ] --\n".
00083      implode("\n", $this->cmd_output)."\n".
00084      "--";
00085    return $out;
00086   }
00087 
00088   
00093   function info($msg) {
00094     $this->caller->info($msg);
00095   }
00096 
00097 
00102   function kill($msg) {
00103     $this->caller->kill($msg);
00104   }
00105 
00106 
00112   function log($action,$data) {
00113     $this->caller->log($action, $data);
00114   }
00115 
00116 
00123   function checkPath($parent,$entry,$fatal = true) {
00124     $ret = preg_match("/^([a-zA-Z0-9\-_]+[\.,\/]?)*$/",$parent)
00125         && preg_match("/^([a-zA-Z0-9\-_]+[\., ]?)*$/",$entry);
00126 
00127     if (!$ret && $fatal)
00128       $this->kill("malformed path ('$parent','$entry')");
00129     
00130     return $ret;
00131   }
00132 
00133 
00139   function exportHtmlString($html)
00140   {
00141     // if we have the body open & close tags, return raw file
00142     if (preg_match("/<body(\s[^>]*|)>(.*)<\/body>/si",$html))
00143       return $html;
00144     
00145     return "<html>\n<head><title>Diogenes page</title></head>\n<body>$html</body>\n</html>\n";
00146   }
00147 
00148 
00155   function importHtmlString($html)
00156   {
00157     // If available, run tidy to clean sources
00158     if (function_exists('tidy_repair_string')) {
00159         $tidy_config = array('drop-empty-paras' => true,
00160                              'drop-proprietary-attributes' => true,
00161                              'hide-comments' => true,
00162                              'logical-emphasis' => true,
00163                              'output-xhtml' => true,
00164                              'replace-color' => true,
00165                              'join-classes'  => true,
00166                              'join-style' => true, 
00167                              'clean' => true,
00168                              'show-body-only' => true,
00169                              'alt-text' => '[ inserted by TIDY ]',
00170                              'break-before-br' => true,
00171                              'indent' => true,
00172                              'vertical-space' => true,
00173                              'wrap' => 120);
00174         if (function_exists('tidy_setopt')) { // Tidy 1.0
00175             foreach ($tidy_config as $field=>$value) {
00176                 tidy_setopt($field, $value);
00177             }
00178             $html = tidy_repair_string($html);
00179         } else { // Tidy 2.0
00180             $html = tidy_repair_string($html, $tidy_config);
00181         }
00182     }
00183  
00184     // if we cannot find the body open & close tags, return raw file
00185     if (!preg_match("/<body(\s[^>]*|)>(.*)<\/body>/si",$html,$matches))
00186       return $html;
00187 
00188     return $matches[2];
00189   }
00190 
00191 
00197   function spoolPath($parent="",$entry="") {
00198     $this->checkPath($parent,$entry);
00199     return $this->datadir.($parent ? "/$parent": "") . ($entry ? "/$entry" : "");
00200   }
00201 
00202 }
00203 
00204 ?>

Generated on Fri Jan 11 01:20:08 2008 for Diogenes by  doxygen 1.5.1