getTimestamp(); $date_BeginnDatumOffenlage = date_create_from_format('d.m.Y' , $BeginnDatumOffenlage)->getTimestamp(); $date_EndeDatumOffenlage = date_create_from_format('d.m.Y' , $EndeDatumOffenlage)->getTimestamp(); $date_EndeAbkuendigung = date_create_from_format('d.m.Y' , $EndeAbkuendigung)->getTimestamp(); $date_BeginnDatumAnkuendigung = $date_BeginnDatumAnkuendigung /*- (24*60*60)*/; $date_BeginnDatumOffenlage = $date_BeginnDatumOffenlage /*- (24*60*60)*/; $date_EndeDatumOffenlage = $date_EndeDatumOffenlage /*-(24*60*60)*/; $date_EndeAbkuendigung = $date_EndeAbkuendigung /*- (24*60*60)*/; if($aktDatum < $date_BeginnDatumAnkuendigung) { echo "

204 No Content

"; exit; } //Vorinitalisieren $HeaderText = ""; $Projekttitel_1 = ""; $Projekttitel_2 = ""; if ($aktDatum < $date_BeginnDatumOffenlage) { // Schalte Ankuendigung $HeaderText = $TextHeaderAnkuendigungsseite; $Projekttitel_1 = $TextProjektTitel1; $Projekttitel_2 = $TextProjektTitel2; } elseif ($aktDatum >= $date_BeginnDatumOffenlage && $aktDatum < $date_EndeDatumOffenlage) { // Schalte Header Offenlage $HeaderText = $TextHeaderOffenlage; $Projekttitel_1 = $TextProjektTitel1Offenlage; $Projekttitel_2 = $TextProjektTitel2Offenlage; } elseif ($aktDatum >= $date_EndeDatumOffenlage && $aktDatum < $date_EndeAbkuendigung) { // Schalte Header Abkuendigung $HeaderText = $TextHeaderAbkuendigung; $Projekttitel_1 = $TextProjektTitel1Abkuendigung; $Projekttitel_2 = $TextProjektTitel2Abkuendigung; } // Für alle ausser die erste liste (ul) $deeper = ""; ?>
{content}\n"; public static $A_TEMPLATE = "{content}\n"; public static $UL_TEMPLATE = "
    {content}
\n"; // -------------------------------------------------------------------------------------------- public static function compile($template, $replacements) { $compiledString = $template; foreach ( $replacements as $key => $value ) { $compiledString = preg_replace ( "/{" . $key . "}/", $value, $compiledString ); } return $compiledString; } // -------------------------------------------------------------------------------------------- } class NodeElement { // -------------------------------------------------------------------------------------------- private $parent; private $name; private $link; private $css; private $style; private $elements; // -------------------------------------------------------------------------------------------- public function __construct($name, $link, $css, $style) { $this->name = $name; $this->link = $link; $this->css = $css; $this->style = $style; $this->elements = array (); } // -------------------------------------------------------------------------------------------- /** * will create the html from this node and all it's elements * * @return html string */ public function toHTML() { // set the name as the default content $content = $this->name; // prepare the link if set and override the content if (isset ( $this->link ) && !empty($this->link)) { $content = Template::compile ( Template::$A_TEMPLATE, array ( "link" => $this->link, "style" => @$this->style, "content" => $this->name ) ); } // add the elements to the content $content .= $this->getElementsHTML (); if(strpos($this->css,"Titel") !== false) { $this->css = $this->css . " Projekt-Titel"; } else {} // create the li element $li = Template::compile ( Template::$LI_TEMPLATE, array ( "class" => @$this->css, "style" => @$this->style, "content" => $content ) ); return $li; } // -------------------------------------------------------------------------------------------- public function getElementsHTML() { $elementsHTML = ""; if (! empty ( $this->elements )) { foreach ( $this->elements as $element ) { $elementsHTML .= $element->toHTML (); } $deeper = "Liste"; if(strpos($elementsHTML,"Projekt-Titel") !== false) { $deeper = "None"; } // wrap the elements into an ul tag $elementsHTML = Template::compile ( Template::$UL_TEMPLATE, array ( "class" => $deeper, "content" => $elementsHTML ) ); } return $elementsHTML; } // -------------------------------------------------------------------------------------------- public function getParent() { return $this->parent; } // -------------------------------------------------------------------------------------------- public function getName() { return $this->name; } // -------------------------------------------------------------------------------------------- public function getLink() { return $this->link; } // -------------------------------------------------------------------------------------------- public function getCss() { return $this->css; } // -------------------------------------------------------------------------------------------- public function getStyle() { return $this->style; } // -------------------------------------------------------------------------------------------- public function addElement($element) { $element->parent = $this; $this->elements [] = $element; } // -------------------------------------------------------------------------------------------- } class ULBuilder { // -------------------------------------------------------------------------------------------- private $rootNode; /** * holds the regex which describse one entry line and the groups of the values */ //public $entryRegex = "/\[(.*)\](-+)(?:\s+)?([\wäöüÄÖÜ\/ß\$\%\§\&\.\(\)\-\: ]+).+\[(.*)\](?:.+)?/"; public $entryRegex = '/\[(.*)\](-+)(?:\s+)?([\wäöüÄÖÜ\/ßẞµ´\',ʼˮ\"„“”‚‘«»–+;\$\%\§\&\.\(\)\-\: ]+).+\[(.*)\] ?(.*)(?:.+)?/i'; // Enthält den Format String als regex public $formatRegex = '/\.(.*)[[:blank:]]\{(.*)\}[[:blank:]]?([KE])?/i'; /** * mapps the supported values to it's group within the regex */ public $nameGroupMap = array ( "css" => 1, "indent" => 2, "name" => 3, "link" => 4, "style" => 5, ); // -------------------------------------------------------------------------------------------- /** * Reads the file and creates all the nodes. * * @param string $filename */ public function getAllNodes($filename) { $handle = fopen ( $filename, 'r' ); if ($handle) { $lastIndent = 1; // create a root node which holds the whole tree // this is a special node and will be handled differently $this->rootNode = new NodeElement ( "ROOT", NULL, NULL , ""); $actualNode = $this->rootNode; $lastNode = NULL; while ( ($line = fgets ( $handle )) !== false ) { $utf8_line = /*utf8_encode(*/ $line /*)*/; //$utf8_line = utf8_decode(html_entity_decode($line)); // PARSE CSS FORMAT INFORMATION preg_match ( $this->formatRegex, $utf8_line, $cssMatches ); if($cssMatches) { //var_dump($cssMatches); // Zeile ist CSS Zusatzinformation! // Schreibe in CSS Style element für Knoten if($cssMatches[3] == "K"){ echo "\n"; } else if ($cssMatches[3] == "E") { echo "\n"; } else { echo "\n"; } if($cssMatches[1] == "SeitenHintergrundFarbe") { echo "\n"; } else { } // Schreibein CSS Style element für Eintrag } // the regex how a valid entry should look like preg_match ( $this->entryRegex, $utf8_line, $matches ); if ($matches) { // first create a new node $name = $matches [$this->nameGroupMap ["name"]]; $link = $matches [$this->nameGroupMap ["link"]]; $css = $matches [$this->nameGroupMap ["css"]]; $style = $matches [$this->nameGroupMap ["style"]]; // Wird als Klasse benötigt für Design if(strpos($css,"Eintrag") !== FALSE) { $css = $css . " Standard-Eintrag2"; } // Wird als Klasse benötigt für Design else if(strpos($css,"Knoten") !== FALSE) { $css = $css . " Standard-Knoten2"; } $link = str_replace("ö","%F6",$link); $link = str_replace("Ö","%D6",$link); $link = str_replace("ä","%E4",$link); $link = str_replace("Ä","%C4",$link); $link = str_replace("ü","%FC",$link); $link = str_replace("Ü","%DC",$link); $link = str_replace("ß","%DF",$link); //$link = str_replace(",","%2c",$link); $node = new NodeElement ( $name, $link, $css , "color: " . $style); // now get the - and decide where it belongs to $indent = strlen ( $matches [$this->nameGroupMap ["indent"]] ); $indentDiff = $indent - $lastIndent; if ($indentDiff > 0) { // add the node to the one added before $actualNode = $lastNode; $actualNode->addElement ( $node ); } else if ($indentDiff == 0) { // need to add the node to the same as the one before $actualNode->addElement ( $node ); } else { // need to go back diff amout of nodes for($i = 0; $i < abs ( $indentDiff ); ++ $i) { if ($actualNode->getParent () != NULL) { $actualNode = $actualNode->getParent (); } else { // this should never happen throw Exception ( "cannot go higher then the root node" ); } } $actualNode->addElement ( $node ); } $lastNode = $node; $lastIndent = $indent; } } } else { // Failure (not found) -> File $fileerror = 1; echo "
File not found!
"; } // Failure (empty) -> File if (!$fileerror) { if (file_get_contents($filename) == false) echo "
File empty!
"; } fclose ( $handle ); } // -------------------------------------------------------------------------------------------- /** * Generates the HTML * * @return html string */ public function generateHTML() { // the root element is a special node which shouldn't show up in the html return $this->rootNode->getElementsHTML (); } // -------------------------------------------------------------------------------------------- } // create a ul builder and pass the file $ulBuilder = new ULBuilder (); $ulBuilder->getAllNodes ( 'gliederung.txt' ); echo $ulBuilder->generateHTML (); ?>