SimplePortal

Customization => Custom Coding => Topic started by: neverhurry on February 21, 2010, 03:59:15 PM

Title: Help needed almost finished boardnews attachment!
Post by: neverhurry on February 21, 2010, 03:59:15 PM
Hi,

a boardnews with attachement pictures is a function many users would like to have. I don't think any other portal has this function. I do wish Simple Portal could have it. What I want is to display the attached picture under the subject (if that post happen to have no attached pic then show the post "body").

I have manually added the attachment into the boardnews function, here is the code:

Code: [Select]
function sp_boardNews($parameters, $id, $return_parameters = false)

{

global $scripturl, $txt, $settings, $modSettings, $context, $smcFunc, $color_profile;



$block_parameters = array(

'board' => 'boards',

'limit' => 'int',

'start' => 'int',

'length' => 'int',

'avatar' => 'check',

'per_page' => 'int',

);



if ($return_parameters)

return $block_parameters;



$board = !empty($parameters['board']) ? explode('|', $parameters['board']) : null;

$limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 5;

$start = !empty($parameters['start']) ? (int) $parameters['start'] : 0;

$length = isset($parameters['length']) ? (int) $parameters['length'] : 250;

$avatars = !empty($parameters['avatar']);

$per_page = !empty($parameters['per_page']) ? (int) $parameters['per_page'] : 0;



$limit = max(0, $limit);

$start = max(0, $start);



loadLanguage('Stats');



$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';



$request = $smcFunc['db_query']('', '

SELECT t.id_first_msg

FROM {db_prefix}topics AS t

INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)

INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)

WHERE ' . (empty($board) ? '{query_see_board}

AND t.id_first_msg >= {int:min_msg_id}' : 't.id_board IN ({array_int:current_board})') . ($modSettings['postmod_active'] ? '

AND t.approved = {int:is_approved}' : '') . '

AND (t.locked != {int:locked} OR m.icon != {string:icon})

ORDER BY t.id_first_msg DESC

LIMIT {int:limit}',

array(

'current_board' => $board,

'min_msg_id' => $modSettings['maxMsgID'] - 45 * min($limit, 5),

'is_approved' => 1,

'locked' => 1,

'icon' => 'moved',

'limit' => $limit,

)

);

$posts = array();

while ($row = $smcFunc['db_fetch_assoc']($request))

$posts[] = $row['id_first_msg'];

$smcFunc['db_free_result']($request);



if (empty($posts))

{

echo '

', $txt['error_sp_no_posts_found'];

return;

}

elseif (!empty($per_page))

{

$limit = count($posts);

$start = !empty($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;

$page_index = constructPageIndex($context['portal_url'] . '?sa=news', $start, $limit, $per_page);

}



$request = $smcFunc['db_query']('', '

SELECT

m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,

t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, mem.avatar,

a.id_attach, a.attachment_type, a.filename, t.num_views

FROM {db_prefix}topics AS t

INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)

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 = mem.id_member)

WHERE t.id_first_msg IN ({array_int:post_list})

ORDER BY t.id_first_msg DESC

LIMIT ' . (!empty($per_page) ? '{int:start}, ' : '') . '{int:limit}',

array(

'post_list' => $posts,

'start' => $start,

'limit' => !empty($per_page) ? $per_page : $limit,

)

);

$return = array();

$colorids = array();

while ($row = $smcFunc['db_fetch_assoc']($request))

{

if (!empty($length) && $smcFunc['strlen']($row['body']) > $length)

$row['body'] = parse_bbc(sp_truncateText($row['body'], $length), $row['smileys_enabled'], $row['id_msg']) . '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0" title="' . $row['subject'] . '">...</a>';

else

$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);



if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')

{

$avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';

$avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';

}

else

{

$avatar_width = '';

$avatar_height = '';

}



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']);





if ($modSettings['sp_resize_images'])

$row['body'] = preg_replace('~class="bbc_img"~i', 'class="bbc_img sp_article"', $row['body']);



if (!empty($row['id_member']))

$colorids[$row['id_member']] = $row['id_member'];



$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['poster_time']),

'timestamp' => forum_time(true, $row['poster_time']),

'timeyear' => timeformat($row['poster_time'], '%d %b %y'),

'timeday' => timeformat($row['poster_time'], '%H:%M:%S'),

'views' => $row['num_views'],

'body' => $row['body'],

'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',

'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $txt['sp-read_more'] . '</a>',

'replies' => $row['num_replies'],

'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'],

'comment_link' => !empty($row['locked']) ? '' : '| <a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',

'new_comment' => !empty($row['locked']) ? '' : '| <a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',

