Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-28-2008, 02:19 PM
Cloud-Warrior's Avatar
Cloud-Warrior Cloud-Warrior is offline
 
Join Date: Feb 2002
Location: Galway, Ireland
Posts: 100
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Using template hooks vs. manual insertion into template

Hello!

I added some custom options to usercp after I read this great tutorial https://vborg.vbsupport.ru/showthread.php?t=116155

Instead of manually editing a template like in this tutorial I wanted to use a template_hook in order to make a product that is easy install for others.

At first I inserted this code directly into the modifyoptions template (as suggested in the tutorial):
Code:
<fieldset class="fieldset">
	<legend><label for="cb_allowsioc">Export SHA1</label></legend>
	<table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0" width="100%">
	<tr>
		<td>
			Export encrypted version of my e-mail address
		</td>
	</tr>
	<tr>
		<td><label for="cb_allowsioc"><input type="checkbox" name="siocbitoptions[allowsioc]" value="1" id="cb_allowsioc" $checked[allowsioc] />Export SHA1</label><input type="hidden" name="set_options[allowsioc]" value="1" /></td>
	</tr>
	</table>
</fieldset>
And everything worked fine.

But when I add the code to the hook global_start using
Code:
$template_hook[usercp_options_privacy] .= ' [same as above] ';
there is a problem:
When I look at the usercp, the checkbox is never checked - it remains empty even tough in the userinfo I can see a 1 where it should be.

Can anyone see where the problem is?
Reply With Quote
  #2  
Old 01-28-2008, 02:42 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can't place variables inside single quotes. Make sure you use double quotes in the global_start hook or you escape out of the quotes.

PHP Code:
// Outputs: Variables do not $expand $either
echo 'Variables do not $expand $either';

$expand 'YES';
$either 'NO';
// Outputs: Variables do not YES NO
echo "Variables do not $expand $either";

// Outputs: Variables do not YES $either
echo 'Variables do not '$expand .' $either'
Check the source code of the page and find the section around the checkbox it should indicate what is going if anything.

Also make sure you surround array keys by single quotes when you write in PHP
e.g.
PHP Code:
// Your version: $template_hook[usercp_options_privacy]
// The way it should be:
$template_hook['usercp_options_privacy']
// N.B. The single quotes 
Reply With Quote
  #3  
Old 01-28-2008, 03:58 PM
Cloud-Warrior's Avatar
Cloud-Warrior Cloud-Warrior is offline
 
Join Date: Feb 2002
Location: Galway, Ireland
Posts: 100
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Opstery, good hint, but still I couldn't get it to work.

Now I have it like this:
Code:
$template_hook['usercp_options_privacy'] .='<fieldset class="fieldset">
	<legend><label for="cb_allowsioc">Export SHA1</label></legend>
	<table cellpadding="0" cellspacing="'.$stylevar[formspacer].'" border="0" width="100%">
	<tr>
		<td>
			Export encrypted version of my e-mail address
		</td>
	</tr>
	<tr>
		<td><label for="cb_allowsioc"><input type="checkbox" name="siocbitoptions[allowsioc]" value="1" id="cb_allowsioc" '.$checked[allowsioc].' />Export SHA1</label><input type="hidden" name="set_options[allowsioc]" value="1" /></td>
	</tr>
	</table>
</fieldset> ';
This should be right and $stylevar[formspacer] does get expanded. But still no checked checkbox - everything gets saved correctly though when I check the box (it also did that before).

Somehow I suspect there is another obvious thing I am missing - any other suggestions what might be wrong? Maybe another hook location instead of global_start?
Reply With Quote
  #4  
Old 01-28-2008, 04:57 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh wait, your using global_start aren't you. You need to choose somewhere "closer" to your page. Find a hook in the PHP in which the original template shows, then choose a hook from there. Make sure that $checked[allowsioc] is actually been set somewhere too and also that the template hook is assigned after $checked[allowioc] is set.
Reply With Quote
  #5  
Old 01-29-2008, 02:27 PM
Cloud-Warrior's Avatar
Cloud-Warrior Cloud-Warrior is offline
 
Join Date: Feb 2002
Location: Galway, Ireland
Posts: 100
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay, after quite a while I found the problem: there is no appropriate hook location.
In profile.php there is the hook "profile_editoptions_start" which is closest to where I need it - but the code that checks the checkboxes is only executed just right after it:
Code:
($hook = vBulletinHook::fetch_hook('profile_editoptions_start')) ? eval($hook) : false;

	// check the appropriate checkboxes
	$checked = array();
	foreach ($vbulletin->userinfo AS $key => $val)
	{
		if ($val != 0)
		{
			$checked["$key"] = 'checked="checked"';
		}
		else

		{
			$checked["$key"] = '';
		}
	}
So no checked checkboxes when I use this hook.

And the next hook "profile_updateoptions" is already "too late" - nothing gets displayed at all when I use this hook!

I edited profile.php and moved the first hook just a couple of lines down, and then everything worked perfectly - but of course I would prefer if the people who install my product wouldn't have to do that, too.

Should I request a new hook / a change of the hook location?
Or is there any other way to deal with that?
(I am running the latest version of 3.6.8)
Reply With Quote
  #6  
Old 01-29-2008, 04:45 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Why don't you just do something like this in your plugin?

PHP Code:
// if(...Some kind of conditions?)
// {
        
$vbulletin->userinfo['allowioc'] = true;
// } 
Reply With Quote
  #7  
Old 01-30-2008, 08:44 AM
Cloud-Warrior's Avatar
Cloud-Warrior Cloud-Warrior is offline
 
Join Date: Feb 2002
Location: Galway, Ireland
Posts: 100
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Opserty!

The saving of the status userinfo['allowioc'] wasn't the problem, just the checkbox didn't get checked when it was true - but your point remains valid:
I just added another plugin that takes care of checking my custom checkboxes at the same hook location with higher priority in the execution order and it now seems to work as needed

Thank you very much! :up:
Reply With Quote
Reply


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 11:43 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.05099 seconds
  • Memory Usage 2,235KB
  • 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
  • (4)bbcode_code
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (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_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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete