CMS help. XML instead of TXT

I stubbled across a nice little CMS-type thing which updates an external .txt file. I was wondering if some kind soul knew if it were possible to change the coding so one could edit/update/manage .xml files instead?

Here is a link to the full code, a tutorial, demos and source files: http://ntdesigns.net/tutorial/NewsManager.html

Many many thanx in advance for anyone that can help me out.

Anybody? Nobody? Kirupaaaa! :frowning:

ive been wanting to do the same thing Asparagus.

i probably wont get a chance to have a proper look till friday. but i’ll see if i can come up with something similar.

:}

Are you after a single entry like that example or multiple entries?

If you want multiple entries I cant help much… well not yet anyway.

ho k,
I got a single entry version working. Ive only spent half an hour on it. hopefully it works for too.

EDIT: FOUND SOME ISSUES

i renamed this file to “newsSaver_xml2.php”


<?
$myFileName=$_POST["myFileName"]; 
$title=$_POST["title"]; 
$article=$_POST["article"];

if(ereg("/","$myFileName") || ereg('.php',"$myFileName")) 
die("Thou shall not hack!");  

$xml_output = "<?xml version=\"1.0\"?>
\r";
$xml_output .= "<entries>
";
$xml_output .= "	<title><![CDATA[" . $title . "]]>
";
$xml_output .= "	</title>
";
$xml_output .= "	<entry><![CDATA[" . $article . "]]>
";
$xml_output .= "	</entry>
";
$xml_output .= "</entries>";

$fp = fopen ("$myFileName", "w+");
fwrite($fp,$xml_output); 
//fwrite($fp,"$article"); 
fclose($fp); 

if ($fp) { 
echo ("&msg=Save Successful!&name=$name&myTextSave=$myTextSave");   
} else { 
echo ("&error=OK&msg=Save unsuccessful!...an error occurred!"); 
} 
 
?> 

newsReaderAdmin.fla replace all code on frame 1 with this check html enabled of main text box


stop();
//Create the loadVars object to hold the data
container = new LoadVars();
//Create a variable to hold the file name for the data to be saved
container.myFileName = "saveAndLoad.xml";
container.myFilePath = "http://yourpath/";


blog_xml = new XML();
blog_xml.ignoreWhite = true;
blog_xml.onLoad = function(success) {
	if (!success) {
		trace("Failed to load");
		_root.article.htmlText = "Failed to load. Please try again.";
	} else {
		trace("Data is loaded");
		blog = this.firstChild.childNodes;
		//populate the textfields with the container data
		_root.title.htmlText = unescape(blog[0].childNodes);
		_root.article.htmlText = unescape(blog[1].childNodes);
		trace(blog[0].childNodes);
		_root.msg.text = _root.container.msg;
	}
};
blog_xml.load("http://yourpath/saveAndLoad.xml");


//Button event to update the textfile and NewsReader movie
myButton.onRelease = function() {
	
	container.title = escape(_root.title.htmlText);
	container.article = escape(_root.article.htmlText);
	//call the PHP script to write the data to the textfile
	container.sendAndLoad("http://yourpath/newsSaver_xml2.php", _root.container, POST);
	//create a local connection to the NewsReader movie to update it real time
	myLocalConnection = new LocalConnection();
	//send the updated data
	myLocalConnection.send("incoming message", "onReceive1");
	//close the connection
	myLocalConnection.close();
	//custom function to clear the return message from the PHP script
	myInterval=setInterval(myLoad, 4000);
	//repopulate the container data
	container.load("http://yourpath/saveAndLoad.xml");
_root.nextFrame();
}
//Custom function to clear msg textfield
myLoad = function () {
	_root.msg.text = "";
	clearInterval(myInterval);	
}

newsReader.fla
replace current code on frame 1 with this. Make sure both text boxes are html enabled


blog_xml = new XML();
blog_xml.ignoreWhite = true;
blog_xml.onLoad = function(success) {
	if (!success) {
		trace("Failed to load");
		_root.article.htmlText = "Failed to load. Please try again.";
	} else {
		trace("Data is loaded");
		blog = this.firstChild.childNodes;
		//populate the textfields with the container data
		_root.title.html = true;
		_root.article.html = true;
		_root.title.htmlText = unescape(blog[0].childNodes);
		_root.article.htmlText = unescape(blog[1].childNodes);
		trace(unescape(blog[0].childNodes));
	}
};
blog_xml.load("http://yourpath/saveAndLoad.xml");

//Create the local connection object for the admin movie
myLocalConnection = new LocalConnection();
//When the connection call is recieved, repopulate the loadVars object
myLocalConnection.onReceive1 = function() {
	//Set a delay interval to allow time for the data to 
	//be updated before loading.
	myInterval=setInterval(myLoad,1000);
}
//Listen for the local connection from the admin movie
myLocalConnection.connect("incoming Message");

will have another look later, hopefully this helps.
:rocker:

almost forgot…

php file now spits xml out like this…

saveAndLoad.xml

EDIT: Have changed the tree structure to this…


<?xml version="1.0"?>

<entries>
	<title><![CDATA[%3Cb%3Etitle%20text%3C%2Fb%3E]]>
	</title>
	<entry><![CDATA[body%20text]]>
	</entry>
</entries>

you may need to save this into your directory
:moustache

Absolutely brilliant! Next time I’m in Melbourne, I’ll buy ya a beer.
Now that’s said, I’m going to start getting greedy.

I use XML from my external text instead of basic TXT because I have found a nice way of implimenting stylesheets to the text. Just basic stuff: style, rollover links, headings, etc.

Is there any way to anable this? Here’s the actionscript I’ve used in the past:

//init TextArea component
myText.html = true; myText.wordWrap = true; myText.multiline = true; myText.label.condenseWhite=true;
/*****load css*****/
Style = new TextField.StyleSheet(); Style.load("stylesheet.css"); myText.styleSheet = Style;
/*****load in XML*****/
Content = new XML(); Content.ignoreWhite = true; Content.load("news.xml"); Content.onLoad = function(success) {if(success) {myText.text = Content;}}

I’ve tried just plopping the ‘load css’ script in, but to no avail…

Many thanx for any help given.

maybe your stylesheet isn’t being loaded before it’s being assigned. try using an onLoad function (the same as you’ve done with Content.onLoad) to check if the css is loaded before assigning it to your textfield. something like this:


myText.html = true;
myText.wordWrap = true;
myText.multiline = true;
myText.label.condenseWhite=true;
Content = new XML();
Content.ignoreWhite = true;

Content.onLoad = function(success) {
if(success) {
// If the xml loaded without error,
// assign it text field
trace("xml loaded");
myText.htmlText = Content;}
}

Style.onLoad = function(success) {
if (success) {
// If the style sheet loaded without error,
// assign it to the text object
trace("stylesheet loaded");
myText.styleSheet = Style;
// now load the xml
Content.load("news.xml");
} else {
trace("ERROR loading stylesheet");
}

};

Style.load("stylesheet.css"); /*starts everything off*/

hope that helps,
:slight_smile:

Thanx for trying, treatkor, but it didn’t seem to make a difference.

On a side note, I’ve been looking around at Flash text editors, and thought about Frankensteining it with this little gadget we’re making here, to make a nifty little writer/converter/CMS for Flash.

If it ever comes alive, I’ll post it.

myText.html = true;
myText.wordWrap = true;
myText.multiline = true;
myText.label.condenseWhite = true;
myContent = new XML();
myContent.ignoreWhite = true;
myStyle = new TextField.StyleSheet(); //i forgot this line before
myContent.onLoad = function(success) {
trace(“myContent functioncalled”);
if (success) {
// If the xml loaded without error,
// assign it to the text field
trace(“xml loaded”);
myText.htmlText = myContent;
}
};
myStyle.onLoad = function(success) {
trace(“myStyle function called”);
if (success) {
// If the style sheet loaded without error,
// assign it to the text object
trace(“stylesheet loaded”);
myText.styleSheet = myStyle;
// now load the xml
myContent.load(“news.xml”);
} else {
trace(“ERROR loading stylesheet”);
}
};
myStyle.load(“stylesheet.css”);
/starts everything off/
stop();

i just realised that the xml text file has to start and end with <body> tags for the CSS to work. how can i replace the <title><entry> tags?

I had another look at what i did last night, and im not convinced I have done this the best way…

I dont have a chance to check it right now but may get a chance later.

I have a feeling I may not need to escape characters when using <!CDATA[ ]]>

either that or I dont need to use <!CDATA[ ]]> as I have escaped (ie. url encoded characters)

not sure though…will check again later.

Problems arose when I tryed to use html tags with the above code I showed you.

truth is I only use xml for text that needs columns and use normal .txt like the original CMS does whenever I need html styling.

would be good to figure out how to do all of this with xml.
more soon…

:angry:

http://www.asparagusproductions.com/cms/xml/xml_cms_with_css.zip 296kb/.zip

Here’s what I have so far. I’ve messed around with the lot and renamed stuff. I think it’s the CMS_saver.php file that needs fiddling with to remove the <title><entry> tags and replace them with <body> tags.

At this point, it’s working, just without CSS.

And if any genious can figure out how to intergrate it with a Rich Text Editor, then we may just have something quite snazzy.

I load css much like Treaktor does. ie… ensure css is loaded then load/set text. Strange that it doesnt work for you.

im presuming you have a style named ‘body’

if you are doing something like this that is…

if this is the case. Change the names in the php file to suit. Change ‘title’ or ‘entry’ to ‘body’. Make sure you do it for both the opening and closing tags

eg:

<?
$myFileName=$_POST["myFileName"]; 
$title=$_POST["title"]; 
$article=$_POST["article"];

if(ereg("/","$myFileName") || ereg('.php',"$myFileName")) 
die("Thou shall not hack!");  

$xml_output = "<?xml version=\"1.0\"?>
\r";
$xml_output .= "<entries>
";

/*
$xml_output .= "	<title><![CDATA[" . $title . "]]>
";
$xml_output .= "	</title>
";
*/
$xml_output .= "	<body><![CDATA[" . $title . "]]>
";
$xml_output .= "	</body>
";



$xml_output .= "	<entry><![CDATA[" . $article . "]]>
";
$xml_output .= "	</entry>
";
$xml_output .= "</entries>";

$fp = fopen ("$myFileName", "w+");
fwrite($fp,$xml_output); 
//fwrite($fp,"$article"); 
fclose($fp); 

if ($fp) { 
echo ("&msg=Save Successful!&name=$name&myTextSave=$myTextSave");   
} else { 
echo ("&error=OK&msg=Save unsuccessful!...an error occurred!"); 
} 
 
?> 

Im giving up on this particular flash example. I want a text editor like this kirupa one (as it seems you do too). Something with bold, italics, links, colour and size at least.
Im gonna try downloading a free php forum and figure out how to extract what i need.

I’ll let you know how I get on
:vamp:

had a wee look at a rich text editor which i now know is called a WYSIWYG editor.

pretty fine really. found a few here http://www.htmlarea.com

Ive been pulling apart this one
http://www.unverse.net/whizzywig-cross-browser-html-editor.html

it likes to change <b> tags to <strong> and changes <font color> tags to inline styles but so far it seems pretty easy to change it to suit flash.

have yourself a looky
:bandit: