display avy in ssi_boardNews

Started by diplomat., January 06, 2005, 05:21:31 PM

Previous topic - Next topic

diplomat.

is it possible to display the avatar of the person who made the topic along with the topic body of ssi_boardNews? i made a little example:



can the avy or the topic author be pulled so that it shows up on the page sort of like that
avidSOUND.com: Where Aspiring Musicians Can Be HEARD!

[Unknown]

Sorry for taking so long to respond.

It's possible, but it could take some modification...

From SSI.php:
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
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_BOARD = $board
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY m.ID_MSG DESC
LIMIT $start, $limit", __FILE__, __LINE__);


Make that:
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, mem.avatar, a.ID_ATTACH
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)
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = m.ID_MEMBER)
WHERE t.ID_BOARD = $board
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY m.ID_MSG DESC
LIMIT $start, $limit", __FILE__, __LINE__);


Not much later, after:
$row['body'] = doUBBC($row['body'], $row['smileysEnabled']);

Add:
if (stristr($row['avatar'], 'http://') && !empty($modSettings['avatar_check_size']))
{
$sizes = url_image_size($row['avatar']);

// Does your avatar still fit the maximum size?
if ($modSettings['avatar_action_too_large'] == 'option_refuse' && is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
{
// Fix it permanently!
$row['avatar'] = '';
updateMemberData($row['ID_MEMBER'], array('avatar' => '\'\''));
}
}


And then find:
'is_last' => false

Make that:

'is_last' => false,
'avatar' => array(
'name' => &$row['avatar'],
'image' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 && !empty($modSettings['avatar_allow_upload']) ? '<img src="' . $scripturl . '?action=dlattach;id=' . $row['ID_ATTACH'] . ';type=avatar" alt="" />' : '') : (stristr($row['avatar'], 'http://') && !empty($modSettings['avatar_allow_external_url']) ? '<img src="' . $row['avatar'] . '"' . ($modSettings['avatar_action_too_large'] == 'option_html_resize' ? (!empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '') . (!empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '') : '') . ' alt="" border="0" />' : (!empty($modSettings['avatar_allow_server_stored']) ? '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" />' : '')),
'href' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 && !empty($modSettings['avatar_allow_upload']) ? $scripturl . '?action=dlattach;id=' . $row['ID_ATTACH'] . ';type=avatar' : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar'])
),


Then you have the href and image ;).

-[Unknown]

Midgard


Iriasu

#3
When I add ', $news['avatar'], ' to the place where I want to show my avatar, it just says "Array" on that spot of my news posts. The actual coding seems to work somewhat fine, but what is that small string I should write to make avatars show up on news post?

Something in the fashion of:
', $something['something'], '

Thanks in advance! ^_^

EDIT: Nevermind. I found out myself. I wrote ', $news['avatar']['image'], ' and it worked splendidly. ^^

EDIT: While I'm at the questionings, what should I do, if I want my (as an example) 100x100 avatar on my board show up on my news posts as 50x50 instead? I want the avatar to keep its original size in the board, but reduce its size on news posts.
hxxp:www.rockmanpm.com [nonactive]
Fight, Iriasu! For Everlasting Orange Fanta!
hxxp:img100.exs.cx/img100/2870/nvcdash4qs.gif [nonactive]

[Unknown]

<img src="', $news['avatar']['href'], '" width="50" height="50" alt="" />

-[Unknown]

MKava

Can somebody please update this for the latest released version of SMF?
I'm running v1.1.2 and couldn't get to this work. It'd be a real nice feature to add on just for a little more flavor to my site. :D
M. Kava
SMF Forums: Freaky Forums [nofollow] for NintendoFreaks.com [nofollow]

codenaught

Quote from: MKava on March 11, 2007, 12:47:08 AM
Can somebody please update this for the latest released version of SMF?
I'm running v1.1.2 and couldn't get to this work. It'd be a real nice feature to add on just for a little more flavor to my site. :D
MKava, still need help with this?
Dev Consultant
Former SMF Doc Coordinator

KouZeN

I'd like to see this updated for v1.1.3 if at all possible.

Ryatzu


codenaught

Code for 1.1.3 (Simply adapted from [Unknown]'s):

SSI.php

Code (Find) Select
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__);


Code (Replace with) Select
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, mem.avatar, a.ID_ATTACH, a.attachmentType, a.filename
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)
LEFT JOIN {$db_prefix}attachments AS a ON (a.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__);


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

Code (After add) Select
if (stristr($row['avatar'], 'http://') && !empty($modSettings['avatar_check_size']))
{
$sizes = url_image_size($row['avatar']);

// Does your avatar still fit the maximum size?
if ($modSettings['avatar_action_too_large'] == 'option_refuse' && is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
{
// Fix it permanently!
$row['avatar'] = '';
updateMemberData($row['ID_MEMBER'], array('avatar' => '\'\''));
}
}


Code (Find (in ssi_boardNews function)  ) Select
'is_last' => false


Code (Replace above with (Code adapted from Load.php)  ) Select
'is_last' => false,
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? '<img src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '" alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
),


Then you can use either add the variables as you wish in the template output inside the SSI function, or if not using the 'echo' return type when calling the function, you can just use the added variables as needed when outputting the news.
Dev Consultant
Former SMF Doc Coordinator

Ryatzu

ok i changed it, how can i get the avatar on the index now?

Ryatzu


mira-san

I try to make that but it doesn't work in smf 1.14
I make all the step.
Hope you can help me please.

codenaught

Quote from: mira-san on October 15, 2007, 08:42:17 AM
I try to make that but it doesn't work in smf 1.14
I make all the step.
Hope you can help me please.
Were you trying to use my code I posted?

What doesn't work about it? Could you not find all of the code that is there? Do you get parse errors? That code alone, won't show the avatar, you would need to echo out the avatar variable created with that code manually, which I can help with if I know that is the stage you are on (That you have successfully applied those code changes with no errors but don't see an avatar being displayed).
Dev Consultant
Former SMF Doc Coordinator

myaicons

@ akabugeyes

does your code work with 1.1.4?

can i get further details? Thanks!
i scratch your back you scratch my back...
funny thing about my back is its located on my...

Ryatzu

Just used it again in 1.14, works great.

myaicons

#16
Quote from: akabugeyes on November 13, 2007, 12:45:33 AM
That code alone, won't show the avatar, you would need to echo out the avatar variable created with that code manually, which I can help with if I know that is the stage you are on (That you have successfully applied those code changes with no errors but don't see an avatar being displayed).


can i get help with this?  i dont know how to make the avatar show up


this just shows a red x :

<img src="', $news['avatar']['href'], '" width="50" height="50" alt="" /> 

when i add it like this:

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>
<img src="', $news['avatar']['href'], '" width="50" height="50" alt="" /> 
<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%" />';
}
}
i scratch your back you scratch my back...
funny thing about my back is its located on my...

myaicons

i scratch your back you scratch my back...
funny thing about my back is its located on my...

[SiNaN]

Former SMF Core Developer | My Mods | SimplePortal

myaicons

tried that... still wont work for me....

any more ideas???
i scratch your back you scratch my back...
funny thing about my back is its located on my...

[SiNaN]

Are you sure you made the needed change in the code that akabugeyes gave correctly?
Former SMF Core Developer | My Mods | SimplePortal

myaicons

yup... im pretty sure i did... i just double checked it.... (its all only in the ssi.php right?)

i scratch your back you scratch my back...
funny thing about my back is its located on my...

ApocalypticSpirit

Sorry to dig up an old thread again, but I've tried to apply this on a 1.1.4 board and there is no image loading at all.

I've just recently been experimenting with SSI so I could have placed something wrong :P
<?php
ob_start
();
?>

QuoteSite Stuff
<?

require("forum/SSI.php");

   $array = ssi_boardNews(15.0, 5, null, 250, 'array');

   foreach ($array as $news)
   
   {
      echo '
  <div style="background-color:#999999; width:564px; height:auto; border:1px solid #000000;">
         <table border="0" width="100%" align="center" class="ssi_table" cellspacing="5">
            <tr>
               <td width="50px" height="50px">
<img src="', $news['avatar']['href'], '" width="50" height="50" />
               </td>
               <td align="left" width="100%">
               <small>', $news['time'], '</small><br />
   <b><font size="3" color="#cccccc">', $news['subject'], '</font></b><br />
   <small>Posted by: ', $news['poster']['name'], '</small><br />
      </td>
            </tr>
            <tr>
              <td align="left" colspan="2"><hr align="left" width="50%" /></td>
            </tr>
            <tr>
               <td align="left" colspan="2">', $news['body'], '<br /><br /></td>
            </tr>
<tr>
               <td align="left" colspan="2"><a href="', $news['href'], '">Comment</a><br /><br /></td>
            </tr>
         </table>
</div>
         ';

      if (!$news['is_last'])
         echo '
         <hr width="100%" />
         ';
   }

?>

QuoteMore Site Stuff

ApocalypticSpirit

Sorry if i'm seeming pushy but we really need this fix, then we can launch the site :)

Here's the ssi_boardNews part of the SSI also.

// 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, mem.avatar, a.ID_ATTACH, a.attachmentType, a.filename
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)
LEFT JOIN {$db_prefix}attachments AS a ON (a.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']);

      if (stristr($row['avatar'], 'http://') && !empty($modSettings['avatar_check_size']))
      {
         $sizes = url_image_size($row['avatar']);

         // Does your avatar still fit the maximum size?
         if ($modSettings['avatar_action_too_large'] == 'option_refuse' && is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
         {
            // Fix it permanently!
            $row['avatar'] = '';
            updateMemberData($row['ID_MEMBER'], array('avatar' => '\'\''));
         }
      }

// 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%" />';
}
}

[SiNaN]

You didn't make the last edit, check it again.
Former SMF Core Developer | My Mods | SimplePortal

Gambi

Hi, is there a way to get this to work with comments? I'm using the replies from a thread via SSI.php to look like comments on the mainpage and they already look good but I would like to add the user's avatar next to their name. I'm sure it shouldn't be too difficult but I cannot find the right avatar string for it. I'm using 1.1.5 and here is the code for my page.

<img src="images/division.PNG" width="780" height="11">

      <table width="700" border="0">
        <tr>
          <td><img src="images/news_head.png" width="457" height="110"></td>
          <td><img src="images/iaad.gif" width="334" height="109"></td>
        </tr>
      </table>
      </p>
      </td>
  </tr>
  <tr> <img src="images/division.PNG" width="800" height="11">

<?php
// Require SSI
require('/home/content/B/l/a/Blackthorne519/html/forum/SSI.php');

// No topic? That's bad
if (empty($_REQUEST['topic']))
die('No topic passed');

// Get this topic and its replies
$return ssi_topic($_REQUEST['topic'], nullnull'array'); // Setting something to 'null' will use the default value.

// Output the first post
echo '
<div>
<h3><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="36"><font style="text-transform: uppercase;">'
$return['icon'], '</font></td>
<td><font style="text-transform: uppercase;"><b>'
$return['subject'], ' </b> </font><br>

<i>'
$return['time'], ' by '$return['poster']['link'], '</i></td>
</tr>
</table>


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

'
$return['locked'] ? '' $return['link'], '<br /><br />
</div>

<h3><font style="text-transform: uppercase;"><b>'
$txt['ssiTopic_replies'], '</font></b></h3><br>

'
$return['pageindex'];
echo 
'<br><br>';
// Loop through each post
foreach ($return['replies'] as $post)
{
echo '
<h2><div>
<div><font style="text-transform: uppercase;"><b><img src="(users avatar)" width="30" height="30" align="left" hspace="3" border="1" />'
$post['poster']['link'], '</font></b> <br><i> '$post['time'], '</i></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 '
</h2>'
$return['pageindex'];
else
echo '
'
;
}
?>


   <br> <td><img src="images/bottom.PNG" width="800" height="67"></td>


Thanks!


[SiNaN]

What do you mean by comments? Can you post your ssi_topic function here?
Former SMF Core Developer | My Mods | SimplePortal

Advertisement: