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
00025
00038 function lock_index()
00039 {
00040 $book_id = WebApp::getSVar('docbook->book_id');
00041 $lock_file = WS_BOOKS.$book_id.'/lock';
00042
00043
00044
00045 while (file_exists($lock_file))
00046 {
00047 clearstatcache();
00048 $lock_age = time() - filectime($lock_file);
00049 if ($lock_age > 60) break;
00050 }
00051 shell("touch $lock_file");
00052 }
00053
00054 function unlock_index()
00055 {
00056 $book_id = WebApp::getSVar('docbook->book_id');
00057 $lock_file = WS_BOOKS.$book_id.'/lock';
00058 shell("rm $lock_file");
00059 }
00060
00062 function add_to_modified_nodes($path =UNDEFINED)
00063 {
00064 if ($path==UNDEFINED) $path = WebApp::getSVar('docbook->node_path');
00065
00066 $book_id = WebApp::getSVar('docbook->book_id');
00067 $lng = WebApp::getSVar('docbook->lng');
00068
00069
00070 $lock_file = WS_BOOKS."$book_id/$lng/modified_lock";
00071 while (file_exists($lock_file))
00072 {
00073 clearstatcache();
00074 $lock_age = time() - filectime($lock_file);
00075 if ($lock_age > 10) break;
00076 }
00077 shell("touch $lock_file");
00078
00079
00080 $modified_nodes = WS_BOOKS."$book_id/$lng/modified_nodes.txt";
00081 shell("sed '\|^$path\$|d' -i $modified_nodes");
00082 shell("echo \"$path\" >> $modified_nodes");
00083
00084
00085 shell("rm $lock_file");
00086 }
00087
00089 function remove_from_modified_nodes($path =UNDEFINED, $recursive =false)
00090 {
00091 if ($path==UNDEFINED) $path = WebApp::getSVar('docbook->node_path');
00092
00093 $book_id = WebApp::getSVar('docbook->book_id');
00094 $lng = WebApp::getSVar('docbook->lng');
00095
00096
00097 $lock_file = WS_BOOKS."$book_id/$lng/modified_lock";
00098 while (file_exists($lock_file))
00099 {
00100 clearstatcache();
00101 $lock_age = time() - filectime($lock_file);
00102 if ($lock_age > 10) break;
00103 }
00104 shell("touch $lock_file");
00105
00106
00107 $pattern = ($recursive ? "^$path" : "^$path\$");
00108 $modified_nodes = WS_BOOKS."$book_id/$lng/modified_nodes.txt";
00109 shell("sed '\|$pattern|d' -i $modified_nodes");
00110
00111
00112 shell("rm $lock_file");
00113 }
00114
00115
00116
00118 function add_subsections_rs()
00119 {
00120 $subsections = process_index_node('subsections');
00121 $lines = explode("\n", $subsections);
00122
00123 $rs = new EditableRS('subsections');
00124 for ($i=0; $i < sizeof($lines); $i++)
00125 {
00126 list($path,$title) = split(' ', $lines[$i], 2);
00127 if ($path=='') continue;
00128 $title = trim($title);
00129 $rs->addRec(compact('path', 'title'));
00130 }
00131 global $webPage;
00132 $webPage->addRecordset($rs);
00133 }
00134
00139 function process_index_node($transformer, $node_path =UNDEFINED)
00140 {
00141 if ($node_path==UNDEFINED)
00142 {
00143 $node_path = WebApp::getSVar('docbook->node_path');
00144 }
00145 $lng = WebApp::getSVar('docbook->lng');
00146 $transformer = "edit/${transformer}.xsl";
00147 $params = array('path'=>$node_path, 'lng'=>$lng);
00148 $output = process_index($transformer, $params);
00149
00150 return $output;
00151 }
00152
00157 function transform_index($action, $arr_params =array())
00158 {
00159
00160 $index_xml = process_index("edit/${action}.xsl", $arr_params);
00161
00162
00163 $params = "action=\"$action\", ".array2str($arr_params);
00164 $commit_msg = date('Y-m-d H:i').' >> Modified by '.USER. ' >> '.$params;
00165
00166 $book_id = WebApp::getSVar('docbook->book_id');
00167
00168
00169 $langs = WebApp::getSVar('docbook->languages');
00170 $arr_langs = explode(',', $langs);
00171 for ($i=0; $i < sizeof($arr_langs); $i++)
00172 {
00173 $lng = $arr_langs[$i];
00174
00175
00176 $workspace_xml_file = WS_BOOKS."$book_id/$lng/index.xml";
00177 write_file($workspace_xml_file, $index_xml);
00178
00179
00180 shell("svn commit $workspace_xml_file -m '$commit_msg'");
00181
00182
00183 $tag = book_fixed_to_tag($book_id, $lng);
00184 if ($tag)
00185 {
00186 $msg = T_("The book (v_book_id, v_lng) is fixed to v_tag, \n\
00187 so the changes will not be displayed in the public copy.");
00188 $msg = str_replace('v_book_id', $book_id, $msg);
00189 $msg = str_replace('v_lng', $lng, $msg);
00190 $msg = str_replace('v_tag', $tag, $msg);
00191 WebApp::message($msg);
00192 }
00193 else
00194 {
00195 $book_dir = BOOKS."$book_id/$lng/";
00196 $public_xml_file = $book_dir.'index.xml';
00197 shell("svn update $book_dir");
00198 }
00199 }
00200 }
00201
00203 function update_navigation_all_langs($node_path)
00204 {
00205 $langs = WebApp::getSVar('docbook->languages');
00206 $arr_langs = explode(',', $langs);
00207 for ($i=0; $i < sizeof($arr_langs); $i++)
00208 {
00209 $lng = $arr_langs[$i];
00210 update_navigation($node_path, $lng);
00211 }
00212 }
00213
00215 function update_navigation($node_path, $lng)
00216 {
00217 $book_id = WebApp::getSVar('docbook->book_id');
00218 $xsl_file = 'edit/get_navigation.xsl';
00219 $params = array('path'=>$node_path, 'lng'=>$lng);
00220
00221
00222 $navigation = process_index($xsl_file, $params, WS_BOOKS);
00223 $fname = WS_CACHE."$book_id/$lng/$node_path/navigation.txt";
00224 write_file($fname, $navigation);
00225
00226
00227 if (!book_fixed_to_tag($book_id, $lng))
00228 {
00229 $navigation = process_index($xsl_file, $params, BOOKS);
00230 $fname = CACHE."$book_id/$lng/$node_path/navigation.txt";
00231 write_file($fname, $navigation);
00232 }
00233 }
00234
00239 function update_subnodes_html_all_langs($node_path =UNDEFINED)
00240 {
00241 if ($node_path==UNDEFINED)
00242 {
00243 $node_path = WebApp::getSVar('docbook->node_path');
00244 }
00245
00246
00247 $langs = WebApp::getSVar('docbook->languages');
00248 $arr_langs = explode(',', $langs);
00249 for ($i=0; $i < sizeof($arr_langs); $i++)
00250 {
00251 $lng = $arr_langs[$i];
00252 update_subnodes_html($node_path, $lng);
00253 }
00254 }
00255
00264 function update_subnodes_html($node_path, $lng, $recursive ='true')
00265 {
00266 $transformer = 'edit/get_subnodes.xsl';
00267 $book_id = WebApp::getSVar('docbook->book_id');
00268 $fixed = book_fixed_to_tag($book_id, $lng);
00269
00270
00271
00272 while (true)
00273 {
00274
00275 $params = array('path'=>$node_path);
00276
00277
00278 $subnodes = process_index($transformer, $params, WS_BOOKS, $lng);
00279 $book_path = WS_CACHE."$book_id/$lng/";
00280 $subnodes_html = $book_path.$node_path.'subnodes.html';
00281 write_file($subnodes_html, $subnodes);
00282
00283
00284 if (!$fixed)
00285 {
00286 $subnodes = process_index($transformer, $params, BOOKS, $lng);
00287 $book_path = CACHE."$book_id/$lng/";
00288 $subnodes_html = $book_path.$node_path.'subnodes.html';
00289 write_file($subnodes_html, $subnodes);
00290 }
00291
00292 if ($recursive!='true') break;
00293 if ($node_path=='./') break;
00294
00295
00296 $node_path = ereg_replace('[^/]+/$', '', $node_path);
00297 }
00298 }
00299
00300
00301
00302 function updatenavig_moveup($node_path)
00303 {
00304
00305 update_navigation_all_langs($node_path);
00306 $navig = get_arr_navigation($node_path);
00307 update_navigation_all_langs($navig['prev_path']);
00308 update_navigation_all_langs($navig['next_path']);
00309 $next_navig = get_arr_navigation($navig['next_path']);
00310 update_navigation_all_langs($next_navig['next_path']);
00311 }
00312
00313 function updatenavig_movedown($node_path)
00314 {
00315
00316 update_navigation_all_langs($node_path);
00317 $navig = get_arr_navigation($node_path);
00318 update_navigation_all_langs($navig['prev_path']);
00319 update_navigation_all_langs($navig['next_path']);
00320 $prev_navig = get_arr_navigation($navig['prev_path']);
00321 update_navigation_all_langs($prev_navig['prev_path']);
00322 }
00323
00324 function update_cache_files_all_langs($node_path)
00325 {
00326 update_navigation_all_langs($node_path);
00327 $navig = get_arr_navigation($node_path);
00328 update_navigation_all_langs($navig['prev_path']);
00329 update_navigation_all_langs($navig['next_path']);
00330
00331
00332 update_subnodes_html_all_langs($node_path);
00333 }
00334
00335 function update_cache_files($node_path, $lng =UNDEFINED)
00336 {
00337 if ($lng==UNDEFINED) $lng = WebApp::getSVar('docbook->lng');
00338
00339 update_navigation($node_path, $lng);
00340 $navig = get_arr_navigation($node_path);
00341 update_navigation($navig['prev_path'], $lng);
00342 update_navigation($navig['next_path'], $lng);
00343
00344
00345 update_subnodes_html($node_path, $lng);
00346 }
00347
00348 function delete_removefolders_all_langs($node_path)
00349 {
00350 $langs = WebApp::getSVar('docbook->languages');
00351 $arr_langs = explode(',', $langs);
00352 for ($i=0; $i < sizeof($arr_langs); $i++)
00353 {
00354 $lng = $arr_langs[$i];
00355 delete_removefolders($node_path, $lng);
00356 }
00357 }
00358
00359 function delete_removefolders($node_path, $lng)
00360 {
00361 $book_id = WebApp::getSVar('docbook->book_id');
00362 $path = "$book_id/$lng/$node_path";
00363 $msg = date('Y-m-d H:i') . " >> Deleted by " . USER
00364 . " >> node_path='$node_path'";
00365
00366
00367 shell("svn remove --force ".WS_BOOKS.$path);
00368 shell("svn update ".WS_BOOKS.$path);
00369 shell("svn commit ".WS_BOOKS.$path." -m '$msg'");
00370
00371
00372 shell("rm -rf ".WS_CACHE.$path);
00373
00374
00375 if (!book_fixed_to_tag($book_id, $lng))
00376 {
00377
00378 $book_dir = BOOKS."$book_id/$lng/";
00379 shell("svn update $book_dir");
00380
00381
00382 shell("rm -rf ".CACHE.$path);
00383 }
00384 }
00385
00387 function create_new_node($id, $title, $type)
00388 {
00389 $book_id = WebApp::getSVar('docbook->book_id');
00390 $node_path = WebApp::getSVar('docbook->node_path');
00391
00392 $new_node_path = $node_path.$id;
00393
00394
00395 $content_html = '<html/>';
00396 $content_xml = "<?xml version='1.0' encoding='utf-8' standalone='no'?>
00397 <$type id='$id'>
00398 <title>$title</title>
00399 <para/>
00400 </$type>";
00401 $state_txt = "unlocked::::\nadded:".USER.':'.EMAIL.':'.time();
00402
00403 $msg_params = "parent_node='$node_path', new_node_id='$id'";
00404 $commit_msg = date('Y-m-d H:i'). ' >> Added by '.USER.' >> '.$msg_params;
00405
00406 $langs = WebApp::getSVar('docbook->languages');
00407 $arr_langs = explode(',', $langs);
00408 for ($i=0; $i < sizeof($arr_langs); $i++)
00409 {
00410 $lng = $arr_langs[$i];
00411 $path = "$book_id/$lng/$new_node_path";
00412
00413
00414 $xml_path = WS_BOOKS.$path;
00415 shell("mkdir $xml_path");
00416 shell("chmod +x $xml_path");
00417 write_file("$xml_path/content.xml", $content_xml);
00418 shell("svn add $xml_path");
00419 shell("svn commit $xml_path -m '$commit_msg'");
00420 write_file("$xml_path/state.txt", $state_txt);
00421
00422
00423 $cache_path = WS_CACHE.$path;
00424 shell("mkdir $cache_path");
00425 shell("chmod +x $cache_path");
00426 write_file("$cache_path/content.html", $content_html);
00427
00428
00429 if (!book_fixed_to_tag($book_id, $lng))
00430 {
00431
00432 $book_dir = BOOKS."$book_id/$lng/";
00433 shell("svn update $book_dir");
00434
00435
00436 $cache_path = CACHE.$path;
00437 shell("mkdir $cache_path");
00438 shell("chmod +x $cache_path");
00439 write_file("$cache_path/content.html", $content_html);
00440 }
00441 }
00442 }
00443
00445 function change_id_validate($new_id)
00446 {
00447 $node_path = WebApp::getSVar('docbook->node_path');
00448 $book_id = WebApp::getSVar('docbook->book_id');
00449
00450
00451 ereg('([^/]+)/$', $node_path, $regs);
00452 $old_id = $regs[1];
00453 if ($old_id=='.') $old_id = $book_id;
00454
00455 if ($new_id==$old_id) return false;
00456
00457
00458 if ($old_id==$book_id)
00459 {
00460 WebApp::message(T_("The book ID cannot be changed."));
00461 return false;
00462 }
00463
00464
00465 if ($new_id=='')
00466 {
00467 $msg = T_("The id cannot be empty.");
00468 WebApp::message($msg);
00469 return false;
00470 }
00471
00472
00473 $output = process_index('edit/get_node_id.xsl', array('id'=>$new_id));
00474 if ($output<>'')
00475 {
00476 $msg = T_("The id 'v_new_id' is already used by another section.");
00477 $msg = str_replace('v_new_id', $new_id, $msg);
00478 WebApp::message($msg);
00479 return false;
00480 }
00481
00482
00483 $refs = get_node_references();
00484 if ($refs != '')
00485 {
00486 $msg = T_("This node id cannot be changed because it is referenced by \n v_refs \nFirst delete the references.");
00487 $msg = str_replace('v_refs', $refs, $msg);
00488 WebApp::message($msg);
00489 return false;
00490 }
00491
00492 return true;
00493 }
00494
00496 function changeid_movefolders($node_path, $new_node_path)
00497 {
00498 $book_id = WebApp::getSVar('docbook->book_id');
00499 $langs = WebApp::getSVar('docbook->languages');
00500 $arr_langs = explode(',', $langs);
00501 for ($i=0; $i < sizeof($arr_langs); $i++)
00502 {
00503 $lng = $arr_langs[$i];
00504
00505
00506 $node_folder = WS_BOOKS."$book_id/$lng/$node_path";
00507 $new_node_folder = WS_BOOKS."$book_id/$lng/$new_node_path";
00508 $parent_folder = ereg_replace('[^/]+/$', '', $new_node_folder);
00509 $msg_params = "node_path='$node_path', new_node_path='$new_node_path'";
00510 $msg = date('Y-m-d H:i').' >> Changed node id by '.USER.' >> '.$msg_params;
00511 $status = 'synchronized:'.USER.':'.EMAIL.':'.time();
00512 shell("svn update $parent_folder");
00513 shell("svn move --force $node_folder $new_node_folder");
00514 shell("svn commit $parent_folder -m '$msg'");
00515
00516
00517 $cache_folder = WS_CACHE."$book_id/$lng/$node_path";
00518 $new_cache_folder = WS_CACHE."$book_id/$lng/$new_node_path";
00519 shell("mv $cache_folder $new_cache_folder");
00520
00521
00522 if (!book_fixed_to_tag($book_id, $lng))
00523 {
00524
00525 $book_dir = BOOKS."$book_id/$lng/";
00526 shell("svn update $book_dir");
00527 $new_node_folder = $book_dir.$new_node_path;
00528 $parent_folder = ereg_replace('[^/]+/$', '', $new_node_folder);
00529
00530
00531 $cache_folder = CACHE."$book_id/$lng/$node_path";
00532 $new_cache_folder = CACHE."$book_id/$lng/$new_node_path";
00533 shell("mv $cache_folder $new_cache_folder");
00534 }
00535 }
00536 }
00537
00539 function changeid_setid($new_id)
00540 {
00541 $book_id = WebApp::getSVar('docbook->book_id');
00542 $node_path = WebApp::getSVar('docbook->node_path');
00543
00544 $langs = WebApp::getSVar('docbook->languages');
00545 $arr_langs = explode(',', $langs);
00546 for ($i=0; $i < sizeof($arr_langs); $i++)
00547 {
00548 $lng = $arr_langs[$i];
00549 $xml_file = file_content_xml(WS_BOOKS, $node_path, $lng);
00550
00551
00552 $params = "--stringparam id \"$new_id\" ";
00553 $xsl_file = XSLT."edit/set_content_id.xsl";
00554 $content = shell("xsltproc $params $xsl_file $xml_file");
00555 write_file($xml_file, $content);
00556
00557
00558 $commit_msg = date('Y-m-d H:i') . ' >> Changed node id by ' . USER
00559 . " >> node_path='$node_path' new_id='$new_id'";
00560 shell("svn commit $xml_file -m '$commit_msg'");
00561
00562
00563 if (!book_fixed_to_tag($book_id, $lng))
00564 {
00565 $book_dir = BOOKS."$book_id/$lng/";
00566 shell("svn update $book_dir");
00567 $public_xml_file = file_content_xml(BOOKS, $node_path, $lng);
00568 }
00569 }
00570 }
00571
00572 function changeid_updatecache($node_path)
00573 {
00574
00575 $book_id = WebApp::getSVar('docbook->book_id');
00576 $langs = WebApp::getSVar('docbook->languages');
00577 $arr_langs = explode(',', $langs);
00578 for ($i=0; $i < sizeof($arr_langs); $i++)
00579 {
00580 $lng = $arr_langs[$i];
00581 shell(CONTENT."cache/cache.sh $book_id $lng 'workspace' '$node_path'");
00582 if (!book_fixed_to_tag($book_id, $lng))
00583 {
00584 shell(CONTENT."cache/cache.sh $book_id $lng 'books' '$node_path'");
00585 }
00586 }
00587
00588
00589 $navig = get_arr_navigation($node_path);
00590 update_navigation_all_langs($navig['prev_path']);
00591 update_navigation_all_langs($navig['next_path']);
00592
00593
00594 update_subnodes_html_all_langs($node_path);
00595 }
00596
00607 function get_node_references()
00608 {
00609 $book_id = WebApp::getSVar('docbook->book_id');
00610 $lng = WebApp::getSVar('docbook->lng');
00611 $node_path = WebApp::getSVar('docbook->node_path');
00612
00613
00614 $node_id = basename(substr($node_path,0,-1));
00615
00616
00617 $grep = "grep -R '<xref linkend=\"$node_id\"' ".WS_BOOKS."$book_id/";
00618 $output = shell($grep);
00619
00620 if (trim($output)=='') return '';
00621
00622
00623 $arr_lines = explode("\n", $output);
00624 for ($i=0; $i < sizeof($arr_lines); $i++)
00625 {
00626 $line = trim($arr_lines[$i]);
00627 if ($line=='') continue;
00628
00629 $line = ereg_replace('/content\\.xml: .*', '', $line);
00630 $line = str_replace(WS_BOOKS, '', $line);
00631 $arr_refs[] = $line;
00632 }
00633
00634 $refs = implode("\n", $arr_refs);
00635 return $refs;
00636 }
00637 ?>