PHP: "Sie sind hier"-Navigation à la "Home > Bilder ..."

Der_baum

Mitglied
Hallo zusammen,

ich spiele gerade mit dem Gedanken zu der bereits bestehenden Navigation ( http://www.tutorials.de/forum/php-t...on-ueber-die-url-index-php-section-index.html ) noch eine wie hier im Forum hinzuzufügen.
Speziell meine ich hier die „Sie sind hier“-Navigation à la Home > Bilder > Gallerie 1 …

Grad fehlt mir aber noch der Denk- und Umsetzunganstoß. Die Forum und Websuche hat mich leider auch nicht so weitergebracht….

Gerne würde ich eine Lösung für meine bereits bestehende Navi finden.

Danke schonmal im vorraus,
Gruß Dan
 
Eine ganz einfache Lösung wäre das du ganz oben in der page eine switch abfrage machst und die parameter die du per Get übergibst checken lässt und dann eine Variable instanzierst (je nach Ort) und diese dann an der Gewünschten stelle ausgibst.

Das is vielleicht keine saubere Lösung aber eine sehr einfach gelöste Methode die du überall wo du deine Includes mit GET übergibst einbauen kannst.

:)
 
Das einfachte wäre, wenn du ein passendes URL-Design hättest, wobei die Hierarchieebenen den Pfadsegmenten entsprächen. Dort könntest du dann einfach die REQUEST_URI-Umgebungsvariable an den Schrägstrichen zerteilen und fertig.
 
Hallo und danke euch drei!

@sexmagic: Es soll schon eine 100 Prozentige Lösung sein da ich mir die Zeit dafür nehmen kann und will! :)

@daddz: Endlich! :) Ich hab die ganze Zeit nach einem passenden Suchbegriff dafür gesucht!
Hab dann auch gleich das hier gefunden (hoffentlich darf man den Link setzten....): http://www.drweb.de/php/brotkrumen.shtml und versuche es mal einzubinden und umzusetzen.

@Gumbo: Das wird aber leider nicht funktionieren da ich den Inhalt ja mit PHP tauschen lasse und somit auch nichts in der URl hab wie ..... .de/bilder/gallerie1, oder hab ich dich falsch Verstanden?

Wenn ich weiter bin und/oder Fragen habe, werde ich mich melden!
Lösung wird natürlich auch sofort gepostet!


Gruß Dan
 
Hi,


mmmmh. Ich habs irgendwie schon vorher geahnt. Haut alles nicht so ganz hin wie ich mir das vorstelle.

Kennt jemand eine möglichkeit das mit meiner Art der Navigation (siehe Link erstes Posting) umzusetzten?
Gerne bin ich auch offen für eine komplett MySQL-Datenbankgestützte Lösung offen. Soll heißen das ich auch gerne mein Konzept überdenke.


Gruß Dan
 
Hallo zusammen,

vorab mal, dass drüber hat sich erledigt, allerdings hab ich noch ne Frage.

Ich Löse die ganz Geschichte nun wie folgt.
Navigation läuft über folgendes abgewandeltes Script: http://www.tutorials.de/forum/php-t...on-ueber-die-url-index-php-section-index.html .
Funktioniert alles soweit super, die Breadcrump Sache erledigt ich mit folgemdem Script: http://www.baskettcase.com/classes/breadcrumb/ .

Jo, ich weiss... aber ich bin noch am lernen, deswegen muss ich mir erst alle Scripte zusammensuchen und dann anpassen, später kann ich das dann (hoffentlich) selber.

Problem ist aber das das folgende Script:

PHP:
<?php

class breadcrumb {
  // Directory Structure
  var $scriptArray = '';
  
  // Filename
  var $fileName = '';
  
  // Document Root
  var $document_root = '';
  
  // Homepage name
  var $homepage = 'Home';
  
  // Directory type formatting
  var $dirformat = '';
  
  // Symbol to use between Directories
  var $symbol = ' &gt; ';
  
  // CSS Class to use for each item
  var $cssClass = '';
  
  // Special Directory text style
  var $special = '';
  
  // Frameset target value default is '_self'
  var $target = '';
  
  // is this a personal site?
  var $personalSite = '';
  
  // Show the filename with the path
  var $showfile = TRUE;
  
  // Remove the link to the current directory
  var $unlinkCurrentDir = TRUE;
  
  // Hide the file Extension
  var $hideFileExt = TRUE;
  
  // Linke the filename to itself
  var $linkFile = FALSE;
  
  // Replace underscore with space
  var $_toSpace = TRUE;
  
