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
00026 include_once DOCBOOK.'/edit/content/process_content.php';
00027
00028
00029 include_once DOCBOOK.'/edit/edit_funcs.php';
00030
00038 class approve extends WebObject
00039 {
00040 function on_set_lock($event_args)
00041 {
00042 $lock = $event_args['lock'];
00043 set_node_lock($lock, 'approve');
00044 }
00045
00046 function on_revert($event_args)
00047 {
00048 $recursive = ($event_args['recursive'] == 'true');
00049 if ($recursive)
00050 $this->recursive_revert();
00051 else
00052 $this->non_recursive_revert();
00053 }
00054
00055 function non_recursive_revert()
00056 {
00057 $workspace_xml_file = file_content_xml(WS_BOOKS);
00058 $node_dir = dirname($workspace_xml_file);
00059
00060
00061 shell(SCRIPTS."approve/svn_revert.sh $node_dir");
00062
00063
00064 update_cache();
00065
00066
00067 $node_path = WebApp::getSVar('docbook->node_path');
00068 update_cache_files($node_path);
00069
00070
00071 set_node_status('synchronized');
00072
00073
00074 remove_from_modified_nodes();
00075 }
00076
00077 function recursive_revert()
00078 {
00079 $workspace_xml_file = file_content_xml(WS_BOOKS);
00080 $node_dir = dirname($workspace_xml_file);
00081 $node_dir = str_replace('./', '', $node_dir);
00082
00083
00084 $result = shell("svn revert -R $node_dir");
00085 $result = str_replace($node_dir.'/', '', $result);
00086 if ($result != '') WebApp::message($result);
00087
00088
00089 $book_id = WebApp::getSVar('docbook->book_id');
00090 $lng = WebApp::getSVar('docbook->lng');
00091 $node_path = WebApp::getSVar('docbook->node_path');
00092 shell(CONTENT."cache/cache.sh $book_id $lng 'workspace' '$node_path'");
00093
00094
00095 $this->set_all_synchronized($node_dir);
00096
00097
00098 remove_from_modified_nodes($node_path, true);
00099 }
00100
00101 function set_all_synchronized($node_dir)
00102 {
00103 shell(SCRIPTS."approve/set_synchronized.sh $node_dir");
00104 }
00105
00106 function on_commit($event_args)
00107 {
00108 $log = trim($event_args['log']);
00109
00110 $recursive = ($event_args['recursive'] == 'true');
00111 if ($recursive)
00112 $this->recursive_commit($log);
00113 else
00114 $this->non_recursive_commit($log);
00115 }
00116
00117 function non_recursive_commit($log)
00118 {
00119
00120 if ($log!='') $log = "\nLog: ".$log;
00121 $arr_state = get_node_state();
00122 extract($arr_state);
00123 $m_time = date('Y-m-d H:i', $m_timestamp);
00124 $time = date('Y-m-d H:i');
00125 $msg = ("Modified by $m_user, $m_time. "
00126 . "Approved by ".USER.", $time".$log);
00127
00128
00129 $workspace_xml_file = file_content_xml(WS_BOOKS);
00130 $node_dir = dirname($workspace_xml_file);
00131 shell(SCRIPTS."approve/svn_commit.sh $node_dir '$msg'");
00132
00133
00134 $book_id = WebApp::getSVar('docbook->book_id');
00135 $lng = WebApp::getSVar('docbook->lng');
00136 $tag = book_fixed_to_tag($book_id, $lng);
00137
00138 if ($tag)
00139 $this->msg_book_fixed_to_tag($tag);
00140 else
00141 {
00142
00143 $public_xml_file = file_content_xml(BOOKS);
00144 $node_dir = dirname($public_xml_file);
00145 shell("svn update -N $node_dir");
00146
00147
00148 update_cache('public');
00149
00150 $node_path = WebApp::getSVar('docbook->node_path');
00151 update_cache_files($node_path);
00152 }
00153
00154
00155 set_node_status('synchronized');
00156
00157
00158 remove_from_modified_nodes();
00159 }
00160
00161 function msg_book_fixed_to_tag($tag)
00162 {
00163 $book_id = WebApp::getSVar('docbook->book_id');
00164 $lng = WebApp::getSVar('docbook->lng');
00165
00166 $msg = T_("The book (v_book_id, v_lng) is fixed to v_tag, \
00167 so the changes will not be displayed in the public copy.");
00168
00169 $msg = str_replace('v_book_id', $book_id, $msg);
00170 $msg = str_replace('v_lng', $lng, $msg);
00171 $msg = str_replace('v_tag', $tag, $msg);
00172
00173 WebApp::message($msg);
00174 }
00175
00176 function recursive_commit($log)
00177 {
00178
00179 if ($log!='') $log = "\nLog: ".$log;
00180 $workspace_xml_file = file_content_xml(WS_BOOKS);
00181 $node_dir = dirname($workspace_xml_file);
00182 $msg = date('Y-m-d H:i').' >> Approved by '.USER . $log;
00183 shell("svn commit $node_dir -m '$msg'");
00184
00185
00186 $book_id = WebApp::getSVar('docbook->book_id');
00187 $lng = WebApp::getSVar('docbook->lng');
00188 $tag = book_fixed_to_tag($book_id, $lng);
00189
00190 if ($tag)
00191 $this->msg_book_fixed_to_tag($tag);
00192 else
00193 {
00194
00195 $public_xml_file = file_content_xml(BOOKS);
00196 $node_dir = dirname($public_xml_file).'/';
00197 shell("svn update $node_dir");
00198
00199
00200 $node_path = WebApp::getSVar('docbook->node_path');
00201 shell(CONTENT."cache/cache.sh $book_id $lng 'books' '$node_path'");
00202
00203 update_cache_files($node_path);
00204 }
00205
00206
00207 $node_dir = dirname($workspace_xml_file);
00208 $this->set_all_synchronized($node_dir);
00209
00210
00211 $node_path = WebApp::getSVar('docbook->node_path');
00212 remove_from_modified_nodes($node_path, true);
00213 }
00214
00215 function onRender()
00216 {
00217
00218 $arr_state = get_node_state();
00219 WebApp::addVar('status', $arr_state['status']);
00220 $m_user = $arr_state['m_user'];
00221 $m_email = $arr_state['m_email'];
00222 WebApp::addVar('m_user', "<a href='mailto:$m_email'>$m_user</a>");
00223 $m_time = get_date_str($arr_state['m_timestamp']);
00224 WebApp::addVar('m_time', $m_time);
00225
00226
00227 $locked_by_somebody = locked_by_somebody($arr_state);
00228 $str_locked_by_somebody = ($locked_by_somebody ? 'true' : 'false');
00229 $str_locked = (is_locked($arr_state) ? 'true' : 'false');
00230 WebApp::addVar('locked_by_somebody', $str_locked_by_somebody);
00231 WebApp::addVar('locked', $str_locked);
00232
00233
00234 if ($locked_by_somebody)
00235 {
00236 extract($arr_state);
00237 $msg = T_("This node is locked for v_mode\n\
00238 by v_l_user (v_l_email).\n\
00239 Please try again later.");
00240 $msg = str_replace('v_mode', $mode, $msg);
00241 $msg = str_replace('v_l_user', $l_user, $msg);
00242 $msg = str_replace('v_l_email', $l_email, $msg);
00243 WebApp::message($msg);
00244 WebApp::addVar('l_mode', $mode);
00245 WebApp::addVar('l_user', "<a href='mailto:$l_email'>$l_user</a>");
00246 return;
00247 }
00248
00249
00250 ereg('([^/]+)/$', $node_path, $regs);
00251 $id = $regs[1];
00252 if ($id=='.') $id = WebApp::getSVar('docbook->book_id');
00253 WebApp::addVar("id", $id);
00254
00255
00256 $content_diff = $this->get_content_diff();
00257 WebApp::addVar('content_diff', $content_diff."\n");
00258
00259
00260 $svn_status = $this->get_svn_status();
00261 WebApp::addVar('svn_status', $svn_status."\n");
00262
00263 $view_revisions = (trim($diff)=='' ? 'true' : 'false');
00264 WebApp::addVar('view_revisions', $view_revisions);
00265 }
00266
00268 function get_content_diff()
00269 {
00270 $file_xml = file_content_xml();
00271 $get_title_xsl = XSLT.'edit/get_content_title.xsl';
00272
00273
00274 $xml_HEAD = shell("svn cat $file_xml -r HEAD");
00275 $file_xml_head = write_tmp_file($xml_HEAD);
00276
00277
00278 $title = shell("xsltproc $get_title_xsl $file_xml_head");
00279 $txt = get_node_content($file_xml_head, 'text');
00280 $txt = 'T: '.$title."\n\n".trim($txt)."\n";
00281 $file_txt_head = write_tmp_file($txt);
00282
00283
00284 $title = shell("xsltproc $get_title_xsl $file_xml");
00285 $txt = get_node_content($file_xml, 'text');
00286 $txt = 'T: '.$title."\n\n".trim($txt)."\n";
00287 $file_txt = write_tmp_file($txt);
00288
00289
00290 $diff = shell("diff -ubB $file_txt_head $file_txt | sed '1,2d'");
00291
00292
00293 unlink($file_xml_head);
00294 unlink($file_txt_head);
00295 unlink($file_txt);
00296
00297
00298 $diff = htmlspecialchars($diff);
00299 $patterns = array(
00300 '/^(@@.*@@)$/m',
00301 '/^-(.*)$/m',
00302 '/^\+(.*)$/m',
00303 '/^ (.*)$/m'
00304 );
00305 $replacements = array(
00306 '<div class="line_nr">\\1</div>',
00307 '<div class="removed"> \\1</div>',
00308 '<div class="added"> \\1</div>',
00309 '<div class="context"> \\1</div>'
00310 );
00311 $diff = preg_replace($patterns, $replacements, $diff);
00312
00313 return $diff;
00314 }
00315
00320 function get_svn_status()
00321 {
00322
00323 $path = dirname(file_content_xml());
00324 $path = str_replace('./', '', $path);
00325 $path .= '/';
00326
00327
00328 $sed_expr = "-e '/^\\? /d' -e '/state\\.txt/d' -e 's#$path##'";
00329 $status = shell("svn status $path | sed $sed_expr");
00330
00331
00332 $status = trim($status);
00333 $patterns = array(
00334 '/^(M +.*)$/m',
00335 '/^(D +.*)$/m',
00336 '/^(A +.*)$/m'
00337 );
00338 $replacements = array(
00339 '<span class="modified">\\1</span>',
00340 '<span class="removed">\\1</span>',
00341 '<span class="added">\\1</span>'
00342 );
00343 $status = preg_replace($patterns, $replacements, $status);
00344
00345 return $status;
00346 }
00347 }
00348 ?>