Leaving a database record's "snapshot" at a post. [SOLVED]
#3
So, beside the DB considerations about saving this preview, everything looks fine? Cool, Those are great news. Thanks for your help!

Edit: This is my new code:

    function character_preview_save(&$datahandler)
    {
        global $mybb, $db, $templates, $lang;

        $post = get_post($datahandler->pid);

        if(!$post)
        {
            error('No se encontró el tema/post.');
        }

        if(strpos($post['message'], '[personaje]') !== false)
        {
            $character = rpsystem_get_character($post['uid']);

            if(is_null($character))
            {
                error('No puedes usar el bbcode [personaje] sin haber creado un personaje.');
            }
            else
            {
                $preview_data = array(
                    'firstname'     => $character['firstname'],
                    'lastname'      => $character['lastname'],
                    'age'           => $character['age'],
                    'gender'        => $character['gender'],
                    'template'      => 'character_preview'
                );

                $db->insert_query('rpsystem_character_previews', [
                    'pid'           => $post['pid'],
                    'preview'       => $db->escape_string(serialize($preview_data)),
                ]);
            }
        }
    }

    function character_preview_show(&$post)
    {
        global $myVar, $templates;

        $preview = rpsystem_get_character_preview($post['pid']);

        if(is_null($preview))
        {
            $post['message'] = str_replace('[hoja_de_personaje]', '<b>Error:</b> La hoja de personaje no pudo ser localizada.', $post['message']);
        }
        else
        {
            $data = unserialize($preview);

            $firstname = $data['firstname'];
            $lastname = $data['lastname'];
            $age = $data['age'];
            $gender = $data['gender'];
            eval('$myVar = "' . $templates->get($data['template']) . '";');

            $post = str_replace('[hoja_de_personaje]',  $myVar, $post);
        }
    }

This is what you were talking about?
Reply


Messages In This Thread
RE: Leaving a database record's "snapshot" at a post. - by enrolmudas - 2019-01-04, 10:48 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)