Events.php

00001 <?php
00002 /*
00003  * Copyright (C) 2003-2006 Polytechnique.org
00004  * http://opensource.polytechnique.org/
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 define('EVENT_FLAG_NONE', 0);
00022 define('EVENT_FLAG_PUBLIC', 1);
00023 
00026 class Diogenes_Barrel_Events
00027 {
00029   var $barrel;
00030 
00033   function Diogenes_Barrel_Events(&$barrel)
00034   {
00035     $this->barrel = $barrel;
00036   }
00037 
00038 
00041   function makeFileLoc($log_file, &$caller)
00042   {
00043     $homepage = $this->barrel->getPID('');
00044     if (stristr($log_file, '/') == FALSE ) {
00045       // this is a directory
00046       $mydir = $log_file;
00047       $myfile = '';
00048     } else {
00049       $myfile = basename($log_file);
00050       $mydir = dirname($log_file);
00051     }
00052 
00053     $myloc = $this->barrel->getLocation($mydir);
00054     if ($myloc or ($mydir == $homepage))
00055     {
00056       $log_file = $myloc ? "$myloc/$myfile" : $myfile;
00057       $url_loc = $myloc ? "$myloc/" : '';
00058       $link = $caller->urlBarrel($this->barrel->alias, $this->barrel->vhost, $url_loc);
00059     } else {
00060       $link = '';
00061     }
00062   
00063     return array($log_file, $mydir, $myfile, $link);
00064   }
00065 
00068   function getEvents($caller)
00069   {
00070     global $globals;
00071     $events = array();
00072     $res = $globals->db->query("select e.action,e.stamp,e.data,a.text,s.auth,s.uid "
00073                   ."from {$globals->table_log_events} as e "
00074                   ."left join {$globals->table_log_actions} as a on e.action=a.id "
00075                   ."left join {$globals->table_log_sessions} as s on e.session=s.id "
00076                   ."where e.data like '{$this->barrel->alias}:%' "
00077                   ."order by stamp desc limit 0,10");
00078     while ($myarr = mysql_fetch_assoc($res)) {
00079       $myarr['author'] = call_user_func(array($globals->session,'getUsername'),$myarr['auth'],$myarr['uid']);
00080       $myarr['flags'] = EVENT_FLAG_NONE;
00081       list($op_alias, $op_file) = split(":",$myarr['data']);
00082 
00083       switch($myarr['text']) {
00084       case "barrel_create":
00085         $myarr['title'] = __("site created");
00086         $myarr['icon'] = $globals->icons->get_action_icon('add');    
00087         break;
00088     
00089       case "barrel_options":
00090         $myarr['title'] = __("barrel options");
00091         $myarr['icon'] = $globals->icons->get_action_icon('properties');    
00092         break;
00093   
00094       case "barrel_plugins":
00095         $myarr['title'] = __("barrel plugins");
00096         $myarr['icon'] = $globals->icons->get_action_icon('plugins');
00097         $myarr['link_admin'] = "plugins";
00098         break;
00099         
00100       case "page_create":
00101         $myarr['title'] = __("page created");
00102         $myarr['icon'] = $globals->icons->get_action_icon('add');    
00103         list($op_file, $myarr['dir'], $myarr['file'], $myarr['link']) = $this->makeFileLoc($op_file, $caller);
00104         $myarr['link_admin'] = "pages?dir={$myarr['dir']}";
00105         $myarr['flags'] |= EVENT_FLAG_PUBLIC;
00106         break;
00107 
00108       case "page_delete":
00109         $myarr['title'] = __("page removed");
00110         $myarr['icon'] = $globals->icons->get_action_icon('remove');
00111         break;
00112     
00113       case "page_props":
00114         $myarr['title'] = __("page properties");
00115         $myarr['icon'] = $globals->icons->get_action_icon('properties');
00116         list($op_file, $myarr['dir'], $myarr['file']) = $this->makeFileLoc($op_file, $caller);
00117         $myarr['link_admin'] = "pages?dir={$myarr['dir']}";
00118         break;
00119   
00120       case "page_plugins":
00121         $myarr['title'] = __("page plugins");
00122         $myarr['icon'] = $globals->icons->get_action_icon('plugins');
00123         list($op_file, $myarr['dir'], $myarr['file']) = $this->makeFileLoc($op_file, $caller);
00124         $myarr['link_admin'] = "plugins?plug_page={$myarr['dir']}";
00125         break;
00126 
00127       case "rcs_commit": 
00128         $myarr['title'] = __("file updated");
00129         $myarr['icon'] = $globals->icons->get_action_icon('update');    
00130         list($op_file, $myarr['dir'], $myarr['file'], $myarr['link']) = $this->makeFileLoc($op_file, $caller);  
00131         $myarr['link_admin'] = "files?action=revs&amp;dir={$myarr['dir']}&amp;target={$myarr['file']}";
00132         $myarr['flags'] |= EVENT_FLAG_PUBLIC;
00133 
00134         break;
00135       
00136       case "rcs_delete":
00137         $myarr['title'] = __("file deleted");        
00138         $myarr['icon'] = $globals->icons->get_action_icon('delete');    
00139         list($op_file, $myarr['dir'], $myarr['file']) = $this->makeFileLoc($op_file, $caller);    
00140         break;
00141       }
00142       $myarr['opfile'] = $op_file;
00143  
00144       if (isset($myarr['title']))
00145         array_push($events, $myarr);
00146     }
00147     mysql_free_result($res);
00148     return $events;
00149   }
00150 }
00151 
00152 ?>

Generated on Fri Jan 11 01:20:08 2008 for Diogenes by  doxygen 1.5.1