like php
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
namespace FusionChartTest
{
public partial class SiteMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
string current_file = Path.GetFileName(Request.Path);
System.Diagnostics.Debug.WriteLine("filename: " + current_file);
string[] lines = System.IO.File.ReadAllLines(Server.MapPath("~") + @"\sitemap.ini").Where(s => s.Trim() != string.Empty).ToArray();
int window_blank = 0;
string nav_subject ="";
string nav_link = "";
string submenu_link = "";
string show_nav_subject = "";
string menu_link = "";
string submenu = "";
string submenu2 = "";
string navi = "";
foreach (string linetext in lines)
{ //Kommentare und Leerzeilen auslassen
string line = linetext.Substring(0,-1);
if(line.Substring(0,1) != "#" && line.Length>2) {
//echo $line."
";
string line_cleaned = line.Replace("^-|^--|^---","");
//workaround for ereg_replace not replacing ^--- properly
//string line_cleaned = line_cleaned.Replace("^-|^--|^---","");
if (Regex.Match(line_cleaned, "^|popup$")) {
window_blank = 1;
line_cleaned = line_cleaned.Replace("|popup$","");
}
else window_blank = 0;
//Seitentitel
if (line.IndexOf('|') == 0)
nav_subject = line_cleaned.Substring(0, line_cleaned.IndexOf('|'));
else
nav_subject = line_cleaned;
//Link auslesen
if (line.IndexOf('|') == 0)
nav_link = line_cleaned.Replace('|',"",line_cleaned.Substring(line_cleaned.IndexOf('|')+1));
else
nav_link = "#";
//bei externen Links darf PrependPath nicht gesetzt werden
string link_extern=(Regex.Replace("^(http|https|ftp)://",nav_link))?1:0;
int active = (nav_link == current_file)?1:0;
//print_r($nav_link);
// edit by Markus
// sobald ein Parent Eintrag gefunden wurde, den eintrag aus dem filename_ini array entfernen
// so wird verhindert, dass eintrage mit gleichem name wie ein Parent Eintrag auch gehighlightet wird
if(is_array($filename_ini) && in_array(nav_link.Trim() ,$filename_ini))
{
$key = array_search(trim($nav_link),$filename_ini);
$active_parent = 1;
unset($filename_ini[$key]);
} else {
$active_parent = 0;
}
//Markus end
//if(is_array($filename_ini)) $active_parent = (in_array(trim($nav_link),$filename_ini))?1:0;
//else $active_parent = 0;
//Link für Submenü zusammenbauen
if (nav_link == "#")
submenu_link = "
if (nav_link == current_file) node_active2=true;
}
//3. Ebene
else if (line.Substring(0,3) != "---"){
node_active3 = false;
if (show_submenu3 && submenu3_dump) submenu3 = submenu3_dump;
show_submenu3 = false;
submenu3_dump = "";
submenu2 .= "
"+(active?"":"").(active_parent?"":"")."");using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
namespace FusionChartTest
{
public partial class SiteMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
string current_file = Path.GetFileName(Request.Path);
System.Diagnostics.Debug.WriteLine("filename: " + current_file);
string[] lines = System.IO.File.ReadAllLines(Server.MapPath("~") + @"\sitemap.ini").Where(s => s.Trim() != string.Empty).ToArray();
int window_blank = 0;
string nav_subject ="";
string nav_link = "";
string submenu_link = "";
string show_nav_subject = "";
string menu_link = "";
string submenu = "";
string submenu2 = "";
string navi = "";
foreach (string linetext in lines)
{ //Kommentare und Leerzeilen auslassen
string line = linetext.Substring(0,-1);
if(line.Substring(0,1) != "#" && line.Length>2) {
//echo $line."
";
string line_cleaned = line.Replace("^-|^--|^---","");
//workaround for ereg_replace not replacing ^--- properly
//string line_cleaned = line_cleaned.Replace("^-|^--|^---","");
if (Regex.Match(line_cleaned, "^|popup$")) {
window_blank = 1;
line_cleaned = line_cleaned.Replace("|popup$","");
}
else window_blank = 0;
//Seitentitel
if (line.IndexOf('|') == 0)
nav_subject = line_cleaned.Substring(0, line_cleaned.IndexOf('|'));
else
nav_subject = line_cleaned;
//Link auslesen
if (line.IndexOf('|') == 0)
nav_link = line_cleaned.Replace('|',"",line_cleaned.Substring(line_cleaned.IndexOf('|')+1));
else
nav_link = "#";
//bei externen Links darf PrependPath nicht gesetzt werden
string link_extern=(Regex.Replace("^(http|https|ftp)://",nav_link))?1:0;
int active = (nav_link == current_file)?1:0;
//print_r($nav_link);
// edit by Markus
// sobald ein Parent Eintrag gefunden wurde, den eintrag aus dem filename_ini array entfernen
// so wird verhindert, dass eintrage mit gleichem name wie ein Parent Eintrag auch gehighlightet wird
if(is_array($filename_ini) && in_array(nav_link.Trim() ,$filename_ini))
{
$key = array_search(trim($nav_link),$filename_ini);
$active_parent = 1;
unset($filename_ini[$key]);
} else {
$active_parent = 0;
}
//Markus end
//if(is_array($filename_ini)) $active_parent = (in_array(trim($nav_link),$filename_ini))?1:0;
//else $active_parent = 0;
//Link für Submenü zusammenbauen
if (nav_link == "#")
submenu_link = "
";
else {
if (line.Substring(0,3) == "---") {
submenu_link = "
");else {
if (line.Substring(0,3) == "---") {
submenu_link = "
"+ "
":"")."
\n";
}
else {
submenu_link = "
":"").($active_parent?"}
else {
submenu_link = "
"+ "
node_active = "";
}
//2. Ebene
else if (line.Substring(0,2) != "--") {
//echo $node_active."
";
submenu = node_active2?submenu2:"";
submenu2 = "";
node_active2 = 0;
submenu += "
"+(active?"
\n";
//submenu_link = ($active?"
":"");//submenu_link = ($active?"
":"").($active_parent?"
").(active_parent?"
":"")+(active?"node_active = "";
}
//2. Ebene
else if (line.Substring(0,2) != "--") {
//echo $node_active."
";
submenu = node_active2?submenu2:"";
submenu2 = "";
node_active2 = 0;
submenu += "
"+submenu_link+show_nav_subject+((nav_link == "#")?"
":"if (nav_link == current_file) node_active2=true;
}
//3. Ebene
else if (line.Substring(0,3) != "---"){
node_active3 = false;
if (show_submenu3 && submenu3_dump) submenu3 = submenu3_dump;
show_submenu3 = false;
submenu3_dump = "";
submenu2 .= "
".
submenu_link+show_nav_subject+((nav_link == "#")?"
":"submenu_link+show_nav_subject+((nav_link == "#")?"
if (nav_link == current_file) node_active2=true;
if (nav_link == current_file) {
node_active3=true;
ebene3subject = show_nav_subject;
}
last_nav_subject3 = show_nav_subject;
}
//4. Ebene
else {
submenu3_dump += submenu_link+show_nav_subject+((nav_link == "#")?"":"")+(active?"":"");
if (node_active3 || nav_link == current_file) show_submenu3 = true;
if (nav_link == current_file) {
node_active2=true;
ebene3subject = last_nav_subject3;
}
}
if (nav_link == current_file) {
node_active=true;
current_title = nav_subject;
}
}
}
navi += node_active?submenu:"";
}
public int show_level(string file){
int ebene = 0;
if(Regex.Matches("/^-+/",file, trf)){
switch((2)){
case 1:
ebene = 2;break;
case 2:
ebene = 3;break;
case 3:
ebene = 4;break;
default:break;
}
}else{
ebene = 1;//suchbegriff="";
}
return ebene;
}
//vorgänger des aktiven Knotens ausgeben (rückgabe: array mit navigationslevel als index)
public string show_parent_nodes(string sitemapFile, string current_file){
string sitemap =sitemapFile;
string[] file = System.IO.File.ReadAllLines(Server.MapPath("~") + @"\sitemap.ini").Where(s => s.Trim() != string.Empty).ToArray();
//string file = file(sitemap);
//current_file = current_file.Replace("/","\/");
current_file = current_file.Replace("/","/");
int i = 0;
foreach(string row in file){
if(row.Substring(0,1) != '#' && row.Length > 2){
if(preg_match('/\|'.trim($current_file).'$/',trim($row))){
//$treffer = $row;
break;
}
}i++;
}
level = show_level(file[i]);
counter = level;
//$filename_ini[$level] = trim($file[$i]);
for(d=1;d
if(file[i].(0,1) != '#' && strlen(file[i]) > 2){
current_level = show_level(file[i]);
if(current_level
level = current_level;
break 1;
}
}
}
}
filename_ini = preg_replace("/^.*\|/","",filename_ini);
return filename_ini;
}
public string getIndex(string url)
{
int index = 0;
int node = 0;
int label = 1;
string str = "";
string[] lines = System.IO.File.ReadAllLines(Server.MapPath("~") + @"\sitemap.ini").Where(s => s.Trim() != string.Empty).ToArray();
foreach (string linetext in lines)
{
string[] Content = linetext.Split('|');
string tag = Content[0].Substring(0, 2);
System.Diagnostics.Debug.WriteLine("tag :" + tag);
if (tag.IndexOf('-') != 0) index++;
/*
{
if (tag.Substring(0, 1) == "-" && System.Text.RegularExpressions.Regex.IsMatch(tag.Substring(1, 1), "^[a-zA-Z'.]$")) index++;
node++;
}
*/
if (Content[1] == url)
{
//string tag = Content[0].Substring(0, 2);
//for the first lavel
if (System.Text.RegularExpressions.Regex.IsMatch(tag.Substring(0, 1), "^[a-zA-Z'.]$"))
{
str = node.ToString() + "_" + label.ToString() + "_" + index.ToString();
}
//for the 2nd lavel
else if (tag.Substring(0, 1) == "-" && System.Text.RegularExpressions.Regex.IsMatch(tag.Substring(1, 1), "^[a-zA-Z'.]$"))
{
//node+label then position
label = 2;
str = node.ToString() + "_" + label.ToString() + "_" + index.ToString();
}
//for the 3rd lavel
else if (tag == "--")
{
label = 3;
str = node.ToString() + "_" + label.ToString() + "_" + index.ToString();
}
//str = node.ToString() + index.ToString();
return str;
}
/*
else
{
index++;
}
*/
}
//System.Diagnostics.Debug.WriteLine("node and lebel :" +str);
//Array.IndexOf(Content[1], url);
return str;
}
}
}
Comments
Post a Comment