TinyPortal

Development => Support => Topic started by: Maddog452 on November 01, 2007, 07:16:14 AM

Title: Change to Recent Articles Snippet
Post by: Maddog452 on November 01, 2007, 07:16:14 AM
I am currently using the following SSI code in a PHP Box on my front page.
ssi_boardNews($board = 17.0 , $limit = 5, $start = null, $length = 300, $output_method = 'echo');

Unfortunately, this means that the board that this function points to needs to be open to guests.

Is it possible to have the block on the front page that offers an article from one board if a guest and then another board if they are members??  I was thinking something like:


if ($context['user']['is_guest'])
   ssi_boardNews($board = 17.0 , $limit = 5, $start = null, $length = 300, $output_method = 'echo')
else
    ssi_boardNews($board = 6.0 , $limit = 5, $start = null, $length = 300, $output_method = 'echo')


I know the above code wouldnt work (I'm dumb but not that dumb) plus the above function still would not work because the SSI function requires the target board to be accessable to guests

Cheers

Dog
Title: Re: Change to Recent Articles Snippet
Post by: jacortina on November 01, 2007, 01:37:56 PM
That general form would work, though it would have to be cleaned up some.

But is there a reason you even SHOW the block to guests. The point becomes moot, if you simply uncheck the box that enables Guests to see this block, doesn't it?

But if you want guests to see an alternate board, then:
global $$context;
if ($context['user']['is_guest']) {
   ssi_boardNews(17, 5, null, 300); }
else {
   ssi_boardNews(6, 5, null, 300); }


Should work fine IF guests are to be shown entries from board 17 and members are to be shown entries from board 6.
Title: Re: Change to Recent Articles Snippet
Post by: Maddog452 on November 01, 2007, 07:56:52 PM
Thanks for the code.

The issue from my side is that to use the "ssi_boardNews" function, the board needs to be accessible to guests.

Unfortunately a newspaper reporter quoted one of the Obituaries in our news section and then went on to "Quote inside sources", which make me look like I provided the datail from our members only forum.

How can I stop that?
Title: Re: Change to Recent Articles Snippet
Post by: jacortina on November 01, 2007, 08:11:50 PM
Let's make sure we're using the same terms here. A board is a section within the forum and you can make them (and the topics/posts within) inaccesible to guests. Were a guest to view a block which displayed the ssi_boardNews output, it would NOT include anything from boards which don't grant access to guests because of this bit of code in the function:

// Make sure guests can see this board.
$request = db_query("
SELECT ID_BOARD
FROM {$db_prefix}boards
WHERE " . ($board === null ? '' : "ID_BOARD = $board
AND ") . "FIND_IN_SET(-1, memberGroups)
LIMIT 1", __FILE__, __LINE__);
if (mysql_num_rows($request) == 0)
{
if ($output_method == 'echo')
die($txt['smf_news_error2']);
else
return array();
}


That's why you would supply a board # for guests which points to a publicly viewable board and different 'restricted to logged in members' board for those logged in.

So, you can give highly constrained access (to, say, one single board) to guests (and let them only READ that one at that). And guests will NOT be able to see anything more of your forum than that. They will certainly not be shown (by ssi functions) posts from boards to which they have no access.
Title: Re: Change to Recent Articles Snippet
Post by: Maddog452 on November 02, 2007, 08:10:56 AM
J.A.C

Thanks for taking the time to help me understand this.

Firstly my set up so far.  All boards are excessible by members and only one (#17) is accessible to guests (I will probably change that to just an article) once I work out how to do it.

I tried the first section of code:
global $$context;
if ($context['user']['is_guest']) {
   ssi_boardNews(17, 5, null, 300); }
else {
   ssi_boardNews(6, 5, null, 300); }


It works perfectly except when I actually log in and I get the following error message:

QuoteYou cannot specify a board that doesn't allow guests. Please check the board ID before trying again

Board #6 is my members news board and is set with all membergroups getting access but the Guest check box is unchecked - hence the error. Is there a way to modify the function or do I need to find the full function and post that into the function after the "else".

When people log in as guests they get the members only speil.

The second block of code - is that from the source code or should I insert that in the block with (or instead of) the first lot of code??

I can give you a login to have a look if you want.  PM me.

Cheers
Dog

Title: Re: Change to Recent Articles Snippet
Post by: jacortina on November 02, 2007, 03:09:35 PM
Sorry. Was simply not familiar with that aspect of the ssi_boardNews function.

That bit of code was just to illustrate some of the constraints the code puts on guests. In fact, that bit of code is actually the culprit in this case.

I would tend to say you should copy the necessary code into your block rather than modify the function. Otherwise, the next time you upgrade, the SSI.php will simply be overwritten and you'll encounter this problem again until you go and modify it again.

Without taking the time to pull apart the function to get rid of things you don't need but it has to allow for, simply copy the whole thing and comment out the name and the enclosing brackets. Directly assign the values that would have been passed in (or defaulted to). Then comment out the chunk that's causing the problem (and it's actually noted as the place where the code is to "// Make sure guests can see this board.").

You end up with this:

$board = 6;
$limit = 5;
$start = null;
$length = 300;
$output_method = 'echo';

// Show the latest news, with a template... by board.
// function ssi_boardNews($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
// {
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
global $func;

loadLanguage('Stats');

// Must be integers....
if ($limit === null)
$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
else
$limit = (int) $limit;

if ($start === null)
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
else
$start = (int) $start;

if ($board !== null)
$board = (int) $board;
elseif (isset($_GET['board']))
$board = (int) $_GET['board'];

if ($length === null)
$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
else
$length = (int) $length;

$limit = max(0, $limit);
$start = max(0, $start);

// // Make sure guests can see this board.
// $request = db_query("
// SELECT ID_BOARD
// FROM {$db_prefix}boards
// WHERE " . ($board === null ? '' : "ID_BOARD = $board
// AND ") . "FIND_IN_SET(-1, memberGroups)
// LIMIT 1", __FILE__, __LINE__);
// if (mysql_num_rows($request) == 0)
// {
// if ($output_method == 'echo')
// die($txt['smf_news_error2']);
// else
// return array();
// }
// list ($board) = mysql_fetch_row($request);
// mysql_free_result($request);

// Load the message icons - the usual suspects.
$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';

// Find the post ids.
$request = db_query("
SELECT ID_FIRST_MSG
FROM {$db_prefix}topics
WHERE ID_BOARD = $board
ORDER BY ID_FIRST_MSG DESC
LIMIT $start, $limit", __FILE__, __LINE__);
$posts = array();
while ($row = mysql_fetch_assoc($request))
$posts[] = $row['ID_FIRST_MSG'];
mysql_free_result($request);

if (empty($posts))
return array();

// Find the posts.
$request = db_query("
SELECT
m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, m.ID_MSG, t.locked
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE t.ID_FIRST_MSG IN (" . implode(', ', $posts) . ")
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_FIRST_MSG DESC
LIMIT " . count($posts), __FILE__, __LINE__);
$return = array();
while ($row = mysql_fetch_assoc($request))
{
// If we want to limit the length of the post.
if (!empty($length) && $func['strlen']($row['body']) > $length)
{
$row['body'] = $func['substr']($row['body'], 0, $length);

// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));

if ($cutoff !== false)
$row['body'] = $func['substr']($row['body'], 0, $cutoff);
$row['body'] .= '...';
}

$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);

// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

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

$return[] = array(
'id' => $row['ID_TOPIC'],
'message_id' => $row['ID_MSG'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $row['posterTime']),
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['numReplies'] . ' ' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_2']) . '</a>',
'replies' => $row['numReplies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'],
'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</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']
),
'locked' => !empty($row['locked']),
'is_last' => false
);
}
mysql_free_result($request);

if (empty($return))
return $return;

$return[count($return) - 1]['is_last'] = true;

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

foreach ($return as $news)
{
echo '
<div>
<a href="', $news['href'], '">', $news['icon'], '</a> <b>', $news['subject'], '</b>
<div class="smaller">', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '</div>

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

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

if (!$news['is_last'])
echo '
<hr style="margin: 2ex 0;" width="100%" />';
}
// }


Just paste that mass in where the "ssi_boardNews(6, 5, null, 300);" is (be careful to retain the closing curly bracket which follows on that line).
Title: Re: Change to Recent Articles Snippet
Post by: Maddog452 on November 02, 2007, 09:17:37 PM
Thanks for that.  That funxtion rocks.

The SSI function only shows the original post - the actual news.  How do I modify this one to show only the news??

Sorry about the constant stream of dumb questions.  I am struggling to follow the code.  The simple "If" statements are ok but after that, I get very confused. :uglystupid2:

Cheers
DM
Title: Re: Change to Recent Articles Snippet
Post by: Maddog452 on November 02, 2007, 09:22:16 PM
Disragard my last.  I does work.  My members did something I didn't notice.

Thanks

DM
Title: Re: Change to Recent Articles Snippet
Post by: jacortina on November 02, 2007, 09:25:52 PM
Good, because the way the code works, I'd be hard pressed to figure out how it was looking at anything but the first post in a topic.

Title: Re: Change to Recent Articles Snippet
Post by: Maddog452 on December 15, 2007, 04:40:45 AM
JAC

Sorry to pester after more than a month but is it possible to modify the second part of this to show more than one board (eg the 5 or 6 most recent posts from two or three boards).

Maybe inserting an Array??

I dunno.

Cheers
Dog
Title: Re: Change to Recent Articles Snippet
Post by: jacortina on December 16, 2007, 12:08:49 AM
Try this. On that very first line:
$board = 6;

Change it to:
$boards = array(6, 7, 8); // All the boards you want to include

Then find this line:
WHERE ID_BOARD = $board

And change it to:
WHERE ID_BOARD IN (" . implode(', ', $boards . ")

Change the value for $limit to change how many recent topics are shown.

This wil get the most recent topics from ANY of those boards. This does NOT get 5 or 6 (or however many) from EACH of those boards (you will get a TOTAL of $limit topics, but they will be the most recent when look at all of the boards given).
Title: Re: Change to Recent Articles Snippet
Post by: lebisol on December 16, 2007, 02:16:03 AM
try this snip: http://www.tinyportalmedia.com/main/index.php/topic,1246.new.html
Title: Re: Change to Recent Articles Snippet
Post by: Maddog452 on December 16, 2007, 07:24:20 AM
Lebisol

Quotetry this snip: http://www.tinyportalmedia.com/main/index.php/topic,1246.new.html
Will have a go with the stuff JAC has done for me.  It has some Membergroup issues attached to it but I do like the simplicity of it.
Thanks

J.A.C

Once again, increadible response time.  You rock!!.
QuoteThis wil get the most recent topics from ANY of those boards. This does NOT get 5 or 6 (or however many) from EACH of those boards (you will get a TOTAL of $limit topics, but they will be the most recent when look at all of the boards given).

That is exactly what I was after - Thanks again.  My site is nearing completion - I am now ready to rule the world  :uglystupid2: (Sorry - Did I type that out load)!

Cheers

DM

[EDIT]

I get an error -
QuoteParse error: syntax error, unexpected ';' in /home/the15537/public_html/forum/Sources/Load.php(1752) : eval()'d code(35) : eval()'d code on line 72
Title: Re: Change to Recent Articles Snippet
Post by: Dragooon on December 16, 2007, 07:32:27 AM
Quote from: Maddog452 on December 16, 2007, 07:24:20 AM
Lebisol

Quotetry this snip: http://www.tinyportalmedia.com/main/index.php/topic,1246.new.html
Will have a go with the stuff JAC has done for me.  It has some Membergroup issues attached to it but I do like the simplicity of it.
Thanks
Since i created it, what do you mean by some "MemberGroup issues"?

And about your error,
Replace the second part with WHERE ID_BOARD IN (" . implode(', ', $boards) . ")
Title: Re: Change to Recent Articles Snippet
Post by: Maddog452 on December 16, 2007, 08:10:49 AM
I meant that my site has membergroup issues!!.  I only want certain membergroups to see stuff.  I havent' tried your mod yet.  Sorry for the confusion

Dog

[EDIT]  Your correction did the trick - Its amazing how something so small will kill the entire lot!!

Thanks
JAC and Dragooon
Title: Re: Change to Recent Articles Snippet
Post by: Dragooon on December 16, 2007, 08:32:08 AM
No Problem, Glad I could help :)
Title: Re: Change to Recent Articles Snippet
Post by: lebisol on December 17, 2007, 03:30:43 AM
There you Maddog452 and again mainly postoing back to give Dragoon credit for his support of scripts, nice work as always!