00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031 class revisions extends WebObject
00032 {
00033 function init()
00034 {
00035 $this->addSVar('visible', 'false');
00036 $this->addSVar('tag', '');
00037 $this->addSVar('revision', '');
00038 $this->addSVar('date', '');
00039 }
00040
00041 function on_show($event_args)
00042 {
00043 $this->setSVar('visible', 'true');
00044 }
00045
00046 function on_hide($event_args)
00047 {
00048 $this->setSVar('visible', 'false');
00049 }
00050
00051 function clear()
00052 {
00053 $this->setSVar('tag', '');
00054 $this->setSVar('revision', '');
00055 $this->setSVar('date', '');
00056 }
00057
00058 function on_set_tag($event_args)
00059 {
00060 $this->clear();
00061 $tag = $event_args['tag'];
00062 $this->setSVar('tag', $tag);
00063 }
00064
00065 function on_set_rev($event_args)
00066 {
00067 $this->clear();
00068 $rev = $event_args['rev'];
00069 $this->setSVar('revision', $rev);
00070 }
00071
00072 function on_set_date($event_args)
00073 {
00074 $this->clear();
00075 $date = $event_args['date'];
00076 $this->setSVar('date', $date);
00077 }
00078
00079 function on_save($event_args)
00080 {
00081
00082 $content_xml = file_content_xml();
00083 $file_revision = $this->get_revision();
00084 write_file($content_xml, $file_revision);
00085
00086
00087 update_cache();
00088
00089
00090 set_node_status('modified');
00091
00092
00093 $this->clear();
00094 }
00095
00096 function onRender()
00097 {
00098 $visible = $this->getSVar('visible');
00099 if ($visible=='true')
00100 {
00101 $this->add_rs_tags();
00102 $this->add_rs_revs();
00103 $this->add_file_revision();
00104 $this->add_rev_diff();
00105 }
00106 }
00107
00109 function add_rs_tags()
00110 {
00111 $rs = new EditableRS('tags');
00112
00113 $url = $this->get_svn_url();
00114 $output = shell("svn list $url/tags/");
00115
00116 $rs->addRec(array('id'=>'', 'label'=>''));
00117 $lines = explode("\n", $output);
00118 for ($i=0; $i < sizeof($lines); $i++)
00119 {
00120 $line = $lines[$i];
00121 if ($line=='') continue;
00122 $tag = substr($line, 0, -1);
00123 $rs->addRec(array('id'=>$tag, 'label'=>$tag));
00124 }
00125
00126 global $webPage;
00127 $webPage->addRecordset($rs);
00128 }
00129
00131 function add_rs_revs()
00132 {
00133 $rs = new EditableRS('revs');
00134
00135 $content_xml = file_content_xml(WS_BOOKS);
00136 $output = shell("svn log -q $content_xml");
00137
00138 $rs->addRec(array('id'=>'', 'label'=>''));
00139 $lines = explode("\n", $output);
00140 for ($i=0; $i < sizeof($lines); $i++)
00141 {
00142 $line = $lines[$i];
00143 if (substr($line, 0, 4)=='----') continue;
00144 $arr = explode(' ', $line);
00145 $rev = $arr[0];
00146 $rev = substr($rev, 1);
00147 $rs->addRec(array('id'=>$rev, 'label'=>$rev));
00148 }
00149
00150 global $webPage;
00151 $webPage->addRecordset($rs);
00152 }
00153
00155 function add_file_revision()
00156 {
00157
00158 $content_xml = $this->get_revision();
00159 if (substr($content_xml, 0, 4)=='svn:')
00160 {
00161 WebApp::addVar('file_revision', '');
00162 return;
00163 }
00164
00165
00166 $tmpfile = write_tmp_file($content_xml);
00167
00168
00169 $book_id = WebApp::getSVar('docbook->book_id');
00170 $lng = WebApp::getSVar('docbook->lng');
00171 $book_path = WS_BOOKS.$book_id.'/'.$lng.'/';
00172 $params = "--stringparam book_path \"$book_path\"";
00173 $xsl_file = XSLT."cache/update_content.xsl";
00174 $content_html = shell("xsltproc $params $xsl_file $tmpfile");
00175 unlink($tmpfile);
00176
00177
00178 WebApp::addVar('file_revision', $content_html);
00179 }
00180
00182 function get_revision()
00183 {
00184 extract($this->getSVars());
00185 $content_xml = file_content_xml(WS_BOOKS);
00186
00187 if ($tag != '')
00188 {
00189 $url = $this->get_svn_url();
00190 $node_path = WebApp::getSVar('docbook->node_path');
00191 $cmd = "svn cat $url/tags/$tag/${node_path}content.xml";
00192 }
00193 else if ($revision != '')
00194 {
00195 $cmd = "svn cat -r $revision $content_xml";
00196 }
00197 else if ($date != '')
00198 {
00199 $cmd = "svn cat -r {'$date'} $content_xml";
00200 }
00201 else
00202 {
00203 $cmd = "svn cat $content_xml";
00204 }
00205
00206 $output = shell($cmd);
00207 return $output;
00208 }
00209
00212 function add_rev_diff()
00213 {
00214 extract($this->getSVars());
00215 $content_xml = file_content_xml(WS_BOOKS);
00216 $get_title_xsl = XSLT.'edit/get_content_title.xsl';
00217
00218
00219 if ($tag != '')
00220 {
00221 $url = $this->get_svn_url();
00222 $node_path = WebApp::getSVar('docbook->node_path');
00223 $tag_url = "$url/tags/$tag/$node_path".'content.xml';
00224 $xml_rev = shell("svn cat $tag_url");
00225 $log = shell("svn log $tag_url");
00226 }
00227 else if ($date != '')
00228 {
00229 $xml_rev = shell("svn cat $content_xml -r {'$date'}");
00230 $log = shell("svn log $content_xml -r {'$date'}");
00231 }
00232 else if ($revision != '')
00233 {
00234 $xml_rev = shell("svn cat $content_xml -r $revision");
00235 $log = shell("svn log $content_xml -r $revision");
00236 }
00237 else
00238 {
00239 $xml_rev = shell("svn cat $content_xml -r HEAD");
00240 $log = shell("svn log $content_xml -r HEAD");
00241 }
00242 $file_xml_rev = write_tmp_file($xml_rev);
00243
00244
00245 $title = shell("xsltproc $get_title_xsl $file_xml_rev");
00246 $txt = get_node_content($file_xml_rev, 'text');
00247 $txt = 'T: '.$title."\n\n".trim($txt)."\n";
00248 $file_txt_rev = write_tmp_file($txt);
00249
00250
00251 $title = shell("xsltproc $get_title_xsl $content_xml");
00252 $txt = get_node_content($content_xml, 'text');
00253 $txt = 'T: '.$title."\n\n".trim($txt)."\n";
00254 $file_txt = write_tmp_file($txt);
00255
00256
00257 $diff = shell("diff -ubB $file_txt $file_txt_rev | sed '1,2d'");
00258
00259
00260 unlink($file_xml_rev);
00261 unlink($file_txt_rev);
00262 unlink($file_txt);
00263
00264
00265 $diff = htmlspecialchars($diff);
00266 $patterns = array(
00267 '/^(@@.*@@)$/m',
00268 '/^-(.*)$/m',
00269 '/^\+(.*)$/m',
00270 '/^ (.*)$/m'
00271 );
00272 $replacements = array(
00273 '<div class="line_nr">\\1</div>',
00274 '<div class="removed"> \\1</div>',
00275 '<div class="added"> \\1</div>',
00276 '<div class="context"> \\1</div>'
00277 );
00278 $diff = preg_replace($patterns, $replacements, $diff);
00279
00280
00281 $patterns = array(
00282 '/^-----+$/m',
00283 '/\n+/'
00284 );
00285 $replacements = array(
00286 '',
00287 "\n"
00288 );
00289 $log = preg_replace($patterns, $replacements, $log);
00290
00291
00292 WebApp::addVar('rev_diff', $diff);
00293 WebApp::addVar('rev_log', $log);
00294 }
00295
00297 function get_svn_url()
00298 {
00299 $book_id = WebApp::getSVar('docbook->book_id');
00300 $lng = WebApp::getSVar('docbook->lng');
00301 $book_dir = WS_BOOKS."$book_id/$lng/";
00302
00303 $url = shell("svn info $book_dir | sed -n '/^URL: /p'");
00304
00305 $url = ereg_replace('^URL: ', '', $url);
00306 $url = ereg_replace("$book_id/$lng/.*", "$book_id/$lng", $url);
00307
00308 return $url;
00309 }
00310 }
00311 ?>