Gå til innhold

Script inn i html editor og lagre. (har script)


Anbefalte innlegg

Hei

 

Jeg fant et script som henta ut koden til den fila vi velger i en liste som kommer opp.

 

Jeg holder på med å skal legge inn det scriptet i en html editor som redigrer filer etc.

Test her: http://www.hmp.hotserv.dk/edit2.php

 

 

Jeg har sittet en stund å prøvd å lakt inn koden i "Textareaet" i html editor å det fikk jeg till men koden blir helt anneledes når den kommer inn i html editoren. Det blir annen skrift annen farge og størrelse.

 

Noen som har noe peil?

 

Og så trenger jeg hjelp med å få html editoren til å lagre filene dirrekte på servern i stede for å lagre som og så laste opp fila.

 

Her er scriptet som henter ut koden fra fila vi velger:

 

<?
function list_dir($dir) {
      if($handle=opendir($dir)) {
              while(false!==($file = readdir($handle))) {
                      if($file != ".." && $file != ".") {
                              $files[] = $file;
                      }
              }
      }
      closedir();
      if(count($files) > 0) {
              sort($files);
              chdir($dir);
              foreach($files as $file) {
                      if(is_dir($file)) {
                              echo "[dir] - <a href='?action=opendir&mappe=$dir/$file'>$file</a><br>";
                      }
                      else {
                              echo "[file] - <a href='?action=edit&file=$dir/$file'>$file</a><br>";
                      }
              }
      }
}
if(isset($_GET["action"])) {
      $action = $_GET["action"];
}
else {
      $action = "";
}
$basedir = "/var/www/hotserv.dk/users/hmp/inc"; // Endre dette til den dir du vil ha som "rot"

if($action == "opendir") {
      if(!isset($_GET["mappe"])) {
              $mappe = $basedir;
      }
      else {
              $mappe = $_GET["mappe"];
      }
      if(!ereg($basedir, $mappe)) die("Katalog som ikke er støttet (basedir er ikke med)<br>$mappe");
      if(strpos($mappe, "..")) die("kan ikke komme deg lenger opp i filsystemet !");
      list_dir($mappe);
}
elseif($action == "edit") 

{

      // Her kan du lage en kodesnutt for å redigere filene
      // Jeg har bare skrevet ut sourcen til den aktuelle filen.
      $file = $_GET["file"];
      highlight_file($file);
}
else {
      list_dir($basedir);
}?>

 

 

Her er html editor scriptet: OBS! OBS!! Scriptet er langt

 

<script language="JavaScript">
helpstat = false;
stprompt = false;
basic = true;

function thelp(swtch){
if (swtch == 1){
basic = false;
stprompt = false;
helpstat = true;
}
else if (swtch == 0) {
helpstat = false;
stprompt = false;
basic = true;
}
else if (swtch == 2) {
helpstat = false;
basic = false;
stprompt = true;
}
}

function treset(){
if (helpstat){
alert("Clears the current editor.");
}
else {
clear = prompt("Are you sure? (yes/no)",'');
clear = clear.toLowerCase();
if(clear == 'yes') {
document.editor.reset();
document.editor.value = "";
}
}
}

function start(){
if (helpstat){
alert("Elements that appear at the beginning of the document, including TITLE.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<html>\n<head>\n<title></title>\n</head>\n<body>\n";
}
else if (stprompt) {
for(;;){
twrite = prompt("Title?",'');
if (twrite != "" && twrite != null){
break;
}
else {
prompt("You must enter a title.",'Ok, sorry.');
}
}
document.editor.area.value = document.editor.area.value + "<html>\n<head>\n<title>" + twrite + "</title>\n</head>\n<body ";

twrite = prompt("Background color? (blank if none)",'');
if (twrite != "" && twrite != null){
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + "bgcolor=" + twrite + " ";
}

twrite = prompt("Background image? (blank if none)",'');
if (twrite != "" && twrite != null){
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + "background=" + twrite + " ";
}

twrite = prompt("Text color? (blank if none)",'');
if (twrite != "" && twrite != null){
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + "text=" + twrite + " ";
}

twrite = prompt("Link color? (blank if none)",'');
if (twrite != "" && twrite != null){
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + "link=" + twrite + " ";
}

twrite = prompt("Visited link color? (blank if none)",'');
if (twrite != "" && twrite != null){
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + "vlink=" + twrite + " ";
}

document.editor.area.value = document.editor.area.value + ">\n";
}
}

function end(){
if (helpstat){
alert("Adds the the final elements to a document.");
}
else {
document.editor.area.value = document.editor.area.value + "\n</body>\n</html>\n";
}
}

function preview(){
if (helpstat) {
alert("Preview/save the document.");
}
else {
temp = document.editor.area.value;
preWindow= open("", "preWindow","status=no,toolbar=no,menubar=yes");
preWindow.document.open();
preWindow.document.write(temp);
preWindow.document.close();
}
}

function bold() {
if (helpstat) {
alert("Bold text.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<b></b>";
}
else if (stprompt) {
twrite = prompt("Text?",'');
if (twrite != null && twrite != ""){
document.editor.area.value = document.editor.area.value + "<b>" + twrite + "</b>";
}
}
}

function italic() {
if (helpstat) {
alert("Italicizes text.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<i></i>";
}
else if (stprompt) {
twrite = prompt("Text?",'');
if (twrite != null && twrite != ""){
document.editor.area.value = document.editor.area.value + "<i>" + twrite + "</i>";
}
}
}

function underline(){
if (helpstat) {
alert("Underlines text.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<u></u>";
}
else if (stprompt) {
twrite = prompt("Text?",'');
if (twrite != null && twrite != ""){
document.editor.area.value = document.editor.area.value + "<u>" + twrite + "</u>";
}
}
}

function pre(){
if (helpstat) {
alert("Sets text as preformatted.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<pre></pre>";
}
else if (stprompt) {
twrite = prompt("Text?",'');
if (twrite != null && twrite != ""){
document.editor.area.value = document.editor.area.value + "<pre>" + twrite + "</pre>";
}
}
}

function center(){
if (helpstat) {
alert("Centers text.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<center></center>";
}
else if (stprompt) {
twrite = prompt("Text?",'');
if (twrite != null && twrite != ""){
document.editor.area.value = document.editor.area.value + "<center>" + twrite + "</center>";
}
}
}

function hbar(){
if (helpstat) {
alert("Creates a horizontal bar.");
}
else {
document.editor.area.value = document.editor.area.value + "<hr>\n";
}
}

function lbreak(){
if (helpstat) {
alert("Makes a new line, the equivalent of return or enter.");
}
else {
document.editor.area.value = document.editor.area.value + "<br>\n";
}
}

function pbreak(){
if (helpstat) {
alert("Makes two new lines, the equivalent of two returns or enters.");
}
else {
document.editor.area.value = document.editor.area.value + "<p>\n";
}
}

function image(){
if (helpstat) {
alert("Inserts an image.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + '<img src="">\n';
}
else if (stprompt) {
twrite = prompt("Image location?",'');
if (twrite != null && twrite != ""){
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + '<img src=' + twrite + '>\n';
}
}
}

function aleft(){
if (helpstat) {
alert("Inserts an image with align left.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + '<img src="" align=left>\n';
}
else if (stprompt){
twrite = prompt("Image location?",'');
if (twrite != null && twrite != ""){
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + '<img src=' + twrite + ' align=left>\n';
}
}
}

function aright(){
if (helpstat) {
alert("Inserts an image with align right.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + '<img src="" align=right>\n';
}
else if (stprompt) {
twrite = prompt("Image location?",'');
if (twrite != null && twrite != ""){
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + '<img src=' + twrite + ' align=right>\n';
}
}
}

function atop(){
if (helpstat) {
alert("Inserts an image with align top.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + '<img src=""align=top>\n';
}
else if (stprompt) {
twrite = prompt("Image location?",'');
if (twrite != null && twrite != ""){
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + '<img src=' + twrite + ' align=top>\n';
}
}
}

function amid(){
if (helpstat) {
alert("Inserts an image with align middle.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + '<img src="" align=middle>\n';
}
else if (stprompt) {
twrite = prompt("Image location?",'');
if (twrite != null && twrite != ""){
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + '<img src=' + twrite + ' align=middle>\n';
}
}
}

function abottom(){
if (helpstat) {
alert("Inserts an image with align bottom.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + '<img src="" align=bottom>\n';
}
else if (stprompt) {
twrite = prompt("Image location?",'');
if (twrite != null && twrite != ""){
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + '<img src=' + twrite + ' align=bottom>\n';
}
}
}

function head1(){
if (helpstat) {
alert("Creates a header, size 1 (largest size).");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<h1></h1>\n";
}
else if (stprompt) {
twrite = prompt("Text?",'');
if (twrite != null && twrite != ""){
document.editor.area.value = document.editor.area.value + "<h1>" + twrite + "</h1>\n";
}
}
}

function head2(){
if (helpstat) {
alert("Creates a header, size 2 (slightly smaller than 1).");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<h2></h2>\n";
}
else if (stprompt) {
twrite = prompt("Text?",'');
if (twrite != null && twrite != ""){
document.editor.area.value = document.editor.area.value + "<h2>" + twrite + "</h2>\n";
}
}
}

function head3(){
if (helpstat) {
alert("Creates a header, size 3 (slightly smaller than 2).");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<h3></h3>\n";
}
else if (stprompt) {
twrite = prompt("Text?",'');
if (twrite != null && twrite != ""){
document.editor.area.value = document.editor.area.value + "<h3>" + twrite + "</h3>\n";
}
}
}

function head4(){
if (helpstat) {
alert("Creates a header, size 4 (slightly smaller than 3).");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<h4></h4>\n";
}
else if (stprompt) {
twrite = prompt("Text?",'');
if (twrite != null && twrite != ""){
document.editor.area.value = document.editor.area.value + "<h4>" + twrite + "</h4>\n";
}
}
}

function head5(){
if (helpstat) {
alert("Creates a header, size 5 (slightly smaller than 4).");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<h5></h5>\n";
}
else if (stprompt) {
twrite = prompt("Text?",'');
if (twrite != null && twrite != ""){
document.editor.area.value = document.editor.area.value + "<h5>" + twrite + "</h5>\n";
}
}
}

function head6(){
if (helpstat) {
alert("Creates a header, size 6 (smallest size).");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<h6></h6>\n";
}
else if (stprompt) {
twrite = prompt("Text?",'');
if (twrite != null && twrite != ""){
document.editor.area.value = document.editor.area.value + "<h6>" + twrite + "</h6>\n";
}
}
}

function linkopen(){
if (helpstat) {
alert("Begins a link.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + '<a href="">';
}
else if (stprompt) {
twrite = prompt("File location?",'');
if (twrite != null && twrite != ""){
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + '<a href=' + twrite + '>';
for(;;){
twrite = prompt("Text?",'');
if (twrite != "" && twrite != null){
break;
}
else {
prompt("You must enter the link text.",'Ok, sorry.');
}
}
document.editor.area.value = document.editor.area.value + twrite + '</a>\n';
}
}
}

function linktext(){
if (helpstat) {
alert("Inserts the text for a link.");
}
else if (basic) {
for(;;){
twrite = prompt("Text?",'');
if (twrite != "" && twrite != null){
break;
}
else {
prompt("You must enter the link text.",'Ok, sorry.');
}
}
document.editor.area.value = document.editor.area.value + twrite + '\n';
}
else if (stprompt) {
alert("Not used in prompt mode.");
}
}

function linkclose(){
if (helpstat) {
alert("Closes a link.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "</a>\n";
}
else if (stprompt) {
alert("Not used in prompt mode.");
}
}

function anchor(){
if (helpstat) {
alert("Sets an anchor (e.g. #here).");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + '<a name="">\n';
}
else if (stprompt) {
twrite = prompt("Anchor name?",'');
if (twrite != null && twrite != ""){
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + '<a name=' + twrite + '>\n';
}
}
}

function orderopen(){
if (helpstat) {
alert("Starts an ordered list.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<ol>\n";
}
else if (stprompt) {
for(i=1;;i++){
twrite = prompt("Item " + i + "? (Blank entry stops.)",'');
if (twrite == "" || twrite == null){
break;
}
if (i == 1){
document.editor.area.value = document.editor.area.value + "<ol>\n";
okeydokey = 1;
}
document.editor.area.value = document.editor.area.value + "<li>" + twrite + "\n";
}
if (okeydokey) {
document.editor.area.value = document.editor.area.value + "</ol>\n";
}
}
}

function li(){
if (helpstat) {
alert("Creates an item in a list.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<li>";
}
else if (stprompt) {
alert("Not used in prompt mode.");
}
}

function orderclose(){
if (helpstat) {
alert("Closes an ordered list.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "</ol>\n";
}
else if (stprompt) {
alert("Not used in prompt mode.");
}
}

function unorderopen(){
if (helpstat) {
alert("Starts an unordered list.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<ul>";
}
else if (stprompt) {
for(i=1;;i++){
twrite = prompt("Item " + i + "? (Blank entry stops.)",'');
if (twrite == "" || twrite == null){
break;
}
if (i == 1){
document.editor.area.value = document.editor.area.value + "<ul>\n";
okeydokey = 1;
}
document.editor.area.value = document.editor.area.value + "<li>" + twrite + "\n";
}
if (okeydokey) {
document.editor.area.value = document.editor.area.value + "</ul>\n";
}
}
}

function unorderclose(){
if (helpstat) {
alert("Closes an unordered list.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "</ul>\n";
}
else if (stprompt) {
alert("Not used in prompt mode.");
}
}

function defopen(){
if (helpstat) {
alert("Starts a definition list.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<dl>";
}
else if (stprompt) {
for(i=1;;i++){
twrite = prompt("Term " + i + "? (Blank entry stops.)",'');
if (twrite == "" || twrite == null){
break;
}
if (i == 1) {
document.editor.area.value = document.editor.area.value + "<dl>\n";
okeydokey = 1;
}
document.editor.area.value = document.editor.area.value + "<dt>" + twrite + "</dt>\n";
twrite = prompt("Definition" + i + "? (Blank entry stops.)",'');
if (twrite == "" || twrite == null){
break;
}
document.editor.area.value = document.editor.area.value + "<dd>" + twrite + "<dd>\n";
}
if (okeydokey){
document.editor.area.value = document.editor.area.value + "</dl>\n";
}
}
}

function defterm(){
if (helpstat) {
alert("Creates the term in a definition.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<dt>";
}
else if (stprompt) {
alert("Not used in prompt mode.");
}
}

function define(){
if (helpstat) {
alert("Creates the definition.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "<dd>";
}
else if (stprompt) {
alert("Not used in prompt mode.");
}
}

function defclose(){
if (helpstat) {
alert("Closes a defeinition list.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "</dt>";
}
else if (stprompt) {
alert("Not used in prompt mode.");
}
}

function font(){
if (helpstat) {
alert("Sets the font.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + '<font face="">';
}
else if (stprompt) {
twrite = prompt("Font?",'');
if (twrite != null && twrite != "") {
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + '<font face=' + twrite + '>';
}
}
}

function fontcolor(){
if (helpstat) {
alert("Sets the font color.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + '<font color="">';
}
else if (stprompt) {
twrite = prompt("Color? (hex or name)",'');
if (twrite != null && twrite != "") {
twrite = '"' + twrite + '"';
document.editor.area.value = document.editor.area.value + '<font color=' + twrite + '>';
}
}
}


function fontsize(){
if (helpstat) {
alert("Sets the font size (a number 1-7, or +2, -3, etc.).");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "font size=>";
}
else if (stprompt) {
twrite = prompt("Size? (e.g. 1, +5, -2, etc.)",'');
if (twrite != null && twrite != "") {
document.editor.area.value = document.editor.area.value + "<font size=" + twrite + ">";
}
}
}

function fontclose(){
if (helpstat) {
alert("Closes the font changes.");
}
else if (basic) {
document.editor.area.value = document.editor.area.value + "</font>";
}
else if (stprompt) {
document.editor.area.value = document.editor.area.value + "</font>";
}
}







// --> De-Hide
</script>

</head>
<body>
<form name="editor">
<center>
<textarea name="area" rows=12 cols=50 wrap=physical>
</textarea>
<p>
<b>For å lagre: Trykk på 'Forhåndsvis', og gå til 'File>Lagre som' i det nye vinduet.</b>
<table border=1>
<tr>
<td align=center>
<b>
<input type="button" value=" Start " onClick="start()"> 
<input type="button" value=" Stopp " onClick="end()">
     <input type="button" value=" Forhåndsvis " onClick="preview()">

</b>
</td>
<td align=center>
<input type="button" value=" Start på nytt " onClick="treset()">  
<i>
<input type="button" value=" Om " onClick="alert('© .:Av Vegard Sømliøy:. ©')">
</i>
</td>
</tr>
<tr>
<td valign=top>
<b>Formatering</b><br>
<input type="button" value=" Feit " onClick="bold()">   
<input type="button" value=" Kursiv "
onClick="italic()">   
<input type="button" value=" Understrek " onClick="underline()"><br>
<input type="button" value=" Preformater " onClick="pre()"><br>
<input type="button" value=" Midtstill " onClick="center()">
         
<input type="button" value=" Horisontal linje " onClick="hbar()"><br>
<input type="button" value=" Linje skifte " onClick="lbreak()"> 
<input type="button" value=" Paragraf skrifte " onClick="pbreak()">
</td>
<td valign=top>
<b>Type</b><br>
<input type="radio" name="mode" value="help"
onClick="thelp(1)">  Hjelp<br>
  <i><small>Fortell om ellemntentene</small></i><br>
<input type="radio" name="mode" value="prompt" onClick="thelp(2)">  Spør<br>
  <i><small>Spør deg for informasjon som<br>  skal skrive i ellemntet.</i></small><br>
<input type="radio" name="mode" value="basic" checked onClick="thelp(0)">  Standar<br>
  <i><small>Skriv alt selv<br>
  i tekst feltet</small></i>
</td>
</tr>
<tr>
<td valign=top>
<b>Tekst størrelse</b><br>
<input type="button" value=" 1 " onClick="head1()">
 
<input type="button" value=" 2 " onClick="head2()">
 
<input type="button" value=" 3 " onClick="head3()">
 
<input type="button" value=" 4 " onClick="head4()">
 
<input type="button" value=" 5 " onClick="head5()">
 
<input type="button" value=" 6 " onClick="head6()">
</td>
<td valign=top>
<b>Linker</b><br>
<input type="button" value=" Åpne " onClick="linkopen()"> 
<input type="button" value=" Tekst " onClick="linktext()"> 
<input type="button" value=" Steng " onClick="linkclose()">
<br>
<input type="button" value=" Anchor " onClick="anchor()">
</tr>
<tr>
<td valign=top>
<b>Liste</b><br>

     <i>Ordne</i><br>
     <input type="button" value=" Åpne "
onClick="orderopen()"> 
<input type="button" value=" Ting " onClick="li()"> 
<input type="button" value=" Steng " onClick="orderclose()">
<br>
     <i>Uordna</i><br>
     <input type="button" value=" Åpne "
onClick="unorderopen()"> 
<input type="button" value=" Ting " onClick="li()"> 
<input type="button" value=" Steng " onClick="unorderclose()">
<br>
     <i>Definisjon</i><br>
     <input type="button" value=" Åpne " onClick="defopen()">
<input type="button" value=" Term " onClick="defterm()">
<input type="button" value=" Definisjon " onClick="define()">
<input type="button" value=" Steng " onClick="defclose()">
</td>
<td valign=top>
<b>Bilde</b><br>
<input type="button" value=" Bilde " onClick="image()">
<br>
     <i>Align (Hvor teksten skal være i forhold til Internett leseren)</i><br>
     <input type="button" value=" Venstre "onClick="aleft()"> 
<input type="button" value=" Høyre " onClick="aright()"><br>
     <input type="button" value=" Toppen " onClick="atop()"> 
<input type="button" value=" Midten " onClick="amid()"> 
<input type="button" value=" Nederst " onClick="abottom()">
</td>
</tr>
<tr>
<td valign=top>
<b>Skrift</b><br>
<input type="button" value=" Skrift " onClick="font()"> 
<input type="button" value=" Farge " onClick="fontcolor()"> 
<input type="button" value=" Størrelse " onClick="fontsize()"> 
<input type="button" value=" Steng " onClick="fontclose()">
</td>
<td align=center>
</td>
</tr>
</table>
</center>

<p>
</form>

 

Endret av BigJackW
Lenke til kommentar
Videoannonse
Annonse

Det virker jo som om du viser kildekoden til det øverste scriptet, på en måte, liksom... Det er vel neppe det du ønsker?

 

I det første scriptet, kan du bytte ut

highlight_file($file);

med

echo "<textarea rows='50' cols='12' name='area' wrap='physical'>$file</textarea>";

evt legg dette under highlight_file linjen, dersom du fortsatt vil ha det med...

 

For å lagre på serveren, så skriver du bare til filen på nytt, hvis du mener hva jeg forstår. :)

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...