From: Jeremy Laine Date: Thu, 20 Jul 2006 17:50:56 +0000 (+0000) Subject: merge selected changes from 'branches/diogenes-newplugins': X-Git-Url: http://git.polytechnique.org/?p=diogenes.git;a=commitdiff_plain;h=51dda5825f66ced0a744d9e49159cedbe0fd5771 merge selected changes from 'branches/diogenes-newplugins': * move all menu-related code to include/Barrel/Menu.php * add RSS feeds for events --- diff --git a/ChangeLog b/ChangeLog index 59686ce..25b9576 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,5 @@ Diogenes 0.9.20pre1 - * TODO + * added - add RSS feeds describing public changes to barrels Diogenes 0.9.19.1 * fixed - fix a warning when a barrel's menu is empty diff --git a/include/Barrel/Events.php b/include/Barrel/Events.php new file mode 100644 index 0000000..5a20fed --- /dev/null +++ b/include/Barrel/Events.php @@ -0,0 +1,152 @@ +barrel = $barrel; + } + + + /** Filename transformations. + */ + function makeFileLoc($log_file, &$caller) + { + $homepage = $this->barrel->getPID(''); + if (stristr($log_file, '/') == FALSE ) { + // this is a directory + $mydir = $log_file; + $myfile = ''; + } else { + $myfile = basename($log_file); + $mydir = dirname($log_file); + } + + $myloc = $this->barrel->getLocation($mydir); + if ($myloc or ($mydir == $homepage)) + { + $log_file = $myloc ? "$myloc/$myfile" : $myfile; + $url_loc = $myloc ? "$myloc/" : ''; + $link = $caller->urlBarrel($this->barrel->alias, $this->barrel->vhost, $url_loc); + } else { + $link = ''; + } + + return array($log_file, $mydir, $myfile, $link); + } + + /** Retrieve recent events. + */ + function getEvents($caller) + { + global $globals; + $events = array(); + $res = $globals->db->query("select e.action,e.stamp,e.data,a.text,s.auth,s.uid " + ."from {$globals->table_log_events} as e " + ."left join {$globals->table_log_actions} as a on e.action=a.id " + ."left join {$globals->table_log_sessions} as s on e.session=s.id " + ."where e.data like '{$this->barrel->alias}:%' " + ."order by stamp desc limit 0,10"); + while ($myarr = mysql_fetch_array($res)) { + $myarr['author'] = call_user_func(array($globals->session,'getUsername'),$myarr['auth'],$myarr['uid']); + $myarr['flags'] = EVENT_FLAG_NONE; + list($op_alias, $op_file) = split(":",$myarr['data']); + + switch($myarr['text']) { + case "barrel_create": + $myarr['title'] = __("site created"); + $myarr['icon'] = $globals->icons->get_action_icon('add'); + break; + + case "barrel_options": + $myarr['title'] = __("barrel options"); + $myarr['icon'] = $globals->icons->get_action_icon('properties'); + break; + + case "barrel_plugins": + $myarr['title'] = __("barrel plugins"); + $myarr['icon'] = $globals->icons->get_action_icon('plugins'); + $myarr['link_admin'] = "plugins"; + break; + + case "page_create": + $myarr['title'] = __("page created"); + $myarr['icon'] = $globals->icons->get_action_icon('add'); + list($op_file, $myarr['dir'], $myarr['file'], $myarr['link']) = $this->makeFileLoc($op_file, $caller); + $myarr['link_admin'] = "pages?dir={$myarr['dir']}"; + $myarr['flags'] |= EVENT_FLAG_PUBLIC; + break; + + case "page_delete": + $myarr['title'] = __("page removed"); + $myarr['icon'] = $globals->icons->get_action_icon('remove'); + break; + + case "page_props": + $myarr['title'] = __("page properties"); + $myarr['icon'] = $globals->icons->get_action_icon('properties'); + list($op_file, $myarr['dir'], $myarr['file']) = $this->makeFileLoc($op_file, $caller); + $myarr['link_admin'] = "pages?dir={$myarr['dir']}"; + break; + + case "page_plugins": + $myarr['title'] = __("page plugins"); + $myarr['icon'] = $globals->icons->get_action_icon('plugins'); + list($op_file, $myarr['dir'], $myarr['file']) = $this->makeFileLoc($op_file, $caller); + $myarr['link_admin'] = "plugins?plug_page={$myarr['dir']}"; + break; + + case "rcs_commit": + $myarr['title'] = __("file updated"); + $myarr['icon'] = $globals->icons->get_action_icon('update'); + list($op_file, $myarr['dir'], $myarr['file'], $myarr['link']) = $this->makeFileLoc($op_file, $caller); + $myarr['link_admin'] = "files?action=revs&dir={$myarr['dir']}&target={$myarr['file']}"; + $myarr['flags'] |= EVENT_FLAG_PUBLIC; + + break; + + case "rcs_delete": + $myarr['title'] = __("file deleted"); + $myarr['icon'] = $globals->icons->get_action_icon('delete'); + list($op_file, $myarr['dir'], $myarr['file']) = $this->makeFileLoc($op_file, $caller); + break; + } + $myarr['opfile'] = $op_file; + + if (isset($myarr['title'])) + array_push($events, $myarr); + } + mysql_free_result($res); + return $events; + } +} + +?> diff --git a/include/Barrel/Menu.php b/include/Barrel/Menu.php new file mode 100644 index 0000000..e5279c9 --- /dev/null +++ b/include/Barrel/Menu.php @@ -0,0 +1,255 @@ +dbh =& $dbh; + $this->table_menu = $table_menu; + } + + /** Delete the specified entry. + * + * @param $MID + * @param $parent + * @param $caller + */ + function deleteEntry($MID, $parent, &$caller) + { + if (mysql_num_rows($this->dbh->query("SELECT MID FROM {$this->table_menu} WHERE MIDpere=$MID")) > 0) { + $caller->info(__("The selected menu has child items, please remove them first.")); + return; + } + + /* erase the current entry */ + $this->dbh->query("DELETE FROM {$this->table_menu} WHERE MID=$MID"); + + /* renumber the other menu entries so that they are between 1 and the number of entries */ + $res = $this->dbh->query("SELECT MID FROM {$this->table_menu} WHERE MIDpere=$parent ORDER BY ordre"); + $i = 0; + while (list($MIDtoorder) = mysql_fetch_array($res)) { + $i++; + $this->dbh->query("UPDATE {$this->table_menu} SET ordre=$i WHERE MID=$MIDtoorder"); + } + mysql_free_result($res); + } + + + /** Build the user-defined part of the menu. + * + * @param $PID + * @param $pid_to_url + */ + function makeMenu($PID, $min_level, $pid_to_url) + { + // all menu entries from database + $mcache = $this->menuRead(); + + // try to figure out the current MID from the current PID + // and build filiation + $filiation = array(); + foreach ($mcache as $mid => $mentry) + { + if ($mentry['pid'] == $PID) + $filiation = $this->menuToRoot($mcache, $mid, $filiation); + } + + $menu = $this->menuRecurse($mcache, 0, $filiation, 0, $min_level, $pid_to_url); + + return $menu; + } + + + /** Return the maximum index for children of a given entry. + * + * @param $parent + */ + function maxChildIndex($parent) + { + $res=$this->dbh->query("SELECT MAX(ordre) from {$this->table_menu} where MIDpere=$parent"); + list($maxOrdre)=mysql_fetch_row($res); + mysql_free_result($res); + return $maxOrdre; + } + + + /** Return the filiation to get to the root element. + * + * @param mcache + * @param MID + * @param path + */ + function menuToRoot($mcache, $MID, $path) { + /* add ourself to the path */ + array_push($path,$MID); + + if ($MID) { + /* recursion */ + return $this->menuToRoot($mcache, $mcache[$MID]['parent'], $path); + } else { + /* termination */ + return $path; + } + } + + + /** Recursively add menu entries + * + * @param mcache + * @param MIDpere + * @param filiation + * @param level + * @param min_level + * @param pid_to_url + */ + function menuRecurse($mcache, $MIDpere, $filiation, $level, $min_level, $pid_to_url) { + // the produced output + $out = array(); + + foreach ($mcache[$MIDpere]['children'] as $mid) + { + $mentry = $mcache[$mid]; +// echo "pid : $pid, location : $location
"; + $entry = htmlentities(stripslashes($mentry['title']), ENT_QUOTES); + if ($mentry['pid']) + { + $link = call_user_func($pid_to_url, $mentry['pid']); + } else { + $link = $mentry['link']; + } + // decide whether this menu should be expanded + $expanded = ($min_level == 0) || + ($level+1 < $min_level) || + in_array($mid, $filiation); + array_push($out, array($level, $entry, $link, $expanded)); + $out = array_merge($out, $this->menuRecurse($mcache, $mid, $filiation, $level+1, $min_level, $pid_to_url)); + } + + return $out; + } + + + /** Read this barrel's menu entries from database. + */ + function menuRead() + { + $menu = array(); + $menu[0]['children'] = array(); + $res = $this->dbh->query("select MID,MIDpere,title,link,PID,ordre from {$this->table_menu} order by ordre"); + while (list($mid, $parent, $title, $link, $pid, $ordre) = mysql_fetch_row($res)) + { + $menu[$mid]['parent'] = $parent; + $menu[$mid]['title'] = $title; + $menu[$mid]['link'] = $link; + $menu[$mid]['title'] = $title; + $menu[$mid]['pid'] = $pid; + $menu[$mid]['ordre'] = $ordre; + if (!is_array($menu[$mid]['children'])) + $menu[$mid]['children'] = array(); + + // register this entry with its parent + if (!is_array($menu[$parent]['children'])) + $menu[$parent]['children'] = array(); + array_push($menu[$parent]['children'], $mid); + } + mysql_free_result($res); + return $menu; + } + + + /** + * Swap entries $a and $b within $parent. + * + * @param $parent + * @param $a + * @param $b + */ + function swapEntries($parent, $a, $b) + { + $res = $this->dbh->query("SELECT MID from {$this->table_menu} where MIDpere=$parent and (ordre=$a or ordre=$b) ORDER BY ordre"); + /* make sure that $a <= $b */ + if ($a > $b) + { + $c = $a; + $a = $b; + $b = $c; + } + /* perform swap */ + list($MIDa) = mysql_fetch_row($res); + list($MIDb) = mysql_fetch_row($res); + mysql_free_result($res); + + $this->dbh->query("UPDATE {$this->table_menu} SET ordre=$b WHERE MID=$MIDa"); + $this->dbh->query("UPDATE {$this->table_menu} SET ordre=$a WHERE MID=$MIDb"); + } + + + /** + * Write an entry to database. If $mid is 0, a new entry is created. + * + * @param $mid + * @param $props + */ + function writeEntry($mid, $props) + { + if ($mid == 0) { + $props['ordre'] = $this->maxChildIndex($props['parent']) + 1; + } + + // build SQL string + $nprops = array('parent' => 'MIDpere', 'ordre' => 'ordre', 'title' => 'title', 'link' => 'link', 'pid' => 'pid'); + $sprops = ""; + foreach($nprops as $prop => $dbkey) + { + if (isset($props[$prop])) + { + $val = $props[$prop]; + $sprops .= "$dbkey='$val', "; + } + } + if (!$sprops) + return; + $sprops = substr($sprops, 0, -2); + if ($mid == 0) { + $this->dbh->query("INSERT INTO {$this->table_menu} SET $sprops"); + $mid = mysql_insert_id(); + } else { + $this->dbh->query("UPDATE {$this->table_menu} SET $sprops WHERE MID=$mid"); + } + return $mid; + } + +} + +?> diff --git a/include/admin/index.php b/include/admin/index.php index 4604049..64b5df2 100644 --- a/include/admin/index.php +++ b/include/admin/index.php @@ -2,104 +2,15 @@ require_once 'diogenes.common.inc.php'; require_once 'diogenes.admin.inc.php'; require_once 'diogenes.icons.inc.php'; +require_once 'Barrel/Events.php'; $page = new DiogenesAdmin; $bbarrel =& $page->barrel; -$homepage = $bbarrel->getPID(''); - -// filename transformations -function makeFileLoc($log_file) { - global $homepage, $bbarrel; - - if (stristr($log_file, '/') == FALSE ) { - // this is a directory - $mydir = $log_file; - $myfile = ''; - } else { - $myfile = basename($log_file); - $mydir = dirname($log_file); - } - - $myloc = $bbarrel->getLocation($mydir); - if ($myloc or ($mydir == $homepage)) - { - $log_file = $myloc ? "$myloc/$myfile" : $myfile; - } - - return array($log_file, $mydir, $myfile); -} - +$events = new Diogenes_Barrel_Events($bbarrel); // retrieve recent events -$res = $globals->db->query("select e.action,e.stamp,e.data,a.text,s.auth,s.uid " - ."from {$globals->table_log_events} as e " - ."left join {$globals->table_log_actions} as a on e.action=a.id " - ."left join {$globals->table_log_sessions} as s on e.session=s.id " - ."where e.data like '{$bbarrel->alias}:%' " - ."order by stamp desc limit 0,10"); -while ($myarr = mysql_fetch_array($res)) { - $myarr['username'] = call_user_func(array($globals->session,'getUsername'),$myarr['auth'],$myarr['uid']); - list($op_alias, $op_file) = split(":",$myarr['data']); - - switch($myarr['text']) { - case "barrel_create": - $myarr['icon'] = $globals->icons->get_action_icon('add'); - $myarr['desc'] = __("site created"); - break; - - case "barrel_options": - $myarr['icon'] = $globals->icons->get_action_icon('properties'); - $myarr['desc'] = array(__("barrel options"), "options"); - break; - - case "barrel_plugins": - $myarr['icon'] = $globals->icons->get_action_icon('plugins'); - $myarr['desc'] = array(__("barrel plugins"), "plugins"); - break; - - case "page_create": - $myarr['icon'] = $globals->icons->get_action_icon('add'); - list($op_file, $mydir, $myfile) = makeFileLoc($op_file); - $myarr['desc'] = array(__("page created"), "pages?dir=$mydir"); - break; - - case "page_delete": - $myarr['icon'] = $globals->icons->get_action_icon('remove'); - $myarr['desc'] = __("page removed"); - break; - - case "page_props": - $myarr['icon'] = $globals->icons->get_action_icon('properties'); - list($op_file, $mydir, $myfile) = makeFileLoc($op_file); - $myarr['desc'] = array(__("page properties"), "pages?dir=$mydir"); - break; - - case "page_plugins": - $myarr['icon'] = $globals->icons->get_action_icon('plugins'); - list($op_file, $mydir, $myfile) = makeFileLoc($op_file); - $myarr['desc'] = array(__("page plugins"), "plugins?plug_page=$mydir"); - break; - - case "rcs_commit": - $myarr['icon'] = $globals->icons->get_action_icon('update'); - list($op_file, $mydir, $myfile) = makeFileLoc($op_file); - $myarr['desc'] = array(__("file updated"), "files?action=revs&dir=$mydir&target=$myfile"); - break; - - case "rcs_delete": - $myarr['icon'] = $globals->icons->get_action_icon('delete'); - list($op_file, $mydir, $myfile) = makeFileLoc($op_file); - $myarr['desc'] = __("file deleted"); - break; - - } - - $myarr['file'] = $op_file; - - if (isset($myarr['desc'])) - $page->append('events',$myarr); -} -mysql_free_result($res); +$event_arr = $events->getEvents($page); +$page->assign('events', $event_arr); // do display $page->assign('greeting',__("Welcome to the Diogenes backoffice")); diff --git a/include/admin/menus.php b/include/admin/menus.php index 269c4c7..1fbb24f 100644 --- a/include/admin/menus.php +++ b/include/admin/menus.php @@ -1,37 +1,16 @@ barrel; +$bmenu = new Diogenes_Barrel_Menu($globals->db, $bbarrel->table_menu); // the id of the parent menu $MIDpere = isset($_REQUEST['MIDpere']) ? $_REQUEST['MIDpere'] : 0; -/** - * This function swaps entries $a and $b within $parent. - */ -function swapentries($parent,$a,$b,$table_menu) -{ - global $globals; - $res = $globals->db->query("SELECT MID from $table_menu where MIDpere=$parent and (ordre=$a or ordre=$b) ORDER BY ordre"); - /* make sure that $a <= $b */ - if ($a > $b) - { - $c = $a; - $a = $b; - $b = $c; - } - /* perform swap */ - list($MIDa) = mysql_fetch_row($res); - list($MIDb) = mysql_fetch_row($res); - mysql_free_result($res); - - $globals->db->query("UPDATE $table_menu SET ordre=$b WHERE MID=$MIDa"); - $globals->db->query("UPDATE $table_menu SET ordre=$a WHERE MID=$MIDb"); -} - - //// start constructing the page $page->assign('greeting',__("The site's menus")); @@ -41,64 +20,39 @@ switch ($action) { /* we want to erase the current entry */ case "supprimer": $MID = $_REQUEST['MID']; - if (mysql_num_rows($globals->db->query("SELECT MID FROM {$bbarrel->table_menu} WHERE MIDpere=$MID")) > 0) { - $page->info(__("The selected menu has child items, please remove them first.")); - break; - } - - /* erase the current entry */ - $globals->db->query("DELETE FROM {$bbarrel->table_menu} WHERE MID=$MID"); - - /* renumber the other menu entries so that they are between 1 and the number of entries */ - $res = $globals->db->query("SELECT MID FROM {$bbarrel->table_menu} WHERE MIDpere=$MIDpere ORDER BY ordre"); - $i = 0; - while (list($MIDtoorder) = mysql_fetch_array($res)) { - $i++; - $globals->db->query("UPDATE {$bbarrel->table_menu} SET ordre=$i WHERE MID=$MIDtoorder"); - } - mysql_free_result($res); + $bmenu->deleteEntry($MID, $MIDpere, $page); break; /* bring an entry up in the menu */ case "remonter": $ordre = $_REQUEST['ordre']; - swapentries($MIDpere,$ordre-1,$ordre,$bbarrel->table_menu); + $bmenu->swapEntries($MIDpere, $ordre-1, $ordre); break; /* push an entry down in the menu */ case "descendre": $ordre = $_REQUEST['ordre']; - swapentries($MIDpere,$ordre,$ordre+1,$bbarrel->table_menu); + $bmenu->swapEntries($MIDpere, $ordre, $ordre+1); break; /* create or update a menu entry */ case "modifier": $typelink = $_REQUEST['typelink']; + $props = array( + 'parent' => $MIDpere, + 'pid' => 0, + 'link' => '', + 'title' => $_REQUEST['title'], + ); switch ($typelink) { case "boutonPI" : - $pid = isset($_REQUEST['PIvaleur']) ? $_REQUEST['PIvaleur'] : 0; - $link = ""; + $props['pid'] = isset($_REQUEST['PIvaleur']) ? $_REQUEST['PIvaleur'] : 0; break; case "boutonSE" : - $pid = 0; - $link = $_REQUEST['SEvaleur']; + $props['link'] = $_REQUEST['SEvaleur']; break; - default: - $pid = 0; - $link = ""; - } - $MID = $_REQUEST['MID']; - $title = $_REQUEST['title']; - if ($MID == 0) { - $res=$globals->db->query("SELECT MAX(ordre) from {$bbarrel->table_menu} where MIDpere=$MIDpere"); - list($ordre) = mysql_fetch_row($res); - $ordre++; - $globals->db->query("INSERT INTO {$bbarrel->table_menu} SET MIDpere='$MIDpere',ordre='$ordre',title='$title',link='$link',pid='$pid'"); - $MID = mysql_insert_id(); - } else { - $globals->db->query("UPDATE {$bbarrel->table_menu} SET title='$title',link='$link',pid='$pid' WHERE MID=$MID"); } - + $MID = $bmenu->writeEntry($_REQUEST['MID'], $props); break; /* display the form to edit an entry */ @@ -111,9 +65,10 @@ case "editer": // if this is an existing entry, retrieve data if ($MID) { - $res = $globals->db->query("SELECT link,title,pid FROM {$bbarrel->table_menu} WHERE MID=$MID"); - list($link, $title, $pid) = mysql_fetch_row($res); - mysql_free_result($res); + $mcache = $bmenu->menuRead(); + $link = $mcache[$MID]['link']; + $title = $mcache[$MID]['title']; + $pid = $mcache[$MID]['pid']; } // fill out form data @@ -168,16 +123,17 @@ case "editer": } // get the maximum order -$res=$globals->db->query("SELECT MAX(ordre) from {$bbarrel->table_menu} where MIDpere=$MIDpere"); -list($maxOrdre)=mysql_fetch_row($res); -mysql_free_result($res); - -// retrieve the entries -$res = $globals->db->query("SELECT m.MID,m.ordre,m.title,m.link,m.PID,p.title ". - "from {$bbarrel->table_menu} as m ". - "left join {$bbarrel->table_page} as p on m.PID=p.PID ". - "where MIDpere=$MIDpere order by ordre"); -while (list($MID,$ordre,$title,$link,$PID,$ptitle) = mysql_fetch_row($res)) { +$maxOrdre = $bmenu->maxChildIndex($MIDpere); + +// all menu entries from database +$mcache = $bmenu->menuRead(); + +foreach($mcache[$MIDpere]['children'] as $MID) +{ + $ordre = $mcache[$MID]['ordre']; + $title = $mcache[$MID]['title']; + $link = $mcache[$MID]['link']; + $PID = $mcache[$MID]['pid']; $clickup="?action=remonter&MIDpere=$MIDpere&ordre=$ordre"; $clickdown="?action=descendre&MIDpere=$MIDpere&ordre=$ordre"; @@ -192,7 +148,8 @@ while (list($MID,$ordre,$title,$link,$PID,$ptitle) = mysql_fetch_row($res)) { // describe the current link if ($PID) { - $descr = "$ptitle"; + $tpage = Diogenes_Barrel_Page::fromDb($bbarrel, $PID); + $descr = "".$tpage->props['title'].""; } elseif ($link) { $descr = "[ext] $link"; } else { @@ -205,20 +162,15 @@ while (list($MID,$ordre,$title,$link,$PID,$ptitle) = mysql_fetch_row($res)) { stripslashes($descr), $edit,$del,$up,$down)); } -mysql_free_result($res); // all menu entries from database -$mcache = $page->menuRead(); -$filiation = $page->menuToRoot($mcache,$MIDpere,array()); +$filiation = $bmenu->menuToRoot($mcache,$MIDpere,array()); $menubar = array(); foreach($filiation as $mykey=>$myval) { if ($myval == 0) { $blab = "home"; } else { - $res = $globals->db->query("SELECT title FROM {$bbarrel->table_menu} WHERE MID='$myval'"); - list($blab) = mysql_fetch_row($res); - $blab = stripslashes($blab); - mysql_free_result($res); + $blab = stripslashes($mcache[$myval]['title']); } array_unshift($menubar,$mykey ? array($blab,"?MIDpere=$myval") : array($blab)); } diff --git a/include/admin/rss.php b/include/admin/rss.php new file mode 100644 index 0000000..9a9187a --- /dev/null +++ b/include/admin/rss.php @@ -0,0 +1,28 @@ +barrel; +$events = new Diogenes_Barrel_Events($page->barrel); + +// assignments +$page->assign('version', $globals->version); +$page->assign('site_title', stripslashes($page->barrel->options->title)); +$page->assign('site_link', $page->urlBarrel($page->barrel->alias, $page->barrel->vhost, '')); + +// retrieve recent events +$event_arr = $events->getEvents($page); +foreach($event_arr as $event) +{ + //$page->assign('events', $event_arr); + if ($event['flags'] & EVENT_FLAG_PUBLIC) + { + $item = $event; + $item['date'] = gmstrftime("%a, %d %b %Y %T %Z", strtotime($event['stamp'])); + $item['title'] .= " : ". $item['opfile']; + $page->append('items', $item); + } +} +header("Content-Type: application/rss+xml"); +$page->display('', 'admin-rss.tpl'); +?> diff --git a/include/diogenes.barrel.inc.php b/include/diogenes.barrel.inc.php index 3893284..65ad7ff 100644 --- a/include/diogenes.barrel.inc.php +++ b/include/diogenes.barrel.inc.php @@ -21,6 +21,7 @@ require_once 'diogenes.page.inc.php'; require_once 'Barrel.php'; +require_once 'Barrel/Menu.php'; /** This class is used to display a page of a Diogenes barrel, * that is an RCS-managed website with a virtual directory @@ -312,6 +313,9 @@ class DiogenesBarrel extends DiogenesPage // favicon if ($bbarrel->options->favicon) array_push($this->head, 'options->favicon).'" type="image/png" />'); + + // RSS feed + array_push($this->head, ''); } @@ -352,74 +356,9 @@ class DiogenesBarrel extends DiogenesPage if (!isset($this->table_menu)) return; - // all menu entries from database - $mcache = $this->menuRead(); - - // try to figure out the current MID from the current PID - // and build filiation - $filiation = array(); - foreach ($mcache as $mid => $mentry) - { - if ($mentry['pid'] == $PID) - $filiation = $this->menuToRoot($mcache, $mid, $filiation); - } - // add the user-defined part of the menu - $this->menu = array_merge($this->menu,$this->menuRecurse($mcache,0,$filiation,0)); - } - - - /** Return the filiation to get to the root element. - * - * @param mcache - * @param MID - * @param path - */ - function menuToRoot($mcache, $MID, $path) { - /* add ourself to the path */ - array_push($path,$MID); - - if ($MID) { - /* recursion */ - return $this->menuToRoot($mcache, $mcache[$MID]['parent'], $path); - } else { - /* termination */ - return $path; - } - } - - - /** Recursively add menu entries - * - * @param mcache - * @param MIDpere - * @param filiation - * @param level - */ - function menuRecurse($mcache, $MIDpere, $filiation, $level) { - // the produced output - $out = array(); - - foreach ($mcache[$MIDpere]['children'] as $mid) - { - $mentry = $mcache[$mid]; -// echo "pid : $pid, location : $location
"; - $entry = htmlentities(stripslashes($mentry['title']), ENT_QUOTES); - if ($mentry['pid']) - { - $link = $this->urlSite($this->barrel->getLocation($mentry['pid'])); - } else { - $link = $mentry['link']; - } - // decide whether this menu should be expanded - $expanded = ($this->barrel->options->menu_min_level == 0) || - ($level+1 < $this->barrel->options->menu_min_level) || - in_array($mid, $filiation); - array_push($out, array($level, $entry, $link, $expanded)); - $out = array_merge($out, $this->menuRecurse($mcache, $mid, $filiation, $level+1)); - } - - return $out; + $bmenu = new Diogenes_Barrel_Menu($this->dbh, $this->table_menu); + $this->menu = array_merge($this->menu, $bmenu->makeMenu($PID, $this->barrel->options->menu_min_level, array($this, 'urlSiteByPid'))); } @@ -496,7 +435,7 @@ class DiogenesBarrel extends DiogenesPage } return $path; } - + /** Returns the URL to one of the barrel's pages relative to * the current location. @@ -511,6 +450,18 @@ class DiogenesBarrel extends DiogenesPage return strlen($url) ? $url : "./"; } + + /** Returns the URL to one of the barrel's pages relative to + * the current location. + * + * @param dir + * @param file + */ + function urlSiteByPid($PID, $file = '') + { + return $this->urlSite($this->barrel->getLocation($PID), $file); + } + } ?> diff --git a/templates/admin-index.tpl b/templates/admin-index.tpl index bac68e0..1529cd8 100644 --- a/templates/admin-index.tpl +++ b/templates/admin-index.tpl @@ -9,9 +9,9 @@ {if $myevent.icon}{else} {/if} {$myevent.stamp|date_format:"%Y-%m-%d %H:%M:%S"} - {$myevent.username} - {a lnk=$myevent.desc} - {$myevent.file} + {$myevent.author} + {$myevent.title} + {$myevent.opfile} {/foreach} diff --git a/templates/admin-rss.tpl b/templates/admin-rss.tpl new file mode 100644 index 0000000..aea0e1e --- /dev/null +++ b/templates/admin-rss.tpl @@ -0,0 +1,20 @@ + + + +Diogenes +Diogenes RSS feed - {$site_title} + +{$site_link} + +Diogenes {$version} +{foreach item=item from=$items} + + {$item.title} + {if $item.link}{$item.link}{/if} + {if $item.description}{$item.description}{/if} + {if $item.author}{$item.author}{/if} + {if $item.data}{$item.date}{/if} + +{/foreach} + +