![]() |
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(" Quote:
Quote:
Thanks for your help, James |
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)) 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 |
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 |
Do you have your error phrase in the error phrases or in global or.....etc?
|
I put my custom phrase in "Front-End Error Messages".
Thanks, James |
Quote:
|
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; |
So if you disable your plugin and upload the file as a registered user, it works?
|
Quote:
--------------- 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()) |
Quote:
|
kh99,
I'm glad you could duplicate the issue. My gut feeling is that it is in issue with using the data manager, but I'm open to any suggestions. |
Yeah, it's caused by this code in class_upload.php (around line 957):
Code:
if (!($result = $this->data->save())) For some reason if you're not an admin it doesn't use the errors from the attachment object. |
Thanks so much for finding that. It makes sense now why it it is a usergroup problem. I'm guessing the VB developers didn't want to show more descriptive error messages to anyone except admin users.
Now I just need to find the most sensible workaround to show other usergroups my phrase in this scenario. Thanks again, James |
I knew that wasn't really going to be a lot of help in fixing the problem. :) Anyway, I was thinking maybe upload_accept, although i'm not sure if the file data is in a variable at that point.
|
I'm looking at upload_accept, but it doesn't look like the filehash has been created yet and I don't think I have the file data yet to create one myself. I'll keep digging.
Thanks, James --------------- Added [DATE]1328546156[/DATE] at [TIME]1328546156[/TIME] --------------- Quote:
This works: Code:
if (!($result = $this->data->save())) Thanks, James |
All times are GMT. The time now is 01:31 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|