News:

Wondering if this will always be free?  See why free is better.

Main Menu

SMF Post Prefix

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

Previous topic - Next topic

Diego Andrés

What @jafl reported is indeed an issue I confirmed while browsing his site.

4.3.2 - 05 July 2023
  • Bug Fix Fixed modifying 'New Topic' url when it's not set.

SMF Tricks - Free & Premium Responsive Themes for SMF.

sbartelski

Quote from: TwitchisMental on June 29, 2023, 01:08:23 PM
Quote from: sbartelski on June 29, 2023, 12:54:15 PMDiego,
I like the look of your mod, but as an SMF noob I am not sure how to install it. I looked up 'hooks' in the SMF documentation and found it quite confusing. Do you, or someone else, have a step by step guide on installing a 'hooks' mod like yours?

TIA
Stefan
You do not need to worry about the "Hooks".

You are looking for how to install a mod package.

See more here - https://wiki.simplemachines.org/smf/SMF2.1:Package_manager

Thanks for the reply, I will try this out
Stefan
Stefan Bartelski
Webmaster for the Cadillac LaSalle Discussion forums

Diego Andrés

4.3.3 - 12 November 2023
  • New Feature Pre-select filtered prefixes when posting a new poll in boards.
List of changes

SMF Tricks - Free & Premium Responsive Themes for SMF.

CraftyLion

How do we add a padding to each prefix against their background? What css file would we need to use? Right now, it is touching the edges of the prefix ...

Diego Andrés

By default it has padding.
You can tweak the CSS in the Themes/default/css/postprefix.css file.

span.postprefix-all,
.postprefix-all {
    padding-inline: 5px !important;

SMF Tricks - Free & Premium Responsive Themes for SMF.

CraftyLion

#565
Unfortunately, tweaking the inline padding makes no difference to the pre-fix ...

However, I ended up adding more to the css code which seems work.

span.postprefix-all,
.postprefix-all {
padding-inline-start: 5px !important;
padding-inline-end: 5px !important;

Diego Andrés


SMF Tricks - Free & Premium Responsive Themes for SMF.

StarredSkies

Hello! Updating from 2.0.17 to 2.1.4 here.

When upgrading this mod after emulating/uninstalling, I am getting this error:
Unknown column 'pp.invert_color' in 'field list'
File: /home/DOMAIN/SUBDOMAIN/Sources/PostPrefix/Helper/Database.php
Line: 70

The databases postprefix_groups and _boards do not have any information in them. Is this to be expected upon installation?

After uninstalling dropping postprefix_groups and _boards (as mentioned here), there has been no change. I am afraid to drop postprefix from the database as I assume it has info that cannot be re-added.

Would there be another fix to this?

Diego Andrés

You'll need to make sure the new tables were created correctly.
Try uploading the install.php file from the package and run it directly from the browser {domain}/install.php

You can also open the file and just use it as a 'blueprint' to check if your columns are correct.

SMF Tricks - Free & Premium Responsive Themes for SMF.

StarredSkies

Sorry for the late reply.

Quote from: Diego Andrés on December 14, 2023, 12:36:38 AMTry uploading the install.php file from the package and run it directly from the browser {domain}/install.php
Tried this. Blank screen (which I presume is normal) and no changes.

Quote from: Diego Andrés on December 14, 2023, 12:36:38 AMYou can also open the file and just use it as a 'blueprint' to check if your columns are correct.
Just checked. Here's what I am seeing for postprefixes (information from 2.0 prefixes). Differences are 'status,' 'invert_color,' and 'icon_class.'

postprefixes_board

postprefixes_group


My assumption is that the first table isn't updating correctly, but what do I know about databases?
Still getting the error as listed above.

Diego Andrés

Okay, one idea that might work.

Edit the install.php file and change this:
'if_exists' => 'ignore',To:
'if_exists' => 'update',
You might get an error (irrelevant), but you will probably get the missing columns added.

Also, did your data change, is it now updated in the same table?

SMF Tricks - Free & Premium Responsive Themes for SMF.

Jotade29

In version 2.0.2 for version smf 2.0.19 there are a big problem security

@Diego Andrés

Any user, whether or not they have permission to use a prefix for their group, or for the forum, can use any prefix.

To do this, simply copy and paste the following fragment into the web inspector

<select name="id_prefix" id="id_prefix">
<optgroup label="Select Prefix">
<option value="0" selected="">[No Prefix]</option>
<option value="5">[icon]</option>
</optgroup>
</select>

They change the value to whatever they want in the prefix they select from the list, and they can use that prefix. Is this bug fixed for the 2.1 branch? If yes, how could i fix it for 2.0.19?
Quote from: Diego Andrés on August 12, 2023, 02:20:18 AMI'm afraid convincing Jotade to upgrade to SMF 2.1 will require bigger effort than your work sanitizing Unicode characters  :laugh:

Diego Andrés

Quote from: Jotade29 on March 28, 2024, 04:59:55 PMThey change the value to whatever they want in the prefix they select from the list, and they can use that prefix. Is this bug fixed for the 2.1 branch? If yes, how could i fix it for 2.0.19?

Yes.
It's solved using a master list of user's available prefixes.
https://github.com/SMFTricks/SMF-Post-Prefix/blob/8700fa4f34c5b97566973c39e91a8b0f74d1cf79/Sources/PostPrefix/PostPrefix.php#L174-L201

SMF Tricks - Free & Premium Responsive Themes for SMF.

Jotade29

Quote from: Diego Andrés on March 28, 2024, 05:45:56 PM
Quote from: Jotade29 on March 28, 2024, 04:59:55 PMThey change the value to whatever they want in the prefix they select from the list, and they can use that prefix. Is this bug fixed for the 2.1 branch? If yes, how could i fix it for 2.0.19?

Yes.
It's solved using a master list of user's available prefixes.
https://github.com/SMFTricks/SMF-Post-Prefix/blob/8700fa4f34c5b97566973c39e91a8b0f74d1cf79/Sources/PostPrefix/PostPrefix.php#L174-L201

@Diego Andrés
To fix this bug in 2.0.19 should i change that function to this one?

public static function load_theme() : void
    {
        global $user_info, $context, $modSettings;

        // It's only for post pages really...
        if (!isset($_REQUEST['action']) && empty($_REQUEST['action']) || ($_REQUEST['action'] !== 'post' && $_REQUEST['action'] !== 'post2'))
            return;

        // Load the prefixes
        if (($context['user_prefixes']['post'] = cache_get_data('user_postprefixes_u' . $user_info['id'], 600)) === null)
        {
            $context['user_prefixes']['post'] = Database::pNested(
                'pp.' . (!empty($modSettings['PostPrefix_select_order']) ? 'id' : 'name'), 'postprefixes AS pp',
                array_merge(array_merge(Database::$_prefix_normal, Database::$_boards_columns), Database::$_groups_columns), ['b.id_board'], 'boards',
                'WHERE pp.status = 1' . (allowedTo('postprefix_manage') ? '' : '
                    AND ppg.id_group ' . ($user_info['is_guest'] ? '= {int:guest}' : 'IN ({array_int:groups})')
                ),
                'LEFT JOIN {db_prefix}postprefixes_groups AS ppg ON (ppg.id_prefix = pp.id)
                LEFT JOIN {db_prefix}postprefixes_boards AS ppb ON (ppb.id_prefix = pp.id)
                RIGHT JOIN {db_prefix}boards AS b ON (b.id_board = ppb.id_board)',
                [
                    'groups' => array_unique(array_merge($user_info['groups'], [0])),
                    'guest' => -1,
                ]
            );
            cache_put_data('user_postprefixes_u' . $user_info['id'], $context['user_prefixes']['post'], 600);
        }
    }


The function that i have is very different

public static function load_theme()
{
global $context, $settings;

// Color picker
if ((isset($_REQUEST['action']) && ($_REQUEST['action'] == 'admin')) && (isset($_REQUEST['area']) && ($_REQUEST['area'] == 'postprefix')) && (isset($_REQUEST['sa']) && (($_REQUEST['sa'] == 'add') || ($_REQUEST['sa'] == 'edit'))))
{
$context['html_headers'] .= '
<script type="text/javascript">!window.jQuery && document.write(unescape(\'%3Cscript src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"%3E%3C/script%3E\'))</script>
<link rel="stylesheet" type="text/css" href="'. $settings['default_theme_url']. '/css/colpick.css" />
<script type="text/javascript" src="'. $settings['default_theme_url']. '/scripts/colpick.js"></script>';
}
}
Quote from: Diego Andrés on August 12, 2023, 02:20:18 AMI'm afraid convincing Jotade to upgrade to SMF 2.1 will require bigger effort than your work sanitizing Unicode characters  :laugh:

Jotade29

Quote from: Jotade29 on March 28, 2024, 06:27:39 PM
Quote from: Diego Andrés on March 28, 2024, 05:45:56 PM
Quote from: Jotade29 on March 28, 2024, 04:59:55 PMThey change the value to whatever they want in the prefix they select from the list, and they can use that prefix. Is this bug fixed for the 2.1 branch? If yes, how could i fix it for 2.0.19?

Yes.
It's solved using a master list of user's available prefixes.
https://github.com/SMFTricks/SMF-Post-Prefix/blob/8700fa4f34c5b97566973c39e91a8b0f74d1cf79/Sources/PostPrefix/PostPrefix.php#L174-L201

@Diego Andrés
To fix this bug in 2.0.19 should i change that function to this one?

public static function load_theme() : void
    {
        global $user_info, $context, $modSettings;

        // It's only for post pages really...
        if (!isset($_REQUEST['action']) && empty($_REQUEST['action']) || ($_REQUEST['action'] !== 'post' && $_REQUEST['action'] !== 'post2'))
            return;

        // Load the prefixes
        if (($context['user_prefixes']['post'] = cache_get_data('user_postprefixes_u' . $user_info['id'], 600)) === null)
        {
            $context['user_prefixes']['post'] = Database::pNested(
                'pp.' . (!empty($modSettings['PostPrefix_select_order']) ? 'id' : 'name'), 'postprefixes AS pp',
                array_merge(array_merge(Database::$_prefix_normal, Database::$_boards_columns), Database::$_groups_columns), ['b.id_board'], 'boards',
                'WHERE pp.status = 1' . (allowedTo('postprefix_manage') ? '' : '
                    AND ppg.id_group ' . ($user_info['is_guest'] ? '= {int:guest}' : 'IN ({array_int:groups})')
                ),
                'LEFT JOIN {db_prefix}postprefixes_groups AS ppg ON (ppg.id_prefix = pp.id)
                LEFT JOIN {db_prefix}postprefixes_boards AS ppb ON (ppb.id_prefix = pp.id)
                RIGHT JOIN {db_prefix}boards AS b ON (b.id_board = ppb.id_board)',
                [
                    'groups' => array_unique(array_merge($user_info['groups'], [0])),
                    'guest' => -1,
                ]
            );
            cache_put_data('user_postprefixes_u' . $user_info['id'], $context['user_prefixes']['post'], 600);
        }
    }


The function that i have is very different

public static function load_theme()
{
global $context, $settings;

// Color picker
if ((isset($_REQUEST['action']) && ($_REQUEST['action'] == 'admin')) && (isset($_REQUEST['area']) && ($_REQUEST['area'] == 'postprefix')) && (isset($_REQUEST['sa']) && (($_REQUEST['sa'] == 'add') || ($_REQUEST['sa'] == 'edit'))))
{
$context['html_headers'] .= '
<script type="text/javascript">!window.jQuery && document.write(unescape(\'%3Cscript src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"%3E%3C/script%3E\'))</script>
<link rel="stylesheet" type="text/css" href="'. $settings['default_theme_url']. '/css/colpick.css" />
<script type="text/javascript" src="'. $settings['default_theme_url']. '/scripts/colpick.js"></script>';
}
}

I have done the crazy thing of trying it, and obviously it does not work for version 2.0.19. Could you tell me how to adapt that code to 2.0.19? I know that for that version the support is obsolete, but taking into account that it is still used, and it is a serious security problem, i ask you to please help me adapt. Thank you @Diego Andrés   :)
Quote from: Diego Andrés on August 12, 2023, 02:20:18 AMI'm afraid convincing Jotade to upgrade to SMF 2.1 will require bigger effort than your work sanitizing Unicode characters  :laugh:

Diego Andrés

I don't have time at the moment to look into it, and I don't support that MOD anymore.

All you'd need to do is query the prefixes from the table that contains the membergroups and the boards (inside that function is fine) and build a usable array to check using in_array() PHP function, and then load it into a global variable using $context.
An alternative solution you could use is querying the boards/groups each time the posts are edited/posted against the table using the prefix id to check if the user group and the current board are a match.

SMF Tricks - Free & Premium Responsive Themes for SMF.

Jotade29

Quote from: Diego Andrés on March 28, 2024, 10:32:28 PMI don't have time at the moment to look into it, and I don't support that MOD anymore.

All you'd need to do is query the prefixes from the table that contains the membergroups and the boards (inside that function is fine) and build a usable array to check using in_array() PHP function, and then load it into a global variable using $context.
An alternative solution you could use is querying the boards/groups each time the posts are edited/posted against the table using the prefix id to check if the user group and the current board are a match.

Thank you very much for the schematic @Diego Andrés 

It's a pity that support for 2.0 branches has ended in your mods; they are really good, but they have their bugs, and many people still use that branch.

I have already patched it. To avoid leaving things... please confirm if, apart from the board restriction, i only have to keep in mind the powers:

- member_groups
- deny_member_groups

Thank you!!
Quote from: Diego Andrés on August 12, 2023, 02:20:18 AMI'm afraid convincing Jotade to upgrade to SMF 2.1 will require bigger effort than your work sanitizing Unicode characters  :laugh:

Diego Andrés

I'd assume so, but I haven't seen that version of the MOD in many years so I'm not sure  O:)

SMF Tricks - Free & Premium Responsive Themes for SMF.

mickjav

Hi Diego, As you know I'm doing a lot of work on my site, The current section I'm working on will require me to create new topics and replies via a custom UI, as you know I use the prefixes mod, my question is can I send the prefix_id to createPost using the topic array I.E.

createPost($msgOptions, $topicOptions, $posterOptions);
All the best mick

Diego Andrés

You need to define it in the array before sending it:
$topicOptions['id_prefix'] = id;

You should already have it defined before calling createPost() so just add the new key with the value.

SMF Tricks - Free & Premium Responsive Themes for SMF.

Advertisement: