• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

Online Text aus HTML Code bearbeiten

_iChris_

Neues Mitglied
Hi Leute,

da ich bei meiner Problemstellung hier wirklich nicht weiterkomme, hoffe ich das mir nun irgendjemand weiterhelfen kann. Falls das hier falsch eingeordnet ist bitte ich um Entschuldigung da ich nicht wusste wohin damit.
Zum Problem:
Seit einiger Zeit schon versuche ich die Möglichkeit zu finden, Text aus einem HTML Code in einem Editor "öffnen - bearbeiten - speichern" zu können. Nun habe ich eine Möglichkeit gefunden dies zu realisieren. Im Internet bin ich auf einen RichText-Editor gestoßen der mithilfe einer <textarea> den Editor einbindet. Mit meinem Skript, welches zum öffnen und speichern des Textes gedacht ist, sollte das ja keine Problem sein ... Tja, falsch gedacht ...

Hier der Link zum Editor bzw. einbinden des Editors: https://github.com/xing/wysihtml5/wiki/Getting-Started

Hier mein Skript:

Code:
<?php


if(isset($_POST['ok'])){


   //Datei schreiben
   $write=fopen($_POST['filename'], "w");
    if(fwrite ($write, $_POST['datei'])) {
        echo "&Auml;nderung erfolgreich";
    } else {


        echo "Schreiben fehlgeschlagen!";
    }
    fclose($write);


}


// Datei einlesen


$file = '';
$file_content = '';


if(!empty($_GET['filename'])){








      $file = $_GET['filename'];


      $file_content = file_get_contents($file);


}


if (empty($file)) {
    echo 'Achtung: Fehlender Parameter!';
    exit();
}




?>


<!DOCTYPE html>
<html>
    <head>
    <meta charset="utf-8">
    <meta name="description" content="Open source rich text editor based on HTML5 and the progressive-enhancement approach. Uses a sophisticated security concept and aims to generate fully valid HTML5 markup by preventing unmaintainable tag soups and inline styles.">
    <title><?php echo htmlspecialchars($file);?> editieren</title>


    <link rel="stylesheet" href="http://yui.yahooapis.com/2.9.0/build/reset/reset-min.css">
    <link rel="stylesheet" href="css/stylesheet.css">
    <script src="../parser_rules/advanced.js" ></script>
    <script src="../dist/wysihtml5-0.3.0.js" ></script>


    </head>
    <body>
    <form action="edit.php?filename=<?php echo $file;?>" method="post">
    <!--<form action="" method="post">-->
    <input type="hidden" name="filename" value="<?php echo $file;?>" />
    <input type="hidden" name="gesendet" value="jo" />


    <div id="wysihtml5-editor-toolbar">
      <header>
        <ul class="commands">
          <li data-wysihtml5-command="bold" title="Make text bold (CTRL + B)" class="command"></li>
          <li data-wysihtml5-command="italic" title="Make text italic (CTRL + I)" class="command"></li>
          <li data-wysihtml5-command="insertUnorderedList" title="Insert an unordered list" class="command"></li>
          <li data-wysihtml5-command="insertOrderedList" title="Insert an ordered list" class="command"></li>
          <li data-wysihtml5-command="createLink" title="Insert a link" class="command"></li>
          <li data-wysihtml5-command="insertImage" title="Insert an image" class="command"></li>
          <li data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h1" title="Insert headline 1" class="command"></li>
          <li data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h2" title="Insert headline 2" class="command"></li>
          <li data-wysihtml5-command-group="foreColor" class="fore-color" title="Color the selected text" class="command">
            <ul>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="silver"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="gray"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="maroon"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="red"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="purple"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="green"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="olive"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="navy"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="blue"></li>
            </ul>
          </li>
          <li data-wysihtml5-command="insertSpeech" title="Insert speech" class="command"></li>
          <li data-wysihtml5-action="change_view" title="Show HTML" class="action"></li>
        </ul>
      </header>
      <div data-wysihtml5-dialog="createLink" style="display: none;">
        <label>
          Link:
          <input data-wysihtml5-dialog-field="href" value="http://">
        </label>
        <a data-wysihtml5-dialog-action="save">OK</a>&nbsp;<a data-wysihtml5-dialog-action="cancel">Cancel</a>
      </div>


      <div data-wysihtml5-dialog="insertImage" style="display: none;">
        <label>
          Image:
          <input data-wysihtml5-dialog-field="src" value="http://">
        </label>
        <a data-wysihtml5-dialog-action="save">OK</a>&nbsp;<a data-wysihtml5-dialog-action="cancel">Cancel</a>
      </div>
    </div>


    <textarea id="wysihtml5-textarea" name="datei" cols="50" rows="10"><?php echo htmlspecialchars($file_content);?>
    </textarea>


    <input type="submit" name="ok" value="Speichern">
    </form>
    <script>
      var editor = new wysihtml5.Editor("wysihtml5-editor", {
        toolbar: "wysihtml5-editor-toolbar",
        stylesheets: ["http://yui.yahooapis.com/2.9.0/build/reset/reset-min.css", "css/editor.css"],
        parserRules: wysihtml5ParserRules
      });


      editor.on("load", function() {
        var composer = editor.composer;
        composer.selection.selectNode(editor.composer.element.querySelector("h1"));
      });
    </script>
    </body>
</html>
 
Werbung:
Im Beispiel Ordner war dieses File enthalten, habe alles so eingebunden wie in diesem File - ohne Erfolg:

Code:
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="description" content="Open source rich text editor based on HTML5 and the progressive-enhancement approach. Uses a sophisticated security concept and aims to generate fully valid HTML5 markup by preventing unmaintainable tag soups and inline styles.">
    <title>wysihtml5 - A better approach to rich text editing</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/2.9.0/build/reset/reset-min.css">
    <link rel="stylesheet" href="css/stylesheet.css">
    <script src="../parser_rules/advanced.js" ></script>
    <script src="../dist/wysihtml5-0.3.0.js" ></script>
  </head>
  <body>
    <a href="http://github.com/xing/wysihtml5" class="fork"><img src="https://a248.e.akamai.net/camo.github.com/abad93f42020b733148435e2cd92ce15c542d320/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub"></a>
    <p class="get-started"><strong>Get started:</strong> <a href="#">Download</a> the latest version and read the <a href="#">introduction</a></p>
    <div id="wysihtml5-editor-toolbar">
      <header>
        <ul class="commands">
          <li data-wysihtml5-command="bold" title="Make text bold (CTRL + B)" class="command"></li>
          <li data-wysihtml5-command="italic" title="Make text italic (CTRL + I)" class="command"></li>
          <li data-wysihtml5-command="insertUnorderedList" title="Insert an unordered list" class="command"></li>
          <li data-wysihtml5-command="insertOrderedList" title="Insert an ordered list" class="command"></li>
          <li data-wysihtml5-command="createLink" title="Insert a link" class="command"></li>
          <li data-wysihtml5-command="insertImage" title="Insert an image" class="command"></li>
          <li data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h1" title="Insert headline 1" class="command"></li>
          <li data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h2" title="Insert headline 2" class="command"></li>
          <li data-wysihtml5-command-group="foreColor" class="fore-color" title="Color the selected text" class="command">
            <ul>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="silver"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="gray"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="maroon"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="red"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="purple"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="green"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="olive"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="navy"></li>
              <li data-wysihtml5-command="foreColor" data-wysihtml5-command-value="blue"></li>
            </ul>
          </li>
          <li data-wysihtml5-command="insertSpeech" title="Insert speech" class="command"></li>
          <li data-wysihtml5-action="change_view" title="Show HTML" class="action"></li>
        </ul>
      </header>
      <div data-wysihtml5-dialog="createLink" style="display: none;">
        <label>
          Link:
          <input data-wysihtml5-dialog-field="href" value="http://">
        </label>
        <a data-wysihtml5-dialog-action="save">OK</a>&nbsp;<a data-wysihtml5-dialog-action="cancel">Cancel</a>
      </div>
 
 
      <div data-wysihtml5-dialog="insertImage" style="display: none;">
        <label>
          Image:
          <input data-wysihtml5-dialog-field="src" value="http://">
        </label>
        <a data-wysihtml5-dialog-action="save">OK</a>&nbsp;<a data-wysihtml5-dialog-action="cancel">Cancel</a>
      </div>
    </div>
 
 
    <section>
      <textarea id="wysihtml5-editor" spellcheck="false" wrap="off" autofocus placeholder="Enter something ...">
