News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

SSI Topic and Replies

Started by tyty1234, April 06, 2007, 07:35:13 AM

Previous topic - Next topic

tyty1234

SSI Topics and Replies

Original Author: Daniel15
Currently Developed by: tyty1234
Current Version: 2.0
Compatible With: SMF 2.0

Download



Summary
This mod adds a new SSI function that allows you to grab a topic and its replies.

Usage
Basic usage:
<?php ssi_topic(int $topicint $num_replies); ?>

$topic - The topic id for the topic you want to grab.
$num_replies - The number of replies you would like to show (provides a "more replies" link if there are more comments than the amount you limit).

Please visit the tytyweb.net for advanced usage.

Installation
This mod should be installed using the Package Manager. No manual edits should be necessary, but if it comes to that resort, please use the Package Parser.

Changelog
What's new in this version?
Released for SMF 2.0
Dropped SMF 1.1.x compatibility.
Full re-write of mod.
Ability to grab attachments, and use of negative offsets in $start variable to get last # of replies.
Replaced page index with a "more replies" link (customizable).
My Activity: Inactive
My Links: tyty1234's SMF Site | SMF Package Parser | SMF Helper | My Mods [5]
Subscribe to my SMF blog for updates
PMs for support will not be accepted, unless requested otherwise.

samozin

thanx man let  understand some
u  know that  ssi function
<?php ssi_boardNews(); ?>
grabs the topics  and number  on comment on the topics  only from the frist section in the  frist catigory  that was aproblem to me ...
so that  mod  u gave to.. gonna  grab all  new  topics from all over the catigories of the whole  forum or what ?

Daniel15

Quoteso that  mod  u gave to.. gonna  grab all  new  topics from all over the catigories of the whole  forum or what ?
No, this mod just grabs one topic and all of its replies.

Quoteu  know that  ssi function
<?php ssi_boardNews(); ?>
grabs the topics  and number  on comment on the topics  only from the frist section in the  frist catigory  that was aproblem to me ...
You can get the topics from another board with ssi_boardNews(), just pass it the board ID. On your forum index, if you go into the board, the URL will look a bit like:
index.php?board=2
The 2 is the board number. Then, you use the ssi_boardNews function like this:

<?php ssi_boardNews(2); ?>
Daniel15, former Customisation team member, resigned due to lack of time. I still love everyone here :D.
Go to smfshop.com for SMFshop support, do NOT email or PM me!

samozin

 thanx my hero
listen  in the package-info.xml  u didnt  type any thing about the  smf versions  that mod should  be in installed with ..

i tried to u use ur  mod  but  the forum  gave me the error that says  that pakage doesnt fit the forum  version
my forum is
SMF 1.1.2
now what ?....  i  dont like to  install mods  manually....  plz   tell me  that it is ur fault and ur gonna fix  it  

Daniel15

Sorry about that, my computer seems to make corrupted ZIP files. I've uploaded a new package that should work. Please download it and tell me if it works for you :).

Quotelisten  in the package-info.xml  u didnt  type any thing about the  smf versions  that mod should  be in installed with
Yeah, I don't usually do that, as this should work for all current SMF versions
Daniel15, former Customisation team member, resigned due to lack of time. I still love everyone here :D.
Go to smfshop.com for SMFshop support, do NOT email or PM me!

samozin

 yah  i can install it  with no errors now  but
i still confused about how to use  it
can u show an example for dummies like me  :P
  u  know  eglish is not my 1st language  and many ppl in this  site dont speak english too
 
  hey do me afav  plzzz  add this code in ur   mod
its actually atranslation for ur  mode  in to arabic


Quote
      <file name="$languagedir/Modifications.arabic.php">
      <operation>
         <search position="after"><![CDATA[?>]]></search>
         <add><![CDATA[
// --- Begin modification - SSI Topic and Replies ---
$txt['ssiTopic_no_id'] = 'ssi_topic(): من فضلك اختار رقم الموضوع';
$txt['ssiTopic_notfound'] = 'الملف اذزى تحاول العثور عليه غير موجود او لايمكنك الحصول عليه';
$txt['ssiTopic_replies'] = 'الردود';
$txt['ssiTopic_reply'] = 'اضافة رد';
// --- End modification ---
]]></add>
      </operation>
   </file>



now u  know why  ian calling my self dummy  

Daniel15

Quoteyah  i can install it  with no errors now  but
i still confused about how to use  it
Basically, you pass the function a topic ID, and it returns that topic, and the replies for it. You'd use this if you want to get a topic on your own PHP page.
A simple example can be seen on the ssi_examples.php page (yoursite.com/forum/ssi_examples.php).

And thanks for the translation; I'll add it soon :)
Daniel15, former Customisation team member, resigned due to lack of time. I still love everyone here :D.
Go to smfshop.com for SMFshop support, do NOT email or PM me!

Gambi

Cool mod! I've put it in but I was wondering how the best way of intergrating this with the board news would be? I'm a novice when it comes to this but instead of clicking the news link which takes you to the actual forum topic, could it take you to another page on your site utilizing this mod? I'm sure it can be done, just wouldn't know where to start. Thanks in advance!

Also, I liked the page function and I was wondering how I could get that on my news page also? I tested it manually with the news and it works but when I tried to add it to the SSI.php page nothing would show up.

// The last post? Let's put the page numbers
if ($news['is_last'])
echo '
', $return['pageindex'];
else
echo '
<hr style="margin: 2ex 0;" width="100%" />';


Cheers!

Daniel15

QuoteCool mod! I've put it in but I was wondering how the best way of intergrating this with the board news would be? I'm a novice when it comes to this but instead of clicking the news link which takes you to the actual forum topic, could it take you to another page on your site utilizing this mod?
Alright, let's see :)
The page you want the news on, put something like this:

<?php
// Require SSI
require('SSI.php');

// Some variables. Change these if you like :)
$board 1// Board to use
$number 10// Number of items to return
$length 300// Return this number of characters, followed by "...".

// Get the news
$news_items ssi_boardNews($board$numbernull$length'array'); // board, number of items, item to start at, number of characters, output method
// Loop through all items
foreach ($news_items as $news)
{
// Output this item
echo '
<div>
<a href="viewnews.php?topic='
$news['id'], '">'$news['icon'], ' <b>'$news['subject'], '</b></a>
<div class="smaller">'
$news['time'], ' by '$news['poster']['link'], '</div>

<div class="post" style="padding: 2ex 0;">'
$news['body'], '</div>

'
$news['link'], $news['locked'] ? '' ' | ' $news['comment_link'], '
</div>'
;

// If it isn't the last item, output a <hr />
if (!$news['is_last'])
echo '
<hr style="margin: 2ex 0;" width="100%" />'
;
}
?>



The most important things are:
1) The "array" return method is used (so we can customise the output)
2) Instead of linking to the topic page (that's $news['href']), we link to a file called "viewnews.php"

Now, in viewnews.php, add something like:

<?php
// Require SSI
require('SSI.php');

// No topic? That's bad
if (empty($_REQUEST['topic']))
die('No topic passed');

// Get this topic and its replies
$return ssi_topic($_REQUEST['topic'], nullnull'array'); // Setting something to 'null' will use the default value.

// Output the first post
echo '
<div>
<a href="'
$return['href'], '">'$return['icon'], '<b>'$return['subject'], '</b></a>
<div class="smaller">'
$return['time'], ' by '$return['poster']['link'], '</div>

<div class="post" style="padding: 2ex 0;">'
$return['body'], '</div>

'
$return['locked'] ? '' $return['comment_link'], '<br /><br />
</div>

<h2>'
$txt['ssiTopic_replies'], ':</h2>
'
$return['pageindex'];

// Loop through each post
foreach ($return['replies'] as $post)
{
echo '
<div>
<a href="'
$post['href'], '">'$post['icon'], ' <b>'$post['subject'], '</b></a>
<div class="smaller">'
$txt['ssiTopic_reply'], ' '$post['number'], ': '$post['time'], ' by '$post['poster']['link'], '</div>

<div class="post" style="padding: 2ex 0;">'
$post['body'], '</div>
</div>'
;

// The last post? Let's put the page numbers
if ($post['is_last'])
echo '
'
$return['pageindex'];
else
echo '
<hr style="margin: 2ex 0;" width="100%" />'
;

?>


I've used the "array" return type because this allows you to customise the output however you want :). If you want it to only show replies (and not the topic itself), remove the bit that outputs the topic (the // Output the first post bit).

QuoteAlso, I liked the page function and I was wondering how I could get that on my news page also?
Ah, that's SMF in-built page number thingy :D.
constructPageIndex is responsible for doing that. In this mod, the line that gets all the page numbers is:

'pageindex' => constructPageIndex('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?start=%d', $start, $row['numReplies'], $num_replies, true),

Basically, you pass the base URL (with %d to tell it where the number should go), the position to start at, the number of total replies, and the number of replies per page, and it returns a nicely formatted list of page numbers.

I wish I knew about constructPageIndex() sooner - I only discovered it recently. Before that, I spent time writing my own page number functions to duplicate SMF's ones :P :o.

If you need any help adding the page numbers to something, please feel free to ask :)
Daniel15, former Customisation team member, resigned due to lack of time. I still love everyone here :D.
Go to smfshop.com for SMFshop support, do NOT email or PM me!

Gambi

#9
Hi, thanks my site is looking ace now! I didn't seem to understand how to add the page index on my main site to go through the pages of news. Also, the page index on the replies only links to one thread ID.


/ !!! Better way to do this?
'pageindex' => constructPageIndex('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?page=viewnews&topic=2026&start=%d', $start, $row['numReplies'], $num_replies, true),

'replies' => array(),


I tried changing 2026 to ', $news['id'], ' but I just got an error:

Warning: Division by zero in /home/content/B/l/a/Blackthorne519/html/forum/Sources/Subs.php on line 766

Warning: Division by zero in /home/content/B/l/a/Blackthorne519/html/forum/Sources/Subs.php on line 766

Warning: Division by zero in /home/content/B/l/a/Blackthorne519/html/forum/Sources/Subs.php on line 771

Warning: Division by zero in /home/content/B/l/a/Blackthorne519/html/forum/Sources/Subs.php on line 776

Warning: Division by zero in /home/content/B/l/a/Blackthorne519/html/forum/Sources/Subs.php on line 781

Warning: Division by zero in /home/content/B/l/a/Blackthorne519/html/forum/Sources/Subs.php on line 781


So apart from the scuffle with the pages, everything else is looking great! If you need any information I can send you some of my pages through PM?

EDIT Nevermind, I fixed the problem with the replies page. I just still can't get anything on my home page.

mkress

#10
hello!

i think there should be an if-clause for the output of
<h2>', $txt['ssiTopic_replies'], ':</h2>
', $return['pageindex'];


when no reply exists...

Edit: i think there is also a bug:
if i set $num_replies to 0 i get following error:
Warning: Division by zero in \Sources\Subs.php on line 773

Warning: Division by zero in \Sources\Subs.php on line 773

Warning: Division by zero in Sources\Subs.php on line 778

Warning: Division by zero in \Sources\Subs.php on line 783

Warning: Division by zero in \Sources\Subs.php on line 788

Warning: Division by zero in \Sources\Subs.php on line 788

TestMonkey

#11
Hey Daniel, as usual great minds think alike.
I Have a similar mod released here
If you want to adopt any of the code or features of my mod let me know I don't mind if you use any of my code/ideas.
Sounds like both our mods are headed in similar directions mine doesn't show replies tho which is deffinately a nice feature if that can turned on or off.

Anyway ill check back soon let me know what you're thoughts are maybe could just merge into one project that you or I (or both) maintain..
Doesn't matter who maintains the code to me really just as long as a project similar to our mods is kept alive for future versions of SMF.
Knowledge is power
www.serverhash.com

Vandaahl

Why doesn't this mod support attachments? Is that too hard to implement?

Daniel15

Yeah, the replies thing is a known bug... It does not check if you do not want the replies (number of replies = 0). I'll modify it in the future (when I get some spare time).

Quote from: Vandaahl on May 27, 2007, 08:52:50 AM
Why doesn't this mod support attachments? Is that too hard to implement?
This is only the first beta version, and only has basic functionality at the moment. I'll work on it more when I have more spare time (all my stuff is done in my spare time, which is very limited at the moment).
Daniel15, former Customisation team member, resigned due to lack of time. I still love everyone here :D.
Go to smfshop.com for SMFshop support, do NOT email or PM me!

Vandaahl

Quote from: Daniel15 link=topic=162958.msg1107539#msg1107539
Quote from: Vandaahl on May 27, 2007, 08:52:50 AM
Why doesn't this mod support attachments? Is that too hard to implement?
This is only the first beta version, and only has basic functionality at the moment. I'll work on it more when I have more spare time (all my stuff is done in my spare time, which is very limited at the moment).

Alright, keep up the good work ;)

TestMonkey

#15
Quote
Yeah, the replies thing is a known bug... It does not check if you do not want the replies (number of replies = 0). I'll modify it in the future (when I get some spare time).

Good to hear, would you think about adding support for an "extra" variable possibly?

My mod which is similar to this I use a spare value $link as an extra for anything additional I may want to do, it adds alot more flexibility to the array results..
It could be used for anything you're own array of values to be used in the output or whatever.
You could add in limit/length/link/other this way passed thru the extra value, to limit the results if you wanted to show a headline only and a readmore link as an example, then link to the full thing with replies and everything.

That's the main thing I would wish in you're mod if that's a possiblity =)

It may be benifitial if you wanted to keep developing our mods seperately, you never responded to that..
Not sure you're thoughts there..
My Ideal orgiastic combination of mods would possibly be:
ssi_boardNews to grab everything in a specific forum in an array, output links to see the specific stories which links  over to either of our mods.
Using either of our mods(or both), the results could just be a larger headline or like the first page or something whatever, then have it go thru displaying limited output for a while untill you reach the end at which point it would hit the end and display replies/comments etc..
Or actually possibly display replies/comments beneath the main post the whole time just limit it's output for headline/fullstory etc..
All thru that one extra field and some well thought out array usage etc.

That would basically generate links(boardNews) and have them link to content(either of our mods) in an extremely automatic and customizable fashion fairly easilly.
Knowledge is power
www.serverhash.com

Daniel15

Sorry TestMonkey, I didn't have time to read your full post :-[. I'll read over it again when I have more spare time ;)
Daniel15, former Customisation team member, resigned due to lack of time. I still love everyone here :D.
Go to smfshop.com for SMFshop support, do NOT email or PM me!

8105

Does this allow you to reply to a topic without being redirected to the forum?

Daniel15

QuoteMy mod which is similar to this I use a spare value $link as an extra for anything additional I may want to do, it adds alot more flexibility to the array results..
So, what would $link actually do?

QuoteIt may be benifitial if you wanted to keep developing our mods seperately, you never responded to that..
Not sure you're thoughts there..
I'm not sure what to do, actually (I didn't know about yours until you told me about it).

QuoteThat would basically generate links(boardNews) and have them link to content(either of our mods) in an extremely automatic and customizable fashion fairly easilly.
Have you seen my SMFBlog mod? It's kinda the same idea as what you're describing, except designed as a blog.

Quote from: 8105 on June 02, 2007, 01:23:31 AM
Does this allow you to reply to a topic without being redirected to the forum?
No, not at the moment. This mod is a SSI function for when you want to get a topic and its replies, to use it in some code. To see more about SMF's SSI functions, see ssi_examples.php in your SMF installation.
Daniel15, former Customisation team member, resigned due to lack of time. I still love everyone here :D.
Go to smfshop.com for SMFshop support, do NOT email or PM me!

TestMonkey

The $link value i pass a url usually you can see a basic example how I use it here:
http://www.irconcepts.net/article_example.phps
which produces:
http://www.irconcepts.net/article_example.php

More or less I just use it for anything extra, in this instance to pass a URL.. But it could be any data really or an array/multi demisnional array.. anything really could be used here a more proper name would be $extra or something honestly.


In reference to you're blog mod no I have not looked at the code itself.

Basically im trying to keep things as simple as possible, mods like these allow me to have full control over how I tie everything in as far as content goes, like using small tools/mods like boardnews and a mod like mine or yours etc. allows someone like me to have more control over the main pages of sites I run.

If you would contact me thru any of the means in my profile sometime may help us both out some in regards to these mods.

Knowledge is power
www.serverhash.com

Advertisement: