• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Post Guard (basic) 1.1.4

No permission to download

Yugensoft

Active member
#1
Yugensoft submitted a new resource:

Post Guard - Prevent users posting invalid posts with regex post guards

Introduction
XenForo prevents users from creating posts with no content. However there may be other types of invalid posts that you wish to prevent users making.

Description
This add-on allows you to specify invalid posts using regular expressions, or "post guards". If a user attempts to submit a post with matches one of your post guards, it will fail and they will receive an error message that you specify for that post guard.

Instructions
  • ...
Read more about this resource...
 

Alfa1

Well-known member
#2
Would it be possible to:
  1. block off site links
  2. Block Wikipedia links
  3. An exact word
  4. Texts of more than X characters without line breaks.
  5. Texts of more than X characters without punctuation.
 

Yugensoft

Active member
#3
Would it be possible to:
  1. block off site links
  2. Block Wikipedia links
  3. An exact word
  4. Texts of more than X characters without line breaks.
  5. Texts of more than X characters without punctuation.
I actually don't know what regex can't do when it comes to text manipulation.

Those would be approx these, but I'd have to check them.
  1. /\[url.*?\].*?\[\/url\]/si
  2. /\[url='.*?wikipedia.*?'\].*?\[\/url\]/si
  3. /theword/si (where theword is the exact word)
  4. /^[^\n]{20,}?$/si (where 20 is the number of characters)
  5. /^[^.,\/#!$%\^&\*;:{}=\-_`~()]{20,}?$/si (where 20 is the number of characters)
 
Last edited:

Alfa1

Well-known member
#4
  1. This seems to block any url including internal links.
  2. This works like a charm.
  3. This has a problem as there needs to be a space before and after the word. Currently its giving the error for all words that contain the same characters.
  4. Works like a charm.
  5. Works like a charm.
Multiple guards are not listed in the error message. Please add this.
Please add guards for thread title.
 

Yugensoft

Active member
#5
  1. This seems to block any url including internal links.
  2. This works like a charm.
  3. This has a problem as there needs to be a space before and after the word. Currently its giving the error for all words that contain the same characters.
  4. Works like a charm.
  5. Works like a charm.
Multiple guards are not listed in the error message. Please add this.
Please add guards for thread title.
Ah, misinterpreted (1) as "block-off" rather than "off-site".

Sure, won't take much. Thread title will have to be done next revision though.
 
Last edited:

Alfa1

Well-known member
#12
After upgrade the error only shows the phrase name.
This is not fixed in the latest version.
The cause is that the upgrade has wiped out all guard phrases listed in the addon. This makes me worried what other phrases may have been affected.
I realize that its not possible to fix deleted custom phrases, so its not possible to fix the issue in this sense. However, I need to be 100% sure that no further phrases will be deleted with upgrades or other events. Data loss always scares me. I dont understand how it is possible that these phrases were wiped. Please let me know.

Maybe its an idea to create/edit the new phrases upon creation/edit of the guard. Or somehow tie it together.
 

Yugensoft

Active member
#13
I dont understand how it is possible that these phrases were wiped. Please let me know.
There's nothing in the add-on that deletes phrases. There are only two things internally that can cause data deletion: when you uninstall the add-on (deletes the add-on's created "guard" table only); or when you delete a guard (deletes a row in that table only). Perhaps it's something internal to the way add-on upgrades work in XenForo regarding phrases.

To take a guess, did you put the phrases in Master and also associate them with the "Post Guard" add-on?

Edit: yes it appears XenForo automatically deletes any previous phrases associated with an add-on when it upgrades it:
library\XenForo\Model\Phrase.php:1226
Code:
$this->deletePhrasesForAddOn($addOnId);
I'll have to consider the best way to circumvent XenForo doing this. Easiest way is just not to use the Phrase system altogether, but I wanted to do this the "right" way.
 
Last edited:

Alfa1

Well-known member
#14
It could make sense not to use phrases for this. As long as its still optimized for big boards. i.e. not increase things like simplecache unnecessarily.
 

NixFifty

Well-known member
#15
I'll have to consider the best way to circumvent XenForo doing this. Easiest way is just not to use the Phrase system altogether, but I wanted to do this the "right" way.
I've not used this add-on so I'm not sure how you're creating phrases and then finding them but one way to do it is by creating a new phrase with the ID of the actual post guard (e.g. postguard_guard_{id}_text) and not associating it with an add-on. You can then write a quick function to return a phrase based on the post guard ID you pass in to it.

On uninstall, you can nuke leftover phrases that have the post guard prefix.

That's how I (and most others) do it. :)
 

Yugensoft

Active member
#16
Given that the purpose of phrases is primarily multi-language support, I don't see how a generate id-containing phrase name system is going to help that much.

In the case of a multi-language board (are they even that common?), the admin would have to manually identify the generated phrase name to duplicate into the different languages, versus the current setup where he is making the human-readable phrase name himself.

The following option looks easiest: just tell the users not to associate phrases with the add-on in Master. Unfortunately, that's counter-intuitive. I guess I could put a note to that effect under the "error phrase" textbox.

The other option is just say "sorry no multi-language", and store the error text directly in the add-ons database table -- they can always just populate the error message with both languages.
 
Last edited:

Alfa1

Well-known member
#17
Multi-language boards are the norm. Even a purely English board has master plus 1 language (English). I never touch master language phrases as these are usually overwritten with upgrades. I only edit English phrases.

I think the way Nixfifty does it is also the way that other experienced XenForo developers work and is a useful approach.
I was already manually adding a pg_ prefix to phrases for this reason.
 

Yugensoft

Active member
#18
Multi-language boards are the norm. Even a purely English board has master plus 1 language (English). I never touch master language phrases as these are usually overwritten with upgrades. I only edit English phrases.

I think the way Nixfifty does it is also the way that other experienced XenForo developers work and is a useful approach.
I was already manually adding a pg_ prefix to phrases for this reason.
Then it's unclear how the phrases could have been deleted. Without touching Master (which allows associating a phrase with an add-on), I don't see any mechanism by which either XenForo or the add-on could've identified & deleted the phrases. I will test upgrading with a saved non-Master phrase myself and investigate it.

Edit: I upgraded through each version since 1.0.0 to the latest, on my live server (which doesn't have developer mode enabled), and I did not observe any deletion of a "Language:English (US)" phrase during upgrades.
 
Last edited:

Alfa1

Well-known member
#19
I should elaborate on this. There always needs to be a master phrase. Sop first a master phrase needs to be created. The English phrase is copied from the master phrase upon first edit. If the master phrase is deleted then the child phrases are deleted as well.
 

Yugensoft

Active member
#20
I should elaborate on this. There always needs to be a master phrase. Sop first a master phrase needs to be created. The English phrase is copied from the master phrase upon first edit. If the master phrase is deleted then the child phrases are deleted as well.
I've made a test phrase in English without making it in Master.

Either way, it's true that the interface for inserting a phrase currently isn't that smooth, and could be improved later. But it does appear to work without add-on upgrade interference as long as you put the new phrase in English only.