<h1>WYSIHTML5 - A better approach to rich text editing</h1>
<p>wysihtml5 is an <span class="wysiwyg-color-green"><a href="https://github.com/xing/wysihtml5">open source</a></span> rich text editor based on HTML5 technology and the progressive-enhancement approach.
It uses a sophisticated security concept and aims to generate fully valid HTML5 markup by preventing unmaintainable tag soups and inline styles.</p>
<h2>Features</h2>
<ul>
  <li>It's fast and lightweight (smaller than TinyMCE, Aloha, ...)</li>
  <li>Auto-linking of urls as-you-type</li>
  <li>Generates valid and semantic HTML5 markup (even when the content is pasted from MS Word)</li>
  <li>Uses class names instead of inline styles</li>
  <li>Unifies line break handling across browsers</li>
  <li>Uses sandboxed iframes in order to prevent identity theft through XSS</li>
  <li>Speech-input for Chrome</li>
  <li>No jQuery required</li>
</ul>
<h2>Browser Support</h2>
<ul>
  <li><img src="img/icn_firefox.png" width="24" height="24"> Firefox 3.5+</li>
  <li><img src="img/icn_chrome.png" width="24" height="24"> Chrome</li>
  <li><img src="img/icn_internet_explorer.png" width="24" height="24"> IE 8+</li>
  <li><img src="img/icn_safari.png" width="24" height="24"> Safari 4+</li>
  <li><img src="img/icn_ios.png" width="24" height="24"> Safari on iOS 5+</li>
  <li><img src="img/icn_opera.png" width="24" height="24"> Opera 11+</li>
  <li><strong>Graceful degradation:</strong> Unsupported browsers will get a <i>&amp;lt;textarea&amp;gt;</i></li>
</ul>
      </textarea>
    </section>
    <script>
      var editor = new wysihtml5.Editor("wysihtml5-editor", {
        toolbar:     "wysihtml5-editor-toolbar",
        stylesheets: ["http://yui.yahooapis.com/2.9.0/build/reset/reset-min.css", "css/editor.css"],
        parserRules: wysihtml5ParserRules
      });
 
 
      editor.on("load", function() {
        var composer = editor.composer;
        composer.selection.selectNode(editor.composer.element.querySelector("h1"));
      });
    </script>
  </body>
</html>

Hier auf meiner Website habe ich einen test Ordner angelegt: index.html editieren ... Das eigentliche Problem daran ist das die obere Menüleiste nicht funktioniert - auch der HTML-CODE im Textfeld sollte normalerweise als RichText angezeigt werden.

Da ich so einiges schon probiert habe und ich nicht wusste wie ich alles zusammenfassen sollte tut es mir leid wenn das geschriebene jetzt etwas verwirrend klingt, dennoch hoffe ich das mir jemand wirklich behilflich sein kann. Ich bedanke mich schonmal im Vorraus
 
Hi Chris,

also den code aus den erste Post in ein edit.php file gepackt und dann Aufruf mit


http://localhost/cvo_ed1/edit/edit.php?filename=Test.txt

/* edit.php?filename=Test.txt */

öffnent bei mir die Web-Seite.

Ich sehe den Text welcher in meiner Test.txt in Verzeichnis der edit.php vorhanden ist.

Der Button speichern, speichert eine Änderung in der textarea.

soweit tut das.

mir fehlen allerdings:
die Inhalte der Dateien css/stylesheet.css, /parser_rules/advanced.js und /dist/wysihtml5-0.3.0.js

Code:
    <link rel="stylesheet" href="[URL]http://yui.yahooapis.com/2.9.0/build/reset/reset-min.css[/URL]">
    <link rel="stylesheet" href="css/stylesheet.css">
    <script src="../parser_rules/advanced.js" ></script>
    <script src="../dist/wysihtml5-0.3.0.js" ></script>

daher sieht die Seite wohl hier etwas komisch aus.
Das Div <div id="wysihtml5-editor-toolbar"> ist ebenfalls nicht zu sehen :)

gretz the old man


PS. klar in einem Apache Web-Server mit php support... sonst funzt das nicht :)
 
Zuletzt bearbeitet:
Werbung:
Zurück
Oben