global.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 
00030 function shell($cmd)
00031 {
00032   //some basic check for invalid input
00033   $cmd = ereg_replace(';.*', '', $cmd);
00034   $cmd .= ' 2>&1';
00035   $data_owner = DATA_OWNER;
00036   $output = shell_exec("sudo -u $data_owner $cmd");
00037   //print "<xmp>sudo -u $data_owner $cmd \n----- \n$output</xmp>\n";  //debug
00038   return $output;
00039 }
00040 
00045 function write_file($fname, &$fcontent)
00046 {
00047   //create the directories in the path, in case they do not exist
00048   shell('mkdir -p '.dirname($fname));
00049 
00050   //write the content to a temporary file
00051   $tmp_fname = write_tmp_file($fcontent);
00052 
00053   //copy the temporary file to the fname
00054   shell("cp $tmp_fname $fname");
00055 
00056   //delete the temporary file
00057   unlink($tmp_fname);
00058 }
00059 
00065 function write_tmp_file(&$fcontent)
00066 {
00067   //get the name of a temporary file
00068   $tmpfile = tempnam('/tmp', 'dbwiki_');
00069 
00070   //open the file and write the content
00071   $fp = fopen($tmpfile, 'w');
00072   fputs($fp, $fcontent);
00073   fclose($fp);
00074 
00075   //make the file read-writeable by everybody
00076   chmod($tmpfile, 0666);
00077 
00078   //return the name of the file
00079   return $tmpfile;
00080 }
00081 
00086 function array2str($assoc_array)
00087 {
00088   while ( list($key, $value) = each($assoc_array) )
00089     {
00090       $str_array[] = "$key=\"$value\"";
00091     }
00092   return implode(', ', $str_array);
00093 }
00094 ?>

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