SimplePortal

Customization => Custom Coding => Topic started by: willemjan on January 19, 2011, 08:49:20 AM

Title: Where do I look...
Post by: willemjan on January 19, 2011, 08:49:20 AM
Wich file should I edit, if I want to change the look of the SP standard blocks?
Title: Re: Where do I look...
Post by: AngelinaBelle on January 19, 2011, 09:23:46 AM
blocks.template.php
 
But most of the types of changes you want can be handled in CSS.
Title: Re: Where do I look...
Post by: willemjan on January 19, 2011, 09:31:25 AM
Thank you very much! I'll dig into it  ;D
Title: Re: Where do I look...
Post by: willemjan on January 20, 2011, 02:37:58 AM
Hmm I can't find that file in the SP package. See the attachment ;)
Title: Re: Where do I look...
Post by: AngelinaBelle on January 20, 2011, 10:12:08 AM
sorry.
Portal.template.php
Title: Re: Where do I look...
Post by: willemjan on January 21, 2011, 05:51:43 AM
Hmm.. it was PortalBlocks.php what I was looking for. Now I changed this:

Code: [Select]
function sp_articles($parameters, $id, $return_parameters = false)
{
global $smcFunc, $modSettings, $scripturl, $txt, $color_profile;

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

if ($return_parameters)
return $block_parameters;

$limit = empty($parameters['limit']) ? 5 : (int) $parameters['limit'];
$type = empty($parameters['type']) ? 0 : 1;
$image = empty($parameters['image']) ? 0 : (int) $parameters['image'];

$request = $smcFunc['db_query']('','
SELECT
m.id_topic, m.subject, m.poster_name, c.picture, c.name,
mem.id_member, mem.real_name, mem.avatar,
at.id_attach, at.attachment_type, at.filename
FROM {db_prefix}sp_articles AS a
INNER JOIN {db_prefix}sp_categories AS c ON (c.id_category = a.id_category)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_message)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}attachments AS at ON (at.id_member = mem.id_member)
WHERE {query_see_board}
AND a.approved = {int:approved}
ORDER BY {raw:type}
LIMIT {int:limit}',
array(
'approved' => 1,
'type' => $type ? 'RAND()' : 'm.poster_time DESC',
'limit' => $limit,
)
);
$articles = array();
$colorids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (!empty($row['id_member']))
$colorids[$row['id_member']] = $row['id_member'];

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 = '';
}

$articles[] = array(
'id' => $row['id_topic'],
'name' => $row['subject'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>',
'poster' => array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
),
'image' => array(
'href' => $row['picture'],
'image' => '<img src="' . $row['picture'] . '" alt="' . $row['name'] . '" />',
),
'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($articles))
{
echo '
', $txt['error_sp_no_articles_found'];
return;
}

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

if (empty($image))
{
echo '
<ul class="sp_list">';

foreach ($articles as $article)
echo '
<li>', sp_embed_image('topic'), ' ', $article['link'], '</li>';

echo '
</ul>';
}
else
{
echo '
<table class="sp_fullwidth sp_articles">';

foreach ($articles as $article)
{
echo '
<tr>
<td class="sp_articles sp_center">';

if (!empty($article['avatar']['href']) && $image == 1)
echo '<img src="', $article['avatar']['href'], '" alt="', $article['poster']['name'], '" width="40" />';
elseif (!empty($article['image']['href']) && $image == 2)
echo '<img src="', $article['image']['href'], '" alt="', $article['name'], '" width="40" />';

echo '</td>
<td>
<span class="sp_articles_title">', $article['poster']['link'], '</span><br />
', $article['link'], '
</td>
</tr>';
}

echo '
</table>';
}
}
Into this:
Code: [Select]
function sp_articles($parameters, $id, $return_parameters = false)
{
global $smcFunc, $modSettings, $scripturl, $txt, $color_profile;

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

if ($return_parameters)
return $block_parameters;

$limit = empty($parameters['limit']) ? 5 : (int) $parameters['limit'];
$type = empty($parameters['type']) ? 0 : 1;
$image = empty($parameters['image']) ? 0 : (int) $parameters['image'];

$request = $smcFunc['db_query']('','
SELECT
m.id_topic, m.subject, m.poster_name, c.picture, c.name,
mem.id_member, mem.real_name, mem.avatar,
at.id_attach, at.attachment_type, at.filename
FROM {db_prefix}sp_articles AS a
INNER JOIN {db_prefix}sp_categories AS c ON (c.id_category = a.id_category)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_message)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}attachments AS at ON (at.id_member = mem.id_member)
WHERE {query_see_board}
AND a.approved = {int:approved}
ORDER BY {raw:type}
LIMIT {int:limit}',
array(
'approved' => 1,
'type' => $type ? 'RAND()' : 'm.poster_time DESC',
'limit' => $limit,
)
);
$articles = array();
$colorids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (!empty($row['id_member']))
$colorids[$row['id_member']] = $row['id_member'];

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 = '';
}

