![]() |
Leaving a database record's "snapshot" at a post. [SOLVED] - Printable Version +- MyBB Community Forums (https://community.mybb.com) +-- Forum: Extensions (https://community.mybb.com/forum-201.html) +--- Forum: Plugins (https://community.mybb.com/forum-73.html) +---- Forum: Plugin Development (https://community.mybb.com/forum-68.html) +---- Thread: Leaving a database record's "snapshot" at a post. [SOLVED] (/thread-221340.html) |
Leaving a database record's "snapshot" at a post. [SOLVED] - enrolmudas - 2019-01-04 Well, here i am (again) to ask another question. The last time I was looking for a way to create some sort of "character sheet" for my users to fill and I did it! Now, even though I can save it on my database, lock the view for those users who want to create another character and show the sheet at a post using the next tag: [hoja_de_personaje] which is replaced by a hook so it displays basic dat such a firstname, lastname, gender and age using a template... *takes a breath* I'm facing a new problem: It works, it shows the template, replaces the variables and works like i wanted but... Can i leave some sort of snapshot instead of the updated data? This is my template:
That's what i show if an user writes "[hoja_de_personaje]" on its post. Now, this shows the exact same data that is on my database, which is cool, but I don't want to do so. I want to show how it was a the time he/she posted it. So, if the thread/post is 10 days old, I want that 10 days old data, not the updated one. Why do I want this? Well, easy: I want to avoid cheating. If a user goes and trains his character, it will have better stats (yes, this character sheet will have fields like "power", "health", "mana", etc) so he/she can say: "Hey, my character sheet says that i have it so i can use it" but he/she did not have those new stats at that time. It may sound silly but this is quite important for me. So, is there a way achieve this? I think that MyBB should have some sort of thread or post table where it stores that information and that I can (somehow) modify that table to add this field. That's a first thought, i don't know if that's the better way. Other idea that came to my mind was to create a new table a keep record of this data in there, but... again, I want to know if there is a better way than those two. Once again, sorry for my bad english, I am not a native speaker and... thanks in advance! --- Edit: Almost forgot it. I like how this is going and I hope that you can solve my problem but I have another question: Is there a wat to add an option to the text editor so the users can click it and it would add the "[hoja_de_personaje]" inside their post? I know, that's like using a nuke to kill a single bug, but it would help me on future tasks if I came with more complex tags. --- Edit 2: Hi!, well, this was quite difficult but I did it and it works. Either way, I would like to know if any of you think if this is a good method or if I should modify it. - Table to upload my "character sheets previews":
- Hook:
- Function to save the character preview: (saves the template with the data)
- Function to show the data:
- Function used to get the preview in the "character_post_preview_show" function:
And that's it. I think that it is a lot of work to achieve but I want but this is the only way I could find. RE: Leaving a database record's "snapshot" at a post. - Devilshakerz - 2019-01-04 (2019-01-04, 02:50 AM)enrolmudas Wrote: Edit: Almost forgot it. I like how this is going and I hope that you can solve my problem but I have another question: Is there a wat to add an option to the text editor so the users can click it and it would add the "[hoja_de_personaje]" inside their post? I know, that's like using a nuke to kill a single bug, but it would help me on future tasks if I came with more complex tags. See https://www.sceditor.com/documentation/custom-commands/ - these could be added to jscripts/bbcodes_sceditor.js or custom .js files.Quote:Edit 2: Hi!, well, this was quite difficult but I did it and it works. Either way, I would like to know if any of you think if this is a good method or if I should modify it.Currently the HTML is rendered and inserted into the database - it might be easier (now or in the future, e.g. when the layout needs changes) to simply save a copy of the raw data in multiple table columns (or a single column, using serialize() if the field structure changes often) and then render it with the template on output (in character_post_preview_show() ). That's also where the data should be escaped (MyBB uses htmlspecialchars_uni() ) to make sure that HTML code that may be inserted by users doesn't work there (it may break the layout and introduce security problems).Additionally, all columns values should be escaped with $db->escape_string() before being inserted (in character_post_preview_save() ).
RE: Leaving a database record's "snapshot" at a post. - enrolmudas - 2019-01-04 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:
This is what you were talking about? RE: Leaving a database record's "snapshot" at a post. - Devilshakerz - 2019-01-05 Yes, only need to filter the values on output like so: before the eval() bit; this should make values like <b>hello</b> display exactly as typed, instead of making these HTML tags actually work.
RE: Leaving a database record's "snapshot" at a post. - enrolmudas - 2019-01-05 (2019-01-05, 12:15 AM)Devilshakerz Wrote: Yes, only need to filter the values on output like so: Roger that! Thanks ![]() |