vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Running all posts through regular expressions set (https://vborg.vbsupport.ru/showthread.php?t=184153)

mdoliwa 07-02-2008 08:35 AM

Running all posts through regular expressions set
 
Hi,
I'd like to run regular expressions on all my forum posts. And then write a plugin which run these regexps when the new post is submited.
I'm going to exchange some words with adlinks, but wouldnt like them to look like regular underlined links, would be better if they could be the same as regular text, maybe a little different color.

Could you give me any tips how to do it, or where can I read about it?

1. Running regexps on all posts in forum database
2. How to create a plugin runnig set of regular expressions on post while it's being submited by an user ?
3. How to create links that look like regular text but have only different color (I wan't to leave regular links like they are)

Thanks for any help

cheers,
Marcin

Dismounted 07-03-2008 06:45 AM

You can run your code during newreply_process and newthread_process.

mdoliwa 07-03-2008 08:23 AM

Where can I find more info about writing vbulletin plugins ? Any good tutorials?

cheers,
Marcin

necris 07-03-2008 08:31 AM

I use something similar to transform certain words into links and to "block" certain subrepticious spams.

I use the hook "postbit_display_complete", so its executed on every "page-spam" using "newreply_process" and "newthread_process" would be more efficient but less versatile.

Here is an option ^^ up to you tu take it. Regular expressions power :).

Code:

$custom_replace[] = array (
                'string' => '/plainword/',
                'replacement' => '<a>tunned plain word</a>',
                'act' => 1,
                'grp' => 1
        );

....

$custom_replace[] = array (
                'string' => '/plainword10000/',
                'replacement' => '<a>tunned plain word 10000</a>',
                'act' => 1,
                'grp' => 10000
        );

$counter=0;
$grp_old=0;
foreach ($custom_replace as $k => $v) {
        if ( $v['act'] == 1) {
                if($v['grp']<>$grp_old){
                    $grp_old=$v['grp'];
                    $counter=0;
                }
                if($counter==0){
                      $counter=preg_match  ( $v['string']  , $this->post['message']);
                      if($counter<>0){
                            $this->post['message'] = preg_replace($v['string'],$v['replacement'],$this->post['message'],-1);
                      }
                }
        }
}


Dismounted 07-03-2008 10:24 AM

You'd want to prevent it in the first place. Doing it your way will run fairly "load expensive" PCRE functions every time someone views the post and on every post in the thread.

@mdoliwa: You can have a look at the vBulletin Manual.


All times are GMT. The time now is 07:12 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.01063 seconds
  • Memory Usage 1,723KB
  • 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
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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