Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 02-05-2012, 11:13 PM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to return error phrase in attachdata_presave hook?

I'm trying to block certain attachments from being posted. When I make use of returning "false" in the attachdata_presave hook I can successfully stop the file from being saved in VB. However, when I try to customize the error message shown in the browser to the end-user, it only works when I am logged in as "admin". Registered users still see the standard error message.

Here's what I have in attachdata_presave
Code:
$bannedmatches = $this->dbobject->query_first("
	SELECT COUNT(*) AS count
	FROM " . TABLE_PREFIX . "banned_attachment
	WHERE filehash = '" . $this->fetch_field('filehash') . "'
");

if ($bannedmatches['count'] > 0)
{
     $return_value = false;
     $this->error('jb_file_not_allowed_here');
}
When I'm logged in as admin and try to upload a banned attachment I see my custom error phrase in the response page.
Quote:
hippos.jpg:
This file is not allowed to be uploaded on our website.
When I'm logged in as a registered user and try to upload the same attachment, I see the standard error phrase.
Quote:
hippos.jpg:
Upload of file failed.
What am I missing? What would be the best way to set the error text here to use my own custom phrase?

Thanks for your help,
James
Reply With Quote
  #2  
Old 02-06-2012, 12:32 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Why would you go to all that trouble?, just don't allow the file type in the attachments manager?

That said you can display an error message like this example, if you create a custom hook (custom_template_permissions)
HTML Code:
if (is_member_of($vbulletin->userinfo, 1))
{
        print_no_ permission_ custom_ template(); 
        exit(); 
}
if (is_member_of($vbulletin->userinfo, 8,9,10))
{
        print_no_ permission(); 
}
In fact the easiest would probably be to edit the newattachment_errormessage template, remove the $errormessage and put your own text in there and/or conditions

These should help too
HOOKS CALLED
init_startup
fetch_userinfo_query
fetch_musername
fetch_userinfo
cache_permissions
fetch_foruminfo
style_fetch
cache_templates
global_start
parse_templates
notices_check_start
notifications_list
global_setup_complete
newattachment_start
attachdata_start
upload_accept
error_fetch
newattachment_attach
editor_wysiwyg_compatible
newattachment_complete


TEMPLATES CALLED
newattachment
newattachment_errormessage
newattachment_keybit


PHRASE GROUPS CALLED
global
posting
prefix
Reply With Quote
  #3  
Old 02-06-2012, 01:08 AM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Simon,
Thanks for your help. I'm not trying to block certain types of attachments. I'm trying to block specific attachments by comparing the filehash of the file that the member uploaded to a list filehash values I'll maintain of "banned" files/attachments.

I'm still trying to figure out why my error phrase is working correctly for the admin usergroup, but registered users are seeing the VB default phrase. I double-checked and both phrases are the same type.

(Stock VB phrase)
Front-End Error Messages
upload_file_failed
"Upload of file failed."

(My custom phrase)
Front-End Error Messages
jb_file_not_allowed_here
"This file is not allowed to be uploaded on our website."

It's a mystery to me why different usergroups are seeing different phrases.

Thanks,
James
Reply With Quote
  #4  
Old 02-06-2012, 01:11 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Do you have your error phrase in the error phrases or in global or.....etc?
Reply With Quote
  #5  
Old 02-06-2012, 01:18 AM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I put my custom phrase in "Front-End Error Messages".

Thanks,
James
Reply With Quote
  #6  
Old 02-06-2012, 01:23 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by JamesAB View Post
It's a mystery to me why different usergroups are seeing different phrases.
Are you sure it's getting to that point for registered users? Maybe it's a different error.
Reply With Quote
  #7  
Old 02-06-2012, 01:38 AM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes. I know the code in the hook is being executed because the line above the line that sets the error is being executed:
Code:
$return_value = false;
This is stopping the attachment from being saved and is working as expected for both admins and registered users.
Reply With Quote
  #8  
Old 02-06-2012, 01:40 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So if you disable your plugin and upload the file as a registered user, it works?
Reply With Quote
  #9  
Old 02-06-2012, 01:52 AM
JamesAB JamesAB is offline
 
Join Date: Dec 2003
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
So if you disable your plugin and upload the file as a registered user, it works?
Yes. When I disable the plugin, "Manage Attachments" works as expected. All usergroups can upload the same files with no limitations or error messages.

--------------- Added [DATE]1328496982[/DATE] at [TIME]1328496982[/TIME] ---------------

Maybe something weird is happening with the vB_Upload_Attachment datamanager?

Here is where newattachment.php is getting the error text from:
Code:
				if ($error = $upload->fetch_error())
				{
					$errors[] = array(
						'filename' => is_array($attachment) ? $attachment['name'] : $attachment,
						'error'    => $error,
					);
				}
Reply With Quote
  #10  
Old 02-06-2012, 02:03 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by JamesAB View Post
Yes. When I disable the plugin, "Manage Attachments" works as expected. All usergroups can upload the same files with no limitations or error messages.
OK, just wanted to make sure. I tried your code (well, I really just set the return value and error message) and I do get the same problem.
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 08:12 PM.


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.07039 seconds
  • Memory Usage 2,261KB
  • Queries Executed 13 (?)
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
  • (1)bbcode_html
  • (5)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
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (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_postinfo_query
  • fetch_postinfo
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete