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
00028 class main extends WebObject
00029 {
00030 function init()
00031 {
00032
00033 $book_id = $this->check_book_id(DEFAULT_BOOK);
00034
00035
00036 $arr_langs = $this->get_langs($book_id);
00037 $langs = implode(',', $arr_langs);
00038 $lng = (in_array(LNG, $arr_langs) ? LNG : $arr_langs[0]);
00039
00040
00041 $book_title = $this->get_book_title($book_id, $lng);
00042 WebApp::addSVar('book_title', $book_title);
00043
00044
00045 WebApp::addSVar('docbook->book_id', $book_id);
00046 WebApp::addSVar('docbook->node_path', './');
00047 WebApp::addSVar('docbook->languages', $langs);
00048 WebApp::addSVar('docbook->lng', $lng);
00049 WebApp::addSVar('docbook->mode', 'view');
00050
00051
00052 $this->addSVar('content_file', 'docbook/docbook.html');
00053 }
00054
00060 function check_book_id($book_id)
00061 {
00062 if (!file_exists(BOOKS.$book_id))
00063 {
00064 $msg = T_("Book 'v_book_id' not found.");
00065 $msg = str_replace('v_book_id', $book_id, $msg);
00066 WebApp::message($msg);
00067 $book_id = 'docbookwiki_guide';
00068 }
00069 return $book_id;
00070 }
00071
00072 function on_book($event_args)
00073 {
00074 $book_id = $event_args['book_id'];
00075 $book_id = $this->check_book_id($book_id);
00076
00077
00078 $arr_langs = $this->get_langs($book_id);
00079 $langs = implode(',', $arr_langs);
00080
00081
00082
00083 $lng = WebApp::getSVar('docbook->lng');
00084 if (!in_array($lng, $arr_langs))
00085 {
00086 $lng = $arr_langs[0];
00087 WebApp::setSVar('docbook->lng', $lng);
00088 }
00089
00090
00091 $book_title = $this->get_book_title($book_id, $lng);
00092 WebApp::setSVar('book_title', $book_title);
00093
00094
00095 WebApp::setSVar('docbook->book_id', $book_id);
00096 WebApp::setSVar('docbook->languages', $langs);
00097 WebApp::setSVar('docbook->node_path', './');
00098 }
00099
00100 function on_approve($event_args)
00101 {
00102 extract($event_args);
00103 if (!isset($book_id)) $book_id = WebApp::getSVar('docbook->book_id');
00104 if (!isset($node_path)) $node_path = WebApp::getSVar('docbook->node_path');
00105 if (!isset($lng)) $lng = WebApp::getSVar('docbook->lng');
00106
00107
00108 $arr_langs = $this->get_langs($book_id);
00109 $langs = implode(',', $arr_langs);
00110
00111 WebApp::setSVar('docbook->book_id', $book_id);
00112 WebApp::setSVar('docbook->node_path', $node_path);
00113 WebApp::setSVar('docbook->lng', $lng);
00114 WebApp::setSVar('docbook->languages', $langs);
00115 WebApp::setSVar('docbook->mode', 'approve');
00116
00117
00118 $book_title = $this->get_book_title($book_id, $lng);
00119 WebApp::setSVar('book_title', $book_title);
00120 }
00121
00122 function on_search($event_args)
00123 {
00124 $words = $event_args['words'];
00125 if (trim($words) != '')
00126 {
00127 WebApp::setSVar('search->expression', trim($words));
00128 WebApp::setSVar('search->all_books', '');
00129 WebApp::setSVar('search->all_langs', '');
00130 WebApp::setSVar('search->recs_per_page', '20');
00131 WebApp::setSVar('search->current_page', '1');
00132 }
00133 else { }
00134
00135 $this->setSVar('content_file', 'main/search/search.html');
00136 }
00137
00138 function on_docbook($event_args)
00139 {
00140 $this->setSVar('content_file', 'docbook/docbook.html');
00141 if (!isset($event_args['node_path'])) return;
00142
00143 $book_id = $event_args['book_id'];
00144
00145
00146 $arr_langs = $this->get_langs($book_id);
00147 $langs = implode(',', $arr_langs);
00148
00149 if (!file_exists(BOOKS.$book_id))
00150 {
00151 $msg = T_("Book 'v_book_id' not found.");
00152 $msg = str_replace('v_book_id', $book_id, $msg);
00153 WebApp::message($msg);
00154 $book_id = 'docbookwiki_guide';
00155 $lng = 'en';
00156 $node_path = './';
00157 }
00158 else
00159 {
00160 $node_path = $event_args['node_path'];
00161 $lng = $event_args['lng'];
00162 if ($lng=='')
00163 {
00164 $msg = T_("Language 'v_lng' not found.");
00165 $msg = str_replace('v_lng', $lng, $msg);
00166 WebApp::message($msg);
00167 $lng = $arr_langs[0];
00168 }
00169 }
00170
00171
00172 WebApp::setSVar('docbook->book_id', $book_id);
00173 WebApp::setSVar('docbook->node_path', $node_path);
00174 WebApp::setSVar('docbook->languages', $langs);
00175 WebApp::setSVar('docbook->lng', $lng);
00176
00177
00178 $book_title = $this->get_book_title($book_id, $lng);
00179 WebApp::setSVar('book_title', $book_title);
00180 }
00181
00183 function on_xref($event_args)
00184 {
00185 $this->setSVar('content_file', 'docbook/docbook.html');
00186
00187 $book_id = $event_args['book_id'];
00188
00189
00190 $arr_langs = $this->get_langs($book_id);
00191 $langs = implode(',', $arr_langs);
00192
00193 if (!file_exists(BOOKS.$book_id))
00194 {
00195 $msg = T_("Book 'v_book_id' not found.");
00196 $msg = str_replace('v_book_id', $book_id, $msg);
00197 WebApp::message($msg);
00198 $book_id = 'docbookwiki_guide';
00199 $lng = 'en';
00200 $node_path = './';
00201 }
00202 else
00203 {
00204 $lng = $event_args['lng'];
00205 if ($lng=='') $lng = $arr_langs[0];
00206
00207
00208 $node_id = $event_args['node_id'];
00209 $xsl = XSLT.'edit/get_node_path.xsl';
00210 $index_xml = BOOKS."$book_id/$lng/index.xml";
00211 $param_id = "--stringparam id '$node_id'";
00212 $node_path = shell("xsltproc $param_id $xsl $index_xml");
00213 if ($node_path=='') $node_path = './';
00214 }
00215 $mode = $event_args['mode'];
00216 if ($mode=='') $mode = 'view';
00217
00218
00219 WebApp::setSVar('docbook->book_id', $book_id);
00220 WebApp::setSVar('docbook->node_path', $node_path);
00221 WebApp::setSVar('docbook->languages', $langs);
00222 WebApp::setSVar('docbook->lng', $lng);
00223 WebApp::setSVar('docbook->mode', $mode);
00224
00225
00226 $book_title = $this->get_book_title($book_id, $lng);
00227 WebApp::setSVar('book_title', $book_title);
00228 }
00229
00230
00231 function onRender()
00232 {
00233 WebApp::addVar("search_button", T_("Search >>"));
00234 }
00235
00240 function get_langs($book_id)
00241 {
00242 $book_path = BOOKS.$book_id.'/';
00243 if (!file_exists($book_path)) return array();
00244
00245 $langs = shell("ls $book_path");
00246 $arr_langs = explode("\n", chop($langs));
00247
00248 return $arr_langs;
00249 }
00250
00251 function get_book_title($book_id, $lng)
00252 {
00253 $book_list = CONTENT.'books/book_list';
00254 $line = shell("sed -n '/^$book_id:$lng:/p' $book_list");
00255 $line = ereg_replace("\n.*", '', $line);
00256 $arr = split(':', $line, 3);
00257 $title = trim($arr[2]);
00258
00259 return $title;
00260 }
00261 }
00262 ?>