+ Antworten
Ergebnis 1 bis 2 von 2

Thema: Kommentarscript legt überall eine textdatei an

  1. #1
    TP-Insider paul123 ist auf einem guten Weg Avatar von paul123
    Registriert seit
    Apr 2003
    Ort
    sachsen
    Beiträge
    945

    Question Kommentarscript in eine textdatei speichern

    --- Ich glaube das ist zu kompliziert geschrieben ; hab es noch mal umdefiniert ----
    ...und ich dachte, ich schaff das mal alleine aber nein, mir fehlt einfach dazu das Hintergrundwissen.

    Vorweg: Ich versuche gerade meine ersten leichten Gehversuche mit PHP (local). Ich habe von hier ein Kommentarscript. Dieses speichert die Kommentare in einer Textdatei. Das funktioniert auch sofern das Script und die textdatei in einem Ordner sind.
    Nun wollte ich aber gern dieses script in verschiedenen Dateien (und entsprechenden Unterordnern) einsetzen und stelle fest - der findet die textdatei nicht . Diese habe ich mit dem admin-login in einem Ordner namens "daten" (um diesen dann gesamt mit passwort zu schützen war die Überlegung).
    Im script wird ja gleich oben die variable $comment_file für die textdatei definiert. Somit ist der Pfad festgelegt. Nun ist meine Überlegung/Frage: wenn diese variable so flexibel wäre, das je nachdem woher das script aufgerufen wird, auch der passende pfad erscheint dann müsste das doch funktionieren? Und wenn ja, wie geht das?

    - das Forum auf der dortigen Seite ist zwar sehr schön, aber hat mir zu meinem Problem nichts ausgegeben und ist leider nicht so oft besucht...
    PHP-Code:
    <?php
    // Einstellungen:

    // in dieser Datei werden die Kommentare gespeichert (diese Datei auf
    // CHMOD 666 setzen)
    $comment_file "comments.dat";

    // E-Mail-Adresse, an die die Kommentare gesendet werden sollen (optional):
    $comment_admin_email "";

    // neue Kommentare oben (top) oder unten (bottom) anhängen?
    $comment_add_comments "bottom";

    // wieviele Kommentare sollen pro Seite angezeigt werden?
    $comment_comments_per_page 10;

    // Soll versucht werden, Links automatisch zu erkennen und anklickbar gemacht werden? (true=an / false=aus)
    $comment_autolink true;

    // wie lange dürfen Kommentare und Wörter maximal sein?
    $comment_text_maxlength 500;
    $comment_word_maxlength 50;

    // Was angezeigt werden soll, falls kein Name eingegeben wurde:
    $comment_anonym "Anonym";

    // Zeit-Format:
    $comment_time_format "%d.%m.%Y, %H:%M Uhr";

    // Anker, wo auf der Seite die Kommentare sind:
    $comment_anker "#Kommentare";

    // Zeilenumbruch ersetzen (falls nein "<br />"):
    $comment_wordwrap " - ";

    // Ende der Einstellungen

    function comment_make_link($string)
     {
      
    $string ' ' $string;
      
    $string preg_replace("#(^|[\n ])([\w]+?://.*?[^ \"\n\r\t<]*)#is""\\1<a href=\"\\2\">\\2</a>"$string);
      
    $string preg_replace("#(^|[\n ])((www|ftp)\.[\w\-]+\.[\w\-.\~]+(?:/[^ \"\t\n\r<]*)?)#is""\\1<a href=\"http://\\2\">\\2</a>"$string);
      
    $string preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i""\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>"$string);
      
    $string substr($string1);
      return 
    $string;
     }

    function 
    count_comments($comment_id$text=0)
     {
      global 
    $comment_file;
      
    $data file($comment_file);
      
    $comment_total_entries count($data);
      
    // zählen, wieviele Einträge es gibt:
      
    $comment_count 0;
      for (
    $i 0$i $comment_total_entries$i++)
      {
       
    $parts explode("|"$data[$i]);
       if (
    $parts[3] == $comment_id$comment_count++;
      }
      if (
    $text == 0) return $comment_count;
      else
       {
        if (
    $comment_count == 0$count_text "keine Kommentare";
        elseif (
    $comment_count == 1$count_text "1 Kommentar";
        else 
    $count_text $comment_count " Kommentare";
        return 
    $count_text;
       }
     }

     if (isset(
    $_GET['comment_id'])) $comment_id $_GET['comment_id'];
    if (isset(
    $_POST['comment_id'])) $comment_id $_POST['comment_id'];
    if (isset(
    $_GET['comment_popup'])) $comment_popup $_GET['comment_popup'];
    if (isset(
    $_POST['comment_popup'])) $comment_popup $_POST['comment_popup'];

    if (empty(
    $comment_popup) && empty($comment_id) && empty($_GET['get_comment_link'])) $comment_id basename($_SERVER["PHP_SELF"]);

    if (isset(
    $comment_id))
     {
      if (isset(
    $_GET['comment_page'])) $comment_page $_GET['comment_page']; else $comment_page 1;

    // wenn Kommentar eingegeben wurde:
    if (isset($_POST['comment_text']) && trim($_POST['comment_text']) != "")
      {
       
    // Überprüfungen:
       
    unset($errors);
       if (
    strlen($_POST['comment_text']) > $comment_text_maxlength)
        
    $errors[] = "der Text ist zu lang (".strlen($_POST['comment_text'])." Zeichen - es sind nur ".$comment_text_maxlength." Zeichen zugelassen)";
       
    $text_arr str_replace("\n"" "$_POST['comment_text']);
       
    $text_arr explode(" ",$text_arr); for ($i=0;$i<count($text_arr);$i++) { trim($text_arr[$i]); $laenge strlen($text_arr[$i]); if ($laenge $comment_word_maxlength) {
        
    $errors[] = "das Wort \"".htmlentities(stripslashes(substr($text_arr[$i],0,$comment_word_maxlength)))."...\" im Text ist zu lang"; } }

       
    // Schauen, ob doppelt:
       
    $data file($comment_file);
       
    $row_count count($data);
       for (
    $row 0$row $row_count$row++)
         {
          
    $parts explode("|"$data[$row]);
          if (
    $parts[3] == $_POST['comment_id'] && urldecode($parts[4]) == trim($_POST['name']) && trim(urldecode($parts[6])) == trim($_POST['comment_text'])) { $double_entry true; break; }
         }

       
    // wenn keine Fehler, Kommentar speichern:
       
    if (empty($errors) && empty($double_entry))
        {
          
    $comment_text urlencode(trim($_POST['comment_text']));
          
    $name urlencode(trim($_POST['name']));
          
    $email_hp trim($_POST['email_hp']);
          if (
    substr($email_hp,0,7) == "http://"$email_hp substr($email_hp,7);
          
    $email_hp urlencode(base64_encode($email_hp));

          
    $uniqid uniqid("");
          if (
    $comment_add_comments == "top")
          {
           
    $data file($comment_file);
           
    $c count($data);
           
    $datei fopen($comment_file'w+');
           
    flock($datei2);
           
    fwrite($datei$uniqid."|".time()."|".$_SERVER["REMOTE_ADDR"]."|".$_POST['comment_id']."|".$name."|".$email_hp."|".$comment_text."\n");
           for (
    $i 0$i $c$i++) { fwrite($dateitrim($data[$i])."\n"); }
           
    flock($datei3);
           
    fclose($datei);
          }
          else
          {
           
    $datei fopen($comment_file"a");
           
    flock($datei2);
           
    fwrite($datei$uniqid."|".time()."|".$_SERVER["REMOTE_ADDR"]."|".$_POST['comment_id']."|".$name."|".$email_hp."|".$comment_text."\n");
           
    flock($datei3);
           
    fclose($datei);
          }

         
    // E-Mail benachrichtigung an Admin:
         
    if (isset($comment_admin_email) && $comment_admin_email !="")
          {
           if (isset(
    $comment_popup)) { $acid1="?comment_id=".$comment_id."&ampcomment_popup=true"$acid2="&comment_id=".$comment_id."&comment_popup=true"; } else { $acid1 ""$acid2 ""; }
           
    $sender_name trim($_POST['name']);
           if (
    $sender_name==""$sender_name $comment_anonym;
           if (
    preg_match("/^[^@]+@.+\.\D{2,5}$/"base64_decode(urldecode($email_hp)))) $sender_email base64_decode(urldecode($email_hp)); else $sender_email "no@email.xx";
           
    $emailbody "Kommentar zu ".$_POST['comment_id']." von ".$sender_name.":\n\n".$_POST['comment_text'];
           
    $emailbody .= "\n\n\nLink zum Kommentar:\nhttp://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'].$acid1.$comment_anker;
           
    $header"From: ".$sender_name." <".$sender_email.">\n";
           
    $header .= "X-Mailer: PHP/" phpversion(). "\n";
           
    $header .= "X-Sender-IP: ".$_SERVER["REMOTE_ADDR"]."\n";
           
    $header .= "Content-Type: text/plain";
           @
    mail($comment_admin_email"Kommentar zu ".$_POST['comment_id'], $emailbody$header);
          }
         }
       }

      
    // Kommentar-Datei einlesen:
      
    $data file($comment_file);
      
    $comment_total_entries count($data);

      
    // zählen, wieviele Einträge es gibt:
      
    $comment_count 0;
      for (
    $i 0$i $comment_total_entries$i++)
      {
       
    $parts explode("|"$data[$i]);
       if (
    $parts[3] == $comment_id) { $comment_count++; }
      }

      
    // Header für Popup-Fenster:
      
    if (isset($comment_popup))
       {
        
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de"><head><title>Kommentare</title><meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /><style type="text/css"><!-- body { color: #000000; background: #ffffff; margin: 15px; padding: 0px; font-family: verdana, arial, sans-serif; font-size: 13px; } p { font-family: verdana, arial, sans-serif; font-size: 13px; line-height: 19px; } h1 { font-family: verdana, arial, sans-serif; font-size: 18px; font-weight: bold; } --></style></head><body><h1 id="kommentare">Kommentare</h1><?php
       
    }

      
    // Kommentare anzeigen:
      
    if (isset($_GET['show_comments'])) $show_comments $_GET['show_comments'];
      if (isset(
    $_POST['show_comments'])) $show_comments $_POST['show_comments'];
      if (isset(
    $show_comments) && isset($hide_comments)) unset($hide_comments);
      if (empty(
    $hide_comments))
      {
      
    $comment_k 0;
      
    $comment_a 0;
      for (
    $i 0$i $comment_total_entries$i++)
        {
         
    $parts explode("|"$data[$i]);
         if (
    $parts[3] == $comment_id)
          {
           
    $comment_k++;
           if (
    $parts[4] != ""$name htmlentities(stripslashes(urldecode($parts[4]))); else $name $comment_anonym;
           if (
    $parts[5] != "")
            {
             
    $email_hp htmlentities(stripslashes(base64_decode(urldecode($parts[5]))));
             if (
    preg_match("/^[^@]+@.+\.\D{2,5}$/"$email_hp))
                 {
                  
    $email_parts explode("@"$email_hp);
                  
    $email_name $email_parts[0];
                  
    $email_domain_tld $email_parts[1];
                  
    $domain_parts explode("."$email_domain_tld);
                  
    $email_domain "";
                  for (
    $x 0$x count($domain_parts)-1$x++)
                   {
                    
    $email_domain .= $domain_parts[$x].".";
                   }
                  
    $email_tld $domain_parts[$x];
                  
    $name "<script type=\"text/javascript\">
                  <!--
                  document.write('<a href=\"mailto:');
                  document.write('"
    .$email_name."');
                  document.write('@');
                  document.write('"
    .$email_domain."');
                  document.write('"
    .$email_tld."');
                  document.write('\" title=\"E-mail an "
    .$name."\">');
                  //-->
                  </script>"
    .$name."<script type=\"text/javascript\">
                  <!--
                  document.write('</a>');
                  //-->
                  </script>"
    ;
                 }
              else
              {
               if (isset(
    $comment_popup)) $name '<a href="http://'.$email_hp.'" title="Homepage: '.$email_hp.'" target="_blank">'.$name.'</a>';
               else 
    $name '<a href="http://'.$email_hp.'" title="Homepage: '.$email_hp.'">'.$name.'</a>';
              }
            }
           
    $kommentar htmlentities(stripslashes(urldecode($parts[6])));
           if (isset(
    $comment_wordwrap) && $comment_wordwrap != ""$kommentar str_replace("\n"$comment_wordwraptrim($kommentar));
           if (isset(
    $comment_autolink) && $comment_autolink==true$kommentar comment_make_link($kommentar);
           
    $zeit $parts[1];

           if (
    $comment_add_comments == "top")
            {
             if (
    $comment_page=="show_all" || ($comment_k>($comment_page-1)*$comment_comments_per_page && $comment_k<$comment_page*$comment_comments_per_page+1)) { ?><p style="margin:0px 0px 5px 0px;"><b><?php echo $name?>:</b>&nbsp;<?php echo $kommentar?><br /><span style="font-size: 10px; color: #808080;">(<?php echo strftime($comment_time_format$parts[1]); ?>)</span></p><?php $comment_a++; }
            }
           else
            {
             if (
    $comment_page=="show_all" || ($comment_k > ( ($comment_count-$comment_comments_per_page) - ( ($comment_page-1) * $comment_comments_per_page ) ) && $comment_k < (($comment_count-$comment_comments_per_page)-(($comment_page-1)*$comment_comments_per_page))+($comment_comments_per_page+1))) { ?><p style="margin:0px 0px 5px 0px;"><b><?php echo $name?>:</b>&nbsp;<?php echo $kommentar?><br /><span style="font-size: 10px; color: #808080;">(<?php echo strftime($comment_time_format$parts[1]); ?>)</span></p><?php $comment_a++; }
            }
          }
        }

     if (
    $comment_k == 0) echo "<p><i>- es sind noch keine Kommentare vorhanden -</i></p>";
     if (
    $comment_comments_per_page $comment_count && $comment_page != "show_all") { ?><p style="margin:10px 0px 3px 0px; font-family: verdana, arial, sans-serif; font-size: 11px;">Es werden <?php echo $comment_a?> von <?php echo $comment_count?> Kommentaren angezeigt (Teil <?php echo $comment_page?>).&nbsp;<?php
     
    if ($comment_comments_per_page $comment_count && $comment_page 1) { ?>[ <a href="<?php echo basename($_SERVER["PHP_SELF"]); ?>?comment_id=<?php echo $comment_id?>&comment_page=<?php echo $comment_page-1; if (isset($comment_popup)) echo "&amp;comment_popup=true"; if (isset($show_comments)) echo "&amp;show_comments=true"; echo $comment_anker?>" title="voriger Teil">&laquo;</a> ] <?php }
     if (
    $comment_comments_per_page $comment_count && $comment_page < (($comment_count/$comment_comments_per_page))) { ?>[ <a href="<?php echo basename($_SERVER["PHP_SELF"]); ?>?comment_id=<?php echo $comment_id?>&comment_page=<?php echo $comment_page+1; if (isset($comment_popup)) echo "&amp;comment_popup=true"; if (isset($show_comments)) echo "&amp;show_comments=true"; echo $comment_anker?>" title="nächster Teil">&raquo;</a> ] <?php }
     
    ?>
     [ <a href="<?php echo basename($_SERVER["PHP_SELF"]); ?>?comment_id=<?php echo $comment_id?>&comment_page=show_all<?php if (isset($comment_popup)) echo "&amp;comment_popup=true"; if (isset($show_comments)) echo "&amp;show_comments=true"; echo $comment_anker?>" title="alle Kommentare anzeigen">*</a> ]</p><?php }
     if(isset(
    $errors))
      {
       
    ?><p style="color:red; font-weight:bold;">Fehler:</p><ul><?php foreach($errors as $f) { ?><li><?php echo $f?></li><?php ?></ul><?php
      
    }
     
    ?>
     <form method="post" action="<?php echo basename($_SERVER["PHP_SELF"]); ?>"><div>
     <?php if (isset($comment_popup)) { ?><input type="hidden" name="comment_popup" value="true" /><?php ?>
     <input type="hidden" name="comment_id" value="<?php echo $comment_id?>" />
     <input type="hidden" name="show_comments" value="true" />
     <table style="margin-top: 10px;" border="0" cellpadding="1" cellspacing="0">
      <tr>
       <td colspan="3">
       <b>Kommentar schreiben:</b><br />
       <textarea style="width: 400px;" name="comment_text" cols="45" rows="4"><?php if (isset($errors) && isset($_POST['comment_text'])) echo htmlentities(stripslashes($_POST['comment_text'])); ?></textarea><br />
       </td>
      </tr>
      <tr>
       <td style="font-family: verdana, arial, sans-serif; font-size: 11px; vertical-align: bottom;">Name:<br /><input type="text" name="name" value="<?php if (isset($errors) && isset($_POST['name'])) echo htmlentities(stripslashes($_POST['name'])); else echo ""?>" size="23" maxlength="25" /></td>
       <td style="font-family: verdana, arial, sans-serif; font-size: 11px; vertical-align: bottom;">E-Mail oder Homepage:<br/><input type="text" name="email_hp" value="<?php if (isset($errors) && isset($_POST['email_hp'])) echo htmlentities(stripslashes($_POST['email_hp'])); else echo ""?>" size="23" maxlength="60" /></td>
       <td style="font-family: verdana, arial, sans-serif; font-size: 11px; vertical-align: bottom;"><input type="submit" value="  OK  " /></td>
      </tr>
     </table>
     </div></form>
     <?php /* Bei Entfernen des Links bitte ein paar Euro spenden: http://www.alex.ilosuna.org/donation.html */ ?>
     <p style="font-size: 11px;">Script by <a href="http://www.alex.ilosuna.org/kommentar.html"<?php if (isset($comment_popup)) echo " target=\"_blank\""?>>Alex</a></p>
     <?php
     
    }
     else
     {

      
    ?><p>[ <a href="<?php echo basename($_SERVER['PHP_SELF']); ?>?show_comments=true<?php echo $comment_anker?>" title="Kommentare lesen oder schreiben"><?php echo count_comments($comment_id1); ?></a> ]</p>
      <?php
     
    }
     
    // Footer für Popup-Fenster:
     
    if (isset($comment_popup))
      {
       
    ?></body></html><?php
      
    }
    }
    // JavaScript für Popup und Kommentar-Link mit Anzeige, wieviel Kommentare vorhanden sind:
    if (isset($_GET['get_comment_link']))
     {
     
    ?>function comment(id)
     {
     var page = "<?php echo $_SERVER['PHP_SELF']; ?>?comment_id=" + id + "&comment_popup=true";
     popwin = window.open(page,"","width=460,height=500,scrollbars,resizable")
     popwin.focus();
     }
     document.open();
     document.write("[ <a href=\"javascript:comment('<?php echo $_GET['get_comment_link']; ?>')\" title=\"Kommentare lesen oder schreiben\"><?php echo count_comments($_GET['get_comment_link'], 1); ?></a> ]");
     document.close();
     <?php
     
    }
    ?>
    Geändert von paul123 (15.08.2004 um 21:54 Uhr)

    |~| "Ein Traum ist immer der Anfang aller Taten!" |~| made by mir

    -------------------------------------------------------

    ...es wird kalt im Wald.


  2. #2
    TP-Insider paul123 ist auf einem guten Weg Avatar von paul123
    Registriert seit
    Apr 2003
    Ort
    sachsen
    Beiträge
    945
    Nachdem ich es nochmals neu geschrieben habe (in der Hoffnung besser verstanden zu werden) erlaube ich mir mal einen kleinen "nachobenschieb" ... (bitte nicht hauen)


    edit: in der Hoffnung das richtig verstanden zu haben müßte es nun klappen!
    Ich habe nur die variable $comment_file = "comments.dat"; aus dem script rausgenommen und in der datei einzeln eingebunden (mit dem passenden Pfad) - bis jetzt klappts! Hurra. Weiter will ich heut nicht mehr kommen - mein Ziel war zwar wesentlich höher gesteckt; aber nun kann ich wenigstens das WE damit abschließen das es vermutlich klappt. Warum kommt man nicht auf die (in diesem Falle) einfachsten Ideen.

    Naja; habs reingepackt für den ders wissen will/wollte/braucht.
    Geändert von paul123 (15.08.2004 um 23:13 Uhr)

    |~| "Ein Traum ist immer der Anfang aller Taten!" |~| made by mir

    -------------------------------------------------------

    ...es wird kalt im Wald.


+ Antworten

Ähnliche Themen

  1. Wer hat eine Idee?
    Von fränzel im Forum Traum-Dynamik
    Antworten: 25
    Letzter Beitrag: 21.08.2003, 13:54
  2. iDVD kann ich aus 2 DVD´s eine machen?
    Von sos477 im Forum Mac OS
    Antworten: 2
    Letzter Beitrag: 13.06.2003, 13:18
  3. Antworten: 24
    Letzter Beitrag: 17.03.2003, 16:31
  4. Tabellen eine fixe Größe zuweisen
    Von kenny im Forum Dreamweaver & andere Webeditoren
    Antworten: 5
    Letzter Beitrag: 13.03.2003, 17:43

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

     

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51