tags.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 dirname(__FILE__).'/func.popup_window.php';
00026 
00034 class tags extends WebObject
00035 {
00036   function set_revision($revision)
00037   {
00038     $book_id = WebApp::getSVar('docbook->book_id');
00039     $lng = WebApp::getSVar('docbook->lng');
00040     $book_dir = BOOKS."$book_id/$lng/";
00041 
00042     //if it is sticked to a tag, then switch first to the trunk
00043     $tag = $this->get_current_tag();
00044     if ($tag != '')
00045       {
00046         $url = $this->get_svn_url();
00047         shell("svn switch $url/trunk/ $book_dir");
00048       }
00049 
00050     //update to the given revision
00051     $output = shell("svn update -r $revision $book_dir");
00052     popup_window(T_("Updated Files"), $output);
00053 
00054     //update cache files in the public copy for this lng
00055     shell(CONTENT."cache/cache.sh $book_id $lng 'books' './'");
00056   }
00057 
00062   function write_fixed_file($content)
00063   {
00064     $fname = $this->get_book_dir().'fixed';
00065     write_file($fname, $content);
00066   }
00067 
00068   function on_set_tag($event_args)
00069   {
00070     $book_id = WebApp::getSVar('docbook->book_id');
00071     $lng = WebApp::getSVar('docbook->lng');
00072     $book_dir = BOOKS."$book_id/$lng/";
00073 
00074     $tag = $event_args['tag'];
00075     $this->write_fixed_file("tag=$tag");
00076     $url = $this->get_svn_url();
00077     $tag_url = ( $tag=='' ? "$url/trunk/" : "$url/tags/$tag/" );
00078 
00079     //switch to the given tag
00080     $output = shell("svn switch $tag_url $book_dir");
00081     popup_window(T_("Updated Files"), $output);
00082 
00083     //update cache files in the public copy for this lng
00084     shell(CONTENT."cache/cache.sh $book_id $lng 'books' './'");
00085   }
00086 
00087   function on_set_rev($event_args)
00088   {
00089     $rev = $event_args['rev'];
00090     $this->write_fixed_file("rev=$rev");
00091     $this->set_revision($rev);
00092 
00093     //if rev is HEAD, remove the 'fixed' file
00094     if ($rev=='HEAD')
00095       {
00096     $book_dir = $this->get_book_dir();
00097     shell("rm $book_dir/fixed");
00098       }
00099   }
00100 
00101   function on_set_date($event_args)
00102   {
00103     $date = $event_args['date'];
00104     $this->write_fixed_file("date=$date");
00105     $this->set_revision("{'$date'}");
00106   }
00107 
00108   function on_add_tag($event_args)
00109   {
00110     $tag = $event_args['tag'];
00111 
00112     $rev = $this->get_revision_nr();
00113     $date = $this->get_revision_date();
00114     $msg = date('Y-m-d H:i') . " >> Tag $tag created by " . USER
00115       . " for revision $rev (last modified date: $date)";
00116 
00117     $book_dir = $this->get_book_dir();
00118     $url = $this->get_svn_url();
00119     shell("svn copy -m '$msg' $book_dir $url/tags/$tag/");
00120   }
00121 
00122   function on_del_tag($event_args)
00123   {
00124     $tag = $event_args['tag'];
00125     $msg = date('Y-m-d H:i') . " >> Tag $tag deleted by " . USER;
00126     $url = $this->get_svn_url();
00127     shell("svn delete -m '$msg' $url/tags/$tag/");
00128   }
00129 
00130   function onRender()
00131   {
00132     WebApp::addVar('tag', $this->get_current_tag());
00133     WebApp::addVar('revision', $this->get_revision_nr());
00134     WebApp::addVar('revision_date', $this->get_revision_date());
00135     WebApp::addVar('head_revision', $this->get_head_revision());
00136     WebApp::addVar('is_fixed', $this->is_fixed());
00137     $this->add_rs_tags();
00138   }
00139 
00140   function get_current_tag()
00141   {
00142     $book_id = WebApp::getSVar('docbook->book_id');
00143     $lng = WebApp::getSVar('docbook->lng');
00144     $book_dir = BOOKS."$book_id/$lng/";
00145 
00146     $url_line = shell("svn info $book_dir | sed -n '/^URL: /p'");
00147     $url_line = trim($url_line);
00148     $pattern = "/$book_id/$lng/tags/([^/]+)";
00149     $tag = ( ereg($pattern, $url_line, $regs) ? $regs[1] : '' );
00150     return $tag;
00151   }
00152 
00153   function get_revision_nr()
00154   {
00155     $book_dir = $this->get_book_dir();
00156     $rev_line = shell("svn info $book_dir | sed -n '/^Revision: /p'");
00157     $rev = str_replace('Revision: ', '', $rev_line);
00158     $rev = trim($rev);
00159     return $rev;
00160   }
00161 
00162   function get_revision_date()
00163   {
00164     $book_dir = $this->get_book_dir();
00165     $sed = "sed -n '/^Last Changed Date: /p'";
00166     $gawk = 'gawk \'{print $4" "$5}\'';
00167     $date = shell("svn info $book_dir | $sed | $gawk");
00168     $date = trim($date);
00169     return $date;
00170   }
00171 
00172   function get_head_revision()
00173   {
00174     $book_id = WebApp::getSVar('docbook->book_id');
00175     $lng = WebApp::getSVar('docbook->lng');
00176     $svn_dir = SVN."$book_id/$lng/";
00177     $head_rev = shell("svnlook youngest $svn_dir");
00178     $head_rev = trim($head_rev);
00179     return $head_rev;
00180   }
00181 
00182   function is_fixed()
00183   {
00184     $book_dir = $this->get_book_dir();
00185     if (file_exists($book_dir.'fixed'))
00186       return true;
00187     else
00188       return false;
00189   }
00190 
00192   function add_rs_tags()
00193   {
00194     $rs = new EditableRS('rs_tags');
00195 
00196     $url = $this->get_svn_url();
00197     $output = shell("svn list $url/tags/");
00198 
00199     $rs->addRec(array('id'=>'', 'label'=>''));
00200     $lines = explode("\n", $output);
00201     for ($i=0; $i < sizeof($lines); $i++)
00202       {
00203         $line = $lines[$i];
00204         if ($line=='')  continue;
00205         $tag = substr($line, 0, -1);
00206         $rs->addRec(array('id'=>$tag, 'label'=>$tag));
00207       }
00208 
00209     global $webPage;
00210     $webPage->addRecordset($rs);
00211   }
00212 
00214   function get_svn_url()
00215   {
00216     $book_id = WebApp::getSVar('docbook->book_id');
00217     $lng = WebApp::getSVar('docbook->lng');
00218     $book_dir = BOOKS."$book_id/$lng/";
00219 
00220     $url = shell("svn info $book_dir | sed -n '/^URL: /p'");
00221 
00222     $url = ereg_replace('^URL: ', '', $url);
00223     $url = ereg_replace("$book_id/$lng/.*", "$book_id/$lng", $url);
00224 
00225     return $url;
00226   }
00227 
00229   function get_book_dir()
00230   {
00231     $book_id = WebApp::getSVar('docbook->book_id');
00232     $lng = WebApp::getSVar('docbook->lng');
00233     $book_dir = BOOKS."$book_id/$lng/";
00234     return $book_dir;
00235   }
00236 }
00237 ?>

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