The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
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'); } Quote:
Quote:
Thanks for your help, James |
#2
|
||||
|
||||
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(); } 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 |
#3
|
|||
|
|||
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 |
#4
|
||||
|
||||
Do you have your error phrase in the error phrases or in global or.....etc?
|
#5
|
|||
|
|||
I put my custom phrase in "Front-End Error Messages".
Thanks, James |
#6
|
|||
|
|||
Are you sure it's getting to that point for registered users? Maybe it's a different error.
|
#7
|
|||
|
|||
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; |
#8
|
|||
|
|||
So if you disable your plugin and upload the file as a registered user, it works?
|
#9
|
|||
|
|||
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()) { $errors[] = array( 'filename' => is_array($attachment) ? $attachment['name'] : $attachment, 'error' => $error, ); } |
#10
|
|||
|
|||
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.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|