00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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')) {
00175 foreach ($tidy_config as $field=>$value) {
00176 tidy_setopt($field, $value);
00177 }
00178 $html = tidy_repair_string($html);
00179 } else {
00180 $html = tidy_repair_string($html, $tidy_config);
00181 }
00182 }
00183
00184
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 ?>