Simple script
Posted on 2005-04-13 14:58:04 EEST.
OK, Midgard has new release. 1.7alpha1.
I wonder what can I do with new code and with new objects and methods ;)
First , I am lazy right now to use my favourite browser , so I will use simple plain PHP file and write some simple code.
Consider the fact that I run this php script as root. I may use it to setup Midgard database or even manage this database and even virtual hosts without any need to request web pages.
And some style features.
Change virtual host configuration and force midgard apache module to act like old module without caching facilities.
Let's say we have three (different ones) styles with "navi" style element, and we want get one of them during request time.
We need to use mgd_preparse function as Apache module serve page and style elements with this function.
I wonder what can I do with new code and with new objects and methods ;)
First , I am lazy right now to use my favourite browser , so I will use simple plain PHP file and write some simple code.
<?php
mgd_config_init("amerigard");
/*
* I do initialize midgard internals from 'amerigard' file , which is located
* in /etc/midgard/conf.d/amerigard file in my case
*/
mgd_auth_midgard("admin", "password");
/*
* Note that I did not use third parameter.
* Do I need cookie? In plain text?
* Midgard does not send cookie anymore.
*/
$host = new NewMidgardHost();
/*
* Notice 'New' in class name.
* New midgard types can not overwrite old ones.
*/
$host->name = "localhost";
$host->find();
/* I want to get only host objects which has localhost as name */
while ($host && $host->fetch())
{
print "Host 'localhost' with id $host->id\n";
$oldhost = mgd_get_host($host->id);
$style = new NewMidgardStyle();
$style->get_by_id($oldhost->style);
/*
* Every old object may used as new object
* and every new object may used as old one.
*/
print "This host uses $style->name style \n\n";
}
?>
And the output:
Host 'localhost' with id 1
This host uses Aegir_Master_Style style
Host 'localhost' with id 2
This host uses Empty style
Consider the fact that I run this php script as root. I may use it to setup Midgard database or even manage this database and even virtual hosts without any need to request web pages.
And some style features.
Change virtual host configuration and force midgard apache module to act like old module without caching facilities.
Let's say we have three (different ones) styles with "navi" style element, and we want get one of them during request time.
We need to use mgd_preparse function as Apache module serve page and style elements with this function.
<?php
$current_style = $page->style;
$style_a = 1;
$style_b = 2;
$style_element = "navi";
/*
* Current requested page uses style with id=3.
*/
eval('?>'.mgd_preparse(mgd_template($style_element).'<?php '));
mgd_set_style($style_a);
eval('?>'.mgd_preparse(mgd_template($style_element).'<?php '));
mgd_set_style($style_b);
eval('?>'.mgd_preparse(mgd_template($style_element).'<?php '));
/* Set style to initial value */Every mgd_set_style call forces midgard to "reload" internal style elements storage and gets all style elemements which has style field set to style id used as function parameter. This is not flexible as it should be right now , as this may be used only with "old" midgard apache module. Anyway we are closer now to ability to set midgard internals from other levels.
mgd_set_style($current_style);
/* Do more */
?>