<?php
// File: $Id: menu.php,v 1.24 2001/12/09 20:58:46 gregorrothfuss Exp $
// ----------------------------------------------------------------------
// POST-NUKE Content Management System
// Copyright (C) 2001 by the Post-Nuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// Based on:
// PHP-NUKE Web Portal System - http://phpnuke.org/
// Thatware - http://thatware.org/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file: Jim McDonald
// Purpose of file: Display menu, with lots of options
// ----------------------------------------------------------------------
// 11-08-01 eugenioBaldi possibility to change/translate the modulename in MainMenu
// Create a file in modules/<module>/modname.php where _REVIEWS is the name of the module
// <?php
// $modname = ""._REVIEWS."";
$blocks_modules['menu'] = array(
'func_display' => 'blocks_menu_block',
'func_edit' => 'blocks_menu_select',
'func_update' => 'blocks_menu_update',
'text_type' => 'Menu',
'text_type_long' => 'Generic menu',
'allow_multiple' => true,
'form_content' => false,
'form_refresh' => false,
'show_preview' => true
);
addinstanceschemainfo('Menublock::', 'Block name:Link name:');
function blocks_menu_block($row)
{
global $blocks_modules, $pntable, $dbconn, $admin;
// Break out options from our content field
$vars = getMenuVarsFromContent($row);
// Display style
// style = 1 - simple list
// style = 2 - drop-down list
// Title
$block['title'] = $row['title'];
//FTO add Position
$block['position'] = $row['position'];
//FTO add id
$block['bid'] = $row['bid'];
// Styling
$block['content'] = startMenuStyle($vars['style']);
$content = 0;
// nkame: must start with some blank line, otherwise we're not able to
// chose the first option in case of a drop-down menu.
// a better solution would be to detect where we are, and adjust the selected
// option in the list, and only add a blank line in case of no recognition.
if($vars['style'] == 2)
$block['content'] .= addMenuStyledUrl($vars['style'], "", "", "");
// Content
if (!empty($vars['content'])) {
$contentlines = explode("LINESPLIT", $vars['content']);
foreach ($contentlines as $contentline) {
list($url, $title, $comment) = explode('|', $contentline);
if (authorised(0, "Menublock::", "$row[title]:$title:", ACCESS_READ)) {
$block['content'] .= addMenuStyledUrl($vars['style'], $title, $url, $comment);
$content = 1;
}
}
}
// Modules
if ($vars['displaymodules']) {
$handle=opendir('modules');
while ($f = readdir($handle)) {
if (!ereg('[.]',$f) && !ereg('^NS-.*',$f) && !ereg('^CVS',$f)) {
$moduleslist[] = $f;
}
}
closedir($handle);
usort($moduleslist,"strnatcasecmp");
// Separate from current content, if any
if ($content == 1) {
$block['content'] .= addMenuStyledUrl($vars['style'], "", "", "");
}
foreach ($moduleslist as $v) {
if (file_exists("modules/$v/modname.php")) {
include "modules/$v/modname.php";
}
$xname = str_replace('_', ' ', $v);
if (empty($modname)) {
$modname = $xname;
}
if (authorised(0, "$xname::", "::", ACCESS_OVERVIEW)) {
$block['content'] .= addMenuStyledUrl($vars['style'], $modname, "modules.php?op=modload&name=$v&file=index", "");
$content = 1;
}
$modname = '';
}
}
// Waiting content
if ($vars['displaywaiting']) {
// Separate from current content, if any
if ($content == 1) {
$block['content'] .= addMenuStyledUrl($vars['style'], "", "", "");
}
$header = 0;
if (authorised(0, "Stories::", "::", ACCESS_ADD)) {
//FTO Select count optimized by using primary key (index)
$result = $dbconn->Execute("SELECT count({$pntable['queue_column']['qid']}) FROM $pntable[queue]
WHERE {$pntable['queue_column']['arcd']}=0");
list($qnum) = $result->fields;
$result->Close();
if ($header == 0) {
$block['content'] .= addMenuStyledUrl($vars['style'], "<strong>" . _WAITINGCONT. "</strong>", "", "");
$header = 1;
}
$block['content'] .= addMenuStyledUrl($vars['style'], _SUBMISSIONS.": $qnum", "admin.php?op=submissions", "");
}
if (authorised(0, "Reviews::", "::", ACCESS_ADD)) {
//FTO Select count optimized by using primary key (index)
$result = $dbconn->Execute("SELECT count( {$pntable['reviews_add_column']['id']} ) FROM $pntable[reviews_add]");
list($rnum) = $result->fields;
$result->Close();
if ($header == 0) {
$block['content'] .= addMenuStyledUrl($vars['style'], "<strong>" . _WAITINGCONT. "</strong>", "", "");
$header = 1;
}
$block['content'] .= addMenuStyledUrl($vars['style'], _WREVIEWS.": $rnum", "admin.php?op=reviews", "");
}
if (authorised(0, "Web links::", "::", ACCESS_ADD)) {
//FTO Select count optimized by using primary key (index)
$result = $dbconn->Execute("SELECT count({$pntable['links_newlink_column']['lid']}) FROM $pntable[links_newlink]");
list($lnum) = $result->fields;
$result->Close();
if ($header == 0) {
$block['content'] .= addMenuStyledUrl($vars['style'], "<strong>" . _WAITINGCONT. "</strong>", "", "");
$header = 1;
}
$block['content'] .= addMenuStyledUrl($vars['style'], _WLINKS.": $lnum", "admin.php?module=Web_Links&op=main", "");
}
if (authorised(0, "Downloads::", "::", ACCESS_ADD)) {
//FTO Select count optimized by using primary key (index)
$result = $dbconn->Execute("SELECT count({$pntable['downloads_newdownload_column']['lid']}) FROM $pntable[downloads_newdownload]");
list($dnum) = $result->fields;
$result->Close();
if ($header == 0) {
$block['content'] .= addMenuStyledUrl($vars['style'], "<strong>" . _WAITINGCONT. "</strong>", "", "");
$header = 1;
}
$block['content'] .= addMenuStyledUrl($vars['style'], _WDOWNLOADS.": $dnum", "admin.php?module=Downloads&op=main", "");
}
if (authorised(0, "FAQ::", "::", ACCESS_ADD)) {
//FTO . Add IS NULL clause for Oracle
// ORACLEDONE
//FTO Select count optimized by using primary key (index)
$result = $dbconn->Execute("SELECT count({$pntable['faqanswer_column']['id']}) FROM $pntable[faqanswer] WHERE answer='' OR answer IS NULL");
list($fnum) = $result->fields;
$result->Close();
if ($header == 0) {
$block['content'] .= addMenuStyledUrl($vars['style'], "<strong>" . _WAITINGCONT. "</strong>", "", "");
$header = 1;
}
$block['content'] .= addMenuStyledUrl($vars['style'], _FQUESTIONS.": $fnum", "admin.php?op=FaqCatUnanswered", "");
}
}
// Styling
$block['content'] .= endMenuStyle($vars['style']);
// Waiting content
if (!empty($block['content'])) {
themesideblock($block);
}
}
function blocks_menu_select($row)
{
global $pntable, $dbconn;
//FTO : remove warning
global $pntheme;
// Break out options from our content field
$vars = getMenuVarsFromContent($row);
$row['content'] = "";
// What style of menu
$output = "<tr><td class=\"pn-title\">"._MENU_FORMAT."</td><td></td></tr>";
$output .= "<tr><td class=\"pn-normal\">"._MENU_AS_LIST.":</td><td><input type=\"radio\" name=\"style\" value=\"1\"";
if ($vars['style'] == 1) {
$output .= " checked";
}
$output .= "></td></tr><tr><td class=\"pn-normal\">"._MENU_AS_DROPDOWN.":</td><td><input type=\"radio\" name=\"style\" value=\"2\"";
if ($vars['style'] == 2) {
$output .= " checked";
}
$output .= "></td></tr>";
// What to display
$output .= "<tr><td class=\"pn-title\">"._DISPLAY."</td><td></td></tr>";
$output .= "<tr><td class=\"pn-normal\">"._MODULES.":</td><td><input type=\"checkbox\" value=\"1\" name=\"displaymodules\"";
if ($vars['displaymodules'] == 1) {
$output .= " checked";
}
$output .= "></td></tr><tr><td class=\"pn-normal\">"._WAITINGCONT.":</td><td><input type=\"checkbox\" value=\"1\" name=\"displaywaiting\"";
if ($vars['displaywaiting'] == 1) {
$output .= " checked";
}
$output .= "></td></tr>";
// Content
$c=1;
$output .= "</table><table>";
$output .= "<tr><td valign=\"top\" class=\"pn-title\">"._CONTENT.":</td><td><table border=\"1\"><tr><td align=\"center\" class=\"pn-normal\" style=\"color:$pntheme[table_header_text]; background-color:$pntheme[table_header]; text-align:center\"><b>"._TITLE."</b></td><td align=\"center\" class=\"pn-normal\" style=\"color:$pntheme[table_header_text]; background-color:$pntheme[table_header]; text-align:center\"><b>"._URL."</b></td><td align=\"center\" class=\"pn-normal\" style=\"color:$pntheme[table_header_text]; background-color:$pntheme[table_header]; text-align:center\"><b>"._DESCRIPTION." </b><span class=\"pn-sub\"><b>("._OPTIONAL.")</b></span></td><td align=\"center\" class=\"pn-normal\" style=\"color:$pntheme[table_header_text]; background-color:$pntheme[table_header]; text-align:center\"><b>"._DELETE."</b></td><td align=\"center\" class=\"pn-normal\" style=\"color:$pntheme[table_header_text]; background-color:$pntheme[table_header]; text-align:center\"><b>"._INSERT_BLANK_AFTER."</b></td></tr>";
if (!empty($vars['content'])) {
$contentlines = explode("LINESPLIT", $vars['content']);
foreach ($contentlines as $contentline) {
$link = explode('|', $contentline);
$output .= "<tr><td valign=\"top\"><input type=\"text\" name=\"linkname[$c]\" size=\"30\" maxlength=\"255\" value=\"$link[1]\" class=\"pn-normal\"></td><td valign=\"top\"><input type=\"text\" name=\"linkurl[$c]\" size=\"30\" maxlength=\"255\" value=\"$link[0]\" class=\"pn-normal\"></td><td valign=\"top\"><input type=\"text\" name=\"linkdesc[$c]\" size=\"30\" maxlength=\"255\" value=\"$link[2]\" class=\"pn-normal\"></td><td valign=\"top\"><input type=\"checkbox\" name=\"linkdelete[$c]\" value=\"1\" class=\"pn-normal\"></td><td valign=\"top\"><input type=\"checkbox\" name=\"linkinsert[$c]\" value=\"1\" class=\"pn-normal\"></td></tr>\n";
$c++;
}
}
$output .= "<tr><td><input type=\"text\" name=\"new_linkname\" size=\"30\" maxlength=\"255\" class=\"pn-normal\"></td><td><input type=\"text\" name=\"new_linkurl\" size=\"30\" maxlength=\"255\" class=\"pn-normal\"></td><td class=\"pn-normal\"><input type=\"text\" name=\"new_linkdesc\" size=\"30\" maxlength=\"255\" class=\"pn-normal\"></td><td class=\"pn-normal\">"._NEWONE."</td><td class=\"pn-normal\"><input type=\"checkbox\" name=\"new_linkinsert\" value=\"1\" class=\"pn-normal\"></td></tr>\n";
$output .= '</table></td></tr>';
return $output;
}
function blocks_menu_update($row)
{
global $HTTP_POST_VARS;
if (empty($HTTP_POST_VARS[displaymodules])) {
$HTTP_POST_VARS[displaymodules] = 0;
}
if (empty($HTTP_POST_VARS[displaywaiting])) {
$HTTP_POST_VARS[displaywaiting] = 0;
}
// User links
$content = array();
$c = 1;
if (count($row[linkname])) {
foreach ($row[linkname] as $v) {
$delete = $row[linkdelete];
if (!$delete[$c]) {
$content[] = $row[linkurl][$c].'|'.$row[linkname][$c].'|'.$row[linkdesc][$c];
}
if ($row[linkinsert][$c]) {
$content[] = "||";
}
$c++;
}
}
if ($row[new_linkname]) {
$content[] = "$row[new_linkurl]|$row[new_linkname]|$row[new_linkdesc]";
}
$content = implode("LINESPLIT", $content);
$row['content']="style:=$HTTP_POST_VARS[style]
displaymodules:=$HTTP_POST_VARS[displaymodules]
displaywaiting:=$HTTP_POST_VARS[displaywaiting]
content:=$content";
return($row);
}
// Get variables from content
// Format of variables:
// name=val
// name=val
function getMenuVarsFromContent($row)
{
//FTO : MySQL parse \n as \r\n in the content
// but not Oracle. Good Idea to parse with other cars.
// Why not XML syntax ?
//kill every \r (true or false) and use <:> separator
$row['content'] = str_replace("\\r","",$row['content']);
$row['content'] = str_replace("\\n","<:>",$row['content']);
$row['content'] = str_replace("\r","",$row['content']);
$row['content'] = str_replace("\n","<:>",$row['content']);
$links = explode("<:>", $row['content']);
foreach ($links as $link) {
$link = trim($link);
if ($link) {
$var = explode(":=", $link);
$vars[$var[0]] = $var[1];
}
}
// Defaults
if (empty($vars['style'])) {
$vars['style'] = 1;
}
if ($vars['displaymodules'] == "") {
$vars['displaymodules'] = 1;
}
if ($vars['displaywaiting'] == "") {
$vars['displaywaiting'] = 0;
}
return($vars);
}
function startMenuStyle($style)
{
// Nothing to do for style == 1 (bullet list)
$content = "";
if ($style == 2) {
$content = "<br><center><form method=\"post\" action=\"index.php\"><select class=\"pn-text\" name=\"newlanguage\" onChange=\"top.location.href=this.options[this.selectedIndex].value\">";
}
return $content;
}
function endMenuStyle($style)
{
// Nothing to do for style == 1 (bullet list)
$content = "";
if ($style == 2) {
$content = "</select></form></center>";
}
return $content;
}
function addMenuStyledUrl($style, $name, $url, $comment)
{
if ($style == 1) {
// Bullet list
if (empty($url)) {
// Separator
if (empty($name)) {
$content = "<br>";
} else {
$content = "<br><b>$name</b><br>";
}
} else {
switch ($url[0]) // Used to allow support for linking to modules with the use of bracket
{
case '[': // module link
$url = explode('|', $url);
$url = preg_replace("/\[(.*?)\]/si", "modules.php?op=modload&name=\\1&file=index", $url[0]);
break;
} // End Bracket Linking
$content = "<strong><big>·</big></strong> <a class=\"pn-normal\" href=\"$url\" title=\"$comment\">$name</a><br>";
}
} else if ($style == 2) {
// Drop-down lilst
if (empty($url)) {
// Separator
$content = "<option>-----</option>";
if (!empty($name)) {
$content .= "<option>$name</option>";
$content .= "<option>-----</option>";
}
} else {
switch ($url[0]) // Used to allow support for linking to modules with the use of bracket
{
case '[': // module link
$url = explode('|', $url);
$url = preg_replace("/\[(.*?)\]/si", "modules.php?op=modload&name=\\1&file=index", $url[0]);
break;
} // End bracket linking.
$content = "<option value=\"$url\">$name</option>";
}
}
return $content;
}
?>