News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

SMF Post Prefix

Started by Diego Andrés, May 11, 2015, 10:37:35 PM

Previous topic - Next topic

Diego Andrés

That should work.
Make sure it's the correct language name and it's translated properly.

SMF Tricks - Free & Premium Responsive Themes for SMF.

mickjav

#481
Created The final Part of may artists homepage.

I use the Prefixes so I have built a Recent posts for each artist that uses the prefixes.

you can see it here

In your table set the field that holds the prefix to a default of 0 or edit the line of code below

$context['prefix'] holds my Prefix ID for selected artist change for your Prefix id

Code ("In your template add the following line where you want the list") Select
//Recent Topics
        if ($context['prefix'] !=0) GetHomeRecentPosts($context['prefix']);

Code ("Add to your language file") Select
$txt['Music_artists_recent_posts'] = 'Recent Posts';
If you see any errors of can help improve the below code please post it here.

Code ("Function to be added to your file") Select
function GetHomeRecentPosts($prefix)
{
global $smcFunc, $scripturl, $txt;

$link = '';
$title = '';

$dbquery = $smcFunc['db_query']('', '
    SELECT t.id_topic ,t.id_last_msg ,t.id_board, t.id_first_msg, t.id_member_started, t.num_views, t.id_prefix,
t.num_replies, t.locked, t.approved, m.id_msg, m.id_member, m.poster_time, m.subject, m.poster_name, m.approved,
mg.online_color, mem.real_name
    FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (t.id_last_msg = m.id_msg)
LEFT JOIN {db_prefix}members AS mem ON (m.id_member = mem.id_member)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))
WHERE t.id_prefix = {int:id_prefix}
ORDER BY m.poster_time DESC
LIMIT 5',
array(
'id_prefix' => (int) $prefix,
)
);

if ($smcFunc['db_affected_rows']() != 0)
    {
echo'<br /><div class="cat_bar">
    <h3 class="catbg">'. $txt['Music_artists_recent_posts'] .'</h3>
</div>';

echo '<div class="roundframe"><table border="0" Width="100%"><tbody>';

echo '<tr class="title_bar">
<th style="colspan=col">Message</th>
<th scope="col">Author</th>
<th scope="col">Date</th>
</tr>';

while($row = $smcFunc['db_fetch_assoc']($dbquery))
{
if (!empty($row['online_color']))
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
else
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';

$title = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg'. $row['id_last_msg'] .';topicseen#msg'. $row['id_last_msg'] . '">' . $row['subject'] . '</a>';

echo  '<tr>
<td style="text-align: left; width: 60%">' . $title . '</td>
<td style="text-align: left; width: 20%">' . $link . '</td>
<td style="text-align: left; width: 20%">' . date("Y-m-d H:i:s",$row['poster_time']) . '</td></tr>';

}

echo '</tbody></table></div>';
}

}

mickjav

Have Updated the code so only the selected board(s) posts will be displayed but can't update the above as timed out for edits.

Edit this AND t.id_board IN(126,128) For the boards you wish to display

function GetHomeRecentPosts($prefix)
{
global $smcFunc, $scripturl, $txt;

$link = '';
$title = '';

$dbquery = $smcFunc['db_query']('', '
    SELECT t.id_topic ,t.id_last_msg ,t.id_board, t.id_first_msg, t.id_member_started, t.num_views, t.id_prefix,
t.num_replies, t.locked, t.approved, m.id_msg, m.id_member, m.poster_time, m.subject, m.poster_name, m.approved,
mg.online_color, mem.real_name
    FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (t.id_last_msg = m.id_msg)
LEFT JOIN {db_prefix}members AS mem ON (m.id_member = mem.id_member)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))
WHERE t.id_prefix = {int:id_prefix} AND t.id_board IN(126,128)
ORDER BY m.poster_time DESC
LIMIT 5',
array(
'id_prefix' => (int) $prefix,
)
);

if ($smcFunc['db_affected_rows']() != 0)
    {
echo'<br /><div class="cat_bar">
    <h3 class="catbg">'. $txt['Music_artists_recent_posts'] .'</h3>
</div>';

echo '<div class="roundframe"><table border="0" Width="100%"><tbody>';

echo '<tr class="title_bar">
<th style="colspan=col">Message</th>
<th scope="col">Author</th>
<th scope="col">Date</th>
</tr>';

while($row = $smcFunc['db_fetch_assoc']($dbquery))
{
if (!empty($row['online_color']))
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
else
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';

$title = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg'. $row['id_last_msg'] .';topicseen#msg'. $row['id_last_msg'] . '">' . $row['subject'] . '</a>';

echo  '<tr>
<td style="text-align: left; width: 60%">' . $title . '</td>
<td style="text-align: left; width: 20%">' . $link . '</td>
<td style="text-align: left; width: 20%">' . date("Y-m-d H:i:s",$row['poster_time']) . '</td></tr>';

}

echo '</tbody></table></div>';
}

}



