I want my SSI news articles on my home page (http://www.murraysworld.com/) to have their own separate non-forum pages when clicked on, can someone please help with the code?
This is what Bloc said about my request:
Quote from: Bloc on March 16, 2009, 08:52:17 AM
For that to work you probably need to 1) fetch the info from 'News" using SSI and returned as an array, and 2) make your own links from that info(it would have the topic number in the array), and finally 3) let another SSI function fetch the actual post into your page.
None of these is possible from TP I am afraid, but you might be able to do it from your own pages, by the help of a mod that adds a SSI function fetching single post. I would get the SSI info on topic zzz into xx.php and make the links on xx.php point to yy.php?topic=zzz, then inside yy.php use that single-post SSI to show topicID=zzz.(first post will show then naturally)
I'm offering $20 for this.
Can a mod move this to the appropriate board now?
I hope you are using 1.1.8.
Firstly, install SSI Topic and Replies (http://custom.simplemachines.org/mods/index.php?mod=751) mod. Then create a file and include SSI.php at the top. Change url of your current news to the file you have created, passing the id of topic by url. In the file you created, fetch the topic info by ssi_topic() function using the id sent with url. Here is an example:
main.php
<?php
$ssi_layers = array('main');
$context['page_title'] = 'Main Page';
require(dirname(__FILE__) . '/SSI.php');
$news = ssi_boardNews(1, 5, 0, 250, 'array');
echo '
<table width="100%" class="tborder" cellspacing="0" cellpadding="4">
<tr>
<td class="catbg">News</td>
</tr>
<tr>
<td>';
foreach ($news as $topic)
{
echo '
<div>
', $topic['icon'], ' <a href="page.php?article=', $topic['id'], '"><strong>', $topic['subject'], '</strong></a>
<div class="smaller">', $topic['time'], ' ', $txt[525], ' ', $topic['poster']['link'], '</div>
<div class="post" style="padding: 2ex 0;">', $topic['body'], '</div>
</div>';
if (!$topic['is_last'])
echo '
<hr style="margin: 2ex 0;" width="100%" />';
}
echo '
</td>
</tr>
</table>';
?>
Pay attention to the URL here.
<a href="page.php?article=', $topic['id'], '">
It will be like http://forum.com/page.php?article={topic_id}
page.php
<?php
$ssi_layers = array('main');
$context['page_title'] = 'View Article';
require(dirname(__FILE__) . '/SSI.php');
$article_id = !empty($_REQUEST['article']) ? (int) $_REQUEST['article'] : 0;
if (empty($article_id))
fatal_error('No article selected!', false);
$article = ssi_topic($article_id, 5, 0, 'array');
if (empty($article))
fatal_error('Article does not exist!', false);
echo '
<table width="100%" class="tborder" cellspacing="0" cellpadding="4">
<tr>
<td class="catbg">News</td>
</tr>
<tr>
<td>
<div>
', $article['icon'], ' <a href="page.php?article=', $article['id'], '"><strong>', $article['subject'], '</strong></a>
<div class="smaller">', $article['time'], ' ', $txt[525], ' ', $article['poster']['link'], '</div>
<div class="post" style="padding: 2ex 0;">', $article['body'], '</div>
</div>';
if (!empty($article['replies']))
{
echo '
<p><strong>Comments</strong></p>
<hr />';
foreach ($article['replies'] as $comment)
echo '
<div class="windowbg2" style="padding: 5px; border: 1px solid #AAA;">
<span style="padding-bottom: 5px; border-bottom: 1px dashed;">Poster: ', $comment['poster']['link'], '</span>
<p>', $comment['body'], '</p>
</div>
<br />';
}
echo '
</td>
</tr>
</table>';
?>
It shows replies to topic as comments but you can remove the codes if you don't need them.
I hope it helps you. Feel free to ask questions if there is something unclear.
Thank you so much for your help, it works great! I encounted an issue with a blank page but fixed it by doing the following:
Replace:
require(dirname(__FILE__) . 'forum/SSI.php');
With:
require_once('forum/SSI.php');
And put that at the top of the pages before everything.
The only issue now is the pages don't have a title tag, can this be fixed?
Yeah, you should have change it to path to your SSI.php file. I suggest using the full path there though, that's better.
Is this issue solved then?
Edit.
Quote from: mark7144 on March 18, 2009, 09:30:20 AM
The only issue now is the pages don't have a title tag, can this be fixed?
They should have, unless you removed $context['page_title'] there.
In my header.php for all my pages it has:
<title><? echo $title ?></title>
So anyway I can still have a title tag?
If you set the $title for those pages too, you'll have the title. I can't help much about how and where to set it, without seeing the actual code though.
Does this help?
Header.php (included on all pages):
<?php
require_once('forum/SSI.php');
$context['aeva_safe_passage'] = true;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- Header -->
<head>
<title><? echo $title ?></title>
<meta name="description" content="<? echo $description ? $description : ''; ?>" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="andy murray, murray, andy, tennis, news" />
<meta http-equiv="content-language" content="en-gb" />
<meta name="robots" content="noodp" />
<link media="all" href="/mw.css?3" type="text/css" rel="stylesheet" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="alternate" type="application/rss+xml" href="http://feeds.feedburner.com/andy-murray-news" title="Andy Murray News via RSS" />
<? echo $can ?>
<script type="text/javascript" src="/mw.js"></script>
<noscript><link media="all" href="/noscript.css" type="text/css" rel="stylesheet" /></noscript>
</head>
<!-- /Header -->
<body>
<div id="main_container">
<div id="banner2"><div class="banner_text"><a class="banner_click" href="/"></a> <strong><?php date_default_timezone_set ("Europe/London"); echo(date("l, j F Y ")); ?></strong> | <a href="/forum/" class="banner_links">Forum</a> | <a href="/forum/news-12/?wap2" class="banner_links">Mobile</a> | <a href="http://feeds.feedburner.com/andy-murray-news" class="banner_links">RSS Feed</a> | <a href="http://www.facebook.com/pages/MurraysWorld/57207935961" class="banner_links">Facebook</a><br />
<form action="http://www.murraysworld.com/search-results.php" id="cse-search-box">
<input type="hidden" name="cof" value="FORID:11" />
<input type="hidden" name="cx" value="015912399745642733982:zef2tzke_fs" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="text" name="q" class="searchbox" value="Search News..." onFocus="if (value == 'Search News...') { value = ''; }" onBlur="if (value == '') { value = 'Search News...'; }" />
<input name="sa" value="Go" alt="Search" id="searchbutton" class="searchbutton" title="Search" type="submit">
</form>
</div><div></div></div>
<div id="wrapper_parent">
<? include ('poll/top.php'); ?>
Main.php
<?php
$ssi_layers = array('main');
$context['page_title'] = 'Main Page';
$news = ssi_boardNews(12
, 5, 0, 250, 'array');
echo '
<table width="100%" class="tborder" cellspacing="0" cellpadding="4">
<tr>
<td class="catbg">News</td>
</tr>
<tr>
<td>';
foreach ($news as $topic)
{
echo '
<div>
', $topic['icon'], ' <a href="page.php?article=', $topic['id'], '"><strong>', $topic['subject'], '</strong></a>
<div class="smaller">', $topic['time'], ' ', $txt[525], ' ', $topic['poster']['link'], '</div>
<div class="post" style="padding: 2ex 0;">', $topic['body'], '</div>
</div>';
if (!$topic['is_last'])
echo '
<hr style="margin: 2ex 0;" width="100%" />';
}
echo '
</td>
</tr>
</table>';
?>
Page.php
<? include('header.php'); ?>
<?php
$_GET['action'] = 'mw_front';
writeLog(true);
?>
<!-- News -->
<div id="newswrapper">
<?php
$ssi_layers = array('main');
$context['page_title'] = 'View Article';
$article_id = !empty($_REQUEST['article']) ? (int) $_REQUEST['article'] : 0;
if (empty($article_id))
fatal_error('No article selected!', false);
$article = ssi_topic($article_id, 5, 0, 'array');
if (empty($article))
fatal_error('Article does not exist!', false);
echo '
<table width="100%" class="tborder" cellspacing="0" cellpadding="4">
<tr>
<td class="catbg">News</td>
</tr>
<tr>
<td>
<div>
', $article['icon'], ' <a href="page.php?article=', $article['id'], '"><strong>', $article['subject'], '</strong></a>
<div class="smaller">', $article['time'], ' ', $txt[525], ' ', $article['poster']['link'], '</div>
<div class="post" style="padding: 2ex 0;">', $article['body'], '</div>
</div>';
if (!empty($article['replies']))
{
echo '
<p><strong>Comments</strong></p>
<hr />';
foreach ($article['replies'] as $comment)
echo '
<div class="windowbg2" style="padding: 5px; border: 1px solid #AAA;">
<span style="padding-bottom: 5px; border-bottom: 1px dashed;">Poster: ', $comment['poster']['link'], '</span>
<p>', $comment['body'], '</p>
</div>
<br />';
}
echo '
</td>
</tr>
</table>';
?>
<div align="right"><b><a href="http://www.murraysworld.com/forum/news-b12.0" rel="nofollow">older news » </a></b></div>
<br />
<div class="bottom_message">Welcome to the leading Andrew Murray website. This is the central resource for anything Andy Murray related. You can keep up to date with <a class="light" href="/andy-murray-ranking/">Andy Murray ranking</a> in the ATP <a class="light" href="/andy-murray-ranking/">here</a>. Fans often post up their <a class="light" href="/forum/murray-pictures-t412.0.html">Andy Murray pictures</a> taken from the latest ATP tournaments. And for the girls, you might be interested in some photos of <a class="light" href="/forum/andy-murray-message-board/andy-murray-shirtless/">Andy Murray shirtless</a> if you take a look around. Our biggest asset here is our <a class="light" href="/forum/index.php">Andy Murray forum</a>, the <a class="light" href="/forum/andy-murray-message-board/">Andy Murray message board</a> has the biggest community of Murray fans on the net. We realise many people find us from searching <a class="light" href="/andy-murray-girlfriend/">Andy Murray Girlfriend</a> and we would therefore recommend you read her profile <a class="light" href="/andy-murray-girlfriend/">here</a>.</div>
</div>
<!-- /News -->
<? include ('poll/top.php'); ?>
<? include('leftbar.php'); ?>
<? include('rightbar.php'); ?>
<? include('footer.php'); ?>
How do you set the title for your other pages?
Edit.
Try this.
<? $description = "Andy Murray tennis website with news, results, schedule, live scores, video, pictures and the largest Andy Murray message board.";?>
<? $title = 'Some title';
$description = "Andy Murray tennis website with news, results, schedule, live scores, video, pictures and the largest Andy Murray message board.";?>
Quote from: Tenma on March 18, 2009, 09:48:07 AM
How do you set the title for your other pages?
<? $title = "Example Title"; ?>
Check my post above. ;D
I know how to set my own titles but that is done manually at the top of each page. But for your nice hack, I need a bit of code to grab the title from the name of the article and dump it there automatically.
For example, I tried this but it failed:
<? $title = $article['subject'] ?>
Ah, sorry.
Find:
Quote<? include('header.php'); ?>
<?php
$_GET['action'] = 'mw_front';
writeLog(true);
?>
<!-- News -->
<div id="newswrapper">
<?php
$ssi_layers = array('main');
$context['page_title'] = 'View Article';
$article_id = !empty($_REQUEST['article']) ? (int) $_REQUEST['article'] : 0;
if (empty($article_id))
fatal_error('No article selected!', false);
$article = ssi_topic($article_id, 5, 0, 'array');
if (empty($article))
fatal_error('Article does not exist!', false);
echo '
<table width="100%" class="tborder" cellspacing="0" cellpadding="4">
Replace:
Quote<?php
require_once('forum/SSI.php');
$_GET['action'] = 'mw_front';
writeLog(true);
$ssi_layers = array('main');
$context['page_title'] = 'View Article';
$article_id = !empty($_REQUEST['article']) ? (int) $_REQUEST['article'] : 0;
if (empty($article_id))
fatal_error('No article selected!', false);
$article = ssi_topic($article_id, 5, 0, 'array');
if (empty($article))
fatal_error('Article does not exist!', false);
$title = $article['subject'];
include('header.php');
echo '
<div id="newswrapper">
<table width="100%" class="tborder" cellspacing="0" cellpadding="4">
Sorry again. For some reason, it stripped out some single quotes within code and php tags. I've put them inside quotes.
Fantastic, that worked!! Thanks :D
Now I just want to check with you...I assume getting SEO urls for these pages is on a different level and would be far too much work, right? I currently use PrettyURLs mod.
I have no idea about Pretty URLs, sorry. The best I can suggest is asking the author of the mod.
No probs, just wanted to check.
You have been incredible getting this working for me, thank you so much!
Oh sorry, one last thing. Is it possible to disable emoticons for the comments?
You'll have to modify the mod you've installed.
SSI.php
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
// Add this to our messages array
parsesmileys($row['body']);
$row['body'] = parse_bbc(strip_tags($row['body']), $row['smileysEnabled'], $row['ID_MSG']);
// Add this to our messages array
Thanks, that worked :)
If anyone can implement a 'Previous' and 'Next' type PHP page system into the above then I can pay, it's the final thing I need done.
To add pagination to ssi_boardNews() function.
SSI.php
// Find the posts.
global $boardurl;
$limit = count($posts);
$per_page = 2;
$start = !empty($_REQUEST['page']) ? (int) $_REQUEST['page'] : 0;
$page_index = constructPageIndex($boardurl . '/test.php?page=%d', $start, $limit, $per_page, true);
// Find the posts.
LIMIT ' . count($posts),
array(
'post_list' => $posts,
LIMIT {int:start}, {int:limit}',
array(
'post_list' => $posts,
'start' => $start,
'limit' => $per_page,
echo '
<hr style="margin: 2ex 0;" width="100%" />';
}
echo '
<hr style="margin: 2ex 0;" width="100%" />';
}
echo $page_index;
If you just want Previous/Next links, use this for $per_page variable.
$page_index = (!empty($start) && $start >= $per_page ? '<a href="' . $boardurl . '/test.php?page=' . ($start - $per_page) . '"><< Previous</a>' . ($start + $per_page < $limit ? ' | ' : '') : '') . ($start + $per_page < $limit ? '<a href="' . $boardurl . '/test.php?page=' . ($start + $per_page) . '">Next >></a>' : '');
Note that you should modify the url for $per_page variable to reflect your file, in both cases.
Thanks a lot :)
When I eventually move to SMF2 in the future, can the hacks you have done in this thread be easily modified to work with SMF2?
Actually, I forgot that it was SMF 1.1 you use and the last bits I gave was for SMF 2.0.
The mod I linked does not support SMF 2.0 and that was the reason why I hoped you had 1.1. But all codes I gave except the last post should work with both versions of SMF.
Sorry for not understanding.. so the actual hack of looking at an SSI article on a non-forum page will not work with SMF2?
Sorry, was in a hurry and made another typo. I've edited my post above.
This (http://custom.simplemachines.org/mods/index.php?mod=751) mod does not support SMF 2.0. Other codes I provided will work with both versions of SMF, but you still will be needing a few changes. So if you can find a similar mod or code your own query, you can easily achieve the same in SMF 2.0 version.
OK thanks, maybe when that times come I will offer money to an SMF coder to change what you have done to SMF2
Quote from: mark7144 on March 27, 2009, 11:50:29 AM
OK thanks, maybe when that times come I will offer money to an SMF coder to change what you have done to SMF2
hey after that can you share it with us!?
Sure but I haven't changed to SMF2 yet, could be a while.
Quote from: mark7144 on June 06, 2009, 04:16:21 PM
Sure but I haven't changed to SMF2 yet, could be a while.
OK, but I have write my own too! But may be it's not so comfortable to all off you( I'm not a good coder!)
Demo:
http://hocvui.net/html (http://hocvui.net/html)
If you want this code I can share for all of you!
Can someone help me fix this code a little... basically everything is fine but the comments that show below the news articles, they don't detect when a poster has used a line break. So everything is squashed together.
Does anyone know why the comments do not recognise line breaks?
Good example here, everything is just one big chunk of text when it should be broken up: http://www.murraysworld.com/news/article/14777/
So what code are you using now to get the comments?
More specifically, are you calling something to strip the BBcode/HTML from it before displaying it?
Code for commentsif (!empty($article['replies']))
{
echo '
<div align="center" style="margin-bottom: 11px;"><strong>' . $article['comment_link']. '</strong> | ' .$article['link'], '</div>
';
foreach ($article['replies'] as $comment)
echo '
<div class="news_comment">
', $comment['body'], '
<div class="date">'.$comment['time']. '<br />By ', $comment['poster']['name'], '</div>
</div>
<br />';
}
echo ' <div align="center"><strong>' . $article['comment_link']. '</strong> | ' .$article['link'], ' <br /><br />
Code for everything including news articles and comments
<?php
require_once('forum/SSI.php');
$context['aeva_safe_passage'] = true;
$ssi_layers = array('main');
$context['page_title'] = 'View Article';
$article_id = !empty($_REQUEST['article']) ? (int) $_REQUEST['article'] : 0;
if (empty($article_id))
fatal_error('No article selected!', false);
$article = ssi_topic($article_id, 10, 0, 'array');
if (empty($article))
fatal_error('Article does not exist!', false);
$string = $article['poster']['name'];
$patterns[0] = "/(Joe)/";
$patterns[1] = "/(Clydey)/";
$patterns[2] = "/(Sir Panda)/";
$patterns[3] = "/(Allan)/";
$patterns[4] = "[MurraysWorld|Mark]";
$patterns[5] = "/(ljsmall)/";
$patterns[6] = "/(boogers)/";
$replacements[0] = "Joe Bailey";
$replacements[1] = "James MacDonald";
$replacements[2] = "Andrew Hunter";
$replacements[3] = "Allan Hendry";
$replacements[4] = "Mark Sanger";
$replacements[5] = "Lorna Small";
$replacements[6] = "Phil Messenger";
$article['poster']['name'] = preg_replace($patterns, $replacements, $string);
$string2 = $article['body'];
$patterns2[0] = "#<span class=\"more_intro\"><a href=\"javascript:void\(0\)\" class=\"more\" onclick=\"dsp\(this\)\">(.*?)</a></span>#i";
$patterns2[1] = "#<div class=\"more_content\">(.*?)</div>#i";
$patterns2[2] = "#<div class=\"more_intro\"></div>#i";
$patterns2[3] = "#<div class=\"more_intro\">Read more \(([a-z0-9\s]+)\):</div>#i";
$patterns2[4] = "#<div class=\"more_intro\">In other news:(.*?)</div>#i";
$patterns2[5] = "#\(1 image\)#i";
$patterns2[6] = "#\(1 video\)#i";
$patterns2[7] = "#\(1 audio\)#i";
//$patterns2[6] = "#<div class=\"more_intro\">(.*?)\(1 video\):</div>#i";
//$patterns2[7] = "#<div class=\"more_intro\">(.*?)\(1 audio\):</div>#i";
$patterns2[8] = "# :#i";
$replacements2[0] = "<div class=\"more_intro\">$1:</div>";
$replacements2[1] = "$1";
$replacements2[2] = "";
$replacements2[3] = "";
$replacements2[4] = "<span class=\"other_news\">In other news:</span>";
$replacements2[5] = "";
$replacements2[6] = "";
$replacements2[7] = "";
$replacements2[8] = ":";
$article['body'] = preg_replace($patterns2, $replacements2, $string2);
// #WORKING# $article['body'] = preg_replace('#<div class=\"more_intro\">(.*?)\(1 video\):</div>#i', 'Multimedia:', $article['body']);
$article['subject'] = preg_replace('/(Murray)/', 'Andy Murray', $article['subject']);
$title = $article['subject'];
include('header.php');
echo '
<div id="newswrapper">
<div class="news_body_full">
<h1>', $article['subject'], '</h1>
<div class="date">'.$article['time']. ' | By '.$article['poster']['name'], '</div>
', $article['body'], '
</div>';
if (!empty($article['replies']))
{
echo '
<div align="center" style="margin-bottom: 11px;"><strong>' . $article['comment_link']. '</strong> | ' .$article['link'], '</div>
';
foreach ($article['replies'] as $comment)
echo '
<div class="news_comment">
', $comment['body'], '
<div class="date">'.$comment['time']. '<br />By ', $comment['poster']['name'], '</div>
</div>
<br />';
}
echo ' <div align="center"><strong>' . $article['comment_link']. '</strong> | ' .$article['link'], ' <br /><br /><script type="text/javascript" src="http://w.sharethis.com/button/sharethis.js#tabs=web%2Cpost%2Cemail&charset=utf-8&style=default&publisher=cad2263b-c893-46da-9c2b-239b2e40aad4"></script><br /><br /></div>
';
?>
</div>
<!-- /News -->
<? include ('footer_includes.php'); ?>
Hmm.
ssi_topic is not a standard SMF SSI function. Please can you post that function too?
// --- Begin modification - SSI Topic and Replies ---
// Grab posts from a certain topic
function ssi_topic($topic = null, $num_replies = null, $start = null, $output_method = 'echo')
{
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
global $func, $memberContext;
loadLanguage('Stats');
// Topic variable set?
if ($topic !== null)
// Yes, let's use it (integer, please)
$topic = (int) $topic;
// No? What about a GET variable?
elseif (isset($_GET['topic']))
$topic = (int) $_GET['topic'];
// Well, what else are we going to do?
else
if ($output_method == 'echo')
return $txt['ssiTopic_no_id'];
// !!! Return some error code rather than a blank array?
else
return array();
// Number of replies per page
if ($num_replies === null)
//$num_replies = isset($_GET['num_replies']) ? (int) $_GET['num_replies'] : 10;
$num_replies = 10;
else
$num_replies = (int) $num_replies;
// Reply to start at
if ($start === null)
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
else
$start = (int) $start;
$num_replies = max(0, $num_replies);
$start = max(0, $start);
// Get some information about the topic (ie. the first post)
// !!! This should check logged in user's permissions, rather than checking if guests are allowed.
$result = db_query("
SELECT
t.ID_TOPIC, t.ID_BOARD, t.ID_FIRST_MSG, t.ID_LAST_MSG,
t.ID_MEMBER_STARTED, t.numReplies, t.locked, m.ID_MEMBER,
m.icon, m.subject, m.posterTime, m.body, m.smileysEnabled,
m.ID_MSG,
IFNULL(mem.realName, m.posterName) AS posterName,
b.name AS board_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 t.ID_TOPIC = $topic
AND m.ID_MSG = t.ID_FIRST_MSG
AND b.ID_BOARD = t.ID_BOARD
AND FIND_IN_SET(-1, b.memberGroups)", __FILE__, __LINE__);
// No results? That's not good!
if (mysql_num_rows($result) == 0)
{
if ($output_method == 'echo')
// !!! Maybe use fatal_lang_error()?
echo $txt['ssiTopic_notfound'];
else
return array();
}
// Get the topic info
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
// Censor it
censorText($row['body']);
censorText($row['subject']);
// Parse BBC in the message
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);
// Start our array of information
$return = array(
'id' => $row['ID_TOPIC'],
'id_msg' => $row['ID_MSG'],
'icon' => '<img src="' . $settings['images_url'] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'body' => $row['body'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $row['posterTime']),
'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>',
'reply_count' => $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>',
'locked' => !empty($row['locked']),
'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'],
),
// !!! Better way to do this?
'pageindex' => constructPageIndex('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?start=%d', $start, $row['numReplies'], $num_replies, true),
'replies' => array(),
);
// Get each post and poster in this topic
$result = db_query("
SELECT m.ID_MSG, m.ID_MEMBER
FROM {$db_prefix}messages AS m, {$db_prefix}topics AS t
WHERE m.ID_TOPIC = $topic
AND t.ID_TOPIC = $topic
AND m.ID_MSG != t.ID_FIRST_MSG
ORDER BY m.ID_MSG ASC
LIMIT $start, $num_replies", __FILE__, __LINE__);
// Was there any replies?
if (mysql_num_rows($result) != 0)
{
$messages = array();
$posters = array();
// Loop through each post
while ($row = mysql_fetch_assoc($result))
{
// If it wasn't a guest, add them to the posters array
if (!empty($row['ID_MEMBER']))
$posters[] = $row['ID_MEMBER'];
// Add this message to the messages array
$messages[] = $row['ID_MSG'];
}
mysql_free_result($result);
$posters = array_unique($posters);
// Load the member data of all the members that posted in this topic
loadMemberData($posters);
// Now, let's get all the replies (posts)
$result = db_query("
SELECT
m.ID_MSG, m.posterTime, m.ID_MEMBER, m.subject,
IFNULL(mem.realName, m.posterName) AS posterName,
m.posterIP, m.smileysEnabled, m.modifiedTime,
m.modifiedName, m.body, m.icon
FROM {$db_prefix}messages AS m
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE ID_MSG IN (" . implode(', ', $messages) . ")
ORDER BY m.ID_MSG ASC", __FILE__, __LINE__);
$counter = $start;
// Loop through each reply
// !!! This will probably use way too much memory for large topics!!
// !!! Callbacks instead?
while ($row = mysql_fetch_assoc($result))
{
// Try loading the member's data.
//If it couldn't load, or the user was a guest, use some failsafe values
if (!loadMemberContext($row['ID_MEMBER']))
{
// Notice this information isn't used anywhere else....
$memberContext[$row['ID_MEMBER']]['name'] = $row['posterName'];
$memberContext[$row['ID_MEMBER']]['id'] = 0;
$memberContext[$row['ID_MEMBER']]['group'] = $txt[28];
$memberContext[$row['ID_MEMBER']]['link'] = $row['posterName'];
$memberContext[$row['ID_MEMBER']]['email'] = $row['posterEmail'];
$memberContext[$row['ID_MEMBER']]['hide_email'] = $row['posterEmail'] == '' || (!empty($modSettings['guest_hideContacts']) && $user_info['is_guest']);
$memberContext[$row['ID_MEMBER']]['is_guest'] = true;
}
else
{
$memberContext[$row['ID_MEMBER']]['can_view_profile'] = allowedTo('profile_view_any') || ($row['ID_MEMBER'] == $ID_MEMBER && allowedTo('profile_view_own'));
$memberContext[$row['ID_MEMBER']]['is_topic_starter'] = $row['ID_MEMBER'] == $return['poster']['id'];
}
$memberContext[$row['ID_MEMBER']]['ip'] = $row['posterIP'];
// Censor it
censorText($row['body']);
censorText($row['subject']);
// Parse BBC in the message
parsesmileys($row['body']);
$context['aeva_disable'] = 1;
$row['body'] = parse_bbc(strip_tags($row['body']), $row['smileysEnabled'], $row['ID_MSG']);
// Add this to our messages array
$return['replies'][] = array(
'number' => $counter + 1,
'alternate' => $counter % 2,
'id' => $row['ID_MSG'],
'href' => $scripturl . '?topic=' . $topic . '.msg' . $row['ID_MSG'] . '#msg' . $row['ID_MSG'],
'link' => '<a href="' . $scripturl . '?topic=' . $topic . '.msg' . $row['ID_MSG'] . '#msg' . $row['ID_MSG'] . '">' . $row['subject'] . '</a>',
'poster' => &$memberContext[$row['ID_MEMBER']],
'icon' => '<img src="' . $settings['images_url'] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $row['posterTime']),
'modified' => array(
'time' => timeformat($row['modifiedTime']),
'timestamp' => forum_time(true, $row['modifiedTime']),
'name' => $row['modifiedName']
),
'body' => $row['body'],
'new' => empty($row['isRead']),
'first_new' => isset($context['start_from']) && $context['start_from'] == $counter,
'can_modify' => allowedTo('modify_any') || (allowedTo('modify_replies') && $context['user']['started']) || (allowedTo('modify_own') && $row['ID_MEMBER'] == $ID_MEMBER && (empty($modSettings['edit_disable_time']) || $row['posterTime'] + $modSettings['edit_disable_time'] * 60 > time())),
'can_remove' => allowedTo('delete_any') || (allowedTo('delete_replies') && $context['user']['started']) || (allowedTo('delete_own') && $row['ID_MEMBER'] == $ID_MEMBER && (empty($modSettings['edit_disable_time']) || $row['posterTime'] + $modSettings['edit_disable_time'] * 60 > time())),
'can_see_ip' => allowedTo('moderate_forum') || ($row['ID_MEMBER'] == $ID_MEMBER && !empty($ID_MEMBER)),
'is_last' => false,
);
$counter++;
}
mysql_free_result($result);
// The last post
$return['replies'][count($return['replies']) - 1]['is_last'] = true;
}
// If we're not echoing, return this information
if ($output_method != 'echo')
return $return;
// OK, if we're here, we need to echo the data.
// Output the first post
echo '
<div>
<a href="', $return['href'], '">', $return['icon'], '<b>', $return['subject'], '</b></a>
<div class="smaller">', $return['time'], ' ', $txt[525], ' ', $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'], ' ', $txt[525], ' ', $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%" />';
}
}
// --- End modification ---
Ah, yes, I see the problem.
The 'get all the replies' bit removes the line breaks.
Do you want users to be able to use BBcode in their posts?
I don't think there is a problem with them using BBcode but I don't want the emoticon graphics. Ideally I would want just the text version of the emotions like below,
:) :D ;)
Currently the emoticons are disabled completely for SSI which is a shame but at least avoids the graphics.
In ssi_topic, find:
$row['body'] = parse_bbc(strip_tags($row['body']), $row['smileysEnabled'], $row['ID_MSG']);
Replace with:
$row['body'] = parse_bbc($row['body'], false);
Thanks but line breaks still do not show and graphic emoticons are now showing?
I'd rather have no emoticons than graphic emoticons but ideally would want just the text versions.
Do you have a modified parse_bbc function, then? The false is supposed to stop parse_bbc handling smileys at all.
As for the lack of line break, I'm confused then since the line breaks should have been removed by the strip-tags function.
My most important issue by far is the lack of line breaks... the comments can look horrible because if someone writes a couple 100-200 words, it will be all squashed together with no line breaks which makes it very hard to read.