The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Add/Change posting data
Hello, everyone!
I am currently working on a similar functionality of anonymous posting, adapted to vBulletin 5. I have added a check box to flag that the user will post anonymously. Now, I need to change the code which gets the data submitted by the form and saves it in the DB. So, how do I change the data submitted by the user when he/she posts in a topic? I don't want to change the code of the vBulletin classes. Maybe there is a way of simply add/change the content of the $data array which saves the data in the node table. I also need to perform a second insertion (this time, to another table, to add the anonymous information). Does anyone have any hint of what to do or know any plugin that does something similar using vB 5? Note: as soon as the plugin is complete, I intend to post it on the forum to get feedback and share it with other people who need the same feature. ------------------- Edit to add code related to the plugin: 1) Download the product_anonymous.xml file attached to this post; 2) Install the product: go to "Products & Hooks" -> "Manage Products" -> "Add/Import Product" and install the .xml file; 3) Create a new template: Go to "Style & Themes" -> "Style Manager" -> pick "Add New Tamplate" for "Default vB5 Style" 3.1) For this new template, set "anonymous_cb" as the title and following code: HTML Code:
<vb:if condition="$page['hasCheckbox'] == true"> <div class="b-content-entry-panel__content b-content-entry-panel__content--smiley h-clearfix"> <label class="js-collapse__link h-align-middle text-bold b-link js-link" for="checkbox_anonymous">Post as anonymous</label> <input type="checkbox" id="checkbox_anonymous" name="anonymous_post" value="1"> </div> </vb:if> As result, a check box to post anonymously will appear (the function must be implemented). |
#2
|
||||
|
||||
Sounds like an interesting project. I'm by far no expert but here's my initial thoughts on the subject.
Changing the data array in the ckeditor submission probably won't work. Until the submission takes place, there is no nodeid to associate your anonymous user data to. Take a look at /js/ckeditor-rollup-519.js. This is where the post submission occurs. A script will be needed for the additional anonymous info submission via a frontend controller. I'm thinking you will need to capture the response data to get the nodeid of the new post, then use that data to insert the node info in your new anonymous table. Then you will need to add conditionals in the display_contenttype_threadview_header template (I believe) to check your anonymous info table for the current nodeid. You will also need to create an API extension to get the data from the anonymous table (probably cache it) so you can call that function from the templates. |
Благодарность от: | ||
ndoktoruser |
#3
|
|||
|
|||
Thanks for the hint, Replicant!
However, maybe I didn't explain very well what I want to do. I do not want to change the content submitted by the form (/js/ckeditor-rollup-519.js). Is this the best option? I imagined the following: 1) receive the content submitted by the form; (probably some API extension would do it, with no changes to the JS) 2) validate whether the check box for anonymous post was checked or not; 3) if so, change the data which will be saved for the post (in the table node); 3.1) the current API saves the "userid" and "authorname" in the table "node", so I would set values for an anonymous post (0, "Guest"); 3.2) at the same time, I would store the real "userid", "authorname" and "nodeid" in a new table created by the plugin (this information might be important for moderation). I believe that this would be the simplest way, because I wouldn't change any existing code. And when the topic is displayed, the current API would fetch the correct "anonymous" id and user from the table node. PS: I changed the initial post to add the code for the hook. PS2: the feature would have the same functionality as if we allow "non registered users" post in the community, but only for "registered users". And would add the log in the new table. So, technically vB already does that, I just don't know where. |
#4
|
||||
|
||||
Looks like you have a start. Any progress on the function?
|
#5
|
|||
|
|||
No real progress so far.
I will start changing the code and check what happens (when I get understand enough, I undo the changes and extend the classes in a proper way). I suppose the function vB_Api_Content::add (in core/vb/api/content.php) is responsible for creating the new node. Then I have to find the proper way pass the right values to the parameter data. Unfortunately I have no experience with vB. --------------- Added [DATE]1443451334[/DATE] at [TIME]1443451334[/TIME] --------------- Does anyone know any plugin for vBulletin 5 that changes or adds something to the default data which is posted by the forum users? |
#6
|
||||
|
||||
I'm still thinking the js method is the way to go. The form is submitted via ajax to the createcontent controller. If you can submit the form to your own controller function instead, forward the form data to the correct function for posting, catch the jsonResponse, and do your insert to your custom table at that point.
After looking at it a little closer, changing the data in the node table is going to cause issues with statistics, editing by post owner and also issues with attachments and images. There are more tables involved in the posts than just the node table that are attached to the userid. I would suggest staying away from changing the node table data and look at changing the output at template time. |
#7
|
|||
|
|||
I will take at the JS then.
I will be useful to set the "anonymous check" in the data array. I found that, in the function vB_Api_Content_Text::add, I have access to the text and title of the post/topic. And changing the text or title worked. The data array also contains the userid and auhtorname, but it doesn't make any difference if I change it inside of this function. Somewhere else in the code, the session user is retrieved and saved. |
#8
|
||||
|
||||
The post data contains userid, username, secret, token and so forth. Some of that info is hashed to authenticate the post. That is why it needs to be submitted as the real user. That's why I am inclined to use the data as is and work it server side after the post is made. Here's a rough idea of what I'm thinking.
Post is clicked anonymous. That click changes the class on the reply button to call the custom controller using jquery. The controller hands off the data to the createcontent controller and intercepts the jsonResponse. The json Response has the nodeid of the new post. The controller then takes that nodeid and does an insert into the anonymous db table with userid and whatever else may be needed, then returns the jsonResponse to the browser to complete the post and reload the page. In the content template, there would be a conditional that checks if the post nodeid =anonymous.nodeid, if it does, it replaces the post authorname with "Anonymous" else it just continues loading as usual. There will need to be an api extension made to query the anonymous table. The whole process should only add one db query. This is just a rough idea and may not work as I haven't tested any of it. I do have a working api extension to query the database for the template conditional that I can share with you. |
#9
|
|||
|
|||
Hello!
Sorry for the late reply, but I was very sick and didn't work on the feature. Could you please share the template you told about? |
#10
|
||||
|
||||
I'll try to get that for you this week. I'm kind of slammed this week, so it may be this weekend before I have a chance to get to it.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|