TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

April 18, 2024, 04:55:09 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,164
  • Total Topics: 21,219
  • Online today: 203
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 193
  • Total: 193

help to change the "normal" block "recent topics"

Started by dan4ever, June 22, 2021, 03:40:22 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dan4ever

hi

Where can I change the built in block "recent topics".
I want the user how posted not bold text and the topic bold instead.
And if you klick on the avatar I will come to the post, not the profil!!!!!

And maybe lite text from the post too if its possible.

/Dan

@rjen

If you want to change the layout of the standard recent topics you will have to edit this file: TPsubs.template.php

Look for the section that starts with:
// blocktype 12: Recent Topics
Running Latest TP on SMF2.1 at: www.fjr-club.nl

dan4ever

or maybe ask if I can use an "php-box" I used with my last portal?
But it's not working just like that, somebody have to look into the code and fix a little, I think.
I post it here and say what u think:

<?php

/* Recent posts with post preview */

/* SETUP */

$topics_posts 1; // TOPICS - 1 | MESSAGES - 2
$limit 25; // How many recent posts do you want to output?
$number 90; // How many characters do you want to output?
$exclude_boards = array( 444586); // IF null guests can see all boards | IF you want to hide some boards use: array( ID1, ID2, ID3) where ID is the board's ID
$htmlspecialcharacters true// Do you need to show html special characters like Greek characters?

// Scroll Enable? Height and Speed?
$scrolling =0;       // ENABLE - 1 | DISABLE - 2
$speed 3;           // SLOW - 1 | MEDIUM - 10 | FAST - 20
$height "350px";
$scrollbar 0;       // ENABLE - 1 | DISABLE - 2

// Do you want to translate it to your own language? :P
$text['board'] = 'i';
$text['who'] = 'av';

/* [STOP!] - THIS IS THE END OF SETUP */

//Only code from now on ;)
global $smcFunc$scripturl$sourcedir$modSettings$user_info$settings$context;


