View previous topic :: View next topic |
Author |
Message |
chrisale
Joined: 09 Nov 2005 Posts: 187
|
Posted: Wed Feb 15, 2006 4:02 pm Post subject: PHP or other server-side scripting support |
|
|
I'd be super-uber-cool if wview could generate PHP files (which would make the most sense, wview exists mainly in Linux/Unix and PHP is included by default on most of those systems with Apache).
I'm thinking of this so that people could add custom content based on data *both* directly from wview and also stuff archived in the database. This would give the webpages wview generates a nearly limitless amount of flexibility!
I have some really cool applications in mind for the data that wview generates... things like user-defineable "views" of data.. for a user defineable period of time.. etc. People more comfortable with PHP could also use PHPs' built in graphics manipulation abilities to generate graphs and dials and whatnot to augment what's there without messing up wview proper.
Thanks!
Chris
Last edited by chrisale on Thu Feb 16, 2006 10:12 am; edited 1 time in total |
|
Back to top |
|
|
bhnb
Joined: 28 Nov 2005 Posts: 127
|
Posted: Wed Feb 15, 2006 4:41 pm Post subject: |
|
|
Hi Chris
I might be getting the wrong end of the stick as I've never done any PHP coding, but I think this should already be do-able.
If the MySQL instance hosting wviewDB is accessible from your webserver, that gives you the archive data. Everything else is available in parameterlist.htm, so as long as PHP can parse a text file you should have everything you need. Or not?
Cheers
Jon
p.s. I'm presently doing some perl which I think will produce similar stuff to what you're doing, but from the wview server end. If the template feature Mark talked about in the other thread comes together people should have a huge range of features to choose from. |
|
Back to top |
|
|
chrisale
Joined: 09 Nov 2005 Posts: 187
|
Posted: Wed Feb 15, 2006 4:52 pm Post subject: |
|
|
"If the MySQL instance hosting wviewDB is accessible from your webserver, that gives you the archive data."
Yes, people would have this ability, but you wouldn't be able to add to/modify current pages as they are generated... unless you somehow used PHP to parse the html files and then generate 2nd files, which seems kinda redundant and potentially very very slow.
"Everything else is available in parameterlist.htm, so as long as PHP can parse a text file you should have everything you need. Or not? "
I think you're thinking on the wrong end of things. PHP is a web-scripting language... it works with Apache so if someone goes to "index.php" it would look, to the browser, exactly the same as if it went to "index.htm"... but on the server side, you can use PHP to create applications within those webpages.
To say it another way... PHP would be able to read the parameterlist.htm file, but it doesn't "output" a file, like a perl or bash script... it's "output" occurs when someone accesses the file through a webbrowser/Apache... so there would be no way for php to give a file back to wview. |
|
Back to top |
|
|
chrisale
Joined: 09 Nov 2005 Posts: 187
|
Posted: Wed Feb 15, 2006 5:00 pm Post subject: |
|
|
I mean..I could just ignore what wview outputs in terms of HTML completely and just create my own PHP application that uses nothing but the data archived from mySQL... but then I'd be recreating the wheel in many ways... so I'd like to be able to use the html that wview generates, and simply augment it by adding php code to the templates.
All that needs to happen is for wview to parse a ".phx" and spit out a ".php" file on the other end. |
|
Back to top |
|
|
bhnb
Joined: 28 Nov 2005 Posts: 127
|
Posted: Wed Feb 15, 2006 6:10 pm Post subject: |
|
|
Hi Chris
I'm familiar with web-scripting in general, just not php in particular. I do quite a bit of dynamic web page creation using sh and perl (my scripts tend to live in /cgi-bin and start their output with 'Content-Type:' )
I wasn't suggesting that you parse html files, or that anything is fed back to wview, I just couldn't understand why a server-side script would need to be uploaded every few minutes. With some server-side languages this should be actively discouraged as there's an element of compilation the first time the server sees a new/changed object.
As for re-inventing the wheel, I think the more the merrier in terms of templates/themes/skins.
Cheers
Jon |
|
Back to top |
|
|
bhnb
Joined: 28 Nov 2005 Posts: 127
|
Posted: Wed Feb 15, 2006 6:11 pm Post subject: |
|
|
Apart from all that, I do see what you mean about phx->php... |
|
Back to top |
|
|
chrisale
Joined: 09 Nov 2005 Posts: 187
|
Posted: Wed Feb 15, 2006 10:18 pm Post subject: |
|
|
" I just couldn't understand why a server-side script would need to be uploaded every few minutes."
Oh i totally agree
That's just a function of wview and wanting to use the just-in-time data that it provides and building a webapp on top of that. |
|
Back to top |
|
|
bhnb
Joined: 28 Nov 2005 Posts: 127
|
Posted: Thu Feb 16, 2006 3:28 pm Post subject: |
|
|
Chris
This is slightly off-topic, but I've had a bit of a look at PHP today and I think XML might be the way to go. Have a look at http://www.scorpiocomputing.com/weather/metric/test3.php - it's simple and ugly but demonstrates what info is available.
To do this, I ran this script to generate an xml template:
Code: | #!/bin/sh
INFILE=/etc/wview/html/parameterlist.txt
OUTFILE=/etc/wview/html/parameterlist.xtx
if [ -f $OUTFILE ]
then
echo moving $OUTFILE to $OUTFILE.1
mv $OUTFILE $OUTFILE.old
fi
awk 'BEGIN { print "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";
print "<wviewdata>"; }
{ if ( (substr( $1,1,1) != "#" ) && ( substr($0,1,1) == "<" ) ) {
split($0,a,"-");
print "<param>";
print "<item>" a[3] "</item><value><!--" a[3] "--></value>";
print "</param>";
} } END { print "</wviewdata>"}' $INFILE > $OUTFILE
|
Then added parameterlist.xtx to html-templates.conf
The php code looks like this:
Code: |
<?php
// the xml file we want to parse
$xmlSource="parameterlist.xml";
//First we define a number of variables to store the data from each element
$item="";
$value="";
$wvparams=array();
$currentElement=""; //holds the name of the current element
/* The start Element Handler
* This is where we store the element name, currently being parsed, in $currentElement.
* This is also where we get the attribute, if any.
*/
function startElement($parser,$name,$attr){
$GLOBALS['currentElement']=$name;
}//end startElement()
/*
* The end Element Handler
*/
function endElement($parser,$name){
$elements=array('item','value');
/*If the element being parsed is a param it means that the
*parser has completed parsing param. We can then store
* in our array $wvparams[ ]
*/
if(strcmp($name,"param")==0){
foreach($elements as $element){
$temp[$element]=$GLOBALS[$element];
}
}
$GLOBALS['wvparams'][]=$temp;
/*After parsing a parameter we reset the globals.*/
if(strcmp($name,"param")==0){
$GLOBALS['item']="";
$GLOBALS['value']="";
}
}//end endElement()
/* The character data Handler
* Depending on what the currentElement is,
* the handler assigns the value to the appropriate variable
*/
function characterData($parser, $data) {
$elements = array (
'item',
'value'
);
foreach ($elements as $element) {
if ($GLOBALS["currentElement"] == $element) {
$GLOBALS[$element] .= $data;
}
}
}
/* This is where the actual parsing is going on.
* parseFile() parses the xml document and return an array
* with the data we asked for.
*/
function parseFile(){
global $xmlSource,$wvparams;
/*Creating the xml parser*/
$xml_parser=xml_parser_create();
/*Register the handlers*/
xml_set_element_handler($xml_parser,"startElement","endElement");
xml_set_character_data_handler($xml_parser,"characterData");
/*Disables case-folding. Needed for this example*/
xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,false);
/*Open the xml file and feed it to the parser in 4k blocks*/
if(!($fp=fopen($xmlSource,"r"))){
die("Cannot open $xmlSource ");
}
while(($data=fread($fp,4096))){
if(!xml_parse($xml_parser,$data,feof($fp))){
die(sprintf("XML error at line %d column %d ",
xml_get_current_line_number($xml_parser),
xml_get_current_column_number($xml_parser)));
}
}
/*Finish ! we free the parser and returns the array*/
xml_parser_free($xml_parser);
return $wvparams;
}//end parseFile()
/**********************************************************************************************
Calling the parseFile() and getting the result out in a simple html-table
**********************************************************************************************/
$result=parseFile();
print '<table >';
foreach($result as $arr){
if ( $arr["item"] != "" ) {
print '<tr><td><b>'.$arr["item"].'</b></td><td>'.$arr["value"].'</td></tr>';
}
}
print '</table>';
?>
|
|
|
Back to top |
|
|
chrisale
Joined: 09 Nov 2005 Posts: 187
|
Posted: Thu Feb 16, 2006 9:09 pm Post subject: |
|
|
Hmm.. that's very cool, I've never used PHP to parse an XML file like that... I'll have to check it out more on the weekend when I have more time.
I'll get my php guru buddy to look at it too, I think he'll find it interesting...
Thanks for posting that!
Chris |
|
Back to top |
|
|
chrisale
Joined: 09 Nov 2005 Posts: 187
|
Posted: Sat Mar 04, 2006 7:50 pm Post subject: |
|
|
I've been rooting aroud in the code trying to figure out where you add the ability process different file types?
Could you point me in the direction of the files I need to fiddle with? I'd like to see if I can hack up some support for processing PHP and JS files. |
|
Back to top |
|
|
mteel
Joined: 30 Jun 2005 Posts: 435 Location: Collinsville, TX
|
Posted: Sun Mar 05, 2006 7:35 am Post subject: |
|
|
No need to - the next release of wview will support any file type template your heart desires - template extensions named "[ext]x" will be generated as "[ext]" - i.e., example.phpx will be generated as example.php and example.wmlx will be generated as example.wml.
Note that wview will replace only any tags defined in parameterlist.txt and leave all other html comments or script syntax alone.
Also, 7-day charts have been implemented...
Mark |
|
Back to top |
|
|
chrisale
Joined: 09 Nov 2005 Posts: 187
|
Posted: Sun Mar 05, 2006 2:29 pm Post subject: |
|
|
"Note that wview will replace only any tags defined in parameterlist.txt and leave all other html comments or script syntax alone. "
Bonus!!
Thank you very much... that's certainly more than I asked for... you'll be seeing the fruits of those labours hopefully soon! |
|
Back to top |
|
|
|