Piotr Pokora wrote:
>
> Hi Alexander,
>
> Thanks for your help :))
> But now I just wonder how to generate correct link with:
> <? if ($topic) {
> function twalk($id) {
> if (!$id || !($t = mgd_get_topic($id))) return;
> twalk($t->up);
> printf('/ <a href="%d.html">%s</a> ', $t->id, htmlentities($t-
> >name));
> }
> twalk($topic);
> }
>
> if I use it like this and when I read some article, link is like this
> /topic/article/1.html
> when I look for topics link looks /topic/1.html (this is correct)
> I know I can use <a href="/really_topic_name_/%d> but I want to use
> this function for all topics.
> You know , I want page to look like this:
>
> history................
>
> menu | centent | something
>
Seems that it's better to provide you with working code :-)
On our LUG site (www.minsk-lug.net) we are using the following code to
display arbitrary topics and articles. The implications that we are
using mgd_get_topic_by_name and mgd_get_article_by_name for accessing
topics and articles.
If you'll place this code in page named 'foo' and make it active, then
it'll serve all topics/articles under your root topic (in code below it
marked as $mlug->RTopic) automatically. It works like active directory
and shows only sub-topics and articles under 'current' topic, i.e. if
you'll ask for 'foo/topic/' it'll display all sub-topics and articles
for 'topic', making links as 'sub-topic/' or 'article.html' (they are
relative and it means that browser will ask for 'foo/topic/sub-topic/'
or 'foo/topic/article.html' actually). Moreover, this script has no
limitations on depth of topic's tree.
Of course, you need to replace $images - path to images, $MLUG_prefix --
prefix of the site and other variables to get it working. $link argument
to article is used for displaying different icons before article name
(we have articles and links, the latter one is articles which describes
documents on other sites).
<?
if(ereg("^(.*)/(.*)|(.*\.html)$",$midgard->uri,$p)) {
$kpath=$p[1]."/";
}
$topic=mgd_get_topic($mlug->RTopic);
$max=(substr($midgard->uri,-5)==".html")?$argc-1:$argc;
for($i=0;$i<$max;$i++) {
if($topic) $topic=mgd_get_topic_by_name($topic->id,$argv[$i]);
}
if($topic) $ktopic=$topic; else unset($ktopic);
if(isset($karticle)) unset($karticle);
if(!empty($p[2]) && isset($ktopic)) {
$karticle=mgd_get_article_by_name($ktopic->id,$argv[$argc-1]);
}
// $ktopic now is set to last requested topic, $karticle - to requested
article, if any
function DisplayArticle($article, $full = true) {
global $mlug, $MLUG_prefix, $images, $midgard;;
$DisplayTypes = array( 0 => ":p", 1 => ":F", 2 => ":h");
$author = mgd_get_person($article->author);
$revisor = mgd_get_person($article->revisor);
?>
<p class="textright">[<span class="timestamp"><? echo
strftime("%d.%m.%Y", $article->created); ?></span>
/ &(author.name);]</p>
<h1>&(article.title);</h1>
<? if($article->type != 1) { ?>
<p>
<? }
$ArticleText =
"?>&(article.abstract".$DisplayTypes[$article->type].");\n&(article.content".$DisplayTypes[$article->type].");<?";
eval($ArticleText);
if($article->type != 1) { ?>
</p>
<? }
if($article->created != $article->revised) { ?>
<p class="textright">(Last revision: <? echo strftime("%d.%m.%Y",
$article->revised); ?>, &(revisor.name);)</p>
<? }
}
function DisplayTopic($topic, $link = false) {
global $mlug, $MLUG_prefix, $images, $midgard;
$DisplayTypes = array( 0 => ":p", 1 => ":F", 2 => ":h");
?><h1>&(topic.description);</h1>
<p>&(topic.extra:F);</p>
<br>
<? $t = mgd_list_topics($topic->id); ?>
<table border=0 cellspacing=0 cellpadding=0 width="550">
<? if($t) {
while($t->fetch()) {?>
<tr><td width=24 valign=top align=left><img src="&(images);folder.gif"
width=20 height=22 border=0></td>
<td valign=top align=left><a class="headerleft"
href="&(t.name);/">&(t.description);</a><br> </td></tr>
<? }
}
$article = mgd_list_topic_articles($topic->id,"reverse created");
if($article) { ?>
<? while($article->fetch()) { ?>
<tr><td width=24 valign=top align=left><img src="&(images);<? echo $link
? "link" : "text";?>.gif" width=20 height=22 border=0> </td>
<td valign=top align=left><a class="headerleft"
href="&(article.name);.html">&(article.title);</a></td>
<td valign=top align=right class="textright">[<span class="timestamp"><?
echo strftime("%d.%m.%Y", $article->revised>$article->created ?
$article->revised : $article->created); ?></span>]</td></tr>
<tr><td> </td><td colspan=2 valign=top
align=left><p>&(article.abstract:p);<br> </p></td></tr>
<?
}
}
?></table><?
}
// Actual page code that handles requests
if( $karticle) {
DisplayArticle($karticle, true);
} elseif ($ktopic) {
DisplayTopic($ktopic);
} else { ?>
<h1>Error</h1>
<p>The document you've requested does not exist in our data base.
Please check the source for this link, it is probably outdated.
</p>
<? }
?>
--
Alexander Bokovoy
Reality is bad enough, why should I tell the truth?
-- Patrick Sky
--
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]