News:

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

Main Menu

Page for each SSI news article

Started by mark7144, March 16, 2009, 11:03:49 AM

Previous topic - Next topic

mark7144

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?

onepiece

#21
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.

mark7144

Sorry for not understanding.. so the actual hack of looking at an SSI article on a non-forum page will not work with SMF2?

onepiece

Sorry, was in a hurry and made another typo. I've edited my post above.

This 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.

mark7144

OK thanks, maybe when that times come I will offer money to an SMF coder to change what you have done to SMF2

nvcnvn

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!?

mark7144

Sure but I haven't changed to SMF2 yet, could be a while.

nvcnvn

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
If you want this code I can share for all of you!

mark7144

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.


mark7144

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/

Arantor

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?
Holder of controversial views, all of which my own.


mark7144

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&amp;charset=utf-8&amp;style=default&amp;publisher=cad2263b-c893-46da-9c2b-239b2e40aad4"></script><br /><br /></div>
'
;

?>
</div>
<!-- /News -->
<? include ('footer_includes.php'); ?>

Arantor

Hmm.

ssi_topic is not a standard SMF SSI function. Please can you post that function too?
Holder of controversial views, all of which my own.


mark7144

// --- 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 ---

Arantor

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?
Holder of controversial views, all of which my own.


mark7144

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.

Arantor

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);
Holder of controversial views, all of which my own.


mark7144

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.

Arantor

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.
Holder of controversial views, all of which my own.


mark7144

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.

Advertisement: