Go Back   vb.org Archive > vBulletin 5 Connect Discussion > vB5 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-24-2015, 11:25 AM
ndoktoruser ndoktoruser is offline
 
Join Date: Aug 2015
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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).

Attached Images
File Type: png result.png (21.2 KB, 0 views)
Attached Files
File Type: xml product_anonymous.xml (1.7 KB, 18 views)
Reply With Quote
  #2  
Old 09-25-2015, 01:17 AM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Благодарность от:
ndoktoruser
  #3  
Old 09-25-2015, 09:29 AM
ndoktoruser ndoktoruser is offline
 
Join Date: Aug 2015
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 09-28-2015, 01:14 AM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Looks like you have a start. Any progress on the function?
Reply With Quote
  #5  
Old 09-28-2015, 06:59 AM
ndoktoruser ndoktoruser is offline
 
Join Date: Aug 2015
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #6  
Old 09-28-2015, 01:45 PM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 09-28-2015, 03:27 PM
ndoktoruser ndoktoruser is offline
 
Join Date: Aug 2015
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 09-28-2015, 05:05 PM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 10-05-2015, 01:59 PM
ndoktoruser ndoktoruser is offline
 
Join Date: Aug 2015
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #10  
Old 10-05-2015, 03:01 PM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:09 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04605 seconds
  • Memory Usage 2,290KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_html
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (2)postbit_attachment
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete