On Wed, 31 Oct 2001 03:10:31 +0100
"Tarjei Huse" <[EMAIL PROTECTED]> wrote:
> Hi David and everyone else
> > mgd_register_filter($name, [$function])
> >
> > - if $name and $function are not empty, it will register the function $function
>with the filter name $name
> > - if $function is present but empty (""), it will unregister the function
>associated with the filter name $name
> > - if only the $name parameter is present, it will return the name of the
>registered function with that filter name.
>
> Hmm. And the uses for such a function is being able to return an object without
> making one?
No, it's just meant to extend the &(var:formatter); syntax, with mgd_register_filter,
you can add your own formatters.
Note that the function $function doesn't return any value.
> It seems like a nifty function, I would just like to get an idea on where to use
> it :)
Another example:
this is the code-init or code-global element:
<?
function udf_news($topicid) {
$i = 3;
if($topicid && $al=mgd_list_topic_articles($topicid)) {
while(--$i && $al->fetch()) {
echo "<h3>$al->title</h3>\n";
echo "<p>$al->abstract</h3>\n";
}
}
}
function udf_edito($topicid) {
$topic = mgd_get_topic($topicid);
echo "<h1>$topic->description</h1>\n";
echo "<p>$topic->extra</p>\n";
}
mgd_register_filter("news", "udf_news");
mgd_register_filter("edito", "udf_edito");
$tid = $argv[0];
?>
Now this is the page or style content:
<table>
<tr>
<td>&(tid:xedito);</td>
<td>&(tid:xnews);</td>
<tr>
</table>
this example displays a table with two columns, the left one displaying the topic
description and extra, the right one displaying the 3 first articles in that topic.
See how easy it is for an html designer to make up the page layout without having to
care about the code needed to fetch and display.
Now as an exercise, I let you find the code needed to do the same the old way ;)
David
> Tarjei
>
>
> > Example of use:
> > <?
> > function my_news_filter($obj) {
> > echo "<h1>$obj->title</h1>\n";
> > echo "<p>$obj->abstract</p>\n";
> > echo "<p>$obj->content</p>\n";
> > }
> >
> > mgd_register_function("article", "my_news_filter"); // registers the filter func
> >
> > $article = mgd_get_article($argv[0]);
> >
> > ?>&(article:xnews);<? // the x prefix is necessary to identify the filter name
> >
> > echo mgd_register_filter("article"); // prints "my_news_filter"
> >
> > mgd_register_filter("article", ""); // unregisters the filter func
> >
> > echo mgd_register_filter("article"); // prints nothing
> > ?>
> >
> > Of course, this is a simple one, and instead of passing the article object, you
>can pass any PHP variable, provided the filter function is able to understand its
>parameter.
> >
> > Hope that helps,
> >
> > David
> >
> > > Tarjei
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]