News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

SMF Post Prefix

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

Previous topic - Next topic

peter_mein

Everything OK. The cache was not yet rewritten and
still showed me the old state.

mickjav

Hi I'm sure this request will only be related to what I'm doing.

What I have done:

I have built A Synce To My Chart Weeks So when new weeks are added it creates the corresponding prefix and links it to the Chart Week.

My prefix name is created so:
2020 Jul 09: UK Singles Chart:
2020 Jun 13: Billboard Hot 100 Singles:
2020 Feb 06: UK Albums Chart:

This all works fine but my question/request is would of be possible For specific boards to to be able to change the sort order from ASC to DESC The board I wish the order to be changed for is board_ID 136

if there is a code change I could make please let me know.

Just in case it's of use to others i've posted the code.
this is what I built to synce the prefixes and chart weeks

The call is set so only admin runs it "Q: Is there a is admin context?"
//Add Any New Chart Weeks To The Prexixes
        if ($context['user']['is_guest'])
        $mem_id = 0;
        else
        $mem_id = $context['user']['id'];
        //Only Run For Admin
        if ($mem_id == 1) CheckForNewChartWeeks();

The two functions below do the work, You will need to update the "id_prefix = 805" to what you need plus I have added a tag to the prefixes table to make managing them simpler "p_type"

function CheckForNewChartWeeks()
{
    global $smcFunc;
   
    $prefix_name = '';
   
    $dbquery = $smcFunc['db_query']('', '
    SELECT w.week_id, w.wkend, c.chart_name, c.chart_name_short, c.use_prefix
    FROM {db_prefix}chart_weeks AS w
    INNER JOIN {db_prefix}chart_names AS c ON (w.chart_id = c.chart_id)
    WHERE w.prefix_id = 0 AND YEAR(w.wkend) >= 2020 AND c.use_prefix = 1
    ORDER BY YEAR(w.wkend) DESC');
       
    if ($smcFunc['db_affected_rows']() != 0)
    {
        while($row = $smcFunc['db_fetch_assoc']($dbquery)){
        $prefix_name = date("Y M d",strtotime($row['wkend'])) . ': ' .(strlen($row['chart_name_short'])>0 ? $row['chart_name_short'] : $row['chart_name']) . ':';
        addChartWeeksPrefix($row['week_id'], $prefix_name, 3);
        }
    }       
   
        $smcFunc['db_free_result']($dbquery);
}

//Auto Add Prefixes To Artists
function addChartWeeksPrefix($id, $prefix_name, $typ)
{

        global $smcFunc;

        isAllowedTo('music_can_edit_artists');
   
       
        $smcFunc['db_query']('', "INSERT INTO {db_prefix}postprefixes
                    (name, p_type)
                    VALUES('$prefix_name', '$typ')");
                   
        $prefix = $smcFunc['db_insert_id']('{db_prefix}postprefixes', 'id');
       
    //Update The Chart Week
    $smcFunc['db_query']('', "UPDATE {db_prefix}chart_weeks
                    SET prefix_id = '$prefix'
                    WHERE week_id = $id LIMIT 1");
   
    //Do Boards
    $boardquery = $smcFunc['db_query']('', '
    SELECT id_board
    FROM {db_prefix}postprefixes_boards
    WHERE id_prefix = 805');


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

    //Do Permissions
    $groupquery = $smcFunc['db_query']('', '
    SELECT id_group
    FROM {db_prefix}postprefixes_groups
    WHERE id_prefix = 805');


        while ($grow = $smcFunc['db_fetch_assoc']($groupquery))
        {
            $group = $grow['id_group'];
            $smcFunc['db_query']('', "INSERT INTO {db_prefix}postprefixes_groups
                    (id_prefix, id_group)
                    VALUES('$prefix', '$group')");
        }
        $smcFunc['db_free_result']($groupquery);       
       
}

Steve

I may have come across a bug. When I have a board that requires prefixes and have 'Remove 'No prefix' from the list when the board requires a prefix.' selected, the 'No Prefix' still shows in the boards requiring a prefix. Can you confirm Diego?
DO NOT pm me for support!

Diego Andrés

Quote from: mickjav on January 09, 2023, 03:57:16 AMThis all works fine but my question/request is would of be possible For specific boards to to be able to change the sort order from ASC to DESC The board I wish the order to be changed for is board_ID 136
Prefixes are added globally so they can be available easier.

In PostPrefix/PostPrefix.php
Add $board to the globals.
Code (Search) Select
$context['user_prefixes']['post'] = Database::pNested(
'pp.' . (!empty($modSettings['PostPrefix_select_order']) ? 'id' : 'name')
Code (Replace) Select
$custom_boards = [1];
$custom_sorting = (!empty($board) && in_array($board, $custom_boards) ? ' DESC' : '');
$context['user_prefixes']['post'] = Database::pNested(
'pp.' . (!empty($modSettings['PostPrefix_select_order']) ? 'id' : 'name') . $custom_sorting

Just put your boards in the $custom_boards array: [2,5,453,67,223]





Quote from: Steve on January 12, 2023, 06:26:54 PMI may have come across a bug. When I have a board that requires prefixes and have 'Remove 'No prefix' from the list when the board requires a prefix.' selected, the 'No Prefix' still shows in the boards requiring a prefix. Can you confirm Diego?

I reckon a few pages ago on this topic it was suggested it worked this way to prevent users from submitting topics with whatever prefix appears first on the list.

SMF Tricks - Free & Premium Responsive Themes for SMF.

mickjav


Steve

Quote from: Steve on January 12, 2023, 06:26:54 PMI may have come across a bug. When I have a board that requires prefixes and have 'Remove 'No prefix' from the list when the board requires a prefix.' selected, the 'No Prefix' still shows in the boards requiring a prefix. Can you confirm Diego?
Quote from: Diego Andrés on January 12, 2023, 07:56:37 PMI reckon a few pages ago on this topic it was suggested it worked this way to prevent users from submitting topics with whatever prefix appears first on the list.
I don't think I understand. Why would the option be in the settings then?
DO NOT pm me for support!

Diego Andrés

I might remove it, or add a note that it doesn't apply for boards that require prefixes to prevent users from submitting topics without checking what prefix is selected.

SMF Tricks - Free & Premium Responsive Themes for SMF.

Steve

Ah, okay. Thanks Diego.
DO NOT pm me for support!

mickjav

Hi think this may relate to @vbgamer45 pretty urls

When I use the link I created
/charts/chart-analysis/?action=post;prefix=809 all works as intended,

But when I use the new topic button link I see the prefix id I.E. charts/chart-analysis/?prefix=1 but no prefix is preselected on the post screen.


All the best mick





Diego Andrés

For filtering the board? I wouldn't know how to support pretty urls.
But also you provided different examples, action=post would be different than just browsing the board without action=post

SMF Tricks - Free & Premium Responsive Themes for SMF.

mickjav

This is the link

https://www.databasedreams.co.uk/charts/artists-forums-126/?prefix=152 but I can't see the prefix in the new topic button url anymore??, that link filters the board for that prefix which is from my artists homepage
https://www.databasedreams.co.uk/charts/index.php?action=music;area=artists;sa=home;art=-1455642346

When I get on my pc ill look into this more as was sure the new topic button included the prefix? maybe I'm seeing things  :o



Diego Andrés

The new topic button does not add a prefix to the url when filtering, that's not a feature... yet.  :P
I'm not sure if you added the prefix to a custom url from the music action and that's why you thought it was the same behavior?

SMF Tricks - Free & Premium Responsive Themes for SMF.

mickjav

Thought I was going nuts lol

All the best mick

pulgatomika

Hello Diego Andres.
The first thing very good this mod, I discovered it yesterday and delighted with it, but I did not want to comment a couple of doubts I have and if it is possible to do so.
The first one. You could add more prefixes in the topics 2,3,4 the ones that are needed.
And the second one is possible to change the position of the prefixes, instead of going out before the title of the topic in the left part, to go out just under the title.
I hope to see me explained.
Greetings and very good mod.

Diego Andrés

Quote from: pulgatomika on February 23, 2023, 10:30:16 AMThe first one. You could add more prefixes in the topics 2,3,4 the ones that are needed.

No this won't be a feature because it's not a label or tags mod.


Quote from: pulgatomika on February 23, 2023, 10:30:16 AMAnd the second one is possible to change the position of the prefixes, instead of going out before the title of the topic in the left part, to go out just under the title.
Could be done changing the order in the code in the multiple files that add the prefix before the subject. In practice I don't think it's useful at all, defeats the purpose of being a prefix (it comes before).

SMF Tricks - Free & Premium Responsive Themes for SMF.

pulgatomika

Hello Diego Andres, thank you very much for the quick response, everything is very well explained.
Greetings.

DeadMan...

Quote from: Diego Andrés on May 11, 2015, 10:37:35 PMDisplay prefixes in the boardindex and latest posts
Display prefixes in the unread posts/replies action

I'm using NameX theme, and am not seeing the prefixes on board index, or recent posts.
Even when go to look at recent posts page, they are not showing.
I tell it how I see it... Don't like it? Hit Alt+F4!

Diego Andrés

I'll have a look later.
Did you enable it for posts too? Otherwise it only displays prefixes for the first post (topic).

SMF Tricks - Free & Premium Responsive Themes for SMF.

DeadMan...

Quote from: Diego Andrés on March 18, 2023, 06:58:39 PMI'll have a look later.
Did you enable it for posts too? Otherwise it only displays prefixes for the first post (topic).

Tried that, and still not showing.
Only seems to show in message index and topic view.
I tell it how I see it... Don't like it? Hit Alt+F4!

Diego Andrés

I'm not having any issues on my test forum. I also have a similar theme/setup on ST and it works fine there as well.
Perhaps some other mod is giving you this issue?

SMF Tricks - Free & Premium Responsive Themes for SMF.

Advertisement: