Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: TestMonkey on April 01, 2007, 09:59:05 PM

Title: ssi_topicNews
Post by: TestMonkey on April 01, 2007, 09:59:05 PM
Link to Mod (http://custom.simplemachines.org/mods/index.php?mod=662)

Thank you for you're interest in ssi_topicNews Mod by James L. Moss aka: TestMonkey.

This Mod is an updated and packaged version of the function originally posted and created by sting in this thread:
http://www.simplemachines.org/community/index.php?topic=78532.0

This Mod Adds a function that allows you to get and display a specific topic as an single story or article.

Example usage:
    ssi_topicNews($topic, $limit = null, $start = null, $length = null, $link = null, $output_method = 'array');

Demo:
    http://www.irconcepts.net/article_example.php

Changelog:
ssi_topicNews v0.8
- Changed the parse_bbc call to point to ID_TOPIC instead of ID_MSG this fixes a forum error log msg.

ssi_topicNews v0.7
- Cleaned up and changed the default output to a cleaner div style layout and removed the hard coded font coloring.

ssi_topicNews v0.6
- Cleaned up the cutoff/length code so it works more correctly helping to keep the output correct and more predictable.
- Shifted the parse_bbcode call up some to insure any and all output is sent thru it.

ssi_topicNews v0.5
- Cleaned up code a bit, updated the $length/$cutoff code to work correctly like how ssi_BoardNews() is done currently.
- Added new option $link, which allows you to pass a url into the function which generates a "Read More..." link.

ssi_topicNews v0.4
- Install Scripts now use install.mod and uninstall.mod so the package now cleanly uninstal's the modification.

ssi_topicNews v0.3
- Cleaned up the package install scripts

ssi_topicNews v0.2
- Added $board = null; to the function to eleminate errors in the forum logs.
- Added code to turn $topic into an integer
- Added code to default to $topic 2 which is the default first post if $topic 0 or 1 was defined

ssi_topicNews v0.1
- First release

TODO List:
- Keep Optimising the code in ssi_topicNews();
- Add upgrade ability to the package for version 1.0 and higher

Notes:
1) $topic 0 or 1 can not be selected, It will default to 2 the default SMF first post..
2) If you get an parse error while trying to install the mod, go into:
    Packages -> Options, and Change all file permissions throughout the forum such that:: All files are writable.
    -OR-
    Manually chmod SSI.php to 666 or 777 through an ftp program.
    Now try to apply the modification again and it should work.
3) You need to play with the $length value some to get the desired short headline output.
4) If you use the $link variable it needs to point to the full story somewhere.

Contributors and other credits:
- Major credit to the SMF team for creating SMF & SSI.php especially for the functions we can use as a reference.
- Major credit to [Unknown] for all the hard work he's done and still does.
- Sting for the original code he posted here: http://www.simplemachines.org/community/index.php?topic=78532.0
- Credit to winrules for noticing and suggesting the font color change in v0.7

Keep in mind this mod is still being developed.
Understand it works fine now but will keep being improved apon check for updates.
Title: Re: ssi_topicNews
Post by: sifirforum.com on May 17, 2007, 01:44:07 PM
thank you... usefull mod.

i want to make a little modification.

i have day of history topics.

how can i change topic ID according to date (day+month)??

like this: http://sifirforum.com/test.php
Title: Re: ssi_topicNews
Post by: TestMonkey on May 27, 2007, 05:28:52 AM
Can you go into more detail what you are wanting to do, are you wanting to have the example script i provided generate topic IDs based off the current date?

Like say today is may 27th, are you wanting to find any/all topics created on "may 27th" and display them, basically putting together a daily listing of posts ?

I'm unclear on what you are wanting exactly, please take you're time and provide as much detail as possible in what you are requesting.
Title: Re: ssi_topicNews
Post by: Vandaahl on May 27, 2007, 08:37:40 AM
Does this mod also display attachments? I haven't figured out how to pull that of myself.
Title: Re: ssi_topicNews
Post by: TestMonkey on May 28, 2007, 12:48:47 PM
Not in the current release, that is a good catch but that raises some questions also..
Would we want guests/world to see attachments?
Or just allow logged in users, or just users of a specific group etc?

I'll work on adding the ability to see attachments tho in a new release within the next few weeks.
I may work on adding the ability to assign users/groups to a list that can see the attachments in a new seperate mod and add the functionality required into this mod so that they can work side by side.
I'll look thru the mods to see if a mod like the one im suggesting exists or not if one does i'll test it and add the functionality to my mod to work side by side with it.

Go ahead and post any idea's thoughts about this or anything else you can come up with.
Title: Re: ssi_topicNews
Post by: Vandaahl on May 29, 2007, 06:11:21 PM
Here's what I came up with for image attachments. It works, but it's very basic. May be a good starting point for you:


  //////////////////////////////
// Return a single post //
/////////////////////////////
function ssi_grabMessage($message_id = null, $output_method = 'echo')
{
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context, $attachments;
loadLanguage('Stats');

if ($message_id !== null) $message_id = (int) $message_id;
elseif (isset($_GET['ID_MSG'])) $message_id = (int) $_GET['ID_MSG'];
else die("Geen message id ingevoerd");

// This is needed for loadAttachmentContext()
include_once('Sources/Display.php');

// Fetch attachments.
if (!empty($modSettings['attachmentEnable']) && allowedTo('view_attachments'))
{
$request = db_query("
SELECT
a.ID_ATTACH, a.ID_MSG, a.filename, IFNULL(a.size, 0) AS filesize, a.downloads,
a.width, a.height" . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ",
IFNULL(thumb.ID_ATTACH, 0) AS ID_THUMB, thumb.width AS thumb_width, thumb.height AS thumb_height") . "
FROM {$db_prefix}attachments AS a" . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : "
LEFT JOIN {$db_prefix}attachments AS thumb ON (thumb.ID_ATTACH = a.ID_THUMB)") . "
WHERE a.ID_MSG = $message_id
AND a.attachmentType = 0", __FILE__, __LINE__);

$temp = array();
while ($row = mysql_fetch_assoc($request))
{
$temp[$row['ID_ATTACH']] = $row;

if (!isset($attachments[$row['ID_MSG']]))
$attachments[$row['ID_MSG']] = array();
}
mysql_free_result($request);

// This is better than sorting it with the query...
ksort($temp);

foreach ($temp as $row)
$attachments[$row['ID_MSG']][] = $row;
}

$request = db_query("
SELECT
m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName,
m.posterTime, m.ID_MSG, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, b.name
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}boards as b)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE m.ID_MSG = $message_id
AND m.ID_TOPIC = t.ID_TOPIC
AND t.ID_BOARD = b.ID_BOARD
AND FIND_IN_SET(-1, b.memberGroups)
", __FILE__, __LINE__);
$return = array();

if (mysql_num_rows($request) == 0) {
if ($output_method == 'echo') die($txt['smf_news_error2']);
else return;
}

$row = mysql_fetch_assoc($request);
$row['body'] = doUBBC($row['body'], $row['smileysEnabled']);

censorText($row['subject']);
censorText($row['body']);

$return[] = array(
'icon' => '<img src="' . $settings['images_url'] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" />',
'subject' => $row['subject'],
'time' => timeformat($row['posterTime']),
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#msg' . $row['ID_MSG'] . '">Read More...',
'new_comment' => '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.0">Reply</a>',
'poster' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'href' => !empty($row['ID_MEMBER']) ? $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] : '',
'link' => !empty($row['ID_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>' : $row['posterName']
),
'attachment' => loadAttachmentContext($row['ID_MSG']),
);
mysql_free_result($request);

if ($output_method != 'echo') return $return;

foreach ($return as $news) {
echo '
<table border="0" width="100%" align="center" class="smfNews">
<tr><td>', $news['icon'], ' <b>', $news['subject'], '</b><span class="smaller"><br />', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '<br /><br /></span></td></tr>
<tr><td>', $news['body'], '<br /><br /></td></tr>
<tr><td>';
foreach ($news['attachment'] as $attachedfile) {
echo '
<a href="', $attachedfile['href'] , '";image" id="link_', $attachedfile['id'], '" onclick="', $attachedfile['thumbnail']['javascript'], '"><img src="', $attachedfile['thumbnail']['href'] .'" id="thumb_', $attachment['id'], '"></a>';
}
echo '
</td></tr><tr><td>', $news['link'], ' | ', $news['new_comment'], '</td></tr>
</table>';
}

}
Title: Re: ssi_topicNews
Post by: TestMonkey on May 30, 2007, 12:51:01 AM
Thx man ill look this over and work on adding the attachment functionality in new releases of my code =)
Title: Re: ssi_topicNews
Post by: TestMonkey on June 04, 2007, 02:41:56 AM
Due to several other projects coming up this has been put on the backburner to a degree but I do plan on releasing an update soon so stay tuned.
Title: Re: ssi_topicNews
Post by: Vandaahl on June 04, 2007, 12:30:16 PM
Will it contain a decent attachment integration?
Title: Re: ssi_topicNews
Post by: TestMonkey on June 05, 2007, 02:22:28 AM
Quote from: Vandaahl on June 04, 2007, 12:30:16 PM
Will it contain a decent attachment integration?
Read above.
Title: Re: ssi_topicNews
Post by: Max22 on August 26, 2007, 12:31:59 PM
How to extend visualization to all topic?
Thx.
Title: Re: ssi_topicNews
Post by: TestMonkey on August 26, 2007, 10:35:46 PM
I'm no longer actively working on this mod, try:
http://custom.simplemachines.org/mods/index.php?mod=751

it should have everything you

My mod should still work fine for 1.3, but i'm not going to be releasing any updates to it as Daniel's mod should do everything mine does more or less.