vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   scan for bbcodes within posts (https://vborg.vbsupport.ru/showthread.php?t=148946)

succo 06-05-2007 06:28 AM

scan for bbcodes within posts
 
ok, this is what i'd like to do:
i've got a nice 'media' forum, containing many [media][/media] bbcode tags for stuff i'd like to show in the homepage... at the moment i'm working on making the 'upcoming' module read all the posts in some forums, find the ones containing 'my' bbcode and strip it and put it in a variable... this is my code so far:

PHP Code:

<?php
require_once('./global.php'); // for now it's working alone :)
$mod_options['code'] = "media"// this is my media code
$mod_options['limit'] = "5"// i want only five records
$mod_options['forumid'] = "35"// the forum where the media stuff is
if (!$mod_options['replace']) {
    
$mod_options['replace'] = $mod_options['code'];
        }
$poststuffs $db->query_read_slave("
SELECT post.pagetext
FROM " 
TABLE_PREFIX "post AS post
INNER JOIN " 
TABLE_PREFIX "thread USING (threadid)
WHERE forumid = "
.$mod_options['forumid']."
AND pagetext LIKE '%["
.$mod_options['code']."]%[/".$mod_options['code']."]%'
AND pagetext NOT LIKE '%["
.$mod_options['code']."]%mp3[/".$mod_options['code']."]%'
AND pagetext NOT LIKE '%["
.$mod_options['code']."]mms%[/".$mod_options['code']."]%'
AND pagetext NOT LIKE '%[quote]%["
.$mod_options['code']."]%[/".$mod_options['code']."]%[/quote]%'
ORDER BY post.dateline DESC LIMIT "
.$mod_options['limit']."
"
);
while (
$poststuff $db->fetch_array($poststuffs)) {
    
$poststring[] = ereg_replace("\[/".$mod_options['code']."\].*$""[/".$mod_options['code']."]"ereg_replace("^.*\[".$mod_options['code']."\]""[".$mod_options['replace']."]"$poststuff[pagetext])); // remove everything before and after my tag
    
}
    
print_r($poststring); // i want to see what happened :)
?>

it's partially working, as it finds the correct posts, but (in one case) doesn't succeed in stripping some part of the post away, maybe (that's what i noticed) because it finds some " (quotes)

may anyone help in building this thing up? :)

Dismounted 06-05-2007 06:49 AM

Use preg instead of ereg. It's faster.

succo 06-05-2007 07:20 AM

mmmmmmmh... trying with
PHP Code:

$seek = array("/^.*\[".$mod_options['code']."\]/""/\[\/".$mod_options['code']."\].*$/");
$destroy = array("[".$mod_options['replace']."]""[/".$mod_options['code']."]");
$poststring[] = preg_replace($seek$destroy$poststuff[pagetext]); 

but isn't substituting anything in the text... so, what's wrong? :)
thanks

Dismounted 06-05-2007 08:05 AM

Have you had a look at how vBulletin does it?

succo 06-05-2007 08:24 AM

ok, will try later when back from work :)

thanks

ok, made it work like this

PHP Code:

<?php
require_once('./global.php');
$mod_options['code'] = "media";
$mod_options['limit'] = "5";
$mod_options['forumid'] = "35";
if (!
$mod_options['replace']) {
    
$mod_options['replace'] = $mod_options['code'];
}
$poststuffs $db->query_read_slave("
SELECT post.pagetext
FROM " 
TABLE_PREFIX "post AS post
INNER JOIN " 
TABLE_PREFIX "thread USING (threadid)
WHERE forumid = "
.$mod_options['forumid']."
AND pagetext LIKE '%["
.$mod_options['code']."]%[/".$mod_options['code']."]%'
AND pagetext NOT LIKE '%["
.$mod_options['code']."]%mp3[/".$mod_options['code']."]%'
AND pagetext NOT LIKE '%["
.$mod_options['code']."]mms%[/".$mod_options['code']."]%'
AND pagetext NOT LIKE '%[quote]%["
.$mod_options['code']."]%[/".$mod_options['code']."]%[/quote]%'
ORDER BY post.dateline DESC LIMIT "
.$mod_options['limit']."
"
);
while (
$poststuff $db->fetch_array($poststuffs)) {
    
$poststring[] = preg_replace("#^.*\[".$mod_options['code']."\](.*)\[/".$mod_options['code']."\].*$#si""[".$mod_options['replace']."]$1[/".$mod_options['code']."]"$poststuff[pagetext]);
}
print_r($poststring);
?>

thanks :)


All times are GMT. The time now is 10:54 AM.

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.01707 seconds
  • Memory Usage 1,753KB
  • 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
  • (3)bbcode_php_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