MyBB Hacks

Full Version: PHP in Templates / Complex Templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
I'm not sure what your first question (?) is about, but I wouldn't recommend trying to use MyCode.
For a simple group conditional, just do it in PHP.  Trying to mix stuff will either lead you to a world of pain, and probably won't work.
Hello, I am trying to do something. I don't think the conditionals are grabbing what I intend. I don't see this ass a problem with the code, but I may be wrong.

This is me trying to be fancy and removing my own profile fields from posts.
Postbit Classic:

Code:
<if $mybb->user['uid'] != 2 then>
 {$post['usertitle']}
 </if>


This ended up deleting all the usertitles there are.
I'd love your help making this work if you have time!

$mybb->user refers to the user of the person viewing the page (i.e. you).
If memory serves correct, try using $post['uid'] instead.
Oh! That was my problem. Thanks a lot lol. It works wondrous now.
Hello!
What about PHP 7 compatibility?

There is an issues with /e modifier in preg_replace from phptpl_parsetpl function.

EDIT:
I tried rewrite code to preg_replace_callback, but it doesn't work:

PHP Code:
    $ourtpl = preg_replace_callback(
        '#\<((?:else)?if\s+(.*?)\s+then|else\s*/?|/if)\>#si',
        function ($m) {
            return phptpl_if($m[1], $m[2]);
        },
        $ourtpl
    ); 
    $ourtpl = preg_replace_callback(
        '#\<template\s+([a-z0-9_ \-+!(),.]+)(\s*/)?\>#i',
        function ($m) {
            return $GLOBALS['templates']->get($m[1]);
        },
        $ourtpl
    );
    $ourtpl = preg_replace_callback(
        '#\<\?=(.*?)\?\>#s',
        function ($m) {
            return strval(phptpl_unescape_string($m[1]));
        },
        $ourtpl
    );
    $ourtpl = preg_replace_callback(
        '#\<setvar\s+([a-z0-9_\-+!(),.]+)\>(.*?)\</setvar\>#i',
        function ($m) {
            $GLOBALS["tplvars"][$m[1]] = $m[2];
            return '';
        },
        $ourtpl
    );
    $ourtpl = preg_replace_callback(
        '#\<\?(?:php|\s).+?(\?\>)#s',
        function ($m) {
            return phptpl_evalphp($m[0], $m[1]);
        },
        $ourtpl
    );

Removal of the 'e' flag is problematic because PHP doesn't really have a direct replacement.  They suggest preg_replace_callback, but it's different in a number of ways.  I've been looking into the preg_replace_callback_array function added in PHP 7, which seems like a feasible solution, but does mean that I need two versions of the code.
Template conditionals plugin is also broken with php7... I am looking for a new updated version soon, must have plugin! Thank you very much!
Updated to v2.1 for PHP 7 compatibility.  As of this version PHP 5.3 or later is required.
but the problem is when i save this the html part is not shown. how can i fix this? any idea?

p.s: i started php with this plugin since 4 days Biggrin
I can't really guess what you're trying to do.
I recommend printing out the variables (i.e. var_dump) so you can see what they're evaluating to and narrow down from there.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Reference URL's