4.13 Topic Content Retrieval Webservice: offset
This webservice differs from the previous one in the sense that
you can define an offset mode to add retrieval pagination
-
idforum : ID of the forum where the topic is located
-
idcat : ID of the category where the topic is located
-
idtopic : ID of the topic to be listed
-
tri : retrieval order, 0 = Ascending order, 1 = Descending
order
-
offset : number of the first reply retrieved
-
limit : maximum number of messages to be retrieved.
$param = array(
'idforum' => 1,
'idcat' => 22,
'idtopic' => 48,
'tri' => 0,
'offset' => 0,
'limit' => 10
);
$results = $sel->call('read_topic', $param);
This webservice returns several parameters:
-
topictitle : topic title
-
nbanswer : number of replies for the topic
-
messages : XML feed that contains the messages to be
retrieved. This XML feed is composed of:
<topic>
<reponse id="ID of the reply">
<auteur>Author of the repy</auteur>
<date>Date and time of the message</date>
<message><!--[CDATA[Content of the message]]--></message>
</reponse>
</topic>
Example :
<topic>
<reponse id="108">
<auteur>Zorro</auteur>
<date>02-01-2007 à 14:05:56</date>
<message><!--[CDATA[I am adding a reply just to play around.]]--></message>
</reponse>
<reponse id="109">
<auteur>Zorro</auteur>
<date>03-01-2007 à 11:04:50</date>
<message><!--[CDATA[Answer okey]]--></message>
</reponse>
<reponse id="110">
<auteur>EchoCedric</auteur>
<date>03-01-2007 à 11:05:36</date>
<message><!--[CDATA[This is a test reply]]--></message>
</reponse>
</topic>
We provide an example of topic reading management via the
webservice which can be used on a website to include comments on the
articles.
<?php
require('nusoap/nusoap.php');
// tests parameters
$idsite= 1;
$urlnameforum= 'forumdev';
$url_forum= 'http://forumdev.mydiscussions.net/';
$url_webservice= 'http://forumdev.mydiscussions.net/webservices/wservice.php';
$idcat= 22;
$idtopic= 48;
$tri= 0; // 0 = ascending order, 1 => descending order
$reponse_par_page= 5;
if (isset($_GET['idtopic'])) {
$idtopic= intval($_GET['idtopic']);
}
if (isset($_GET['page'])) {
$page= intval($_GET['page']);
} else {
$page= 1;
}
$offset= (($page-1)*$reponse_par_page)+1;
$sel = new soapclient($url_webservice);
$param = array('idforum' => $idsite,'idcat' => $idcat,'idtopic' => $idtopic,'tri' => $tri, 'offset' => $offset,'limit' => $reponse_par_page);
$results = $sel->call('read_topic_page', $param);
$sujet_titre= $results['topictitle'];
?>
<h1><?php echo $sujet_titre; ?></h1>
<p>Ici se trouve mon site.</p>
<?php
$nbrep= $results['nbanswer'];
echo $nbrep,' messages<hr />';
$nbpage= ceil(($nbrep)/$reponse_par_page); // Calculate the number of pages
echo 'Pages :';
for ($i=1;$i<=$nbpage;$i++) {
if ($i == $page) {
echo ' ',$i,' ';
} else {
echo ' <a href="?idtopic='.$idtopic.'&page='.$i.'">',$i,'</a> ';
}
}
echo '</hr>';
if ($nbrep == 0) { // if the number of replies is equal to 0, we display a different message.
echo "<a href=\"$url_forum/message.php?config=$urlnameforum.inc&cat=$idcat&post=$idtopic&page=$page\">Be the first to leave a comment</a>";
} else {
echo "<a href=\"$url_forum/message.php?config=$urlnameforum.inc&cat=$idcat&post=$idtopic&page=$page\">Leave a comment</a>";
}
echo '<hr />';
$xml_get = simplexml_load_string(utf8_encode($results['messages']));
if ($xml_get) {
foreach ($xml_get->reponse as $reponse) {
$auteur= $reponse->auteur;
$date= $reponse->date;
$contenu= $reponse->message;
echo '<blockquote>';
echo utf8_decode($auteur),' - ',utf8_decode($date),'<br />';
echo '-------<br />';
echo utf8_decode($contenu);
echo '</blockquote>';
echo '<hr />';
}
}
?>