  // Show errors
  var $showErrors = FALSE;
  
  // Where are the images kept and what type of images
  var $imagedir = array();
  
  // Change the Directory Names to something a bit more readable
  var $changeName = array('hide_folder');
  
  // Change the file name to something a bit more user friendly
  var $changeFileName = array();
  
  // If variable has a value check for that page if it exists link the directory
  // otherwise just show the name of the directory.
  var $fileExists = array();
  
  // Remove a directory from the breadcrumb so that it does not show
  var $removeDirs = array();
  
  /**
   * function breadcrumb
   * @since Version 2.0.0
   */
  function breadcrumb() {
    // Creates an array of Directory Structure
    $this->scriptArray = explode("/", $_SERVER['PHP_SELF']);
    // Pops the filename off the end and throws it into it's own variable
    $this->fileName = array_pop($this->scriptArray);
    // Is this a personal site?
    if (substr($_SERVER['PHP_SELF'], 1, 1)=='~') {
    	$tmp = explode('/', $_SERVER['PHP_SELF']);
    	$this->personalSite = $tmp[1];
			$this->document_root = str_replace(str_replace('/'.$this->personalSite, '', $_SERVER["SCRIPT_NAME"]), '', $_SERVER['PATH_TRANSLATED']);
   	}
   	else 
			$this->document_root = str_replace($_SERVER["SCRIPT_NAME"], '', $_SERVER['PATH_TRANSLATED']);
   	#echo $this->document_root.'<Br />';
   	#echo $_SERVER["SCRIPT_NAME"].'<Br />';
   	#echo $_SERVER["PATH_TRANSLATED"].'<Br />';
  }
  
  /**
   * function str_split
   * @since Version 2.2.0
   * Converts a string to an array
   */
  function str_split($string) {
    for ($i=0; $i<strlen($string); $i++) $array[] = $string{$i};
    return $array;
  }
  
  
  /**
   * function specialLang
   * @since Version 2.0.0
   * Convert string into language specified
   */
  function specialLang($string, $lang) {
    // parse Directory special text style
    switch($lang) {
      case 'elmer': $string = str_replace('l','w',$string);
                    $string = str_replace('r','w',$string);
                    break;
      case 'hacker': $string = strtoupper($string);
                     $string = str_replace('A','4',$string);
                     $string = str_replace('C','(',$string);
                     $string = str_replace('D','D',$string);
                     $string = str_replace('E','3',$string);
                     $string = str_replace('F','ph',$string);
                     $string = str_replace('G','6',$string);
                     $string = str_replace('H','}{',$string);
                     $string = str_replace('I','1',$string);
                     $string = str_replace('M','|V|',$string);
                     $string = str_replace('N','|\|',$string);
                     $string = str_replace('O','0',$string);
                     $string = str_replace('R','R',$string);
                     $string = str_replace('S','5',$string);
                     $string = str_replace('T','7',$string);
                     break;
      case 'pig': $vowels = array('a','A','e','E','i','I','o','O','u','U');
                  $string = $this->str_split($string);
                  $firstLetter = array_shift($string);
                  $string = implode('',$string);
                  $string = (in_array($firstLetter, $vowels))
                    ? $firstLetter.$string.'yay'
                    : $string.$firstLetter.'ay';
                  break;
      case 'reverse': $string = strrev($string);
                      break;
    }
    return $string;
  }
  
  
  /**
   * function dirFormat
   * @since Version 2.2.0
   * Convert string into specified format
   */
  function dirFormat($string, $format) {
    // parse Directory text style
      switch($format) {
        case 'titlecase': $string = $this->titleCase($string); break;
        case 'ucfirst': $string = ucfirst($string); break;
        case 'ucwords': $string = $this->convertUnderScores($string);
                        $string = ucwords($string); break;
        case 'uppercase': $string = strtoupper($string); break;
        case 'lowercase': $string = strtolower($string); break;
        default: $string = $string;
      }
    return $string;
  }
  
  
  /**
   * function titleCase
   * @since Version 2.3.0
   * Convert string into Title Case which excludes capitalizing certain small
   * words.  As in a movie title, or book title. "The Wind in the Trees"
   * @author Justin@gha.bravepages.com, un-thesis@wakeup-people.com,
   *         mgm@starlingtech.com, rick@baskettcase.com
   */
  function titleCase($text) {
    $text = $this->convertUnderScores($text);
    $min_word_len = 4;
    $always_cap_first = TRUE;
    $exclude = array('of','a','the ','and','an','or','nor','but','is','if',
                     'then','else','when','up','at','from','by','on','off',
                     'for','in','out','over','to','into','with','htm','html',
                     'php','phtml'); 

    // Allows for the specification of the minimum length  
    // of characters each word must be in order to be capitalized 

    // Make sure words following punctuation are capitalized 
    $text = str_replace(array('(', '-', '.', '?', ',',':','[',';','!'), 
                        array('( ', '- ', '. ', '? ', ', ',': ','[ ','; ','! '),
                        $text); 

    $words = explode (' ', strtolower($text)); 
    $count = count($words); 
    $num = 0; 
    
    while ($num < $count) { 
      if (strlen($words[$num]) >= $min_word_len 
          && array_search($words[$num], $exclude) === false) 
        $words[$num] = ucfirst($words[$num]); 
      $num++; 
    } 
    
    $text = implode(' ', $words); 
    $text = str_replace( 
    array('( ', '- ', '. ', '? ', ', ',': ','[ ','; ','! '), 
    array('(', '-', '.', '?', ',',':','[',';','!'), $text); 
    
     // Always capitalize first char if cap_first is true 
    if ($always_cap_first) { 
       if (ctype_alpha($text[0]) && ord($text[0]) <= ord('z') 
          && ord($text[0]) > ord('Z')) 
         $text[0] = chr(ord($text[0]) - 32); 
    }
  
   return $text; 
  }


  
  /**
   * function removeDirectories
   * @since Version 2.3.2
   * @author rick@baskettcase.com
   * Remove the directories from the breadcrumb
   */
  function removeDirectories() {
    $numDirs = count($this->scriptArray);
    for ($i=0; $i<$numDirs; $i++) {
      if (!in_array($this->scriptArray[$i], $this->removeDirs))
        $newArray[] = $this->scriptArray[$i];
    }
    return $newArray;
  }


  
  /**
   * function removeFileExt
   * @since Version 2.4
   * @author rick@baskettcase.com
   * Remove the file extension from the filename
   */
  function removeFileExt($filename) {
    $newFileName = @explode('.',$filename);
    return $newFileName[0];
  }


  
  /**
   * function convertUnderScores
   * @since Version 2.4
   * @author rick@baskettcase.com
   * Replace underscores with spaces
   */
  function convertUnderScores($name) {
    $varName = str_replace('_',' ',$name);
    return $varName;
  }