$articles[] = array(
'id' => $row['id_topic'],
'name' => $row['subject'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>',
'poster' => array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
),
'image' => array(
'href' => $row['picture'],
'image' => '<img src="' . $row['picture'] . '" alt="' . $row['name'] . '" />',
),
'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($articles))
{
echo '
', $txt['error_sp_no_articles_found'];
return;
}

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

if (empty($image))
{
echo '
<ul class="sp_list">';

foreach ($articles as $article)
echo '
<li>', $article['link'], '<br />', $item['time'], '<br /><hr /></li>';

echo '
</ul>';
}
else
{
echo '
<table class="sp_fullwidth sp_articles">';

foreach ($articles as $article)
{
echo '
<tr>
<td class="sp_articles sp_center">';

if (!empty($article['avatar']['href']) && $image == 1)
echo '<img src="', $article['avatar']['href'], '" alt="', $article['poster']['name'], '" width="40" />';
elseif (!empty($article['image']['href']) && $image == 2)
echo '<img src="', $article['image']['href'], '" alt="', $article['name'], '" width="40" />';

echo '</td>
<td>
<span class="sp_articles_title">', $article['poster']['link'], '</span><br />
', $article['link'], '
</td>
</tr>';
}

echo '
</table>';
}
}

I changed this part of that block:

Code: [Select]
<li>', $article['link'], '<br />', $item['time'], '<br /><hr /></li>';
Now it works, but it doesn't display the time. I get this error message:
Quote
8: Undefined variable: item

I guess this is the time variable. How should I define it?
Title: Re: Where do I look...
Post by: AngelinaBelle on January 21, 2011, 10:08:55 AM
I misunderstood you.  I thought you were planning to change the overall appearance of all blocks. 
 
But if you want to change the contents of the articles block, you did find the right place to do that.
 
Now it works, but it doesn't display the time. I get this error message:
Quote
8: Undefined variable: item

I guess this is the time variable. How should I define it?
I don't know how you should define it, because I don't know what you wish it to be. Time of what? Where do you wish to get that time from? When you know that, then you will know what to put in your code.
Title: Re: Where do I look...
Post by: willemjan on January 21, 2011, 10:18:37 AM
I'm sorry, I should have explained it a bit more...

I got that $item['time'] from the recent posts block, wich is:
Code: [Select]
function sp_recent($parameters, $id, $return_parameters = false)
{
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 = empty($parameters['display']) ? 'compact' : '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>';
}
}

You'll find the time attribute here:
Code: [Select]
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 />' : '';
}
It shows the date/time of when the reply/topic got posted.
Title: Re: Where do I look...
Post by: AngelinaBelle on January 21, 2011, 03:55:05 PM
OK. but in sp_articles, the developer decided to stuff everything in an array called $articles. So, in sp_articles, $item does not exist.
 
You could certainly add m.poster_time  to the SQL statement, stuff it into the $articles array (a good example is function ssi_queryPosts, where it is stuffed in an array called $posts. sp_recent gets its data from ssi_queryPosts, actually)
 
Then it would be available in the loop
 
foreach ($articles as $article), and you could have $article['time'], if you set it up that way beforehand.
Title: Re: Where do I look...
Post by: willemjan on January 22, 2011, 06:57:50 AM
Ok, I dont understand all of what you said, but I tried the following. I added m.poster_time to the db query:

Code: [Select]
$request = $smcFunc['db_query']('','
SELECT
m.id_topic, m.subject, m.poster_name, m.poster_time, c.picture, c.name,
mem.id_member, mem.real_name, mem.avatar,
at.id_attach, at.attachment_type, at.filename

Then I defined it in the $articles array:

Code: [Select]
$articles[] = array(
'id' => $row['id_topic'],
'name' => $row['subject'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['subject'] . '</a>',
'time' => $row['m.poster_time'],
'poster' => array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',

And I changed the code:
Code: [Select]
foreach ($articles as $article)
echo '
<li>', $article['link'], '<br />', $articles['time'], '<br /><hr /></li>';

But things are still not showing. Now I never made an db query before, so I guess there is something wrong in there. Got an clue? Thank you very much for all your help so far  :applause:
Title: Re: Where do I look...
Post by: willemjan on January 22, 2011, 08:05:11 AM
Hmm... Nevermind, I figured that it would look better without the date ;)
Title: Re: Where do I look...
Post by: AngelinaBelle on January 22, 2011, 07:21:42 PM
Very good job!
 
I would make only these two little changes:
Code: [Select]
'time' => $row['poster_time'],and
Code: [Select]
$article['time'],
This is a good introduction to php for you.
You can read more, perhaps at w3schools.com.
 
Even if you changed your mind about this one, it is a good experience for the next time.
Title: Re: Where do I look...
Post by: willemjan on January 25, 2011, 05:42:36 AM
Thanks, I will try that for the practice! Thank you very much for all your help!  :thumbsup:
SimplePortal 2.3.8 © 2008-2024, SimplePortal