MyBB Community Forums

Full Version: How to escape mybb codes with php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Are you kidding ? I just use
<?
and do what ever I want, what functionality is restricted in it ?
?>
(2012-09-01, 03:20 PM)Paul H. Wrote: [ -> ]The PHP in templates plugin doens't really allow PHP; it allows certain functions, and in a slightly different syntax. You'll need to use a plugin for what you want.
Hm, nevermind I guess I am wrong.

Also, you shouldn't use mysql_query and other mysql_* functions; use $db->query and $db->fetch_array etc.
(2012-09-01, 03:26 PM)Paul H. Wrote: [ -> ]Hm, nevermind I guess I am wrong.

Also, you shouldn't use mysql_query and other mysql_* functions; use $db->query and $db->fetch_array etc.

Thanks, and what about my problem ?
Try this;
<?php
$query=$db->query("SELECT * FROM `mybb_posts` LIMIT 0 , 30");
while($row=$db->fetch_array($query))
{
       require_once MYBB_ROOT."inc/class_parser.php";
       $parser_options = array(
            'allow_html' => 0,
            'allow_mycode' => 0,
            'allow_smilies' => 0,
            'allow_imgcode' => 0,
            'filter_badwords' => 0
        );
$message['message']=strip_tags($parser->parse_message($row['message'], $parser_options));
$message['message']=substr($message['message'],0,86);
echo $message['message'].'...';
}
?>
(2012-09-01, 03:38 PM)Yaldaram Wrote: [ -> ]Try this;
<?php
$query=$db->query("SELECT * FROM `mybb_posts` LIMIT 0 , 30");
while($row=$db->fetch_array($query))
{
       require_once MYBB_ROOT."inc/class_parser.php";
       $parser_options = array(
            'allow_html' => 0,
            'allow_mycode' => 0,
            'allow_smilies' => 0,
            'allow_imgcode' => 0,
            'filter_badwords' => 0
        );
$message['message']=strip_tags($parser->parse_message($row['message'], $parser_options));
$message['message']=substr($message['message'],0,86);
echo $message['message'].'...';
}
?>

Didn't work Sad
Strange, try this instead;
$query=$db->query("SELECT * FROM `mybb_posts` LIMIT 0 , 30");
while($row=$db->fetch_array($query))
{
	$message['message'] = htmlspecialchars_uni($row['message']);
	$message['message'] = strip_tags(str_replace(array('[',']'), array('<','>'), $message['message']));
	echo $message['message'].'...';
}
It's giving content encoding error in firefox.
Have you tried the script in your forum ?
Yes, tried and it worked. BTW I'm not using PHP in templates plugin, I used the above script directly in index.php file just below index_start hook.
I am using it on index template from the admin panel
there it doens't work Sad
Pages: 1 2