main.php

Go to the documentation of this file.
00001 <?php
00002   /*
00003    This file is part of DocBookWiki.  DocBookWiki is a web application
00004    that displays and edits DocBook documents.
00005 
00006    Copyright (C) 2004, 2005, 2006, 2007
00007    Dashamir Hoxha, dashohoxha@users.sourceforge.net
00008 
00009    DocBookWiki is free software; you can redistribute it and/or modify
00010    it under the  terms of the GNU General  Public License as published
00011    by the Free  Software Foundation; either version 2  of the License,
00012    or (at your option) any later version.
00013 
00014    DocBookWiki is distributed in the  hope that it will be useful, but
00015    WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
00016    MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
00017    General Public License for more details.
00018 
00019    You should have  received a copy of the  GNU General Public License
00020    along  with  DocBookWiki;  if  not,  write  to  the  Free  Software
00021    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022    USA
00023   */
00024 
00028 class main extends WebObject
00029 {
00030   function init()
00031   {
00032     //get the book that will be displayed initially
00033     $book_id = $this->check_book_id(DEFAULT_BOOK);
00034 
00035     //get languages
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     //set book_title
00041     $book_title = $this->get_book_title($book_id, $lng);
00042     WebApp::addSVar('book_title', $book_title);
00043  
00044     //init docbook state variables
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     //display docbook in the content part
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     //get languages
00078     $arr_langs = $this->get_langs($book_id);
00079     $langs = implode(',', $arr_langs);
00080 
00081     //check lng (in case that the current language 
00082     //is not available for this book)
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     //set book_title
00091     $book_title = $this->get_book_title($book_id, $lng);
00092     WebApp::setSVar('book_title', $book_title);
00093 
00094     //set some other state variables
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     //get languages
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     //set book_title
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 { /* do nothing, display the last search */ }
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     //get languages
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     //set docbook state variables
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     //set book_title
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     //get languages
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         //get node path from node id
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     //set the state variables of the docbook webbox
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     //set book_title
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 ?>

Generated on Wed Jan 9 08:27:32 2008 for DokBookWiki by  doxygen 1.5.2