vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Thread title only alphanumeric and space (https://vborg.vbsupport.ru/showthread.php?t=269188)

Gripi 08-26-2011 06:15 PM

Thread title only alphanumeric and space
 
hi...

could someone help me to make the thread title in every new thread can only use "alphanumeric and space" ?

i dont want any special character in the thread title.

thanks alot

kh99 08-26-2011 06:54 PM

Create a new plugin using hook location newpost_process and this code:

PHP Code:

if (!preg_match('/^[A-Za-z0-9\s]+$/'$post['title']))
    
$errors[] = "Only letters, number, and spaces are allowed in title."


Gripi 08-27-2011 03:45 AM

thank you very2 much :)

Badshah93 08-27-2011 04:20 AM

Quote:

Originally Posted by kh99 (Post 2238447)
Create a new plugin using hook location newpost_process and this code:

PHP Code:

if (!preg_match('/^[A-Za-z0-9\s]+$/'$post['title']))
    
$errors[] = "Only letters, number, and spaces are allowed in title."


I think plugin hook should be changed to newthread_post_start

OR

code should be modified to

PHP Code:

iif (!preg_match('/^[A-Za-z0-9\s]+$/'$post['title']) AND $type == 'thread')
    
$errors[] = "Only letters, number, and spaces are allowed in title."


Because the present code will check for new reply also. and generally new reply title are like this

Code:

Re: //title

kh99 08-27-2011 05:25 AM

Quote:

Originally Posted by Sherif (Post 2238593)
Because the present code will check for new reply also. and generally new reply title are like this

Good point. But changing the hook to newthread_post_start doesn't seem to work. Your second suggestion works except that you have 'iff' at the beginning (is that a typo?).

Checking for $type == 'thread' will allow any characters in reply titles, but the OP does specifically say "thread titles", so maybe that's OK.

Gripi, sorry for any problems this may have caused on your forum. :o

Edit: I also figured out that it only quotes the title with "Re:" if you have set the "Automatically Quote Post / Thread Title" to true, otherwise title is blank by default (which also caused a problem since the pattern didn't allow blank titles). So I have the following suggestion (using newpost_process):

PHP Code:

if ($type != 'thread' && $vbulletin->options['quotetitle'])
    
$titlepat '/^(' preg_quote($vbphrase['reply_prefix'], "/") . ')?[A-Za-z0-9\s]*$/';
else
    
$titlepat '/^[A-Za-z0-9\s]*$/';
if (!
preg_match($titlepat$post['title']))
    
$errors[] = "Only letters, number, and spaces are allowed in title."


Badshah93 08-27-2011 05:53 AM

Quote:

Originally Posted by kh99 (Post 2238614)
Good point. But changing the hook to newthread_post_start doesn't seem to work. Your second suggestion works except that you have 'iff' at the beginning (is that a typo?).

Checking for $type == 'thread' will allow any characters in reply titles, but the OP does specifically say "thread titles", so maybe that's OK.

Gripi, sorry for any problems this may have caused on your forum. :o

YA ITS IF NOT IIF

PHP Code:

if (!preg_match('/^[A-Za-z0-9\s]+$/'$post['title']) AND $type == 'thread')
    
$errors[] = "Only letters, number, and spaces are allowed in title."


For newthread_post_start hook we need to modify the code to this


PHP Code:

if (!preg_match('/^[A-Za-z0-9\s]+$/'$vbulletin->GPC[subject]))
    
standard_error("Only letters, number, and spaces are allowed in title."); 


Gripi 08-28-2011 04:56 PM

once again thanks, i'm thinking to put the code in the beta forum this monday, i will let you know if the code works or not.

Gripi 10-22-2011 08:12 AM

Hi again...

could you please tell me how to automaticly remove any character beside alphanumeric and space in the title when someone post a new thread or a new post?

i dont want any warning error msg, just submit the post / thread to database, and remove any ilegal character.

thanks

--------------- Added [DATE]1319275153[/DATE] at [TIME]1319275153[/TIME] ---------------

and is it possible to make the plugin to work like this:

not just allowing alphanumeric and space, but remove character that i choose.

kh99 10-22-2011 12:09 PM

If you want to replace any non-alphanumeric or space chars you can use preg_replace() like:

PHP Code:

$pattern '/[^a-zA-Z0-9 ]/';
$replace ' ';
$post['title'] = preg_replace($pattern$replace$post['title']); 


$replace is a space in that example, you can make it a null string if you want to delete the char instead.

If you want to only eliminate one or a set of chars you could change $pattern to a list of the chars to delete, like:

PHP Code:

$pattern '/[@#*$]/';
... 


Gripi 10-23-2011 06:12 PM

thank you


All times are GMT. The time now is 03:53 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01166 seconds
  • Memory Usage 1,754KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (8)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete