modified_nodes.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 
00025 include_once SCRIPTS.'user_data.php';
00026 
00033 class modified_nodes extends WebObject
00034 {
00041   function onRender()
00042   {
00043     $rs = new EditableRS('modified_nodes');
00044 
00045     //get the books for which the user is admin
00046     $arr_books_admin = $this->get_arr_books_admin();
00047 
00048     //add in the recordset all the modified nodes in the books
00049     //for which the user is admin
00050     $this->add_is_admin($rs, $arr_books_admin);
00051 
00052     //find the books where the user has some access rights and is not admin
00053     $arr_books_accr = $this->get_arr_books_accr($arr_books_admin);
00054 
00055     //find the modified nodes in these books that can be approved 
00056     //by user and add them in the recordset
00057     $this->add_has_accr($rs, $arr_books_accr);
00058 
00059     //add the recordset to the webPage
00060     global $webPage;
00061     $webPage->addRecordset($rs);
00062   }
00063 
00065   function get_arr_books_admin()
00066   {
00067     $user_data = get_user_data(USER);
00068     $books = trim($user_data['books']);
00069     $arr_books = explode(',', $books);
00070 
00071     $last_idx = sizeof($arr_books) - 1;
00072     if ($arr_books[$last_idx]=='')  unset($arr_books[$last_idx]);
00073 
00074     return $arr_books;
00075   }
00076 
00081   function add_is_admin(&$rs, $arr_books_admin)
00082   {
00083     for ($i=0; $i < sizeof($arr_books_admin); $i++)
00084       {
00085         $book_id = $arr_books_admin[$i];
00086         $book_path = WS_BOOKS.$book_id.'/';
00087         $output = shell("ls $book_path/");
00088         $arr_langs = explode("\n", trim($output));
00089         for ($l=0; $l < sizeof($arr_langs); $l++)
00090           {
00091             $lng = $arr_langs[$l];
00092             $filename = "$book_path/$lng/modified_nodes.txt";
00093             if (!file_exists($filename))  continue;
00094             $arr_modified_nodes = file($filename);
00095             for ($n=0; $n < sizeof($arr_modified_nodes); $n++)
00096               {
00097                 $node_path = $arr_modified_nodes[$n];
00098                 $node_path = trim($node_path);
00099                 $node_title = $this->get_title($book_id, $lng, $node_path);
00100                 $rec = compact('book_id', 'lng', 'node_path', 'node_title');
00101                 $rs->addRec($rec);          
00102               }
00103           }
00104       }
00105   }
00106 
00111   function get_arr_books_accr($arr_books_admin)
00112   {
00113     $arr_books_accr = array();
00114 
00115     $accr_path = ADMIN.'access_rights/';
00116     $user = USER;
00117     $output = shell("find $accr_path -type f -name '$user'");
00118     $arr_files = explode("\n", $output);
00119 
00120     for ($i=0; $i < sizeof($arr_files); $i++)
00121       {
00122         $file = trim($arr_files[$i]);
00123         if ($file=='')  continue;
00124         $book_id = basename(dirname($file));
00125         if (!in_array($book_id, $arr_books_admin))
00126           {
00127             $arr_books_accr[] = $book_id;
00128           }
00129       }
00130 
00131     return $arr_books_accr;
00132   }
00133 
00138   function add_has_accr(&$rs, $arr_books_accr)
00139   {
00140     for ($i=0; $i < sizeof($arr_books_accr); $i++)
00141       {
00142         $book_id = $arr_books_accr[$i];
00143 
00144         //get the access right rules for this book and the current user
00145         $accr_file = ADMIN . "access_rights/$book_id/" . USER;
00146         $accr_rules = file($accr_file);
00147 
00148         //get the languages of the book
00149         $book_path = WS_BOOKS.$book_id.'/';
00150         $output = shell("ls $book_path/");
00151         $arr_langs = explode("\n", trim($output));
00152 
00153         //process the modified nodes for all the languages of the book
00154         for ($l=0; $l < sizeof($arr_langs); $l++)
00155           {
00156             $lng = $arr_langs[$l];
00157             $filename = "$book_path/$lng/modified_nodes.txt";
00158             if (!file_exists($filename))  continue;
00159             $arr_modified_nodes = file($filename);
00160             for ($n=0; $n < sizeof($arr_modified_nodes); $n++)
00161               {
00162                 $node_path = $arr_modified_nodes[$n];
00163                 $node_path = trim($node_path);
00164 
00165                 //add the modified node to recordset,
00166                 //if the user can approve it
00167                 if ($this->has_approve_right($lng, $node_path, $accr_rules))
00168                   {
00169                     $node_title = $this->get_title($book_id,$lng,$node_path);
00170                     $rec = compact('book_id','lng','node_path','node_title');
00171                     $rs->addRec($rec);
00172                   }
00173               }
00174           }
00175       }
00176   }
00177 
00179   function has_approve_right($lng, $node_path, $arr_access_rights)
00180   {
00181     //try to match the given node and language with the access rights
00182     $approve = false;
00183     for ($i=0; $i < sizeof($arr_access_rights); $i++)
00184       {
00185         $line = trim($arr_access_rights[$i]);
00186         list($access,$levels,$nodes,$langs) = explode(':', $line);
00187 
00188         //if this line matches the given node and language 
00189         //then set the value of approve according to it
00190         if ($this->node_match($node_path, $nodes)
00191             and $this->lang_match($lng, $langs))
00192           {
00193             $arr_levels = explode(',', $levels);
00194             if (in_array('approve', $arr_levels))
00195               {
00196                 $approve = ($access=='allow' ? true : false);
00197               }
00198           }
00199       }
00200 
00201     return $approve;
00202   }
00203 
00211   function node_match($node_path, $node_list)
00212   {
00213     if (strtoupper($node_list)=='ALL')  return true;
00214 
00215     $arr_nodes = explode(',', $node_list);
00216     for ($i=0; $i < sizeof($arr_nodes); $i++)
00217       {
00218         $expr = $arr_nodes[$i];
00219         if (ereg('^'.$expr, $node_path)) return true;
00220       }
00221   }
00222 
00229   function lang_match($lng, $lang_list)
00230   {
00231     if (strtoupper($lang_list)=='ALL')  return true;
00232 
00233     $arr_langs = explode(',', $lang_list);
00234     $match = in_array($lng, $arr_langs);
00235 
00236     return $match;
00237   }
00238 
00239   function get_title($book_id, $lng, $node_path)
00240   {
00241     $cache_path = WS_CACHE."$book_id/$lng/";
00242     $navigation_file = $cache_path.$node_path."navigation.txt";
00243     $line = shell("grep full_title $navigation_file");
00244     $arr = split('=', chop($line), 2);
00245     $title = $arr[1];
00246     if ($title=='')  $title = 'Table Of Contents';
00247     return $title;
00248   }
00249 }
00250 ?>

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