Go Back   vb.org Archive > vBulletin 5 Connect Discussion > vB5 Programming Discussions

Reply
 
Thread Tools Display Modes
  #11  
Old 10-07-2015, 02:14 PM
ndoktoruser ndoktoruser is offline
 
Join Date: Aug 2015
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am working on the possibility of saving with the actual userId, but I see a couple of problems:
  1. The routine that fetches last poster / topic creator;
  2. The count of posts made by the user;
  3. The search of posts made by a user.

Now I see that all of those features would need to take the new table into account.
Reply With Quote
  #12  
Old 10-17-2015, 11:54 PM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ndoktoruser View Post
I am working on the possibility of saving with the actual userId, but I see a couple of problems:
  1. The routine that fetches last poster / topic creator;
  2. The count of posts made by the user;
  3. The search of posts made by a user.

Now I see that all of those features would need to take the new table into account.

I've been thinking about this and maybe updating the node table with the anonymous user info is the way to go. Adding logic to the template to determine whether or not the post belongs to a specific user shouldn't be too difficult for editing purposes. There will also need to be an undo script added to the uninstall procedure to revert the changes made by the mod.

EDIT:Ya, after thinking about it, I don't like this idea. If something in the mod or uninstall script were to go awry, the anonymous posts would be irreversible, unowned and I still think it's a bad idea to modify the node table directly. Also the future vbulletin upgrade scripts are not going to take the changes into account and could cause issues there as well.
Reply With Quote
  #13  
Old 10-19-2015, 11:21 AM
ndoktoruser ndoktoruser is offline
 
Join Date: Aug 2015
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Replicant View Post
If something in the mod or uninstall script were to go awry, the anonymous posts would be irreversible
If we start from the point that posts written anonymously would never have been written, once the users didn't have this feature, it would be OK having those posts as "guest user". Plus the fact that it would be inconvenient to the users initially having something personal or awkward posted as anonymous, then having their identities shown.

Once we, the moderators, have their identities saved in a special table to avoid eventual problems, I would be fine with that.

Quote:
Originally Posted by Replicant View Post
I still think it's a bad idea to modify the node table directly.
Yes. I don't know what issues those changes might cause, but I did a small test and couldn't detect any problem.


Quote:
Originally Posted by Replicant View Post
Also the future vbulletin upgrade scripts are not going to take the changes into account and could cause issues there as well.
I agree with you.
To perform any update, one would need to uninstall the plugin (and undo changes to the hook), then update vB and install the plugin adapted for the new version.
I foresee hard time testing the feature, but I don't see another way to avoid multiple hacks (for the post counter, for the topic creator, for the last poster in the topic, for the user information in the topic itself, for the search and maybe more).

So, we have two options: change the data vB stores in the table node or multiple hacks to override fetchUserInfo.
Reply With Quote
  #14  
Old 10-19-2015, 11:24 AM
ndoktoruser ndoktoruser is offline
 
Join Date: Aug 2015
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here it is a functional code to replace the user with "Guest".

Instead of userid (an integer), the table node will save 0.
Instead of username for authorname, the table node will save Guest.

I picked those values, because old posts as anonymous from my old system were migrated with those values.

PS: I tried to not change any existing logic, expect of the userid and authorname, to avoid a higher possibility of including bugs.


-------------------

Notes:

page.php manages whether the checkbox should be displayed or not. Currently, it always returns true. However, page.php is only called when there is a submission of the whole page.
That means for ajax calls (case 1: when the user clicks to edit the post; case 2: when the user posts something in a thread), the anonymous checkbox won't appear.

The case 2 (or simply the whole thing to show the checkbox) should be fixed.


-------------------

1) Installing the plugin:
1.1) Download the file product_anonymous.xml attached to this post;
1.2) Install the product: go to "Products & Hooks" -> "Manage Products" -> "Add/Import Product" and install the .xml file;
2) Copying the page.php file with the function to enable the checkbox:
2.1) Create the structure /anonymous/api/ inside of /core/packages/, so you will have /core/packages/anonymous/api/;
2.2) Download the file page.php attached to this post;
2.3) Copy it to the directory /core/packages/anonymous/api/;
3) Create a new template: Go to "Style & Themes" -> "Style Manager" , then pick "Add New Tamplate" for "Default vB5 Style"
3.1) For this new template, set "anonymous_cb" as the title. Then add the 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>
4) Change the file /core/vb/library/content.php
4.1) Look for the if statement (line 242-258):
HTML Code:
		// *************************************
		// * Fill some default data if missing *
		// *************************************
		if (empty($data['userid']))
		{
			$user = vB::getCurrentSession()->fetch_userinfo();
			$data['authorname'] = $user['username'];
			$userid = $data['userid'] = $user['userid'];
		}
		else
		{
			$userid = $data['userid'];
			if (empty($data['authorname']))
			{
				$data['authorname'] = vB_Api::instanceInternal('user')->fetchUserName($userid);
			}
		}
4.2) Add the following right after the if statement:
HTML Code:
		if ($_POST['anonymous_post'] === "1") {
			$data['authorname'] = "Guest";
			$userid = $data['userid'] = 0;
		}
4.3) Now, look for the if statement (initially on the line 456, now it went to the line 460):
HTML Code:
		if (empty($nodevals['userid']))
4.4) Replace it with:
HTML Code:
		$isPostAnonymous = $_POST['anonymous_post'] === "1" && $nodevals['userid'] === 0;
		if (empty($nodevals['userid']) && !$isPostAnonymous)
5) Change the file /core/vb/library/content/text.php
5.1) Look for the if statement (line 492-506):
HTML Code:
		if (empty($data['userid']))
		{
			$user = vB::getCurrentSession()->fetch_userinfo();
			$data['authorname'] = $user['username'];
			$userid = $data['userid'] = $user['userid'];
		}
		else
		{
			$userid = $data['userid'];
			if (empty($data['authorname']))
			{
				$data['authorname'] = vB_Api::instanceInternal('user')->fetchUserName($userid);
			}
			$user = vB_Api::instance('user')->fetchUserinfo($userid);
		}
5.2) Add the following right after the if statement:
HTML Code:
		if ($_POST['anonymous_post'] === "1") {
			$data['authorname'] = "Guest";
			$userid = $data['userid'] = 0;
		}
Attached Files
File Type: xml product_anonymous.xml (1.7 KB, 9 views)
File Type: php page.php (492 Bytes, 10 views)
Reply With Quote
  #15  
Old 10-19-2015, 11:41 AM
ndoktoruser ndoktoruser is offline
 
Join Date: Aug 2015
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There are two major issues in the code:

1) User information still not saved in the table anonymous_log.
I didn't find any example in vb5 of a plugin which saves info in a new table. Does anyone know one?

2) Condition to display the checkbox needs to be treated in a proper way.
I added the hook to "editor_additional_panels". So how can I know whether it is a new post, a new topic or edition of an existing post?
Reply With Quote
  #16  
Old 10-20-2015, 03:00 AM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Create the following directory structure in your product directory

Code:
db/mysql
Create a file called querydefs.php in the mysql directory, adjust column names as needed

Code:
<?php if (!defined('VB_ENTRY')) die('Access denied.');
class Anonymous_dB_MYSQL_QueryDefs extends vB_dB_QueryDefs
{
	protected $db_type = 'MYSQL';
	protected $saveDbCacheErrorState = false;
	protected $table_data = array(
		'anonymous_log' => array('key' =>  array('logid' , 'userid' , 'parentid' , 'nodeid')) 
	);
	protected $query_data = array();
}
This is the code to do the insert. You will need to set the variables appropriately. These variables worked in my test. I tested it in the createcontent.php frontend controller in the createNewNode() function.

Code:
$userinfo = vB_Api::instance('user')->fetchUserInfo();
vB::getDbAssertor()->insert('Replinonymous:anonymous_log',  array(
'userid' => $userinfo['userid'],
'logid' => '',
'parentid' => $input['parentid'],
'nodeid' => $nodeId 
));
That's pretty much it. Any table you want to write to that is not in the vb querydefs file, has to have an entry in your product query defs file for the api to work. You can also put named queries in the querydefs file and call them with assertQuery().
Reply With Quote
  #17  
Old 10-28-2015, 01:00 PM
ndoktoruser ndoktoruser is offline
 
Join Date: Aug 2015
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello Replicant, sorry for the long time with no reply, but I've tried it and it works fine!
Thank you for the help!

Soon I will edit the initial post and add the last state of all files.
Reply With Quote
Reply

Thread Tools
Display Modes

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 10:22 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.07358 seconds
  • Memory Usage 2,262KB
  • 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
  • (3)bbcode_code
  • (7)bbcode_html
  • (4)bbcode_quote
  • (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
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (2)postbit_attachment
  • (7)postbit_onlinestatus
  • (7)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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete