SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: Kobar on October 24, 2012, 04:21:34 PM

Title: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: Kobar on October 24, 2012, 04:21:34 PM
Hello,

How do I change at block 'recent posts' the ''images/sp/post.png'' to ''posts' message icon' ?
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: phantomm on October 26, 2012, 12:43:26 PM
You can find in ./Sources/PortalBlocks.php:
Code: [Select]
', sp_embed_image(empty($parameters['type']) ? 'post' : 'topic'), 'and replace it with HTML image code:
Code: [Select]
<img src="URL_TO_IMAGE" alt="">
But then this will affect every recent topics and recent posts blocks.

Or you can use this in custom PHP block:
Code: [Select]
global $txt, $scripturl, $settings, $context, $color_profile;

$block_parameters = array(
'boards' => 'boards',
'limit' => 'int',
'type' => 'select',
'display' => 'select',
);

if ($return_parameters)
return $block_parameters;

$boards = !empty($parameters['boards']) ? explode('|', $parameters['boards']) : null;
$limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 5;
$type = 'ssi_recent' . (empty($parameters['type']) ? 'Posts' : 'Topics');
$display = 'full';

$items = $type($limit, null, $boards, 'array');

if (empty($items))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}
else
$items[count($items) - 1]['is_last'] = true;

$colorids = array();
foreach ($items as $item)
$colorids[] = $item['poster']['id'];

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($items as $k => $p)
{
if (!empty($color_profile[$p['poster']['id']]['link']))
$items[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];
}
}

if ($display == 'compact')
{
foreach ($items as $key => $item)
echo '
<a href="', $item['href'], '">', $item['subject'], '</a> <span class="smalltext">', $txt['by'], ' ', $item['poster']['link'], $item['new'] ? '' : ' <a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['time'], ']</span><br />', empty($item['is_last']) ? '<hr />' : '';
}
elseif ($display == 'full')
{
echo '
<table class="sp_fullwidth">';

foreach ($items as $item)
echo '
<tr>
<td class="sp_recent_icon sp_center">
', sp_embed_image(empty($parameters['type']) ? 'post' : 'topic'), '
</td>
<td class="sp_recent_subject">
<a href="', $item['href'], '">', $item['subject'], '</a>
', $item['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['board']['link'], ']
</td>
<td class="sp_recent_info sp_right">
', $item['poster']['link'], '<br />', $item['time'], '
</td>
</tr>';

echo '
</table>';
}

and replace in this code
Code: [Select]
', sp_embed_image(empty($parameters['type']) ? 'post' : 'topic'), 'with HTML image code:
Code: [Select]
<img src="URL_TO_IMAGE" alt="">
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: Kobar on October 26, 2012, 04:17:00 PM
I used your custom php code and changed that HTML code with sp_embed..

All good but the 'message icons' are not visible..
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: phantomm on October 26, 2012, 04:37:41 PM
What exactly are you adding in PHP block?
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: Kobar on October 26, 2012, 05:01:55 PM
Code: [Select]
global $txt, $scripturl, $settings, $context, $color_profile;

$block_parameters = array(
'boards' => 'boards',
'limit' => 'int',
'type' => 'select',
'display' => 'select',
);

if ($return_parameters)
return $block_parameters;

$boards = !empty($parameters['boards']) ? explode('|', $parameters['boards']) : null;
$limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 5;
$type = 'ssi_recent' . (empty($parameters['type']) ? 'Posts' : 'Topics');
$display = 'full';

$items = $type($limit, null, $boards, 'array');

if (empty($items))
{
echo '
', $txt['error_sp_no_posts_found'];
return;
}
else
$items[count($items) - 1]['is_last'] = true;

$colorids = array();
foreach ($items as $item)
$colorids[] = $item['poster']['id'];

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($items as $k => $p)
{
if (!empty($color_profile[$p['poster']['id']]['link']))
$items[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];
}
}

if ($display == 'compact')
{
foreach ($items as $key => $item)
echo '
<a href="', $item['href'], '">', $item['subject'], '</a> <span class="smalltext">', $txt['by'], ' ', $item['poster']['link'], $item['new'] ? '' : ' <a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['time'], ']</span><br />', empty($item['is_last']) ? '<hr />' : '';
}
elseif ($display == 'full')
{
echo '
<table class="sp_fullwidth">';

foreach ($items as $item)
echo '
<tr>
<td class="sp_recent_icon sp_center">
<img src="URL_TO_IMAGE" alt="">
</td>
<td class="sp_recent_subject">
<a href="', $item['href'], '">', $item['subject'], '</a>
', $item['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['board']['link'], ']
</td>
<td class="sp_recent_info sp_right">
', $item['poster']['link'], '<br />', $item['time'], '
</td>
</tr>';

echo '
</table>';
}
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: Chen Zhen on October 26, 2012, 05:52:07 PM
Kobar,

You need to edit in the appropriate image url. Your block code has the initial image for full display as URL_TO_IMAGE ... you need to edit that text to the full url of the image you are attempting to display.
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: Kobar on October 26, 2012, 06:33:56 PM
Ah! But the message icons are not always the same.. Sometimes people are posting from iphone, blackberry and android.. I just need the message icon people are posting with.. :)

(see attachment)
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: hcfwesker on October 27, 2012, 02:46:38 AM
I could be wrong, but seems you'll need to get the "icon" info from the messages databse to make that happen.  and change that image line to something like this ...

Code: [Select]
<img src="', $settings['images_url'], '/images/post/'.$icon.'.gif" alt="">
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: Kobar on October 27, 2012, 04:23:06 AM
I could be wrong, but seems you'll need to get the "icon" info from the messages databse to make that happen.  and change that image line to something like this ...

Code: [Select]
<img src="', $settings['images_url'], '/images/post/'.$icon.'.gif" alt="">

I tried that.

I also tried from Defaut/post.template.php

Code: [Select]
<img src="', $context['icon_url'], '" name="icons" hspace="15" alt="" />
But nothing appears..
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: hcfwesker on October 27, 2012, 04:57:17 AM
I never said simply putting that would work.  You'd need to retrieve the "icon" data from the messages database table before it would do anything..
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: Chen Zhen on October 27, 2012, 08:34:44 AM
Kobar,

  Do you have a modification installed that detects the source hardware (ie. specific mobile device) and then alters the message icon to match the device? Or perhaps a mod that allows the user to select more icons beyond the defaults?  If so can you provide a link to that modification?

  The messages table in the database does not contain such portable device icons & I assume you must be using some mod that adds these. Furthermore, the default SSI function you are using in your block does not retrieve that specific data & would need to be altered or another function made anew. After which your block would need to be altered to display that retrieved data.

Edit -> This mod perhaps? ... http://custom.simplemachines.org/mods/index.php?mod=3349
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: Kobar on October 27, 2012, 09:07:08 AM
Hello Underdog,

I have installed a mod yes. I'm not allowed to post that mod in public, but I will send it to you in PM, if that's ok?
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: Chen Zhen on October 27, 2012, 12:55:56 PM
Kobar,

  I had assumed it was a mod from the SMF site & am not willing to download files from unknown sources such as the one you provided for reasons of possible security/viruses. If you can figure out what column the mod added to your messages table or what additional table with columns it added to render these images then I can help you. This can be done via phpmyadmin where you would need to browse your database for the table information that is necessary to perform the needed edits/code.

  It's possible that this mod automatically adds the icon file name to the icon column in the messages table which is an existing column but you will have to determine this & then I will be able to assist you. Show me a screenshot of the top of one of these forum posts (the actual post).  Does this icon appear directly left of the post title?
 
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: Chen Zhen on October 27, 2012, 02:10:56 PM
Kobar,

  The following is assuming the mod in question uses the messages_icon table/column.

You need to perform edits to the SSI.php file.

Find (approx. line 328):
Code: [Select]
// Find all the posts. Newer ones will have higher IDs.
$request = $smcFunc['db_query']('substring', '
SELECT
m.poster_time, m.subject, m.id_topic, m.id_member, m.id_msg, m.id_board, b.name AS board_name,

Replace with:
Code: [Select]
// Find all the posts. Newer ones will have higher IDs.
$request = $smcFunc['db_query']('substring', '
SELECT
m.poster_time, m.subject, m.id_topic, m.id_member, m.id_msg, m.id_board, m.icon, b.name AS board_name,

Find (approx. line 366):
Code: [Select]
// Build the array.
$posts[] = array(
'id' => $row['id_msg'],
'board' => array(
'id' => $row['id_board'],
'name' => $row['board_name'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
),
'topic' => $row['id_topic'],
'poster' => array(
'id' => $row['id_member'],

Replace with:
Code: [Select]
// Build the array.
$posts[] = array(
'id' => $row['id_msg'],
'board' => array(
'id' => $row['id_board'],
'name' => $row['board_name'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
),
'topic' => $row['id_topic'],
'poster' => array(
'id' => $row['id_member'],
'icon' => $row['icon'],

Find (approx. line 442):
Code: [Select]
// Find all the posts in distinct topics.  Newer ones will have higher IDs.
$request = $smcFunc['db_query']('substring', '
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS board_name, t.num_replies, t.num_views,

Replace with:
Code: [Select]
// Find all the posts in distinct topics.  Newer ones will have higher IDs.
$request = $smcFunc['db_query']('substring', '
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, m.icon, b.id_board, b.name AS board_name, t.num_replies, t.num_views,

Find (approx. line 495):
Code: [Select]
// Build the array.
$posts[] = array(
'board' => array(
'id' => $row['id_board'],
'name' => $row['board_name'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
),
'topic' => $row['id_topic'],
'poster' => array(
'id' => $row['id_member'],

Replace with:
Code: [Select]
// Build the array.
$posts[] = array(
'board' => array(
'id' => $row['id_board'],
'name' => $row['board_name'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
),
'topic' => $row['id_topic'],
'poster' => array(
'id' => $row['id_member'],
'icon' => $row['icon'],



I will attach a copy of the SSI.php file with the above edits already implemented assuming you do not have any previous needed edits to your current file.




Here is the block code:
Code: [Select]
global $txt, $scripturl, $settings, $context, $color_profile;

$block_parameters = array(
'boards' => null,
'limit' => '5',
'type' => 'Topics',
'display' => 'full',
);

$boards =  $block_parameters['boards'] ? $block_parameters['boards'] : null;
$limit = $block_parameters['limit'] ? (int) $block_parameters['limit'] : 5;
$type = 'ssi_recent' . (!$block_parameters['type'] ? 'Posts' : $block_parameters['type']);
$display = $block_parameters['display'] ? $block_parameters['display'] : 'full';

$items = $type($limit, null, $boards, 'array');

if (empty($items))
{
echo $txt['error_sp_no_posts_found'];
return;
}
else
$items[count($items) - 1]['is_last'] = true;

$colorids = array();
foreach ($items as $item)
$colorids[] = $item['poster']['id'];

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($items as $k => $p)
{
if (!empty($color_profile[$p['poster']['id']]['link']))
$items[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];
}
}

if ($display == 'compact')
{
foreach ($items as $key => $item)
echo '
<a href="', $item['href'], '">', $item['subject'], '</a> <span class="smalltext">', $txt['by'], ' ', $item['poster']['link'], $item['new'] ? '' : ' <a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['time'], ']</span><br />', empty($item['is_last']) ? '<hr />' : '';
}
else
{
echo '
<table class="sp_fullwidth">';

foreach ($items as $item)
echo '
<tr>
<td class="sp_recent_icon sp_center">
<img src="'.$settings['images_url']. '/post/'.$item['poster']['icon'].'.gif" alt="" />
</td>
<td class="sp_recent_subject">
<a href="', $item['href'], '">', $item['subject'], '</a>
', $item['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['board']['link'], ']
</td>
<td class="sp_recent_info sp_right">
', $item['poster']['link'], '<br />', $item['time'], '
</td>
</tr>';

echo '
</table>';
}

If you want specific boards only, edit the boards of the block_parameters with an array.
null will display all boards (current setting)
ie.
Code: [Select]
global $txt, $scripturl, $settings, $context, $color_profile;

$block_parameters = array(
'boards' => array(1,2,3,4),
'limit' => '5',
'type' => 'Topics',
'display' => 'full',
);

$boards =  $block_parameters['boards'] ? $block_parameters['boards'] : null;
$limit = $block_parameters['limit'] ? (int) $block_parameters['limit'] : 5;
$type = 'ssi_recent' . (!$block_parameters['type'] ? 'Posts' : $block_parameters['type']);
$display = $block_parameters['display'] ? $block_parameters['display'] : 'full';

$items = $type($limit, null, $boards, 'array');

if (empty($items))
{
echo $txt['error_sp_no_posts_found'];
return;
}
else
$items[count($items) - 1]['is_last'] = true;

$colorids = array();
foreach ($items as $item)
$colorids[] = $item['poster']['id'];

if (!empty($colorids) && sp_loadColors($colorids) !== false)
{
foreach ($items as $k => $p)
{
if (!empty($color_profile[$p['poster']['id']]['link']))
$items[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];
}
}

if ($display == 'compact')
{
foreach ($items as $key => $item)
echo '
<a href="', $item['href'], '">', $item['subject'], '</a> <span class="smalltext">', $txt['by'], ' ', $item['poster']['link'], $item['new'] ? '' : ' <a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['time'], ']</span><br />', empty($item['is_last']) ? '<hr />' : '';
}
else
{
echo '
<table class="sp_fullwidth">';

foreach ($items as $item)
echo '
<tr>
<td class="sp_recent_icon sp_center">
<img src="'.$settings['images_url']. '/post/'.$item['poster']['icon'].'.gif" alt="" />
</td>
<td class="sp_recent_subject">
<a href="', $item['href'], '">', $item['subject'], '</a>
', $item['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['board']['link'], ']
</td>
<td class="sp_recent_info sp_right">
', $item['poster']['link'], '<br />', $item['time'], '
</td>
</tr>';

echo '
</table>';
}
Title: Re: [SMF 2.0.2] Change in 'Recent Posts' icon..
Post by: Kobar on October 27, 2012, 04:10:35 PM
Thank you so much!!  ;D
SimplePortal 2.3.8 © 2008-2024, SimplePortal