Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: myaicons on January 27, 2008, 03:15:56 PM

Title: SSI to show the most popular topic from a specified board ?
Post by: myaicons on January 27, 2008, 03:15:56 PM

is it possible to have an SSI to show the most popular topic from a specified board?

either based on posts or views...

... i know there is the Top Topics SSI

Top Topics by View Function: <?php ssi_topTopicsViews(); ?>
which lists the links to the topics

but instead... something that shows the whole message... not just the message link...


thanks in advance! 


P.S. and a random topic from a specific board?


Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on January 29, 2008, 10:03:10 PM
so... is this question too easy to spend time answering? or too hard to answer?   :)
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: jamesk on January 29, 2008, 10:27:45 PM
Is it possible -- yes.  With the default SSI.php -- I don't think so.

Is it easy or hard?  Depends on who you ask...  :P

I haven't tried and/or verified but...
If you're not a MySQL person, the easy way is to use the existing ssi_topTopics() to get the $topics['id'] and once you have the topic IDs, you can retrieve the message body by following this thread (bottom half):

http://www.simplemachines.org/community/index.php?topic=214231.msg1377171#msg1377171

If you ARE a MySQL and/or database person, then you can write a query from scratch...

Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on January 29, 2008, 11:00:14 PM
Quote from: jamesk on January 29, 2008, 10:27:45 PM<br />Is it possible -- yes.  With the default SSI.php -- I don't think so.  Is it easy or hard?  Depends on who you ask...

ahhh... a brave one ! yay... so am i asking the right person? lol

nope... not a database person...
i prefer the easy route of modifying the ssi call...

i wouldnt imagine it wouldnt be too far from the ssi_topTopics()
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on January 30, 2008, 05:29:00 PM
I will take a stab at it....

This will require you to make 2 changes in the SSI.php file, however, it should not change any part of the original output of SSI.php functions. 

What you are wanting is for the ssi_topTopics(); function to add a request in the database query for the body field from the messages table.

In the original 1.1.4 SSI.php file, in the ssi_topTopics(); function,
find around line 536:
SELECT m.subject, m.ID_TOPIC, t.numViews, t.numReplies
replace with:
SELECT m.subject, m.ID_TOPIC, t.numViews, t.numReplies, m.body

OK... the body field should be available to get the data.  Now we need to put it in the $topics variable....

Around line 551 find:
'id' => $row['ID_TOPIC'],
replace with:

'id' => $row['ID_TOPIC'],
'body' => $row['body'],


Now you should be able to use $output_method = 'array' and call the body field.
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on January 30, 2008, 06:27:10 PM
sounds like that would make sense...  :)

but i guess i didnt clarify from my previous post that i want the body from the top topics by view or by reply

<?php ssi_topTopicsViews(); ?>

or

<?php ssi_topTopicsReplies(); ?>


would it work the same way if i added your code to those functions?


the ssi would look like this:  ??

Quote<?php ssi_topTopicsReplies($num_recent = 1, $exclude_boards = array(1,2,3), $output_method = 'm.body' ); ?>

(if i exluded a few boards)


Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on January 30, 2008, 06:35:55 PM
please reread my post above....  you did not understand it very well....

To help you out a little....  there are only 2 ways to output....  by 'array' or by 'echo'
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on January 30, 2008, 06:51:31 PM
actually... its because i literally do not  understand it...  :-[

im very new and still learning to php and all this coding...


(im on chapter 2 of teach yourself php in 10 mins) lol

Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on January 30, 2008, 06:58:59 PM
Here is a sample using the output method 'array' :

$array = ssi_boardNews($board = $newsboard, $limit = 5, $start = null, $length = 500, $output_method = 'array');

     

if (empty($array))

   echo _NOTOPICSPOSTED;



foreach ($array as $news)

{

echo '

<div style="width:100%" class="option">

        ', $news['icon'], '&nbsp;<strong>', $news['subject'], '</strong><br />

<span style="font-size:x-small">Posted On:&nbsp;&nbsp;', $news['time'], '</span><br />

<span class="option">', $news['body'],' <a href="', $news['href'], '">', _READMORE ,'</a></span></div><br />

<span style="font-size:smaller">', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], ' |

<a href="forum/index.php?action=post;board=', $newsboard ,'">', _POSTNEWSARTICLE ,'</a></span><br /><br />';



if (!$news['is_last'])

echo '<hr style="width:50%;text-align:left; margin: 0 auto 0 auto" /><br />';



}
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on January 30, 2008, 07:09:19 PM
yikes... completely lost now...


<?php ssi_topTopicsReplies($output_method= 'array'); ?>
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on January 30, 2008, 07:30:42 PM
yes....  then you can make something similar to the example I posted.  You will need to see what fields are available in the ssi_toptopics...
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on January 30, 2008, 08:23:20 PM
i keep getting a database error  :(
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on January 30, 2008, 08:27:52 PM
keep testing.....

and when you post a reply, please copy/paste the error here.
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on January 30, 2008, 08:39:21 PM
this is the error i get everytime:

Database Error
Please try again. If you come back to this error screen, report the error to an administrator. 
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on January 30, 2008, 08:45:43 PM
do you have:

require_once("path_to/SSI.php");

at the top of your page?

and if so, is the path correct?
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on January 30, 2008, 09:08:13 PM
yup...
that i know i have right

<?php require('./forum/SSI.php'); ?>

its the rest that is not quite right i think
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on January 30, 2008, 09:17:14 PM
hmmmm....  can you post your page code here?

also, is your ssi function inside the <?  ?>   ???
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on January 30, 2008, 09:32:40 PM


<?php

$array 
ssi_topTopicsReplies($output_method 'array');

     


if (empty(
$array))

   echo 
_NOTOPICSPOSTED;



foreach ($array as $topics)

{

echo '

<div style="width:100%" class="option">

        '
$topics['icon'], '&nbsp;<strong>'$topic['subject'], '</strong><br />

<span style="font-size:x-small">Posted On:&nbsp;&nbsp;'
,$topic['time'], '</span><br />

<span class="option">'
$topic['body'],' <a href="'$topic['href'], '">'_READMORE ,'</a></span></div><br />

<span style="font-size:smaller">'
$topics['link'], $topic['locked'] ? '' ' | ' $topic['comment_link'], ' | 


if (!$topic['
is_last'])

echo '
<hr style="width:50%;text-align:left; margin: 0 auto 0 auto" /><br />';



} ?>



Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on January 30, 2008, 09:49:05 PM
you need to put this line immediately after <?php

require_once("path_to/SSI.php");

replace "path_to" with the actual path to your SSI.php file.
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on January 30, 2008, 09:50:33 PM
i actually have this right above it


<?php require('./forum/SSI.php'); ?>
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on January 30, 2008, 10:00:36 PM
try this:


<?php
require('./forum/SSI.php');
$array ssi_topTopicsReplies($output_method 'array');

if (empty(
$array))

   echo 
'No topic posted';

foreach (
$array as $topics)

{
echo 
'

<div style="width:100%" class="option">

        '
$topics['icon'], '&nbsp;<strong>'$topics['subject'], '</strong><br />


<span style="font-size:x-small">Posted On:&nbsp;&nbsp;'
,$topics['time'], '</span><br />
<span class="option">'
$topics['body'],' <a href="'$topics['href'], '">Read more...</a></span></div><br />


<span style="font-size:smaller">'
$topics['link'], $topics['locked'] ? '' ' | ' $topics['comment_link'], ' | 


if (!$topics['
is_last'])

echo '
<hr style="width:50%;text-align:left; margin: 0 auto 0 auto" /><br />;

?>


and save it as a php file extention page, for example:  text.php

---you had some variables named $topic instead of $topics
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on February 01, 2008, 08:35:55 PM
i got this error now:


Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/content/html/toptopicpost.php on line 27

line 27:
if (!$topics['is_last'])
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on February 01, 2008, 08:45:26 PM
I guess I did not look at your code closely enough... sorry.

You need to replace this line:
<span style="font-size:smaller">', $topics['link'], $topics['locked'] ? '' : ' | ' . $topics['comment_link'], ' |

with maybe this:

<span style="font-size:smaller">', $topics['link'], $topics['locked'] ? '' : ' | ' . $topics['comment_link'], ' </span>';
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on February 01, 2008, 08:49:13 PM
um... now this:


Parse error: parse error, unexpected $ in /home/content/html/toptopicpost.php on line 31
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on February 01, 2008, 08:57:44 PM
Can you please copy/paste the file here?

thanks
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on February 01, 2008, 08:58:48 PM



<?php
require('./sforum/SSI.php');
$array ssi_topTopicsReplies($output_method 'array');

if (empty(
$array))

   echo 
'No topic posted';

foreach (
$array as $topics)

{
echo 
'

<div style="width:100%" class="option">

        '
$topics['icon'], '&nbsp;<strong>'$topics['subject'], '</strong><br />


<span style="font-size:x-small">Posted On:&nbsp;&nbsp;'
,$topics['time'], '</span><br />
<span class="option">'
$topics['body'],' <a href="'$topics['href'], '">Read more...</a></span></div><br />


<span style="font-size:smaller">'
$topics['link'], $topics['locked'] ? '' ' | ' $topics['comment_link'], ' </span>';


if (!
$topics['is_last'])

echo 
'<hr style="width:50%;text-align:left; margin: 0 auto 0 auto" /><br />;

} ?>




i appreciate all the help  :)
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on February 01, 2008, 09:16:28 PM
see if this works:

<?php
require('./sforum/SSI.php');
$array ssi_topTopicsReplies($output_method 'array');
if (empty(
$array))
   echo 
'No topic posted';
   echo 
'
<table class="ssi_table">'
;
foreach ($array as $topics)
echo '
<tr>
<td align="left">
'
$topics['link'], '
</td>
<td>'
$topics['body'], '</td>
</tr>'
;
echo '
</table>'
;

?>

Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on February 01, 2008, 09:26:53 PM
that just gave me another :

Database Error
Please try again. If you come back to this error screen, report the error to an administrator


i think the previous code was more on the right track
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on February 01, 2008, 09:39:53 PM
Firstly, let's get one that is working, then modify it from there.  I looked over the SSI.php file, and the $num_topics variable was left out before.

Try this one:

<?php
require('./sforum/SSI.php');
$array ssi_topTopicsReplies($num_topics 10$output_method 'array');
if (empty(
$array))
   echo 
'No topic posted';
   echo 
'
<table class="ssi_table">'
;
foreach (
$array as $topics)
echo 
'
<tr>
<td align="left" valign="top">
'
$topics['link'], '
</td>
<td valign="top">'
$topics['body'], '</td>
</tr>'
;
echo 
'
</table>'
;

?>

It works for my local install.

I just added the valign so both lines would start at the top of the table cell.
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on February 01, 2008, 09:56:47 PM
woo hoo!

that did it!!! :)

but i tried to add

$exclude_boards = array(1,2,3,4,5)

to exclude some boards from the results but that didnt work

Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on February 01, 2008, 10:04:25 PM
In the SSI.php file, around line 542 find:

AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "

replace with:
AND b.ID_BOARD != $modSettings[recycle_board]" : ''
AND ID_BOARD != array(1,2,3,4,5)) . "


Try that....  I have not tested it, but it may work.
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on February 01, 2008, 10:18:03 PM
nope... that didnt do anything...

i also tried modifying the actual ssi call (just in case i want to repeat it with different boards) but that didnt work for me either


<?php
require('./sforum/SSI.php');
$array ssi_topTopicsReplies($num_topics 1$output_method 'array'$exclude_boards = array(1,2,3,4,5,6));
if (empty(
$array))
   echo 
'No topic posted';
   echo 
'
<table class="ssi_table">'
;
foreach (
$array as $topics)
echo 
'
<tr>
<td align="left" valign="top">
'
$topics['link'], '
<br>
<br>'
$topics['body'], '</td>
</tr>'
;
echo 
'
</table>'
;

?>


either through exclusion or inclusion of boards?  whichever works....


secondly, the icon, date, poster, and comments wont work for it either.... im trying to make it look as close to the board news output as much as possible 

$topics['icon'], $topics['comment_link'], etc...
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on February 02, 2008, 01:21:41 PM
Ok... now you are asking more than that ssi function does.

If you are wanting these kinds of outputs, you will probably need to create your own MySQL query and write the outputs from that, thus bypassing SSI.php functions.

Quotesecondly, the icon, date, poster, and comments wont work for it either.... im trying to make it look as close to the board news output as much as possible

$topics['icon'], $topics['comment_link'], etc...

Those do not work because that ssi function does not "draw out" those variables or database inputs.

Determine what you are fully wanting, then create the query that will supply the needed variables.
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on February 02, 2008, 01:54:57 PM
that is what i feared  :(

i guess those are not necessary... but thanks for all the help!  :D

...all except for the specified board(s) to pull the popular topic from...
would be nice to have...
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: spottedhog on February 02, 2008, 02:48:45 PM
don't fear it....  try things....

I would highly recommend downloading this software below.  You can make your own computer a webserver and test out code.  If you have Windoz, you can make a USB thumb drive a webserver, and then test out your code.

http://www.apachefriends.org/en/xampp.html (http://www.apachefriends.org/en/xampp.html)

Personally, I have Kubuntu Linux installed on my dual-boot laptop, so I am able to start up my local webserver from the hard drive and test out all things related to html, php, and mysql.

All that you need to know to make the query you want is contained inside that SSI.php file.  It is just a matter of determining what you want, create the MySQL query for it, and then putting your output into an array.  I know it sounds a bit hard, but I know all you need to know for working examples are in the SSI.php file.

If/when you can write your own query and display the results, you then have a great working knowledge of SMF and other php/mysql applications.

Maybe someone will volunteer to write it for you....  who knows.
Title: Re: SSI to show the most popular topic from a specified board ?
Post by: myaicons on February 02, 2008, 03:31:57 PM
thanks! :)

im slowly getting there lol