Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)

Reply
 
Thread Tools Display Modes
  #1  
Old 01-23-2015, 04:30 AM
fai99al99 fai99al99 is offline
 
Join Date: Sep 2011
Posts: 53
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How To Make Attachments Required ...?

Hello,

I Want To Make Attachments Required For A Certain Forum
When Someone Add A New Thread , How To Do This?

Thanks for your time,
Reply With Quote
  #2  
Old 01-23-2015, 08:54 AM
Dave Dave is offline
 
Join Date: May 2010
Posts: 2,583
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hook into newthread_post_start and then check if there are any attachments present.
Reply With Quote
  #3  
Old 01-23-2015, 09:30 AM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think you would need an event listener attached to the form that would listen for "submit" and fire a function that would use a regex to check for an attachment on the text submitted and if not preventDefault() and throw an alert or put text in the error div. I guess you would also have to have server checking that would redirect to an error message.

I may play around with it later.
Reply With Quote
  #4  
Old 01-23-2015, 11:11 PM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here we go. This adds an additional hidden input to enabled forums for server checking in case someone posts with JavaScript disabled. The server returns an error message if no attachment is uploaded.

With JavaScript enabled the page will throw an alert if no attachment is uploaded. I had hoped I could distinguish between a submission and preview but that was too complicated so the alert shows for both submit and preview.

Enable this and set forum(s) in "Message Posting Check for Attachment" in Options

Two phrases can be edited by searching phrases for "ca_"

Check it thoroughly and get back if anything goes wrong.
Attached Files
File Type: xml product-check_attachment.xml (5.1 KB, 10 views)
Reply With Quote
Благодарность от:
fai99al99
  #5  
Old 01-24-2015, 04:21 AM
fai99al99 fai99al99 is offline
 
Join Date: Sep 2011
Posts: 53
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you nerbert for your time making this , I really appreciate It.

I have tested It out ,but It seems It does not work ...
It works fine when I click the Preview button only .. but when I click the submit button it does not show any alert that there is no Attachment


I have been searching and figured a another way to do this:

hook : newpost_process

PHP Code:
if($type=='thread' AND in_array($foruminfo['forumid'], array(1,2,3,4,5)))
{

$attachs $vbulletin->db->query_read("SELECT attachmentid
FROM " 
TABLE_PREFIX "attachment 
WHERE posthash = '" 
$vbulletin->db->escape_string($post['posthash']) . "'
AND userid = " 
$vbulletin->userinfo['userid'] . "
ORDER BY attachmentid"
);
if(
$vbulletin->db->num_rows($attachs) <= 0)
$errors[] = $vbphrase['required_attachments'];

Reply With Quote
  #6  
Old 01-24-2015, 04:36 AM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm getting the alert for submit and preview for both sets of buttons. I don't know why an event listener wouldn't fire for that. I was wondering about how to see if an attachment exists for a thread and the only other way to do it besides the new hidden input would be a query like you did. I wanted to avoid queries if possible. Did you find the checkattachmentjavascript template? That's where my JS is.

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

I see you're using a hook in newpost instead of newthread. Is this supposed to require an attachment for each post of the thread or just for the opening post of a new thread?
Reply With Quote
  #7  
Old 01-24-2015, 05:15 AM
fai99al99 fai99al99 is offline
 
Join Date: Sep 2011
Posts: 53
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have re-install It , but still the same problem facing me.
yes, checkattachmentjavascript template Is there
Reply With Quote
  #8  
Old 01-24-2015, 06:12 AM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No matter how you detect an attachment in the server code it would be nice to have an alert before it's submitted rather than getting an error message from the server and going back.

Have you tried editing in more alerts in the JavaScript to see if it's detecting the submit event , whether the function is called and how many "li" elements are in the list? When the page loads there's only one "li" in the list. I don't know what it does, all it contains is &nbsp;. After you load an attachment it should have 2 "li"s.

Try this:
Code:
<script type="text/javascript">
function Check_For_Attachment() {
	this.form = document.forms.vbform;
	this.attachlist = fetch_object("attachlist_list2");
	this.checkInput = document.createElement("input");
		this.checkInput.setAttribute("type", "hidden");
		this.checkInput.setAttribute("name", "checkattachment");
		this.checkInput.setAttribute("value", "");
	this.form.appendChild(this.checkInput);
	this.alertText = "{vb:rawphrase ca_alert_text}";
	YAHOO.util.Event.on(this.form, "submit",  function(e){
		alert("submit detected");
		checkAttachment.checkForm(e)
	})

}

Check_For_Attachment.prototype.checkForm = function(e) {
	var items = fetch_tags(this.attachlist, "li");
	alert("list items " + items.length)
	if(items.length < 2) {
		alert(this.alertText)
		YAHOO.util.Event.stopEvent(e);
	} else {
		this.checkInput.value = "true";
	}
}

YAHOO.util.Event.onDOMReady(function(e) {
	checkAttachment = new Check_For_Attachment();
});
</script>
Reply With Quote
  #9  
Old 01-24-2015, 07:54 AM
fai99al99 fai99al99 is offline
 
Join Date: Sep 2011
Posts: 53
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

did not work ..
I tried to change hook location and editing the code ,but still no luck

to distinguish between a submission and preview buttons I used this:
$_REQUEST['sbutton']
Reply With Quote
  #10  
Old 01-24-2015, 08:06 AM
nerbert nerbert is offline
 
Join Date: May 2008
Posts: 784
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I used $_REQUEST['preview'] but you don't get that until after it's submitted and is read in server code. It doesn't help with the JavaScript though. Well, I don't know what the problem is but as long as you can check at the server I guess you have what you need.

Too bad it didn't work for you.
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 02:39 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04868 seconds
  • Memory Usage 2,278KB
  • 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_code
  • (1)bbcode_php
  • (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
  • (1)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_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
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete