Hi,
> On Thu, 27 Jan 2000, Ken Pooley wrote:
> > section of a host and call it from elsewhere...which I think I can't
> > do...
>
> Not yet but yet another fine idea for 2.0. So many projects, so little
> time...
>
And if you can't wait, Jean-Pierre and I have made a little function you can
put in the code-global, and that allows you to load a library located in the
topic tree.
It is definitely more efficient than the one I have posted a week ago (or
was it two weeks ?), and I didn't have time yet to put it in the Hints &
Tips, so I post it here.
It defines the function mgd_load_library(string $path_to_lib), where
$path_to_lib is the topic path to the library you want to load.
The code in the library may be put into the $topic->code, and you can define
the LIBRARY_ROOT constant to any topic in the DB.
It call recursively any sub-topic from the one you want to load, and
maintain a cache to speed up subsequent calls.
With this function, you can then share bits of code or variables like
$my_mail="[EMAIL PROTECTED]" between all of your hosts on the same DB.
hope this helps, comment appreciated...
> emile
regards,
[EMAIL PROTECTED]
below is the code:
<?
define("LIBRARY_ROOT",54);
function mgd_load_library($path="/")
{
static $libs;
$libs[0]["loaded"]=0;
$libs[0]["cached"]=0;
if($path[0]!="/")
$path="/".$path;
if(isSet($libs[$path]["loaded"])) return;
if(!isSet($libs[$path]["cached"]))
{
$split_path=explode("/",$path);
$topic=mgd_get_topic(LIBRARY_ROOT);
for($i=($path[0]=="/"?1:0),$subpath="";$i<count($split_path) &&
!empty($split_path[$i]);$i++)
{
$subpath.="/".$split_path[$i];
if(!isSet($libs[$subpath]["cached"]))
{
$topic=mgd_get_topic_by_name($topic->id,$split_path[$i]);
$libs[$subpath]["cached"]=$topic->id;
}
else
{
$topic->id=$libs[$subpath]["cached"];
$topic->name="";
}
}
$id=$topic->id;
}
else
$id=$libs[$path]["cached"];
if(!isset($topic) || empty($topic->name))
$topic=mgd_get_topic($id);
?>&(topic.code:p);<?
$libs[$path]["loaded"]=$id;
$topics=mgd_list_topics($id);
if(substr($path,-1)!="/") // if($path!="/")
$path.="/";
while($topics && $topics->fetch())
mgd_load_library($path.$topics->name);
}
?>
--
This is The Midgard Project's mailing list. For more information,
please visit the project's web site at http://www.midgard-project.org
To unsubscribe the list, send an empty email message to address
[EMAIL PROTECTED]