1) Script Title: Ajax XML Ticker (txt file source)
2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...ajaxticker.htm
3) Describe problem:
First of all please excuse my basic English. I will try to explain so clear as I can my question.
Someone asked me to help him to implement in his website a ticker which can introduce personal messages. I found the script here in dynamicdrive.com and in fact it works very well.
The problem I have is not the script but rather the user who want some help from me. And my incompetence in PHP.
He is unable to use a FTP application in such a way for a changing of the HTML code. That's why I made for him a web page where he should give himself the text he wants: http://costel-marian.de/scroll/test/superuser.html (the URL for the page with the script in this testing phase is at http://costel-marian.de/scroll/test/test.html )
The page contents a javascript:
and two php files:HTML Code:<script type="text/javascript"> var http_request = false; function saveText() { http_request = false; if (window.XMLHttpRequest) { http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Sorry, das hat net geklappt...'); return false; } var text = document.getElementById("text").value; var datei = document.getElementById("datei").innerHTML; document.Eingabe.speichern.value = "Bitte warten"; http_request.onreadystatechange = save; http_request.open('GET', 'saveText.php?text='+text+'&datei='+datei, true); http_request.send(null); } function loadText(datei) { http_request = false; if (window.XMLHttpRequest) { http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Sorry, das hat net geklappt...'); return false; } document.Eingabe.speichern.value = "Bitte warten"; var time = new Date(); var tmp = time.getSeconds(); http_request.onreadystatechange = show; http_request.open('GET', 'loadText.php?datei='+datei+'&tmp='+tmp, true); http_request.send(null); } function save() { if (http_request.readyState == 4) { if (http_request.status == 200) { document.Eingabe.speichern.value = "Die Datei wurde gespeichert!"; document.getElementById("ausgabe").innerHTML = (http_request.responseText); } else { alert('Sorry, das hat nicht geklappt...'); } } } function show() { if (http_request.readyState == 4) { if (http_request.status == 200) { document.Eingabe.speichern.value = "Speichern!"; var text = http_request.responseText; document.getElementById("text").value = text; } else { alert('Sorry, das hat nicht geklappt...'); } } } </script>
saveText.php with:
and loadText.php with:PHP Code:<?php
if(function_exists('get_magic_quotes_gpc')&& get_magic_quotes_gpc()) // PHP6 safe
{
if(!function_exists('array_stripslashes'))
{
// man könnte unter PHP5+6 auch mit
// array_walk_recursive() arbeiten
function array_stripslashes(&$var)
{
if(is_string($var))
$var = stripslashes($var);
else
if(is_array($var))
foreach($var AS $key => $value)
array_stripslashes($var[$key]);
}
}
// die wichtigsten
array_stripslashes($_GET);
array_stripslashes($_POST);
array_stripslashes($_COOKIE);
// seltener notwendig
array_stripslashes($_REQUESET);
array_stripslashes($_FILES);
}
if(function_exists('set_magic_quotes_runtime')) // PHP6 safe
set_magic_quotes_runtime(FALSE); // abschalten
// magic_quotes_sybase ist damit auch automatisch aus
$text = $_GET["text"];
$datei = $_GET["datei"];
$FilePointer = fopen($datei, "w");
fwrite($FilePointer, $text);
fclose($FilePointer);
echo "".$datei." wurde erfolgreich aktualisiert!...";
?>
This construction works also very well.PHP Code:<?php
if(function_exists('get_magic_quotes_gpc')&& get_magic_quotes_gpc()) // PHP6 safe
{
if(!function_exists('array_stripslashes'))
{
// man könnte unter PHP5+6 auch mit
// array_walk_recursive() arbeiten
function array_stripslashes(&$var)
{
if(is_string($var))
$var = stripslashes($var);
else
if(is_array($var))
foreach($var AS $key => $value)
array_stripslashes($var[$key]);
}
}
// die wichtigsten
array_stripslashes($_GET);
array_stripslashes($_POST);
array_stripslashes($_COOKIE);
// seltener notwendig
array_stripslashes($_REQUESET);
array_stripslashes($_FILES);
}
if(function_exists('set_magic_quotes_runtime')) // PHP6 safe
set_magic_quotes_runtime(FALSE); // abschalten
// magic_quotes_sybase ist damit auch automatisch aus
$filename = $_GET["datei"];
$handle = fopen ($filename, "r");
$content = fread ($handle, 100000);
echo $content;
?>
But the person who should use this is afraid of making mistakes at the introducing of messages.
Unfortunatelly my construction doesn't "understand" paragraphs at the saving of the file tickercontent.txt
So the file is a whole paragraph:
<div class="message">Decima tempor soluta consequat sollemnes nam. Iriure laoreet nunc euismod tempor accumsan.</div><div class="message">In quinta option dolore typi sed.</div><div class="message">Processus qui gothica ut dolor demonstraverunt. Litterarum est saepius ii futurum per.</div>
I hope that with your help I can make this construction better. Unfortunatelly, as I said, I don't have any ideea of PHP, but I am willing to learn something.
What I would like to do is:
1. the user should entry only his messages as paragraphs and at the saving of the file (tickercontent.txt) the saveText.php should write at the beginnig of every paragraph a <div class="message"> and at its end a </div>
2. when the file tickercontent.txt is loaded into the form, the file loadText.php should warp these <div class="message"> and </div> but the paragraps should remain as paragraps.
I am very sure that my PHP files are not ready for this but I don't know how should I continue this user-friendly construction.
Thank you very much for your help.



Reply With Quote


Bookmarks