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
00032
00037 function file_content_xml($xml_path =WS_BOOKS,
00038 $node_path =UNDEFINED,
00039 $lng =UNDEFINED)
00040 {
00041 if ($node_path==UNDEFINED)
00042 {
00043 $node_path = WebApp::getSVar('docbook->node_path');
00044 }
00045 if ($lng==UNDEFINED)
00046 {
00047 $lng = WebApp::getSVar('docbook->lng');
00048 }
00049
00050 $book_id = WebApp::getSVar('docbook->book_id');
00051 $book_path = $xml_path.$book_id.'/'.$lng.'/';
00052 $content_xml = $book_path.$node_path."content.xml";
00053
00054 return $content_xml;
00055 }
00056
00061 function file_content_html($cache_path =WS_CACHE,
00062 $node_path =UNDEFINED,
00063 $lng =UNDEFINED)
00064 {
00065 if ($node_path==UNDEFINED)
00066 {
00067 $node_path = WebApp::getSVar('docbook->node_path');
00068 }
00069 if ($lng==UNDEFINED)
00070 {
00071 $lng = WebApp::getSVar('docbook->lng');
00072 }
00073 $book_id = WebApp::getSVar('docbook->book_id');
00074 $book_path = $cache_path.$book_id.'/'.$lng.'/';
00075 $content_html = $book_path.$node_path."content.html";
00076
00077 return $content_html;
00078 }
00079
00081 function process_index($transformer, $arr_params =array(),
00082 $books =UNDEFINED, $lng =UNDEFINED)
00083 {
00084 if ($books==UNDEFINED)
00085 {
00086 $books = (defined('EDIT') ? WS_BOOKS : BOOKS);
00087 }
00088 if ($lng==UNDEFINED)
00089 {
00090 $lng = WebApp::getSVar('docbook->lng');
00091 }
00092
00093 $book_id = WebApp::getSVar('docbook->book_id');
00094 $xml_file = $books."$book_id/$lng/index.xml";
00095
00096
00097 $book_dir = '../../'.dirname($xml_file).'/';
00098
00099 $params = "--stringparam book_dir $book_dir ";
00100 while ( list($p_name, $p_value) = each($arr_params) )
00101 {
00102 $params .= "--stringparam $p_name \"$p_value\" ";
00103 }
00104
00105 $xsl_file = XSLT.$transformer;
00106
00107 $output = shell("xsltproc $params $xsl_file $xml_file");
00108
00109 return $output;
00110 }
00111
00118 function get_arr_navigation($node_path, $cache_path =UNDEFINED, $lng =UNDEFINED)
00119 {
00120 if ($cache_path==UNDEFINED)
00121 {
00122 $cache_path = (defined('EDIT') ? WS_CACHE : CACHE);
00123 }
00124 if ($lng==UNDEFINED)
00125 {
00126 $lng = WebApp::getSVar('docbook->lng');
00127 }
00128
00129 $arr_navigation = array();
00130
00131
00132 $book_id = WebApp::getSVar('docbook->book_id');
00133 $book_path = $cache_path.$book_id.'/'.$lng.'/';
00134 $fname = $book_path.$node_path."navigation.txt";
00135 if (!file_exists($fname))
00136 {
00137 $arr_navigation['next_path'] = './';
00138 $arr_navigation['prev_path'] = './';
00139 $arr_navigation['up_path'] = './';
00140 return $arr_navigation;
00141 }
00142
00143
00144 $lines = file($fname);
00145
00146
00147 for ($i=0; $i < sizeof($lines); $i++)
00148 {
00149 $line = $lines[$i];
00150 list($var_name,$var_value) = split('=', $line, 2);
00151 if ($var_name=='') continue;
00152 $arr_navigation[$var_name] = trim($var_value);
00153 }
00154
00155 return $arr_navigation;
00156 }
00157
00159 function update_cache($public ='workspace', $node_path =UNDEFINED, $lng =UNDEFINED)
00160 {
00161 $book_id = WebApp::getSVar('docbook->book_id');
00162
00163 if ($node_path==UNDEFINED)
00164 {
00165 $node_path = WebApp::getSVar('docbook->node_path');
00166 }
00167 $node_path = str_replace('./', '', $node_path);
00168
00169 if ($lng==UNDEFINED)
00170 {
00171 $lng = WebApp::getSVar('docbook->lng');
00172 }
00173
00174 if ($public=='public')
00175 {
00176 $book_path = BOOKS.$book_id.'/'.$lng.'/';
00177 $xml_file = $book_path.$node_path.'content.xml';
00178 $html_file = CACHE.$book_id.'/'.$lng.'/'.$node_path.'content.html';
00179 }
00180 else
00181 {
00182 $book_path = WS_BOOKS.$book_id.'/'.$lng.'/';
00183 $xml_file = $book_path.$node_path.'content.xml';
00184 $html_file = WS_CACHE.$book_id.'/'.$lng.'/'.$node_path.'content.html';
00185 }
00186
00187 $xsl_file = XSLT."cache/update_content.xsl";
00188 $params = "--stringparam book_path \"$book_path\"";
00189 $content_html = shell("xsltproc $params $xsl_file $xml_file");
00190 write_file($html_file, $content_html);
00191 }
00192
00193
00194
00196 function get_state_filename()
00197 {
00198 $book_id = WebApp::getSVar('docbook->book_id');
00199 $node_path = WebApp::getSVar('docbook->node_path');
00200 $lng = WebApp::getSVar('docbook->lng');
00201 $fname = WS_BOOKS.$book_id.'/'.$lng.'/'.$node_path."state.txt";
00202 return $fname;
00203 }
00204
00217 function get_node_state()
00218 {
00219 $fname = get_state_filename();
00220 if (!file_exists($fname))
00221 {
00222 list($lock, $mode, $l_user, $l_email, $l_timestamp)
00223 = array('unlocked', '', '', '', '');
00224 list($status,$m_user,$m_email,$m_timestamp)
00225 = array('none', '', '', '');
00226 }
00227 else
00228 {
00229 $lines = file($fname);
00230 list($lock, $mode, $l_user, $l_email, $l_timestamp)
00231 = explode(':', chop($lines[0]));
00232 list($status,$m_user,$m_email,$m_timestamp)
00233 = explode(':', chop($lines[1]));
00234 }
00235
00236 $arr_state =
00237 compact('lock', 'mode', 'l_user', 'l_email', 'l_timestamp',
00238 'status', 'm_user', 'm_email', 'm_timestamp');
00239 return $arr_state;
00240 }
00241
00242 function write_node_state($arr_state)
00243 {
00244 extract($arr_state);
00245 $str_state = ( "$lock:$mode:$l_user:$l_email:$l_timestamp\n"
00246 ."$status:$m_user:$m_email:$m_timestamp\n");
00247 $fname = get_state_filename();
00248 write_file($fname, $str_state);
00249 }
00250
00255 function set_node_status($new_status)
00256 {
00257 $arr_state = get_node_state();
00258 $arr_state['status'] = $new_status;
00259 $arr_state['m_user'] = USER;
00260 $arr_state['m_email'] = EMAIL;
00261 $arr_state['m_timestamp'] = time();
00262 write_node_state($arr_state);
00263 }
00264
00270 function set_node_lock($lock, $mode)
00271 {
00272
00273 $arr_state = get_node_state();
00274 if (locked_by_somebody($arr_state)) return;
00275
00276 $arr_state['lock'] = $lock;
00277 if ($lock=='locked')
00278 {
00279 $arr_state['mode'] = $mode;
00280 $arr_state['l_user'] = USER;
00281 $arr_state['l_email'] = EMAIL;
00282 $arr_state['l_timestamp'] = time();
00283 }
00284 write_node_state($arr_state);
00285 }
00286
00291 function locked_by_somebody($arr_state =UNDEFINED)
00292 {
00293 if ($arr_state==UNDEFINED) $arr_state = get_node_state();
00294 if ($arr_state['l_user']==USER) return false;
00295 return is_locked($arr_state);
00296 }
00297
00299 function is_locked($arr_state)
00300 {
00301 extract($arr_state);
00302 if ($lock=='unlocked') return false;
00303
00304
00305
00306 if ( (time() - $l_timestamp) > 15*60 )
00307 {
00308 if ($m_timestamp=='') return false;
00309 if ( (time() - $m_timestamp) > 15*60 ) return false;
00310 }
00311
00312 return true;
00313 }
00314
00320 function get_date_str($timestamp)
00321 {
00322 $day = 24*60*60;
00323 $t = getdate(time());
00324 $midnight = mktime(1, 1, 0, $t['mon'], $t['mday'], $t['year']);
00325 $firstday = mktime(1, 1, 0, 1, 1, $t['year']);
00326
00327 if ($timestamp > $midnight)
00328 {
00329 $date = date('H:i', $timestamp);
00330 $str = T_("today at v_date_H:i");
00331 $str = str_replace('v_date_H:i', $date, $str);
00332 return $str;
00333 }
00334
00335 if ($timestamp > $midnight - $day)
00336 {
00337 $date = date('H:i', $timestamp);
00338 $str = T_("yesterday at v_date_H:i");
00339 $str = str_replace('v_date_H:i', $date, $str);
00340 return $str;
00341 }
00342
00343 if ($timestamp > $midnight - 6*$day)
00344 {
00345 $date = date('D H:i', $timestamp);
00346 $str = T_("on v_date_D_H:i");
00347 $str = str_replace('v_date_D_H:i', $date, $str);
00348 return $str;
00349 }
00350
00351 if ($timestamp > $firstday)
00352 {
00353 $date = date('M d, H:i', $timestamp);
00354 $str = T_("on v_date_M_d_H:i");
00355 $str = str_replace('v_date_M_d_H:i', $date, $str);
00356 return $str;
00357 }
00358
00359
00360 $date = date('M d, Y', $timestamp);
00361 $str = T_("on v_date_M_d_Y");
00362 $str = str_replace('v_date_M_d_Y', $date, $str);
00363 return $str;
00364 }
00365
00366
00372 function book_fixed_to_tag($book_id, $lng)
00373 {
00374 $book_dir = BOOKS."$book_id/$lng/";
00375
00376 if (file_exists($book_dir.'fixed'))
00377 {
00378 $lines = file($book_dir.'fixed');
00379 $tag = trim($lines[0]);
00380 return $tag;
00381 }
00382 else
00383 return false;
00384 }
00385 ?>