Dr. Arne Jachens

Arnes Skriptbibliothek

content

Wird verwendet von:

Keine Erläuterungen gefunden.

<?php
/* 
   published under GPL www.gnu.org/licenses/gpl.html 
   
   Primitives ContentManagentSystem, dieses Skript erlaubt es,
   die Seiten der Homepage mit mehreren Leuten per Webbrowser 
   zu pflegen - dabei werden minimale HTML-Kenntnisse vorausgesetzt.
   Der eigentliche Seitenaufbau ist dabei in cms.php festgelegt und 
   wird per CMSlayout.css formatiert. Ergaenzt wird das Layout durch
   Formatierungen am Ende dieser Datei, die primaer dem Bearbeiten 
   der Seiten dienen.
   Statt eine Datenbank zu nutzen, werden die Eintraege 
   in Form von HTM-Datein gespeichert.
   Die Abschnitte einer Seite werden per <block> </block> separiert.
   Steuerung erfolgt per $what2do:
   * default: Zeige die Seite an.
   * upload: Lade Bild auf den Server hoch und binde es in die Seite
     ein. (Skalierung ist vorher vorzunehmen, Verlinkung per Thumbnail
     ist haendisch anzulegen.)
   * edit: Zeige Eingabeformular, wenn $sec gesetzt ist, lade 
     HTM-Datei dieses Namens.
   * save: Hole Angaben des Formulars und speichere sie in Datei.
   Zum Testen kann $debug=true gesetzt werden.
   
   2011-01-26
   Arne Jachens
   */

$dir = "Content/";  #edit here, check group writing permission

$entryBlocks=array("sec");


function content($sec,$subSec,$what2do){
  /* zentrale Ablaufsteuerung */
  $content ="";
  $message ="";
  global $selfSec, $debug, $secRights;
  $newPage="?sec=".$sec."&what2do=edit";
  if(strlen($what2do)<1){$what2do="default";}
  if ($debug){
    $message.= "<p><aj>content()</aj> what2do=".$what2do." <br>index.php".$selfSec."</p>";
  }
  switch ($what2do){
  case "upload":
    $content.= uploadChooseFile();
    break;
  case "delete":
    $delNo=$_POST['delNo'];
    $entry = contentPost();
    for($d=0;$d<$_POST['NoOfBlocks'];$d++){
      if($d==$delNo){
	$entry[$d]=$thisBlock;
      }
    } #d
    #fall through
  case "save":
    if (!is_array($entry)){list($entry,$message) = contentPost();}
    $message = contentWrite($entry);
    $sec = $entry['sec'];#??
    #fall through
  case "edit":
    $login = contentLogin("form");
    if($_SESSION['IamGod']){
      list($entry,$msg)= contentRead($subSec);
      #$content.= $entry;
      $message.= $msg;
      list($form,$msg) = contentEdit($entry,$subSec);
      $message.= $msg;
      $content.= $form;
    }else{
      $content.= $login;
    }
    break;
  case "delete":
    list($entry,$message) = contentPost();
    $content.= contentDelete($entry);
    break;
  case "contact":
    list($contactForm,$msg) = contact(addslashes($_POST['sendState']),$sec);
    $content.= $contactForm;
    $message.= $msg;
    break;
  default:
    if($_SESSION['securityLevel']>=$secRights[$sec] AND $what2do!="edit"){
      list($thisContent,$msg) =  contentShow($subSec);
      $message.= $msg;
      $content.= $thisContent;
    }elseif($_SESSION['IamGod']){
      list($thisContent,$msg) = contentShow($subSec);
      $message.= $msg;
      $content.= $thisContent;
    }else{
      $content.= contentLogin("form");
    }
    #$content = stripslashes(str_replace("block>","div>",$content));
  }
  return array($content,$message);
}

function contentLogin($what2do){
  /* Bearbeitung nur nach Login moeglich */
  global $debug,$selfSec,$levelPwd;
  if(!isset($_SESSION['securityLevel'])){$_SESSION['securityLevel']=0;}
  if(isset($_POST['pwd'])){$pwd=addslashes($_POST['pwd']);}else{$pwd="";}
  switch($what2do){
  case "form":
    if ($_SESSION['IamGod']){
      $form="<div class='loginForm'><form method='POST' action='".$selfSec."&what2do=edit' align='center'>
    <input type='submit' name='logout' value='logout'></p></form></div>\n";
    }else{
      $form="<div class='loginForm'><form method='POST' action='".$selfSec."' align='center'>
    <input type='password' name='pwd' size='15'>
    <input type='submit' name='login' value='login'></p></form></div>";
    }
    return $form;
    break;
  default:
    $mode=$what2do;
    /* log out */
    if(isset($_POST['logout']) AND $_POST['logout']=="logout"){
      $_SESSION['IamGod']=false;
      $_SESSION['securityLevel']=0;
      $mode="show";
    }
    /* pwd was entered, increase counter */
    if (isset($_POST['login'])){
      if(isset($_SESSION['loginCount'])){
	$_SESSION['loginCount']++;
      }else{
	$_SESSION['loginCount']=1;
      }
    }
    /* admin valid: login, highest secLevel, reset counter */
    if(isset($_POST['login']) AND $_POST['login']=="login" AND $pwd==ADMINPASSWORT){
      $_SESSION['IamGod']=true;
      $_SESSION['securityLevel']=9;
      $mode="edit";
      $_SESSION['loginCount']=0;
    }
    /* set any valid secLevel, reset counter */
    if(!empty($pwd)){
      for($s=0;$s<10;$s++){
	if(isset($levelPwd[$s]) AND strcmp($pwd,$levelPwd[$s])==0){
	  $_SESSION['securityLevel']=$s;
	  $mode="show";
	  $_SESSION['loginCount']=0;
	  break;
	}
       #s
      if($s==9){$mode=$what2do;}
    }
    /* increase delay in case of attac */
    if(isset($_SESSION['loginCount']) AND $_SESSION['loginCount']>0){
      $time=time();
      time_sleep_until($time+$_SESSION['loginCount']);
    }
    return $mode;
  } #switch
}

function contentEdit($content,$sec){
  $content = str_replace("&","&",$content);
  /* Eingabeformular fuer Abschnitte der Datei */
  global $self, $selfSec, $dir, $delimiter, $debug;
  $message="";
  $entry['sec']=$sec;
  if(isset($_GET['block'])){
    $blockActual=$_GET['block'];
  }else{
    $blockActual="";
  }
  $form ="<form method='POST' action='".$selfSec."'>\n";
  $form.="<table class='content'>\n";
  if($blockActual=="sec" OR empty($entry['sec'])){
    $form.="<tr><td class='input'>Erstmal brauchen wir einen Namen für die Seite:<br>
    <input type='text' name='sec' value='".$entry['sec']."' size='70'></td>
    <td class='button'> </td></tr>\n";
  }else{
    $form.="<tr><td class='input'><span class='sec'>".$entry['sec']."</span>
    <input type='hidden' name='sec' value='".$entry['sec']."'></td>
    <td class='button'>  </td></tr>\n";
  }
  /* split text into blocks to edit */
  if (!empty($content)){
    $block = explode("</block>",$content);
    $NoOfBlocks=count($block)-1;
    for($d=0;$d<=$NoOfBlocks;$d++){
      $block[$d]=substr(trim($block[$d]),strpos($block[$d],"<block>")+7);
    } #d
    $block[$d-1]=substr($block[$d-1],0,strpos($block[$d-1],"</block>"));
  }else{
    $NoOfBlocks=0;
    $form.="<tr><td class='input'>Erstmal brauchen wir einen Namen für die Seite:<br>
    <input type='text' name='sec' value='".$entry['sec']."' size='70'></td>
    <td class='button'> </td></tr>\n";
  }
  if ($debug){$message.= "<aj>contentEdit</aj> NoOfDivision=".$NoOfBlocks."<br>";}
  for($d=0;$d<$NoOfBlocks;$d++){
    if($blockActual=="block".$d){
      $form.="<tr><td class='input'>
      <textarea name='block".$d."' rows='16' cols='100'>".stripslashes($block[$d])."</textarea></td>
      <td class='button'> </td></tr>\n";
      /* submit */
      $form.="<tr><td class='input'><table width='100%'><tr><td><input type='submit' name='what2do' value='save' /></td><td align='right'><input type='submit' name='what2do' value='delete' /><input type='hidden' name='delNo' value='".$d."' /></td></table></td><td class='button'> </td></tr>\n";
    }else{
      $form.="<tr><td class='input'>".stripslashes($block[$d])."
      <input type='hidden' name='block".$d."' value='".$block[$d]." '></td>
      <td class='button'> <a href='".$selfSec."&what2do=edit&block=block".$d."'>[edit]</a></td></tr>\n";
    }
  } #d
  /* add block */
  if ($blockActual=="p"){
    $d++;
    $form.="<tr><td class='input'>
    <textarea name='block".$d."' rows='8' cols='60'><p> </p></textarea></td>
    <td class='button'> </td></tr>\n";
  }
  /* add list */
  if ($blockActual=="ul"){
    $d++;
    $form.="<tr><td class='input'>
    <textarea name='block".$d."' rows='8' cols='60'><ul>\n<li> </li>\n<li> </li>\n<li> </li>\n </ul></textarea></td>
    <td class='button'> </td></tr>\n";
  }
  /* add numerated list */
  if ($blockActual=="ol"){
    $d++;
    $form.="<tr><td class='input'>
    <textarea name='block".$d."' rows='8' cols='60'><ol>\n<li> </li>\n<li> </li>\n<li> </li>\n </ol></textarea></td>
    <td class='button'> </td></tr>\n";
  }
  /* upload picutre */
  if ($blockActual=="img"){
    $form.= uploadChooseFile();
  }
  /* safe uploaded file */
  if(isset($_POST['block']) AND $_POST['block']=="upload"){
    $userfile=basename($_FILES['userfile']['name']);
    $target = $dir.$userfile;
    $result = move_uploaded_file($_FILES['userfile']['tmp_name'], $target);
    if ($debug){
      if ($result){
	$message.= "<aj>contentEdit</aj> <p>Upload war erfolgreich: 
        <strong>". basename( $_FILES['userfile']['name']). "</strong></p>";
      }else{
	$message.= "<aj>contentEdit</aj> ".$_FILES['userfile']['error']."<br>
        Upload war NICHT erfolgreich: <strong>".$target."</strong><br>";
      }
    }
#    if ($_FILES['userfile']['type']=="image/jpg"
    $d++;
    $type=substr($userfile,strlen($userfile)-3);
    $content.= $type;
    if ($type=="pdf" OR $type=="ocx" OR $type=="doc"){
      $imgSrc="<p><a href='".$target."'>".$userfile."</a></p>";
      $imgSrc=str_replace("'","\"",$imgSrc);
      $form.="<tr><td class='input'><p><a href='".$target."'>".$userfile."</a></p><input 
      type='hidden' name='block".$d."' value='".addslashes($imgSrc)."'>";
    }else{
      $imgSrc="<p><img src='".$target."' alt='".$userfile."'></p>";
      $imgSrc=str_replace("'","\"",$imgSrc);
      $form.="<tr><td class='input'><p><img src='".$target."' alt='".$userfile."'></p><input 
      type='hidden' name='block".$d."' value='".addslashes($imgSrc)."'>";
    }
    $blockActual="img";
    $form.="</td>
    <td class='button'><a href='".$selfSec."&what2do=edit&block=block".$d."'>[edit]</a></td></tr>\n";
  } #fi, upload
  if($blockActual=="p" OR $blockActual=="ul" OR $blockActual=="ol" OR $blockActual=="img"){
  /* submit */
    $form.="<tr><td class='input'><table width='100%'><tr><td><input type='submit' name='what2do' value='save' /></td><td align='right'><input type='submit' name='what2do' value='delete' /></td></table></td><td class='button'> </td></tr>\n";
  }
  $form.="</table>\n";
  $dd=$d+1;
  $form.="<input type='hidden' name='NoOfBlocks' value='".$dd."'>\n";
  $form.="</form>\n";
  $form.="Hinzufügen: <a href='".$selfSec."&what2do=edit&block=p'>Absatz</a>, ";
  $form.="<a href='".$selfSec."&what2do=upload'>Bild</a>, ";
  $form.="<a href='".$selfSec."&what2do=edit&block=ul'>Aufzählung</a>, ";
  $form.="<a href='".$selfSec."&what2do=edit&block=ol'>Nummerierung</a></p><p> </p>";

  $pageURL=substr($selfSec,strpos($selfSec,"index.php"));
  $newPage="?sec=".$selfSec."&what2do=edit";
  $form.="<div style='background-color:#dddddd;'>
  <h4>Hinweis:</h4><p>Du kannst ausser reinem Text auch HTML eingeben:<br>
  <tt><em> </tt>kursiv<tt> </em></tt> wird <em>kursiv</em> und <br><tt><strong> </tt>fett<tt> </strong></tt> wird <strong>fett</strong> dargestellt,<br>
  <tt><a href='http://www.lindheim.de'>Lindheim.de</a></tt> ist ein <a href='http://www.arne.jachens.de'>Link</a>,<br>
  <tt><br></tt> ist ein Zeilenumbruch und <tt><p> </tt>text<tt> </p></tt> ein Absatz.</p>
  <p>Ausnahmen:<br><tt><</tt> als <tt>&lt;</tt> und <br><tt>></tt> als <tt>&gt;</tt> eingeben;<br>
  einfache Anführungszeichen <tt>'</tt> werden durch doppelte <tt>"</tt> ersetzt.</p>
  <p>Falls du mal einen Abschnitt <u>vor</u> einem anderen einfügen musst, kannst du dies, indem du <br> <tt></block><block></tt> als erste Zeichen in den folgenden Abschnitt kopierst und speicherst.</p>
  <p>Falls du diese Seite irgendwo - z.B. links im Menü - verlinken willst, ist der passende Link auf diese Seite:<br> <strong><a href='".$pageURL."'><a href='".$selfSec."'>".$sec."</a><a></strong></p> 
  <p>Und wenn du eine neue Seite (in diesem Bereich der Homepage) anlegen willst, kannst du entweder in der URL eine neue 'subSec' eingeben, oder du gibst den neuen Namen (ohne Umlaute!) in das Formular ein:<br>\n
  <form style='background-color:#dddddd;' method='POST' action='".$newPage."'>\n<input type='text' name='subSec' size='75'><input type='submit' value='new'>\n</form>
  </p></div>";
  $form.= contentLogin("form");
  return array($form,$message);
}

function contentPost(){
  /* uebertrage Angaben aus Eingabeformular in Struktur */
  global $self, $debug, $delimiter, $entryBlocks;
  $message="";
  for($f=0;$f<count($entryBlocks);$f++){
    $entry[$entryBlocks[$f]] = addslashes($_POST[$entryBlocks[$f]]);
  } #f
  $sec = $entry['sec'];
  $sec = strtolower(strtr($sec, "", "s"));
  $sec = preg_replace("/[^A-Za-z0-9]+/", "_", $sec);
  $sec = preg_replace("/[_]+$/", "", $sec);
  $sec = preg_replace("/^[_]+/", "", $sec);
  $entry['sec'] = $sec;
  $NoOfBlocks=sprintf("%d",$_POST['NoOfBlocks']);
  for($d=0;$d<$NoOfBlocks;$d++){
    if(isset($_POST['block'.$d])){
      $thisBlock = trim($_POST['block'.$d]);
      $thisBlock = str_replace("'","\"",$thisBlock);
      $thisBlock = str_replace("<?","?",$thisBlock);
      $thisBlock = str_replace("<script","script",$thisBlock);
      $thisBlock = stripslashes($thisBlock);
      $thisBlock = stripslashes($thisBlock);
      $thisBlock = addslashes($thisBlock);
      if (strlen($thisBlock)>0){
	$entry[$d]=$thisBlock;
      }
    } #fi
  } #d
  if ($debug){
   $message.= "<aj>contentPost</aj> NoOfBlocks ".$NoOfBlocks."<br>";
    for($f=0;$f<count($entryBlocks);$f++){
      $message.= "  ".$entryBlocks[$f].": ";
      $message.=showHTML($entry[$entryBlocks[$f]])."<br>";
    } #f
  }
  return array($entry,$message);
}


function contentWrite($entry){
  /* speichere Struktur als HTM-Datei */
  global $self, $dir, $debug, $delimiter, $entryBlocks;
  $message="";
  $fname = $entry['sec'].".htm";
  $backup= $entry['sec'].".bak";
  $fname = $dir.$fname;
  $backup= $dir.$backup;
  if ($debug){$message.= "<aj>contentWrite</aj> ".$fname." ";}
  /* create backup */
  $oldContent="";
  if (file_exists($fname)) {
  $fid = fopen($fname,"r");
  $line = fgets( $fid, 1024 );
  while(!feof($fid)){
    $oldContent.=$line;
    $line = fgets( $fid, 2048 );
  }
  fclose($fid);
  $fid = fopen($backup,"w");
  if(!$fid){
    $message.= "<p><b>Backup nicht moeglich!</b></p>";
  }else{
    fputs($fid,$oldContent);
    $backupDone=TRUE;
  }
    fclose($fid);
  }else{
    $backupDone=TRUE;
  }
  /* save new content */
  $entryString ="";
  $fid = fopen($fname,"w");
  if($fid==false){
    $message='<aj>Schreiben nicht moeglich!</aj>';
  }else{
    for($d=0;$d<count($entry);$d++){
      if(isset($entry[$d])){
	$bad=array("&","","","","","","","");
	$good=array("&","ä","ö","ü","Ä","Ö","Ü","ß");
	$entry[$d] = str_replace($bad,$good,$entry[$d]);
	$bad=array("amp;amp","amp;auml","amp;ouml","amp;uuml","amp;Auml","amp;Ouml","amp;Uuml","amp;szlig","amp;nbsp","amp;quot","amp;euro","amp;lt","amp;gt","amp #","amp;hearts","amp;#39");
	$good=array("amp","auml","ouml","uuml","Auml","Ouml","Uuml","szlig","nbsp","quot","euro","lt","gt"," #","hearts","#39");
	$entry[$d] = str_replace($bad,$good,$entry[$d]);
	$entryString.="<block>\n".$entry[$d]."</block>\n";
      }
     #d

    if($_SESSION['IamGod'] AND $backupDone){
      fputs($fid,$entryString);
      $message='<aj>Datei geschrieben</aj><br>';
    }else{
      $message.="<p><aj>Du bist rechtelos!</aj></p>";
      $message.=$entryString;
    }
    fclose($fid);
  } #fi
  return $message;
}

function contentDelete($entry){
  global $self, $dir, $debug;
  $message="";
  $fname = $entry['date']."_".$entry['ID'].".cal";
  $fname=$dir.$fname;
  if (file_exists($fname)){
    if($_SESSION['IamGod']){
      $result = unlink($fname);
    }else{
      $message.="<p><aj>Du bist rechtelos!</aj></p>";
    }
  }else{
    $message.= "<aj>File not found: </aj>".$fname."<br>";
  }
  if ($result){$message.= "<aj>Eintrag gelöscht.</aj><br>";}
  return $message;
}

function contentRead($sec){
  /* lese HTM-Datei zur Seite $sec */
  global $self, $dir, $debug, $delimiter, $entryBlocks;
  $content="";
  $message="";
  $fname=$dir.$sec.".htm";
  if(isset($_GET['bak'])){$fname=$dir.$sec.".bak";}/* show backup */
  if (file_exists($fname)) {
    $fid = fopen($fname,"r");
    $line = fgets( $fid, 2048 );
    $content =trim($line);
    while(!feof($fid)){
      $line = fgets( $fid, 2048 );
      $content .=$line;
    }
    fclose($fid);
  }else{
    $message.= "<aj>CONTENT ".$sec.".htm DOES NOT EXIST!</aj><br>";
    $message.="<block><h2>".$sec."</h2></block>";
  }
  if(isset($_GET['bak'])){$message.=showHTML(stripslashes($content));} /* show backup */
  if ($debug){
    $message.= "<aj>contentRead</aj> ".$sec.".htm<br>";
    $message.=showHTML($content);
  }
  return array($content,$message);
}

function showHTML($html){
  /* zum Testen, Anzeige von HTML-Code */
  $html=str_replace("<","<",$html);
  $html=str_replace(">",">",$html);
  $html=str_replace("/div>","/div><br>",$html);
  return "<pre>".$html."</pre>";
}

function contentShow($sec){
  /* Anzeige der $sec HTM-Datei */
  global $self, $selfSec, $dir, $debug, $delimiter, $entryBlocks;
  $message = "";
  $content = "";
  if(isset($_SESSION['IamGod']) AND $_SESSION['IamGod']){
    $content.="<p style='text-align:center;'><a class='klein' href='".$selfSec."&what2do=edit'>[edit]</a></p>\n";
  }
    list($html,$message1) = contentRead($sec);
    $content.= stripslashes($html);
  if ($debug){
    $message = "<aj>contentShow</aj> <br>".$message1;
  }
  if(isset($_SESSION['IamGod']) AND $_SESSION['IamGod']){
    $content.="<p style='text-align:center;'><a class='klein' href='".$selfSec."&what2do=edit'>[edit]</a></p>\n";
  }
  return array($content,$message);
}

function uploadChooseFile(){
  /* Auswahl Bild fuer Upload */
  global $debug;
  $form ="\n";
  $subSec=$_GET['subSec'];
  if(empty($subSec)){
    $name=$_GET['name'];
    $self="?sec=".$_GET['sec']."&name=".$name;
  }else{
    $self="?sec=".$_GET['sec']."&subSec=".$subSec;
  }
  if ($_SESSION['IamGod']){
    $form.= "<form enctype='multipart/form-data' action='".$self."&what2do=edit' method='POST'>";
    $form.= "<table width='100%'><tr><td class='input'>";
    $form.= "Wähle ein Bild von deinem Rechner aus (max 500 kb):<br>\n";
    $form.= "<input type='hidden' name='MAX_FILE_SIZE' value='500000'>\n";
    $form.= "<input type='file'   name='userfile'>\n";
    $form.= "<input type='hidden' name='what2do' value='edit'>\n";
    $form.= "<input type='hidden' name='block' value='upload'>\n";
    $form.= "<input type='submit' value='Upload File'>\n";
    $form.= "</td><td class='button'></td></tr>\n";
    $form.= "</table></form> ";
  }else{
    $form.= "<div align='center'><p> </p><a href='".$self."?what2do=edit'>Bitte log dich als Admin ein!</a></div>";
  }
 return $form;
}

function contentStyle(){
  /* spezielle Formatierung der Funktionen dieser Seite */

$style ="
td.input       { }
td.button      { }
form.light     { background-color:white; }
form.dark      { background-color #eeeeee; }
td.light       { background-color:white;   vertical-align:top; }
td.dark        { background-color #eeeeee; vertical-align:top; }
td.lightDate   { background-color:white; text-align:left; vertical-align:top; }
td.darkDate    { background-color #eeeeee; text-align:left; vertical-align:top; }
td.month       { font-weight:bold; background-color #cccccc; }
span.desc      {  }
span.sec       { color:silver; }
b              { color:red; }
";
 return $style;
}
?>
1fraktal.php
2VereinsverwaltungKartei.php
3VereinsverwaltungKarteikarte.php
4VereinsverwaltungKonto.php
5VereinsverwaltungLastschriften.php
6VereinsverwaltungMenue.php
7whichLengthDoWeHaveInXfigFile.php
8XML_extractAttribute.php
9XML_extractElement.php
10XML_extractTag.php
11XML_findAllElements.php
12XML_readFile.php
13writeNamedData.php
14menu.php
15content.php
16cms.php
17indexCms.php
18areaOfPolygon.php
19areaOfTriangle.php
20calculateAreasOfPolygonsInXfig.php
21calculateMeanStd.php
22checkChanges.php
23closeFigures.php
24db.php
25distanceOfPoints.php
26dtaus.php
27enumerateFiles.php
28fileGrep.php
29fitData.php
30fotoalbum.php
31genAlbum.php
32genDTAUS.php
33genFotoalbum.php
34genThumbnails.php
35globals.php
36hex2dec.php
37LaTeXbrief.php
38norm.php
39pdf.php
40plotResult.php
41pointsOfPolygon.php
42polynominalFit.php
43readData.php
44readDymolaOuput.php
45readFilenames.php
46readFromStdIn.php
47readNamedData.php
48readXmlFile.php
49searchMedian.php
50sortIEindex.php
51sortIntoBins.php
52sortPDF.php
53synchronise.php
54synchroniseDirectories.php
55Vereinsverwaltung.php
56writeData.php

 

gnuplot

gnuplot is used to visualise the results - via script you can do infinite diagrams in 1 second.
Run 'test' in gnuplot to get an owerview of the available line- and symbolstyles.