'poster' => array(

'id' => $row['id_member'],

'name' => $row['poster_name'],

'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['poster_name'] . '</a>' : $row['poster_name']

),

'locked' => !empty($row['locked']),

'is_last' => false,

'attachment' => array(
'href' => $scripturl . '?action=dlattach;topic=' . $row['id_topic'] . '.0;attach=' . $row['id_attach']. ';image',
'filename' => htmlspecialchars($row['filename']),),



'avatar' => array(

'name' => $row['avatar'],

'image' => $row['avatar'] == '' ? ($row['id_attach'] > 0 ? '<img src="' . (empty($row['attachment_type']) ? $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'] . '"' . $avatar_width . $avatar_height . ' 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['attachment_type']) ? $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'])

),

);

}

$smcFunc['db_free_result']($request);



if (empty($return))

{

echo '

', $txt['error_sp_no_posts_found'];

return;

}



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



if (!empty($colorids) && sp_loadColors($colorids) !== false)

{

foreach ($return as $k => $p)

{

if (!empty($color_profile[$p['poster']['id']]['link']))

$return[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];

}

}




foreach ($return as $news)


{
   if (!empty($news['attachment']))

   {
    echo ' <div class="frontpost">';
   
echo ' <div class="frontsubject"><a href="', $news['href'], '">', shorten_subject($news['subject'], 20), '</a><br />[' , $news['board']['link'] , ']</div>';
 

echo '<div class="frontimg"">';
echo '<a href="', $news['href'], '"><img src="', $news['attachment']['href'], '" width="" height="100" /></a>';
    echo '</div>';

echo '</div>';
   }
else
   {
     echo ' <div class="frontpost">';
echo ' <div class="frontsubject"><a href="', $news['href'], '">', shorten_subject($news['subject'], 20), '</a><br />[' , $news['board']['link'] , ']</div>';
     echo '<div>', $news['body'], '</div>';
echo ' </div>';
   }
}
echo '<div style="clear: both;" /></div>';



if (!empty($per_page))

echo '

<div class="sp_page_index">', $txt['sp-articlesPages'], ': ', $page_index, '</div>';

}

Then I checked the attachment pic in Google Chrome browser, I find out that the attachment pic href has lost the id_attach: for example:

http://www.tianxiafumuxin.com/index.php?action=dlattach;topic=97.0;attach=;image

live demo is here: http://www.tianxiafumuxin.com/

but only in Google chrome the attachment picture position can be shown.

after 'attach' there lost the 'id_attach', I need this very much. I sincerely appreciate and thank you for your help, any idea or hint to help me complete this task. kind regards, Paul
Title: Re: Help needed almost finished boardnews attachment!
Post by: AngelinaBelle on February 25, 2010, 04:42:21 PM
neverhurry,
I am stumped.
Your code is not browser-specific, so it seems to me the generated URL should be the same in all browsers.
I tried your link, but guests are not permitted to see the output.
 
Here's what I would do to debug:
 
Code: [Select]
$sql_query=
'
SELECT
m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, mem.avatar,
a.id_attach, a.attachment_type, a.filename, t.num_views
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
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 = mem.id_member)
WHERE t.id_first_msg IN ({array_int:post_list})
ORDER BY t.id_first_msg DESC
LIMIT ' . (!empty($per_page) ? '{int:start}, ' : '') . '{int:limit}
$request = $smcFunc['db_query']('', $sql_query,
   array(
     'current_board' => $board,
     'min_msg_id' => $modSettings['maxMsgID'] - 45 * min($limit, 5),
     'is_approved' => 1,
     'locked' => 1,
     'icon' => 'moved',
     'limit' => $limit,
     )
   );

Then, right before
Code: [Select]
foreach ($return as $news)
Code: [Select]
echo '<div class="frontpost"><pre>SQL query: ', $sql_qry, '</pre></div>
';

And see what you get.
If that looks OK, I'd insert some debugging statements to see if $return[]
['attachment']['href'] elements are what you expect them to be.
 
Because it sounds as though they are going empty.
 
What will happen if you have more than one attachment per message id?
 
 
Title: Re: Help needed almost finished boardnews attachment!
Post by: ccbtimewiz on February 25, 2010, 10:21:01 PM
It's a known SMF issue with webkit based browsers like Safari and Chrome.
Title: Re: Help needed almost finished boardnews attachment!
Post by: AngelinaBelle on February 26, 2010, 08:03:52 AM
That's bizarre! At what point in the process does the URL lose the a.id?
SimplePortal 2.3.8 © 2008-2024, SimplePortal