mickjav

Request:

Not Shure if I've formatted the link incorrectly, I am trying to create a create a new post with the Prefix pre selected.

This is the link that is created for a artist.

https://www.databasedreams.co.uk/charts/artists-charts-analysis/?action=post;prefix=267

Steve

@Diego Andrés - there's a serious issue (at least, serious to me) with this mod.

If I create a prefix and have it show in boards:

A
B
C
D

And then delete boards C and D (or only just D), I have to now go to the prefix settings and just save it again without changing anything in order for it to be available for boards A and B.

I have almost 200 prefixes and it's going to take me a long time to re-save each and every one.

Is there a fix for this?
DO NOT pm me for support!

mickjav

does that give you orphaned Records in postprefixes_boards if so I would delete those records for boards C and D depending on which you deleted.

mick

mickjav

I use this to add current prefixes to a new board.

function addPrefixBoard()
{
//DONT USE UNLESS ADDING NEW BOARDS
        global $smcFunc;

$board = 75; //Change as needed.
        //Loop Through Prefixes Adding The Board
    $boardquery = $smcFunc['db_query']('', '
    SELECT id
    FROM {db_prefix}postprefixes');

        while ($brow = $smcFunc['db_fetch_assoc']($boardquery))
        {
            $prefix = $brow['id'];
            $smcFunc['db_query']('', "INSERT INTO {db_prefix}postprefixes_boards
                    (id_prefix, id_board)
                    VALUES('$prefix', '$board')");
        }
        $smcFunc['db_free_result']($boardquery);


}

Diego Andrés

It's indeed a bug, because the query is using a left join so those boards don't exist anymore.
I'll fix it in a bit.


SMF Tricks - Free & Premium Responsive Themes for SMF.

Steve

DO NOT pm me for support!

peter_mein

Hello
How can i delete a Prefix ?
If an user used a prefix, how can i delete this prefix from the user ?

 

Diego Andrés

You can edit the post and remove the prefix from it... I'm not sure what you mean.
You can also limit their permissions or put this user in a group where they can't use that specific prefix.

SMF Tricks - Free & Premium Responsive Themes for SMF.

Diego Andrés

4.1.0 - 07 January 2023
  • Improvement Allow passing prefixes in the URL when posting to have them pre-selected.
  • Improvement Deleting groups will now drop them from the table.
  • Improvement Deleting boards will now drop them from the table.
  • Bug Fix Fixed query for getting prefixes when boards are missing.

@mickjav If you modified files from the mod, you can check the individual commits on GitHub to update your files.

SMF Tricks - Free & Premium Responsive Themes for SMF.

peter_mein

Ok
Found it.
I ticked too many in the settings. Now it works as I wanted

mickjav

No I haven't edited the files as to be honest they are still a bit beyond me Think It will be at least a year before I feel confident enough to edit them not that I need to as your doing a very nice job.

Thank you for adding the "Allow passing prefixes in the URL when posting to have them pre-selected" That sorts my OCD lol.

I'll uninstall and update hopefully tomorrow.

All the best mick

peter_mein

Not solved my problem.
If I put a prefix in a contribution and want it
subsequently delete the prefix so this is not possible.
I edit the contribution and select no prefix. If I now go to save now the text appears that I should choose a prefix.
See attachement

Diego Andrés

Then don't require prefixes in that board if you are planning to have topics without prefix.

SMF Tricks - Free & Premium Responsive Themes for SMF.

peter_mein

And why can I then select no prefix?
Then it makes no sense

Steve

Awesome Diego! Works like a charm!
DO NOT pm me for support!

peter_mein

No prefix is needed when moving a post.
If prefixes are allowed in a board and I move a post to a board
where no prefixes are allowed, the prefix is moved with it
and you can no longer delete it.


Diego Andrés

My only guess is that you are having this issue if you enable the option to remove "No Prefix"?
Otherwise I don't understand how you are unable to choose "No prefix", unless you still have this board requiring prefixes.

SMF Tricks - Free & Premium Responsive Themes for SMF.

Advertisement: