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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,966
  • Latest: safir45
Stats
  • Total Posts: 195,993
  • Total Topics: 21,324
  • Online today: 388
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 327
  • Total: 327

[Block] recentPosts dropdown in a block

Started by IchBin, August 05, 2007, 02:37:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

IchBin

At the request of another user. I have put together a php block code snippet that should grab all the boards in your forum and put them into a dropdown menu. You can then select the board you would like to see the recentPosts from. I don't have the time to customize this to everyone's needs. Feel free to do so at your own discretion.

Create a new phpbox type of block and add this code to it:
global $db_prefix, $context, $user_info;


// Find the boards/cateogories they can see.
$request = db_query("
SELECT c.name AS catName, c.ID_CAT, b.ID_BOARD, b.name AS boardName, b.childLevel
FROM {$db_prefix}boards AS b
LEFT JOIN {$db_prefix}categories AS c ON (c.ID_CAT = b.ID_CAT)
WHERE $user_info[query_see_board]", __FILE__, __LINE__);
$context['jump_to'] = array();
$this_cat = array('id' => -1);
while ($row = mysql_fetch_assoc($request)){
if ($this_cat['id'] != $row['ID_CAT'])
{
$this_cat = &$context['jump_to'][];
$this_cat['id'] = $row['ID_CAT'];
$this_cat['name'] = $row['catName'];
$this_cat['boards'] = array();
}

$this_cat['boards'][] = array(
'id' => $row['ID_BOARD'],
'name' => $row['boardName'],
'child_level' => $row['childLevel'],
'is_current' => isset($context['current_board']) && $row['ID_BOARD'] == $context['current_board']
);
}
mysql_free_result($request);

echo '<form action="',$scripturl,  '?', $_SERVER['QUERY_STRING'],'" method="post">
<select id="moveItTo" name="move_to">';

foreach ($context['jump_to'] as $category){
foreach ($category['boards'] as $board){
echo '<option value="', $board['id'], '">', str_repeat('-', $board['child_level'] + 1), ' ', $board['name'], '</option>';
}
}

  echo '</select>
<input type="submit" name="mySubmit" value="Submit">
      </form>';

if (isset($_POST['mySubmit'])){
$temp = $user_info['query_see_board'];
$user_info['query_see_board'] .= "\nAND b.id_board = " .(int) $_POST['move_to'];
ssi_recentPosts();
$user_info['query_see_board'] = $temp;
}


Thanks to winrules for all the help. Couldn't have done it without his help. :)

Ken.

Sounds like a great snippet IchBinâ„¢, got to try this on for sure.  :)
" If everything seems under control, you're not going fast enough." - Mario Andretti
Yesterday When I was Young.

jdvarner

Nice IchBin.

Do you have code to center? Using in center block and also can it direct to the actual forum board versus refreshing inscreen with recent posts?

Just thought i'd ask. :)

jpark


IchBin

To redirect to the topic you can change this line:
echo '<form action="',$scripturl,  '?', $_SERVER['QUERY_STRING'],'" method="post">

To this:
echo '<form action="',$scripturl,  '?board='.$_POST['move_to'].'" method="post">

As for centering it, you can just change this code:
if (isset($_POST['mySubmit'])){
$temp = $user_info['query_see_board'];
$user_info['query_see_board'] .= "\nAND b.id_board = " .(int) $_POST['move_to'];
ssi_recentPosts();
$user_info['query_see_board'] = $temp;
}


To This:
if (isset($_POST['mySubmit'])){
$temp = $user_info['query_see_board'];
$user_info['query_see_board'] .= "\nAND b.id_board = " .(int) $_POST['move_to'];
echo '<center>';
ssi_recentPosts();
echo '</center>';
$user_info['query_see_board'] = $temp;
}

jdvarner


jpark

i changed the recentPosts to recentTopics but do you know how i would get the original topic author instead of the last post author? (so sorted by first post date and with first post author) 

Also, how can I get a default list (without selecting any board) showing all recent topics from all different boards.  Then you can specify which board you want to see recent topics from with the drop-down selection.

Ichbin, I appreciate your help so far and I know you said you're busy.. so if anyone else knows, I would really appreciate it!

I attached a sample picture for what I'm trying to get...  Thanks!

IchBin

To have a default recentPosts you can just add a else statement at the end.

else {
ssi_recentPosts();
}

This means if the submit button has not been pushed it should automatically do a recentPosts call by default with no board selected.

As for the author problem, I'll have to see if I can look at that later if I get some time.

jpark

that's great!

I got some of the things I was looking for by changing the recentTopics ssi

After this:// Just return it.
if ($output_method != 'echo' || empty($posts))
return $posts;

echo '
<table border="0" class="ssi_table">';


I added:

echo '
<tr class="titlebg">
<td width="20%">Category</td>
<td>Title</td>
<td width="10%" align="center">Date</td>
</tr>';


I also left-aligned the [board] column.

I don't know if it's good to mess around with the ssi code or rather make the changes on the block code... hopefully it's okay.

I guess i'll look around to see how to make changes to get original poster and ordered by first post.. I know the information is here.. i just gotta look for it :)

I would also like to find how to add a drop-down selection titled "All Categories" to go back to the default selection..

Is there a way to get the refresh to happen only inside the block and not the whole page?  Thanks so much for all your help!

IchBin

I try not to edit any SMF files whenever possible. As to get the author etc. you can tell it to output the array. If you look at the other recentTopic/recentPosts code snippets you can see how they work this out.

The other drop down you're talking about I don't have the time to look into. As for the block refresh instead of the page that would require ajax which I know absolutely nothing about...

This website is proudly hosted on Crocweb Cloud Website Hosting.