  /**
   * function show_breadcrumb
   * @since Version 0.0.1
   */
  function show_breadcrumb() {
   // Either set the home element or pop the first empty array off the beginning
    if ($this->homepage != '') $this->scriptArray[0] = $this->homepage;
    else $tmp = array_shift($this->scriptArray);
    
    // if this is a personal site remove the root directory and set
    // new homepage to user directory
    if ($this->personalSite!='') {
    	$this->removeDirs[] = $this->scriptArray[0];
    	if ($this->homepage != '') $this->scriptArray[1] = $this->homepage;
    	else $tmp = array_shift($this->scriptArray);
		}
		    	
    if ($this->homepage=='') $dir = '/';
    
    // Build Path Structure
    $numDirs = count($this->scriptArray);
    
    // BEGIN DIRECTORY FOR LOOP
    for ($i=0; $i<$numDirs; $i++) {
      #echo $this->changeName[$this->scriptArray[$i]];
      #$dirName = $this->scriptArray[$i];
      $dirName = ($this->changeName[$this->scriptArray[$i]]!='') ? 
                  $this->changeName[$this->scriptArray[$i]] :
                  $this->scriptArray[$i];
                  
      // append the current directory
      if ($this->personalSite!='' && $i==1)
      	$this->scriptArray[$i] = $this->personalSite;
      $dir .= ($i==0 && $this->homepage!='') ? '/' : $this->scriptArray[$i]."/";
      
      // Use Text instead of Images
      if (!$this->imagedir) {
        // Replace underscores with spaces if _toSpace is set
        if ($this->_toSpace==TRUE) 
          $dirName = $this->convertUnderScores($dirName);
        
        // parse Directory special text style
        $dirName = $this->specialLang($dirName, $this->special);
  
        // Convert string into specified format
        $dirName = $this->dirFormat($dirName, $this->dirformat);
      }
      // Use Images instead of text
      else {
        $dirName = '<img src="'.$this->imagedir[0].$dirName.'.'.
                   $this->imagedir[1].'" />'; 
      }
      
      // Add CSS
      if ($this->cssClass!='') $class = ' class="'.$this->cssClass.'"';
      
      // Add frame target
      if ($this->target!='') $target = ' target="'.$this->target.'"';
      
      // create link
      // If fileExists has values then check to make sure one of those files
      // exists, if it does, link it, otherwise do not link
      if ($this->fileExists) {
        for ($k=0; $k<count($this->fileExists); $k++) {
        	if ($this->personalSite!='') {
        		if (strpos($dir, $this->personalSite))
        			$exists_filename = str_replace($this->personalSite.'/', '', $this->document_root.$dir.$this->fileExists[$k]);
						else continue;
					}
					else
						$exists_filename = $this->document_root.$dir.$this->fileExists[$k];
					#echo $exists_filename.'<br />';
          if (file_exists($exists_filename)) {
            $showLink = 'yes';
            break;
          } else $showLink = 'no';
        }
      }
      
      if ($this->unlinkCurrentDir==TRUE && ($i+1)==$numDirs || $showLink=='no')
         $breadcrumb[] = $dirName;
      // If we are not supposed to remove the directory, show it
      elseif (!in_array($this->scriptArray[$i], $this->removeDirs) || $showLink=='yes') 
      	$breadcrumb[] = "<a href='$dir'$class$target>$dirName</a>";
      elseif ($this->personalSite!='' && $i==1)
      	$breadcrumb[] = "<a href='$dir'$class$target>$dirName</a>";
    }
    // END DIRECTORY FOR LOOP
    
    $fileName = $originalFileName = $this->fileName;
    
    if ($this->fileNametoTitle==TRUE) $fileName = $this->getPageTitle(); 
    
    // Check to see if hideFileExt is on, if so turn on showfile
    // and remove the file extension
    if ($this->hideFileExt==TRUE) $this->showfile = TRUE;
    
    if ($this->showfile==TRUE) {
      // Change the filename if filename is in changeFileName array
      if ($this->changeFileName[$_SERVER['PHP_SELF']]!='') 
        $fileName = $this->changeFileName[$_SERVER['PHP_SELF']];
      // If it is not then just use $fileName or remove extension if specified
      elseif ($this->hideFileExt==TRUE)
        $fileName = $this->removeFileExt($fileName);
        
      // Convert underscores to spaces
      if ($this->_toSpace==TRUE) 
        $fileName = $this->convertUnderScores($fileName);
      // parse filename special text style
      $fileName = $this->specialLang($fileName, $this->special);
      // Convert string into specified format
      $fileName = $this->dirFormat($fileName, $this->dirformat);
      // Add CSS
      if ($this->cssClass!='') $fileName = '<span class="'.$this->cssClass.'">'.
                                           $fileName.'</span>';
      // Add link to filename
      if ($this->linkFile==TRUE)
        $fileName = '<a href="'.$originalFileName.'">'.$fileName.'</a>';
      $fileName = $this->symbol.$fileName;
    } else $fileName = '';
    
    // Web Server Path
    // return if we are not at root
    if ($numDirs>0) return implode($this->symbol,$breadcrumb).$fileName;
    // if at root just return the filename
    else return $fileName;
  }
}
?>

mit der URl arbeit.

Frage ist nun ich das Script umschreiben oder austricksen kann und zwar so das die Breadcrump-Navi trotzdem funktioniert.
Den Pfad der Datei kann ich mir ja aus der "Haupt-"Navi ausgeben lassen mit:

PHP:
$dateien[$_GET['section']]

Hier nochmal das Sript zum Codeschnipsel:

Config.php:
PHP:
<?php 
$dateien = array(); //Erstellt einen neuen Array $dateien 
$dateien['home'] = "home.php"; //für jede Section ein neue Variable 
$dateien['news'] = "news.php";  //usw. 
$dateien['error'] = "error.php"; 
?>

Inhalt.php:
PHP:
<?php 
include('config.php');  
?> 
.
.
.
.
.
<?php 
include('config.php'); 

if(isset($_GET['section']) AND isset($dateien[$_GET['section']])) 
{ 
 //Ist eine $_GET Variable vorhanden wird PHP angewiesen  
 //zu prüfen ob die Datei existiert und diese dann zu laden 
  
 if(!file_exists($dateien[$_GET['section']])) echo "Die Datei ist nicht vorhanden."; 

 include $dateien[$_GET['section']];  
} 
else 
{ 
 //Wenn keine Variable oder Definition vorhanden ist 
 //lade die Fehlerseite bzw. die Indexseite 
 include $dateien['error'];  
} 
?>
 

Neue Beiträge

Zurück