// Let's grab some database results
if ($topics_posts == 1) {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, t.id_member_updated, m.subject, m.body, m.id_topic, b.name, t.id_last_msg, u.avatar, g.online_color,' 
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from'
) . '
   FROM {db_prefix}topics AS t
   LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
   LEFT JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
   LEFT JOIN {db_prefix}members AS u ON (t.id_member_updated = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '     
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY t.id_last_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member_updated']);
      
loadMemberContext($row_posts['id_member_updated']);

   
$posts[] = array(
  'id' => $row_posts['id_member_updated'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member_updated'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . ' ' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_last_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member_updated']]['avatar']['href'] : (stristr($row_posts['avatar'], 'https://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'], 
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

} else {

if (is_array($exclude_boards) || (int) $exclude_boards === $exclude_boards)
{
$exclude_boards is_array($exclude_boards) ? $exclude_boards : array($exclude_boards);
}
elseif ($exclude_boards != null)
{
$output_method $exclude_boards;
$exclude_boards = array();
}

$posts_result $smcFunc['db_query']('''
   SELECT m.poster_name, m.poster_time, m.id_msg, m.id_member, m.subject, m.body, m.id_topic, b.name, b.id_board, u.avatar, g.online_color,' 
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from'
) . '
   FROM {db_prefix}messages AS m
   LEFT JOIN {db_prefix}boards AS b ON (m.id_board = b.id_board)
   LEFT JOIN {db_prefix}members AS u ON (m.id_member = u.id_member)
   LEFT JOIN {db_prefix}membergroups AS g ON (g.id_group = CASE WHEN u.id_group = 0 THEN u.id_post_group ELSE u.id_group END)
   ' 
. (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = ' 
$user_info['id'] . ')
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = ' 
$user_info['id'] . ')' '') . '   
   WHERE m.approved=1'   
. (empty($exclude_boards) ? '' '
AND b.id_board NOT IN ({array_int:exclude_boards})'
) . ' AND {query_see_board}
   ORDER BY m.id_msg DESC
   LIMIT ' 
$limit
array(
'exclude_boards' => empty($exclude_boards) ? '' $exclude_boards,
)   
   );
$posts = array();
while (
$row_posts $smcFunc['db_fetch_assoc']($posts_result))
{

      global 
$memberContext;
      
loadMemberData($row_posts['id_member']);
      
loadMemberContext($row_posts['id_member']);

   
$posts[] = array(
  'id' => $row_posts['id_member'],
      
'username' => '<a style="color: ' $row_posts['online_color'] . ';" href="' $scripturl '?action=profile;u=' $row_posts['id_member'] . '">' $row_posts['poster_name'] . '</a>',
      
'subject' => '<a style="font-weight: bold;" title="' $text['board'] . ' ' $row_posts['name'] .'" href="' $scripturl '?topic=' $row_posts['id_topic'] . '.msg' $row_posts['id_msg'] . ';topicseen#new">' $row_posts['subject'] . '</a>',
      
'body' => $row_posts['body'],
  'avatar' => $row_posts['avatar'] == '' $memberContext[$row_posts['id_member']]['avatar']['href'] : (stristr($row_posts['avatar'], 'https://') ? $row_posts['avatar'] : $modSettings['avatar_url'] . '/' $row_posts['avatar']),
  'board' => $row_posts['name'],  
  'time' => timeformat($row_posts['poster_time']),
  'new' => !empty($row_posts['is_read'])
   );
}
$smcFunc['db_free_result']($posts_result);

}

//Finally the Output

//Scrolling xD
if ($scrolling == 1)
echo 
'<div style="overflow: hidden;"><marquee height=' $height ' behavior="scroll" direction="up" scrollamount="' $speed '" onmouseover="this.stop()" onmouseout="this.start()">';

if (
$scrollbar == 1)
echo 
'<div style="height:' $height '; overflow-y: scroll; overflow-x: hidden;">';

foreach (
$posts as $post) {

// Lets fix the BBCode bug and Strip the Text
$content1 str_replace("[""<"$post['body']);
$content2 str_replace("]"">"$content1); 
$content3 strip_tags($content2);
$preview substr ($content3,0,$number);

echo
'<table>
<tr>
<td style="width: 40px;">
<img src="' 
$post['avatar'] .'" alt="" width="40px" height="40px" />
</td>
<td>
$post['subject'];

if (!$post['new'] && $context['user']['is_logged'])
echo ' <img src="'$settings['images_url'], '/'$context['user']['language'], '/new.gif" alt="new" border="0" />';

echo '<br />
<small>' 
$text['who'] . ' ' $post['username'] . ' | ' $post['time'] .'</small>
</td>
</tr>
</table>'
;

if ($htmlspecialcharacters) {
echo htmlspecialchars($previewENT_NOQUOTES"UTF-8") . '...';
} else {
echo $preview '...';
}

echo 
'<hr />';
}
        
//Scrolling xD
if ($scrollbar == 1)
echo 
'</div>'

if (
$scrolling == 1)
echo 
'</marquee></div>';

?>

@rjen

Of course, a php block can be used , but that's not what you asked for...
Running Latest TP on SMF2.1 at: www.fjr-club.nl

dan4ever

Quote from: @rjen on June 25, 2021, 02:44:53 PM
Of course, a php block can be used , but that's not what you asked for...
No, you're so right
I started by asking for a "Facebook-flow", and now this...
I'm never satisfied until perfection  O0

And later on maybe some mod to the "Recent posts"

/Dan

tino

What's not working with the php block you posted? It should work as before as it's not using any custom calls from a portal by what I can see.

lurkalot

Quote from: tino on June 26, 2021, 01:49:10 PM
What's not working with the php block you posted? It should work as before as it's not using any custom calls from a portal by what I can see.

Works for me. Although you will have to remove the php tags from the start and end of the code for it to work.

<?php

and

?>


dan4ever

#7
So simple, Thanks a lot!!!!

The member with no profil Picture(avatar) have a broken picture. (if u understand me?)
aren't there a "default"-avatar ??

/Dan

tino

The &quote is an entity decoding issue. Does it do it using the built in TinyPortal Recent posts? If it doesn't then you'll have to look at what that's doing for the entities.

The missing avatar will be the link, you probably have errors in the logs? If so you need to check they exist first if not go to the default one.

dan4ever

Quote from: tino on June 28, 2021, 07:47:20 PM
The missing avatar will be the link, you probably have errors in the logs? If so you need to check they exist first if not go to the default one.
No error in logs. 
But found this in "java-consul":
<img src="" alt="" width="40px" height="40px">

But if I go into the forum and look at the same member, java-consul says:
<span class="no_avatar Nybörjare">G</span>
And "Nybörjare" are a group a made like "newbie"

But does SMF have a default pic for a member?
$modSettings['avatar_url'] is empty
/Dan

@rjen

No, SMF2.0 does NOT, so if you want a default to show, you will need to code that yourself in the block. From what I am seeing your block code does not make that exception, so it tries to show an avatar every time...

I do not have the code you need available, so you will have to try it out yourself...
Running Latest TP on SMF2.1 at: www.fjr-club.nl